Use the correct Settings in Engine::Spawn (#30741)
* Use the correct Settings in Engine::Spawn
* Add unit tests
diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h
index 9fd346a..59c9f1e 100644
--- a/runtime/runtime_controller.h
+++ b/runtime/runtime_controller.h
@@ -532,6 +532,10 @@
// |PlatformConfigurationClient|
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
+
+ // |PlatformConfigurationClient|
+ std::shared_ptr<const fml::Mapping> GetPersistentIsolateData() override;
+
const fml::WeakPtr<IOManager>& GetIOManager() const {
return context_.io_manager;
}
@@ -614,9 +618,6 @@
void SetNeedsReportTimings(bool value) override;
// |PlatformConfigurationClient|
- std::shared_ptr<const fml::Mapping> GetPersistentIsolateData() override;
-
- // |PlatformConfigurationClient|
std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
const std::vector<std::string>& supported_locale_data) override;
diff --git a/shell/common/engine.cc b/shell/common/engine.cc
index d382e5e..103d05e 100644
--- a/shell/common/engine.cc
+++ b/shell/common/engine.cc
@@ -121,15 +121,15 @@
/*font_collection=*/font_collection_,
/*runtime_controller=*/nullptr);
result->runtime_controller_ = runtime_controller_->Spawn(
- *result, // runtime delegate
- settings_.advisory_script_uri, // advisory script uri
- settings_.advisory_script_entrypoint, // advisory script entrypoint
- settings_.idle_notification_callback, // idle notification callback
- settings_.isolate_create_callback, // isolate create callback
- settings_.isolate_shutdown_callback, // isolate shutdown callback
- settings_.persistent_isolate_data, // persistent isolate data
- io_manager, // io_manager
- result->GetImageDecoderWeakPtr() // imageDecoder
+ *result, // runtime delegate
+ settings.advisory_script_uri, // advisory script uri
+ settings.advisory_script_entrypoint, // advisory script entrypoint
+ settings.idle_notification_callback, // idle notification callback
+ settings.isolate_create_callback, // isolate create callback
+ settings.isolate_shutdown_callback, // isolate shutdown callback
+ settings.persistent_isolate_data, // persistent isolate data
+ io_manager, // io_manager
+ result->GetImageDecoderWeakPtr() // imageDecoder
);
result->initial_route_ = initial_route;
return result;
diff --git a/shell/common/engine_unittests.cc b/shell/common/engine_unittests.cc
index 53df307..ed2f8ca 100644
--- a/shell/common/engine_unittests.cc
+++ b/shell/common/engine_unittests.cc
@@ -340,6 +340,41 @@
});
}
+TEST_F(EngineTest, SpawnWithCustomSettings) {
+ PostUITaskSync([this] {
+ MockRuntimeDelegate client;
+ auto mock_runtime_controller =
+ std::make_unique<MockRuntimeController>(client, task_runners_);
+ auto vm_ref = DartVMRef::Create(settings_);
+ EXPECT_CALL(*mock_runtime_controller, GetDartVM())
+ .WillRepeatedly(::testing::Return(vm_ref.get()));
+ auto engine = std::make_unique<Engine>(
+ /*delegate=*/delegate_,
+ /*dispatcher_maker=*/dispatcher_maker_,
+ /*image_decoder_task_runner=*/image_decoder_task_runner_,
+ /*task_runners=*/task_runners_,
+ /*settings=*/settings_,
+ /*animator=*/std::move(animator_),
+ /*io_manager=*/io_manager_,
+ /*font_collection=*/std::make_shared<FontCollection>(),
+ /*runtime_controller=*/std::move(mock_runtime_controller));
+
+ Settings custom_settings = settings_;
+ custom_settings.persistent_isolate_data =
+ std::make_shared<fml::DataMapping>("foo");
+ auto spawn = engine->Spawn(delegate_, dispatcher_maker_, custom_settings,
+ nullptr, std::string(), io_manager_);
+ EXPECT_TRUE(spawn != nullptr);
+ auto new_persistent_isolate_data =
+ const_cast<RuntimeController*>(spawn->GetRuntimeController())
+ ->GetPersistentIsolateData();
+ EXPECT_EQ(custom_settings.persistent_isolate_data->GetMapping(),
+ new_persistent_isolate_data->GetMapping());
+ EXPECT_EQ(custom_settings.persistent_isolate_data->GetSize(),
+ new_persistent_isolate_data->GetSize());
+ });
+}
+
TEST_F(EngineTest, PassesLoadDartDeferredLibraryErrorToRuntime) {
PostUITaskSync([this] {
intptr_t error_id = 123;