Migrates android semanitcs integration to integration test (#127128)

I think the flake is due to setclipboard or semantics update race condition. I migrated the test to use integration test package which relies less on timing

fixes https://github.com/flutter/flutter/issues/124636
This commit is contained in:
chunhtai
2023-05-23 15:33:19 -07:00
committed by GitHub
parent 8c086d0171
commit c687dcd56f
11 changed files with 979 additions and 766 deletions

View File

@@ -0,0 +1,79 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io' as io;
import 'package:path/path.dart' as path;
import 'package:pub_semver/pub_semver.dart';
String adbPath() {
final String? androidHome = io.Platform.environment['ANDROID_HOME'] ?? io.Platform.environment['ANDROID_SDK_ROOT'];
if (androidHome == null) {
return 'adb';
} else {
return path.join(androidHome, 'platform-tools', 'adb');
}
}
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'),
);
}
Future<void> enableTalkBack() async {
final io.Process run = await io.Process.start(adbPath(), const <String>[
'shell',
'settings',
'put',
'secure',
'enabled_accessibility_services',
'com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService',
]);
await run.exitCode;
print('TalkBack version is ${await getTalkbackVersion()}');
}
Future<void> disableTalkBack() async {
final io.Process run = await io.Process.start(adbPath(), const <String>[
'shell',
'settings',
'put',
'secure',
'enabled_accessibility_services',
'null',
]);
await run.exitCode;
}

View File

@@ -4,6 +4,7 @@
import '../framework/devices.dart';
import '../framework/framework.dart';
import '../framework/talkback.dart';
import '../framework/task_result.dart';
import '../framework/utils.dart';
@@ -74,9 +75,10 @@ TaskFunction createHybridAndroidViewsIntegrationTest() {
}
TaskFunction createAndroidSemanticsIntegrationTest() {
return DriverTest(
return IntegrationTest(
'${flutterDirectory.path}/dev/integration_tests/android_semantics_testing',
'lib/main.dart',
'integration_test/main_test.dart',
withTalkBack: true,
).call;
}
@@ -213,6 +215,7 @@ class IntegrationTest {
this.testTarget, {
this.extraOptions = const <String>[],
this.createPlatforms = const <String>[],
this.withTalkBack = false,
}
);
@@ -220,6 +223,7 @@ class IntegrationTest {
final String testTarget;
final List<String> extraOptions;
final List<String> createPlatforms;
final bool withTalkBack;
Future<TaskResult> call() {
return inDirectory<TaskResult>(testDirectory, () async {
@@ -237,6 +241,13 @@ class IntegrationTest {
]);
}
if (withTalkBack) {
if (device is! AndroidDevice) {
return TaskResult.failure('A test that enables TalkBack can only be run on Android devices');
}
await enableTalkBack();
}
final List<String> options = <String>[
'-v',
'-d',
@@ -246,6 +257,10 @@ class IntegrationTest {
];
await flutter('test', options: options);
if (withTalkBack) {
await disableTalkBack();
}
return TaskResult.success(null);
});
}