Skip to content

Commit 939214c

Browse files
committed
fix(ios): focus an empty masked field before skipping its clear
The masked clear returned for an empty field before its focus check, so an empty secure field whose focus tap was refused was typed into without focus, which records an XCTest failure. The old edge tap had focused it. From review: the clear's mask-placeholder rule now applies on every platform, the read-back has three cases, an input that stops answering after the deletes gets no caret tap (its one burst, as for callstack#3060), and a test covers the caret-tap fallback for masked text the deletes can't reach. The rule stays out of textValueRead. There it turns a formatted read-back in a field that reports a bullet placeholder, such as a PIN field, from unconfirmed into TEXT_ENTRY_MISMATCH.
1 parent fa2b299 commit 939214c

3 files changed

Lines changed: 69 additions & 32 deletions

File tree

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

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ extension RunnerTests {
408408
// be stale after the field repositions on focus (e.g. the Settings search bar jumps
409409
// bottom->top and reveals a "Suggestions" list) — tapping there navigates away instead of
410410
// clearing; and replacing into an already-empty field is a no-op anyway.
411-
// textValueForClear returns nil for secure (and unknown) fields, and on iOS for a placeholder
412-
// that is itself a mask, where we CANNOT confirm emptiness — those must still be cleared, or
411+
// textValueForClear returns nil for secure (and unknown) fields, and for a placeholder that is
412+
// itself a mask, where we CANNOT confirm emptiness — those must still be cleared, or
413413
// replace would concatenate stale + new text. So distinguish nil (clear) from "" (skip). On iOS
414414
// the masked route below can still prove a masked field empty.
415415
let existing = textValueForClear(input.attributes)
@@ -424,24 +424,25 @@ extension RunnerTests {
424424
// a secure field on its first delete after the field takes focus, and deletes from a caret left
425425
// at the end reach the rest, so deletes go first and the caret moves only for masked text left.
426426
if textValueRead(for: input.attributes) == .unreadable {
427-
if maskedTextShown(by: input) == .empty {
428-
return
429-
}
430-
// Deletes into a field without focus record an XCTest failure, which tears down the runner. The
431-
// focus step can leave focus unconfirmed, so the field gets the readiness repeat at its center,
432-
// clear of a control at the edge.
427+
// Deletes or text sent to a field without focus record an XCTest failure, which tears down the
428+
// runner. The focus step can leave focus unconfirmed, so the field gets the readiness repeat at
429+
// its center, clear of a control at the edge, even when it is empty and needs no clear.
433430
if input.snapshot.map({ snapshotHasKeyboardFocus($0) }) != true {
434431
try reader.dispatch { try retapAt(read: input, app: app, element: input.element) }
435432
}
433+
if maskedTextShown(by: input) == .empty {
434+
return
435+
}
436436
let burst = Self.textClearBurst(valueLength: valueLength)
437437
reader.dispatch { input.element.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: burst)) }
438-
// An input that stops answering (#3060) goes on to the caret tap and burst below.
439-
if let cleared = try reader.input() {
440-
let shown = maskedTextShown(by: cleared)
441-
NSLog("AGENT_DEVICE_RUNNER_TEXT_ENTRY_CLEAR route=masked-deletes shown=%@", String(describing: shown))
442-
if shown == .empty || shown == .maskPlaceholder {
443-
return
444-
}
438+
// An input that stops answering (#3060) has had its one burst, as below.
439+
guard let cleared = try reader.input() else {
440+
return
441+
}
442+
let shown = maskedTextShown(by: cleared)
443+
NSLog("AGENT_DEVICE_RUNNER_TEXT_ENTRY_CLEAR route=masked-deletes shown=%@", String(describing: shown))
444+
if shown != .text {
445+
return
445446
}
446447
}
447448
#endif
@@ -547,11 +548,8 @@ extension RunnerTests {
547548
case empty
548549
/// A placeholder that is itself a mask, which text of the same length shows too.
549550
case maskPlaceholder
550-
/// A mask other than the placeholder, so text is in the field.
551-
case mask
552-
/// Any other value, which says nothing about the text. Like `.mask`, it leaves the clear to the
553-
/// caret tap; the clear's log line tells the two apart.
554-
case unknown
551+
/// Anything else, such as a mask other than the placeholder: text may be in the field.
552+
case text
555553
}
556554

557555
static func maskedTextShown(value: String, showsPlaceholder: Bool) -> MaskedTextShown {
@@ -562,7 +560,7 @@ extension RunnerTests {
562560
if showsPlaceholder {
563561
return isMaskedTextValue(shown) ? .maskPlaceholder : .empty
564562
}
565-
return isMaskedTextValue(shown) ? .mask : .unknown
563+
return .text
566564
}
567565

568566
/// `maskedTextShown(value:showsPlaceholder:)` for `input`, with the placeholder rule the shared read uses.
@@ -808,17 +806,16 @@ extension RunnerTests {
808806
}
809807

810808
/// The text a clear can trust in the input `attributes` describe, with a placeholder read as empty;
811-
/// nil when unreadable. On iOS a placeholder that is itself a mask is nil too, since text of its length
812-
/// shows it as well: the masked clear reads that field back instead of skipping it.
809+
/// nil when unreadable. A placeholder that is itself a mask is nil too, since text of its length shows
810+
/// it as well, so that field is cleared instead of skipped. Only the clear reads it this way: the
811+
/// shared read keeps such a placeholder empty for verification, as a PIN field that shows its digits needs.
813812
func textValueForClear(_ attributes: (any XCUIElementAttributes)?) -> String? {
814813
guard let value = editableTextValue(for: attributes, treatingPlaceholderAsEmpty: true) else {
815814
return nil
816815
}
817-
#if os(iOS)
818816
if value.isEmpty, Self.isMaskedTextValue(normalizedElementText(attributes?.value)) {
819817
return nil
820818
}
821-
#endif
822819
return value
823820
}
824821

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,16 @@ extension RunnerTests {
141141
XCTAssertFalse(Self.textClearContinues(clearedLength: 501, remainingLength: 640))
142142
}
143143

144-
// A secure field shows its placeholder when empty and a mask otherwise, so only a mask other than
145-
// the placeholder proves text is in it; a placeholder that is itself a mask proves nothing
146-
// (tester-army/e2e#1631).
147-
func testMaskedTextShownProvesTextOnlyWithAMaskOtherThanThePlaceholder() {
144+
// A secure field shows its placeholder when empty and a mask otherwise. A placeholder that is not a
145+
// mask proves it empty; one that is itself a mask proves nothing, since text of its length shows it
146+
// too (tester-army/e2e#1631).
147+
func testMaskedTextShownTellsAnEmptyFieldFromAMaskPlaceholder() {
148148
let bullets = { (count: Int) in String(repeating: "\u{2022}", count: count) }
149149
XCTAssertEqual(Self.maskedTextShown(value: "", showsPlaceholder: false), .empty)
150150
XCTAssertEqual(Self.maskedTextShown(value: "Password", showsPlaceholder: true), .empty)
151151
XCTAssertEqual(Self.maskedTextShown(value: bullets(8), showsPlaceholder: true), .maskPlaceholder)
152-
XCTAssertEqual(Self.maskedTextShown(value: bullets(3), showsPlaceholder: false), .mask)
153-
XCTAssertEqual(Self.maskedTextShown(value: "\u{25CF}\u{25CF}", showsPlaceholder: false), .mask)
154-
XCTAssertEqual(Self.maskedTextShown(value: "hunter2", showsPlaceholder: false), .unknown)
152+
XCTAssertEqual(Self.maskedTextShown(value: bullets(3), showsPlaceholder: false), .text)
153+
XCTAssertEqual(Self.maskedTextShown(value: "hunter2", showsPlaceholder: false), .text)
155154
}
156155

157156
// One read owns readability for every route: a secure field is unreadable whatever it reports,

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,47 @@ extension RunnerTests {
627627
)
628628
}
629629

630+
// An empty one needs no clear, but the text typed next needs focus just as the deletes do.
631+
@MainActor
632+
func testFirstFillIntoAnEmptySecureFieldThatRefusedTheFocusTap() throws {
633+
try assertFillLeavesTheEdgeToggleUnpressed(
634+
launchArguments: ["--agent-device-text-entry-secure-entry", "--agent-device-text-entry-refuses-first-focus"],
635+
field: { $0.secureTextFields },
636+
expectedValue: String(repeating: "\u{2022}", count: 16)
637+
)
638+
XCTAssertEqual(try secureEntryCounts().deletes, 0)
639+
}
640+
641+
// Deletes from a caret moved to the start reach none of the text, so the clear falls back to the caret
642+
// tap at the right edge, which in this fixture lands on the toggle: the limit `fill`'s docs name.
643+
@MainActor
644+
func testMaskedTextTheDeletesCannotReachFallsBackToTheCaretTap() throws {
645+
app.launchArguments = [
646+
"--agent-device-text-entry-regression",
647+
"--agent-device-text-entry-soft-keyboard",
648+
"--agent-device-text-entry-masked-value",
649+
"--agent-device-text-entry-prefilled",
650+
]
651+
app.launch()
652+
addTeardownBlock { [self] in
653+
invalidateCachedTarget(reason: "unit_test_cleanup")
654+
app.terminate()
655+
}
656+
let input = app.textFields["agent-device-hardware-keyboard-input"]
657+
XCTAssertTrue(input.waitForFixtureExistence(timeout: appExistenceTimeout))
658+
let togglePresses = app.staticTexts["agent-device-masked-toggle-presses"]
659+
XCTAssertTrue(togglePresses.waitForFixtureExistence(timeout: appExistenceTimeout))
660+
input.coordinate(withNormalizedOffset: CGVector(dx: 0.02, dy: 0.5)).tap()
661+
662+
let response = try executeTypeCommand(
663+
activeApp: app,
664+
command: try fillCommandFixture(commandId: "fill-caret-at-start", text: "abc", at: input)
665+
)
666+
667+
XCTAssertTrue(response.ok, String(describing: response.error))
668+
XCTAssertEqual(togglePresses.label, "presses=1")
669+
}
670+
630671
// The issue's own case: its placeholder is eight bullets, which React Native reports as the value of
631672
// the empty field.
632673
@MainActor

0 commit comments

Comments
 (0)