Flutter Engine
flutter_runner::testing Namespace Reference

Classes

class  PlatformViewTests
 

Functions

 TEST_F (PlatformViewTests, CreateSurfaceTest)
 
 TEST_F (PlatformViewTests, SetViewportMetrics)
 
 TEST_F (PlatformViewTests, ChangesAccessibilitySettings)
 
 TEST_F (PlatformViewTests, EnableWireframeTest)
 
 TEST_F (PlatformViewTests, CreateViewTest)
 
 TEST_F (PlatformViewTests, UpdateViewTest)
 
 TEST_F (PlatformViewTests, DestroyViewTest)
 
 TEST_F (PlatformViewTests, ViewEventsTest)
 
 TEST_F (PlatformViewTests, RequestFocusTest)
 
 TEST_F (PlatformViewTests, RequestFocusFailTest)
 

Function Documentation

◆ TEST_F() [1/10]

flutter_runner::testing::TEST_F ( PlatformViewTests  ,
CreateSurfaceTest   
)

Definition at line 171 of file platform_view_unittest.cc.

References flutter_runner::CreateFMLTaskRunner(), flutter::PlatformView::NotifyCreated(), and fml::TimeDelta::Zero().

171  {
172  sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
173  MockPlatformViewDelegate delegate;
174 
175  flutter::TaskRunners task_runners =
176  flutter::TaskRunners("test_runners", // label
177  nullptr, // platform
179  async_get_default_dispatcher()), // raster
180  nullptr, // ui
181  nullptr // io
182  );
183 
184  // Test create surface callback function.
185  sk_sp<GrDirectContext> gr_context =
186  GrDirectContext::MakeMock(nullptr, GrContextOptions());
187  std::shared_ptr<MockExternalViewEmbedder> view_embedder =
188  std::make_shared<MockExternalViewEmbedder>();
189  auto CreateSurfaceCallback = [&view_embedder, gr_context]() {
190  return std::make_unique<flutter_runner::Surface>(
191  "PlatformViewTest", view_embedder, gr_context.get());
192  };
193 
194  auto platform_view = flutter_runner::PlatformView(
195  delegate, // delegate
196  "test_platform_view", // label
197  fuchsia::ui::views::ViewRef(), // view_ref
198  std::move(task_runners), // task_runners
199  services_provider.service_directory(), // runner_services
200  nullptr, // parent_environment_service_provider_handle
201  nullptr, // session_listener_request
202  nullptr, // focuser,
203  nullptr, // on_session_listener_error_callback
204  nullptr, // on_enable_wireframe_callback,
205  nullptr, // on_create_view_callback,
206  nullptr, // on_update_view_callback,
207  nullptr, // on_destroy_view_callback,
208  CreateSurfaceCallback, // on_create_surface_callback,
209  view_embedder, // external_view_embedder,
210  fml::TimeDelta::Zero(), // vsync_offset
211  ZX_HANDLE_INVALID // vsync_event_handle
212  );
213  platform_view.NotifyCreated();
214 
215  RunLoopUntilIdle();
216 
217  EXPECT_EQ(gr_context.get(), delegate.surface()->GetContext());
218  EXPECT_EQ(view_embedder.get(), delegate.surface()->GetExternalViewEmbedder());
219 }
fml::RefPtr< fml::TaskRunner > CreateFMLTaskRunner(async_dispatcher_t *dispatcher)
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
void NotifyCreated()
Used by embedders to notify the shell that a platform view has been created. This notification is use...

◆ TEST_F() [2/10]

flutter_runner::testing::TEST_F ( PlatformViewTests  ,
SetViewportMetrics   
)

Definition at line 224 of file platform_view_unittest.cc.

References fml::TimeDelta::Zero().

