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