44
55@TestOn ('chrome || safari || firefox' )
66
7- import 'dart:typed_data' ;
8-
97import 'package:test/bootstrap/browser.dart' ;
108import 'package:test/test.dart' ;
119
@@ -50,11 +48,6 @@ void testMain() {
5048 testTextEditing.configuration = singlelineConfig;
5149 });
5250
53- /// Emulates sending of a message by the framework to the engine.
54- void sendFrameworkMessage (ByteData ? message) {
55- testTextEditing.channel.handleTextInput (message, (ByteData ? data) {});
56- }
57-
5851 test ('renders a text field' , () async {
5952 semantics ()
6053 ..debugOverrideTimestampFunction (() => _testTime)
@@ -134,7 +127,7 @@ void testMain() {
134127 // TODO(yjbanov): https://github.com/flutter/flutter/issues/50754
135128 skip: browserEngine != BrowserEngine .blink);
136129
137- test ('Syncs semantic state from framework' , () async {
130+ test ('Syncs editing state from framework' , () async {
138131 semantics ()
139132 ..debugOverrideTimestampFunction (() => _testTime)
140133 ..semanticsEnabled = true ;
@@ -166,6 +159,7 @@ void testMain() {
166159 expect (domDocument.activeElement, flutterViewEmbedder.glassPaneElement);
167160 expect (appHostNode.activeElement, strategy.domElement);
168161 expect (textField.editableElement, strategy.domElement);
162+ expect ((textField.editableElement as dynamic ).value, 'hello' );
169163 expect (textField.editableElement.getAttribute ('aria-label' ), 'greeting' );
170164 expect (textField.editableElement.style.width, '10px' );
171165 expect (textField.editableElement.style.height, '15px' );
@@ -180,6 +174,7 @@ void testMain() {
180174 expect (domDocument.activeElement, domDocument.body);
181175 expect (appHostNode.activeElement, null );
182176 expect (strategy.domElement, null );
177+ expect ((textField.editableElement as dynamic ).value, 'bye' );
183178 expect (textField.editableElement.getAttribute ('aria-label' ), 'farewell' );
184179 expect (textField.editableElement.style.width, '12px' );
185180 expect (textField.editableElement.style.height, '17px' );
@@ -193,92 +188,6 @@ void testMain() {
193188 expect (actionCount, 0 );
194189 });
195190
196- test (
197- 'Does not overwrite text value and selection editing state on semantic updates' ,
198- () async {
199- semantics ()
200- ..debugOverrideTimestampFunction (() => _testTime)
201- ..semanticsEnabled = true ;
202-
203- strategy.enable (
204- singlelineConfig,
205- onChange: (_, __) {},
206- onAction: (_) {},
207- );
208-
209- final SemanticsObject textFieldSemantics = createTextFieldSemantics (
210- value: 'hello' ,
211- textSelectionBase: 1 ,
212- textSelectionExtent: 3 ,
213- isFocused: true ,
214- rect: const ui.Rect .fromLTWH (0 , 0 , 10 , 15 ));
215-
216- final TextField textField =
217- textFieldSemantics.debugRoleManagerFor (Role .textField)! as TextField ;
218- final DomHTMLInputElement editableElement =
219- textField.editableElement as DomHTMLInputElement ;
220-
221- expect (editableElement, strategy.domElement);
222- expect (editableElement.value, '' );
223- expect (editableElement.selectionStart, 0 );
224- expect (editableElement.selectionEnd, 0 );
225-
226- strategy.disable ();
227- semantics ().semanticsEnabled = false ;
228- });
229-
230- test (
231- 'Updates editing state when receiving framework messages from the text input channel' ,
232- () async {
233- semantics ()
234- ..debugOverrideTimestampFunction (() => _testTime)
235- ..semanticsEnabled = true ;
236-
237- expect (domDocument.activeElement, domDocument.body);
238- expect (appHostNode.activeElement, null );
239-
240- strategy.enable (
241- singlelineConfig,
242- onChange: (_, __) {},
243- onAction: (_) {},
244- );
245-
246- final SemanticsObject textFieldSemantics = createTextFieldSemantics (
247- value: 'hello' ,
248- textSelectionBase: 1 ,
249- textSelectionExtent: 3 ,
250- isFocused: true ,
251- rect: const ui.Rect .fromLTWH (0 , 0 , 10 , 15 ));
252-
253- final TextField textField =
254- textFieldSemantics.debugRoleManagerFor (Role .textField)! as TextField ;
255- final DomHTMLInputElement editableElement =
256- textField.editableElement as DomHTMLInputElement ;
257-
258- // No updates expected on semantic updates
259- expect (editableElement, strategy.domElement);
260- expect (editableElement.value, '' );
261- expect (editableElement.selectionStart, 0 );
262- expect (editableElement.selectionEnd, 0 );
263-
264- // Update from framework
265- const MethodCall setEditingState =
266- MethodCall ('TextInput.setEditingState' , < String , dynamic > {
267- 'text' : 'updated' ,
268- 'selectionBase' : 2 ,
269- 'selectionExtent' : 3 ,
270- });
271- sendFrameworkMessage (codec.encodeMethodCall (setEditingState));
272-
273- // Editing state should now be updated
274- expect (editableElement.value, 'updated' );
275- expect (editableElement.selectionStart, 2 );
276- expect (editableElement.selectionEnd, 3 );
277-
278- strategy.disable ();
279- semantics ().semanticsEnabled = false ;
280- });
281-
282191 test ('Gives up focus after DOM blur' , () async {
283192 semantics ()
284193 ..debugOverrideTimestampFunction (() => _testTime)
@@ -537,8 +446,6 @@ SemanticsObject createTextFieldSemantics({
537446 bool isFocused = false ,
538447 bool isMultiline = false ,
539448 ui.Rect rect = const ui.Rect .fromLTRB (0 , 0 , 100 , 50 ),
540- int textSelectionBase = 0 ,
541- int textSelectionExtent = 0 ,
542449}) {
543450 final SemanticsTester tester = SemanticsTester (semantics ());
544451 tester.updateNode (
@@ -551,8 +458,6 @@ SemanticsObject createTextFieldSemantics({
551458 hasTap: true ,
552459 rect: rect,
553460 textDirection: ui.TextDirection .ltr,
554- textSelectionBase: textSelectionBase,
555- textSelectionExtent: textSelectionExtent
556461 );
557462 tester.apply ();
558463 return tester.getSemanticsObject (0 );
0 commit comments