feat(e2e): give the macOS test window a class by its accessibility subrole

--class was accepted and ignored on macOS, so the scenarios that match a window by
a class could not run. The test window now sets its accessibility subrole to the
class (NSWindow setAccessibilitySubrole), and the host passes the app id of spawn as
--class.
This commit is contained in:
LGUG2Z committed 2026-11-06 14:49:36 -08:00
1 parent 1849547153
commit bb3c986f26
4 files changed
+15 -2

No files matched your search

+3
View File
@@ -23,6 +23,9 @@ objc2-app-kit = { version = "0.3", default-features = false, features = [
"NSScreen",
"NSGraphics",
"NSEvent",
"NSAccessibility",
"NSAccessibilityConstants",
"NSAccessibilityProtocols",
"NSRunningApplication",
"objc2-core-foundation",
"libc",
+6
View File
@@ -15,6 +15,7 @@ use std::time::Instant;
use objc2::MainThreadMarker;
use objc2::MainThreadOnly;
use objc2::rc::Retained;
use objc2_app_kit::NSAccessibility;
use objc2_app_kit::NSApplication;
use objc2_app_kit::NSApplicationActivationPolicy;
use objc2_app_kit::NSBackingStoreType;
@@ -154,6 +155,11 @@ pub fn run(options: cli::Options) {
// SAFETY: this program owns the window, so a close does not release it a second time.
unsafe { window.setReleasedWhenClosed(false) };
window.setTitle(&NSString::from_str(&options.title));
if let Some(class) = &options.class {
// a macOS window has no class: the daemon takes the accessibility subrole of a window for
// it, which a program is free to name as it likes
window.setAccessibilitySubrole(Some(&NSString::from_str(class)));
}
if let Some(rgb) = options.color {
window.setBackgroundColor(Some(&color(rgb)));
}
+2 -1
View File
@@ -9,7 +9,8 @@ pub struct Options {
pub title: String,
/// The size of the window, in pixels (points on macOS).
pub size: (i32, i32),
/// The window class on Windows; no other platform has one, and ignores it.
/// The window class on Windows; on macOS, which has none, the accessibility subrole of the
/// window, which is what the daemon takes for one; no other platform has one, and ignores it.
pub class: Option<String>,
/// `0xRRGGBB`.
pub color: Option<u32>,
+4 -1
View File
@@ -254,8 +254,11 @@ class MacosPlatform:
rename_to: str | None = None,
after: float = 0,
) -> Client:
# `app_id` is a window class, which a macOS window does not have: it is not passed
args = ["--title", title]
if app_id is not None:
# a macOS window has no class: the daemon takes its accessibility subrole for one, which
# the test window is given as this
args += ["--class", app_id]
if rename_to is not None:
# the window gives itself this title `after` seconds from now
args += ["--rename-to", rename_to, "--after", str(after)]