Skip to content

Commit 8a3ae74

Browse files
committed
test(ios): the bridge fixture records the attributes the bridge requests, and the keyboard-focus test asserts it asked for keyboard focus
1 parent 394fed5 commit 8a3ae74

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ private final class AXFixtureClient: NSObject {
194194
private let keyboardFocusIdentity: String?
195195
private(set) var requests = 0
196196
private(set) var rejected = 0
197+
/// Every attribute the bridge asked for, across requests: the request contract under test.
198+
private(set) var requestedAttributes: [String] = []
197199

198200
init(rejectLevelsAbove: Int?, vanishAtFrontier: Bool, keyboardFocusIdentity: String? = nil) {
199201
self.rejectLevelsAbove = rejectLevelsAbove
@@ -206,6 +208,7 @@ private final class AXFixtureClient: NSObject {
206208
forElement element: Any, attributes: Any, parameters: [String: Any], error: NSErrorPointer
207209
) -> Any? {
208210
requests += 1
211+
requestedAttributes.append(contentsOf: (attributes as? [Any] ?? []).compactMap { $0 as? String })
209212
let levels = (parameters["maxDepth"] as? NSNumber)?.intValue ?? 0
210213
if let limit = rejectLevelsAbove, levels > limit {
211214
rejected += 1
@@ -395,6 +398,15 @@ extension RunnerTests {
395398
XCTAssertEqual(root["focused"] as? Bool, false, "no focus of either kind is not focused")
396399
XCTAssertEqual(field["label"] as? String, "1")
397400
XCTAssertEqual(field["focused"] as? Bool, true, "keyboard focus alone is focused")
401+
// The AX server answers only what it was asked for: the request must name keyboard focus, as
402+
// the snapshot keypath or as the AX attribute XCElementSnapshot maps it to, or a real capture
403+
// would come back without it and read false above.
404+
XCTAssertTrue(
405+
client.requestedAttributes.contains { $0.range(of: "keyboardfocus", options: .caseInsensitive) != nil },
406+
"requested attributes name keyboard focus: \(client.requestedAttributes)")
407+
XCTAssertTrue(
408+
client.requestedAttributes.contains { $0.range(of: "hasfocus", options: .caseInsensitive) != nil },
409+
"requested attributes still name the focus engine's focus: \(client.requestedAttributes)")
398410
}
399411

400412
/// Every recovery case of the shared fixture, replayed through the real ladder, bridge

0 commit comments

Comments
 (0)