Unverified Commit 707f995d authored by Mouad Debbar's avatar Mouad Debbar Committed by GitHub

[web] Fix and enable editable_text_test.dart (#64516)

parent be7c7fae
...@@ -92,7 +92,6 @@ const List<String> kWebTestFileKnownFailures = <String>[ ...@@ -92,7 +92,6 @@ const List<String> kWebTestFileKnownFailures = <String>[
'test/widgets/selectable_text_test.dart', 'test/widgets/selectable_text_test.dart',
'test/widgets/color_filter_test.dart', 'test/widgets/color_filter_test.dart',
'test/widgets/editable_text_cursor_test.dart', 'test/widgets/editable_text_cursor_test.dart',
'test/widgets/editable_text_test.dart',
'test/material/animated_icons_private_test.dart', 'test/material/animated_icons_private_test.dart',
'test/material/data_table_test.dart', 'test/material/data_table_test.dart',
'test/cupertino/nav_bar_transition_test.dart', 'test/cupertino/nav_bar_transition_test.dart',
......
...@@ -1627,6 +1627,11 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -1627,6 +1627,11 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
if (!_shouldCreateInputConnection) { if (!_shouldCreateInputConnection) {
return; return;
} }
if (widget.readOnly) {
// In the read-only case, we only care about selection changes, and reject
// everything else.
value = _value.copyWith(selection: value.selection);
}
_receivedRemoteTextEditingValue = value; _receivedRemoteTextEditingValue = value;
if (value.text != _value.text) { if (value.text != _value.text) {
hideToolbar(); hideToolbar();
......
...@@ -300,7 +300,12 @@ void main() { ...@@ -300,7 +300,12 @@ void main() {
controller.text = 'test'; controller.text = 'test';
await tester.idle(); await tester.idle();
expect(tester.testTextInput.editingState['text'], equals('test')); expect(tester.testTextInput.editingState['text'], equals('test'));
expect(tester.testTextInput.setClientArgs['inputType']['name'], equals('TextInputType.name')); expect(
tester.testTextInput.setClientArgs['inputType']['name'],
// On web, we don't infer the keyboard type as "name". We only infer
// on iOS and macOS.
kIsWeb ? equals('TextInputType.address') : equals('TextInputType.name'),
);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('infer keyboard types from autofillHints: non-ios', testWidgets('infer keyboard types from autofillHints: non-ios',
...@@ -1106,9 +1111,10 @@ void main() { ...@@ -1106,9 +1111,10 @@ void main() {
cause: SelectionChangedCause.tap, cause: SelectionChangedCause.tap,
); );
await tester.pump(); await tester.pump();
expect(state.showToolbar(), true); // On web, we don't let Flutter show the toolbar.
expect(state.showToolbar(), kIsWeb ? isFalse : isTrue);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('Paste'), findsOneWidget); expect(find.text('Paste'), kIsWeb ? findsNothing : findsOneWidget);
// Hide the menu again. // Hide the menu again.
state.hideToolbar(); state.hideToolbar();
...@@ -1118,9 +1124,10 @@ void main() { ...@@ -1118,9 +1124,10 @@ void main() {
// Can show the menu with text and a selection. // Can show the menu with text and a selection.
controller.text = 'blah'; controller.text = 'blah';
await tester.pump(); await tester.pump();
expect(state.showToolbar(), true); // On web, we don't let Flutter show the toolbar.
expect(state.showToolbar(), kIsWeb ? isFalse : isTrue);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('Paste'), findsOneWidget); expect(find.text('Paste'), kIsWeb ? findsNothing : findsOneWidget);
}); });
testWidgets('can show the toolbar after clearing all text', (WidgetTester tester) async { testWidgets('can show the toolbar after clearing all text', (WidgetTester tester) async {
...@@ -1158,9 +1165,10 @@ void main() { ...@@ -1158,9 +1165,10 @@ void main() {
await tester.pump(); await tester.pump();
// Should be able to show the toolbar. // Should be able to show the toolbar.
expect(state.showToolbar(), true); // On web, we don't let Flutter show the toolbar.
expect(state.showToolbar(), kIsWeb ? isFalse : isTrue);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('Paste'), findsOneWidget); expect(find.text('Paste'), kIsWeb ? findsNothing : findsOneWidget);
}); });
testWidgets('can dynamically disable options in toolbar', (WidgetTester tester) async { testWidgets('can dynamically disable options in toolbar', (WidgetTester tester) async {
...@@ -1190,10 +1198,11 @@ void main() { ...@@ -1190,10 +1198,11 @@ void main() {
cause: SelectionChangedCause.tap, cause: SelectionChangedCause.tap,
); );
await tester.pump(); await tester.pump();
expect(state.showToolbar(), true); // On web, we don't let Flutter show the toolbar.
expect(state.showToolbar(), kIsWeb ? isFalse : isTrue);
await tester.pump(); await tester.pump();
expect(find.text('Select all'), findsOneWidget); expect(find.text('Select all'), kIsWeb ? findsNothing : findsOneWidget);
expect(find.text('Copy'), findsOneWidget); expect(find.text('Copy'), kIsWeb ? findsNothing : findsOneWidget);
expect(find.text('Paste'), findsNothing); expect(find.text('Paste'), findsNothing);
expect(find.text('Cut'), findsNothing); expect(find.text('Cut'), findsNothing);
}); });
...@@ -1220,7 +1229,8 @@ void main() { ...@@ -1220,7 +1229,8 @@ void main() {
tester.state<EditableTextState>(find.byType(EditableText)); tester.state<EditableTextState>(find.byType(EditableText));
await tester.tap(find.byType(EditableText)); await tester.tap(find.byType(EditableText));
await tester.pump(); await tester.pump();
expect(state.showToolbar(), true); // On web, we don't let Flutter show the toolbar.
expect(state.showToolbar(), kIsWeb ? isFalse : isTrue);
await tester.pump(); await tester.pump();
expect(find.text('Select All'), findsNothing); expect(find.text('Select All'), findsNothing);
expect(find.text('Copy'), findsNothing); expect(find.text('Copy'), findsNothing);
...@@ -1256,10 +1266,11 @@ void main() { ...@@ -1256,10 +1266,11 @@ void main() {
cause: SelectionChangedCause.tap, cause: SelectionChangedCause.tap,
); );
await tester.pump(); await tester.pump();
expect(state.showToolbar(), true); // On web, we don't let Flutter show the toolbar.
expect(state.showToolbar(), kIsWeb ? isFalse : isTrue);
await tester.pump(); await tester.pump();
expect(find.text('Select all'), findsNothing); expect(find.text('Select all'), findsNothing);
expect(find.text('Copy'), findsOneWidget); expect(find.text('Copy'), kIsWeb ? findsNothing : findsOneWidget);
expect(find.text('Paste'), findsNothing); expect(find.text('Paste'), findsNothing);
expect(find.text('Cut'), findsNothing); expect(find.text('Cut'), findsNothing);
}); });
...@@ -1294,10 +1305,11 @@ void main() { ...@@ -1294,10 +1305,11 @@ void main() {
cause: SelectionChangedCause.tap, cause: SelectionChangedCause.tap,
); );
await tester.pump(); await tester.pump();
expect(state.showToolbar(), true); // On web, we don't let Flutter show the toolbar.
expect(state.showToolbar(), kIsWeb ? isFalse : isTrue);
await tester.pump(); await tester.pump();
expect(find.text('Select all'), findsOneWidget); expect(find.text('Select all'), kIsWeb ? findsNothing : findsOneWidget);
expect(find.text('Copy'), findsOneWidget); expect(find.text('Copy'), kIsWeb ? findsNothing : findsOneWidget);
expect(find.text('Paste'), findsNothing); expect(find.text('Paste'), findsNothing);
expect(find.text('Cut'), findsNothing); expect(find.text('Cut'), findsNothing);
}); });
...@@ -1308,6 +1320,7 @@ void main() { ...@@ -1308,6 +1320,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: EditableText( home: EditableText(
readOnly: true,
controller: controller, controller: controller,
backgroundCursorColor: Colors.grey, backgroundCursorColor: Colors.grey,
focusNode: focusNode, focusNode: focusNode,
...@@ -1317,21 +1330,25 @@ void main() { ...@@ -1317,21 +1330,25 @@ void main() {
), ),
); );
final EditableTextState state = // Interact with the field to establish the input connection.
tester.state<EditableTextState>(find.byType(EditableText)); final Offset topLeft = tester.getTopLeft(find.byType(EditableText));
await tester.tapAt(topLeft + const Offset(0.0, 5.0));
await tester.pump();
// Select the first word "Lorem". controller.selection = const TextSelection(baseOffset: 0, extentOffset: 5);
state.renderEditable.selectWordsInRange( await tester.pump();
from: Offset.zero,
cause: SelectionChangedCause.tap,
);
if (kIsWeb) { if (kIsWeb) {
// On the web, a regular connection to the platform should've been made // On the web, a regular connection to the platform should've been made
// with the `readOnly` flag set to true. // with the `readOnly` flag set to true.
expect(tester.testTextInput.hasAnyClients, isTrue); expect(tester.testTextInput.hasAnyClients, isTrue);
expect(tester.testTextInput.setClientArgs['readOnly'], isTrue); expect(tester.testTextInput.setClientArgs['readOnly'], isTrue);
expect(tester.testTextInput.editingState['text'], equals('Lorem')); expect(
tester.testTextInput.editingState['text'],
'Lorem ipsum dolor sit amet',
);
expect(tester.testTextInput.editingState['selectionBase'], 0);
expect(tester.testTextInput.editingState['selectionExtent'], 5);
} else { } else {
// On non-web platforms, a read-only field doesn't need a connection with // On non-web platforms, a read-only field doesn't need a connection with
// the platform. // the platform.
...@@ -1345,6 +1362,7 @@ void main() { ...@@ -1345,6 +1362,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: EditableText( home: EditableText(
readOnly: true,
controller: controller, controller: controller,
backgroundCursorColor: Colors.grey, backgroundCursorColor: Colors.grey,
focusNode: focusNode, focusNode: focusNode,
...@@ -1354,22 +1372,29 @@ void main() { ...@@ -1354,22 +1372,29 @@ void main() {
), ),
); );
final EditableTextState state = // Interact with the field to establish the input connection.
tester.state<EditableTextState>(find.byType(EditableText)); final Offset topLeft = tester.getTopLeft(find.byType(EditableText));
await tester.tapAt(topLeft + const Offset(0.0, 5.0));
// Select something. await tester.pump();
state.renderEditable.selectWordsInRange(
from: Offset.zero,
cause: SelectionChangedCause.tap,
);
expect(tester.testTextInput.hasAnyClients, kIsWeb ? isTrue : isFalse); expect(tester.testTextInput.hasAnyClients, kIsWeb ? isTrue : isFalse);
if (kIsWeb) { if (kIsWeb) {
// On the web, the input connection exists, but text updates should be // On the web, the input connection exists, but text updates should be
// ignored. // ignored.
tester.testTextInput.enterText('Foo bar'); tester.testTextInput.updateEditingValue(const TextEditingValue(
// No change. text: 'Foo bar',
expect(controller.text, 'Lorem ipsum dolor sit amet'); selection: TextSelection(baseOffset: 0, extentOffset: 3),
composing: TextRange(start: 3, end: 4),
));
// Only selection should change.
expect(
controller.value,
const TextEditingValue(
text: 'Lorem ipsum dolor sit amet',
selection: TextSelection(baseOffset: 0, extentOffset: 3),
composing: TextRange.empty,
),
);
} }
}); });
...@@ -1405,7 +1430,10 @@ void main() { ...@@ -1405,7 +1430,10 @@ void main() {
await tester.pump(); await tester.pump();
expect(changedValue, clipboardContent); expect(changedValue, clipboardContent);
});
// On web, we don't show the Flutter toolbar and instead rely on the browser
// toolbar. Until we change that, this test should remain skipped.
}, skip: kIsWeb);
// The variants to test in the focus handling test. // The variants to test in the focus handling test.
final ValueVariant<TextInputAction> focusVariants = ValueVariant< final ValueVariant<TextInputAction> focusVariants = ValueVariant<
...@@ -2271,7 +2299,8 @@ void main() { ...@@ -2271,7 +2299,8 @@ void main() {
expect(controller.selection.extentOffset, 9); expect(controller.selection.extentOffset, 9);
semantics.dispose(); semantics.dispose();
}); // https://github.com/flutter/flutter/issues/64507
}, skip: kIsWeb);
testWidgets('can extend selection with a11y means - character', (WidgetTester tester) async { testWidgets('can extend selection with a11y means - character', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
...@@ -2472,7 +2501,8 @@ void main() { ...@@ -2472,7 +2501,8 @@ void main() {
expect(controller.selection.extentOffset, 9); expect(controller.selection.extentOffset, 9);
semantics.dispose(); semantics.dispose();
}); // https://github.com/flutter/flutter/issues/64507
}, skip: kIsWeb);
testWidgets('password fields have correct semantics', (WidgetTester tester) async { testWidgets('password fields have correct semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
...@@ -3466,7 +3496,10 @@ void main() { ...@@ -3466,7 +3496,10 @@ void main() {
// at all. Again, both handles should be invisible. // at all. Again, both handles should be invisible.
scrollable.controller.jumpTo(0); scrollable.controller.jumpTo(0);
await verifyVisibility(HandlePositionInViewport.rightEdge, false, HandlePositionInViewport.rightEdge, false); await verifyVisibility(HandlePositionInViewport.rightEdge, false, HandlePositionInViewport.rightEdge, false);
});
// On web, we don't show the Flutter toolbar and instead rely on the browser
// toolbar. Until we change that, this test should remain skipped.
}, skip: kIsWeb);
testWidgets('text selection handle visibility RTL', (WidgetTester tester) async { testWidgets('text selection handle visibility RTL', (WidgetTester tester) async {
// Text with two separate words to select. // Text with two separate words to select.
...@@ -3525,7 +3558,10 @@ void main() { ...@@ -3525,7 +3558,10 @@ void main() {
expect(state.selectionOverlay.handlesAreVisible, isTrue); expect(state.selectionOverlay.handlesAreVisible, isTrue);
expect(controller.selection.base.offset, 0); expect(controller.selection.base.offset, 0);
expect(controller.selection.extent.offset, 5); expect(controller.selection.extent.offset, 5);
});
// On web, we don't show the Flutter toolbar and instead rely on the browser
// toolbar. Until we change that, this test should remain skipped.
}, skip: kIsWeb);
const String testText = 'Now is the time for\n' const String testText = 'Now is the time for\n'
'all good people\n' 'all good people\n'
...@@ -4121,19 +4157,23 @@ void main() { ...@@ -4121,19 +4157,23 @@ void main() {
testWidgets('keyboard text selection works as expected on linux', (WidgetTester tester) async { testWidgets('keyboard text selection works as expected on linux', (WidgetTester tester) async {
await testTextEditing(tester, platform: 'linux'); await testTextEditing(tester, platform: 'linux');
}); // On web, using keyboard for selection is handled by the browser.
}, skip: kIsWeb);
testWidgets('keyboard text selection works as expected on android', (WidgetTester tester) async { testWidgets('keyboard text selection works as expected on android', (WidgetTester tester) async {
await testTextEditing(tester, platform: 'android'); await testTextEditing(tester, platform: 'android');
}); // On web, using keyboard for selection is handled by the browser.
}, skip: kIsWeb);
testWidgets('keyboard text selection works as expected on fuchsia', (WidgetTester tester) async { testWidgets('keyboard text selection works as expected on fuchsia', (WidgetTester tester) async {
await testTextEditing(tester, platform: 'fuchsia'); await testTextEditing(tester, platform: 'fuchsia');
}); // On web, using keyboard for selection is handled by the browser.
}, skip: kIsWeb);
testWidgets('keyboard text selection works as expected on macos', (WidgetTester tester) async { testWidgets('keyboard text selection works as expected on macos', (WidgetTester tester) async {
await testTextEditing(tester, platform: 'macos'); await testTextEditing(tester, platform: 'macos');
}); // On web, using keyboard for selection is handled by the browser.
}, skip: kIsWeb);
// Regression test for https://github.com/flutter/flutter/issues/31287 // Regression test for https://github.com/flutter/flutter/issues/31287
testWidgets('text selection handle visibility', (WidgetTester tester) async { testWidgets('text selection handle visibility', (WidgetTester tester) async {
...@@ -4301,7 +4341,10 @@ void main() { ...@@ -4301,7 +4341,10 @@ void main() {
// at all. Again, both handles should be invisible. // at all. Again, both handles should be invisible.
scrollable.controller.jumpTo(0); scrollable.controller.jumpTo(0);
await verifyVisibility(HandlePositionInViewport.rightEdge, false, HandlePositionInViewport.rightEdge, false); await verifyVisibility(HandlePositionInViewport.rightEdge, false, HandlePositionInViewport.rightEdge, false);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
// On web, we don't show the Flutter toolbar and instead rely on the browser
// toolbar. Until we change that, this test should remain skipped.
}, skip: kIsWeb, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets("scrolling doesn't bounce", (WidgetTester tester) async { testWidgets("scrolling doesn't bounce", (WidgetTester tester) async {
// 3 lines of text, where the last line overflows and requires scrolling. // 3 lines of text, where the last line overflows and requires scrolling.
......
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