Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
Expand iframe and scrollbar input coverage
ldm04f39a0f0d980
diff --git a/moli-cdp-smoke/README.md b/moli-cdp-smoke/README.mdindex 228c94e39..6029462b4 100644--- a/moli-cdp-smoke/README.md+++ b/moli-cdp-smoke/README.md@@ -167,6 +167,9 @@ Covered well:- Chromium-derived proxy authentication coverage uses a real local proxy and per-browser-context proxy configuration. HTTP Basic authentication must expose the initial unauthenticated target request headers and final `200` response through ExtraInfo without leaking `Proxy-Authorization`; an HTTPS `CONNECT` challenge canceled through Fetch must expose proxy origin, a `407` response with `hasExtraInfo=false`, and `Network.loadingFailed` without treating CONNECT headers as target-request ExtraInfo.- Parser-discovered external script, link stylesheet, and parser-created `@import` stylesheet observation plus `Network.getResponseBody`; configured `20,000,000 / 2,000,000` inspector-cache budgets retain a small body while a `2,000,001`-byte body keeps its request identity and repeatedly returns the inspector-cache eviction error.- Classic WebSocket echo, WebSocket `Network.webSocket*` events, and blocked WebSocket handshake behavior.+- Chromium-calibrated transformed-iframe input routing through raw CDP: exact+ used child viewport, hover/click/wheel targets and child-local coordinates,+ overflow-container scrolling, and cross-frame mouseout coordinates.- Dedicated default `Page.setDocumentContent` replacement coverage throughPlaywright and raw CDP: exact-once, ordered document-open/DOM/load projectionto two attached sessions while one session has a pending Runtime command;@@ -258,6 +261,9 @@ Runner layout:- `groups/network.py`: document/fetch/XHR routing, Network event observation, parser script and stylesheet body capture, WebSocket, and downloads.- `groups/workers.py`: dedicated worker `postMessage`, SharedWorker port reuse, worker fetch routing/auth, and worker XHR routing.- `groups/dom_input.py`: `set_content`, file upload, file chooser, scripted picker, click navigation, locator/input workflows, Playwright upstream derived locator composition, `page.type()`, layout-backed mouse/touch/tap/raw-drag input, `fill()`, `check()` / `uncheck()` / `setChecked()`, and `selectOption()` workflows, DOM/handle workflows, plus the explicit high-level drag-interception boundary.+- `groups/iframe_input.py`: a Chromium-calibrated raw-CDP regression for+ transformed iframe hover, click, wheel, child-local event coordinates, and+ exact used frame viewport propagation.- `groups/emulation_storage.py`: viewport and Playwright screenshot-clip boundary, storage/cookie isolation, IndexedDB baseline, and browser-context profile overrides.- `groups/browser_semantics.py`: raw-target and page/runtime cross-enginecontracts calibrated against Chromium before they are applied to Moli.diff --git a/moli-cdp-smoke/moli_cdp_smoke/groups/classic_scrollbar.py b/moli-cdp-smoke/moli_cdp_smoke/groups/classic_scrollbar.pyindex aa7509928..74f1d06d6 100644--- a/moli-cdp-smoke/moli_cdp_smoke/groups/classic_scrollbar.py+++ b/moli-cdp-smoke/moli_cdp_smoke/groups/classic_scrollbar.py@@ -176,9 +176,208 @@ async def run_classic_scrollbar_group(state: SmokeState) -> None:"cdpNativeDrag": is_moli,},)+ await _run_multi_scroller_drag_workflow(state, is_moli)await _run_root_scrollbar_workflow(state, is_moli)+async def _run_multi_scroller_drag_workflow(state: SmokeState, is_moli: bool) -> None:+ page = state.page+ cdp = state.cdp+ await page.set_viewport_size({"width": 800, "height": 600})+ await page.set_content(+ """+ <!doctype html>+ <style>+ html, body { margin: 0; overflow: hidden; }+ #outer {+ position: absolute; left: 20px; top: 20px;+ width: 280px; height: 200px; overflow: auto;+ }+ #outer-content { position: relative; width: 620px; height: 500px; }+ #inner {+ position: absolute; left: 30px; top: 30px;+ width: 180px; height: 120px; overflow: auto;+ }+ .large { width: 420px; height: 320px; }+ #sibling {+ position: absolute; left: 340px; top: 20px;+ width: 180px; height: 120px; overflow: auto;+ }+ #horizontal {+ position: absolute; left: 340px; top: 180px;+ width: 220px; height: 100px; overflow: auto;+ }+ #horizontal > div { width: 600px; height: 60px; }+ #thin-child {+ position: absolute; left: 600px; top: 20px;+ width: 160px; height: 120px; overflow: auto; scrollbar-width: thin;+ }+ #rtl-child {+ position: absolute; left: 600px; top: 180px;+ width: 160px; height: 120px; overflow: auto; direction: rtl;+ }+ </style>+ <div id="outer">+ <div id="outer-content">+ <div id="inner"><div class="large"></div></div>+ </div>+ </div>+ <div id="sibling"><div class="large"></div></div>+ <div id="horizontal"><div></div></div>+ <div id="thin-child"><div style="width:400px;height:320px"></div></div>+ <div id="rtl-child"><div style="width:400px;height:320px"></div></div>+ <script>+ window.__multiScrollbarDomEvents = [];+ for (const name of [+ "pointerdown", "pointermove", "pointerup",+ "mousedown", "mousemove", "mouseup", "click"+ ]) {+ document.addEventListener(name, () => __multiScrollbarDomEvents.push(name), true);+ }+ </script>+ """,+ wait_until="domcontentloaded",+ )+ metrics = await page.evaluate(+ """() => {+ const outer = document.getElementById("outer");+ const inner = document.getElementById("inner");+ const sibling = document.getElementById("sibling");+ const horizontal = document.getElementById("horizontal");+ const thin = document.getElementById("thin-child");+ const rtl = document.getElementById("rtl-child");+ return [+ outer.clientWidth, outer.clientHeight, outer.scrollWidth, outer.scrollHeight,+ inner.clientWidth, inner.clientHeight, inner.scrollWidth, inner.scrollHeight,+ sibling.clientWidth, sibling.clientHeight,+ horizontal.clientWidth, horizontal.clientHeight,+ horizontal.scrollWidth, horizontal.scrollHeight,+ thin.clientWidth, thin.clientHeight,+ rtl.clientWidth, rtl.clientHeight, rtl.clientLeft, rtl.scrollLeft,+ ];+ }"""+ )+ assert_equal(+ metrics,+ [+ 265, 185, 620, 500, 165, 105, 420, 320, 165, 105,+ 220, 85, 600, 85, 150, 110, 145, 105, 15, 0,+ ],+ "nested and sibling classic scrollbar geometry",+ )++ scroll = None+ if is_moli:+ async def mouse(event_type: str, x: int, y: int, *, pressed: bool) -> None:+ await cdp.send(+ "Input.dispatchMouseEvent",+ {+ "type": event_type,+ "x": x,+ "y": y,+ "button": "left" if event_type != "mouseMoved" else "none",+ "buttons": 1 if pressed else 0,+ "clickCount": 1,+ },+ )++ # Release over a sibling scrollbar: capture must remain on the inner+ # thumb until mouseReleased and must not leak input into either DOM.+ await mouse("mousePressed", 225, 75, pressed=True)+ await mouse("mouseMoved", 515, 115, pressed=True)+ await mouse("mouseReleased", 515, 115, pressed=False)+ first_drag = await page.evaluate(+ """() => [+ document.getElementById("inner").scrollTop,+ document.getElementById("outer").scrollTop,+ document.getElementById("sibling").scrollTop,+ ]"""+ )+ if first_drag[0] <= 180 or first_drag[1:] != [0, 0]:+ raise SmokeError(f"nested scrollbar capture retargeted unexpectedly: {first_drag!r}")++ await mouse("mousePressed", 515, 45, pressed=True)+ await mouse("mouseMoved", 515, 85, pressed=True)+ await mouse("mouseReleased", 515, 85, pressed=False)+ await mouse("mousePressed", 370, 275, pressed=True)+ await mouse("mouseMoved", 450, 275, pressed=True)+ await mouse("mouseReleased", 450, 275, pressed=False)++ await mouse("mousePressed", 755, 45, pressed=True)+ await mouse("mouseMoved", 755, 75, pressed=True)+ await mouse("mouseReleased", 755, 75, pressed=False)+ await mouse("mousePressed", 630, 135, pressed=True)+ await mouse("mouseMoved", 690, 135, pressed=True)+ await mouse("mouseReleased", 690, 135, pressed=False)++ await mouse("mousePressed", 607, 205, pressed=True)+ await mouse("mouseMoved", 607, 235, pressed=True)+ await mouse("mouseReleased", 607, 235, pressed=False)+ await mouse("mousePressed", 720, 292, pressed=True)+ await mouse("mouseMoved", 660, 292, pressed=True)+ await mouse("mouseReleased", 660, 292, pressed=False)++ await page.evaluate(+ """() => {+ document.getElementById("outer").scrollTop = 50;+ document.getElementById("inner").scrollTop = 0;+ }"""+ )+ await mouse("mousePressed", 225, 25, pressed=True)+ await mouse("mouseMoved", 700, 45, pressed=True)+ await mouse("mouseReleased", 700, 45, pressed=False)+ await mouse("mousePressed", 295, 65, pressed=True)+ await mouse("mouseMoved", 295, 125, pressed=True)+ await mouse("mouseReleased", 295, 125, pressed=False)++ state_after = await page.evaluate(+ """() => ({+ outer: document.getElementById("outer").scrollTop,+ inner: document.getElementById("inner").scrollTop,+ sibling: document.getElementById("sibling").scrollTop,+ horizontal: document.getElementById("horizontal").scrollLeft,+ thinLeft: document.getElementById("thin-child").scrollLeft,+ thinTop: document.getElementById("thin-child").scrollTop,+ rtlLeft: document.getElementById("rtl-child").scrollLeft,+ rtlTop: document.getElementById("rtl-child").scrollTop,+ events: __multiScrollbarDomEvents,+ })"""+ )+ if (+ state_after["outer"] <= 200+ or state_after["inner"] <= 90+ or state_after["sibling"] <= 180+ or state_after["horizontal"] <= 250+ or state_after["thinLeft"] <= 180+ or state_after["thinTop"] <= 100+ or state_after["rtlLeft"] >= -180+ or state_after["rtlTop"] <= 130+ ):+ raise SmokeError(f"multi-scroller thumb drag matrix diverged: {state_after!r}")+ assert_equal(+ state_after["events"],+ [],+ "captured nested and sibling scrollbars stay outside DOM dispatch",+ )+ scroll = {+ key: state_after[key]+ for key in (+ "outer", "inner", "sibling", "horizontal",+ "thinLeft", "thinTop", "rtlLeft", "rtlTop",+ )+ }++ state.record(+ "nested_sibling_and_horizontal_scrollbar_drag_matrix",+ {+ "engine": "moli" if is_moli else "chromium",+ "metrics": metrics,+ "scroll": scroll,+ "cdpNativeDrag": is_moli,+ },+ )++async def _run_root_scrollbar_workflow(state: SmokeState, is_moli: bool) -> None:page = state.pagecdp = state.cdpdiff --git a/moli-cdp-smoke/moli_cdp_smoke/groups/iframe_input.py b/moli-cdp-smoke/moli_cdp_smoke/groups/iframe_input.pynew file mode 100644index 000000000..0bbba0dcc--- /dev/null+++ b/moli-cdp-smoke/moli_cdp_smoke/groups/iframe_input.py@@ -0,0 +1,292 @@+from __future__ import annotations++from . import SmokeState+from ..assertions import SmokeError, assert_equal, wait_until+++def _assert_close(actual: object, expected: float, label: str, tolerance: float = 0.15) -> None:+ if not isinstance(actual, (int, float)) or abs(float(actual) - expected) > tolerance:+ raise SmokeError(+ f"{label}: expected {expected!r} ± {tolerance}, got {actual!r}"+ )+++async def run_iframe_input_group(state: SmokeState) -> None:+ page = state.page+ cdp = state.cdp+ await page.set_viewport_size({"width": 1200, "height": 800})+ await page.set_content(+ """+ <!doctype html>+ <style>+ html, body { margin: 0; padding: 0; min-height: 1400px; }+ #outside {+ position: fixed; left: 0; top: 0; width: 30px; height: 30px;+ }+ #clip {+ position: absolute; left: 100px; top: 120px;+ width: 720px; height: 500px; overflow: hidden;+ }+ #input-frame {+ display: block;+ width: calc(100% / .78);+ height: calc(500px / .78);+ margin: 0; border: 0; padding: 0;+ transform: scale(.78);+ transform-origin: 0 0;+ }+ </style>+ <div id="outside"></div>+ <div id="clip"><iframe id="input-frame"></iframe></div>+ <script>+ const frame = document.getElementById("input-frame");+ const child = frame.contentDocument;+ child.documentElement.style.cssText = "margin:0;padding:0";+ child.body.style.cssText = "margin:0;padding:0";+ const style = child.createElement("style");+ style.textContent = `+ #hover-target {+ position: fixed; left: 220px; top: 50px;+ width: 40px; height: 80px; background: red;+ margin: 0; border: 0; padding: 0;+ }+ #hover-target:hover { background: lime; }+ #wheel-target {+ position: fixed; left: 500px; top: 180px;+ width: 120px; height: 120px; overflow: auto;+ }+ #wheel-content { width: 100px; height: 900px; }+ `;+ child.head.appendChild(style);+ child.body.innerHTML = `+ <button id="hover-target">Run</button>+ <div id="wheel-target"><div id="wheel-content"></div></div>+ `;+ frame.contentWindow.__inputEvents = [];+ for (const type of [+ "pointerover", "pointerout", "mouseover", "mouseout",+ "mousemove", "mousedown", "mouseup", "click", "focus", "wheel"+ ]) {+ child.addEventListener(type, event => {+ frame.contentWindow.__inputEvents.push({+ type,+ target: event.target.id,+ clientX: event.clientX,+ clientY: event.clientY,+ deltaY: event.deltaY || 0,+ });+ }, true);+ }+ </script>+ """,+ wait_until="domcontentloaded",+ )++ geometry = await page.evaluate(+ """() => {+ const frame = document.getElementById("input-frame");+ const rect = frame.getBoundingClientRect();+ return {+ offset: [frame.offsetWidth, frame.offsetHeight],+ rect: [rect.left, rect.top, rect.width, rect.height],+ childViewport: [frame.contentWindow.innerWidth, frame.contentWindow.innerHeight],+ };+ }"""+ )+ assert_equal(geometry["offset"], [923, 641], "transformed iframe used size")+ assert_equal(+ geometry["childViewport"],+ [923, 641],+ "child LocalFrameView uses the iframe's exact content viewport",+ )+ for actual, expected, label in zip(+ geometry["rect"],+ [100.0, 120.0, 719.94, 499.98],+ ["left", "top", "width", "height"],+ ):+ _assert_close(actual, expected, f"transformed iframe visual {label}")++ async def mouse(+ event_type: str,+ x: float,+ y: float,+ *,+ button: str = "none",+ buttons: int = 0,+ delta_y: float | None = None,+ ) -> None:+ params: dict[str, object] = {+ "type": event_type,+ "x": x,+ "y": y,+ "button": button,+ "buttons": buttons,+ "clickCount": 1,+ }+ if delta_y is not None:+ params.update({"deltaX": 0, "deltaY": delta_y})+ await cdp.send("Input.dispatchMouseEvent", params)++ # Child point (240, 90), the visible target center, maps through .78 to+ # root point (287.2, 190.2).+ await mouse("mouseMoved", 287.2, 190.2)+ hover_probe = await page.evaluate(+ """() => {+ const child = document.getElementById("input-frame").contentDocument;+ return {+ hovered: child.getElementById("hover-target").matches(":hover"),+ events: document.getElementById("input-frame").contentWindow.__inputEvents,+ childHit: child.elementFromPoint(240, 90)?.id || null,+ };+ }"""+ )+ assert_equal(hover_probe["childHit"], "hover-target", "child target fixture hit")+ hover_event = next(+ (+ event+ for event in hover_probe["events"]+ if event["type"] == "mouseover" and event["target"] == "hover-target"+ ),+ None,+ )+ if hover_event is None:+ raise SmokeError(f"transformed iframe hover target was missed: {hover_probe!r}")+ await mouse("mousePressed", 287.2, 190.2, button="left", buttons=1)+ await mouse("mouseReleased", 287.2, 190.2, button="left", buttons=0)++ # Child point (560, 240) lies in the nested overflow element.+ await mouse("mouseWheel", 536.8, 307.2, delta_y=120)++ async def wheel_applied() -> bool:+ return bool(+ await page.evaluate(+ """() =>+ document.getElementById("input-frame").contentDocument+ .getElementById("wheel-target").scrollTop === 120"""+ )+ )++ await wait_until(wheel_applied, "transformed iframe wheel action", timeout_ms=3_000)+ before_exit = await page.evaluate(+ """() => {+ const frame = document.getElementById("input-frame");+ const child = frame.contentDocument;+ return {+ wheelTop: child.getElementById("wheel-target").scrollTop,+ rootTop: document.scrollingElement.scrollTop,+ events: frame.contentWindow.__inputEvents,+ };+ }"""+ )+ assert_equal(before_exit["wheelTop"], 120, "child overflow scrollTop")+ assert_equal(before_exit["rootTop"], 0, "top document remains unscrolled")++ events = before_exit["events"]+ for event_type in ["mousemove", "mousedown", "mouseup", "click"]:+ event = next(+ (+ candidate+ for candidate in events+ if candidate["type"] == event_type+ and candidate["target"] == "hover-target"+ ),+ None,+ )+ if event is None:+ raise SmokeError(f"missing child {event_type} event: {events!r}")+ _assert_close(event["clientX"], 240.0, f"child {event_type}.clientX")+ _assert_close(event["clientY"], 90.0, f"child {event_type}.clientY")+ wheel = next((event for event in events if event["type"] == "wheel"), None)+ if wheel is None:+ raise SmokeError(f"missing child wheel event: {events!r}")+ assert_equal(wheel["target"], "wheel-content", "child wheel target")+ _assert_close(wheel["clientX"], 560.0, "child wheel.clientX")+ _assert_close(wheel["clientY"], 240.0, "child wheel.clientY")++ await mouse("mouseMoved", 10.0, 10.0)+ mouseout = await page.evaluate(+ """() => {+ const events = document.getElementById("input-frame").contentWindow.__inputEvents;+ return [...events].reverse().find(event => event.type === "mouseout") || null;+ }"""+ )+ if mouseout is None:+ raise SmokeError("moving from the child frame did not dispatch mouseout")+ assert_equal(mouseout["target"], "hover-target", "child mouseout target")+ # Chromium rounds cross-frame boundary-event coordinates to integral CSS+ # pixels; Moli retains the subpixel affine result.+ _assert_close(mouseout["clientX"], -115.3846, "child mouseout.clientX", 1.1)+ _assert_close(mouseout["clientY"], -141.0256, "child mouseout.clientY", 1.1)++ # Put the same transformed iframe partly below the top viewport. Its+ # button remains visible, so focusing the button must bubble that button's+ # rect to the parent rather than scrolling the entire iframe into view.+ await page.evaluate(+ """() => {+ const clip = document.getElementById("clip");+ const frame = document.getElementById("input-frame");+ clip.style.top = "400px";+ frame.contentWindow.__inputEvents = [];+ window.scrollTo(0, 0);+ }"""+ )++ async def frame_repositioned() -> bool:+ top = await page.evaluate(+ """() => document.getElementById("input-frame")+ .getBoundingClientRect().top"""+ )+ return isinstance(top, (int, float)) and abs(float(top) - 400.0) < 0.15++ await wait_until(frame_repositioned, "partially hidden iframe layout", timeout_ms=3_000)+ await mouse("mouseMoved", 287.2, 470.2)+ await mouse("mousePressed", 287.2, 470.2, button="left", buttons=1)+ scroll_after_press = await page.evaluate("() => window.scrollY")+ assert_equal(+ scroll_after_press,+ 0,+ "focusing a visible child target does not scroll the whole iframe",+ )+ await mouse("mouseReleased", 287.2, 470.2, button="left", buttons=0)+ focus_probe = await page.evaluate(+ """() => {+ const frame = document.getElementById("input-frame");+ const child = frame.contentDocument;+ return {+ rootTop: window.scrollY,+ parentActive: document.activeElement === frame,+ childActive: child.activeElement === child.getElementById("hover-target"),+ events: frame.contentWindow.__inputEvents,+ };+ }"""+ )+ assert_equal(focus_probe["rootTop"], 0, "top document stays still through release")+ assert_equal(focus_probe["parentActive"], True, "parent active element is iframe")+ assert_equal(focus_probe["childActive"], True, "child button keeps focus")+ for event_type in ["mousedown", "mouseup", "click"]:+ event = next(+ (+ candidate+ for candidate in focus_probe["events"]+ if candidate["type"] == event_type+ and candidate["target"] == "hover-target"+ ),+ None,+ )+ if event is None:+ raise SmokeError(+ f"missing stable child {event_type} after focus: {focus_probe!r}"+ )+ _assert_close(event["clientX"], 240.0, f"focused child {event_type}.clientX")+ _assert_close(event["clientY"], 90.0, f"focused child {event_type}.clientY")++ state.record(+ "transformed_iframe_hover_click_wheel_coordinates",+ {+ "methods": ["Input.dispatchMouseEvent", "Runtime.evaluate"],+ "geometry": geometry,+ "wheelTop": before_exit["wheelTop"],+ "mouseout": mouseout,+ "focusWithoutParentScroll": focus_probe,+ },+ )diff --git a/moli-cdp-smoke/moli_cdp_smoke/runner.py b/moli-cdp-smoke/moli_cdp_smoke/runner.pyindex 29c65fd26..0cd7a1abe 100644--- a/moli-cdp-smoke/moli_cdp_smoke/runner.py+++ b/moli-cdp-smoke/moli_cdp_smoke/runner.py@@ -37,6 +37,7 @@ from .groups.emulation_storage import run_emulation_storage_groupfrom .groups.error_document import run_error_document_groupfrom .groups.fetch_runtime_teardown import run_fetch_runtime_teardown_groupfrom .groups.inspector_routing import run_inspector_routing_group+from .groups.iframe_input import run_iframe_input_groupfrom .groups.layout_screenshot import run_layout_screenshot_groupfrom .groups.multi_client import run_multi_client_groupfrom .groups.multi_context import run_multi_context_group@@ -156,6 +157,12 @@ RAW_GROUPS: tuple[SmokeGroup, ...] = ()PAGE_GROUPS: tuple[SmokeGroup, ...] = (+ SmokeGroup(+ "iframe-input",+ "Cross-engine transformed iframe hover, click, wheel, and target-Document coordinate routing.",+ "page",+ run_iframe_input_group,+ ),SmokeGroup("classic-scrollbar","Cross-engine classic scrollbar layout, paint, and raw CDP thumb dragging.",diff --git a/moli-layout/tests/phase5_output_contract.rs b/moli-layout/tests/phase5_output_contract.rsindex af26d4b45..57fcd8fb8 100644--- a/moli-layout/tests/phase5_output_contract.rs+++ b/moli-layout/tests/phase5_output_contract.rs@@ -1356,6 +1356,76 @@ fn transforms_and_semantic_paint_order_share_the_hit_test_projection() {);}+#[test]+fn transformed_hit_retains_exact_local_content_box_and_inverse_mapping() {+ let source = Source(vec![+ Node::element("root", vec![1]),+ Node::element("embedded-content", Vec::new()),+ ]);+ let mut styles = Styles::default();+ styles.0.insert(+ 0,+ fixed_size(LayoutDisplay::Block, 320.0, 240.0)+ .with_position(moli_layout::LayoutPosition::Relative),+ );+ styles.0.insert(+ 1,+ resolved(+ LayoutDisplay::Block,+ Style {+ box_sizing: BoxSizing::ContentBox,+ position: Position::Absolute,+ inset: Rect {+ left: length(20.0),+ right: LengthPercentageAuto::auto(),+ top: length(30.0),+ bottom: LengthPercentageAuto::auto(),+ },+ size: Size {+ width: length(100.0),+ height: length(60.0),+ },+ padding: Rect {+ left: length(5.0),+ right: length(5.0),+ top: length(5.0),+ bottom: length(5.0),+ },+ border: Rect {+ left: length(2.0),+ right: length(2.0),+ top: length(2.0),+ bottom: length(2.0),+ },+ ..Style::default()+ },+ )+ .with_2d_transform(LayoutTransform2D::scale(0.5, 0.5)),+ );++ let output = build(&source, &mut styles);+ let viewport_point = LayoutPoint::new(35.0, 45.0);+ let hit = output+ .hit_test(viewport_point, false)+ .expect("scaled embedded content should be hit");+ assert_eq!(hit.source, 1);+ let mapped = hit.viewport_to_local.map_point(viewport_point);+ assert_close(mapped.x, hit.local_point.x);+ assert_close(mapped.y, hit.local_point.y);++ let local_content = hit+ .local_content_box+ .expect("box hit should retain its unprojected content box");+ assert_rect(local_content, LayoutRect::new(7.0, 7.0, 100.0, 60.0));+ let projected_content = hit+ .box_model+ .expect("box hit should retain its projected protocol model")+ .content+ .bounding_rect();+ assert_close(projected_content.width, 50.0);+ assert_close(projected_content.height, 30.0);+}+#[test]fn viewport_fixed_geometry_does_not_move_with_root_scroll() {let mut source = Source(vec![diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rsindex 8e8450f03..0a823952f 100644--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs@@ -418,6 +418,485 @@ fn wheel_default_action_scrolls_the_innermost_container_then_chains_to_the_root();}+#[test]+fn transformed_constrained_iframe_routes_hover_click_and_wheel_in_child_coordinates() {+ let mut vm = new_storage_test_vm("https://iframe-input-coordinates.test/");+ vm.set_viewport_surface(Some(crate::protocol_types::ViewportSurface {+ inner_width: 1200,+ inner_height: 800,+ outer_width: 1200,+ outer_height: 800,+ device_pixel_ratio: 1.0,+ screen_width: 1200,+ screen_height: 800,+ screen_avail_width: 1200,+ screen_avail_height: 800,+ }))+ .expect("iframe input viewport should update");+ vm.force_fresh_layout_reads_for_test();++ vm.eval(+ r#"+ if (!document.documentElement) {+ document.appendChild(document.createElement('html'));+ }+ if (!document.head) {+ document.documentElement.appendChild(document.createElement('head'));+ }+ if (!document.body) {+ document.documentElement.appendChild(document.createElement('body'));+ }+ document.documentElement.style.cssText = 'margin:0;padding:0';+ document.body.style.cssText = 'margin:0;padding:0';++ const container = document.createElement('div');+ container.id = 'input-frame-clip';+ container.style.cssText = 'position:absolute;left:100px;top:120px;width:720px;height:500px;overflow:hidden';+ const frame = document.createElement('iframe');+ frame.id = 'input-frame';+ frame.style.cssText = 'display:block;width:calc(100% / 0.78);height:calc(500px / 0.78);margin:0;border:0;padding:0;transform:scale(0.78);transform-origin:0 0';+ container.appendChild(frame);+ document.body.appendChild(container);++ const child = frame.contentDocument;+ child.documentElement.style.cssText = 'margin:0;padding:0';+ child.body.style.cssText = 'margin:0;padding:0';+ const style = child.createElement('style');+ style.textContent = `+ #hover-target { position:fixed;left:220px;top:50px;width:40px;height:80px;background:red }+ #hover-target:hover { background:lime }+ #wheel-target { position:fixed;left:500px;top:180px;width:120px;height:120px;overflow:auto }+ #wheel-content { width:100px;height:900px }+ `;+ child.head.appendChild(style);+ child.body.innerHTML = `+ <div id="hover-target"></div>+ <div id="wheel-target"><div id="wheel-content"></div></div>+ `;+ frame.contentWindow.__inputEvents = [];+ for (const type of ['pointerover', 'mouseover', 'mousemove', 'mousedown', 'mouseup', 'click', 'wheel']) {+ child.addEventListener(type, event => {+ frame.contentWindow.__inputEvents.push({+ type,+ target: event.target.id,+ clientX: event.clientX,+ clientY: event.clientY,+ deltaY: event.deltaY || 0+ });+ }, true);+ }+ 'installed'+ "#,+ )+ .expect("transformed iframe input fixture should initialize");++ let geometry = vm+ .eval(+ r#"+ (() => {+ const frame = document.getElementById('input-frame');+ const rect = frame.getBoundingClientRect();+ return JSON.stringify({+ offset: [frame.offsetWidth, frame.offsetHeight],+ rect: [rect.left, rect.top, rect.width, rect.height],+ childViewport: [frame.contentWindow.innerWidth, frame.contentWindow.innerHeight]+ });+ })()+ "#,+ )+ .expect("transformed iframe geometry should evaluate");+ let geometry: serde_json::Value =+ serde_json::from_str(&geometry).expect("iframe geometry should be JSON");+ assert_eq!(geometry["offset"], serde_json::json!([923, 641]));+ assert_eq!(geometry["childViewport"], serde_json::json!([923, 641]));+ let rect = geometry["rect"]+ .as_array()+ .expect("iframe rect should be an array");+ assert!((rect[0].as_f64().unwrap() - 100.0).abs() < 0.01);+ assert!((rect[1].as_f64().unwrap() - 120.0).abs() < 0.01);+ assert!((rect[2].as_f64().unwrap() - 719.94).abs() < 0.1);+ assert!((rect[3].as_f64().unwrap() - 499.98).abs() < 0.1);++ // Child point (240, 90) is the visible center of #hover-target. The+ // iframe's 0.78 transform maps it to root-frame point (287.2, 190.2).+ vm.dispatch_mouse_event_at_point(287.2, 190.2, "mousemove", -1, Some(0), 0.0, 0.0)+ .expect("child hover move should dispatch");+ vm.dispatch_mouse_event_at_point(287.2, 190.2, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("child mouse down should dispatch");+ vm.dispatch_mouse_event_at_point(287.2, 190.2, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("child mouse up should dispatch");++ // Child point (560, 240) lies in the inner overflow container.+ vm.dispatch_mouse_event_at_point(536.8, 307.2, "wheel", -1, Some(0), 0.0, 100.0)+ .expect("child wheel should dispatch");++ let result = vm+ .eval(+ r#"+ (() => {+ const frame = document.getElementById('input-frame');+ const child = frame.contentDocument;+ return JSON.stringify({+ hovered: child.getElementById('hover-target').matches(':hover'),+ wheelTop: child.getElementById('wheel-target').scrollTop,+ rootTop: document.scrollingElement.scrollTop,+ events: frame.contentWindow.__inputEvents+ });+ })()+ "#,+ )+ .expect("child input result should evaluate");+ let result: serde_json::Value =+ serde_json::from_str(&result).expect("child input result should be JSON");+ assert_eq!(result["hovered"], true);+ assert_eq!(result["wheelTop"], 100);+ assert_eq!(result["rootTop"], 0);++ let events = result["events"]+ .as_array()+ .expect("child events should be an array");+ for event_type in ["mousemove", "mousedown", "mouseup", "click"] {+ let event = events+ .iter()+ .find(|event| event["type"] == event_type)+ .unwrap_or_else(|| panic!("missing {event_type} event: {events:?}"));+ assert_eq!(event["target"], "hover-target");+ assert!((event["clientX"].as_f64().unwrap() - 240.0).abs() < 0.1);+ assert!((event["clientY"].as_f64().unwrap() - 90.0).abs() < 0.1);+ }+ let wheel = events+ .iter()+ .find(|event| event["type"] == "wheel")+ .unwrap_or_else(|| panic!("missing wheel event: {events:?}"));+ assert_eq!(wheel["target"], "wheel-content");+ assert!((wheel["clientX"].as_f64().unwrap() - 560.0).abs() < 0.1);+ assert!((wheel["clientY"].as_f64().unwrap() - 240.0).abs() < 0.1);++ assert_eq!(+ vm.eval(+ r#"+ (() => {+ document.getElementById('input-frame-clip').style.width = '624px';+ const frame = document.getElementById('input-frame');+ return [frame.offsetWidth, frame.contentWindow.innerWidth].join('|');+ })()+ "#,+ )+ .expect("resized iframe viewport should evaluate"),+ "800|800"+ );+}++#[test]+fn focusing_visible_child_target_does_not_scroll_partially_hidden_transformed_iframe() {+ let mut vm = new_storage_test_vm("https://iframe-focus-scroll.test/");+ vm.set_viewport_surface(Some(crate::protocol_types::ViewportSurface {+ inner_width: 800,+ inner_height: 600,+ outer_width: 800,+ outer_height: 600,+ device_pixel_ratio: 1.0,+ screen_width: 800,+ screen_height: 600,+ screen_avail_width: 800,+ screen_avail_height: 600,+ }))+ .expect("iframe focus viewport should update");+ vm.force_fresh_layout_reads_for_test();++ vm.eval(+ r#"+ if (!document.documentElement) {+ document.appendChild(document.createElement('html'));+ }+ if (!document.body) {+ document.documentElement.appendChild(document.createElement('body'));+ }+ document.documentElement.style.cssText = 'margin:0;padding:0';+ document.body.style.cssText = 'margin:0;padding:0;min-height:1200px';++ const clip = document.createElement('div');+ clip.style.cssText = 'position:absolute;left:100px;top:400px;width:720px;height:500px;overflow:hidden';+ const frame = document.createElement('iframe');+ frame.id = 'focus-frame';+ frame.style.cssText = 'display:block;width:calc(100% / .78);height:calc(500px / .78);margin:0;border:0;padding:0;transform:scale(.78);transform-origin:0 0';+ clip.appendChild(frame);+ document.body.appendChild(clip);++ const child = frame.contentDocument;+ child.documentElement.style.cssText = 'margin:0;padding:0';+ child.body.style.cssText = 'margin:0;padding:0';+ child.body.innerHTML = '<button id="focus-target" style="position:fixed;left:20px;top:20px;width:80px;height:40px">Run</button>';+ frame.contentWindow.__focusEvents = [];+ for (const type of ['mousemove', 'mousedown', 'focus', 'mouseup', 'click']) {+ child.addEventListener(type, event => {+ frame.contentWindow.__focusEvents.push({+ type,+ target: event.target.id,+ clientX: event.clientX || 0,+ clientY: event.clientY || 0+ });+ }, true);+ }+ 'installed'+ "#,+ )+ .expect("iframe focus fixture should initialize");++ // Child point (60, 40), the button center, maps through scale(.78) to+ // root-frame point (146.8, 431.2). The button is visible, while the frame+ // continues below the 600px-high top viewport.+ vm.dispatch_mouse_event_at_point(146.8, 431.2, "mousemove", -1, Some(0), 0.0, 0.0)+ .expect("child hover should dispatch");+ vm.dispatch_mouse_event_at_point(146.8, 431.2, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("child press should dispatch");++ assert_eq!(+ vm.eval("String(window.scrollY)")+ .expect("parent scroll after child focus should evaluate"),+ "0",+ "focusing a visible child target must not reveal the whole iframe"+ );++ vm.dispatch_mouse_event_at_point(146.8, 431.2, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("child release should dispatch");++ let result = vm+ .eval(+ r#"+ (() => {+ const frame = document.getElementById('focus-frame');+ const child = frame.contentDocument;+ return JSON.stringify({+ parentScroll: window.scrollY,+ parentActive: document.activeElement === frame,+ childActive: child.activeElement === child.getElementById('focus-target'),+ hovered: child.getElementById('focus-target').matches(':hover'),+ events: frame.contentWindow.__focusEvents+ });+ })()+ "#,+ )+ .expect("iframe focus result should evaluate");+ let result: serde_json::Value =+ serde_json::from_str(&result).expect("iframe focus result should be JSON");+ assert_eq!(result["parentScroll"], 0);+ assert_eq!(result["parentActive"], true);+ assert_eq!(result["childActive"], true);+ assert_eq!(result["hovered"], true);++ let events = result["events"]+ .as_array()+ .expect("iframe focus events should be an array");+ for event_type in ["mousemove", "mousedown", "mouseup", "click"] {+ let event = events+ .iter()+ .find(|event| event["type"] == event_type)+ .unwrap_or_else(|| panic!("missing child {event_type}: {events:?}"));+ assert_eq!(event["target"], "focus-target");+ assert!((event["clientX"].as_f64().unwrap() - 60.0).abs() < 0.1);+ assert!((event["clientY"].as_f64().unwrap() - 40.0).abs() < 0.1);+ }+}++#[test]+fn nested_transformed_iframe_input_composes_scroll_border_padding_and_exit_coordinates() {+ let mut vm = new_storage_test_vm("https://nested-iframe-input.test/");+ vm.set_viewport_surface(Some(crate::protocol_types::ViewportSurface {+ inner_width: 800,+ inner_height: 600,+ outer_width: 800,+ outer_height: 600,+ device_pixel_ratio: 1.0,+ screen_width: 800,+ screen_height: 600,+ screen_avail_width: 800,+ screen_avail_height: 600,+ }))+ .expect("nested iframe viewport should update");+ vm.force_fresh_layout_reads_for_test();++ vm.eval(+ r#"+ if (!document.documentElement) {+ document.appendChild(document.createElement('html'));+ }+ if (!document.body) {+ document.documentElement.appendChild(document.createElement('body'));+ }+ document.documentElement.style.cssText = 'margin:0;padding:0';+ document.body.style.cssText = 'margin:0;padding:0';++ const outside = document.createElement('div');+ outside.id = 'outside';+ outside.style.cssText = 'position:fixed;left:0;top:0;width:30px;height:30px';+ document.body.appendChild(outside);++ const parentScroller = document.createElement('div');+ parentScroller.id = 'parent-scroller';+ parentScroller.style.cssText = 'position:absolute;left:40px;top:30px;width:400px;height:300px;overflow:auto';+ const canvas = document.createElement('div');+ canvas.style.cssText = 'position:relative;width:800px;height:600px';+ const outerFrame = document.createElement('iframe');+ outerFrame.id = 'outer-frame';+ outerFrame.style.cssText = 'position:absolute;left:100px;top:80px;display:block;box-sizing:border-box;width:240px;height:180px;margin:0;border:4px solid black;padding:6px;transform:scale(.75);transform-origin:0 0';+ canvas.appendChild(outerFrame);+ parentScroller.appendChild(canvas);+ document.body.appendChild(parentScroller);++ const child = outerFrame.contentDocument;+ child.documentElement.style.cssText = 'margin:0;padding:0';+ child.body.style.cssText = 'margin:0;padding:0';+ const nestedFrame = child.createElement('iframe');+ nestedFrame.id = 'nested-frame';+ nestedFrame.style.cssText = 'position:absolute;left:40px;top:30px;display:block;box-sizing:border-box;width:100px;height:80px;margin:0;border:2px solid black;padding:3px;transform:scale(.5);transform-origin:0 0';+ child.body.appendChild(nestedFrame);++ const nested = nestedFrame.contentDocument;+ nested.documentElement.style.cssText = 'margin:0;padding:0';+ nested.body.style.cssText = 'margin:0;padding:0';+ nested.body.innerHTML = `+ <div id="nested-target" style="position:fixed;left:10px;top:10px;width:20px;height:20px"></div>+ <div id="nested-scroll" style="position:fixed;left:10px;top:30px;width:50px;height:40px;overflow:auto">+ <div id="nested-scroll-content" style="width:200px;height:200px"></div>+ </div>+ `;+ nestedFrame.contentWindow.__nestedEvents = [];+ for (const type of ['pointerover', 'pointerout', 'mouseover', 'mouseout', 'mousemove', 'mousedown', 'mouseup', 'click', 'wheel']) {+ nested.addEventListener(type, event => {+ nestedFrame.contentWindow.__nestedEvents.push({+ type,+ target: event.target.id,+ clientX: event.clientX,+ clientY: event.clientY+ });+ }, true);+ }+ parentScroller.scrollTo(50, 40);+ 'installed'+ "#,+ )+ .expect("nested transformed iframe fixture should initialize");++ // The exact used content viewports exclude each frame's border and+ // padding: 240 - 2*(4+6) = 220, then 100 - 2*(2+3) = 90.+ assert_eq!(+ vm.eval(+ r#"+ (() => {+ const outer = document.getElementById('outer-frame');+ const nested = outer.contentDocument.getElementById('nested-frame');+ return JSON.stringify([+ outer.clientWidth - 12, outer.clientHeight - 12,+ nested.clientWidth - 6, nested.clientHeight - 6,+ document.getElementById('parent-scroller').scrollLeft,+ document.getElementById('parent-scroller').scrollTop+ ]);+ })()+ "#,+ )+ .expect("nested frame geometry should evaluate"),+ "[220,160,90,70,50,40]"+ );++ // Nested client point (20, 20) maps through scale(.5), the inner frame's+ // 5px border+padding edge, scale(.75), the outer frame's 10px edge, and+ // the scrolled parent to root point (136.875, 109.375).+ for event_name in ["mousemove", "mousedown", "mouseup"] {+ let (button, buttons) = match event_name {+ "mousedown" => (0, Some(1)),+ "mouseup" => (0, Some(0)),+ _ => (-1, Some(0)),+ };+ vm.dispatch_mouse_event_at_point(136.875, 109.375, event_name, button, buttons, 0.0, 0.0)+ .unwrap_or_else(|error| panic!("nested {event_name} should dispatch: {error:#}"));+ }++ // Nested client point (20, 35) is inside the scroll content.+ vm.dispatch_mouse_event_at_point(136.875, 115.0, "wheel", -1, Some(0), 0.0, 30.0)+ .expect("nested wheel should dispatch");+ let events_before_scrollbar = vm+ .eval(+ "String(document.getElementById('outer-frame').contentDocument.getElementById('nested-frame').contentWindow.__nestedEvents.length)",+ )+ .expect("nested event count should evaluate")+ .parse::<usize>()+ .expect("nested event count should be numeric");+ // Nested client point (52, 50) is the vertical scrollbar's forward+ // button. UA scrollbar input is routed through the same two frame maps and+ // remains outside DOM mouse dispatch.+ vm.dispatch_mouse_event_at_point(148.875, 120.625, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("nested scrollbar press should dispatch");+ vm.dispatch_mouse_event_at_point(148.875, 120.625, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("nested scrollbar release should dispatch");+ assert_eq!(+ vm.eval(+ r#"+ (() => {+ const nestedFrame = document.getElementById('outer-frame').contentDocument.getElementById('nested-frame');+ return JSON.stringify([+ nestedFrame.contentDocument.getElementById('nested-scroll').scrollTop,+ nestedFrame.contentWindow.__nestedEvents.length+ ]);+ })()+ "#,+ )+ .expect("nested scrollbar result should evaluate"),+ format!("[70,{events_before_scrollbar}]")+ );+ // Move to a top-document element. The outgoing events must still convert+ // this new root point through the previous nested frame chain.+ vm.dispatch_mouse_event_at_point(10.0, 10.0, "mousemove", -1, Some(0), 0.0, 0.0)+ .expect("nested hover exit should dispatch");++ let result = vm+ .eval(+ r#"+ (() => {+ const outer = document.getElementById('outer-frame');+ const nestedFrame = outer.contentDocument.getElementById('nested-frame');+ const nested = nestedFrame.contentDocument;+ return JSON.stringify({+ events: nestedFrame.contentWindow.__nestedEvents,+ scrollTop: nested.getElementById('nested-scroll').scrollTop,+ parentTop: document.getElementById('parent-scroller').scrollTop+ });+ })()+ "#,+ )+ .expect("nested iframe input result should evaluate");+ let result: serde_json::Value =+ serde_json::from_str(&result).expect("nested iframe result should be JSON");+ assert_eq!(result["scrollTop"], 70);+ assert_eq!(result["parentTop"], 40);+ let events = result["events"]+ .as_array()+ .expect("nested events should be an array");+ for event_type in ["mousemove", "mousedown", "mouseup", "click"] {+ let event = events+ .iter()+ .find(|event| event["type"] == event_type && event["target"] == "nested-target")+ .unwrap_or_else(|| panic!("missing nested {event_type}: {events:?}"));+ assert!((event["clientX"].as_f64().unwrap() - 20.0).abs() < 0.1);+ assert!((event["clientY"].as_f64().unwrap() - 20.0).abs() < 0.1);+ }+ let wheel = events+ .iter()+ .find(|event| event["type"] == "wheel")+ .unwrap_or_else(|| panic!("missing nested wheel: {events:?}"));+ assert_eq!(wheel["target"], "nested-scroll-content");+ assert!((wheel["clientX"].as_f64().unwrap() - 20.0).abs() < 0.1);+ assert!((wheel["clientY"].as_f64().unwrap() - 35.0).abs() < 0.1);+ let mouseout = events+ .iter()+ .rev()+ .find(|event| event["type"] == "mouseout")+ .unwrap_or_else(|| panic!("missing nested mouseout: {events:?}"));+ assert_eq!(mouseout["target"], "nested-target");+ assert!((mouseout["clientX"].as_f64().unwrap() + 318.333).abs() < 0.2);+ assert!((mouseout["clientY"].as_f64().unwrap() + 245.0).abs() < 0.2);+}+#[test]fn classic_scrollbar_metrics_and_thumb_drag_match_chromium_without_dom_mouse_events() {let mut vm = new_storage_test_vm("https://classic-scrollbar-input.test/");@@ -550,6 +1029,366 @@ fn classic_scrollbar_metrics_and_thumb_drag_match_chromium_without_dom_mouse_eveassert_eq!(result["events"], serde_json::json!([]));}+#[test]+fn nested_and_sibling_scrollbar_drags_stay_bound_to_the_pressed_scroller() {+ let mut vm = new_storage_test_vm("https://nested-classic-scrollbar-input.test/");+ vm.eval(+ r#"+ (() => {+ if (!document.documentElement) {+ document.appendChild(document.createElement("html"));+ }+ if (!document.body) {+ document.documentElement.appendChild(document.createElement("body"));+ }+ document.documentElement.style.margin = "0";+ document.body.style.margin = "0";+ document.body.innerHTML = `+ <div id="outer" style="position:absolute;left:20px;top:20px;width:280px;height:200px;overflow:auto">+ <div style="position:relative;width:620px;height:500px">+ <div id="inner" style="position:absolute;left:30px;top:30px;width:180px;height:120px;overflow:auto">+ <div style="width:420px;height:320px"></div>+ </div>+ </div>+ </div>+ <div id="sibling" style="position:absolute;left:340px;top:20px;width:180px;height:120px;overflow:auto">+ <div style="width:420px;height:320px"></div>+ </div>+ <div id="horizontal" style="position:absolute;left:340px;top:180px;width:220px;height:100px;overflow:auto">+ <div style="width:600px;height:60px"></div>+ </div>+ <div id="thin-child" style="position:absolute;left:600px;top:20px;width:160px;height:120px;overflow:auto;scrollbar-width:thin">+ <div style="width:400px;height:320px"></div>+ </div>+ <div id="rtl-child" style="position:absolute;left:600px;top:180px;width:160px;height:120px;overflow:auto;direction:rtl">+ <div style="width:400px;height:320px"></div>+ </div>`;+ window.__nestedScrollbarDomEvents = [];+ for (const name of ["pointerdown", "pointermove", "pointerup", "mousedown", "mousemove", "mouseup", "click"]) {+ document.addEventListener(name, () => __nestedScrollbarDomEvents.push(name), true);+ }+ })()+ "#,+ )+ .expect("nested scrollbar fixture should initialize");+ refresh_layout_for_test(&mut vm);++ assert_eq!(+ vm.eval(+ r#"JSON.stringify([+ outer.clientWidth, outer.clientHeight, outer.scrollWidth, outer.scrollHeight,+ inner.clientWidth, inner.clientHeight, inner.scrollWidth, inner.scrollHeight,+ sibling.clientWidth, sibling.clientHeight,+ horizontal.clientWidth, horizontal.clientHeight,+ horizontal.scrollWidth, horizontal.scrollHeight,+ document.getElementById("thin-child").clientWidth,+ document.getElementById("thin-child").clientHeight,+ document.getElementById("rtl-child").clientWidth,+ document.getElementById("rtl-child").clientHeight,+ document.getElementById("rtl-child").clientLeft,+ document.getElementById("rtl-child").scrollLeft+ ])"#,+ )+ .expect("multi-scroller metrics should evaluate"),+ "[265,185,620,500,165,105,420,320,165,105,220,85,600,85,150,110,145,105,15,0]"+ );++ // Start on the nested vertical thumb, then move and release over the+ // sibling's scrollbar. Native dragging captures the originally pressed+ // scrollbar instead of retargeting every move by viewport hit testing.+ vm.dispatch_mouse_event_at_point(225.0, 75.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("nested thumb press should dispatch");+ vm.dispatch_mouse_event_at_point(515.0, 115.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("captured nested thumb move should dispatch");+ vm.dispatch_mouse_event_at_point(515.0, 115.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("captured nested thumb release should dispatch");+ let after_nested: serde_json::Value = serde_json::from_str(+ &vm.eval("JSON.stringify([inner.scrollTop, outer.scrollTop, sibling.scrollTop])")+ .expect("nested drag state should evaluate"),+ )+ .expect("nested drag state should be JSON");+ assert!(+ after_nested[0].as_f64().is_some_and(|value| value > 180.0),+ "nested thumb should move its own element: {after_nested}"+ );+ assert_eq!(after_nested[1], 0);+ assert_eq!(after_nested[2], 0);++ vm.dispatch_mouse_event_at_point(515.0, 45.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("sibling thumb press should dispatch after captured release");+ vm.dispatch_mouse_event_at_point(515.0, 85.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("sibling thumb move should dispatch");+ vm.dispatch_mouse_event_at_point(515.0, 85.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("sibling thumb release should dispatch");++ vm.dispatch_mouse_event_at_point(370.0, 275.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("horizontal child thumb press should dispatch");+ vm.dispatch_mouse_event_at_point(450.0, 275.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("horizontal child thumb move should dispatch");+ vm.dispatch_mouse_event_at_point(450.0, 275.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("horizontal child thumb release should dispatch");++ vm.dispatch_mouse_event_at_point(755.0, 45.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("thin vertical thumb press should dispatch");+ vm.dispatch_mouse_event_at_point(755.0, 75.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("thin vertical thumb move should dispatch");+ vm.dispatch_mouse_event_at_point(755.0, 75.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("thin vertical thumb release should dispatch");+ vm.dispatch_mouse_event_at_point(630.0, 135.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("thin horizontal thumb press should dispatch");+ vm.dispatch_mouse_event_at_point(690.0, 135.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("thin horizontal thumb move should dispatch");+ vm.dispatch_mouse_event_at_point(690.0, 135.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("thin horizontal thumb release should dispatch");++ vm.dispatch_mouse_event_at_point(607.0, 205.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("RTL left-edge vertical thumb press should dispatch");+ vm.dispatch_mouse_event_at_point(607.0, 235.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("RTL left-edge vertical thumb move should dispatch");+ vm.dispatch_mouse_event_at_point(607.0, 235.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("RTL left-edge vertical thumb release should dispatch");+ vm.dispatch_mouse_event_at_point(720.0, 292.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("RTL horizontal thumb press should dispatch");+ vm.dispatch_mouse_event_at_point(660.0, 292.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("RTL horizontal thumb move should dispatch toward the negative range");+ vm.dispatch_mouse_event_at_point(660.0, 292.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("RTL horizontal thumb release should dispatch");++ // Move the nested scroller partly above its parent's clip, then prove the+ // remaining visible piece of its thumb is hittable in the new space.+ vm.eval("outer.scrollTop = 50; inner.scrollTop = 0")+ .expect("ancestor and nested scroll positions should reset");+ refresh_layout_for_test(&mut vm);+ vm.dispatch_mouse_event_at_point(225.0, 25.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("partly clipped nested thumb press should dispatch");+ vm.dispatch_mouse_event_at_point(700.0, 45.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("partly clipped captured move should dispatch outside the scroller");+ vm.dispatch_mouse_event_at_point(700.0, 45.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("partly clipped captured release should dispatch");++ vm.dispatch_mouse_event_at_point(295.0, 65.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("outer thumb press should dispatch");+ vm.dispatch_mouse_event_at_point(295.0, 125.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("outer thumb move should dispatch");+ vm.dispatch_mouse_event_at_point(295.0, 125.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("outer thumb release should dispatch");++ let result: serde_json::Value = serde_json::from_str(+ &vm.eval(+ "JSON.stringify([outer.scrollTop, inner.scrollTop, sibling.scrollTop, horizontal.scrollLeft, document.getElementById('thin-child').scrollLeft, document.getElementById('thin-child').scrollTop, document.getElementById('rtl-child').scrollLeft, document.getElementById('rtl-child').scrollTop, __nestedScrollbarDomEvents])",+ )+ .expect("multi-scroller drag state should evaluate"),+ )+ .expect("multi-scroller drag state should be JSON");+ assert!(result[0].as_f64().is_some_and(|value| value > 200.0));+ assert!(result[1].as_f64().is_some_and(|value| value > 90.0));+ assert!(result[2].as_f64().is_some_and(|value| value > 180.0));+ assert!(result[3].as_f64().is_some_and(|value| value > 250.0));+ assert!(result[4].as_f64().is_some_and(|value| value > 180.0));+ assert!(result[5].as_f64().is_some_and(|value| value > 100.0));+ assert!(result[6].as_f64().is_some_and(|value| value < -180.0));+ assert!(result[7].as_f64().is_some_and(|value| value > 130.0));+ assert_eq!(result[8], serde_json::json!([]));+}++#[test]+fn transformed_scrollbar_drag_uses_local_motion_clamps_and_cancels_on_button_loss() {+ let mut vm = new_storage_test_vm("https://transformed-classic-scrollbar-input.test/");+ vm.eval(+ r#"+ (() => {+ if (!document.documentElement) {+ document.appendChild(document.createElement("html"));+ }+ if (!document.body) {+ document.documentElement.appendChild(document.createElement("body"));+ }+ document.documentElement.style.margin = "0";+ document.body.style.margin = "0";+ document.body.innerHTML = `+ <div id="scaled" style="position:absolute;left:50px;top:350px;width:160px;height:100px;overflow:auto;transform:scale(2);transform-origin:0 0">+ <div style="width:400px;height:300px"></div>+ </div>+ <div id="releaseTarget" style="position:absolute;left:650px;top:350px;width:140px;height:220px"></div>`;+ window.__transformedScrollbarDomEvents = [];+ for (const name of ["pointermove", "mousemove"]) {+ document.addEventListener(name, () => __transformedScrollbarDomEvents.push(name), true);+ }+ })()+ "#,+ )+ .expect("transformed scrollbar fixture should initialize");+ refresh_layout_for_test(&mut vm);++ let hit = crate::native_bridge::element::observable_scrollbar_hit_test(+ &vm._context_host.borrow(),+ vm.document_runtime.document_handle(),+ moli_layout::LayoutPoint::new(355.0, 400.0),+ )+ .expect("transformed scrollbar hit test should succeed")+ .expect("scaled vertical thumb should be hit");+ assert_eq!(hit.part, moli_layout::LayoutScrollbarPart::Thumb);+ assert_eq!(+ hit.scrollbar.axis,+ moli_layout::LayoutScrollbarAxis::Vertical+ );++ // Cross-axis motion does nothing. Each later move is absolute from the+ // original press, and forty viewport pixels are twenty local pixels under+ // scale(2), rather than forty CSS pixels or a sum of prior move deltas.+ vm.dispatch_mouse_event_at_point(355.0, 400.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("scaled thumb press should dispatch");+ vm.dispatch_mouse_event_at_point(700.0, 400.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("scaled cross-axis-only captured move should dispatch");+ assert_eq!(+ vm.eval("scaled.scrollTop")+ .expect("cross-axis-only scaled scrollTop should evaluate"),+ "0"+ );+ vm.dispatch_mouse_event_at_point(700.0, 420.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("first scaled incremental thumb move should dispatch");+ let first_move = vm+ .eval("scaled.scrollTop")+ .expect("first scaled scrollTop should evaluate")+ .parse::<f64>()+ .expect("first scaled scrollTop should be numeric");+ assert!(+ (first_move - 67.1875).abs() < 0.01,+ "scrollTop={first_move}"+ );+ vm.dispatch_mouse_event_at_point(700.0, 440.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("scaled captured thumb move should dispatch outside its element");+ vm.dispatch_mouse_event_at_point(700.0, 440.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("scaled captured thumb release should dispatch");+ let moderate = vm+ .eval("scaled.scrollTop")+ .expect("scaled scrollTop should evaluate")+ .parse::<f64>()+ .expect("scaled scrollTop should be numeric");+ assert!((moderate - 134.375).abs() < 0.01, "scrollTop={moderate}");++ vm.eval("scaled.scrollTop = 0")+ .expect("scaled scrollTop should reset");+ refresh_layout_for_test(&mut vm);+ vm.dispatch_mouse_event_at_point(355.0, 400.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("scaled lower-clamp thumb press should dispatch");+ vm.dispatch_mouse_event_at_point(700.0, 590.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("scaled lower-clamp thumb move should dispatch");+ vm.dispatch_mouse_event_at_point(700.0, 590.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("scaled lower-clamp thumb release should dispatch");+ assert_eq!(+ vm.eval("scaled.scrollTop")+ .expect("maximum scaled scrollTop should evaluate"),+ "215"+ );++ refresh_layout_for_test(&mut vm);+ vm.dispatch_mouse_event_at_point(355.0, 460.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("scaled upper-clamp thumb press should dispatch");+ vm.dispatch_mouse_event_at_point(700.0, 300.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("scaled upper-clamp thumb move should dispatch");+ vm.dispatch_mouse_event_at_point(700.0, 300.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("scaled upper-clamp thumb release should dispatch");+ assert_eq!(+ vm.eval("scaled.scrollTop")+ .expect("minimum scaled scrollTop should evaluate"),+ "0"+ );++ // Losing the primary-button bit cancels native capture. Later moves must+ // return to DOM dispatch and must not continue scrolling the old element.+ refresh_layout_for_test(&mut vm);+ vm.dispatch_mouse_event_at_point(355.0, 400.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("cancelable scaled thumb press should dispatch");+ vm.dispatch_mouse_event_at_point(700.0, 440.0, "mousemove", -1, Some(0), 0.0, 0.0)+ .expect("primary-button loss should cancel native drag");+ vm.dispatch_mouse_event_at_point(700.0, 500.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("post-cancel DOM move should dispatch");+ let cancelled: serde_json::Value = serde_json::from_str(+ &vm.eval("JSON.stringify([scaled.scrollTop, __transformedScrollbarDomEvents])")+ .expect("cancelled transformed drag state should evaluate"),+ )+ .expect("cancelled transformed drag state should be JSON");+ assert_eq!(cancelled[0], 0);+ assert!(+ cancelled[1]+ .as_array()+ .is_some_and(|events| events.iter().any(|event| event == "mousemove")),+ "post-cancel moves should return to the DOM: {cancelled}"+ );+}++#[test]+fn document_replacement_cancels_old_scrollbar_capture_and_allows_a_new_drag() {+ let mut vm = new_storage_test_vm("https://replacement-classic-scrollbar-input.test/");+ vm.eval(+ r#"+ (() => {+ if (!document.documentElement) {+ document.appendChild(document.createElement("html"));+ }+ if (!document.body) {+ document.documentElement.appendChild(document.createElement("body"));+ }+ document.documentElement.style.margin = "0";+ document.body.style.margin = "0";+ document.body.innerHTML = `+ <div id="retiringScroller" style="width:200px;height:100px;overflow:auto">+ <div style="width:400px;height:300px"></div>+ </div>`;+ window.__retiredScroller = retiringScroller;+ })()+ "#,+ )+ .expect("retiring scrollbar fixture should initialize");+ refresh_layout_for_test(&mut vm);+ vm.dispatch_mouse_event_at_point(190.0, 30.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("retiring thumb press should dispatch");++ vm.eval(+ r#"+ document.open();+ document.write(`<!doctype html><style>html,body{margin:0}</style>+ <div id="replacementScroller" style="width:200px;height:100px;overflow:auto">+ <div style="width:400px;height:300px"></div>+ </div>+ <div id="replacementTarget" style="position:absolute;left:300px;top:0;width:100px;height:100px"></div>`);+ document.close();+ window.__replacementMoves = [];+ replacementTarget.addEventListener("pointermove", () => __replacementMoves.push("pointermove"));+ replacementTarget.addEventListener("mousemove", () => __replacementMoves.push("mousemove"));+ "#,+ )+ .expect("document.open should install the replacement input fixture");+ refresh_layout_for_test(&mut vm);++ vm.dispatch_mouse_event_at_point(320.0, 20.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("replacement-document move should dispatch normally");+ let replacement_move: serde_json::Value = serde_json::from_str(+ &vm.eval("JSON.stringify([__retiredScroller.scrollTop, __replacementMoves])")+ .expect("replacement move state should evaluate"),+ )+ .expect("replacement move state should be JSON");+ assert_eq!(replacement_move[0], 0);+ assert_eq!(+ replacement_move[1],+ serde_json::json!(["pointermove", "mousemove"])+ );++ vm.dispatch_mouse_event_at_point(190.0, 30.0, "mousedown", 0, Some(1), 0.0, 0.0)+ .expect("replacement thumb press should start a fresh drag");+ vm.dispatch_mouse_event_at_point(190.0, 50.0, "mousemove", -1, Some(1), 0.0, 0.0)+ .expect("replacement thumb move should dispatch");+ vm.dispatch_mouse_event_at_point(190.0, 50.0, "mouseup", 0, Some(0), 0.0, 0.0)+ .expect("replacement thumb release should dispatch");+ let replacement_scroll = vm+ .eval("replacementScroller.scrollTop")+ .expect("replacement scroller state should evaluate")+ .parse::<f64>()+ .expect("replacement scrollTop should be numeric");+ assert!(replacement_scroll > 130.0, "scrollTop={replacement_scroll}");+}+#[test]fn root_classic_scrollbars_stay_viewport_fixed_and_drive_window_scroll() {let mut vm = new_storage_test_vm("https://root-classic-scrollbar.test/");