Rename native_driver to android_{driver_extensions|engine_test} (#161263)

Towards https://github.com/flutter/flutter/issues/161261 (before I add
more tests).

This is a 1:1 move, with massaging of
`run_flutter_driver_android_tests.dart` to be more automated as tests
are added.

/cc @reidbaker
This commit is contained in:
Matan Lurey
2025-01-08 12:28:38 -08:00
committed by GitHub
parent 04a60d6b27
commit 132e298335
74 changed files with 62 additions and 1051 deletions

View File

@@ -0,0 +1,86 @@
// 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:typed_data';
import 'package:android_driver_extensions/src/backend/android.dart';
/// A stub of [Adb] that allows overriding its methods.
///
/// The default implementation of each method is a simple success case.
final class FakeAdb implements Adb {
FakeAdb({
Future<(bool, String?)> Function()? isDeviceConnected,
Future<Uint8List> Function()? screencap,
Future<void> Function(int x, int y)? tap,
Future<void> Function()? disableImmersiveModeConfirmations,
Future<void> Function()? disableAnimations,
Future<void> Function()? sendToHome,
Future<void> Function(String appName, [String? activityName])? resumeApp,
Future<void> Function(String appName)? trimMemory,
}) : _isDeviceConnected = isDeviceConnected,
_screencap = screencap,
_tap = tap,
_disableImmersiveModeConfirmations = disableImmersiveModeConfirmations,
_disableAnimations = disableAnimations,
_sendToHome = sendToHome,
_resumeApp = resumeApp,
_trimMemory = trimMemory;
@override
Future<(bool, String?)> isDeviceConnected() async {
return _isDeviceConnected?.call() ?? (true, null);
}
final Future<(bool, String?)> Function()? _isDeviceConnected;
@override
Future<Uint8List> screencap() {
return _screencap?.call() ?? Future<Uint8List>.value(Uint8List(0));
}
final Future<Uint8List> Function()? _screencap;
@override
Future<void> tap(int x, int y) async {
return _tap?.call(x, y) ?? Future<void>.value();
}
final Future<void> Function(int x, int y)? _tap;
@override
Future<void> disableImmersiveModeConfirmations() {
return _disableImmersiveModeConfirmations?.call() ?? Future<void>.value();
}
final Future<void> Function()? _disableImmersiveModeConfirmations;
@override
Future<void> disableAnimations() {
return _disableAnimations?.call() ?? Future<void>.value();
}
final Future<void> Function()? _disableAnimations;
@override
Future<void> sendToHome() {
return _sendToHome?.call() ?? Future<void>.value();
}
final Future<void> Function()? _sendToHome;
@override
Future<void> resumeApp({required String appName, String? activityName}) {
return _resumeApp?.call(appName, activityName) ?? Future<void>.value();
}
final Future<void> Function(String appName, [String? activityName])? _resumeApp;
@override
Future<void> trimMemory({required String appName}) {
return _trimMemory?.call(appName) ?? Future<void>.value();
}
final Future<void> Function(String appName)? _trimMemory;
}

View File

@@ -0,0 +1,13 @@
// 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 'package:flutter_driver/flutter_driver.dart';
/// A fake [FlutterDriver] that throws [UnimplementedError] for all methods.
final class NullFlutterDriver implements FlutterDriver {
const NullFlutterDriver();
@override
Never noSuchMethod(Invocation invocation) => throw UnimplementedError();
}

View File

@@ -0,0 +1,50 @@
// 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:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:process/process.dart';
/// A stub of [ProcessManager] that allows mocking the [run] method only.
final class FakeProcessManager extends ProcessManager {
/// Creates a new [FakeProcessManager] with the given delegate callback.
FakeProcessManager(this._runDelegate);
final Future<ProcessResult> Function(String executable, List<String> arguments) _runDelegate;
@override
Never noSuchMethod(_) => throw UnimplementedError();
@override
Future<ProcessResult> run(
List<Object> command, {
String? workingDirectory,
Map<String, String>? environment,
bool includeParentEnvironment = true,
bool runInShell = false,
Encoding? stdoutEncoding = systemEncoding,
Encoding? stderrEncoding = systemEncoding,
}) {
final List<String> strings = command.map((Object e) => '$e').toList();
final [String executable, ...List<String> arguments] = strings;
return _runDelegate(executable, arguments);
}
/// Returns a [ProcessResult] with the given [stdout].
static ProcessResult ok([String stdout = '']) {
return ProcessResult(0, 0, stdout, '');
}
/// Returns a [ProcessResult] with the given [stderr].
static ProcessResult error([String stderr = '']) {
return ProcessResult(0, 1, '', stderr);
}
/// Returns a [ProcessResult] with the given [stdout] binary data.
static ProcessResult okBinary(List<int> stdout) {
return ProcessResult(0, 0, Uint8List.fromList(stdout), '');
}
}