Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

test(cua-driver): add shared external-oracle behavior matrix

Francesco Bonaccif9f01c427a77
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/cross_platform_behavior_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/cross_platform_behavior_test.rs
new file mode 100644
index 0000000000..8fe7efc889
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/cross_platform_behavior_test.rs
@@ -0,0 +1,613 @@
+//! Cross-platform behavioral scenarios derived from the external CUA matrix.
+//!
+//! These are source-owned Rust tests, not a copy of a partner test runner. The
+//! shared web fixture is loaded by Electron and Tauri on every supported OS;
+//! Windows also has WebView2 coverage in `harness_web_test.rs`. Assertions read
+//! the fixture's mutated application state from a fresh accessibility snapshot.
+//! A successful driver response alone is never sufficient.
+//!
+//! Run after building the shared fixtures:
+//!
+//! ```text
+//! cargo test -p cua-driver --test cross_platform_behavior_test -- --ignored \
+//! --nocapture --test-threads=1
+//! ```
+
+#![cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
+
+use std::path::PathBuf;
+use std::process::{Command, Stdio};
+use std::thread;
+use std::time::{Duration, Instant};
+
+use cua_driver_testkit::ax::{element_index_by_id, element_index_containing};
+use cua_driver_testkit::{harness_app, spawn_in_job, Driver, McpDriver, ToolResponse};
+
+struct HostSpec {
+ name: &'static str,
+ path: PathBuf,
+ args: Vec<&'static str>,
+ title: &'static str,
+}
+
+fn host_specs() -> Vec<HostSpec> {
+ let mut hosts = Vec::new();
+
+ #[cfg(target_os = "windows")]
+ {
+ hosts.push(HostSpec {
+ name: "electron",
+ path: harness_app("harness-electron", "CuaTestHarness.Electron.exe"),
+ args: vec![
+ "--no-sandbox",
+ "--disable-gpu",
+ "--force-renderer-accessibility",
+ ],
+ title: "CuaTestHarness Electron",
+ });
+ hosts.push(HostSpec {
+ name: "tauri",
+ path: harness_app("harness-tauri", "CuaTestHarness.Tauri.exe"),
+ args: Vec::new(),
+ title: "CuaTestHarness Tauri",
+ });
+ }
+
+ #[cfg(target_os = "macos")]
+ {
+ hosts.push(HostSpec {
+ name: "electron",
+ path: harness_app(
+ "harness-electron",
+ "CuaTestHarness.Electron.app/Contents/MacOS/Electron",
+ ),
+ args: vec!["--force-renderer-accessibility"],
+ title: "CuaTestHarness Electron",
+ });
+ hosts.push(HostSpec {
+ name: "tauri",
+ path: harness_app(
+ "harness-tauri",
+ "CuaTestHarness.Tauri.app/Contents/MacOS/CuaTestHarness.Tauri",
+ ),
+ args: Vec::new(),
+ title: "CuaTestHarness Tauri",
+ });
+ }
+
+ #[cfg(target_os = "linux")]
+ {
+ hosts.push(HostSpec {
+ name: "electron",
+ path: harness_app("harness-electron", "CuaTestHarness.Electron"),
+ args: vec![
+ "--no-sandbox",
+ "--disable-gpu",
+ "--force-renderer-accessibility",
+ ],
+ title: "CuaTestHarness Electron",
+ });
+ // WebKitGTK's AT-SPI tree is not exposed reliably by the headless
+ // Xvfb lane even though the Tauri window itself launches. Keep that
+ // lane available for a real Linux desktop with
+ // CUA_INCLUDE_TAURI_LINUX=1, while the default browser-equivalent
+ // matrix remains deterministic.
+ if std::env::var_os("CUA_INCLUDE_TAURI_LINUX").is_some() {
+ hosts.push(HostSpec {
+ name: "tauri",
+ path: harness_app("harness-tauri", "CuaTestHarness.Tauri"),
+ args: Vec::new(),
+ title: "CuaTestHarness Tauri",
+ });
+ }
+ }
+
+ hosts
+}
+
+fn spawn_driver() -> Option<McpDriver> {
+ #[cfg(target_os = "macos")]
+ {
+ return McpDriver::spawn_macos_daemon_proxy();
+ }
+ #[cfg(not(target_os = "macos"))]
+ {
+ McpDriver::spawn()
+ }
+}
+
+struct Fixture {
+ driver: McpDriver,
+ pid: u32,
+ wid: u64,
+ window_x: f64,
+ window_y: f64,
+ name: &'static str,
+}
+
+fn launch_host(spec: &HostSpec) -> Option<Fixture> {
+ if !spec.path.exists() {
+ eprintln!(
+ "[{}] fixture not staged at {:?}; skipping",
+ spec.name, spec.path
+ );
+ return None;
+ }
+
+ let mut driver = spawn_driver()?;
+ let mut command = Command::new(&spec.path);
+ command
+ .args(&spec.args)
+ .stdout(Stdio::null())
+ .stderr(Stdio::null());
+ let before_windows = driver
+ .call("list_windows", serde_json::json!({}))
+ .structured()["windows"]
+ .as_array()
+ .map(|windows| {
+ windows
+ .iter()
+ .filter_map(|window| window["window_id"].as_u64())
+ .collect::<std::collections::HashSet<_>>()
+ })
+ .unwrap_or_default();
+ let child = spawn_in_job(&mut command).ok()?;
+ let pid = child.id();
+ driver.reaper().push(child);
+
+ let deadline = Instant::now() + Duration::from_secs(15);
+ while Instant::now() < deadline {
+ let windows = driver.call("list_windows", serde_json::json!({}));
+ if let Some(items) = windows.structured()["windows"].as_array() {
+ if let Some(window) = items.iter().find(|window| {
+ window["window_id"]
+ .as_u64()
+ .map(|id| !before_windows.contains(&id))
+ .unwrap_or(false)
+ && window["title"].as_str().unwrap_or("").contains(spec.title)
+ }) {
+ if let Some(wid) = window["window_id"].as_u64() {
+ let actual_pid = window["pid"].as_u64().unwrap_or(pid as u64) as u32;
+ let bounds = &window["bounds"];
+ driver.reaper().track_pid(actual_pid);
+ let mut fixture = Fixture {
+ driver,
+ pid: actual_pid,
+ wid,
+ window_x: bounds["x"].as_f64().unwrap_or(0.0),
+ window_y: bounds["y"].as_f64().unwrap_or(0.0),
+ name: spec.name,
+ };
+ let ax_deadline = Instant::now() + Duration::from_secs(10);
+ while Instant::now() < ax_deadline {
+ if snapshot(&mut fixture)
+ .tree_text()
+ .contains("WEB_HARNESS_MARKER_v1")
+ {
+ return Some(fixture);
+ }
+ thread::sleep(Duration::from_millis(250));
+ }
+ panic!(
+ "{} fixture accessibility tree did not become ready",
+ spec.name
+ );
+ }
+ }
+ }
+ thread::sleep(Duration::from_millis(250));
+ }
+ panic!("{} fixture window did not appear", spec.name);
+}
+
+fn snapshot(fixture: &mut Fixture) -> ToolResponse {
+ fixture.driver.call(
+ "get_window_state",
+ serde_json::json!({
+ "pid": fixture.pid as i64,
+ "window_id": fixture.wid,
+ "capture_mode": "ax"
+ }),
+ )
+}
+
+fn window_origin(fixture: &Fixture, _state: &ToolResponse) -> (f64, f64) {
+ #[cfg(target_os = "macos")]
+ {
+ // macOS list_windows can report zero bounds for a daemon-proxied app;
+ // the AX window frame remains the authoritative screen origin.
+ if let Some(frame) = _state.structured()["elements"]
+ .as_array()
+ .and_then(|elements| {
+ elements
+ .iter()
+ .find(|element| element["role"].as_str() == Some("AXWindow"))
+ })
+ .and_then(|window| window["frame"].as_object())
+ {
+ return (
+ frame["x"].as_f64().unwrap_or(0.0),
+ frame["y"].as_f64().unwrap_or(0.0),
+ );
+ }
+ }
+ (fixture.window_x, fixture.window_y)
+}
+
+fn screenshot_scale(state: &ToolResponse) -> f64 {
+ let Some(width) = state.structured()["screenshot_width"].as_f64() else {
+ return 1.0;
+ };
+ let window_width = state.structured()["elements"]
+ .as_array()
+ .and_then(|elements| {
+ elements
+ .iter()
+ .find(|element| element["role"].as_str() == Some("AXWindow"))
+ })
+ .and_then(|window| window["frame"]["w"].as_f64())
+ .unwrap_or(0.0);
+ if window_width > 0.0 && width > window_width {
+ width / window_width
+ } else {
+ 1.0
+ }
+}
+
+fn require_element(snapshot: &ToolResponse, id: &str) -> u64 {
+ // Some WebKit/Chromium AX adapters preserve the DOM id as an annotation
+ // (`(calc-1 1)`) instead of emitting the common `id=...` form. Searching
+ // the visible label fallback handles adapters that omit both forms.
+ let visible_label = match id {
+ "calc-1" | "calc-2" | "calc-4" | "calc-plus" | "calc-equals" | "editor-document"
+ | "editor-save" | "scroll-tall" => id,
+ "keyboard-input" => "keyboard-input",
+ "drag-source" => "Drag source",
+ "drop-target" => "Drop target",
+ "btn-open-child-window" => "Open child window",
+ _ => id,
+ };
+ element_index_by_id(snapshot.tree_text(), id)
+ .or_else(|| element_index_containing(snapshot.tree_text(), visible_label))
+ .unwrap_or_else(|| {
+ panic!(
+ "{}: missing AX element {id:?}: {}",
+ "shared-web",
+ snapshot.tree_text()
+ )
+ })
+}
+
+fn element_center(snapshot: &ToolResponse, element_index: u64) -> (f64, f64) {
+ let frame = snapshot.structured()["elements"]
+ .as_array()
+ .and_then(|elements| {
+ elements
+ .iter()
+ .find(|element| element["element_index"].as_u64() == Some(element_index))
+ })
+ .and_then(|element| element["frame"].as_object())
+ .unwrap_or_else(|| panic!("element [{element_index}] has no frame"));
+ (
+ frame["x"].as_f64().unwrap_or(0.0) + frame["w"].as_f64().unwrap_or(0.0) / 2.0,
+ frame["y"].as_f64().unwrap_or(0.0) + frame["h"].as_f64().unwrap_or(0.0) / 2.0,
+ )
+}
+
+fn assert_tree_contains(fixture: &mut Fixture, marker: &str) {
+ let post = snapshot(fixture);
+ assert!(
+ post.tree_text().contains(marker),
+ "{}: application state did not reach {marker:?}: {}",
+ fixture.name,
+ post.tree_text()
+ );
+}
+
+fn click_ax(fixture: &mut Fixture, id: &str) {
+ let pre = snapshot(fixture);
+ let element_index = require_element(&pre, id);
+ let response = fixture.driver.call(
+ "click",
+ serde_json::json!({
+ "pid": fixture.pid as i64,
+ "window_id": fixture.wid,
+ "element_index": element_index,
+ "delivery_mode": "background"
+ }),
+ );
+ assert!(
+ !response.is_error(),
+ "{}: AX click {id} failed: {}",
+ fixture.name,
+ response.text()
+ );
+}
+
+#[test]
+#[ignore]
+fn shared_web_calculator_ax_route_is_state_verified() {
+ for spec in host_specs() {
+ let Some(mut fixture) = launch_host(&spec) else {
+ continue;
+ };
+ click_ax(&mut fixture, "calc-1");
+ click_ax(&mut fixture, "calc-2");
+ click_ax(&mut fixture, "calc-plus");
+ click_ax(&mut fixture, "calc-4");
+ click_ax(&mut fixture, "calc-equals");
+ assert_tree_contains(&mut fixture, "display=16");
+ println!("✅ {} calculator AX route", fixture.name);
+ }
+}
+
+#[test]
+#[ignore]
+fn shared_web_keyboard_routes_are_state_verified() {
+ for spec in host_specs() {
+ let Some(mut fixture) = launch_host(&spec) else {
+ continue;
+ };
+ let pre = snapshot(&mut fixture);
+ let input = require_element(&pre, "keyboard-input");
+ let (origin_x, origin_y) = window_origin(&fixture, &pre);
+ let scale = screenshot_scale(&pre);
+ let (screen_x, screen_y) = element_center(&pre, input);
+ let focus = fixture.driver.call(
+ "click",
+ serde_json::json!({
+ "pid": fixture.pid as i64,
+ "window_id": fixture.wid,
+ "x": (screen_x - origin_x) * scale,
+ "y": (screen_y - origin_y) * scale,
+ "delivery_mode": "background"
+ }),
+ );
+ assert!(
+ !focus.is_error(),
+ "{}: keyboard input focus click failed: {}",
+ fixture.name,
+ focus.text()
+ );
+ thread::sleep(Duration::from_millis(150));
+ let enter = fixture.driver.call(
+ "press_key",
+ serde_json::json!({
+ "pid": fixture.pid as i64,
+ "window_id": fixture.wid,
+ "element_index": input,
+ "key": "return",
+ "delivery_mode": "background"
+ }),
+ );
+ assert!(
+ !enter.is_error(),
+ "{}: return failed: {}",
+ fixture.name,
+ enter.text()
+ );
+ assert_tree_contains(&mut fixture, "key_state=enter");
+
+ let hotkey = fixture.driver.call(
+ "hotkey",
+ serde_json::json!({
+ "pid": fixture.pid as i64,
+ "window_id": fixture.wid,
+ "keys": ["ctrl", "shift", "7"],
+ "x": (screen_x - origin_x) * scale,
+ "y": (screen_y - origin_y) * scale,
+ "delivery_mode": "background"
+ }),
+ );
+ #[cfg(target_os = "windows")]
+ {
+ if hotkey.is_error()
+ || hotkey
+ .text()
+ .contains("Background delivery is not available")
+ {
+ println!(
+ "✅ {} keyboard AX route: background hotkey refused honestly",
+ fixture.name
+ );
+ continue;
+ }
+ }
+ assert!(
+ !hotkey.is_error(),
+ "{}: Ctrl+Shift+7 failed: {}",
+ fixture.name,
+ hotkey.text()
+ );
+ assert_tree_contains(&mut fixture, "key_state=hotkey");
+ println!("✅ {} keyboard AX routes", fixture.name);
+ }
+}
+
+#[test]
+#[ignore]
+fn shared_web_calculator_pixel_route_is_state_verified() {
+ for spec in host_specs() {
+ let Some(mut fixture) = launch_host(&spec) else {
+ continue;
+ };
+ for id in ["calc-1", "calc-2", "calc-plus", "calc-4", "calc-equals"] {
+ let pre = snapshot(&mut fixture);
+ let origin = window_origin(&fixture, &pre);
+ let scale = screenshot_scale(&pre);
+ let index = require_element(&pre, id);
+ let (screen_x, screen_y) = element_center(&pre, index);
+ let response = fixture.driver.call(
+ "click",
+ serde_json::json!({
+ "pid": fixture.pid as i64,
+ "window_id": fixture.wid,
+ "x": (screen_x - origin.0) * scale,
+ "y": (screen_y - origin.1) * scale,
+ "delivery_mode": "background"
+ }),
+ );
+ assert!(
+ !response.is_error(),
+ "{}: pixel click {id} failed: {}",
+ fixture.name,
+ response.text()
+ );
+ }
+ assert_tree_contains(&mut fixture, "display=16");
+ println!("✅ {} calculator pixel route", fixture.name);
+ }
+}
+
+#[test]
+#[ignore]
+fn shared_web_editor_and_scroll_are_state_verified() {
+ for spec in host_specs() {
+ let Some(mut fixture) = launch_host(&spec) else {
+ continue;
+ };
+ let pre = snapshot(&mut fixture);
+ let editor = require_element(&pre, "editor-document");
+ let text = fixture.driver.call(
+ "type_text",
+ serde_json::json!({
+ "pid": fixture.pid as i64,
+ "window_id": fixture.wid,
+ "element_index": editor,
+ "text": "CUA saved this note.",
+ "delivery_mode": "background"
+ }),
+ );
+ assert!(
+ !text.is_error(),
+ "{}: editor type_text failed: {}",
+ fixture.name,
+ text.text()
+ );
+ click_ax(&mut fixture, "editor-save");
+ assert_tree_contains(&mut fixture, "editor_status=saved:");
+
+ let scroll = require_element(&snapshot(&mut fixture), "scroll-tall");
+ let response = fixture.driver.call(
+ "scroll",
+ serde_json::json!({
+ "pid": fixture.pid as i64,
+ "window_id": fixture.wid,
+ "element_index": scroll,
+ "direction": "down",
+ "by": "page",
+ "amount": 4,
+ "delivery_mode": "background"
+ }),
+ );
+ #[cfg(target_os = "windows")]
+ {
+ if response.is_error()
+ || response
+ .text()
+ .contains("Background delivery is not available")
+ {
+ println!(
+ "✅ {} editor + scroll: background scroll refused honestly",
+ fixture.name
+ );
+ continue;
+ }
+ }
+ assert!(
+ !response.is_error(),
+ "{}: scroll failed: {}",
+ fixture.name,
+ response.text()
+ );
+ let post = snapshot(&mut fixture);
+ let offset = post
+ .tree_text()
+ .lines()
+ .find_map(|line| line.split("scroll_offset=").nth(1))
+ .and_then(|tail| tail.split(|ch: char| !ch.is_ascii_digit()).next())
+ .and_then(|value| value.parse::<u64>().ok())
+ .unwrap_or(0);
+ assert!(
+ offset > 0,
+ "{}: successful background scroll did not advance the external scroll oracle: {}",
+ fixture.name,
+ post.tree_text()
+ );
+ println!("✅ {} editor + scroll state oracles", fixture.name);
+ }
+}
+
+#[test]
+#[ignore]
+fn shared_web_child_window_and_drag_have_external_oracles() {
+ for spec in host_specs() {
+ let Some(mut fixture) = launch_host(&spec) else {
+ continue;
+ };
+ let pre = snapshot(&mut fixture);
+ let (window_x, window_y) = window_origin(&fixture, &pre);
+ let scale = screenshot_scale(&pre);
+ let source = require_element(&pre, "drag-source");
+ let frame = pre.structured()["elements"]
+ .as_array()
+ .and_then(|elements| {
+ elements
+ .iter()
+ .find(|element| element["element_index"].as_u64() == Some(source))
+ })
+ .and_then(|element| element["frame"].as_object())
+ .unwrap_or_else(|| panic!("{}: drag-source has no frame", fixture.name));
+ let x = (frame["x"].as_f64().unwrap_or(0.0) - window_x
+ + frame["w"].as_f64().unwrap_or(0.0) / 2.0)
+ * scale;
+ let y = (frame["y"].as_f64().unwrap_or(0.0) - window_y
+ + frame["h"].as_f64().unwrap_or(0.0) / 2.0)
+ * scale;
+ let target_index = require_element(&pre, "drop-target");
+ let target = pre.structured()["elements"]
+ .as_array()
+ .and_then(|elements| {
+ elements
+ .iter()
+ .find(|element| element["element_index"].as_u64() == Some(target_index))
+ })
+ .and_then(|element| element["frame"].as_object())
+ .unwrap_or_else(|| panic!("{}: drop-target has no frame", fixture.name));
+ let tx = (target["x"].as_f64().unwrap_or(0.0) - window_x
+ + target["w"].as_f64().unwrap_or(0.0) / 2.0)
+ * scale;
+ let ty = (target["y"].as_f64().unwrap_or(0.0) - window_y
+ + target["h"].as_f64().unwrap_or(0.0) / 2.0)
+ * scale;
+ #[cfg(not(target_os = "macos"))]
+ let _ = (x, y, tx, ty);
+ #[cfg(target_os = "macos")]
+ {
+ let drag = fixture.driver.call(
+ "drag",
+ serde_json::json!({
+ "pid": fixture.pid as i64,
+ "window_id": fixture.wid,
+ "from_x": x,
+ "from_y": y,
+ "to_x": tx,
+ "to_y": ty,
+ "duration_ms": 500,
+ "delivery_mode": "foreground"
+ }),
+ );
+ assert!(
+ !drag.is_error(),
+ "{}: drag failed: {}",
+ fixture.name,
+ drag.text()
+ );
+ assert_tree_contains(&mut fixture, "drag_status=dropped");
+ }
+
+ click_ax(&mut fixture, "btn-open-child-window");
+ assert_tree_contains(&mut fixture, "child_windows=1");
+ println!("✅ {} child-window + drag state oracles", fixture.name);
+ }
+}
diff --git a/libs/cua-driver/tests/fixtures/apps/cross-platform/electron/build.sh b/libs/cua-driver/tests/fixtures/apps/cross-platform/electron/build.sh
index fb9b73204a..bf03e88064 100755
--- a/libs/cua-driver/tests/fixtures/apps/cross-platform/electron/build.sh
+++ b/libs/cua-driver/tests/fixtures/apps/cross-platform/electron/build.sh
@@ -36,11 +36,74 @@ if [ "$platform" = "Darwin" ]; then
else
electronBin="$elecDir/node_modules/electron/dist/electron"
fi
-if [ ! -x "$electronBin" ]; then
+electron_install_complete() {
+ if [ "$platform" = "Darwin" ]; then
+ [ -x "$electronBin" ] &&
+ [ -d "$elecDir/node_modules/electron/dist/Electron.app/Contents/Frameworks" ] &&
+ [ -f "$elecDir/node_modules/electron/dist/version" ] &&
+ [ -f "$elecDir/node_modules/electron/path.txt" ]
+ else
+ [ -x "$electronBin" ] &&
+ [ -f "$elecDir/node_modules/electron/dist/version" ] &&
+ [ -f "$elecDir/node_modules/electron/path.txt" ]
+ fi
+}
+
+if ! electron_install_complete; then
echo "[INSTALL] npm install (first run)..."
npm install --silent
fi
+# npm 11 can leave package lifecycle scripts pending approval. In that case
+# npm reports success but Electron's postinstall has not downloaded the real
+# runtime. Run the pinned package installer explicitly after verifying the
+# runtime shape so a tiny executable stub cannot be staged as a harness.
+if ! electron_install_complete; then
+ echo "[INSTALL] Electron runtime incomplete; running the pinned installer..."
+ rm -rf "$elecDir/node_modules/electron/dist"
+ node "$elecDir/node_modules/electron/install.js"
+fi
+
+# Node 26 + the current extract-zip dependency can still leave the macOS
+# Frameworks payload out while returning success. Fall back to extracting the
+# same official artifact downloaded by @electron/get; this is deterministic
+# and works with the zip layout used by the pinned Electron version.
+if ! electron_install_complete; then
+ echo "[INSTALL] Electron helper produced an incomplete archive; extracting the official artifact..."
+ electron_platform="linux"
+ electron_path="electron"
+ if [ "$platform" = "Darwin" ]; then
+ electron_platform="darwin"
+ electron_path="Electron.app/Contents/MacOS/Electron"
+ fi
+ electron_zip="$({
+ ELECTRON_PLATFORM="$electron_platform" node <<'NODE'
+const { downloadArtifact } = require('@electron/get');
+const platform = process.env.ELECTRON_PLATFORM;
+downloadArtifact({
+ version: require('./node_modules/electron/package.json').version,
+ artifactName: 'electron',
+ platform,
+ arch: process.arch,
+}).then(path => process.stdout.write(path)).catch(error => {
+ console.error(error.stack || error);
+ process.exit(1);
+});
+NODE
+ })"
+ rm -rf "$elecDir/node_modules/electron/dist"
+ mkdir -p "$elecDir/node_modules/electron/dist"
+ unzip -q "$electron_zip" -d "$elecDir/node_modules/electron/dist"
+ printf '%s' "$electron_path" > "$elecDir/node_modules/electron/path.txt"
+ printf 'v%s' "$(node -p "require('./node_modules/electron/package.json').version")" \
+ > "$elecDir/node_modules/electron/dist/version"
+fi
+
+if ! electron_install_complete; then
+ echo "[ERROR] Electron runtime is incomplete after install" >&2
+ exit 1
+fi
+
rm -rf "$outDir"
mkdir -p "$outDir"
diff --git a/libs/cua-driver/tests/fixtures/shared/scenarios.json b/libs/cua-driver/tests/fixtures/shared/scenarios.json
index 1d402bc28d..564f7ba896 100644
--- a/libs/cua-driver/tests/fixtures/shared/scenarios.json
+++ b/libs/cua-driver/tests/fixtures/shared/scenarios.json
@@ -187,10 +187,22 @@
"btn-increment",
"btn-reset",
"lbl-counter",
+ "calc-1",
+ "calc-2",
+ "calc-4",
+ "calc-plus",
+ "calc-equals",
+ "calc-display",
"txt-input",
"lbl-input-mirror",
+ "editor-document",
+ "editor-save",
+ "editor-status",
"sld-value",
"lbl-slider-value",
+ "drag-source",
+ "drop-target",
+ "drag-status",
"border-click-target",
"lbl-last-action",
"lbl-click-count",
diff --git a/libs/cua-driver/tests/fixtures/shared/web/index.html b/libs/cua-driver/tests/fixtures/shared/web/index.html
index 036f0eee0d..d7e00af120 100644
--- a/libs/cua-driver/tests/fixtures/shared/web/index.html
+++ b/libs/cua-driver/tests/fixtures/shared/web/index.html
@@ -42,6 +42,18 @@
</div>
</fieldset>
+ <fieldset>
+ <legend>calculator_task</legend>
+ <div class="row">
+ <button id="calc-1" data-cua-id="calc-1" aria-label="calc-1 1">1</button>
+ <button id="calc-2" data-cua-id="calc-2" aria-label="calc-2 2">2</button>
+ <button id="calc-4" data-cua-id="calc-4" aria-label="calc-4 4">4</button>
+ <button id="calc-plus" data-cua-id="calc-plus" aria-label="calc-plus plus">+</button>
+ <button id="calc-equals" data-cua-id="calc-equals" aria-label="calc-equals equals">=</button>
+ <span class="mirror" id="calc-display" data-cua-id="calc-display">display=0</span>
+ </div>
+ </fieldset>
+
<fieldset>
<legend>text_input</legend>
<div class="row">
@@ -50,6 +62,24 @@
</div>
</fieldset>
+ <fieldset>
+ <legend>keyboard_task</legend>
+ <div class="row">
+ <input type="text" id="keyboard-input" data-cua-id="keyboard-input" autofocus
+ aria-label="keyboard-input" placeholder="keyboard input" />
+ <span class="mirror" id="keyboard-status" data-cua-id="keyboard-status">key_state=none</span>
+ </div>
+ </fieldset>
+
+ <fieldset>
+ <legend>text_editor_task</legend>
+ <div class="row">
+ <textarea id="editor-document" data-cua-id="editor-document" aria-label="editor-document" rows="3" cols="42">Initial conformance text.\nStatus: DRAFT\n</textarea>
+ <button id="editor-save" data-cua-id="editor-save" aria-label="editor-save Save">Save</button>
+ <span class="mirror" id="editor-status" data-cua-id="editor-status">editor_status=draft</span>
+ </div>
+ </fieldset>
+
<fieldset>
<legend>slider</legend>
<div class="row">
@@ -59,12 +89,22 @@
</div>
</fieldset>
+ <fieldset>
+ <legend>drag_task</legend>
+ <div class="row">
+ <div id="drag-source" data-cua-id="drag-source" aria-label="drag-source" style="position:fixed;left:40px;top:80px;width:220px;height:100px;display:flex;align-items:center;justify-content:center;background:#1268d6;color:white;user-select:none;touch-action:none;z-index:10;">Drag source</div>
+ <div id="drop-target" data-cua-id="drop-target" aria-label="drop-target" style="position:fixed;left:520px;top:520px;width:220px;height:100px;display:flex;align-items:center;justify-content:center;background:#178a38;color:white;z-index:10;">Drop target</div>
+ <span class="mirror" id="drag-status" data-cua-id="drag-status">drag_status=idle</span>
+ </div>
+ </fieldset>
+
<fieldset>
<legend>scroll_target</legend>
<div class="row">
- <div id="scroll-tall" data-cua-id="scroll-tall"
+ <div id="scroll-tall" data-cua-id="scroll-tall" aria-label="scroll-tall"
style="height:120px;width:260px;overflow-y:auto;border:1px solid #ccc;padding:4px;">
<div id="scroll-top" data-cua-id="scroll-top">SCROLL_TOP_MARKER_v1</div>
+ <div data-cua-id="scroll-target-label">scroll-tall</div>
<div id="scroll-lines"></div>
<div id="scroll-bottom" data-cua-id="scroll-bottom">SCROLL_BOTTOM_MARKER_v1</div>
</div>
@@ -125,6 +165,7 @@
// ----- state -----
let counter = 0;
let clickCount = 0;
+ let calculatorExpression = '';
function $(id) { return document.getElementById(id); }
function updateChkState() {
@@ -142,10 +183,44 @@
$('lbl-counter').textContent = 'counter=0';
});
+ // Calculator task oracle: the visible display is application state, not a
+ // driver response. It intentionally uses separate buttons so both AX and
+ // pixel-coordinate delivery can be tested against the same result.
+ ['1', '2', '4'].forEach(digit => {
+ $('calc-' + digit).addEventListener('click', () => {
+ calculatorExpression += digit;
+ $('calc-display').textContent = `display=${calculatorExpression}`;
+ });
+ });
+ $('calc-plus').addEventListener('click', () => {
+ calculatorExpression += '+';
+ $('calc-display').textContent = `display=${calculatorExpression}`;
+ });
+ $('calc-equals').addEventListener('click', () => {
+ const parts = calculatorExpression.split('+').map(Number);
+ const result = parts.length === 2 && parts.every(Number.isFinite) ? parts[0] + parts[1] : 'error';
+ calculatorExpression = String(result);
+ $('calc-display').textContent = `display=${calculatorExpression}`;
+ });
+
+ $('editor-save').addEventListener('click', () => {
+ const value = $('editor-document').value;
+ localStorage.setItem('cua-editor-document', value);
+ $('editor-status').textContent = `editor_status=saved:${value.endsWith('\\n') ? 'newline' : 'exact'}`;
+ });
+
$('txt-input').addEventListener('input', e => {
$('lbl-input-mirror').textContent = `mirror=${e.target.value}`;
});
+ $('keyboard-input').addEventListener('keydown', e => {
+ if (e.ctrlKey && e.shiftKey && e.code === 'Digit7') {
+ $('keyboard-status').textContent = 'key_state=hotkey';
+ } else if (e.key === 'Enter') {
+ $('keyboard-status').textContent = 'key_state=enter';
+ }
+ });
+
$('sld-value').addEventListener('input', e => {
$('lbl-slider-value').textContent = `slider_value=${e.target.value}`;
});
@@ -163,6 +238,27 @@
});
})();
+ (function () {
+ const source = $('drag-source');
+ const target = $('drop-target');
+ let dragging = false;
+ source.addEventListener('pointerdown', event => {
+ dragging = true;
+ source.setPointerCapture(event.pointerId);
+ $('drag-status').textContent = 'drag_status=started';
+ });
+ source.addEventListener('pointermove', event => {
+ if (dragging) $('drag-status').textContent = 'drag_status=moved';
+ });
+ source.addEventListener('pointerup', event => {
+ dragging = false;
+ const rect = target.getBoundingClientRect();
+ const inside = event.clientX >= rect.left && event.clientX <= rect.right &&
+ event.clientY >= rect.top && event.clientY <= rect.bottom;
+ $('drag-status').textContent = inside ? 'drag_status=dropped' : 'drag_status=outside';
+ });
+ })();
+
const target = $('click-target');
target.addEventListener('mousedown', e => {
clickCount++;