Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
flutter_embedder_test::FlutterEmbedderTest Class Reference
Inheritance diagram for flutter_embedder_test::FlutterEmbedderTest:

Public Member Functions

 FlutterEmbedderTest ()
 
bool HasViewConnected (const fuchsia::ui::observation::geometry::ViewTreeWatcherPtr &view_tree_watcher, std::optional< fuchsia::ui::observation::geometry::WatchResponse > &watch_response, zx_koid_t view_ref_koid)
 
void LaunchParentViewInRealm (const std::vector< std::string > &component_args={})
 
fuchsia_test_utils::Screenshot TakeScreenshot ()
 
bool TakeScreenshotUntil (fuchsia_test_utils::Pixel color, fit::function< void(std::map< fuchsia_test_utils::Pixel, uint32_t >)> callback=nullptr, zx::duration timeout=kTestTimeout)
 

Detailed Description

Definition at line 115 of file flutter-embedder-test.cc.

Constructor & Destructor Documentation

◆ FlutterEmbedderTest()

flutter_embedder_test::FlutterEmbedderTest::FlutterEmbedderTest ( )
inline

Definition at line 118 of file flutter-embedder-test.cc.

119 : realm_builder_(component_testing::RealmBuilder::Create()) {
120 FML_VLOG(1) << "Setting up base realm";
121 SetUpRealmBase();
122
123 // Post a "just in case" quit task, if the test hangs.
124 async::PostDelayedTask(
125 dispatcher(),
126 [] {
128 << "\n\n>> Test did not complete in time, terminating. <<\n\n";
129 },
130 kTestTimeout);
131 }
static sk_sp< Effect > Create()
Definition: RefCntTest.cpp:117
#define FATAL(error)
#define FML_VLOG(verbose_level)
Definition: logging.h:98
#define FML_LOG(severity)
Definition: logging.h:82

Member Function Documentation

◆ HasViewConnected()

bool flutter_embedder_test::FlutterEmbedderTest::HasViewConnected ( const fuchsia::ui::observation::geometry::ViewTreeWatcherPtr &  view_tree_watcher,
std::optional< fuchsia::ui::observation::geometry::WatchResponse > &  watch_response,
zx_koid_t  view_ref_koid 
)

Definition at line 298 of file flutter-embedder-test.cc.

303 {
304 std::optional<fuchsia::ui::observation::geometry::WatchResponse> watch_result;
305 view_tree_watcher->Watch(
306 [&watch_result](auto response) { watch_result = std::move(response); });
307 FML_LOG(INFO) << "Waiting for view tree watch result";
308 RunLoopUntil([&watch_result] { return watch_result.has_value(); });
309 FML_LOG(INFO) << "Received for view tree watch result";
310 if (CheckViewExistsInUpdates(watch_result->updates(), view_ref_koid)) {
311 watch_response = std::move(watch_result);
312 };
313 return watch_response.has_value();
314}
bool CheckViewExistsInUpdates(const std::vector< fuchsia::ui::observation::geometry::ViewTreeSnapshot > &updates, zx_koid_t view_ref_koid)
Definition: check_view.cc:27

◆ LaunchParentViewInRealm()

void flutter_embedder_test::FlutterEmbedderTest::LaunchParentViewInRealm ( const std::vector< std::string > &  component_args = {})

Definition at line 316 of file flutter-embedder-test.cc.

