4
4
5
5
@TestOn ('chrome || safari || firefox' )
6
6
7
- import 'dart:typed_data' ;
8
-
9
7
import 'package:test/bootstrap/browser.dart' ;
10
8
import 'package:test/test.dart' ;
11
9
@@ -50,11 +48,6 @@ void testMain() {
50
48
testTextEditing.configuration = singlelineConfig;
51
49
});
52
50
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
-
58
51
test ('renders a text field' , () async {
59
52
semantics ()
60
53
..debugOverrideTimestampFunction (() => _testTime)
@@ -134,7 +127,7 @@ void testMain() {
134
127
// TODO(yjbanov): https://github.com/flutter/flutter/issues/50754
135
128
skip: browserEngine != BrowserEngine .blink);
136
129
137
- test ('Syncs semantic state from framework' , () async {
130
+ test ('Syncs editing state from framework' , () async {
138
131
semantics ()
139
132
..debugOverrideTimestampFunction (() => _testTime)
140
133
..semanticsEnabled = true ;
@@ -166,6 +159,7 @@ void testMain() {
166
159
expect (domDocument.activeElement, flutterViewEmbedder.glassPaneElement);
167
160
expect (appHostNode.activeElement, strategy.domElement);
168
161
expect (textField.editableElement, strategy.domElement);
162
+ expect ((textField.editableElement as dynamic ).value, 'hello' );
169
163
expect (textField.editableElement.getAttribute ('aria-label' ), 'greeting' );
170
164
expect (textField.editableElement.style.width, '10px' );
171
165
expect (textField.editableElement.style.height, '15px' );
@@ -180,6 +174,7 @@ void testMain() {
180
174
expect (domDocument.activeElement, domDocument.body);
181
175
expect (appHostNode.activeElement, null );
182
176
expect (strategy.domElement, null );
177
+ expect ((textField.editableElement as dynamic ).value, 'bye' );
183
178
expect (textField.editableElement.getAttribute ('aria-label' ), 'farewell' );
184
179
expect (textField.editableElement.style.width, '12px' );
185
180
expect (textField.editableElement.style.height, '17px' );
@@ -193,92 +188,6 @@ void testMain() {
193
188
expect (actionCount, 0 );
194
189
});
195
190
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
-
282
191
test ('Gives up focus after DOM blur' , () async {
283
192
semantics ()
284
193
..debugOverrideTimestampFunction (() => _testTime)
@@ -537,8 +446,6 @@ SemanticsObject createTextFieldSemantics({
537
446
bool isFocused = false ,
538
447
bool isMultiline = false ,
539
448
ui.Rect rect = const ui.Rect .fromLTRB (0 , 0 , 100 , 50 ),
540
- int textSelectionBase = 0 ,
541
- int textSelectionExtent = 0 ,
542
449
}) {
543
450
final SemanticsTester tester = SemanticsTester (semantics ());
544
451
tester.updateNode (
@@ -551,8 +458,6 @@ SemanticsObject createTextFieldSemantics({
551
458
hasTap: true ,
552
459
rect: rect,
553
460
textDirection: ui.TextDirection .ltr,
554
- textSelectionBase: textSelectionBase,
555
- textSelectionExtent: textSelectionExtent
556
461
);
557
462
tester.apply ();
558
463
return tester.getSemanticsObject (0 );
0 commit comments