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() {
final List<TestMenu> opened = <TestMenu>[];
final List<TestMenu> closed = <TestMenu>[];
final GlobalKey menuItemKey = GlobalKey();
late Size defaultSize;
void onPressed(TestMenu item) {
selected.add(item);
......@@ -33,6 +34,11 @@ void main() {
focusedMenu = primaryFocus?.debugLabel ?? primaryFocus?.toString();
}
setUpAll(() {
final MediaQueryData mediaQueryData = MediaQueryData.fromWindow(TestWidgetsFlutterBinding.instance.window);
defaultSize = mediaQueryData.size;
});
setUp(() {
focusedMenu = null;
selected.clear();
......@@ -42,6 +48,13 @@ void main() {
focusedMenu = null;
});
Future<void> changeSurfaceSize(WidgetTester tester, Size size) async {
await tester.binding.setSurfaceSize(size);
addTearDown(() async {
await tester.binding.setSurfaceSize(defaultSize);
});
}
void listenForFocusChanges() {
FocusManager.instance.addListener(handleFocusChange);
addTearDown(() => FocusManager.instance.removeListener(handleFocusChange));
......@@ -1059,16 +1072,13 @@ void main() {
opened.clear();
const Size smallSize = Size(200, 200);
await tester.binding.setSurfaceSize(smallSize);
await changeSurfaceSize(tester, smallSize);
await tester.pumpWidget(build(smallSize));
await tester.pump();
expect(opened, isEmpty);
expect(closed, isNotEmpty);
// Reset binding when done.
await tester.binding.setSurfaceSize(mediaQueryData.size);
});
});
......@@ -1408,7 +1418,7 @@ void main() {
}
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(
MaterialApp(
home: Material(
......@@ -1446,7 +1456,7 @@ void main() {
});
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(
MaterialApp(
home: Directionality(
......@@ -1487,7 +1497,7 @@ void main() {
});
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(
MaterialApp(
home: Builder(
......@@ -1526,7 +1536,7 @@ void main() {
});
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(
MaterialApp(
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