Differentiate between TalkBack versions for semantics tests. (#92602)
Makes the android_semantics_testing test not fail for newer versions of Talkback. Also, since the test now depends on pub_semver, upgraded the pubspec files. The only substantive changes in the PR are in dev/integration_tests/android_semantics_testing/test_driver/main_test.dart
This commit is contained in:
@@ -8,6 +8,7 @@ import 'package:android_semantics_testing/android_semantics_testing.dart';
|
||||
import 'package:android_semantics_testing/test_constants.dart';
|
||||
import 'package:flutter_driver/flutter_driver.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
import 'package:test/test.dart' hide isInstanceOf;
|
||||
|
||||
String adbPath() {
|
||||
@@ -28,8 +29,54 @@ void main() {
|
||||
return AndroidSemanticsNode.deserialize(data);
|
||||
}
|
||||
|
||||
// The version of TalkBack running on the device.
|
||||
Version talkbackVersion;
|
||||
|
||||
// The version of TalkBack where the actions on the first item were fixed.
|
||||
final Version fixedTalkback = Version(9, 1, 0);
|
||||
|
||||
|
||||
Future<Version> getTalkbackVersion() async {
|
||||
final io.ProcessResult result = await io.Process.run(adbPath(), const <String>[
|
||||
'shell',
|
||||
'dumpsys',
|
||||
'package',
|
||||
'com.google.android.marvin.talkback',
|
||||
]);
|
||||
if (result.exitCode != 0) {
|
||||
throw Exception('Failed to get TalkBack version: ${result.stdout as String}\n${result.stderr as String}');
|
||||
}
|
||||
final List<String> lines = (result.stdout as String).split('\n');
|
||||
String version;
|
||||
for (final String line in lines) {
|
||||
if (line.contains('versionName')) {
|
||||
version = line.replaceAll(RegExp(r'\s*versionName='), '');
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (version == null) {
|
||||
throw Exception('Unable to determine TalkBack version.');
|
||||
}
|
||||
|
||||
// Android doesn't quite use semver, so convert the version string to semver form.
|
||||
final RegExp startVersion = RegExp(r'(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(\.(?<build>\d+))?');
|
||||
final RegExpMatch match = startVersion.firstMatch(version);
|
||||
if (match == null) {
|
||||
return Version(0, 0, 0);
|
||||
}
|
||||
return Version(
|
||||
int.parse(match.namedGroup('major')),
|
||||
int.parse(match.namedGroup('minor')),
|
||||
int.parse(match.namedGroup('patch')),
|
||||
build: match.namedGroup('build'),
|
||||
);
|
||||
}
|
||||
|
||||
setUpAll(() async {
|
||||
driver = await FlutterDriver.connect();
|
||||
talkbackVersion ??= await getTalkbackVersion();
|
||||
print('TalkBack version is $talkbackVersion');
|
||||
|
||||
// Say the magic words..
|
||||
final io.Process run = await io.Process.start(adbPath(), const <String>[
|
||||
'shell',
|
||||
@@ -110,7 +157,8 @@ void main() {
|
||||
isFocused: false,
|
||||
isPassword: false,
|
||||
actions: <AndroidSemanticsAction>[
|
||||
AndroidSemanticsAction.accessibilityFocus,
|
||||
if (talkbackVersion < fixedTalkback) AndroidSemanticsAction.accessibilityFocus,
|
||||
if (talkbackVersion >= fixedTalkback) AndroidSemanticsAction.clearAccessibilityFocus,
|
||||
AndroidSemanticsAction.click,
|
||||
],
|
||||
),
|
||||
@@ -449,10 +497,9 @@ void main() {
|
||||
isEnabled: true,
|
||||
isFocusable: true,
|
||||
actions: <AndroidSemanticsAction>[
|
||||
// TODO(gspencergoog): This should really be clearAccessibilityFocus,
|
||||
// but TalkBack doesn't focus it the second time for some reason.
|
||||
// https://github.com/flutter/flutter/issues/40101
|
||||
AndroidSemanticsAction.accessibilityFocus,
|
||||
if (talkbackVersion < fixedTalkback && item == popupItems.first) AndroidSemanticsAction.accessibilityFocus,
|
||||
if (talkbackVersion >= fixedTalkback && item == popupItems.first) AndroidSemanticsAction.clearAccessibilityFocus,
|
||||
if (item != popupItems.first) AndroidSemanticsAction.accessibilityFocus,
|
||||
AndroidSemanticsAction.click,
|
||||
],
|
||||
),
|
||||
@@ -498,10 +545,9 @@ void main() {
|
||||
isEnabled: true,
|
||||
isFocusable: true,
|
||||
actions: <AndroidSemanticsAction>[
|
||||
// TODO(gspencergoog): This should really be different for the first item:
|
||||
// It should have clearAccessibilityFocus instead, but for some reason
|
||||
// TalkBack doesn't ask to focus it.
|
||||
AndroidSemanticsAction.accessibilityFocus,
|
||||
if (talkbackVersion < fixedTalkback && item == popupItems.first) AndroidSemanticsAction.accessibilityFocus,
|
||||
if (talkbackVersion >= fixedTalkback && item == popupItems.first) AndroidSemanticsAction.clearAccessibilityFocus,
|
||||
if (item != popupItems.first) AndroidSemanticsAction.accessibilityFocus,
|
||||
AndroidSemanticsAction.click,
|
||||
],
|
||||
),
|
||||
@@ -534,10 +580,9 @@ void main() {
|
||||
isEnabled: true,
|
||||
isFocusable: true,
|
||||
actions: <AndroidSemanticsAction>[
|
||||
// TODO(gspencergoog): This should really be different for the first item:
|
||||
// It should have clearAccessibilityFocus instead, but for some reason
|
||||
// TalkBack doesn't ask to focus it.
|
||||
AndroidSemanticsAction.accessibilityFocus,
|
||||
if (talkbackVersion < fixedTalkback && item == popupItems.first) AndroidSemanticsAction.accessibilityFocus,
|
||||
if (talkbackVersion >= fixedTalkback && item == popupItems.first) AndroidSemanticsAction.clearAccessibilityFocus,
|
||||
if (item != popupItems.first) AndroidSemanticsAction.accessibilityFocus,
|
||||
AndroidSemanticsAction.click,
|
||||
],
|
||||
),
|
||||
@@ -637,9 +682,9 @@ void main() {
|
||||
isEnabled: true,
|
||||
isFocusable: true,
|
||||
actions: <AndroidSemanticsAction>[
|
||||
// TODO(gspencergoog): This should really be identical to the first time,
|
||||
// but TalkBack doesn't find it the second time for some reason.
|
||||
AndroidSemanticsAction.accessibilityFocus,
|
||||
if (talkbackVersion < fixedTalkback && item == 'Title') AndroidSemanticsAction.accessibilityFocus,
|
||||
if (talkbackVersion >= fixedTalkback && item == 'Title') AndroidSemanticsAction.clearAccessibilityFocus,
|
||||
if (item != 'Title') AndroidSemanticsAction.accessibilityFocus,
|
||||
],
|
||||
),
|
||||
reason: "Alert $item button doesn't have the right semantics");
|
||||
|
||||
Reference in New Issue
Block a user