Skip to content

Commit ddbfc85

Browse files
thymikeeclaude
andauthored
fix(ios): press the navigation bar back button and speed up the back swipe (#4508)
* fix(ios): press the navigation bar back button and speed up the back swipe iOS back now reads the current tree in the same runner call for the navigation bar's system back button (identifier BackButton inside a navigation bar). When exactly one is hittable, it taps it with a synthesized tap and the daemon's settle observes the pop. No other button counts, whatever its label; an unreadable or penalized tree, or two candidates, fall back to the swipe. The swipe is resolved before settling, samples 0.05 s apart, and measures the change from the last still sample, so the separate just-before capture is gone. The post-swipe delay drops from 0.25 s to 0.1 s, which also shortens the required still span. The settle budget is 2 s. The gap-coverage and baseline checks still decide every success. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(ios): confirm the back button tap and scale the settle budget The navigation bar back button path now reads the bars again after the tap (one XCTest snapshot per bar, 0.05 s apart, up to 1 s) and answers BACK_SWIPE_UNVERIFIED when neither the bar title nor its back button changed; a delivered tap is never followed by the swipe. The button log line is emitted on every exit. The back swipe settle budget grows with the slowest capture so a still screen can settle on a slow host. Help, flag text, command docs, and the runner protocol describe when the button is pressed and what each fallback answers. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(back): scope the iOS swipe fallback and state the settle budget plainly Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(ios): hold XCTest issues in the back button reads Every navigation bar read in iOS back runs inside holdingRecordedIssues. A held issue before the tap means no button, so back swipes. A held issue after the tap proves nothing, so back answers back_swipe_unverified and never swipes. This replaces the suppressed-issue counter diff, which only saw kAXError issues. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(ios): hold the back bar still before the tap and surface a hung query - Read the bar state twice around the button lookup and tap only when the two reads agree and contain the button's frame, so a push still animating is not taken for the state a pop changes. - Compare bar count, identifier, static-text titles, and back buttons. - Start bar reads only within the 1 s budget, checked before each bar's snapshot; document what bounds a read in flight. - Re-record a hung XCTest query as record(_:) requires, send nothing more: BACK_SWIPE_NOT_DISPATCHED before the tap, BACK_SWIPE_UNVERIFIED after it. - Drop the dead outcome guard on the XCTest tap fallback. - Correct the visionOS back hints; a thrown tap no longer logs a swipe verification error line. - Test the two-candidate rule, the skipped read, and hung queries; the lookup-issue test asserts the swipe path, not a swipe outcome. - Name the simulator still span in commands.md. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(ios): match the back button in screen space on a placed iPad window A live XCUIElement frame is in screen points, but a snapshot frame of a placed iPad window starts at the window's own top-left (#3899). The pre-tap still check compared the two directly, so on a placed window the button was never found still: back spent the 1 s read budget and swiped. The check now places the snapshot frames at the window's screen origin through the synthesized coordinate context's SurfaceGeometry. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(ios): keep the placed-window back-button test iOS-only The macOS runner test build has no navigationBarBackState. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(ios): confirm back only from the back button and space the still reads The still check before the tap now needs two agreeing bar reads started at least one read interval apart, so two reads drawn in one animation frame no longer pass for a still bar. The bar state is now each bar's back button label and frame, so a bar title that updates itself, such as a countdown, can no longer confirm a tap that navigated nowhere. The placed-window button match allows 0.5 pt per edge for fractional frame values. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(ios): confirm a back button pop only from bar and back button labels and counts A tap that navigates nowhere can still move the back button, such as by a large-title collapse, so its frame no longer confirms a pop. Frames stay in the still check before the tap and in matching the button to press. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(ios): drop the timed read and frame tolerance from the back button check Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(ios): read the bar once more after the back button confirmation budget A snapshot of a navigation bar that vanished mid-pop spends about 2 s in XCTest's element-resolution retries before it raises a held issue. On a slow CI simulator that read used up the 1 s confirmation budget, so no read saw the settled screen and back answered back_swipe_unverified after a real pop. One read now always follows the budget, with no deadline, so the screen after the pop is read. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(ios): fail every in-budget back confirmation read, not a fixed count The slow-host confirmation test failed two reads that each slept 0.6 s, so whether the final read came third depended on real read speed. The confirmation loop now tells the test hook which read starts after the budget, so the test fails every read in the budget and succeeds only on that final read. The protocol and command docs now say the final read can also fail or hang, and that a read can run well past the 1 s. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(back): name the final confirmation read in back_swipe_unverified Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(back): describe NavigationBarBackReadPhase as the read hook's phase Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent b68ed4b commit ddbfc85

11 files changed

Lines changed: 949 additions & 104 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m‎

Lines changed: 124 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,117 @@
3939
@interface AgentDeviceRunnerFixtureViewController : AgentDeviceRunnerViewController
4040
@end
4141

42+
// A real navigation stack for `back`. `--agent-device-back-navigation-bar` pushes a detail screen,
43+
// so the bar shows UIKit's system back button; the interactive pop is off, so only that button can
44+
// pop it. `--blocked-back` keeps that button but replaces its action, so pressing it navigates
45+
// nowhere. `--shifting-back` makes that press move the bar down instead, so the back button moves
46+
// without any navigation. `--ticking-title` counts the detail screen's title down every 0.2 s, as a timer does,
47+
// so its bar changes without any navigation. `--custom-back-item` instead puts a bar button titled
48+
// "Back" on the root, which is not the system back button and must never be pressed. The root's
49+
// label reports what happened.
50+
@interface AgentDeviceBackNavigationFixture : UINavigationController <UINavigationControllerDelegate>
51+
@property(nonatomic, strong) UILabel *status;
52+
@property(nonatomic, strong) NSTimer *titleTimer;
53+
@end
54+
55+
@implementation AgentDeviceBackNavigationFixture
56+
- (instancetype)initWithCustomBackItem:(BOOL)customBackItem blockedBack:(BOOL)blockedBack {
57+
UIViewController *root = [UIViewController new];
58+
root.title = @"Root";
59+
root.view.backgroundColor = UIColor.systemBackgroundColor;
60+
self = [super initWithRootViewController:root];
61+
if (!self) return nil;
62+
UILabel *status = [UILabel new];
63+
status.text = @"Navigation root";
64+
status.accessibilityIdentifier = @"agent-device-back-navigation-status";
65+
status.translatesAutoresizingMaskIntoConstraints = NO;
66+
[root.view addSubview:status];
67+
[NSLayoutConstraint activateConstraints:@[
68+
[status.centerXAnchor constraintEqualToAnchor:root.view.centerXAnchor],
69+
[status.centerYAnchor constraintEqualToAnchor:root.view.centerYAnchor],
70+
]];
71+
self.status = status;
72+
self.modalPresentationStyle = UIModalPresentationFullScreen;
73+
if (customBackItem) {
74+
root.navigationItem.leftBarButtonItem =
75+
[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self
76+
action:@selector(customBackPressed)];
77+
} else {
78+
UIViewController *detail = [UIViewController new];
79+
detail.title = @"Detail";
80+
detail.view.backgroundColor = UIColor.systemTealColor;
81+
if (blockedBack) {
82+
if (@available(iOS 16.0, *)) {
83+
BOOL shifting = [NSProcessInfo.processInfo.arguments containsObject:@"--shifting-back"];
84+
__weak UINavigationController *weakSelf = self;
85+
detail.navigationItem.backAction = [UIAction actionWithHandler:^(__kindof UIAction *action) {
86+
if (shifting) weakSelf.additionalSafeAreaInsets = UIEdgeInsetsMake(30, 0, 0, 0);
87+
}];
88+
}
89+
}
90+
if ([NSProcessInfo.processInfo.arguments containsObject:@"--ticking-title"]) {
91+
__block NSInteger remaining = 59;
92+
__weak UIViewController *weakDetail = detail;
93+
self.titleTimer = [NSTimer scheduledTimerWithTimeInterval:0.2 repeats:YES block:^(NSTimer *timer) {
94+
remaining = remaining > 0 ? remaining - 1 : 59;
95+
weakDetail.title = [NSString stringWithFormat:@"0:%02ld", (long)remaining];
96+
}];
97+
}
98+
[self pushViewController:detail animated:NO];
99+
}
100+
return self;
101+
}
102+
103+
- (void)viewDidLoad {
104+
[super viewDidLoad];
105+
self.interactivePopGestureRecognizer.enabled = NO;
106+
self.delegate = self;
107+
}
108+
109+
- (void)customBackPressed {
110+
self.status.text = @"Custom back pressed";
111+
}
112+
113+
- (void)navigationController:(UINavigationController *)navigationController
114+
didShowViewController:(UIViewController *)viewController
115+
animated:(BOOL)animated {
116+
// Only the pushed stack ever shows its root again, and only by popping the detail screen.
117+
if (viewController == self.viewControllers.firstObject && viewController.navigationItem.leftBarButtonItem == nil) {
118+
self.status.text = @"Back pressed";
119+
}
120+
}
121+
@end
122+
123+
// `--two-stacks` shows two pushed navigation stacks, one above the other, so two hittable system
124+
// back buttons are on screen at once and neither is the one `back` should press.
125+
@interface AgentDeviceTwoStacksBackFixture : UIViewController
126+
@end
127+
128+
@implementation AgentDeviceTwoStacksBackFixture
129+
- (void)viewDidLoad {
130+
[super viewDidLoad];
131+
self.view.backgroundColor = UIColor.systemBackgroundColor;
132+
UIStackView *stack = [UIStackView new];
133+
stack.axis = UILayoutConstraintAxisVertical;
134+
stack.distribution = UIStackViewDistributionFillEqually;
135+
stack.translatesAutoresizingMaskIntoConstraints = NO;
136+
[self.view addSubview:stack];
137+
[NSLayoutConstraint activateConstraints:@[
138+
[stack.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor],
139+
[stack.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
140+
[stack.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
141+
[stack.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
142+
]];
143+
for (NSInteger index = 0; index < 2; index++) {
144+
AgentDeviceBackNavigationFixture *child = [[AgentDeviceBackNavigationFixture alloc] initWithCustomBackItem:NO
145+
blockedBack:NO];
146+
[self addChildViewController:child];
147+
[stack addArrangedSubview:child.view];
148+
[child didMoveToParentViewController:self];
149+
}
150+
}
151+
@end
152+
42153
@interface AgentDeviceRunnerFixtureViewController () <UNUserNotificationCenterDelegate>
43154
// Held for the app's lifetime: a window nobody retained would be gone before the test queried it.
44155
@property(nonatomic, strong) UIWindow *secondWindow;
@@ -422,6 +533,17 @@ - (void)presentAlertDeclineChoiceFixture {
422533

423534
- (void)viewDidAppear:(BOOL)animated {
424535
[super viewDidAppear:animated];
536+
if (!self.alertFixtureStarted &&
537+
[NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-back-navigation-bar"]) {
538+
self.alertFixtureStarted = YES;
539+
BOOL customBackItem = [NSProcessInfo.processInfo.arguments containsObject:@"--custom-back-item"];
540+
BOOL blockedBack = [NSProcessInfo.processInfo.arguments containsObject:@"--blocked-back"];
541+
UIViewController *fixture = [NSProcessInfo.processInfo.arguments containsObject:@"--two-stacks"]
542+
? [AgentDeviceTwoStacksBackFixture new]
543+
: [[AgentDeviceBackNavigationFixture alloc] initWithCustomBackItem:customBackItem blockedBack:blockedBack];
544+
fixture.modalPresentationStyle = UIModalPresentationFullScreen;
545+
[self presentViewController:fixture animated:NO completion:nil];
546+
}
425547
if (!self.alertFixtureStarted &&
426548
([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-alert-decline-choice"] ||
427549
[NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-alert-affirmative-only"])) {
@@ -662,12 +784,12 @@ - (void)viewDidLoad {
662784
}
663785
}];
664786
}
665-
// `--slow-toggle` repaints the whole screen every 0.5 s, slower than one verification delay, as
787+
// `--slow-toggle` repaints the whole screen every 0.3 s, slower than one verification delay, as
666788
// a carousel does: one quiet pair of samples must not pass it for settled.
667789
if ([NSProcessInfo.processInfo.arguments containsObject:@"--slow-toggle"]) {
668790
__weak UIView *view = self.view;
669791
[self.animationTimer invalidate];
670-
self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 repeats:YES block:^(NSTimer *timer) {
792+
self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 repeats:YES block:^(NSTimer *timer) {
671793
view.backgroundColor = [view.backgroundColor isEqual:UIColor.blackColor] ? UIColor.whiteColor : UIColor.blackColor;
672794
}];
673795
}

0 commit comments

Comments
 (0)