From f62da01068e887e1e49cd8f024a0f7065bf94c66 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Fri, 5 Aug 2022 08:44:08 -0700 Subject: [PATCH] [flutter_tools] ensure setAssetDirectory uses windows path (#109021) --- packages/flutter_tools/lib/src/run_hot.dart | 1 + packages/flutter_tools/lib/src/vmservice.dart | 3 +- .../test/general.shard/vmservice_test.dart | 29 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart index 4132eedd321..9ee2225f97e 100644 --- a/packages/flutter_tools/lib/src/run_hot.dart +++ b/packages/flutter_tools/lib/src/run_hot.dart @@ -1047,6 +1047,7 @@ class HotRunner extends ResidentRunner { assetsDirectory: deviceAssetsDirectoryUri, uiIsolateId: view.uiIsolate!.id, viewId: view.id, + windows: device.targetPlatform == TargetPlatform.windows_x64, ) )); for (final FlutterView view in views) { diff --git a/packages/flutter_tools/lib/src/vmservice.dart b/packages/flutter_tools/lib/src/vmservice.dart index 2238814dffb..09f24fb171d 100644 --- a/packages/flutter_tools/lib/src/vmservice.dart +++ b/packages/flutter_tools/lib/src/vmservice.dart @@ -478,12 +478,13 @@ class FlutterVmService { required Uri assetsDirectory, required String? viewId, required String? uiIsolateId, + required bool windows, }) async { await callMethodWrapper(kSetAssetBundlePathMethod, isolateId: uiIsolateId, args: { 'viewId': viewId, - 'assetDirectory': assetsDirectory.toFilePath(windows: false), + 'assetDirectory': assetsDirectory.toFilePath(windows: windows), }); } diff --git a/packages/flutter_tools/test/general.shard/vmservice_test.dart b/packages/flutter_tools/test/general.shard/vmservice_test.dart index 7824683b2a5..fb4e87de7e9 100644 --- a/packages/flutter_tools/test/general.shard/vmservice_test.dart +++ b/packages/flutter_tools/test/general.shard/vmservice_test.dart @@ -214,6 +214,7 @@ void main() { assetsDirectory: Uri(path: 'abc', scheme: 'file'), viewId: 'abc', uiIsolateId: 'def', + windows: false, )); final Map rawRequest = json.decode(await completer.future) as Map; @@ -228,6 +229,34 @@ void main() { ])); }); + testWithoutContext('setAssetDirectory forwards arguments correctly - windows', () async { + final Completer completer = Completer(); + final vm_service.VmService vmService = vm_service.VmService( + const Stream.empty(), + completer.complete, + ); + final FlutterVmService flutterVmService = FlutterVmService(vmService); + unawaited(flutterVmService.setAssetDirectory( + assetsDirectory: Uri(path: 'C:/Users/Tester/AppData/Local/Temp/hello_worldb42a6da5/hello_world/build/flutter_assets', scheme: 'file'), + viewId: 'abc', + uiIsolateId: 'def', + // If windows is not set to `true`, then the file path below is incorrectly prepended with a `/` which + // causes the engine asset manager to interpret the file scheme as invalid. + windows: true, + )); + + final Map rawRequest = json.decode(await completer.future) as Map; + + expect(rawRequest, allOf([ + containsPair('method', kSetAssetBundlePathMethod), + containsPair('params', allOf([ + containsPair('viewId', 'abc'), + containsPair('assetDirectory', r'C:\Users\Tester\AppData\Local\Temp\hello_worldb42a6da5\hello_world\build\flutter_assets'), + containsPair('isolateId', 'def'), + ])), + ])); + }); + testWithoutContext('getSkSLs forwards arguments correctly', () async { final Completer completer = Completer(); final vm_service.VmService vmService = vm_service.VmService(