7#include <lib/async-testing/test_loop.h>
8#include <lib/async/dispatcher.h>
12#include "flutter/fml/logging.h"
13#include "fuchsia/ui/composition/cpp/fidl.h"
14#include "gtest/gtest.h"
20 return ::testing::UnitTest::GetInstance()->current_test_info()->name();
30 async::TestLoop&
loop() {
return loop_; }
37 auto flatland_handle =
39 return flatland_handle.Bind();
48 async::TestLoop loop_;
49 std::unique_ptr<async::LoopInterface> flatland_subloop_;
55 EXPECT_EQ(fake_flatland().debug_name(),
"");
58 loop().RunUntilIdle();
59 EXPECT_EQ(fake_flatland().debug_name(),
"");
64 fuchsia::ui::composition::FlatlandPtr flatland = ConnectFlatland();
68 flatland->SetDebugName(debug_label);
69 EXPECT_EQ(fake_flatland().debug_name(),
"");
73 loop().RunUntilIdle();
74 EXPECT_EQ(fake_flatland().debug_name(), debug_label);
78 fuchsia::ui::composition::FlatlandPtr flatland = ConnectFlatland();
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);
92 on_next_frame_additional_present_credits =
93 on_next_frame_begin_values.additional_present_credits();
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);
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);
111 frame_presented_num_presents_allowed =
112 frame_presented_info.num_presents_allowed;
115 fake_flatland().FireOnFramePresentedEvent(
116 fuchsia::scenic::scheduling::FramePresentedInfo{
117 .actual_presentation_time = 0,
118 .num_presents_allowed = kOnFramePresentedNumPresentsAllowed,
120 EXPECT_EQ(frame_presented_num_presents_allowed, 0u);
121 loop().RunUntilIdle();
122 EXPECT_EQ(frame_presented_num_presents_allowed,
123 kOnFramePresentedNumPresentsAllowed);
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);
135 present_requested_time = present_args.requested_presentation_time();
138 flatland->Present(std::move(present_args));
139 EXPECT_EQ(present_requested_time, 0);
140 loop().RunUntilIdle();
141 EXPECT_EQ(present_requested_time, kPresentRequestedTime);
fuchsia::ui::composition::FlatlandPtr ConnectFlatland()
FakeFlatland & fake_flatland()
~FakeFlatlandTest() override=default
fuchsia::ui::composition::FlatlandHandle ConnectFlatland(async_dispatcher_t *dispatcher=nullptr)
bool is_flatland_connected() const
#define FML_CHECK(condition)
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
TEST_F(FocusDelegateTest, WatchCallbackSeries)