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 @@
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,
);
}
......
......@@ -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<Uri?> _gotProcessObservatoryUri;
final Completer<int> _exitCode = Completer<int>();
......@@ -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<DartDevelopmentService> startDds(Uri uri) {
Future<DartDevelopmentService> startDds(Uri uri, {UriConverter? uriConverter}) {
return DartDevelopmentService.startDartDevelopmentService(
uri,
serviceUri: _ddsServiceUri,
enableAuthCodes: !debuggingOptions.disableServiceAuthCodes,
ipv6: host!.type == InternetAddressType.IPv6,
uriConverter: uriConverter,
);
}
......
......@@ -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');
});
});
}
......
......@@ -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<String> 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<Uri> _ddsServiceUriCompleter = Completer<Uri>();
Future<Uri> ddsServiceUriFuture() => _ddsServiceUriCompleter.future;
@override
Future<DartDevelopmentService> startDds(Uri uri) async {
Future<DartDevelopmentService> 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;
......
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