Skip to content

Commit 56cbf3e

Browse files
authored
Cover more test/widgets tests with leak tracking #5 (flutter#134869)
1 parent abf8361 commit 56cbf3e

18 files changed

+263
-227
lines changed

packages/flutter/test/material/filled_button_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,9 +1976,7 @@ void main() {
19761976
);
19771977
expect(controller.value, <MaterialState>{MaterialState.disabled});
19781978
expect(count, 1);
1979-
},
1980-
leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed(),
1981-
);
1979+
});
19821980

19831981
}
19841982

packages/flutter/test/material/snack_bar_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,6 @@ void main() {
25442544
});
25452545

25462546
testWidgetsWithLeakTracking('Should have only one SnackBar during back swipe navigation',
2547-
leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed(),
25482547
(WidgetTester tester) async {
25492548
const String snackBarText = 'hello snackbar';
25502549
const Key snackTarget = Key('snack-target');

packages/flutter/test/widgets/listener_test.dart

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import 'package:flutter/gestures.dart';
88
import 'package:flutter/material.dart';
99
import 'package:flutter/rendering.dart';
1010
import 'package:flutter_test/flutter_test.dart';
11+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
1112

1213
import 'gesture_utils.dart';
1314

1415
void main() {
15-
testWidgets('Events bubble up the tree', (WidgetTester tester) async {
16+
testWidgetsWithLeakTracking('Events bubble up the tree', (WidgetTester tester) async {
1617
final List<String> log = <String>[];
1718

1819
await tester.pumpWidget(
@@ -46,7 +47,7 @@ void main() {
4647
]));
4748
});
4849

49-
testWidgets('Detects hover events from touch devices', (WidgetTester tester) async {
50+
testWidgetsWithLeakTracking('Detects hover events from touch devices', (WidgetTester tester) async {
5051
final List<String> log = <String>[];
5152

5253
await tester.pumpWidget(
@@ -74,7 +75,7 @@ void main() {
7475
});
7576

7677
group('transformed events', () {
77-
testWidgets('simple offset for touch/signal', (WidgetTester tester) async {
78+
testWidgetsWithLeakTracking('simple offset for touch/signal', (WidgetTester tester) async {
7879
final List<PointerEvent> events = <PointerEvent>[];
7980
final Key key = UniqueKey();
8081

@@ -145,7 +146,7 @@ void main() {
145146
expect(events.single.transform, expectedTransform);
146147
});
147148

148-
testWidgets('scaled for touch/signal', (WidgetTester tester) async {
149+
testWidgetsWithLeakTracking('scaled for touch/signal', (WidgetTester tester) async {
149150
final List<PointerEvent> events = <PointerEvent>[];
150151
final Key key = UniqueKey();
151152

@@ -222,7 +223,7 @@ void main() {
222223
expect(events.single.transform, expectedTransform);
223224
});
224225

225-
testWidgets('scaled and offset for touch/signal', (WidgetTester tester) async {
226+
testWidgetsWithLeakTracking('scaled and offset for touch/signal', (WidgetTester tester) async {
226227
final List<PointerEvent> events = <PointerEvent>[];
227228
final Key key = UniqueKey();
228229

@@ -300,7 +301,7 @@ void main() {
300301
expect(events.single.transform, expectedTransform);
301302
});
302303

303-
testWidgets('rotated for touch/signal', (WidgetTester tester) async {
304+
testWidgetsWithLeakTracking('rotated for touch/signal', (WidgetTester tester) async {
304305
final List<PointerEvent> events = <PointerEvent>[];
305306
final Key key = UniqueKey();
306307

@@ -378,9 +379,12 @@ void main() {
378379
});
379380
});
380381

381-
testWidgets("RenderPointerListener's debugFillProperties when default", (WidgetTester tester) async {
382+
testWidgetsWithLeakTracking("RenderPointerListener's debugFillProperties when default", (WidgetTester tester) async {
382383
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
383-
RenderPointerListener().debugFillProperties(builder);
384+
final RenderPointerListener renderListener = RenderPointerListener();
385+
addTearDown(renderListener.dispose);
386+
387+
renderListener.debugFillProperties(builder);
384388

385389
final List<String> description = builder.properties
386390
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
@@ -396,18 +400,25 @@ void main() {
396400
]);
397401
});
398402

399-
testWidgets("RenderPointerListener's debugFillProperties when full", (WidgetTester tester) async {
403+
testWidgetsWithLeakTracking("RenderPointerListener's debugFillProperties when full", (WidgetTester tester) async {
400404
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
401-
RenderPointerListener(
405+
406+
final RenderErrorBox renderErrorBox = RenderErrorBox();
407+
addTearDown(() => renderErrorBox.dispose());
408+
409+
final RenderPointerListener renderListener = RenderPointerListener(
402410
onPointerDown: (PointerDownEvent event) {},
403411
onPointerUp: (PointerUpEvent event) {},
404412
onPointerMove: (PointerMoveEvent event) {},
405413
onPointerHover: (PointerHoverEvent event) {},
406414
onPointerCancel: (PointerCancelEvent event) {},
407415
onPointerSignal: (PointerSignalEvent event) {},
408416
behavior: HitTestBehavior.opaque,
409-
child: RenderErrorBox(),
410-
).debugFillProperties(builder);
417+
child: renderErrorBox,
418+
);
419+
addTearDown(renderListener.dispose);
420+
421+
renderListener.debugFillProperties(builder);
411422

412423
final List<String> description = builder.properties
413424
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))

packages/flutter/test/widgets/listview_end_append_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import 'package:flutter/gestures.dart' show DragStartBehavior;
66
import 'package:flutter/widgets.dart';
77
import 'package:flutter_test/flutter_test.dart';
8+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
89

910
void main() {
10-
testWidgets('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
11+
testWidgetsWithLeakTracking('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
1112
// Regression test for https://github.com/flutter/flutter/issues/9506
1213

1314
Widget buildFrame(int itemCount) {
@@ -35,7 +36,7 @@ void main() {
3536
expect(find.text('item 3'), findsOneWidget);
3637
});
3738

38-
testWidgets('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
39+
testWidgetsWithLeakTracking('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
3940
// Regression test for https://github.com/flutter/flutter/issues/9506
4041

4142
Widget buildFrame(int itemCount) {

packages/flutter/test/widgets/localizations_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import 'dart:async';
66

77
import 'package:flutter/widgets.dart';
88
import 'package:flutter_test/flutter_test.dart';
9+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
910

1011
void main() {
1112
final TestAutomatedTestWidgetsFlutterBinding binding = TestAutomatedTestWidgetsFlutterBinding();
1213

13-
testWidgets('Locale is available when Localizations widget stops deferring frames', (WidgetTester tester) async {
14+
testWidgetsWithLeakTracking('Locale is available when Localizations widget stops deferring frames', (WidgetTester tester) async {
1415
final FakeLocalizationsDelegate delegate = FakeLocalizationsDelegate();
1516
await tester.pumpWidget(Localizations(
1617
locale: const Locale('fo'),
@@ -37,7 +38,7 @@ void main() {
3738
expect(find.text('loaded'), findsOneWidget);
3839
});
3940

40-
testWidgets('Localizations.localeOf throws when no localizations exist', (WidgetTester tester) async {
41+
testWidgetsWithLeakTracking('Localizations.localeOf throws when no localizations exist', (WidgetTester tester) async {
4142
final GlobalKey contextKey = GlobalKey(debugLabel: 'Test Key');
4243
await tester.pumpWidget(Container(key: contextKey));
4344

@@ -48,7 +49,7 @@ void main() {
4849
)));
4950
});
5051

51-
testWidgets('Localizations.maybeLocaleOf returns null when no localizations exist', (WidgetTester tester) async {
52+
testWidgetsWithLeakTracking('Localizations.maybeLocaleOf returns null when no localizations exist', (WidgetTester tester) async {
5253
final GlobalKey contextKey = GlobalKey(debugLabel: 'Test Key');
5354
await tester.pumpWidget(Container(key: contextKey));
5455

0 commit comments

Comments
 (0)