Unverified Commit 95eae5f9 authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

Cover more test/widgets tests with leak tracking #12. (#135385)

parent fdde2419
......@@ -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(
......
......@@ -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,
......@@ -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
......
......@@ -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();
......@@ -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);
......@@ -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);
......@@ -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(
......@@ -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(
......@@ -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);
......@@ -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(
......@@ -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();
......@@ -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));
......@@ -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(
......@@ -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(
......@@ -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);
......
......@@ -5,9 +5,10 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
testWidgets('Router state restoration without RouteInformationProvider', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Router state restoration without RouteInformationProvider', (WidgetTester tester) async {
final UniqueKey router = UniqueKey();
_TestRouterDelegate delegate() => tester.widget<Router<Object?>>(find.byKey(router)).routerDelegate as _TestRouterDelegate;
......@@ -39,7 +40,12 @@ void main() {
expect(find.text('Current config: /foo'), findsOneWidget);
expect(delegate().newRoutePaths, isEmpty);
expect(delegate().restoredRoutePaths, <String>['/foo', '/foo']);
});
},
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134205
notDisposedAllowList: <String, int?> {'_RestorableRouteInformation': 2},
));
testWidgets('Router state restoration with RouteInformationProvider', (WidgetTester tester) async {
final UniqueKey router = UniqueKey();
......@@ -152,22 +158,37 @@ class _TestRouteInformationProvider extends RouteInformationProvider with Change
}
}
class _TestWidget extends StatelessWidget {
class _TestWidget extends StatefulWidget {
const _TestWidget({this.withInformationProvider = false, this.routerKey});
final bool withInformationProvider;
final Key? routerKey;
@override
State<_TestWidget> createState() => _TestWidgetState();
}
class _TestWidgetState extends State<_TestWidget> {
final _TestRouterDelegate _delegate = _TestRouterDelegate();
final _TestRouteInformationProvider _routeInformationProvider = _TestRouteInformationProvider();
@override
void dispose() {
_delegate.dispose();
_routeInformationProvider.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return RootRestorationScope(
restorationId: 'root',
child: Router<String>(
key: routerKey,
key: widget.routerKey,
restorationScopeId: 'router',
routerDelegate: _TestRouterDelegate(),
routerDelegate: _delegate,
routeInformationParser: _TestRouteInformationParser(),
routeInformationProvider: withInformationProvider ? _TestRouteInformationProvider() : null,
routeInformationProvider: widget.withInformationProvider ? _routeInformationProvider : null,
),
);
}
......
......@@ -861,12 +861,13 @@ void main() {
expect(targetMidLeftPage1, findsOneWidget);
});
testWidgets('ensureVisible does not move TabViews', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ensureVisible does not move TabViews', (WidgetTester tester) async {
final TickerProvider vsync = TestTickerProvider();
final TabController controller = TabController(
length: 3,
vsync: vsync,
);
addTearDown(controller.dispose);
await tester.pumpWidget(
Directionality(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment