From 56cbf3e1d9b373dc70099c96c09e4133f36a332f Mon Sep 17 00:00:00 2001 From: Kostia Sokolovskyi Date: Mon, 18 Sep 2023 22:44:55 +0200 Subject: [PATCH] Cover more test/widgets tests with leak tracking #5 (#134869) --- .../test/material/filled_button_test.dart | 4 +- .../flutter/test/material/snack_bar_test.dart | 1 - .../flutter/test/widgets/listener_test.dart | 35 ++++-- .../widgets/listview_end_append_test.dart | 5 +- .../test/widgets/localizations_test.dart | 7 +- .../test/widgets/lookup_boundary_test.dart | 85 +++++++------- .../flutter/test/widgets/magnifier_test.dart | 12 +- .../test/widgets/mark_needs_build_test.dart | 3 +- .../test/widgets/media_query_test.dart | 65 +++++------ .../test/widgets/modal_barrier_test.dart | 68 ++++++------ .../test/widgets/mouse_region_test.dart | 104 ++++++++++-------- .../test/widgets/multi_view_binding_test.dart | 5 +- .../widgets/multi_view_tree_updates_test.dart | 7 +- .../flutter/test/widgets/multichild_test.dart | 7 +- .../multichildobject_with_keys_test.dart | 7 +- .../widgets/navigator_and_layers_test.dart | 3 +- .../widgets/navigator_replacement_test.dart | 11 +- .../widgets/navigator_restoration_test.dart | 61 +++++----- 18 files changed, 263 insertions(+), 227 deletions(-) diff --git a/packages/flutter/test/material/filled_button_test.dart b/packages/flutter/test/material/filled_button_test.dart index 5c71f5395f..58cfd9c7ae 100644 --- a/packages/flutter/test/material/filled_button_test.dart +++ b/packages/flutter/test/material/filled_button_test.dart @@ -1976,9 +1976,7 @@ void main() { ); expect(controller.value, {MaterialState.disabled}); expect(count, 1); - }, - leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed(), - ); + }); } diff --git a/packages/flutter/test/material/snack_bar_test.dart b/packages/flutter/test/material/snack_bar_test.dart index bf7e4fe7b9..4f32a07907 100644 --- a/packages/flutter/test/material/snack_bar_test.dart +++ b/packages/flutter/test/material/snack_bar_test.dart @@ -2544,7 +2544,6 @@ void main() { }); testWidgetsWithLeakTracking('Should have only one SnackBar during back swipe navigation', - leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed(), (WidgetTester tester) async { const String snackBarText = 'hello snackbar'; const Key snackTarget = Key('snack-target'); diff --git a/packages/flutter/test/widgets/listener_test.dart b/packages/flutter/test/widgets/listener_test.dart index f1f8686cc2..64daf2e4bb 100644 --- a/packages/flutter/test/widgets/listener_test.dart +++ b/packages/flutter/test/widgets/listener_test.dart @@ -8,11 +8,12 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; import 'gesture_utils.dart'; void main() { - testWidgets('Events bubble up the tree', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Events bubble up the tree', (WidgetTester tester) async { final List log = []; await tester.pumpWidget( @@ -46,7 +47,7 @@ void main() { ])); }); - testWidgets('Detects hover events from touch devices', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Detects hover events from touch devices', (WidgetTester tester) async { final List log = []; await tester.pumpWidget( @@ -74,7 +75,7 @@ void main() { }); group('transformed events', () { - testWidgets('simple offset for touch/signal', (WidgetTester tester) async { + testWidgetsWithLeakTracking('simple offset for touch/signal', (WidgetTester tester) async { final List events = []; final Key key = UniqueKey(); @@ -145,7 +146,7 @@ void main() { expect(events.single.transform, expectedTransform); }); - testWidgets('scaled for touch/signal', (WidgetTester tester) async { + testWidgetsWithLeakTracking('scaled for touch/signal', (WidgetTester tester) async { final List events = []; final Key key = UniqueKey(); @@ -222,7 +223,7 @@ void main() { expect(events.single.transform, expectedTransform); }); - testWidgets('scaled and offset for touch/signal', (WidgetTester tester) async { + testWidgetsWithLeakTracking('scaled and offset for touch/signal', (WidgetTester tester) async { final List events = []; final Key key = UniqueKey(); @@ -300,7 +301,7 @@ void main() { expect(events.single.transform, expectedTransform); }); - testWidgets('rotated for touch/signal', (WidgetTester tester) async { + testWidgetsWithLeakTracking('rotated for touch/signal', (WidgetTester tester) async { final List events = []; final Key key = UniqueKey(); @@ -378,9 +379,12 @@ void main() { }); }); - testWidgets("RenderPointerListener's debugFillProperties when default", (WidgetTester tester) async { + testWidgetsWithLeakTracking("RenderPointerListener's debugFillProperties when default", (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); - RenderPointerListener().debugFillProperties(builder); + final RenderPointerListener renderListener = RenderPointerListener(); + addTearDown(renderListener.dispose); + + renderListener.debugFillProperties(builder); final List description = builder.properties .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) @@ -396,9 +400,13 @@ void main() { ]); }); - testWidgets("RenderPointerListener's debugFillProperties when full", (WidgetTester tester) async { + testWidgetsWithLeakTracking("RenderPointerListener's debugFillProperties when full", (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); - RenderPointerListener( + + final RenderErrorBox renderErrorBox = RenderErrorBox(); + addTearDown(() => renderErrorBox.dispose()); + + final RenderPointerListener renderListener = RenderPointerListener( onPointerDown: (PointerDownEvent event) {}, onPointerUp: (PointerUpEvent event) {}, onPointerMove: (PointerMoveEvent event) {}, @@ -406,8 +414,11 @@ void main() { onPointerCancel: (PointerCancelEvent event) {}, onPointerSignal: (PointerSignalEvent event) {}, behavior: HitTestBehavior.opaque, - child: RenderErrorBox(), - ).debugFillProperties(builder); + child: renderErrorBox, + ); + addTearDown(renderListener.dispose); + + renderListener.debugFillProperties(builder); final List description = builder.properties .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) diff --git a/packages/flutter/test/widgets/listview_end_append_test.dart b/packages/flutter/test/widgets/listview_end_append_test.dart index 6d587828fd..1e1cf76869 100644 --- a/packages/flutter/test/widgets/listview_end_append_test.dart +++ b/packages/flutter/test/widgets/listview_end_append_test.dart @@ -5,9 +5,10 @@ import 'package:flutter/gestures.dart' show DragStartBehavior; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; void main() { - testWidgets('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async { + testWidgetsWithLeakTracking('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/9506 Widget buildFrame(int itemCount) { @@ -35,7 +36,7 @@ void main() { expect(find.text('item 3'), findsOneWidget); }); - testWidgets('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async { + testWidgetsWithLeakTracking('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/9506 Widget buildFrame(int itemCount) { diff --git a/packages/flutter/test/widgets/localizations_test.dart b/packages/flutter/test/widgets/localizations_test.dart index ff96e095fa..213fe955f5 100644 --- a/packages/flutter/test/widgets/localizations_test.dart +++ b/packages/flutter/test/widgets/localizations_test.dart @@ -6,11 +6,12 @@ import 'dart:async'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; void main() { final TestAutomatedTestWidgetsFlutterBinding binding = TestAutomatedTestWidgetsFlutterBinding(); - testWidgets('Locale is available when Localizations widget stops deferring frames', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Locale is available when Localizations widget stops deferring frames', (WidgetTester tester) async { final FakeLocalizationsDelegate delegate = FakeLocalizationsDelegate(); await tester.pumpWidget(Localizations( locale: const Locale('fo'), @@ -37,7 +38,7 @@ void main() { expect(find.text('loaded'), findsOneWidget); }); - testWidgets('Localizations.localeOf throws when no localizations exist', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Localizations.localeOf throws when no localizations exist', (WidgetTester tester) async { final GlobalKey contextKey = GlobalKey(debugLabel: 'Test Key'); await tester.pumpWidget(Container(key: contextKey)); @@ -48,7 +49,7 @@ void main() { ))); }); - testWidgets('Localizations.maybeLocaleOf returns null when no localizations exist', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Localizations.maybeLocaleOf returns null when no localizations exist', (WidgetTester tester) async { final GlobalKey contextKey = GlobalKey(debugLabel: 'Test Key'); await tester.pumpWidget(Container(key: contextKey)); diff --git a/packages/flutter/test/widgets/lookup_boundary_test.dart b/packages/flutter/test/widgets/lookup_boundary_test.dart index 36d2d3b310..d1af4fa09a 100644 --- a/packages/flutter/test/widgets/lookup_boundary_test.dart +++ b/packages/flutter/test/widgets/lookup_boundary_test.dart @@ -5,10 +5,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; void main() { group('LookupBoundary.dependOnInheritedWidgetOfExactType', () { - testWidgets('respects boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('respects boundary', (WidgetTester tester) async { InheritedWidget? containerThroughBoundary; InheritedWidget? containerStoppedAtBoundary; @@ -32,7 +33,7 @@ void main() { expect(containerStoppedAtBoundary, isNull); }); - testWidgets('ignores ancestor boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('ignores ancestor boundary', (WidgetTester tester) async { InheritedWidget? inheritedWidget; final Key inheritedKey = UniqueKey(); @@ -53,7 +54,7 @@ void main() { expect(inheritedWidget, equals(tester.widget(find.byKey(inheritedKey)))); }); - testWidgets('finds widget before boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('finds widget before boundary', (WidgetTester tester) async { InheritedWidget? containerThroughBoundary; InheritedWidget? containerStoppedAtBoundary; @@ -80,7 +81,7 @@ void main() { expect(containerStoppedAtBoundary, equals(tester.widget(find.byKey(inheritedKey)))); }); - testWidgets('creates dependency', (WidgetTester tester) async { + testWidgetsWithLeakTracking('creates dependency', (WidgetTester tester) async { MyInheritedWidget? inheritedWidget; final Widget widgetTree = DidChangeDependencySpy( @@ -108,7 +109,7 @@ void main() { expect(tester.state<_DidChangeDependencySpyState>(find.byType(DidChangeDependencySpy)).didChangeDependenciesCount, 2); }); - testWidgets('causes didChangeDependencies to be called on move even if dependency was not fulfilled due to boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('causes didChangeDependencies to be called on move even if dependency was not fulfilled due to boundary', (WidgetTester tester) async { MyInheritedWidget? inheritedWidget; final Key globalKey = GlobalKey(); @@ -173,7 +174,7 @@ void main() { expect(tester.state<_DidChangeDependencySpyState>(find.byType(DidChangeDependencySpy)).didChangeDependenciesCount, 3); }); - testWidgets('causes didChangeDependencies to be called on move even if dependency was non-existant', (WidgetTester tester) async { + testWidgetsWithLeakTracking('causes didChangeDependencies to be called on move even if dependency was non-existant', (WidgetTester tester) async { MyInheritedWidget? inheritedWidget; final Key globalKey = GlobalKey(); @@ -212,7 +213,7 @@ void main() { }); group('LookupBoundary.getElementForInheritedWidgetOfExactType', () { - testWidgets('respects boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('respects boundary', (WidgetTester tester) async { InheritedElement? containerThroughBoundary; InheritedElement? containerStoppedAtBoundary; @@ -236,7 +237,7 @@ void main() { expect(containerStoppedAtBoundary, isNull); }); - testWidgets('ignores ancestor boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('ignores ancestor boundary', (WidgetTester tester) async { InheritedElement? inheritedWidget; final Key inheritedKey = UniqueKey(); @@ -257,7 +258,7 @@ void main() { expect(inheritedWidget, equals(tester.element(find.byKey(inheritedKey)))); }); - testWidgets('finds widget before boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('finds widget before boundary', (WidgetTester tester) async { InheritedElement? containerThroughBoundary; InheritedElement? containerStoppedAtBoundary; @@ -284,7 +285,7 @@ void main() { expect(containerStoppedAtBoundary, equals(tester.element(find.byKey(inheritedKey)))); }); - testWidgets('does not creates dependency', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not creates dependency', (WidgetTester tester) async { final Widget widgetTree = DidChangeDependencySpy( onDidChangeDependencies: (BuildContext context) { @@ -309,7 +310,7 @@ void main() { expect(tester.state<_DidChangeDependencySpyState>(find.byType(DidChangeDependencySpy)).didChangeDependenciesCount, 1); }); - testWidgets('does not cause didChangeDependencies to be called on move when found', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not cause didChangeDependencies to be called on move when found', (WidgetTester tester) async { final Key globalKey = GlobalKey(); final Widget widgetTree = DidChangeDependencySpy( @@ -369,7 +370,7 @@ void main() { expect(tester.state<_DidChangeDependencySpyState>(find.byType(DidChangeDependencySpy)).didChangeDependenciesCount, 1); }); - testWidgets('does not cause didChangeDependencies to be called on move when nothing was found', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not cause didChangeDependencies to be called on move when nothing was found', (WidgetTester tester) async { final Key globalKey = GlobalKey(); final Widget widgetTree = DidChangeDependencySpy( @@ -404,7 +405,7 @@ void main() { }); group('LookupBoundary.findAncestorWidgetOfExactType', () { - testWidgets('respects boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('respects boundary', (WidgetTester tester) async { Widget? containerThroughBoundary; Widget? containerStoppedAtBoundary; Widget? boundaryThroughBoundary; @@ -435,7 +436,7 @@ void main() { expect(boundaryStoppedAtBoundary, equals(tester.widget(find.byKey(boundaryKey)))); }); - testWidgets('finds right widget before boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('finds right widget before boundary', (WidgetTester tester) async { Widget? containerThroughBoundary; Widget? containerStoppedAtBoundary; @@ -466,7 +467,7 @@ void main() { expect(containerStoppedAtBoundary, equals(tester.widget(find.byKey(innerContainerKey)))); }); - testWidgets('works if nothing is found', (WidgetTester tester) async { + testWidgetsWithLeakTracking('works if nothing is found', (WidgetTester tester) async { Widget? containerStoppedAtBoundary; await tester.pumpWidget(Builder( @@ -479,7 +480,7 @@ void main() { expect(containerStoppedAtBoundary, isNull); }); - testWidgets('does not establish a dependency', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not establish a dependency', (WidgetTester tester) async { Widget? containerThroughBoundary; Widget? containerStoppedAtBoundary; Widget? containerStoppedAtBoundaryUnfulfilled; @@ -520,7 +521,7 @@ void main() { }); group('LookupBoundary.findAncestorStateOfType', () { - testWidgets('respects boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('respects boundary', (WidgetTester tester) async { State? containerThroughBoundary; State? containerStoppedAtBoundary; @@ -543,7 +544,7 @@ void main() { expect(containerStoppedAtBoundary, isNull); }); - testWidgets('finds right widget before boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('finds right widget before boundary', (WidgetTester tester) async { State? containerThroughBoundary; State? containerStoppedAtBoundary; @@ -572,7 +573,7 @@ void main() { expect(containerStoppedAtBoundary, equals(tester.state(find.byKey(innerContainerKey)))); }); - testWidgets('works if nothing is found', (WidgetTester tester) async { + testWidgetsWithLeakTracking('works if nothing is found', (WidgetTester tester) async { State? containerStoppedAtBoundary; await tester.pumpWidget(Builder( @@ -585,7 +586,7 @@ void main() { expect(containerStoppedAtBoundary, isNull); }); - testWidgets('does not establish a dependency', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not establish a dependency', (WidgetTester tester) async { State? containerThroughBoundary; State? containerStoppedAtBoundary; State? containerStoppedAtBoundaryUnfulfilled; @@ -626,7 +627,7 @@ void main() { }); group('LookupBoundary.findRootAncestorStateOfType', () { - testWidgets('respects boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('respects boundary', (WidgetTester tester) async { State? containerThroughBoundary; State? containerStoppedAtBoundary; @@ -649,7 +650,7 @@ void main() { expect(containerStoppedAtBoundary, isNull); }); - testWidgets('finds right widget before boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('finds right widget before boundary', (WidgetTester tester) async { State? containerThroughBoundary; State? containerStoppedAtBoundary; @@ -678,7 +679,7 @@ void main() { expect(containerStoppedAtBoundary, equals(tester.state(find.byKey(innerContainerKey)))); }); - testWidgets('works if nothing is found', (WidgetTester tester) async { + testWidgetsWithLeakTracking('works if nothing is found', (WidgetTester tester) async { State? containerStoppedAtBoundary; await tester.pumpWidget(Builder( @@ -691,7 +692,7 @@ void main() { expect(containerStoppedAtBoundary, isNull); }); - testWidgets('does not establish a dependency', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not establish a dependency', (WidgetTester tester) async { State? containerThroughBoundary; State? containerStoppedAtBoundary; State? containerStoppedAtBoundaryUnfulfilled; @@ -732,7 +733,7 @@ void main() { }); group('LookupBoundary.findAncestorRenderObjectOfType', () { - testWidgets('respects boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('respects boundary', (WidgetTester tester) async { RenderPadding? paddingThroughBoundary; RenderPadding? passingStoppedAtBoundary; @@ -756,7 +757,7 @@ void main() { expect(passingStoppedAtBoundary, isNull); }); - testWidgets('finds right widget before boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('finds right widget before boundary', (WidgetTester tester) async { RenderPadding? paddingThroughBoundary; RenderPadding? paddingStoppedAtBoundary; @@ -788,7 +789,7 @@ void main() { expect(paddingStoppedAtBoundary, equals(tester.renderObject(find.byKey(innerPaddingKey)))); }); - testWidgets('works if nothing is found', (WidgetTester tester) async { + testWidgetsWithLeakTracking('works if nothing is found', (WidgetTester tester) async { RenderPadding? paddingStoppedAtBoundary; await tester.pumpWidget(Builder( @@ -801,7 +802,7 @@ void main() { expect(paddingStoppedAtBoundary, isNull); }); - testWidgets('does not establish a dependency', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not establish a dependency', (WidgetTester tester) async { RenderPadding? paddingThroughBoundary; RenderPadding? paddingStoppedAtBoundary; RenderWrap? wrapStoppedAtBoundaryUnfulfilled; @@ -843,7 +844,7 @@ void main() { }); group('LookupBoundary.visitAncestorElements', () { - testWidgets('respects boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('respects boundary', (WidgetTester tester) async { final List throughBoundary = []; final List stoppedAtBoundary = []; final List stoppedAtBoundaryTerminatedEarly = []; @@ -909,7 +910,7 @@ void main() { }); group('LookupBoundary.visitChildElements', () { - testWidgets('respects boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('respects boundary', (WidgetTester tester) async { final Key root = UniqueKey(); final Key child1 = UniqueKey(); final Key child2 = UniqueKey(); @@ -961,7 +962,7 @@ void main() { }); group('LookupBoundary.debugIsHidingAncestorWidgetOfExactType', () { - testWidgets('is hiding', (WidgetTester tester) async { + testWidgetsWithLeakTracking('is hiding', (WidgetTester tester) async { bool? isHidden; await tester.pumpWidget(Container( padding: const EdgeInsets.all(10), @@ -978,7 +979,7 @@ void main() { expect(isHidden, isTrue); }); - testWidgets('is not hiding entity within boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('is not hiding entity within boundary', (WidgetTester tester) async { bool? isHidden; await tester.pumpWidget(Container( padding: const EdgeInsets.all(10), @@ -999,7 +1000,7 @@ void main() { expect(isHidden, isFalse); }); - testWidgets('is not hiding if no boundary exists', (WidgetTester tester) async { + testWidgetsWithLeakTracking('is not hiding if no boundary exists', (WidgetTester tester) async { bool? isHidden; await tester.pumpWidget(Container( padding: const EdgeInsets.all(10), @@ -1014,7 +1015,7 @@ void main() { expect(isHidden, isFalse); }); - testWidgets('is not hiding if no boundary and no entity exists', (WidgetTester tester) async { + testWidgetsWithLeakTracking('is not hiding if no boundary and no entity exists', (WidgetTester tester) async { bool? isHidden; await tester.pumpWidget(Builder( builder: (BuildContext context) { @@ -1027,7 +1028,7 @@ void main() { }); group('LookupBoundary.debugIsHidingAncestorStateOfType', () { - testWidgets('is hiding', (WidgetTester tester) async { + testWidgetsWithLeakTracking('is hiding', (WidgetTester tester) async { bool? isHidden; await tester.pumpWidget(MyStatefulContainer( child: LookupBoundary( @@ -1042,7 +1043,7 @@ void main() { expect(isHidden, isTrue); }); - testWidgets('is not hiding entity within boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('is not hiding entity within boundary', (WidgetTester tester) async { bool? isHidden; await tester.pumpWidget(MyStatefulContainer( child: LookupBoundary( @@ -1059,7 +1060,7 @@ void main() { expect(isHidden, isFalse); }); - testWidgets('is not hiding if no boundary exists', (WidgetTester tester) async { + testWidgetsWithLeakTracking('is not hiding if no boundary exists', (WidgetTester tester) async { bool? isHidden; await tester.pumpWidget(MyStatefulContainer( child: Builder( @@ -1072,7 +1073,7 @@ void main() { expect(isHidden, isFalse); }); - testWidgets('is not hiding if no boundary and no entity exists', (WidgetTester tester) async { + testWidgetsWithLeakTracking('is not hiding if no boundary and no entity exists', (WidgetTester tester) async { bool? isHidden; await tester.pumpWidget(Builder( builder: (BuildContext context) { @@ -1085,7 +1086,7 @@ void main() { }); group('LookupBoundary.debugIsHidingAncestorRenderObjectOfType', () { - testWidgets('is hiding', (WidgetTester tester) async { + testWidgetsWithLeakTracking('is hiding', (WidgetTester tester) async { bool? isHidden; await tester.pumpWidget(Padding( padding: EdgeInsets.zero, @@ -1101,7 +1102,7 @@ void main() { expect(isHidden, isTrue); }); - testWidgets('is not hiding entity within boundary', (WidgetTester tester) async { + testWidgetsWithLeakTracking('is not hiding entity within boundary', (WidgetTester tester) async { bool? isHidden; await tester.pumpWidget(Padding( padding: EdgeInsets.zero, @@ -1120,7 +1121,7 @@ void main() { expect(isHidden, isFalse); }); - testWidgets('is not hiding if no boundary exists', (WidgetTester tester) async { + testWidgetsWithLeakTracking('is not hiding if no boundary exists', (WidgetTester tester) async { bool? isHidden; await tester.pumpWidget(Padding( padding: EdgeInsets.zero, @@ -1134,7 +1135,7 @@ void main() { expect(isHidden, isFalse); }); - testWidgets('is not hiding if no boundary and no entity exists', (WidgetTester tester) async { + testWidgetsWithLeakTracking('is not hiding if no boundary and no entity exists', (WidgetTester tester) async { bool? isHidden; await tester.pumpWidget(Builder( builder: (BuildContext context) { diff --git a/packages/flutter/test/widgets/magnifier_test.dart b/packages/flutter/test/widgets/magnifier_test.dart index b6dda7a2e6..2175efaf8e 100644 --- a/packages/flutter/test/widgets/magnifier_test.dart +++ b/packages/flutter/test/widgets/magnifier_test.dart @@ -9,6 +9,7 @@ import 'package:fake_async/fake_async.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; class _MockAnimationController extends AnimationController { _MockAnimationController() @@ -42,7 +43,7 @@ void main() { } group('Raw Magnifier', () { - testWidgets('should render with correct focal point and decoration', + testWidgetsWithLeakTracking('should render with correct focal point and decoration', (WidgetTester tester) async { final Key appKey = UniqueKey(); const Size magnifierSize = Size(100, 100); @@ -116,7 +117,7 @@ void main() { magnifierController.removeFromOverlay(); }); - testWidgets( + testWidgetsWithLeakTracking( 'should immediately remove from overlay on no animation controller', (WidgetTester tester) async { await runFakeAsync((FakeAsync async) async { @@ -149,7 +150,7 @@ void main() { }); }); - testWidgets('should update shown based on animation status', + testWidgetsWithLeakTracking('should update shown based on animation status', (WidgetTester tester) async { await runFakeAsync((FakeAsync async) async { final MagnifierController magnifierController = @@ -214,7 +215,7 @@ void main() { }); group('show', () { - testWidgets('should insert below below widget', (WidgetTester tester) async { + testWidgetsWithLeakTracking('should insert below below widget', (WidgetTester tester) async { await tester.pumpWidget(const MaterialApp( home: Text('text'), )); @@ -226,6 +227,7 @@ void main() { final OverlayEntry fakeBeforeOverlayEntry = OverlayEntry(builder: (_) => fakeBefore); + addTearDown(() => fakeBeforeOverlayEntry..remove()..dispose()); Overlay.of(context).insert(fakeBeforeOverlayEntry); magnifierController.show( @@ -247,7 +249,7 @@ void main() { expect(allOverlayChildren.first.widget.key, fakeMagnifier.key); }); - testWidgets('should insert newly built widget without animating out if overlay != null', + testWidgetsWithLeakTracking('should insert newly built widget without animating out if overlay != null', (WidgetTester tester) async { await runFakeAsync((FakeAsync async) async { final _MockAnimationController animationController = diff --git a/packages/flutter/test/widgets/mark_needs_build_test.dart b/packages/flutter/test/widgets/mark_needs_build_test.dart index 9fa2d008b3..af21964be2 100644 --- a/packages/flutter/test/widgets/mark_needs_build_test.dart +++ b/packages/flutter/test/widgets/mark_needs_build_test.dart @@ -4,9 +4,10 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; void main() { - testWidgets('setState can be called from build, initState, didChangeDependencies, and didUpdateWidget', (WidgetTester tester) async { + testWidgetsWithLeakTracking('setState can be called from build, initState, didChangeDependencies, and didUpdateWidget', (WidgetTester tester) async { // Initial build. await tester.pumpWidget( const Directionality( diff --git a/packages/flutter/test/widgets/media_query_test.dart b/packages/flutter/test/widgets/media_query_test.dart index 38793a3948..35b0ba95e0 100644 --- a/packages/flutter/test/widgets/media_query_test.dart +++ b/packages/flutter/test/widgets/media_query_test.dart @@ -7,6 +7,7 @@ import 'dart:ui' show Brightness, DisplayFeature, DisplayFeatureState, DisplayFe import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; class _MediaQueryAspectCase { const _MediaQueryAspectCase(this.method, this.data); @@ -43,7 +44,7 @@ class _MediaQueryAspectVariant extends TestVariant<_MediaQueryAspectCase> { } void main() { - testWidgets('MediaQuery does not have a default', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery does not have a default', (WidgetTester tester) async { late final FlutterError error; // Cannot use tester.pumpWidget here because it wraps the widget in a View, // which introduces a MediaQuery ancestor. @@ -87,7 +88,7 @@ void main() { ); }); - testWidgets('MediaQuery.of finds a MediaQueryData when there is one', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.of finds a MediaQueryData when there is one', (WidgetTester tester) async { bool tested = false; await tester.pumpWidget( MediaQuery( @@ -107,7 +108,7 @@ void main() { expect(tested, isTrue); }); - testWidgets('MediaQuery.maybeOf defaults to null', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.maybeOf defaults to null', (WidgetTester tester) async { bool tested = false; // Cannot use tester.pumpWidget here because it wraps the widget in a View, // which introduces a MediaQuery ancestor. @@ -128,7 +129,7 @@ void main() { expect(tested, isTrue); }); - testWidgets('MediaQuery.maybeOf finds a MediaQueryData when there is one', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.maybeOf finds a MediaQueryData when there is one', (WidgetTester tester) async { bool tested = false; await tester.pumpWidget( MediaQuery( @@ -146,7 +147,7 @@ void main() { expect(tested, isTrue); }); - testWidgets('MediaQueryData.fromView is sane', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQueryData.fromView is sane', (WidgetTester tester) async { final MediaQueryData data = MediaQueryData.fromView(tester.view); expect(data, hasOneLineDescription); expect(data.hashCode, equals(data.copyWith().hashCode)); @@ -162,7 +163,7 @@ void main() { expect(data.displayFeatures, isEmpty); }); - testWidgets('MediaQueryData.fromView uses platformData if provided', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQueryData.fromView uses platformData if provided', (WidgetTester tester) async { const MediaQueryData platformData = MediaQueryData( textScaleFactor: 1234, platformBrightness: Brightness.dark, @@ -199,7 +200,7 @@ void main() { expect(data.displayFeatures, tester.view.displayFeatures); }); - testWidgets('MediaQueryData.fromView uses data from platformDispatcher if no platformData is provided', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQueryData.fromView uses data from platformDispatcher if no platformData is provided', (WidgetTester tester) async { tester.platformDispatcher ..textScaleFactorTestValue = 123 ..platformBrightnessTestValue = Brightness.dark @@ -229,7 +230,7 @@ void main() { expect(data.displayFeatures, tester.view.displayFeatures); }); - testWidgets('MediaQuery.fromView injects a new MediaQuery with data from view, preserving platform-specific data', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.fromView injects a new MediaQuery with data from view, preserving platform-specific data', (WidgetTester tester) async { const MediaQueryData platformData = MediaQueryData( textScaleFactor: 1234, platformBrightness: Brightness.dark, @@ -278,7 +279,7 @@ void main() { expect(data.displayFeatures, tester.view.displayFeatures); }); - testWidgets('MediaQuery.fromView injects a new MediaQuery with data from view when no surrounding MediaQuery exists', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.fromView injects a new MediaQuery with data from view when no surrounding MediaQuery exists', (WidgetTester tester) async { tester.platformDispatcher ..textScaleFactorTestValue = 123 ..platformBrightnessTestValue = Brightness.dark @@ -329,7 +330,7 @@ void main() { expect(data.displayFeatures, tester.view.displayFeatures); }); - testWidgets('MediaQuery.fromView updates on notifications (no parent data)', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.fromView updates on notifications (no parent data)', (WidgetTester tester) async { addTearDown(() => tester.platformDispatcher.clearAllTestValues()); addTearDown(() => tester.view.reset()); @@ -392,7 +393,7 @@ void main() { expect(rebuildCount, 5); }); - testWidgets('MediaQuery.fromView updates on notifications (with parent data)', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.fromView updates on notifications (with parent data)', (WidgetTester tester) async { addTearDown(() => tester.platformDispatcher.clearAllTestValues()); addTearDown(() => tester.view.reset()); @@ -451,7 +452,7 @@ void main() { expect(rebuildCount, 2); }); - testWidgets('MediaQuery.fromView updates when parent data changes', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.fromView updates when parent data changes', (WidgetTester tester) async { late MediaQueryData data; int rebuildCount = 0; TextScaler textScaler = const TextScaler.linear(55); @@ -488,7 +489,7 @@ void main() { expect(rebuildCount, 2); }); - testWidgets('MediaQueryData.copyWith defaults to source', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQueryData.copyWith defaults to source', (WidgetTester tester) async { final MediaQueryData data = MediaQueryData.fromView(tester.view); final MediaQueryData copied = data.copyWith(); expect(copied.size, data.size); @@ -510,7 +511,7 @@ void main() { expect(copied.displayFeatures, data.displayFeatures); }); - testWidgets('MediaQuery.copyWith copies specified values', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.copyWith copies specified values', (WidgetTester tester) async { // Random and unique double values are used to ensure that the correct // values are copied over exactly const Size customSize = Size(3.14, 2.72); @@ -570,7 +571,7 @@ void main() { expect(copied.displayFeatures, customDisplayFeatures); }); - testWidgets('MediaQuery.removePadding removes specified padding', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.removePadding removes specified padding', (WidgetTester tester) async { const Size size = Size(2.0, 4.0); const double devicePixelRatio = 2.0; const TextScaler textScaler = TextScaler.linear(1.2); @@ -642,7 +643,7 @@ void main() { expect(unpadded.displayFeatures, displayFeatures); }); - testWidgets('MediaQuery.removePadding only removes specified padding', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.removePadding only removes specified padding', (WidgetTester tester) async { const Size size = Size(2.0, 4.0); const double devicePixelRatio = 2.0; const TextScaler textScaler = TextScaler.linear(1.2); @@ -711,7 +712,7 @@ void main() { expect(unpadded.displayFeatures, displayFeatures); }); - testWidgets('MediaQuery.removeViewInsets removes specified viewInsets', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.removeViewInsets removes specified viewInsets', (WidgetTester tester) async { const Size size = Size(2.0, 4.0); const double devicePixelRatio = 2.0; const TextScaler textScaler = TextScaler.linear(1.2); @@ -783,7 +784,7 @@ void main() { expect(unpadded.displayFeatures, displayFeatures); }); - testWidgets('MediaQuery.removeViewInsets removes only specified viewInsets', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.removeViewInsets removes only specified viewInsets', (WidgetTester tester) async { const Size size = Size(2.0, 4.0); const double devicePixelRatio = 2.0; const TextScaler textScaler = TextScaler.linear(1.2); @@ -852,7 +853,7 @@ void main() { expect(unpadded.displayFeatures, displayFeatures); }); - testWidgets('MediaQuery.removeViewPadding removes specified viewPadding', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.removeViewPadding removes specified viewPadding', (WidgetTester tester) async { const Size size = Size(2.0, 4.0); const double devicePixelRatio = 2.0; const TextScaler textScaler = TextScaler.linear(1.2); @@ -924,7 +925,7 @@ void main() { expect(unpadded.displayFeatures, displayFeatures); }); - testWidgets('MediaQuery.removeViewPadding removes only specified viewPadding', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.removeViewPadding removes only specified viewPadding', (WidgetTester tester) async { const Size size = Size(2.0, 4.0); const double devicePixelRatio = 2.0; const TextScaler textScaler = TextScaler.linear(1.2); @@ -993,7 +994,7 @@ void main() { expect(unpadded.displayFeatures, displayFeatures); }); - testWidgets('MediaQuery.textScalerOf', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.textScalerOf', (WidgetTester tester) async { late TextScaler outsideTextScaler; late TextScaler insideTextScaler; @@ -1020,7 +1021,7 @@ void main() { expect(insideTextScaler, const TextScaler.linear(4.0)); }); - testWidgets('MediaQuery.platformBrightnessOf', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.platformBrightnessOf', (WidgetTester tester) async { late Brightness outsideBrightness; late Brightness insideBrightness; @@ -1047,7 +1048,7 @@ void main() { expect(insideBrightness, Brightness.dark); }); - testWidgets('MediaQuery.highContrastOf', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.highContrastOf', (WidgetTester tester) async { late bool outsideHighContrast; late bool insideHighContrast; @@ -1074,7 +1075,7 @@ void main() { expect(insideHighContrast, true); }); - testWidgets('MediaQuery.onOffSwitchLabelsOf', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.onOffSwitchLabelsOf', (WidgetTester tester) async { late bool outsideOnOffSwitchLabels; late bool insideOnOffSwitchLabels; @@ -1101,7 +1102,7 @@ void main() { expect(insideOnOffSwitchLabels, true); }); - testWidgets('MediaQuery.boldTextOf', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.boldTextOf', (WidgetTester tester) async { late bool outsideBoldTextOverride; late bool insideBoldTextOverride; @@ -1128,7 +1129,7 @@ void main() { expect(insideBoldTextOverride, true); }); - testWidgets('MediaQuery.fromView creates a MediaQuery', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.fromView creates a MediaQuery', (WidgetTester tester) async { MediaQuery? mediaQueryOutside; MediaQuery? mediaQueryInside; @@ -1153,7 +1154,7 @@ void main() { expect(mediaQueryOutside, isNot(mediaQueryInside)); }); - testWidgets('MediaQueryData.fromWindow is created using window values', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQueryData.fromWindow is created using window values', (WidgetTester tester) async { final MediaQueryData windowData = MediaQueryData.fromWindow(tester.view); late MediaQueryData fromWindowData; @@ -1189,7 +1190,7 @@ void main() { expect(settingsA, isNot(settingsB)); }); - testWidgets('MediaQuery.removeDisplayFeatures removes specified display features and padding', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.removeDisplayFeatures removes specified display features and padding', (WidgetTester tester) async { const Size size = Size(82.0, 40.0); const double devicePixelRatio = 2.0; const TextScaler textScaler = TextScaler.linear(1.2); @@ -1263,7 +1264,7 @@ void main() { expect(subScreenMediaQuery.displayFeatures, isEmpty); }); - testWidgets('MediaQuery.removePadding only removes specified display features and padding', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery.removePadding only removes specified display features and padding', (WidgetTester tester) async { const Size size = Size(82.0, 40.0); const double devicePixelRatio = 2.0; const TextScaler textScaler = TextScaler.linear(1.2); @@ -1347,14 +1348,14 @@ void main() { expect(subScreenMediaQuery.displayFeatures, [cutoutDisplayFeature]); }); - testWidgets('MediaQueryData.gestureSettings is set from view.gestureSettings', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQueryData.gestureSettings is set from view.gestureSettings', (WidgetTester tester) async { tester.view.gestureSettings = const GestureSettings(physicalDoubleTapSlop: 100, physicalTouchSlop: 100); addTearDown(() => tester.view.resetGestureSettings()); expect(MediaQueryData.fromView(tester.view).gestureSettings.touchSlop, closeTo(33.33, 0.1)); // Repeating, of course }); - testWidgets('MediaQuery can be partially depended-on', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery can be partially depended-on', (WidgetTester tester) async { MediaQueryData data = const MediaQueryData( size: Size(800, 600), textScaler: TextScaler.linear(1.1), @@ -1430,7 +1431,7 @@ void main() { expect(textScalerBuildCount, 2); }); - testWidgets('MediaQuery partial dependencies', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MediaQuery partial dependencies', (WidgetTester tester) async { MediaQueryData data = const MediaQueryData(); int buildCount = 0; diff --git a/packages/flutter/test/widgets/modal_barrier_test.dart b/packages/flutter/test/widgets/modal_barrier_test.dart index 3d8ea7cc27..d502f9cd3f 100644 --- a/packages/flutter/test/widgets/modal_barrier_test.dart +++ b/packages/flutter/test/widgets/modal_barrier_test.dart @@ -8,6 +8,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; import 'semantics_tester.dart'; @@ -46,7 +47,7 @@ void main() { }); group('ModalBarrier', () { - testWidgets('prevents interactions with widgets behind it', (WidgetTester tester) async { + testWidgetsWithLeakTracking('prevents interactions with widgets behind it', (WidgetTester tester) async { final Widget subject = Stack( textDirection: TextDirection.ltr, children: [ @@ -61,7 +62,7 @@ void main() { expect(tapped, isFalse, reason: 'because the tap is not prevented by ModalBarrier'); }); - testWidgets('prevents hover interactions with widgets behind it', (WidgetTester tester) async { + testWidgetsWithLeakTracking('prevents hover interactions with widgets behind it', (WidgetTester tester) async { final Widget subject = Stack( textDirection: TextDirection.ltr, children: [ @@ -88,7 +89,7 @@ void main() { expect(hovered, isFalse, reason: 'because the hover is not prevented by ModalBarrier'); }); - testWidgets('does not prevent interactions with widgets in front of it', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not prevent interactions with widgets in front of it', (WidgetTester tester) async { final Widget subject = Stack( textDirection: TextDirection.ltr, children: [ @@ -103,7 +104,7 @@ void main() { expect(tapped, isTrue, reason: 'because the tap is prevented by ModalBarrier'); }); - testWidgets('does not prevent interactions with translucent widgets in front of it', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not prevent interactions with translucent widgets in front of it', (WidgetTester tester) async { bool dragged = false; final Widget subject = Stack( textDirection: TextDirection.ltr, @@ -130,7 +131,7 @@ void main() { expect(dragged, isTrue, reason: 'because the drag is prevented by ModalBarrier'); }); - testWidgets('does not prevent hover interactions with widgets in front of it', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not prevent hover interactions with widgets in front of it', (WidgetTester tester) async { final Widget subject = Stack( textDirection: TextDirection.ltr, children: [ @@ -158,7 +159,7 @@ void main() { hovered = false; }); - testWidgets('plays system alert sound when user tries to dismiss it', (WidgetTester tester) async { + testWidgetsWithLeakTracking('plays system alert sound when user tries to dismiss it', (WidgetTester tester) async { final List playedSystemSounds = []; try { tester.binding.defaultBinaryMessenger.setMockMethodCallHandler( @@ -187,7 +188,7 @@ void main() { expect(playedSystemSounds[0], SystemSoundType.alert.toString()); }); - testWidgets('pops the Navigator when dismissed by primary tap', (WidgetTester tester) async { + testWidgetsWithLeakTracking('pops the Navigator when dismissed by primary tap', (WidgetTester tester) async { final Map routes = { '/': (BuildContext context) => const FirstWidget(), '/modal': (BuildContext context) => const SecondWidget(), @@ -220,7 +221,7 @@ void main() { ); }); - testWidgets('pops the Navigator when dismissed by non-primary tap', (WidgetTester tester) async { + testWidgetsWithLeakTracking('pops the Navigator when dismissed by non-primary tap', (WidgetTester tester) async { final Map routes = { '/': (BuildContext context) => const FirstWidget(), '/modal': (BuildContext context) => const SecondWidget(), @@ -254,7 +255,7 @@ void main() { ); }); - testWidgets('may pop the Navigator when competing with other gestures', (WidgetTester tester) async { + testWidgetsWithLeakTracking('may pop the Navigator when competing with other gestures', (WidgetTester tester) async { final Map routes = { '/': (BuildContext context) => const FirstWidget(), '/modal': (BuildContext context) => const SecondWidgetWithCompetence(), @@ -282,7 +283,7 @@ void main() { ); }); - testWidgets('does not pop the Navigator with a WillPopScope that returns false', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not pop the Navigator with a WillPopScope that returns false', (WidgetTester tester) async { bool willPopCalled = false; final Map routes = { '/': (BuildContext context) => const FirstWidget(), @@ -327,7 +328,7 @@ void main() { expect(willPopCalled, isTrue); }); - testWidgets('pops the Navigator with a WillPopScope that returns true', (WidgetTester tester) async { + testWidgetsWithLeakTracking('pops the Navigator with a WillPopScope that returns true', (WidgetTester tester) async { bool willPopCalled = false; final Map routes = { '/': (BuildContext context) => const FirstWidget(), @@ -372,7 +373,7 @@ void main() { expect(willPopCalled, isTrue); }); - testWidgets('will call onDismiss callback', (WidgetTester tester) async { + testWidgetsWithLeakTracking('will call onDismiss callback', (WidgetTester tester) async { bool dismissCallbackCalled = false; final Map routes = { '/': (BuildContext context) => const FirstWidget(), @@ -400,7 +401,7 @@ void main() { expect(dismissCallbackCalled, true); }); - testWidgets('when onDismiss throws, should have correct context', (WidgetTester tester) async { + testWidgetsWithLeakTracking('when onDismiss throws, should have correct context', (WidgetTester tester) async { final FlutterExceptionHandler? handler = FlutterError.onError; FlutterErrorDetails? error; FlutterError.onError = (FlutterErrorDetails details) { @@ -423,7 +424,7 @@ void main() { FlutterError.onError = handler; }); - testWidgets('will not pop when given an onDismiss callback', (WidgetTester tester) async { + testWidgetsWithLeakTracking('will not pop when given an onDismiss callback', (WidgetTester tester) async { final Map routes = { '/': (BuildContext context) => const FirstWidget(), '/modal': (BuildContext context) => SecondWidget(onDismiss: () {}), @@ -450,7 +451,7 @@ void main() { ); }); - testWidgets('Undismissible ModalBarrier hidden in semantic tree', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Undismissible ModalBarrier hidden in semantic tree', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); await tester.pumpWidget(const ModalBarrier(dismissible: false)); @@ -460,7 +461,7 @@ void main() { semantics.dispose(); }); - testWidgets('Dismissible ModalBarrier includes button in semantic tree on iOS, macOS and android', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Dismissible ModalBarrier includes button in semantic tree on iOS, macOS and android', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); await tester.pumpWidget(const Directionality( textDirection: TextDirection.ltr, @@ -486,7 +487,7 @@ void main() { }, variant: const TargetPlatformVariant({ TargetPlatform.iOS, TargetPlatform.macOS, TargetPlatform.android})); }); group('AnimatedModalBarrier', () { - testWidgets('prevents interactions with widgets behind it', (WidgetTester tester) async { + testWidgetsWithLeakTracking('prevents interactions with widgets behind it', (WidgetTester tester) async { final Widget subject = Stack( textDirection: TextDirection.ltr, children: [ @@ -501,7 +502,7 @@ void main() { expect(tapped, isFalse, reason: 'because the tap is not prevented by ModalBarrier'); }); - testWidgets('prevents hover interactions with widgets behind it', (WidgetTester tester) async { + testWidgetsWithLeakTracking('prevents hover interactions with widgets behind it', (WidgetTester tester) async { final Widget subject = Stack( textDirection: TextDirection.ltr, children: [ @@ -528,7 +529,7 @@ void main() { expect(hovered, isFalse, reason: 'because the hover is not prevented by AnimatedModalBarrier'); }); - testWidgets('does not prevent interactions with widgets in front of it', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not prevent interactions with widgets in front of it', (WidgetTester tester) async { final Widget subject = Stack( textDirection: TextDirection.ltr, children: [ @@ -543,7 +544,7 @@ void main() { expect(tapped, isTrue, reason: 'because the tap is prevented by AnimatedModalBarrier'); }); - testWidgets('does not prevent interactions with translucent widgets in front of it', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not prevent interactions with translucent widgets in front of it', (WidgetTester tester) async { bool dragged = false; final Widget subject = Stack( textDirection: TextDirection.ltr, @@ -570,7 +571,7 @@ void main() { expect(dragged, isTrue, reason: 'because the drag is prevented by AnimatedModalBarrier'); }); - testWidgets('does not prevent hover interactions with widgets in front of it', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not prevent hover interactions with widgets in front of it', (WidgetTester tester) async { final Widget subject = Stack( textDirection: TextDirection.ltr, children: [ @@ -598,7 +599,7 @@ void main() { hovered = false; }); - testWidgets('plays system alert sound when user tries to dismiss it', (WidgetTester tester) async { + testWidgetsWithLeakTracking('plays system alert sound when user tries to dismiss it', (WidgetTester tester) async { final List playedSystemSounds = []; try { tester.binding.defaultBinaryMessenger.setMockMethodCallHandler( @@ -627,7 +628,7 @@ void main() { expect(playedSystemSounds[0], SystemSoundType.alert.toString()); }); - testWidgets('pops the Navigator when dismissed by primary tap', (WidgetTester tester) async { + testWidgetsWithLeakTracking('pops the Navigator when dismissed by primary tap', (WidgetTester tester) async { final Map routes = { '/': (BuildContext context) => const FirstWidget(), '/modal': (BuildContext context) => const AnimatedSecondWidget(), @@ -660,7 +661,7 @@ void main() { ); }); - testWidgets('pops the Navigator when dismissed by non-primary tap', (WidgetTester tester) async { + testWidgetsWithLeakTracking('pops the Navigator when dismissed by non-primary tap', (WidgetTester tester) async { final Map routes = { '/': (BuildContext context) => const FirstWidget(), '/modal': (BuildContext context) => const AnimatedSecondWidget(), @@ -694,7 +695,7 @@ void main() { ); }); - testWidgets('may pop the Navigator when competing with other gestures', (WidgetTester tester) async { + testWidgetsWithLeakTracking('may pop the Navigator when competing with other gestures', (WidgetTester tester) async { final Map routes = { '/': (BuildContext context) => const FirstWidget(), '/modal': (BuildContext context) => const AnimatedSecondWidgetWithCompetence(), @@ -722,7 +723,7 @@ void main() { ); }); - testWidgets('does not pop the Navigator with a WillPopScope that returns false', (WidgetTester tester) async { + testWidgetsWithLeakTracking('does not pop the Navigator with a WillPopScope that returns false', (WidgetTester tester) async { bool willPopCalled = false; final Map routes = { '/': (BuildContext context) => const FirstWidget(), @@ -767,7 +768,7 @@ void main() { expect(willPopCalled, isTrue); }); - testWidgets('pops the Navigator with a WillPopScope that returns true', (WidgetTester tester) async { + testWidgetsWithLeakTracking('pops the Navigator with a WillPopScope that returns true', (WidgetTester tester) async { bool willPopCalled = false; final Map routes = { '/': (BuildContext context) => const FirstWidget(), @@ -812,7 +813,7 @@ void main() { expect(willPopCalled, isTrue); }); - testWidgets('will call onDismiss callback', (WidgetTester tester) async { + testWidgetsWithLeakTracking('will call onDismiss callback', (WidgetTester tester) async { bool dismissCallbackCalled = false; final Map routes = { '/': (BuildContext context) => const FirstWidget(), @@ -840,7 +841,7 @@ void main() { expect(dismissCallbackCalled, true); }); - testWidgets('will not pop when given an onDismiss callback', (WidgetTester tester) async { + testWidgetsWithLeakTracking('will not pop when given an onDismiss callback', (WidgetTester tester) async { final Map routes = { '/': (BuildContext context) => const FirstWidget(), '/modal': (BuildContext context) => AnimatedSecondWidget(onDismiss: () {}), @@ -867,7 +868,7 @@ void main() { ); }); - testWidgets('Undismissible AnimatedModalBarrier hidden in semantic tree', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Undismissible AnimatedModalBarrier hidden in semantic tree', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); await tester.pumpWidget(AnimatedModalBarrier(dismissible: false, color: colorAnimation)); @@ -877,7 +878,7 @@ void main() { semantics.dispose(); }); - testWidgets('Dismissible AnimatedModalBarrier includes button in semantic tree on iOS, macOS and android', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Dismissible AnimatedModalBarrier includes button in semantic tree on iOS, macOS and android', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, @@ -904,9 +905,10 @@ void main() { }); group('SemanticsClipper', () { - testWidgets('SemanticsClipper correctly clips Semantics.rect in four directions', (WidgetTester tester) async { + testWidgetsWithLeakTracking('SemanticsClipper correctly clips Semantics.rect in four directions', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); final ValueNotifier notifier = ValueNotifier(const EdgeInsets.fromLTRB(10, 20, 30, 40)); + addTearDown(notifier.dispose); const Rect fullScreen = TestSemantics.fullScreen; await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, @@ -933,7 +935,7 @@ void main() { }, variant: const TargetPlatformVariant({ TargetPlatform.iOS, TargetPlatform.macOS, TargetPlatform.android})); }); - testWidgets('uses default mouse cursor', (WidgetTester tester) async { + testWidgetsWithLeakTracking('uses default mouse cursor', (WidgetTester tester) async { await tester.pumpWidget(const Stack( textDirection: TextDirection.ltr, children: [ diff --git a/packages/flutter/test/widgets/mouse_region_test.dart b/packages/flutter/test/widgets/mouse_region_test.dart index 91e3b3e6e8..a26d7b3d79 100644 --- a/packages/flutter/test/widgets/mouse_region_test.dart +++ b/packages/flutter/test/widgets/mouse_region_test.dart @@ -8,6 +8,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; class HoverClient extends StatefulWidget { const HoverClient({ @@ -77,7 +78,7 @@ class _HoverFeedbackState extends State { void main() { // Regression test for https://github.com/flutter/flutter/issues/73330 - testWidgets('hitTestBehavior test - HitTestBehavior.deferToChild/opaque', (WidgetTester tester) async { + testWidgetsWithLeakTracking('hitTestBehavior test - HitTestBehavior.deferToChild/opaque', (WidgetTester tester) async { bool onEnter = false; await tester.pumpWidget(Center( child: MouseRegion( @@ -103,7 +104,7 @@ void main() { expect(onEnter, true); }); - testWidgets('hitTestBehavior test - HitTestBehavior.deferToChild and non-opaque', (WidgetTester tester) async { + testWidgetsWithLeakTracking('hitTestBehavior test - HitTestBehavior.deferToChild and non-opaque', (WidgetTester tester) async { bool onEnterRegion1 = false; bool onEnterRegion2 = false; await tester.pumpWidget(Directionality( @@ -143,7 +144,7 @@ void main() { expect(onEnterRegion1, true); }); - testWidgets('hitTestBehavior test - HitTestBehavior.translucent', (WidgetTester tester) async { + testWidgetsWithLeakTracking('hitTestBehavior test - HitTestBehavior.translucent', (WidgetTester tester) async { bool onEnterRegion1 = false; bool onEnterRegion2 = false; await tester.pumpWidget(Directionality( @@ -177,7 +178,7 @@ void main() { expect(onEnterRegion1, true); }); - testWidgets('onEnter and onExit can be triggered with mouse buttons pressed', (WidgetTester tester) async { + testWidgetsWithLeakTracking('onEnter and onExit can be triggered with mouse buttons pressed', (WidgetTester tester) async { PointerEnterEvent? enter; PointerExitEvent? exit; await tester.pumpWidget(Center( @@ -212,7 +213,7 @@ void main() { expect(exit!.localPosition, equals(const Offset(-349.0, -249.0))); }); - testWidgets('detects pointer enter', (WidgetTester tester) async { + testWidgetsWithLeakTracking('detects pointer enter', (WidgetTester tester) async { PointerEnterEvent? enter; PointerHoverEvent? move; PointerExitEvent? exit; @@ -244,7 +245,7 @@ void main() { expect(exit, isNull); }); - testWidgets('detects pointer exiting', (WidgetTester tester) async { + testWidgetsWithLeakTracking('detects pointer exiting', (WidgetTester tester) async { PointerEnterEvent? enter; PointerHoverEvent? move; PointerExitEvent? exit; @@ -275,7 +276,7 @@ void main() { expect(exit!.localPosition, equals(const Offset(-349.0, -249.0))); }); - testWidgets('triggers pointer enter when a mouse is connected', (WidgetTester tester) async { + testWidgetsWithLeakTracking('triggers pointer enter when a mouse is connected', (WidgetTester tester) async { PointerEnterEvent? enter; PointerHoverEvent? move; PointerExitEvent? exit; @@ -301,7 +302,7 @@ void main() { expect(exit, isNull); }); - testWidgets('triggers pointer exit when a mouse is disconnected', (WidgetTester tester) async { + testWidgetsWithLeakTracking('triggers pointer exit when a mouse is disconnected', (WidgetTester tester) async { PointerEnterEvent? enter; PointerHoverEvent? move; PointerExitEvent? exit; @@ -339,7 +340,7 @@ void main() { expect(exit, isNull); }); - testWidgets('triggers pointer enter when widget appears', (WidgetTester tester) async { + testWidgetsWithLeakTracking('triggers pointer enter when widget appears', (WidgetTester tester) async { PointerEnterEvent? enter; PointerHoverEvent? move; PointerExitEvent? exit; @@ -375,7 +376,7 @@ void main() { expect(exit, isNull); }); - testWidgets("doesn't trigger pointer exit when widget disappears", (WidgetTester tester) async { + testWidgetsWithLeakTracking("doesn't trigger pointer exit when widget disappears", (WidgetTester tester) async { PointerEnterEvent? enter; PointerHoverEvent? move; PointerExitEvent? exit; @@ -408,7 +409,7 @@ void main() { expect(exit, isNull); }); - testWidgets('triggers pointer enter when widget moves in', (WidgetTester tester) async { + testWidgetsWithLeakTracking('triggers pointer enter when widget moves in', (WidgetTester tester) async { PointerEnterEvent? enter; PointerHoverEvent? move; PointerExitEvent? exit; @@ -450,7 +451,7 @@ void main() { expect(exit, isNull); }); - testWidgets('triggers pointer exit when widget moves out', (WidgetTester tester) async { + testWidgetsWithLeakTracking('triggers pointer exit when widget moves out', (WidgetTester tester) async { PointerEnterEvent? enter; PointerHoverEvent? move; PointerExitEvent? exit; @@ -492,7 +493,7 @@ void main() { expect(exit!.localPosition, equals(const Offset(50, 50))); }); - testWidgets('detects hover from touch devices', (WidgetTester tester) async { + testWidgetsWithLeakTracking('detects hover from touch devices', (WidgetTester tester) async { PointerEnterEvent? enter; PointerHoverEvent? move; PointerExitEvent? exit; @@ -522,7 +523,7 @@ void main() { expect(exit, isNull); }); - testWidgets('Hover works with nested listeners', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Hover works with nested listeners', (WidgetTester tester) async { final UniqueKey key1 = UniqueKey(); final UniqueKey key2 = UniqueKey(); final List enter1 = []; @@ -597,7 +598,7 @@ void main() { clearLists(); }); - testWidgets('Hover transfers between two listeners', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Hover transfers between two listeners', (WidgetTester tester) async { final UniqueKey key1 = UniqueKey(); final UniqueKey key2 = UniqueKey(); final List enter1 = []; @@ -690,7 +691,7 @@ void main() { expect(exit2, isEmpty); }); - testWidgets('applies mouse cursor', (WidgetTester tester) async { + testWidgetsWithLeakTracking('applies mouse cursor', (WidgetTester tester) async { await tester.pumpWidget(const _Scaffold( topLeft: MouseRegion( cursor: SystemMouseCursors.text, @@ -711,7 +712,7 @@ void main() { expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); }); - testWidgets('MouseRegion uses updated callbacks', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MouseRegion uses updated callbacks', (WidgetTester tester) async { final List logs = []; Widget hoverableContainer({ PointerEnterEventListener? onEnter, @@ -773,7 +774,7 @@ void main() { expect(logs, ['enter2', 'hover2', 'exit2']); }); - testWidgets('needsCompositing set when parent class needsCompositing is set', (WidgetTester tester) async { + testWidgetsWithLeakTracking('needsCompositing set when parent class needsCompositing is set', (WidgetTester tester) async { await tester.pumpWidget( MouseRegion( onEnter: (PointerEnterEvent _) {}, @@ -795,7 +796,7 @@ void main() { expect(listener.needsCompositing, isFalse); }); - testWidgets('works with transform', (WidgetTester tester) async { + testWidgetsWithLeakTracking('works with transform', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/31986. final Key key = UniqueKey(); const double scaleFactor = 2.0; @@ -862,7 +863,7 @@ void main() { events.clear(); }); - testWidgets('needsCompositing is always false', (WidgetTester tester) async { + testWidgetsWithLeakTracking('needsCompositing is always false', (WidgetTester tester) async { // Pretend that we have a mouse connected. final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); await gesture.addPointer(); @@ -897,7 +898,7 @@ void main() { expect(tester.layers.whereType(), hasLength(1)); }); - testWidgets("Callbacks aren't called during build", (WidgetTester tester) async { + testWidgetsWithLeakTracking("Callbacks aren't called during build", (WidgetTester tester) async { final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); await gesture.addPointer(location: Offset.zero); @@ -939,7 +940,7 @@ void main() { expect(numExits, equals(0)); }); - testWidgets("MouseRegion activate/deactivate don't duplicate annotations", (WidgetTester tester) async { + testWidgetsWithLeakTracking("MouseRegion activate/deactivate don't duplicate annotations", (WidgetTester tester) async { final GlobalKey feedbackKey = GlobalKey(); final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); await gesture.addPointer(); @@ -983,7 +984,7 @@ void main() { expect(numExits, equals(0)); }); - testWidgets('Exit event when unplugging mouse should have a position', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Exit event when unplugging mouse should have a position', (WidgetTester tester) async { final List enter = []; final List hover = []; final List exit = []; @@ -1031,7 +1032,7 @@ void main() { expect(exit.single.delta, Offset.zero); }); - testWidgets('detects pointer enter with closure arguments', (WidgetTester tester) async { + testWidgetsWithLeakTracking('detects pointer enter with closure arguments', (WidgetTester tester) async { await tester.pumpWidget(const _HoverClientWithClosures()); expect(find.text('not hovering'), findsOneWidget); @@ -1048,7 +1049,7 @@ void main() { expect(find.text('HOVERING'), findsOneWidget); }); - testWidgets('MouseRegion paints child once and only once when MouseRegion is inactive', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MouseRegion paints child once and only once when MouseRegion is inactive', (WidgetTester tester) async { int paintCount = 0; await tester.pumpWidget( Directionality( @@ -1066,7 +1067,7 @@ void main() { expect(paintCount, 1); }); - testWidgets('MouseRegion paints child once and only once when MouseRegion is active', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MouseRegion paints child once and only once when MouseRegion is active', (WidgetTester tester) async { int paintCount = 0; final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); @@ -1088,7 +1089,7 @@ void main() { expect(paintCount, 1); }); - testWidgets('A MouseRegion mounted under the pointer should take effect in the next postframe', (WidgetTester tester) async { + testWidgetsWithLeakTracking('A MouseRegion mounted under the pointer should take effect in the next postframe', (WidgetTester tester) async { bool hovered = false; final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); @@ -1130,7 +1131,7 @@ void main() { expect(tester.binding.hasScheduledFrame, isFalse); }); - testWidgets('A MouseRegion unmounted under the pointer should not trigger state change', (WidgetTester tester) async { + testWidgetsWithLeakTracking('A MouseRegion unmounted under the pointer should not trigger state change', (WidgetTester tester) async { bool hovered = true; final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); @@ -1173,7 +1174,7 @@ void main() { expect(tester.binding.hasScheduledFrame, isFalse); }); - testWidgets('A MouseRegion moved into the mouse should take effect in the next postframe', (WidgetTester tester) async { + testWidgetsWithLeakTracking('A MouseRegion moved into the mouse should take effect in the next postframe', (WidgetTester tester) async { bool hovered = false; final List logHovered = []; bool moved = false; @@ -1303,7 +1304,7 @@ void main() { ); } - testWidgets('a transparent one should allow MouseRegions behind it to receive pointers', (WidgetTester tester) async { + testWidgetsWithLeakTracking('a transparent one should allow MouseRegions behind it to receive pointers', (WidgetTester tester) async { final List logs = []; await tester.pumpWidget(tripleRegions( opaqueC: false, @@ -1350,7 +1351,7 @@ void main() { expect(logs, ['exitC', 'exitB', 'exitA']); }); - testWidgets('an opaque one should prevent MouseRegions behind it receiving pointers', (WidgetTester tester) async { + testWidgetsWithLeakTracking('an opaque one should prevent MouseRegions behind it receiving pointers', (WidgetTester tester) async { final List logs = []; await tester.pumpWidget(tripleRegions( opaqueC: true, @@ -1397,7 +1398,7 @@ void main() { expect(logs, ['exitC', 'exitA']); }); - testWidgets('opaque should default to true', (WidgetTester tester) async { + testWidgetsWithLeakTracking('opaque should default to true', (WidgetTester tester) async { final List logs = []; await tester.pumpWidget(tripleRegions( addLog: (String log) => logs.add(log), @@ -1420,7 +1421,7 @@ void main() { }); }); - testWidgets('an empty opaque MouseRegion is effective', (WidgetTester tester) async { + testWidgetsWithLeakTracking('an empty opaque MouseRegion is effective', (WidgetTester tester) async { bool bottomRegionIsHovered = false; await tester.pumpWidget( Directionality( @@ -1455,7 +1456,7 @@ void main() { expect(bottomRegionIsHovered, isFalse); }); - testWidgets("Changing MouseRegion's callbacks is effective and doesn't repaint", (WidgetTester tester) async { + testWidgetsWithLeakTracking("Changing MouseRegion's callbacks is effective and doesn't repaint", (WidgetTester tester) async { final List logs = []; const Key key = ValueKey(1); @@ -1519,7 +1520,7 @@ void main() { expect(logs, ['paint']); }); - testWidgets('Changing MouseRegion.opaque is effective and repaints', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Changing MouseRegion.opaque is effective and repaints', (WidgetTester tester) async { final List logs = []; final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); @@ -1563,7 +1564,7 @@ void main() { expect(logs, ['paint', 'hover-enter']); }); - testWidgets('Changing MouseRegion.cursor is effective and repaints', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Changing MouseRegion.cursor is effective and repaints', (WidgetTester tester) async { final List logPaints = []; final List logEnters = []; @@ -1610,7 +1611,7 @@ void main() { logEnters.clear(); }); - testWidgets('Changing whether MouseRegion.cursor is null is effective and repaints', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Changing whether MouseRegion.cursor is null is effective and repaints', (WidgetTester tester) async { final List logEnters = []; final List logPaints = []; @@ -1682,7 +1683,7 @@ void main() { logEnters.clear(); }); - testWidgets('Does not trigger side effects during a reparent', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Does not trigger side effects during a reparent', (WidgetTester tester) async { final List logEnters = []; final List logExits = []; final List logCursors = []; @@ -1766,9 +1767,13 @@ void main() { expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click); }); - testWidgets("RenderMouseRegion's debugFillProperties when default", (WidgetTester tester) async { + testWidgetsWithLeakTracking("RenderMouseRegion's debugFillProperties when default", (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); - RenderMouseRegion().debugFillProperties(builder); + + final RenderMouseRegion renderMouseRegion = RenderMouseRegion(); + addTearDown(renderMouseRegion.dispose); + + renderMouseRegion.debugFillProperties(builder); final List description = builder.properties.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)).map((DiagnosticsNode node) => node.toString()).toList(); @@ -1781,16 +1786,23 @@ void main() { ]); }); - testWidgets("RenderMouseRegion's debugFillProperties when full", (WidgetTester tester) async { + testWidgetsWithLeakTracking("RenderMouseRegion's debugFillProperties when full", (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); - RenderMouseRegion( + + final RenderErrorBox renderErrorBox = RenderErrorBox(); + addTearDown(renderErrorBox.dispose); + + final RenderMouseRegion renderMouseRegion = RenderMouseRegion( onEnter: (PointerEnterEvent event) {}, onExit: (PointerExitEvent event) {}, onHover: (PointerHoverEvent event) {}, cursor: SystemMouseCursors.click, validForMouseTracker: false, - child: RenderErrorBox(), - ).debugFillProperties(builder); + child: renderErrorBox, + ); + addTearDown(renderMouseRegion.dispose); + + renderMouseRegion.debugFillProperties(builder); final List description = builder.properties.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)).map((DiagnosticsNode node) => node.toString()).toList(); @@ -1805,7 +1817,7 @@ void main() { ]); }); - testWidgets('No new frames are scheduled when mouse moves without triggering callbacks', (WidgetTester tester) async { + testWidgetsWithLeakTracking('No new frames are scheduled when mouse moves without triggering callbacks', (WidgetTester tester) async { await tester.pumpWidget(Center( child: MouseRegion( child: const SizedBox( @@ -1825,7 +1837,7 @@ void main() { }); // Regression test for https://github.com/flutter/flutter/issues/67044 - testWidgets('Handle mouse events should ignore the detached MouseTrackerAnnotation', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Handle mouse events should ignore the detached MouseTrackerAnnotation', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( home: Center( child: Draggable( diff --git a/packages/flutter/test/widgets/multi_view_binding_test.dart b/packages/flutter/test/widgets/multi_view_binding_test.dart index 6c7c1d09de..d896cfa196 100644 --- a/packages/flutter/test/widgets/multi_view_binding_test.dart +++ b/packages/flutter/test/widgets/multi_view_binding_test.dart @@ -5,9 +5,10 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; void main() { - testWidgets('runApp uses deprecated pipelineOwner and renderView', (WidgetTester tester) async { + testWidgetsWithLeakTracking('runApp uses deprecated pipelineOwner and renderView', (WidgetTester tester) async { runApp(const SizedBox()); final RenderObject renderObject = tester.renderObject(find.byType(SizedBox)); @@ -21,7 +22,7 @@ void main() { expect(renderObject.owner, equals(tester.binding.pipelineOwner)); }); - testWidgets('can manually attach RootWidget to build owner', (WidgetTester tester) async { + testWidgetsWithLeakTracking('can manually attach RootWidget to build owner', (WidgetTester tester) async { expect(find.byType(ColoredBox), findsNothing); final RootWidget rootWidget = RootWidget( diff --git a/packages/flutter/test/widgets/multi_view_tree_updates_test.dart b/packages/flutter/test/widgets/multi_view_tree_updates_test.dart index 7bc41fe9c5..c8d6c049b8 100644 --- a/packages/flutter/test/widgets/multi_view_tree_updates_test.dart +++ b/packages/flutter/test/widgets/multi_view_tree_updates_test.dart @@ -7,9 +7,10 @@ import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; void main() { - testWidgets('Widgets in view update as expected', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Widgets in view update as expected', (WidgetTester tester) async { final Widget widget = View( view: tester.view, child: const TestWidget(), @@ -49,7 +50,7 @@ void main() { expect(tester.renderObject(find.byType(Text)).text.toPlainText(), 'FooBar'); }); - testWidgets('Views in ViewCollection update as expected', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Views in ViewCollection update as expected', (WidgetTester tester) async { Iterable renderParagraphTexts() { return tester.renderObjectList(find.byType(Text)).map((RenderParagraph r) => r.text.toPlainText()); } @@ -103,7 +104,7 @@ void main() { expect(renderParagraphTexts(), ['Guten', 'Morgen']); }); - testWidgets('Views in ViewAnchor update as expected', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Views in ViewAnchor update as expected', (WidgetTester tester) async { Iterable renderParagraphTexts() { return tester.renderObjectList(find.byType(Text)).map((RenderParagraph r) => r.text.toPlainText()); } diff --git a/packages/flutter/test/widgets/multichild_test.dart b/packages/flutter/test/widgets/multichild_test.dart index 78dc38fe9d..f52afc5ef9 100644 --- a/packages/flutter/test/widgets/multichild_test.dart +++ b/packages/flutter/test/widgets/multichild_test.dart @@ -5,6 +5,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; import 'test_widgets.dart'; @@ -32,7 +33,7 @@ void checkTree(WidgetTester tester, List expectedDecorations) { } void main() { - testWidgets('MultiChildRenderObjectElement control test', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MultiChildRenderObjectElement control test', (WidgetTester tester) async { await tester.pumpWidget( const Stack( @@ -117,7 +118,7 @@ void main() { }); - testWidgets('MultiChildRenderObjectElement with stateless widgets', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MultiChildRenderObjectElement with stateless widgets', (WidgetTester tester) async { await tester.pumpWidget( const Stack( @@ -243,7 +244,7 @@ void main() { checkTree(tester, []); }); - testWidgets('MultiChildRenderObjectElement with stateful widgets', (WidgetTester tester) async { + testWidgetsWithLeakTracking('MultiChildRenderObjectElement with stateful widgets', (WidgetTester tester) async { await tester.pumpWidget( const Stack( textDirection: TextDirection.ltr, diff --git a/packages/flutter/test/widgets/multichildobject_with_keys_test.dart b/packages/flutter/test/widgets/multichildobject_with_keys_test.dart index d00260a774..07d04fa389 100644 --- a/packages/flutter/test/widgets/multichildobject_with_keys_test.dart +++ b/packages/flutter/test/widgets/multichildobject_with_keys_test.dart @@ -5,9 +5,10 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; void main() { - testWidgets('Render and element tree stay in sync when keyed children move around', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Render and element tree stay in sync when keyed children move around', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/48855. await tester.pumpWidget( @@ -59,7 +60,7 @@ void main() { ); }); - testWidgets('Building a new MultiChildRenderObjectElement with children having duplicated keys throws', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Building a new MultiChildRenderObjectElement with children having duplicated keys throws', (WidgetTester tester) async { const ValueKey duplicatedKey = ValueKey(1); await tester.pumpWidget(const Column( @@ -79,7 +80,7 @@ void main() { ); }); - testWidgets('Updating a MultiChildRenderObjectElement to have children with duplicated keys throws', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Updating a MultiChildRenderObjectElement to have children with duplicated keys throws', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/81541 const ValueKey key1 = ValueKey(1); diff --git a/packages/flutter/test/widgets/navigator_and_layers_test.dart b/packages/flutter/test/widgets/navigator_and_layers_test.dart index 1283a38643..496b69fc35 100644 --- a/packages/flutter/test/widgets/navigator_and_layers_test.dart +++ b/packages/flutter/test/widgets/navigator_and_layers_test.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; import 'test_widgets.dart'; @@ -26,7 +27,7 @@ class TestCustomPainter extends CustomPainter { } void main() { - testWidgets('Do we paint when coming back from a navigation', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Do we paint when coming back from a navigation', (WidgetTester tester) async { final List log = []; log.add('0'); await tester.pumpWidget( diff --git a/packages/flutter/test/widgets/navigator_replacement_test.dart b/packages/flutter/test/widgets/navigator_replacement_test.dart index d43df8a88c..a1c762c0d6 100644 --- a/packages/flutter/test/widgets/navigator_replacement_test.dart +++ b/packages/flutter/test/widgets/navigator_replacement_test.dart @@ -4,11 +4,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; import 'observer_tester.dart'; void main() { - testWidgets('Back during pushReplacement', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Back during pushReplacement', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( home: const Material(child: Text('home')), routes: { @@ -42,7 +43,7 @@ void main() { }); group('pushAndRemoveUntil', () { - testWidgets('notifies appropriately', (WidgetTester tester) async { + testWidgetsWithLeakTracking('notifies appropriately', (WidgetTester tester) async { final TestObserver observer = TestObserver(); final Widget myApp = MaterialApp( home: const Material(child: Text('home')), @@ -110,7 +111,7 @@ void main() { ])); }); - testWidgets('triggers page transition animation for pushed route', (WidgetTester tester) async { + testWidgetsWithLeakTracking('triggers page transition animation for pushed route', (WidgetTester tester) async { final Widget myApp = MaterialApp( home: const Material(child: Text('home')), routes: { @@ -139,7 +140,7 @@ void main() { expect(find.text('b'), findsOneWidget); }); - testWidgets('Hero transition triggers when preceding route contains hero, and predicate route does not', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Hero transition triggers when preceding route contains hero, and predicate route does not', (WidgetTester tester) async { const String kHeroTag = 'hero'; final Widget myApp = MaterialApp( initialRoute: '/', @@ -184,7 +185,7 @@ void main() { expect(find.text('b'), isOnstage); }); - testWidgets('Hero transition does not trigger when preceding route does not contain hero, but predicate route does', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Hero transition does not trigger when preceding route does not contain hero, but predicate route does', (WidgetTester tester) async { const String kHeroTag = 'hero'; final Widget myApp = MaterialApp( theme: ThemeData( diff --git a/packages/flutter/test/widgets/navigator_restoration_test.dart b/packages/flutter/test/widgets/navigator_restoration_test.dart index ecbed9bfb7..e91d41aa1f 100644 --- a/packages/flutter/test/widgets/navigator_restoration_test.dart +++ b/packages/flutter/test/widgets/navigator_restoration_test.dart @@ -5,9 +5,10 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; void main() { - testWidgets('Restoration Smoke Test', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Restoration Smoke Test', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home', count: 0), findsOneWidget); @@ -29,7 +30,7 @@ void main() { expect(findRoute('home', count: 2), findsOneWidget); }); - testWidgets('restorablePushNamed', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorablePushNamed', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); await tapRouteCounter('home', tester); expect(findRoute('home', count: 1), findsOneWidget); @@ -66,7 +67,7 @@ void main() { expect(findRoute('Bar'), findsNothing); }); - testWidgets('restorablePushReplacementNamed', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorablePushReplacementNamed', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home'), findsOneWidget); @@ -99,7 +100,7 @@ void main() { expect(findRoute('Bar'), findsNothing); }); - testWidgets('restorablePopAndPushNamed', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorablePopAndPushNamed', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home'), findsOneWidget); @@ -132,7 +133,7 @@ void main() { expect(findRoute('Bar'), findsNothing); }); - testWidgets('restorablePushNamedAndRemoveUntil', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorablePushNamedAndRemoveUntil', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home'), findsOneWidget); @@ -165,7 +166,7 @@ void main() { expect(findRoute('Bar'), findsNothing); }); - testWidgets('restorablePush', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorablePush', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); await tapRouteCounter('home', tester); expect(findRoute('home', count: 1), findsOneWidget); @@ -202,7 +203,7 @@ void main() { expect(findRoute('Bar'), findsNothing); }, skip: isBrowser); // https://github.com/flutter/flutter/issues/33615 - testWidgets('restorablePush adds route on all platforms', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorablePush adds route on all platforms', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); await tapRouteCounter('home', tester); expect(findRoute('home', count: 1), findsOneWidget); @@ -212,7 +213,7 @@ void main() { expect(findRoute('Foo'), findsOneWidget); }); - testWidgets('restorablePushReplacement', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorablePushReplacement', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home', count: 0), findsOneWidget); @@ -245,7 +246,7 @@ void main() { expect(findRoute('Bar'), findsNothing); }, skip: isBrowser); // https://github.com/flutter/flutter/issues/33615 - testWidgets('restorablePushReplacement adds route on all platforms', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorablePushReplacement adds route on all platforms', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); await tapRouteCounter('home', tester); expect(findRoute('home', count: 1), findsOneWidget); @@ -255,7 +256,7 @@ void main() { expect(findRoute('Foo'), findsOneWidget); }); - testWidgets('restorablePushAndRemoveUntil', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorablePushAndRemoveUntil', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home', count: 0), findsOneWidget); @@ -288,7 +289,7 @@ void main() { expect(findRoute('Bar'), findsNothing); }, skip: isBrowser); // https://github.com/flutter/flutter/issues/33615 - testWidgets('restorablePushAndRemoveUntil adds route on all platforms', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorablePushAndRemoveUntil adds route on all platforms', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); await tapRouteCounter('home', tester); expect(findRoute('home', count: 1), findsOneWidget); @@ -298,7 +299,7 @@ void main() { expect(findRoute('Foo'), findsOneWidget); }); - testWidgets('restorableReplace', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorableReplace', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home', count: 0), findsOneWidget); @@ -334,7 +335,7 @@ void main() { expect(findRoute('Bar'), findsNothing); }, skip: isBrowser); // https://github.com/flutter/flutter/issues/33615 - testWidgets('restorableReplace adds route on all platforms', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorableReplace adds route on all platforms', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home', count: 0), findsOneWidget); @@ -346,7 +347,7 @@ void main() { expect(findRoute('Foo'), findsOneWidget); }); - testWidgets('restorableReplaceRouteBelow', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorableReplaceRouteBelow', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home', count: 0), findsOneWidget); @@ -392,7 +393,7 @@ void main() { expect(findRoute('Anchor', count: 2), findsOneWidget); }, skip: isBrowser); // https://github.com/flutter/flutter/issues/33615 - testWidgets('restorableReplaceRouteBelow adds route on all platforms', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restorableReplaceRouteBelow adds route on all platforms', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home', count: 0), findsOneWidget); @@ -412,7 +413,7 @@ void main() { expect(findRoute('Foo', skipOffstage: false), findsOneWidget); }); - testWidgets('restoring a popped route', (WidgetTester tester) async { + testWidgetsWithLeakTracking('restoring a popped route', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); await tapRouteCounter('home', tester); expect(findRoute('home', count: 1), findsOneWidget); @@ -440,7 +441,7 @@ void main() { expect(findRoute('Foo', count: 2), findsOneWidget); }); - testWidgets('popped routes are not restored', (WidgetTester tester) async { + testWidgetsWithLeakTracking('popped routes are not restored', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home'), findsOneWidget); @@ -465,7 +466,7 @@ void main() { expect(findRoute('home', skipOffstage: false), findsOneWidget); }); - testWidgets('routes that are in the process of push are restored', (WidgetTester tester) async { + testWidgetsWithLeakTracking('routes that are in the process of push are restored', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home'), findsOneWidget); @@ -494,7 +495,7 @@ void main() { expect(route2.isActive, isTrue); }); - testWidgets('routes that are in the process of pop are not restored', (WidgetTester tester) async { + testWidgetsWithLeakTracking('routes that are in the process of pop are not restored', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); await tapRouteCounter('home', tester); expect(findRoute('home', count: 1), findsOneWidget); @@ -531,7 +532,7 @@ void main() { expect(notifyCount, 1); }); - testWidgets('routes are restored in the right order', (WidgetTester tester) async { + testWidgetsWithLeakTracking('routes are restored in the right order', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home'), findsOneWidget); tester.state(find.byType(Navigator)).restorablePushNamed('route1'); @@ -569,7 +570,7 @@ void main() { expect(findRoute('home'), findsOneWidget); }); - testWidgets('all routes up to first unrestorable are restored', (WidgetTester tester) async { + testWidgetsWithLeakTracking('all routes up to first unrestorable are restored', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home'), findsOneWidget); tester.state(find.byType(Navigator)).restorablePushNamed('route1'); @@ -599,7 +600,7 @@ void main() { expect(findRoute('home', skipOffstage: false), findsOneWidget); }); - testWidgets('removing unrestorable routes restores all of them', (WidgetTester tester) async { + testWidgetsWithLeakTracking('removing unrestorable routes restores all of them', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home'), findsOneWidget); tester.state(find.byType(Navigator)).restorablePushNamed('route1'); @@ -633,7 +634,7 @@ void main() { expect(findRoute('home', skipOffstage: false), findsOneWidget); }); - testWidgets('RestorableRouteFuture', (WidgetTester tester) async { + testWidgetsWithLeakTracking('RestorableRouteFuture', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home'), findsOneWidget); @@ -673,7 +674,7 @@ void main() { expect(restoredRouteFuture.enabled, isFalse); }, skip: isBrowser); // https://github.com/flutter/flutter/issues/33615 - testWidgets('RestorableRouteFuture in unrestorable context', (WidgetTester tester) async { + testWidgetsWithLeakTracking('RestorableRouteFuture in unrestorable context', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); expect(findRoute('home'), findsOneWidget); @@ -704,7 +705,7 @@ void main() { expect(findRoute('home'), findsOneWidget); }); - testWidgets('Illegal arguments throw', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Illegal arguments throw', (WidgetTester tester) async { await tester.pumpWidget(const TestWidget()); tester.state(find.byType(Navigator)).restorablePushNamed('Bar'); await tester.pumpAndSettle(); @@ -787,7 +788,7 @@ void main() { ); }); - testWidgets('Moving scopes', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Moving scopes', (WidgetTester tester) async { await tester.pumpWidget(const RootRestorationScope( restorationId: 'root', child: TestWidget( @@ -840,7 +841,7 @@ void main() { expect(findRoute('home', count: 0), findsOneWidget); }); - testWidgets('Restoring pages', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Restoring pages', (WidgetTester tester) async { await tester.pumpWidget(const PagedTestWidget()); expect(findRoute('home', count: 0), findsOneWidget); await tapRouteCounter('home', tester); @@ -882,7 +883,7 @@ void main() { expect(findRoute('bar', count: 0), findsOneWidget); }); - testWidgets('Unrestorable pages', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Unrestorable pages', (WidgetTester tester) async { await tester.pumpWidget(const PagedTestWidget()); await tapRouteCounter('home', tester); expect(findRoute('home', count: 1), findsOneWidget); @@ -936,7 +937,7 @@ void main() { expect(findRoute('home', count: 1), findsOneWidget); }); - testWidgets('removed page is not restored', (WidgetTester tester) async { + testWidgetsWithLeakTracking('removed page is not restored', (WidgetTester tester) async { await tester.pumpWidget(const PagedTestWidget()); await tapRouteCounter('home', tester); expect(findRoute('home', count: 1), findsOneWidget); @@ -976,7 +977,7 @@ void main() { expect(findRoute('p1', count: 0), findsOneWidget); }); - testWidgets('Helpful assert thrown all routes in onGenerateInitialRoutes are not restorable', (WidgetTester tester) async { + testWidgetsWithLeakTracking('Helpful assert thrown all routes in onGenerateInitialRoutes are not restorable', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( restorationScopeId: 'material_app',