diff --git a/assets/asset_manager.cc b/assets/asset_manager.cc index ef73894d07647..ecf97a4ce5e69 100644 --- a/assets/asset_manager.cc +++ b/assets/asset_manager.cc @@ -13,20 +13,22 @@ AssetManager::AssetManager() = default; AssetManager::~AssetManager() = default; -void AssetManager::PushFront(std::unique_ptr resolver) { +bool AssetManager::PushFront(std::unique_ptr resolver) { if (resolver == nullptr || !resolver->IsValid()) { - return; + return false; } resolvers_.push_front(std::move(resolver)); + return true; } -void AssetManager::PushBack(std::unique_ptr resolver) { +bool AssetManager::PushBack(std::unique_ptr resolver) { if (resolver == nullptr || !resolver->IsValid()) { - return; + return false; } resolvers_.push_back(std::move(resolver)); + return true; } void AssetManager::UpdateResolverByType( diff --git a/assets/asset_manager.h b/assets/asset_manager.h index 335bd84116365..b9e704d58a18f 100644 --- a/assets/asset_manager.h +++ b/assets/asset_manager.h @@ -22,9 +22,23 @@ class AssetManager final : public AssetResolver { ~AssetManager() override; - void PushFront(std::unique_ptr resolver); + //-------------------------------------------------------------------------- + /// @brief Adds an asset resolver to the front of the resolver queue. + /// Assets would be loaded from this resolver before any follwing + /// resolvers. + /// + /// @return Returns whether this resolver is valid and has been added to + /// the resolver queue. + bool PushFront(std::unique_ptr resolver); - void PushBack(std::unique_ptr resolver); + //-------------------------------------------------------------------------- + /// @brief Adds an asset resolver to the end of the resolver queue. + /// Assets would be loaded from this resolver after any previous + /// resolvers. + /// + /// @return Returns whether this resolver is valid and has been added to + /// the resolver queue. + bool PushBack(std::unique_ptr resolver); //-------------------------------------------------------------------------- /// @brief Replaces an asset resolver of the specified `type` with diff --git a/shell/common/shell.cc b/shell/common/shell.cc index e28a0391a3552..721a95295c8e2 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -1773,10 +1773,15 @@ bool Shell::OnServiceProtocolSetAssetBundlePath( auto asset_manager = std::make_shared(); - asset_manager->PushFront(std::make_unique( - fml::OpenDirectory(params.at("assetDirectory").data(), false, - fml::FilePermission::kRead), - false)); + if (!asset_manager->PushFront(std::make_unique( + fml::OpenDirectory(params.at("assetDirectory").data(), false, + fml::FilePermission::kRead), + false))) { + // The new asset directory path was invalid. + FML_DLOG(ERROR) << "Could not update asset directory."; + ServiceProtocolFailureError(response, "Could not update asset directory."); + return false; + } // Preserve any original asset resolvers to avoid syncing unchanged assets // over the DevFS connection. diff --git a/testing/dart/observatory/BUILD.gn b/testing/dart/observatory/BUILD.gn index 3aca101451b36..a0e6afbe6be17 100644 --- a/testing/dart/observatory/BUILD.gn +++ b/testing/dart/observatory/BUILD.gn @@ -8,6 +8,7 @@ tests = [ "skp_test.dart", "tracing_test.dart", "shader_reload_test.dart", + "vmservice_methods_test.dart", ] foreach(test, tests) { diff --git a/testing/dart/observatory/vmservice_methods_test.dart b/testing/dart/observatory/vmservice_methods_test.dart new file mode 100644 index 0000000000000..8dbbf0dc6eccb --- /dev/null +++ b/testing/dart/observatory/vmservice_methods_test.dart @@ -0,0 +1,44 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:developer' as developer; + +import 'package:litetest/litetest.dart'; +import 'package:vm_service/vm_service.dart' as vms; +import 'package:vm_service/vm_service_io.dart'; + +void main() { + test('Setting invalid directory returns an error', () async { + vms.VmService? vmService; + try { + final developer.ServiceProtocolInfo info = await developer.Service.getInfo(); + if (info.serverUri == null) { + fail('This test must not be run with --disable-observatory.'); + } + + vmService = await vmServiceConnectUri( + 'ws://localhost:${info.serverUri!.port}${info.serverUri!.path}ws', + ); + final vms.Response response = await vmService.callMethod('_flutter.listViews'); + final List? rawViews = response.json!['views'] as List?; + final String viewId = (rawViews![0]! as Map?)!['id']! as String; + + dynamic error; + try { + final vms.Response setAssetDirectoryPath = await vmService.callMethod( + '_flutter.setAssetBundlePath', + args: { + 'viewId': viewId, + 'assetDirectory': '' + }, + ); + } catch (err) { + error = err; + } + expect(error != null, true); + } finally { + await vmService?.dispose(); + } + }); +}