Unverified Commit 874ea75d authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Fix menu_anchor_test.dart's state leak (#112718)

Merging on red to green the build.
parent 99fb2d36
...@@ -16,6 +16,7 @@ void main() { ...@@ -16,6 +16,7 @@ void main() {
final List<TestMenu> opened = <TestMenu>[]; final List<TestMenu> opened = <TestMenu>[];
final List<TestMenu> closed = <TestMenu>[]; final List<TestMenu> closed = <TestMenu>[];
final GlobalKey menuItemKey = GlobalKey(); final GlobalKey menuItemKey = GlobalKey();
late Size defaultSize;
void onPressed(TestMenu item) { void onPressed(TestMenu item) {
selected.add(item); selected.add(item);
...@@ -33,6 +34,11 @@ void main() { ...@@ -33,6 +34,11 @@ void main() {
focusedMenu = primaryFocus?.debugLabel ?? primaryFocus?.toString(); focusedMenu = primaryFocus?.debugLabel ?? primaryFocus?.toString();
} }
setUpAll(() {
final MediaQueryData mediaQueryData = MediaQueryData.fromWindow(TestWidgetsFlutterBinding.instance.window);
defaultSize = mediaQueryData.size;
});
setUp(() { setUp(() {
focusedMenu = null; focusedMenu = null;
selected.clear(); selected.clear();
...@@ -42,6 +48,13 @@ void main() { ...@@ -42,6 +48,13 @@ void main() {
focusedMenu = null; focusedMenu = null;
}); });
Future<void> changeSurfaceSize(WidgetTester tester, Size size) async {
await tester.binding.setSurfaceSize(size);
addTearDown(() async {
await tester.binding.setSurfaceSize(defaultSize);
});
}
void listenForFocusChanges() { void listenForFocusChanges() {
FocusManager.instance.addListener(handleFocusChange); FocusManager.instance.addListener(handleFocusChange);
addTearDown(() => FocusManager.instance.removeListener(handleFocusChange)); addTearDown(() => FocusManager.instance.removeListener(handleFocusChange));
...@@ -1059,16 +1072,13 @@ void main() { ...@@ -1059,16 +1072,13 @@ void main() {
opened.clear(); opened.clear();
const Size smallSize = Size(200, 200); const Size smallSize = Size(200, 200);
await tester.binding.setSurfaceSize(smallSize); await changeSurfaceSize(tester, smallSize);
await tester.pumpWidget(build(smallSize)); await tester.pumpWidget(build(smallSize));
await tester.pump(); await tester.pump();
expect(opened, isEmpty); expect(opened, isEmpty);
expect(closed, isNotEmpty); expect(closed, isNotEmpty);
// Reset binding when done.
await tester.binding.setSurfaceSize(mediaQueryData.size);
}); });
}); });
...@@ -1408,7 +1418,7 @@ void main() { ...@@ -1408,7 +1418,7 @@ void main() {
} }
testWidgets('unconstrained menus show up in the right place in LTR', (WidgetTester tester) async { testWidgets('unconstrained menus show up in the right place in LTR', (WidgetTester tester) async {
await tester.binding.setSurfaceSize(const Size(800, 600)); await changeSurfaceSize(tester, const Size(800, 600));
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Material( home: Material(
...@@ -1446,7 +1456,7 @@ void main() { ...@@ -1446,7 +1456,7 @@ void main() {
}); });
testWidgets('unconstrained menus show up in the right place in RTL', (WidgetTester tester) async { testWidgets('unconstrained menus show up in the right place in RTL', (WidgetTester tester) async {
await tester.binding.setSurfaceSize(const Size(800, 600)); await changeSurfaceSize(tester, const Size(800, 600));
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Directionality( home: Directionality(
...@@ -1487,7 +1497,7 @@ void main() { ...@@ -1487,7 +1497,7 @@ void main() {
}); });
testWidgets('constrained menus show up in the right place in LTR', (WidgetTester tester) async { testWidgets('constrained menus show up in the right place in LTR', (WidgetTester tester) async {
await tester.binding.setSurfaceSize(const Size(300, 300)); await changeSurfaceSize(tester, const Size(300, 300));
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Builder( home: Builder(
...@@ -1526,7 +1536,7 @@ void main() { ...@@ -1526,7 +1536,7 @@ void main() {
}); });
testWidgets('constrained menus show up in the right place in RTL', (WidgetTester tester) async { testWidgets('constrained menus show up in the right place in RTL', (WidgetTester tester) async {
await tester.binding.setSurfaceSize(const Size(300, 300)); await changeSurfaceSize(tester, const Size(300, 300));
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Builder( home: Builder(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment