WEFT_OS/tests/frame/check_input.py

168 lines
7.3 KiB
Python
Raw Normal View History

test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input
2026-10-09 01:18:53 +00:00
"""Check that native pointer and keyboard input reaches a page through weft-compositor.
The harness runs a Servo host with `input.html` on a nested desktop (see
test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input
2026-10-09 01:18:53 +00:00
session.py) and injects real X input into the compositor's window with
xdotool (after giving that window X input focus, since Xvfb runs without a
window manager), which weft-compositor's winit backend receives and routes to
the focused Wayland client. Each step must change the page as the page's script
defines, as seen in the presented pixels:
1. A click 6 px inside the left half's right edge turns only the left half
green; the right half must stay blue.
2. Typing `a` turns the right half yellow.
3. Typing `Shift+a` turns the right half magenta, which checks the modifier.
4. A click 6 px inside the right half's left edge turns the right half white.
5. Wheel notches down over the left half scroll it to the cyan block beneath,
so no green remains; notches up scroll it back to green.
test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input
2026-10-09 01:18:53 +00:00
The two clicks straddle the boundary between the halves, so a pointer
position that is scaled or offset by more than a few pixels fails.
`--host system` (the default) runs weft-servo-shell with the page as its
system UI; `--host app` runs weft-app-shell with the page as an
application's UI document, as check_frame.py does.
test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input
2026-10-09 01:18:53 +00:00
Requires Xvfb, xwd, ImageMagick's convert and xdotool.
"""
import argparse
import shutil
import subprocess
import sys
import time
from pathlib import Path
sys.dont_write_bytecode = True
from check_frame import APP_ID, app_ui # noqa: E402
test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input
2026-10-09 01:18:53 +00:00
from session import ROOT, Desktop, SessionError, bounding_box, missing_tools, parse_ppm # noqa: E402
HERE = Path(__file__).resolve().parent
RED, GREEN, BLUE = (255, 0, 0), (0, 255, 0), (0, 0, 255)
WHITE, YELLOW, MAGENTA = (255, 255, 255), (255, 255, 0), (255, 0, 255)
CYAN = (0, 255, 255)
# More notches than the pane needs to reach either end.
WHEEL_NOTCHES = "30"
test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input
2026-10-09 01:18:53 +00:00
MIN_SIDE = 40
def region(screenshot, color):
"""Bounding box of `color` if it covers a page half, else None."""
box = bounding_box(*parse_ppm(screenshot), color)
if box and box[2] - box[0] >= MIN_SIDE and box[3] - box[1] >= MIN_SIDE:
return box
return None
STARTUP_TIMEOUT = 120.0
EDGE_INSET = 6
class Steps:
def __init__(self, desktop, shell, timeout):
self.desktop = desktop
self.shell = shell
self.timeout = timeout
self.screenshot = None
self.xdotool_path = shutil.which("xdotool")
def expect(self, description, present, absent=(), timeout=None):
"""Wait until every colour in `present` and none in `absent` is shown."""
deadline = time.monotonic() + (self.timeout if timeout is None else timeout)
while time.monotonic() < deadline:
if self.shell.poll() is not None:
raise AssertionError(f"shell exited with status {self.shell.returncode}")
self.screenshot = self.desktop.capture()
boxes = {color: region(self.screenshot, color) for color in present}
if all(boxes.values()) and not any(region(self.screenshot, c) for c in absent):
return boxes
time.sleep(0.5)
raise AssertionError(f"{description}: expected page state not shown")
def xdotool(self, *arguments):
subprocess.run([self.xdotool_path, *arguments], env={"DISPLAY": self.desktop.display},
check=True, timeout=20)
def click(self, x, y, button="1", repeat="1"):
test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input
2026-10-09 01:18:53 +00:00
self.xdotool("mousemove", "--sync", str(x), str(y))
self.xdotool("click", "--repeat", repeat, "--delay", "30", button)
test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input
2026-10-09 01:18:53 +00:00
def run(steps):
boxes = steps.expect("initial page", [RED, BLUE], timeout=STARTUP_TIMEOUT)
# Xvfb runs without a window manager, so give the compositor's window the
# X input focus that a real session's window manager would.
steps.xdotool("search", "--class", "weft-compositor", "windowfocus", "--sync")
left, right = boxes[RED], boxes[BLUE]
middle = (left[1] + left[3]) // 2
steps.click(left[2] - EDGE_INSET, middle)
steps.expect("click near the right edge of the left half", [GREEN, BLUE],
absent=[RED, WHITE])
steps.xdotool("key", "a")
steps.expect("key a", [GREEN, YELLOW], absent=[BLUE])
steps.xdotool("key", "shift+a")
steps.expect("key Shift+a", [GREEN, MAGENTA], absent=[YELLOW])
steps.click(right[0] + EDGE_INSET, middle)
steps.expect("click near the left edge of the right half", [GREEN, WHITE],
absent=[MAGENTA, RED])
# X buttons 5 and 4 are wheel notches down and up.
centre = (left[0] + left[2]) // 2
steps.click(centre, middle, button="5", repeat=WHEEL_NOTCHES)
steps.expect("wheel down over the left half", [CYAN, WHITE], absent=[GREEN])
steps.click(centre, middle, button="4", repeat=WHEEL_NOTCHES)
steps.expect("wheel up over the left half", [GREEN, WHITE], absent=[CYAN])
test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input
2026-10-09 01:18:53 +00:00
def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--compositor", type=Path, default=ROOT / "target/debug/weft-compositor")
parser.add_argument("--host", choices=("system", "app"), default="system")
parser.add_argument("--shell", type=Path,
help="host binary (default: target/debug/weft-servo-shell or "
"target/debug/weft-app-shell)")
test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input
2026-10-09 01:18:53 +00:00
parser.add_argument("--page", type=Path, default=HERE / "input.html")
parser.add_argument("--timeout", type=float, default=30.0,
help="seconds to wait for each expected page state")
parser.add_argument("--output", type=Path, default=ROOT / "target/input-check",
help="directory for logs and the last capture")
args = parser.parse_args(argv)
if args.shell is None:
name = "weft-servo-shell" if args.host == "system" else "weft-app-shell"
args.shell = ROOT / "target/debug" / name
test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input
2026-10-09 01:18:53 +00:00
missing = missing_tools() + [tool for tool in ("xdotool",) if shutil.which(tool) is None]
missing += [str(b) for b in (args.compositor, args.shell) if not b.is_file()]
if missing:
print("missing: " + ", ".join(missing), file=sys.stderr)
return 2
try:
with Desktop(args.compositor, args.output, outputs=["input.ppm"]) as desktop:
if args.host == "system":
shell = desktop.launch_client(
"shell", [args.shell], {"WEFT_SYSTEM_UI_HTML": str(args.page.resolve())})
else:
entry = app_ui(desktop.runtime / APP_ID, args.page)
shell = desktop.launch_client(
"shell", [args.shell, APP_ID, "1", "--ui", str(entry)])
test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input
2026-10-09 01:18:53 +00:00
steps = Steps(desktop, shell, args.timeout)
try:
run(steps)
except AssertionError as failure:
print(f"input check failed: {failure}", file=sys.stderr)
print(f"logs and last capture in {args.output}", file=sys.stderr)
return 1
finally:
if steps.screenshot is not None:
(args.output / "input.ppm").write_bytes(steps.screenshot)
except SessionError as error:
print(error, file=sys.stderr)
return 1
print("input check passed")
return 0
if __name__ == "__main__":
raise SystemExit(main())