Unverified Commit 2e5569eb authored by Mouad Debbar's avatar Mouad Debbar Committed by GitHub

[web] Enable Cupertino text field tests on web (#79817)

parent 98a9195d
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
@TestOn('!chrome')
import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle, Color; import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle, Color;
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
...@@ -15,6 +14,9 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -15,6 +14,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart'; import '../rendering/mock_canvas.dart';
import '../widgets/semantics_tester.dart'; import '../widgets/semantics_tester.dart';
// On web, the context menu (aka toolbar) is provided by the browser.
final bool isContextMenuProvidedByPlatform = isBrowser;
class MockClipboard { class MockClipboard {
Object _clipboardData = <String, dynamic>{ Object _clipboardData = <String, dynamic>{
'text': null, 'text': null,
...@@ -332,7 +334,7 @@ void main() { ...@@ -332,7 +334,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(focusNode.hasFocus, isTrue); expect(focusNode.hasFocus, isTrue);
semantics.dispose(); semantics.dispose();
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.macOS }), skip: kIsWeb); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.macOS }));
testWidgets( testWidgets(
'takes available space horizontally and takes intrinsic space vertically no-strut', 'takes available space horizontally and takes intrinsic space vertically no-strut',
...@@ -446,6 +448,9 @@ void main() { ...@@ -446,6 +448,9 @@ void main() {
const Size(200, 36), const Size(200, 36),
); );
}, },
// TODO(mdebbar): Strut styles support.
// https://github.com/flutter/flutter/issues/32243
skip: isBrowser,
); );
testWidgets( testWidgets(
...@@ -474,6 +479,9 @@ void main() { ...@@ -474,6 +479,9 @@ void main() {
const Size(200, 66), const Size(200, 66),
); );
}, },
// TODO(mdebbar): Strut styles support.
// https://github.com/flutter/flutter/issues/32243
skip: isBrowser,
); );
testWidgets( testWidgets(
...@@ -1476,8 +1484,7 @@ void main() { ...@@ -1476,8 +1484,7 @@ void main() {
expect(text.style!.fontSize, 14); expect(text.style!.fontSize, 14);
expect(text.style!.letterSpacing, -0.15); expect(text.style!.letterSpacing, -0.15);
expect(text.style!.fontWeight, FontWeight.w400); expect(text.style!.fontWeight, FontWeight.w400);
}); }, skip: isContextMenuProvidedByPlatform);
testWidgets('text field toolbar options correctly changes options', (WidgetTester tester) async { testWidgets('text field toolbar options correctly changes options', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
...@@ -1520,7 +1527,8 @@ void main() { ...@@ -1520,7 +1527,8 @@ void main() {
expect(find.text('Copy'), findsOneWidget); expect(find.text('Copy'), findsOneWidget);
expect(find.text('Cut'), findsNothing); expect(find.text('Cut'), findsNothing);
expect(find.text('Select All'), findsNothing); expect(find.text('Select All'), findsNothing);
}); }, skip: isContextMenuProvidedByPlatform);
testWidgets('Read only text field', (WidgetTester tester) async { testWidgets('Read only text field', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController(text: 'readonly'); final TextEditingController controller = TextEditingController(text: 'readonly');
...@@ -1556,7 +1564,7 @@ void main() { ...@@ -1556,7 +1564,7 @@ void main() {
expect(find.text('Copy'), findsOneWidget); expect(find.text('Copy'), findsOneWidget);
expect(find.text('Paste'), findsNothing); expect(find.text('Paste'), findsNothing);
expect(find.text('Cut'), findsNothing); expect(find.text('Cut'), findsNothing);
}); }, skip: isContextMenuProvidedByPlatform);
testWidgets('copy paste', (WidgetTester tester) async { testWidgets('copy paste', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
...@@ -1607,7 +1615,7 @@ void main() { ...@@ -1607,7 +1615,7 @@ void main() {
expect(find.text('field 1'), findsOneWidget); expect(find.text('field 1'), findsOneWidget);
expect(find.text("j'aime la poutine"), findsOneWidget); expect(find.text("j'aime la poutine"), findsOneWidget);
expect(find.text('field 2'), findsNothing); expect(find.text('field 2'), findsNothing);
}); }, skip: isContextMenuProvidedByPlatform);
testWidgets( testWidgets(
'tap moves cursor to the edge of the word it tapped on', 'tap moves cursor to the edge of the word it tapped on',
...@@ -1711,7 +1719,7 @@ void main() { ...@@ -1711,7 +1719,7 @@ void main() {
); );
// Selected text shows 3 toolbar buttons. // Selected text shows 3 toolbar buttons.
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
}, },
); );
...@@ -1772,7 +1780,7 @@ void main() { ...@@ -1772,7 +1780,7 @@ void main() {
); );
// Selected text shows 3 toolbar buttons. // Selected text shows 3 toolbar buttons.
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
}, },
); );
...@@ -1807,7 +1815,7 @@ void main() { ...@@ -1807,7 +1815,7 @@ void main() {
); );
// Selected text shows 3 toolbar buttons. // Selected text shows 3 toolbar buttons.
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
await gesture.up(); await gesture.up();
await tester.pump(); await tester.pump();
...@@ -1817,7 +1825,7 @@ void main() { ...@@ -1817,7 +1825,7 @@ void main() {
controller.selection, controller.selection,
const TextSelection(baseOffset: 8, extentOffset: 12), const TextSelection(baseOffset: 8, extentOffset: 12),
); );
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
}, },
); );
...@@ -2135,7 +2143,7 @@ void main() { ...@@ -2135,7 +2143,7 @@ void main() {
); );
// Selected text shows paste toolbar buttons. // Selected text shows paste toolbar buttons.
expect(find.byType(CupertinoButton), findsNWidgets(1)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(1));
await gesture.up(); await gesture.up();
await tester.pump(); await tester.pump();
...@@ -2145,7 +2153,7 @@ void main() { ...@@ -2145,7 +2153,7 @@ void main() {
controller.selection, controller.selection,
const TextSelection(baseOffset: 0, extentOffset: 35), const TextSelection(baseOffset: 0, extentOffset: 35),
); );
expect(find.byType(CupertinoButton), findsNWidgets(1)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(1));
}, },
); );
...@@ -2191,7 +2199,7 @@ void main() { ...@@ -2191,7 +2199,7 @@ void main() {
expect(find.text('Select All'), findsOneWidget); expect(find.text('Select All'), findsOneWidget);
expect(find.text('Copy'), findsNothing); expect(find.text('Copy'), findsNothing);
expect(find.text('Cut'), findsNothing); expect(find.text('Cut'), findsNothing);
}); }, skip: isContextMenuProvidedByPlatform);
testWidgets( testWidgets(
'long press moves cursor to the exact long press position and shows toolbar', 'long press moves cursor to the exact long press position and shows toolbar',
...@@ -2221,7 +2229,7 @@ void main() { ...@@ -2221,7 +2229,7 @@ void main() {
); );
// Collapsed toolbar shows 2 buttons. // Collapsed toolbar shows 2 buttons.
expect(find.byType(CupertinoButton), findsNWidgets(2)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(2));
}, },
); );
...@@ -2320,7 +2328,7 @@ void main() { ...@@ -2320,7 +2328,7 @@ void main() {
const TextSelection.collapsed(offset: 9, affinity: TextAffinity.upstream), const TextSelection.collapsed(offset: 9, affinity: TextAffinity.upstream),
); );
// The toolbar now shows up. // The toolbar now shows up.
expect(find.byType(CupertinoButton), findsNWidgets(2)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(2));
}, },
); );
...@@ -2350,7 +2358,7 @@ void main() { ...@@ -2350,7 +2358,7 @@ void main() {
expect(lastCharEndpoint.length, 1); expect(lastCharEndpoint.length, 1);
// Just testing the test and making sure that the last character is off // Just testing the test and making sure that the last character is off
// the right side of the screen. // the right side of the screen.
expect(lastCharEndpoint[0].point.dx, moreOrLessEquals(1094.73, epsilon: 0.01)); expect(lastCharEndpoint[0].point.dx, moreOrLessEquals(1094.73, epsilon: 0.25));
final Offset textfieldStart = tester.getTopLeft(find.byType(CupertinoTextField)); final Offset textfieldStart = tester.getTopLeft(find.byType(CupertinoTextField));
...@@ -2395,7 +2403,7 @@ void main() { ...@@ -2395,7 +2403,7 @@ void main() {
const TextSelection.collapsed(offset: 66, affinity: TextAffinity.upstream), const TextSelection.collapsed(offset: 66, affinity: TextAffinity.upstream),
); );
// The toolbar now shows up. // The toolbar now shows up.
expect(find.byType(CupertinoButton), findsNWidgets(2)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(2));
lastCharEndpoint = renderEditable.getEndpointsForSelection( lastCharEndpoint = renderEditable.getEndpointsForSelection(
const TextSelection.collapsed(offset: 66), // Last character's position. const TextSelection.collapsed(offset: 66), // Last character's position.
...@@ -2403,14 +2411,14 @@ void main() { ...@@ -2403,14 +2411,14 @@ void main() {
expect(lastCharEndpoint.length, 1); expect(lastCharEndpoint.length, 1);
// The last character is now on screen. // The last character is now on screen.
expect(lastCharEndpoint[0].point.dx, moreOrLessEquals(786.73, epsilon: 0.01)); expect(lastCharEndpoint[0].point.dx, moreOrLessEquals(786.73, epsilon: 0.25));
final List<TextSelectionPoint> firstCharEndpoint = renderEditable.getEndpointsForSelection( final List<TextSelectionPoint> firstCharEndpoint = renderEditable.getEndpointsForSelection(
const TextSelection.collapsed(offset: 0), // First character's position. const TextSelection.collapsed(offset: 0), // First character's position.
); );
expect(firstCharEndpoint.length, 1); expect(firstCharEndpoint.length, 1);
// The first character is now offscreen to the left. // The first character is now offscreen to the left.
expect(firstCharEndpoint[0].point.dx, moreOrLessEquals(-308.20, epsilon: 0.01)); expect(firstCharEndpoint[0].point.dx, moreOrLessEquals(-308.20, epsilon: 0.25));
}); });
testWidgets( testWidgets(
...@@ -2451,7 +2459,7 @@ void main() { ...@@ -2451,7 +2459,7 @@ void main() {
); );
// Long press toolbar. // Long press toolbar.
expect(find.byType(CupertinoButton), findsNWidgets(2)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(2));
}, },
); );
...@@ -2492,7 +2500,7 @@ void main() { ...@@ -2492,7 +2500,7 @@ void main() {
const TextSelection(baseOffset: 8, extentOffset: 12), const TextSelection(baseOffset: 8, extentOffset: 12),
); );
// Shows toolbar. // Shows toolbar.
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
}, },
); );
...@@ -2526,7 +2534,7 @@ void main() { ...@@ -2526,7 +2534,7 @@ void main() {
controller.selection, controller.selection,
const TextSelection(baseOffset: 0, extentOffset: 7), const TextSelection(baseOffset: 0, extentOffset: 7),
); );
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
// Double tap selecting the same word somewhere else is fine. // Double tap selecting the same word somewhere else is fine.
await tester.tapAt(textfieldStart + const Offset(100.0, 5.0)); await tester.tapAt(textfieldStart + const Offset(100.0, 5.0));
...@@ -2542,7 +2550,7 @@ void main() { ...@@ -2542,7 +2550,7 @@ void main() {
controller.selection, controller.selection,
const TextSelection(baseOffset: 0, extentOffset: 7), const TextSelection(baseOffset: 0, extentOffset: 7),
); );
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
await tester.tapAt(textfieldStart + const Offset(150.0, 5.0)); await tester.tapAt(textfieldStart + const Offset(150.0, 5.0));
await tester.pump(const Duration(milliseconds: 50)); await tester.pump(const Duration(milliseconds: 50));
...@@ -2557,7 +2565,7 @@ void main() { ...@@ -2557,7 +2565,7 @@ void main() {
controller.selection, controller.selection,
const TextSelection(baseOffset: 8, extentOffset: 12), const TextSelection(baseOffset: 8, extentOffset: 12),
); );
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
}, },
); );
...@@ -2598,7 +2606,7 @@ void main() { ...@@ -2598,7 +2606,7 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// Shows toolbar. // Shows toolbar.
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(3));
}); });
testWidgets('force press on unsupported devices falls back to tap', (WidgetTester tester) async { testWidgets('force press on unsupported devices falls back to tap', (WidgetTester tester) async {
...@@ -2842,7 +2850,7 @@ void main() { ...@@ -2842,7 +2850,7 @@ void main() {
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay!.handlesAreVisible, isFalse); expect(editableText.selectionOverlay!.handlesAreVisible, isFalse);
expect(editableText.selectionOverlay!.toolbarIsVisible, isTrue); expect(editableText.selectionOverlay!.toolbarIsVisible, isContextMenuProvidedByPlatform ? isFalse : isTrue);
}); });
testWidgets( testWidgets(
...@@ -2870,7 +2878,7 @@ void main() { ...@@ -2870,7 +2878,7 @@ void main() {
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay!.handlesAreVisible, isTrue); expect(editableText.selectionOverlay!.handlesAreVisible, isTrue);
expect(editableText.selectionOverlay!.toolbarIsVisible, isTrue); expect(editableText.selectionOverlay!.toolbarIsVisible, isContextMenuProvidedByPlatform ? isFalse : isTrue);
}, },
); );
...@@ -2899,7 +2907,7 @@ void main() { ...@@ -2899,7 +2907,7 @@ void main() {
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay!.handlesAreVisible, isFalse); expect(editableText.selectionOverlay!.handlesAreVisible, isFalse);
expect(editableText.selectionOverlay!.toolbarIsVisible, isTrue); expect(editableText.selectionOverlay!.toolbarIsVisible, isContextMenuProvidedByPlatform ? isFalse : isTrue);
}, },
); );
...@@ -3214,6 +3222,7 @@ void main() { ...@@ -3214,6 +3222,7 @@ void main() {
textFieldTopLeft = tester.getTopLeft(find.byType(CupertinoTextField)); textFieldTopLeft = tester.getTopLeft(find.byType(CupertinoTextField));
expect(toolbarTopLeft.dy, lessThan(textFieldTopLeft.dy)); expect(toolbarTopLeft.dy, lessThan(textFieldTopLeft.dy));
}, },
skip: isContextMenuProvidedByPlatform,
); );
testWidgets('text field respects keyboardAppearance from theme', (WidgetTester tester) async { testWidgets('text field respects keyboardAppearance from theme', (WidgetTester tester) async {
...@@ -3810,7 +3819,7 @@ void main() { ...@@ -3810,7 +3819,7 @@ void main() {
expect(find.byType(CupertinoTextSelectionToolbar), findsOneWidget); expect(find.byType(CupertinoTextSelectionToolbar), findsOneWidget);
expect(tester.takeException(), null); expect(tester.takeException(), null);
}); });
}); }, skip: isContextMenuProvidedByPlatform);
group('textAlignVertical position', () { group('textAlignVertical position', () {
group('simple case', () { group('simple case', () {
...@@ -4243,7 +4252,7 @@ void main() { ...@@ -4243,7 +4252,7 @@ void main() {
// Long press shows the selection menu. // Long press shows the selection menu.
await tester.longPressAt(textOffsetToPosition(tester, 0)); await tester.longPressAt(textOffsetToPosition(tester, 0));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('Paste'), findsOneWidget); expect(find.text('Paste'), isContextMenuProvidedByPlatform ? findsNothing : findsOneWidget);
}, },
); );
}); });
......
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