@@ -92,9 +92,8 @@ extension RunnerTests {
9292
9393 /// After a focus tap raises the software keyboard, stabilization takes focus from the tapped
9494 /// input's own read before it asks for the keyboard. While the keyboard is presented, the keyboard
95- /// query blocks and then finds none: after a fill's focus tap it took 0.68 s on the test app
96- /// (iPhone 17 Pro, iOS 27.0) and 0.57–3.77 s on CI. The keyboard is already up here, so asking it
97- /// first confirms focus from the keyboard's arrival instead.
95+ /// query blocks and then finds none. The keyboard is already up here, so asking it first confirms
96+ /// focus from the keyboard's arrival instead.
9897 @ MainActor
9998 func testFocusStabilizationAsksTheTappedInputBeforeTheKeyboard ( ) throws {
10099 app . launchArguments = [ " --agent-device-text-entry-regression " , " --agent-device-text-entry-soft-keyboard " ]
@@ -111,35 +110,48 @@ extension RunnerTests {
111110
112111 let stabilized = stabilizeTextInputBeforeTyping ( app : app , target : field , keyboardVisibleBeforeTap : false )
113112
114- XCTAssertEqual ( stabilized . evidence , . inputReportsKeyboardFocus )
115- XCTAssertEqual ( stabilized . focusRead ? . snapshot ? . frame , field . frame )
113+ guard case . inputReportsKeyboardFocus ( let read ) = stabilized . evidence else {
114+ return XCTFail ( " focus confirmed by \( stabilized . evidence ? . name ?? " nothing " ) , not by the tapped input " )
115+ }
116+ XCTAssertEqual ( read . snapshot ? . frame , field . frame )
116117 }
117118
118- /// A fill whose focus tap raises the software keyboard types and reads its text back when focus is
119- /// confirmed from the input rather than from the keyboard's arrival.
119+ /// A fill whose focus tap raises the software keyboard hands the read that confirmed focus to the
120+ /// entry as its first read. The fixture counts queries as in
121+ /// `testFillReadsEachResolvedFieldThroughOneSnapshot`: this fill made 17, and 19 when the entry
122+ /// resolved the input again. The one read of headroom covers a keyboard that arrives before the
123+ /// field reports focus.
120124 @ MainActor
121- func testFillThatRaisesTheSoftwareKeyboardTypesAndReadsBack ( ) throws {
122- app . launchArguments = [ " --agent-device-text-entry-regression " , " --agent-device-text-entry-soft-keyboard " ]
125+ func testFillThatRaisesTheSoftwareKeyboardReusesTheReadThatConfirmedFocus ( ) throws {
126+ app . launchArguments = [
127+ " --agent-device-text-entry-regression " ,
128+ " --agent-device-text-entry-soft-keyboard " ,
129+ " --agent-device-text-entry-counts-value-reads " ,
130+ ]
123131 app . launch ( )
124132 defer { invalidateCachedTarget ( reason : " unit_test_cleanup " ) ; app . terminate ( ) }
125133 XCTAssertTrue ( app . waitForFixtureExistence ( timeout : appExistenceTimeout ) )
126134 let field = app . textFields [ " agent-device-hardware-keyboard-input " ]
127135 XCTAssertTrue ( field . waitForFixtureExistence ( timeout : appExistenceTimeout ) )
128136 XCTAssertFalse ( isKeyboardVisible ( app : app ) )
137+ let valueReads = app . staticTexts [ " agent-device-text-entry-value-reads " ]
129138 let frame = field . frame
130139 let fill = try runnerCommandFixture (
131140 #"{"command":"type","commandId":"fill-raises-keyboard","text":"hello","textEntryMode":"replace","x": \#( frame . midX ) ,"y": \#( frame . midY ) }"#
132141 )
133142
143+ let readsBefore = try XCTUnwrap ( Int ( valueReads . label ) )
134144 let response = executeTypeCommand ( activeApp : app , command : fill )
145+ let readsAfter = try XCTUnwrap ( Int ( valueReads . label ) )
135146
136- XCTAssertTrue ( response . ok , String ( describing : response . error ) )
137- XCTAssertEqual ( response . data ? . textEntryRoute , " xctest-element " )
138- XCTAssertEqual ( field . value as? String , " hello " )
139147 try XCTSkipUnless (
140148 app . keyboards . firstMatch . waitForFixtureExistence ( timeout : appExistenceTimeout ) ,
141149 " software keyboard is down: this simulator did not raise the keyboard the focus tap asked for "
142150 )
151+ XCTAssertTrue ( response . ok , String ( describing : response . error ) )
152+ XCTAssertEqual ( response . data ? . textEntryRoute , " xctest-element " )
153+ XCTAssertEqual ( valueReads . value as? String , " hello " )
154+ XCTAssertLessThanOrEqual ( readsAfter - readsBefore , 18 )
143155 }
144156#endif
145157}
0 commit comments