Skip to content

Commit 118248b

Browse files
authored
Pass URI converter from context to DDS (#106840)
* Pass URI converter from context to DDS * Match change that will be merged * Revert SDK web change
1 parent b1410c2 commit 118248b

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

packages/flutter_tools/lib/src/base/dds.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:dds/dds.dart' as dds;
88
import 'package:meta/meta.dart';
99

1010
import 'common.dart';
11+
import 'context.dart';
1112
import 'io.dart' as io;
1213
import 'logger.dart';
1314

@@ -18,6 +19,7 @@ Future<dds.DartDevelopmentService> Function(
1819
bool ipv6,
1920
Uri? serviceUri,
2021
List<String> cachedUserTags,
22+
dds.UriConverter? uriConverter,
2123
}) ddsLauncherCallback = dds.DartDevelopmentService.startDartDevelopmentService;
2224

2325
/// Helper class to launch a [dds.DartDevelopmentService]. Allows for us to
@@ -56,6 +58,7 @@ class DartDevelopmentService {
5658
ipv6: ipv6 ?? false,
5759
// Enables caching of CPU samples collected during application startup.
5860
cachedUserTags: cacheStartupProfile ? const <String>['AppStartUp'] : const <String>[],
61+
uriConverter: context.get<dds.UriConverter>(),
5962
);
6063
unawaited(_ddsInstance?.done.whenComplete(() {
6164
if (!_completer.isCompleted) {

packages/flutter_tools/test/general.shard/resident_runner_test.dart

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,12 +2035,13 @@ flutter:
20352035
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
20362036
final FakeDevice device = FakeDevice()
20372037
..dds = DartDevelopmentService();
2038-
ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List<String> cachedUserTags}) {
2038+
ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List<String> cachedUserTags, dds.UriConverter uriConverter}) {
20392039
expect(uri, Uri(scheme: 'foo', host: 'bar'));
20402040
expect(enableAuthCodes, isTrue);
20412041
expect(ipv6, isFalse);
20422042
expect(serviceUri, Uri(scheme: 'http', host: '127.0.0.1', port: 0));
20432043
expect(cachedUserTags, isEmpty);
2044+
expect(uriConverter, isNull);
20442045
throw FakeDartDevelopmentServiceException(message:
20452046
'Existing VM service clients prevent DDS from taking control.',
20462047
);
@@ -2083,12 +2084,13 @@ flutter:
20832084
final FakeDevice device = FakeDevice()
20842085
..dds = DartDevelopmentService();
20852086
final Completer<void>done = Completer<void>();
2086-
ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List<String> cachedUserTags}) async {
2087+
ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List<String> cachedUserTags, dds.UriConverter uriConverter}) async {
20872088
expect(uri, Uri(scheme: 'foo', host: 'bar'));
20882089
expect(enableAuthCodes, isFalse);
20892090
expect(ipv6, isTrue);
20902091
expect(serviceUri, Uri(scheme: 'http', host: '::1', port: 0));
20912092
expect(cachedUserTags, isEmpty);
2093+
expect(uriConverter, isNull);
20922094
done.complete();
20932095
return null;
20942096
};
@@ -2111,16 +2113,52 @@ flutter:
21112113
}) async => FakeVmServiceHost(requests: <VmServiceExpectation>[]).vmService,
21122114
}));
21132115

2116+
testUsingContext('Context includes URI converter', () => testbed.run(() async {
2117+
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
2118+
final FakeDevice device = FakeDevice()
2119+
..dds = DartDevelopmentService();
2120+
final Completer<void>done = Completer<void>();
2121+
ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List<String> cachedUserTags, dds.UriConverter uriConverter}) async {
2122+
expect(uri, Uri(scheme: 'foo', host: 'bar'));
2123+
expect(enableAuthCodes, isFalse);
2124+
expect(ipv6, isTrue);
2125+
expect(serviceUri, Uri(scheme: 'http', host: '::1', port: 0));
2126+
expect(cachedUserTags, isEmpty);
2127+
expect(uriConverter, isNotNull);
2128+
done.complete();
2129+
return null;
2130+
};
2131+
final TestFlutterDevice flutterDevice = TestFlutterDevice(
2132+
device,
2133+
observatoryUris: Stream<Uri>.value(testUri),
2134+
);
2135+
await flutterDevice.connect(allowExistingDdsInstance: true, ipv6: true, disableServiceAuthCodes: true);
2136+
await done.future;
2137+
}, overrides: <Type, Generator>{
2138+
VMServiceConnector: () => (Uri httpUri, {
2139+
ReloadSources reloadSources,
2140+
Restart restart,
2141+
CompileExpression compileExpression,
2142+
GetSkSLMethod getSkSLMethod,
2143+
PrintStructuredErrorLogMethod printStructuredErrorLogMethod,
2144+
io.CompressionOptions compression,
2145+
Device device,
2146+
Logger logger,
2147+
}) async => FakeVmServiceHost(requests: <VmServiceExpectation>[]).vmService,
2148+
dds.UriConverter: () => (String uri) => 'test',
2149+
}));
2150+
21142151
testUsingContext('Failed DDS start outputs error message', () => testbed.run(() async {
21152152
// See https://github.com/flutter/flutter/issues/72385 for context.
21162153
final FakeDevice device = FakeDevice()
21172154
..dds = DartDevelopmentService();
2118-
ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List<String> cachedUserTags}) {
2155+
ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List<String> cachedUserTags, dds.UriConverter uriConverter}) {
21192156
expect(uri, Uri(scheme: 'foo', host: 'bar'));
21202157
expect(enableAuthCodes, isTrue);
21212158
expect(ipv6, isFalse);
21222159
expect(serviceUri, Uri(scheme: 'http', host: '127.0.0.1', port: 0));
21232160
expect(cachedUserTags, isEmpty);
2161+
expect(uriConverter, isNull);
21242162
throw FakeDartDevelopmentServiceException(message: 'No URI');
21252163
};
21262164
final TestFlutterDevice flutterDevice = TestFlutterDevice(

0 commit comments

Comments
 (0)