Skip to content

Commit 95eae5f

Browse files
authored
Cover more test/widgets tests with leak tracking #12. (flutter#135385)
1 parent fdde241 commit 95eae5f

9 files changed

+456
-283
lines changed

packages/flutter/test/widgets/animated_size_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ void main() {
435435
);
436436
});
437437

438-
testWidgets('disposes animation and controller', (WidgetTester tester) async {
438+
testWidgetsWithLeakTracking('disposes animation and controller', (WidgetTester tester) async {
439439
await tester.pumpWidget(
440440
const Center(
441441
child: AnimatedSize(

packages/flutter/test/widgets/framework_test.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -1062,13 +1062,14 @@ void main() {
10621062
element.createChild(0, after: null);
10631063
});
10641064

1065-
testWidgets('GlobalKey - re-attach child to new parents, and the old parent is deactivated(unmounted)', (WidgetTester tester) async {
1065+
testWidgetsWithLeakTracking('GlobalKey - re-attach child to new parents, and the old parent is deactivated(unmounted)', (WidgetTester tester) async {
10661066
// This is a regression test for https://github.com/flutter/flutter/issues/62055
10671067
const Key key1 = GlobalObjectKey('key1');
10681068
const Key key2 = GlobalObjectKey('key2');
10691069
late StateSetter setState;
10701070
int tabBarViewCnt = 2;
10711071
TabController tabController = TabController(length: tabBarViewCnt, vsync: const TestVSync());
1072+
addTearDown(tabController.dispose);
10721073

10731074
await tester.pumpWidget(Directionality(
10741075
textDirection: TextDirection.ltr,
@@ -1101,6 +1102,7 @@ void main() {
11011102
setState(() {
11021103
tabBarViewCnt = 1;
11031104
tabController = TabController(length: tabBarViewCnt, vsync: const TestVSync());
1105+
addTearDown(tabController.dispose);
11041106
});
11051107

11061108
await tester.pump(const Duration(seconds: 1)); // finish the animation

packages/flutter/test/widgets/html_element_view_test.dart

+12-11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:flutter/src/widgets/_html_element_view_web.dart'
1515
show debugOverridePlatformViewRegistry;
1616
import 'package:flutter/widgets.dart';
1717
import 'package:flutter_test/flutter_test.dart';
18+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
1819
import 'package:web/web.dart' as web;
1920

2021
final Object _mockHtmlElement = Object();
@@ -42,7 +43,7 @@ void main() {
4243
});
4344

4445
group('HtmlElementView', () {
45-
testWidgets('Create HTML view', (WidgetTester tester) async {
46+
testWidgetsWithLeakTracking('Create HTML view', (WidgetTester tester) async {
4647
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
4748
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);
4849

@@ -64,7 +65,7 @@ void main() {
6465
);
6566
});
6667

67-
testWidgets('Create HTML view with PlatformViewCreatedCallback', (WidgetTester tester) async {
68+
testWidgetsWithLeakTracking('Create HTML view with PlatformViewCreatedCallback', (WidgetTester tester) async {
6869
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
6970
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);
7071

@@ -97,7 +98,7 @@ void main() {
9798
);
9899
});
99100

100-
testWidgets('Create HTML view with creation params', (WidgetTester tester) async {
101+
testWidgetsWithLeakTracking('Create HTML view with creation params', (WidgetTester tester) async {
101102
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
102103
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);
103104
await tester.pumpWidget(
@@ -132,7 +133,7 @@ void main() {
132133
);
133134
});
134135

135-
testWidgets('Resize HTML view', (WidgetTester tester) async {
136+
testWidgetsWithLeakTracking('Resize HTML view', (WidgetTester tester) async {
136137
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
137138
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);
138139
await tester.pumpWidget(
@@ -168,7 +169,7 @@ void main() {
168169
);
169170
});
170171

171-
testWidgets('Change HTML view type', (WidgetTester tester) async {
172+
testWidgetsWithLeakTracking('Change HTML view type', (WidgetTester tester) async {
172173
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
173174
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);
174175
fakePlatformViewRegistry.registerViewFactory('maps', _mockViewFactory);
@@ -200,7 +201,7 @@ void main() {
200201
);
201202
});
202203

203-
testWidgets('Dispose HTML view', (WidgetTester tester) async {
204+
testWidgetsWithLeakTracking('Dispose HTML view', (WidgetTester tester) async {
204205
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);
205206
await tester.pumpWidget(
206207
const Center(
@@ -227,7 +228,7 @@ void main() {
227228
);
228229
});
229230

230-
testWidgets('HTML view survives widget tree change', (WidgetTester tester) async {
231+
testWidgetsWithLeakTracking('HTML view survives widget tree change', (WidgetTester tester) async {
231232
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
232233
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);
233234
final GlobalKey key = GlobalKey();
@@ -259,7 +260,7 @@ void main() {
259260
);
260261
});
261262

262-
testWidgets('HtmlElementView has correct semantics', (WidgetTester tester) async {
263+
testWidgetsWithLeakTracking('HtmlElementView has correct semantics', (WidgetTester tester) async {
263264
final SemanticsHandle handle = tester.ensureSemantics();
264265
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
265266
expect(currentViewId, greaterThanOrEqualTo(0));
@@ -306,7 +307,7 @@ void main() {
306307
debugOverridePlatformViewRegistry = null;
307308
});
308309

309-
testWidgets('Create platform view from tagName', (WidgetTester tester) async {
310+
testWidgetsWithLeakTracking('Create platform view from tagName', (WidgetTester tester) async {
310311
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
311312

312313
await tester.pumpWidget(
@@ -331,7 +332,7 @@ void main() {
331332
expect(htmlElement.tagName, equalsIgnoringCase('div'));
332333
});
333334

334-
testWidgets('Create invisible platform view', (WidgetTester tester) async {
335+
testWidgetsWithLeakTracking('Create invisible platform view', (WidgetTester tester) async {
335336
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
336337

337338
await tester.pumpWidget(
@@ -357,7 +358,7 @@ void main() {
357358
expect(htmlElement.tagName, equalsIgnoringCase('script'));
358359
});
359360

360-
testWidgets('onElementCreated', (WidgetTester tester) async {
361+
testWidgetsWithLeakTracking('onElementCreated', (WidgetTester tester) async {
361362
final List<Object> createdElements = <Object>[];
362363
void onElementCreated(Object element) {
363364
createdElements.add(element);

0 commit comments

Comments
 (0)