M7: test platform — Platform traits, Application, TestPlatform, VisualTestContext #7

Merged
nandi merged 1 commits from feat/test-platform into feat/window 2026-11-24 23:54:56 +00:00
Owner

Stacked on #6 (base feat/window); the diff shows only M7. Retarget to main once #6 is merged.

Why

Before adding the browser platform and Canvas2D renderer in M8, window needs a backend-neutral Platform / PlatformWindow boundary and a deterministic headless test harness mirroring GPUI's TestPlatform, TestAppContext, and VisualTestContext. This lets views, elements, async timers, input dispatch, and window lifecycle be tested end-to-end across all four MoonBit backends without a browser or GPU.

What's here

  • input: MouseExitEvent, ModifiersChangedEvent, PlatformInput, DispatchEventResult, and mouse/platform-input helpers.
  • platform: core Platform and PlatformWindow traits plus WindowId, WindowBounds, WindowOptions, WindowParams, and text-subset ClipboardItem / ClipboardEntry / ClipboardString.
  • window:
    • Application, application_for, AnyWindowHandle, and WindowHandle[V] connecting App, Platform, and open windows while keeping app free of platform/rendering dependencies.
    • Window::from_platform wiring frame requests, input, resize/scale-factor changes, active/hover status, on_should_close, and on_close callbacks (while keeping standalone Window::new backwards-compatible).
    • Window::dispatch_input, prevent_default, replace_root_view, clipboard/cursor/title/activation methods, and automatic root-view release on Window::close (Design Decision 1).
    • Hitbox hit-testing moved between Prepaint and Paint (matching GPUI) and gated on pointer containment so MouseExited and on_hover_status_change(false) clear hover cleanly.
  • platform/test:
    • TestPlatform and TestWindow recording every presented Scene and providing simulation hooks for frames, input, resize, scale factor, active/hover status, and close requests.
    • TestAppContext and VisualTestContext pumping TestDispatcher tasks and scheduled frames together (run_until_parked, advance_clock, add_window_view, simulate_*), with a 100-pass runaway-redraw guard.
  • Example & docs: src/examples/card now runs through TestAppContext / VisualTestContext; docs/PORTING.md and README.md document M7 status, deviations, and toolchain notes.

Deviations

Recorded in docs/PORTING.md:

  • Platform and PlatformWindow cover the core subset (text system, glyph atlas, IME, menus, and displays arrive in M9/M10).
  • Added explicit PlatformWindow::close for app-driven teardown (no Drop in MoonBit); closing a window releases its root view.
  • TestWindow defaults to scale_factor = 1.0 (matching M6 Window::new; configurable via TestPlatform::new or WindowOptions).
  • Application lives in window and is looked up via a private GlobalKey (application_for).

Testing

  • moon check --target all passes with zero warnings or errors.
  • moon test --target all passes 157/157 tests on wasm, wasm-gc, js, and native, including:
    • platform type/clipboard unit tests.
    • platform/test unit tests covering explicit frame scheduling, resize/scale-factor changes without recursion, title/cursor/clipboard/open_url, multi-window activation, MouseExited/ModifiersChanged/DispatchEventResult, on_should_close veto and root-view release on close, async virtual-clock redraws, replace_root_view, skip_drawing, and three panic-on-misuse tests (drawing/dispatching on closed windows, runaway redraw loop).
    • elements/visual_test.mbt integration tests for div(), canvas(), hover, clicks, resize/2x, async ticker redraws, and close release via VisualTestContext.
  • moon run src/examples/card --target js prints the expected 3-frame card report.
