Skip to content

Commit 5a80f8d

Browse files
authored
Define testWidgetsWithLeakTracking. (#125063)
1 parent fde717d commit 5a80f8d

22 files changed

+495
-189
lines changed

packages/flutter/test/animation/animation_sheet_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ void main() {
1616
* because [matchesGoldenFile] does not use Skia Gold in its native package.
1717
*/
1818

19+
// TODO(polina-c): fix ValueNotifier not disposed and switch to testWidgetsWithLeakTracking.
20+
// https://github.com/flutter/devtools/issues/3951
1921
testWidgets('correctly records frames using display', (WidgetTester tester) async {
2022
final AnimationSheetBuilder builder = AnimationSheetBuilder(frameSize: _DecuplePixels.size);
2123

@@ -52,6 +54,8 @@ void main() {
5254
await expectLater(find.byWidget(display), matchesGoldenFile('test.animation_sheet_builder.records.png'));
5355
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/56001
5456

57+
// TODO(polina-c): fix ValueNotifier not disposed and switch to testWidgetsWithLeakTracking.
58+
// https://github.com/flutter/devtools/issues/3951
5559
testWidgets('correctly wraps a row', (WidgetTester tester) async {
5660
final AnimationSheetBuilder builder = AnimationSheetBuilder(frameSize: _DecuplePixels.size);
5761

@@ -70,6 +74,8 @@ void main() {
7074
await expectLater(find.byWidget(display), matchesGoldenFile('test.animation_sheet_builder.wraps.png'));
7175
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/56001
7276

77+
// TODO(polina-c): fix Picture and Image not disposed and and switch to testWidgetsWithLeakTracking.
78+
// https://github.com/flutter/devtools/issues/3951
7379
testWidgets('correctly records frames using collate', (WidgetTester tester) async {
7480
final AnimationSheetBuilder builder = AnimationSheetBuilder(frameSize: _DecuplePixels.size);
7581

@@ -104,6 +110,8 @@ void main() {
104110
);
105111
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/56001
106112

113+
// TODO(polina-c): fix Picture and Image not disposed and switch to testWidgetsWithLeakTracking.
114+
// https://github.com/flutter/devtools/issues/3951
107115
testWidgets('use allLayers to record out-of-subtree contents', (WidgetTester tester) async {
108116
final AnimationSheetBuilder builder = AnimationSheetBuilder(
109117
frameSize: const Size(8, 2),

packages/flutter/test/animation/futures_test.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import 'package:flutter/animation.dart';
66
import 'package:flutter/widgets.dart';
77
import 'package:flutter_test/flutter_test.dart';
88

9+
import '../foundation/leak_tracking.dart';
10+
911
void main() {
10-
testWidgets('awaiting animation controllers - using direct future', (WidgetTester tester) async {
12+
testWidgetsWithLeakTracking('awaiting animation controllers - using direct future', (WidgetTester tester) async {
1113
final AnimationController controller1 = AnimationController(
1214
duration: const Duration(milliseconds: 100),
1315
vsync: const TestVSync(),
@@ -56,7 +58,7 @@ void main() {
5658
expect(log, <String>['start', 'a', 'b', 'c', 'd', 'end']);
5759
});
5860

59-
testWidgets('awaiting animation controllers - using orCancel', (WidgetTester tester) async {
61+
testWidgetsWithLeakTracking('awaiting animation controllers - using orCancel', (WidgetTester tester) async {
6062
final AnimationController controller1 = AnimationController(
6163
duration: const Duration(milliseconds: 100),
6264
vsync: const TestVSync(),
@@ -105,7 +107,7 @@ void main() {
105107
expect(log, <String>['start', 'a', 'b', 'c', 'd', 'end']);
106108
});
107109

108-
testWidgets('awaiting animation controllers and failing', (WidgetTester tester) async {
110+
testWidgetsWithLeakTracking('awaiting animation controllers and failing', (WidgetTester tester) async {
109111
final AnimationController controller1 = AnimationController(
110112
duration: const Duration(milliseconds: 100),
111113
vsync: const TestVSync(),
@@ -133,7 +135,7 @@ void main() {
133135
expect(log, <String>['start', 'caught', 'end']);
134136
});
135137

136-
testWidgets('creating orCancel future later', (WidgetTester tester) async {
138+
testWidgetsWithLeakTracking('creating orCancel future later', (WidgetTester tester) async {
137139
final AnimationController controller1 = AnimationController(
138140
duration: const Duration(milliseconds: 100),
139141
vsync: const TestVSync(),
@@ -146,7 +148,7 @@ void main() {
146148
expect(true, isTrue); // should reach here
147149
});
148150

149-
testWidgets('creating orCancel future later', (WidgetTester tester) async {
151+
testWidgetsWithLeakTracking('creating orCancel future later', (WidgetTester tester) async {
150152
final AnimationController controller1 = AnimationController(
151153
duration: const Duration(milliseconds: 100),
152154
vsync: const TestVSync(),
@@ -163,7 +165,7 @@ void main() {
163165
expect(ok, isTrue); // should reach here
164166
});
165167

166-
testWidgets('TickerFuture is a Future', (WidgetTester tester) async {
168+
testWidgetsWithLeakTracking('TickerFuture is a Future', (WidgetTester tester) async {
167169
final AnimationController controller1 = AnimationController(
168170
duration: const Duration(milliseconds: 100),
169171
vsync: const TestVSync(),

packages/flutter/test/animation/iteration_patterns_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import 'package:flutter/widgets.dart';
66
import 'package:flutter_test/flutter_test.dart';
77

8+
import '../foundation/leak_tracking.dart';
9+
810
void main() {
911
setUp(() {
1012
WidgetsFlutterBinding.ensureInitialized();
@@ -79,7 +81,7 @@ void main() {
7981
controller.dispose();
8082
});
8183

82-
testWidgets('AnimationController with throwing listener', (WidgetTester tester) async {
84+
testWidgetsWithLeakTracking('AnimationController with throwing listener', (WidgetTester tester) async {
8385
final AnimationController controller = AnimationController(
8486
duration: const Duration(milliseconds: 100),
8587
vsync: const TestVSync(),
@@ -102,7 +104,7 @@ void main() {
102104
log.clear();
103105
});
104106

105-
testWidgets('AnimationController with throwing status listener', (WidgetTester tester) async {
107+
testWidgetsWithLeakTracking('AnimationController with throwing status listener', (WidgetTester tester) async {
106108
final AnimationController controller = AnimationController(
107109
duration: const Duration(milliseconds: 100),
108110
vsync: const TestVSync(),

packages/flutter/test/animation/live_binding_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ library;
1010
import 'package:flutter/material.dart';
1111
import 'package:flutter_test/flutter_test.dart';
1212

13+
import '../foundation/leak_tracking.dart';
14+
1315
void main() {
1416
/*
1517
* Here lies golden tests for packages/flutter_test/lib/src/binding.dart
@@ -18,7 +20,7 @@ void main() {
1820

1921
LiveTestWidgetsFlutterBinding().framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.onlyPumps;
2022

21-
testWidgets('Should show event indicator for pointer events', (WidgetTester tester) async {
23+
testWidgetsWithLeakTracking('Should show event indicator for pointer events', (WidgetTester tester) async {
2224
final AnimationSheetBuilder animationSheet = AnimationSheetBuilder(frameSize: const Size(200, 200), allLayers: true);
2325
final List<Offset> taps = <Offset>[];
2426
Widget target({bool recording = true}) => Container(
@@ -76,6 +78,8 @@ void main() {
7678
// Currently skipped due to daily flake: https://github.com/flutter/flutter/issues/87588
7779
}, skip: true); // Typically skip: isBrowser https://github.com/flutter/flutter/issues/42767
7880

81+
// TODO(polina-c): fix ValueNotifier not disposed and switch to testWidgetsWithLeakTracking.
82+
// https://github.com/flutter/devtools/issues/3951
7983
testWidgets('Should show event indicator for pointer events with setSurfaceSize', (WidgetTester tester) async {
8084
final AnimationSheetBuilder animationSheet = AnimationSheetBuilder(frameSize: const Size(200, 200), allLayers: true);
8185
final List<Offset> taps = <Offset>[];

packages/flutter/test/flutter_test_config.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ import 'dart:async';
66

77
import 'package:flutter/rendering.dart';
88
import 'package:flutter_test/flutter_test.dart';
9+
import 'package:leak_tracker/leak_tracker.dart';
910

1011
import '_goldens_io.dart'
1112
if (dart.library.html) '_goldens_web.dart' as flutter_goldens;
1213

14+
/// Test configuration for each test library in this directory.
15+
///
16+
/// See https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html.
1317
Future<void> testExecutable(FutureOr<void> Function() testMain) {
1418
// Enable checks because there are many implementations of [RenderBox] in this
1519
// package can benefit from the additional validations.
@@ -19,6 +23,8 @@ Future<void> testExecutable(FutureOr<void> Function() testMain) {
1923
// receive the event.
2024
WidgetController.hitTestWarningShouldBeFatal = true;
2125

26+
LeakTrackingTestConfig.warnForNonSupportedPlatforms = false;
27+
2228
// Enable golden file testing using Skia Gold.
2329
return flutter_goldens.testExecutable(testMain);
2430
}

packages/flutter/test/foundation/change_notifier_test.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import 'package:flutter/foundation.dart';
66
import 'package:flutter_test/flutter_test.dart';
77

8+
import 'leak_tracking.dart';
9+
810
class TestNotifier extends ChangeNotifier {
911
void notify() {
1012
notifyListeners();
@@ -49,23 +51,25 @@ class Counter with ChangeNotifier {
4951
}
5052

5153
void main() {
52-
testWidgets('ChangeNotifier can not dispose in callback', (WidgetTester tester) async {
54+
testWidgetsWithLeakTracking('ChangeNotifier can not dispose in callback', (WidgetTester tester) async {
5355
final TestNotifier test = TestNotifier();
5456
bool callbackDidFinish = false;
5557
void foo() {
5658
test.dispose();
5759
callbackDidFinish = true;
5860
}
59-
6061
test.addListener(foo);
62+
6163
test.notify();
64+
6265
final AssertionError error = tester.takeException() as AssertionError;
6366
expect(error.toString().contains('dispose()'), isTrue);
6467
// Make sure it crashes during dispose call.
6568
expect(callbackDidFinish, isFalse);
69+
test.dispose();
6670
});
6771

68-
testWidgets('ChangeNotifier', (WidgetTester tester) async {
72+
testWidgetsWithLeakTracking('ChangeNotifier', (WidgetTester tester) async {
6973
final List<String> log = <String>[];
7074
void listener() {
7175
log.add('listener');
@@ -147,6 +151,7 @@ void main() {
147151
expect(log, <String>['badListener', 'listener1', 'listener2']);
148152
expect(tester.takeException(), isArgumentError);
149153
log.clear();
154+
test.dispose();
150155
});
151156

152157
test('ChangeNotifier with mutating listener', () {

0 commit comments

Comments
 (0)