Unverified Commit 5064f782 authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

Cover more test/material tests with leak tracking. (#136093)

parent 83134ac7
...@@ -876,7 +876,7 @@ void main() { ...@@ -876,7 +876,7 @@ void main() {
expect(tester.getSize(find.byKey(keyA)), equals(const Size(20.0, 20.0))); expect(tester.getSize(find.byKey(keyA)), equals(const Size(20.0, 20.0)));
}); });
testWidgets('Chip padding - LTR', (WidgetTester tester) async { testWidgetsWithLeakTracking('Chip padding - LTR', (WidgetTester tester) async {
final GlobalKey keyA = GlobalKey(); final GlobalKey keyA = GlobalKey();
final GlobalKey keyB = GlobalKey(); final GlobalKey keyB = GlobalKey();
...@@ -915,7 +915,7 @@ void main() { ...@@ -915,7 +915,7 @@ void main() {
expect(tester.getBottomRight(find.byType(Icon)), const Offset(457.0, 309.0)); expect(tester.getBottomRight(find.byType(Icon)), const Offset(457.0, 309.0));
}); });
testWidgets('Chip padding - RTL', (WidgetTester tester) async { testWidgetsWithLeakTracking('Chip padding - RTL', (WidgetTester tester) async {
final GlobalKey keyA = GlobalKey(); final GlobalKey keyA = GlobalKey();
final GlobalKey keyB = GlobalKey(); final GlobalKey keyB = GlobalKey();
...@@ -1849,7 +1849,7 @@ void main() { ...@@ -1849,7 +1849,7 @@ void main() {
expect(tester.getSize(find.byKey(key2)), const Size(80.0, 32.0)); expect(tester.getSize(find.byKey(key2)), const Size(80.0, 32.0));
}); });
testWidgets('Chip uses the right theme colors for the right components', (WidgetTester tester) async { testWidgetsWithLeakTracking('Chip uses the right theme colors for the right components', (WidgetTester tester) async {
final ThemeData themeData = ThemeData( final ThemeData themeData = ThemeData(
platform: TargetPlatform.android, platform: TargetPlatform.android,
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
...@@ -2596,7 +2596,7 @@ void main() { ...@@ -2596,7 +2596,7 @@ void main() {
checkChipMaterialClipBehavior(tester, Clip.antiAlias); checkChipMaterialClipBehavior(tester, Clip.antiAlias);
}); });
testWidgets('selected chip and avatar draw darkened layer within avatar circle', (WidgetTester tester) async { testWidgetsWithLeakTracking('selected chip and avatar draw darkened layer within avatar circle', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
wrapForChip( wrapForChip(
useMaterial3: false, useMaterial3: false,
...@@ -2639,8 +2639,9 @@ void main() { ...@@ -2639,8 +2639,9 @@ void main() {
expect(find.byType(InkWell), findsOneWidget); expect(find.byType(InkWell), findsOneWidget);
}); });
testWidgets('Chip uses stateful color for text color in different states', (WidgetTester tester) async { testWidgetsWithLeakTracking('Chip uses stateful color for text color in different states', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(); final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
const Color pressedColor = Color(0x00000001); const Color pressedColor = Color(0x00000001);
const Color hoverColor = Color(0x00000002); const Color hoverColor = Color(0x00000002);
...@@ -2727,8 +2728,9 @@ void main() { ...@@ -2727,8 +2728,9 @@ void main() {
expect(textColor(), disabledColor); expect(textColor(), disabledColor);
}); });
testWidgets('Chip uses stateful border side color in different states', (WidgetTester tester) async { testWidgetsWithLeakTracking('Chip uses stateful border side color in different states', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(); final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
const Color pressedColor = Color(0x00000001); const Color pressedColor = Color(0x00000001);
const Color hoverColor = Color(0x00000002); const Color hoverColor = Color(0x00000002);
...@@ -2807,8 +2809,9 @@ void main() { ...@@ -2807,8 +2809,9 @@ void main() {
expect(find.byType(RawChip), paints..rrect()..rrect(color: disabledColor)); expect(find.byType(RawChip), paints..rrect()..rrect(color: disabledColor));
}); });
testWidgets('Chip uses stateful border side color from resolveWith', (WidgetTester tester) async { testWidgetsWithLeakTracking('Chip uses stateful border side color from resolveWith', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(); final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
const Color pressedColor = Color(0x00000001); const Color pressedColor = Color(0x00000001);
const Color hoverColor = Color(0x00000002); const Color hoverColor = Color(0x00000002);
...@@ -2888,8 +2891,9 @@ void main() { ...@@ -2888,8 +2891,9 @@ void main() {
}); });
testWidgets('Chip uses stateful nullable border side color from resolveWith', (WidgetTester tester) async { testWidgetsWithLeakTracking('Chip uses stateful nullable border side color from resolveWith', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(); final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
const Color pressedColor = Color(0x00000001); const Color pressedColor = Color(0x00000001);
const Color hoverColor = Color(0x00000002); const Color hoverColor = Color(0x00000002);
...@@ -2977,8 +2981,9 @@ void main() { ...@@ -2977,8 +2981,9 @@ void main() {
expect(find.byType(RawChip), paints..rrect()..rrect(color: disabledColor)); expect(find.byType(RawChip), paints..rrect()..rrect(color: disabledColor));
}); });
testWidgets('Chip uses stateful shape in different states', (WidgetTester tester) async { testWidgetsWithLeakTracking('Chip uses stateful shape in different states', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(); final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
OutlinedBorder? getShape(Set<MaterialState> states) { OutlinedBorder? getShape(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) { if (states.contains(MaterialState.disabled)) {
...@@ -3320,8 +3325,9 @@ void main() { ...@@ -3320,8 +3325,9 @@ void main() {
expect(decoration.shape, shape); expect(decoration.shape, shape);
}); });
testWidgets('Chip highlight color is drawn on top of the backgroundColor', (WidgetTester tester) async { testWidgetsWithLeakTracking('Chip highlight color is drawn on top of the backgroundColor', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(debugLabel: 'RawChip'); final FocusNode focusNode = FocusNode(debugLabel: 'RawChip');
addTearDown(focusNode.dispose);
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
const Color backgroundColor = Color(0xff00ff00); const Color backgroundColor = Color(0xff00ff00);
...@@ -3443,7 +3449,7 @@ void main() { ...@@ -3443,7 +3449,7 @@ void main() {
expect(getMaterialBox(tester), paints..rrect(color: selectedColor)); expect(getMaterialBox(tester), paints..rrect(color: selectedColor));
}); });
testWidgets('Delete button tap target area does not include label', (WidgetTester tester) async { testWidgetsWithLeakTracking('Delete button tap target area does not include label', (WidgetTester tester) async {
bool calledDelete = false; bool calledDelete = false;
await tester.pumpWidget( await tester.pumpWidget(
wrapForChip( wrapForChip(
...@@ -3486,7 +3492,7 @@ void main() { ...@@ -3486,7 +3492,7 @@ void main() {
}); });
// This is a regression test for https://github.com/flutter/flutter/pull/133615. // This is a regression test for https://github.com/flutter/flutter/pull/133615.
testWidgets('Material3 - Custom shape without provided side uses default side', (WidgetTester tester) async { testWidgetsWithLeakTracking('Material3 - Custom shape without provided side uses default side', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true); final ThemeData theme = ThemeData(useMaterial3: true);
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
...@@ -3510,7 +3516,7 @@ void main() { ...@@ -3510,7 +3516,7 @@ void main() {
); );
}); });
testWidgets("Material3 - RawChip.shape's side is used when provided", (WidgetTester tester) async { testWidgetsWithLeakTracking("Material3 - RawChip.shape's side is used when provided", (WidgetTester tester) async {
Widget buildChip({ OutlinedBorder? shape, BorderSide? side }) { Widget buildChip({ OutlinedBorder? shape, BorderSide? side }) {
return MaterialApp( return MaterialApp(
theme: ThemeData(useMaterial3: true), theme: ThemeData(useMaterial3: true),
...@@ -3569,7 +3575,7 @@ void main() { ...@@ -3569,7 +3575,7 @@ void main() {
// support is deprecated and the APIs are removed, these tests // support is deprecated and the APIs are removed, these tests
// can be deleted. // can be deleted.
testWidgets('M2 Chip defaults', (WidgetTester tester) async { testWidgetsWithLeakTracking('M2 Chip defaults', (WidgetTester tester) async {
late TextTheme textTheme; late TextTheme textTheme;
Widget buildFrame(Brightness brightness) { Widget buildFrame(Brightness brightness) {
...@@ -3646,7 +3652,7 @@ void main() { ...@@ -3646,7 +3652,7 @@ void main() {
expect(labelStyle.wordSpacing, textTheme.bodyLarge?.wordSpacing); expect(labelStyle.wordSpacing, textTheme.bodyLarge?.wordSpacing);
}); });
testWidgets('Chip uses the right theme colors for the right components', (WidgetTester tester) async { testWidgetsWithLeakTracking('Chip uses the right theme colors for the right components', (WidgetTester tester) async {
final ThemeData themeData = ThemeData( final ThemeData themeData = ThemeData(
platform: TargetPlatform.android, platform: TargetPlatform.android,
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
......
...@@ -929,7 +929,7 @@ void main() { ...@@ -929,7 +929,7 @@ void main() {
); );
}); });
testWidgets("Material3 - RawChip.shape's side is used when provided", (WidgetTester tester) async { testWidgetsWithLeakTracking("Material3 - RawChip.shape's side is used when provided", (WidgetTester tester) async {
Widget buildChip({ OutlinedBorder? shape, BorderSide? side }) { Widget buildChip({ OutlinedBorder? shape, BorderSide? side }) {
return MaterialApp( return MaterialApp(
theme: ThemeData( theme: ThemeData(
......
...@@ -698,7 +698,7 @@ void main() { ...@@ -698,7 +698,7 @@ void main() {
expect(find.text('disabled'), findsOneWidget); expect(find.text('disabled'), findsOneWidget);
}); });
testWidgets( testWidgetsWithLeakTracking(
'DropdownButtonFormField - hint displays when the items list is ' 'DropdownButtonFormField - hint displays when the items list is '
'empty, items is null, and disabledHint is null', 'empty, items is null, and disabledHint is null',
(WidgetTester tester) async { (WidgetTester tester) async {
...@@ -1232,7 +1232,7 @@ void main() { ...@@ -1232,7 +1232,7 @@ void main() {
expect(inkWell.borderRadius, errorBorderRadius); expect(inkWell.borderRadius, errorBorderRadius);
}); });
testWidgets('DropdownButtonFormField onChanged is called when the form is reset', (WidgetTester tester) async { testWidgetsWithLeakTracking('DropdownButtonFormField onChanged is called when the form is reset', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/123009. // Regression test for https://github.com/flutter/flutter/issues/123009.
final GlobalKey<FormFieldState<String>> stateKey = GlobalKey<FormFieldState<String>>(); final GlobalKey<FormFieldState<String>> stateKey = GlobalKey<FormFieldState<String>>();
final GlobalKey<FormState> formKey = GlobalKey<FormState>(); final GlobalKey<FormState> formKey = GlobalKey<FormState>();
......
...@@ -1782,6 +1782,7 @@ void main() { ...@@ -1782,6 +1782,7 @@ void main() {
count += 1; count += 1;
} }
final MaterialStatesController controller = MaterialStatesController(); final MaterialStatesController controller = MaterialStatesController();
addTearDown(controller.dispose);
controller.addListener(valueChanged); controller.addListener(valueChanged);
await tester.pumpWidget( await tester.pumpWidget(
...@@ -1882,21 +1883,23 @@ void main() { ...@@ -1882,21 +1883,23 @@ void main() {
await gesture.removePointer(); await gesture.removePointer();
} }
testWidgets('ElevatedButton statesController', (WidgetTester tester) async { testWidgetsWithLeakTracking('ElevatedButton statesController', (WidgetTester tester) async {
testStatesController(null, tester); testStatesController(null, tester);
}); });
testWidgets('ElevatedButton.icon statesController', (WidgetTester tester) async { testWidgetsWithLeakTracking('ElevatedButton.icon statesController', (WidgetTester tester) async {
testStatesController(const Icon(Icons.add), tester); testStatesController(const Icon(Icons.add), tester);
}); });
testWidgets('Disabled ElevatedButton statesController', (WidgetTester tester) async { testWidgetsWithLeakTracking('Disabled ElevatedButton statesController', (WidgetTester tester) async {
int count = 0; int count = 0;
void valueChanged() { void valueChanged() {
count += 1; count += 1;
} }
final MaterialStatesController controller = MaterialStatesController(); final MaterialStatesController controller = MaterialStatesController();
addTearDown(controller.dispose);
controller.addListener(valueChanged); controller.addListener(valueChanged);
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Center( home: Center(
......
...@@ -589,7 +589,7 @@ void main() { ...@@ -589,7 +589,7 @@ void main() {
}); });
// Regression test for https://github.com/flutter/flutter/issues/71435 // Regression test for https://github.com/flutter/flutter/issues/71435
testWidgets( testWidgetsWithLeakTracking(
'Scaffold.bottomSheet should be updated without creating a new RO' 'Scaffold.bottomSheet should be updated without creating a new RO'
' when the new widget has the same key and type.', ' when the new widget has the same key and type.',
(WidgetTester tester) async { (WidgetTester tester) async {
......
...@@ -1134,7 +1134,7 @@ void main() { ...@@ -1134,7 +1134,7 @@ void main() {
expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 14.0 + 40.0); // margin + bottom padding expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 14.0 + 40.0); // margin + bottom padding
}); });
testWidgets( testWidgetsWithLeakTracking(
'Material2 - Custom padding between SnackBar and its contents when set to SnackBarBehavior.fixed', 'Material2 - Custom padding between SnackBar and its contents when set to SnackBarBehavior.fixed',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
...@@ -1191,7 +1191,7 @@ void main() { ...@@ -1191,7 +1191,7 @@ void main() {
}, },
); );
testWidgets( testWidgetsWithLeakTracking(
'Material3 - Custom padding between SnackBar and its contents when set to SnackBarBehavior.fixed', 'Material3 - Custom padding between SnackBar and its contents when set to SnackBarBehavior.fixed',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
...@@ -1405,7 +1405,7 @@ void main() { ...@@ -1405,7 +1405,7 @@ void main() {
expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 24.0); // margin (with no bottom padding) expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 24.0); // margin (with no bottom padding)
}); });
testWidgets( testWidgetsWithLeakTracking(
'Material2 - Custom padding between SnackBar and its contents when set to SnackBarBehavior.floating', 'Material2 - Custom padding between SnackBar and its contents when set to SnackBarBehavior.floating',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
...@@ -1465,7 +1465,7 @@ void main() { ...@@ -1465,7 +1465,7 @@ void main() {
}, },
); );
testWidgets( testWidgetsWithLeakTracking(
'Material3 - Custom padding between SnackBar and its contents when set to SnackBarBehavior.floating', 'Material3 - Custom padding between SnackBar and its contents when set to SnackBarBehavior.floating',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
...@@ -1873,7 +1873,7 @@ void main() { ...@@ -1873,7 +1873,7 @@ void main() {
behavior: behavior, behavior: behavior,
); );
testWidgets( testWidgetsWithLeakTracking(
'$behavior should align SnackBar with the bottom of Scaffold ' '$behavior should align SnackBar with the bottom of Scaffold '
'when Scaffold has no other elements', 'when Scaffold has no other elements',
(WidgetTester tester) async { (WidgetTester tester) async {
...@@ -1902,7 +1902,7 @@ void main() { ...@@ -1902,7 +1902,7 @@ void main() {
}, },
); );
testWidgets( testWidgetsWithLeakTracking(
'$behavior should align SnackBar with the top of BottomNavigationBar ' '$behavior should align SnackBar with the top of BottomNavigationBar '
'when Scaffold has no FloatingActionButton', 'when Scaffold has no FloatingActionButton',
(WidgetTester tester) async { (WidgetTester tester) async {
...@@ -1934,7 +1934,7 @@ void main() { ...@@ -1934,7 +1934,7 @@ void main() {
); );
} }
testWidgets( testWidgetsWithLeakTracking(
'Padding of ${SnackBarBehavior.fixed} is not consumed by viewInsets', 'Padding of ${SnackBarBehavior.fixed} is not consumed by viewInsets',
(WidgetTester tester) async { (WidgetTester tester) async {
final Widget child = MaterialApp( final Widget child = MaterialApp(
...@@ -1997,7 +1997,7 @@ void main() { ...@@ -1997,7 +1997,7 @@ void main() {
}, },
); );
testWidgets( testWidgetsWithLeakTracking(
'${SnackBarBehavior.fixed} should align SnackBar with the bottom of Scaffold ' '${SnackBarBehavior.fixed} should align SnackBar with the bottom of Scaffold '
'when Scaffold has a FloatingActionButton', 'when Scaffold has a FloatingActionButton',
(WidgetTester tester) async { (WidgetTester tester) async {
...@@ -2032,7 +2032,7 @@ void main() { ...@@ -2032,7 +2032,7 @@ void main() {
}, },
); );
testWidgets( testWidgetsWithLeakTracking(
'${SnackBarBehavior.floating} should align SnackBar with the top of FloatingActionButton when Scaffold has a FloatingActionButton', '${SnackBarBehavior.floating} should align SnackBar with the top of FloatingActionButton when Scaffold has a FloatingActionButton',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
...@@ -2072,7 +2072,7 @@ void main() { ...@@ -2072,7 +2072,7 @@ void main() {
}, },
); );
testWidgets( testWidgetsWithLeakTracking(
'${SnackBarBehavior.floating} should not align SnackBar with the top of FloatingActionButton ' '${SnackBarBehavior.floating} should not align SnackBar with the top of FloatingActionButton '
'when Scaffold has a FloatingActionButton and floatingActionButtonLocation is set to a top position', 'when Scaffold has a FloatingActionButton and floatingActionButtonLocation is set to a top position',
(WidgetTester tester) async { (WidgetTester tester) async {
...@@ -2125,7 +2125,7 @@ void main() { ...@@ -2125,7 +2125,7 @@ void main() {
}, },
); );
testWidgets( testWidgetsWithLeakTracking(
'${SnackBarBehavior.floating} should align SnackBar with the top of FloatingActionButton ' '${SnackBarBehavior.floating} should align SnackBar with the top of FloatingActionButton '
'when Scaffold has a FloatingActionButton and floatingActionButtonLocation is not set to a top position', 'when Scaffold has a FloatingActionButton and floatingActionButtonLocation is not set to a top position',
(WidgetTester tester) async { (WidgetTester tester) async {
...@@ -2193,7 +2193,7 @@ void main() { ...@@ -2193,7 +2193,7 @@ void main() {
}, },
); );
testWidgets( testWidgetsWithLeakTracking(
'${SnackBarBehavior.fixed} should align SnackBar with the top of BottomNavigationBar ' '${SnackBarBehavior.fixed} should align SnackBar with the top of BottomNavigationBar '
'when Scaffold has a BottomNavigationBar and FloatingActionButton', 'when Scaffold has a BottomNavigationBar and FloatingActionButton',
(WidgetTester tester) async { (WidgetTester tester) async {
...@@ -2230,7 +2230,7 @@ void main() { ...@@ -2230,7 +2230,7 @@ void main() {
}, },
); );
testWidgets( testWidgetsWithLeakTracking(
'${SnackBarBehavior.floating} should align SnackBar with the top of FloatingActionButton ' '${SnackBarBehavior.floating} should align SnackBar with the top of FloatingActionButton '
'when Scaffold has BottomNavigationBar and FloatingActionButton', 'when Scaffold has BottomNavigationBar and FloatingActionButton',
(WidgetTester tester) async { (WidgetTester tester) async {
...@@ -2400,7 +2400,7 @@ void main() { ...@@ -2400,7 +2400,7 @@ void main() {
expect(errorMessages.contains(offScreenMessage), isTrue); expect(errorMessages.contains(offScreenMessage), isTrue);
}); });
testWidgets( testWidgetsWithLeakTracking(
'SnackBar has correct end padding when it contains an action with fixed behavior', 'SnackBar has correct end padding when it contains an action with fixed behavior',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
...@@ -2437,7 +2437,7 @@ void main() { ...@@ -2437,7 +2437,7 @@ void main() {
}, },
); );
testWidgets( testWidgetsWithLeakTracking(
'SnackBar has correct end padding when it contains an action with floating behavior', 'SnackBar has correct end padding when it contains an action with floating behavior',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
...@@ -3337,7 +3337,7 @@ void main() { ...@@ -3337,7 +3337,7 @@ void main() {
); );
}); });
testWidgets( testWidgetsWithLeakTracking(
'ScaffoldMessenger will alert for snackbars that cannot be presented', (WidgetTester tester) async { 'ScaffoldMessenger will alert for snackbars that cannot be presented', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/103004 // Regression test for https://github.com/flutter/flutter/issues/103004
await tester.pumpWidget(const MaterialApp( await tester.pumpWidget(const MaterialApp(
...@@ -3723,7 +3723,7 @@ testWidgetsWithLeakTracking('SnackBarAction backgroundColor works as a Color', ( ...@@ -3723,7 +3723,7 @@ testWidgetsWithLeakTracking('SnackBarAction backgroundColor works as a Color', (
expect(completer.isCompleted, true); expect(completer.isCompleted, true);
}); });
testWidgets("Can't tap on button behind snack bar defined by margin and HitTestBehavior.opaque", (WidgetTester tester) async { testWidgetsWithLeakTracking("Can't tap on button behind snack bar defined by margin and HitTestBehavior.opaque", (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/78537. // Regression test for https://github.com/flutter/flutter/issues/78537.
tester.view.physicalSize = const Size.square(200); tester.view.physicalSize = const Size.square(200);
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
......
...@@ -787,7 +787,7 @@ void main() { ...@@ -787,7 +787,7 @@ void main() {
expect(state.widget.cursorColor, cursorColor); expect(state.widget.cursorColor, cursorColor);
}); });
testWidgets('Use error cursor color when an InputDecoration with an errorText or error widget is provided', (WidgetTester tester) async { testWidgetsWithLeakTracking('Use error cursor color when an InputDecoration with an errorText or error widget is provided', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
home: Material( home: Material(
...@@ -2484,7 +2484,7 @@ void main() { ...@@ -2484,7 +2484,7 @@ void main() {
expect(controller.selection.extentOffset, testValue.indexOf('g')); expect(controller.selection.extentOffset, testValue.indexOf('g'));
}); });
testWidgets('Can move cursor when dragging, when tap is on collapsed selection (iOS)', (WidgetTester tester) async { testWidgetsWithLeakTracking('Can move cursor when dragging, when tap is on collapsed selection (iOS)', (WidgetTester tester) async {
final TextEditingController controller = _textEditingController(); final TextEditingController controller = _textEditingController();
await tester.pumpWidget( await tester.pumpWidget(
...@@ -2527,6 +2527,11 @@ void main() { ...@@ -2527,6 +2527,11 @@ void main() {
expect(controller.selection.isCollapsed, true); expect(controller.selection.isCollapsed, true);
expect(controller.selection.baseOffset, testValue.indexOf('i')); expect(controller.selection.baseOffset, testValue.indexOf('i'));
// End gesture and skip the magnifier hide animation, so it can release
// resources.
await gesture.up();
await tester.pumpAndSettle();
}, },
variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS }), variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS }),
); );
...@@ -2576,7 +2581,7 @@ void main() { ...@@ -2576,7 +2581,7 @@ void main() {
variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS }), variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS }),
); );
testWidgets('Can move cursor when dragging, when tap is on collapsed selection (iOS) - multiline', (WidgetTester tester) async { testWidgetsWithLeakTracking('Can move cursor when dragging, when tap is on collapsed selection (iOS) - multiline', (WidgetTester tester) async {
final TextEditingController controller = _textEditingController(); final TextEditingController controller = _textEditingController();
await tester.pumpWidget( await tester.pumpWidget(
...@@ -2620,11 +2625,16 @@ void main() { ...@@ -2620,11 +2625,16 @@ void main() {
expect(controller.selection.isCollapsed, true); expect(controller.selection.isCollapsed, true);
expect(controller.selection.baseOffset, testValue.indexOf('i')); expect(controller.selection.baseOffset, testValue.indexOf('i'));
// End gesture and skip the magnifier hide animation, so it can release
// resources.
await gesture.up();
await tester.pumpAndSettle();
}, },
variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS }), variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS }),
); );
testWidgets('Can move cursor when dragging, when tap is on collapsed selection (iOS) - ListView', (WidgetTester tester) async { testWidgetsWithLeakTracking('Can move cursor when dragging, when tap is on collapsed selection (iOS) - ListView', (WidgetTester tester) async {
// This is a regression test for // This is a regression test for
// https://github.com/flutter/flutter/issues/122519 // https://github.com/flutter/flutter/issues/122519
final TextEditingController controller = _textEditingController(); final TextEditingController controller = _textEditingController();
...@@ -2697,6 +2707,11 @@ void main() { ...@@ -2697,6 +2707,11 @@ void main() {
expect(controller.selection.isCollapsed, true); expect(controller.selection.isCollapsed, true);
expect(controller.selection.baseOffset, testValue.indexOf('i')); expect(controller.selection.baseOffset, testValue.indexOf('i'));
// End gesture and skip the magnifier hide animation, so it can release
// resources.
await gesture.up();
await tester.pumpAndSettle();
}, },
variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS }), variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS }),
); );
...@@ -12361,7 +12376,7 @@ void main() { ...@@ -12361,7 +12376,7 @@ void main() {
skip: isBrowser, // [intended] Browser handles arrow keys differently. skip: isBrowser, // [intended] Browser handles arrow keys differently.
); );
testWidgets('long press drag can edge scroll vertically', (WidgetTester tester) async { testWidgetsWithLeakTracking('long press drag can edge scroll vertically', (WidgetTester tester) async {
final TextEditingController controller = _textEditingController( final TextEditingController controller = _textEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure Angrignon Peel Côte-des-Neigse Atwater Peel Sherbrooke Bonaventure Angrignon Peel Côte-des-Neiges', text: 'Atwater Peel Sherbrooke Bonaventure Angrignon Peel Côte-des-Neigse Atwater Peel Sherbrooke Bonaventure Angrignon Peel Côte-des-Neiges',
); );
...@@ -12438,6 +12453,11 @@ void main() { ...@@ -12438,6 +12453,11 @@ void main() {
textOffsetToPosition(tester, 0).dy, textOffsetToPosition(tester, 0).dy,
moreOrLessEquals(firstCharY - lineHeight, epsilon: 1), moreOrLessEquals(firstCharY - lineHeight, epsilon: 1),
); );
// End gesture and skip the magnifier hide animation, so it can release
// resources.
await gesture.up();
await tester.pumpAndSettle();
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgetsWithLeakTracking('keyboard selection change scrolls the field vertically', (WidgetTester tester) async { testWidgetsWithLeakTracking('keyboard selection change scrolls the field vertically', (WidgetTester tester) async {
...@@ -14283,7 +14303,7 @@ void main() { ...@@ -14283,7 +14303,7 @@ void main() {
}); });
}); });
}); });
testWidgets("Arrow keys don't move input focus", (WidgetTester tester) async { testWidgetsWithLeakTracking("Arrow keys don't move input focus", (WidgetTester tester) async {
final TextEditingController controller1 = _textEditingController(); final TextEditingController controller1 = _textEditingController();
final TextEditingController controller2 = _textEditingController(); final TextEditingController controller2 = _textEditingController();
final TextEditingController controller3 = _textEditingController(); final TextEditingController controller3 = _textEditingController();
...@@ -14446,7 +14466,7 @@ void main() { ...@@ -14446,7 +14466,7 @@ void main() {
expect(textFieldSize1, equals(textFieldSize2)); expect(textFieldSize1, equals(textFieldSize2));
}); });
testWidgets( testWidgetsWithLeakTracking(
'The selection menu displays in an Overlay without error', 'The selection menu displays in an Overlay without error',
(WidgetTester tester) async { (WidgetTester tester) async {
// This is a regression test for // This is a regression test for
...@@ -14455,6 +14475,9 @@ void main() { ...@@ -14455,6 +14475,9 @@ void main() {
text: 'This is a test that shows some odd behavior with Text Selection!', text: 'This is a test that shows some odd behavior with Text Selection!',
); );
late final OverlayEntry overlayEntry;
addTearDown(() => overlayEntry..remove()..dispose());
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
home: Scaffold( home: Scaffold(
body: ColoredBox( body: ColoredBox(
...@@ -14466,7 +14489,7 @@ void main() { ...@@ -14466,7 +14489,7 @@ void main() {
height: 600, height: 600,
child: Overlay( child: Overlay(
initialEntries: <OverlayEntry>[ initialEntries: <OverlayEntry>[
OverlayEntry( overlayEntry = OverlayEntry(
builder: (BuildContext context) => Center( builder: (BuildContext context) => Center(
child: TextField( child: TextField(
controller: controller, controller: controller,
...@@ -16271,7 +16294,7 @@ void main() { ...@@ -16271,7 +16294,7 @@ void main() {
}); });
group('magnifier builder', () { group('magnifier builder', () {
testWidgets('should build custom magnifier if given', testWidgetsWithLeakTracking('should build custom magnifier if given',
(WidgetTester tester) async { (WidgetTester tester) async {
final Widget customMagnifier = Container( final Widget customMagnifier = Container(
key: UniqueKey(), key: UniqueKey(),
...@@ -16286,14 +16309,15 @@ void main() { ...@@ -16286,14 +16309,15 @@ void main() {
home: Placeholder(), home: Placeholder(),
)); ));
final BuildContext context = final BuildContext context = tester.firstElement(find.byType(Placeholder));
tester.firstElement(find.byType(Placeholder)); final ValueNotifier<MagnifierInfo> magnifierInfo = ValueNotifier<MagnifierInfo>(MagnifierInfo.empty);
addTearDown(magnifierInfo.dispose);
expect( expect(
textField.magnifierConfiguration!.magnifierBuilder( textField.magnifierConfiguration!.magnifierBuilder(
context, context,
MagnifierController(), MagnifierController(),
ValueNotifier<MagnifierInfo>(MagnifierInfo.empty), magnifierInfo,
), ),
isA<Widget>().having( isA<Widget>().having(
(Widget widget) => widget.key, (Widget widget) => widget.key,
...@@ -16302,24 +16326,26 @@ void main() { ...@@ -16302,24 +16326,26 @@ void main() {
}); });
group('defaults', () { group('defaults', () {
testWidgets('should build Magnifier on Android', (WidgetTester tester) async { testWidgetsWithLeakTracking('should build Magnifier on Android', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp( await tester.pumpWidget(const MaterialApp(
home: Scaffold(body: TextField())) home: Scaffold(body: TextField()))
); );
final BuildContext context = tester.firstElement(find.byType(TextField)); final BuildContext context = tester.firstElement(find.byType(TextField));
final EditableText editableText = tester.widget(find.byType(EditableText)); final EditableText editableText = tester.widget(find.byType(EditableText));
final ValueNotifier<MagnifierInfo> magnifierInfo = ValueNotifier<MagnifierInfo>(MagnifierInfo.empty);
addTearDown(magnifierInfo.dispose);
expect( expect(
editableText.magnifierConfiguration.magnifierBuilder( editableText.magnifierConfiguration.magnifierBuilder(
context, context,
MagnifierController(), MagnifierController(),
ValueNotifier<MagnifierInfo>(MagnifierInfo.empty), magnifierInfo,
), ),
isA<TextMagnifier>()); isA<TextMagnifier>());
}, variant: TargetPlatformVariant.only(TargetPlatform.android)); }, variant: TargetPlatformVariant.only(TargetPlatform.android));
testWidgets('should build CupertinoMagnifier on iOS', testWidgetsWithLeakTracking('should build CupertinoMagnifier on iOS',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp( await tester.pumpWidget(const MaterialApp(
home: Scaffold(body: TextField())) home: Scaffold(body: TextField()))
...@@ -16327,17 +16353,19 @@ void main() { ...@@ -16327,17 +16353,19 @@ void main() {
final BuildContext context = tester.firstElement(find.byType(TextField)); final BuildContext context = tester.firstElement(find.byType(TextField));
final EditableText editableText = tester.widget(find.byType(EditableText)); final EditableText editableText = tester.widget(find.byType(EditableText));
final ValueNotifier<MagnifierInfo> magnifierInfo = ValueNotifier<MagnifierInfo>(MagnifierInfo.empty);
addTearDown(magnifierInfo.dispose);
expect( expect(
editableText.magnifierConfiguration.magnifierBuilder( editableText.magnifierConfiguration.magnifierBuilder(
context, context,
MagnifierController(), MagnifierController(),
ValueNotifier<MagnifierInfo>(MagnifierInfo.empty), magnifierInfo,
), ),
isA<CupertinoTextMagnifier>()); isA<CupertinoTextMagnifier>());
}, variant: TargetPlatformVariant.only(TargetPlatform.iOS)); }, variant: TargetPlatformVariant.only(TargetPlatform.iOS));
testWidgets('should build nothing on Android and iOS', testWidgetsWithLeakTracking('should build nothing on Android and iOS',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp( await tester.pumpWidget(const MaterialApp(
home: Scaffold(body: TextField())) home: Scaffold(body: TextField()))
...@@ -16345,12 +16373,14 @@ void main() { ...@@ -16345,12 +16373,14 @@ void main() {
final BuildContext context = tester.firstElement(find.byType(TextField)); final BuildContext context = tester.firstElement(find.byType(TextField));
final EditableText editableText = tester.widget(find.byType(EditableText)); final EditableText editableText = tester.widget(find.byType(EditableText));
final ValueNotifier<MagnifierInfo> magnifierInfo = ValueNotifier<MagnifierInfo>(MagnifierInfo.empty);
addTearDown(magnifierInfo.dispose);
expect( expect(
editableText.magnifierConfiguration.magnifierBuilder( editableText.magnifierConfiguration.magnifierBuilder(
context, context,
MagnifierController(), MagnifierController(),
ValueNotifier<MagnifierInfo>(MagnifierInfo.empty), magnifierInfo,
), ),
isNull); isNull);
}, },
......
...@@ -694,7 +694,7 @@ void main() { ...@@ -694,7 +694,7 @@ void main() {
expect(find.text('5 of 10'), findsOneWidget); expect(find.text('5 of 10'), findsOneWidget);
}); });
testWidgets('readonly text form field will hide cursor by default', (WidgetTester tester) async { testWidgetsWithLeakTracking('readonly text form field will hide cursor by default', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Material( home: Material(
......
...@@ -864,12 +864,15 @@ void main() { ...@@ -864,12 +864,15 @@ void main() {
expect(tooltipContainer.padding, const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0)); expect(tooltipContainer.padding, const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0));
}, variant: const TargetPlatformVariant(<TargetPlatform>{TargetPlatform.macOS, TargetPlatform.linux, TargetPlatform.windows})); }, variant: const TargetPlatformVariant(<TargetPlatform>{TargetPlatform.macOS, TargetPlatform.linux, TargetPlatform.windows}));
testWidgets('Can tooltip decoration be customized', (WidgetTester tester) async { testWidgetsWithLeakTracking('Can tooltip decoration be customized', (WidgetTester tester) async {
final GlobalKey<TooltipState> tooltipKey = GlobalKey<TooltipState>(); final GlobalKey<TooltipState> tooltipKey = GlobalKey<TooltipState>();
const Decoration customDecoration = ShapeDecoration( const Decoration customDecoration = ShapeDecoration(
shape: StadiumBorder(), shape: StadiumBorder(),
color: Color(0x80800000), color: Color(0x80800000),
); );
late final OverlayEntry entry;
addTearDown(() => entry..remove()..dispose());
await tester.pumpWidget( await tester.pumpWidget(
Theme( Theme(
data: ThemeData(useMaterial3: false), data: ThemeData(useMaterial3: false),
...@@ -877,7 +880,7 @@ void main() { ...@@ -877,7 +880,7 @@ void main() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Overlay( child: Overlay(
initialEntries: <OverlayEntry>[ initialEntries: <OverlayEntry>[
OverlayEntry( entry = OverlayEntry(
builder: (BuildContext context) { builder: (BuildContext context) {
return Tooltip( return Tooltip(
key: tooltipKey, key: tooltipKey,
...@@ -1422,16 +1425,18 @@ void main() { ...@@ -1422,16 +1425,18 @@ void main() {
await tester.pump(waitDuration); await tester.pump(waitDuration);
}); });
testWidgets('Does tooltip contribute semantics', (WidgetTester tester) async { testWidgetsWithLeakTracking('Does tooltip contribute semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
final GlobalKey<TooltipState> tooltipKey = GlobalKey<TooltipState>(); final GlobalKey<TooltipState> tooltipKey = GlobalKey<TooltipState>();
late final OverlayEntry entry;
addTearDown(() => entry..remove()..dispose());
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Overlay( child: Overlay(
initialEntries: <OverlayEntry>[ initialEntries: <OverlayEntry>[
OverlayEntry( entry = OverlayEntry(
builder: (BuildContext context) { builder: (BuildContext context) {
return Stack( return Stack(
children: <Widget>[ children: <Widget>[
...@@ -2349,7 +2354,7 @@ void main() { ...@@ -2349,7 +2354,7 @@ void main() {
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
}); });
testWidgets('Tooltip is not selectable', (WidgetTester tester) async { testWidgetsWithLeakTracking('Tooltip is not selectable', (WidgetTester tester) async {
const String tooltipText = 'AAAAAAAAAAAAAAAAAAAAAAA'; const String tooltipText = 'AAAAAAAAAAAAAAAAAAAAAAA';
String? selectedText; String? selectedText;
await tester.pumpWidget( await tester.pumpWidget(
......
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