317 {
318 FML_LOG(INFO) << "Launching parent-view";
319
320 if (!component_args.empty()) {
321 // Construct a args.csv file containing the specified comma-separated
322 // component args.
323 std::string csv;
324 for (const auto& arg : component_args) {
325 csv += arg + ',';
326 }
327 // Remove last comma.
328 csv.pop_back();
329
330 auto config_directory_contents = DirectoryContents();
331 config_directory_contents.AddFile("args.csv", csv);
332 realm_builder_.RouteReadOnlyDirectory("config-data", {kParentViewRef},
333 std::move(config_directory_contents));
334 }
335 realm_ = std::make_unique<RealmRoot>(realm_builder_.Build());
336
337 // Get the display information using the |fuchsia.ui.display.singleton.Info|.
338 std::optional<bool> display_metrics_obtained;
339 fuchsia::ui::display::singleton::InfoPtr display_info =
340 realm_->component().Connect<fuchsia::ui::display::singleton::Info>();
341 display_info->GetMetrics([this, &display_metrics_obtained](auto info) {
342 display_width_ = info.extent_in_px().width;
343 display_height_ = info.extent_in_px().height;
344 display_metrics_obtained = true;
345 });
346 RunLoopUntil([&display_metrics_obtained] {
347 return display_metrics_obtained.has_value();
348 });
349 FML_LOG(INFO) << "Got display_width " << display_width_ << " display_height "
350 << display_height_;
351
352 // Instruct Test UI Stack to present parent-view's View.
353 std::optional<zx_koid_t> view_ref_koid;
354 scene_provider_ =
355 realm_->component().Connect<fuchsia::ui::test::scene::Controller>();
356 scene_provider_.set_error_handler(
357 [](auto) { FML_LOG(ERROR) << "Error from test scene provider"; });
358 fuchsia::ui::test::scene::ControllerAttachClientViewRequest request;
359 request.set_view_provider(
360 realm_->component().Connect<fuchsia::ui::app::ViewProvider>());
361 scene_provider_->RegisterViewTreeWatcher(view_tree_watcher_.NewRequest(),
362 []() {});
363 scene_provider_->AttachClientView(
364 std::move(request), [&view_ref_koid](auto client_view_ref_koid) {
365 view_ref_koid = client_view_ref_koid;
366 });
367
368 FML_LOG(INFO) << "Waiting for client view ref koid";
369 RunLoopUntil([&view_ref_koid] { return view_ref_koid.has_value(); });
370
371 // Wait for the client view to get attached to the view tree.
372 std::optional<fuchsia::ui::observation::geometry::WatchResponse>
373 watch_response;
374 FML_LOG(INFO) << "Waiting for client view to render; koid is "
375 << (view_ref_koid.has_value() ? view_ref_koid.value() : 0);
376 RunLoopUntil([this, &watch_response, &view_ref_koid] {
377 return HasViewConnected(view_tree_watcher_, watch_response, *view_ref_koid);
378 });
379 FML_LOG(INFO) << "Client view has rendered";
380
381 screenshot_ =
382 realm_->component().Connect<fuchsia::ui::composition::Screenshot>();
383 FML_LOG(INFO) << "Launched parent-view";
384}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
bool HasViewConnected(const fuchsia::ui::observation::geometry::ViewTreeWatcherPtr &view_tree_watcher, std::optional< fuchsia::ui::observation::geometry::WatchResponse > &watch_response, zx_koid_t view_ref_koid)
#define ERROR(message)
Definition: elf_loader.cc:260

◆ TakeScreenshot()

fuchsia_test_utils::Screenshot flutter_embedder_test::FlutterEmbedderTest::TakeScreenshot ( )

Definition at line 386 of file flutter-embedder-test.cc.

386 {
387 FML_LOG(INFO) << "Taking screenshot... ";
388
389 fuchsia::ui::composition::ScreenshotTakeRequest request;
390 request.set_format(fuchsia::ui::composition::ScreenshotFormat::BGRA_RAW);
391
392 std::optional<fuchsia::ui::composition::ScreenshotTakeResponse> response;
393 screenshot_->Take(std::move(request), [this, &response](auto screenshot) {
394 response = std::move(screenshot);
395 QuitLoop();
396 });
397
398 EXPECT_FALSE(RunLoopWithTimeout(kScreenshotTimeout))
399 << "Timed out waiting for screenshot.";
400 FML_LOG(INFO) << "Screenshot captured.";
401
403 response->vmo(), display_width_, display_height_, /*display_rotation*/ 0);
404}

◆ TakeScreenshotUntil()

bool flutter_embedder_test::FlutterEmbedderTest::TakeScreenshotUntil ( fuchsia_test_utils::Pixel  color,
fit::function< void(std::map< fuchsia_test_utils::Pixel, uint32_t >)>  callback = nullptr,
zx::duration  timeout = kTestTimeout 
)

Definition at line 406 of file flutter-embedder-test.cc.

409 {
410 return RunLoopWithTimeoutOrUntil(
411 [this, &callback, &color] {
412 auto screenshot = TakeScreenshot();
413 auto histogram = screenshot.Histogram();
414
415 bool color_found = histogram[color] > 0;
416 if (color_found && callback != nullptr) {
417 callback(std::move(histogram));
418 }
419 return color_found;
420 },
421 timeout);
422}
fuchsia_test_utils::Screenshot TakeScreenshot()
DlColor color
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
def timeout(deadline, cmd)

The documentation for this class was generated from the following file: