diff --git a/shell/platform/windows/flutter_windows_unittests.cc b/shell/platform/windows/flutter_windows_unittests.cc index e012254d976b2..a35bfae0f6cea 100644 --- a/shell/platform/windows/flutter_windows_unittests.cc +++ b/shell/platform/windows/flutter_windows_unittests.cc @@ -116,10 +116,8 @@ TEST_F(WindowsTest, LaunchCustomEntrypointInEngineRunInvocation) { TEST_F(WindowsTest, LaunchHeadlessEngine) { auto& context = GetContext(); WindowsConfigBuilder builder(context); - EnginePtr engine{builder.InitializeEngine()}; + EnginePtr engine{builder.RunHeadless()}; ASSERT_NE(engine, nullptr); - - ASSERT_TRUE(FlutterDesktopEngineRun(engine.get(), nullptr)); } // Verify that accessibility features are initialized when a view is created. diff --git a/shell/platform/windows/testing/windows_test_config_builder.cc b/shell/platform/windows/testing/windows_test_config_builder.cc index 35376e241f062..f39b4db64377d 100644 --- a/shell/platform/windows/testing/windows_test_config_builder.cc +++ b/shell/platform/windows/testing/windows_test_config_builder.cc @@ -68,7 +68,28 @@ FlutterDesktopEngineProperties WindowsConfigBuilder::GetEngineProperties() EnginePtr WindowsConfigBuilder::InitializeEngine() const { FlutterDesktopEngineProperties engine_properties = GetEngineProperties(); - return EnginePtr(FlutterDesktopEngineCreate(&engine_properties)); + return EnginePtr{FlutterDesktopEngineCreate(&engine_properties)}; +} + +EnginePtr WindowsConfigBuilder::RunHeadless() const { + InitializeCOM(); + + EnginePtr engine = InitializeEngine(); + if (!engine) { + return {}; + } + + // Register native functions. + FlutterWindowsEngine* windows_engine = + reinterpret_cast(engine.get()); + windows_engine->SetRootIsolateCreateCallback( + context_.GetRootIsolateCallback()); + + if (!FlutterDesktopEngineRun(engine.get(), /* entry_point */ nullptr)) { + return {}; + } + + return engine; } ViewControllerPtr WindowsConfigBuilder::Run() const { @@ -87,8 +108,8 @@ ViewControllerPtr WindowsConfigBuilder::Run() const { int width = 600; int height = 400; - ViewControllerPtr controller( - FlutterDesktopViewControllerCreate(width, height, engine.release())); + ViewControllerPtr controller{ + FlutterDesktopViewControllerCreate(width, height, engine.release())}; if (!controller) { return {}; } diff --git a/shell/platform/windows/testing/windows_test_config_builder.h b/shell/platform/windows/testing/windows_test_config_builder.h index 7ec9a3352b741..f634c86f53948 100644 --- a/shell/platform/windows/testing/windows_test_config_builder.h +++ b/shell/platform/windows/testing/windows_test_config_builder.h @@ -64,8 +64,16 @@ class WindowsConfigBuilder { // Returns a configured and initialized engine. EnginePtr InitializeEngine() const; - // Returns a configured and initialized view controller running the default - // Dart entrypoint. + // Returns a configured and initialized engine that runs the configured Dart + // entrypoint. + // + // Returns null on failure. + EnginePtr RunHeadless() const; + + // Returns a configured and initialized view controller that runs the + // configured Dart entrypoint. + // + // Returns null on failure. ViewControllerPtr Run() const; private: