Flutter Engine
flutter_runner::testing Namespace Reference

Classes

class  EngineTest
 
struct  FakeEntityNodeT
 
class  FakeFlatland
 
class  FakeFlatlandTest
 
class  FakeFocuser
 
struct  FakeImageT
 
struct  FakeMaterialT
 
struct  FakeMemoryT
 
class  FakeMouseSource
 
struct  FakeNodeT
 
struct  FakeOpacityNodeT
 
class  FakePlatformMessageResponse
 
struct  FakeResourceT
 
struct  FakeSceneGraphT
 
class  FakeSession
 
class  FakeSessionTest
 
struct  FakeShapeNodeT
 
struct  FakeShapeT
 
class  FakeTouchSource
 
struct  FakeViewHolderT
 
class  FakeViewRefFocused
 
struct  FakeViewT
 
class  FlatlandConnectionTest
 
class  FocusDelegateTest
 
class  GfxExternalViewEmbedderTest
 
class  GfxSessionConnectionTest
 
class  MockTaskRunner
 
class  PlatformViewTests
 
class  PointerDelegateTest
 
struct  SnapshotT
 
struct  StateT
 
class  TouchEventBuilder
 

Typedefs

using fup_EventPhase = fuchsia::ui::pointer::EventPhase
 
using fup_TouchEvent = fuchsia::ui::pointer::TouchEvent
 
using fup_TouchIxnId = fuchsia::ui::pointer::TouchInteractionId
 
using fup_TouchIxnResult = fuchsia::ui::pointer::TouchInteractionResult
 
using fup_TouchIxnStatus = fuchsia::ui::pointer::TouchInteractionStatus
 
using fup_TouchPointerSample = fuchsia::ui::pointer::TouchPointerSample
 
using fup_TouchResponse = fuchsia::ui::pointer::TouchResponse
 
using fup_TouchResponseType = fuchsia::ui::pointer::TouchResponseType
 
using fup_ViewParameters = fuchsia::ui::pointer::ViewParameters
 
using FakeResourceId = decltype(fuchsia::ui::gfx::CreateResourceCmd::id)
 
using FakeNodeState = FakeNodeT< StateT >
 
using FakeNode = FakeNodeT< SnapshotT >
 
using FakeEntityNodeState = FakeEntityNodeT< StateT >
 
using FakeEntityNode = FakeEntityNodeT< SnapshotT >
 
using FakeOpacityNodeState = FakeOpacityNodeT< StateT >
 
using FakeOpacityNode = FakeOpacityNodeT< SnapshotT >
 
using FakeShapeNodeState = FakeShapeNodeT< StateT >
 
using FakeShapeNode = FakeShapeNodeT< SnapshotT >
 
using FakeViewState = FakeViewT< StateT >
 
using FakeView = FakeViewT< SnapshotT >
 
using FakeViewHolderState = FakeViewHolderT< StateT >
 
using FakeViewHolder = FakeViewHolderT< SnapshotT >
 
using FakeShapeState = FakeShapeT< StateT >
 
using FakeShape = FakeShapeT< SnapshotT >
 
using FakeMaterialState = FakeMaterialT< StateT >
 
using FakeMaterial = FakeMaterialT< SnapshotT >
 
using FakeImageState = FakeImageT< StateT >
 
using FakeImage = FakeImageT< SnapshotT >
 
using FakeMemoryState = FakeMemoryT< StateT >
 
using FakeMemory = FakeMemoryT< SnapshotT >
 
using FakeResourceState = FakeResourceT< StateT >
 
using FakeResource = FakeResourceT< SnapshotT >
 
using FakeSceneGraphState = FakeSceneGraphT< StateT >
 
using FakeSceneGraph = FakeSceneGraphT< SnapshotT >
 

Functions

 TEST_F (FocusDelegateTest, WatchCallbackSeries)
 
 TEST_F (FocusDelegateTest, RequestFocusTest)
 
 TEST_F (FocusDelegateTest, RequestFocusFailTest)
 
 TEST_F (PlatformViewTests, InvalidPlatformMessageRequest)
 
 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, GetFocusStatesTest)
 
 TEST_F (PlatformViewTests, RequestFocusTest)
 
 TEST_F (PlatformViewTests, RequestFocusFailTest)
 
 TEST_F (PlatformViewTests, OnKeyEvent)
 
 TEST_F (PlatformViewTests, OnShaderWarmup)
 
 TEST_F (PlatformViewTests, TouchSourceLogicalToPhysicalConversion)
 
 TEST_F (PlatformViewTests, DownPointerNumericNudge)
 
 TEST_F (PointerDelegateTest, Data_FuchsiaTimeVersusFlutterTime)
 
 TEST_F (PointerDelegateTest, Phase_FlutterPhasesAreSynthesized)
 
 TEST_F (PointerDelegateTest, Phase_FuchsiaCancelBecomesFlutterCancel)
 
 TEST_F (PointerDelegateTest, Coordinates_CorrectMapping)
 
 TEST_F (PointerDelegateTest, Coordinates_DownEventClampedToView)
 
 TEST_F (PointerDelegateTest, Protocol_FirstResponseIsEmpty)
 
 TEST_F (PointerDelegateTest, Protocol_ResponseMatchesEarlierEvents)
 
 TEST_F (PointerDelegateTest, Protocol_LateGrant)
 
 TEST_F (PointerDelegateTest, Protocol_LateGrantCombo)
 
 TEST_F (PointerDelegateTest, Protocol_EarlyGrant)
 
 TEST_F (PointerDelegateTest, Protocol_LateDeny)
 
 TEST_F (PointerDelegateTest, Protocol_LateDenyCombo)
 
 TEST_F (PointerDelegateTest, Protocol_PointersAreIndependent)
 
 TEST_F (EngineTest, ThreadNames)
 
 TEST_F (EngineTest, SkpWarmup)
 
 TEST_F (EngineTest, SkpWarmupAsync)
 
 TEST_F (FakeFlatlandTest, Initialization)
 
 TEST_F (FakeFlatlandTest, DebugLabel)
 
 TEST_F (FakeFlatlandTest, Present)
 
 TEST_F (FakeSessionTest, Initialization)
 
 TEST_F (FakeSessionTest, DebugLabel)
 
 TEST_F (FakeSessionTest, CommandQueueInvariants)
 
 TEST_F (FakeSessionTest, SimpleResourceLifecycle)
 
 TEST_F (FakeSessionTest, ResourceReferenceCounting)
 
 TEST_F (FakeSessionTest, BasicSceneGraph)
 
FakeSceneGraph SceneGraphFromState (const FakeSceneGraphState &state)
 
 TEST_F (FlatlandConnectionTest, Initialization)
 
 TEST_F (FlatlandConnectionTest, FlatlandDisconnect)
 
 TEST_F (FlatlandConnectionTest, BasicPresent)
 
 TEST_F (FlatlandConnectionTest, OutOfOrderAwait)
 
 TEST_F (FlatlandConnectionTest, PresentCreditExhaustion)
 
 TEST_F (GfxExternalViewEmbedderTest, RootScene)
 
 TEST_F (GfxExternalViewEmbedderTest, SimpleScene)
 
 TEST_F (GfxExternalViewEmbedderTest, SceneWithOneView)
 
 TEST_F (GfxSessionConnectionTest, Initialization)
 
 TEST_F (GfxSessionConnectionTest, SessionDisconnect)
 
 TEST_F (GfxSessionConnectionTest, BasicPresent)
 
 TEST_F (GfxSessionConnectionTest, AwaitVsyncBackpressure)
 
 TEST_F (GfxSessionConnectionTest, PresentBackpressure)
 
 TEST (CalculateNextLatchPointTest, PresentAsSoonAsPossible)
 
 TEST (CalculateNextLatchPointTest, LongFrameBuildTime)
 
 TEST (CalculateNextLatchPointTest, DelayedPresentRequestWithLongFrameBuildTime)
 
 TEST (CalculateNextLatchPointTest, LastLastPointTargetedLate)
 
 TEST (CalculateNextLatchPointTest, SteadyState_OnTimeFrames)
 
 TEST (CalculateNextLatchPointTest, SteadyState_LongFrameBuildTimes)
 
 TEST (CalculateNextLatchPointTest, SteadyState_LateLastLatchPointTargeted)
 
 TEST (CalculateNextLatchPointTest, SteadyState_DelayedPresentRequestWithLongFrameBuildTime)
 
 TEST (CalculateNextLatchPointTest, SteadyState_FuzzyLatchPointsBeforeTarget)
 
 TEST (CalculateNextLatchPointTest, SteadyState_FuzzyLatchPointsAfterTarget)
 
 TEST (SnapToNextPhaseTest, SnapOverlapsWithNow)
 
 TEST (SnapToNextPhaseTest, SnapAfterNow)
 
 TEST (SnapToNextPhaseTest, SnapAfterNowMultiJump)
 
 TEST (SnapToNextPhaseTest, SnapAfterNowMultiJumpAccountForCeils)
 
 TEST (GetTargetTimesTest, ScheduleForNextVsync)
 
 TEST (GetTargetTimesTest, ScheduleForCurrentVsync_DueToOffset)
 
 TEST (GetTargetTimesTest, ScheduleForFollowingVsync_BecauseOfNow)
 
 TEST (GetTargetTimesTest, ScheduleForFollowingVsync_BecauseOfTargettedTime)
 
 TEST (GetTargetTimesTest, ScheduleForDistantVsync_BecauseOfTargettedTime)
 
 TEST (GetTargetTimesTest, ScheduleForFollowingVsync_WithSlightVsyncDrift)
 
 TEST (GetTargetTimesTest, ScheduleForAnOffsetFromVsync)
 
 TEST (GetTargetTimesTest, ScheduleMultipleTimes)
 
 TEST (GetTargetTimesTest, ScheduleMultipleTimes_WithDelayedWakeups)
 
 TEST (UpdatePresentationInfoTest, SingleUpdate)
 
 TEST (UpdatePresentationInfoTest, MultipleUpdates)
 

Variables

constexpr std::array< std::array< float, 2 >, 2 > kRect = {{{0, 0}, {20, 20}}}
 
constexpr std::array< float, 9 > kIdentity = {1, 0, 0, 0, 1, 0, 0, 0, 1}
 
constexpr fup_TouchIxnId kIxnOne
 
constexpr FakeResourceId kInvalidFakeResourceId = 0u
 

Typedef Documentation

◆ FakeEntityNode

◆ FakeEntityNodeState

◆ FakeImage

Definition at line 324 of file fake_resources.h.

◆ FakeImageState

Definition at line 323 of file fake_resources.h.

◆ FakeMaterial

◆ FakeMaterialState

◆ FakeMemory

Definition at line 339 of file fake_resources.h.

◆ FakeMemoryState

Definition at line 338 of file fake_resources.h.

◆ FakeNode

Definition at line 135 of file fake_resources.h.

◆ FakeNodeState

Definition at line 134 of file fake_resources.h.

◆ FakeOpacityNode

◆ FakeOpacityNodeState

◆ FakeResource

◆ FakeResourceId

◆ FakeResourceState

◆ FakeSceneGraph

◆ FakeSceneGraphState

◆ FakeShape

Definition at line 256 of file fake_resources.h.

◆ FakeShapeNode

◆ FakeShapeNodeState

◆ FakeShapeState

Definition at line 255 of file fake_resources.h.

◆ FakeView

Definition at line 204 of file fake_resources.h.

◆ FakeViewHolder

◆ FakeViewHolderState

◆ FakeViewState

Definition at line 203 of file fake_resources.h.

◆ fup_EventPhase

typedef fuchsia::ui::pointer::EventPhase flutter_runner::testing::fup_EventPhase

Definition at line 24 of file pointer_delegate_unittests.cc.

◆ fup_TouchEvent

typedef fuchsia::ui::pointer::TouchEvent flutter_runner::testing::fup_TouchEvent

Definition at line 25 of file pointer_delegate_unittests.cc.

◆ fup_TouchIxnId

typedef fuchsia::ui::pointer::TouchInteractionId flutter_runner::testing::fup_TouchIxnId

Definition at line 26 of file pointer_delegate_unittests.cc.

◆ fup_TouchIxnResult

typedef fuchsia::ui::pointer::TouchInteractionResult flutter_runner::testing::fup_TouchIxnResult

Definition at line 27 of file pointer_delegate_unittests.cc.

◆ fup_TouchIxnStatus

using flutter_runner::testing::fup_TouchIxnStatus = typedef fuchsia::ui::pointer::TouchInteractionStatus

Definition at line 28 of file pointer_delegate_unittests.cc.

◆ fup_TouchPointerSample

typedef fuchsia::ui::pointer::TouchPointerSample flutter_runner::testing::fup_TouchPointerSample

Definition at line 29 of file pointer_delegate_unittests.cc.

◆ fup_TouchResponse

using flutter_runner::testing::fup_TouchResponse = typedef fuchsia::ui::pointer::TouchResponse

Definition at line 30 of file pointer_delegate_unittests.cc.

◆ fup_TouchResponseType

using flutter_runner::testing::fup_TouchResponseType = typedef fuchsia::ui::pointer::TouchResponseType

Definition at line 31 of file pointer_delegate_unittests.cc.

◆ fup_ViewParameters

typedef fuchsia::ui::pointer::ViewParameters flutter_runner::testing::fup_ViewParameters

Definition at line 32 of file pointer_delegate_unittests.cc.

Function Documentation

◆ SceneGraphFromState()

FakeSceneGraph flutter_runner::testing::SceneGraphFromState ( const FakeSceneGraphState state)

Definition at line 276 of file fake_resources.cc.

References flutter_runner::testing::FakeSceneGraphT< S >::buffer_collection_map, FML_CHECK, flutter_runner::testing::FakeSceneGraphT< S >::label_map, flutter_runner::testing::FakeSceneGraphT< S >::resource_map, and flutter_runner::testing::FakeSceneGraphT< S >::root_view_id.

Referenced by flutter_runner::testing::FakeSession::SceneGraph().

276  {
277  FakeResourceCache resource_cache;
278  FakeSceneGraph scene_graph;
279 
280  // Snapshot all buffer collections.
281  for (auto& buffer_collection : state.buffer_collection_map) {
282  scene_graph.buffer_collection_map.emplace(
283  std::make_pair(buffer_collection.first, buffer_collection.second.koid));
284  }
285 
286  // Snapshot resources in the map recursively.
287  for (auto& resource : state.resource_map) {
288  scene_graph.resource_map.emplace(std::make_pair(
289  resource.first, ResourceFromState(resource.second, resource_cache)));
290  }
291 
292  // Snapshot labels in the map.
293  for (auto& label_resources : state.label_map) {
294  auto [label_iter, label_success] =
295  scene_graph.label_map.emplace(std::make_pair(
296  label_resources.first, std::vector<std::weak_ptr<FakeResource>>()));
297  FML_CHECK(label_success);
298  auto& snapshot_label_resources = label_iter->second;
299 
300  for (auto& resource : label_resources.second) {
301  auto resource_ptr = resource.lock();
302  FML_CHECK(resource_ptr);
303 
304  snapshot_label_resources.emplace_back(
305  ResourceFromState(resource_ptr, resource_cache));
306  }
307  }
308 
309  // Snapshot the view id.
310  scene_graph.root_view_id = state.root_view_id;
311 
312  return scene_graph;
313 }
FakeSceneGraphT< SnapshotT > FakeSceneGraph
#define FML_CHECK(condition)
Definition: logging.h:68
AtkStateType state

◆ TEST() [1/25]

flutter_runner::testing::TEST ( CalculateNextLatchPointTest  ,
PresentAsSoonAsPossible   
)

Definition at line 448 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::CalculateNextLatchPoint().

448  {
449  fml::TimePoint present_requested_time = TimePointFromInt(0);
450  fml::TimePoint now = TimePointFromInt(0);
451  fml::TimePoint last_latch_point_targeted = TimePointFromInt(0);
452  fml::TimeDelta flutter_frame_build_time = TimeDeltaFromInt(0);
453  fml::TimeDelta vsync_interval = TimeDeltaFromInt(1000);
454  std::deque<std::pair<fml::TimePoint, fml::TimePoint>>
455  future_presentation_infos = {};
456 
457  // Assertions about given values.
458  EXPECT_GE(now, present_requested_time);
459  EXPECT_GE(flutter_frame_build_time, TimeDeltaFromInt(0));
460  EXPECT_GT(vsync_interval, TimeDeltaFromInt(0));
461 
462  fml::TimePoint calculated_latch_point =
463  GfxSessionConnection::CalculateNextLatchPoint(
464  present_requested_time, now, last_latch_point_targeted,
465  flutter_frame_build_time, vsync_interval, future_presentation_infos);
466 
467  EXPECT_GE(TimePointToInt(calculated_latch_point), TimePointToInt(now));
468  EXPECT_LE(TimePointToInt(calculated_latch_point),
469  TimePointToInt(now + vsync_interval));
470 
471  EXPECT_GE(TimePointToInt(calculated_latch_point),
472  TimePointToInt(present_requested_time + flutter_frame_build_time));
473  EXPECT_GE(TimePointToInt(calculated_latch_point),
474  TimePointToInt(last_latch_point_targeted));
475 }

◆ TEST() [2/25]

flutter_runner::testing::TEST ( CalculateNextLatchPointTest  ,
LongFrameBuildTime   
)

Definition at line 477 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::CalculateNextLatchPoint().

477  {
478  fml::TimePoint present_requested_time = TimePointFromInt(500);
479  fml::TimePoint now = TimePointFromInt(600);
480  fml::TimePoint last_latch_point_targeted = TimePointFromInt(0);
481  fml::TimeDelta flutter_frame_build_time = TimeDeltaFromInt(2500);
482  fml::TimeDelta vsync_interval = TimeDeltaFromInt(1000);
483  std::deque<std::pair<fml::TimePoint, fml::TimePoint>>
484  future_presentation_infos = {};
485 
486  // Assertions about given values.
487  EXPECT_GE(now, present_requested_time);
488  EXPECT_GE(flutter_frame_build_time, TimeDeltaFromInt(0));
489  EXPECT_GT(vsync_interval, TimeDeltaFromInt(0));
490 
491  EXPECT_GT(flutter_frame_build_time, vsync_interval);
492 
493  fml::TimePoint calculated_latch_point =
494  GfxSessionConnection::CalculateNextLatchPoint(
495  present_requested_time, now, last_latch_point_targeted,
496  flutter_frame_build_time, vsync_interval, future_presentation_infos);
497 
498  EXPECT_GE(TimePointToInt(calculated_latch_point),
499  TimePointToInt(now + (vsync_interval * 2)));
500  EXPECT_LE(TimePointToInt(calculated_latch_point),
501  TimePointToInt(now + (vsync_interval * 3)));
502 
503  EXPECT_GE(TimePointToInt(calculated_latch_point),
504  TimePointToInt(present_requested_time + flutter_frame_build_time));
505  EXPECT_GE(TimePointToInt(calculated_latch_point),
506  TimePointToInt(last_latch_point_targeted));
507 }

◆ TEST() [3/25]

flutter_runner::testing::TEST ( CalculateNextLatchPointTest  ,
DelayedPresentRequestWithLongFrameBuildTime   
)

Definition at line 509 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::CalculateNextLatchPoint().

509  {
510  fml::TimePoint present_requested_time = TimePointFromInt(0);
511  fml::TimePoint now = TimePointFromInt(1500);
512  fml::TimePoint last_latch_point_targeted = TimePointFromInt(0);
513  fml::TimeDelta flutter_frame_build_time = TimeDeltaFromInt(2000);
514  fml::TimeDelta vsync_interval = TimeDeltaFromInt(1000);
515  std::deque<std::pair<fml::TimePoint, fml::TimePoint>>
516  future_presentation_infos = {};
517 
518  // Assertions about given values.
519  EXPECT_GE(now, present_requested_time);
520  EXPECT_GE(flutter_frame_build_time, TimeDeltaFromInt(0));
521  EXPECT_GT(vsync_interval, TimeDeltaFromInt(0));
522 
523  EXPECT_GT(flutter_frame_build_time, vsync_interval);
524  EXPECT_GT(now, present_requested_time + vsync_interval);
525 
526  fml::TimePoint calculated_latch_point =
527  GfxSessionConnection::CalculateNextLatchPoint(
528  present_requested_time, now, last_latch_point_targeted,
529  flutter_frame_build_time, vsync_interval, future_presentation_infos);
530 
531  EXPECT_GE(TimePointToInt(calculated_latch_point), TimePointToInt(now));
532  EXPECT_LE(TimePointToInt(calculated_latch_point),
533  TimePointToInt(now + vsync_interval));
534 
535  EXPECT_GE(TimePointToInt(calculated_latch_point),
536  TimePointToInt(present_requested_time + flutter_frame_build_time));
537  EXPECT_GE(TimePointToInt(calculated_latch_point),
538  TimePointToInt(last_latch_point_targeted));
539 }

◆ TEST() [4/25]

flutter_runner::testing::TEST ( CalculateNextLatchPointTest  ,
LastLastPointTargetedLate   
)

Definition at line 541 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::CalculateNextLatchPoint().

541  {
542  fml::TimePoint present_requested_time = TimePointFromInt(2000);
543  fml::TimePoint now = TimePointFromInt(2000);
544  fml::TimePoint last_latch_point_targeted = TimePointFromInt(2600);
545  fml::TimeDelta flutter_frame_build_time = TimeDeltaFromInt(1000);
546  fml::TimeDelta vsync_interval = TimeDeltaFromInt(1000);
547  std::deque<std::pair<fml::TimePoint, fml::TimePoint>>
548  future_presentation_infos = {};
549 
550  // Assertions about given values.
551  EXPECT_GE(now, present_requested_time);
552  EXPECT_GE(flutter_frame_build_time, TimeDeltaFromInt(0));
553  EXPECT_GT(vsync_interval, TimeDeltaFromInt(0));
554 
555  EXPECT_GT(last_latch_point_targeted, present_requested_time);
556 
557  fml::TimePoint calculated_latch_point =
558  GfxSessionConnection::CalculateNextLatchPoint(
559  present_requested_time, now, last_latch_point_targeted,
560  flutter_frame_build_time, vsync_interval, future_presentation_infos);
561 
562  EXPECT_GE(TimePointToInt(calculated_latch_point),
563  TimePointToInt(now + vsync_interval));
564  EXPECT_LE(TimePointToInt(calculated_latch_point),
565  TimePointToInt(now + (vsync_interval * 2)));
566 
567  EXPECT_GE(TimePointToInt(calculated_latch_point),
568  TimePointToInt(present_requested_time + flutter_frame_build_time));
569  EXPECT_GE(TimePointToInt(calculated_latch_point),
570  TimePointToInt(last_latch_point_targeted));
571 }

◆ TEST() [5/25]

flutter_runner::testing::TEST ( CalculateNextLatchPointTest  ,
SteadyState_OnTimeFrames   
)

Definition at line 577 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::CalculateNextLatchPoint().

577  {
578  fml::TimePoint present_requested_time = TimePointFromInt(5000);
579  fml::TimePoint now = TimePointFromInt(5000);
580  fml::TimePoint last_latch_point_targeted = TimePointFromInt(4500);
581  fml::TimeDelta flutter_frame_build_time = TimeDeltaFromInt(1000);
582  fml::TimeDelta vsync_interval = TimeDeltaFromInt(1000);
583  std::deque<std::pair<fml::TimePoint, fml::TimePoint>>
584  future_presentation_infos = {
585  {TimePointFromInt(3500), TimePointFromInt(4000)},
586  {TimePointFromInt(4500), TimePointFromInt(5000)},
587  {TimePointFromInt(5500), TimePointFromInt(6000)},
588  {TimePointFromInt(6500), TimePointFromInt(7000)},
589  {TimePointFromInt(7500), TimePointFromInt(8000)},
590  };
591 
592  // Assertions about given values.
593  EXPECT_GE(now, present_requested_time);
594  EXPECT_GE(flutter_frame_build_time, TimeDeltaFromInt(0));
595  EXPECT_GT(vsync_interval, TimeDeltaFromInt(0));
596 
597  fml::TimePoint calculated_latch_point =
598  GfxSessionConnection::CalculateNextLatchPoint(
599  present_requested_time, now, last_latch_point_targeted,
600  flutter_frame_build_time, vsync_interval, future_presentation_infos);
601 
602  EXPECT_GE(TimePointToInt(calculated_latch_point),
603  TimePointToInt(now + vsync_interval));
604  EXPECT_LE(TimePointToInt(calculated_latch_point),
605  TimePointToInt(now + (vsync_interval * 2)));
606  EXPECT_EQ(TimePointToInt(calculated_latch_point), 6500);
607 
608  EXPECT_GE(TimePointToInt(calculated_latch_point),
609  TimePointToInt(present_requested_time + flutter_frame_build_time));
610  EXPECT_GE(TimePointToInt(calculated_latch_point),
611  TimePointToInt(last_latch_point_targeted));
612 }

◆ TEST() [6/25]

flutter_runner::testing::TEST ( CalculateNextLatchPointTest  ,
SteadyState_LongFrameBuildTimes   
)

Definition at line 614 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::CalculateNextLatchPoint().

614  {
615  fml::TimePoint present_requested_time = TimePointFromInt(5000);
616  fml::TimePoint now = TimePointFromInt(5000);
617  fml::TimePoint last_latch_point_targeted = TimePointFromInt(4500);
618  fml::TimeDelta flutter_frame_build_time = TimeDeltaFromInt(2000);
619  fml::TimeDelta vsync_interval = TimeDeltaFromInt(1000);
620  std::deque<std::pair<fml::TimePoint, fml::TimePoint>>
621  future_presentation_infos = {
622  {TimePointFromInt(3500), TimePointFromInt(4000)},
623  {TimePointFromInt(4500), TimePointFromInt(5000)},
624  {TimePointFromInt(5500), TimePointFromInt(6000)},
625  {TimePointFromInt(6500), TimePointFromInt(7000)},
626  {TimePointFromInt(7500), TimePointFromInt(8000)},
627  };
628 
629  // Assertions about given values.
630  EXPECT_GE(now, present_requested_time);
631  EXPECT_GE(flutter_frame_build_time, TimeDeltaFromInt(0));
632  EXPECT_GT(vsync_interval, TimeDeltaFromInt(0));
633 
634  EXPECT_GT(flutter_frame_build_time, vsync_interval);
635 
636  fml::TimePoint calculated_latch_point =
637  GfxSessionConnection::CalculateNextLatchPoint(
638  present_requested_time, now, last_latch_point_targeted,
639  flutter_frame_build_time, vsync_interval, future_presentation_infos);
640 
641  EXPECT_GE(TimePointToInt(calculated_latch_point),
642  TimePointToInt(now + (vsync_interval * 2)));
643  EXPECT_LE(TimePointToInt(calculated_latch_point),
644  TimePointToInt(now + (vsync_interval * 3)));
645  EXPECT_EQ(TimePointToInt(calculated_latch_point), 7500);
646 
647  EXPECT_GE(TimePointToInt(calculated_latch_point),
648  TimePointToInt(present_requested_time + flutter_frame_build_time));
649  EXPECT_GE(TimePointToInt(calculated_latch_point),
650  TimePointToInt(last_latch_point_targeted));
651 }

◆ TEST() [7/25]

flutter_runner::testing::TEST ( CalculateNextLatchPointTest  ,
SteadyState_LateLastLatchPointTargeted   
)

Definition at line 653 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::CalculateNextLatchPoint().

