Skip to content

Commit 2e5569e

Browse files
authored
[web] Enable Cupertino text field tests on web (flutter#79817)
1 parent 98a9195 commit 2e5569e

1 file changed

Lines changed: 40 additions & 31 deletions

File tree

packages/flutter/test/cupertino/text_field_test.dart

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
@TestOn('!chrome')
65
import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle, Color;
76

87
import 'package:flutter/cupertino.dart';
@@ -15,6 +14,9 @@ import 'package:flutter_test/flutter_test.dart';
1514
import '../rendering/mock_canvas.dart';
1615
import '../widgets/semantics_tester.dart';
1716

17+
// On web, the context menu (aka toolbar) is provided by the browser.
18+
final bool isContextMenuProvidedByPlatform = isBrowser;
19+
1820
class MockClipboard {
1921
Object _clipboardData = <String, dynamic>{
2022
'text': null,
@@ -332,7 +334,7 @@ void main() {
332334
await tester.pumpAndSettle();
333335
expect(focusNode.hasFocus, isTrue);
334336
semantics.dispose();
335-
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.macOS }), skip: kIsWeb);
337+
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.macOS }));
336338

337339
testWidgets(
338340
'takes available space horizontally and takes intrinsic space vertically no-strut',
@@ -446,6 +448,9 @@ void main() {
446448
const Size(200, 36),
447449
);
448450
},
451+
// TODO(mdebbar): Strut styles support.
452+
// https://github.com/flutter/flutter/issues/32243
453+
skip: isBrowser,
449454
);
450455

451456
testWidgets(
@@ -474,6 +479,9 @@ void main() {
474479
const Size(200, 66),
475480
);
476481
},
482+
// TODO(mdebbar): Strut styles support.
483+
// https://github.com/flutter/flutter/issues/32243
484+
skip: isBrowser,
477485
);
478486

479487
testWidgets(
@@ -1476,8 +1484,7 @@ void main() {
14761484
expect(text.style!.fontSize, 14);
14771485
expect(text.style!.letterSpacing, -0.15);
14781486
expect(text.style!.fontWeight, FontWeight.w400);
1479-
});
1480-
1487+
}, skip: isContextMenuProvidedByPlatform);
14811488

14821489
testWidgets('text field toolbar options correctly changes options', (WidgetTester tester) async {
14831490
final TextEditingController controller = TextEditingController(
@@ -1520,7 +1527,8 @@ void main() {
15201527
expect(find.text('Copy'), findsOneWidget);
15211528
expect(find.text('Cut'), findsNothing);
15221529
expect(find.text('Select All'), findsNothing);
1523-
});
1530+
}, skip: isContextMenuProvidedByPlatform);
1531+
15241532
testWidgets('Read only text field', (WidgetTester tester) async {
15251533
final TextEditingController controller = TextEditingController(text: 'readonly');
15261534

@@ -1556,7 +1564,7 @@ void main() {
15561564
expect(find.text('Copy'), findsOneWidget);
15571565
expect(find.text('Paste'), findsNothing);
15581566
expect(find.text('Cut'), findsNothing);
1559-
});
1567+
}, skip: isContextMenuProvidedByPlatform);
15601568

15611569
testWidgets('copy paste', (WidgetTester tester) async {
15621570
await tester.pumpWidget(
@@ -1607,7 +1615,7 @@ void main() {
16071615
expect(find.text('field 1'), findsOneWidget);
16081616
expect(find.text("j'aime la poutine"), findsOneWidget);
16091617
expect(find.text('field 2'), findsNothing);
1610-
});
1618+
}, skip: isContextMenuProvidedByPlatform);
16111619

16121620
testWidgets(
16131621
'tap moves cursor to the edge of the word it tapped on',
@@ -1711,7 +1719,7 @@ void main() {
17111719
);
17121720

17131721
// Selected text shows 3 toolbar buttons.
1714-
expect(find.byType(CupertinoButton), findsNWidgets(3));
1722+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
17151723
},
17161724
);
17171725

@@ -1772,7 +1780,7 @@ void main() {
17721780
);
17731781

17741782
// Selected text shows 3 toolbar buttons.
1775-
expect(find.byType(CupertinoButton), findsNWidgets(3));
1783+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
17761784
},
17771785
);
17781786

@@ -1807,7 +1815,7 @@ void main() {
18071815
);
18081816

18091817
// Selected text shows 3 toolbar buttons.
1810-
expect(find.byType(CupertinoButton), findsNWidgets(3));
1818+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
18111819

