@@ -24,6 +24,7 @@ import 'package:flutter_tools/src/device.dart';
2424import 'package:flutter_tools/src/drive/drive_service.dart' ;
2525import 'package:flutter_tools/src/ios/devices.dart' ;
2626import 'package:flutter_tools/src/project.dart' ;
27+ import 'package:flutter_tools/src/web/web_device.dart' ;
2728import 'package:package_config/package_config.dart' ;
2829import 'package:test/fake.dart' ;
2930
@@ -58,6 +59,47 @@ void main() {
5859 Cache .enableLocking ();
5960 });
6061
62+ testUsingContext (
63+ 'web drive runs without launching Chrome directly' ,
64+ () async {
65+ final capturingDriverService = CapturingDriverService ();
66+ final command = DriveCommand (
67+ fileSystem: fileSystem,
68+ logger: logger,
69+ platform: platform,
70+ terminal: terminal,
71+ outputPreferences: outputPreferences,
72+ signals: signals,
73+ flutterDriverFactory: CapturingFlutterDriverFactory (capturingDriverService),
74+ );
75+
76+ fileSystem.file ('lib/main.dart' ).createSync (recursive: true );
77+ fileSystem.file ('test_driver/main_test.dart' ).createSync (recursive: true );
78+ fileSystem.file ('pubspec.yaml' ).createSync ();
79+ fileSystem.file ('web/index.html' ).createSync (recursive: true );
80+
81+ fakeDeviceManager.attachedDevices = < Device > [FakeChromiumDriveDevice ()];
82+
83+ await createTestCommandRunner (command).run (< String > [
84+ 'drive' ,
85+ '--no-pub' ,
86+ '-d' ,
87+ 'chrome' ,
88+ '--browser-name=chrome' ,
89+ '--chrome-binary=/tmp/custom-chrome' ,
90+ ]);
91+
92+ expect (capturingDriverService.platformArgs, containsPair ('no-launch-chrome' , true ));
93+ expect (capturingDriverService.platformArgs, isNot (contains ('--no-launch-chrome' )));
94+ },
95+ overrides: < Type , Generator > {
96+ FileSystem : () => fileSystem,
97+ ProcessManager : () => FakeProcessManager .any (),
98+ Pub : () => FakePub (),
99+ DeviceManager : () => fakeDeviceManager,
100+ },
101+ );
102+
61103 testUsingContext (
62104 'fails if the specified --target is not found' ,
63105 () async {
@@ -836,27 +878,23 @@ void main() {
836878 },
837879 );
838880
839- testUsingContext (
840- 'flutter drive --help explains how to use the command' ,
841- () async {
842- final command = DriveCommand (
843- fileSystem: fileSystem,
844- logger: logger,
845- platform: platform,
846- terminal: terminal,
847- outputPreferences: outputPreferences,
848- signals: signals,
849- );
850-
851- await createTestCommandRunner (command).run (< String > ['drive' , '--help' ]);
852-
853- expect (
854- logger.statusText,
855- stringContainsInOrder (< String > ['flutter drive' , '--target' , '--driver' ]),
856- );
857- },
858- overrides: < Type , Generator > {Logger : () => logger},
859- );
881+ testUsingContext ('flutter drive --help explains how to use the command' , () async {
882+ final command = DriveCommand (
883+ fileSystem: fileSystem,
884+ logger: logger,
885+ platform: platform,
886+ terminal: terminal,
887+ outputPreferences: outputPreferences,
888+ signals: signals,
889+ );
890+
891+ await createTestCommandRunner (command).run (< String > ['drive' , '--help' ]);
892+
893+ expect (
894+ logger.statusText,
895+ stringContainsInOrder (< String > ['flutter drive' , '--target' , '--driver' ]),
896+ );
897+ }, overrides: < Type , Generator > {Logger : () => logger});
860898}
861899
862900class ThrowingScreenshotDevice extends ScreenshotDevice {
@@ -955,6 +993,15 @@ class FakeFlutterDriverFactory extends Fake implements FlutterDriverFactory {
955993 }
956994}
957995
996+ class CapturingFlutterDriverFactory extends Fake implements FlutterDriverFactory {
997+ CapturingFlutterDriverFactory (this .driverService);
998+
999+ final CapturingDriverService driverService;
1000+
1001+ @override
1002+ DriverService createDriverService (bool web) => driverService;
1003+ }
1004+
9581005/// A [DriverService] that will return a Future from [startTest] that will never complete.
9591006///
9601007/// This is to simulate when the test will take a long time, but a signal is
@@ -996,6 +1043,49 @@ class FakeDriverService extends Fake implements DriverService {
9961043 }
9971044}
9981045
1046+ class CapturingDriverService extends Fake implements DriverService {
1047+ Map <String , Object >? platformArgs;
1048+
1049+ @override
1050+ Future <void > start (
1051+ BuildInfo buildInfo,
1052+ Device device,
1053+ DebuggingOptions debuggingOptions, {
1054+ File ? applicationBinary,
1055+ String ? route,
1056+ String ? userIdentifier,
1057+ String ? mainPath,
1058+ Map <String , Object > platformArgs = const < String , Object > {},
1059+ }) async {
1060+ this .platformArgs = platformArgs;
1061+ }
1062+
1063+ @override
1064+ Future <void > reuseApplication (
1065+ Uri vmServiceUri,
1066+ Device device,
1067+ DebuggingOptions debuggingOptions,
1068+ ) async {}
1069+
1070+ @override
1071+ Future <int > startTest (
1072+ String testFile,
1073+ List <String > arguments,
1074+ PackageConfig packageConfig, {
1075+ bool ? headless,
1076+ String ? chromeBinary,
1077+ String ? browserName,
1078+ bool ? androidEmulator,
1079+ int ? driverPort,
1080+ List <String >? webBrowserFlags,
1081+ List <String >? browserDimension,
1082+ String ? profileMemory,
1083+ }) async => 0 ;
1084+
1085+ @override
1086+ Future <void > stop ({String ? userIdentifier}) async {}
1087+ }
1088+
9991089class FailingFakeFlutterDriverFactory extends Fake implements FlutterDriverFactory {
10001090 @override
10011091 DriverService createDriverService (bool web) => FailingFakeDriverService ();
@@ -1043,6 +1133,46 @@ class FakeIosDevice extends Fake implements IOSDevice {
10431133 Future <TargetPlatform > get targetPlatform async => TargetPlatform .ios;
10441134}
10451135
1136+ class FakeChromiumDriveDevice extends Fake implements ChromiumDevice {
1137+ @override
1138+ final String id = 'chrome' ;
1139+
1140+ @override
1141+ String get name => 'Chrome' ;
1142+
1143+ @override
1144+ String get displayName => name;
1145+
1146+ @override
1147+ bool get isConnected => true ;
1148+
1149+ @override
1150+ bool get supportsScreenshot => false ;
1151+
1152+ @override
1153+ Category get category => Category .web;
1154+
1155+ @override
1156+ PlatformType get platformType => PlatformType .web;
1157+
1158+ @override
1159+ Future <bool > get isLocalEmulator async => false ;
1160+
1161+ @override
1162+ Future <String > get sdkNameAndVersion async => 'Google Chrome 0.0' ;
1163+
1164+ @override
1165+ Future <TargetPlatform > get targetPlatform async => TargetPlatform .web_javascript;
1166+
1167+ @override
1168+ DeviceLogReader getLogReader ({ApplicationPackage ? app, bool includePastLogs = false }) {
1169+ return NoOpDeviceLogReader (app? .name);
1170+ }
1171+
1172+ @override
1173+ bool supportsRuntimeMode (BuildMode buildMode) => true ;
1174+ }
1175+
10461176class FakeSignals extends Fake implements Signals {
10471177 List <SignalHandler > addedHandlers = < SignalHandler > [];
10481178
0 commit comments