Repository navigation
fix(ios): answer Safari's "Open in" prompt and inner-panel SpringBoard alerts #4001
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
703e6fa
25ce4a6
a3daa4c
e869aa5
9ceab45
6e7ad51
8cf03e5
428c5ff
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import XCTest | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import AgentDeviceSnapshotPresentation | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| extension RunnerTests { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| func captureAlertPresentation(_ element: XCUIElement) -> RunnerAlertPresentation? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -47,24 +48,26 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| return Date() < deadline ? observation : .deadlineExceeded | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| private func alertSnapshots( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| func alertSnapshots( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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 · hostWindow widens from a placement check to an origin for every window-shaped snapshot In alertSnapshots the host frame is taken from any snapshot whose elementType is .window, but .window is also the matching shape for .dismissPopup, and the recursion now overwrites Suggested change Keep Detailspersona: Reply Useful? Reply |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| in snapshot: XCUIElementSnapshot, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| source: RunnerAlertSource, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| viewport: CGRect | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> [XCUIElementSnapshot] { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| let frame = snapshot.frame | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| let visible = !frame.isNull && !frame.isEmpty && viewport.contains(CGPoint(x: frame.midX, y: frame.midY)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| let hostWindow = snapshot.elementType == .window && SnapshotGeometry.isPositiveFinite(frame) ? frame : viewport | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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. 🟠 Major · Placement guard for a dismiss-popup window is self-referential and can never reject a candidate
Suggested change
Suggested change Keep the placement test anchored to the viewport the candidate was enumerated against when the candidate itself is the host window: pass the incoming viewport (not the node's own frame) as the box for the DetailsFailing sequence: Also raised hereAlso raised at this location by swift-ios: Placement gate in alertSnapshots is vacuous for the .dismissPopup source — persona: Reply Useful? Reply |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| let matches: Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch source { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| case .blockingSystemModal: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| matches = snapshot.elementType == .alert || snapshot.elementType == .sheet | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| case .appAlert: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| matches = snapshot.elementType == .alert | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| case .safariDialog: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| matches = snapshot.identifier == Self.safariDialogIdentifier | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| case .dismissPopup: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| matches = snapshot.elementType == .window && containsDismissPopupMarker(snapshot) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if matches && visible { return [snapshot] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return snapshot.children.flatMap { alertSnapshots(in: $0, source: source, viewport: viewport) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if matches && Self.isPlaced(frame, in: hostWindow) { return [snapshot] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return snapshot.children.flatMap { alertSnapshots(in: $0, source: source, viewport: hostWindow) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 70 in apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| private func containsDismissPopupMarker(_ snapshot: XCUIElementSnapshot) -> Bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,3 +190,19 @@ | |
| + " fallbackAttempted=\(fallbackAttempted)" | ||
| } | ||
| } | ||
|
|
||
| extension SynthesizedCoordinateContext { | ||
|
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 · SynthesizedCoordinateContext now validates with a stricter box guard than the code it replaced The inline guard in Detailspersona: Reply Useful? Reply |
||
| /// Nil when `referenceFrame` is not a finite, non-empty box a point can be placed in. | ||
| init?( | ||
| validating referenceFrame: CGRect, | ||
| resolvedWindow: XCUIElement?, | ||
| accessibilityHealth: RunnerAccessibilityHealth | ||
| ) { | ||
| guard SnapshotGeometry.isPositiveFinite(referenceFrame) else { return nil } | ||
| self.init( | ||
| referenceFrame: referenceFrame, | ||
| resolvedWindow: resolvedWindow, | ||
| accessibilityHealth: accessibilityHealth | ||
| ) | ||
| } | ||
| } | ||
|
Check notice on line 208 in apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,17 +102,20 @@ | |
| ) | ||
| } | ||
|
|
||
| /// A SpringBoard modal and the window that hosts it. A foldable's SpringBoard has windows on | ||
| /// each panel, and `springboard.frame` names only one of them, so the modal is placed against | ||
| /// its own window and its activation is routed through that window's display. | ||
| struct SpringBoardModal { | ||
| let root: XCUIElement | ||
| let window: XCUIElement | ||
| } | ||
|
|
||
| func firstBlockingSystemModal( | ||
| in springboard: XCUIApplication, | ||
| deadline: Date = .distantFuture | ||
| ) -> XCUIElement? { | ||
| let alerts = safeElementsQuery { | ||
| springboard.alerts.allElementsBoundByIndex | ||
| } | ||
| for alert in alerts { | ||
| if safeIsBlockingSystemModal(alert, in: springboard) { | ||
| return alert | ||
| } | ||
| ) -> SpringBoardModal? { | ||
| if let alert = firstBlockingSystemModal(in: springboard, matching: .alert, deadline: deadline) { | ||
| return alert | ||
| } | ||
|
|
||
| // Don't start the second (sheet) enumeration once the shared probe deadline is spent (#1244). | ||
|
|
@@ -121,38 +124,49 @@ | |
| return nil | ||
| } | ||
|
|
||
| let sheets = safeElementsQuery { | ||
| springboard.sheets.allElementsBoundByIndex | ||
| return firstBlockingSystemModal(in: springboard, matching: .sheet, deadline: deadline) | ||
| } | ||
|
|
||
| private func firstBlockingSystemModal( | ||
|
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 · Blocking system modal discovery now requires the modal to sit inside a SpringBoard window
Suggested change Confirm on a device that every SpringBoard modal the probe previously matched is nested under a DetailsAlso raised hereAlso raised at this location by senior-developer: Unanswered launch confirmations are no longer surfaced when the panel window names no alert or sheet — persona: Reply Useful? Reply |
||
| in springboard: XCUIApplication, | ||
| matching type: XCUIElement.ElementType, | ||
| deadline: Date | ||
| ) -> SpringBoardModal? { | ||
| let windows = safeElementsQuery { | ||
| springboard.windows.containing(type, identifier: nil).allElementsBoundByIndex | ||
| } | ||
| for sheet in sheets { | ||
| if safeIsBlockingSystemModal(sheet, in: springboard) { | ||
| return sheet | ||
| for window in windows { | ||
| guard Date() < deadline else { return nil } | ||
| let modals = safeElementsQuery { | ||
| window.descendants(matching: type).allElementsBoundByIndex | ||
| } | ||
| for modal in modals { | ||
| guard Date() < deadline else { return nil } | ||
| if safeIsBlockingSystemModal(modal, in: window) { | ||
| return SpringBoardModal(root: modal, window: window) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
Check warning on line 151 in apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift
|
||
|
|
||
| func safeElementsQuery(_ fetch: () -> [XCUIElement]) -> [XCUIElement] { | ||
| safely("MODAL_QUERY", [], fetch) | ||
| } | ||
|
|
||
| private func safeIsBlockingSystemModal(_ element: XCUIElement, in springboard: XCUIApplication) -> Bool { | ||
| safely("MODAL_CHECK", false) { isBlockingSystemModal(element, in: springboard) } | ||
| private func safeIsBlockingSystemModal(_ element: XCUIElement, in window: XCUIElement) -> Bool { | ||
|
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 · isBlockingSystemModal keeps its name after becoming a placement test Renaming the parameter from Suggested change Rename to something like Detailspersona: Reply Useful? Reply |
||
| safely("MODAL_CHECK", false) { isBlockingSystemModal(element, in: window) } | ||
| } | ||
|
|
||
| private func isBlockingSystemModal(_ element: XCUIElement, in springboard: XCUIApplication) -> Bool { | ||
| guard element.exists else { return false } | ||
| let frame = element.frame | ||
| if frame.isNull || frame.isEmpty { return false } | ||
|
|
||
| let viewport = springboard.frame | ||
| if viewport.isNull || viewport.isEmpty { return false } | ||
|
|
||
| let center = CGPoint(x: frame.midX, y: frame.midY) | ||
| if !viewport.contains(center) { return false } | ||
| private func isBlockingSystemModal(_ element: XCUIElement, in window: XCUIElement) -> Bool { | ||
| element.exists && Self.isPlaced(element.frame, in: window.frame) | ||
| } | ||
|
|
||
| return true | ||
| /// Whether a modal is on screen in the window that hosts it. A foldable's SpringBoard has a | ||
| /// window on each panel, and the application frame names only one of them. | ||
| static func isPlaced(_ frame: CGRect, in hostWindow: CGRect) -> Bool { | ||
| SnapshotGeometry.isPositiveFinite(frame) && SnapshotGeometry.isPositiveFinite(hostWindow) | ||
| && hostWindow.contains(CGPoint(x: frame.midX, y: frame.midY)) | ||
|
Check notice on line 169 in apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift
|
||
| } | ||
|
|
||
| func actionableElements(in element: XCUIElement) -> [XCUIElement] { | ||
|
|
||
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.
🔵 Nit · New alert-activation failure path has no test
activateAlertButtongains a new refusal: whenalert.windowis set but its frame read fails (safely("ALERT_WINDOW", CGRect.null)yields a non-positive-finite box), the command returns.unsupported("alert activation could not read the window hosting the alert")instead of tapping. The sibling pre-synthesis refusal in the same function (missing_waitForQuiescenceAsPreEvent:) and the deadline paths are pinned byRunnerTests+AlertObservationTests, but this new branch is not, and the file already carries the stubbing hooks (alertResolutionOverrideForTesting,AlertTapDeadlineStub) needed to reach it.Suggested change
Add a unit test that resolves an alert whose window frame read throws or returns CGRect.null and asserts the unsupported outcome and that no tap was synthesized.
Details
persona:
javascriptReply
@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.