Unverified Commit 1437aa2c authored by derdilla's avatar derdilla Committed by GitHub

Cover some cupertino tests with leak tracking (#135230)

parent 397da064
...@@ -8,6 +8,7 @@ library; ...@@ -8,6 +8,7 @@ library;
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.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() {
final Offset basicOffset = Offset(CupertinoMagnifier.kDefaultSize.width / 2, final Offset basicOffset = Offset(CupertinoMagnifier.kDefaultSize.width / 2,
...@@ -48,7 +49,7 @@ void main() { ...@@ -48,7 +49,7 @@ void main() {
animatedPositioned.left ?? 0, animatedPositioned.top ?? 0); animatedPositioned.left ?? 0, animatedPositioned.top ?? 0);
} }
testWidgets('should be at gesture position if does not violate any positioning rules', (WidgetTester tester) async { testWidgetsWithLeakTracking('should be at gesture position if does not violate any positioning rules', (WidgetTester tester) async {
final Key fakeTextFieldKey = UniqueKey(); final Key fakeTextFieldKey = UniqueKey();
final Key outerKey = UniqueKey(); final Key outerKey = UniqueKey();
...@@ -87,6 +88,7 @@ void main() { ...@@ -87,6 +88,7 @@ void main() {
globalGesturePosition: fakeTextFieldRect.center, globalGesturePosition: fakeTextFieldRect.center,
), ),
); );
addTearDown(magnifier.dispose);
await showCupertinoMagnifier(context, tester, magnifier); await showCupertinoMagnifier(context, tester, magnifier);
...@@ -98,7 +100,7 @@ void main() { ...@@ -98,7 +100,7 @@ void main() {
); );
}); });
testWidgets('should never horizontally be outside of Screen Padding', (WidgetTester tester) async { testWidgetsWithLeakTracking('should never horizontally be outside of Screen Padding', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
color: Color.fromARGB(7, 0, 129, 90), color: Color.fromARGB(7, 0, 129, 90),
...@@ -108,19 +110,21 @@ void main() { ...@@ -108,19 +110,21 @@ void main() {
final BuildContext context = tester.firstElement(find.byType(Placeholder)); final BuildContext context = tester.firstElement(find.byType(Placeholder));
final ValueNotifier<MagnifierInfo> magnifierInfo = ValueNotifier<MagnifierInfo>(
MagnifierInfo(
currentLineBoundaries: reasonableTextField,
fieldBounds: reasonableTextField,
caretRect: reasonableTextField,
// The tap position is far out of the right side of the app.
globalGesturePosition:
Offset(MediaQuery.sizeOf(context).width + 100, 0),
),
);
addTearDown(magnifierInfo.dispose);
await showCupertinoMagnifier( await showCupertinoMagnifier(
context, context,
tester, tester,
ValueNotifier<MagnifierInfo>( magnifierInfo,
MagnifierInfo(
currentLineBoundaries: reasonableTextField,
fieldBounds: reasonableTextField,
caretRect: reasonableTextField,
// The tap position is far out of the right side of the app.
globalGesturePosition:
Offset(MediaQuery.sizeOf(context).width + 100, 0),
),
),
); );
// Should be less than the right edge, since we have padding. // Should be less than the right edge, since we have padding.
...@@ -128,7 +132,7 @@ void main() { ...@@ -128,7 +132,7 @@ void main() {
lessThan(MediaQuery.sizeOf(context).width)); lessThan(MediaQuery.sizeOf(context).width));
}); });
testWidgets('should have some vertical drag', (WidgetTester tester) async { testWidgetsWithLeakTracking('should have some vertical drag', (WidgetTester tester) async {
final double dragPositionBelowTextField = reasonableTextField.center.dy + 30; final double dragPositionBelowTextField = reasonableTextField.center.dy + 30;
await tester.pumpWidget( await tester.pumpWidget(
...@@ -141,20 +145,23 @@ void main() { ...@@ -141,20 +145,23 @@ void main() {
final BuildContext context = final BuildContext context =
tester.firstElement(find.byType(Placeholder)); tester.firstElement(find.byType(Placeholder));
final ValueNotifier<MagnifierInfo> magnifierInfo =
ValueNotifier<MagnifierInfo>(
MagnifierInfo(
currentLineBoundaries: reasonableTextField,
fieldBounds: reasonableTextField,
caretRect: reasonableTextField,
// The tap position is dragBelow units below the text field.
globalGesturePosition: Offset(
MediaQuery.sizeOf(context).width / 2,
dragPositionBelowTextField),
),
);
addTearDown(magnifierInfo.dispose);
await showCupertinoMagnifier( await showCupertinoMagnifier(
context, context,
tester, tester,
ValueNotifier<MagnifierInfo>( magnifierInfo,
MagnifierInfo(
currentLineBoundaries: reasonableTextField,
fieldBounds: reasonableTextField,
caretRect: reasonableTextField,
// The tap position is dragBelow units below the text field.
globalGesturePosition: Offset(
MediaQuery.sizeOf(context).width / 2,
dragPositionBelowTextField),
),
),
); );
// The magnifier Y should be greater than the text field, since we "dragged" it down. // The magnifier Y should be greater than the text field, since we "dragged" it down.
...@@ -166,7 +173,7 @@ void main() { ...@@ -166,7 +173,7 @@ void main() {
}); });
group('status', () { group('status', () {
testWidgets('should hide if gesture is far below the text field', (WidgetTester tester) async { testWidgetsWithLeakTracking('should hide if gesture is far below the text field', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
color: Color.fromARGB(7, 0, 129, 90), color: Color.fromARGB(7, 0, 129, 90),
...@@ -177,7 +184,7 @@ void main() { ...@@ -177,7 +184,7 @@ void main() {
final BuildContext context = final BuildContext context =
tester.firstElement(find.byType(Placeholder)); tester.firstElement(find.byType(Placeholder));
final ValueNotifier<MagnifierInfo> magnifierinfo = final ValueNotifier<MagnifierInfo> magnifierInfo =
ValueNotifier<MagnifierInfo>( ValueNotifier<MagnifierInfo>(
MagnifierInfo( MagnifierInfo(
currentLineBoundaries: reasonableTextField, currentLineBoundaries: reasonableTextField,
...@@ -188,16 +195,17 @@ void main() { ...@@ -188,16 +195,17 @@ void main() {
MediaQuery.sizeOf(context).width / 2, reasonableTextField.top), MediaQuery.sizeOf(context).width / 2, reasonableTextField.top),
), ),
); );
addTearDown(magnifierInfo.dispose);
// Show the magnifier initially, so that we get it in a not hidden state. // Show the magnifier initially, so that we get it in a not hidden state.
await showCupertinoMagnifier(context, tester, magnifierinfo); await showCupertinoMagnifier(context, tester, magnifierInfo);
// Move the gesture to one that should hide it. // Move the gesture to one that should hide it.
magnifierinfo.value = MagnifierInfo( magnifierInfo.value = MagnifierInfo(
currentLineBoundaries: reasonableTextField, currentLineBoundaries: reasonableTextField,
fieldBounds: reasonableTextField, fieldBounds: reasonableTextField,
caretRect: reasonableTextField, caretRect: reasonableTextField,
globalGesturePosition: magnifierinfo.value.globalGesturePosition + const Offset(0, 100), globalGesturePosition: magnifierInfo.value.globalGesturePosition + const Offset(0, 100),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -205,7 +213,7 @@ void main() { ...@@ -205,7 +213,7 @@ void main() {
expect(magnifierController.overlayEntry, isNotNull); expect(magnifierController.overlayEntry, isNotNull);
}); });
testWidgets('should re-show if gesture moves back up', testWidgetsWithLeakTracking('should re-show if gesture moves back up',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
...@@ -227,6 +235,7 @@ void main() { ...@@ -227,6 +235,7 @@ void main() {
globalGesturePosition: Offset(MediaQuery.sizeOf(context).width / 2, reasonableTextField.top), globalGesturePosition: Offset(MediaQuery.sizeOf(context).width / 2, reasonableTextField.top),
), ),
); );
addTearDown(magnifierInfo.dispose);
// Show the magnifier initially, so that we get it in a not hidden state. // Show the magnifier initially, so that we get it in a not hidden state.
await showCupertinoMagnifier(context, tester, magnifierInfo); await showCupertinoMagnifier(context, tester, magnifierInfo);
......
...@@ -7,11 +7,12 @@ import 'package:flutter/foundation.dart'; ...@@ -7,11 +7,12 @@ 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';
void main() { void main() {
testWidgets('Radio control test', (WidgetTester tester) async { testWidgetsWithLeakTracking('Radio control test', (WidgetTester tester) async {
final Key key = UniqueKey(); final Key key = UniqueKey();
final List<int?> log = <int?>[]; final List<int?> log = <int?>[];
...@@ -63,7 +64,7 @@ void main() { ...@@ -63,7 +64,7 @@ void main() {
expect(log, isEmpty); expect(log, isEmpty);
}); });
testWidgets('Radio can be toggled when toggleable is set', (WidgetTester tester) async { testWidgetsWithLeakTracking('Radio can be toggled when toggleable is set', (WidgetTester tester) async {
final Key key = UniqueKey(); final Key key = UniqueKey();
final List<int?> log = <int?>[]; final List<int?> log = <int?>[];
...@@ -118,7 +119,7 @@ void main() { ...@@ -118,7 +119,7 @@ void main() {
expect(log, equals(<int>[1])); expect(log, equals(<int>[1]));
}); });
testWidgets('Radio selected semantics - platform adaptive', (WidgetTester tester) async { testWidgetsWithLeakTracking('Radio selected semantics - platform adaptive', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(CupertinoApp( await tester.pumpWidget(CupertinoApp(
...@@ -153,7 +154,7 @@ void main() { ...@@ -153,7 +154,7 @@ void main() {
semantics.dispose(); semantics.dispose();
}, variant: TargetPlatformVariant.all()); }, variant: TargetPlatformVariant.all());
testWidgets('Radio semantics', (WidgetTester tester) async { testWidgetsWithLeakTracking('Radio semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(CupertinoApp( await tester.pumpWidget(CupertinoApp(
...@@ -241,7 +242,7 @@ void main() { ...@@ -241,7 +242,7 @@ void main() {
semantics.dispose(); semantics.dispose();
}); });
testWidgets('has semantic events', (WidgetTester tester) async { testWidgetsWithLeakTracking('has semantic events', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
final Key key = UniqueKey(); final Key key = UniqueKey();
dynamic semanticEvent; dynamic semanticEvent;
...@@ -278,13 +279,14 @@ void main() { ...@@ -278,13 +279,14 @@ void main() {
tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler<dynamic>(SystemChannels.accessibility, null); tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler<dynamic>(SystemChannels.accessibility, null);
}); });
testWidgets('Radio can be controlled by keyboard shortcuts', (WidgetTester tester) async { testWidgetsWithLeakTracking('Radio can be controlled by keyboard shortcuts', (WidgetTester tester) async {
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
int? groupValue = 1; int? groupValue = 1;
const Key radioKey0 = Key('radio0'); const Key radioKey0 = Key('radio0');
const Key radioKey1 = Key('radio1'); const Key radioKey1 = Key('radio1');
const Key radioKey2 = Key('radio2'); const Key radioKey2 = Key('radio2');
final FocusNode focusNode2 = FocusNode(debugLabel: 'radio2'); final FocusNode focusNode2 = FocusNode(debugLabel: 'radio2');
addTearDown(focusNode2.dispose);
Widget buildApp({bool enabled = true}) { Widget buildApp({bool enabled = true}) {
return CupertinoApp( return CupertinoApp(
home: Center( home: Center(
...@@ -350,7 +352,7 @@ void main() { ...@@ -350,7 +352,7 @@ void main() {
expect(groupValue, equals(2)); expect(groupValue, equals(2));
}); });
testWidgets('Show a checkmark when useCheckmarkStyle is true', (WidgetTester tester) async { testWidgetsWithLeakTracking('Show a checkmark when useCheckmarkStyle is true', (WidgetTester tester) async {
await tester.pumpWidget(CupertinoApp( await tester.pumpWidget(CupertinoApp(
home: Center( home: Center(
child: CupertinoRadio<int>( child: CupertinoRadio<int>(
...@@ -405,7 +407,7 @@ void main() { ...@@ -405,7 +407,7 @@ void main() {
); );
}); });
testWidgets('Do not crash when widget disappears while pointer is down', (WidgetTester tester) async { testWidgetsWithLeakTracking('Do not crash when widget disappears while pointer is down', (WidgetTester tester) async {
final Key key = UniqueKey(); final Key key = UniqueKey();
Widget buildRadio(bool show) { Widget buildRadio(bool show) {
......
...@@ -7,11 +7,12 @@ import 'package:flutter/foundation.dart'; ...@@ -7,11 +7,12 @@ 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';
void main() { void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
testWidgets('more than three suggestions throws an error', (WidgetTester tester) async { testWidgetsWithLeakTracking('more than three suggestions throws an error', (WidgetTester tester) async {
Future<void> pumpToolbar(List<String> suggestions) async { Future<void> pumpToolbar(List<String> suggestions) async {
await tester.pumpWidget( await tester.pumpWidget(
CupertinoApp( CupertinoApp(
...@@ -61,10 +62,14 @@ void main() { ...@@ -61,10 +62,14 @@ void main() {
expect(labels, isNot(contains('yeller'))); expect(labels, isNot(contains('yeller')));
}); });
testWidgets('buildButtonItems builds a disabled "No Replacements Found" button when no suggestions', (WidgetTester tester) async { testWidgetsWithLeakTracking('buildButtonItems builds a disabled "No Replacements Found" button when no suggestions', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController();
addTearDown(controller.dispose);
final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
await tester.pumpWidget( await tester.pumpWidget(
CupertinoApp( CupertinoApp(
home: _FakeEditableText(), home: _FakeEditableText(focusNode, controller),
), ),
); );
final _FakeEditableTextState editableTextState = final _FakeEditableTextState editableTextState =
...@@ -80,9 +85,11 @@ void main() { ...@@ -80,9 +85,11 @@ void main() {
} }
class _FakeEditableText extends EditableText { class _FakeEditableText extends EditableText {
_FakeEditableText() : super( /// The parameters focusNode and controller are needed here so the can be
controller: TextEditingController(), /// safely disposed after the test is completed.
focusNode: FocusNode(), _FakeEditableText(FocusNode focusNode, TextEditingController controller) : super(
controller: controller,
focusNode: focusNode,
backgroundCursorColor: CupertinoColors.white, backgroundCursorColor: CupertinoColors.white,
cursorColor: CupertinoColors.white, cursorColor: CupertinoColors.white,
style: const TextStyle(), style: const TextStyle(),
......
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