Unverified Commit 658710b6 authored by Polina Cherkasova's avatar Polina Cherkasova Committed by GitHub

Cover more tests with leak tracking. (#134805)

parent 56cbf3e1
...@@ -10,9 +10,10 @@ library; ...@@ -10,9 +10,10 @@ library;
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() { void main() {
testWidgets('Activity indicator animate property works', (WidgetTester tester) async { testWidgetsWithLeakTracking('Activity indicator animate property works', (WidgetTester tester) async {
await tester.pumpWidget(buildCupertinoActivityIndicator()); await tester.pumpWidget(buildCupertinoActivityIndicator());
expect(SchedulerBinding.instance.transientCallbackCount, equals(1)); expect(SchedulerBinding.instance.transientCallbackCount, equals(1));
...@@ -28,7 +29,7 @@ void main() { ...@@ -28,7 +29,7 @@ void main() {
expect(SchedulerBinding.instance.transientCallbackCount, equals(1)); 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(); final Key key = UniqueKey();
await tester.pumpWidget( await tester.pumpWidget(
Center( Center(
...@@ -77,7 +78,7 @@ void main() { ...@@ -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(); final Key key = UniqueKey();
await tester.pumpWidget( await tester.pumpWidget(
Center( Center(
...@@ -99,7 +100,7 @@ void main() { ...@@ -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(); final Key key = UniqueKey();
await tester.pumpWidget( await tester.pumpWidget(
Center( Center(
...@@ -121,7 +122,7 @@ void main() { ...@@ -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(); final Key key = UniqueKey();
await tester.pumpWidget( await tester.pumpWidget(
Center( Center(
...@@ -142,7 +143,7 @@ void main() { ...@@ -142,7 +143,7 @@ void main() {
}); });
// Regression test for https://github.com/flutter/flutter/issues/41345. // 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( await tester.pumpWidget(
const CupertinoActivityIndicator(animating: false, radius: 100), const CupertinoActivityIndicator(animating: false, radius: 100),
); );
...@@ -158,7 +159,7 @@ void main() { ...@@ -158,7 +159,7 @@ void main() {
); );
}); });
testWidgets('Can specify color', (WidgetTester tester) async { testWidgetsWithLeakTracking('Can specify color', (WidgetTester tester) async {
final Key key = UniqueKey(); final Key key = UniqueKey();
await tester.pumpWidget( await tester.pumpWidget(
Center( Center(
......
...@@ -6,6 +6,7 @@ import 'package:flutter/cupertino.dart'; ...@@ -6,6 +6,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.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/clipboard_utils.dart';
import '../widgets/live_text_utils.dart'; import '../widgets/live_text_utils.dart';
...@@ -37,7 +38,7 @@ void main() { ...@@ -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'; const String buttonText = 'Click me';
await tester.pumpWidget( await tester.pumpWidget(
...@@ -78,7 +79,7 @@ void main() { ...@@ -78,7 +79,7 @@ void main() {
skip: isBrowser, // [intended] see https://github.com/flutter/flutter/issues/108382 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(); final GlobalKey key = GlobalKey();
await tester.pumpWidget( await tester.pumpWidget(
...@@ -101,17 +102,21 @@ void main() { ...@@ -101,17 +102,21 @@ void main() {
skip: isBrowser, // [intended] see https://github.com/flutter/flutter/issues/108382 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 GlobalKey key = GlobalKey();
final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
final TextEditingController controller = TextEditingController();
addTearDown(controller.dispose);
await tester.pumpWidget(CupertinoApp( await tester.pumpWidget(CupertinoApp(
home: Align( home: Align(
alignment: Alignment.topLeft, alignment: Alignment.topLeft,
child: SizedBox( child: SizedBox(
width: 400, width: 400,
child: EditableText( child: EditableText(
controller: TextEditingController(), controller: controller,
backgroundCursorColor: const Color(0xff00ffff), backgroundCursorColor: const Color(0xff00ffff),
focusNode: FocusNode(), focusNode: focusNode,
style: const TextStyle(), style: const TextStyle(),
cursorColor: const Color(0xff00ffff), cursorColor: const Color(0xff00ffff),
selectionControls: cupertinoTextSelectionHandleControls, selectionControls: cupertinoTextSelectionHandleControls,
...@@ -160,7 +165,7 @@ void main() { ...@@ -160,7 +165,7 @@ void main() {
variant: TargetPlatformVariant.all(), 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(); final GlobalKey key = GlobalKey();
await tester.pumpWidget(CupertinoApp( await tester.pumpWidget(CupertinoApp(
home: Center( home: Center(
...@@ -210,7 +215,7 @@ void main() { ...@@ -210,7 +215,7 @@ void main() {
variant: TargetPlatformVariant.all(), 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'; const String buttonText = 'Click me';
await tester.pumpWidget( await tester.pumpWidget(
......
...@@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart'; ...@@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import '../image_data.dart'; import '../image_data.dart';
import '../widgets/semantics_tester.dart'; import '../widgets/semantics_tester.dart';
...@@ -29,7 +30,7 @@ Future<void> pumpWidgetWithBoilerplate(WidgetTester tester, Widget widget) async ...@@ -29,7 +30,7 @@ Future<void> pumpWidgetWithBoilerplate(WidgetTester tester, Widget widget) async
Future<void> main() async { Future<void> main() async {
testWidgets('Need at least 2 tabs', (WidgetTester tester) async { testWidgetsWithLeakTracking('Need at least 2 tabs', (WidgetTester tester) async {
await expectLater( await expectLater(
() => pumpWidgetWithBoilerplate(tester, CupertinoTabBar( () => pumpWidgetWithBoilerplate(tester, CupertinoTabBar(
items: <BottomNavigationBarItem>[ items: <BottomNavigationBarItem>[
...@@ -47,7 +48,7 @@ Future<void> main() async { ...@@ -47,7 +48,7 @@ Future<void> main() async {
); );
}); });
testWidgets('Active and inactive colors', (WidgetTester tester) async { testWidgetsWithLeakTracking('Active and inactive colors', (WidgetTester tester) async {
await pumpWidgetWithBoilerplate(tester, MediaQuery( await pumpWidgetWithBoilerplate(tester, MediaQuery(
data: const MediaQueryData(), data: const MediaQueryData(),
child: CupertinoTabBar( child: CupertinoTabBar(
...@@ -81,7 +82,7 @@ Future<void> main() async { ...@@ -81,7 +82,7 @@ Future<void> main() async {
}); });
testWidgets('BottomNavigationBar.label will create a text widget', (WidgetTester tester) async { testWidgetsWithLeakTracking('BottomNavigationBar.label will create a text widget', (WidgetTester tester) async {
await pumpWidgetWithBoilerplate(tester, MediaQuery( await pumpWidgetWithBoilerplate(tester, MediaQuery(
data: const MediaQueryData(), data: const MediaQueryData(),
child: CupertinoTabBar( child: CupertinoTabBar(
...@@ -103,7 +104,7 @@ Future<void> main() async { ...@@ -103,7 +104,7 @@ Future<void> main() async {
expect(find.text('Tab 2'), findsOneWidget); expect(find.text('Tab 2'), findsOneWidget);
}); });
testWidgets('Active and inactive colors dark mode', (WidgetTester tester) async { testWidgetsWithLeakTracking('Active and inactive colors dark mode', (WidgetTester tester) async {
const CupertinoDynamicColor dynamicActiveColor = CupertinoDynamicColor.withBrightness( const CupertinoDynamicColor dynamicActiveColor = CupertinoDynamicColor.withBrightness(
color: Color(0xFF000000), color: Color(0xFF000000),
darkColor: Color(0xFF000001), darkColor: Color(0xFF000001),
...@@ -191,7 +192,7 @@ Future<void> main() async { ...@@ -191,7 +192,7 @@ Future<void> main() async {
expect(decoration2.border!.top.color.value, 0x29000000); expect(decoration2.border!.top.color.value, 0x29000000);
}); });
testWidgets('Tabs respects themes', (WidgetTester tester) async { testWidgetsWithLeakTracking('Tabs respects themes', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
CupertinoApp( CupertinoApp(
home: CupertinoTabBar( home: CupertinoTabBar(
...@@ -255,7 +256,7 @@ Future<void> main() async { ...@@ -255,7 +256,7 @@ Future<void> main() async {
expect(actualActive.text.style!.color, isSameColorAs(CupertinoColors.activeBlue.darkColor)); expect(actualActive.text.style!.color, isSameColorAs(CupertinoColors.activeBlue.darkColor));
}); });
testWidgets('Use active icon', (WidgetTester tester) async { testWidgetsWithLeakTracking('Use active icon', (WidgetTester tester) async {
final MemoryImage activeIcon = MemoryImage(Uint8List.fromList(kBlueSquarePng)); final MemoryImage activeIcon = MemoryImage(Uint8List.fromList(kBlueSquarePng));
final MemoryImage inactiveIcon = MemoryImage(Uint8List.fromList(kTransparentImage)); final MemoryImage inactiveIcon = MemoryImage(Uint8List.fromList(kTransparentImage));
...@@ -288,7 +289,7 @@ Future<void> main() async { ...@@ -288,7 +289,7 @@ Future<void> main() async {
expect(image.image, activeIcon); expect(image.image, activeIcon);
}); });
testWidgets('Adjusts height to account for bottom padding', (WidgetTester tester) async { testWidgetsWithLeakTracking('Adjusts height to account for bottom padding', (WidgetTester tester) async {
final CupertinoTabBar tabBar = CupertinoTabBar( final CupertinoTabBar tabBar = CupertinoTabBar(
items: <BottomNavigationBarItem>[ items: <BottomNavigationBarItem>[
BottomNavigationBarItem( BottomNavigationBarItem(
...@@ -327,7 +328,7 @@ Future<void> main() async { ...@@ -327,7 +328,7 @@ Future<void> main() async {
expect(tester.getSize(find.byType(CupertinoTabBar)).height, 90.0); expect(tester.getSize(find.byType(CupertinoTabBar)).height, 90.0);
}); });
testWidgets('Set custom height', (WidgetTester tester) async { testWidgetsWithLeakTracking('Set custom height', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/51704 // Regression test for https://github.com/flutter/flutter/issues/51704
const double tabBarHeight = 56.0; const double tabBarHeight = 56.0;
final CupertinoTabBar tabBar = CupertinoTabBar( final CupertinoTabBar tabBar = CupertinoTabBar(
...@@ -370,7 +371,7 @@ Future<void> main() async { ...@@ -370,7 +371,7 @@ Future<void> main() async {
expect(tester.getSize(find.byType(CupertinoTabBar)).height, tabBarHeight + bottomPadding); expect(tester.getSize(find.byType(CupertinoTabBar)).height, tabBarHeight + bottomPadding);
}); });
testWidgets('Ensure bar height will not change when toggle keyboard', (WidgetTester tester) async { testWidgetsWithLeakTracking('Ensure bar height will not change when toggle keyboard', (WidgetTester tester) async {
const double tabBarHeight = 56.0; const double tabBarHeight = 56.0;
final CupertinoTabBar tabBar = CupertinoTabBar( final CupertinoTabBar tabBar = CupertinoTabBar(
height: tabBarHeight, height: tabBarHeight,
...@@ -424,7 +425,7 @@ Future<void> main() async { ...@@ -424,7 +425,7 @@ Future<void> main() async {
expect(tester.getSize(find.byType(CupertinoTabBar)).height, tabBarHeight + bottomPadding); expect(tester.getSize(find.byType(CupertinoTabBar)).height, tabBarHeight + bottomPadding);
}); });
testWidgets('Opaque background does not add blur effects', (WidgetTester tester) async { testWidgetsWithLeakTracking('Opaque background does not add blur effects', (WidgetTester tester) async {
await pumpWidgetWithBoilerplate(tester, MediaQuery( await pumpWidgetWithBoilerplate(tester, MediaQuery(
data: const MediaQueryData(), data: const MediaQueryData(),
child: CupertinoTabBar( child: CupertinoTabBar(
...@@ -463,7 +464,7 @@ Future<void> main() async { ...@@ -463,7 +464,7 @@ Future<void> main() async {
expect(find.byType(BackdropFilter), findsNothing); expect(find.byType(BackdropFilter), findsNothing);
}); });
testWidgets('Tap callback', (WidgetTester tester) async { testWidgetsWithLeakTracking('Tap callback', (WidgetTester tester) async {
late int callbackTab; late int callbackTab;
await pumpWidgetWithBoilerplate(tester, MediaQuery( await pumpWidgetWithBoilerplate(tester, MediaQuery(
...@@ -491,7 +492,7 @@ Future<void> main() async { ...@@ -491,7 +492,7 @@ Future<void> main() async {
expect(callbackTab, 1); expect(callbackTab, 1);
}); });
testWidgets('tabs announce semantics', (WidgetTester tester) async { testWidgetsWithLeakTracking('tabs announce semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
await pumpWidgetWithBoilerplate(tester, MediaQuery( await pumpWidgetWithBoilerplate(tester, MediaQuery(
...@@ -526,7 +527,7 @@ Future<void> main() async { ...@@ -526,7 +527,7 @@ Future<void> main() async {
semantics.dispose(); semantics.dispose();
}); });
testWidgets('Label of items should be nullable', (WidgetTester tester) async { testWidgetsWithLeakTracking('Label of items should be nullable', (WidgetTester tester) async {
final MemoryImage iconProvider = MemoryImage(Uint8List.fromList(kTransparentImage)); final MemoryImage iconProvider = MemoryImage(Uint8List.fromList(kTransparentImage));
final List<int> itemsTapped = <int>[]; final List<int> itemsTapped = <int>[];
...@@ -563,7 +564,7 @@ Future<void> main() async { ...@@ -563,7 +564,7 @@ Future<void> main() async {
expect(itemsTapped, <int>[1]); expect(itemsTapped, <int>[1]);
}); });
testWidgets('Hide border hides the top border of the tabBar', (WidgetTester tester) async { testWidgetsWithLeakTracking('Hide border hides the top border of the tabBar', (WidgetTester tester) async {
await pumpWidgetWithBoilerplate( await pumpWidgetWithBoilerplate(
tester, tester,
MediaQuery( MediaQuery(
...@@ -623,7 +624,7 @@ Future<void> main() async { ...@@ -623,7 +624,7 @@ Future<void> main() async {
expect(boxDecorationHiddenBorder.border, isNull); expect(boxDecorationHiddenBorder.border, isNull);
}); });
testWidgets('Hovering over tab bar item updates cursor to clickable on Web', (WidgetTester tester) async { testWidgetsWithLeakTracking('Hovering over tab bar item updates cursor to clickable on Web', (WidgetTester tester) async {
await pumpWidgetWithBoilerplate( await pumpWidgetWithBoilerplate(
tester, tester,
MediaQuery( MediaQuery(
......
...@@ -8,6 +8,7 @@ import 'package:flutter/gestures.dart'; ...@@ -8,6 +8,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import '../widgets/semantics_tester.dart'; import '../widgets/semantics_tester.dart';
...@@ -17,7 +18,7 @@ const TextStyle testStyle = TextStyle( ...@@ -17,7 +18,7 @@ const TextStyle testStyle = TextStyle(
); );
void main() { void main() {
testWidgets('Default layout minimum size', (WidgetTester tester) async { testWidgetsWithLeakTracking('Default layout minimum size', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
boilerplate(child: const CupertinoButton( boilerplate(child: const CupertinoButton(
onPressed: null, onPressed: null,
...@@ -32,7 +33,7 @@ void main() { ...@@ -32,7 +33,7 @@ void main() {
); );
}); });
testWidgets('Minimum size parameter', (WidgetTester tester) async { testWidgetsWithLeakTracking('Minimum size parameter', (WidgetTester tester) async {
const double minSize = 60.0; const double minSize = 60.0;
await tester.pumpWidget( await tester.pumpWidget(
boilerplate(child: const CupertinoButton( boilerplate(child: const CupertinoButton(
...@@ -49,7 +50,7 @@ void main() { ...@@ -49,7 +50,7 @@ void main() {
); );
}); });
testWidgets('Size grows with text', (WidgetTester tester) async { testWidgetsWithLeakTracking('Size grows with text', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
boilerplate(child: const CupertinoButton( boilerplate(child: const CupertinoButton(
onPressed: null, onPressed: null,
...@@ -102,7 +103,7 @@ void main() { ...@@ -102,7 +103,7 @@ void main() {
}); });
*/ */
testWidgets('Button child alignment', (WidgetTester tester) async { testWidgetsWithLeakTracking('Button child alignment', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
CupertinoApp( CupertinoApp(
home: CupertinoButton( home: CupertinoButton(
...@@ -129,7 +130,7 @@ void main() { ...@@ -129,7 +130,7 @@ void main() {
expect(align.alignment, Alignment.centerLeft); expect(align.alignment, Alignment.centerLeft);
}); });
testWidgets('Button with background is wider', (WidgetTester tester) async { testWidgetsWithLeakTracking('Button with background is wider', (WidgetTester tester) async {
await tester.pumpWidget(boilerplate(child: const CupertinoButton( await tester.pumpWidget(boilerplate(child: const CupertinoButton(
onPressed: null, onPressed: null,
color: Color(0xFFFFFFFF), color: Color(0xFFFFFFFF),
...@@ -143,7 +144,7 @@ void main() { ...@@ -143,7 +144,7 @@ void main() {
); );
}); });
testWidgets('Custom padding', (WidgetTester tester) async { testWidgetsWithLeakTracking('Custom padding', (WidgetTester tester) async {
await tester.pumpWidget(boilerplate(child: const CupertinoButton( await tester.pumpWidget(boilerplate(child: const CupertinoButton(
onPressed: null, onPressed: null,
padding: EdgeInsets.all(100.0), padding: EdgeInsets.all(100.0),
...@@ -156,7 +157,7 @@ void main() { ...@@ -156,7 +157,7 @@ void main() {
); );
}); });
testWidgets('Button takes taps', (WidgetTester tester) async { testWidgetsWithLeakTracking('Button takes taps', (WidgetTester tester) async {
bool value = false; bool value = false;
await tester.pumpWidget( await tester.pumpWidget(
StatefulBuilder( StatefulBuilder(
...@@ -195,7 +196,7 @@ void main() { ...@@ -195,7 +196,7 @@ void main() {
expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
}); });
testWidgets('Enabled button animates', (WidgetTester tester) async { testWidgetsWithLeakTracking('Enabled button animates', (WidgetTester tester) async {
await tester.pumpWidget(boilerplate(child: CupertinoButton( await tester.pumpWidget(boilerplate(child: CupertinoButton(
child: const Text('Tap me'), child: const Text('Tap me'),
onPressed: () { }, onPressed: () { },
...@@ -231,7 +232,7 @@ void main() { ...@@ -231,7 +232,7 @@ void main() {
expect(transition.opacity.value, moreOrLessEquals(1.0, epsilon: 0.001)); expect(transition.opacity.value, moreOrLessEquals(1.0, epsilon: 0.001));
}); });
testWidgets('pressedOpacity defaults to 0.1', (WidgetTester tester) async { testWidgetsWithLeakTracking('pressedOpacity defaults to 0.1', (WidgetTester tester) async {
await tester.pumpWidget(boilerplate(child: CupertinoButton( await tester.pumpWidget(boilerplate(child: CupertinoButton(
child: const Text('Tap me'), child: const Text('Tap me'),
onPressed: () { }, onPressed: () { },
...@@ -250,7 +251,7 @@ void main() { ...@@ -250,7 +251,7 @@ void main() {
expect(opacity.opacity.value, 0.4); expect(opacity.opacity.value, 0.4);
}); });
testWidgets('pressedOpacity parameter', (WidgetTester tester) async { testWidgetsWithLeakTracking('pressedOpacity parameter', (WidgetTester tester) async {
const double pressedOpacity = 0.5; const double pressedOpacity = 0.5;
await tester.pumpWidget(boilerplate(child: CupertinoButton( await tester.pumpWidget(boilerplate(child: CupertinoButton(
pressedOpacity: pressedOpacity, pressedOpacity: pressedOpacity,
...@@ -271,7 +272,7 @@ void main() { ...@@ -271,7 +272,7 @@ void main() {
expect(opacity.opacity.value, pressedOpacity); expect(opacity.opacity.value, pressedOpacity);
}); });
testWidgets('Cupertino button is semantically a button', (WidgetTester tester) async { testWidgetsWithLeakTracking('Cupertino button is semantically a button', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget( await tester.pumpWidget(
boilerplate( boilerplate(
...@@ -302,7 +303,7 @@ void main() { ...@@ -302,7 +303,7 @@ void main() {
semantics.dispose(); semantics.dispose();
}); });
testWidgets('Can specify colors', (WidgetTester tester) async { testWidgetsWithLeakTracking('Can specify colors', (WidgetTester tester) async {
await tester.pumpWidget(boilerplate(child: CupertinoButton( await tester.pumpWidget(boilerplate(child: CupertinoButton(
color: const Color(0x000000FF), color: const Color(0x000000FF),
disabledColor: const Color(0x0000FF00), disabledColor: const Color(0x0000FF00),
...@@ -330,7 +331,7 @@ void main() { ...@@ -330,7 +331,7 @@ void main() {
expect(boxDecoration.color, const Color(0x0000FF00)); expect(boxDecoration.color, const Color(0x0000FF00));
}); });
testWidgets('Can specify dynamic colors', (WidgetTester tester) async { testWidgetsWithLeakTracking('Can specify dynamic colors', (WidgetTester tester) async {
const Color bgColor = CupertinoDynamicColor.withBrightness( const Color bgColor = CupertinoDynamicColor.withBrightness(
color: Color(0xFF123456), color: Color(0xFF123456),
darkColor: Color(0xFF654321), darkColor: Color(0xFF654321),
...@@ -379,7 +380,7 @@ void main() { ...@@ -379,7 +380,7 @@ void main() {
expect(boxDecoration.color!.value, 0xFF111111); expect(boxDecoration.color!.value, 0xFF111111);
}); });
testWidgets('Button respects themes', (WidgetTester tester) async { testWidgetsWithLeakTracking('Button respects themes', (WidgetTester tester) async {
late TextStyle textStyle; late TextStyle textStyle;
await tester.pumpWidget( await tester.pumpWidget(
...@@ -453,7 +454,7 @@ void main() { ...@@ -453,7 +454,7 @@ void main() {
expect(decoration.color, isSameColorAs(CupertinoColors.systemBlue.darkColor)); expect(decoration.color, isSameColorAs(CupertinoColors.systemBlue.darkColor));
}); });
testWidgets('Hovering over Cupertino button updates cursor to clickable on Web', (WidgetTester tester) async { testWidgetsWithLeakTracking('Hovering over Cupertino button updates cursor to clickable on Web', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
CupertinoApp( CupertinoApp(
home: Center( home: Center(
......
...@@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart'; ...@@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import '../widgets/semantics_tester.dart'; import '../widgets/semantics_tester.dart';
...@@ -15,7 +16,7 @@ void main() { ...@@ -15,7 +16,7 @@ void main() {
debugResetSemanticsIdCounter(); debugResetSemanticsIdCounter();
}); });
testWidgets('CupertinoCheckbox semantics', (WidgetTester tester) async { testWidgetsWithLeakTracking('CupertinoCheckbox semantics', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics(); final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget( await tester.pumpWidget(
...@@ -155,7 +156,7 @@ void main() { ...@@ -155,7 +156,7 @@ void main() {
handle.dispose(); handle.dispose();
}); });
testWidgets('Can wrap CupertinoCheckbox with Semantics', (WidgetTester tester) async { testWidgetsWithLeakTracking('Can wrap CupertinoCheckbox with Semantics', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics(); final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget( await tester.pumpWidget(
...@@ -183,7 +184,7 @@ void main() { ...@@ -183,7 +184,7 @@ void main() {
handle.dispose(); handle.dispose();
}); });
testWidgets('CupertinoCheckbox tristate: true', (WidgetTester tester) async { testWidgetsWithLeakTracking('CupertinoCheckbox tristate: true', (WidgetTester tester) async {
bool? checkBoxValue; bool? checkBoxValue;
await tester.pumpWidget( await tester.pumpWidget(
...@@ -227,7 +228,7 @@ void main() { ...@@ -227,7 +228,7 @@ void main() {
expect(checkBoxValue, null); expect(checkBoxValue, null);
}); });
testWidgets('has semantics for tristate', (WidgetTester tester) async { testWidgetsWithLeakTracking('has semantics for tristate', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget( await tester.pumpWidget(
CupertinoApp( CupertinoApp(
...@@ -294,7 +295,7 @@ void main() { ...@@ -294,7 +295,7 @@ void main() {
semantics.dispose(); semantics.dispose();
}); });
testWidgets('has semantic events', (WidgetTester tester) async { testWidgetsWithLeakTracking('has semantic events', (WidgetTester tester) async {
dynamic semanticEvent; dynamic semanticEvent;
bool? checkboxValue = false; bool? checkboxValue = false;
tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler<dynamic>(SystemChannels.accessibility, (dynamic message) async { tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler<dynamic>(SystemChannels.accessibility, (dynamic message) async {
...@@ -334,7 +335,7 @@ void main() { ...@@ -334,7 +335,7 @@ void main() {
semanticsTester.dispose(); semanticsTester.dispose();
}); });
testWidgets('Checkbox can be toggled by keyboard shortcuts', (WidgetTester tester) async { testWidgetsWithLeakTracking('Checkbox can be toggled by keyboard shortcuts', (WidgetTester tester) async {
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
bool? value = true; bool? value = true;
Widget buildApp({bool enabled = true}) { Widget buildApp({bool enabled = true}) {
...@@ -371,7 +372,7 @@ void main() { ...@@ -371,7 +372,7 @@ void main() {
expect(value, isTrue); expect(value, isTrue);
}); });
testWidgets('Checkbox respects shape and side', (WidgetTester tester) async { testWidgetsWithLeakTracking('Checkbox respects shape and side', (WidgetTester tester) async {
const RoundedRectangleBorder roundedRectangleBorder = const RoundedRectangleBorder roundedRectangleBorder =
RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(5))); RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(5)));
......
...@@ -1083,12 +1083,13 @@ void main() { ...@@ -1083,12 +1083,13 @@ void main() {
expect(key1.currentState, isNull); expect(key1.currentState, isNull);
}); });
testWidgets('MaterialApp.router works', (WidgetTester tester) async { testWidgetsWithLeakTracking('MaterialApp.router works', (WidgetTester tester) async {
final PlatformRouteInformationProvider provider = PlatformRouteInformationProvider( final PlatformRouteInformationProvider provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation( initialRouteInformation: RouteInformation(
uri: Uri.parse('initial'), uri: Uri.parse('initial'),
), ),
); );
addTearDown(provider.dispose);
final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate( final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate(
builder: (BuildContext context, RouteInformation information) { builder: (BuildContext context, RouteInformation information) {
return Text(information.uri.toString()); return Text(information.uri.toString());
...@@ -1100,6 +1101,7 @@ void main() { ...@@ -1100,6 +1101,7 @@ void main() {
return route.didPop(result); return route.didPop(result);
}, },
); );
addTearDown(delegate.dispose);
await tester.pumpWidget(MaterialApp.router( await tester.pumpWidget(MaterialApp.router(
routeInformationProvider: provider, routeInformationProvider: provider,
routeInformationParser: SimpleRouteInformationParser(), routeInformationParser: SimpleRouteInformationParser(),
...@@ -1112,9 +1114,14 @@ void main() { ...@@ -1112,9 +1114,14 @@ void main() {
await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { }); await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { });
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('popped'), findsOneWidget); expect(find.text('popped'), findsOneWidget);
}); },
// TODO(polina-c): remove after fixing
testWidgets('MaterialApp.router route information parser is optional', (WidgetTester tester) async { // https://github.com/flutter/flutter/issues/134205
leakTrackingTestConfig: const LeakTrackingTestConfig(
allowAllNotDisposed: true,
));
testWidgetsWithLeakTracking('MaterialApp.router route information parser is optional', (WidgetTester tester) async {
final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate( final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate(
builder: (BuildContext context, RouteInformation information) { builder: (BuildContext context, RouteInformation information) {
return Text(information.uri.toString()); return Text(information.uri.toString());
...@@ -1126,6 +1133,7 @@ void main() { ...@@ -1126,6 +1133,7 @@ void main() {
return route.didPop(result); return route.didPop(result);
}, },
); );
addTearDown(delegate.dispose);
delegate.routeInformation = RouteInformation(uri: Uri.parse('initial')); delegate.routeInformation = RouteInformation(uri: Uri.parse('initial'));
await tester.pumpWidget(MaterialApp.router( await tester.pumpWidget(MaterialApp.router(
routerDelegate: delegate, routerDelegate: delegate,
...@@ -1137,7 +1145,12 @@ void main() { ...@@ -1137,7 +1145,12 @@ void main() {
await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { }); await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { });
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('popped'), findsOneWidget); expect(find.text('popped'), findsOneWidget);
}); },
// TODO(polina-c): remove after fixing
// https://github.com/flutter/flutter/issues/134205
leakTrackingTestConfig: const LeakTrackingTestConfig(
allowAllNotDisposed: true,
));
testWidgetsWithLeakTracking('MaterialApp.router throw if route information provider is provided but no route information parser', (WidgetTester tester) async { testWidgetsWithLeakTracking('MaterialApp.router throw if route information provider is provided but no route information parser', (WidgetTester tester) async {
final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate( final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate(
...@@ -1151,6 +1164,7 @@ void main() { ...@@ -1151,6 +1164,7 @@ void main() {
return route.didPop(result); return route.didPop(result);
}, },
); );
addTearDown(delegate.dispose);
delegate.routeInformation = RouteInformation(uri: Uri.parse('initial')); delegate.routeInformation = RouteInformation(uri: Uri.parse('initial'));
final PlatformRouteInformationProvider provider = PlatformRouteInformationProvider( final PlatformRouteInformationProvider provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation( initialRouteInformation: RouteInformation(
...@@ -1177,6 +1191,7 @@ void main() { ...@@ -1177,6 +1191,7 @@ void main() {
return route.didPop(result); return route.didPop(result);
}, },
); );
addTearDown(delegate.dispose);
delegate.routeInformation = RouteInformation(uri: Uri.parse('initial')); delegate.routeInformation = RouteInformation(uri: Uri.parse('initial'));
final RouterConfig<RouteInformation> routerConfig = RouterConfig<RouteInformation>(routerDelegate: delegate); final RouterConfig<RouteInformation> routerConfig = RouterConfig<RouteInformation>(routerDelegate: delegate);
await tester.pumpWidget(MaterialApp.router( await tester.pumpWidget(MaterialApp.router(
...@@ -1186,15 +1201,19 @@ void main() { ...@@ -1186,15 +1201,19 @@ void main() {
expect(tester.takeException(), isAssertionError); expect(tester.takeException(), isAssertionError);
}); });
testWidgets('MaterialApp.router router config works', (WidgetTester tester) async { testWidgetsWithLeakTracking('MaterialApp.router router config works', (WidgetTester tester) async {
late SimpleNavigatorRouterDelegate routerDelegate;
addTearDown(() => routerDelegate.dispose());
late PlatformRouteInformationProvider provider;
addTearDown(() => provider.dispose());
final RouterConfig<RouteInformation> routerConfig = RouterConfig<RouteInformation>( final RouterConfig<RouteInformation> routerConfig = RouterConfig<RouteInformation>(
routeInformationProvider: PlatformRouteInformationProvider( routeInformationProvider: provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation( initialRouteInformation: RouteInformation(
uri: Uri.parse('initial'), uri: Uri.parse('initial'),
), ),
), ),
routeInformationParser: SimpleRouteInformationParser(), routeInformationParser: SimpleRouteInformationParser(),
routerDelegate: SimpleNavigatorRouterDelegate( routerDelegate: routerDelegate = SimpleNavigatorRouterDelegate(
builder: (BuildContext context, RouteInformation information) { builder: (BuildContext context, RouteInformation information) {
return Text(information.uri.toString()); return Text(information.uri.toString());
}, },
...@@ -1217,7 +1236,12 @@ void main() { ...@@ -1217,7 +1236,12 @@ void main() {
await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { }); await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { });
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('popped'), findsOneWidget); expect(find.text('popped'), findsOneWidget);
}); },
// TODO(polina-c): remove after fixing
// https://github.com/flutter/flutter/issues/134205
leakTrackingTestConfig: const LeakTrackingTestConfig(
allowAllNotDisposed: true,
));
testWidgetsWithLeakTracking('MaterialApp.builder can build app without a Navigator', (WidgetTester tester) async { testWidgetsWithLeakTracking('MaterialApp.builder can build app without a Navigator', (WidgetTester tester) async {
Widget? builderChild; Widget? builderChild;
...@@ -1545,7 +1569,9 @@ class SimpleNavigatorRouterDelegate extends RouterDelegate<RouteInformation> wit ...@@ -1545,7 +1569,9 @@ class SimpleNavigatorRouterDelegate extends RouterDelegate<RouteInformation> wit
SimpleNavigatorRouterDelegate({ SimpleNavigatorRouterDelegate({
required this.builder, required this.builder,
required this.onPopPage, required this.onPopPage,
}); }) {
maybeDispatchObjectCreation();
}
@override @override
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>(); GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
......
...@@ -703,11 +703,13 @@ void main() { ...@@ -703,11 +703,13 @@ void main() {
expect(calledDelete, isFalse); expect(calledDelete, isFalse);
}); });
testWidgets('Chip elements are ordered horizontally for locale', (WidgetTester tester) async { testWidgetsWithLeakTracking('Chip elements are ordered horizontally for locale', (WidgetTester tester) async {
final UniqueKey iconKey = UniqueKey(); final UniqueKey iconKey = UniqueKey();
late final OverlayEntry entry;
addTearDown(() => entry..remove()..dispose());
final Widget test = Overlay( final Widget test = Overlay(
initialEntries: <OverlayEntry>[ initialEntries: <OverlayEntry>[
OverlayEntry( entry = OverlayEntry(
builder: (BuildContext context) { builder: (BuildContext context) {
return Material( return Material(
child: Chip( child: Chip(
...@@ -882,11 +884,14 @@ void main() { ...@@ -882,11 +884,14 @@ void main() {
testWidgets('Chip padding - LTR', (WidgetTester tester) async { testWidgets('Chip padding - LTR', (WidgetTester tester) async {
final GlobalKey keyA = GlobalKey(); final GlobalKey keyA = GlobalKey();
final GlobalKey keyB = GlobalKey(); final GlobalKey keyB = GlobalKey();
late final OverlayEntry entry;
addTearDown(() => entry..remove()..dispose());
await tester.pumpWidget( await tester.pumpWidget(
wrapForChip( wrapForChip(
child: Overlay( child: Overlay(
initialEntries: <OverlayEntry>[ initialEntries: <OverlayEntry>[
OverlayEntry( entry = OverlayEntry(
builder: (BuildContext context) { builder: (BuildContext context) {
return Material( return Material(
child: Center( child: Center(
...@@ -918,12 +923,16 @@ void main() { ...@@ -918,12 +923,16 @@ void main() {
testWidgets('Chip padding - RTL', (WidgetTester tester) async { testWidgets('Chip padding - RTL', (WidgetTester tester) async {
final GlobalKey keyA = GlobalKey(); final GlobalKey keyA = GlobalKey();
final GlobalKey keyB = GlobalKey(); final GlobalKey keyB = GlobalKey();
late final OverlayEntry entry;
addTearDown(() => entry..remove()..dispose());
await tester.pumpWidget( await tester.pumpWidget(
wrapForChip( wrapForChip(
textDirection: TextDirection.rtl, textDirection: TextDirection.rtl,
child: Overlay( child: Overlay(
initialEntries: <OverlayEntry>[ initialEntries: <OverlayEntry>[
OverlayEntry( entry = OverlayEntry(
builder: (BuildContext context) { builder: (BuildContext context) {
return Material( return Material(
child: Center( child: Center(
......
...@@ -9,7 +9,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -9,7 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'editable_text_utils.dart'; import 'editable_text_utils.dart';
final FocusNode focusNode = FocusNode(debugLabel: 'UndoHistory Node'); final FocusNode _focusNode = FocusNode(debugLabel: 'UndoHistory Node');
void main() { void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
...@@ -41,7 +41,7 @@ void main() { ...@@ -41,7 +41,7 @@ void main() {
onTriggered: (int newValue) { onTriggered: (int newValue) {
value.value = newValue; value.value = newValue;
}, },
focusNode: focusNode, focusNode: _focusNode,
child: Container(), child: Container(),
), ),
), ),
...@@ -57,7 +57,7 @@ void main() { ...@@ -57,7 +57,7 @@ void main() {
controller.redo(); controller.redo();
expect(value.value, 0); expect(value.value, 0);
focusNode.requestFocus(); _focusNode.requestFocus();
await tester.pump(); await tester.pump();
expect(controller.value.canUndo, false); expect(controller.value.canUndo, false);
expect(controller.value.canRedo, false); expect(controller.value.canRedo, false);
...@@ -130,9 +130,9 @@ void main() { ...@@ -130,9 +130,9 @@ void main() {
onTriggered: (int newValue) { onTriggered: (int newValue) {
value.value = newValue; value.value = newValue;
}, },
focusNode: focusNode, focusNode: _focusNode,
child: Focus( child: Focus(
focusNode: focusNode, focusNode: _focusNode,
child: Container(), child: Container(),
), ),
), ),
...@@ -149,7 +149,7 @@ void main() { ...@@ -149,7 +149,7 @@ void main() {
await sendRedo(tester); await sendRedo(tester);
expect(value.value, 0); expect(value.value, 0);
focusNode.requestFocus(); _focusNode.requestFocus();
await tester.pump(); await tester.pump();
expect(controller.value.canUndo, false); expect(controller.value.canUndo, false);
expect(controller.value.canRedo, false); expect(controller.value.canRedo, false);
...@@ -222,13 +222,13 @@ void main() { ...@@ -222,13 +222,13 @@ void main() {
onTriggered: (int newValue) { onTriggered: (int newValue) {
value.value = newValue; value.value = newValue;
}, },
focusNode: focusNode, focusNode: _focusNode,
child: Container(), child: Container(),
), ),
), ),
); );
focusNode.requestFocus(); _focusNode.requestFocus();
// Wait for the throttling. // Wait for the throttling.
await tester.pump(const Duration(milliseconds: 500)); await tester.pump(const Duration(milliseconds: 500));
...@@ -275,7 +275,7 @@ void main() { ...@@ -275,7 +275,7 @@ void main() {
onTriggered: (int newValue) { onTriggered: (int newValue) {
value.value = valueToUse(newValue); value.value = valueToUse(newValue);
}, },
focusNode: focusNode, focusNode: _focusNode,
child: Container(), child: Container(),
), ),
), ),
...@@ -291,7 +291,7 @@ void main() { ...@@ -291,7 +291,7 @@ void main() {
controller.redo(); controller.redo();
expect(value.value, 0); expect(value.value, 0);
focusNode.requestFocus(); _focusNode.requestFocus();
await tester.pump(); await tester.pump();
expect(controller.value.canUndo, false); expect(controller.value.canUndo, false);
expect(controller.value.canRedo, false); expect(controller.value.canRedo, false);
...@@ -389,9 +389,9 @@ void main() { ...@@ -389,9 +389,9 @@ void main() {
onTriggered: (int newValue) { onTriggered: (int newValue) {
value.value = newValue; value.value = newValue;
}, },
focusNode: focusNode, focusNode: _focusNode,
child: Focus( child: Focus(
focusNode: focusNode, focusNode: _focusNode,
child: Container(), child: Container(),
), ),
), ),
...@@ -399,7 +399,7 @@ void main() { ...@@ -399,7 +399,7 @@ void main() {
); );
await tester.pump(const Duration(milliseconds: 500)); await tester.pump(const Duration(milliseconds: 500));
focusNode.requestFocus(); _focusNode.requestFocus();
await tester.pump(); await tester.pump();
// Undo/redo have no effect if the value has never changed. // Undo/redo have no effect if the value has never changed.
......
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