653  {
654  fml::TimePoint present_requested_time = TimePointFromInt(5000);
655  fml::TimePoint now = TimePointFromInt(5000);
656  fml::TimePoint last_latch_point_targeted = TimePointFromInt(6500);
657  fml::TimeDelta flutter_frame_build_time = TimeDeltaFromInt(1000);
658  fml::TimeDelta vsync_interval = TimeDeltaFromInt(1000);
659  std::deque<std::pair<fml::TimePoint, fml::TimePoint>>
660  future_presentation_infos = {
661  {TimePointFromInt(4500), TimePointFromInt(5000)},
662  {TimePointFromInt(5500), TimePointFromInt(6000)},
663  {TimePointFromInt(6500), TimePointFromInt(7000)},
664  {TimePointFromInt(7500), TimePointFromInt(8000)},
665  {TimePointFromInt(8500), TimePointFromInt(9000)},
666  };
667 
668  // Assertions about given values.
669  EXPECT_GE(now, present_requested_time);
670  EXPECT_GE(flutter_frame_build_time, TimeDeltaFromInt(0));
671  EXPECT_GT(vsync_interval, TimeDeltaFromInt(0));
672 
673  EXPECT_GT(last_latch_point_targeted, now + vsync_interval);
674 
675  fml::TimePoint calculated_latch_point =
676  GfxSessionConnection::CalculateNextLatchPoint(
677  present_requested_time, now, last_latch_point_targeted,
678  flutter_frame_build_time, vsync_interval, future_presentation_infos);
679 
680  EXPECT_GE(TimePointToInt(calculated_latch_point),
681  TimePointToInt(now + vsync_interval));
682  EXPECT_LE(TimePointToInt(calculated_latch_point),
683  TimePointToInt(now + (vsync_interval * 2)));
684  EXPECT_EQ(TimePointToInt(calculated_latch_point), 6500);
685 
686  EXPECT_GE(TimePointToInt(calculated_latch_point),
687  TimePointToInt(present_requested_time + flutter_frame_build_time));
688  EXPECT_GE(TimePointToInt(calculated_latch_point),
689  TimePointToInt(last_latch_point_targeted));
690 }

◆ TEST() [8/25]

flutter_runner::testing::TEST ( CalculateNextLatchPointTest  ,
SteadyState_DelayedPresentRequestWithLongFrameBuildTime   
)

Definition at line 692 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::CalculateNextLatchPoint().

693  {
694  fml::TimePoint present_requested_time = TimePointFromInt(4000);
695  fml::TimePoint now = TimePointFromInt(5500);
696  fml::TimePoint last_latch_point_targeted = TimePointFromInt(3500);
697  fml::TimeDelta flutter_frame_build_time = TimeDeltaFromInt(2000);
698  fml::TimeDelta vsync_interval = TimeDeltaFromInt(1000);
699  std::deque<std::pair<fml::TimePoint, fml::TimePoint>>
700  future_presentation_infos = {
701  {TimePointFromInt(4500), TimePointFromInt(5000)},
702  {TimePointFromInt(5500), TimePointFromInt(6000)},
703  {TimePointFromInt(6500), TimePointFromInt(7000)},
704  };
705 
706  // Assertions about given values.
707  EXPECT_GE(now, present_requested_time);
708  EXPECT_GE(flutter_frame_build_time, TimeDeltaFromInt(0));
709  EXPECT_GT(vsync_interval, TimeDeltaFromInt(0));
710 
711  EXPECT_GT(flutter_frame_build_time, vsync_interval);
712  EXPECT_GT(now, present_requested_time + vsync_interval);
713 
714  fml::TimePoint calculated_latch_point =
715  GfxSessionConnection::CalculateNextLatchPoint(
716  present_requested_time, now, last_latch_point_targeted,
717  flutter_frame_build_time, vsync_interval, future_presentation_infos);
718 
719  EXPECT_GE(TimePointToInt(calculated_latch_point),
720  TimePointToInt(now + vsync_interval));
721  EXPECT_LE(TimePointToInt(calculated_latch_point),
722  TimePointToInt(now + (vsync_interval * 2)));
723  EXPECT_EQ(TimePointToInt(calculated_latch_point), 6500);
724 
725  EXPECT_GE(TimePointToInt(calculated_latch_point),
726  TimePointToInt(present_requested_time + flutter_frame_build_time));
727  EXPECT_GE(TimePointToInt(calculated_latch_point),
728  TimePointToInt(last_latch_point_targeted));
729 }

◆ TEST() [9/25]

flutter_runner::testing::TEST ( CalculateNextLatchPointTest  ,
SteadyState_FuzzyLatchPointsBeforeTarget   
)

Definition at line 731 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::CalculateNextLatchPoint().

731  {
732  fml::TimePoint present_requested_time = TimePointFromInt(4000);
733  fml::TimePoint now = TimePointFromInt(4000);
734  fml::TimePoint last_latch_point_targeted = TimePointFromInt(5490);
735  fml::TimeDelta flutter_frame_build_time = TimeDeltaFromInt(1000);
736  fml::TimeDelta vsync_interval = TimeDeltaFromInt(1000);
737  std::deque<std::pair<fml::TimePoint, fml::TimePoint>>
738  future_presentation_infos = {
739  {TimePointFromInt(4510), TimePointFromInt(5000)},
740  {TimePointFromInt(5557), TimePointFromInt(6000)},
741  {TimePointFromInt(6482), TimePointFromInt(7000)},
742  {TimePointFromInt(7356), TimePointFromInt(8000)},
743  };
744 
745  // Assertions about given values.
746  EXPECT_GE(now, present_requested_time);
747  EXPECT_GE(flutter_frame_build_time, TimeDeltaFromInt(0));
748  EXPECT_GT(vsync_interval, TimeDeltaFromInt(0));
749 
750  fml::TimePoint calculated_latch_point =
751  GfxSessionConnection::CalculateNextLatchPoint(
752  present_requested_time, now, last_latch_point_targeted,
753  flutter_frame_build_time, vsync_interval, future_presentation_infos);
754 
755  EXPECT_GE(TimePointToInt(calculated_latch_point),
756  TimePointToInt(now + vsync_interval));
757  EXPECT_LE(TimePointToInt(calculated_latch_point),
758  TimePointToInt(now + (vsync_interval * 2)));
759  EXPECT_EQ(TimePointToInt(calculated_latch_point), 5557);
760 
761  EXPECT_GE(TimePointToInt(calculated_latch_point),
762  TimePointToInt(present_requested_time + flutter_frame_build_time));
763  EXPECT_GE(TimePointToInt(calculated_latch_point),
764  TimePointToInt(last_latch_point_targeted));
765 }

◆ TEST() [10/25]

flutter_runner::testing::TEST ( CalculateNextLatchPointTest  ,
SteadyState_FuzzyLatchPointsAfterTarget   
)

Definition at line 767 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::CalculateNextLatchPoint().

767  {
768  fml::TimePoint present_requested_time = TimePointFromInt(4000);
769  fml::TimePoint now = TimePointFromInt(4000);
770  fml::TimePoint last_latch_point_targeted = TimePointFromInt(5557);
771  fml::TimeDelta flutter_frame_build_time = TimeDeltaFromInt(1000);
772  fml::TimeDelta vsync_interval = TimeDeltaFromInt(1000);
773  std::deque<std::pair<fml::TimePoint, fml::TimePoint>>
774  future_presentation_infos = {
775  {TimePointFromInt(4510), TimePointFromInt(5000)},
776  {TimePointFromInt(5490), TimePointFromInt(6000)},
777  {TimePointFromInt(6482), TimePointFromInt(7000)},
778  {TimePointFromInt(7356), TimePointFromInt(8000)},
779  };
780 
781  // Assertions about given values.
782  EXPECT_GE(now, present_requested_time);
783  EXPECT_GE(flutter_frame_build_time, TimeDeltaFromInt(0));
784  EXPECT_GT(vsync_interval, TimeDeltaFromInt(0));
785 
786  fml::TimePoint calculated_latch_point =
787  GfxSessionConnection::CalculateNextLatchPoint(
788  present_requested_time, now, last_latch_point_targeted,
789  flutter_frame_build_time, vsync_interval, future_presentation_infos);
790 
791  EXPECT_GE(TimePointToInt(calculated_latch_point),
792  TimePointToInt(now + (vsync_interval * 2)));
793  EXPECT_LE(TimePointToInt(calculated_latch_point),
794  TimePointToInt(now + (vsync_interval * 3)));
795  EXPECT_EQ(TimePointToInt(calculated_latch_point), 6482);
796 
797  EXPECT_GE(TimePointToInt(calculated_latch_point),
798  TimePointToInt(present_requested_time + flutter_frame_build_time));
799  EXPECT_GE(TimePointToInt(calculated_latch_point),
800  TimePointToInt(last_latch_point_targeted));
801 }

◆ TEST() [11/25]

flutter_runner::testing::TEST ( SnapToNextPhaseTest  ,
SnapOverlapsWithNow   
)

Definition at line 803 of file gfx_session_connection_unittests.cc.

References fml::TimeDelta::FromNanoseconds(), fml::TimePoint::Now(), and flutter_runner::GfxSessionConnection::SnapToNextPhase().

803  {
804  const auto now = fml::TimePoint::Now();
805  const auto last_presentation_time = now - fml::TimeDelta::FromNanoseconds(10);
806  const auto delta = fml::TimeDelta::FromNanoseconds(10);
808  now, last_presentation_time, delta);
809 
810  EXPECT_EQ(now + delta, next_vsync);
811 }
static fml::TimePoint SnapToNextPhase(const fml::TimePoint now, const fml::TimePoint last_frame_presentation_time, const fml::TimeDelta presentation_interval)
static constexpr TimeDelta FromNanoseconds(int64_t nanos)
Definition: time_delta.h:40
static TimePoint Now()
Definition: time_point.cc:39

◆ TEST() [12/25]

flutter_runner::testing::TEST ( SnapToNextPhaseTest  ,
SnapAfterNow   
)

Definition at line 813 of file gfx_session_connection_unittests.cc.

References fml::TimeDelta::FromNanoseconds(), fml::TimePoint::Now(), and flutter_runner::GfxSessionConnection::SnapToNextPhase().

813  {
814  const auto now = fml::TimePoint::Now();
815  const auto last_presentation_time = now - fml::TimeDelta::FromNanoseconds(9);
816  const auto delta = fml::TimeDelta::FromNanoseconds(10);
818  now, last_presentation_time, delta);
819 
820  // math here: 10 - 9 = 1
821  EXPECT_EQ(now + fml::TimeDelta::FromNanoseconds(1), next_vsync);
822 }
static fml::TimePoint SnapToNextPhase(const fml::TimePoint now, const fml::TimePoint last_frame_presentation_time, const fml::TimeDelta presentation_interval)
static constexpr TimeDelta FromNanoseconds(int64_t nanos)
Definition: time_delta.h:40
static TimePoint Now()
Definition: time_point.cc:39

◆ TEST() [13/25]

flutter_runner::testing::TEST ( SnapToNextPhaseTest  ,
SnapAfterNowMultiJump   
)

Definition at line 824 of file gfx_session_connection_unittests.cc.

References fml::TimeDelta::FromNanoseconds(), fml::TimePoint::Now(), and flutter_runner::GfxSessionConnection::SnapToNextPhase().

824  {
825  const auto now = fml::TimePoint::Now();
826  const auto last_presentation_time = now - fml::TimeDelta::FromNanoseconds(34);
827  const auto delta = fml::TimeDelta::FromNanoseconds(10);
829  now, last_presentation_time, delta);
830 
831  // zeroes: -34, -24, -14, -4, 6, ...
832  EXPECT_EQ(now + fml::TimeDelta::FromNanoseconds(6), next_vsync);
833 }
static fml::TimePoint SnapToNextPhase(const fml::TimePoint now, const fml::TimePoint last_frame_presentation_time, const fml::TimeDelta presentation_interval)
static constexpr TimeDelta FromNanoseconds(int64_t nanos)
Definition: time_delta.h:40
static TimePoint Now()
Definition: time_point.cc:39

◆ TEST() [14/25]

flutter_runner::testing::TEST ( SnapToNextPhaseTest  ,
SnapAfterNowMultiJumpAccountForCeils   
)

Definition at line 835 of file gfx_session_connection_unittests.cc.

References fml::TimeDelta::FromNanoseconds(), fml::TimePoint::Now(), and flutter_runner::GfxSessionConnection::SnapToNextPhase().

835  {
836  const auto now = fml::TimePoint::Now();
837  const auto last_presentation_time = now - fml::TimeDelta::FromNanoseconds(20);
838  const auto delta = fml::TimeDelta::FromNanoseconds(16);
840  now, last_presentation_time, delta);
841 
842  // zeroes: -20, -4, 12, 28, ...
843  EXPECT_EQ(now + fml::TimeDelta::FromNanoseconds(12), next_vsync);
844 }
static fml::TimePoint SnapToNextPhase(const fml::TimePoint now, const fml::TimePoint last_frame_presentation_time, const fml::TimeDelta presentation_interval)
static constexpr TimeDelta FromNanoseconds(int64_t nanos)
Definition: time_delta.h:40
static TimePoint Now()
Definition: time_point.cc:39

◆ TEST() [15/25]

flutter_runner::testing::TEST ( GetTargetTimesTest  ,
ScheduleForNextVsync   
)

Definition at line 846 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::GetTargetTimes().

846  {
847  const fml::TimeDelta vsync_offset = TimeDeltaFromInt(0);
848  const fml::TimeDelta vsync_interval = TimeDeltaFromInt(10);
849  const fml::TimePoint last_targeted_vsync = TimePointFromInt(10);
850  const fml::TimePoint now = TimePointFromInt(9);
851  const fml::TimePoint next_vsync = TimePointFromInt(10);
852 
853  const auto target_times =
855  vsync_offset, vsync_interval, last_targeted_vsync, now, next_vsync);
856 
857  EXPECT_EQ(TimePointToInt(target_times.frame_start), 10);
858  EXPECT_EQ(TimePointToInt(target_times.frame_target), 20);
859 }
static FlutterFrameTimes GetTargetTimes(fml::TimeDelta vsync_offset, fml::TimeDelta vsync_interval, fml::TimePoint last_targeted_vsync, fml::TimePoint now, fml::TimePoint next_vsync)

◆ TEST() [16/25]

flutter_runner::testing::TEST ( GetTargetTimesTest  ,
ScheduleForCurrentVsync_DueToOffset   
)

Definition at line 861 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::GetTargetTimes().

861  {
862  const fml::TimeDelta vsync_offset = TimeDeltaFromInt(3);
863  const fml::TimeDelta vsync_interval = TimeDeltaFromInt(10);
864  const fml::TimePoint last_targeted_vsync = TimePointFromInt(0);
865  const fml::TimePoint now = TimePointFromInt(6);
866  const fml::TimePoint next_vsync = TimePointFromInt(10);
867 
868  const auto target_times =
870  vsync_offset, vsync_interval, last_targeted_vsync, now, next_vsync);
871 
872  EXPECT_EQ(TimePointToInt(target_times.frame_start), 7);
873  EXPECT_EQ(TimePointToInt(target_times.frame_target), 10);
874 }
static FlutterFrameTimes GetTargetTimes(fml::TimeDelta vsync_offset, fml::TimeDelta vsync_interval, fml::TimePoint last_targeted_vsync, fml::TimePoint now, fml::TimePoint next_vsync)

◆ TEST() [17/25]

flutter_runner::testing::TEST ( GetTargetTimesTest  ,
ScheduleForFollowingVsync_BecauseOfNow   
)

Definition at line 876 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::GetTargetTimes().

876  {
877  const fml::TimeDelta vsync_offset = TimeDeltaFromInt(0);
878  const fml::TimeDelta vsync_interval = TimeDeltaFromInt(10);
879  const fml::TimePoint last_targeted_vsync = TimePointFromInt(10);
880  const fml::TimePoint now = TimePointFromInt(15);
881  const fml::TimePoint next_vsync = TimePointFromInt(10);
882 
883  const auto target_times =
885  vsync_offset, vsync_interval, last_targeted_vsync, now, next_vsync);
886 
887  EXPECT_EQ(TimePointToInt(target_times.frame_start), 20);
888  EXPECT_EQ(TimePointToInt(target_times.frame_target), 30);
889 }
static FlutterFrameTimes GetTargetTimes(fml::TimeDelta vsync_offset, fml::TimeDelta vsync_interval, fml::TimePoint last_targeted_vsync, fml::TimePoint now, fml::TimePoint next_vsync)

◆ TEST() [18/25]

flutter_runner::testing::TEST ( GetTargetTimesTest  ,
ScheduleForFollowingVsync_BecauseOfTargettedTime   
)

Definition at line 891 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::GetTargetTimes().

891  {
892  const fml::TimeDelta vsync_offset = TimeDeltaFromInt(0);
893  const fml::TimeDelta vsync_interval = TimeDeltaFromInt(10);
894  const fml::TimePoint last_targeted_vsync = TimePointFromInt(20);
895  const fml::TimePoint now = TimePointFromInt(9);
896  const fml::TimePoint next_vsync = TimePointFromInt(10);
897 
898  const auto target_times =
900  vsync_offset, vsync_interval, last_targeted_vsync, now, next_vsync);
901 
902  EXPECT_EQ(TimePointToInt(target_times.frame_start), 20);
903  EXPECT_EQ(TimePointToInt(target_times.frame_target), 30);
904 }
static FlutterFrameTimes GetTargetTimes(fml::TimeDelta vsync_offset, fml::TimeDelta vsync_interval, fml::TimePoint last_targeted_vsync, fml::TimePoint now, fml::TimePoint next_vsync)

◆ TEST() [19/25]

flutter_runner::testing::TEST ( GetTargetTimesTest  ,
ScheduleForDistantVsync_BecauseOfTargettedTime   
)

Definition at line 906 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::GetTargetTimes().

906  {
907  const fml::TimeDelta vsync_offset = TimeDeltaFromInt(0);
908  const fml::TimeDelta vsync_interval = TimeDeltaFromInt(10);
909  const fml::TimePoint last_targeted_vsync = TimePointFromInt(60);
910  const fml::TimePoint now = TimePointFromInt(9);
911  const fml::TimePoint next_vsync = TimePointFromInt(10);
912 
913  const auto target_times =
915  vsync_offset, vsync_interval, last_targeted_vsync, now, next_vsync);
916 
917  EXPECT_EQ(TimePointToInt(target_times.frame_start), 60);
918  EXPECT_EQ(TimePointToInt(target_times.frame_target), 70);
919 }
static FlutterFrameTimes GetTargetTimes(fml::TimeDelta vsync_offset, fml::TimeDelta vsync_interval, fml::TimePoint last_targeted_vsync, fml::TimePoint now, fml::TimePoint next_vsync)

◆ TEST() [20/25]

flutter_runner::testing::TEST ( GetTargetTimesTest  ,
ScheduleForFollowingVsync_WithSlightVsyncDrift   
)

Definition at line 921 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::GetTargetTimes().

921  {
922  const fml::TimeDelta vsync_offset = TimeDeltaFromInt(0);
923  const fml::TimeDelta vsync_interval = TimeDeltaFromInt(10);
924 
925  // Even though it appears as if the next vsync is at time 40, we should still
926  // present at time 50.
927  const fml::TimePoint last_targeted_vsync = TimePointFromInt(37);
928  const fml::TimePoint now = TimePointFromInt(9);
929  const fml::TimePoint next_vsync = TimePointFromInt(10);
930 
931  const auto target_times =
933  vsync_offset, vsync_interval, last_targeted_vsync, now, next_vsync);
934 
935  EXPECT_EQ(TimePointToInt(target_times.frame_start), 40);
936  EXPECT_EQ(TimePointToInt(target_times.frame_target), 50);
937 }
static FlutterFrameTimes GetTargetTimes(fml::TimeDelta vsync_offset, fml::TimeDelta vsync_interval, fml::TimePoint last_targeted_vsync, fml::TimePoint now, fml::TimePoint next_vsync)

◆ TEST() [21/25]

flutter_runner::testing::TEST ( GetTargetTimesTest  ,
ScheduleForAnOffsetFromVsync   
)

Definition at line 939 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::GetTargetTimes().

939  {
940  const fml::TimeDelta vsync_offset = TimeDeltaFromInt(4);
941  const fml::TimeDelta vsync_interval = TimeDeltaFromInt(10);
942  const fml::TimePoint last_targeted_vsync = TimePointFromInt(10);
943  const fml::TimePoint now = TimePointFromInt(9);
944  const fml::TimePoint next_vsync = TimePointFromInt(10);
945 
946  const auto target_times =
948  vsync_offset, vsync_interval, last_targeted_vsync, now, next_vsync);
949 
950  EXPECT_EQ(TimePointToInt(target_times.frame_start), 16);
951  EXPECT_EQ(TimePointToInt(target_times.frame_target), 20);
952 }
static FlutterFrameTimes GetTargetTimes(fml::TimeDelta vsync_offset, fml::TimeDelta vsync_interval, fml::TimePoint last_targeted_vsync, fml::TimePoint now, fml::TimePoint next_vsync)

◆ TEST() [22/25]

flutter_runner::testing::TEST ( GetTargetTimesTest  ,
ScheduleMultipleTimes   
)

Definition at line 954 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::GetTargetTimes().

954  {
955  const fml::TimeDelta vsync_offset = TimeDeltaFromInt(0);
956  const fml::TimeDelta vsync_interval = TimeDeltaFromInt(10);
957 
958  fml::TimePoint last_targeted_vsync = TimePointFromInt(0);
959  fml::TimePoint now = TimePointFromInt(5);
960  fml::TimePoint next_vsync = TimePointFromInt(10);
961 
962  for (int i = 0; i < 100; ++i) {
963  const auto target_times =
965  vsync_offset, vsync_interval, last_targeted_vsync, now, next_vsync);
966 
967  EXPECT_EQ(TimePointToInt(target_times.frame_start), 10 * (i + 1));
968  EXPECT_EQ(TimePointToInt(target_times.frame_target), 10 * (i + 2));
969 
970  // Simulate the passage of time.
971  now = now + vsync_interval;
972  next_vsync = next_vsync + vsync_interval;
973  last_targeted_vsync = target_times.frame_target;
974  }
975 }
static FlutterFrameTimes GetTargetTimes(fml::TimeDelta vsync_offset, fml::TimeDelta vsync_interval, fml::TimePoint last_targeted_vsync, fml::TimePoint now, fml::TimePoint next_vsync)

◆ TEST() [23/25]

flutter_runner::testing::TEST ( GetTargetTimesTest  ,
ScheduleMultipleTimes_WithDelayedWakeups   
)

Definition at line 977 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::GetTargetTimes().

977  {
978  // It is often the case that Flutter does not wake up when it intends to due
979  // to CPU contention. This test has GfxSessionConnection wake up to
980  // schedule 0-4ns after when |now| should be - and we verify that the results
981  // should be the same as if there were no delay.
982  const fml::TimeDelta vsync_offset = TimeDeltaFromInt(0);
983  const fml::TimeDelta vsync_interval = TimeDeltaFromInt(10);
984 
985  fml::TimePoint last_targeted_vsync = TimePointFromInt(0);
986  fml::TimePoint now = TimePointFromInt(5);
987  fml::TimePoint next_vsync = TimePointFromInt(10);
988 
989  for (int i = 0; i < 100; ++i) {
990  const auto target_times =
992  vsync_offset, vsync_interval, last_targeted_vsync, now, next_vsync);
993 
994  const auto target_times_delay =
996  vsync_offset, vsync_interval, last_targeted_vsync,
997  now + TimeDeltaFromInt(i % 5), next_vsync);
998 
999  EXPECT_EQ(TimePointToInt(target_times.frame_start),
1000  TimePointToInt(target_times_delay.frame_start));
1001  EXPECT_EQ(TimePointToInt(target_times.frame_target),
1002  TimePointToInt(target_times_delay.frame_target));
1003 
1004  // Simulate the passage of time.
1005  now = now + vsync_interval;
1006  next_vsync = next_vsync + vsync_interval;
1007  last_targeted_vsync = target_times.frame_target;
1008  }
1009 }
static FlutterFrameTimes GetTargetTimes(fml::TimeDelta vsync_offset, fml::TimeDelta vsync_interval, fml::TimePoint last_targeted_vsync, fml::TimePoint now, fml::TimePoint next_vsync)

◆ TEST() [24/25]

flutter_runner::testing::TEST ( UpdatePresentationInfoTest  ,
SingleUpdate   
)

Definition at line 1011 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::UpdatePresentationInfo().

1011  {
1012  std::vector<fuchsia::scenic::scheduling::PresentationInfo>
1013  future_presentations = {};
1014 
1015  // Update the |vsync_info|.
1016  future_presentations.push_back(
1017  CreatePresentationInfo(/*latch_point=*/5, /*presentation_time=*/10));
1018 
1019  fuchsia::scenic::scheduling::FuturePresentationTimes future_info;
1020  future_info.future_presentations = std::move(future_presentations);
1021  future_info.remaining_presents_in_flight_allowed = 1;
1022 
1023  fuchsia::scenic::scheduling::PresentationInfo presentation_info;
1024  presentation_info.set_presentation_time(0);
1025 
1026  fuchsia::scenic::scheduling::PresentationInfo new_presentation_info =
1028  std::move(future_info), presentation_info);
1029 
1030  EXPECT_EQ(new_presentation_info.presentation_time(), 10);
1031 }
static fuchsia::scenic::scheduling::PresentationInfo UpdatePresentationInfo(fuchsia::scenic::scheduling::FuturePresentationTimes future_info, fuchsia::scenic::scheduling::PresentationInfo &presentation_info)

◆ TEST() [25/25]

flutter_runner::testing::TEST ( UpdatePresentationInfoTest  ,
MultipleUpdates   
)

Definition at line 1033 of file gfx_session_connection_unittests.cc.

References flutter_runner::GfxSessionConnection::UpdatePresentationInfo().

1033  {
1034  std::vector<fuchsia::scenic::scheduling::PresentationInfo>
1035  future_presentations = {};
1036 
1037  // Update the |vsync_info|.
1038  future_presentations.push_back(
1039  CreatePresentationInfo(/*latch_point=*/15, /*presentation_time=*/20));
1040  future_presentations.push_back(
1041  CreatePresentationInfo(/*latch_point=*/25, /*presentation_time=*/30));
1042  fuchsia::scenic::scheduling::FuturePresentationTimes future_info;
1043  future_info.future_presentations = std::move(future_presentations);
1044  future_info.remaining_presents_in_flight_allowed = 1;
1045 
1046  fuchsia::scenic::scheduling::PresentationInfo presentation_info;
1047  presentation_info.set_presentation_time(0);
1048 
1049  fuchsia::scenic::scheduling::PresentationInfo new_presentation_info =
1051  std::move(future_info), presentation_info);
1052 
1053  EXPECT_EQ(new_presentation_info.presentation_time(), 20);
1054 
1055  // Clear and re-try with more future times!
1056  future_presentations.clear();
1057  future_presentations.push_back(
1058  CreatePresentationInfo(/*latch_point=*/15, /*presentation_time=*/20));
1059  future_presentations.push_back(
1060  CreatePresentationInfo(/*latch_point=*/25, /*presentation_time=*/30));
1061  future_presentations.push_back(
1062  CreatePresentationInfo(/*latch_point=*/35, /*presentation_time=*/40));
1063  future_presentations.push_back(
1064  CreatePresentationInfo(/*latch_point=*/45, /*presentation_time=*/50));
1065  future_info.future_presentations = std::move(future_presentations);
1066  future_info.remaining_presents_in_flight_allowed = 1;
1067 
1068  new_presentation_info =
1070  std::move(future_info), new_presentation_info);
1071 
1072  EXPECT_EQ(new_presentation_info.presentation_time(), 30);
1073 }
static fuchsia::scenic::scheduling::PresentationInfo UpdatePresentationInfo(fuchsia::scenic::scheduling::FuturePresentationTimes future_info, fuchsia::scenic::scheduling::PresentationInfo &presentation_info)

◆ TEST_F() [1/57]

flutter_runner::testing::TEST_F ( FakeFlatlandTest  ,
Initialization   
)

Definition at line 54 of file fake_flatland_unittests.cc.

References flutter_runner::testing::FakeFlatlandTest::fake_flatland(), and flutter_runner::testing::FakeFlatlandTest::loop().

54  {
55  EXPECT_EQ(fake_flatland().debug_name(), "");
56 
57  // Pump the loop one time; the flatland should retain its initial state.
58  loop().RunUntilIdle();
59  EXPECT_EQ(fake_flatland().debug_name(), "");
60 }

◆ TEST_F() [2/57]

flutter_runner::testing::TEST_F ( FakeFlatlandTest  ,
DebugLabel   
)

Definition at line 62 of file fake_flatland_unittests.cc.

References flutter_runner::testing::FakeFlatlandTest::ConnectFlatland(), flutter_runner::testing::FakeFlatlandTest::fake_flatland(), flutter::testing::GetCurrentTestName(), and flutter_runner::testing::FakeFlatlandTest::loop().