18121820
await gesture.up();
18131821
await tester.pump();
@@ -1817,7 +1825,7 @@ void main() {
18171825
controller.selection,
18181826
const TextSelection(baseOffset: 8, extentOffset: 12),
18191827
);
1820-
expect(find.byType(CupertinoButton), findsNWidgets(3));
1828+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
18211829
},
18221830
);
18231831

@@ -2135,7 +2143,7 @@ void main() {
21352143
);
21362144

21372145
// Selected text shows paste toolbar buttons.
2138-
expect(find.byType(CupertinoButton), findsNWidgets(1));
2146+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(1));
21392147

21402148
await gesture.up();
21412149
await tester.pump();
@@ -2145,7 +2153,7 @@ void main() {
21452153
controller.selection,
21462154
const TextSelection(baseOffset: 0, extentOffset: 35),
21472155
);
2148-
expect(find.byType(CupertinoButton), findsNWidgets(1));
2156+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(1));
21492157
},
21502158
);
21512159

@@ -2191,7 +2199,7 @@ void main() {
21912199
expect(find.text('Select All'), findsOneWidget);
21922200
expect(find.text('Copy'), findsNothing);
21932201
expect(find.text('Cut'), findsNothing);
2194-
});
2202+
}, skip: isContextMenuProvidedByPlatform);
21952203

21962204
testWidgets(
21972205
'long press moves cursor to the exact long press position and shows toolbar',
@@ -2221,7 +2229,7 @@ void main() {
22212229
);
22222230

22232231
// Collapsed toolbar shows 2 buttons.
2224-
expect(find.byType(CupertinoButton), findsNWidgets(2));
2232+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(2));
22252233
},
22262234
);
22272235

@@ -2320,7 +2328,7 @@ void main() {
23202328
const TextSelection.collapsed(offset: 9, affinity: TextAffinity.upstream),
23212329
);
23222330
// The toolbar now shows up.
2323-
expect(find.byType(CupertinoButton), findsNWidgets(2));
2331+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(2));
23242332
},
23252333
);
23262334

@@ -2350,7 +2358,7 @@ void main() {
23502358
expect(lastCharEndpoint.length, 1);
23512359
// Just testing the test and making sure that the last character is off
23522360
// the right side of the screen.
2353-
expect(lastCharEndpoint[0].point.dx, moreOrLessEquals(1094.73, epsilon: 0.01));
2361+
expect(lastCharEndpoint[0].point.dx, moreOrLessEquals(1094.73, epsilon: 0.25));
23542362

23552363
final Offset textfieldStart = tester.getTopLeft(find.byType(CupertinoTextField));
23562364

@@ -2395,22 +2403,22 @@ void main() {
23952403
const TextSelection.collapsed(offset: 66, affinity: TextAffinity.upstream),
23962404
);
23972405
// The toolbar now shows up.
2398-
expect(find.byType(CupertinoButton), findsNWidgets(2));
2406+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(2));
23992407

24002408
lastCharEndpoint = renderEditable.getEndpointsForSelection(
24012409
const TextSelection.collapsed(offset: 66), // Last character's position.
24022410
);
24032411

24042412
expect(lastCharEndpoint.length, 1);
24052413
// The last character is now on screen.
2406-
expect(lastCharEndpoint[0].point.dx, moreOrLessEquals(786.73, epsilon: 0.01));
2414+
expect(lastCharEndpoint[0].point.dx, moreOrLessEquals(786.73, epsilon: 0.25));
24072415

24082416
final List<TextSelectionPoint> firstCharEndpoint = renderEditable.getEndpointsForSelection(
24092417
const TextSelection.collapsed(offset: 0), // First character's position.
24102418
);
24112419
expect(firstCharEndpoint.length, 1);
24122420
// The first character is now offscreen to the left.
2413-
expect(firstCharEndpoint[0].point.dx, moreOrLessEquals(-308.20, epsilon: 0.01));
2421+
expect(firstCharEndpoint[0].point.dx, moreOrLessEquals(-308.20, epsilon: 0.25));
24142422
});
24152423

24162424
testWidgets(
@@ -2451,7 +2459,7 @@ void main() {
24512459
);
24522460

24532461
// Long press toolbar.
2454-
expect(find.byType(CupertinoButton), findsNWidgets(2));
2462+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(2));
24552463
},
24562464
);
24572465

@@ -2492,7 +2500,7 @@ void main() {
24922500
const TextSelection(baseOffset: 8, extentOffset: 12),
24932501
);
24942502
// Shows toolbar.
2495-
expect(find.byType(CupertinoButton), findsNWidgets(3));
2503+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
24962504
},
24972505
);
24982506

