Skip to content

Commit 09c1397

Browse files
thymikeeclaude
andcommitted
fix(ios): enforce the sole-screen device rule at the synthesis boundary
Review follow-up. The sampled gesture path passed an unresolved window to synthesis without the iPhone check, so a single-screen iPad could route there. RunnerResolveSoleScreenDisplayID now refuses anything but an iPhone with one screen. A context built on the sole-screen route also reports accessibility unavailable, so scroll skips keyboard probes that would fail on the same tree. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e9f7502 commit 09c1397

4 files changed

Lines changed: 36 additions & 5 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ extension RunnerTests {
387387
policy: SynthesizedGesturePolicy
388388
) -> SynthesizedCoordinateContext? {
389389
#if os(iOS)
390-
let health = mainOwned.accessibilityHealth
390+
var health = mainOwned.accessibilityHealth
391391
let window: XCUIElement?
392392
let referenceFrame: CGRect
393393
if let resolved = resolveRunnerWindowElement(app: app) {
@@ -396,6 +396,9 @@ extension RunnerTests {
396396
} else if let soleScreenFrame = soleScreenReferenceFrame(app: app) {
397397
window = nil
398398
referenceFrame = soleScreenFrame
399+
// The windows query just failed on this tree, so this gesture's keyboard probes and XCTest
400+
// fallbacks would fail on it too, after XCTest's own retries.
401+
health = .unavailable
399402
} else {
400403
return nil
401404
}

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ FOUNDATION_EXPORT NSString * _Nullable RunnerResolveWindowDisplayID(
7878
);
7979

8080
// Reads the display ID of the device's only screen, for a gesture whose app window XCTest cannot
81-
// resolve because the app's accessibility tree is too deep to serialize. With exactly one screen
82-
// that screen hosts the app, so no window is needed to name it; with any other count this returns
83-
// a message and leaves `displayID` untouched, because only a window can say which panel lights the
84-
// app.
81+
// resolve because the app's accessibility tree is too deep to serialize. On an iPhone with exactly
82+
// one screen that screen hosts the full-screen app, so no window is needed to name it. Anywhere else
83+
// this returns a message and leaves `displayID` untouched: an iPad can show the app in part of its
84+
// screen, and only a window can say which panel lights a foldable's app.
8585
FOUNDATION_EXPORT NSString * _Nullable RunnerResolveSoleScreenDisplayID(NSUInteger *displayID);
8686

8787
FOUNDATION_EXPORT NSString * _Nullable RunnerRequireClass(

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.m‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#import <CoreGraphics/CoreGraphics.h>
44
#import <XCTest/XCTest.h>
55
#import <math.h>
6+
#if TARGET_OS_IOS
7+
#import <UIKit/UIKit.h>
8+
#endif
69

710
NSString * _Nullable RunnerResolveXCTestEventBridge(
811
id application,
@@ -216,6 +219,14 @@ BOOL RunnerResolveApplicationScreen(
216219
// its frame is read before its screen, and a window that answers empty or raises fails closed with
217220
// the same reasons the application walk gives.
218221
NSString * _Nullable RunnerResolveSoleScreenDisplayID(NSUInteger *displayID) {
222+
#if TARGET_OS_IOS
223+
// Only an iPhone keeps every app full-screen; an iPad can show one in part of its only screen.
224+
if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
225+
return @"private XCTest event synthesis unavailable: no resolved application window, and only an iPhone routes to its sole screen";
226+
}
227+
#else
228+
return @"private XCTest event synthesis unavailable: no resolved application window";
229+
#endif
219230
__block NSUInteger screenCount = 0;
220231
__block NSUInteger readDisplayID = 0;
221232
NSString *exception = [RunnerObjCExceptionCatcher catchException:^{

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+SynthesizedInteractionTests.swift‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ extension RunnerTests {
1919
}
2020
}
2121

22+
#if os(iOS)
23+
/// The sole-screen route is the boundary every window-less gesture crosses, so it decides the device
24+
/// rule itself: an iPhone with one screen names that screen, and an iPad refuses, because it can show
25+
/// the app in part of its screen. Run on both device families to cover both answers.
26+
func testSoleScreenDisplayIDIsNamedOnlyForAnIPhoneWithOneScreen() {
27+
var displayID: UInt = 0
28+
let refusal = RunnerResolveSoleScreenDisplayID(&displayID)
29+
if UIDevice.current.userInterfaceIdiom == .phone, XCUIScreen.screens.count == 1 {
30+
XCTAssertNil(refusal)
31+
XCTAssertNotEqual(displayID, 0)
32+
} else {
33+
XCTAssertNotNil(refusal)
34+
XCTAssertEqual(displayID, 0)
35+
}
36+
}
37+
#endif
38+
2239
func testSoleScreenReferenceFrameRefusesAnUnknownOrientationOrAnEmptyScreen() {
2340
XCTAssertNil(
2441
Self.soleScreenReferenceFrame(

0 commit comments

Comments
 (0)