diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart index f8804d6f78d..eea5f7a1252 100644 --- a/packages/flutter_tools/lib/src/test/flutter_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart @@ -6,6 +6,7 @@ import 'dart:async'; +import 'package:dds/dds.dart'; import 'package:meta/meta.dart'; import 'package:package_config/package_config.dart'; import 'package:stream_channel/stream_channel.dart'; @@ -65,6 +66,7 @@ FlutterPlatform installHook({ Device? integrationTestDevice, String? integrationTestUserIdentifier, TestTimeRecorder? testTimeRecorder, + UriConverter? uriConverter, }) { assert(testWrapper != null); assert(enableObservatory || (!debuggingOptions.startPaused && debuggingOptions.hostVmServicePort == null)); @@ -95,6 +97,7 @@ FlutterPlatform installHook({ integrationTestDevice: integrationTestDevice, integrationTestUserIdentifier: integrationTestUserIdentifier, testTimeRecorder: testTimeRecorder, + uriConverter: uriConverter, ); platformPluginRegistration(platform); return platform; @@ -290,6 +293,7 @@ class FlutterPlatform extends PlatformPlugin { this.integrationTestDevice, this.integrationTestUserIdentifier, this.testTimeRecorder, + this.uriConverter, }) : assert(shellPath != null); final String shellPath; @@ -307,6 +311,9 @@ class FlutterPlatform extends PlatformPlugin { final String? icudtlPath; final TestTimeRecorder? testTimeRecorder; + // This can be used by internal projects that require custom logic for converting package: URIs to local paths. + final UriConverter? uriConverter; + /// The device to run the test on for Integration Tests. /// /// If this is null, the test will run as a regular test with the Flutter @@ -428,7 +435,8 @@ class FlutterPlatform extends PlatformPlugin { flutterProject: flutterProject, icudtlPath: icudtlPath, compileExpression: _compileExpressionService, - fontConfigManager: _fontConfigManager + fontConfigManager: _fontConfigManager, + uriConverter: uriConverter, ); } diff --git a/packages/flutter_tools/lib/src/test/flutter_tester_device.dart b/packages/flutter_tools/lib/src/test/flutter_tester_device.dart index 8778995cb9c..14cdfc02451 100644 --- a/packages/flutter_tools/lib/src/test/flutter_tester_device.dart +++ b/packages/flutter_tools/lib/src/test/flutter_tester_device.dart @@ -43,6 +43,7 @@ class FlutterTesterTestDevice extends TestDevice { required this.icudtlPath, required this.compileExpression, required this.fontConfigManager, + required this.uriConverter, }) : assert(shellPath != null), // Please provide the path to the shell in the SKY_SHELL environment variable. assert(!debuggingOptions.startPaused || enableObservatory), _gotProcessObservatoryUri = enableObservatory @@ -64,6 +65,7 @@ class FlutterTesterTestDevice extends TestDevice { final String? icudtlPath; final CompileExpression? compileExpression; final FontConfigManager fontConfigManager; + final UriConverter? uriConverter; final Completer _gotProcessObservatoryUri; final Completer _exitCode = Completer(); @@ -162,7 +164,10 @@ class FlutterTesterTestDevice extends TestDevice { Uri? forwardingUri; if (debuggingOptions.enableDds) { logger.printTrace('test $id: Starting Dart Development Service'); - final DartDevelopmentService dds = await startDds(detectedUri); + final DartDevelopmentService dds = await startDds( + detectedUri, + uriConverter: uriConverter, + ); forwardingUri = dds.uri; logger.printTrace('test $id: Dart Development Service started at ${dds.uri}, forwarding to VM service at ${dds.remoteVmServiceUri}.'); } else { @@ -239,12 +244,13 @@ class FlutterTesterTestDevice extends TestDevice { @visibleForTesting @protected - Future startDds(Uri uri) { + Future startDds(Uri uri, {UriConverter? uriConverter}) { return DartDevelopmentService.startDartDevelopmentService( uri, serviceUri: _ddsServiceUri, enableAuthCodes: !debuggingOptions.disableServiceAuthCodes, ipv6: host!.type == InternetAddressType.IPv6, + uriConverter: uriConverter, ); } diff --git a/packages/flutter_tools/test/general.shard/flutter_platform_test.dart b/packages/flutter_tools/test/general.shard/flutter_platform_test.dart index 68362339c83..68e457d65b4 100644 --- a/packages/flutter_tools/test/general.shard/flutter_platform_test.dart +++ b/packages/flutter_tools/test/general.shard/flutter_platform_test.dart @@ -97,7 +97,9 @@ void main() { icudtlPath: 'ghi', platformPluginRegistration: (FlutterPlatform platform) { capturedPlatform = platform; - }); + }, + uriConverter: (String input) => '$input/test', + ); expect(identical(capturedPlatform, flutterPlatform), equals(true)); expect(flutterPlatform.shellPath, equals('abc')); @@ -113,6 +115,7 @@ void main() { expect(flutterPlatform.updateGoldens, equals(true)); expect(flutterPlatform.testAssetDirectory, '/build/test'); expect(flutterPlatform.icudtlPath, equals('ghi')); + expect(flutterPlatform.uriConverter?.call('hello'), 'hello/test'); }); }); } diff --git a/packages/flutter_tools/test/general.shard/flutter_tester_device_test.dart b/packages/flutter_tools/test/general.shard/flutter_tester_device_test.dart index cf0c0cc1357..8edeafafb17 100644 --- a/packages/flutter_tools/test/general.shard/flutter_tester_device_test.dart +++ b/packages/flutter_tools/test/general.shard/flutter_tester_device_test.dart @@ -46,6 +46,7 @@ void main() { processManager: processManager, enableObservatory: enableObservatory, dartEntrypointArgs: dartEntrypointArgs, + uriConverter: (String input) => '$input/converted', ); group('The FLUTTER_TEST environment variable is passed to the test process', () { @@ -182,6 +183,18 @@ void main() { final Uri uri = await (device as TestFlutterTesterDevice).ddsServiceUriFuture(); expect(uri.port, 1234); }); + + testUsingContext('sets up UriConverter from context', () async { + await device.start('example.dill'); + await device.observatoryUri; + + final FakeDartDevelopmentService dds = (device as TestFlutterTesterDevice).dds + as FakeDartDevelopmentService; + final String? result = dds + .uriConverter + ?.call('test'); + expect(result, 'test/converted'); + }); }); } @@ -195,6 +208,7 @@ class TestFlutterTesterDevice extends FlutterTesterTestDevice { required super.processManager, required super.enableObservatory, required List dartEntrypointArgs, + required UriConverter uriConverter, }) : super( id: 999, shellPath: '/', @@ -215,16 +229,26 @@ class TestFlutterTesterDevice extends FlutterTesterTestDevice { icudtlPath: null, compileExpression: null, fontConfigManager: FontConfigManager(), + uriConverter: uriConverter, ); + late DartDevelopmentService dds; final Completer _ddsServiceUriCompleter = Completer(); Future ddsServiceUriFuture() => _ddsServiceUriCompleter.future; @override - Future startDds(Uri uri) async { + Future startDds( + Uri uri, { + UriConverter? uriConverter, + }) async { _ddsServiceUriCompleter.complete(uri); - return FakeDartDevelopmentService(Uri.parse('http://localhost:${debuggingOptions.hostVmServicePort}'), Uri.parse('http://localhost:8080')); + dds = FakeDartDevelopmentService( + Uri.parse('http://localhost:${debuggingOptions.hostVmServicePort}'), + Uri.parse('http://localhost:8080'), + uriConverter: uriConverter, + ); + return dds; } @override @@ -235,9 +259,10 @@ class TestFlutterTesterDevice extends FlutterTesterTestDevice { } class FakeDartDevelopmentService extends Fake implements DartDevelopmentService { - FakeDartDevelopmentService(this.uri, this.original); + FakeDartDevelopmentService(this.uri, this.original, {this.uriConverter}); final Uri original; + final UriConverter? uriConverter; @override final Uri uri;