Repository navigation
fix(ios): place a matched alert window in the box it sits in #4113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,7 +54,6 @@ | |
| viewport: CGRect | ||
| ) -> [XCUIElementSnapshot] { | ||
| let frame = snapshot.frame | ||
| let hostWindow = snapshot.elementType == .window && SnapshotGeometry.isPositiveFinite(frame) ? frame : viewport | ||
| let matches: Bool | ||
| switch source { | ||
| case .blockingSystemModal: | ||
|
|
@@ -66,8 +65,10 @@ | |
| case .dismissPopup: | ||
| matches = snapshot.elementType == .window && containsDismissPopupMarker(snapshot) | ||
| } | ||
| if matches && Self.isPlaced(frame, in: hostWindow) { return [snapshot] } | ||
| return snapshot.children.flatMap { alertSnapshots(in: $0, source: source, viewport: hostWindow) } | ||
| if matches && Self.isPlaced(frame, in: viewport) { return [snapshot] } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Minor · Off-screen dismiss-popup windows are rejected only at the level the match happens; a marked window nested inside an off-screen window is still accepted
Suggested change Decide whether a marked window nested inside an off-screen window may be answered, and encode it: either gate a window's right to become the child box on it being placed in the box it sits in (without breaking the unplaced inner-panel foldable window) or add a fixture test for a marked window inside an off-screen window. Detailspersona: Reply Useful? Reply There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Nit · In Suggested change Rename the new Detailspersona: Reply Useful? Reply |
||
| // A window is placed in the box it sits in, and is itself the box of what it hosts. | ||
| let childViewport = snapshot.elementType == .window && SnapshotGeometry.isPositiveFinite(frame) ? frame : viewport | ||
|
thymikee marked this conversation as resolved.
Resolved
|
||
| return snapshot.children.flatMap { alertSnapshots(in: $0, source: source, viewport: childViewport) } | ||
|
Check warning on line 71 in apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift
|
||
| } | ||
|
|
||
| private func containsDismissPopupMarker(_ snapshot: XCUIElementSnapshot) -> Bool { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -104,6 +104,39 @@ | |||||||||||||||||||
| XCTAssertEqual(app.staticTexts["agent-device-alert-actions"].label, "First actions: 0; replacement actions: 0") | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @MainActor | ||||||||||||||||||||
| func testAlertActivationRefusesAnUnreadableHostWindowWithoutTapping() throws { | ||||||||||||||||||||
| app.launchArguments = ["--agent-device-alert-replacement-regression"] | ||||||||||||||||||||
| app.launch() | ||||||||||||||||||||
| defer { | ||||||||||||||||||||
| invalidateCachedTarget(reason: "unit_test_cleanup") | ||||||||||||||||||||
| app.terminate() | ||||||||||||||||||||
| } | ||||||||||||||||||||
| XCTAssertTrue(app.alerts.firstMatch.waitForFixtureExistence(timeout: appExistenceTimeout)) | ||||||||||||||||||||
| let resolved = try resolveAlertBeforeTheCommand() | ||||||||||||||||||||
| let alert = RunnerAlert( | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Nit · New unreadable-host-window test relies on XCTExpectFailure absorbing a second, unrelated XCTest failure
Suggested change
Suggested change Keep the refusal assertion, and make the unreadable window a value the test controls (for example a stub or override that returns CGRect.null for the window frame) so no XCTest issue has to be absorbed by XCTExpectFailure. DetailsThe behavior the test pins (a refused tap when the host window cannot be read, so the tap is not routed through the owner app's first window on a foldable) is worth keeping; only the expected-failure matching is fragile. Also raised hereAlso raised at this location by senior-developer: New test matches an XCTest issue by error text rather than by a typed reason — persona: Reply Useful? Reply |
||||||||||||||||||||
| root: resolved.root, | ||||||||||||||||||||
| ownerApp: resolved.ownerApp, | ||||||||||||||||||||
| buttons: resolved.buttons, | ||||||||||||||||||||
| source: resolved.source, | ||||||||||||||||||||
| window: app.windows.matching(identifier: "agent-device-missing-window").firstMatch | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| let button = try XCTUnwrap(alert.buttons.first { $0.label == "OK" }) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| let frame = button.frame | ||||||||||||||||||||
| let options = XCTExpectedFailure.Options() | ||||||||||||||||||||
| options.issueMatcher = { $0.compactDescription.contains("agent-device-missing-window") } | ||||||||||||||||||||
| var outcome: RunnerInteractionOutcome? | ||||||||||||||||||||
| XCTExpectFailure("The unreadable window is the condition under test", options: options) { | ||||||||||||||||||||
| outcome = activateAlertButton(alert, button: button, action: "accept", frame: frame, deadline: .distantFuture) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Check notice on line 132 in apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertObservationTests.swift
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| guard case .unsupported? = outcome else { | ||||||||||||||||||||
| return XCTFail("an unreadable host window must refuse the tap, got \(String(describing: outcome))") | ||||||||||||||||||||
| } | ||||||||||||||||||||
| XCTAssertEqual(app.staticTexts["agent-device-alert-actions"].label, "First actions: 0; replacement actions: 0") | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @MainActor | ||||||||||||||||||||
| func testAlertDeadlineDuringSynthesisPreparationLeavesTheOriginalUntouched() throws { | ||||||||||||||||||||
| app.launchArguments = ["--agent-device-alert-replacement-regression"] | ||||||||||||||||||||
|
|
@@ -307,5 +340,25 @@ | |||||||||||||||||||
| ) | ||||||||||||||||||||
| XCTAssertEqual(alertSnapshots(in: window, source: .appAlert, viewport: window.frame).map(\.elementType), [.alert]) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @MainActor | ||||||||||||||||||||
| func testDismissPopupWindowIsPlacedInTheBoxItSitsIn() { | ||||||||||||||||||||
| let viewport = CGRect(x: 0, y: 0, width: 402, height: 874) | ||||||||||||||||||||
| let popup = { (x: CGFloat) in | ||||||||||||||||||||
| ElementAttributesFixture(.window, CGRect(x: x, y: 0, width: 402, height: 874), children: [ | ||||||||||||||||||||
| ElementAttributesFixture(.other, CGRect(x: x, y: 0, width: 402, height: 874), label: "dismiss popup") | ||||||||||||||||||||
| ]) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| XCTAssertEqual(alertSnapshots(in: popup(0), source: .dismissPopup, viewport: viewport).count, 1) | ||||||||||||||||||||
| XCTAssertTrue(alertSnapshots(in: popup(1000), source: .dismissPopup, viewport: viewport).isEmpty) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @MainActor | ||||||||||||||||||||
| func testAnInnerPanelAlertIsPlacedInItsWindowNotTheApplicationFrame() { | ||||||||||||||||||||
| let alert = ElementAttributesFixture(.alert, CGRect(x: 341, y: 250, width: 270, height: 170)) | ||||||||||||||||||||
| let innerPanel = ElementAttributesFixture(.window, CGRect(x: 0, y: 0, width: 951, height: 669), children: [alert]) | ||||||||||||||||||||
| let root = ElementAttributesFixture(.application, CGRect(x: 0, y: 0, width: 466, height: 678), children: [innerPanel]) | ||||||||||||||||||||
| XCTAssertEqual(alertSnapshots(in: root, source: .appAlert, viewport: root.frame).map(\.elementType), [.alert]) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| #endif | ||||||||||||||||||||
| } | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Minor · Nested dismiss-popup window on a foldable's inner panel is now rejected as off screen
The new placement check tests a window against the box it sits in, and at the observation root that box is the application frame:
observeAlertcallsalertSnapshots(in: snapshot, source: source, viewport: snapshot.frame)(RunnerTests+AlertObservation.swift:44), wheresnapshotisownerApp.snapshot(), an.applicationnode, so the children — the app's windows — are matched against the application frame.Suggested change
Decide whether a dismiss-popup window on a foldable's inner panel — a window whose center sits outside the 466-wide application frame, the geometry this PR adds a test for — must still be observed. If it must, place a window that matches (or any window) against the union of the box it sits in and the screen rather than against the box it sits in alone, and pin the answer with a dismissPopup case using the 951x669 inner-panel window and the 466x678 application frame.
Details
The PR's own second test records the foldable geometry: the inner-panel window is 951x669 inside a 466x678 application frame (
testAnInnerPanelAlertIsPlacedInItsWindowNotTheApplicationFrame, lines 358-360). That window's center is (475.5, 334.5), andisPlacedcompares exactly the center (hostWindow.contains(CGPoint(x: frame.midX, y: frame.midY)), RunnerTests+SystemModal.swift:167-170). Withx = 475.5 > 466,isPlacedreturns false for that window frame inside that application frame.So for
source == .dismissPopup— the only source that matches a window itself (line 66) — a popup window that lives in the inner-panel window of the shape this PR just documented is refused, andobserveAlertreports.absentfor a popup that is on screen. That is the same failure #4001 fixed for SpringBoard alerts by comparing an alert against its hosting window instead of the application frame (the comment at RunnerTests+SystemModal.swift:165-166: "the application frame names only one of them"), now reintroduced one level up for the popup source.The case is partly masked in
handleAlert: an.absentverification is answered asok(alertVerificationResponsemaps.disappearedto ok), so the visible symptom is a confirmed answer that was never proved. The direct cost is the guard inobserveAlert: if both an inner-panel popup window and another marked window are present,candidates.count <= 1fails (line 45) and the observation staysunavailable, so a genuine dismissal is reported asALERT_CONFIRMATION_UNAVAILABLEinstead of a confirmed answer.persona:
swift-iosReply
@apex-sentinel-staging note ...to add context, or@apex-sentinel-staging pivot ...if this is wrong — I will re-check the cited code.Useful? Reply
@apex-sentinel-staging like, or@apex-sentinel-staging dislike <why>if it is not.