Unverified Commit 8842281c authored by Helin Shiah's avatar Helin Shiah Committed by GitHub

Use UriConverter from context for test (#110539)

* Use UriConverter from context for test

* Fix type

* Pass URI converter using installHook

* Fix formatting

* Fix formatting in test

* Add comment about URI converter
parent 069f5042
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import 'dart:async'; import 'dart:async';
import 'package:dds/dds.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart'; import 'package:package_config/package_config.dart';
import 'package:stream_channel/stream_channel.dart'; import 'package:stream_channel/stream_channel.dart';
...@@ -65,6 +66,7 @@ FlutterPlatform installHook({ ...@@ -65,6 +66,7 @@ FlutterPlatform installHook({
Device? integrationTestDevice, Device? integrationTestDevice,
String? integrationTestUserIdentifier, String? integrationTestUserIdentifier,
TestTimeRecorder? testTimeRecorder, TestTimeRecorder? testTimeRecorder,
UriConverter? uriConverter,
}) { }) {
assert(testWrapper != null); assert(testWrapper != null);
assert(enableObservatory || (!debuggingOptions.startPaused && debuggingOptions.hostVmServicePort == null)); assert(enableObservatory || (!debuggingOptions.startPaused && debuggingOptions.hostVmServicePort == null));
...@@ -95,6 +97,7 @@ FlutterPlatform installHook({ ...@@ -95,6 +97,7 @@ FlutterPlatform installHook({
integrationTestDevice: integrationTestDevice, integrationTestDevice: integrationTestDevice,
integrationTestUserIdentifier: integrationTestUserIdentifier, integrationTestUserIdentifier: integrationTestUserIdentifier,
testTimeRecorder: testTimeRecorder, testTimeRecorder: testTimeRecorder,
uriConverter: uriConverter,
); );
platformPluginRegistration(platform); platformPluginRegistration(platform);
return platform; return platform;
...@@ -290,6 +293,7 @@ class FlutterPlatform extends PlatformPlugin { ...@@ -290,6 +293,7 @@ class FlutterPlatform extends PlatformPlugin {
this.integrationTestDevice, this.integrationTestDevice,
this.integrationTestUserIdentifier, this.integrationTestUserIdentifier,
this.testTimeRecorder, this.testTimeRecorder,
this.uriConverter,
}) : assert(shellPath != null); }) : assert(shellPath != null);
final String shellPath; final String shellPath;
...@@ -307,6 +311,9 @@ class FlutterPlatform extends PlatformPlugin { ...@@ -307,6 +311,9 @@ class FlutterPlatform extends PlatformPlugin {
final String? icudtlPath; final String? icudtlPath;
final TestTimeRecorder? testTimeRecorder; 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. /// 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 /// If this is null, the test will run as a regular test with the Flutter
...@@ -428,7 +435,8 @@ class FlutterPlatform extends PlatformPlugin { ...@@ -428,7 +435,8 @@ class FlutterPlatform extends PlatformPlugin {
flutterProject: flutterProject, flutterProject: flutterProject,
icudtlPath: icudtlPath, icudtlPath: icudtlPath,
compileExpression: _compileExpressionService, compileExpression: _compileExpressionService,
fontConfigManager: _fontConfigManager fontConfigManager: _fontConfigManager,
uriConverter: uriConverter,
); );
} }
......
...@@ -43,6 +43,7 @@ class FlutterTesterTestDevice extends TestDevice { ...@@ -43,6 +43,7 @@ class FlutterTesterTestDevice extends TestDevice {
required this.icudtlPath, required this.icudtlPath,
required this.compileExpression, required this.compileExpression,
required this.fontConfigManager, required this.fontConfigManager,
required this.uriConverter,
}) : assert(shellPath != null), // Please provide the path to the shell in the SKY_SHELL environment variable. }) : assert(shellPath != null), // Please provide the path to the shell in the SKY_SHELL environment variable.
assert(!debuggingOptions.startPaused || enableObservatory), assert(!debuggingOptions.startPaused || enableObservatory),
_gotProcessObservatoryUri = enableObservatory _gotProcessObservatoryUri = enableObservatory
...@@ -64,6 +65,7 @@ class FlutterTesterTestDevice extends TestDevice { ...@@ -64,6 +65,7 @@ class FlutterTesterTestDevice extends TestDevice {
final String? icudtlPath; final String? icudtlPath;
final CompileExpression? compileExpression; final CompileExpression? compileExpression;
final FontConfigManager fontConfigManager; final FontConfigManager fontConfigManager;
final UriConverter? uriConverter;
final Completer<Uri?> _gotProcessObservatoryUri; final Completer<Uri?> _gotProcessObservatoryUri;
final Completer<int> _exitCode = Completer<int>(); final Completer<int> _exitCode = Completer<int>();
...@@ -162,7 +164,10 @@ class FlutterTesterTestDevice extends TestDevice { ...@@ -162,7 +164,10 @@ class FlutterTesterTestDevice extends TestDevice {
Uri? forwardingUri; Uri? forwardingUri;
if (debuggingOptions.enableDds) { if (debuggingOptions.enableDds) {
logger.printTrace('test $id: Starting Dart Development Service'); 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; forwardingUri = dds.uri;
logger.printTrace('test $id: Dart Development Service started at ${dds.uri}, forwarding to VM service at ${dds.remoteVmServiceUri}.'); logger.printTrace('test $id: Dart Development Service started at ${dds.uri}, forwarding to VM service at ${dds.remoteVmServiceUri}.');
} else { } else {
...@@ -239,12 +244,13 @@ class FlutterTesterTestDevice extends TestDevice { ...@@ -239,12 +244,13 @@ class FlutterTesterTestDevice extends TestDevice {
@visibleForTesting @visibleForTesting
@protected @protected
Future<DartDevelopmentService> startDds(Uri uri) { Future<DartDevelopmentService> startDds(Uri uri, {UriConverter? uriConverter}) {
return DartDevelopmentService.startDartDevelopmentService( return DartDevelopmentService.startDartDevelopmentService(
uri, uri,
serviceUri: _ddsServiceUri, serviceUri: _ddsServiceUri,
enableAuthCodes: !debuggingOptions.disableServiceAuthCodes, enableAuthCodes: !debuggingOptions.disableServiceAuthCodes,
ipv6: host!.type == InternetAddressType.IPv6, ipv6: host!.type == InternetAddressType.IPv6,
uriConverter: uriConverter,
); );
} }
......
...@@ -97,7 +97,9 @@ void main() { ...@@ -97,7 +97,9 @@ void main() {
icudtlPath: 'ghi', icudtlPath: 'ghi',
platformPluginRegistration: (FlutterPlatform platform) { platformPluginRegistration: (FlutterPlatform platform) {
capturedPlatform = platform; capturedPlatform = platform;
}); },
uriConverter: (String input) => '$input/test',
);
expect(identical(capturedPlatform, flutterPlatform), equals(true)); expect(identical(capturedPlatform, flutterPlatform), equals(true));
expect(flutterPlatform.shellPath, equals('abc')); expect(flutterPlatform.shellPath, equals('abc'));
...@@ -113,6 +115,7 @@ void main() { ...@@ -113,6 +115,7 @@ void main() {
expect(flutterPlatform.updateGoldens, equals(true)); expect(flutterPlatform.updateGoldens, equals(true));
expect(flutterPlatform.testAssetDirectory, '/build/test'); expect(flutterPlatform.testAssetDirectory, '/build/test');
expect(flutterPlatform.icudtlPath, equals('ghi')); expect(flutterPlatform.icudtlPath, equals('ghi'));
expect(flutterPlatform.uriConverter?.call('hello'), 'hello/test');
}); });
}); });
} }
......
...@@ -46,6 +46,7 @@ void main() { ...@@ -46,6 +46,7 @@ void main() {
processManager: processManager, processManager: processManager,
enableObservatory: enableObservatory, enableObservatory: enableObservatory,
dartEntrypointArgs: dartEntrypointArgs, dartEntrypointArgs: dartEntrypointArgs,
uriConverter: (String input) => '$input/converted',
); );
group('The FLUTTER_TEST environment variable is passed to the test process', () { group('The FLUTTER_TEST environment variable is passed to the test process', () {
...@@ -182,6 +183,18 @@ void main() { ...@@ -182,6 +183,18 @@ void main() {
final Uri uri = await (device as TestFlutterTesterDevice).ddsServiceUriFuture(); final Uri uri = await (device as TestFlutterTesterDevice).ddsServiceUriFuture();
expect(uri.port, 1234); 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 { ...@@ -195,6 +208,7 @@ class TestFlutterTesterDevice extends FlutterTesterTestDevice {
required super.processManager, required super.processManager,
required super.enableObservatory, required super.enableObservatory,
required List<String> dartEntrypointArgs, required List<String> dartEntrypointArgs,
required UriConverter uriConverter,
}) : super( }) : super(
id: 999, id: 999,
shellPath: '/', shellPath: '/',
...@@ -215,16 +229,26 @@ class TestFlutterTesterDevice extends FlutterTesterTestDevice { ...@@ -215,16 +229,26 @@ class TestFlutterTesterDevice extends FlutterTesterTestDevice {
icudtlPath: null, icudtlPath: null,
compileExpression: null, compileExpression: null,
fontConfigManager: FontConfigManager(), fontConfigManager: FontConfigManager(),
uriConverter: uriConverter,
); );
late DartDevelopmentService dds;
final Completer<Uri> _ddsServiceUriCompleter = Completer<Uri>(); final Completer<Uri> _ddsServiceUriCompleter = Completer<Uri>();
Future<Uri> ddsServiceUriFuture() => _ddsServiceUriCompleter.future; Future<Uri> ddsServiceUriFuture() => _ddsServiceUriCompleter.future;
@override @override
Future<DartDevelopmentService> startDds(Uri uri) async { Future<DartDevelopmentService> startDds(
Uri uri, {
UriConverter? uriConverter,
}) async {
_ddsServiceUriCompleter.complete(uri); _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 @override
...@@ -235,9 +259,10 @@ class TestFlutterTesterDevice extends FlutterTesterTestDevice { ...@@ -235,9 +259,10 @@ class TestFlutterTesterDevice extends FlutterTesterTestDevice {
} }
class FakeDartDevelopmentService extends Fake implements DartDevelopmentService { class FakeDartDevelopmentService extends Fake implements DartDevelopmentService {
FakeDartDevelopmentService(this.uri, this.original); FakeDartDevelopmentService(this.uri, this.original, {this.uriConverter});
final Uri original; final Uri original;
final UriConverter? uriConverter;
@override @override
final Uri uri; final Uri uri;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment