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;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
final Offset basicOffset = Offset(CupertinoMagnifier.kDefaultSize.width / 2,
......@@ -48,7 +49,7 @@ void main() {
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 outerKey = UniqueKey();
......@@ -87,6 +88,7 @@ void main() {
globalGesturePosition: fakeTextFieldRect.center,
),
);
addTearDown(magnifier.dispose);
await showCupertinoMagnifier(context, tester, magnifier);
......@@ -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(
const MaterialApp(
color: Color.fromARGB(7, 0, 129, 90),
......@@ -108,19 +110,21 @@ void main() {
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(
context,
tester,
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),
),
),
magnifierInfo,
);
// Should be less than the right edge, since we have padding.
......@@ -128,7 +132,7 @@ void main() {
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;
await tester.pumpWidget(
......@@ -141,20 +145,23 @@ void main() {
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 dragBelow units below the text field.
globalGesturePosition: Offset(
MediaQuery.sizeOf(context).width / 2,
dragPositionBelowTextField),
),
);
addTearDown(magnifierInfo.dispose);
await showCupertinoMagnifier(
context,
tester,
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),
),
),
magnifierInfo,
);
// The magnifier Y should be greater than the text field, since we "dragged" it down.
......@@ -166,7 +173,7 @@ void main() {
});
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(
const MaterialApp(
color: Color.fromARGB(7, 0, 129, 90),
......@@ -177,7 +184,7 @@ void main() {
final BuildContext context =
tester.firstElement(find.byType(Placeholder));
final ValueNotifier<MagnifierInfo> magnifierinfo =
final ValueNotifier<MagnifierInfo> magnifierInfo =
ValueNotifier<MagnifierInfo>(
MagnifierInfo(
currentLineBoundaries: reasonableTextField,
......@@ -188,16 +195,17 @@ void main() {
MediaQuery.sizeOf(context).width / 2, reasonableTextField.top),
),
);
addTearDown(magnifierInfo.dispose);
// 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.
magnifierinfo.value = MagnifierInfo(
magnifierInfo.value = MagnifierInfo(
currentLineBoundaries: reasonableTextField,
fieldBounds: reasonableTextField,
caretRect: reasonableTextField,
globalGesturePosition: magnifierinfo.value.globalGesturePosition + const Offset(0, 100),
globalGesturePosition: magnifierInfo.value.globalGesturePosition + const Offset(0, 100),
);
await tester.pumpAndSettle();
......@@ -205,7 +213,7 @@ void main() {
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 {
await tester.pumpWidget(
const MaterialApp(
......@@ -227,6 +235,7 @@ void main() {
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.
await showCupertinoMagnifier(context, tester, magnifierInfo);
......
......@@ -7,11 +7,12 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import '../widgets/semantics_tester.dart';
void main() {
testWidgets('Radio control test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Radio control test', (WidgetTester tester) async {
final Key key = UniqueKey();
final List<int?> log = <int?>[];
......@@ -63,7 +64,7 @@ void main() {
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 List<int?> log = <int?>[];
......@@ -118,7 +119,7 @@ void main() {
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);
await tester.pumpWidget(CupertinoApp(
......@@ -153,7 +154,7 @@ void main() {
semantics.dispose();
}, variant: TargetPlatformVariant.all());
testWidgets('Radio semantics', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Radio semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(CupertinoApp(
......@@ -241,7 +242,7 @@ void main() {
semantics.dispose();
});
testWidgets('has semantic events', (WidgetTester tester) async {
testWidgetsWithLeakTracking('has semantic events', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
final Key key = UniqueKey();
dynamic semanticEvent;
......@@ -278,13 +279,14 @@ void main() {
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;
int? groupValue = 1;
const Key radioKey0 = Key('radio0');
const Key radioKey1 = Key('radio1');
const Key radioKey2 = Key('radio2');
final FocusNode focusNode2 = FocusNode(debugLabel: 'radio2');
addTearDown(focusNode2.dispose);
Widget buildApp({bool enabled = true}) {
return CupertinoApp(
home: Center(
......@@ -350,7 +352,7 @@ void main() {
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(
home: Center(
child: CupertinoRadio<int>(
......@@ -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();
Widget buildRadio(bool show) {
......
......@@ -7,11 +7,12 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
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 {
await tester.pumpWidget(
CupertinoApp(
......@@ -61,10 +62,14 @@ void main() {
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(
CupertinoApp(
home: _FakeEditableText(),
home: _FakeEditableText(focusNode, controller),
),
);
final _FakeEditableTextState editableTextState =
......@@ -80,9 +85,11 @@ void main() {
}
class _FakeEditableText extends EditableText {
_FakeEditableText() : super(
controller: TextEditingController(),
focusNode: FocusNode(),
/// The parameters focusNode and controller are needed here so the can be
/// safely disposed after the test is completed.
_FakeEditableText(FocusNode focusNode, TextEditingController controller) : super(
controller: controller,
focusNode: focusNode,
backgroundCursorColor: CupertinoColors.white,
cursorColor: CupertinoColors.white,
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