@native-sdk/cli 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.zig +91 -2
- package/build.zig +756 -5
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +19 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/rt/rt.zig +416 -9
- package/packages/core/sdk/core.ts +706 -5
- package/packages/core/sdk/events.ts +17 -8
- package/packages/core/src/checker.ts +305 -2
- package/packages/core/src/diagnostics.ts +12 -0
- package/packages/core/src/emitter.ts +3187 -264
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +42 -4
- package/skill-data/ts-core/SKILL.md +13 -3
- package/src/app_runner/root.zig +112 -10
- package/src/app_runner/ts_core_main.zig +4 -0
- package/src/automation/layout_fingerprint.zig +160 -0
- package/src/automation/protocol.zig +82 -33
- package/src/automation/root.zig +1 -0
- package/src/automation/server.zig +1 -1
- package/src/automation/snapshot.zig +68 -9
- package/src/automation/watcher.zig +1 -1
- package/src/embed/host.zig +5 -0
- package/src/embed/tests.zig +119 -1
- package/src/embed/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +639 -16
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +351 -7
- package/src/platform/macos/appkit_host.h +152 -8
- package/src/platform/macos/appkit_host.m +1816 -100
- package/src/platform/macos/cef_host.mm +372 -11
- package/src/platform/macos/root.zig +379 -11
- package/src/platform/null_platform.zig +696 -9
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +42 -0
- package/src/platform/types.zig +524 -18
- package/src/platform/windows/root.zig +432 -9
- package/src/platform/windows/webview2_host.cpp +482 -45
- package/src/primitives/app_manifest/comptime_scene.zig +5 -0
- package/src/primitives/app_manifest/root.zig +1 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/canvas/a11y_audit.zig +33 -11
- package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
- package/src/primitives/canvas/drawing.zig +25 -0
- package/src/primitives/canvas/equality.zig +8 -0
- package/src/primitives/canvas/events.zig +103 -16
- package/src/primitives/canvas/frame.zig +125 -1
- package/src/primitives/canvas/layout_audit.zig +22 -5
- package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
- package/src/primitives/canvas/render_tests.zig +13 -10
- package/src/primitives/canvas/root.zig +48 -0
- package/src/primitives/canvas/terminal_box.zig +471 -0
- package/src/primitives/canvas/terminal_grid.zig +978 -0
- package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/tests.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +535 -12
- package/src/primitives/canvas/ui_markup.zig +253 -36
- package/src/primitives/canvas/ui_markup_binary.zig +4 -1
- package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
- package/src/primitives/canvas/ui_markup_contract.zig +89 -6
- package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
- package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
- package/src/primitives/canvas/ui_markup_tests.zig +178 -9
- package/src/primitives/canvas/ui_markup_view.zig +220 -11
- package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
- package/src/primitives/canvas/ui_schema.zig +110 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -10
- package/src/primitives/canvas/ui_tests.zig +141 -9
- package/src/primitives/canvas/widget_access.zig +28 -2
- package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
- package/src/primitives/canvas/widget_invalidation.zig +81 -1
- package/src/primitives/canvas/widget_layout.zig +59 -11
- package/src/primitives/canvas/widget_layout_tests.zig +125 -4
- package/src/primitives/canvas/widget_render.zig +272 -18
- package/src/primitives/canvas/widget_render_scroll.zig +108 -27
- package/src/primitives/canvas/widget_routing.zig +59 -7
- package/src/primitives/canvas/widget_runtime.zig +23 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
- package/src/primitives/canvas/widget_semantics.zig +119 -11
- package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
- package/src/primitives/canvas/widget_tree.zig +17 -0
- package/src/primitives/canvas/widgets.zig +132 -0
- package/src/root.zig +23 -0
- package/src/runtime/api.zig +76 -5
- package/src/runtime/automation_commands.zig +20 -1
- package/src/runtime/automation_snapshot.zig +25 -1
- package/src/runtime/automation_widget_dispatch.zig +73 -8
- package/src/runtime/bridge_payload.zig +8 -0
- package/src/runtime/bridge_responses.zig +5 -0
- package/src/runtime/builtin_bridge.zig +9 -4
- package/src/runtime/canvas_font_tests.zig +439 -2
- package/src/runtime/canvas_fonts.zig +61 -6
- package/src/runtime/canvas_frame.zig +62 -7
- package/src/runtime/canvas_frame_animation_tests.zig +5 -4
- package/src/runtime/canvas_frame_helpers.zig +190 -1
- package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
- package/src/runtime/canvas_frame_patch_tests.zig +161 -10
- package/src/runtime/canvas_frame_retained_tests.zig +5 -2
- package/src/runtime/canvas_image_tests.zig +195 -0
- package/src/runtime/canvas_images.zig +45 -12
- package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
- package/src/runtime/canvas_widget_context_menu.zig +269 -32
- package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
- package/src/runtime/canvas_widget_display.zig +1 -1
- package/src/runtime/canvas_widget_event_tests.zig +1823 -0
- package/src/runtime/canvas_widget_events.zig +240 -24
- package/src/runtime/canvas_widget_runtime.zig +213 -29
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
- package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
- package/src/runtime/canvas_widget_state.zig +6 -0
- package/src/runtime/canvas_widget_text_tests.zig +1 -1
- package/src/runtime/core.zig +131 -13
- package/src/runtime/effects.zig +8136 -180
- package/src/runtime/effects_channel_tests.zig +3519 -0
- package/src/runtime/effects_fetch_tests.zig +89 -1
- package/src/runtime/effects_file_tests.zig +41 -1
- package/src/runtime/effects_image_tests.zig +1304 -0
- package/src/runtime/effects_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +167 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +42 -4
- package/src/runtime/gpu_surface_events.zig +473 -13
- package/src/runtime/media_surface.zig +116 -11
- package/src/runtime/media_surface_tests.zig +61 -0
- package/src/runtime/pty.zig +1252 -0
- package/src/runtime/pty_windows.zig +1780 -0
- package/src/runtime/root.zig +36 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_blobs.zig +689 -0
- package/src/runtime/session_journal.zig +432 -62
- package/src/runtime/session_record.zig +43 -2
- package/src/runtime/session_replay.zig +556 -20
- package/src/runtime/session_tests.zig +2087 -1
- package/src/runtime/shell_layout.zig +7 -0
- package/src/runtime/terminal_session.zig +1569 -0
- package/src/runtime/terminal_session_tests.zig +450 -0
- package/src/runtime/terminal_vt_ghostty.zig +15 -0
- package/src/runtime/terminal_vt_stub.zig +13 -0
- package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
- package/src/runtime/testdata/fonts/OFL.txt +93 -0
- package/src/runtime/tests.zig +8 -0
- package/src/runtime/ts_core_host.zig +1320 -45
- package/src/runtime/ts_core_host_tests.zig +1100 -1
- package/src/runtime/ts_ui_app.zig +23 -5
- package/src/runtime/ui_app.zig +2444 -69
- package/src/runtime/ui_app_tests.zig +3171 -744
- package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
- package/src/runtime/ui_app_window_tests.zig +736 -0
- package/src/runtime/view.zig +190 -2
- package/src/runtime/view_widget_scroll.zig +218 -68
- package/src/runtime/view_widget_text.zig +11 -2
- package/src/runtime/view_widget_tree.zig +111 -3
- package/src/runtime/window_command_bridge_tests.zig +117 -0
- package/src/runtime/window_storage.zig +77 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +62 -1
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/manifest.zig +75 -0
- package/src/tooling/raw_manifest.zig +2 -0
- package/src/tooling/templates.zig +244 -8
|
@@ -594,6 +594,8 @@ const VerbMsg = union(enum) {
|
|
|
594
594
|
minimize_settings,
|
|
595
595
|
minimize_main,
|
|
596
596
|
close_settings,
|
|
597
|
+
show_settings,
|
|
598
|
+
quit,
|
|
597
599
|
settings_closed,
|
|
598
600
|
};
|
|
599
601
|
|
|
@@ -606,6 +608,8 @@ fn verbUpdate(model: *VerbModel, msg: VerbMsg, fx: *VerbApp.Effects) void {
|
|
|
606
608
|
// The imperative close, for the seam test — a real app's
|
|
607
609
|
// model-declared window usually closes declaratively instead.
|
|
608
610
|
.close_settings => fx.closeWindow(settings_window_label),
|
|
611
|
+
.show_settings => fx.showWindow(settings_window_label),
|
|
612
|
+
.quit => fx.quitApp(),
|
|
609
613
|
.settings_closed => model.settings_open = false,
|
|
610
614
|
}
|
|
611
615
|
}
|
|
@@ -692,6 +696,14 @@ test "window-action effects resolve labels to live windows and drive the real ve
|
|
|
692
696
|
if (info.id == settings_id) try std.testing.expect(info.open);
|
|
693
697
|
}
|
|
694
698
|
|
|
699
|
+
// Show by label is the counterpart verb: it reaches the platform's
|
|
700
|
+
// show (the minimized window comes back with focus) and the mirror
|
|
701
|
+
// counts it.
|
|
702
|
+
try app_state.dispatch(&harness.runtime, 1, .show_settings);
|
|
703
|
+
try std.testing.expectEqual(@as(u32, 1), harness.null_platform.showCountForWindow(settings_id));
|
|
704
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.effects.windowActionState().show_count);
|
|
705
|
+
try std.testing.expectEqualStrings(settings_window_label, app_state.effects.windowActionState().lastLabel());
|
|
706
|
+
|
|
695
707
|
// The main window resolves by label too (the runtime adopted the
|
|
696
708
|
// host-reported startup window above). The fake host never created
|
|
697
709
|
// a native window for it — live hosts own the startup window — so
|
|
@@ -714,4 +726,728 @@ test "window-action effects resolve labels to live windows and drive the real ve
|
|
|
714
726
|
// main window still answers after the secondary's churn.
|
|
715
727
|
try app_state.dispatch(&harness.runtime, 1, .minimize_main);
|
|
716
728
|
try std.testing.expectEqual(@as(u32, 3), app_state.effects.windowActionState().minimize_count);
|
|
729
|
+
|
|
730
|
+
// quitApp asks the platform for the graceful terminate (the modeled
|
|
731
|
+
// host records the request; a real host QUEUES the stop so
|
|
732
|
+
// app_shutdown emits on the next loop turn, after this dispatch
|
|
733
|
+
// has returned) and the mirror counts it.
|
|
734
|
+
try app_state.dispatch(&harness.runtime, 1, .quit);
|
|
735
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.effects.windowActionState().quit_count);
|
|
736
|
+
try std.testing.expectEqual(@as(u32, 1), harness.null_platform.quit_request_count);
|
|
737
|
+
// The host's queued shutdown echo delivers the exactly-once stop
|
|
738
|
+
// hook — the same path a last-window close takes. Draining it here
|
|
739
|
+
// IS the next loop turn, and it drains exactly once.
|
|
740
|
+
const shutdown_event = harness.null_platform.takeQueuedQuit() orelse return error.TestUnexpectedResult;
|
|
741
|
+
try std.testing.expect(harness.null_platform.takeQueuedQuit() == null);
|
|
742
|
+
try harness.runtime.dispatchPlatformEvent(app, shutdown_event);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
test "the .hide close then showWindow round-trip: tray Open brings the hidden window back" {
|
|
746
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
747
|
+
defer harness.destroy(std.testing.allocator);
|
|
748
|
+
harness.null_platform.gpu_surfaces = true;
|
|
749
|
+
const app_state = try VerbApp.create(std.heap.page_allocator, .{
|
|
750
|
+
.name = "ui-app-hide-show-loop",
|
|
751
|
+
.scene = panel_scene,
|
|
752
|
+
.canvas_label = canvas_label,
|
|
753
|
+
.update_fx = verbUpdate,
|
|
754
|
+
.view = verbView,
|
|
755
|
+
.windows_fn = verbWindows,
|
|
756
|
+
.window_view = verbWindowView,
|
|
757
|
+
});
|
|
758
|
+
defer app_state.destroy();
|
|
759
|
+
const app = app_state.app();
|
|
760
|
+
try harness.start(app);
|
|
761
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
762
|
+
.label = canvas_label,
|
|
763
|
+
.size = geometry.SizeF.init(400, 300),
|
|
764
|
+
.scale_factor = 2,
|
|
765
|
+
.frame_index = 1,
|
|
766
|
+
.timestamp_ns = 1_000_000,
|
|
767
|
+
.nonblank = true,
|
|
768
|
+
} });
|
|
769
|
+
var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
|
|
770
|
+
var settings_id: support.platform.WindowId = 0;
|
|
771
|
+
for (harness.runtime.listWindows(&buffer)) |info| {
|
|
772
|
+
if (std.mem.eql(u8, info.label, settings_window_label)) settings_id = info.id;
|
|
773
|
+
}
|
|
774
|
+
try std.testing.expect(settings_id != 0);
|
|
775
|
+
|
|
776
|
+
// Give the live window the .hide policy at the platform (the seam a
|
|
777
|
+
// manifest declaration rides) and close it as the user: hidden, not
|
|
778
|
+
// gone.
|
|
779
|
+
for (harness.null_platform.windows[0..harness.null_platform.window_count], 0..) |window, index| {
|
|
780
|
+
if (window.id == settings_id) harness.null_platform.window_close_policy[index] = .hide;
|
|
781
|
+
}
|
|
782
|
+
const hide_event = harness.null_platform.userCloseWindow(settings_id).?;
|
|
783
|
+
try harness.runtime.dispatchPlatformEvent(app, hide_event);
|
|
784
|
+
for (harness.runtime.listWindows(&buffer)) |info| {
|
|
785
|
+
if (info.id == settings_id) try std.testing.expect(info.hidden);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// The tray "Open" consequence: the model returns the show verb, the
|
|
789
|
+
// label resolves against the still-open hidden window, and the
|
|
790
|
+
// platform + runtime state both flip back.
|
|
791
|
+
try app_state.dispatch(&harness.runtime, 1, .show_settings);
|
|
792
|
+
try std.testing.expectEqual(@as(u32, 1), harness.null_platform.showCountForWindow(settings_id));
|
|
793
|
+
for (harness.runtime.listWindows(&buffer)) |info| {
|
|
794
|
+
if (info.id == settings_id) try std.testing.expect(!info.hidden);
|
|
795
|
+
}
|
|
796
|
+
for (harness.null_platform.windows[0..harness.null_platform.window_count]) |window| {
|
|
797
|
+
if (window.id == settings_id) {
|
|
798
|
+
try std.testing.expect(!window.hidden);
|
|
799
|
+
try std.testing.expect(window.focused);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// ------------------------------------- close_policy (.quit | .hide)
|
|
805
|
+
|
|
806
|
+
test "close_policy .hide: the user close hides the window, nothing tears down, and the reopen re-shows it" {
|
|
807
|
+
const fixture = try Fixture.create();
|
|
808
|
+
defer fixture.destroy();
|
|
809
|
+
|
|
810
|
+
// A menu-bar-shaped window through the REAL create seam (the same
|
|
811
|
+
// `ShellWindow` path a manifest-declared window rides): the
|
|
812
|
+
// declared policy must survive to the platform.
|
|
813
|
+
const info = try fixture.harness.runtime.createSourcelessShellWindow(.{
|
|
814
|
+
.label = "player",
|
|
815
|
+
.title = "Player",
|
|
816
|
+
.width = 400,
|
|
817
|
+
.height = 300,
|
|
818
|
+
.close_policy = .hide,
|
|
819
|
+
});
|
|
820
|
+
try std.testing.expectEqual(support.platform.WindowClosePolicy.hide, fixture.harness.null_platform.closePolicyForWindow(info.id).?);
|
|
821
|
+
|
|
822
|
+
// The user clicks the red button: the modeled close delegate hides
|
|
823
|
+
// instead of closing — the window stays in the host's records
|
|
824
|
+
// (open = true), only the hidden flag flips, and because open never
|
|
825
|
+
// transitioned, NO window_closed app event (and so no on_close Msg)
|
|
826
|
+
// fires.
|
|
827
|
+
const hide_event = fixture.harness.null_platform.userCloseWindow(info.id).?;
|
|
828
|
+
try std.testing.expect(hide_event.window_frame_changed.open);
|
|
829
|
+
try std.testing.expect(hide_event.window_frame_changed.hidden);
|
|
830
|
+
try fixture.harness.runtime.dispatchPlatformEvent(fixture.app, hide_event);
|
|
831
|
+
try std.testing.expectEqual(@as(u32, 0), fixture.app_state.model.user_closes);
|
|
832
|
+
var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
|
|
833
|
+
for (fixture.harness.runtime.listWindows(&buffer)) |window| {
|
|
834
|
+
if (window.id != info.id) continue;
|
|
835
|
+
try std.testing.expect(window.open);
|
|
836
|
+
try std.testing.expect(window.hidden);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
// The Dock-icon reopen: every policy-hidden window re-shows and the
|
|
840
|
+
// hidden flag clears through the same journaled frame channel.
|
|
841
|
+
var reopen_buffer: [support.platform.max_windows]support.platform.Event = undefined;
|
|
842
|
+
const reopen_events = fixture.harness.null_platform.userReopenApp(&reopen_buffer);
|
|
843
|
+
try std.testing.expectEqual(@as(usize, 1), reopen_events.len);
|
|
844
|
+
try std.testing.expect(!reopen_events[0].window_frame_changed.hidden);
|
|
845
|
+
for (reopen_events) |event| try fixture.harness.runtime.dispatchPlatformEvent(fixture.app, event);
|
|
846
|
+
for (fixture.harness.runtime.listWindows(&buffer)) |window| {
|
|
847
|
+
if (window.id != info.id) continue;
|
|
848
|
+
try std.testing.expect(window.open);
|
|
849
|
+
try std.testing.expect(!window.hidden);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// A reopen with nothing hidden is honestly empty — the host's
|
|
853
|
+
// default reopen behavior stays in charge.
|
|
854
|
+
try std.testing.expectEqual(@as(usize, 0), fixture.harness.null_platform.userReopenApp(&reopen_buffer).len);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
test "an app-driven close of a policy-hidden window clears hidden with open, and rolls it back on platform failure" {
|
|
858
|
+
const fixture = try Fixture.create();
|
|
859
|
+
defer fixture.destroy();
|
|
860
|
+
|
|
861
|
+
// A menu-bar-shaped window through the REAL create seam, hidden by
|
|
862
|
+
// its .hide close policy (the user clicked the red button).
|
|
863
|
+
const info = try fixture.harness.runtime.createSourcelessShellWindow(.{
|
|
864
|
+
.label = "player",
|
|
865
|
+
.title = "Player",
|
|
866
|
+
.width = 400,
|
|
867
|
+
.height = 300,
|
|
868
|
+
.close_policy = .hide,
|
|
869
|
+
});
|
|
870
|
+
const hide_event = fixture.harness.null_platform.userCloseWindow(info.id).?;
|
|
871
|
+
try fixture.harness.runtime.dispatchPlatformEvent(fixture.app, hide_event);
|
|
872
|
+
var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
|
|
873
|
+
for (fixture.harness.runtime.listWindows(&buffer)) |window| {
|
|
874
|
+
if (window.id != info.id) continue;
|
|
875
|
+
try std.testing.expect(window.open);
|
|
876
|
+
try std.testing.expect(window.hidden);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
// The platform refuses the close: EVERY optimistically flipped flag
|
|
880
|
+
// rolls back — the window is still open, still policy-hidden.
|
|
881
|
+
fixture.harness.null_platform.fail_next_close_window = true;
|
|
882
|
+
try std.testing.expectError(error.CloseFailed, fixture.harness.runtime.closeWindow(info.id));
|
|
883
|
+
for (fixture.harness.runtime.listWindows(&buffer)) |window| {
|
|
884
|
+
if (window.id != info.id) continue;
|
|
885
|
+
try std.testing.expect(window.open);
|
|
886
|
+
try std.testing.expect(window.hidden);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// The app closes its hidden window for real: a closed window is not
|
|
890
|
+
// "hidden", it is gone — the runtime table (the JS bridge's window
|
|
891
|
+
// list) must read {open=false, hidden=false}, never a closed window
|
|
892
|
+
// still flying the hidden flag.
|
|
893
|
+
try fixture.harness.runtime.closeWindow(info.id);
|
|
894
|
+
var found = false;
|
|
895
|
+
for (fixture.harness.runtime.listWindows(&buffer)) |window| {
|
|
896
|
+
if (window.id != info.id) continue;
|
|
897
|
+
found = true;
|
|
898
|
+
try std.testing.expect(!window.open);
|
|
899
|
+
try std.testing.expect(!window.hidden);
|
|
900
|
+
try std.testing.expect(!window.focused);
|
|
901
|
+
}
|
|
902
|
+
try std.testing.expect(found);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
test "showWindow activates: the shown window takes key in the runtime table, and a refused show moves nothing" {
|
|
906
|
+
const fixture = try Fixture.create();
|
|
907
|
+
defer fixture.destroy();
|
|
908
|
+
|
|
909
|
+
// A policy-hidden window (the user's close under .hide).
|
|
910
|
+
const info = try fixture.harness.runtime.createSourcelessShellWindow(.{
|
|
911
|
+
.label = "player",
|
|
912
|
+
.title = "Player",
|
|
913
|
+
.width = 400,
|
|
914
|
+
.height = 300,
|
|
915
|
+
.close_policy = .hide,
|
|
916
|
+
});
|
|
917
|
+
const hide_event = fixture.harness.null_platform.userCloseWindow(info.id).?;
|
|
918
|
+
try fixture.harness.runtime.dispatchPlatformEvent(fixture.app, hide_event);
|
|
919
|
+
|
|
920
|
+
// The show verb's contract is show AND activate — every host's show
|
|
921
|
+
// path makes the window key. After a successful platform show, the
|
|
922
|
+
// runtime table (what listWindows and the JS bridge serve) must
|
|
923
|
+
// read the shown window focused and every other window unfocused,
|
|
924
|
+
// not a frontmost window still reported keyless.
|
|
925
|
+
try fixture.harness.runtime.showWindow(info.id);
|
|
926
|
+
var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
|
|
927
|
+
var found = false;
|
|
928
|
+
for (fixture.harness.runtime.listWindows(&buffer)) |window| {
|
|
929
|
+
if (window.id == info.id) {
|
|
930
|
+
found = true;
|
|
931
|
+
try std.testing.expect(!window.hidden);
|
|
932
|
+
try std.testing.expect(window.focused);
|
|
933
|
+
} else {
|
|
934
|
+
try std.testing.expect(!window.focused);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
try std.testing.expect(found);
|
|
938
|
+
|
|
939
|
+
// Hide again, then refuse the show at the platform: hidden rolls
|
|
940
|
+
// back and focus does not move — a refused show must never report
|
|
941
|
+
// a focused window that never came back to the glass.
|
|
942
|
+
const rehide_event = fixture.harness.null_platform.userCloseWindow(info.id).?;
|
|
943
|
+
try fixture.harness.runtime.dispatchPlatformEvent(fixture.app, rehide_event);
|
|
944
|
+
fixture.harness.null_platform.fail_next_show_window = true;
|
|
945
|
+
try std.testing.expectError(error.ShowFailed, fixture.harness.runtime.showWindow(info.id));
|
|
946
|
+
for (fixture.harness.runtime.listWindows(&buffer)) |window| {
|
|
947
|
+
if (window.id != info.id) continue;
|
|
948
|
+
try std.testing.expect(window.hidden);
|
|
949
|
+
try std.testing.expect(!window.focused);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
test "the window verbs refuse a retained closed slot: show, focus, and minimize answer WindowNotFound with no platform call" {
|
|
954
|
+
const fixture = try Fixture.create();
|
|
955
|
+
defer fixture.destroy();
|
|
956
|
+
|
|
957
|
+
// A closed window keeps its table slot (the id and label release
|
|
958
|
+
// lazily, at the next create), so resolving the id is not liveness.
|
|
959
|
+
// Without the open gate the null platform accepts the verbs and
|
|
960
|
+
// reports {open:false, focused:true}, and the CEF host — which
|
|
961
|
+
// retains browser-bearing windows past their close — would visibly
|
|
962
|
+
// re-order the closed window onto the glass. The runtime gate holds
|
|
963
|
+
// independent of host timing.
|
|
964
|
+
const info = try fixture.harness.runtime.createSourcelessShellWindow(.{
|
|
965
|
+
.label = "player",
|
|
966
|
+
.title = "Player",
|
|
967
|
+
.width = 400,
|
|
968
|
+
.height = 300,
|
|
969
|
+
.close_policy = .hide,
|
|
970
|
+
});
|
|
971
|
+
try fixture.harness.runtime.closeWindow(info.id);
|
|
972
|
+
|
|
973
|
+
// show: the dead-slot answer, and the platform recorder never moves.
|
|
974
|
+
try std.testing.expectError(error.WindowNotFound, fixture.harness.runtime.showWindow(info.id));
|
|
975
|
+
try std.testing.expectEqual(@as(u32, 0), fixture.harness.null_platform.showCountForWindow(info.id));
|
|
976
|
+
|
|
977
|
+
// focus resolves by id too, and close cleared `hidden` with `open`,
|
|
978
|
+
// so without its own gate it skips the hidden-routing and reaches
|
|
979
|
+
// the platform's focus verb directly.
|
|
980
|
+
try std.testing.expectError(error.WindowNotFound, fixture.harness.runtime.focusWindow(info.id));
|
|
981
|
+
try std.testing.expectEqual(@as(u32, 0), fixture.harness.null_platform.showCountForWindow(info.id));
|
|
982
|
+
|
|
983
|
+
// The minimize twin (the CEF host would genie the retained closed
|
|
984
|
+
// window into the Dock).
|
|
985
|
+
try std.testing.expectError(error.WindowNotFound, fixture.harness.runtime.minimizeWindow(info.id));
|
|
986
|
+
try std.testing.expectEqual(@as(u32, 0), fixture.harness.null_platform.minimizeCountForWindow(info.id));
|
|
987
|
+
|
|
988
|
+
// Nothing resurrected: the runtime table and the platform mirror
|
|
989
|
+
// both still read the window closed, unfocused, un-hidden.
|
|
990
|
+
var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
|
|
991
|
+
var found = false;
|
|
992
|
+
for (fixture.harness.runtime.listWindows(&buffer)) |window| {
|
|
993
|
+
if (window.id != info.id) continue;
|
|
994
|
+
found = true;
|
|
995
|
+
try std.testing.expect(!window.open);
|
|
996
|
+
try std.testing.expect(!window.focused);
|
|
997
|
+
try std.testing.expect(!window.hidden);
|
|
998
|
+
}
|
|
999
|
+
try std.testing.expect(found);
|
|
1000
|
+
for (fixture.harness.null_platform.windows[0..fixture.harness.null_platform.window_count]) |window| {
|
|
1001
|
+
if (window.id != info.id) continue;
|
|
1002
|
+
try std.testing.expect(!window.open);
|
|
1003
|
+
try std.testing.expect(!window.focused);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
test "the modeled host mirrors the app close of a hidden window, and the reopen never resurrects a closed one" {
|
|
1008
|
+
const fixture = try Fixture.create();
|
|
1009
|
+
defer fixture.destroy();
|
|
1010
|
+
|
|
1011
|
+
// A menu-bar-shaped window, policy-hidden by the user's close.
|
|
1012
|
+
const info = try fixture.harness.runtime.createSourcelessShellWindow(.{
|
|
1013
|
+
.label = "player",
|
|
1014
|
+
.title = "Player",
|
|
1015
|
+
.width = 400,
|
|
1016
|
+
.height = 300,
|
|
1017
|
+
.close_policy = .hide,
|
|
1018
|
+
});
|
|
1019
|
+
const hide_event = fixture.harness.null_platform.userCloseWindow(info.id).?;
|
|
1020
|
+
try fixture.harness.runtime.dispatchPlatformEvent(fixture.app, hide_event);
|
|
1021
|
+
|
|
1022
|
+
// The app closes the hidden window through the runtime. The modeled
|
|
1023
|
+
// host's mirror must read closed AND un-hidden — the same
|
|
1024
|
+
// hidden-clears-with-open rule the real hosts' close paths carry
|
|
1025
|
+
// (set cleanup before the open=false emit) and the runtime table
|
|
1026
|
+
// already pins for its own flags.
|
|
1027
|
+
try fixture.harness.runtime.closeWindow(info.id);
|
|
1028
|
+
for (fixture.harness.null_platform.windows[0..fixture.harness.null_platform.window_count]) |window| {
|
|
1029
|
+
if (window.id != info.id) continue;
|
|
1030
|
+
try std.testing.expect(!window.open);
|
|
1031
|
+
try std.testing.expect(!window.hidden);
|
|
1032
|
+
try std.testing.expect(!window.focused);
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
// The Dock reopen after the close: NO frame event for the closed
|
|
1036
|
+
// window — nothing hidden-and-open remains to re-show.
|
|
1037
|
+
var reopen_buffer: [support.platform.max_windows]support.platform.Event = undefined;
|
|
1038
|
+
try std.testing.expectEqual(@as(usize, 0), fixture.harness.null_platform.userReopenApp(&reopen_buffer).len);
|
|
1039
|
+
|
|
1040
|
+
// The reopen's liveness check must hold on its own, not lean on the
|
|
1041
|
+
// close mirror's hidden clear: model a host whose close path forgot
|
|
1042
|
+
// that cleanup by forcing the stale flag onto the closed slot — the
|
|
1043
|
+
// reopen still refuses to resurrect (hidden alone is not liveness).
|
|
1044
|
+
for (fixture.harness.null_platform.windows[0..fixture.harness.null_platform.window_count]) |*window| {
|
|
1045
|
+
if (window.id == info.id) window.hidden = true;
|
|
1046
|
+
}
|
|
1047
|
+
try std.testing.expectEqual(@as(usize, 0), fixture.harness.null_platform.userReopenApp(&reopen_buffer).len);
|
|
1048
|
+
|
|
1049
|
+
// No events dispatched, so the runtime table is untouched: the
|
|
1050
|
+
// window stays closed, un-hidden, never re-focused.
|
|
1051
|
+
var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
|
|
1052
|
+
var found = false;
|
|
1053
|
+
for (fixture.harness.runtime.listWindows(&buffer)) |window| {
|
|
1054
|
+
if (window.id != info.id) continue;
|
|
1055
|
+
found = true;
|
|
1056
|
+
try std.testing.expect(!window.open);
|
|
1057
|
+
try std.testing.expect(!window.hidden);
|
|
1058
|
+
try std.testing.expect(!window.focused);
|
|
1059
|
+
}
|
|
1060
|
+
try std.testing.expect(found);
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
test "focus-while-hidden routes through the show verb: hidden clears before the window takes key" {
|
|
1064
|
+
const fixture = try Fixture.create();
|
|
1065
|
+
defer fixture.destroy();
|
|
1066
|
+
|
|
1067
|
+
const info = try fixture.harness.runtime.createSourcelessShellWindow(.{
|
|
1068
|
+
.label = "player",
|
|
1069
|
+
.title = "Player",
|
|
1070
|
+
.width = 400,
|
|
1071
|
+
.height = 300,
|
|
1072
|
+
.close_policy = .hide,
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
// The user close hides the window (policy .hide) and the runtime
|
|
1076
|
+
// adopts the hidden state off the journaled frame channel.
|
|
1077
|
+
const hide_event = fixture.harness.null_platform.userCloseWindow(info.id).?;
|
|
1078
|
+
try fixture.harness.runtime.dispatchPlatformEvent(fixture.app, hide_event);
|
|
1079
|
+
var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
|
|
1080
|
+
for (fixture.harness.runtime.listWindows(&buffer)) |window| {
|
|
1081
|
+
if (window.id == info.id) try std.testing.expect(window.hidden);
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
// Focusing the hidden window must drive the platform's SHOW verb
|
|
1085
|
+
// (the path that clears the hosts' policy-hidden bookkeeping and
|
|
1086
|
+
// emits consistent state), not just its focus verb: the hidden
|
|
1087
|
+
// flag clears, focus lands, and the show count pins the routing —
|
|
1088
|
+
// a focusWindow that skips the show seam leaves this count at 0
|
|
1089
|
+
// and the window reported hidden while standing on the glass.
|
|
1090
|
+
try fixture.harness.runtime.focusWindow(info.id);
|
|
1091
|
+
try std.testing.expectEqual(@as(u32, 1), fixture.harness.null_platform.showCountForWindow(info.id));
|
|
1092
|
+
for (fixture.harness.runtime.listWindows(&buffer)) |window| {
|
|
1093
|
+
if (window.id != info.id) continue;
|
|
1094
|
+
try std.testing.expect(window.open);
|
|
1095
|
+
try std.testing.expect(!window.hidden);
|
|
1096
|
+
try std.testing.expect(window.focused);
|
|
1097
|
+
}
|
|
1098
|
+
// The platform mirror agrees on both flags.
|
|
1099
|
+
for (fixture.harness.null_platform.windows[0..fixture.harness.null_platform.window_count]) |window| {
|
|
1100
|
+
if (window.id != info.id) continue;
|
|
1101
|
+
try std.testing.expect(!window.hidden);
|
|
1102
|
+
try std.testing.expect(window.focused);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
// A visible window's focus stays a plain focus: no second show.
|
|
1106
|
+
try fixture.harness.runtime.focusWindow(info.id);
|
|
1107
|
+
try std.testing.expectEqual(@as(u32, 1), fixture.harness.null_platform.showCountForWindow(info.id));
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
test "close_policy default stays .quit: the user close still tears the window down" {
|
|
1111
|
+
const fixture = try Fixture.create();
|
|
1112
|
+
defer fixture.destroy();
|
|
1113
|
+
|
|
1114
|
+
try fixture.clickSettingsButton();
|
|
1115
|
+
const info = fixture.settingsWindowInfo() orelse return error.TestUnexpectedResult;
|
|
1116
|
+
// No declaration means .quit: the capture proves the default rode
|
|
1117
|
+
// the create seam unchanged.
|
|
1118
|
+
try std.testing.expectEqual(support.platform.WindowClosePolicy.quit, fixture.harness.null_platform.closePolicyForWindow(info.id).?);
|
|
1119
|
+
const close_event = fixture.harness.null_platform.userCloseWindow(info.id).?;
|
|
1120
|
+
try std.testing.expect(!close_event.window_frame_changed.open);
|
|
1121
|
+
try std.testing.expect(!close_event.window_frame_changed.hidden);
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
test "close_policy .hide is refused loudly at create on hosts without the affordance" {
|
|
1125
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
1126
|
+
defer harness.destroy(std.testing.allocator);
|
|
1127
|
+
// Model a GTK-shaped host: no status item, no way to bring a
|
|
1128
|
+
// hidden window back — the feature reports false and window create
|
|
1129
|
+
// refuses the declaration instead of stranding the window.
|
|
1130
|
+
harness.null_platform.window_hide_on_close = false;
|
|
1131
|
+
try std.testing.expectError(error.UnsupportedWindowClosePolicy, harness.runtime.createSourcelessShellWindow(.{
|
|
1132
|
+
.label = "tools",
|
|
1133
|
+
.title = "Tools",
|
|
1134
|
+
.width = 320,
|
|
1135
|
+
.height = 240,
|
|
1136
|
+
.close_policy = .hide,
|
|
1137
|
+
}));
|
|
1138
|
+
// The same shape under .quit (the default) creates fine.
|
|
1139
|
+
const info = try harness.runtime.createSourcelessShellWindow(.{
|
|
1140
|
+
.label = "tools",
|
|
1141
|
+
.title = "Tools",
|
|
1142
|
+
.width = 320,
|
|
1143
|
+
.height = 240,
|
|
1144
|
+
});
|
|
1145
|
+
try std.testing.expect(info.open);
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
test "close_policy .hide on a secondary startup window is refused loudly at startup load on hosts without the affordance" {
|
|
1149
|
+
const SourceApp = struct {
|
|
1150
|
+
fn app(self: *@This()) support.App {
|
|
1151
|
+
return .{ .context = self, .name = "startup-hide", .source = support.platform.WebViewSource.html("<p>Startup</p>") };
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
const startup_windows = [_]support.platform.WindowOptions{
|
|
1155
|
+
.{ .id = 1, .label = "main", .title = "Main" },
|
|
1156
|
+
.{ .id = 2, .label = "panel", .title = "Panel", .close_policy = .hide },
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1159
|
+
// Model a GTK-shaped host: the feature reports false, and the
|
|
1160
|
+
// startup-window load — which creates secondary windows through
|
|
1161
|
+
// the platform services directly, not the runtime's createWindow —
|
|
1162
|
+
// must refuse the secondary window's `.hide` declaration with the
|
|
1163
|
+
// same loud error as the create seam. A silent accept here means
|
|
1164
|
+
// the host ignores the policy and the user's close really closes.
|
|
1165
|
+
{
|
|
1166
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
1167
|
+
defer harness.destroy(std.testing.allocator);
|
|
1168
|
+
harness.null_platform.window_hide_on_close = false;
|
|
1169
|
+
harness.runtime.options.platform.app_info.windows = &startup_windows;
|
|
1170
|
+
var app_state: SourceApp = .{};
|
|
1171
|
+
try std.testing.expectError(error.UnsupportedWindowClosePolicy, harness.start(app_state.app()));
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
// A host WITH the affordance loads the same declaration: both
|
|
1175
|
+
// startup windows come up.
|
|
1176
|
+
{
|
|
1177
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
1178
|
+
defer harness.destroy(std.testing.allocator);
|
|
1179
|
+
harness.runtime.options.platform.app_info.windows = &startup_windows;
|
|
1180
|
+
var app_state: SourceApp = .{};
|
|
1181
|
+
try harness.start(app_state.app());
|
|
1182
|
+
var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
|
|
1183
|
+
try std.testing.expectEqual(@as(usize, 2), harness.runtime.listWindows(&buffer).len);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
// --------------------- context-menu pin across the window lifecycle
|
|
1188
|
+
|
|
1189
|
+
const MenuWinModel = struct {
|
|
1190
|
+
a_open: bool = true,
|
|
1191
|
+
b_open: bool = true,
|
|
1192
|
+
generation: u32 = 0,
|
|
1193
|
+
sends: u32 = 0,
|
|
1194
|
+
received_storage: [64]u8 = undefined,
|
|
1195
|
+
received_len: usize = 0,
|
|
1196
|
+
received_ptr: usize = 0,
|
|
1197
|
+
};
|
|
1198
|
+
|
|
1199
|
+
const MenuWinMsg = union(enum) {
|
|
1200
|
+
bump,
|
|
1201
|
+
close_a,
|
|
1202
|
+
a_closed,
|
|
1203
|
+
b_closed,
|
|
1204
|
+
send: []const u8,
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1207
|
+
const MenuWinApp = ui_app_model.UiApp(MenuWinModel, MenuWinMsg);
|
|
1208
|
+
|
|
1209
|
+
fn menuWinUpdate(model: *MenuWinModel, msg: MenuWinMsg) void {
|
|
1210
|
+
switch (msg) {
|
|
1211
|
+
.bump => model.generation += 1,
|
|
1212
|
+
.close_a, .a_closed => model.a_open = false,
|
|
1213
|
+
.b_closed => model.b_open = false,
|
|
1214
|
+
.send => |bytes| {
|
|
1215
|
+
const len = @min(bytes.len, model.received_storage.len);
|
|
1216
|
+
@memcpy(model.received_storage[0..len], bytes[0..len]);
|
|
1217
|
+
model.received_len = len;
|
|
1218
|
+
model.received_ptr = @intFromPtr(bytes.ptr);
|
|
1219
|
+
model.sends += 1;
|
|
1220
|
+
},
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
fn menuWinView(ui: *MenuWinApp.Ui, model: *const MenuWinModel) MenuWinApp.Ui.Node {
|
|
1225
|
+
_ = model;
|
|
1226
|
+
return ui.column(.{ .gap = 8, .padding = 12 }, .{
|
|
1227
|
+
ui.button(.{ .on_press = .bump }, "Rebuild"),
|
|
1228
|
+
ui.button(.{ .on_press = .close_a }, "Close A"),
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
fn menuWinWindows(model: *const MenuWinModel, scratch: *MenuWinApp.WindowsScratch) []const MenuWinApp.WindowDescriptor {
|
|
1233
|
+
var count: usize = 0;
|
|
1234
|
+
if (model.a_open) {
|
|
1235
|
+
scratch.windows[count] = .{
|
|
1236
|
+
.label = "win-a",
|
|
1237
|
+
.canvas_label = "canvas-a",
|
|
1238
|
+
.title = "A",
|
|
1239
|
+
.width = 320,
|
|
1240
|
+
.height = 240,
|
|
1241
|
+
.on_close = .a_closed,
|
|
1242
|
+
};
|
|
1243
|
+
count += 1;
|
|
1244
|
+
}
|
|
1245
|
+
if (model.b_open) {
|
|
1246
|
+
scratch.windows[count] = .{
|
|
1247
|
+
.label = "win-b",
|
|
1248
|
+
.canvas_label = "canvas-b",
|
|
1249
|
+
.title = "B",
|
|
1250
|
+
.width = 320,
|
|
1251
|
+
.height = 240,
|
|
1252
|
+
.on_close = .b_closed,
|
|
1253
|
+
};
|
|
1254
|
+
count += 1;
|
|
1255
|
+
}
|
|
1256
|
+
return scratch.windows[0..count];
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
fn menuWinWindowView(ui: *MenuWinApp.Ui, model: *const MenuWinModel, window_label: []const u8) MenuWinApp.Ui.Node {
|
|
1260
|
+
// The same address-stability slab as the main-canvas arena fixture:
|
|
1261
|
+
// if the pin regresses, the byte assertion fails deterministically
|
|
1262
|
+
// instead of reading whatever the reused chunk happens to hold.
|
|
1263
|
+
const slab = ui.arena.alloc(u8, 64 * 1024) catch @panic("arena slab");
|
|
1264
|
+
@memset(slab, '!');
|
|
1265
|
+
// Window labels share a length, so every window's payload is
|
|
1266
|
+
// same-sized and generation-stamped.
|
|
1267
|
+
const payload = ui.fmt("payload-{s}-{d:0>4}", .{ window_label, model.generation });
|
|
1268
|
+
return ui.column(.{ .gap = 8, .padding = 12 }, .{
|
|
1269
|
+
ui.el(.list_item, .{
|
|
1270
|
+
.text = "Row",
|
|
1271
|
+
.context_menu = &.{
|
|
1272
|
+
.{ .label = "Send", .msg = .{ .send = payload } },
|
|
1273
|
+
},
|
|
1274
|
+
}, .{}),
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
const MenuWinFixture = struct {
|
|
1279
|
+
harness: *core.TestHarness(),
|
|
1280
|
+
app_state: *MenuWinApp,
|
|
1281
|
+
app: core.App,
|
|
1282
|
+
|
|
1283
|
+
fn create() !MenuWinFixture {
|
|
1284
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
1285
|
+
errdefer harness.destroy(std.testing.allocator);
|
|
1286
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1287
|
+
const app_state = try MenuWinApp.create(std.testing.allocator, .{
|
|
1288
|
+
.name = "ui-app-menu-windows",
|
|
1289
|
+
.scene = panel_scene,
|
|
1290
|
+
.canvas_label = canvas_label,
|
|
1291
|
+
.update = menuWinUpdate,
|
|
1292
|
+
.view = menuWinView,
|
|
1293
|
+
.windows_fn = menuWinWindows,
|
|
1294
|
+
.window_view = menuWinWindowView,
|
|
1295
|
+
});
|
|
1296
|
+
errdefer app_state.destroy();
|
|
1297
|
+
const app = app_state.app();
|
|
1298
|
+
try harness.start(app);
|
|
1299
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
1300
|
+
.label = canvas_label,
|
|
1301
|
+
.size = geometry.SizeF.init(400, 300),
|
|
1302
|
+
.scale_factor = 2,
|
|
1303
|
+
.frame_index = 1,
|
|
1304
|
+
.timestamp_ns = 1_000_000,
|
|
1305
|
+
.nonblank = true,
|
|
1306
|
+
} });
|
|
1307
|
+
return .{ .harness = harness, .app_state = app_state, .app = app };
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
fn destroy(self: MenuWinFixture) void {
|
|
1311
|
+
self.app_state.destroy();
|
|
1312
|
+
self.harness.destroy(std.testing.allocator);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
fn windowInfo(self: MenuWinFixture, label: []const u8) ?support.platform.WindowInfo {
|
|
1316
|
+
var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
|
|
1317
|
+
for (self.harness.runtime.listWindows(&buffer)) |info| {
|
|
1318
|
+
if (std.mem.eql(u8, info.label, label)) return info;
|
|
1319
|
+
}
|
|
1320
|
+
return null;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
fn installCanvas(self: MenuWinFixture, window_id: support.platform.WindowId, label: []const u8, timestamp_ns: u64) !void {
|
|
1324
|
+
try self.harness.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_frame = .{
|
|
1325
|
+
.window_id = window_id,
|
|
1326
|
+
.label = label,
|
|
1327
|
+
.size = geometry.SizeF.init(320, 240),
|
|
1328
|
+
.scale_factor = 2,
|
|
1329
|
+
.frame_index = 1,
|
|
1330
|
+
.timestamp_ns = timestamp_ns,
|
|
1331
|
+
.nonblank = true,
|
|
1332
|
+
} });
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
/// A real secondary-button press on the window's "Row" item — the
|
|
1336
|
+
/// path that presents the row's native menu.
|
|
1337
|
+
fn rightClickRow(self: MenuWinFixture, window_id: support.platform.WindowId, label: []const u8, timestamp_ns: u64) !void {
|
|
1338
|
+
const layout = try self.harness.runtime.canvasWidgetLayout(window_id, label);
|
|
1339
|
+
const id = widgetIdByText(layout, .list_item, "Row") orelse return error.TestUnexpectedResult;
|
|
1340
|
+
var frame: geometry.RectF = .{};
|
|
1341
|
+
for (layout.nodes) |node| {
|
|
1342
|
+
if (node.widget.id == id) frame = node.frame;
|
|
1343
|
+
}
|
|
1344
|
+
try self.harness.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_input = .{
|
|
1345
|
+
.window_id = window_id,
|
|
1346
|
+
.label = label,
|
|
1347
|
+
.kind = .pointer_down,
|
|
1348
|
+
.button = 1,
|
|
1349
|
+
.x = frame.x + 4,
|
|
1350
|
+
.y = frame.y + 4,
|
|
1351
|
+
.timestamp_ns = timestamp_ns,
|
|
1352
|
+
} });
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/// Drive a main-canvas button through the real automation click.
|
|
1356
|
+
fn clickMainButton(self: MenuWinFixture, text: []const u8) !void {
|
|
1357
|
+
const layout = try self.harness.runtime.canvasWidgetLayout(1, canvas_label);
|
|
1358
|
+
const id = widgetIdByText(layout, .button, text) orelse return error.TestUnexpectedResult;
|
|
1359
|
+
var buffer: [96]u8 = undefined;
|
|
1360
|
+
const command = try std.fmt.bufPrint(&buffer, "widget-click {s} {d}", .{ canvas_label, id });
|
|
1361
|
+
try self.harness.runtime.dispatchAutomationCommand(self.app, command);
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
fn slotCanvasLabel(self: MenuWinFixture, index: usize) []const u8 {
|
|
1365
|
+
const slot = &self.app_state.window_slots[index];
|
|
1366
|
+
return slot.canvas_label_storage[0..slot.canvas_label_len];
|
|
1367
|
+
}
|
|
1368
|
+
};
|
|
1369
|
+
|
|
1370
|
+
test "the menu pin follows its window across slot compaction" {
|
|
1371
|
+
const fixture = try MenuWinFixture.create();
|
|
1372
|
+
defer fixture.destroy();
|
|
1373
|
+
try std.testing.expect(fixture.windowInfo("win-a") != null);
|
|
1374
|
+
const b_info = fixture.windowInfo("win-b") orelse return error.TestUnexpectedResult;
|
|
1375
|
+
try fixture.installCanvas(b_info.id, "canvas-b", 2_000_000);
|
|
1376
|
+
|
|
1377
|
+
// Present the menu from window B (slot index 1) and capture the
|
|
1378
|
+
// presented payload's address.
|
|
1379
|
+
try fixture.rightClickRow(b_info.id, "canvas-b", 3_000_000);
|
|
1380
|
+
try std.testing.expectEqual(@as(usize, 1), fixture.harness.null_platform.context_menu_request_count);
|
|
1381
|
+
const token = fixture.harness.null_platform.context_menu_token;
|
|
1382
|
+
const pin = fixture.app_state.context_menu_pin orelse return error.TestUnexpectedResult;
|
|
1383
|
+
try std.testing.expectEqual(b_info.id, pin.window_id.?);
|
|
1384
|
+
var presented_ptr: usize = 0;
|
|
1385
|
+
for (fixture.app_state.window_slots[0..fixture.app_state.window_slot_count]) |*slot| {
|
|
1386
|
+
if (!std.mem.eql(u8, slot.canvas_label_storage[0..slot.canvas_label_len], "canvas-b")) continue;
|
|
1387
|
+
const layout = try fixture.harness.runtime.canvasWidgetLayout(b_info.id, "canvas-b");
|
|
1388
|
+
const row_id = widgetIdByText(layout, .list_item, "Row") orelse return error.TestUnexpectedResult;
|
|
1389
|
+
const msg = slot.tree.?.msgForContextMenu(row_id, 0) orelse return error.TestUnexpectedResult;
|
|
1390
|
+
presented_ptr = @intFromPtr(msg.send.ptr);
|
|
1391
|
+
}
|
|
1392
|
+
try std.testing.expect(presented_ptr != 0);
|
|
1393
|
+
|
|
1394
|
+
// Close window A: the slot bookkeeping swap-moves B's slot into
|
|
1395
|
+
// A's index while B's menu is still on the glass. The pin is keyed
|
|
1396
|
+
// by window identity, so it moves with the slot.
|
|
1397
|
+
try fixture.clickMainButton("Close A");
|
|
1398
|
+
try std.testing.expect(!fixture.app_state.model.a_open);
|
|
1399
|
+
const closed = fixture.windowInfo("win-a");
|
|
1400
|
+
try std.testing.expect(closed == null or !closed.?.open);
|
|
1401
|
+
try std.testing.expectEqual(@as(usize, 1), fixture.app_state.window_slot_count);
|
|
1402
|
+
try std.testing.expectEqualStrings("canvas-b", fixture.slotCanvasLabel(0));
|
|
1403
|
+
try std.testing.expect(fixture.app_state.context_menu_pin != null);
|
|
1404
|
+
|
|
1405
|
+
// Rebuild twice under the open menu (the arena-pair race), then
|
|
1406
|
+
// select: the dispatched Msg is the ORIGINAL presented value.
|
|
1407
|
+
try fixture.clickMainButton("Rebuild");
|
|
1408
|
+
try fixture.clickMainButton("Rebuild");
|
|
1409
|
+
try std.testing.expectEqual(@as(u32, 2), fixture.app_state.model.generation);
|
|
1410
|
+
try fixture.harness.runtime.dispatchPlatformEvent(fixture.app, .{ .context_menu_action = .{
|
|
1411
|
+
.window_id = b_info.id,
|
|
1412
|
+
.view_label = "canvas-b",
|
|
1413
|
+
.token = token,
|
|
1414
|
+
.item_id = 1,
|
|
1415
|
+
} });
|
|
1416
|
+
try std.testing.expectEqual(@as(u32, 1), fixture.app_state.model.sends);
|
|
1417
|
+
try std.testing.expectEqualStrings("payload-win-b-0000", fixture.app_state.model.received_storage[0..fixture.app_state.model.received_len]);
|
|
1418
|
+
try std.testing.expectEqual(presented_ptr, fixture.app_state.model.received_ptr);
|
|
1419
|
+
try std.testing.expect(fixture.app_state.context_menu_pin == null);
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
test "closing the pin-owning window releases its snapshot and pin" {
|
|
1423
|
+
const fixture = try MenuWinFixture.create();
|
|
1424
|
+
defer fixture.destroy();
|
|
1425
|
+
const a_info = fixture.windowInfo("win-a") orelse return error.TestUnexpectedResult;
|
|
1426
|
+
try fixture.installCanvas(a_info.id, "canvas-a", 2_000_000);
|
|
1427
|
+
|
|
1428
|
+
try fixture.rightClickRow(a_info.id, "canvas-a", 3_000_000);
|
|
1429
|
+
const token = fixture.harness.null_platform.context_menu_token;
|
|
1430
|
+
try std.testing.expect(fixture.app_state.context_menu_pin != null);
|
|
1431
|
+
try std.testing.expect(fixture.app_state.context_menu_shown_token != 0);
|
|
1432
|
+
|
|
1433
|
+
// The model stops declaring window A while its menu is open: the
|
|
1434
|
+
// reconcile close deinits the slot's arenas, so the snapshot and
|
|
1435
|
+
// pin presented from it must release NOW — a stale pin would keep
|
|
1436
|
+
// steering the reused slot's rebuild cadence around a generation
|
|
1437
|
+
// that no longer exists.
|
|
1438
|
+
try fixture.clickMainButton("Close A");
|
|
1439
|
+
try std.testing.expect(!fixture.app_state.model.a_open);
|
|
1440
|
+
const closed = fixture.windowInfo("win-a");
|
|
1441
|
+
try std.testing.expect(closed == null or !closed.?.open);
|
|
1442
|
+
try std.testing.expect(fixture.app_state.context_menu_pin == null);
|
|
1443
|
+
try std.testing.expectEqual(@as(u64, 0), fixture.app_state.context_menu_shown_token);
|
|
1444
|
+
|
|
1445
|
+
// The dead window's selection dispatches nothing.
|
|
1446
|
+
try fixture.harness.runtime.dispatchPlatformEvent(fixture.app, .{ .context_menu_action = .{
|
|
1447
|
+
.window_id = a_info.id,
|
|
1448
|
+
.view_label = "canvas-a",
|
|
1449
|
+
.token = token,
|
|
1450
|
+
.item_id = 1,
|
|
1451
|
+
} });
|
|
1452
|
+
try std.testing.expectEqual(@as(u32, 0), fixture.app_state.model.sends);
|
|
717
1453
|
}
|