Skip to content

Commit ece3c3b

Browse files
committed
Add iOS reorder semantics regression test
Exercise the default mobile long-press reorder path and verify that the native iOS semantic hierarchy preserves the reordered item's frame. Issue: flutter#100946
1 parent 09599d4 commit ece3c3b

3 files changed

Lines changed: 122 additions & 0 deletions

File tree

‎dev/integration_tests/ios_platform_view_tests/ios/PlatformViewUITests/PlatformViewUITests.m‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
static const CGFloat kStandardTimeOut = 60.0;
88

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+
917
@interface XCUIElement(Test)
1018
@property (nonatomic, readonly) BOOL flt_hasKeyboardFocus;
1119
- (void)flt_forceTap;
@@ -68,6 +76,66 @@ - (void)testPlatformViewFocus {
6876
XCTAssertFalse(flutterTextField.flt_hasKeyboardFocus);
6977
}
7078

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+
NSLog(@"Item 2 accessibility frame before reorder: %@",
105+
NSStringFromCGRect(item2FrameBeforeReorder));
106+
107+
XCUICoordinate *dragStart =
108+
[item2 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)];
109+
XCUICoordinate *dragEnd =
110+
[item4 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)];
111+
[dragStart pressForDuration:1.0 thenDragToCoordinate:dragEnd];
112+
113+
NSArray<NSString *> *reorderedItems =
114+
@[ @"Item 1", @"Item 3", @"Item 4", @"Item 2" ];
115+
NSPredicate *hierarchyUpdated =
116+
[NSPredicate predicateWithBlock:^BOOL(XCUIElementQuery *query,
117+
NSDictionary *bindings) {
118+
return [ElementLabels(query) isEqualToArray:reorderedItems];
119+
}];
120+
XCTNSPredicateExpectation *hierarchyExpectation =
121+
[[XCTNSPredicateExpectation alloc] initWithPredicate:hierarchyUpdated object:items];
122+
XCTWaiterResult result =
123+
[XCTWaiter waitForExpectations:@[ hierarchyExpectation ] timeout:kStandardTimeOut];
124+
CGRect item2FrameAfterReorder = item2.frame;
125+
NSLog(@"Item 2 accessibility frame after reorder: %@",
126+
NSStringFromCGRect(item2FrameAfterReorder));
127+
XCTAssertEqual(result, XCTWaiterResultCompleted,
128+
@"Item 2 frame before: %@; after: %@. The element tree is %@",
129+
NSStringFromCGRect(item2FrameBeforeReorder),
130+
NSStringFromCGRect(item2FrameAfterReorder), self.app.debugDescription);
131+
XCTAssertEqualObjects(ElementLabels(items), reorderedItems,
132+
@"The element tree is %@", self.app.debugDescription);
133+
XCTAssertTrue(CGRectEqualToRect(item2FrameAfterReorder, expectedItem2FrameAfterReorder),
134+
@"Expected Item 2 frame %@ after reorder, but found %@. The element tree is %@",
135+
NSStringFromCGRect(expectedItem2FrameAfterReorder),
136+
NSStringFromCGRect(item2FrameAfterReorder), self.app.debugDescription);
137+
}
138+
71139
- (void)testPlatformViewZOrder {
72140
XCUIElement *entranceButton = self.app.buttons[@"platform view z order test"];
73141
XCTAssertTrue([entranceButton waitForExistenceWithTimeout:kStandardTimeOut], @"The element tree is %@", self.app.debugDescription);

‎dev/integration_tests/ios_platform_view_tests/lib/main.dart‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
66
import 'package:flutter/services.dart';
77
import 'package:flutter_driver/driver_extension.dart';
88

9+
import 'reorderable_list_semantics.dart';
10+
911
void main() {
1012
// enableFlutterDriverExtension() will disable keyboard,
1113
// which is required for flutter_driver tests
@@ -127,6 +129,17 @@ class _MyHomePageState extends State<MyHomePage> {
127129
);
128130
},
129131
),
132+
TextButton(
133+
child: const Text('reorderable list semantics test'),
134+
onPressed: () {
135+
Navigator.push(
136+
context,
137+
MaterialPageRoute<ReorderableListSemanticsScreen>(
138+
builder: (BuildContext context) => const ReorderableListSemanticsScreen(),
139+
),
140+
);
141+
},
142+
),
130143
],
131144
),
132145
);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2014 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+
5+
import 'package:flutter/material.dart';
6+
7+
/// A mobile [ReorderableListView] fixture that starts a drag after a long press.
8+
class ReorderableListSemanticsScreen extends StatefulWidget {
9+
const ReorderableListSemanticsScreen({super.key});
10+
11+
@override
12+
State<ReorderableListSemanticsScreen> createState() => _ReorderableListSemanticsScreenState();
13+
}
14+
15+
class _ReorderableListSemanticsScreenState extends State<ReorderableListSemanticsScreen> {
16+
final List<String> _items = <String>['Item 1', 'Item 2', 'Item 3', 'Item 4'];
17+
18+
@override
19+
Widget build(BuildContext context) {
20+
return Scaffold(
21+
appBar: AppBar(title: const Text('Reorderable list semantics test')),
22+
body: ReorderableListView.builder(
23+
itemCount: _items.length,
24+
itemBuilder: (BuildContext context, int index) {
25+
final String item = _items[index];
26+
return Semantics(
27+
container: true,
28+
explicitChildNodes: true,
29+
key: ValueKey<String>(item),
30+
child: ListTile(title: Text(item)),
31+
);
32+
},
33+
onReorderItem: (int oldIndex, int newIndex) {
34+
setState(() {
35+
_items.insert(newIndex, _items.removeAt(oldIndex));
36+
});
37+
},
38+
),
39+
);
40+
}
41+
}

0 commit comments

Comments
 (0)