@@ -2526,7 +2534,7 @@ void main() {
25262534
controller.selection,
25272535
const TextSelection(baseOffset: 0, extentOffset: 7),
25282536
);
2529-
expect(find.byType(CupertinoButton), findsNWidgets(3));
2537+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
25302538

25312539
// Double tap selecting the same word somewhere else is fine.
25322540
await tester.tapAt(textfieldStart + const Offset(100.0, 5.0));
@@ -2542,7 +2550,7 @@ void main() {
25422550
controller.selection,
25432551
const TextSelection(baseOffset: 0, extentOffset: 7),
25442552
);
2545-
expect(find.byType(CupertinoButton), findsNWidgets(3));
2553+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
25462554

25472555
await tester.tapAt(textfieldStart + const Offset(150.0, 5.0));
25482556
await tester.pump(const Duration(milliseconds: 50));
@@ -2557,7 +2565,7 @@ void main() {
25572565
controller.selection,
25582566
const TextSelection(baseOffset: 8, extentOffset: 12),
25592567
);
2560-
expect(find.byType(CupertinoButton), findsNWidgets(3));
2568+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
25612569
},
25622570
);
25632571

@@ -2598,7 +2606,7 @@ void main() {
25982606
await gesture.up();
25992607
await tester.pumpAndSettle();
26002608
// Shows toolbar.
2601-
expect(find.byType(CupertinoButton), findsNWidgets(3));
2609+
expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
26022610
});
26032611

26042612
testWidgets('force press on unsupported devices falls back to tap', (WidgetTester tester) async {
@@ -2842,7 +2850,7 @@ void main() {
28422850

28432851
final EditableTextState editableText = tester.state(find.byType(EditableText));
28442852
expect(editableText.selectionOverlay!.handlesAreVisible, isFalse);
2845-
expect(editableText.selectionOverlay!.toolbarIsVisible, isTrue);
2853+
expect(editableText.selectionOverlay!.toolbarIsVisible, isContextMenuProvidedByPlatform ? isFalse : isTrue);
28462854
});
28472855

28482856
testWidgets(
@@ -2870,7 +2878,7 @@ void main() {
28702878

28712879
final EditableTextState editableText = tester.state(find.byType(EditableText));
28722880
expect(editableText.selectionOverlay!.handlesAreVisible, isTrue);
2873-
expect(editableText.selectionOverlay!.toolbarIsVisible, isTrue);
2881+
expect(editableText.selectionOverlay!.toolbarIsVisible, isContextMenuProvidedByPlatform ? isFalse : isTrue);
28742882
},
28752883
);
28762884

@@ -2899,7 +2907,7 @@ void main() {
28992907

29002908
final EditableTextState editableText = tester.state(find.byType(EditableText));
29012909
expect(editableText.selectionOverlay!.handlesAreVisible, isFalse);
2902-
expect(editableText.selectionOverlay!.toolbarIsVisible, isTrue);
2910+
expect(editableText.selectionOverlay!.toolbarIsVisible, isContextMenuProvidedByPlatform ? isFalse : isTrue);
29032911
},
29042912
);
29052913

@@ -3214,6 +3222,7 @@ void main() {
32143222
textFieldTopLeft = tester.getTopLeft(find.byType(CupertinoTextField));
32153223
expect(toolbarTopLeft.dy, lessThan(textFieldTopLeft.dy));
32163224
},
3225+
skip: isContextMenuProvidedByPlatform,
32173226
);
32183227

32193228
testWidgets('text field respects keyboardAppearance from theme', (WidgetTester tester) async {
@@ -3810,7 +3819,7 @@ void main() {
38103819
expect(find.byType(CupertinoTextSelectionToolbar), findsOneWidget);
38113820
expect(tester.takeException(), null);
38123821
});
3813-
});
3822+
}, skip: isContextMenuProvidedByPlatform);
38143823

38153824
group('textAlignVertical position', () {
38163825
group('simple case', () {
@@ -4243,7 +4252,7 @@ void main() {
42434252
// Long press shows the selection menu.
42444253
await tester.longPressAt(textOffsetToPosition(tester, 0));
42454254
await tester.pumpAndSettle();
4246-
expect(find.text('Paste'), findsOneWidget);
4255+
expect(find.text('Paste'), isContextMenuProvidedByPlatform ? findsNothing : findsOneWidget);
42474256
},
42484257
);
42494258
});

0 commit comments

Comments
 (0)