From 118248bcc56679a8aed29498afbd057f2de2d366 Mon Sep 17 00:00:00 2001 From: Helin Shiah Date: Thu, 7 Jul 2022 10:10:04 -0700 Subject: [PATCH] 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 --- packages/flutter_tools/lib/src/base/dds.dart | 3 ++ .../general.shard/resident_runner_test.dart | 44 +++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/dds.dart b/packages/flutter_tools/lib/src/base/dds.dart index 3d57c9f12a1b..fd01ddbfb9a9 100644 --- a/packages/flutter_tools/lib/src/base/dds.dart +++ b/packages/flutter_tools/lib/src/base/dds.dart @@ -8,6 +8,7 @@ import 'package:dds/dds.dart' as dds; import 'package:meta/meta.dart'; import 'common.dart'; +import 'context.dart'; import 'io.dart' as io; import 'logger.dart'; @@ -18,6 +19,7 @@ Future Function( bool ipv6, Uri? serviceUri, List cachedUserTags, + dds.UriConverter? uriConverter, }) ddsLauncherCallback = dds.DartDevelopmentService.startDartDevelopmentService; /// Helper class to launch a [dds.DartDevelopmentService]. Allows for us to @@ -56,6 +58,7 @@ class DartDevelopmentService { ipv6: ipv6 ?? false, // Enables caching of CPU samples collected during application startup. cachedUserTags: cacheStartupProfile ? const ['AppStartUp'] : const [], + uriConverter: context.get(), ); unawaited(_ddsInstance?.done.whenComplete(() { if (!_completer.isCompleted) { diff --git a/packages/flutter_tools/test/general.shard/resident_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_runner_test.dart index 0013c18221ef..d27e8046d351 100644 --- a/packages/flutter_tools/test/general.shard/resident_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_runner_test.dart @@ -2035,12 +2035,13 @@ flutter: fakeVmServiceHost = FakeVmServiceHost(requests: []); final FakeDevice device = FakeDevice() ..dds = DartDevelopmentService(); - ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List cachedUserTags}) { + ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List cachedUserTags, dds.UriConverter uriConverter}) { expect(uri, Uri(scheme: 'foo', host: 'bar')); expect(enableAuthCodes, isTrue); expect(ipv6, isFalse); expect(serviceUri, Uri(scheme: 'http', host: '127.0.0.1', port: 0)); expect(cachedUserTags, isEmpty); + expect(uriConverter, isNull); throw FakeDartDevelopmentServiceException(message: 'Existing VM service clients prevent DDS from taking control.', ); @@ -2083,12 +2084,13 @@ flutter: final FakeDevice device = FakeDevice() ..dds = DartDevelopmentService(); final Completerdone = Completer(); - ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List cachedUserTags}) async { + ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List cachedUserTags, dds.UriConverter uriConverter}) async { expect(uri, Uri(scheme: 'foo', host: 'bar')); expect(enableAuthCodes, isFalse); expect(ipv6, isTrue); expect(serviceUri, Uri(scheme: 'http', host: '::1', port: 0)); expect(cachedUserTags, isEmpty); + expect(uriConverter, isNull); done.complete(); return null; }; @@ -2111,16 +2113,52 @@ flutter: }) async => FakeVmServiceHost(requests: []).vmService, })); + testUsingContext('Context includes URI converter', () => testbed.run(() async { + fakeVmServiceHost = FakeVmServiceHost(requests: []); + final FakeDevice device = FakeDevice() + ..dds = DartDevelopmentService(); + final Completerdone = Completer(); + ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List cachedUserTags, dds.UriConverter uriConverter}) async { + expect(uri, Uri(scheme: 'foo', host: 'bar')); + expect(enableAuthCodes, isFalse); + expect(ipv6, isTrue); + expect(serviceUri, Uri(scheme: 'http', host: '::1', port: 0)); + expect(cachedUserTags, isEmpty); + expect(uriConverter, isNotNull); + done.complete(); + return null; + }; + final TestFlutterDevice flutterDevice = TestFlutterDevice( + device, + observatoryUris: Stream.value(testUri), + ); + await flutterDevice.connect(allowExistingDdsInstance: true, ipv6: true, disableServiceAuthCodes: true); + await done.future; + }, overrides: { + VMServiceConnector: () => (Uri httpUri, { + ReloadSources reloadSources, + Restart restart, + CompileExpression compileExpression, + GetSkSLMethod getSkSLMethod, + PrintStructuredErrorLogMethod printStructuredErrorLogMethod, + io.CompressionOptions compression, + Device device, + Logger logger, + }) async => FakeVmServiceHost(requests: []).vmService, + dds.UriConverter: () => (String uri) => 'test', + })); + testUsingContext('Failed DDS start outputs error message', () => testbed.run(() async { // See https://github.com/flutter/flutter/issues/72385 for context. final FakeDevice device = FakeDevice() ..dds = DartDevelopmentService(); - ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List cachedUserTags}) { + ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri, List cachedUserTags, dds.UriConverter uriConverter}) { expect(uri, Uri(scheme: 'foo', host: 'bar')); expect(enableAuthCodes, isTrue); expect(ipv6, isFalse); expect(serviceUri, Uri(scheme: 'http', host: '127.0.0.1', port: 0)); expect(cachedUserTags, isEmpty); + expect(uriConverter, isNull); throw FakeDartDevelopmentServiceException(message: 'No URI'); }; final TestFlutterDevice flutterDevice = TestFlutterDevice(