Skip to content

Commit 88890d8

Browse files
committed
refactor(ios): remove unreachable text readiness branches
1 parent f162f1c commit 88890d8

2 files changed

Lines changed: 11 additions & 34 deletions

File tree

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import XCTest
22

3-
// Text-entry target acquisition: choosing the element a `type`/`fill` will address and getting
4-
// focus onto it — the one-shot tap witness, the post-tap stabilization, and the
5-
// `focusTextInputForTextEntry` entry point the command layer calls. Whether that target is ready
6-
// is RunnerTests+TextEntryReadiness.swift's question, and this file asks it rather than answering
7-
// it.
83
extension RunnerTests {
94
/// Books the tap as the address for the next bare `type`. `element` is a text input the caller
105
/// classified BEFORE dispatching, or nil when the tap hit nothing worth typing into; that is the whole
@@ -71,7 +66,6 @@ extension RunnerTests {
7166
#if os(tvOS)
7267
return TextEntryStabilization(element: target, focusConfirmed: true)
7368
#else
74-
let latest = target
7569
let keyboardVisibleAtEntry = keyboardVisibleBeforeTap ?? isKeyboardVisible(app: app)
7670
let deadline = Date().addingTimeInterval(TextEntryTiming.focusTimeout)
7771
while Date() < deadline {
@@ -81,16 +75,16 @@ extension RunnerTests {
8175
// focusedTextInput is intentionally nil on iOS; treat the keyboard transitioning to
8276
// visible after our tap as the focus-moved signal. Don't fast-path when it was already up.
8377
if keyboardBecameVisible(app: app, wasVisibleAtEntry: keyboardVisibleAtEntry) {
84-
return TextEntryStabilization(element: latest, focusConfirmed: true)
78+
return TextEntryStabilization(element: target, focusConfirmed: true)
8579
}
8680
#if os(iOS)
87-
if let latest, keyboardFocusConfirmed(app: app, element: latest) {
88-
return TextEntryStabilization(element: latest, focusConfirmed: true)
81+
if let target, keyboardFocusConfirmed(app: app, element: target) {
82+
return TextEntryStabilization(element: target, focusConfirmed: true)
8983
}
9084
#endif
9185
sleepFor(TextEntryTiming.pollInterval)
9286
}
93-
return TextEntryStabilization(element: latest, focusConfirmed: false)
87+
return TextEntryStabilization(element: target, focusConfirmed: false)
9488
#endif
9589
}
9690

@@ -156,10 +150,9 @@ extension RunnerTests {
156150
refreshPoint: requestedPoint,
157151
prefersFocusedElement: false
158152
)
159-
let concreteTargetReady = keyboardVisibleBeforeTap && readyTarget.element != nil
160-
let element = stabilized.focusConfirmed || concreteTargetReady
161-
? (stabilized.element ?? target)
162-
: (waitForTextEntryReadiness(app: app, target: readyTarget) ?? stabilized.element ?? target)
153+
let element = stabilized.focusConfirmed
154+
? readyTarget.element
155+
: (waitForTextEntryReadiness(app: app, target: readyTarget) ?? readyTarget.element)
163156
return TextEntryTarget(
164157
element: element,
165158
refreshPoint: textEntryRefreshPoint(for: element, fallbackTo: requestedPoint),
@@ -191,10 +184,4 @@ extension RunnerTests {
191184
}
192185
return CGPoint(x: frame.midX, y: frame.midY)
193186
}
194-
195-
/// A focus-moved signal for iOS text entry, where `focusedTextInput` is intentionally nil.
196-
/// The software keyboard TRANSITIONING from hidden (at entry) to visible means the field we
197-
/// just tapped gained first-responder. If the keyboard was ALREADY up (e.g. back-to-back
198-
/// fills into different fields), its visibility is not evidence focus moved to the new field,
199-
/// so callers must keep waiting rather than typing into the previously-focused field.
200187
}

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import XCTest
22

3-
// Text-entry readiness: whether the target is actually able to receive text yet. The waits, the
4-
// keyboard signals they read, and the focus corroboration that ends the hardware-keyboard window.
5-
// RunnerTests+TextEntryFocus.swift is the only caller of the two non-private entries here; nothing
6-
// in this file reaches back into it.
73
extension RunnerTests {
84
func focusedTextInput(app: XCUIApplication) -> XCUIElement? {
95
#if os(iOS)
@@ -35,27 +31,21 @@ extension RunnerTests {
3531
timeout: TimeInterval = TextEntryTiming.readinessTimeout
3632
) -> XCUIElement? {
3733
#if os(iOS)
38-
var latest = resolveTextEntryElement(app: app, target: target)
34+
let candidate = resolveTextEntryElement(app: app, target: target)
3935
let keyboardVisibleAtEntry = isKeyboardVisible(app: app)
4036
let deadline = Date().addingTimeInterval(timeout)
4137
var hardwareKeyboardFallback = Date().addingTimeInterval(
4238
min(TextEntryTiming.hardwareKeyboardFallbackTimeout, timeout)
4339
)
4440
var sawSoftwareKeyboard = false
4541
while Date() < deadline {
46-
if let focused = focusedTextInput(app: app) {
47-
latest = focused
48-
if isKeyboardVisible(app: app) {
49-
return focused
50-
}
51-
}
5242
// Fast-path on a keyboard hidden->visible transition: our tapped field gained focus, so
5343
// return immediately instead of burning the full readinessTimeout (warmup-first-char echo
5444
// + post-type verify/repair remain as drop safety nets). When the keyboard was ALREADY up
5545
// (back-to-back fills), this isn't a focus signal — fall through to the settle/timeout so
5646
// text isn't sent to the previously-focused field.
5747
if keyboardBecameVisible(app: app, wasVisibleAtEntry: keyboardVisibleAtEntry) {
58-
return latest
48+
return candidate
5949
}
6050
sawSoftwareKeyboard = sawSoftwareKeyboard || keyboardElementExists(app: app)
6151
// A responder that takes no software keyboard (hardware keyboard connected, or a custom
@@ -64,7 +54,7 @@ extension RunnerTests {
6454
// simulator state (#1874): on a loaded host the keyboard is merely late, and returning here
6555
// handed the caller an element that had not taken focus yet. Ask the target itself instead,
6656
// and re-arm rather than re-asking every poll — the query is cheap, not free.
67-
if !sawSoftwareKeyboard, Date() >= hardwareKeyboardFallback, let candidate = latest {
57+
if !sawSoftwareKeyboard, Date() >= hardwareKeyboardFallback, let candidate {
6858
if keyboardFocusConfirmed(app: app, element: candidate) {
6959
return candidate
7060
}
@@ -74,7 +64,7 @@ extension RunnerTests {
7464
}
7565
sleepFor(TextEntryTiming.pollInterval)
7666
}
77-
return focusedTextInput(app: app) ?? latest
67+
return candidate
7868
#else
7969
return resolveTextEntryElement(app: app, target: target)
8070
#endif

0 commit comments

Comments
 (0)