Skip to content

Commit f552c5e

Browse files
committed
fix(ios): rotate synthesized gestures in the capture viewport
The synthesized lane derived its rotation frame from XCUIScreen.main.screenshot() image size while capture normalizes node rects into the acquisition viewport (app.frame). On an iPhone Duo in the open pose the runner's main screen is the dark outer panel, so dispatch was not the inverse of capture and taps drifted by a constant offset (hit the Home tab by luck, missed Settings). Use app.frame as the reference frame for every synthesized lane so dispatch is capture's inverse on any panel and orientation, and assert that inverse as a round-trip unit test including the Duo inner panel (669x951, rot90). Drops the per-gesture main-screen screenshot.
1 parent 45e4c59 commit f552c5e

1 file changed

Lines changed: 43 additions & 106 deletions

File tree

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

Lines changed: 43 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,9 @@ extension RunnerTests {
615615
hint: "Retry after the app is foregrounded, or use a plain screenshot to choose coordinates."
616616
)
617617
}
618-
let frame = context.referenceFrame
619618
let point = CoordinateSpaceRotation.native(
620619
point: CGPoint(x: x, y: y),
621-
in: frame,
620+
in: context.referenceFrame,
622621
interfaceOrientation: orientation
623622
)
624623
if let message = RunnerSynthesizedGesture.synthesizeTap(
@@ -837,10 +836,14 @@ extension RunnerTests {
837836
let orientation = Int(
838837
RunnerSynthesizedGesture.interfaceOrientation(forApplication: app)
839838
)
840-
guard let referenceFrame = orientedSynthesizedScreenshotReferenceFrame(
841-
screenshotSize: XCUIScreen.main.screenshot().image.size,
842-
interfaceOrientation: orientation
843-
) else {
839+
// The rotation frame must be the exact frame capture normalized node rects into
840+
// (SnapshotGeometrySpace.normalized uses the acquisition viewport = app.frame), so dispatch
841+
// is that map's inverse on every panel. XCUIScreen.main is not it: on a foldable's lit inner
842+
// panel it still reports the dark outer panel, drifting every synthesized gesture.
843+
let referenceFrame = app.frame
844+
guard referenceFrame.width.isFinite, referenceFrame.height.isFinite,
845+
referenceFrame.width > 0, referenceFrame.height > 0
846+
else {
844847
return nil
845848
}
846849
return SynthesizedCoordinateContext(
@@ -854,36 +857,6 @@ extension RunnerTests {
854857
#endif
855858
}
856859

857-
func orientedSynthesizedScreenshotReferenceFrame(
858-
screenshotSize: CGSize,
859-
interfaceOrientation: Int
860-
) -> CGRect? {
861-
// Physical iOS screenshots can retain portrait dimensions after the interface rotates,
862-
// while accessibility frames remain in the logical landscape coordinate space.
863-
guard screenshotSize.width.isFinite, screenshotSize.height.isFinite,
864-
screenshotSize.width > 0,
865-
screenshotSize.height > 0
866-
else {
867-
return nil
868-
}
869-
let isLandscape = interfaceOrientation == RunnerInterfaceOrientation.landscapeLeft
870-
|| interfaceOrientation == RunnerInterfaceOrientation.landscapeRight
871-
let isPortrait = interfaceOrientation == RunnerInterfaceOrientation.portrait
872-
|| interfaceOrientation == RunnerInterfaceOrientation.portraitUpsideDown
873-
let width: CGFloat
874-
let height: CGFloat
875-
if isLandscape {
876-
width = max(screenshotSize.width, screenshotSize.height)
877-
height = min(screenshotSize.width, screenshotSize.height)
878-
} else if isPortrait {
879-
width = min(screenshotSize.width, screenshotSize.height)
880-
height = max(screenshotSize.width, screenshotSize.height)
881-
} else {
882-
width = screenshotSize.width
883-
height = screenshotSize.height
884-
}
885-
return CGRect(x: 0, y: 0, width: width, height: height)
886-
}
887860

888861
func keyboardAvoidingSynthesizedDragPoints(
889862
app: XCUIApplication,
@@ -1153,77 +1126,41 @@ extension RunnerTests {
11531126
#endif
11541127

11551128
#if AGENT_DEVICE_RUNNER_UNIT_TESTS
1156-
func testSynthesizedScreenshotReferenceFrameUsesScreenshotSize() throws {
1157-
let resolved = try XCTUnwrap(
1158-
orientedSynthesizedScreenshotReferenceFrame(
1159-
screenshotSize: CGSize(width: 430, height: 932),
1160-
interfaceOrientation: RunnerInterfaceOrientation.portrait
1161-
)
1162-
)
1163-
1164-
XCTAssertEqual(resolved, CGRect(x: 0, y: 0, width: 430, height: 932))
1165-
}
1166-
1167-
func testOrientedSynthesizedScreenshotReferenceFrameUsesLandscapeLogicalDimensions() {
1168-
let portraitCapture = CGSize(width: 430, height: 932)
1169-
let landscapeCapture = CGSize(width: 932, height: 430)
1170-
1171-
for orientation in [
1172-
RunnerInterfaceOrientation.landscapeLeft,
1173-
RunnerInterfaceOrientation.landscapeRight,
1174-
] {
1175-
XCTAssertEqual(
1176-
orientedSynthesizedScreenshotReferenceFrame(
1177-
screenshotSize: portraitCapture,
1178-
interfaceOrientation: orientation
1179-
),
1180-
CGRect(x: 0, y: 0, width: 932, height: 430)
1181-
)
1182-
XCTAssertEqual(
1183-
orientedSynthesizedScreenshotReferenceFrame(
1184-
screenshotSize: landscapeCapture,
1185-
interfaceOrientation: orientation
1186-
),
1187-
CGRect(x: 0, y: 0, width: 932, height: 430)
1188-
)
1189-
}
1190-
1191-
for orientation in [
1192-
RunnerInterfaceOrientation.portrait,
1193-
RunnerInterfaceOrientation.portraitUpsideDown,
1194-
] {
1195-
XCTAssertEqual(
1196-
orientedSynthesizedScreenshotReferenceFrame(
1197-
screenshotSize: portraitCapture,
1198-
interfaceOrientation: orientation
1199-
),
1200-
CGRect(x: 0, y: 0, width: 430, height: 932)
1201-
)
1202-
XCTAssertEqual(
1203-
orientedSynthesizedScreenshotReferenceFrame(
1204-
screenshotSize: landscapeCapture,
1205-
interfaceOrientation: orientation
1206-
),
1207-
CGRect(x: 0, y: 0, width: 430, height: 932)
1208-
)
1129+
func testSynthesizedDispatchInvertsCaptureOnEveryInterfaceOrientation() {
1130+
let frames = [
1131+
CGRect(x: 0, y: 0, width: 430, height: 932),
1132+
// iPhone Duo inner panel: 669x951 portrait app frame on a rot90 panel whose
1133+
// windows report landscape 951x669 frames in the display space.
1134+
CGRect(x: 0, y: 0, width: 669, height: 951),
1135+
]
1136+
for frame in frames {
1137+
for orientation in [
1138+
RunnerInterfaceOrientation.portrait,
1139+
RunnerInterfaceOrientation.portraitUpsideDown,
1140+
RunnerInterfaceOrientation.landscapeLeft,
1141+
RunnerInterfaceOrientation.landscapeRight,
1142+
] {
1143+
let corners = [
1144+
CGPoint(x: frame.minX + 1, y: frame.minY + 1),
1145+
CGPoint(x: frame.midX, y: frame.midY),
1146+
CGPoint(x: frame.maxX - 2, y: frame.maxY - 3),
1147+
]
1148+
for displayed in corners {
1149+
let captured = CoordinateSpaceRotation.oriented(
1150+
point: displayed,
1151+
in: frame,
1152+
interfaceOrientation: orientation
1153+
)
1154+
let dispatched = CoordinateSpaceRotation.native(
1155+
point: captured,
1156+
in: frame,
1157+
interfaceOrientation: orientation
1158+
)
1159+
XCTAssertEqual(dispatched.x, displayed.x, accuracy: 0.001, "orientation \(orientation)")
1160+
XCTAssertEqual(dispatched.y, displayed.y, accuracy: 0.001, "orientation \(orientation)")
1161+
}
1162+
}
12091163
}
1210-
1211-
XCTAssertEqual(
1212-
orientedSynthesizedScreenshotReferenceFrame(
1213-
screenshotSize: landscapeCapture,
1214-
interfaceOrientation: RunnerInterfaceOrientation.unknown
1215-
),
1216-
CGRect(x: 0, y: 0, width: 932, height: 430)
1217-
)
1218-
}
1219-
1220-
func testSynthesizedScreenshotReferenceFrameRejectsInvalidSize() {
1221-
XCTAssertNil(
1222-
orientedSynthesizedScreenshotReferenceFrame(
1223-
screenshotSize: CGSize(width: CGFloat.infinity, height: 932),
1224-
interfaceOrientation: RunnerInterfaceOrientation.portrait
1225-
)
1226-
)
12271164
}
12281165

12291166
func testPlannedMultiTouchGestureAcceptsMatchingInBoundsTrajectories() throws {

0 commit comments

Comments
 (0)