forked from firka/flutter
Revert "[flutter_tools] refactor drive launch into separate service, split by mobile+desktop and web (#68451)" (#68845)
This reverts commit 2e75f52ae4.
This commit is contained in:
@@ -590,17 +590,13 @@ class AndroidDevice extends Device {
|
||||
}
|
||||
|
||||
final bool traceStartup = platformArgs['trace-startup'] as bool ?? false;
|
||||
_logger.printTrace('$this startApp');
|
||||
|
||||
ProtocolDiscovery observatoryDiscovery;
|
||||
|
||||
if (debuggingOptions.debuggingEnabled) {
|
||||
observatoryDiscovery = ProtocolDiscovery.observatory(
|
||||
// Avoid using getLogReader, which returns a singleton instance, because the
|
||||
// observatory discovery will dipose at the end. creating a new logger here allows
|
||||
// logs to be surfaced normally during `flutter drive`.
|
||||
await AdbLogReader.createLogReader(
|
||||
this,
|
||||
_processManager,
|
||||
),
|
||||
await getLogReader(),
|
||||
portForwarder: portForwarder,
|
||||
hostPort: debuggingOptions.hostVmServicePort,
|
||||
devicePort: debuggingOptions.deviceVmServicePort,
|
||||
@@ -673,6 +669,8 @@ class AndroidDevice extends Device {
|
||||
// Wait for the service protocol port here. This will complete once the
|
||||
// device has printed "Observatory is listening on...".
|
||||
_logger.printTrace('Waiting for observatory port to be available...');
|
||||
|
||||
// TODO(danrubel): Waiting for observatory services can be made common across all devices.
|
||||
try {
|
||||
Uri observatoryUri;
|
||||
if (debuggingOptions.buildInfo.isDebug || debuggingOptions.buildInfo.isProfile) {
|
||||
|
||||
@@ -22,6 +22,9 @@ import 'assets.dart';
|
||||
import 'common.dart';
|
||||
import 'localizations.dart';
|
||||
|
||||
/// Whether web builds should call the platform initialization logic.
|
||||
const String kInitializePlatform = 'InitializePlatform';
|
||||
|
||||
/// Whether the application has web plugins.
|
||||
const String kHasWebPlugins = 'HasWebPlugins';
|
||||
|
||||
@@ -86,6 +89,7 @@ class WebEntrypointTarget extends Target {
|
||||
@override
|
||||
Future<void> build(Environment environment) async {
|
||||
final String targetFile = environment.defines[kTargetFile];
|
||||
final bool shouldInitializePlatform = environment.defines[kInitializePlatform] == 'true';
|
||||
final bool hasPlugins = environment.defines[kHasWebPlugins] == 'true';
|
||||
final Uri importUri = environment.fileSystem.file(targetFile).absolute.uri;
|
||||
// TODO(jonahwilliams): support configuration of this file.
|
||||
@@ -133,7 +137,9 @@ import '$mainImport' as entrypoint;
|
||||
|
||||
Future<void> main() async {
|
||||
registerPlugins(webPluginRegistry);
|
||||
await ui.webOnlyInitializePlatform();
|
||||
if ($shouldInitializePlatform) {
|
||||
await ui.webOnlyInitializePlatform();
|
||||
}
|
||||
entrypoint.main();
|
||||
}
|
||||
''';
|
||||
@@ -146,7 +152,9 @@ import 'dart:ui' as ui;
|
||||
import '$mainImport' as entrypoint;
|
||||
|
||||
Future<void> main() async {
|
||||
await ui.webOnlyInitializePlatform();
|
||||
if ($shouldInitializePlatform) {
|
||||
await ui.webOnlyInitializePlatform();
|
||||
}
|
||||
entrypoint.main();
|
||||
}
|
||||
''';
|
||||
|
||||
@@ -384,6 +384,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
|
||||
|
||||
final FlutterDevice flutterDevice = await FlutterDevice.create(
|
||||
device,
|
||||
flutterProject: flutterProject,
|
||||
fileSystemRoots: stringsArg('filesystem-root'),
|
||||
fileSystemScheme: stringArg('filesystem-scheme'),
|
||||
target: stringArg('target'),
|
||||
|
||||
@@ -25,6 +25,12 @@ class BuildWebCommand extends BuildSubCommand {
|
||||
usesDartDefineOption();
|
||||
addEnableExperimentation(hide: !verboseHelp);
|
||||
addNullSafetyModeOptions(hide: !verboseHelp);
|
||||
argParser.addFlag('web-initialize-platform',
|
||||
defaultsTo: true,
|
||||
negatable: true,
|
||||
hide: true,
|
||||
help: 'Whether to automatically invoke webOnlyInitializePlatform.',
|
||||
);
|
||||
argParser.addFlag('csp',
|
||||
defaultsTo: false,
|
||||
negatable: false,
|
||||
@@ -86,6 +92,7 @@ class BuildWebCommand extends BuildSubCommand {
|
||||
flutterProject,
|
||||
target,
|
||||
buildInfo,
|
||||
boolArg('web-initialize-platform'),
|
||||
boolArg('csp'),
|
||||
stringArg('pwa-strategy'),
|
||||
boolArg('source-maps')
|
||||
|
||||
@@ -466,6 +466,7 @@ class AppDomain extends Domain {
|
||||
|
||||
final FlutterDevice flutterDevice = await FlutterDevice.create(
|
||||
device,
|
||||
flutterProject: flutterProject,
|
||||
target: target,
|
||||
buildInfo: options.buildInfo,
|
||||
platform: globals.platform,
|
||||
|
||||
@@ -3,21 +3,29 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:dds/dds.dart' as dds;
|
||||
import 'package:vm_service/vm_service_io.dart' as vm_service;
|
||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:webdriver/async_io.dart' as async_io;
|
||||
|
||||
import '../android/android_device.dart';
|
||||
import '../application_package.dart';
|
||||
import '../artifacts.dart';
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../build_info.dart';
|
||||
import '../convert.dart';
|
||||
import '../dart/package_map.dart';
|
||||
import '../device.dart';
|
||||
import '../drive/drive_service.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../resident_runner.dart';
|
||||
import '../runner/flutter_command.dart' show FlutterCommandResult, FlutterOptions;
|
||||
import '../web/web_device.dart';
|
||||
import '../vmservice.dart';
|
||||
import '../web/web_runner.dart';
|
||||
import 'run.dart';
|
||||
|
||||
/// Runs integration (a.k.a. end-to-end) tests.
|
||||
@@ -43,12 +51,7 @@ import 'run.dart';
|
||||
class DriveCommand extends RunCommandBase {
|
||||
DriveCommand({
|
||||
bool verboseHelp = false,
|
||||
@visibleForTesting FlutterDriverFactory flutterDriverFactory,
|
||||
@required FileSystem fileSystem,
|
||||
@required Logger logger,
|
||||
}) : _flutterDriverFactory = flutterDriverFactory,
|
||||
_fileSystem = fileSystem,
|
||||
_logger = logger {
|
||||
}) {
|
||||
requiresPubspecYaml();
|
||||
addEnableExperimentation(hide: !verboseHelp);
|
||||
|
||||
@@ -106,7 +109,7 @@ class DriveCommand extends RunCommandBase {
|
||||
'firefox',
|
||||
'ios-safari',
|
||||
'safari',
|
||||
],
|
||||
]
|
||||
)
|
||||
..addOption('browser-dimension',
|
||||
defaultsTo: '1600,1024',
|
||||
@@ -124,15 +127,10 @@ class DriveCommand extends RunCommandBase {
|
||||
..addOption('write-sksl-on-exit',
|
||||
help:
|
||||
'Attempts to write an SkSL file when the drive process is finished '
|
||||
'to the provided file, overwriting it if necessary.')
|
||||
..addMultiOption('test-arguments', help: 'Additional arguments to pass to the '
|
||||
'Dart VM running The test script.');
|
||||
'to the provided file, overwriting it if necessary.',
|
||||
);
|
||||
}
|
||||
|
||||
FlutterDriverFactory _flutterDriverFactory;
|
||||
final FileSystem _fileSystem;
|
||||
final Logger _logger;
|
||||
|
||||
@override
|
||||
final String name = 'drive';
|
||||
|
||||
@@ -142,15 +140,20 @@ class DriveCommand extends RunCommandBase {
|
||||
@override
|
||||
final List<String> aliases = <String>['driver'];
|
||||
|
||||
Device _device;
|
||||
Device get device => _device;
|
||||
|
||||
bool get verboseSystemLogs => boolArg('verbose-system-logs');
|
||||
String get userIdentifier => stringArg(FlutterOptions.kDeviceUser);
|
||||
|
||||
@override
|
||||
bool get startPausedDefault => true;
|
||||
/// Subscription to log messages printed on the device or simulator.
|
||||
// ignore: cancel_subscriptions
|
||||
StreamSubscription<String> _deviceLogSubscription;
|
||||
|
||||
@override
|
||||
Future<void> validateCommand() async {
|
||||
if (userIdentifier != null) {
|
||||
final Device device = await findTargetDevice();
|
||||
final Device device = await findTargetDevice(timeout: deviceDiscoveryTimeout);
|
||||
if (device is! AndroidDevice) {
|
||||
throwToolExit('--${FlutterOptions.kDeviceUser} is only supported for Android');
|
||||
}
|
||||
@@ -164,70 +167,229 @@ class DriveCommand extends RunCommandBase {
|
||||
if (testFile == null) {
|
||||
throwToolExit(null);
|
||||
}
|
||||
if (await _fileSystem.type(testFile) != FileSystemEntityType.file) {
|
||||
throwToolExit('Test file not found: $testFile');
|
||||
}
|
||||
final Device device = await findTargetDevice(includeUnsupportedDevices: stringArg('use-application-binary') == null);
|
||||
|
||||
_device = await findTargetDevice(timeout: deviceDiscoveryTimeout);
|
||||
if (device == null) {
|
||||
throwToolExit(null);
|
||||
}
|
||||
|
||||
final bool web = device is WebServerDevice || device is ChromiumDevice;
|
||||
_flutterDriverFactory ??= FlutterDriverFactory(
|
||||
applicationPackageFactory: ApplicationPackageFactory.instance,
|
||||
logger: _logger,
|
||||
processUtils: globals.processUtils,
|
||||
dartSdkPath: globals.artifacts.getArtifactPath(Artifact.engineDartBinary),
|
||||
);
|
||||
final DriverService driverService = _flutterDriverFactory.createDriverService(web);
|
||||
if (await globals.fs.type(testFile) != FileSystemEntityType.file) {
|
||||
throwToolExit('Test file not found: $testFile');
|
||||
}
|
||||
|
||||
String observatoryUri;
|
||||
ResidentRunner residentRunner;
|
||||
final BuildInfo buildInfo = getBuildInfo();
|
||||
final DebuggingOptions debuggingOptions = createDebuggingOptions();
|
||||
final bool isWebPlatform = await device.targetPlatform == TargetPlatform.web_javascript;
|
||||
final File applicationBinary = stringArg('use-application-binary') == null
|
||||
? null
|
||||
: _fileSystem.file(stringArg('use-application-binary'));
|
||||
|
||||
await driverService.start(
|
||||
buildInfo,
|
||||
device,
|
||||
debuggingOptions,
|
||||
ipv6,
|
||||
: globals.fs.file(stringArg('use-application-binary'));
|
||||
final ApplicationPackage package = await applicationPackages.getPackageForPlatform(
|
||||
await device.targetPlatform,
|
||||
buildInfo: buildInfo,
|
||||
applicationBinary: applicationBinary,
|
||||
route: route,
|
||||
userIdentifier: userIdentifier,
|
||||
mainPath: targetFile,
|
||||
platformArgs: <String, Object>{
|
||||
if (traceStartup)
|
||||
'trace-startup': traceStartup,
|
||||
if (web)
|
||||
'--no-launch-chrome': true,
|
||||
);
|
||||
if (argResults['use-existing-app'] == null) {
|
||||
globals.printStatus('Starting application: $targetFile');
|
||||
|
||||
if (buildInfo.isRelease && !isWebPlatform) {
|
||||
// This is because we need VM service to be able to drive the app.
|
||||
// For Flutter Web, testing in release mode is allowed.
|
||||
throwToolExit(
|
||||
'Flutter Driver (non-web) does not support running in release mode.\n'
|
||||
'\n'
|
||||
'Use --profile mode for testing application performance.\n'
|
||||
'Use --debug (default) mode for testing correctness (with assertions).'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
final int testResult = await driverService.startTest(
|
||||
testFile,
|
||||
stringsArg('test-arguments'),
|
||||
<String, String>{},
|
||||
chromeBinary: stringArg('chrome-binary'),
|
||||
headless: boolArg('headless'),
|
||||
browserDimension: stringArg('browser-dimension').split(','),
|
||||
browserName: stringArg('browser-name'),
|
||||
driverPort: stringArg('driver-port') != null
|
||||
? int.tryParse(stringArg('driver-port'))
|
||||
: null,
|
||||
androidEmulator: boolArg('android-emulator'),
|
||||
);
|
||||
Uri webUri;
|
||||
|
||||
if (boolArg('keep-app-running') ?? (argResults['use-existing-app'] != null)) {
|
||||
_logger.printStatus('Leaving the application running.');
|
||||
if (isWebPlatform) {
|
||||
// Start Flutter web application for current test
|
||||
final FlutterProject flutterProject = FlutterProject.current();
|
||||
final FlutterDevice flutterDevice = await FlutterDevice.create(
|
||||
device,
|
||||
flutterProject: flutterProject,
|
||||
target: targetFile,
|
||||
buildInfo: buildInfo,
|
||||
platform: globals.platform,
|
||||
);
|
||||
residentRunner = webRunnerFactory.createWebRunner(
|
||||
flutterDevice,
|
||||
target: targetFile,
|
||||
flutterProject: flutterProject,
|
||||
ipv6: ipv6,
|
||||
debuggingOptions: getBuildInfo().isRelease ?
|
||||
DebuggingOptions.disabled(
|
||||
getBuildInfo(),
|
||||
port: stringArg('web-port')
|
||||
)
|
||||
: DebuggingOptions.enabled(
|
||||
getBuildInfo(),
|
||||
port: stringArg('web-port'),
|
||||
disablePortPublication: disablePortPublication,
|
||||
),
|
||||
stayResident: false,
|
||||
urlTunneller: null,
|
||||
);
|
||||
final Completer<void> appStartedCompleter = Completer<void>.sync();
|
||||
final int result = await residentRunner.run(
|
||||
appStartedCompleter: appStartedCompleter,
|
||||
route: route,
|
||||
);
|
||||
if (result != 0) {
|
||||
throwToolExit(null, exitCode: result);
|
||||
}
|
||||
// Wait until the app is started.
|
||||
await appStartedCompleter.future;
|
||||
webUri = residentRunner.uri;
|
||||
}
|
||||
|
||||
// Attempt to launch the application up to 3 times, to validate whether it
|
||||
// is possible to reduce flakiness by hardnening the launch code.
|
||||
int attempt = 0;
|
||||
LaunchResult result;
|
||||
while (attempt < 3) {
|
||||
// On attempts past 1, assume the application is built correctly and re-use it.
|
||||
result = await appStarter(this, webUri, package, applicationBinary != null || attempt > 0);
|
||||
if (result != null) {
|
||||
break;
|
||||
}
|
||||
attempt += 1;
|
||||
globals.printError('Application failed to start on attempt: $attempt');
|
||||
}
|
||||
if (result == null) {
|
||||
throwToolExit('Application failed to start. Will not run test. Quitting.', exitCode: 1);
|
||||
}
|
||||
observatoryUri = result.observatoryUri.toString();
|
||||
// TODO(bkonyi): add web support (https://github.com/flutter/flutter/issues/61259)
|
||||
if (!isWebPlatform && !disableDds) {
|
||||
try {
|
||||
// If there's another flutter_tools instance still connected to the target
|
||||
// application, DDS will already be running remotely and this call will fail.
|
||||
// We can ignore this and continue to use the remote DDS instance.
|
||||
await device.dds.startDartDevelopmentService(
|
||||
Uri.parse(observatoryUri),
|
||||
ddsPort,
|
||||
ipv6,
|
||||
disableServiceAuthCodes,
|
||||
);
|
||||
observatoryUri = device.dds.uri.toString();
|
||||
} on dds.DartDevelopmentServiceException catch(_) {
|
||||
globals.printTrace('Note: DDS is already connected to $observatoryUri.');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final File skslFile = stringArg('write-sksl-on-exit') != null
|
||||
? _fileSystem.file(stringArg('write-sksl-on-exit'))
|
||||
: null;
|
||||
await driverService.stop(userIdentifier: userIdentifier, writeSkslOnExit: skslFile);
|
||||
globals.printStatus('Will connect to already running application instance.');
|
||||
observatoryUri = stringArg('use-existing-app');
|
||||
}
|
||||
if (testResult != 0) {
|
||||
return FlutterCommandResult.fail();
|
||||
|
||||
final Map<String, String> environment = <String, String>{
|
||||
'VM_SERVICE_URL': observatoryUri,
|
||||
};
|
||||
|
||||
async_io.WebDriver driver;
|
||||
// For web device, WebDriver session will be launched beforehand
|
||||
// so that FlutterDriver can reuse it.
|
||||
if (isWebPlatform) {
|
||||
final Browser browser = _browserNameToEnum(
|
||||
argResults['browser-name'].toString());
|
||||
final String driverPort = argResults['driver-port'].toString();
|
||||
// start WebDriver
|
||||
try {
|
||||
driver = await _createDriver(
|
||||
driverPort,
|
||||
browser,
|
||||
argResults['headless'].toString() == 'true',
|
||||
stringArg('chrome-binary'),
|
||||
);
|
||||
} on Exception catch (ex) {
|
||||
throwToolExit(
|
||||
'Unable to start WebDriver Session for Flutter for Web testing. \n'
|
||||
'Make sure you have the correct WebDriver Server running at $driverPort. \n'
|
||||
'Make sure the WebDriver Server matches option --browser-name. \n'
|
||||
'$ex'
|
||||
);
|
||||
}
|
||||
|
||||
final bool isAndroidChrome = browser == Browser.androidChrome;
|
||||
final bool useEmulator = argResults['android-emulator'] as bool;
|
||||
// set window size
|
||||
// for android chrome, skip such action
|
||||
if (!isAndroidChrome) {
|
||||
final List<String> dimensions = argResults['browser-dimension'].split(
|
||||
',') as List<String>;
|
||||
assert(dimensions.length == 2);
|
||||
int x, y;
|
||||
try {
|
||||
x = int.parse(dimensions[0]);
|
||||
y = int.parse(dimensions[1]);
|
||||
} on FormatException catch (ex) {
|
||||
throwToolExit('''
|
||||
Dimension provided to --browser-dimension is invalid:
|
||||
$ex
|
||||
''');
|
||||
}
|
||||
final async_io.Window window = await driver.window;
|
||||
await window.setLocation(const math.Point<int>(0, 0));
|
||||
await window.setSize(math.Rectangle<int>(0, 0, x, y));
|
||||
}
|
||||
|
||||
// add driver info to environment variables
|
||||
environment.addAll(<String, String> {
|
||||
'DRIVER_SESSION_ID': driver.id,
|
||||
'DRIVER_SESSION_URI': driver.uri.toString(),
|
||||
'DRIVER_SESSION_SPEC': driver.spec.toString(),
|
||||
'DRIVER_SESSION_CAPABILITIES': json.encode(driver.capabilities),
|
||||
'SUPPORT_TIMELINE_ACTION': (browser == Browser.chrome).toString(),
|
||||
'FLUTTER_WEB_TEST': 'true',
|
||||
'ANDROID_CHROME_ON_EMULATOR': (isAndroidChrome && useEmulator).toString(),
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await testRunner(
|
||||
<String>[
|
||||
if (buildInfo.dartExperiments.isNotEmpty)
|
||||
'--enable-experiment=${buildInfo.dartExperiments.join(',')}',
|
||||
if (buildInfo.nullSafetyMode == NullSafetyMode.sound)
|
||||
'--sound-null-safety',
|
||||
if (buildInfo.nullSafetyMode == NullSafetyMode.unsound)
|
||||
'--no-sound-null-safety',
|
||||
testFile,
|
||||
],
|
||||
environment,
|
||||
);
|
||||
} on Exception catch (error, stackTrace) {
|
||||
if (error is ToolExit) {
|
||||
rethrow;
|
||||
}
|
||||
throw Exception('Unable to run test: $error\n$stackTrace');
|
||||
} finally {
|
||||
await residentRunner?.exit();
|
||||
await driver?.quit();
|
||||
if (stringArg('write-sksl-on-exit') != null) {
|
||||
final File outputFile = globals.fs.file(stringArg('write-sksl-on-exit'));
|
||||
final vm_service.VmService vmService = await connectToVmService(
|
||||
Uri.parse(observatoryUri),
|
||||
);
|
||||
final FlutterView flutterView = (await vmService.getFlutterViews()).first;
|
||||
final Map<String, Object> result = await vmService.getSkSLs(
|
||||
viewId: flutterView.id
|
||||
);
|
||||
await sharedSkSlWriter(_device, result, outputFile: outputFile);
|
||||
}
|
||||
if (boolArg('keep-app-running') ?? (argResults['use-existing-app'] != null)) {
|
||||
globals.printStatus('Leaving the application running.');
|
||||
} else {
|
||||
globals.printStatus('Stopping application instance.');
|
||||
await appStopper(this, package);
|
||||
}
|
||||
|
||||
await device?.dispose();
|
||||
}
|
||||
|
||||
return FlutterCommandResult.success();
|
||||
}
|
||||
|
||||
@@ -238,28 +400,28 @@ class DriveCommand extends RunCommandBase {
|
||||
|
||||
// If the --driver argument wasn't provided, then derive the value from
|
||||
// the target file.
|
||||
String appFile = _fileSystem.path.normalize(targetFile);
|
||||
String appFile = globals.fs.path.normalize(targetFile);
|
||||
|
||||
// This command extends `flutter run` and therefore CWD == package dir
|
||||
final String packageDir = _fileSystem.currentDirectory.path;
|
||||
final String packageDir = globals.fs.currentDirectory.path;
|
||||
|
||||
// Make appFile path relative to package directory because we are looking
|
||||
// for the corresponding test file relative to it.
|
||||
if (!_fileSystem.path.isRelative(appFile)) {
|
||||
if (!_fileSystem.path.isWithin(packageDir, appFile)) {
|
||||
_logger.printError(
|
||||
if (!globals.fs.path.isRelative(appFile)) {
|
||||
if (!globals.fs.path.isWithin(packageDir, appFile)) {
|
||||
globals.printError(
|
||||
'Application file $appFile is outside the package directory $packageDir'
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
appFile = _fileSystem.path.relative(appFile, from: packageDir);
|
||||
appFile = globals.fs.path.relative(appFile, from: packageDir);
|
||||
}
|
||||
|
||||
final List<String> parts = _fileSystem.path.split(appFile);
|
||||
final List<String> parts = globals.fs.path.split(appFile);
|
||||
|
||||
if (parts.length < 2) {
|
||||
_logger.printError(
|
||||
globals.printError(
|
||||
'Application file $appFile must reside in one of the sub-directories '
|
||||
'of the package structure, not in the root directory.'
|
||||
);
|
||||
@@ -269,8 +431,277 @@ class DriveCommand extends RunCommandBase {
|
||||
// Look for the test file inside `test_driver/` matching the sub-path, e.g.
|
||||
// if the application is `lib/foo/bar.dart`, the test file is expected to
|
||||
// be `test_driver/foo/bar_test.dart`.
|
||||
final String pathWithNoExtension = _fileSystem.path.withoutExtension(_fileSystem.path.joinAll(
|
||||
final String pathWithNoExtension = globals.fs.path.withoutExtension(globals.fs.path.joinAll(
|
||||
<String>[packageDir, 'test_driver', ...parts.skip(1)]));
|
||||
return '${pathWithNoExtension}_test${_fileSystem.path.extension(appFile)}';
|
||||
return '${pathWithNoExtension}_test${globals.fs.path.extension(appFile)}';
|
||||
}
|
||||
}
|
||||
|
||||
Future<Device> findTargetDevice({ @required Duration timeout }) async {
|
||||
final DeviceManager deviceManager = globals.deviceManager;
|
||||
final List<Device> devices = await deviceManager.findTargetDevices(null, timeout: timeout);
|
||||
|
||||
if (deviceManager.hasSpecifiedDeviceId) {
|
||||
if (devices.isEmpty) {
|
||||
globals.printStatus("No devices found with name or id matching '${deviceManager.specifiedDeviceId}'");
|
||||
return null;
|
||||
}
|
||||
if (devices.length > 1) {
|
||||
globals.printStatus("Found ${devices.length} devices with name or id matching '${deviceManager.specifiedDeviceId}':");
|
||||
await Device.printDevices(devices, globals.logger);
|
||||
return null;
|
||||
}
|
||||
return devices.first;
|
||||
}
|
||||
|
||||
if (devices.isEmpty) {
|
||||
globals.printError('No devices found.');
|
||||
return null;
|
||||
} else if (devices.length > 1) {
|
||||
globals.printStatus('Found multiple connected devices:');
|
||||
await Device.printDevices(devices, globals.logger);
|
||||
}
|
||||
globals.printStatus('Using device ${devices.first.name}.');
|
||||
return devices.first;
|
||||
}
|
||||
|
||||
/// Starts the application on the device given command configuration.
|
||||
typedef AppStarter = Future<LaunchResult> Function(DriveCommand command, Uri webUri, ApplicationPackage applicationPackage, bool prebuiltApplication);
|
||||
|
||||
AppStarter appStarter = _startApp; // (mutable for testing)
|
||||
void restoreAppStarter() {
|
||||
appStarter = _startApp;
|
||||
}
|
||||
|
||||
Future<LaunchResult> _startApp(
|
||||
DriveCommand command,
|
||||
Uri webUri,
|
||||
ApplicationPackage applicationPackage,
|
||||
bool prebuiltApplication,
|
||||
) async {
|
||||
final String mainPath = findMainDartFile(command.targetFile);
|
||||
if (await globals.fs.type(mainPath) != FileSystemEntityType.file) {
|
||||
globals.printError('Tried to run $mainPath, but that file does not exist.');
|
||||
return null;
|
||||
}
|
||||
|
||||
globals.printTrace('Stopping previously running application, if any.');
|
||||
await appStopper(command, applicationPackage);
|
||||
|
||||
|
||||
final Map<String, dynamic> platformArgs = <String, dynamic>{};
|
||||
if (command.traceStartup) {
|
||||
platformArgs['trace-startup'] = command.traceStartup;
|
||||
}
|
||||
|
||||
if (webUri != null) {
|
||||
platformArgs['uri'] = webUri.toString();
|
||||
if (!command.getBuildInfo().isDebug) {
|
||||
// For web device, startApp will be triggered twice
|
||||
// and it will error out for chrome the second time.
|
||||
platformArgs['no-launch-chrome'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
globals.printTrace('Starting application.');
|
||||
|
||||
// Forward device log messages to the terminal window running the "drive" command.
|
||||
final DeviceLogReader logReader = await command.device.getLogReader(app: applicationPackage);
|
||||
command._deviceLogSubscription = logReader
|
||||
.logLines
|
||||
.listen(globals.printStatus);
|
||||
|
||||
final LaunchResult result = await command.device.startApp(
|
||||
applicationPackage,
|
||||
mainPath: mainPath,
|
||||
route: command.route,
|
||||
debuggingOptions: DebuggingOptions.enabled(
|
||||
command.getBuildInfo(),
|
||||
startPaused: true,
|
||||
hostVmServicePort: webUri != null ? command.hostVmservicePort : 0,
|
||||
disablePortPublication: command.disablePortPublication,
|
||||
ddsPort: command.ddsPort,
|
||||
verboseSystemLogs: command.verboseSystemLogs,
|
||||
cacheSkSL: command.cacheSkSL,
|
||||
dumpSkpOnShaderCompilation: command.dumpSkpOnShaderCompilation,
|
||||
purgePersistentCache: command.purgePersistentCache,
|
||||
),
|
||||
platformArgs: platformArgs,
|
||||
userIdentifier: command.userIdentifier,
|
||||
prebuiltApplication: prebuiltApplication,
|
||||
);
|
||||
|
||||
if (!result.started) {
|
||||
await command._deviceLogSubscription.cancel();
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Runs driver tests.
|
||||
typedef TestRunner = Future<void> Function(List<String> testArgs, Map<String, String> environment);
|
||||
TestRunner testRunner = _runTests;
|
||||
void restoreTestRunner() {
|
||||
testRunner = _runTests;
|
||||
}
|
||||
|
||||
Future<void> _runTests(List<String> testArgs, Map<String, String> environment) async {
|
||||
globals.printTrace('Running driver tests.');
|
||||
|
||||
globalPackagesPath = globals.fs.path.normalize(globals.fs.path.absolute(globalPackagesPath));
|
||||
final int result = await globals.processUtils.stream(
|
||||
<String>[
|
||||
globals.artifacts.getArtifactPath(Artifact.engineDartBinary),
|
||||
...testArgs,
|
||||
'--packages=$globalPackagesPath',
|
||||
'-rexpanded',
|
||||
],
|
||||
environment: environment,
|
||||
);
|
||||
if (result != 0) {
|
||||
throwToolExit('Driver tests failed: $result', exitCode: result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Stops the application.
|
||||
typedef AppStopper = Future<bool> Function(DriveCommand command, ApplicationPackage applicationPackage);
|
||||
AppStopper appStopper = _stopApp;
|
||||
void restoreAppStopper() {
|
||||
appStopper = _stopApp;
|
||||
}
|
||||
|
||||
Future<bool> _stopApp(DriveCommand command, ApplicationPackage package) async {
|
||||
globals.printTrace('Stopping application.');
|
||||
final bool stopped = await command.device.stopApp(package, userIdentifier: command.userIdentifier);
|
||||
await command.device.uninstallApp(package);
|
||||
await command._deviceLogSubscription?.cancel();
|
||||
return stopped;
|
||||
}
|
||||
|
||||
/// A list of supported browsers.
|
||||
@visibleForTesting
|
||||
enum Browser {
|
||||
/// Chrome on Android: https://developer.chrome.com/multidevice/android/overview
|
||||
androidChrome,
|
||||
/// Chrome: https://www.google.com/chrome/
|
||||
chrome,
|
||||
/// Edge: https://www.microsoft.com/en-us/windows/microsoft-edge
|
||||
edge,
|
||||
/// Firefox: https://www.mozilla.org/en-US/firefox/
|
||||
firefox,
|
||||
/// Safari in iOS: https://www.apple.com/safari/
|
||||
iosSafari,
|
||||
/// Safari in macOS: https://www.apple.com/safari/
|
||||
safari,
|
||||
}
|
||||
|
||||
/// Converts [browserName] string to [Browser]
|
||||
Browser _browserNameToEnum(String browserName){
|
||||
switch (browserName) {
|
||||
case 'android-chrome': return Browser.androidChrome;
|
||||
case 'chrome': return Browser.chrome;
|
||||
case 'edge': return Browser.edge;
|
||||
case 'firefox': return Browser.firefox;
|
||||
case 'ios-safari': return Browser.iosSafari;
|
||||
case 'safari': return Browser.safari;
|
||||
}
|
||||
throw UnsupportedError('Browser $browserName not supported');
|
||||
}
|
||||
|
||||
Future<async_io.WebDriver> _createDriver(String driverPort, Browser browser, bool headless, String chromeBinary) async {
|
||||
return async_io.createDriver(
|
||||
uri: Uri.parse('http://localhost:$driverPort/'),
|
||||
desired: getDesiredCapabilities(browser, headless, chromeBinary),
|
||||
spec: async_io.WebDriverSpec.Auto
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns desired capabilities for given [browser], [headless] and
|
||||
/// [chromeBinary].
|
||||
@visibleForTesting
|
||||
Map<String, dynamic> getDesiredCapabilities(Browser browser, bool headless, [String chromeBinary]) {
|
||||
switch (browser) {
|
||||
case Browser.chrome:
|
||||
return <String, dynamic>{
|
||||
'acceptInsecureCerts': true,
|
||||
'browserName': 'chrome',
|
||||
'goog:loggingPrefs': <String, String>{ async_io.LogType.performance: 'ALL'},
|
||||
'chromeOptions': <String, dynamic>{
|
||||
if (chromeBinary != null)
|
||||
'binary': chromeBinary,
|
||||
'w3c': false,
|
||||
'args': <String>[
|
||||
'--bwsi',
|
||||
'--disable-background-timer-throttling',
|
||||
'--disable-default-apps',
|
||||
'--disable-extensions',
|
||||
'--disable-popup-blocking',
|
||||
'--disable-translate',
|
||||
'--no-default-browser-check',
|
||||
'--no-sandbox',
|
||||
'--no-first-run',
|
||||
if (headless) '--headless'
|
||||
],
|
||||
'perfLoggingPrefs': <String, String>{
|
||||
'traceCategories':
|
||||
'devtools.timeline,'
|
||||
'v8,blink.console,benchmark,blink,'
|
||||
'blink.user_timing'
|
||||
}
|
||||
},
|
||||
};
|
||||
break;
|
||||
case Browser.firefox:
|
||||
return <String, dynamic>{
|
||||
'acceptInsecureCerts': true,
|
||||
'browserName': 'firefox',
|
||||
'moz:firefoxOptions' : <String, dynamic>{
|
||||
'args': <String>[
|
||||
if (headless) '-headless'
|
||||
],
|
||||
'prefs': <String, dynamic>{
|
||||
'dom.file.createInChild': true,
|
||||
'dom.timeout.background_throttling_max_budget': -1,
|
||||
'media.autoplay.default': 0,
|
||||
'media.gmp-manager.url': '',
|
||||
'media.gmp-provider.enabled': false,
|
||||
'network.captive-portal-service.enabled': false,
|
||||
'security.insecure_field_warning.contextual.enabled': false,
|
||||
'test.currentTimeOffsetSeconds': 11491200
|
||||
},
|
||||
'log': <String, String>{'level': 'trace'}
|
||||
}
|
||||
};
|
||||
break;
|
||||
case Browser.edge:
|
||||
return <String, dynamic>{
|
||||
'acceptInsecureCerts': true,
|
||||
'browserName': 'edge',
|
||||
};
|
||||
break;
|
||||
case Browser.safari:
|
||||
return <String, dynamic>{
|
||||
'browserName': 'safari',
|
||||
};
|
||||
break;
|
||||
case Browser.iosSafari:
|
||||
return <String, dynamic>{
|
||||
'platformName': 'ios',
|
||||
'browserName': 'safari',
|
||||
'safari:useSimulator': true
|
||||
};
|
||||
case Browser.androidChrome:
|
||||
return <String, dynamic>{
|
||||
'browserName': 'chrome',
|
||||
'platformName': 'android',
|
||||
'goog:chromeOptions': <String, dynamic>{
|
||||
'androidPackage': 'com.android.chrome',
|
||||
'args': <String>['--disable-fullscreen']
|
||||
},
|
||||
};
|
||||
default:
|
||||
throw UnsupportedError('Browser $browser not supported.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
|
||||
import '../android/android_device.dart';
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
@@ -23,8 +25,8 @@ import '../tracing.dart';
|
||||
import '../web/web_runner.dart';
|
||||
import 'daemon.dart';
|
||||
|
||||
/// Shared logic between `flutter run` and `flutter drive` commands.
|
||||
abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
|
||||
// Used by run and drive commands.
|
||||
RunCommandBase({ bool verboseHelp = false }) {
|
||||
addBuildModeFlags(defaultToRelease: false, verboseHelp: verboseHelp);
|
||||
usesDartDefineOption();
|
||||
@@ -75,45 +77,6 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
|
||||
'this must be the path to an APK. For iOS applications, the path to an IPA. Other device types '
|
||||
'do not yet support prebuilt application binaries',
|
||||
valueHelp: 'path/to/app.apk',
|
||||
)
|
||||
..addFlag('start-paused',
|
||||
defaultsTo: startPausedDefault,
|
||||
help: 'Start in a paused mode and wait for a debugger to connect.',
|
||||
)
|
||||
..addOption('dart-flags',
|
||||
hide: !verboseHelp,
|
||||
help: 'Pass a list of comma separated flags to the Dart instance at '
|
||||
'application startup. Flags passed through this option must be '
|
||||
'present on the allowlist defined within the Flutter engine. If '
|
||||
'a disallowed flag is encountered, the process will be '
|
||||
'terminated immediately.\n\n'
|
||||
'This flag is not available on the stable channel and is only '
|
||||
'applied in debug and profile modes. This option should only '
|
||||
'be used for experiments and should not be used by typical users.'
|
||||
)
|
||||
..addFlag('endless-trace-buffer',
|
||||
negatable: false,
|
||||
help: 'Enable tracing to the endless tracer. This is useful when '
|
||||
'recording huge amounts of traces. If we need to use endless buffer to '
|
||||
'record startup traces, we can combine the ("--trace-startup"). '
|
||||
'For example, flutter run --trace-startup --endless-trace-buffer. ',
|
||||
)
|
||||
..addFlag('trace-systrace',
|
||||
negatable: false,
|
||||
help: 'Enable tracing to the system tracer. This is only useful on '
|
||||
'platforms where such a tracer is available (Android and Fuchsia).',
|
||||
)
|
||||
..addFlag('trace-skia',
|
||||
negatable: false,
|
||||
help: 'Enable tracing of Skia code. This is useful when debugging '
|
||||
'the raster thread (formerly known as the GPU thread). '
|
||||
'By default, Flutter will not log skia code.',
|
||||
)
|
||||
..addOption('trace-allowlist',
|
||||
hide: true,
|
||||
help: 'Filters out all trace events except those that are specified in '
|
||||
'this comma separated list of allowed prefixes.',
|
||||
valueHelp: 'foo,bar',
|
||||
);
|
||||
usesWebOptions(hide: !verboseHelp);
|
||||
usesTargetOption();
|
||||
@@ -133,71 +96,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
|
||||
bool get dumpSkpOnShaderCompilation => boolArg('dump-skp-on-shader-compilation');
|
||||
bool get purgePersistentCache => boolArg('purge-persistent-cache');
|
||||
bool get disableServiceAuthCodes => boolArg('disable-service-auth-codes');
|
||||
bool get runningWithPrebuiltApplication => argResults['use-application-binary'] != null;
|
||||
bool get trackWidgetCreation => boolArg('track-widget-creation');
|
||||
|
||||
/// Whether to start the application paused by default.
|
||||
bool get startPausedDefault;
|
||||
|
||||
String get route => stringArg('route');
|
||||
|
||||
String get traceAllowlist => stringArg('trace-allowlist');
|
||||
|
||||
/// Create a debugging options instance for the current `run` or `drive` invocation.
|
||||
DebuggingOptions createDebuggingOptions() {
|
||||
final BuildInfo buildInfo = getBuildInfo();
|
||||
final int browserDebugPort = featureFlags.isWebEnabled && argResults.wasParsed('web-browser-debug-port')
|
||||
? int.parse(stringArg('web-browser-debug-port'))
|
||||
: null;
|
||||
if (buildInfo.mode.isRelease) {
|
||||
return DebuggingOptions.disabled(
|
||||
buildInfo,
|
||||
hostname: featureFlags.isWebEnabled ? stringArg('web-hostname') : '',
|
||||
port: featureFlags.isWebEnabled ? stringArg('web-port') : '',
|
||||
webUseSseForDebugProxy: featureFlags.isWebEnabled && stringArg('web-server-debug-protocol') == 'sse',
|
||||
webUseSseForDebugBackend: featureFlags.isWebEnabled && stringArg('web-server-debug-backend-protocol') == 'sse',
|
||||
webEnableExposeUrl: featureFlags.isWebEnabled && boolArg('web-allow-expose-url'),
|
||||
webRunHeadless: featureFlags.isWebEnabled && boolArg('web-run-headless'),
|
||||
webBrowserDebugPort: browserDebugPort,
|
||||
);
|
||||
} else {
|
||||
return DebuggingOptions.enabled(
|
||||
buildInfo,
|
||||
startPaused: boolArg('start-paused'),
|
||||
disableServiceAuthCodes: boolArg('disable-service-auth-codes'),
|
||||
disableDds: boolArg('disable-dds'),
|
||||
dartFlags: stringArg('dart-flags') ?? '',
|
||||
useTestFonts: argParser.options.containsKey('use-test-fonts') && boolArg('use-test-fonts'),
|
||||
enableSoftwareRendering: argParser.options.containsKey('enable-software-rendering') && boolArg('enable-software-rendering'),
|
||||
skiaDeterministicRendering: argParser.options.containsKey('skia-deterministic-rendering') && boolArg('skia-deterministic-rendering'),
|
||||
traceSkia: boolArg('trace-skia'),
|
||||
traceAllowlist: traceAllowlist,
|
||||
traceSystrace: boolArg('trace-systrace'),
|
||||
endlessTraceBuffer: boolArg('endless-trace-buffer'),
|
||||
dumpSkpOnShaderCompilation: dumpSkpOnShaderCompilation,
|
||||
cacheSkSL: cacheSkSL,
|
||||
purgePersistentCache: purgePersistentCache,
|
||||
deviceVmServicePort: deviceVmservicePort,
|
||||
hostVmServicePort: hostVmservicePort,
|
||||
disablePortPublication: disablePortPublication,
|
||||
ddsPort: ddsPort,
|
||||
verboseSystemLogs: boolArg('verbose-system-logs'),
|
||||
hostname: featureFlags.isWebEnabled ? stringArg('web-hostname') : '',
|
||||
port: featureFlags.isWebEnabled ? stringArg('web-port') : '',
|
||||
webUseSseForDebugProxy: featureFlags.isWebEnabled && stringArg('web-server-debug-protocol') == 'sse',
|
||||
webUseSseForDebugBackend: featureFlags.isWebEnabled && stringArg('web-server-debug-backend-protocol') == 'sse',
|
||||
webEnableExposeUrl: featureFlags.isWebEnabled && boolArg('web-allow-expose-url'),
|
||||
webRunHeadless: featureFlags.isWebEnabled && boolArg('web-run-headless'),
|
||||
webBrowserDebugPort: browserDebugPort,
|
||||
webEnableExpressionEvaluation: featureFlags.isWebEnabled && boolArg('web-enable-expression-evaluation'),
|
||||
vmserviceOutFile: stringArg('vmservice-out-file'),
|
||||
fastStart: argParser.options.containsKey('fast-start')
|
||||
&& boolArg('fast-start')
|
||||
&& !runningWithPrebuiltApplication,
|
||||
nullAssertions: boolArg('null-assertions'),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RunCommand extends RunCommandBase {
|
||||
@@ -212,6 +111,10 @@ class RunCommand extends RunCommandBase {
|
||||
// without needing to know the port.
|
||||
addPublishPort(enabledByDefault: true, verboseHelp: verboseHelp);
|
||||
argParser
|
||||
..addFlag('start-paused',
|
||||
negatable: false,
|
||||
help: 'Start in a paused mode and wait for a debugger to connect.',
|
||||
)
|
||||
..addFlag('enable-software-rendering',
|
||||
negatable: false,
|
||||
help: 'Enable rendering using the Skia software backend. '
|
||||
@@ -224,6 +127,35 @@ class RunCommand extends RunCommandBase {
|
||||
help: 'When combined with --enable-software-rendering, provides 100% '
|
||||
'deterministic Skia rendering.',
|
||||
)
|
||||
..addFlag('trace-skia',
|
||||
negatable: false,
|
||||
help: 'Enable tracing of Skia code. This is useful when debugging '
|
||||
'the raster thread (formerly known as the GPU thread). '
|
||||
'By default, Flutter will not log skia code.',
|
||||
)
|
||||
..addOption('trace-whitelist',
|
||||
hide: true,
|
||||
help: '(deprecated) Use --trace-allowlist instead',
|
||||
valueHelp: 'foo,bar',
|
||||
)
|
||||
..addOption('trace-allowlist',
|
||||
hide: true,
|
||||
help: 'Filters out all trace events except those that are specified in '
|
||||
'this comma separated list of allowed prefixes.',
|
||||
valueHelp: 'foo,bar',
|
||||
)
|
||||
..addFlag('endless-trace-buffer',
|
||||
negatable: false,
|
||||
help: 'Enable tracing to the endless tracer. This is useful when '
|
||||
'recording huge amounts of traces. If we need to use endless buffer to '
|
||||
'record startup traces, we can combine the ("--trace-startup"). '
|
||||
'For example, flutter run --trace-startup --endless-trace-buffer. ',
|
||||
)
|
||||
..addFlag('trace-systrace',
|
||||
negatable: false,
|
||||
help: 'Enable tracing to the system tracer. This is only useful on '
|
||||
'platforms where such a tracer is available (Android and Fuchsia).',
|
||||
)
|
||||
..addFlag('await-first-frame-when-tracing',
|
||||
defaultsTo: true,
|
||||
help: 'Whether to wait for the first frame when tracing startup ("--trace-startup"), '
|
||||
@@ -244,6 +176,16 @@ class RunCommand extends RunCommandBase {
|
||||
defaultsTo: true,
|
||||
help: 'If necessary, build the app before running.',
|
||||
)
|
||||
..addOption('dart-flags',
|
||||
hide: !verboseHelp,
|
||||
help: 'Pass a list of comma separated flags to the Dart instance at '
|
||||
'application startup. Flags passed through this option must be '
|
||||
'present on the allowlist defined within the Flutter engine. If '
|
||||
'a disallowed flag is encountered, the process will be '
|
||||
'terminated immediately.\n\n'
|
||||
'This flag is not available on the stable channel and is only '
|
||||
'applied in debug and profile modes. This option should only '
|
||||
'be used for experiments and should not be used by typical users.')
|
||||
..addOption('project-root',
|
||||
hide: !verboseHelp,
|
||||
help: 'Specify the project root directory.',
|
||||
@@ -306,9 +248,6 @@ class RunCommand extends RunCommandBase {
|
||||
|
||||
String get userIdentifier => stringArg(FlutterOptions.kDeviceUser);
|
||||
|
||||
@override
|
||||
bool get startPausedDefault => false;
|
||||
|
||||
@override
|
||||
Future<String> get usagePath async {
|
||||
final String command = await super.usagePath;
|
||||
@@ -403,6 +342,9 @@ class RunCommand extends RunCommandBase {
|
||||
return getBuildInfo().isDebug && shouldUseHotMode;
|
||||
}
|
||||
|
||||
bool get runningWithPrebuiltApplication =>
|
||||
argResults['use-application-binary'] != null;
|
||||
|
||||
bool get stayResident => boolArg('resident');
|
||||
bool get awaitFirstFrameWhenTracing => boolArg('await-first-frame-when-tracing');
|
||||
|
||||
@@ -430,6 +372,73 @@ class RunCommand extends RunCommandBase {
|
||||
}
|
||||
}
|
||||
|
||||
String get _traceAllowlist {
|
||||
final String deprecatedValue = stringArg('trace-whitelist');
|
||||
if (deprecatedValue != null) {
|
||||
globals.printError('--trace-whitelist has been deprecated, use --trace-allowlist instead');
|
||||
}
|
||||
return stringArg('trace-allowlist') ?? deprecatedValue;
|
||||
}
|
||||
|
||||
DebuggingOptions _createDebuggingOptions() {
|
||||
final BuildInfo buildInfo = getBuildInfo();
|
||||
final int browserDebugPort = featureFlags.isWebEnabled && argResults.wasParsed('web-browser-debug-port')
|
||||
? int.parse(stringArg('web-browser-debug-port'))
|
||||
: null;
|
||||
if (buildInfo.mode.isRelease) {
|
||||
return DebuggingOptions.disabled(
|
||||
buildInfo,
|
||||
initializePlatform: boolArg('web-initialize-platform'),
|
||||
hostname: featureFlags.isWebEnabled ? stringArg('web-hostname') : '',
|
||||
port: featureFlags.isWebEnabled ? stringArg('web-port') : '',
|
||||
webUseSseForDebugProxy: featureFlags.isWebEnabled && stringArg('web-server-debug-protocol') == 'sse',
|
||||
webUseSseForDebugBackend: featureFlags.isWebEnabled && stringArg('web-server-debug-backend-protocol') == 'sse',
|
||||
webEnableExposeUrl: featureFlags.isWebEnabled && boolArg('web-allow-expose-url'),
|
||||
webRunHeadless: featureFlags.isWebEnabled && boolArg('web-run-headless'),
|
||||
webBrowserDebugPort: browserDebugPort,
|
||||
);
|
||||
} else {
|
||||
return DebuggingOptions.enabled(
|
||||
buildInfo,
|
||||
startPaused: boolArg('start-paused'),
|
||||
disableServiceAuthCodes: boolArg('disable-service-auth-codes'),
|
||||
disableDds: boolArg('disable-dds'),
|
||||
dartFlags: stringArg('dart-flags') ?? '',
|
||||
useTestFonts: boolArg('use-test-fonts'),
|
||||
enableSoftwareRendering: boolArg('enable-software-rendering'),
|
||||
skiaDeterministicRendering: boolArg('skia-deterministic-rendering'),
|
||||
traceSkia: boolArg('trace-skia'),
|
||||
traceAllowlist: _traceAllowlist,
|
||||
traceSystrace: boolArg('trace-systrace'),
|
||||
endlessTraceBuffer: boolArg('endless-trace-buffer'),
|
||||
dumpSkpOnShaderCompilation: dumpSkpOnShaderCompilation,
|
||||
cacheSkSL: cacheSkSL,
|
||||
purgePersistentCache: purgePersistentCache,
|
||||
deviceVmServicePort: deviceVmservicePort,
|
||||
hostVmServicePort: hostVmservicePort,
|
||||
disablePortPublication: disablePortPublication,
|
||||
ddsPort: ddsPort,
|
||||
verboseSystemLogs: boolArg('verbose-system-logs'),
|
||||
initializePlatform: boolArg('web-initialize-platform'),
|
||||
hostname: featureFlags.isWebEnabled ? stringArg('web-hostname') : '',
|
||||
port: featureFlags.isWebEnabled ? stringArg('web-port') : '',
|
||||
webUseSseForDebugProxy: featureFlags.isWebEnabled && stringArg('web-server-debug-protocol') == 'sse',
|
||||
webUseSseForDebugBackend: featureFlags.isWebEnabled && stringArg('web-server-debug-backend-protocol') == 'sse',
|
||||
webEnableExposeUrl: featureFlags.isWebEnabled && boolArg('web-allow-expose-url'),
|
||||
webRunHeadless: featureFlags.isWebEnabled && boolArg('web-run-headless'),
|
||||
webBrowserDebugPort: browserDebugPort,
|
||||
webEnableExpressionEvaluation: featureFlags.isWebEnabled && boolArg('web-enable-expression-evaluation'),
|
||||
vmserviceOutFile: stringArg('vmservice-out-file'),
|
||||
// Allow forcing fast-start to off to prevent doing more work on devices that
|
||||
// don't support it.
|
||||
fastStart: boolArg('fast-start')
|
||||
&& !runningWithPrebuiltApplication
|
||||
&& devices.every((Device device) => device.supportsFastStart),
|
||||
nullAssertions: boolArg('null-assertions'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
// Enable hot mode by default if `--no-hot` was not passed and we are in
|
||||
@@ -455,11 +464,11 @@ class RunCommand extends RunCommandBase {
|
||||
final String applicationBinaryPath = stringArg('use-application-binary');
|
||||
app = await daemon.appDomain.startApp(
|
||||
devices.first, globals.fs.currentDirectory.path, targetFile, route,
|
||||
createDebuggingOptions(), hotMode,
|
||||
_createDebuggingOptions(), hotMode,
|
||||
applicationBinary: applicationBinaryPath == null
|
||||
? null
|
||||
: globals.fs.file(applicationBinaryPath),
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
trackWidgetCreation: boolArg('track-widget-creation'),
|
||||
projectRootPath: stringArg('project-root'),
|
||||
packagesFilePath: globalResults['packages'] as String,
|
||||
dillOutputPath: stringArg('output-dill'),
|
||||
@@ -482,6 +491,11 @@ class RunCommand extends RunCommandBase {
|
||||
}
|
||||
globals.terminal.usesTerminalUi = true;
|
||||
|
||||
if (argResults['dart-flags'] != null && !globals.flutterVersion.isMaster) {
|
||||
throw UsageException('--dart-flags is not available on the stable '
|
||||
'channel.', null);
|
||||
}
|
||||
|
||||
final BuildMode buildMode = getBuildMode();
|
||||
for (final Device device in devices) {
|
||||
if (!await device.supportsRuntimeMode(buildMode)) {
|
||||
@@ -520,6 +534,7 @@ class RunCommand extends RunCommandBase {
|
||||
for (final Device device in devices)
|
||||
await FlutterDevice.create(
|
||||
device,
|
||||
flutterProject: flutterProject,
|
||||
fileSystemRoots: stringsArg('filesystem-root'),
|
||||
fileSystemScheme: stringArg('filesystem-scheme'),
|
||||
experimentalFlags: expFlags,
|
||||
@@ -541,7 +556,7 @@ class RunCommand extends RunCommandBase {
|
||||
runner = HotRunner(
|
||||
flutterDevices,
|
||||
target: targetFile,
|
||||
debuggingOptions: createDebuggingOptions(),
|
||||
debuggingOptions: _createDebuggingOptions(),
|
||||
benchmarkMode: boolArg('benchmark'),
|
||||
applicationBinary: applicationBinaryPath == null
|
||||
? null
|
||||
@@ -557,7 +572,7 @@ class RunCommand extends RunCommandBase {
|
||||
target: targetFile,
|
||||
flutterProject: flutterProject,
|
||||
ipv6: ipv6,
|
||||
debuggingOptions: createDebuggingOptions(),
|
||||
debuggingOptions: _createDebuggingOptions(),
|
||||
stayResident: stayResident,
|
||||
urlTunneller: null,
|
||||
);
|
||||
@@ -565,7 +580,7 @@ class RunCommand extends RunCommandBase {
|
||||
runner = ColdRunner(
|
||||
flutterDevices,
|
||||
target: targetFile,
|
||||
debuggingOptions: createDebuggingOptions(),
|
||||
debuggingOptions: _createDebuggingOptions(),
|
||||
traceStartup: traceStartup,
|
||||
awaitFirstFrameWhenTracing: awaitFirstFrameWhenTracing,
|
||||
applicationBinary: applicationBinaryPath == null
|
||||
|
||||
@@ -847,6 +847,7 @@ class DebuggingOptions {
|
||||
this.disablePortPublication = false,
|
||||
this.deviceVmServicePort,
|
||||
this.ddsPort,
|
||||
this.initializePlatform = true,
|
||||
this.hostname,
|
||||
this.port,
|
||||
this.webEnableExposeUrl,
|
||||
@@ -861,6 +862,7 @@ class DebuggingOptions {
|
||||
}) : debuggingEnabled = true;
|
||||
|
||||
DebuggingOptions.disabled(this.buildInfo, {
|
||||
this.initializePlatform = true,
|
||||
this.port,
|
||||
this.hostname,
|
||||
this.webEnableExposeUrl,
|
||||
@@ -911,6 +913,8 @@ class DebuggingOptions {
|
||||
final bool purgePersistentCache;
|
||||
final bool useTestFonts;
|
||||
final bool verboseSystemLogs;
|
||||
/// Whether to invoke webOnlyInitializePlatform in Flutter for web.
|
||||
final bool initializePlatform;
|
||||
final int hostVmServicePort;
|
||||
final int deviceVmServicePort;
|
||||
final bool disablePortPublication;
|
||||
|
||||
@@ -1,245 +0,0 @@
|
||||
// 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:dds/dds.dart' as dds;
|
||||
import 'package:file/file.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
||||
|
||||
import '../application_package.dart';
|
||||
import '../base/common.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../base/process.dart';
|
||||
import '../build_info.dart';
|
||||
import '../device.dart';
|
||||
import '../vmservice.dart';
|
||||
import 'web_driver_service.dart';
|
||||
|
||||
class FlutterDriverFactory {
|
||||
FlutterDriverFactory({
|
||||
@required ApplicationPackageFactory applicationPackageFactory,
|
||||
@required Logger logger,
|
||||
@required ProcessUtils processUtils,
|
||||
@required String dartSdkPath,
|
||||
}) : _applicationPackageFactory = applicationPackageFactory,
|
||||
_logger = logger,
|
||||
_processUtils = processUtils,
|
||||
_dartSdkPath = dartSdkPath;
|
||||
|
||||
final ApplicationPackageFactory _applicationPackageFactory;
|
||||
final Logger _logger;
|
||||
final ProcessUtils _processUtils;
|
||||
final String _dartSdkPath;
|
||||
|
||||
/// Create a driver service for running `flutter drive`.
|
||||
DriverService createDriverService(bool web) {
|
||||
if (web) {
|
||||
return WebDriverService(
|
||||
processUtils: _processUtils,
|
||||
dartSdkPath: _dartSdkPath,
|
||||
);
|
||||
}
|
||||
return FlutterDriverService(
|
||||
logger: _logger,
|
||||
processUtils: _processUtils,
|
||||
dartSdkPath: _dartSdkPath,
|
||||
applicationPackageFactory: _applicationPackageFactory,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// An interface for the `flutter driver` integration test operations.
|
||||
abstract class DriverService {
|
||||
/// Install and launch the application for the provided [device].
|
||||
Future<void> start(
|
||||
BuildInfo buildInfo,
|
||||
Device device,
|
||||
DebuggingOptions debuggingOptions,
|
||||
bool ipv6, {
|
||||
File applicationBinary,
|
||||
String route,
|
||||
String userIdentifier,
|
||||
String mainPath,
|
||||
Map<String, Object> platformArgs = const <String, Object>{},
|
||||
});
|
||||
|
||||
/// Start the test file with the provided [arguments] and [environment], returning
|
||||
/// the test process exit code.
|
||||
Future<int> startTest(
|
||||
String testFile,
|
||||
List<String> arguments,
|
||||
Map<String, String> environment, {
|
||||
bool headless,
|
||||
String chromeBinary,
|
||||
String browserName,
|
||||
bool androidEmulator,
|
||||
int driverPort,
|
||||
List<String> browserDimension,
|
||||
});
|
||||
|
||||
/// Stop the running application and uninstall it from the device.
|
||||
///
|
||||
/// If [writeSkslOnExit] is non-null, will connect to the VM Service
|
||||
/// and write SkSL to the file. This is only supported on mobile and
|
||||
/// desktop devices.
|
||||
Future<void> stop({
|
||||
File writeSkslOnExit,
|
||||
String userIdentifier,
|
||||
});
|
||||
}
|
||||
|
||||
/// An implementation of the driver service that connects to mobile and desktop
|
||||
/// applications.
|
||||
class FlutterDriverService extends DriverService {
|
||||
FlutterDriverService({
|
||||
@required ApplicationPackageFactory applicationPackageFactory,
|
||||
@required Logger logger,
|
||||
@required ProcessUtils processUtils,
|
||||
@required String dartSdkPath,
|
||||
@visibleForTesting VMServiceConnector vmServiceConnector = connectToVmService,
|
||||
}) : _applicationPackageFactory = applicationPackageFactory,
|
||||
_logger = logger,
|
||||
_processUtils = processUtils,
|
||||
_dartSdkPath = dartSdkPath,
|
||||
_vmServiceConnector = vmServiceConnector;
|
||||
|
||||
static const int _kLaunchAttempts = 3;
|
||||
|
||||
final ApplicationPackageFactory _applicationPackageFactory;
|
||||
final Logger _logger;
|
||||
final ProcessUtils _processUtils;
|
||||
final String _dartSdkPath;
|
||||
final VMServiceConnector _vmServiceConnector;
|
||||
|
||||
Device _device;
|
||||
ApplicationPackage _applicationPackage;
|
||||
String _vmServiceUri;
|
||||
vm_service.VmService _vmService;
|
||||
|
||||
@override
|
||||
Future<void> start(
|
||||
BuildInfo buildInfo,
|
||||
Device device,
|
||||
DebuggingOptions debuggingOptions,
|
||||
bool ipv6, {
|
||||
File applicationBinary,
|
||||
String route,
|
||||
String userIdentifier,
|
||||
Map<String, Object> platformArgs = const <String, Object>{},
|
||||
String mainPath,
|
||||
}) async {
|
||||
if (buildInfo.isRelease) {
|
||||
throwToolExit(
|
||||
'Flutter Driver (non-web) does not support running in release mode.\n'
|
||||
'\n'
|
||||
'Use --profile mode for testing application performance.\n'
|
||||
'Use --debug (default) mode for testing correctness (with assertions).'
|
||||
);
|
||||
}
|
||||
_device = device;
|
||||
final TargetPlatform targetPlatform = await device.targetPlatform;
|
||||
_applicationPackage = await _applicationPackageFactory.getPackageForPlatform(
|
||||
targetPlatform,
|
||||
buildInfo: buildInfo,
|
||||
applicationBinary: applicationBinary,
|
||||
);
|
||||
int attempt = 0;
|
||||
LaunchResult result;
|
||||
bool prebuiltApplication = applicationBinary != null;
|
||||
while (attempt < _kLaunchAttempts) {
|
||||
result = await device.startApp(
|
||||
_applicationPackage,
|
||||
mainPath: mainPath,
|
||||
route: route,
|
||||
debuggingOptions: debuggingOptions,
|
||||
platformArgs: platformArgs,
|
||||
userIdentifier: userIdentifier,
|
||||
prebuiltApplication: prebuiltApplication,
|
||||
);
|
||||
if (result != null && result.started) {
|
||||
break;
|
||||
}
|
||||
// On attempts past 1, assume the application is built correctly and re-use it.
|
||||
attempt += 1;
|
||||
prebuiltApplication = true;
|
||||
_logger.printError('Application failed to start on attempt: $attempt');
|
||||
}
|
||||
if (result == null || !result.started) {
|
||||
throwToolExit('Application failed to start. Will not run test. Quitting.', exitCode: 1);
|
||||
}
|
||||
_vmServiceUri = result.observatoryUri.toString();
|
||||
try {
|
||||
await device.dds.startDartDevelopmentService(
|
||||
result.observatoryUri,
|
||||
debuggingOptions.ddsPort,
|
||||
ipv6,
|
||||
debuggingOptions.disableServiceAuthCodes,
|
||||
);
|
||||
_vmServiceUri = device.dds.uri.toString();
|
||||
} on dds.DartDevelopmentServiceException {
|
||||
// If there's another flutter_tools instance still connected to the target
|
||||
// application, DDS will already be running remotely and this call will fail.
|
||||
// This can be ignored to continue to use the existing remote DDS instance.
|
||||
}
|
||||
_vmService = await _vmServiceConnector(Uri.parse(_vmServiceUri), device: _device);
|
||||
final DeviceLogReader logReader = await device.getLogReader(app: _applicationPackage);
|
||||
logReader.logLines.listen(_logger.printStatus);
|
||||
|
||||
final vm_service.VM vm = await _vmService.getVM();
|
||||
logReader.appPid = vm.pid;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> startTest(
|
||||
String testFile,
|
||||
List<String> arguments,
|
||||
Map<String, String> environment, {
|
||||
bool headless,
|
||||
String chromeBinary,
|
||||
String browserName,
|
||||
bool androidEmulator,
|
||||
int driverPort,
|
||||
List<String> browserDimension,
|
||||
}) async {
|
||||
return _processUtils.stream(<String>[
|
||||
_dartSdkPath,
|
||||
...arguments,
|
||||
testFile,
|
||||
'-rexpanded',
|
||||
], environment: <String, String>{
|
||||
'VM_SERVICE_URL': _vmServiceUri,
|
||||
...environment,
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> stop({
|
||||
File writeSkslOnExit,
|
||||
String userIdentifier,
|
||||
}) async {
|
||||
if (writeSkslOnExit != null) {
|
||||
final FlutterView flutterView = (await _vmService.getFlutterViews()).first;
|
||||
final Map<String, Object> result = await _vmService.getSkSLs(
|
||||
viewId: flutterView.id
|
||||
);
|
||||
await sharedSkSlWriter(_device, result, outputFile: writeSkslOnExit, logger: _logger);
|
||||
}
|
||||
try {
|
||||
if (!await _device.stopApp(_applicationPackage, userIdentifier: userIdentifier)) {
|
||||
_logger.printError('Failed to stop app');
|
||||
}
|
||||
} on Exception catch (err) {
|
||||
_logger.printError('Failed to stop app due to unhandled error: $err');
|
||||
}
|
||||
|
||||
try {
|
||||
if (!await _device.uninstallApp(_applicationPackage, userIdentifier: userIdentifier)) {
|
||||
_logger.printError('Failed to uninstall app');
|
||||
}
|
||||
} on Exception catch (err) {
|
||||
_logger.printError('Failed to uninstall app due to unhandled error: $err');
|
||||
}
|
||||
await _device.dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,264 +0,0 @@
|
||||
// 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:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:webdriver/async_io.dart' as async_io;
|
||||
|
||||
import '../base/common.dart';
|
||||
import '../base/process.dart';
|
||||
import '../build_info.dart';
|
||||
import '../convert.dart';
|
||||
import '../device.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../resident_runner.dart';
|
||||
import '../web/web_runner.dart';
|
||||
import 'drive_service.dart';
|
||||
|
||||
/// An implementation of the driver service for web debug and release applications.
|
||||
class WebDriverService extends DriverService {
|
||||
WebDriverService({
|
||||
@required ProcessUtils processUtils,
|
||||
@required String dartSdkPath,
|
||||
}) : _processUtils = processUtils,
|
||||
_dartSdkPath = dartSdkPath;
|
||||
|
||||
final ProcessUtils _processUtils;
|
||||
final String _dartSdkPath;
|
||||
|
||||
ResidentRunner _residentRunner;
|
||||
Uri _webUri;
|
||||
|
||||
@override
|
||||
Future<void> start(
|
||||
BuildInfo buildInfo,
|
||||
Device device,
|
||||
DebuggingOptions debuggingOptions,
|
||||
bool ipv6, {
|
||||
File applicationBinary,
|
||||
String route,
|
||||
String userIdentifier,
|
||||
String mainPath,
|
||||
Map<String, Object> platformArgs = const <String, Object>{},
|
||||
}) async {
|
||||
final FlutterDevice flutterDevice = await FlutterDevice.create(
|
||||
device,
|
||||
target: mainPath,
|
||||
buildInfo: buildInfo,
|
||||
platform: globals.platform,
|
||||
);
|
||||
_residentRunner = webRunnerFactory.createWebRunner(
|
||||
flutterDevice,
|
||||
target: mainPath,
|
||||
ipv6: ipv6,
|
||||
debuggingOptions: debuggingOptions,
|
||||
stayResident: false,
|
||||
urlTunneller: null,
|
||||
flutterProject: FlutterProject.current(),
|
||||
);
|
||||
final Completer<void> appStartedCompleter = Completer<void>.sync();
|
||||
final int result = await _residentRunner.run(
|
||||
appStartedCompleter: appStartedCompleter,
|
||||
route: route,
|
||||
);
|
||||
_webUri = _residentRunner.uri;
|
||||
if (result != 0) {
|
||||
throwToolExit(null);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> startTest(String testFile, List<String> arguments, Map<String, String> environment, {
|
||||
bool headless,
|
||||
String chromeBinary,
|
||||
String browserName,
|
||||
bool androidEmulator,
|
||||
int driverPort,
|
||||
List<String> browserDimension,
|
||||
}) async {
|
||||
async_io.WebDriver webDriver;
|
||||
final Browser browser = _browserNameToEnum(browserName);
|
||||
try {
|
||||
webDriver = await async_io.createDriver(
|
||||
uri: Uri.parse('http://localhost:$driverPort/'),
|
||||
desired: getDesiredCapabilities(browser, headless, chromeBinary),
|
||||
spec: async_io.WebDriverSpec.Auto
|
||||
);
|
||||
} on Exception catch (ex) {
|
||||
throwToolExit(
|
||||
'Unable to start WebDriver Session for Flutter for Web testing. \n'
|
||||
'Make sure you have the correct WebDriver Server running at $driverPort. \n'
|
||||
'Make sure the WebDriver Server matches option --browser-name. \n'
|
||||
'$ex'
|
||||
);
|
||||
}
|
||||
|
||||
final bool isAndroidChrome = browser == Browser.androidChrome;
|
||||
// Do not set the window size for android chrome browser.
|
||||
if (!isAndroidChrome) {
|
||||
assert(browserDimension.length == 2);
|
||||
int x;
|
||||
int y;
|
||||
try {
|
||||
x = int.parse(browserDimension[0]);
|
||||
y = int.parse(browserDimension[1]);
|
||||
} on FormatException catch (ex) {
|
||||
throwToolExit('Dimension provided to --browser-dimension is invalid: $ex');
|
||||
}
|
||||
final async_io.Window window = await webDriver.window;
|
||||
await window.setLocation(const math.Point<int>(0, 0));
|
||||
await window.setSize(math.Rectangle<int>(0, 0, x, y));
|
||||
}
|
||||
final int result = await _processUtils.stream(<String>[
|
||||
_dartSdkPath,
|
||||
...arguments,
|
||||
testFile,
|
||||
'-rexpanded',
|
||||
], environment: <String, String>{
|
||||
'VM_SERVICE_URL': _webUri.toString(),
|
||||
..._additionalDriverEnvironment(webDriver, browserName, androidEmulator),
|
||||
...environment,
|
||||
});
|
||||
await webDriver.quit();
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> stop({File writeSkslOnExit, String userIdentifier}) async {
|
||||
await _residentRunner.cleanupAtFinish();
|
||||
}
|
||||
|
||||
Map<String, String> _additionalDriverEnvironment(async_io.WebDriver webDriver, String browserName, bool androidEmulator) {
|
||||
return <String, String>{
|
||||
'DRIVER_SESSION_ID': webDriver.id,
|
||||
'DRIVER_SESSION_URI': webDriver.uri.toString(),
|
||||
'DRIVER_SESSION_SPEC': webDriver.spec.toString(),
|
||||
'DRIVER_SESSION_CAPABILITIES': json.encode(webDriver.capabilities),
|
||||
'SUPPORT_TIMELINE_ACTION': (_browserNameToEnum(browserName) == Browser.chrome).toString(),
|
||||
'FLUTTER_WEB_TEST': 'true',
|
||||
'ANDROID_CHROME_ON_EMULATOR': (_browserNameToEnum(browserName) == Browser.androidChrome && androidEmulator).toString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// A list of supported browsers.
|
||||
enum Browser {
|
||||
/// Chrome on Android: https://developer.chrome.com/multidevice/android/overview
|
||||
androidChrome,
|
||||
/// Chrome: https://www.google.com/chrome/
|
||||
chrome,
|
||||
/// Edge: https://www.microsoft.com/en-us/windows/microsoft-edge
|
||||
edge,
|
||||
/// Firefox: https://www.mozilla.org/en-US/firefox/
|
||||
firefox,
|
||||
/// Safari in iOS: https://www.apple.com/safari/
|
||||
iosSafari,
|
||||
/// Safari in macOS: https://www.apple.com/safari/
|
||||
safari,
|
||||
}
|
||||
|
||||
/// Returns desired capabilities for given [browser], [headless] and
|
||||
/// [chromeBinary].
|
||||
@visibleForTesting
|
||||
Map<String, dynamic> getDesiredCapabilities(Browser browser, bool headless, [String chromeBinary]) {
|
||||
switch (browser) {
|
||||
case Browser.chrome:
|
||||
return <String, dynamic>{
|
||||
'acceptInsecureCerts': true,
|
||||
'browserName': 'chrome',
|
||||
'goog:loggingPrefs': <String, String>{ async_io.LogType.performance: 'ALL'},
|
||||
'chromeOptions': <String, dynamic>{
|
||||
if (chromeBinary != null)
|
||||
'binary': chromeBinary,
|
||||
'w3c': false,
|
||||
'args': <String>[
|
||||
'--bwsi',
|
||||
'--disable-background-timer-throttling',
|
||||
'--disable-default-apps',
|
||||
'--disable-extensions',
|
||||
'--disable-popup-blocking',
|
||||
'--disable-translate',
|
||||
'--no-default-browser-check',
|
||||
'--no-sandbox',
|
||||
'--no-first-run',
|
||||
if (headless) '--headless'
|
||||
],
|
||||
'perfLoggingPrefs': <String, String>{
|
||||
'traceCategories':
|
||||
'devtools.timeline,'
|
||||
'v8,blink.console,benchmark,blink,'
|
||||
'blink.user_timing'
|
||||
}
|
||||
},
|
||||
};
|
||||
break;
|
||||
case Browser.firefox:
|
||||
return <String, dynamic>{
|
||||
'acceptInsecureCerts': true,
|
||||
'browserName': 'firefox',
|
||||
'moz:firefoxOptions' : <String, dynamic>{
|
||||
'args': <String>[
|
||||
if (headless) '-headless'
|
||||
],
|
||||
'prefs': <String, dynamic>{
|
||||
'dom.file.createInChild': true,
|
||||
'dom.timeout.background_throttling_max_budget': -1,
|
||||
'media.autoplay.default': 0,
|
||||
'media.gmp-manager.url': '',
|
||||
'media.gmp-provider.enabled': false,
|
||||
'network.captive-portal-service.enabled': false,
|
||||
'security.insecure_field_warning.contextual.enabled': false,
|
||||
'test.currentTimeOffsetSeconds': 11491200
|
||||
},
|
||||
'log': <String, String>{'level': 'trace'}
|
||||
}
|
||||
};
|
||||
break;
|
||||
case Browser.edge:
|
||||
return <String, dynamic>{
|
||||
'acceptInsecureCerts': true,
|
||||
'browserName': 'edge',
|
||||
};
|
||||
break;
|
||||
case Browser.safari:
|
||||
return <String, dynamic>{
|
||||
'browserName': 'safari',
|
||||
};
|
||||
break;
|
||||
case Browser.iosSafari:
|
||||
return <String, dynamic>{
|
||||
'platformName': 'ios',
|
||||
'browserName': 'safari',
|
||||
'safari:useSimulator': true
|
||||
};
|
||||
case Browser.androidChrome:
|
||||
return <String, dynamic>{
|
||||
'browserName': 'chrome',
|
||||
'platformName': 'android',
|
||||
'goog:chromeOptions': <String, dynamic>{
|
||||
'androidPackage': 'com.android.chrome',
|
||||
'args': <String>['--disable-fullscreen']
|
||||
},
|
||||
};
|
||||
default:
|
||||
throw UnsupportedError('Browser $browser not supported.');
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts [browserName] string to [Browser]
|
||||
Browser _browserNameToEnum(String browserName){
|
||||
switch (browserName) {
|
||||
case 'android-chrome': return Browser.androidChrome;
|
||||
case 'chrome': return Browser.chrome;
|
||||
case 'edge': return Browser.edge;
|
||||
case 'firefox': return Browser.firefox;
|
||||
case 'ios-safari': return Browser.iosSafari;
|
||||
case 'safari': return Browser.safari;
|
||||
}
|
||||
throw UnsupportedError('Browser $browserName not supported');
|
||||
}
|
||||
@@ -528,6 +528,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
|
||||
flutterProject,
|
||||
target,
|
||||
debuggingOptions.buildInfo,
|
||||
debuggingOptions.initializePlatform,
|
||||
false,
|
||||
kNoneWorker,
|
||||
true,
|
||||
@@ -595,6 +596,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
|
||||
flutterProject,
|
||||
target,
|
||||
debuggingOptions.buildInfo,
|
||||
debuggingOptions.initializePlatform,
|
||||
false,
|
||||
kNoneWorker,
|
||||
true,
|
||||
|
||||
@@ -70,6 +70,7 @@ class FlutterDevice {
|
||||
/// Create a [FlutterDevice] with optional code generation enabled.
|
||||
static Future<FlutterDevice> create(
|
||||
Device device, {
|
||||
@required FlutterProject flutterProject,
|
||||
@required String target,
|
||||
@required BuildInfo buildInfo,
|
||||
@required Platform platform,
|
||||
|
||||
@@ -8,7 +8,6 @@ import 'package:vm_service/vm_service.dart' as vm_service;
|
||||
|
||||
import 'base/context.dart';
|
||||
import 'base/io.dart' as io;
|
||||
import 'base/logger.dart';
|
||||
import 'build_info.dart';
|
||||
import 'convert.dart';
|
||||
import 'device.dart';
|
||||
@@ -807,11 +806,9 @@ bool isPauseEvent(String kind) {
|
||||
// or delete it.
|
||||
Future<String> sharedSkSlWriter(Device device, Map<String, Object> data, {
|
||||
File outputFile,
|
||||
Logger logger,
|
||||
}) async {
|
||||
logger ??= globals.logger;
|
||||
if (data.isEmpty) {
|
||||
logger.printStatus(
|
||||
globals.logger.printStatus(
|
||||
'No data was received. To ensure SkSL data can be generated use a '
|
||||
'physical device then:\n'
|
||||
' 1. Pass "--cache-sksl" as an argument to flutter run.\n'
|
||||
@@ -847,7 +844,7 @@ Future<String> sharedSkSlWriter(Device device, Map<String, Object> data, {
|
||||
'data': data,
|
||||
};
|
||||
outputFile.writeAsStringSync(json.encode(manifest));
|
||||
logger.printStatus('Wrote SkSL data to ${outputFile.path}.');
|
||||
globals.logger.printStatus('Wrote SkSL data to ${outputFile.path}.');
|
||||
return outputFile.path;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ Future<void> buildWeb(
|
||||
FlutterProject flutterProject,
|
||||
String target,
|
||||
BuildInfo buildInfo,
|
||||
bool initializePlatform,
|
||||
bool csp,
|
||||
String serviceWorkerStrategy,
|
||||
bool sourceMaps,
|
||||
@@ -53,6 +54,7 @@ Future<void> buildWeb(
|
||||
defines: <String, String>{
|
||||
kBuildMode: getNameForBuildMode(buildInfo.mode),
|
||||
kTargetFile: target,
|
||||
kInitializePlatform: initializePlatform.toString(),
|
||||
kHasWebPlugins: hasWebPlugins.toString(),
|
||||
kDartDefines: encodeDartDefines(buildInfo.dartDefines),
|
||||
kCspMode: csp.toString(),
|
||||
|
||||
Reference in New Issue
Block a user