Skip to content

Commit

Permalink
Cover more test/widgets tests with leak tracking #12. (flutter#135385)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksokolovskyi authored Sep 30, 2023
1 parent fdde241 commit 95eae5f
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 283 deletions.
2 changes: 1 addition & 1 deletion packages/flutter/test/widgets/animated_size_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ void main() {
);
});

testWidgets('disposes animation and controller', (WidgetTester tester) async {
testWidgetsWithLeakTracking('disposes animation and controller', (WidgetTester tester) async {
await tester.pumpWidget(
const Center(
child: AnimatedSize(
Expand Down
4 changes: 3 additions & 1 deletion packages/flutter/test/widgets/framework_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1062,13 +1062,14 @@ void main() {
element.createChild(0, after: null);
});

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

await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
Expand Down Expand Up @@ -1101,6 +1102,7 @@ void main() {
setState(() {
tabBarViewCnt = 1;
tabController = TabController(length: tabBarViewCnt, vsync: const TestVSync());
addTearDown(tabController.dispose);
});

await tester.pump(const Duration(seconds: 1)); // finish the animation
Expand Down
23 changes: 12 additions & 11 deletions packages/flutter/test/widgets/html_element_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:flutter/src/widgets/_html_element_view_web.dart'
show debugOverridePlatformViewRegistry;
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import 'package:web/web.dart' as web;

final Object _mockHtmlElement = Object();
Expand Down Expand Up @@ -42,7 +43,7 @@ void main() {
});

group('HtmlElementView', () {
testWidgets('Create HTML view', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Create HTML view', (WidgetTester tester) async {
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);

Expand All @@ -64,7 +65,7 @@ void main() {
);
});

testWidgets('Create HTML view with PlatformViewCreatedCallback', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Create HTML view with PlatformViewCreatedCallback', (WidgetTester tester) async {
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);

Expand Down Expand Up @@ -97,7 +98,7 @@ void main() {
);
});

testWidgets('Create HTML view with creation params', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Create HTML view with creation params', (WidgetTester tester) async {
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);
await tester.pumpWidget(
Expand Down Expand Up @@ -132,7 +133,7 @@ void main() {
);
});

testWidgets('Resize HTML view', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Resize HTML view', (WidgetTester tester) async {
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);
await tester.pumpWidget(
Expand Down Expand Up @@ -168,7 +169,7 @@ void main() {
);
});

testWidgets('Change HTML view type', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Change HTML view type', (WidgetTester tester) async {
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);
fakePlatformViewRegistry.registerViewFactory('maps', _mockViewFactory);
Expand Down Expand Up @@ -200,7 +201,7 @@ void main() {
);
});

testWidgets('Dispose HTML view', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Dispose HTML view', (WidgetTester tester) async {
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);
await tester.pumpWidget(
const Center(
Expand All @@ -227,7 +228,7 @@ void main() {
);
});

testWidgets('HTML view survives widget tree change', (WidgetTester tester) async {
testWidgetsWithLeakTracking('HTML view survives widget tree change', (WidgetTester tester) async {
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
fakePlatformViewRegistry.registerViewFactory('webview', _mockViewFactory);
final GlobalKey key = GlobalKey();
Expand Down Expand Up @@ -259,7 +260,7 @@ void main() {
);
});

testWidgets('HtmlElementView has correct semantics', (WidgetTester tester) async {
testWidgetsWithLeakTracking('HtmlElementView has correct semantics', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
expect(currentViewId, greaterThanOrEqualTo(0));
Expand Down Expand Up @@ -306,7 +307,7 @@ void main() {
debugOverridePlatformViewRegistry = null;
});

testWidgets('Create platform view from tagName', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Create platform view from tagName', (WidgetTester tester) async {
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();

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

testWidgets('Create invisible platform view', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Create invisible platform view', (WidgetTester tester) async {
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();

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

testWidgets('onElementCreated', (WidgetTester tester) async {
testWidgetsWithLeakTracking('onElementCreated', (WidgetTester tester) async {
final List<Object> createdElements = <Object>[];
void onElementCreated(Object element) {
createdElements.add(element);
Expand Down
Loading

0 comments on commit 95eae5f

Please sign in to comment.