diff --git a/dev/integration_tests/flutter_gallery/.gitignore b/dev/integration_tests/flutter_gallery/.gitignore index a61bb46ed6..d8571249c6 100644 --- a/dev/integration_tests/flutter_gallery/.gitignore +++ b/dev/integration_tests/flutter_gallery/.gitignore @@ -1,3 +1,2 @@ -lib/generated_plugin_registrant.dart vmservice.out *.sksl.json diff --git a/packages/flutter_tools/lib/src/drive/web_driver_service.dart b/packages/flutter_tools/lib/src/drive/web_driver_service.dart index 445716b871..ffd4a990dc 100644 --- a/packages/flutter_tools/lib/src/drive/web_driver_service.dart +++ b/packages/flutter_tools/lib/src/drive/web_driver_service.dart @@ -41,6 +41,9 @@ class WebDriverService extends DriverService { late ResidentRunner _residentRunner; Uri? _webUri; + @visibleForTesting + Uri? get webUri => _webUri; + /// The result of [ResidentRunner.run]. /// /// This is expected to stay `null` throughout the test, as the application @@ -74,10 +77,12 @@ class WebDriverService extends DriverService { DebuggingOptions.disabled( buildInfo, port: debuggingOptions.port, + hostname: debuggingOptions.hostname, ) : DebuggingOptions.enabled( buildInfo, port: debuggingOptions.port, + hostname: debuggingOptions.hostname, disablePortPublication: debuggingOptions.disablePortPublication, ), stayResident: true, @@ -116,11 +121,16 @@ class WebDriverService extends DriverService { throw ToolExit('Failed to start application'); } - _webUri = _residentRunner.uri; - - if (_webUri == null) { + if (_residentRunner.uri == null) { throw ToolExit('Unable to connect to the app. URL not available.'); } + + if (debuggingOptions.webLaunchUrl != null) { + // It should thow an error if the provided url is invalid so no tryParse + _webUri = Uri.parse(debuggingOptions.webLaunchUrl!); + } else { + _webUri = _residentRunner.uri; + } } @override diff --git a/packages/flutter_tools/test/general.shard/drive/web_driver_service_test.dart b/packages/flutter_tools/test/general.shard/drive/web_driver_service_test.dart index bab05c5169..28f66f2cc2 100644 --- a/packages/flutter_tools/test/general.shard/drive/web_driver_service_test.dart +++ b/packages/flutter_tools/test/general.shard/drive/web_driver_service_test.dart @@ -258,6 +258,29 @@ void main() { WebRunnerFactory: () => FakeWebRunnerFactory(), }); + testUsingContext('WebDriverService can start an app with a launch url provided', () async { + final WebDriverService service = setUpDriverService(); + final FakeDevice device = FakeDevice(); + const String testUrl = 'http://localhost:1234/test'; + await service.start(BuildInfo.profile, device, DebuggingOptions.enabled(BuildInfo.profile, webLaunchUrl: testUrl), true); + await service.stop(); + expect(service.webUri, Uri.parse(testUrl)); + }, overrides: { + WebRunnerFactory: () => FakeWebRunnerFactory(), + }); + + testUsingContext('WebDriverService will throw when an invalid launch url is provided', () async { + final WebDriverService service = setUpDriverService(); + final FakeDevice device = FakeDevice(); + const String invalidTestUrl = '::INVALID_URL::'; + await expectLater( + service.start(BuildInfo.profile, device, DebuggingOptions.enabled(BuildInfo.profile, webLaunchUrl: invalidTestUrl), true), + throwsA(isA()), + ); + }, overrides: { + WebRunnerFactory: () => FakeWebRunnerFactory(), + }); + testUsingContext('WebDriverService forwards exception when run future fails before app starts', () async { final WebDriverService service = setUpDriverService(); final Device device = FakeDevice();