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:
@@ -10,10 +10,11 @@ dependencies:
|
||||
sdk: flutter
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
pub_semver: 2.1.0
|
||||
test: 1.17.12
|
||||
|
||||
_fe_analyzer_shared: 29.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
analyzer: 2.6.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
_fe_analyzer_shared: 30.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
analyzer: 2.7.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
archive: 3.1.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
args: 2.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
async: 2.8.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
@@ -37,13 +38,12 @@ dependencies:
|
||||
logging: 1.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
matcher: 0.12.11 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
meta: 1.7.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
mime: 1.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
mime: 1.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
node_preamble: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
package_config: 2.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
path: 1.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
pedantic: 1.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
pool: 1.5.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
pub_semver: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
shelf: 1.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
shelf_packages_handler: 3.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
shelf_static: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
@@ -70,4 +70,4 @@ dependencies:
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
|
||||
# PUBSPEC CHECKSUM: 0d38
|
||||
# PUBSPEC CHECKSUM: f832
|
||||
|
||||
@@ -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