Unverified Commit a80ad0e1 authored by chunhtai's avatar chunhtai Committed by GitHub

Force the a11y focus on textfield in android semantics integration test (#93876)

parent fb3f1237
......@@ -27,6 +27,7 @@ import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugins.GeneratedPluginRegistrant;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeProvider;
import android.view.accessibility.AccessibilityNodeInfo;
......@@ -66,6 +67,25 @@ public class MainActivity extends FlutterActivity {
result.success(convertSemantics(node, id));
return;
}
if (methodCall.method.equals("sendSemanticsFocus")) {
Map<String, Object> data = methodCall.arguments();
@SuppressWarnings("unchecked")
Integer id = (Integer) data.get("id");
if (id == null) {
result.error("No ID provided", "", null);
return;
}
if (provider == null) {
result.error("Semantics not enabled", "", null);
return;
}
AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_FOCUSED);
event.setPackageName(flutterView.getContext().getPackageName());
event.setSource(flutterView, id);
flutterView.getParent().requestSendAccessibilityEvent(flutterView, event);
result.success(null);
return;
}
result.notImplemented();
}
......
......@@ -39,6 +39,21 @@ Future<String> dataHandler(String message) async {
completeSemantics();
return completer.future;
}
if (message.contains('sendSemanticsFocus')) {
final Completer<String> completer = Completer<String>();
final int id = int.tryParse(message.split('#')[1]) ?? 0;
Future<void> completeSemantics([Object _]) async {
final dynamic result = await kSemanticsChannel.invokeMethod<dynamic>('sendSemanticsFocus', <String, dynamic>{
'id': id,
});
completer.complete(json.encode(result));
}
if (SchedulerBinding.instance.hasScheduledFrame)
SchedulerBinding.instance.addPostFrameCallback(completeSemantics);
else
completeSemantics();
return completer.future;
}
throw UnimplementedError();
}
......
......@@ -29,6 +29,11 @@ void main() {
return AndroidSemanticsNode.deserialize(data);
}
Future<void> sendSemanticsFocus(SerializableFinder finder) async {
final int id = await driver.getSemanticsId(finder);
await driver.requestData('sendSemanticsFocus#$id');
}
// The version of TalkBack running on the device.
Version talkbackVersion;
......@@ -148,6 +153,10 @@ void main() {
matching: find.byType('Semantics'),
firstMatchOnly: true,
);
// Make sure the focus is on the back button.
await sendSemanticsFocus(find.byValueKey(backButtonKeyValue));
await Future<void>.delayed(const Duration(milliseconds: 500));
expect(
await getSemantics(normalTextField),
hasAndroidSemantics(
......@@ -157,8 +166,7 @@ void main() {
isFocused: false,
isPassword: false,
actions: <AndroidSemanticsAction>[
if (talkbackVersion < fixedTalkback) AndroidSemanticsAction.accessibilityFocus,
if (talkbackVersion >= fixedTalkback) AndroidSemanticsAction.clearAccessibilityFocus,
AndroidSemanticsAction.accessibilityFocus,
AndroidSemanticsAction.click,
],
),
......
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