Skip to content

Commit

Permalink
Cover more tests with leak tracking. (#134805)
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c authored Sep 18, 2023
1 parent 56cbf3e commit 658710b
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 146 deletions.
15 changes: 8 additions & 7 deletions packages/flutter/test/cupertino/activity_indicator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ library;
import 'package:flutter/cupertino.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

void main() {
testWidgets('Activity indicator animate property works', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Activity indicator animate property works', (WidgetTester tester) async {
await tester.pumpWidget(buildCupertinoActivityIndicator());
expect(SchedulerBinding.instance.transientCallbackCount, equals(1));

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

testWidgets('Activity indicator dark mode', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Activity indicator dark mode', (WidgetTester tester) async {
final Key key = UniqueKey();
await tester.pumpWidget(
Center(
Expand Down Expand Up @@ -77,7 +78,7 @@ void main() {
);
});

testWidgets('Activity indicator 0% in progress', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Activity indicator 0% in progress', (WidgetTester tester) async {
final Key key = UniqueKey();
await tester.pumpWidget(
Center(
Expand All @@ -99,7 +100,7 @@ void main() {
);
});

testWidgets('Activity indicator 30% in progress', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Activity indicator 30% in progress', (WidgetTester tester) async {
final Key key = UniqueKey();
await tester.pumpWidget(
Center(
Expand All @@ -121,7 +122,7 @@ void main() {
);
});

testWidgets('Activity indicator 100% in progress', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Activity indicator 100% in progress', (WidgetTester tester) async {
final Key key = UniqueKey();
await tester.pumpWidget(
Center(
Expand All @@ -142,7 +143,7 @@ void main() {
});

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

testWidgets('Can specify color', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Can specify color', (WidgetTester tester) async {
final Key key = UniqueKey();
await tester.pumpWidget(
Center(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

import '../widgets/clipboard_utils.dart';
import '../widgets/live_text_utils.dart';
Expand Down Expand Up @@ -37,7 +38,7 @@ void main() {
);
}

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

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

testWidgets('Can build children directly as well', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Can build children directly as well', (WidgetTester tester) async {
final GlobalKey key = GlobalKey();

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

testWidgets('Can build from EditableTextState', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Can build from EditableTextState', (WidgetTester tester) async {
final GlobalKey key = GlobalKey();
final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
final TextEditingController controller = TextEditingController();
addTearDown(controller.dispose);
await tester.pumpWidget(CupertinoApp(
home: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 400,
child: EditableText(
controller: TextEditingController(),
controller: controller,
backgroundCursorColor: const Color(0xff00ffff),
focusNode: FocusNode(),
focusNode: focusNode,
style: const TextStyle(),
cursorColor: const Color(0xff00ffff),
selectionControls: cupertinoTextSelectionHandleControls,
Expand Down Expand Up @@ -160,7 +165,7 @@ void main() {
variant: TargetPlatformVariant.all(),
);

testWidgets('Can build for editable text from raw parameters', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Can build for editable text from raw parameters', (WidgetTester tester) async {
final GlobalKey key = GlobalKey();
await tester.pumpWidget(CupertinoApp(
home: Center(
Expand Down Expand Up @@ -210,7 +215,7 @@ void main() {
variant: TargetPlatformVariant.all(),
);

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

await tester.pumpWidget(
Expand Down
79 changes: 52 additions & 27 deletions packages/flutter/test/cupertino/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void main() {
expect(find.widgetWithText(Navigator, 'foo'), findsOneWidget);
});

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

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

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

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

testWidgets('CupertinoApp.router works', (WidgetTester tester) async {
testWidgetsWithLeakTracking('CupertinoApp.router works', (WidgetTester tester) async {
final PlatformRouteInformationProvider provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(
uri: Uri.parse('initial'),
),
);
addTearDown(provider.dispose);
final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate(
builder: (BuildContext context, RouteInformation information) {
return Text(information.uri.toString());
Expand All @@ -164,6 +165,7 @@ void main() {
return route.didPop(result);
},
);
addTearDown(delegate.dispose);
await tester.pumpWidget(CupertinoApp.router(
routeInformationProvider: provider,
routeInformationParser: SimpleRouteInformationParser(),
Expand All @@ -176,9 +178,14 @@ void main() {
await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { });
await tester.pumpAndSettle();
expect(find.text('popped'), findsOneWidget);
});

testWidgets('CupertinoApp.router route information parser is optional', (WidgetTester tester) async {
},
// TODO(polina-c): remove after fixing
// https://github.com/flutter/flutter/issues/134205
leakTrackingTestConfig: const LeakTrackingTestConfig(
allowAllNotDisposed: true,
));

testWidgetsWithLeakTracking('CupertinoApp.router route information parser is optional', (WidgetTester tester) async {
final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate(
builder: (BuildContext context, RouteInformation information) {
return Text(information.uri.toString());
Expand All @@ -190,6 +197,7 @@ void main() {
return route.didPop(result);
},
);
addTearDown(delegate.dispose);
delegate.routeInformation = RouteInformation(uri: Uri.parse('initial'));
await tester.pumpWidget(CupertinoApp.router(
routerDelegate: delegate,
Expand All @@ -201,9 +209,14 @@ void main() {
await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { });
await tester.pumpAndSettle();
expect(find.text('popped'), findsOneWidget);
});

testWidgets('CupertinoApp.router throw if route information provider is provided but no route information parser', (WidgetTester tester) async {
},
// TODO(polina-c): remove after fixing
// https://github.com/flutter/flutter/issues/134205
leakTrackingTestConfig: const LeakTrackingTestConfig(
allowAllNotDisposed: true,
));

testWidgetsWithLeakTracking('CupertinoApp.router throw if route information provider is provided but no route information parser', (WidgetTester tester) async {
final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate(
builder: (BuildContext context, RouteInformation information) {
return Text(information.uri.toString());
Expand All @@ -215,20 +228,22 @@ void main() {
return route.didPop(result);
},
);
addTearDown(delegate.dispose);
delegate.routeInformation = RouteInformation(uri: Uri.parse('initial'));
final PlatformRouteInformationProvider provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(
uri: Uri.parse('initial'),
),
);
addTearDown(provider.dispose);
await tester.pumpWidget(CupertinoApp.router(
routeInformationProvider: provider,
routerDelegate: delegate,
));
expect(tester.takeException(), isAssertionError);
});

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

testWidgets('CupertinoApp.router router config works', (WidgetTester tester) async {
testWidgetsWithLeakTracking('CupertinoApp.router router config works', (WidgetTester tester) async {
late SimpleNavigatorRouterDelegate delegate;
addTearDown(() => delegate.dispose());
final PlatformRouteInformationProvider provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(
uri: Uri.parse('initial'),
),
);
addTearDown(provider.dispose);
final RouterConfig<RouteInformation> routerConfig = RouterConfig<RouteInformation>(
routeInformationProvider: PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(
uri: Uri.parse('initial'),
),
),
routeInformationProvider: provider,
routeInformationParser: SimpleRouteInformationParser(),
routerDelegate: SimpleNavigatorRouterDelegate(
routerDelegate: delegate = SimpleNavigatorRouterDelegate(
builder: (BuildContext context, RouteInformation information) {
return Text(information.uri.toString());
},
Expand All @@ -280,9 +300,14 @@ void main() {
await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { });
await tester.pumpAndSettle();
expect(find.text('popped'), findsOneWidget);
});

testWidgets('CupertinoApp has correct default ScrollBehavior', (WidgetTester tester) async {
},
// TODO(polina-c): remove after fixing
// https://github.com/flutter/flutter/issues/134205
leakTrackingTestConfig: const LeakTrackingTestConfig(
allowAllNotDisposed: true,
));

testWidgetsWithLeakTracking('CupertinoApp has correct default ScrollBehavior', (WidgetTester tester) async {
late BuildContext capturedContext;
await tester.pumpWidget(
CupertinoApp(
Expand All @@ -297,7 +322,7 @@ void main() {
expect(ScrollConfiguration.of(capturedContext).runtimeType, CupertinoScrollBehavior);
});

testWidgets('A ScrollBehavior can be set for CupertinoApp', (WidgetTester tester) async {
testWidgetsWithLeakTracking('A ScrollBehavior can be set for CupertinoApp', (WidgetTester tester) async {
late BuildContext capturedContext;
await tester.pumpWidget(
CupertinoApp(
Expand All @@ -315,7 +340,7 @@ void main() {
expect(scrollBehavior.getScrollPhysics(capturedContext).runtimeType, NeverScrollableScrollPhysics);
});

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

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

await tester.pumpWidget(
Expand Down Expand Up @@ -374,7 +399,7 @@ void main() {
debugBrightnessOverride = null;
});

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

RenderEditable findRenderEditable(WidgetTester tester) {
Expand Down Expand Up @@ -431,7 +456,7 @@ void main() {
debugBrightnessOverride = null;
});

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

Expand Down
Loading

0 comments on commit 658710b

Please sign in to comment.