Skip to content

Commit 1437aa2

Browse files
authored
Cover some cupertino tests with leak tracking (#135230)
1 parent 397da06 commit 1437aa2

8 files changed

Lines changed: 263 additions & 200 deletions

packages/flutter/test/cupertino/dialog_test.dart

Lines changed: 53 additions & 38 deletions
Large diffs are not rendered by default.

packages/flutter/test/cupertino/magnifier_test.dart

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ library;
88
import 'package:flutter/cupertino.dart';
99
import 'package:flutter/material.dart';
1010
import 'package:flutter_test/flutter_test.dart';
11+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
1112

1213
void main() {
1314
final Offset basicOffset = Offset(CupertinoMagnifier.kDefaultSize.width / 2,
@@ -48,7 +49,7 @@ void main() {
4849
animatedPositioned.left ?? 0, animatedPositioned.top ?? 0);
4950
}
5051

51-
testWidgets('should be at gesture position if does not violate any positioning rules', (WidgetTester tester) async {
52+
testWidgetsWithLeakTracking('should be at gesture position if does not violate any positioning rules', (WidgetTester tester) async {
5253
final Key fakeTextFieldKey = UniqueKey();
5354
final Key outerKey = UniqueKey();
5455

@@ -87,6 +88,7 @@ void main() {
8788
globalGesturePosition: fakeTextFieldRect.center,
8889
),
8990
);
91+
addTearDown(magnifier.dispose);
9092

9193
await showCupertinoMagnifier(context, tester, magnifier);
9294

@@ -98,7 +100,7 @@ void main() {
98100
);
99101
});
100102

101-
testWidgets('should never horizontally be outside of Screen Padding', (WidgetTester tester) async {
103+
testWidgetsWithLeakTracking('should never horizontally be outside of Screen Padding', (WidgetTester tester) async {
102104
await tester.pumpWidget(
103105
const MaterialApp(
104106
color: Color.fromARGB(7, 0, 129, 90),
@@ -108,27 +110,29 @@ void main() {
108110

109111
final BuildContext context = tester.firstElement(find.byType(Placeholder));
110112

113+
final ValueNotifier<MagnifierInfo> magnifierInfo = ValueNotifier<MagnifierInfo>(
114+
MagnifierInfo(
115+
currentLineBoundaries: reasonableTextField,
116+
fieldBounds: reasonableTextField,
117+
caretRect: reasonableTextField,
118+
// The tap position is far out of the right side of the app.
119+
globalGesturePosition:
120+
Offset(MediaQuery.sizeOf(context).width + 100, 0),
121+
),
122+
);
123+
addTearDown(magnifierInfo.dispose);
111124
await showCupertinoMagnifier(
112125
context,
113126
tester,
114-
ValueNotifier<MagnifierInfo>(
115-
MagnifierInfo(
116-
currentLineBoundaries: reasonableTextField,
117-
fieldBounds: reasonableTextField,
118-
caretRect: reasonableTextField,
119-
// The tap position is far out of the right side of the app.
120-
globalGesturePosition:
121-
Offset(MediaQuery.sizeOf(context).width + 100, 0),
122-
),
123-
),
127+
magnifierInfo,
124128
);
125129

126130
// Should be less than the right edge, since we have padding.
127131
expect(getMagnifierPosition(tester).dx,
128132
lessThan(MediaQuery.sizeOf(context).width));
129133
});
130134

131-
testWidgets('should have some vertical drag', (WidgetTester tester) async {
135+
testWidgetsWithLeakTracking('should have some vertical drag', (WidgetTester tester) async {
132136
final double dragPositionBelowTextField = reasonableTextField.center.dy + 30;
133137

134138
await tester.pumpWidget(
@@ -141,20 +145,23 @@ void main() {
141145
final BuildContext context =
142146
tester.firstElement(find.byType(Placeholder));
143147

148+
final ValueNotifier<MagnifierInfo> magnifierInfo =
149+
ValueNotifier<MagnifierInfo>(
150+
MagnifierInfo(
151+
currentLineBoundaries: reasonableTextField,
152+
fieldBounds: reasonableTextField,
153+
caretRect: reasonableTextField,
154+
// The tap position is dragBelow units below the text field.
155+
globalGesturePosition: Offset(
156+
MediaQuery.sizeOf(context).width / 2,
157+
dragPositionBelowTextField),
158+
),
159+
);
160+
addTearDown(magnifierInfo.dispose);
144161
await showCupertinoMagnifier(
145162
context,
146163
tester,
147-
ValueNotifier<MagnifierInfo>(
148-
MagnifierInfo(
149-
currentLineBoundaries: reasonableTextField,
150-
fieldBounds: reasonableTextField,
151-
caretRect: reasonableTextField,
152-
// The tap position is dragBelow units below the text field.
153-
globalGesturePosition: Offset(
154-
MediaQuery.sizeOf(context).width / 2,
155-
dragPositionBelowTextField),
156-
),
157-
),
164+
magnifierInfo,
158165
);
159166

160167
// The magnifier Y should be greater than the text field, since we "dragged" it down.
@@ -166,7 +173,7 @@ void main() {
166173
});
167174

168175
group('status', () {
169-
testWidgets('should hide if gesture is far below the text field', (WidgetTester tester) async {
176+
testWidgetsWithLeakTracking('should hide if gesture is far below the text field', (WidgetTester tester) async {
170177
await tester.pumpWidget(
171178
const MaterialApp(
172179
color: Color.fromARGB(7, 0, 129, 90),
@@ -177,7 +184,7 @@ void main() {
177184
final BuildContext context =
178185
tester.firstElement(find.byType(Placeholder));
179186

180-
final ValueNotifier<MagnifierInfo> magnifierinfo =
187+
final ValueNotifier<MagnifierInfo> magnifierInfo =
181188
ValueNotifier<MagnifierInfo>(
182189
MagnifierInfo(
183190
currentLineBoundaries: reasonableTextField,
@@ -188,24 +195,25 @@ void main() {
188195
MediaQuery.sizeOf(context).width / 2, reasonableTextField.top),
189196
),
190197
);
198+
addTearDown(magnifierInfo.dispose);
191199

192200
// Show the magnifier initially, so that we get it in a not hidden state.
193-
await showCupertinoMagnifier(context, tester, magnifierinfo);
201+
await showCupertinoMagnifier(context, tester, magnifierInfo);
194202

195203
// Move the gesture to one that should hide it.
196-
magnifierinfo.value = MagnifierInfo(
204+
magnifierInfo.value = MagnifierInfo(
197205
currentLineBoundaries: reasonableTextField,
198206
fieldBounds: reasonableTextField,
199207
caretRect: reasonableTextField,
200-
globalGesturePosition: magnifierinfo.value.globalGesturePosition + const Offset(0, 100),
208+
globalGesturePosition: magnifierInfo.value.globalGesturePosition + const Offset(0, 100),
201209
);
202210
await tester.pumpAndSettle();
203211

204212
expect(magnifierController.shown, false);
205213
expect(magnifierController.overlayEntry, isNotNull);
206214
});
207215

208-
testWidgets('should re-show if gesture moves back up',
216+
testWidgetsWithLeakTracking('should re-show if gesture moves back up',
209217
(WidgetTester tester) async {
210218
await tester.pumpWidget(
211219
const MaterialApp(
@@ -227,6 +235,7 @@ void main() {
227235
globalGesturePosition: Offset(MediaQuery.sizeOf(context).width / 2, reasonableTextField.top),
228236
),
229237
);
238+
addTearDown(magnifierInfo.dispose);
230239

231240
// Show the magnifier initially, so that we get it in a not hidden state.
232241
await showCupertinoMagnifier(context, tester, magnifierInfo);

0 commit comments

Comments
 (0)