62  {
63  const std::string debug_label = GetCurrentTestName();
64  fuchsia::ui::composition::FlatlandPtr flatland = ConnectFlatland();
65 
66  // Set the flatland's debug name. The `SetDebugName` hasn't been processed
67  // yet, so the flatland's view of the debug name is still empty.
68  flatland->SetDebugName(debug_label);
69  EXPECT_EQ(fake_flatland().debug_name(), "");
70 
71  // Pump the loop; the contents of the initial `SetDebugName` should be
72  // processed.
73  loop().RunUntilIdle();
74  EXPECT_EQ(fake_flatland().debug_name(), debug_label);
75 }
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13

◆ TEST_F() [3/57]

flutter_runner::testing::TEST_F ( FocusDelegateTest  ,
WatchCallbackSeries   
)

Definition at line 65 of file focus_delegate_unittests.cc.

References flutter_runner::testing::FakePlatformMessageResponse::Create(), flutter_runner::testing::FocusDelegateTest::focus_delegate_, ParsePlatformMessage(), flutter_runner::testing::FocusDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::FocusDelegateTest::vrf_.

65  {
66  std::vector<bool> vrf_states{false, true, true, false,
67  true, false, true, true};
68  std::size_t vrf_index = 0;
69  std::size_t callback_index = 0;
70  focus_delegate_->WatchLoop([&](bool focus_state) {
71  // Make sure the focus state that FocusDelegate gives us is consistent with
72  // what was fired from the vrf.
73  EXPECT_EQ(vrf_states[callback_index], focus_state);
74 
75  // View.focus.getCurrent should complete with the current (up to date) focus
76  // state.
77  auto response = FakePlatformMessageResponse::Create();
78  EXPECT_TRUE(focus_delegate_->HandlePlatformMessage(
79  ParsePlatformMessage("{\"method\":\"View.focus.getCurrent\"}"),
80  response));
81  response->ExpectCompleted(focus_state ? "[true]" : "[false]");
82 
83  // Ensure this callback always happens in lockstep with
84  // vrf_->ScheduleCallback.
85  EXPECT_EQ(vrf_index, callback_index++);
86  });
87 
88  // Subsequent WatchLoop calls should not be respected.
89  focus_delegate_->WatchLoop([](bool _) {
90  ADD_FAILURE() << "Subsequent WatchLoops should not be respected!";
91  });
92 
93  do {
94  // Ensure the next focus state is handled correctly.
95  auto response1 = FakePlatformMessageResponse::Create();
96  EXPECT_TRUE(focus_delegate_->HandlePlatformMessage(
97  ParsePlatformMessage("{\"method\":\"View.focus.getNext\"}"),
98  response1));
99 
100  // Since there's already an outstanding PlatformMessageResponse, this one
101  // should be completed null.
102  auto response2 = FakePlatformMessageResponse::Create();
103  EXPECT_TRUE(focus_delegate_->HandlePlatformMessage(
104  ParsePlatformMessage("{\"method\":\"View.focus.getNext\"}"),
105  response2));
106  response2->ExpectCompleted("[null]");
107 
108  // Post watch events and trigger the next vrf event.
109  RunLoopUntilIdle();
110  vrf_->ScheduleCallback(vrf_states[vrf_index]);
111  RunLoopUntilIdle();
112 
113  // Next focus state should be completed by now.
114  response1->ExpectCompleted(vrf_states[vrf_index] ? "[true]" : "[false]");
115 
116  // Check View.focus.getCurrent again, and increment vrf_index since we move
117  // on to the next focus state.
118  auto response3 = FakePlatformMessageResponse::Create();
119  EXPECT_TRUE(focus_delegate_->HandlePlatformMessage(
120  ParsePlatformMessage("{\"method\":\"View.focus.getCurrent\"}"),
121  response3));
122  response3->ExpectCompleted(vrf_states[vrf_index++] ? "[true]" : "[false]");
123 
124  // vrf_->times_watched should always be 1 more than the amount of vrf events
125  // emitted.
126  EXPECT_EQ(vrf_index + 1, vrf_->times_watched);
127  } while (vrf_index < vrf_states.size());
128 }
rapidjson::Value ParsePlatformMessage(std::string json)

◆ TEST_F() [4/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Data_FuchsiaTimeVersusFlutterTime   
)

Definition at line 66 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::TouchEventBuilder::AddSample(), flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), kIxnOne, flutter_runner::testing::TouchEventBuilder::New(), flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

66  {
67  std::optional<std::vector<flutter::PointerData>> pointers;
68  pointer_delegate_->WatchLoop(
69  [&pointers](std::vector<flutter::PointerData> events) {
70  pointers = std::move(events);
71  });
72  RunLoopUntilIdle(); // Server gets watch call.
73 
74  // Fuchsia ADD -> Flutter ADD+DOWN
75  std::vector<fup_TouchEvent> events =
76  TouchEventBuilder::New()
77  .AddTime(/* in nanoseconds */ 1111789u)
78  .AddViewParameters(kRect, kRect, kIdentity)
79  .AddSample(kIxnOne, fup_EventPhase::ADD, {10.f, 10.f})
80  .AddResult(
81  {.interaction = kIxnOne, .status = fup_TouchIxnStatus::GRANTED})
82  .BuildAsVector();
83  touch_source_->ScheduleCallback(std::move(events));
84  RunLoopUntilIdle();
85 
86  ASSERT_TRUE(pointers.has_value());
87  ASSERT_EQ(pointers->size(), 2u);
88  EXPECT_EQ((*pointers)[0].time_stamp, /* in microseconds */ 1111u);
89  EXPECT_EQ((*pointers)[1].time_stamp, /* in microseconds */ 1111u);
90 }
constexpr fup_TouchIxnId kIxnOne
constexpr std::array< std::array< float, 2 >, 2 > kRect
constexpr std::array< float, 9 > kIdentity

◆ TEST_F() [5/57]

flutter_runner::testing::TEST_F ( FakeFlatlandTest  ,
Present   
)

Definition at line 77 of file fake_flatland_unittests.cc.

References flutter_runner::testing::FakeFlatlandTest::ConnectFlatland(), flutter_runner::testing::FakeFlatlandTest::fake_flatland(), flutter_runner::testing::FakeFlatland::FireOnFramePresentedEvent(), flutter_runner::testing::FakeFlatland::FireOnNextFrameBeginEvent(), flutter_runner::testing::FakeFlatlandTest::loop(), and flutter_runner::testing::FakeFlatland::SetPresentHandler().

77  {
78  fuchsia::ui::composition::FlatlandPtr flatland = ConnectFlatland();
79 
80  // Fire an OnNextFrameBegin event and verify the test receives it.
81  constexpr uint64_t kOnNextFrameAdditionalPresentCredits = 10u;
82  uint64_t on_next_frame_additional_present_credits = 0u;
83  fuchsia::ui::composition::OnNextFrameBeginValues on_next_frame_begin_values;
84  on_next_frame_begin_values.set_additional_present_credits(
85  kOnNextFrameAdditionalPresentCredits);
86  flatland.events().OnNextFrameBegin =
87  [&on_next_frame_additional_present_credits](
88  auto on_next_frame_begin_values) {
89  static bool called_once = false;
90  EXPECT_FALSE(called_once);
91 
92  on_next_frame_additional_present_credits =
93  on_next_frame_begin_values.additional_present_credits();
94  called_once = true;
95  };
96  fake_flatland().FireOnNextFrameBeginEvent(
97  std::move(on_next_frame_begin_values));
98  EXPECT_EQ(on_next_frame_additional_present_credits, 0u);
99  loop().RunUntilIdle();
100  EXPECT_EQ(on_next_frame_additional_present_credits,
101  kOnNextFrameAdditionalPresentCredits);
102 
103  // Fire an OnFramePresented event and verify the test receives it.
104  constexpr uint64_t kOnFramePresentedNumPresentsAllowed = 20u;
105  uint64_t frame_presented_num_presents_allowed = 0u;
106  flatland.events().OnFramePresented =
107  [&frame_presented_num_presents_allowed](auto frame_presented_info) {
108  static bool called_once = false;
109  EXPECT_FALSE(called_once);
110 
111  frame_presented_num_presents_allowed =
112  frame_presented_info.num_presents_allowed;
113  called_once = true;
114  };
115  fake_flatland().FireOnFramePresentedEvent(
116  fuchsia::scenic::scheduling::FramePresentedInfo{
117  .actual_presentation_time = 0,
118  .num_presents_allowed = kOnFramePresentedNumPresentsAllowed,
119  });
120  EXPECT_EQ(frame_presented_num_presents_allowed, 0u);
121  loop().RunUntilIdle();
122  EXPECT_EQ(frame_presented_num_presents_allowed,
123  kOnFramePresentedNumPresentsAllowed);
124 
125  // Call Present and verify the fake handled it.
126  constexpr int64_t kPresentRequestedTime = 42;
127  int64_t present_requested_time = 0;
128  fuchsia::ui::composition::PresentArgs present_args;
129  present_args.set_requested_presentation_time(kPresentRequestedTime);
130  fake_flatland().SetPresentHandler(
131  [&present_requested_time](auto present_args) {
132  static bool called_once = false;
133  EXPECT_FALSE(called_once);
134 
135  present_requested_time = present_args.requested_presentation_time();
136  called_once = true;
137  });
138  flatland->Present(std::move(present_args));
139  EXPECT_EQ(present_requested_time, 0);
140  loop().RunUntilIdle();
141  EXPECT_EQ(present_requested_time, kPresentRequestedTime);
142 }

◆ TEST_F() [6/57]

flutter_runner::testing::TEST_F ( FlatlandConnectionTest  ,
Initialization   
)

Definition at line 80 of file flatland_connection_unittests.cc.

References flutter_runner::testing::FlatlandConnectionTest::fake_flatland(), flutter::testing::GetCurrentTestName(), flutter_runner::kDefaultFlatlandPresentationInterval, flutter_runner::testing::FlatlandConnectionTest::loop(), flutter_runner::testing::FlatlandConnectionTest::TakeFlatlandHandle(), and fml::TimeDelta::Zero().

