summaryrefslogtreecommitdiff
path: root/test_driver/utils
diff options
context:
space:
mode:
authormirror <mirror@localhost>2026-11-22 08:41:00 +0900
committermirror <mirror@localhost>2026-11-22 08:41:00 +0900
commit449d8b74bd6d9dae98a07254cdfad677b920e7b0 (patch)
treec131c3528c4d517f56e19b854a7453fedb097d40 /test_driver/utils
downloadaves-src-master.tar.gz
aves-src-master.zip
snapshot of aves v1.13.12 (secrets removed: android/app/google-services.json)HEADv1.13.12master
Diffstat (limited to 'test_driver/utils')
-rw-r--r--test_driver/utils/adb_utils.dart49
-rw-r--r--test_driver/utils/driver_extension.dart49
2 files changed, 98 insertions, 0 deletions
diff --git a/test_driver/utils/adb_utils.dart b/test_driver/utils/adb_utils.dart
new file mode 100644
index 0000000..8d86ab5
--- /dev/null
+++ b/test_driver/utils/adb_utils.dart
@@ -0,0 +1,49 @@
+import 'dart:io';
+
+import 'package:path/path.dart' as p;
+
+String get adb {
+ if (Platform.isWindows) {
+ final env = Platform.environment;
+ // e.g. C:\Users\<username>\AppData\Local\Android\Sdk
+ final sdkDir = env['ANDROID_SDK_ROOT'] ?? env['ANDROID_SDK']!;
+ return p.join(sdkDir, 'platform-tools', 'adb.exe');
+ }
+ return 'adb';
+}
+
+/*
+ If there's only one emulator running or only one device connected,
+ the adb command is sent to that device by default.
+ If multiple emulators are running and/or multiple devices are attached,
+ you need to use the -d, -e, or -s option to specify the target device
+ to which the command should be directed.
+ */
+const List<String> adbDeviceParam = ['-d']; // `[]`, `['-d']`, `['-e']`, or `['-s', <serial_number>]`
+
+Future<void> runAdb(List<String> args) async {
+ await Process.run(adb, [...adbDeviceParam, ...args]);
+}
+
+Future<void> createDirectory(String dir) async {
+ await runAdb(['shell', 'mkdir', '-p', dir.replaceAll(' ', '\\ ')]);
+}
+
+Future<void> removeDirectory(String dir) async {
+ await runAdb(['shell', 'rm', '-r', dir.replaceAll(' ', '\\ ')]);
+}
+
+Future<void> copyContent(String sourceDir, String targetDir) async {
+ // to copy the content of `source` inside `target`
+ // `push source/* target/` works only when the target directory exists, and fails when `target` contains spaces
+ // `push source/ target/` works only when the target directory does not exist
+ await removeDirectory(targetDir);
+ await runAdb(['push', sourceDir, targetDir]);
+}
+
+// only works in debug mode
+Future<void> grantPermissions(String packageName, Iterable<String> permissions) async {
+ await Future.forEach<String>(permissions, (permission) => runAdb(['shell', 'pm', 'grant', packageName, permission]));
+}
+
+Future<void> pressDeviceBackButton() => runAdb(['shell', 'input', 'keyevent', 'KEYCODE_BACK']);
diff --git a/test_driver/utils/driver_extension.dart b/test_driver/utils/driver_extension.dart
new file mode 100644
index 0000000..87b4bfb
--- /dev/null
+++ b/test_driver/utils/driver_extension.dart
@@ -0,0 +1,49 @@
+// ignore_for_file: avoid_print
+import 'package:aves/widgets/debug/app_debug_action.dart';
+import 'package:flutter_driver/flutter_driver.dart';
+
+import 'adb_utils.dart';
+
+extension ExtraFlutterDriver on FlutterDriver {
+ static const doubleTapDelay = Duration(milliseconds: 100); // in [kDoubleTapMinTime = 40 ms, kDoubleTapTimeout = 300 ms]
+
+ // scrolling is ineffective when duration is too short for the spatial delta
+ Future<void> scrollX(SerializableFinder finder, double dx) => scroll(finder, dx, 0, Duration(milliseconds: dx.toInt().abs() * 2));
+
+ // scrolling is ineffective when duration is too short for the spatial delta
+ Future<void> scrollY(SerializableFinder finder, double dy) => scroll(finder, 0, dy, Duration(milliseconds: dy.toInt().abs() * 2));
+
+ Future<void> doubleTap(SerializableFinder finder, {Duration? timeout}) async {
+ await tap(finder, timeout: timeout);
+ await Future.delayed(doubleTapDelay);
+ await tap(finder, timeout: timeout);
+ }
+
+ Future<void> tapKeyAndWait(String key, {bool waitUntilNoTransient = true}) async {
+ print(' find key=$key');
+ final finder = find.byValueKey(key);
+ await waitFor(finder);
+ await tap(finder);
+ if (waitUntilNoTransient) {
+ await waitUntilNoTransientCallbacks();
+ }
+ }
+
+ Future<void> scanMediaDir(String dir) async {
+ await tapKeyAndWait('appbar-leading-button');
+ await scroll(find.byValueKey('drawer-settings-button'), 0, -500, const Duration(milliseconds: 500));
+ await tapKeyAndWait('drawer-debug');
+
+ await tapKeyAndWait('appbar-menu-button');
+ await tapKeyAndWait('menu-${AppDebugAction.mediaStoreScanDir.name}');
+
+ await tap(find.byType('TextField'));
+ await enterText(dir);
+
+ await tap(find.byType('TextButton'));
+ await waitUntilNoTransientCallbacks();
+
+ await pressDeviceBackButton();
+ await waitUntilNoTransientCallbacks();
+ }
+}