224  {
225  constexpr float invalid_pixel_ratio = -0.75f;
226  constexpr float valid_pixel_ratio = 0.75f;
227  constexpr float invalid_max_bound = -0.75f;
228  constexpr float valid_max_bound = 0.75f;
229 
230  MockPlatformViewDelegate delegate;
231  EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics());
232 
233  fuchsia::ui::scenic::SessionListenerPtr session_listener;
234  std::vector<fuchsia::ui::scenic::Event> events;
235  sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
236  flutter::TaskRunners task_runners("test_runners", nullptr, nullptr, nullptr,
237  nullptr);
238  flutter_runner::PlatformView platform_view(
239  delegate, // delegate
240  "test_platform_view", // label
241  fuchsia::ui::views::ViewRef(), // view_ref
242  std::move(task_runners), // task_runners
243  services_provider.service_directory(), // runner_services
244  nullptr, // parent_environment_service_provider_handle
245  session_listener.NewRequest(), // session_listener_request
246  nullptr, // focuser,
247  nullptr, // on_session_listener_error_callback
248  nullptr, // on_enable_wireframe_callback,
249  nullptr, // on_create_view_callback,
250  nullptr, // on_update_view_callback,
251  nullptr, // on_destroy_view_callback,
252  nullptr, // on_create_surface_callback,
253  nullptr, // external_view_embedder,
254  fml::TimeDelta::Zero(), // vsync_offset
255  ZX_HANDLE_INVALID // vsync_event_handle
256  );
257  RunLoopUntilIdle();
258  EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics());
259 
260  // Test updating with an invalid pixel ratio. The final metrics should be
261  // unchanged.
262  events.clear();
263  events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
264  fuchsia::ui::gfx::Event::WithMetrics(fuchsia::ui::gfx::MetricsEvent{
265  .node_id = 0,
266  .metrics =
267  fuchsia::ui::gfx::Metrics{
268  .scale_x = invalid_pixel_ratio,
269  .scale_y = 1.f,
270  .scale_z = 1.f,
271  },
272  })));
273  session_listener->OnScenicEvent(std::move(events));
274  RunLoopUntilIdle();
275  EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics());
276 
277  // Test updating with an invalid size. The final metrics should be unchanged.
278  events.clear();
279  events.emplace_back(
280  fuchsia::ui::scenic::Event::WithGfx(
281  fuchsia::ui::gfx::Event::WithViewPropertiesChanged(
282  fuchsia::ui::gfx::ViewPropertiesChangedEvent{
283  .view_id = 0,
284  .properties =
285  fuchsia::ui::gfx::ViewProperties{
286  .bounding_box =
287  fuchsia::ui::gfx::BoundingBox{
288  .min =
289  fuchsia::ui::gfx::vec3{
290  .x = 0.f,
291  .y = 0.f,
292  .z = 0.f,
293  },
294  .max =
295  fuchsia::ui::gfx::vec3{
296  .x = invalid_max_bound,
297  .y = invalid_max_bound,
298  .z = invalid_max_bound,
299  },
300  },
301  },
302  })));
303  session_listener->OnScenicEvent(std::move(events));
304  RunLoopUntilIdle();
305  EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics());
306 
307  // Test updating the size only. The final metrics should be unchanged until
308  // both pixel ratio and size are updated.
309  events.clear();
310  events.emplace_back(
311  fuchsia::ui::scenic::Event::WithGfx(
312  fuchsia::ui::gfx::Event::WithViewPropertiesChanged(
313  fuchsia::ui::gfx::ViewPropertiesChangedEvent{
314  .view_id = 0,
315  .properties =
316  fuchsia::ui::gfx::ViewProperties{
317  .bounding_box =
318  fuchsia::ui::gfx::BoundingBox{
319  .min =
320  fuchsia::ui::gfx::vec3{
321  .x = 0.f,
322  .y = 0.f,
323  .z = 0.f,
324  },
325  .max =
326  fuchsia::ui::gfx::vec3{
327  .x = valid_max_bound,
328  .y = valid_max_bound,
329  .z = valid_max_bound,
330  },
331  },
332  },
333  })));
334  session_listener->OnScenicEvent(std::move(events));
335  RunLoopUntilIdle();
336  EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics());
337 
338  // Test updating the pixel ratio only. The final metrics should change now.
339  events.clear();
340  events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
341  fuchsia::ui::gfx::Event::WithMetrics(fuchsia::ui::gfx::MetricsEvent{
342  .node_id = 0,
343  .metrics =
344  fuchsia::ui::gfx::Metrics{
345  .scale_x = valid_pixel_ratio,
346  .scale_y = 1.f,
347  .scale_z = 1.f,
348  },
349  })));
350  session_listener->OnScenicEvent(std::move(events));
351  RunLoopUntilIdle();
352  EXPECT_EQ(delegate.metrics(),
353  flutter::ViewportMetrics(valid_pixel_ratio,
354  valid_pixel_ratio * valid_max_bound,
355  valid_pixel_ratio * valid_max_bound));
356 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33

