Skip to content

Commit 5c341a1

Browse files
polina-cMairramer
authored andcommitted
Cover more tests with leak tracking. (flutter#134805)
1 parent 491f981 commit 5c341a1

10 files changed

+215
-146
lines changed

packages/flutter/test/cupertino/activity_indicator_test.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ library;
1010
import 'package:flutter/cupertino.dart';
1111
import 'package:flutter/scheduler.dart';
1212
import 'package:flutter_test/flutter_test.dart';
13+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
1314

1415
void main() {
15-
testWidgets('Activity indicator animate property works', (WidgetTester tester) async {
16+
testWidgetsWithLeakTracking('Activity indicator animate property works', (WidgetTester tester) async {
1617
await tester.pumpWidget(buildCupertinoActivityIndicator());
1718
expect(SchedulerBinding.instance.transientCallbackCount, equals(1));
1819

@@ -28,7 +29,7 @@ void main() {
2829
expect(SchedulerBinding.instance.transientCallbackCount, equals(1));
2930
});
3031

31-
testWidgets('Activity indicator dark mode', (WidgetTester tester) async {
32+
testWidgetsWithLeakTracking('Activity indicator dark mode', (WidgetTester tester) async {
3233
final Key key = UniqueKey();
3334
await tester.pumpWidget(
3435
Center(
@@ -77,7 +78,7 @@ void main() {
7778
);
7879
});
7980

80-
testWidgets('Activity indicator 0% in progress', (WidgetTester tester) async {
81+
testWidgetsWithLeakTracking('Activity indicator 0% in progress', (WidgetTester tester) async {
8182
final Key key = UniqueKey();
8283
await tester.pumpWidget(
8384
Center(
@@ -99,7 +100,7 @@ void main() {
99100
);
100101
});
101102

102-
testWidgets('Activity indicator 30% in progress', (WidgetTester tester) async {
103+
testWidgetsWithLeakTracking('Activity indicator 30% in progress', (WidgetTester tester) async {
103104
final Key key = UniqueKey();
104105
await tester.pumpWidget(
105106
Center(
@@ -121,7 +122,7 @@ void main() {
121122
);
122123
});
123124

124-
testWidgets('Activity indicator 100% in progress', (WidgetTester tester) async {
125+
testWidgetsWithLeakTracking('Activity indicator 100% in progress', (WidgetTester tester) async {
125126
final Key key = UniqueKey();
126127
await tester.pumpWidget(
127128
Center(
@@ -142,7 +143,7 @@ void main() {
142143
});
143144

144145
// Regression test for https://github.com/flutter/flutter/issues/41345.
145-
testWidgets('has the correct corner radius', (WidgetTester tester) async {
146+
testWidgetsWithLeakTracking('has the correct corner radius', (WidgetTester tester) async {
146147
await tester.pumpWidget(
147148
const CupertinoActivityIndicator(animating: false, radius: 100),
148149
);
@@ -158,7 +159,7 @@ void main() {
158159
);
159160
});
160161

161-
testWidgets('Can specify color', (WidgetTester tester) async {
162+
testWidgetsWithLeakTracking('Can specify color', (WidgetTester tester) async {
162163
final Key key = UniqueKey();
163164
await tester.pumpWidget(
164165
Center(

packages/flutter/test/cupertino/adaptive_text_selection_toolbar_test.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/cupertino.dart';
66
import 'package:flutter/foundation.dart';
77
import 'package:flutter/services.dart';
88
import 'package:flutter_test/flutter_test.dart';
9+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
910

1011
import '../widgets/clipboard_utils.dart';
1112
import '../widgets/live_text_utils.dart';
@@ -37,7 +38,7 @@ void main() {
3738
);
3839
}
3940

40-
testWidgets('Builds the right toolbar on each platform, including web, and shows buttonItems', (WidgetTester tester) async {
41+
testWidgetsWithLeakTracking('Builds the right toolbar on each platform, including web, and shows buttonItems', (WidgetTester tester) async {
4142
const String buttonText = 'Click me';
4243

4344
await tester.pumpWidget(
@@ -78,7 +79,7 @@ void main() {
7879
skip: isBrowser, // [intended] see https://github.com/flutter/flutter/issues/108382
7980
);
8081

81-
testWidgets('Can build children directly as well', (WidgetTester tester) async {
82+
testWidgetsWithLeakTracking('Can build children directly as well', (WidgetTester tester) async {
8283
final GlobalKey key = GlobalKey();
8384

8485
await tester.pumpWidget(
@@ -101,17 +102,21 @@ void main() {
101102
skip: isBrowser, // [intended] see https://github.com/flutter/flutter/issues/108382
102103
);
103104

104-
testWidgets('Can build from EditableTextState', (WidgetTester tester) async {
105+
testWidgetsWithLeakTracking('Can build from EditableTextState', (WidgetTester tester) async {
105106
final GlobalKey key = GlobalKey();
107+
final FocusNode focusNode = FocusNode();
108+
addTearDown(focusNode.dispose);
109+
final TextEditingController controller = TextEditingController();
110+
addTearDown(controller.dispose);
106111
await tester.pumpWidget(CupertinoApp(
107112
home: Align(
108113
alignment: Alignment.topLeft,
109114
child: SizedBox(
110115
width: 400,
111116
child: EditableText(
112-
controller: TextEditingController(),
117+
controller: controller,
113118
backgroundCursorColor: const Color(0xff00ffff),
114-
focusNode: FocusNode(),
119+
focusNode: focusNode,
115120
style: const TextStyle(),
116121
cursorColor: const Color(0xff00ffff),
117122
selectionControls: cupertinoTextSelectionHandleControls,
@@ -160,7 +165,7 @@ void main() {
160165
variant: TargetPlatformVariant.all(),
161166
);
162167

163-
testWidgets('Can build for editable text from raw parameters', (WidgetTester tester) async {
168+
testWidgetsWithLeakTracking('Can build for editable text from raw parameters', (WidgetTester tester) async {
164169
final GlobalKey key = GlobalKey();
165170
await tester.pumpWidget(CupertinoApp(
166171
home: Center(
@@ -210,7 +215,7 @@ void main() {
210215
variant: TargetPlatformVariant.all(),
211216
);
212217

213-
testWidgets('Builds the correct button per-platform', (WidgetTester tester) async {
218+
testWidgetsWithLeakTracking('Builds the correct button per-platform', (WidgetTester tester) async {
214219
const String buttonText = 'Click me';
215220

216221
await tester.pumpWidget(

packages/flutter/test/cupertino/app_test.dart

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void main() {
4040
expect(find.widgetWithText(Navigator, 'foo'), findsOneWidget);
4141
});
4242

43-
testWidgets('Has default cupertino localizations', (WidgetTester tester) async {
43+
testWidgetsWithLeakTracking('Has default cupertino localizations', (WidgetTester tester) async {
4444
await tester.pumpWidget(
4545
CupertinoApp(
4646
home: Builder(
@@ -62,7 +62,7 @@ void main() {
6262
expect(find.text('Thu Oct 4 '), findsOneWidget);
6363
});
6464

65-
testWidgets('Can use dynamic color', (WidgetTester tester) async {
65+
testWidgetsWithLeakTracking('Can use dynamic color', (WidgetTester tester) async {
6666
const CupertinoDynamicColor dynamicColor = CupertinoDynamicColor.withBrightness(
6767
color: Color(0xFF000000),
6868
darkColor: Color(0xFF000001),
@@ -84,7 +84,7 @@ void main() {
8484
expect(tester.widget<Title>(find.byType(Title)).color.value, 0xFF000001);
8585
});
8686

87-
testWidgets('Can customize initial routes', (WidgetTester tester) async {
87+
testWidgetsWithLeakTracking('Can customize initial routes', (WidgetTester tester) async {
8888
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
8989
await tester.pumpWidget(
9090
CupertinoApp(
@@ -131,7 +131,7 @@ void main() {
131131
expect(find.text('regular page two'), findsNothing);
132132
});
133133

134-
testWidgets('CupertinoApp.navigatorKey can be updated', (WidgetTester tester) async {
134+
testWidgetsWithLeakTracking('CupertinoApp.navigatorKey can be updated', (WidgetTester tester) async {
135135
final GlobalKey<NavigatorState> key1 = GlobalKey<NavigatorState>();
136136
await tester.pumpWidget(CupertinoApp(
137137
navigatorKey: key1,
@@ -147,12 +147,13 @@ void main() {
147147
expect(key1.currentState, isNull);
148148
});
149149

150-
testWidgets('CupertinoApp.router works', (WidgetTester tester) async {
150+
testWidgetsWithLeakTracking('CupertinoApp.router works', (WidgetTester tester) async {
151151
final PlatformRouteInformationProvider provider = PlatformRouteInformationProvider(
152152
initialRouteInformation: RouteInformation(
153153
uri: Uri.parse('initial'),
154154
),
155155
);
156+
addTearDown(provider.dispose);
156157
final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate(
157158
builder: (BuildContext context, RouteInformation information) {
158159
return Text(information.uri.toString());
@@ -164,6 +165,7 @@ void main() {
164165
return route.didPop(result);
165166
},
166167
);
168+
addTearDown(delegate.dispose);
167169
await tester.pumpWidget(CupertinoApp.router(
168170
routeInformationProvider: provider,
169171
routeInformationParser: SimpleRouteInformationParser(),
@@ -176,9 +178,14 @@ void main() {
176178
await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { });
177179
await tester.pumpAndSettle();
178180
expect(find.text('popped'), findsOneWidget);
179-
});
180-
181-
testWidgets('CupertinoApp.router route information parser is optional', (WidgetTester tester) async {
181+
},
182+
// TODO(polina-c): remove after fixing
183+
// https://github.com/flutter/flutter/issues/134205
184+
leakTrackingTestConfig: const LeakTrackingTestConfig(
185+
allowAllNotDisposed: true,
186+
));
187+
188+
testWidgetsWithLeakTracking('CupertinoApp.router route information parser is optional', (WidgetTester tester) async {
182189
final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate(
183190
builder: (BuildContext context, RouteInformation information) {
184191
return Text(information.uri.toString());
@@ -190,6 +197,7 @@ void main() {
190197
return route.didPop(result);
191198
},
192199
);
200+
addTearDown(delegate.dispose);
193201
delegate.routeInformation = RouteInformation(uri: Uri.parse('initial'));
194202
await tester.pumpWidget(CupertinoApp.router(
195203
routerDelegate: delegate,
@@ -201,9 +209,14 @@ void main() {
201209
await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { });
202210
await tester.pumpAndSettle();
203211
expect(find.text('popped'), findsOneWidget);
204-
});
205-
206-
testWidgets('CupertinoApp.router throw if route information provider is provided but no route information parser', (WidgetTester tester) async {
212+
},
213+
// TODO(polina-c): remove after fixing
214+
// https://github.com/flutter/flutter/issues/134205
215+
leakTrackingTestConfig: const LeakTrackingTestConfig(
216+
allowAllNotDisposed: true,
217+
));
218+
219+
testWidgetsWithLeakTracking('CupertinoApp.router throw if route information provider is provided but no route information parser', (WidgetTester tester) async {
207220
final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate(
208221
builder: (BuildContext context, RouteInformation information) {
209222
return Text(information.uri.toString());
@@ -215,20 +228,22 @@ void main() {
215228
return route.didPop(result);
216229
},
217230
);
231+
addTearDown(delegate.dispose);
218232
delegate.routeInformation = RouteInformation(uri: Uri.parse('initial'));
219233
final PlatformRouteInformationProvider provider = PlatformRouteInformationProvider(
220234
initialRouteInformation: RouteInformation(
221235
uri: Uri.parse('initial'),
222236
),
223237
);
238+
addTearDown(provider.dispose);
224239
await tester.pumpWidget(CupertinoApp.router(
225240
routeInformationProvider: provider,
226241
routerDelegate: delegate,
227242
));
228243
expect(tester.takeException(), isAssertionError);
229244
});
230245

231-
testWidgets('CupertinoApp.router throw if route configuration is provided along with other delegate', (WidgetTester tester) async {
246+
testWidgetsWithLeakTracking('CupertinoApp.router throw if route configuration is provided along with other delegate', (WidgetTester tester) async {
232247
final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate(
233248
builder: (BuildContext context, RouteInformation information) {
234249
return Text(information.uri.toString());
@@ -240,6 +255,7 @@ void main() {
240255
return route.didPop(result);
241256
},
242257
);
258+
addTearDown(delegate.dispose);
243259
delegate.routeInformation = RouteInformation(uri: Uri.parse('initial'));
244260
final RouterConfig<RouteInformation> routerConfig = RouterConfig<RouteInformation>(routerDelegate: delegate);
245261
await tester.pumpWidget(CupertinoApp.router(
@@ -249,15 +265,19 @@ void main() {
249265
expect(tester.takeException(), isAssertionError);
250266
});
251267

252-
testWidgets('CupertinoApp.router router config works', (WidgetTester tester) async {
268+
testWidgetsWithLeakTracking('CupertinoApp.router router config works', (WidgetTester tester) async {
269+
late SimpleNavigatorRouterDelegate delegate;
270+
addTearDown(() => delegate.dispose());
271+
final PlatformRouteInformationProvider provider = PlatformRouteInformationProvider(
272+
initialRouteInformation: RouteInformation(
273+
uri: Uri.parse('initial'),
274+
),
275+
);
276+
addTearDown(provider.dispose);
253277
final RouterConfig<RouteInformation> routerConfig = RouterConfig<RouteInformation>(
254-
routeInformationProvider: PlatformRouteInformationProvider(
255-
initialRouteInformation: RouteInformation(
256-
uri: Uri.parse('initial'),
257-
),
258-
),
278+
routeInformationProvider: provider,
259279
routeInformationParser: SimpleRouteInformationParser(),
260-
routerDelegate: SimpleNavigatorRouterDelegate(
280+
routerDelegate: delegate = SimpleNavigatorRouterDelegate(
261281
builder: (BuildContext context, RouteInformation information) {
262282
return Text(information.uri.toString());
263283
},
@@ -280,9 +300,14 @@ void main() {
280300
await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { });
281301
await tester.pumpAndSettle();
282302
expect(find.text('popped'), findsOneWidget);
283-
});
284-
285-
testWidgets('CupertinoApp has correct default ScrollBehavior', (WidgetTester tester) async {
303+
},
304+
// TODO(polina-c): remove after fixing
305+
// https://github.com/flutter/flutter/issues/134205
306+
leakTrackingTestConfig: const LeakTrackingTestConfig(
307+
allowAllNotDisposed: true,
308+
));
309+
310+
testWidgetsWithLeakTracking('CupertinoApp has correct default ScrollBehavior', (WidgetTester tester) async {
286311
late BuildContext capturedContext;
287312
await tester.pumpWidget(
288313
CupertinoApp(
@@ -297,7 +322,7 @@ void main() {
297322
expect(ScrollConfiguration.of(capturedContext).runtimeType, CupertinoScrollBehavior);
298323
});
299324

300-
testWidgets('A ScrollBehavior can be set for CupertinoApp', (WidgetTester tester) async {
325+
testWidgetsWithLeakTracking('A ScrollBehavior can be set for CupertinoApp', (WidgetTester tester) async {
301326
late BuildContext capturedContext;
302327
await tester.pumpWidget(
303328
CupertinoApp(
@@ -315,7 +340,7 @@ void main() {
315340
expect(scrollBehavior.getScrollPhysics(capturedContext).runtimeType, NeverScrollableScrollPhysics);
316341
});
317342

318-
testWidgets('When `useInheritedMediaQuery` is true an existing MediaQuery is used if one is available', (WidgetTester tester) async {
343+
testWidgetsWithLeakTracking('When `useInheritedMediaQuery` is true an existing MediaQuery is used if one is available', (WidgetTester tester) async {
319344
late BuildContext capturedContext;
320345
final UniqueKey uniqueKey = UniqueKey();
321346
await tester.pumpWidget(
@@ -335,7 +360,7 @@ void main() {
335360
expect(capturedContext.dependOnInheritedWidgetOfExactType<MediaQuery>()?.key, uniqueKey);
336361
});
337362

338-
testWidgets('Text color is correctly resolved when CupertinoThemeData.brightness is null', (WidgetTester tester) async {
363+
testWidgetsWithLeakTracking('Text color is correctly resolved when CupertinoThemeData.brightness is null', (WidgetTester tester) async {
339364
debugBrightnessOverride = Brightness.dark;
340365

341366
await tester.pumpWidget(
@@ -374,7 +399,7 @@ void main() {
374399
debugBrightnessOverride = null;
375400
});
376401

377-
testWidgets('Cursor color is resolved when CupertinoThemeData.brightness is null', (WidgetTester tester) async {
402+
testWidgetsWithLeakTracking('Cursor color is resolved when CupertinoThemeData.brightness is null', (WidgetTester tester) async {
378403
debugBrightnessOverride = Brightness.dark;
379404

380405
RenderEditable findRenderEditable(WidgetTester tester) {
@@ -431,7 +456,7 @@ void main() {
431456
debugBrightnessOverride = null;
432457
});
433458

434-
testWidgets('Assert in buildScrollbar that controller != null when using it', (WidgetTester tester) async {
459+
testWidgetsWithLeakTracking('Assert in buildScrollbar that controller != null when using it', (WidgetTester tester) async {
435460
const ScrollBehavior defaultBehavior = CupertinoScrollBehavior();
436461
late BuildContext capturedContext;
437462

0 commit comments

Comments
 (0)