From 103c9c78fcd7833e13554916ee622fc706add0ff Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Mon, 27 Apr 2020 23:53:22 -0700 Subject: [PATCH] Bumped up the timeout for testAccessibilityFocusOnTextSemanticsProducesCorrectIosViews (#17988) * Bumped up the timeout for testAccessibilityFocusOnTextSemanticsProducesCorrectIosViews * ran formatter * made an alternative version of the assertion * removed log statements, seems to mess with the buildbot's xcpretty --- .../ScenariosUITests/TextSemanticsFocusTest.m | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/TextSemanticsFocusTest.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/TextSemanticsFocusTest.m index 900723266..dd004f6b2 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/TextSemanticsFocusTest.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/TextSemanticsFocusTest.m @@ -6,6 +6,34 @@ FLUTTER_ASSERT_ARC +@interface XCUIElement (ftr_waitForNonExistence) +/// Keeps waiting until the element doesn't exist. Returns NO if the timeout is +/// reached before it doesn't exist. +- (BOOL)ftr_waitForNonExistenceWithTimeout:(NSTimeInterval)timeout; +/// Waits the full duration to ensure something doesn't exist for that duration. +/// Returns NO if at some point the element exists during the duration. +- (BOOL)ftr_waitForNonExistenceForDuration:(NSTimeInterval)duration; +@end + +@implementation XCUIElement (ftr_waitForNonExistence) +- (BOOL)ftr_waitForNonExistenceWithTimeout:(NSTimeInterval)timeout { + NSTimeInterval delta = 0.5; + while (timeout > 0.0) { + if (!self.exists) { + return YES; + } + usleep(delta * 1000000); + timeout -= delta; + } + return NO; +} + +- (BOOL)ftr_waitForNonExistenceForDuration:(NSTimeInterval)duration { + return ![self waitForExistenceWithTimeout:duration]; +} + +@end + @implementation TextSemanticsFocusTest - (void)setUp { @@ -18,21 +46,22 @@ FLUTTER_ASSERT_ARC } - (void)testAccessibilityFocusOnTextSemanticsProducesCorrectIosViews { + NSTimeInterval timeout = 10.0; // Find the initial TextInputSemanticsObject which was sent from the mock framework on first // frame. XCUIElement* textInputSemanticsObject = [[[self.application textFields] matchingIdentifier:@"flutter textfield"] element]; - XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:3]); + XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:timeout]); XCTAssertEqualObjects([textInputSemanticsObject valueForKey:@"hasKeyboardFocus"], @(NO)); // Since the first mock framework text field isn't focused on, it shouldn't produce a UITextInput // in the view hierarchy. XCUIElement* delegateTextInput = [[self.application textViews] element]; - XCTAssertFalse([delegateTextInput waitForExistenceWithTimeout:3]); + XCTAssertTrue([delegateTextInput ftr_waitForNonExistenceWithTimeout:timeout]); // Nor should there be a keyboard for text entry. XCUIElement* keyboard = [[self.application keyboards] element]; - XCTAssertFalse([keyboard waitForExistenceWithTimeout:3]); + XCTAssertTrue([keyboard ftr_waitForNonExistenceWithTimeout:timeout]); // The tap location doesn't matter. The mock framework just sends a focused text field on tap. [textInputSemanticsObject tap]; @@ -41,18 +70,18 @@ FLUTTER_ASSERT_ARC // UI tests on a XCUIElement). textInputSemanticsObject = [[[self.application textFields] matchingIdentifier:@"focused flutter textfield"] element]; - XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:3]); + XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:timeout]); XCTAssertEqualObjects([textInputSemanticsObject valueForKey:@"hasKeyboardFocus"], @(YES)); // The delegate UITextInput is also inserted on the window but we make only the // TextInputSemanticsObject visible and not the FlutterTextInputView to avoid confusing // accessibility, it shouldn't be visible to the UI test either. delegateTextInput = [[self.application textViews] element]; - XCTAssertFalse([delegateTextInput waitForExistenceWithTimeout:3]); + XCTAssertTrue([delegateTextInput ftr_waitForNonExistenceForDuration:3.0]); // But since there is focus, the soft keyboard is visible on the simulator. keyboard = [[self.application keyboards] element]; - XCTAssertTrue([keyboard waitForExistenceWithTimeout:3]); + XCTAssertTrue([keyboard waitForExistenceWithTimeout:timeout]); } @end -- GitLab