[web] For Firefox focusing on the DOM element after blur propagates (flutter/engine#22953)

* For Firefox focusing on the DOM element after blur propagates

* modify the unit tests. remove webkit skip

* change async testing to a more common usage
This commit is contained in:
nturgut
2020-12-09 16:07:06 -08:00
committed by GitHub
parent d928bf3645
commit 6211412f85
2 changed files with 31 additions and 11 deletions

View File

@@ -1262,12 +1262,22 @@ class FirefoxTextEditingStrategy extends GloballyPositionedTextEditingStrategy {
// Refocus on the domElement after blur, so that user can keep editing the
// text field.
_subscriptions.add(domElement.onBlur.listen((_) {
domElement.focus();
_postponeFocus();
}));
preventDefaultForMouseEvents();
}
void _postponeFocus() {
// Firefox does not focus on the editing element if we call the focus
// inside the blur event, therefore we postpone the focus.
// Calling focus inside a Timer for `0` milliseconds guarantee that it is
// called after blur event propagation is completed.
Timer(const Duration(milliseconds: 0), () {
domElement.focus();
});
}
@override
void placeElement() {
domElement.focus();

View File

@@ -706,7 +706,10 @@ void testMain() {
expect(spy.messages, isEmpty);
});
test('do not close connection on blur', () async {
test('focus and connection with blur', () async {
// In all the desktop browsers we are keeping the connection
// open, keep the text editing element focused if it receives a blur
// event.
final MethodCall setClient = MethodCall(
'TextInput.setClient', <dynamic>[123, flutterSinglelineConfig]);
sendFrameworkMessage(codec.encodeMethodCall(setClient));
@@ -731,19 +734,26 @@ void testMain() {
// DOM element is blurred.
textEditing.editingElement.domElement.blur();
expect(spy.messages, hasLength(0));
// DOM element still has focus.
// Even though this passes on manual tests it does not work on
// Firefox automated unit tests.
if (browserEngine != BrowserEngine.firefox) {
// For ios-safari the connection is closed.
if (browserEngine == BrowserEngine.webkit &&
operatingSystem == OperatingSystem.iOs) {
expect(spy.messages, hasLength(1));
expect(spy.messages[0].channel, 'flutter/textinput');
expect(spy.messages[0].methodName,
'TextInputClient.onConnectionClosed');
await Future<void>.delayed(Duration.zero);
// DOM element loses the focus.
expect(document.activeElement, document.body);
} else {
// No connection close message sent.
expect(spy.messages, hasLength(0));
await Future<void>.delayed(Duration.zero);
// DOM element still keeps the focus.
expect(document.activeElement, textEditing.editingElement.domElement);
}
},
// TODO(nurhan): https://github.com/flutter/flutter/issues/50590
// TODO(nurhan): https://github.com/flutter/flutter/issues/50769
skip: (browserEngine == BrowserEngine.webkit ||
browserEngine == BrowserEngine.edge));
skip: (browserEngine == BrowserEngine.edge));
test('finishAutofillContext closes connection no autofill element',
() async {