[Windows] Add helper for headless integration tests (flutter/engine#50885)
We'll add more headless mode tests as part of https://github.com/flutter/flutter/issues/143765. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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<FlutterWindowsEngine*>(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 {};
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user