Stacked on #6 (base `feat/window`); the diff shows only M7. Retarget to `main` once #6 is merged. ## Why Before adding the browser platform and Canvas2D renderer in M8, `window` needs a backend-neutral `Platform` / `PlatformWindow` boundary and a deterministic headless test harness mirroring GPUI's `TestPlatform`, `TestAppContext`, and `VisualTestContext`. This lets views, elements, async timers, input dispatch, and window lifecycle be tested end-to-end across all four MoonBit backends without a browser or GPU. ## What's here - **`input`**: `MouseExitEvent`, `ModifiersChangedEvent`, `PlatformInput`, `DispatchEventResult`, and mouse/platform-input helpers. - **`platform`**: core `Platform` and `PlatformWindow` traits plus `WindowId`, `WindowBounds`, `WindowOptions`, `WindowParams`, and text-subset `ClipboardItem` / `ClipboardEntry` / `ClipboardString`. - **`window`**: - `Application`, `application_for`, `AnyWindowHandle`, and `WindowHandle[V]` connecting `App`, `Platform`, and open windows while keeping `app` free of platform/rendering dependencies. - `Window::from_platform` wiring frame requests, input, resize/scale-factor changes, active/hover status, `on_should_close`, and `on_close` callbacks (while keeping standalone `Window::new` backwards-compatible). - `Window::dispatch_input`, `prevent_default`, `replace_root_view`, clipboard/cursor/title/activation methods, and automatic root-view release on `Window::close` (Design Decision 1). - Hitbox hit-testing moved between `Prepaint` and `Paint` (matching GPUI) and gated on pointer containment so `MouseExited` and `on_hover_status_change(false)` clear hover cleanly. - **`platform/test`**: - `TestPlatform` and `TestWindow` recording every presented `Scene` and providing simulation hooks for frames, input, resize, scale factor, active/hover status, and close requests. - `TestAppContext` and `VisualTestContext` pumping `TestDispatcher` tasks and scheduled frames together (`run_until_parked`, `advance_clock`, `add_window_view`, `simulate_*`), with a 100-pass runaway-redraw guard. - **Example & docs**: `src/examples/card` now runs through `TestAppContext` / `VisualTestContext`; `docs/PORTING.md` and `README.md` document M7 status, deviations, and toolchain notes. ## Deviations Recorded in `docs/PORTING.md`: - `Platform` and `PlatformWindow` cover the core subset (text system, glyph atlas, IME, menus, and displays arrive in M9/M10). - Added explicit `PlatformWindow::close` for app-driven teardown (no `Drop` in MoonBit); closing a window releases its root view. - `TestWindow` defaults to `scale_factor = 1.0` (matching M6 `Window::new`; configurable via `TestPlatform::new` or `WindowOptions`). - `Application` lives in `window` and is looked up via a private `GlobalKey` (`application_for`). ## Testing - `moon check --target all` passes with zero warnings or errors. - `moon test --target all` passes 157/157 tests on `wasm`, `wasm-gc`, `js`, and `native`, including: - `platform` type/clipboard unit tests. - `platform/test` unit tests covering explicit frame scheduling, resize/scale-factor changes without recursion, title/cursor/clipboard/`open_url`, multi-window activation, `MouseExited`/`ModifiersChanged`/`DispatchEventResult`, `on_should_close` veto and root-view release on close, async virtual-clock redraws, `replace_root_view`, `skip_drawing`, and three panic-on-misuse tests (drawing/dispatching on closed windows, runaway redraw loop). - `elements/visual_test.mbt` integration tests for `div()`, `canvas()`, hover, clicks, resize/2x, async ticker redraws, and close release via `VisualTestContext`. - `moon run src/examples/card --target js` prints the expected 3-frame card report.
nandi added 1 commit 2026-11-24 23:53:09 +00:00
- input: MouseExitEvent, ModifiersChangedEvent, PlatformInput, and
  DispatchEventResult.
- platform: core Platform and PlatformWindow traits plus WindowId,
  WindowBounds, WindowOptions, WindowParams, and ClipboardItem.
- window: Application, AnyWindowHandle, WindowHandle[V],
  Window::from_platform, dispatch_input, prevent_default, close/activation
  hooks, and replace_root_view while keeping standalone Window::new;
  closing a window releases its root view; hit-testing runs between
  prepaint and paint gated by pointer containment.
- platform/test: TestPlatform, TestWindow (recording Scenes and simulating
  frames, input, resize, scale factor, active/hover status, and close),
  TestAppContext, and VisualTestContext with automatic frame pumping and
  a runaway-redraw guard.
- Tests & example: platform tests, TestPlatform/VisualTestContext unit and
  panic-on-misuse tests, elements visual integration tests, and
  src/examples/card updated to run on TestAppContext/VisualTestContext.
- Docs: updated docs/PORTING.md and README.md.
nandi merged commit 73c67825b2 into feat/window 2026-11-24 23:54:56 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: experiments/moon-gpui#7