Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Add helper for headless integration tests #50885

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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