|
6 | 6 |
|
7 | 7 | static const CGFloat kStandardTimeOut = 60.0; |
8 | 8 |
|
| 9 | +static NSArray<NSString *> *ElementLabels(XCUIElementQuery *query) { |
| 10 | + NSMutableArray<NSString *> *labels = [[NSMutableArray alloc] init]; |
| 11 | + for (XCUIElement *element in query.allElementsBoundByIndex) { |
| 12 | + [labels addObject:element.label]; |
| 13 | + } |
| 14 | + return labels; |
| 15 | +} |
| 16 | + |
9 | 17 | @interface XCUIElement(Test) |
10 | 18 | @property (nonatomic, readonly) BOOL flt_hasKeyboardFocus; |
11 | 19 | - (void)flt_forceTap; |
@@ -68,6 +76,101 @@ - (void)testPlatformViewFocus { |
68 | 76 | XCTAssertFalse(flutterTextField.flt_hasKeyboardFocus); |
69 | 77 | } |
70 | 78 |
|
| 79 | +- (void)testReorderableListAccessibilityHierarchyUpdates { |
| 80 | + // Regression test for https://github.com/flutter/flutter/issues/100946. |
| 81 | + XCUIElement *entranceButton = |
| 82 | + self.app.buttons[@"reorderable list semantics test"]; |
| 83 | + XCTAssertTrue([entranceButton waitForExistenceWithTimeout:kStandardTimeOut], |
| 84 | + @"The element tree is %@", self.app.debugDescription); |
| 85 | + [entranceButton tap]; |
| 86 | + |
| 87 | + XCUIElement *item2 = self.app.staticTexts[@"Item 2"]; |
| 88 | + XCUIElement *item4 = self.app.staticTexts[@"Item 4"]; |
| 89 | + XCTAssertTrue([item2 waitForExistenceWithTimeout:kStandardTimeOut], |
| 90 | + @"The element tree is %@", self.app.debugDescription); |
| 91 | + XCTAssertTrue([item4 waitForExistenceWithTimeout:kStandardTimeOut], |
| 92 | + @"The element tree is %@", self.app.debugDescription); |
| 93 | + |
| 94 | + XCUIElementQuery *items = [self.app.staticTexts |
| 95 | + matchingPredicate:[NSPredicate |
| 96 | + predicateWithFormat:@"label MATCHES 'Item [1-4]'"]]; |
| 97 | + NSArray<NSString *> *initialOrder = |
| 98 | + @[ @"Item 1", @"Item 2", @"Item 3", @"Item 4" ]; |
| 99 | + XCTAssertEqualObjects(ElementLabels(items), initialOrder, |
| 100 | + @"The element tree is %@", self.app.debugDescription); |
| 101 | + |
| 102 | + CGRect item2FrameBeforeReorder = item2.frame; |
| 103 | + CGRect expectedItem2FrameAfterReorder = item4.frame; |
| 104 | + XCUICoordinate *dragStart = |
| 105 | + [item2 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)]; |
| 106 | + XCUICoordinate *dragEnd = |
| 107 | + [item4 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)]; |
| 108 | + [dragStart pressForDuration:1.0 thenDragToCoordinate:dragEnd]; |
| 109 | + |
| 110 | + NSArray<NSString *> *reorderedItems = |
| 111 | + @[ @"Item 1", @"Item 3", @"Item 4", @"Item 2" ]; |
| 112 | + NSPredicate *hierarchyUpdated = |
| 113 | + [NSPredicate predicateWithBlock:^BOOL(XCUIElementQuery *query, |
| 114 | + NSDictionary *bindings) { |
| 115 | + return [ElementLabels(query) isEqualToArray:reorderedItems]; |
| 116 | + }]; |
| 117 | + XCTNSPredicateExpectation *hierarchyExpectation = |
| 118 | + [[XCTNSPredicateExpectation alloc] initWithPredicate:hierarchyUpdated |
| 119 | + object:items]; |
| 120 | + XCTWaiterResult result = |
| 121 | + [XCTWaiter waitForExpectations:@[ hierarchyExpectation ] |
| 122 | + timeout:kStandardTimeOut]; |
| 123 | + CGRect item2FrameAfterReorder = item2.frame; |
| 124 | + XCTAssertEqual(result, XCTWaiterResultCompleted, |
| 125 | + @"Item 2 frame before: %@; after: %@. The element tree is %@", |
| 126 | + NSStringFromCGRect(item2FrameBeforeReorder), |
| 127 | + NSStringFromCGRect(item2FrameAfterReorder), |
| 128 | + self.app.debugDescription); |
| 129 | + XCTAssertEqualObjects(ElementLabels(items), reorderedItems, |
| 130 | + @"The element tree is %@", self.app.debugDescription); |
| 131 | + XCTAssertTrue( |
| 132 | + CGRectEqualToRect(item2FrameAfterReorder, expectedItem2FrameAfterReorder), |
| 133 | + @"Expected Item 2 frame %@ after reorder, but found %@. The element tree " |
| 134 | + @"is %@", |
| 135 | + NSStringFromCGRect(expectedItem2FrameAfterReorder), |
| 136 | + NSStringFromCGRect(item2FrameAfterReorder), self.app.debugDescription); |
| 137 | +} |
| 138 | + |
| 139 | +- (void)testDragScreen { |
| 140 | + XCUIElement *entranceButton = self.app.buttons[@"drag test"]; |
| 141 | + XCTAssertTrue([entranceButton waitForExistenceWithTimeout:kStandardTimeOut], |
| 142 | + @"The element tree is %@", self.app.debugDescription); |
| 143 | + [entranceButton tap]; |
| 144 | + |
| 145 | + XCUIElement *item3 = self.app.staticTexts[@"Item 3"]; |
| 146 | + XCUIElement *item1 = self.app.staticTexts[@"Item 1"]; |
| 147 | + XCTAssertTrue([item3 waitForExistenceWithTimeout:kStandardTimeOut], |
| 148 | + @"The element tree is %@", self.app.debugDescription); |
| 149 | + XCTAssertTrue([item1 waitForExistenceWithTimeout:kStandardTimeOut], |
| 150 | + @"The element tree is %@", self.app.debugDescription); |
| 151 | + |
| 152 | + XCUICoordinate *dragStart = |
| 153 | + [item3 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)]; |
| 154 | + XCUICoordinate *dragEnd = |
| 155 | + [item1 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)]; |
| 156 | + [dragStart pressForDuration:1.0 thenDragToCoordinate:dragEnd]; |
| 157 | + |
| 158 | + XCUIElement *item2 = self.app.staticTexts[@"Item 2"]; |
| 159 | + XCUIElement *item5 = self.app.staticTexts[@"Item 5"]; |
| 160 | + XCTAssertTrue([item2 waitForExistenceWithTimeout:kStandardTimeOut], |
| 161 | + @"The element tree is %@", self.app.debugDescription); |
| 162 | + XCTAssertTrue([item5 waitForExistenceWithTimeout:kStandardTimeOut], |
| 163 | + @"The element tree is %@", self.app.debugDescription); |
| 164 | + |
| 165 | + dragStart = [item2 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)]; |
| 166 | + dragEnd = [item5 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.9)]; |
| 167 | + [dragStart pressForDuration:1.0 thenDragToCoordinate:dragEnd]; |
| 168 | + |
| 169 | + XCUIElement *success = self.app.staticTexts[@"Drag Success"]; |
| 170 | + XCTAssertTrue([success waitForExistenceWithTimeout:kStandardTimeOut], |
| 171 | + @"The element tree is %@", self.app.debugDescription); |
| 172 | +} |
| 173 | + |
71 | 174 | - (void)testPlatformViewZOrder { |
72 | 175 | XCUIElement *entranceButton = self.app.buttons[@"platform view z order test"]; |
73 | 176 | XCTAssertTrue([entranceButton waitForExistenceWithTimeout:kStandardTimeOut], @"The element tree is %@", self.app.debugDescription); |
|
0 commit comments