◆ TEST_F() [3/10]

flutter_runner::testing::TEST_F ( PlatformViewTests  ,
ChangesAccessibilitySettings   
)

Definition at line 361 of file platform_view_unittest.cc.

References flutter::kAccessibleNavigation, and fml::TimeDelta::Zero().

361  {
362  sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
363 
364  MockPlatformViewDelegate delegate;
365  flutter::TaskRunners task_runners =
366  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
367 
368  EXPECT_FALSE(delegate.semantics_enabled());
369  EXPECT_EQ(delegate.semantics_features(), 0);
370 
371  auto platform_view = flutter_runner::PlatformView(
372  delegate, // delegate
373  "test_platform_view", // label
374  fuchsia::ui::views::ViewRef(), // view_ref
375  std::move(task_runners), // task_runners
376  services_provider.service_directory(), // runner_services
377  nullptr, // parent_environment_service_provider_handle
378  nullptr, // session_listener_request
379  nullptr, // focuser,
380  nullptr, // on_session_listener_error_callback
381  nullptr, // on_enable_wireframe_callback,
382  nullptr, // on_create_view_callback,
383  nullptr, // on_update_view_callback,
384  nullptr, // on_destroy_view_callback,
385  nullptr, // on_create_surface_callback,
386  nullptr, // external_view_embedder,
387  fml::TimeDelta::Zero(), // vsync_offset
388  ZX_HANDLE_INVALID // vsync_event_handle
389  );
390 
391  RunLoopUntilIdle();
392 
393  platform_view.SetSemanticsEnabled(true);
394 
395  EXPECT_TRUE(delegate.semantics_enabled());
396  EXPECT_EQ(delegate.semantics_features(),
397  static_cast<int32_t>(
399 
400  platform_view.SetSemanticsEnabled(false);
401 
402  EXPECT_FALSE(delegate.semantics_enabled());
403  EXPECT_EQ(delegate.semantics_features(), 0);
404 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33

◆ TEST_F() [4/10]

flutter_runner::testing::TEST_F ( PlatformViewTests  ,
EnableWireframeTest   
)

Definition at line 408 of file platform_view_unittest.cc.

References fml::TimeDelta::Zero().

408  {
409  sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
410  MockPlatformViewDelegate delegate;
411  flutter::TaskRunners task_runners =
412  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
413 
414  // Test wireframe callback function. If the message sent to the platform
415  // view was properly handled and parsed, this function should be called,
416  // setting |wireframe_enabled| to true.
417  bool wireframe_enabled = false;
418  auto EnableWireframeCallback = [&wireframe_enabled](bool should_enable) {
419  wireframe_enabled = should_enable;
420  };
421 
422  auto platform_view = flutter_runner::PlatformView(
423  delegate, // delegate
424  "test_platform_view", // label
425  fuchsia::ui::views::ViewRef(), // view_ref
426  std::move(task_runners), // task_runners
427  services_provider.service_directory(), // runner_services
428  nullptr, // parent_environment_service_provider_handle
429  nullptr, // session_listener_request
430  nullptr, // focuser,
431  nullptr, // on_session_listener_error_callback
432  EnableWireframeCallback, // on_enable_wireframe_callback,
433  nullptr, // on_create_view_callback,
434  nullptr, // on_update_view_callback,
435  nullptr, // on_destroy_view_callback,
436  nullptr, // on_create_surface_callback,
437  nullptr, // external_view_embedder,
438  fml::TimeDelta::Zero(), // vsync_offset
439  ZX_HANDLE_INVALID // vsync_event_handle
440  );
441 
442  // Cast platform_view to its base view so we can have access to the public
443  // "HandlePlatformMessage" function.
444  auto base_view = dynamic_cast<flutter::PlatformView*>(&platform_view);
445  EXPECT_TRUE(base_view);
446 
447  // JSON for the message to be passed into the PlatformView.
448  const uint8_t txt[] =
449  "{"
450  " \"method\":\"View.enableWireframe\","
451  " \"args\": {"
452  " \"enable\":true"
453  " }"
454  "}";
455 
457  fml::MakeRefCounted<flutter::PlatformMessage>(
458  "flutter/platform_views",
459  std::vector<uint8_t>(txt, txt + sizeof(txt)),
461  base_view->HandlePlatformMessage(message);
462 
463  RunLoopUntilIdle();
464 
465  EXPECT_TRUE(wireframe_enabled);
466 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:44

◆ TEST_F() [5/10]

flutter_runner::testing::TEST_F ( PlatformViewTests  ,
CreateViewTest   
)

Definition at line 470 of file platform_view_unittest.cc.

References fml::TimeDelta::Zero().

470  {
471  sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
472  MockPlatformViewDelegate delegate;
473  flutter::TaskRunners task_runners =
474  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
475 
476  // Test wireframe callback function. If the message sent to the platform
477  // view was properly handled and parsed, this function should be called,
478  // setting |wireframe_enabled| to true.
479  int64_t create_view_called = false;
480  auto CreateViewCallback = [&create_view_called](
481  int64_t view_id, bool hit_testable,
482  bool focusable) { create_view_called = true; };
483 
484  auto platform_view = flutter_runner::PlatformView(
485  delegate, // delegate
486  "test_platform_view", // label
487  fuchsia::ui::views::ViewRef(), // view_ref
488  std::move(task_runners), // task_runners
489  services_provider.service_directory(), // runner_services
490  nullptr, // parent_environment_service_provider_handle
491  nullptr, // session_listener_request
492  nullptr, // focuser,
493  nullptr, // on_session_listener_error_callback
494  nullptr, // on_enable_wireframe_callback,
495  CreateViewCallback, // on_create_view_callback,
496  nullptr, // on_update_view_callback,
497  nullptr, // on_destroy_view_callback,
498  nullptr, // on_create_surface_callback,
499  nullptr, // external_view_embedder,
500  fml::TimeDelta::Zero(), // vsync_offset
501  ZX_HANDLE_INVALID // vsync_event_handle
502  );
503 
504  // Cast platform_view to its base view so we can have access to the public
505  // "HandlePlatformMessage" function.
506  auto base_view = dynamic_cast<flutter::PlatformView*>(&platform_view);
507  EXPECT_TRUE(base_view);
508 
509  // JSON for the message to be passed into the PlatformView.
510  const uint8_t txt[] =
511  "{"
512  " \"method\":\"View.create\","
513  " \"args\": {"
514  " \"viewId\":42,"
515  " \"hitTestable\":true,"
516  " \"focusable\":true"
517  " }"
518  "}";
519 
521  fml::MakeRefCounted<flutter::PlatformMessage>(
522  "flutter/platform_views",
523  std::vector<uint8_t>(txt, txt + sizeof(txt)),
525  base_view->HandlePlatformMessage(message);
526 
527  RunLoopUntilIdle();
528 
529  EXPECT_TRUE(create_view_called);
530 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:44

◆ TEST_F() [6/10]

flutter_runner::testing::TEST_F ( PlatformViewTests  ,
UpdateViewTest   
)

Definition at line 534 of file platform_view_unittest.cc.

References fml::TimeDelta::Zero().

534  {
535  sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
536  MockPlatformViewDelegate delegate;
537  flutter::TaskRunners task_runners =
538  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
539 
540  // Test wireframe callback function. If the message sent to the platform
541  // view was properly handled and parsed, this function should be called,
542  // setting |wireframe_enabled| to true.
543  int64_t update_view_called = false;
544  auto UpdateViewCallback = [&update_view_called](
545  int64_t view_id, bool hit_testable,
546  bool focusable) { update_view_called = true; };
547 
548  auto platform_view = flutter_runner::PlatformView(
549  delegate, // delegate
550  "test_platform_view", // label
551  fuchsia::ui::views::ViewRef(), // view_ref
552  std::move(task_runners), // task_runners
553  services_provider.service_directory(), // runner_services
554  nullptr, // parent_environment_service_provider_handle
555  nullptr, // session_listener_request
556  nullptr, // focuser,
557  nullptr, // on_session_listener_error_callback
558  nullptr, // on_enable_wireframe_callback,
559  nullptr, // on_create_view_callback,
560  UpdateViewCallback, // on_update_view_callback,
561  nullptr, // on_destroy_view_callback,
562  nullptr, // on_create_surface_callback,
563  nullptr, // external_view_embedder,
564  fml::TimeDelta::Zero(), // vsync_offset
565  ZX_HANDLE_INVALID // vsync_event_handle
566  );
567 
568  // Cast platform_view to its base view so we can have access to the public
569  // "HandlePlatformMessage" function.
570  auto base_view = dynamic_cast<flutter::PlatformView*>(&platform_view);
571  EXPECT_TRUE(base_view);
572 
573  // JSON for the message to be passed into the PlatformView.
574  const uint8_t txt[] =
575  "{"
576  " \"method\":\"View.update\","
577  " \"args\": {"
578  " \"viewId\":42,"
579  " \"hitTestable\":true,"
580  " \"focusable\":true"
581  " }"
582  "}";
583 
585  fml::MakeRefCounted<flutter::PlatformMessage>(
586  "flutter/platform_views",
587  std::vector<uint8_t>(txt, txt + sizeof(txt)),
589  base_view->HandlePlatformMessage(message);
590 
591  RunLoopUntilIdle();
592 
593  EXPECT_TRUE(update_view_called);
594 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:44

◆ TEST_F() [7/10]

flutter_runner::testing::TEST_F ( PlatformViewTests  ,
DestroyViewTest   
)

Definition at line 598 of file platform_view_unittest.cc.

References fml::TimeDelta::Zero().

598  {
599  sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
600  MockPlatformViewDelegate delegate;
601  flutter::TaskRunners task_runners =
602  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
603 
604  // Test wireframe callback function. If the message sent to the platform
605  // view was properly handled and parsed, this function should be called,
606  // setting |wireframe_enabled| to true.
607  int64_t destroy_view_called = false;
608  auto DestroyViewCallback = [&destroy_view_called](int64_t view_id) {
609  destroy_view_called = true;
610  };
611 
612  auto platform_view = flutter_runner::PlatformView(
613  delegate, // delegate
614  "test_platform_view", // label
615  fuchsia::ui::views::ViewRef(), // view_ref
616  std::move(task_runners), // task_runners
617  services_provider.service_directory(), // runner_services
618  nullptr, // parent_environment_service_provider_handle
619  nullptr, // session_listener_request
620  nullptr, // focuser,
621  nullptr, // on_session_listener_error_callback
622  nullptr, // on_enable_wireframe_callback,
623  nullptr, // on_create_view_callback,
624  nullptr, // on_update_view_callback,
625  DestroyViewCallback, // on_destroy_view_callback,
626  nullptr, // on_create_surface_callback,
627  nullptr, // external_view_embedder,
628  fml::TimeDelta::Zero(), // vsync_offset
629  ZX_HANDLE_INVALID // vsync_event_handle
630  );
631 
632  // Cast platform_view to its base view so we can have access to the public
633  // "HandlePlatformMessage" function.
634  auto base_view = dynamic_cast<flutter::PlatformView*>(&platform_view);
635  EXPECT_TRUE(base_view);
636 
637  // JSON for the message to be passed into the PlatformView.
638  const uint8_t txt[] =
639  "{"
640  " \"method\":\"View.dispose\","
641  " \"args\": {"
642  " \"viewId\":42"
643  " }"
644  "}";
645 
647  fml::MakeRefCounted<flutter::PlatformMessage>(
648  "flutter/platform_views",
649  std::vector<uint8_t>(txt, txt + sizeof(txt)),
651  base_view->HandlePlatformMessage(message);
652 
653  RunLoopUntilIdle();
654 
655  EXPECT_TRUE(destroy_view_called);
656 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:44

◆ TEST_F() [8/10]

flutter_runner::testing::TEST_F ( PlatformViewTests  ,
ViewEventsTest   
)

Definition at line 661 of file platform_view_unittest.cc.

References flutter_runner::CreateFMLTaskRunner(), and fml::TimeDelta::Zero().

661  {
662  MockPlatformViewDelegate delegate;
663 
664  fuchsia::ui::scenic::SessionListenerPtr session_listener;
665  std::vector<fuchsia::ui::scenic::Event> events;
666  sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
667 
669  "test_runners", nullptr, nullptr,
670  flutter_runner::CreateFMLTaskRunner(async_get_default_dispatcher()),
671  nullptr);
672 
673  auto platform_view = flutter_runner::PlatformView(
674  delegate, // delegate
675  "test_platform_view", // label
676  fuchsia::ui::views::ViewRef(), // view_ref
677  std::move(task_runners), // task_runners
678  services_provider.service_directory(), // runner_services
679  nullptr, // parent_environment_service_provider_handle
680  session_listener.NewRequest(), // session_listener_request
681  nullptr, // focuser,
682  nullptr, // on_session_listener_error_callback
683  nullptr, // on_enable_wireframe_callback,
684  nullptr, // on_create_view_callback,
685  nullptr, // on_update_view_callback,
686  nullptr, // on_destroy_view_callback,
687  nullptr, // on_create_surface_callback,
688  nullptr, // external_view_embedder,
689  fml::TimeDelta::Zero(), // vsync_offset
690  ZX_HANDLE_INVALID // vsync_event_handle
691  );
692  RunLoopUntilIdle();
693 
694  // ViewConnected event.
695  events.clear();
696  events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
697  fuchsia::ui::gfx::Event::WithViewConnected(
698  fuchsia::ui::gfx::ViewConnectedEvent{
699  .view_holder_id = 0,
700  })));
701  session_listener->OnScenicEvent(std::move(events));
702  RunLoopUntilIdle();
703 
704  auto data = delegate.message()->data();
705  auto call = std::string(data.begin(), data.end());
706  std::string expected = "{\"method\":\"View.viewConnected\",\"args\":null}";
707  EXPECT_EQ(expected, call);
708 
709  // ViewDisconnected event.
710  events.clear();
711  events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
712  fuchsia::ui::gfx::Event::WithViewDisconnected(
713  fuchsia::ui::gfx::ViewDisconnectedEvent{
714  .view_holder_id = 0,
715  })));
716  session_listener->OnScenicEvent(std::move(events));
717  RunLoopUntilIdle();
718 
719  data = delegate.message()->data();
720  call = std::string(data.begin(), data.end());
721  expected = "{\"method\":\"View.viewDisconnected\",\"args\":null}";
722  EXPECT_EQ(expected, call);
723 
724  // ViewStateChanged event.
725  events.clear();
726  events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
727  fuchsia::ui::gfx::Event::WithViewStateChanged(
728  fuchsia::ui::gfx::ViewStateChangedEvent{
729  .view_holder_id = 0,
730  .state =
731  fuchsia::ui::gfx::ViewState{
732  .is_rendering = true,
733  },
734  })));
735  session_listener->OnScenicEvent(std::move(events));
736  RunLoopUntilIdle();
737 
738  data = delegate.message()->data();
739  call = std::string(data.begin(), data.end());
740  expected = "{\"method\":\"View.viewStateChanged\",\"args\":{\"state\":true}}";
741  EXPECT_EQ(expected, call);
742 }
fml::RefPtr< fml::TaskRunner > CreateFMLTaskRunner(async_dispatcher_t *dispatcher)
static constexpr TimeDelta Zero()
Definition: time_delta.h:33

◆ TEST_F() [9/10]

flutter_runner::testing::TEST_F ( PlatformViewTests  ,
RequestFocusTest   
)

Definition at line 746 of file platform_view_unittest.cc.

References fml::TimeDelta::Zero().

746  {
747  sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
748  MockPlatformViewDelegate delegate;
749  flutter::TaskRunners task_runners =
750  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
751 
752  MockFocuser mock_focuser;
753  fidl::BindingSet<fuchsia::ui::views::Focuser> focuser_bindings;
754  auto focuser_handle = focuser_bindings.AddBinding(&mock_focuser);
755 
756  auto platform_view = flutter_runner::PlatformView(
757  delegate, // delegate
758  "test_platform_view", // label
759  fuchsia::ui::views::ViewRef(), // view_ref
760  std::move(task_runners), // task_runners
761  services_provider.service_directory(), // runner_services
762  nullptr, // parent_environment_service_provider_handle
763  nullptr, // session_listener_request
764  std::move(focuser_handle), // focuser,
765  nullptr, // on_session_listener_error_callback
766  nullptr, // on_enable_wireframe_callback,
767  nullptr, // on_create_view_callback,
768  nullptr, // on_update_view_callback,
769  nullptr, // on_destroy_view_callback,
770  nullptr, // on_create_surface_callback,
771  nullptr, // external_view_embedder,
772  fml::TimeDelta::Zero(), // vsync_offset
773  ZX_HANDLE_INVALID // vsync_event_handle
774  );
775 
776  // Cast platform_view to its base view so we can have access to the public
777  // "HandlePlatformMessage" function.
778  auto base_view = dynamic_cast<flutter::PlatformView*>(&platform_view);
779  EXPECT_TRUE(base_view);
780 
781  // This "Mock" ViewRef serves as the target for the RequestFocus operation.
782  auto mock_view_ref_pair = scenic::ViewRefPair::New();
783 
784  // JSON for the message to be passed into the PlatformView.
785  char buff[254];
786  snprintf(buff, sizeof(buff),
787  "{"
788  " \"method\":\"View.requestFocus\","
789  " \"args\": {"
790  " \"viewRef\":%u"
791  " }"
792  "}",
793  mock_view_ref_pair.view_ref.reference.get());
794 
795  // Define a custom gmock matcher to capture the response to platform message.
796  struct DataArg {
797  void Complete(std::unique_ptr<fml::Mapping> data) {
798  this->data = std::move(data);
799  }
800  std::unique_ptr<fml::Mapping> data;
801  };
802  DataArg data_arg;
803  fml::RefPtr<MockResponse> response = fml::MakeRefCounted<MockResponse>();
804  EXPECT_CALL(*response, Complete(::testing::_))
805  .WillOnce(::testing::Invoke(&data_arg, &DataArg::Complete));
806 
808  fml::MakeRefCounted<flutter::PlatformMessage>(
809  "flutter/platform_views",
810  std::vector<uint8_t>(buff, buff + sizeof(buff)), response);
811  base_view->HandlePlatformMessage(message);
812 
813  RunLoopUntilIdle();
814 
815  EXPECT_TRUE(mock_focuser.request_focus_called());
816  auto result = std::string((const char*)data_arg.data->GetMapping(),
817  data_arg.data->GetSize());
818  EXPECT_EQ(std::string("[0]"), result);
819 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:44

◆ TEST_F() [10/10]

flutter_runner::testing::TEST_F ( PlatformViewTests  ,
RequestFocusFailTest   
)

Definition at line 823 of file platform_view_unittest.cc.

References fml::TimeDelta::Zero().

823  {
824  sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
825  MockPlatformViewDelegate delegate;
826  flutter::TaskRunners task_runners =
827  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
828 
829  MockFocuser mock_focuser(true /*fail_request_focus*/);
830  fidl::BindingSet<fuchsia::ui::views::Focuser> focuser_bindings;
831  auto focuser_handle = focuser_bindings.AddBinding(&mock_focuser);
832 
833  auto platform_view = flutter_runner::PlatformView(
834  delegate, // delegate
835  "test_platform_view", // label
836  fuchsia::ui::views::ViewRef(), // view_ref
837  std::move(task_runners), // task_runners
838  services_provider.service_directory(), // runner_services
839  nullptr, // parent_environment_service_provider_handle
840  nullptr, // session_listener_request
841  std::move(focuser_handle), // focuser,
842  nullptr, // on_session_listener_error_callback
843  nullptr, // on_enable_wireframe_callback,
844  nullptr, // on_create_view_callback,
845  nullptr, // on_update_view_callback,
846  nullptr, // on_destroy_view_callback,
847  nullptr, // on_create_surface_callback,
848  nullptr, // external_view_embedder,
849  fml::TimeDelta::Zero(), // vsync_offset
850  ZX_HANDLE_INVALID // vsync_event_handle
851  );
852 
853  // Cast platform_view to its base view so we can have access to the public
854  // "HandlePlatformMessage" function.
855  auto base_view = dynamic_cast<flutter::PlatformView*>(&platform_view);
856  EXPECT_TRUE(base_view);
857 
858  // This "Mock" ViewRef serves as the target for the RequestFocus operation.
859  auto mock_view_ref_pair = scenic::ViewRefPair::New();
860 
861  // JSON for the message to be passed into the PlatformView.
862  char buff[254];
863  snprintf(buff, sizeof(buff),
864  "{"
865  " \"method\":\"View.requestFocus\","
866  " \"args\": {"
867  " \"viewRef\":%u"
868  " }"
869  "}",
870  mock_view_ref_pair.view_ref.reference.get());
871 
872  // Define a custom gmock matcher to capture the response to platform message.
873  struct DataArg {
874  void Complete(std::unique_ptr<fml::Mapping> data) {
875  this->data = std::move(data);
876  }
877  std::unique_ptr<fml::Mapping> data;
878  };
879  DataArg data_arg;
880  fml::RefPtr<MockResponse> response = fml::MakeRefCounted<MockResponse>();
881  EXPECT_CALL(*response, Complete(::testing::_))
882  .WillOnce(::testing::Invoke(&data_arg, &DataArg::Complete));
883 
885  fml::MakeRefCounted<flutter::PlatformMessage>(
886  "flutter/platform_views",
887  std::vector<uint8_t>(buff, buff + sizeof(buff)), response);
888  base_view->HandlePlatformMessage(message);
889 
890  RunLoopUntilIdle();
891 
892  EXPECT_TRUE(mock_focuser.request_focus_called());
893  auto result = std::string((const char*)data_arg.data->GetMapping(),
894  data_arg.data->GetSize());
895  std::ostringstream out;
896  out << "["
897  << static_cast<std::underlying_type_t<fuchsia::ui::views::Error>>(
898  fuchsia::ui::views::Error::DENIED)
899  << "]";
900  EXPECT_EQ(out.str(), result);
901 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:44