Skip to content

Commit

Permalink
[Windows] Add helper for headless integration tests (#50885)
Browse files Browse the repository at this point in the history
We'll add more headless mode tests as part of flutter/flutter#143765.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
  • Loading branch information
loic-sharma authored Feb 23, 2024
1 parent c278da6 commit 41c3372
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
4 changes: 1 addition & 3 deletions shell/platform/windows/flutter_windows_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 24 additions & 3 deletions shell/platform/windows/testing/windows_test_config_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {};
}
Expand Down
12 changes: 10 additions & 2 deletions shell/platform/windows/testing/windows_test_config_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 41c3372

Please sign in to comment.