Flutter Engine
TextSemanticsFocusTest.m
Go to the documentation of this file.
1 // Copyright 2020 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
8 
10 /// Keeps waiting until the element doesn't exist. Returns NO if the timeout is
11 /// reached before it doesn't exist.
12 - (BOOL)ftr_waitForNonExistenceWithTimeout:(NSTimeInterval)timeout;
13 /// Waits the full duration to ensure something doesn't exist for that duration.
14 /// Returns NO if at some point the element exists during the duration.
15 - (BOOL)ftr_waitForNonExistenceForDuration:(NSTimeInterval)duration;
16 @end
17 
19 - (BOOL)ftr_waitForNonExistenceWithTimeout:(NSTimeInterval)timeout {
20  NSTimeInterval delta = 0.5;
21  while (timeout > 0.0) {
22  if (!self.exists) {
23  return YES;
24  }
25  usleep(delta * 1000000);
26  timeout -= delta;
27  }
28  return NO;
29 }
30 
31 - (BOOL)ftr_waitForNonExistenceForDuration:(NSTimeInterval)duration {
32  return ![self waitForExistenceWithTimeout:duration];
33 }
34 
35 @end
36 
37 @implementation TextSemanticsFocusTest
38 
39 - (void)setUp {
40  [super setUp];
41  self.continueAfterFailure = NO;
42 
43  self.application = [[XCUIApplication alloc] init];
44  self.application.launchArguments = @[ @"--text-semantics-focus" ];
45  [self.application launch];
46 }
47 
48 - (void)skip_testAccessibilityFocusOnTextSemanticsProducesCorrectIosViews {
49  NSTimeInterval timeout = 10.0;
50  // Find the initial TextInputSemanticsObject which was sent from the mock framework on first
51  // frame.
52  XCUIElement* textInputSemanticsObject =
53  [[[self.application textFields] matchingIdentifier:@"flutter textfield"] element];
54  XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:timeout]);
55  XCTAssertEqualObjects([textInputSemanticsObject valueForKey:@"hasKeyboardFocus"], @(NO));
56 
57  // Since the first mock framework text field isn't focused on, it shouldn't produce a UITextInput
58  // in the view hierarchy.
59  XCUIElement* delegateTextInput = [[self.application textViews] element];
60  XCTAssertTrue([delegateTextInput ftr_waitForNonExistenceWithTimeout:timeout]);
61 
62  // Nor should there be a keyboard for text entry.
63  XCUIElement* keyboard = [[self.application keyboards] element];
64  XCTAssertTrue([keyboard ftr_waitForNonExistenceWithTimeout:timeout]);
65 
66  // The tap location doesn't matter. The mock framework just sends a focused text field on tap.
67  [textInputSemanticsObject tap];
68 
69  // The new TextInputSemanticsObject now has keyboard focus (the only trait accessible through
70  // UI tests on a XCUIElement).
71  textInputSemanticsObject =
72  [[[self.application textFields] matchingIdentifier:@"focused flutter textfield"] element];
73  XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:timeout]);
74  XCTAssertEqualObjects([textInputSemanticsObject valueForKey:@"hasKeyboardFocus"], @(YES));
75 
76  // The delegate UITextInput is also inserted on the window but we make only the
77  // TextInputSemanticsObject visible and not the FlutterTextInputView to avoid confusing
78  // accessibility, it shouldn't be visible to the UI test either.
79  delegateTextInput = [[self.application textViews] element];
80  XCTAssertTrue([delegateTextInput ftr_waitForNonExistenceForDuration:3.0]);
81 
82  // But since there is focus, the soft keyboard is visible on the simulator.
83  keyboard = [[self.application keyboards] element];
84  XCTAssertTrue([keyboard waitForExistenceWithTimeout:timeout]);
85 }
86 
87 @end
#define FLUTTER_ASSERT_ARC
Definition: FlutterMacros.h:44