80  {
81  // Create the FlatlandConnection but don't pump the loop. No FIDL calls are
82  // completed yet.
83  const std::string debug_name = GetCurrentTestName();
84  flutter_runner::FlatlandConnection flatland_connection(
85  debug_name, TakeFlatlandHandle(), []() { FAIL(); },
86  [](auto...) { FAIL(); }, 1, fml::TimeDelta::Zero());
87  EXPECT_EQ(fake_flatland().debug_name(), "");
88 
89  // Simulate an AwaitVsync that comes immediately.
90  bool await_vsync_fired = false;
91  AwaitVsyncChecked(flatland_connection, await_vsync_fired,
93  EXPECT_TRUE(await_vsync_fired);
94 
95  // Ensure the debug name is set.
96  loop().RunUntilIdle();
97  EXPECT_EQ(fake_flatland().debug_name(), debug_name);
98 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13
static constexpr fml::TimeDelta kDefaultFlatlandPresentationInterval

◆ TEST_F() [7/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Phase_FlutterPhasesAreSynthesized   
)

Definition at line 92 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::TouchEventBuilder::AddSample(), flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), flutter::PointerData::kAdd, flutter::PointerData::kDown, kIxnOne, flutter::PointerData::kMove, flutter::PointerData::kRemove, flutter::PointerData::kUp, flutter_runner::testing::TouchEventBuilder::New(), flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

92  {
93  std::optional<std::vector<flutter::PointerData>> pointers;
94  pointer_delegate_->WatchLoop(
95  [&pointers](std::vector<flutter::PointerData> events) {
96  pointers = std::move(events);
97  });
98  RunLoopUntilIdle(); // Server gets watch call.
99 
100  // Fuchsia ADD -> Flutter ADD+DOWN
101  std::vector<fup_TouchEvent> events =
102  TouchEventBuilder::New()
103  .AddTime(1111000u)
104  .AddViewParameters(kRect, kRect, kIdentity)
105  .AddSample(kIxnOne, fup_EventPhase::ADD, {10.f, 10.f})
106  .AddResult(
107  {.interaction = kIxnOne, .status = fup_TouchIxnStatus::GRANTED})
108  .BuildAsVector();
109  touch_source_->ScheduleCallback(std::move(events));
110  RunLoopUntilIdle();
111 
112  ASSERT_TRUE(pointers.has_value());
113  ASSERT_EQ(pointers->size(), 2u);
114  EXPECT_EQ((*pointers)[0].change, flutter::PointerData::Change::kAdd);
115  EXPECT_EQ((*pointers)[1].change, flutter::PointerData::Change::kDown);
116 
117  // Fuchsia CHANGE -> Flutter MOVE
118  events = TouchEventBuilder::New()
119  .AddTime(2222000u)
120  .AddSample(kIxnOne, fup_EventPhase::CHANGE, {10.f, 10.f})
121  .BuildAsVector();
122  touch_source_->ScheduleCallback(std::move(events));
123  RunLoopUntilIdle();
124 
125  ASSERT_TRUE(pointers.has_value());
126  ASSERT_EQ(pointers->size(), 1u);
127  EXPECT_EQ((*pointers)[0].change, flutter::PointerData::Change::kMove);
128 
129  // Fuchsia REMOVE -> Flutter UP+REMOVE
130  events = TouchEventBuilder::New()
131  .AddTime(3333000u)
132  .AddSample(kIxnOne, fup_EventPhase::REMOVE, {10.f, 10.f})
133  .BuildAsVector();
134  touch_source_->ScheduleCallback(std::move(events));
135  RunLoopUntilIdle();
136 
137  ASSERT_TRUE(pointers.has_value());
138  ASSERT_EQ(pointers->size(), 2u);
139  EXPECT_EQ((*pointers)[0].change, flutter::PointerData::Change::kUp);
140  EXPECT_EQ((*pointers)[1].change, flutter::PointerData::Change::kRemove);
141 }
constexpr fup_TouchIxnId kIxnOne
constexpr std::array< std::array< float, 2 >, 2 > kRect
constexpr std::array< float, 9 > kIdentity

◆ TEST_F() [8/57]

flutter_runner::testing::TEST_F ( EngineTest  ,
ThreadNames   
)

Definition at line 94 of file engine_unittests.cc.

References flutter_runner::Engine::CreateThreadHost(), flutter::testing::GetCurrentTestName(), flutter::ThreadHost::io_thread, flutter::ThreadHost::platform_thread, flutter::prefix, flutter::ThreadHost::raster_thread, and flutter::ThreadHost::ui_thread.

94  {
95  std::string prefix = GetCurrentTestName();
96  flutter::ThreadHost engine_thread_host = Engine::CreateThreadHost(prefix);
97 
98  char thread_name[ZX_MAX_NAME_LEN];
99  zx::thread::self()->get_property(ZX_PROP_NAME, thread_name,
100  sizeof(thread_name));
101  EXPECT_EQ(std::string(thread_name), prefix + std::string(".platform"));
102  EXPECT_EQ(engine_thread_host.platform_thread, nullptr);
103 
104  engine_thread_host.raster_thread->GetTaskRunner()->PostTask([&prefix]() {
105  char thread_name[ZX_MAX_NAME_LEN];
106  zx::thread::self()->get_property(ZX_PROP_NAME, thread_name,
107  sizeof(thread_name));
108  EXPECT_EQ(std::string(thread_name), prefix + std::string(".raster"));
109  });
110  engine_thread_host.raster_thread->Join();
111 
112  engine_thread_host.ui_thread->GetTaskRunner()->PostTask([&prefix]() {
113  char thread_name[ZX_MAX_NAME_LEN];
114  zx::thread::self()->get_property(ZX_PROP_NAME, thread_name,
115  sizeof(thread_name));
116  EXPECT_EQ(std::string(thread_name), prefix + std::string(".ui"));
117  });
118  engine_thread_host.ui_thread->Join();
119 
120  engine_thread_host.io_thread->GetTaskRunner()->PostTask([&prefix]() {
121  char thread_name[ZX_MAX_NAME_LEN];
122  zx::thread::self()->get_property(ZX_PROP_NAME, thread_name,
123  sizeof(thread_name));
124  EXPECT_EQ(std::string(thread_name), prefix + std::string(".io"));
125  });
126  engine_thread_host.io_thread->Join();
127 }
std::unique_ptr< fml::Thread > ui_thread
Definition: thread_host.h:27
DEF_SWITCHES_START snapshot asset Path to the directory containing the four files specified by VmSnapshotInstructions and IsolateSnapshotInstructions vm snapshot The VM instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present isolate snapshot The isolate instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present icu symbol prefix
Definition: switches.h:59
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13
The collection of all the threads used by the engine.
Definition: thread_host.h:16
std::unique_ptr< fml::Thread > io_thread
Definition: thread_host.h:29
std::unique_ptr< fml::Thread > raster_thread
Definition: thread_host.h:28
std::unique_ptr< fml::Thread > platform_thread
Definition: thread_host.h:26

◆ TEST_F() [9/57]

flutter_runner::testing::TEST_F ( FlatlandConnectionTest  ,
FlatlandDisconnect   
)

Definition at line 100 of file flatland_connection_unittests.cc.

References flutter_runner::testing::FakeFlatland::Disconnect(), flutter_runner::testing::FlatlandConnectionTest::fake_flatland(), flutter::testing::GetCurrentTestName(), flutter_runner::testing::FlatlandConnectionTest::loop(), flutter_runner::testing::FlatlandConnectionTest::TakeFlatlandHandle(), and fml::TimeDelta::Zero().

100  {
101  // Set up a callback which allows sensing of the error state.
102  bool error_fired = false;
103  fml::closure on_session_error = [&error_fired]() { error_fired = true; };
104 
105  // Create the FlatlandConnection but don't pump the loop. No FIDL calls are
106  // completed yet.
107  flutter_runner::FlatlandConnection flatland_connection(
108  GetCurrentTestName(), TakeFlatlandHandle(), std::move(on_session_error),
109  [](auto...) { FAIL(); }, 1, fml::TimeDelta::Zero());
110  EXPECT_FALSE(error_fired);
111 
112  // Simulate a flatland disconnection, then Pump the loop. The error callback
113  // will fire.
114  fake_flatland().Disconnect(
115  fuchsia::ui::composition::FlatlandError::BAD_OPERATION);
116  loop().RunUntilIdle();
117  EXPECT_TRUE(error_fired);
118 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13
std::function< void()> closure
Definition: closure.h:14

◆ TEST_F() [10/57]

flutter_runner::testing::TEST_F ( FlatlandConnectionTest  ,
BasicPresent   
)

Definition at line 120 of file flatland_connection_unittests.cc.

References event, flutter_runner::testing::FlatlandConnectionTest::fake_flatland(), flutter_runner::testing::FakeFlatland::FireOnFramePresentedEvent(), flutter_runner::testing::FakeFlatland::FireOnNextFrameBeginEvent(), flutter::testing::GetCurrentTestName(), flutter_runner::kDefaultFlatlandPresentationInterval, flutter_runner::testing::FlatlandConnectionTest::loop(), flutter_runner::testing::FakeFlatland::SetPresentHandler(), flutter_runner::testing::FlatlandConnectionTest::TakeFlatlandHandle(), and fml::TimeDelta::Zero().

120  {
121  // Set up callbacks which allow sensing of how many presents were handled.
122  size_t presents_called = 0u;
123  zx_handle_t release_fence_handle;
124  fake_flatland().SetPresentHandler([&presents_called,
125  &release_fence_handle](auto present_args) {
126  presents_called++;
127  release_fence_handle = present_args.release_fences().empty()
128  ? ZX_HANDLE_INVALID
129  : present_args.release_fences().front().get();
130  });
131 
132  // Set up a callback which allows sensing of how many vsync's
133  // (`OnFramePresented` events) were handled.
134  size_t vsyncs_handled = 0u;
135  on_frame_presented_event on_frame_presented = [&vsyncs_handled](auto...) {
136  vsyncs_handled++;
137  };
138 
139  // Create the FlatlandConnection but don't pump the loop. No FIDL calls are
140  // completed yet.
141  flutter_runner::FlatlandConnection flatland_connection(
142  GetCurrentTestName(), TakeFlatlandHandle(), []() { FAIL(); },
143  std::move(on_frame_presented), 1, fml::TimeDelta::Zero());
144  EXPECT_EQ(presents_called, 0u);
145  EXPECT_EQ(vsyncs_handled, 0u);
146 
147  // Pump the loop. Nothing is called.
148  loop().RunUntilIdle();
149  EXPECT_EQ(presents_called, 0u);
150  EXPECT_EQ(vsyncs_handled, 0u);
151 
152  // Simulate an AwaitVsync that comes after the first call.
153  bool await_vsync_fired = false;
154  AwaitVsyncChecked(flatland_connection, await_vsync_fired,
156  EXPECT_TRUE(await_vsync_fired);
157 
158  // Call Present and Pump the loop; `Present` and its callback is called. No
159  // release fence should be queued.
160  await_vsync_fired = false;
161  zx::event first_release_fence;
162  zx::event::create(0, &first_release_fence);
163  const zx_handle_t first_release_fence_handle = first_release_fence.get();
164  flatland_connection.EnqueueReleaseFence(std::move(first_release_fence));
165  flatland_connection.Present();
166  loop().RunUntilIdle();
167  EXPECT_EQ(presents_called, 1u);
168  EXPECT_EQ(release_fence_handle, ZX_HANDLE_INVALID);
169  EXPECT_EQ(vsyncs_handled, 0u);
170  EXPECT_FALSE(await_vsync_fired);
171 
172  // Fire the `OnNextFrameBegin` event. AwaitVsync should be fired.
173  AwaitVsyncChecked(flatland_connection, await_vsync_fired,
175  fuchsia::ui::composition::OnNextFrameBeginValues on_next_frame_begin_values;
176  on_next_frame_begin_values.set_additional_present_credits(3);
177  fake_flatland().FireOnNextFrameBeginEvent(
178  std::move(on_next_frame_begin_values));
179  loop().RunUntilIdle();
180  EXPECT_TRUE(await_vsync_fired);
181 
182  // Fire the `OnFramePresented` event associated with the first `Present`,
183  fake_flatland().FireOnFramePresentedEvent(
184  fuchsia::scenic::scheduling::FramePresentedInfo());
185  loop().RunUntilIdle();
186  EXPECT_EQ(vsyncs_handled, 1u);
187 
188  // Call Present for a second time and Pump the loop; `Present` and its
189  // callback is called. Release fences for the earlier present is used.
190  await_vsync_fired = false;
191  flatland_connection.Present();
192  loop().RunUntilIdle();
193  EXPECT_EQ(presents_called, 2u);
194  EXPECT_EQ(release_fence_handle, first_release_fence_handle);
195 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13
FlKeyEvent * event
std::function< void(fuchsia::scenic::scheduling::FramePresentedInfo)> on_frame_presented_event
static constexpr fml::TimeDelta kDefaultFlatlandPresentationInterval

◆ TEST_F() [11/57]

flutter_runner::testing::TEST_F ( EngineTest  ,
SkpWarmup   
)

Definition at line 129 of file engine_unittests.cc.

References fml::kRead, fml::kReadWrite, fml::OpenDirectory(), flutter::SerializeImageWithoutData(), flutter::SerializeTypefaceWithoutData(), and fml::WriteAtomically().

129  {
130  SkISize draw_size = SkISize::Make(100, 100);
131  SkPictureRecorder recorder;
132  auto canvas = recorder.beginRecording(draw_size.width(), draw_size.height());
133 
134  // adapted from https://fiddle.skia.org/c/@Canvas_drawLine
135  SkPaint paint;
136  paint.setColor(0xFF9a67be);
137  paint.setStrokeWidth(20);
138  canvas->drawLine(0, 0, draw_size.width(), draw_size.height(), paint);
139  canvas->drawLine(0, draw_size.height(), draw_size.width(), 0, paint);
140 
141  sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
142  SkSerialProcs procs = {0};
143  procs.fImageProc = SerializeImageWithoutData;
144  procs.fTypefaceProc = SerializeTypefaceWithoutData;
145  sk_sp<SkData> data = picture->serialize(&procs);
146  ASSERT_TRUE(data);
147  ASSERT_GT(data->size(), 0u);
148 
149  fml::NonOwnedMapping mapping(data->bytes(), data->size());
150 
152  fml::UniqueFD asset_dir_fd = fml::OpenDirectory(
153  asset_dir.path().c_str(), false, fml::FilePermission::kRead);
154  fml::UniqueFD subdir_fd = fml::OpenDirectory(asset_dir_fd, "shaders", true,
156 
157  bool success = fml::WriteAtomically(subdir_fd, "test.skp", mapping);
158  ASSERT_TRUE(success);
159 
160  auto asset_manager = std::make_shared<AssetManager>();
161  asset_manager->PushBack(
162  std::make_unique<DirectoryAssetBundle>(std::move(asset_dir_fd), false));
163 
164  WarmupSkps(draw_size.width(), draw_size.height(), asset_manager, std::nullopt,
165  std::nullopt);
166  concurrent_task_runner_.Run();
167  raster_task_runner_.Run();
168 
169  EXPECT_EQ(concurrent_task_runner_.GetTaskCount(), 1);
170  EXPECT_EQ(raster_task_runner_.GetTaskCount(), 1);
171 }
sk_sp< SkData > SerializeImageWithoutData(SkImage *image, void *ctx)
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:96
sk_sp< SkData > SerializeTypefaceWithoutData(SkTypeface *typeface, void *ctx)
bool WriteAtomically(const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
Definition: file_posix.cc:190

◆ TEST_F() [12/57]

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

Definition at line 132 of file focus_delegate_unittests.cc.

References flutter_runner::testing::FakePlatformMessageResponse::Create(), flutter_runner::testing::FocusDelegateTest::focus_delegate_, flutter_runner::testing::FocusDelegateTest::focuser_, ParsePlatformMessage(), and flutter_runner::testing::FocusDelegateTest::RunLoopUntilIdle().

132  {
133  // This "Mock" ViewRef serves as the target for the RequestFocus operation.
134  auto mock_view_ref_pair = scenic::ViewRefPair::New();
135  // Create the platform message request.
136  std::ostringstream message;
137  message << "{"
138  << " \"method\":\"View.focus.request\","
139  << " \"args\": {"
140  << " \"viewRef\":"
141  << mock_view_ref_pair.view_ref.reference.get() << " }"
142  << "}";
143 
144  // Dispatch the plaform message request with an expected completion response.
145  auto response = FakePlatformMessageResponse::Create();
146  EXPECT_TRUE(focus_delegate_->HandlePlatformMessage(
147  ParsePlatformMessage(message.str()), response));
148  RunLoopUntilIdle();
149 
150  response->ExpectCompleted("[0]");
151  EXPECT_TRUE(focuser_->request_focus_called());
152 }
rapidjson::Value ParsePlatformMessage(std::string json)

◆ TEST_F() [13/57]

flutter_runner::testing::TEST_F ( GfxSessionConnectionTest  ,
Initialization   
)

Definition at line 133 of file gfx_session_connection_unittests.cc.

References flutter_runner::testing::GfxSessionConnectionTest::fake_session(), flutter::testing::GetCurrentTestName(), flutter_runner::testing::GfxSessionConnectionTest::GetInspectNode(), flutter_runner::kDefaultPresentationInterval, flutter_runner::testing::GfxSessionConnectionTest::loop(), flutter_runner::testing::GfxSessionConnectionTest::TakeSessionHandle(), and fml::TimeDelta::Zero().

133  {
134  // Create the GfxSessionConnection but don't pump the loop. No FIDL calls are
135  // completed yet.
136  const std::string debug_name = GetCurrentTestName();
137  flutter_runner::GfxSessionConnection session_connection(
138  debug_name, GetInspectNode(), TakeSessionHandle(), []() { FAIL(); },
139  [](auto...) { FAIL(); }, 1, fml::TimeDelta::Zero());
140  EXPECT_EQ(fake_session().debug_name(), "");
141  EXPECT_TRUE(fake_session().command_queue().empty());
142 
143  // Simulate an AwaitVsync that comes immediately, before
144  // `RequestPresentationTimes` returns.
145  bool await_vsync_fired = false;
146  AwaitVsyncChecked(session_connection, await_vsync_fired,
148  EXPECT_TRUE(await_vsync_fired);
149 
150  // Ensure the debug name is set.
151  loop().RunUntilIdle();
152  EXPECT_EQ(fake_session().debug_name(), debug_name);
153  EXPECT_TRUE(fake_session().command_queue().empty());
154 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13
static constexpr fml::TimeDelta kDefaultPresentationInterval

◆ TEST_F() [14/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Phase_FuchsiaCancelBecomesFlutterCancel   
)

Definition at line 143 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::TouchEventBuilder::AddSample(), flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), flutter::PointerData::kAdd, flutter::PointerData::kCancel, flutter::PointerData::kDown, kIxnOne, flutter_runner::testing::TouchEventBuilder::New(), flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

143  {
144  std::optional<std::vector<flutter::PointerData>> pointers;
145  pointer_delegate_->WatchLoop(
146  [&pointers](std::vector<flutter::PointerData> events) {
147  pointers = std::move(events);
148  });
149  RunLoopUntilIdle(); // Server gets watch call.
150 
151  // Fuchsia ADD -> Flutter ADD+DOWN
152  std::vector<fup_TouchEvent> events =
153  TouchEventBuilder::New()
154  .AddTime(1111000u)
155  .AddViewParameters(kRect, kRect, kIdentity)
156  .AddSample(kIxnOne, fup_EventPhase::ADD, {10.f, 10.f})
157  .AddResult(
158  {.interaction = kIxnOne, .status = fup_TouchIxnStatus::GRANTED})
159  .BuildAsVector();
160  touch_source_->ScheduleCallback(std::move(events));
161  RunLoopUntilIdle();
162 
163  ASSERT_TRUE(pointers.has_value());
164  ASSERT_EQ(pointers->size(), 2u);
165  EXPECT_EQ((*pointers)[0].change, flutter::PointerData::Change::kAdd);
166  EXPECT_EQ((*pointers)[1].change, flutter::PointerData::Change::kDown);
167 
168  // Fuchsia CANCEL -> Flutter CANCEL
169  events = TouchEventBuilder::New()
170  .AddTime(2222000u)
171  .AddSample(kIxnOne, fup_EventPhase::CANCEL, {10.f, 10.f})
172  .BuildAsVector();
173  touch_source_->ScheduleCallback(std::move(events));
174  RunLoopUntilIdle();
175 
176  ASSERT_TRUE(pointers.has_value());
177  ASSERT_EQ(pointers->size(), 1u);
178  EXPECT_EQ((*pointers)[0].change, flutter::PointerData::Change::kCancel);
179 }
constexpr fup_TouchIxnId kIxnOne
constexpr std::array< std::array< float, 2 >, 2 > kRect
constexpr std::array< float, 9 > kIdentity

◆ TEST_F() [15/57]

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

Definition at line 156 of file focus_delegate_unittests.cc.

References flutter_runner::testing::FakePlatformMessageResponse::Create(), flutter_runner::testing::FocusDelegateTest::focus_delegate_, flutter_runner::testing::FocusDelegateTest::focuser_, ParsePlatformMessage(), and flutter_runner::testing::FocusDelegateTest::RunLoopUntilIdle().

156  {
157  // This "Mock" ViewRef serves as the target for the RequestFocus operation.
158  auto mock_view_ref_pair = scenic::ViewRefPair::New();
159  // We're testing the focus failure case.
160  focuser_->fail_request_focus();
161  // Create the platform message request.
162  std::ostringstream message;
163  message << "{"
164  << " \"method\":\"View.focus.request\","
165  << " \"args\": {"
166  << " \"viewRef\":"
167  << mock_view_ref_pair.view_ref.reference.get() << " }"
168  << "}";
169 
170  // Dispatch the plaform message request with an expected completion response.
171  auto response = FakePlatformMessageResponse::Create();
172  EXPECT_TRUE(focus_delegate_->HandlePlatformMessage(
173  ParsePlatformMessage(message.str()), response));
174  RunLoopUntilIdle();
175 
176  response->ExpectCompleted(
177  "[" +
178  std::to_string(
179  static_cast<std::underlying_type_t<fuchsia::ui::views::Error>>(
180  fuchsia::ui::views::Error::DENIED)) +
181  "]");
182  EXPECT_TRUE(focuser_->request_focus_called());
183 }
rapidjson::Value ParsePlatformMessage(std::string json)

◆ TEST_F() [16/57]

flutter_runner::testing::TEST_F ( GfxSessionConnectionTest  ,
SessionDisconnect   
)

Definition at line 156 of file gfx_session_connection_unittests.cc.

References flutter_runner::testing::FakeSession::DisconnectSession(), flutter_runner::testing::GfxSessionConnectionTest::fake_session(), flutter::testing::GetCurrentTestName(), flutter_runner::testing::GfxSessionConnectionTest::GetInspectNode(), flutter_runner::testing::GfxSessionConnectionTest::loop(), flutter_runner::testing::GfxSessionConnectionTest::TakeSessionHandle(), and fml::TimeDelta::Zero().

156  {
157  // Set up a callback which allows sensing of the session error state.
158  bool session_error_fired = false;
159  fml::closure on_session_error = [&session_error_fired]() {
160  session_error_fired = true;
161  };
162 
163  // Create the GfxSessionConnection but don't pump the loop. No FIDL calls are
164  // completed yet.
165  flutter_runner::GfxSessionConnection session_connection(
166  GetCurrentTestName(), GetInspectNode(), TakeSessionHandle(),
167  std::move(on_session_error), [](auto...) { FAIL(); }, 1,
169  EXPECT_FALSE(session_error_fired);
170 
171  // Simulate a session disconnection, then Pump the loop. The session error
172  // callback will fire.
173  fake_session().DisconnectSession();
174  loop().RunUntilIdle();
175  EXPECT_TRUE(session_error_fired);
176 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13
std::function< void()> closure
Definition: closure.h:14

◆ TEST_F() [17/57]

flutter_runner::testing::TEST_F ( EngineTest  ,
SkpWarmupAsync   
)

Definition at line 173 of file engine_unittests.cc.

References fml::kRead, fml::kReadWrite, fml::OpenDirectory(), flutter::SerializeImageWithoutData(), flutter::SerializeTypefaceWithoutData(), and fml::WriteAtomically().

173  {
174  SkISize draw_size = SkISize::Make(100, 100);
175  SkPictureRecorder recorder;
176  auto canvas = recorder.beginRecording(draw_size.width(), draw_size.height());
177 
178  // adapted from https://fiddle.skia.org/c/@Canvas_drawLine
179  SkPaint paint;
180  paint.setColor(0xFF9a67be);
181  paint.setStrokeWidth(20);
182  canvas->drawLine(0, 0, draw_size.width(), draw_size.height(), paint);
183  canvas->drawLine(0, draw_size.height(), draw_size.width(), 0, paint);
184 
185  sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
186  SkSerialProcs procs = {0};
187  procs.fImageProc = SerializeImageWithoutData;
188  procs.fTypefaceProc = SerializeTypefaceWithoutData;
189  sk_sp<SkData> data = picture->serialize(&procs);
190  ASSERT_TRUE(data);
191  ASSERT_GT(data->size(), 0u);
192 
193  fml::NonOwnedMapping mapping(data->bytes(), data->size());
194 
196  fml::UniqueFD asset_dir_fd = fml::OpenDirectory(
197  asset_dir.path().c_str(), false, fml::FilePermission::kRead);
198  fml::UniqueFD subdir_fd = fml::OpenDirectory(asset_dir_fd, "shaders", true,
200  std::string skp_name = "test.skp";
201 
202  bool success = fml::WriteAtomically(subdir_fd, skp_name.c_str(), mapping);
203  ASSERT_TRUE(success);
204 
205  auto asset_manager = std::make_shared<AssetManager>();
206  asset_manager->PushBack(
207  std::make_unique<DirectoryAssetBundle>(std::move(asset_dir_fd), false));
208 
209  std::vector<std::string> skp_names = {skp_name};
210 
211  WarmupSkps(draw_size.width(), draw_size.height(), asset_manager, skp_names,
212  [](uint32_t count) { EXPECT_EQ(1u, count); });
213  concurrent_task_runner_.Run();
214  raster_task_runner_.Run();
215 
216  EXPECT_EQ(concurrent_task_runner_.GetTaskCount(), 1);
217  EXPECT_EQ(raster_task_runner_.GetTaskCount(), 1);
218 }
sk_sp< SkData > SerializeImageWithoutData(SkImage *image, void *ctx)
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:96
sk_sp< SkData > SerializeTypefaceWithoutData(SkTypeface *typeface, void *ctx)
bool WriteAtomically(const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
Definition: file_posix.cc:190

◆ TEST_F() [18/57]

flutter_runner::testing::TEST_F ( GfxSessionConnectionTest  ,
BasicPresent   
)

Definition at line 178 of file gfx_session_connection_unittests.cc.

References flutter_runner::testing::GfxSessionConnectionTest::fake_session(), flutter_runner::testing::FakeSession::FireOnFramePresentedEvent(), flutter::testing::GetCurrentTestName(), flutter_runner::testing::GfxSessionConnectionTest::GetInspectNode(), flutter_runner::kDefaultPresentationInterval, flutter_runner::testing::GfxSessionConnectionTest::loop(), flutter_runner::testing::FakeSession::SetPresent2Handler(), flutter_runner::testing::FakeSession::SetRequestPresentationTimesHandler(), flutter_runner::testing::GfxSessionConnectionTest::TakeSessionHandle(), and fml::TimeDelta::Zero().

178  {
179  // Set up callbacks which allow sensing of how many presents
180  // (`RequestPresentationTimes` or `Present` calls) were handled.
181  size_t request_times_called = 0u;
182  size_t presents_called = 0u;
183  fake_session().SetRequestPresentationTimesHandler([&request_times_called](
184  auto...) -> auto {
185  request_times_called++;
186  return FuturePresentationTimes{
187  .future_presentations = {},
188  .remaining_presents_in_flight_allowed = 1,
189  };
190  });
191  fake_session().SetPresent2Handler([&presents_called](auto...) -> auto {
192  presents_called++;
193  return FuturePresentationTimes{
194  .future_presentations = {},
195  .remaining_presents_in_flight_allowed = 1,
196  };
197  });
198 
199  // Set up a callback which allows sensing of how many vsync's
200  // (`OnFramePresented` events) were handled.
201  size_t vsyncs_handled = 0u;
202  on_frame_presented_event on_frame_presented = [&vsyncs_handled](auto...) {
203  vsyncs_handled++;
204  };
205 
206  // Create the GfxSessionConnection but don't pump the loop. No FIDL calls are
207  // completed yet.
208  flutter_runner::GfxSessionConnection session_connection(
209  GetCurrentTestName(), GetInspectNode(), TakeSessionHandle(),
210  []() { FAIL(); }, std::move(on_frame_presented), 1,
212  EXPECT_TRUE(fake_session().command_queue().empty());
213  EXPECT_EQ(request_times_called, 0u);
214  EXPECT_EQ(presents_called, 0u);
215  EXPECT_EQ(vsyncs_handled, 0u);
216 
217  // Pump the loop; `RequestPresentationTimes`, `Present`, and both of their
218  // callbacks are called.
219  loop().RunUntilIdle();
220  EXPECT_TRUE(fake_session().command_queue().empty());
221  EXPECT_EQ(request_times_called, 1u);
222  EXPECT_EQ(presents_called, 1u);
223  EXPECT_EQ(vsyncs_handled, 0u);
224 
225  // Fire the `OnFramePresented` event associated with the first `Present`, then
226  // pump the loop. The `OnFramePresented` event is resolved.
227  fake_session().FireOnFramePresentedEvent(
228  MakeFramePresentedInfoForOnePresent(0, 0));
229  loop().RunUntilIdle();
230  EXPECT_TRUE(fake_session().command_queue().empty());
231  EXPECT_EQ(request_times_called, 1u);
232  EXPECT_EQ(presents_called, 1u);
233  EXPECT_EQ(vsyncs_handled, 1u);
234 
235  // Simulate an AwaitVsync that comes after the first `OnFramePresented`
236  // event.
237  bool await_vsync_fired = false;
238  AwaitVsyncChecked(session_connection, await_vsync_fired,
240  EXPECT_TRUE(await_vsync_fired);
241 
242  // Call Present and Pump the loop; `Present` and its callback is called.
243  await_vsync_fired = false;
244  session_connection.Present();
245  loop().RunUntilIdle();
246  EXPECT_TRUE(fake_session().command_queue().empty());
247  EXPECT_FALSE(await_vsync_fired);
248  EXPECT_EQ(request_times_called, 1u);
249  EXPECT_EQ(presents_called, 2u);
250  EXPECT_EQ(vsyncs_handled, 1u);
251 
252  // Fire the `OnFramePresented` event associated with the second `Present`,
253  // then pump the loop. The `OnFramePresented` event is resolved.
254  fake_session().FireOnFramePresentedEvent(
255  MakeFramePresentedInfoForOnePresent(0, 0));
256  loop().RunUntilIdle();
257  EXPECT_TRUE(fake_session().command_queue().empty());
258  EXPECT_FALSE(await_vsync_fired);
259  EXPECT_EQ(request_times_called, 1u);
260  EXPECT_EQ(presents_called, 2u);
261  EXPECT_EQ(vsyncs_handled, 2u);
262 
263  // Simulate an AwaitVsync that comes after the second `OnFramePresented`
264  // event.
265  await_vsync_fired = false;
266  AwaitVsyncChecked(session_connection, await_vsync_fired,
269  EXPECT_TRUE(await_vsync_fired);
270 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13
std::function< void(fuchsia::scenic::scheduling::FramePresentedInfo)> on_frame_presented_event
static constexpr fml::TimeDelta kDefaultPresentationInterval

◆ TEST_F() [19/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Coordinates_CorrectMapping   
)

Definition at line 181 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), kIxnOne, flutter_runner::testing::TouchEventBuilder::New(), flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

181  {
182  std::optional<std::vector<flutter::PointerData>> pointers;
183  pointer_delegate_->WatchLoop(
184  [&pointers](std::vector<flutter::PointerData> events) {
185  pointers = std::move(events);
186  });
187  RunLoopUntilIdle(); // Server gets watch call.
188 
189  // Fuchsia ADD event, with a view parameter that maps the viewport identically
190  // to the view. Then the center point of the viewport should map to the center
191  // of the view, (10.f, 10.f).
192  std::vector<fup_TouchEvent> events =
193  TouchEventBuilder::New()
194  .AddTime(2222000u)
195  .AddViewParameters(/*view*/ {{{0, 0}, {20, 20}}},
196  /*viewport*/ {{{0, 0}, {20, 20}}},
197  /*matrix*/ {1, 0, 0, 0, 1, 0, 0, 0, 1})
198  .AddSample(kIxnOne, fup_EventPhase::ADD, {10.f, 10.f})
199  .AddResult(
200  {.interaction = kIxnOne, .status = fup_TouchIxnStatus::GRANTED})
201  .BuildAsVector();
202  touch_source_->ScheduleCallback(std::move(events));
203  RunLoopUntilIdle();
204 
205  ASSERT_TRUE(pointers.has_value());
206  ASSERT_EQ(pointers->size(), 2u); // ADD - DOWN
207  EXPECT_FLOAT_EQ((*pointers)[0].physical_x, 10.f);
208  EXPECT_FLOAT_EQ((*pointers)[0].physical_y, 10.f);
209  pointers = {};
210 
211  // Fuchsia CHANGE event, with a view parameter that translates the viewport by
212  // (10, 10) within the view. Then the minimal point in the viewport (its
213  // origin) should map to the center of the view, (10.f, 10.f).
214  events = TouchEventBuilder::New()
215  .AddTime(2222000u)
216  .AddViewParameters(/*view*/ {{{0, 0}, {20, 20}}},
217  /*viewport*/ {{{0, 0}, {20, 20}}},
218  /*matrix*/ {1, 0, 0, 0, 1, 0, 10, 10, 1})
219  .AddSample(kIxnOne, fup_EventPhase::CHANGE, {0.f, 0.f})
220  .BuildAsVector();
221  touch_source_->ScheduleCallback(std::move(events));
222  RunLoopUntilIdle();
223 
224  ASSERT_TRUE(pointers.has_value());
225  ASSERT_EQ(pointers->size(), 1u); // MOVE
226  EXPECT_FLOAT_EQ((*pointers)[0].physical_x, 10.f);
227  EXPECT_FLOAT_EQ((*pointers)[0].physical_y, 10.f);
228 
229  // Fuchsia CHANGE event, with a view parameter that scales the viewport by
230  // (0.5, 0.5) within the view. Then the maximal point in the viewport should
231  // map to the center of the view, (10.f, 10.f).
232  events = TouchEventBuilder::New()
233  .AddTime(2222000u)
234  .AddViewParameters(/*view*/ {{{0, 0}, {20, 20}}},
235  /*viewport*/ {{{0, 0}, {20, 20}}},
236  /*matrix*/ {0.5f, 0, 0, 0, 0.5f, 0, 0, 0, 1})
237  .AddSample(kIxnOne, fup_EventPhase::CHANGE, {20.f, 20.f})
238  .BuildAsVector();
239  touch_source_->ScheduleCallback(std::move(events));
240  RunLoopUntilIdle();
241 
242  ASSERT_TRUE(pointers.has_value());
243  ASSERT_EQ(pointers->size(), 1u); // MOVE
244  EXPECT_FLOAT_EQ((*pointers)[0].physical_x, 10.f);
245  EXPECT_FLOAT_EQ((*pointers)[0].physical_y, 10.f);
246 }
constexpr fup_TouchIxnId kIxnOne

◆ TEST_F() [20/57]

flutter_runner::testing::TEST_F ( FakeSessionTest  ,
Initialization   
)

Definition at line 184 of file fake_session_unittests.cc.

References flutter_runner::testing::FakeSessionTest::fake_session(), flutter_runner::testing::FakeSessionTest::loop(), and fml::size().

184  {
185  EXPECT_EQ(fake_session().debug_name(), "");
186  EXPECT_EQ(fake_session().command_queue().size(), 0u);
187  EXPECT_THAT(fake_session().SceneGraph(), IsEmptySceneGraph());
188 
189  // Pump the loop one time; the session should retain its initial state.
190  loop().RunUntilIdle();
191  EXPECT_EQ(fake_session().debug_name(), "");
192  EXPECT_EQ(fake_session().command_queue().size(), 0u);
193  EXPECT_THAT(fake_session().SceneGraph(), IsEmptySceneGraph());
194 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13

◆ TEST_F() [21/57]

flutter_runner::testing::TEST_F ( FakeSessionTest  ,
DebugLabel   
)

Definition at line 196 of file fake_session_unittests.cc.

References flutter_runner::testing::FakeSessionTest::CreateSession(), flutter_runner::testing::FakeSessionTest::fake_session(), flutter::testing::GetCurrentTestName(), and flutter_runner::testing::FakeSessionTest::loop().

196  {
197  scenic::Session session = CreateSession();
198 
199  // Set the session's debug name. The `SetDebugName` hasn't been processed
200  // yet, so the session's view of the debug name is still empty.
201  const std::string kDebugLabel = GetCurrentTestName();
202  session.SetDebugName(kDebugLabel);
203  session.Flush(); // Bypass local command caching.
204  EXPECT_EQ(fake_session().debug_name(), "");
205 
206  // Pump the loop; the contents of the initial `SetDebugName` should be
207  // processed.
208  loop().RunUntilIdle();
209  EXPECT_EQ(fake_session().debug_name(), kDebugLabel);
210 }
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13

◆ TEST_F() [22/57]

flutter_runner::testing::TEST_F ( FlatlandConnectionTest  ,
OutOfOrderAwait   
)

Definition at line 197 of file flatland_connection_unittests.cc.

References flutter_runner::testing::FlatlandConnectionTest::fake_flatland(), flutter::testing::GetCurrentTestName(), flutter_runner::kDefaultFlatlandPresentationInterval, flutter_runner::testing::FlatlandConnectionTest::loop(), flutter_runner::testing::FlatlandConnectionTest::OnNextFrameBegin(), flutter_runner::testing::FakeFlatland::SetPresentHandler(), flutter_runner::testing::FlatlandConnectionTest::TakeFlatlandHandle(), and fml::TimeDelta::Zero().

197  {
198  // Set up callbacks which allow sensing of how many presents were handled.
199  size_t presents_called = 0u;
200  zx_handle_t release_fence_handle;
201  fake_flatland().SetPresentHandler([&presents_called,
202  &release_fence_handle](auto present_args) {
203  presents_called++;
204  release_fence_handle = present_args.release_fences().empty()
205  ? ZX_HANDLE_INVALID
206  : present_args.release_fences().front().get();
207  });
208 
209  // Set up a callback which allows sensing of how many vsync's
210  // (`OnFramePresented` events) were handled.
211  size_t vsyncs_handled = 0u;
212  on_frame_presented_event on_frame_presented = [&vsyncs_handled](auto...) {
213  vsyncs_handled++;
214  };
215 
216  // Create the FlatlandConnection but don't pump the loop. No FIDL calls are
217  // completed yet.
218  flutter_runner::FlatlandConnection flatland_connection(
219  GetCurrentTestName(), TakeFlatlandHandle(), []() { FAIL(); },
220  std::move(on_frame_presented), 1, fml::TimeDelta::Zero());
221  EXPECT_EQ(presents_called, 0u);
222  EXPECT_EQ(vsyncs_handled, 0u);
223 
224  // Pump the loop. Nothing is called.
225  loop().RunUntilIdle();
226  EXPECT_EQ(presents_called, 0u);
227  EXPECT_EQ(vsyncs_handled, 0u);
228 
229  // Simulate an AwaitVsync that comes after the first call.
230  bool await_vsync_callback_fired = false;
231  AwaitVsyncChecked(flatland_connection, await_vsync_callback_fired,
233  EXPECT_TRUE(await_vsync_callback_fired);
234 
235  // Set the callback with AwaitVsync, callback should not be fired
236  await_vsync_callback_fired = false;
237  AwaitVsyncChecked(flatland_connection, await_vsync_callback_fired,
239  EXPECT_FALSE(await_vsync_callback_fired);
240 
241  // Fire the `OnNextFrameBegin` event. AwaitVsync callback should be fired.
242  await_vsync_callback_fired = false;
243  OnNextFrameBegin(1);
244  loop().RunUntilIdle();
245  EXPECT_TRUE(await_vsync_callback_fired);
246 
247  // Second consecutive ONFB should not call the fire callback and should
248  // instead set it to be pending to fire on next AwaitVsync
249  await_vsync_callback_fired = false;
250  OnNextFrameBegin(1);
251  loop().RunUntilIdle();
252  EXPECT_FALSE(await_vsync_callback_fired);
253 
254  // Now an AwaitVsync should immediately fire the pending callback
255  await_vsync_callback_fired = false;
256  AwaitVsyncChecked(flatland_connection, await_vsync_callback_fired,
258  EXPECT_TRUE(await_vsync_callback_fired);
259 
260  // With the pending callback fired, The new callback should be set for the
261  // next OnNextFrameBegin to call
262  await_vsync_callback_fired = false;
263  AwaitVsyncChecked(flatland_connection, await_vsync_callback_fired,
265  EXPECT_FALSE(await_vsync_callback_fired);
266 
267  // Now OnNextFrameBegin should fire the callback
268  await_vsync_callback_fired = false;
269  OnNextFrameBegin(1);
270  loop().RunUntilIdle();
271  EXPECT_TRUE(await_vsync_callback_fired);
272 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13
std::function< void(fuchsia::scenic::scheduling::FramePresentedInfo)> on_frame_presented_event
static constexpr fml::TimeDelta kDefaultFlatlandPresentationInterval

◆ TEST_F() [23/57]

flutter_runner::testing::TEST_F ( FakeSessionTest  ,
CommandQueueInvariants   
)

Definition at line 212 of file fake_session_unittests.cc.

References flutter_runner::testing::FakeSessionTest::CreateSession(), flutter_runner::testing::FakeSessionTest::fake_session(), flutter_runner::testing::FakeSessionTest::loop(), node, and fml::size().

212  {
213  scenic::Session session = CreateSession();
214 
215  // The scene graph is initially empty.
216  EXPECT_THAT(fake_session().SceneGraph(), IsEmptySceneGraph());
217 
218  // Create entity node for testing; no creation commands have been processed
219  // yet, so the session's view of the scene graph is empty.
220  std::optional<scenic::EntityNode> node(&session);
221  session.Flush(); // Bypass local command caching.
222  EXPECT_EQ(fake_session().command_queue().size(), 0u);
223  EXPECT_THAT(fake_session().SceneGraph(), IsEmptySceneGraph());
224 
225  // Pump the loop; the initial creation command should be enqueued but still
226  // not processed yet, so the session's view of the scene graph is empty.
227  loop().RunUntilIdle();
228  EXPECT_GT(fake_session().command_queue().size(), 0u);
229  EXPECT_THAT(fake_session().SceneGraph(), IsEmptySceneGraph());
230 
231  // Present initial scene graph. The `Present` hasn't been processed yet, so
232  // the session's view of the scene graph is still empty.
233  session.Present2(0u, 0u, [](auto...) {});
234  EXPECT_GT(fake_session().command_queue().size(), 0u);
235  EXPECT_THAT(fake_session().SceneGraph(), IsEmptySceneGraph());
236 
237  // Pump the loop; the contents of the initial `Present` should be processed.
238  loop().RunUntilIdle();
239  EXPECT_EQ(fake_session().command_queue().size(), 0u);
240  EXPECT_THAT(fake_session().SceneGraph(),
241  IsEntityNodeSceneGraph("", node->id()));
242 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
const FlutterSemanticsNode * node
Definition: fl_view.cc:83
int32_t id
The unique identifier for this node.
Definition: embedder.h:798

◆ TEST_F() [24/57]

flutter_runner::testing::TEST_F ( FakeSessionTest  ,
SimpleResourceLifecycle   
)

Definition at line 244 of file fake_session_unittests.cc.

References flutter_runner::testing::FakeSessionTest::CreateSession(), flutter_runner::testing::FakeSessionTest::fake_session(), flutter_runner::testing::FakeSessionTest::loop(), and node.

244  {
245  scenic::Session session = CreateSession();
246 
247  // The scene graph is initially empty.
248  EXPECT_THAT(fake_session().SceneGraph(), IsEmptySceneGraph());
249 
250  // Present an initial entity node, pumping the loop to process commands.
251  std::optional<scenic::EntityNode> node(&session);
252  session.Present2(0u, 0u, [](auto...) {});
253  loop().RunUntilIdle();
254  EXPECT_THAT(fake_session().SceneGraph(),
255  IsEntityNodeSceneGraph("", node->id()));
256 
257  // Present a simple property update on the test entity node.
258  const std::string kNodeLabel = "EntityNode";
259  node->SetLabel(kNodeLabel);
260  session.Present2(0u, 0u, [](auto...) {});
261  loop().RunUntilIdle();
262  EXPECT_THAT(fake_session().SceneGraph(),
263  IsEntityNodeSceneGraph(kNodeLabel, node->id()));
264 
265  // Present the destruction of the entity node.
266  node.reset();
267  session.Present2(0u, 0u, [](auto...) {});
268  loop().RunUntilIdle();
269  EXPECT_THAT(fake_session().SceneGraph(), IsEmptySceneGraph());
270 }
const FlutterSemanticsNode * node
Definition: fl_view.cc:83
int32_t id
The unique identifier for this node.
Definition: embedder.h:798

◆ TEST_F() [25/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Coordinates_DownEventClampedToView   
)

Definition at line 248 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::TouchEventBuilder::AddSample(), flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), kIxnOne, flutter_runner::testing::TouchEventBuilder::New(), flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

248  {
249  const float kSmallDiscrepancy = -0.00003f;
250 
251  std::optional<std::vector<flutter::PointerData>> pointers;
252  pointer_delegate_->WatchLoop(
253  [&pointers](std::vector<flutter::PointerData> events) {
254  pointers = std::move(events);
255  });
256  RunLoopUntilIdle(); // Server gets watch call.
257 
258  std::vector<fup_TouchEvent> events =
259  TouchEventBuilder::New()
260  .AddTime(1111000u)
261  .AddViewParameters(kRect, kRect, kIdentity)
262  .AddSample(kIxnOne, fup_EventPhase::ADD, {10.f, kSmallDiscrepancy})
263  .AddResult(
264  {.interaction = kIxnOne, .status = fup_TouchIxnStatus::GRANTED})
265  .BuildAsVector();
266  touch_source_->ScheduleCallback(std::move(events));
267  RunLoopUntilIdle();
268 
269  ASSERT_TRUE(pointers.has_value());
270  ASSERT_EQ(pointers->size(), 2u);
271 
272  const auto& add_event = (*pointers)[0];
273  EXPECT_FLOAT_EQ(add_event.physical_x, 10.f);
274  EXPECT_FLOAT_EQ(add_event.physical_y, kSmallDiscrepancy);
275 
276  const auto& down_event = (*pointers)[1];
277  EXPECT_FLOAT_EQ(down_event.physical_x, 10.f);
278  EXPECT_EQ(down_event.physical_y, 0.f);
279 }
constexpr fup_TouchIxnId kIxnOne
constexpr std::array< std::array< float, 2 >, 2 > kRect
constexpr std::array< float, 9 > kIdentity

◆ TEST_F() [26/57]

flutter_runner::testing::TEST_F ( FakeSessionTest  ,
ResourceReferenceCounting   
)

Definition at line 272 of file fake_session_unittests.cc.

References flutter_runner::testing::FakeSessionTest::CreateSession(), flutter_runner::testing::FakeSessionTest::fake_session(), kInvalidFakeResourceId, flutter_runner::testing::FakeSessionTest::loop(), and flutter_runner::testing::FakeSession::SceneGraph().

272  {
273  scenic::Session session = CreateSession();
274 
275  // Present a chain of 4 entity nodes for testing.
276  std::array<std::optional<scenic::EntityNode>, 4> nodes{
277  std::optional<scenic::EntityNode>(&session),
278  std::optional<scenic::EntityNode>(&session),
279  std::optional<scenic::EntityNode>(&session),
280  std::optional<scenic::EntityNode>(&session)};
281  const std::string kNodeLabel = "EntityNode";
282  for (size_t i = 0; i < 4; i++) {
283  nodes[i]->SetLabel(kNodeLabel + std::string(1, '0' + i));
284  if (i < 3) {
285  nodes[i]->AddChild(*nodes[i + 1]);
286  }
287  }
288  session.Present2(0u, 0u, [](auto...) {});
289  loop().RunUntilIdle();
290  {
291  auto scene_graph = fake_session().SceneGraph();
292  EXPECT_EQ(scene_graph.root_view_id, kInvalidFakeResourceId);
293  EXPECT_EQ(scene_graph.buffer_collection_map.size(), 0u);
294  EXPECT_EQ(scene_graph.resource_map.size(), 4u);
295  EXPECT_EQ(scene_graph.label_map.size(), 4u);
296  for (size_t i = 0; i < 4; i++) {
297  const std::string node_i_label = kNodeLabel + std::string(1, '0' + i);
298  ASSERT_EQ(scene_graph.resource_map.count(nodes[i]->id()), 1u);
299  ASSERT_EQ(scene_graph.label_map.count(node_i_label), 1u);
300 
301  const auto node_i = scene_graph.resource_map[nodes[i]->id()];
302  const auto node_i_label_resources = scene_graph.label_map[node_i_label];
303  EXPECT_EQ(node_i_label_resources.size(), 1u);
304  EXPECT_FALSE(node_i_label_resources[0].expired());
305  EXPECT_EQ(node_i_label_resources[0].lock(), node_i);
306  }
307 
308  EXPECT_THAT(
309  scene_graph.resource_map[nodes[0]->id()],
310  Pointee(IsEntityNode(
311  nodes[0]->id(), kNodeLabel + std::string(1, '0'),
312  ElementsAre(Pointee(IsEntityNode(
313  nodes[1]->id(), kNodeLabel + std::string(1, '1'),
314  ElementsAre(Pointee(IsEntityNode(
315  nodes[2]->id(), kNodeLabel + std::string(1, '2'),
316  ElementsAre(Pointee(IsEntityNode(
317  nodes[3]->id(), kNodeLabel + std::string(1, '3'),
318  IsEmpty()))))))))))));
319  }
320 
321  // Destroy node #0. It should be dropped immediately since it has no parent.
322  nodes[0].reset();
323  session.Present2(0u, 0u, [](auto...) {});
324  loop().RunUntilIdle();
325  {
326  auto scene_graph = fake_session().SceneGraph();
327  EXPECT_EQ(scene_graph.root_view_id, kInvalidFakeResourceId);
328  EXPECT_EQ(scene_graph.buffer_collection_map.size(), 0u);
329  EXPECT_EQ(scene_graph.resource_map.size(), 3u);
330  EXPECT_EQ(scene_graph.label_map.size(), 3u);
331  for (size_t i = 1; i < 4; i++) {
332  const std::string node_i_label = kNodeLabel + std::string(1, '0' + i);
333  ASSERT_EQ(scene_graph.resource_map.count(nodes[i]->id()), 1u);
334  ASSERT_EQ(scene_graph.label_map.count(node_i_label), 1u);
335 
336  const auto node_i = scene_graph.resource_map[nodes[i]->id()];
337  const auto node_i_label_resources = scene_graph.label_map[node_i_label];
338  EXPECT_EQ(node_i_label_resources.size(), 1u);
339  EXPECT_FALSE(node_i_label_resources[0].expired());
340  EXPECT_EQ(node_i_label_resources[0].lock(), node_i);
341  }
342 
343  EXPECT_EQ(scene_graph.resource_map.count(nodes[0]->id()), 0u);
344  EXPECT_THAT(scene_graph.resource_map[nodes[1]->id()],
345  Pointee(IsEntityNode(
346  nodes[1]->id(), kNodeLabel + std::string(1, '1'),
347  ElementsAre(Pointee(IsEntityNode(
348  nodes[2]->id(), kNodeLabel + std::string(1, '2'),
349  ElementsAre(Pointee(IsEntityNode(
350  nodes[3]->id(), kNodeLabel + std::string(1, '3'),
351  IsEmpty())))))))));
352  }
353 
354  // Destroy node #2. It should still exist in the tree and the labels map
355  // because it has a parent, but it is removed from the resource map.
356  nodes[2].reset();
357  session.Present2(0u, 0u, [](auto...) {});
358  loop().RunUntilIdle();
359  {
360  auto scene_graph = fake_session().SceneGraph();
361  EXPECT_EQ(scene_graph.root_view_id, kInvalidFakeResourceId);
362  EXPECT_EQ(scene_graph.buffer_collection_map.size(), 0u);
363  EXPECT_EQ(scene_graph.resource_map.size(), 2u);
364  EXPECT_EQ(scene_graph.label_map.size(), 3u);
365  for (size_t i = 1; i < 4; i++) {
366  const std::string node_i_label = kNodeLabel + std::string(1, '0' + i);
367  ASSERT_EQ(scene_graph.label_map.count(node_i_label), 1u);
368  ASSERT_EQ(scene_graph.resource_map.count(nodes[i]->id()),
369  i != 2 ? 1u : 0u);
370 
371  const auto node_i_label_resources = scene_graph.label_map[node_i_label];
372  EXPECT_EQ(node_i_label_resources.size(), 1u);
373  EXPECT_FALSE(node_i_label_resources[0].expired());
374 
375  if (i != 2) {
376  const auto node_i = scene_graph.resource_map[nodes[i]->id()];
377  EXPECT_EQ(node_i_label_resources[0].lock(), node_i);
378  } else {
379  EXPECT_EQ(scene_graph.resource_map.count(nodes[i]->id()), 0u);
380  }
381  }
382 
383  EXPECT_THAT(scene_graph.resource_map[nodes[1]->id()],
384  Pointee(IsEntityNode(
385  nodes[1]->id(), kNodeLabel + std::string(1, '1'),
386  ElementsAre(Pointee(IsEntityNode(
387  nodes[2]->id(), kNodeLabel + std::string(1, '2'),
388  ElementsAre(Pointee(IsEntityNode(
389  nodes[3]->id(), kNodeLabel + std::string(1, '3'),
390  IsEmpty())))))))));
391  }
392 
393  // Destroy node #3. It should still exist in the tree and the labels map
394  // because it has a grand-parent, but it is removed from the resource map.
395  nodes[3].reset();
396  session.Present2(0u, 0u, [](auto...) {});
397  loop().RunUntilIdle();
398  {
399  auto scene_graph = fake_session().SceneGraph();
400  EXPECT_EQ(scene_graph.root_view_id, kInvalidFakeResourceId);
401  EXPECT_EQ(scene_graph.buffer_collection_map.size(), 0u);
402  EXPECT_EQ(scene_graph.resource_map.size(), 1u);
403  EXPECT_EQ(scene_graph.label_map.size(), 3u);
404  for (size_t i = 1; i < 4; i++) {
405  const std::string node_i_label = kNodeLabel + std::string(1, '0' + i);
406  ASSERT_EQ(scene_graph.label_map.count(node_i_label), 1u);
407  ASSERT_EQ(scene_graph.resource_map.count(nodes[i]->id()),
408  i < 2 ? 1u : 0u);
409 
410  const auto node_i_label_resources = scene_graph.label_map[node_i_label];
411  EXPECT_EQ(node_i_label_resources.size(), 1u);
412  EXPECT_FALSE(node_i_label_resources[0].expired());
413 
414  if (i < 2) {
415  const auto node_i = scene_graph.resource_map[nodes[i]->id()];
416  EXPECT_EQ(node_i_label_resources[0].lock(), node_i);
417  } else {
418  EXPECT_EQ(scene_graph.resource_map.count(nodes[i]->id()), 0u);
419  }
420  }
421 
422  EXPECT_THAT(scene_graph.resource_map[nodes[1]->id()],
423  Pointee(IsEntityNode(
424  nodes[1]->id(), kNodeLabel + std::string(1, '1'),
425  ElementsAre(Pointee(IsEntityNode(
426  nodes[2]->id(), kNodeLabel + std::string(1, '2'),
427  ElementsAre(Pointee(IsEntityNode(
428  nodes[3]->id(), kNodeLabel + std::string(1, '3'),
429  IsEmpty())))))))));
430  }
431 }
constexpr FakeResourceId kInvalidFakeResourceId

◆ TEST_F() [27/57]

flutter_runner::testing::TEST_F ( GfxSessionConnectionTest  ,
AwaitVsyncBackpressure   
)

Definition at line 272 of file gfx_session_connection_unittests.cc.

References flutter_runner::testing::GfxSessionConnectionTest::fake_session(), flutter_runner::testing::FakeSession::FireOnFramePresentedEvent(), flutter::testing::GetCurrentTestName(), flutter_runner::testing::GfxSessionConnectionTest::GetInspectNode(), flutter_runner::kDefaultPresentationInterval, flutter_runner::testing::GfxSessionConnectionTest::loop(), flutter_runner::testing::FakeSession::SetPresent2Handler(), flutter_runner::testing::GfxSessionConnectionTest::TakeSessionHandle(), and fml::TimeDelta::Zero().

272  {
273  // Set up a callback which allows sensing of how many presents
274  // (`Present` calls) were handled.
275  size_t presents_called = 0u;
276  fake_session().SetPresent2Handler([&presents_called](auto...) -> auto {
277  presents_called++;
278  return FuturePresentationTimes{
279  .future_presentations = {},
280  .remaining_presents_in_flight_allowed = 1,
281  };
282  });
283 
284  // Set up a callback which allows sensing of how many vsync's
285  // (`OnFramePresented` events) were handled.
286  size_t vsyncs_handled = 0u;
287  on_frame_presented_event on_frame_presented = [&vsyncs_handled](auto...) {
288  vsyncs_handled++;
289  };
290 
291  // Create the GfxSessionConnection but don't pump the loop. No FIDL calls are
292  // completed yet.
293  flutter_runner::GfxSessionConnection session_connection(
294  GetCurrentTestName(), GetInspectNode(), TakeSessionHandle(),
295  []() { FAIL(); }, std::move(on_frame_presented), 1,
297  EXPECT_EQ(presents_called, 0u);
298  EXPECT_EQ(vsyncs_handled, 0u);
299 
300  // Pump the loop; `RequestPresentationTimes`, `Present`, and both of their
301  // callbacks are called.
302  loop().RunUntilIdle();
303  EXPECT_EQ(presents_called, 1u);
304  EXPECT_EQ(vsyncs_handled, 0u);
305 
306  // Simulate an AwaitVsync that comes before the first `OnFramePresented`
307  // event.
308  bool await_vsync_fired = false;
309  AwaitVsyncChecked(session_connection, await_vsync_fired,
311  EXPECT_FALSE(await_vsync_fired);
312 
313  // Fire the `OnFramePresented` event associated with the first `Present`, then
314  // pump the loop. The `OnFramePresented` event is resolved. The AwaitVsync
315  // callback is resolved.
316  fake_session().FireOnFramePresentedEvent(
317  MakeFramePresentedInfoForOnePresent(0, 0));
318  loop().RunUntilIdle();
319  EXPECT_TRUE(await_vsync_fired);
320  EXPECT_EQ(presents_called, 1u);
321  EXPECT_EQ(vsyncs_handled, 1u);
322 
323  // Simulate an AwaitVsync that comes before the second `Present`.
324  await_vsync_fired = false;
325  AwaitVsyncChecked(session_connection, await_vsync_fired,
328  EXPECT_TRUE(await_vsync_fired);
329 
330  // Call Present and Pump the loop; `Present` and its callback is called.
331  await_vsync_fired = false;
332  session_connection.Present();
333  loop().RunUntilIdle();
334  EXPECT_FALSE(await_vsync_fired);
335  EXPECT_EQ(presents_called, 2u);
336  EXPECT_EQ(vsyncs_handled, 1u);
337 
338  // Simulate an AwaitVsync that comes before the second `OnFramePresented`
339  // event.
340  await_vsync_fired = false;
341  AwaitVsyncChecked(session_connection, await_vsync_fired,
344  EXPECT_FALSE(await_vsync_fired);
345 
346  // Fire the `OnFramePresented` event associated with the second `Present`,
347  // then pump the loop. The `OnFramePresented` event is resolved.
348  fake_session().FireOnFramePresentedEvent(
349  MakeFramePresentedInfoForOnePresent(0, 0));
350  loop().RunUntilIdle();
351  EXPECT_TRUE(await_vsync_fired);
352  EXPECT_EQ(presents_called, 2u);
353  EXPECT_EQ(vsyncs_handled, 2u);
354 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13
std::function< void(fuchsia::scenic::scheduling::FramePresentedInfo)> on_frame_presented_event
static constexpr fml::TimeDelta kDefaultPresentationInterval

◆ TEST_F() [28/57]

flutter_runner::testing::TEST_F ( FlatlandConnectionTest  ,
PresentCreditExhaustion   
)

Definition at line 274 of file flatland_connection_unittests.cc.

References event, flutter_runner::testing::FlatlandConnectionTest::fake_flatland(), flutter::testing::GetCurrentTestName(), flutter_runner::testing::FlatlandConnectionTest::loop(), fml::TimePoint::Now(), flutter_runner::testing::FlatlandConnectionTest::OnNextFrameBegin(), flutter_runner::testing::FakeFlatland::SetPresentHandler(), flutter_runner::testing::FlatlandConnectionTest::TakeFlatlandHandle(), and fml::TimeDelta::Zero().

274  {
275  // Set up callbacks which allow sensing of how many presents were handled.
276  size_t num_presents_called = 0u;
277  size_t num_release_fences = 0u;
278  size_t num_acquire_fences = 0u;
279 
280  auto reset_test_counters = [&num_presents_called, &num_acquire_fences,
281  &num_release_fences]() {
282  num_presents_called = 0u;
283  num_release_fences = 0u;
284  num_acquire_fences = 0u;
285  };
286 
287  fake_flatland().SetPresentHandler(
288  [&num_presents_called, &num_acquire_fences, &num_release_fences](
289  fuchsia::ui::composition::PresentArgs present_args) {
290  num_presents_called++;
291  num_acquire_fences = present_args.acquire_fences().size();
292  num_release_fences = present_args.release_fences().size();
293  });
294 
295  // Create the FlatlandConnection but don't pump the loop. No FIDL calls are
296  // completed yet.
297  on_frame_presented_event on_frame_presented = [](auto...) {};
298  flutter_runner::FlatlandConnection flatland_connection(
299  GetCurrentTestName(), TakeFlatlandHandle(), []() { FAIL(); },
300  std::move(on_frame_presented), 1, fml::TimeDelta::Zero());
301  EXPECT_EQ(num_presents_called, 0u);
302 
303  // Pump the loop. Nothing is called.
304  loop().RunUntilIdle();
305  EXPECT_EQ(num_presents_called, 0u);
306 
307  // Simulate an AwaitVsync that comes after the first call.
308  flatland_connection.AwaitVsync([](fml::TimePoint, fml::TimePoint) {});
309  loop().RunUntilIdle();
310  EXPECT_EQ(num_presents_called, 0u);
311 
312  // This test uses a fire callback that triggers Present() with a single
313  // acquire and release fence in order to approximate the behavior of the real
314  // flutter fire callback and let us drive presents with ONFBs
315  auto fire_callback = [&flatland_connection](fml::TimePoint frame_start,
316  fml::TimePoint frame_end) {
317  zx::event acquire_fence;
318  zx::event::create(0, &acquire_fence);
319  zx::event release_fence;
320  zx::event::create(0, &release_fence);
321  flatland_connection.EnqueueAcquireFence(std::move(acquire_fence));
322  flatland_connection.EnqueueReleaseFence(std::move(release_fence));
323  flatland_connection.Present();
324  };
325 
326  // Call Await Vsync with a callback that triggers Present, but this should not
327  // present until ONFB is delivered below.
328  reset_test_counters();
329  flatland_connection.AwaitVsync(fire_callback);
330  loop().RunUntilIdle();
331  EXPECT_EQ(num_presents_called, 0u);
332 
333  // Call ONFB ands supply 0 present credits. This causes `Present` to be
334  // called and consumes the one and only present credit we start with.
335  OnNextFrameBegin(0);
336  loop().RunUntilIdle();
337  EXPECT_EQ(num_presents_called, 1u);
338  EXPECT_EQ(num_acquire_fences, 1u);
339  EXPECT_EQ(num_release_fences, 0u);
340 
341  // Do it again, but this time we should not get a present because the client
342  // has exhausted its present credits.
343  reset_test_counters();
344  flatland_connection.AwaitVsync(fire_callback);
345  OnNextFrameBegin(0);
346  loop().RunUntilIdle();
347  EXPECT_EQ(num_presents_called, 0u);
348 
349  // Supply a present credit but dont set a new fire callback. Fire callback
350  // from previous ONFB should fire and trigger a Present()
351  reset_test_counters();
352  OnNextFrameBegin(1);
353  loop().RunUntilIdle();
354  EXPECT_EQ(num_presents_called, 1u);
355  EXPECT_EQ(num_acquire_fences, 1u);
356  EXPECT_EQ(num_release_fences, 1u);
357 
358  // From here on we are testing handling of a race condition where a fire
359  // callback is fired but another ONFB arrives before the present from the
360  // first fire callback comes in, causing present_credits to be negative
361  // within Present().
362 
363  uint num_onfb = 5;
364  uint num_deferred_callbacks = 0;
365  // This callback will accumulate num_onfb+1 calls before firing all
366  // of their presents at once.
367  auto accumulating_fire_callback = [&](fml::TimePoint frame_start,
368  fml::TimePoint frame_end) {
369  num_deferred_callbacks++;
370  if (num_deferred_callbacks > num_onfb) {
372  for (uint i = 0; i < num_onfb + 1; i++) {
373  fire_callback(now, now);
374  num_deferred_callbacks--;
375  }
376  }
377  };
378 
379  reset_test_counters();
380  for (uint i = 0; i < num_onfb; i++) {
381  flatland_connection.AwaitVsync(accumulating_fire_callback);
382  // only supply a present credit on the first call. Since Presents are being
383  // deferred this credit will not be used up, but we need a credit to call
384  // the accumulating_fire_callback
385  OnNextFrameBegin(i == 0 ? 1 : 0);
386  loop().RunUntilIdle();
387  EXPECT_EQ(num_presents_called, 0u);
388  }
389 
390  // This is the num_onfb+1 call to accumulating_fire_callback which triggers
391  // all of the "racing" presents to fire. the first one should be fired,
392  // but the other num_onfb Presents should be deferred.
393  flatland_connection.AwaitVsync(accumulating_fire_callback);
394  OnNextFrameBegin(0);
395  loop().RunUntilIdle();
396  EXPECT_EQ(num_presents_called, 1u);
397  EXPECT_EQ(num_acquire_fences, 1u);
398  EXPECT_EQ(num_release_fences, 1u);
399 
400  // Supply a present credit, but pass an empty lambda to AwaitVsync so
401  // that it doesnt call Present(). Should get a deferred present with
402  // all the accumulate acuire fences
403  reset_test_counters();
404  flatland_connection.AwaitVsync([](fml::TimePoint, fml::TimePoint) {});
405  OnNextFrameBegin(1);
406  loop().RunUntilIdle();
407  EXPECT_EQ(num_presents_called, 1u);
408  EXPECT_EQ(num_acquire_fences, num_onfb);
409  EXPECT_EQ(num_release_fences, 1u);
410 
411  // Pump another frame to check that release fences accumulate as expected
412  reset_test_counters();
413  flatland_connection.AwaitVsync(fire_callback);
414  OnNextFrameBegin(1);
415  loop().RunUntilIdle();
416  EXPECT_EQ(num_presents_called, 1u);
417  EXPECT_EQ(num_acquire_fences, 1u);
418  EXPECT_EQ(num_release_fences, num_onfb);
419 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13
FlKeyEvent * event
std::function< void(fuchsia::scenic::scheduling::FramePresentedInfo)> on_frame_presented_event
static TimePoint Now()
Definition: time_point.cc:39

◆ TEST_F() [29/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Protocol_FirstResponseIsEmpty   
)

Definition at line 281 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

281  {
282  bool called = false;
283  pointer_delegate_->WatchLoop(
284  [&called](std::vector<flutter::PointerData> events) { called = true; });
285  RunLoopUntilIdle(); // Server gets Watch call.
286 
287  EXPECT_FALSE(called); // No events yet received to forward to client.
288  // Server sees an initial "response" from client, which is empty, by contract.
289  const auto responses = touch_source_->UploadedResponses();
290  ASSERT_TRUE(responses.has_value());
291  ASSERT_EQ(responses->size(), 0u);
292 }

◆ TEST_F() [30/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Protocol_ResponseMatchesEarlierEvents   
)

Definition at line 294 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::TouchEventBuilder::AddSample(), flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), flutter::testing::Build(), flutter_runner::testing::TouchEventBuilder::BuildAsVector(), flutter_runner::testing::TouchEventBuilder::New(), flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

294  {
295  std::optional<std::vector<flutter::PointerData>> pointers;
296  pointer_delegate_->WatchLoop(
297  [&pointers](std::vector<flutter::PointerData> events) {
298  pointers = std::move(events);
299  });
300  RunLoopUntilIdle(); // Server gets watch call.
301 
302  // Fuchsia view parameter only. Empty response.
303  std::vector<fup_TouchEvent> events =
304  TouchEventBuilder::New()
305  .AddTime(1111000u)
306  .AddViewParameters(kRect, kRect, kIdentity)
307  .BuildAsVector();
308 
309  // Fuchsia ptr 1 ADD sample. Yes response.
310  fup_TouchEvent e1 =
311  TouchEventBuilder::New()
312  .AddTime(1111000u)
313  .AddViewParameters(kRect, kRect, kIdentity)
314  .AddSample({.device_id = 0u, .pointer_id = 1u, .interaction_id = 3u},
315  fup_EventPhase::ADD, {10.f, 10.f})
316  .Build();
317  events.emplace_back(std::move(e1));
318 
319  // Fuchsia ptr 2 ADD sample. Yes response.
320  fup_TouchEvent e2 =
321  TouchEventBuilder::New()
322  .AddTime(1111000u)
323  .AddSample({.device_id = 0u, .pointer_id = 2u, .interaction_id = 3u},
324  fup_EventPhase::ADD, {5.f, 5.f})
325  .Build();
326  events.emplace_back(std::move(e2));
327 
328  // Fuchsia ptr 3 ADD sample. Yes response.
329  fup_TouchEvent e3 =
330  TouchEventBuilder::New()
331  .AddTime(1111000u)
332  .AddSample({.device_id = 0u, .pointer_id = 3u, .interaction_id = 3u},
333  fup_EventPhase::ADD, {1.f, 1.f})
334  .Build();
335  events.emplace_back(std::move(e3));
336  touch_source_->ScheduleCallback(std::move(events));
337  RunLoopUntilIdle();
338 
339  const auto responses = touch_source_->UploadedResponses();
340  ASSERT_TRUE(responses.has_value());
341  ASSERT_EQ(responses.value().size(), 4u);
342  // Event 0 did not carry a sample, so no response.
343  EXPECT_FALSE(responses.value()[0].has_response_type());
344  // Events 1-3 had a sample, must have a response.
345  EXPECT_TRUE(responses.value()[1].has_response_type());
346  EXPECT_EQ(responses.value()[1].response_type(),
347  fup_TouchResponseType::YES_PRIORITIZE);
348  EXPECT_TRUE(responses.value()[2].has_response_type());
349  EXPECT_EQ(responses.value()[2].response_type(),
350  fup_TouchResponseType::YES_PRIORITIZE);
351  EXPECT_TRUE(responses.value()[3].has_response_type());
352  EXPECT_EQ(responses.value()[3].response_type(),
353  fup_TouchResponseType::YES_PRIORITIZE);
354 }
constexpr std::array< std::array< float, 2 >, 2 > kRect
static sk_sp< DisplayList > Build(size_t g_index, size_t v_index)
constexpr std::array< float, 9 > kIdentity
fuchsia::ui::pointer::TouchEvent fup_TouchEvent

◆ TEST_F() [31/57]

flutter_runner::testing::TEST_F ( GfxSessionConnectionTest  ,
PresentBackpressure   
)

Definition at line 356 of file gfx_session_connection_unittests.cc.

References flutter_runner::testing::GfxSessionConnectionTest::fake_session(), flutter_runner::testing::FakeSession::FireOnFramePresentedEvent(), flutter::testing::GetCurrentTestName(), flutter_runner::testing::GfxSessionConnectionTest::GetInspectNode(), flutter_runner::testing::GfxSessionConnectionTest::loop(), flutter_runner::testing::FakeSession::SetPresent2Handler(), flutter_runner::testing::GfxSessionConnectionTest::TakeSessionHandle(), and fml::TimeDelta::Zero().

356  {
357  // Set up a callback which allows sensing of how many presents
358  // (`Present` calls) were handled.
359  size_t presents_called = 0u;
360  fake_session().SetPresent2Handler([&presents_called](auto...) -> auto {
361  presents_called++;
362  return FuturePresentationTimes{
363  .future_presentations = {},
364  .remaining_presents_in_flight_allowed = 1,
365  };
366  });
367 
368  // Set up a callback which allows sensing of how many vsync's
369  // (`OnFramePresented` events) were handled.
370  size_t vsyncs_handled = 0u;
371  on_frame_presented_event on_frame_presented = [&vsyncs_handled](auto...) {
372  vsyncs_handled++;
373  };
374 
375  // Create the GfxSessionConnection but don't pump the loop. No FIDL calls are
376  // completed yet.
377  flutter_runner::GfxSessionConnection session_connection(
378  GetCurrentTestName(), GetInspectNode(), TakeSessionHandle(),
379  []() { FAIL(); }, std::move(on_frame_presented), 1,
381  EXPECT_EQ(presents_called, 0u);
382  EXPECT_EQ(vsyncs_handled, 0u);
383 
384  // Pump the loop; `RequestPresentationTimes`, `Present`, and both of their
385  // callbacks are called.
386  loop().RunUntilIdle();
387  EXPECT_EQ(presents_called, 1u);
388  EXPECT_EQ(vsyncs_handled, 0u);
389 
390  // Call Present and Pump the loop; `Present` is not called due to backpressue.
391  session_connection.Present();
392  loop().RunUntilIdle();
393  EXPECT_EQ(presents_called, 1u);
394  EXPECT_EQ(vsyncs_handled, 0u);
395 
396  // Call Present again and Pump the loop; `Present` is not called due to
397  // backpressue.
398  session_connection.Present();
399  loop().RunUntilIdle();
400  EXPECT_EQ(presents_called, 1u);
401  EXPECT_EQ(vsyncs_handled, 0u);
402 
403  // Fire the `OnFramePresented` event associated with the first `Present`, then
404  // pump the loop. The `OnFramePresented` event is resolved. The pending
405  // `Present` calls are resolved.
406  fake_session().FireOnFramePresentedEvent(
407  MakeFramePresentedInfoForOnePresent(0, 0));
408  loop().RunUntilIdle();
409  EXPECT_EQ(presents_called, 2u);
410  EXPECT_EQ(vsyncs_handled, 1u);
411 
412  // Call Present and Pump the loop; `Present` is not called due to
413  // backpressue.
414  session_connection.Present();
415  loop().RunUntilIdle();
416  EXPECT_EQ(presents_called, 2u);
417  EXPECT_EQ(vsyncs_handled, 1u);
418 
419  // Call Present again and Pump the loop; `Present` is not called due to
420  // backpressue.
421  session_connection.Present();
422  loop().RunUntilIdle();
423  EXPECT_EQ(presents_called, 2u);
424  EXPECT_EQ(vsyncs_handled, 1u);
425 
426  // Fire the `OnFramePresented` event associated with the second `Present`,
427  // then pump the loop. The `OnFramePresented` event is resolved. The pending
428  // `Present` calls are resolved.
429  fake_session().FireOnFramePresentedEvent(
430  MakeFramePresentedInfoForOnePresent(0, 0));
431  loop().RunUntilIdle();
432  EXPECT_EQ(presents_called, 3u);
433  EXPECT_EQ(vsyncs_handled, 2u);
434 
435  // Fire the `OnFramePresented` event associated with the third `Present`,
436  // then pump the loop. The `OnFramePresented` event is resolved. No pending
437  // `Present` calls exist, so none are resolved.
438  fake_session().FireOnFramePresentedEvent(
439  MakeFramePresentedInfoForOnePresent(0, 0));
440  loop().RunUntilIdle();
441  EXPECT_EQ(presents_called, 3u);
442  EXPECT_EQ(vsyncs_handled, 3u);
443 }
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13
std::function< void(fuchsia::scenic::scheduling::FramePresentedInfo)> on_frame_presented_event

◆ TEST_F() [32/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Protocol_LateGrant   
)

Definition at line 356 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::TouchEventBuilder::AddResult(), flutter_runner::testing::TouchEventBuilder::AddSample(), flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), flutter::PointerData::kAdd, flutter::PointerData::kDown, kIxnOne, flutter::PointerData::kMove, flutter_runner::testing::TouchEventBuilder::New(), flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

356  {
357  std::optional<std::vector<flutter::PointerData>> pointers;
358  pointer_delegate_->WatchLoop(
359  [&pointers](std::vector<flutter::PointerData> events) {
360  pointers = std::move(events);
361  });
362  RunLoopUntilIdle(); // Server gets watch call.
363 
364  // Fuchsia ADD, no grant result - buffer it.
365  std::vector<fup_TouchEvent> events =
366  TouchEventBuilder::New()
367  .AddTime(1111000u)
368  .AddViewParameters(kRect, kRect, kIdentity)
369  .AddSample(kIxnOne, fup_EventPhase::ADD, {10.f, 10.f})
370  .BuildAsVector();
371  touch_source_->ScheduleCallback(std::move(events));
372  RunLoopUntilIdle();
373 
374  ASSERT_TRUE(pointers.has_value());
375  EXPECT_EQ(pointers.value().size(), 0u);
376  pointers = {};
377 
378  // Fuchsia CHANGE, no grant result - buffer it.
379  events = TouchEventBuilder::New()
380  .AddTime(2222000u)
381  .AddSample(kIxnOne, fup_EventPhase::CHANGE, {10.f, 10.f})
382  .BuildAsVector();
383  touch_source_->ScheduleCallback(std::move(events));
384  RunLoopUntilIdle();
385 
386  ASSERT_TRUE(pointers.has_value());
387  EXPECT_EQ(pointers.value().size(), 0u);
388  pointers = {};
389 
390  // Fuchsia result: ownership granted. Buffered pointers released.
391  events = TouchEventBuilder::New()
392  .AddTime(3333000u)
393  .AddResult({kIxnOne, fup_TouchIxnStatus::GRANTED})
394  .BuildAsVector();
395  touch_source_->ScheduleCallback(std::move(events));
396  RunLoopUntilIdle();
397 
398  ASSERT_TRUE(pointers.has_value());
399  ASSERT_EQ(pointers.value().size(), 3u); // ADD - DOWN - MOVE
400  EXPECT_EQ(pointers.value()[0].change, flutter::PointerData::Change::kAdd);
401  EXPECT_EQ(pointers.value()[1].change, flutter::PointerData::Change::kDown);
402  EXPECT_EQ(pointers.value()[2].change, flutter::PointerData::Change::kMove);
403  pointers = {};
404 
405  // Fuchsia CHANGE, grant result - release immediately.
406  events = TouchEventBuilder::New()
407  .AddTime(/* in nanoseconds */ 4444000u)
408  .AddSample(kIxnOne, fup_EventPhase::CHANGE, {10.f, 10.f})
409  .BuildAsVector();
410  touch_source_->ScheduleCallback(std::move(events));
411  RunLoopUntilIdle();
412 
413  ASSERT_TRUE(pointers.has_value());
414  ASSERT_EQ(pointers.value().size(), 1u);
415  EXPECT_EQ(pointers.value()[0].change, flutter::PointerData::Change::kMove);
416  EXPECT_EQ(pointers.value()[0].time_stamp, /* in microseconds */ 4444u);
417  pointers = {};
418 }
constexpr fup_TouchIxnId kIxnOne
constexpr std::array< std::array< float, 2 >, 2 > kRect
constexpr std::array< float, 9 > kIdentity

◆ TEST_F() [33/57]

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

Definition at line 420 of file platform_view_unittest.cc.

References flutter_runner::testing::FakePlatformMessageResponse::Create(), and platform_view.

420  {
421  MockPlatformViewDelegate delegate;
422  flutter::TaskRunners task_runners =
423  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
424 
425  FakeViewRefFocused vrf;
426  fidl::BindingSet<fuchsia::ui::views::ViewRefFocused> vrf_bindings;
427  auto vrf_handle = vrf_bindings.AddBinding(&vrf);
428 
430  PlatformViewBuilder(delegate, std::move(task_runners))
431  .SetViewRefFocused(std::move(vrf_handle))
432  .Build();
433 
434  // Cast platform_view to its base view so we can have access to the public
435  // "HandlePlatformMessage" function.
436  auto base_view = static_cast<flutter::PlatformView*>(&platform_view);
437  EXPECT_TRUE(base_view);
438 
439  // Invalid platform channel.
440  auto response1 = FakePlatformMessageResponse::Create();
441  base_view->HandlePlatformMessage(response1->WithMessage(
442  "flutter/invalid", "{\"method\":\"Invalid.invalidMethod\"}"));
443 
444  // Invalid json.
445  auto response2 = FakePlatformMessageResponse::Create();
446  base_view->HandlePlatformMessage(
447  response2->WithMessage("flutter/platform_views", "{Invalid JSON"));
448 
449  // Invalid method.
450  auto response3 = FakePlatformMessageResponse::Create();
451  base_view->HandlePlatformMessage(response3->WithMessage(
452  "flutter/platform_views", "{\"method\":\"View.focus.invalidMethod\"}"));
453 
454  // Missing arguments.
455  auto response4 = FakePlatformMessageResponse::Create();
456  base_view->HandlePlatformMessage(response4->WithMessage(
457  "flutter/platform_views", "{\"method\":\"View.update\"}"));
458  auto response5 = FakePlatformMessageResponse::Create();
459  base_view->HandlePlatformMessage(
460  response5->WithMessage("flutter/platform_views",
461  "{\"method\":\"View.update\",\"args\":{"
462  "\"irrelevantField\":\"irrelevantValue\"}}"));
463 
464  // Wrong argument types.
465  auto response6 = FakePlatformMessageResponse::Create();
466  base_view->HandlePlatformMessage(response6->WithMessage(
467  "flutter/platform_views",
468  "{\"method\":\"View.update\",\"args\":{\"viewId\":false,\"hitTestable\":"
469  "123,\"focusable\":\"yes\"}}"));
470 
471  // Run the event loop and check our responses.
472  RunLoopUntilIdle();
473  response1->ExpectCompleted("");
474  response2->ExpectCompleted("");
475  response3->ExpectCompleted("");
476  response4->ExpectCompleted("");
477  response5->ExpectCompleted("");
478  response6->ExpectCompleted("");
479 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:47

◆ TEST_F() [34/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Protocol_LateGrantCombo   
)

Definition at line 420 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::TouchEventBuilder::AddSample(), flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), flutter::PointerData::kAdd, flutter::PointerData::kDown, kIxnOne, flutter::PointerData::kMove, flutter_runner::testing::TouchEventBuilder::New(), flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

420  {
421  std::optional<std::vector<flutter::PointerData>> pointers;
422  pointer_delegate_->WatchLoop(
423  [&pointers](std::vector<flutter::PointerData> events) {
424  pointers = std::move(events);
425  });
426  RunLoopUntilIdle(); // Server gets watch call.
427 
428  // Fuchsia ADD, no grant result - buffer it.
429  std::vector<fup_TouchEvent> events =
430  TouchEventBuilder::New()
431  .AddTime(1111000u)
432  .AddViewParameters(kRect, kRect, kIdentity)
433  .AddSample(kIxnOne, fup_EventPhase::ADD, {10.f, 10.f})
434  .BuildAsVector();
435  touch_source_->ScheduleCallback(std::move(events));
436  RunLoopUntilIdle();
437 
438  ASSERT_TRUE(pointers.has_value());
439  EXPECT_EQ(pointers.value().size(), 0u);
440  pointers = {};
441 
442  // Fuchsia CHANGE, no grant result - buffer it.
443  events = TouchEventBuilder::New()
444  .AddTime(2222000u)
445  .AddSample(kIxnOne, fup_EventPhase::CHANGE, {10.f, 10.f})
446  .BuildAsVector();
447  touch_source_->ScheduleCallback(std::move(events));
448  RunLoopUntilIdle();
449 
450  ASSERT_TRUE(pointers.has_value());
451  EXPECT_EQ(pointers.value().size(), 0u);
452  pointers = {};
453 
454  // Fuchsia CHANGE, with grant result - release buffered events.
455  events = TouchEventBuilder::New()
456  .AddTime(3333000u)
457  .AddSample(kIxnOne, fup_EventPhase::CHANGE, {10.f, 10.f})
458  .AddResult({kIxnOne, fup_TouchIxnStatus::GRANTED})
459  .BuildAsVector();
460  touch_source_->ScheduleCallback(std::move(events));
461  RunLoopUntilIdle();
462 
463  ASSERT_TRUE(pointers.has_value());
464  ASSERT_EQ(pointers.value().size(), 4u); // ADD - DOWN - MOVE - MOVE
465  EXPECT_EQ(pointers.value()[0].change, flutter::PointerData::Change::kAdd);
466  EXPECT_EQ(pointers.value()[0].time_stamp, 1111u);
467  EXPECT_EQ(pointers.value()[1].change, flutter::PointerData::Change::kDown);
468  EXPECT_EQ(pointers.value()[1].time_stamp, 1111u);
469  EXPECT_EQ(pointers.value()[2].change, flutter::PointerData::Change::kMove);
470  EXPECT_EQ(pointers.value()[2].time_stamp, 2222u);
471  EXPECT_EQ(pointers.value()[3].change, flutter::PointerData::Change::kMove);
472  EXPECT_EQ(pointers.value()[3].time_stamp, 3333u);
473  pointers = {};
474 }
constexpr fup_TouchIxnId kIxnOne
constexpr std::array< std::array< float, 2 >, 2 > kRect
constexpr std::array< float, 9 > kIdentity

◆ TEST_F() [35/57]

flutter_runner::testing::TEST_F ( FakeSessionTest  ,
BasicSceneGraph   
)

Definition at line 433 of file fake_session_unittests.cc.

References flutter_runner::testing::FakeSessionTest::CreateSession(), flutter_runner::testing::FakeSessionTest::fake_session(), flutter::testing::GetCurrentTestName(), and flutter_runner::testing::FakeSessionTest::loop().

433  {
434  scenic::Session session = CreateSession();
435 
436  // The scene graph is initially empty.
437  EXPECT_THAT(fake_session().SceneGraph(), IsEmptySceneGraph());
438 
439  // Create and present initial scene graph.
440  const std::string kViewDebugString = GetCurrentTestName();
441  const std::string kNodeLabel = "ChildNode";
442  fuchsia::ui::views::ViewRef view_ref;
443  auto [view_token, view_holder_token] = scenic::ViewTokenPair::New();
444  auto view_ref_pair = scenic::ViewRefPair::New();
445  view_ref_pair.view_ref.Clone(&view_ref);
446  scenic::View root_view(&session, std::move(view_token),
447  std::move(view_ref_pair.control_ref),
448  std::move(view_ref_pair.view_ref), kViewDebugString);
449  scenic::EntityNode child_node(&session);
450  child_node.SetLabel(kNodeLabel);
451  root_view.AddChild(child_node);
452  session.Present2(0u, 0u, [](auto...) {});
453  loop().RunUntilIdle();
454  EXPECT_THAT(fake_session().SceneGraph(),
455  IsBasicSceneGraph(kViewDebugString, kNodeLabel,
456  GetPeerKoid(view_holder_token.value.get()),
457  GetPeerKoid(view_ref.reference.get()),
458  GetKoid(view_ref.reference.get())));
459 }
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13

◆ TEST_F() [36/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Protocol_EarlyGrant   
)

Definition at line 476 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::TouchEventBuilder::AddSample(), flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), flutter::PointerData::kAdd, flutter::PointerData::kDown, kIxnOne, flutter::PointerData::kMove, flutter_runner::testing::TouchEventBuilder::New(), flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

476  {
477  std::optional<std::vector<flutter::PointerData>> pointers;
478  pointer_delegate_->WatchLoop(
479  [&pointers](std::vector<flutter::PointerData> events) {
480  pointers = std::move(events);
481  });
482  RunLoopUntilIdle(); // Server gets watch call.
483 
484  // Fuchsia ADD, with grant result - release immediately.
485  std::vector<fup_TouchEvent> events =
486  TouchEventBuilder::New()
487  .AddTime(1111000u)
488  .AddViewParameters(kRect, kRect, kIdentity)
489  .AddSample(kIxnOne, fup_EventPhase::ADD, {10.f, 10.f})
490  .AddResult({kIxnOne, fup_TouchIxnStatus::GRANTED})
491  .BuildAsVector();
492  touch_source_->ScheduleCallback(std::move(events));
493  RunLoopUntilIdle();
494 
495  ASSERT_TRUE(pointers.has_value());
496  ASSERT_EQ(pointers.value().size(), 2u);
497  EXPECT_EQ(pointers.value()[0].change, flutter::PointerData::Change::kAdd);
498  EXPECT_EQ(pointers.value()[1].change, flutter::PointerData::Change::kDown);
499  pointers = {};
500 
501  // Fuchsia CHANGE, after grant result - release immediately.
502  events = TouchEventBuilder::New()
503  .AddTime(2222000u)
504  .AddSample(kIxnOne, fup_EventPhase::CHANGE, {10.f, 10.f})
505  .BuildAsVector();
506  touch_source_->ScheduleCallback(std::move(events));
507  RunLoopUntilIdle();
508 
509  ASSERT_TRUE(pointers.has_value());
510  ASSERT_EQ(pointers.value().size(), 1u);
511  EXPECT_EQ(pointers.value()[0].change, flutter::PointerData::Change::kMove);
512  pointers = {};
513 }
constexpr fup_TouchIxnId kIxnOne
constexpr std::array< std::array< float, 2 >, 2 > kRect
constexpr std::array< float, 9 > kIdentity

◆ TEST_F() [37/57]

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

Definition at line 483 of file platform_view_unittest.cc.

References flutter_runner::PlatformView::CreateExternalViewEmbedder(), flutter_runner::CreateFMLTaskRunner(), flutter::kRender, flutter::MakeDefaultContextOptions(), flutter::PlatformView::NotifyCreated(), and platform_view.

483  {
484  MockPlatformViewDelegate delegate;
485 
486  flutter::TaskRunners task_runners =
487  flutter::TaskRunners("test_runners", // label
488  nullptr, // platform
490  async_get_default_dispatcher()), // raster
491  nullptr, // ui
492  nullptr // io
493  );
494 
495  // Test create surface callback function.
496  sk_sp<GrDirectContext> gr_context = GrDirectContext::MakeMock(
497  nullptr,
499  std::shared_ptr<MockExternalViewEmbedder> external_view_embedder =
500  std::make_shared<MockExternalViewEmbedder>();
501  auto CreateSurfaceCallback = [&external_view_embedder, gr_context]() {
502  return std::make_unique<flutter_runner::Surface>(
503  "PlatformViewTest", external_view_embedder, gr_context.get());
504  };
505 
507  PlatformViewBuilder(delegate, std::move(task_runners))
508  .SetCreateSurfaceCallback(CreateSurfaceCallback)
509  .SetExternalViewEmbedder(external_view_embedder)
510  .Build();
511  platform_view.NotifyCreated();
512 
513  RunLoopUntilIdle();
514 
515  EXPECT_EQ(gr_context.get(), delegate.surface()->GetContext());
516  EXPECT_EQ(external_view_embedder.get(),
517  platform_view.CreateExternalViewEmbedder().get());
518 }
fml::RefPtr< fml::TaskRunner > CreateFMLTaskRunner(async_dispatcher_t *dispatcher)
std::unique_ptr< flutter::PlatformViewIOS > platform_view
void NotifyCreated()
Used by embedders to notify the shell that a platform view has been created. This notification is use...
std::shared_ptr< flutter::ExternalViewEmbedder > CreateExternalViewEmbedder() override
The context is used to render to a texture or renderbuffer.
GrContextOptions MakeDefaultContextOptions(ContextType type, std::optional< GrBackendApi > api)
Initializes GrContextOptions with values suitable for Flutter. The options can be further tweaked bef...

◆ TEST_F() [38/57]

flutter_runner::testing::TEST_F ( GfxExternalViewEmbedderTest  ,
RootScene   
)

Definition at line 513 of file gfx_external_view_embedder_unittests.cc.

References flutter::testing::GetCurrentTestName().

513  {
514  const std::string debug_name = GetCurrentTestName();
515  auto [view_token, view_holder_token] = scenic::ViewTokenPair::New();
516  auto view_ref_pair = scenic::ViewRefPair::New();
517  fuchsia::ui::views::ViewRef view_ref;
518  view_ref_pair.view_ref.Clone(&view_ref);
519 
520  GfxExternalViewEmbedder external_view_embedder(
521  debug_name, std::move(view_token), std::move(view_ref_pair),
522  session_connection(), fake_surface_producer());
523  EXPECT_EQ(fake_session().debug_name(), "");
524  EXPECT_THAT(fake_session().SceneGraph(), IsEmptySceneGraph());
525 
526  // Pump the loop; the contents of the initial `Present` should be processed.
527  loop().RunUntilIdle();
528  EXPECT_EQ(fake_session().debug_name(), debug_name);
529  ExpectRootSceneGraph(fake_session().SceneGraph(), debug_name,
530  view_holder_token, view_ref);
531 
532  // Fire the `OnFramePresented` event associated with the first `Present`, then
533  // pump the loop. The `OnFramePresented` event is resolved.
534  //
535  // The scene graph shouldn't change.
536  fake_session().FireOnFramePresentedEvent(
537  MakeFramePresentedInfoForOnePresent(0, 0));
538  loop().RunUntilIdle();
539  ExpectRootSceneGraph(fake_session().SceneGraph(), debug_name,
540  view_holder_token, view_ref);
541 }
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13

◆ TEST_F() [39/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Protocol_LateDeny   
)

Definition at line 515 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::TouchEventBuilder::AddResult(), flutter_runner::testing::TouchEventBuilder::AddSample(), flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), kIxnOne, flutter_runner::testing::TouchEventBuilder::New(), flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

515  {
516  std::optional<std::vector<flutter::PointerData>> pointers;
517  pointer_delegate_->WatchLoop(
518  [&pointers](std::vector<flutter::PointerData> events) {
519  pointers = std::move(events);
520  });
521  RunLoopUntilIdle(); // Server gets watch call.
522 
523  // Fuchsia ADD, no grant result - buffer it.
524  std::vector<fup_TouchEvent> events =
525  TouchEventBuilder::New()
526  .AddTime(1111000u)
527  .AddViewParameters(kRect, kRect, kIdentity)
528  .AddSample(kIxnOne, fup_EventPhase::ADD, {10.f, 10.f})
529  .BuildAsVector();
530  touch_source_->ScheduleCallback(std::move(events));
531  RunLoopUntilIdle();
532 
533  ASSERT_TRUE(pointers.has_value());
534  EXPECT_EQ(pointers.value().size(), 0u);
535  pointers = {};
536 
537  // Fuchsia CHANGE, no grant result - buffer it.
538  events = TouchEventBuilder::New()
539  .AddTime(2222000u)
540  .AddSample(kIxnOne, fup_EventPhase::CHANGE, {10.f, 10.f})
541  .BuildAsVector();
542  touch_source_->ScheduleCallback(std::move(events));
543  RunLoopUntilIdle();
544 
545  ASSERT_TRUE(pointers.has_value());
546  EXPECT_EQ(pointers.value().size(), 0u);
547  pointers = {};
548 
549  // Fuchsia result: ownership denied. Buffered pointers deleted.
550  events = TouchEventBuilder::New()
551  .AddTime(3333000u)
552  .AddResult({kIxnOne, fup_TouchIxnStatus::DENIED})
553  .BuildAsVector();
554  touch_source_->ScheduleCallback(std::move(events));
555  RunLoopUntilIdle();
556 
557  ASSERT_TRUE(pointers.has_value());
558  ASSERT_EQ(pointers.value().size(), 0u); // Do not release to client!
559  pointers = {};
560 }
constexpr fup_TouchIxnId kIxnOne
constexpr std::array< std::array< float, 2 >, 2 > kRect
constexpr std::array< float, 9 > kIdentity

◆ TEST_F() [40/57]

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

Definition at line 523 of file platform_view_unittest.cc.

References flutter::testing::Build(), and platform_view.

523  {
524  constexpr float invalid_pixel_ratio = -0.75f;
525  constexpr float valid_pixel_ratio = 0.75f;
526  constexpr float invalid_max_bound = -0.75f;
527  constexpr float valid_max_bound = 0.75f;
528 
529  MockPlatformViewDelegate delegate;
530  EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics());
531 
532  fuchsia::ui::scenic::SessionListenerPtr session_listener;
533  std::vector<fuchsia::ui::scenic::Event> events;
534  flutter::TaskRunners task_runners("test_runners", nullptr, nullptr, nullptr,
535  nullptr);
537  PlatformViewBuilder(delegate, std::move(task_runners))
538  .SetSessionListenerRequest(session_listener.NewRequest())
539  .Build();
540  RunLoopUntilIdle();
541  EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics());
542 
543  // Test updating with an invalid pixel ratio. The final metrics should be
544  // unchanged.
545  events.clear();
546  events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
547  fuchsia::ui::gfx::Event::WithMetrics(fuchsia::ui::gfx::MetricsEvent{
548  .node_id = 0,
549  .metrics =
550  fuchsia::ui::gfx::Metrics{
551  .scale_x = invalid_pixel_ratio,
552  .scale_y = 1.f,
553  .scale_z = 1.f,
554  },
555  })));
556  session_listener->OnScenicEvent(std::move(events));
557  RunLoopUntilIdle();
558  EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics());
559 
560  // Test updating with an invalid size. The final metrics should be unchanged.
561  events.clear();
562  events.emplace_back(
563  fuchsia::ui::scenic::Event::WithGfx(
564  fuchsia::ui::gfx::Event::WithViewPropertiesChanged(
565  fuchsia::ui::gfx::ViewPropertiesChangedEvent{
566  .view_id = 0,
567  .properties =
568  fuchsia::ui::gfx::ViewProperties{
569  .bounding_box =
570  fuchsia::ui::gfx::BoundingBox{
571  .min =
572  fuchsia::ui::gfx::vec3{
573  .x = 0.f,
574  .y = 0.f,
575  .z = 0.f,
576  },
577  .max =
578  fuchsia::ui::gfx::vec3{
579  .x = invalid_max_bound,
580  .y = invalid_max_bound,
581  .z = invalid_max_bound,
582  },
583  },
584  },
585  })));
586  session_listener->OnScenicEvent(std::move(events));
587  RunLoopUntilIdle();
588  EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics());
589 
590  // Test updating the size only. The final metrics should be unchanged until
591  // both pixel ratio and size are updated.
592  events.clear();
593  events.emplace_back(
594  fuchsia::ui::scenic::Event::WithGfx(
595  fuchsia::ui::gfx::Event::WithViewPropertiesChanged(
596  fuchsia::ui::gfx::ViewPropertiesChangedEvent{
597  .view_id = 0,
598  .properties =
599  fuchsia::ui::gfx::ViewProperties{
600  .bounding_box =
601  fuchsia::ui::gfx::BoundingBox{
602  .min =
603  fuchsia::ui::gfx::vec3{
604  .x = 0.f,
605  .y = 0.f,
606  .z = 0.f,
607  },
608  .max =
609  fuchsia::ui::gfx::vec3{
610  .x = valid_max_bound,
611  .y = valid_max_bound,
612  .z = valid_max_bound,
613  },
614  },
615  },
616  })));
617  session_listener->OnScenicEvent(std::move(events));
618  RunLoopUntilIdle();
619  EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics());
620 
621  // Test updating the pixel ratio only. The final metrics should change now.
622  events.clear();
623  events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
624  fuchsia::ui::gfx::Event::WithMetrics(fuchsia::ui::gfx::MetricsEvent{
625  .node_id = 0,
626  .metrics =
627  fuchsia::ui::gfx::Metrics{
628  .scale_x = valid_pixel_ratio,
629  .scale_y = 1.f,
630  .scale_z = 1.f,
631  },
632  })));
633  session_listener->OnScenicEvent(std::move(events));
634  RunLoopUntilIdle();
635  EXPECT_EQ(delegate.metrics(),
637  valid_pixel_ratio, valid_pixel_ratio * valid_max_bound,
638  valid_pixel_ratio * valid_max_bound, -1.0));
639 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view
static sk_sp< DisplayList > Build(size_t g_index, size_t v_index)

◆ TEST_F() [41/57]

flutter_runner::testing::TEST_F ( GfxExternalViewEmbedderTest  ,
SimpleScene   
)

Definition at line 543 of file gfx_external_view_embedder_unittests.cc.

References flutter::testing::GetCurrentTestName().

543  {
544  const std::string debug_name = GetCurrentTestName();
545  auto [view_token, view_holder_token] = scenic::ViewTokenPair::New();
546  auto view_ref_pair = scenic::ViewRefPair::New();
547  fuchsia::ui::views::ViewRef view_ref;
548  view_ref_pair.view_ref.Clone(&view_ref);
549 
550  // Create the `GfxExternalViewEmbedder` and pump the message loop until
551  // the initial scene graph is setup.
552  GfxExternalViewEmbedder external_view_embedder(
553  debug_name, std::move(view_token), std::move(view_ref_pair),
554  session_connection(), fake_surface_producer());
555  loop().RunUntilIdle();
556  fake_session().FireOnFramePresentedEvent(
557  MakeFramePresentedInfoForOnePresent(0, 0));
558  loop().RunUntilIdle();
559  ExpectRootSceneGraph(fake_session().SceneGraph(), debug_name,
560  view_holder_token, view_ref);
561 
562  // Draw the scene. The scene graph shouldn't change yet.
563  const SkISize frame_size = SkISize::Make(512, 512);
564  DrawSimpleFrame(
565  external_view_embedder, frame_size, 1.f, [](SkCanvas* canvas) {
566  const SkSize canvas_size = SkSize::Make(canvas->imageInfo().width(),
567  canvas->imageInfo().height());
568  SkPaint rect_paint;
569  rect_paint.setColor(SK_ColorGREEN);
570  canvas->translate(canvas_size.width() / 4.f,
571  canvas_size.height() / 2.f);
572  canvas->drawRect(SkRect::MakeWH(canvas_size.width() / 32.f,
573  canvas_size.height() / 32.f),
574  rect_paint);
575  });
576  ExpectRootSceneGraph(fake_session().SceneGraph(), debug_name,
577  view_holder_token, view_ref);
578 
579  // Pump the message loop. The scene updates should propogate to Scenic.
580  loop().RunUntilIdle();
581  std::vector<FakeCompositorLayer> compositor_layers =
582  ExtractLayersFromSceneGraph(fake_session().SceneGraph());
583  EXPECT_EQ(compositor_layers.size(), 1u);
584  ExpectImageCompositorLayer(compositor_layers[0], frame_size);
585 }
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13

◆ TEST_F() [42/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Protocol_LateDenyCombo   
)

Definition at line 562 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::TouchEventBuilder::AddSample(), flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), kIxnOne, flutter_runner::testing::TouchEventBuilder::New(), flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

562  {
563  std::optional<std::vector<flutter::PointerData>> pointers;
564  pointer_delegate_->WatchLoop(
565  [&pointers](std::vector<flutter::PointerData> events) {
566  pointers = std::move(events);
567  });
568  RunLoopUntilIdle(); // Server gets watch call.
569 
570  // Fuchsia ADD, no grant result - buffer it.
571  std::vector<fup_TouchEvent> events =
572  TouchEventBuilder::New()
573  .AddTime(1111000u)
574  .AddViewParameters(kRect, kRect, kIdentity)
575  .AddSample(kIxnOne, fup_EventPhase::ADD, {10.f, 10.f})
576  .BuildAsVector();
577  touch_source_->ScheduleCallback(std::move(events));
578  RunLoopUntilIdle();
579 
580  ASSERT_TRUE(pointers.has_value());
581  EXPECT_EQ(pointers.value().size(), 0u);
582  pointers = {};
583 
584  // Fuchsia CHANGE, no grant result - buffer it.
585  events = TouchEventBuilder::New()
586  .AddTime(2222000u)
587  .AddSample(kIxnOne, fup_EventPhase::CHANGE, {10.f, 10.f})
588  .BuildAsVector();
589  touch_source_->ScheduleCallback(std::move(events));
590  RunLoopUntilIdle();
591 
592  ASSERT_TRUE(pointers.has_value());
593  EXPECT_EQ(pointers.value().size(), 0u);
594  pointers = {};
595 
596  // Fuchsia result: ownership denied. Buffered pointers deleted.
597  events = TouchEventBuilder::New()
598  .AddTime(3333000u)
599  .AddSample(kIxnOne, fup_EventPhase::CANCEL, {10.f, 10.f})
600  .AddResult({kIxnOne, fup_TouchIxnStatus::DENIED})
601  .BuildAsVector();
602  touch_source_->ScheduleCallback(std::move(events));
603  RunLoopUntilIdle();
604 
605  ASSERT_TRUE(pointers.has_value());
606  ASSERT_EQ(pointers.value().size(), 0u); // Do not release to client!
607  pointers = {};
608 }
constexpr fup_TouchIxnId kIxnOne
constexpr std::array< std::array< float, 2 >, 2 > kRect
constexpr std::array< float, 9 > kIdentity

◆ TEST_F() [43/57]

flutter_runner::testing::TEST_F ( GfxExternalViewEmbedderTest  ,
SceneWithOneView   
)

Definition at line 587 of file gfx_external_view_embedder_unittests.cc.

References flutter_runner::GfxExternalViewEmbedder::CreateView(), flutter_runner::GfxExternalViewEmbedder::DestroyView(), and flutter::testing::GetCurrentTestName().

587  {
588  const std::string debug_name = GetCurrentTestName();
589  auto [view_token, view_holder_token] = scenic::ViewTokenPair::New();
590  auto view_ref_pair = scenic::ViewRefPair::New();
591  fuchsia::ui::views::ViewRef view_ref;
592  view_ref_pair.view_ref.Clone(&view_ref);
593 
594  // Create the `GfxExternalViewEmbedder` and pump the message loop until
595  // the initial scene graph is setup.
596  GfxExternalViewEmbedder external_view_embedder(
597  debug_name, std::move(view_token), std::move(view_ref_pair),
598  session_connection(), fake_surface_producer());
599  loop().RunUntilIdle();
600  fake_session().FireOnFramePresentedEvent(
601  MakeFramePresentedInfoForOnePresent(0, 0));
602  loop().RunUntilIdle();
603  ExpectRootSceneGraph(fake_session().SceneGraph(), debug_name,
604  view_holder_token, view_ref);
605 
606  // Create the view before drawing the scene.
607  const SkSize child_view_size = SkSize::Make(256.f, 512.f);
608  auto [child_view_token, child_view_holder_token] =
609  scenic::ViewTokenPair::New();
610  const uint32_t child_view_id = child_view_holder_token.value.get();
611  flutter::EmbeddedViewParams child_view_params(SkMatrix::I(), child_view_size,
613  external_view_embedder.CreateView(
614  child_view_id, []() {}, [](scenic::ResourceId) {});
615 
616  // Draw the scene. The scene graph shouldn't change yet.
617  const SkISize frame_size = SkISize::Make(512, 512);
618  DrawFrameWithView(
619  external_view_embedder, frame_size, 1.f, child_view_id, child_view_params,
620  [](SkCanvas* canvas) {
621  const SkSize canvas_size = SkSize::Make(canvas->imageInfo().width(),
622  canvas->imageInfo().height());
623  SkPaint rect_paint;
624  rect_paint.setColor(SK_ColorGREEN);
625  canvas->translate(canvas_size.width() / 4.f,
626  canvas_size.height() / 2.f);
627  canvas->drawRect(SkRect::MakeWH(canvas_size.width() / 32.f,
628  canvas_size.height() / 32.f),
629  rect_paint);
630  },
631  [](SkCanvas* canvas) {
632  const SkSize canvas_size = SkSize::Make(canvas->imageInfo().width(),
633  canvas->imageInfo().height());
634  SkPaint rect_paint;
635  rect_paint.setColor(SK_ColorRED);
636  canvas->translate(canvas_size.width() * 3.f / 4.f,
637  canvas_size.height() / 2.f);
638  canvas->drawRect(SkRect::MakeWH(canvas_size.width() / 32.f,
639  canvas_size.height() / 32.f),
640  rect_paint);
641  });
642  ExpectRootSceneGraph(fake_session().SceneGraph(), debug_name,
643  view_holder_token, view_ref);
644 
645  // Pump the message loop. The scene updates should propagate to Scenic.
646  loop().RunUntilIdle();
647  std::vector<FakeCompositorLayer> compositor_layers =
648  ExtractLayersFromSceneGraph(fake_session().SceneGraph());
649  EXPECT_EQ(compositor_layers.size(), 3u);
650  ExpectImageCompositorLayer(compositor_layers[0], frame_size);
651  ExpectViewCompositorLayer(compositor_layers[1], child_view_token,
652  child_view_params);
653  ExpectImageCompositorLayer(compositor_layers[2], frame_size);
654 
655  // Destroy the view.
656  external_view_embedder.DestroyView(child_view_id, [](scenic::ResourceId) {});
657 
658  // Pump the message loop.
659  loop().RunUntilIdle();
660 }
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13

◆ TEST_F() [44/57]

flutter_runner::testing::TEST_F ( PointerDelegateTest  ,
Protocol_PointersAreIndependent   
)

Definition at line 610 of file pointer_delegate_unittests.cc.

References flutter_runner::testing::TouchEventBuilder::AddResult(), flutter_runner::testing::TouchEventBuilder::AddSample(), flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), flutter::testing::Build(), flutter::PointerData::kAdd, flutter::PointerData::kDown, kIxnOne, flutter_runner::testing::TouchEventBuilder::New(), flutter_runner::testing::PointerDelegateTest::pointer_delegate_, flutter_runner::testing::PointerDelegateTest::RunLoopUntilIdle(), and flutter_runner::testing::PointerDelegateTest::touch_source_.

610  {
611  std::optional<std::vector<flutter::PointerData>> pointers;
612  pointer_delegate_->WatchLoop(
613  [&pointers](std::vector<flutter::PointerData> events) {
614  pointers = std::move(events);
615  });
616  RunLoopUntilIdle(); // Server gets watch call.
617 
618  constexpr fup_TouchIxnId kIxnTwo = {
619  .device_id = 1u, .pointer_id = 2u, .interaction_id = 2u};
620 
621  // Fuchsia ptr1 ADD and ptr2 ADD, no grant result for either - buffer them.
622  std::vector<fup_TouchEvent> events =
623  TouchEventBuilder::New()
624  .AddTime(1111000u)
625  .AddViewParameters(kRect, kRect, kIdentity)
626  .AddSample(kIxnOne, fup_EventPhase::ADD, {10.f, 10.f})
627  .BuildAsVector();
628  fup_TouchEvent ptr2 =
629  TouchEventBuilder::New()
630  .AddTime(1111000u)
631  .AddSample(kIxnTwo, fup_EventPhase::ADD, {15.f, 15.f})
632  .Build();
633  events.emplace_back(std::move(ptr2));
634  touch_source_->ScheduleCallback(std::move(events));
635  RunLoopUntilIdle();
636 
637  ASSERT_TRUE(pointers.has_value());
638  EXPECT_EQ(pointers.value().size(), 0u);
639  pointers = {};
640 
641  // Server grants win to pointer 2.
642  events = TouchEventBuilder::New()
643  .AddTime(2222000u)
644  .AddResult({kIxnTwo, fup_TouchIxnStatus::GRANTED})
645  .BuildAsVector();
646  touch_source_->ScheduleCallback(std::move(events));
647  RunLoopUntilIdle();
648 
649  // Note: Fuchsia's device and pointer IDs (both 32 bit) are coerced together
650  // to fit in Flutter's 64-bit device ID. However, Flutter's pointer_identifier
651  // is not set by platform runner code - PointerDataCaptureConverter (PDPC)
652  // sets it.
653  ASSERT_TRUE(pointers.has_value());
654  ASSERT_EQ(pointers.value().size(), 2u);
655  EXPECT_EQ(pointers.value()[0].pointer_identifier, 0); // reserved for PDPC
656  EXPECT_EQ(pointers.value()[0].device, (int64_t)((1ul << 32) | 2u));
657  EXPECT_EQ(pointers.value()[0].change, flutter::PointerData::Change::kAdd);
658  EXPECT_EQ(pointers.value()[1].pointer_identifier, 0); // reserved for PDPC
659  EXPECT_EQ(pointers.value()[1].device, (int64_t)((1ul << 32) | 2u));
660  EXPECT_EQ(pointers.value()[1].change, flutter::PointerData::Change::kDown);
661  pointers = {};
662 
663  // Server grants win to pointer 1.
664  events = TouchEventBuilder::New()
665  .AddTime(3333000u)
666  .AddResult({kIxnOne, fup_TouchIxnStatus::GRANTED})
667  .BuildAsVector();
668  touch_source_->ScheduleCallback(std::move(events));
669  RunLoopUntilIdle();
670 
671  ASSERT_TRUE(pointers.has_value());
672  ASSERT_EQ(pointers.value().size(), 2u);
673  EXPECT_EQ(pointers.value()[0].pointer_identifier, 0); // reserved for PDPC
674  EXPECT_EQ(pointers.value()[0].device, (int64_t)((1ul << 32) | 1u));
675  EXPECT_EQ(pointers.value()[0].change, flutter::PointerData::Change::kAdd);
676  EXPECT_EQ(pointers.value()[1].pointer_identifier, 0); // reserved for PDPC
677  EXPECT_EQ(pointers.value()[1].device, (int64_t)((1ul << 32) | 1u));
678  EXPECT_EQ(pointers.value()[1].change, flutter::PointerData::Change::kDown);
679  pointers = {};
680 }
constexpr fup_TouchIxnId kIxnOne
constexpr std::array< std::array< float, 2 >, 2 > kRect
static sk_sp< DisplayList > Build(size_t g_index, size_t v_index)
constexpr std::array< float, 9 > kIdentity
fuchsia::ui::pointer::TouchEvent fup_TouchEvent
fuchsia::ui::pointer::TouchInteractionId fup_TouchIxnId

◆ TEST_F() [45/57]

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

Definition at line 644 of file platform_view_unittest.cc.

References flutter::kAccessibleNavigation, and platform_view.

644  {
645  MockPlatformViewDelegate delegate;
646  flutter::TaskRunners task_runners =
647  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
648 
649  EXPECT_FALSE(delegate.semantics_enabled());
650  EXPECT_EQ(delegate.semantics_features(), 0);
651 
653  PlatformViewBuilder(delegate, std::move(task_runners)).Build();
654 
655  RunLoopUntilIdle();
656 
657  platform_view.SetSemanticsEnabled(true);
658 
659  EXPECT_TRUE(delegate.semantics_enabled());
660  EXPECT_EQ(delegate.semantics_features(),
661  static_cast<int32_t>(
663 
664  platform_view.SetSemanticsEnabled(false);
665 
666  EXPECT_FALSE(delegate.semantics_enabled());
667  EXPECT_EQ(delegate.semantics_features(), 0);
668 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view

◆ TEST_F() [46/57]

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

Definition at line 672 of file platform_view_unittest.cc.

References fml::MallocMapping::Copy(), and platform_view.

672  {
673  MockPlatformViewDelegate delegate;
674  flutter::TaskRunners task_runners =
675  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
676 
677  // Test wireframe callback function. If the message sent to the platform
678  // view was properly handled and parsed, this function should be called,
679  // setting |wireframe_enabled| to true.
680  bool wireframe_enabled = false;
681  auto EnableWireframeCallback = [&wireframe_enabled](bool should_enable) {
682  wireframe_enabled = should_enable;
683  };
684 
686  PlatformViewBuilder(delegate, std::move(task_runners))
687  .SetEnableWireframeCallback(EnableWireframeCallback)
688  .Build();
689 
690  // Cast platform_view to its base view so we can have access to the public
691  // "HandlePlatformMessage" function.
692  auto base_view = static_cast<flutter::PlatformView*>(&platform_view);
693  EXPECT_TRUE(base_view);
694 
695  // JSON for the message to be passed into the PlatformView.
696  const uint8_t txt[] =
697  "{"
698  " \"method\":\"View.enableWireframe\","
699  " \"args\": {"
700  " \"enable\":true"
701  " }"
702  "}";
703 
704  std::unique_ptr<flutter::PlatformMessage> message =
705  std::make_unique<flutter::PlatformMessage>(
706  "flutter/platform_views", fml::MallocMapping::Copy(txt, sizeof(txt)),
708  base_view->HandlePlatformMessage(std::move(message));
709 
710  RunLoopUntilIdle();
711 
712  EXPECT_TRUE(wireframe_enabled);
713 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:47
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:147

◆ TEST_F() [47/57]

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

Definition at line 717 of file platform_view_unittest.cc.

References fml::MallocMapping::Copy(), flutter_runner::CreateFMLTaskRunner(), and platform_view.

717  {
718  MockPlatformViewDelegate delegate;
719  flutter::TaskRunners task_runners =
720  flutter::TaskRunners("test_runners", // label
722  async_get_default_dispatcher()), // platform
723  nullptr, // raster
724  nullptr, // ui
725  nullptr // io
726  );
727 
728  // Test wireframe callback function. If the message sent to the platform
729  // view was properly handled and parsed, this function should be called,
730  // setting |wireframe_enabled| to true.
731  bool create_view_called = false;
732  auto CreateViewCallback = [&create_view_called](
733  int64_t view_id,
734  flutter_runner::ViewCallback on_view_created,
735  flutter_runner::GfxViewIdCallback on_view_bound,
736  bool hit_testable, bool focusable) {
737  create_view_called = true;
738  on_view_created();
739  on_view_bound(0);
740  };
741 
743  PlatformViewBuilder(delegate, std::move(task_runners))
744  .SetCreateViewCallback(CreateViewCallback)
745  .Build();
746 
747  // Cast platform_view to its base view so we can have access to the public
748  // "HandlePlatformMessage" function.
749  auto base_view = static_cast<flutter::PlatformView*>(&platform_view);
750  EXPECT_TRUE(base_view);
751 
752  // JSON for the message to be passed into the PlatformView.
753  const uint8_t txt[] =
754  "{"
755  " \"method\":\"View.create\","
756  " \"args\": {"
757  " \"viewId\":42,"
758  " \"hitTestable\":true,"
759  " \"focusable\":true"
760  " }"
761  "}";
762 
763  std::unique_ptr<flutter::PlatformMessage> message =
764  std::make_unique<flutter::PlatformMessage>(
765  "flutter/platform_views", fml::MallocMapping::Copy(txt, sizeof(txt)),
767  base_view->HandlePlatformMessage(std::move(message));
768 
769  RunLoopUntilIdle();
770 
771  EXPECT_TRUE(create_view_called);
772 }
fml::RefPtr< fml::TaskRunner > CreateFMLTaskRunner(async_dispatcher_t *dispatcher)
std::unique_ptr< flutter::PlatformViewIOS > platform_view
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:47
std::function< void()> ViewCallback
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:147
std::function< void(scenic::ResourceId)> GfxViewIdCallback

◆ TEST_F() [48/57]

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

Definition at line 776 of file platform_view_unittest.cc.

References fml::MallocMapping::Copy(), and platform_view.

776  {
777  MockPlatformViewDelegate delegate;
778  flutter::TaskRunners task_runners =
779  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
780 
781  std::optional<SkRect> occlusion_hint_for_test;
782  std::optional<bool> hit_testable_for_test;
783  std::optional<bool> focusable_for_test;
784  auto UpdateViewCallback = [&occlusion_hint_for_test, &hit_testable_for_test,
785  &focusable_for_test](
786  int64_t view_id, SkRect occlusion_hint,
787  bool hit_testable, bool focusable) {
788  occlusion_hint_for_test = occlusion_hint;
789  hit_testable_for_test = hit_testable;
790  focusable_for_test = focusable;
791  };
792 
794  PlatformViewBuilder(delegate, std::move(task_runners))
795  .SetUpdateViewCallback(UpdateViewCallback)
796  .Build();
797 
798  // Cast platform_view to its base view so we can have access to the public
799  // "HandlePlatformMessage" function.
800  auto base_view = static_cast<flutter::PlatformView*>(&platform_view);
801  EXPECT_TRUE(base_view);
802 
803  // Send a basic message.
804  const uint8_t json[] =
805  "{"
806  " \"method\":\"View.update\","
807  " \"args\": {"
808  " \"viewId\":42,"
809  " \"hitTestable\":true,"
810  " \"focusable\":true"
811  " }"
812  "}";
813  std::unique_ptr<flutter::PlatformMessage> message =
814  std::make_unique<flutter::PlatformMessage>(
815  "flutter/platform_views",
816  fml::MallocMapping::Copy(json, sizeof(json)),
818  base_view->HandlePlatformMessage(std::move(message));
819 
820  RunLoopUntilIdle();
821  ASSERT_TRUE(occlusion_hint_for_test.has_value());
822  ASSERT_TRUE(hit_testable_for_test.has_value());
823  ASSERT_TRUE(focusable_for_test.has_value());
824  EXPECT_EQ(occlusion_hint_for_test.value(), SkRect::MakeEmpty());
825  EXPECT_EQ(hit_testable_for_test.value(), true);
826  EXPECT_EQ(focusable_for_test.value(), true);
827 
828  // Reset for the next message.
829  occlusion_hint_for_test.reset();
830  hit_testable_for_test.reset();
831  focusable_for_test.reset();
832 
833  // Send another basic message.
834  const uint8_t json_false[] =
835  "{"
836  " \"method\":\"View.update\","
837  " \"args\": {"
838  " \"viewId\":42,"
839  " \"hitTestable\":false,"
840  " \"focusable\":false"
841  " }"
842  "}";
843  std::unique_ptr<flutter::PlatformMessage> message_false =
844  std::make_unique<flutter::PlatformMessage>(
845  "flutter/platform_views",
846  fml::MallocMapping::Copy(json_false, sizeof(json_false)),
848  base_view->HandlePlatformMessage(std::move(message_false));
849  RunLoopUntilIdle();
850  ASSERT_TRUE(occlusion_hint_for_test.has_value());
851  ASSERT_TRUE(hit_testable_for_test.has_value());
852  ASSERT_TRUE(focusable_for_test.has_value());
853  EXPECT_EQ(occlusion_hint_for_test.value(), SkRect::MakeEmpty());
854  EXPECT_EQ(hit_testable_for_test.value(), false);
855  EXPECT_EQ(focusable_for_test.value(), false);
856 
857  // Reset for the next message.
858  occlusion_hint_for_test.reset();
859  hit_testable_for_test.reset();
860  focusable_for_test.reset();
861 
862  // Send a message including an occlusion hint.
863  const uint8_t json_occlusion_hint[] =
864  "{"
865  " \"method\":\"View.update\","
866  " \"args\": {"
867  " \"viewId\":42,"
868  " \"hitTestable\":true,"
869  " \"focusable\":true,"
870  " \"viewOcclusionHintLTRB\":[0.1,0.2,0.3,0.4]"
871  " }"
872  "}";
873  std::unique_ptr<flutter::PlatformMessage> message_occlusion_hint =
874  std::make_unique<flutter::PlatformMessage>(
875  "flutter/platform_views",
876  fml::MallocMapping::Copy(json_occlusion_hint,
877  sizeof(json_occlusion_hint)),
879  base_view->HandlePlatformMessage(std::move(message_occlusion_hint));
880  RunLoopUntilIdle();
881  ASSERT_TRUE(occlusion_hint_for_test.has_value());
882  ASSERT_TRUE(hit_testable_for_test.has_value());
883  ASSERT_TRUE(focusable_for_test.has_value());
884  EXPECT_EQ(occlusion_hint_for_test.value(),
885  SkRect::MakeLTRB(0.1, 0.2, 0.3, 0.4));
886  EXPECT_EQ(hit_testable_for_test.value(), true);
887  EXPECT_EQ(focusable_for_test.value(), true);
888 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:47
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:147

◆ TEST_F() [49/57]

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

Definition at line 892 of file platform_view_unittest.cc.

References fml::MallocMapping::Copy(), flutter_runner::CreateFMLTaskRunner(), and platform_view.

892  {
893  MockPlatformViewDelegate delegate;
894  flutter::TaskRunners task_runners =
895  flutter::TaskRunners("test_runners", // label
897  async_get_default_dispatcher()), // platform
898  nullptr, // raster
899  nullptr, // ui
900  nullptr // io
901  );
902 
903  // Test wireframe callback function. If the message sent to the platform
904  // view was properly handled and parsed, this function should be called,
905  // setting |wireframe_enabled| to true.
906  bool destroy_view_called = false;
907  auto DestroyViewCallback =
908  [&destroy_view_called](
909  int64_t view_id, flutter_runner::GfxViewIdCallback on_view_unbound) {
910  destroy_view_called = true;
911  on_view_unbound(0);
912  };
913 
915  PlatformViewBuilder(delegate, std::move(task_runners))
916  .SetDestroyViewCallback(DestroyViewCallback)
917  .Build();
918 
919  // Cast platform_view to its base view so we can have access to the public
920  // "HandlePlatformMessage" function.
921  auto base_view = static_cast<flutter::PlatformView*>(&platform_view);
922  EXPECT_TRUE(base_view);
923 
924  // JSON for the message to be passed into the PlatformView.
925  const uint8_t txt[] =
926  "{"
927  " \"method\":\"View.dispose\","
928  " \"args\": {"
929  " \"viewId\":42"
930  " }"
931  "}";
932 
933  std::unique_ptr<flutter::PlatformMessage> message =
934  std::make_unique<flutter::PlatformMessage>(
935  "flutter/platform_views", fml::MallocMapping::Copy(txt, sizeof(txt)),
937  base_view->HandlePlatformMessage(std::move(message));
938 
939  RunLoopUntilIdle();
940 
941  EXPECT_TRUE(destroy_view_called);
942 }
fml::RefPtr< fml::TaskRunner > CreateFMLTaskRunner(async_dispatcher_t *dispatcher)
std::unique_ptr< flutter::PlatformViewIOS > platform_view
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:47
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:147
std::function< void(scenic::ResourceId)> GfxViewIdCallback

◆ TEST_F() [50/57]

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

Definition at line 947 of file platform_view_unittest.cc.

References fml::MallocMapping::Copy(), flutter_runner::CreateFMLTaskRunner(), flutter::PlatformMessage::data(), platform_view, and flutter::ToString().

947  {
948  constexpr int64_t kViewId = 33;
949  constexpr scenic::ResourceId kViewHolderId = 42;
950  MockPlatformViewDelegate delegate;
951 
952  fuchsia::ui::scenic::SessionListenerPtr session_listener;
953  std::vector<fuchsia::ui::scenic::Event> events;
954  flutter::TaskRunners task_runners =
955  flutter::TaskRunners("test_runners", // label
957  async_get_default_dispatcher()), // platform
959  async_get_default_dispatcher()), // raster
961  async_get_default_dispatcher()), // ui
962  nullptr // io
963  );
964 
965  auto on_create_view =
966  [kViewId](int64_t view_id, flutter_runner::ViewCallback on_view_created,
967  flutter_runner::GfxViewIdCallback on_view_bound,
968  bool hit_testable, bool focusable) {
969  ASSERT_EQ(view_id, kViewId);
970  on_view_created();
971  on_view_bound(kViewHolderId);
972  };
973 
975  PlatformViewBuilder(delegate, std::move(task_runners))
976  .SetSessionListenerRequest(session_listener.NewRequest())
977  .SetCreateViewCallback(on_create_view)
978  .Build();
979  RunLoopUntilIdle();
980  ASSERT_EQ(delegate.message(), nullptr);
981 
982  // Create initial view for testing.
983  std::ostringstream create_view_message;
984  create_view_message << "{"
985  << " \"method\":\"View.create\","
986  << " \"args\":{"
987  << " \"viewId\":" << kViewId << ","
988  << " \"hitTestable\":true,"
989  << " \"focusable\":true"
990  << " }"
991  << "}";
992  std::string create_view_call = create_view_message.str();
993  static_cast<flutter::PlatformView*>(&platform_view)
994  ->HandlePlatformMessage(std::make_unique<flutter::PlatformMessage>(
995  "flutter/platform_views",
996  fml::MallocMapping::Copy(create_view_call.c_str(),
997  create_view_call.size()),
999  RunLoopUntilIdle();
1000 
1001  // ViewConnected event.
1002  delegate.Reset();
1003  events.clear();
1004  events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
1005  fuchsia::ui::gfx::Event::WithViewConnected(
1006  fuchsia::ui::gfx::ViewConnectedEvent{
1007  .view_holder_id = kViewHolderId,
1008  })));
1009  session_listener->OnScenicEvent(std::move(events));
1010  RunLoopUntilIdle();
1011 
1012  flutter::PlatformMessage* view_connected_msg = delegate.message();
1013  ASSERT_NE(view_connected_msg, nullptr);
1014  std::ostringstream view_connected_expected_out;
1015  view_connected_expected_out
1016  << "{"
1017  << "\"method\":\"View.viewConnected\","
1018  << "\"args\":{"
1019  << " \"viewId\":" << kViewId // ViewHolderToken handle
1020  << " }"
1021  << "}";
1022  EXPECT_EQ(view_connected_expected_out.str(),
1023  ToString(view_connected_msg->data()));
1024 
1025  // ViewDisconnected event.
1026  delegate.Reset();
1027  events.clear();
1028  events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
1029  fuchsia::ui::gfx::Event::WithViewDisconnected(
1030  fuchsia::ui::gfx::ViewDisconnectedEvent{
1031  .view_holder_id = kViewHolderId,
1032  })));
1033  session_listener->OnScenicEvent(std::move(events));
1034  RunLoopUntilIdle();
1035 
1036  flutter::PlatformMessage* view_disconnected_msg = delegate.message();
1037  ASSERT_NE(view_disconnected_msg, nullptr);
1038  std::ostringstream view_disconnected_expected_out;
1039  view_disconnected_expected_out
1040  << "{"
1041  << "\"method\":\"View.viewDisconnected\","
1042  << "\"args\":{"
1043  << " \"viewId\":" << kViewId // ViewHolderToken handle
1044  << " }"
1045  << "}";
1046  EXPECT_EQ(view_disconnected_expected_out.str(),
1047  ToString(view_disconnected_msg->data()));
1048 
1049  // ViewStateChanged event.
1050  delegate.Reset();
1051  events.clear();
1052  events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
1053  fuchsia::ui::gfx::Event::WithViewStateChanged(
1054  fuchsia::ui::gfx::ViewStateChangedEvent{
1055  .view_holder_id = kViewHolderId,
1056  .state =
1057  fuchsia::ui::gfx::ViewState{
1058  .is_rendering = true,
1059  },
1060  })));
1061  session_listener->OnScenicEvent(std::move(events));
1062  RunLoopUntilIdle();
1063 
1064  flutter::PlatformMessage* view_state_changed_msg = delegate.message();
1065  ASSERT_NE(view_state_changed_msg, nullptr);
1066  std::ostringstream view_state_changed_expected_out;
1067  view_state_changed_expected_out
1068  << "{"
1069  << "\"method\":\"View.viewStateChanged\","
1070  << "\"args\":{"
1071  << " \"viewId\":" << kViewId << "," // ViewHolderToken
1072  << " \"is_rendering\":true," // IsViewRendering
1073  << " \"state\":true" // IsViewRendering
1074  << " }"
1075  << "}";
1076  EXPECT_EQ(view_state_changed_expected_out.str(),
1077  ToString(view_state_changed_msg->data()));
1078 }
fml::RefPtr< fml::TaskRunner > CreateFMLTaskRunner(async_dispatcher_t *dispatcher)
std::unique_ptr< flutter::PlatformViewIOS > platform_view
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:47
static std::string ToString(uint64_t val)
std::function< void()> ViewCallback
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:147
const fml::MallocMapping & data() const
std::function< void(scenic::ResourceId)> GfxViewIdCallback

◆ TEST_F() [51/57]

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

Definition at line 1083 of file platform_view_unittest.cc.

References flutter_runner::testing::FakePlatformMessageResponse::Create(), platform_view, flutter_runner::testing::FakeViewRefFocused::ScheduleCallback(), and flutter_runner::testing::FakeViewRefFocused::times_watched.

1083  {
1084  MockPlatformViewDelegate delegate;
1085  flutter::TaskRunners task_runners =
1086  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
1087 
1088  FakeViewRefFocused vrf;
1089  fidl::BindingSet<fuchsia::ui::views::ViewRefFocused> vrf_bindings;
1090  auto vrf_handle = vrf_bindings.AddBinding(&vrf);
1091 
1093  PlatformViewBuilder(delegate, std::move(task_runners))
1094  .SetViewRefFocused(std::move(vrf_handle))
1095  .Build();
1096 
1097  // Cast platform_view to its base view so we can have access to the public
1098  // "HandlePlatformMessage" function.
1099  auto base_view = static_cast<flutter::PlatformView*>(&platform_view);
1100  EXPECT_TRUE(base_view);
1101 
1102  std::vector<bool> vrf_states{false, true, true, false,
1103  true, false, true, true};
1104 
1105  for (std::size_t i = 0; i < vrf_states.size(); ++i) {
1106  // View.focus.getNext should complete with the next focus state.
1107  auto response1 = FakePlatformMessageResponse::Create();
1108  base_view->HandlePlatformMessage(response1->WithMessage(
1109  "flutter/platform_views", "{\"method\":\"View.focus.getNext\"}"));
1110  // Duplicate View.focus.getNext requests should complete empty.
1111  auto response2 = FakePlatformMessageResponse::Create();
1112  base_view->HandlePlatformMessage(response2->WithMessage(
1113  "flutter/platform_views", "{\"method\":\"View.focus.getNext\"}"));
1114 
1115  // Post watch events and make sure the hanging get is invoked each time.
1116  RunLoopUntilIdle();
1117  EXPECT_EQ(vrf.times_watched, i + 1);
1118 
1119  // Dispatch the next vrf event.
1120  vrf.ScheduleCallback(vrf_states[i]);
1121  RunLoopUntilIdle();
1122 
1123  // Make sure View.focus.getCurrent completes with the current focus state.
1124  auto response3 = FakePlatformMessageResponse::Create();
1125  base_view->HandlePlatformMessage(response3->WithMessage(
1126  "flutter/platform_views", "{\"method\":\"View.focus.getCurrent\"}"));
1127  // Duplicate View.focus.getCurrent are allowed.
1128  auto response4 = FakePlatformMessageResponse::Create();
1129  base_view->HandlePlatformMessage(response4->WithMessage(
1130  "flutter/platform_views", "{\"method\":\"View.focus.getCurrent\"}"));
1131 
1132  // Run event loop and check our results.
1133  RunLoopUntilIdle();
1134  response1->ExpectCompleted(vrf_states[i] ? "[true]" : "[false]");
1135  response2->ExpectCompleted("[null]");
1136  response3->ExpectCompleted(vrf_states[i] ? "[true]" : "[false]");
1137  response4->ExpectCompleted(vrf_states[i] ? "[true]" : "[false]");
1138  }
1139 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:47

◆ TEST_F() [52/57]

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

Definition at line 1143 of file platform_view_unittest.cc.

References flutter_runner::testing::FakePlatformMessageResponse::Create(), platform_view, and flutter_runner::testing::FakeFocuser::request_focus_called().

1143  {
1144  MockPlatformViewDelegate delegate;
1145  flutter::TaskRunners task_runners =
1146  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
1147 
1148  FakeFocuser focuser;
1149  fidl::BindingSet<fuchsia::ui::views::Focuser> focuser_bindings;
1150  auto focuser_handle = focuser_bindings.AddBinding(&focuser);
1151 
1153  PlatformViewBuilder(delegate, std::move(task_runners))
1154  .SetFocuser(std::move(focuser_handle))
1155  .Build();
1156 
1157  // Cast platform_view to its base view so we can have access to the public
1158  // "HandlePlatformMessage" function.
1159  auto base_view = static_cast<flutter::PlatformView*>(&platform_view);
1160  EXPECT_TRUE(base_view);
1161 
1162  // This "Mock" ViewRef serves as the target for the RequestFocus operation.
1163  auto mock_view_ref_pair = scenic::ViewRefPair::New();
1164 
1165  // JSON for the message to be passed into the PlatformView.
1166  std::ostringstream message;
1167  message << "{"
1168  << " \"method\":\"View.focus.request\","
1169  << " \"args\": {"
1170  << " \"viewRef\":"
1171  << mock_view_ref_pair.view_ref.reference.get() << " }"
1172  << "}";
1173 
1174  // Dispatch the plaform message request.
1175  auto response = FakePlatformMessageResponse::Create();
1176  base_view->HandlePlatformMessage(
1177  response->WithMessage("flutter/platform_views", message.str()));
1178  RunLoopUntilIdle();
1179 
1180  response->ExpectCompleted("[0]");
1181  EXPECT_TRUE(focuser.request_focus_called());
1182 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:47

◆ TEST_F() [53/57]

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

Definition at line 1186 of file platform_view_unittest.cc.

References flutter_runner::testing::FakePlatformMessageResponse::Create(), flutter_runner::testing::FakeFocuser::fail_request_focus(), platform_view, and flutter_runner::testing::FakeFocuser::request_focus_called().

1186  {
1187  MockPlatformViewDelegate delegate;
1188  flutter::TaskRunners task_runners =
1189  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
1190 
1191  FakeFocuser focuser;
1192  focuser.fail_request_focus();
1193  fidl::BindingSet<fuchsia::ui::views::Focuser> focuser_bindings;
1194  auto focuser_handle = focuser_bindings.AddBinding(&focuser);
1195 
1197  PlatformViewBuilder(delegate, std::move(task_runners))
1198  .SetFocuser(std::move(focuser_handle))
1199  .Build();
1200 
1201  // Cast platform_view to its base view so we can have access to the public
1202  // "HandlePlatformMessage" function.
1203  auto base_view = static_cast<flutter::PlatformView*>(&platform_view);
1204  EXPECT_TRUE(base_view);
1205 
1206  // This "Mock" ViewRef serves as the target for the RequestFocus operation.
1207  auto mock_view_ref_pair = scenic::ViewRefPair::New();
1208 
1209  // JSON for the message to be passed into the PlatformView.
1210  std::ostringstream message;
1211  message << "{"
1212  << " \"method\":\"View.focus.request\","
1213  << " \"args\": {"
1214  << " \"viewRef\":"
1215  << mock_view_ref_pair.view_ref.reference.get() << " }"
1216  << "}";
1217 
1218  // Dispatch the plaform message request.
1219  auto response = FakePlatformMessageResponse::Create();
1220  base_view->HandlePlatformMessage(
1221  response->WithMessage("flutter/platform_views", message.str()));
1222  RunLoopUntilIdle();
1223 
1224  response->ExpectCompleted(
1225  "[" +
1226  std::to_string(
1227  static_cast<std::underlying_type_t<fuchsia::ui::views::Error>>(
1228  fuchsia::ui::views::Error::DENIED)) +
1229  "]");
1230  EXPECT_TRUE(focuser.request_focus_called());
1231 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:47

◆ TEST_F() [54/57]

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

Definition at line 1234 of file platform_view_unittest.cc.

References event, platform_view, and flutter::ToString().

1234  {
1235  struct EventFlow {
1236  fuchsia::ui::input3::KeyEvent event;
1237  fuchsia::ui::input3::KeyEventStatus expected_key_event_status;
1238  std::string expected_platform_message;
1239  };
1240 
1241  MockPlatformViewDelegate delegate;
1242  flutter::TaskRunners task_runners =
1243  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
1244 
1245  fidl::InterfaceHandle<fuchsia::ui::input3::Keyboard> keyboard_service;
1246  MockKeyboard keyboard(keyboard_service.NewRequest());
1247 
1249  PlatformViewBuilder(delegate, std::move(task_runners))
1250  .SetKeyboard(std::move(keyboard_service))
1251  .Build();
1252  RunLoopUntilIdle();
1253 
1254  std::vector<EventFlow> events;
1255  // Press A. Get 'a'.
1256  events.emplace_back(EventFlow{
1257  MakeEvent(fuchsia::ui::input3::KeyEventType::PRESSED, std::nullopt,
1258  fuchsia::input::Key::A),
1259  fuchsia::ui::input3::KeyEventStatus::HANDLED,
1260  R"({"type":"keydown","keymap":"fuchsia","hidUsage":4,"codePoint":97,"modifiers":0})",
1261  });
1262  // Release A. Get 'a' release.
1263  events.emplace_back(EventFlow{
1264  MakeEvent(fuchsia::ui::input3::KeyEventType::RELEASED, std::nullopt,
1265  fuchsia::input::Key::A),
1266  fuchsia::ui::input3::KeyEventStatus::HANDLED,
1267  R"({"type":"keyup","keymap":"fuchsia","hidUsage":4,"codePoint":97,"modifiers":0})",
1268  });
1269  // Press CAPS_LOCK. Modifier now active.
1270  events.emplace_back(EventFlow{
1271  MakeEvent(fuchsia::ui::input3::KeyEventType::PRESSED,
1272  fuchsia::ui::input3::Modifiers::CAPS_LOCK,
1273  fuchsia::input::Key::CAPS_LOCK),
1274  fuchsia::ui::input3::KeyEventStatus::HANDLED,
1275  R"({"type":"keydown","keymap":"fuchsia","hidUsage":57,"codePoint":0,"modifiers":1})",
1276  });
1277  // Pres A. Get 'A'.
1278  events.emplace_back(EventFlow{
1279  MakeEvent(fuchsia::ui::input3::KeyEventType::PRESSED, std::nullopt,
1280  fuchsia::input::Key::A),
1281  fuchsia::ui::input3::KeyEventStatus::HANDLED,
1282  R"({"type":"keydown","keymap":"fuchsia","hidUsage":4,"codePoint":65,"modifiers":1})",
1283  });
1284  // Release CAPS_LOCK.
1285  events.emplace_back(EventFlow{
1286  MakeEvent(fuchsia::ui::input3::KeyEventType::RELEASED,
1287  fuchsia::ui::input3::Modifiers::CAPS_LOCK,
1288  fuchsia::input::Key::CAPS_LOCK),
1289  fuchsia::ui::input3::KeyEventStatus::HANDLED,
1290  R"({"type":"keyup","keymap":"fuchsia","hidUsage":57,"codePoint":0,"modifiers":1})",
1291  });
1292  // Press A again. This time get 'A'.
1293  // CAPS_LOCK is latched active even if it was just released.
1294  events.emplace_back(EventFlow{
1295  MakeEvent(fuchsia::ui::input3::KeyEventType::PRESSED, std::nullopt,
1296  fuchsia::input::Key::A),
1297  fuchsia::ui::input3::KeyEventStatus::HANDLED,
1298  R"({"type":"keydown","keymap":"fuchsia","hidUsage":4,"codePoint":65,"modifiers":1})",
1299  });
1300 
1301  for (const auto& event : events) {
1302  fuchsia::ui::input3::KeyEvent e;
1303  event.event.Clone(&e);
1304  fuchsia::ui::input3::KeyEventStatus key_event_status{0u};
1305  keyboard.listener_->OnKeyEvent(
1306  std::move(e),
1307  [&key_event_status](fuchsia::ui::input3::KeyEventStatus status) {
1308  key_event_status = status;
1309  });
1310  RunLoopUntilIdle();
1311 
1312  ASSERT_NOTNULL(delegate.message());
1313  EXPECT_EQ(event.expected_platform_message,
1314  ToString(delegate.message()->data()));
1315  EXPECT_EQ(event.expected_key_event_status, key_event_status);
1316  }
1317 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view
FlKeyEvent * event
static std::string ToString(uint64_t val)

◆ TEST_F() [55/57]

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

Definition at line 1319 of file platform_view_unittest.cc.

References fml::MallocMapping::Copy(), height, platform_view, and width.

1319  {
1320  MockPlatformViewDelegate delegate;
1321  flutter::TaskRunners task_runners =
1322  flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
1323 
1324  uint64_t width = 200;
1325  uint64_t height = 100;
1326  std::vector<std::string> shaders = {"foo.skp", "bar.skp", "baz.skp"};
1327 
1328  OnShaderWarmup on_shader_warmup =
1329  [&](const std::vector<std::string>& shaders_in,
1330  std::function<void(uint32_t)> completion_callback, uint64_t width_in,
1331  uint64_t height_in) {
1332  ASSERT_EQ(shaders.size(), shaders_in.size());
1333  for (size_t i = 0; i < shaders_in.size(); i++) {
1334  ASSERT_EQ(shaders[i], shaders_in[i]);
1335  }
1336  ASSERT_EQ(width, width_in);
1337  ASSERT_EQ(height, height_in);
1338 
1339  completion_callback(shaders_in.size());
1340  };
1341 
1343  PlatformViewBuilder(delegate, std::move(task_runners))
1344  .SetShaderWarmupCallback(on_shader_warmup)
1345  .Build();
1346 
1347  std::ostringstream shaders_array_ostream;
1348  shaders_array_ostream << "[ ";
1349  for (auto it = shaders.begin(); it != shaders.end(); ++it) {
1350  shaders_array_ostream << "\"" << *it << "\"";
1351  if (std::next(it) != shaders.end()) {
1352  shaders_array_ostream << ", ";
1353  }
1354  }
1355  shaders_array_ostream << "]";
1356 
1357  std::string shaders_array_string = shaders_array_ostream.str();
1358 
1359  // Create initial view for testing.
1360  std::ostringstream warmup_shaders_ostream;
1361  warmup_shaders_ostream << "{"
1362  << " \"method\":\"WarmupSkps\","
1363  << " \"args\":{"
1364  << " \"shaders\":" << shaders_array_string << ","
1365  << " \"width\":" << width << ","
1366  << " \"height\":" << height << " }"
1367  << "}\n";
1368  std::string warmup_shaders_string = warmup_shaders_ostream.str();
1369 
1371  new TestPlatformMessageResponse);
1372  static_cast<flutter::PlatformView*>(&platform_view)
1373  ->HandlePlatformMessage(std::make_unique<flutter::PlatformMessage>(
1374  "fuchsia/shader_warmup",
1375  fml::MallocMapping::Copy(warmup_shaders_string.c_str(),
1376  warmup_shaders_string.size()),
1377  response));
1378  RunLoopUntilIdle();
1379  ASSERT_TRUE(response->is_complete());
1380 
1381  std::ostringstream expected_result_ostream;
1382  expected_result_ostream << "[" << shaders.size() << "]";
1383  std::string expected_result_string = expected_result_ostream.str();
1384  EXPECT_EQ(expected_result_string, response->result_string);
1385 }
std::function< void(const std::vector< std::string > &, std::function< void(uint32_t)>, uint64_t, uint64_t)> OnShaderWarmup
Definition: platform_view.h:52
std::unique_ptr< flutter::PlatformViewIOS > platform_view
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:47
int32_t width
int32_t height
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:147

◆ TEST_F() [56/57]

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

Definition at line 1387 of file platform_view_unittest.cc.

References flutter_runner::testing::TouchEventBuilder::AddSample(), flutter_runner::testing::TouchEventBuilder::AddTime(), flutter_runner::testing::TouchEventBuilder::AddViewParameters(), flutter::testing::Build(), flutter::PointerData::kAdd, flutter::PointerData::kDown, kIdentity, kIxnOne, kRect, flutter_runner::testing::TouchEventBuilder::New(), platform_view, flutter_runner::testing::FakeTouchSource::ScheduleCallback(), and flutter::testing::UnpackPointerPacket().

1387  {
1388  constexpr std::array<std::array<float, 2>, 2> kRect = {{{0, 0}, {20, 20}}};
1389  constexpr std::array<float, 9> kIdentity = {1, 0, 0, 0, 1, 0, 0, 0, 1};
1390  constexpr fuchsia::ui::pointer::TouchInteractionId kIxnOne = {
1391  .device_id = 0u, .pointer_id = 1u, .interaction_id = 2u};
1392  constexpr float valid_pixel_ratio = 2.f;
1393 
1394  MockPlatformViewDelegate delegate;
1395  flutter::TaskRunners task_runners("test_runners", nullptr, nullptr, nullptr,
1396  nullptr);
1397 
1398  fuchsia::ui::scenic::SessionListenerPtr session_listener;
1399  FakeTouchSource touch_server;
1400  fidl::BindingSet<fuchsia::ui::pointer::TouchSource> touch_bindings;
1401  auto touch_handle = touch_bindings.AddBinding(&touch_server);
1403  PlatformViewBuilder(delegate, std::move(task_runners))
1404  .SetSessionListenerRequest(session_listener.NewRequest())
1405  .SetTouchSource(std::move(touch_handle))
1406  .Build();
1407  RunLoopUntilIdle();
1408  EXPECT_EQ(delegate.pointer_packets().size(), 0u);
1409 
1410  // Set logical-to-physical metrics and logical view size
1411  std::vector<fuchsia::ui::scenic::Event> scenic_events;
1412  scenic_events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
1413  fuchsia::ui::gfx::Event::WithMetrics(fuchsia::ui::gfx::MetricsEvent{
1414  .node_id = 0,
1415  .metrics =
1416  fuchsia::ui::gfx::Metrics{
1417  .scale_x = valid_pixel_ratio,
1418  .scale_y = valid_pixel_ratio,
1419  .scale_z = valid_pixel_ratio,
1420  },
1421  })));
1422  scenic_events.emplace_back(
1423  fuchsia::ui::scenic::Event::WithGfx(
1424  fuchsia::ui::gfx::Event::WithViewPropertiesChanged(
1425  fuchsia::ui::gfx::ViewPropertiesChangedEvent{
1426  .view_id = 0,
1427  .properties =
1428  fuchsia::ui::gfx::ViewProperties{
1429  .bounding_box =
1430  fuchsia::ui::gfx::BoundingBox{
1431  .min =
1432  fuchsia::ui::gfx::vec3{
1433  .x = 0.f,
1434  .y = 0.f,
1435  .z = 0.f,
1436  },
1437  .max =
1438  fuchsia::ui::gfx::vec3{
1439  .x = 20.f,
1440  .y = 20.f,
1441  .z = 20.f,
1442  },
1443  },
1444  },
1445  })));
1446  session_listener->OnScenicEvent(std::move(scenic_events));
1447  RunLoopUntilIdle();
1448  EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics(2.f, 40.f, 40.f, -1));
1449 
1450  // Inject
1451  std::vector<fuchsia::ui::pointer::TouchEvent> events =
1452  TouchEventBuilder::New()
1453  .AddTime(/* in nanoseconds */ 1111789u)
1454  .AddViewParameters(kRect, kRect, kIdentity)
1455  .AddSample(kIxnOne, fuchsia::ui::pointer::EventPhase::ADD,
1456  {10.f, 10.f})
1457  .AddResult(
1458  {.interaction = kIxnOne,
1459  .status = fuchsia::ui::pointer::TouchInteractionStatus::GRANTED})
1460  .BuildAsVector();
1461  touch_server.ScheduleCallback(std::move(events));
1462  RunLoopUntilIdle();
1463 
1464  // Unpack
1465  std::vector<std::unique_ptr<flutter::PointerDataPacket>> packets =
1466  delegate.TakePointerDataPackets();
1467  ASSERT_EQ(packets.size(), 1u);
1468  std::vector<flutter::PointerData> flutter_events;
1469  UnpackPointerPacket(flutter_events, std::move(packets[0]));
1470 
1471  // Examine phases
1472  ASSERT_EQ(flutter_events.size(), 2u);
1473  EXPECT_EQ(flutter_events[0].change, flutter::PointerData::Change::kAdd);
1474  EXPECT_EQ(flutter_events[1].change, flutter::PointerData::Change::kDown);
1475 
1476  // Examine coordinates
1477  // With metrics defined, observe metrics ratio applied.
1478  EXPECT_EQ(flutter_events[0].physical_x, 20.f);
1479  EXPECT_EQ(flutter_events[0].physical_y, 20.f);
1480  EXPECT_EQ(flutter_events[1].physical_x, 20.f);
1481  EXPECT_EQ(flutter_events[1].physical_y, 20.f);
1482 }
constexpr fup_TouchIxnId kIxnOne
constexpr std::array< std::array< float, 2 >, 2 > kRect
std::unique_ptr< flutter::PlatformViewIOS > platform_view
static sk_sp< DisplayList > Build(size_t g_index, size_t v_index)
void UnpackPointerPacket(std::vector< PointerData > &output, std::unique_ptr< PointerDataPacket > packet)
constexpr std::array< float, 9 > kIdentity

◆ TEST_F() [57/57]

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

Definition at line 1484 of file platform_view_unittest.cc.

References flutter::testing::Build(), platform_view, and flutter::testing::UnpackPointerPacket().

1484  {
1485  constexpr float kSmallDiscrepancy = -0.00003f;
1486 
1487  fuchsia::ui::scenic::SessionListenerPtr session_listener;
1488  MockPlatformViewDelegate delegate;
1489  flutter::TaskRunners task_runners("test_runners", nullptr, nullptr, nullptr,
1490  nullptr);
1492  PlatformViewBuilder(delegate, std::move(task_runners))
1493  .SetSessionListenerRequest(session_listener.NewRequest())
1494  .Build();
1495  RunLoopUntilIdle();
1496  EXPECT_EQ(delegate.pointer_packets().size(), 0u);
1497 
1498  std::vector<fuchsia::ui::scenic::Event> events;
1499  events.emplace_back(
1500  fuchsia::ui::scenic::Event::WithGfx(
1501  fuchsia::ui::gfx::Event::WithViewPropertiesChanged(
1502  fuchsia::ui::gfx::ViewPropertiesChangedEvent{
1503  .view_id = 0,
1504  .properties =
1505  fuchsia::ui::gfx::ViewProperties{
1506  .bounding_box =
1507  fuchsia::ui::gfx::BoundingBox{
1508  .min =
1509  fuchsia::ui::gfx::vec3{
1510  .x = 0.f,
1511  .y = 0.f,
1512  .z = 0.f,
1513  },
1514  .max =
1515  fuchsia::ui::gfx::vec3{
1516  .x = 100.f,
1517  .y = 100.f,
1518  .z = 100.f,
1519  },
1520  },
1521  },
1522  })));
1523  events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
1524  fuchsia::ui::gfx::Event::WithMetrics(fuchsia::ui::gfx::MetricsEvent{
1525  .node_id = 0,
1526  .metrics =
1527  fuchsia::ui::gfx::Metrics{
1528  .scale_x = 1.f,
1529  .scale_y = 1.f,
1530  .scale_z = 1.f,
1531  },
1532  })));
1533  events.emplace_back(fuchsia::ui::scenic::Event::WithInput(
1534  fuchsia::ui::input::InputEvent::WithPointer(
1535  fuchsia::ui::input::PointerEvent{
1536  .event_time = 1111,
1537  .device_id = 2222,
1538  .pointer_id = 3333,
1539  .type = fuchsia::ui::input::PointerEventType::TOUCH,
1540  .phase = fuchsia::ui::input::PointerEventPhase::ADD,
1541  .x = 50.f,
1542  .y = kSmallDiscrepancy, // floating point inaccuracy
1543  .radius_major = 0.f,
1544  .radius_minor = 0.f,
1545  .buttons = 0u,
1546  })));
1547  events.emplace_back(fuchsia::ui::scenic::Event::WithInput(
1548  fuchsia::ui::input::InputEvent::WithPointer(
1549  fuchsia::ui::input::PointerEvent{
1550  .event_time = 1111,
1551  .device_id = 2222,
1552  .pointer_id = 3333,
1553  .type = fuchsia::ui::input::PointerEventType::TOUCH,
1554  .phase = fuchsia::ui::input::PointerEventPhase::DOWN,
1555  .x = 50.f,
1556  .y = kSmallDiscrepancy, // floating point inaccuracy
1557  .radius_major = 0.f,
1558  .radius_minor = 0.f,
1559  .buttons = 0u,
1560  })));
1561  events.emplace_back(fuchsia::ui::scenic::Event::WithInput(
1562  fuchsia::ui::input::InputEvent::WithPointer(
1563  fuchsia::ui::input::PointerEvent{
1564  .event_time = 1111,
1565  .device_id = 2222,
1566  .pointer_id = 3333,
1567  .type = fuchsia::ui::input::PointerEventType::TOUCH,
1568  .phase = fuchsia::ui::input::PointerEventPhase::MOVE,
1569  .x = 50.f,
1570  .y = kSmallDiscrepancy, // floating point inaccuracy
1571  .radius_major = 0.f,
1572  .radius_minor = 0.f,
1573  .buttons = 0u,
1574  })));
1575  session_listener->OnScenicEvent(std::move(events));
1576  RunLoopUntilIdle();
1577  ASSERT_EQ(delegate.pointer_packets().size(), 3u);
1578 
1579  // Embedder issues pointer data in a bytestream format, PointerDataPacket.
1580  // Use this handy utility to recover data as a C struct, PointerData.
1581  std::vector<std::unique_ptr<flutter::PointerDataPacket>> packets =
1582  delegate.TakePointerDataPackets();
1583  std::vector<flutter::PointerData> add, down, move;
1584  UnpackPointerPacket(add, std::move(packets[0]));
1585  UnpackPointerPacket(down, std::move(packets[1]));
1586  UnpackPointerPacket(move, std::move(packets[2]));
1587 
1588  EXPECT_EQ(add[0].physical_x, 50.f);
1589  EXPECT_EQ(add[0].physical_y, kSmallDiscrepancy);
1590  EXPECT_EQ(down[0].physical_x, 50.f);
1591  EXPECT_EQ(down[0].physical_y, 0.f); // clamping happened
1592  EXPECT_EQ(move[0].physical_x, 50.f);
1593  EXPECT_EQ(move[0].physical_y, kSmallDiscrepancy);
1594 }
std::unique_ptr< flutter::PlatformViewIOS > platform_view
static sk_sp< DisplayList > Build(size_t g_index, size_t v_index)
void UnpackPointerPacket(std::vector< PointerData > &output, std::unique_ptr< PointerDataPacket > packet)

Variable Documentation

◆ kIdentity

constexpr std::array<float, 9> flutter_runner::testing::kIdentity = {1, 0, 0, 0, 1, 0, 0, 0, 1}

Definition at line 35 of file pointer_delegate_unittests.cc.

Referenced by TEST_F().

◆ kInvalidFakeResourceId

constexpr FakeResourceId flutter_runner::testing::kInvalidFakeResourceId = 0u

◆ kIxnOne

constexpr fup_TouchIxnId flutter_runner::testing::kIxnOne
Initial value:
= {.device_id = 1u,
.pointer_id = 1u,
.interaction_id = 2u}

Definition at line 36 of file pointer_delegate_unittests.cc.

Referenced by TEST_F().

◆ kRect

constexpr std::array<std::array<float, 2>, 2> flutter_runner::testing::kRect = {{{0, 0}, {20, 20}}}

Definition at line 34 of file pointer_delegate_unittests.cc.

Referenced by TEST_F().