Flutter Engine
The Flutter Engine
Protected Member Functions | Protected Attributes | List of all members
flutter_runner::testing::PointerInjectorDelegateTest Class Reference
Inheritance diagram for flutter_runner::testing::PointerInjectorDelegateTest:

Protected Member Functions

 PointerInjectorDelegateTest ()
 
void RunLoopUntilIdle ()
 
bool RunGivenLoopWithTimeout (async::Loop *loop, zx::duration timeout)
 
bool RunLoopWithTimeoutOrUntil (fit::function< bool()> condition, zx::duration timeout, zx::duration step)
 
void RunLoopUntil (fit::function< bool()> condition, zx::duration step=zx::msec(10))
 
void SetUp () override
 
void CreateView (uint64_t view_id, std::optional< fuv_ViewRef > view_ref=std::nullopt)
 

Protected Attributes

std::unique_ptr< PointerInjectorDelegatepointer_injector_delegate_
 
std::unique_ptr< MockInjectorRegistryregistry_
 
fuv_ViewRef host_view_ref_
 

Detailed Description

Definition at line 137 of file pointer_injector_delegate_unittest.cc.

Constructor & Destructor Documentation

◆ PointerInjectorDelegateTest()

flutter_runner::testing::PointerInjectorDelegateTest::PointerInjectorDelegateTest ( )
inlineprotected

Definition at line 140 of file pointer_injector_delegate_unittest.cc.

141 : loop_(&kAsyncLoopConfigAttachToCurrentThread) {}

Member Function Documentation

◆ CreateView()

void flutter_runner::testing::PointerInjectorDelegateTest::CreateView ( uint64_t  view_id,
std::optional< fuv_ViewRef view_ref = std::nullopt 
)
inlineprotected

Definition at line 226 of file pointer_injector_delegate_unittest.cc.

227 {
228 fuv_ViewRef ref;
229 if (view_ref.has_value()) {
230 ref = std::move(*view_ref);
231 } else {
232 fuchsia::ui::views::ViewRefControl view_ref_control;
233 fuchsia::ui::views::ViewRef view_ref;
234 auto status = zx::eventpair::create(
235 /*options*/ 0u, &view_ref_control.reference, &view_ref.reference);
236 ASSERT_EQ(status, ZX_OK);
237 view_ref_control.reference.replace(
238 ZX_DEFAULT_EVENTPAIR_RIGHTS & (~ZX_RIGHT_DUPLICATE),
239 &view_ref_control.reference);
240 view_ref.reference.replace(ZX_RIGHTS_BASIC, &view_ref.reference);
241
242 ref = std::move(view_ref);
243 }
244 pointer_injector_delegate_->OnCreateView(view_id, std::move(ref));
245 }
std::unique_ptr< PointerInjectorDelegate > pointer_injector_delegate_
fuchsia::ui::views::ViewRef fuv_ViewRef
int_closure create

◆ RunGivenLoopWithTimeout()

bool flutter_runner::testing::PointerInjectorDelegateTest::RunGivenLoopWithTimeout ( async::Loop *  loop,
zx::duration  timeout 
)
inlineprotected

Definition at line 147 of file pointer_injector_delegate_unittest.cc.

147 {
148 // This cannot be a local variable because the delayed task below can
149 // execute after this function returns.
150 auto canceled = std::make_shared<bool>(false);
151 bool timed_out = false;
152 async::PostDelayedTask(
153 loop->dispatcher(),
154 [loop, canceled, &timed_out] {
155 if (*canceled) {
156 return;
157 }
158 timed_out = true;
159 loop->Quit();
160 },
161 timeout);
162 loop->Run();
163 loop->ResetQuit();
164
165 if (!timed_out) {
166 *canceled = true;
167 }
168 return timed_out;
169 }
def timeout(deadline, cmd)

◆ RunLoopUntil()

void flutter_runner::testing::PointerInjectorDelegateTest::RunLoopUntil ( fit::function< bool()>  condition,
zx::duration  step = zx::msec(10) 
)
inlineprotected

Definition at line 197 of file pointer_injector_delegate_unittest.cc.

198 {
199 RunLoopWithTimeoutOrUntil(std::move(condition), zx::duration::infinite(),
200 step);
201 }
static int step(int x, SkScalar min, SkScalar max)
Definition: BlurTest.cpp:215
bool RunLoopWithTimeoutOrUntil(fit::function< bool()> condition, zx::duration timeout, zx::duration step)

◆ RunLoopUntilIdle()

void flutter_runner::testing::PointerInjectorDelegateTest::RunLoopUntilIdle ( )
inlineprotected

Definition at line 145 of file pointer_injector_delegate_unittest.cc.

145{ loop_.RunUntilIdle(); }

◆ RunLoopWithTimeoutOrUntil()

bool flutter_runner::testing::PointerInjectorDelegateTest::RunLoopWithTimeoutOrUntil ( fit::function< bool()>  condition,
zx::duration  timeout,
zx::duration  step 
)
inlineprotected

Definition at line 171 of file pointer_injector_delegate_unittest.cc.

173 {
174 const zx::time timeout_deadline = zx::deadline_after(timeout);
175
176 while (zx::clock::get_monotonic() < timeout_deadline &&
177 loop_.GetState() == ASYNC_LOOP_RUNNABLE) {
178 if (condition()) {
179 loop_.ResetQuit();
180 return true;
181 }
182
183 if (step == zx::duration::infinite()) {
184 // Performs a single unit of work, possibly blocking until there is work
185 // to do or the timeout deadline arrives.
186 loop_.Run(timeout_deadline, true);
187 } else {
188 // Performs work until the step deadline arrives.
190 }
191 }
192
193 loop_.ResetQuit();
194 return condition();
195 }
bool RunGivenLoopWithTimeout(async::Loop *loop, zx::duration timeout)
static double time(int loops, Benchmark *bench, Target *target)
Definition: nanobench.cpp:394

◆ SetUp()

void flutter_runner::testing::PointerInjectorDelegateTest::SetUp ( )
inlineoverrideprotected

Definition at line 203 of file pointer_injector_delegate_unittest.cc.

203 {
204 fuchsia::ui::views::ViewRefControl view_ref_control;
205 fuchsia::ui::views::ViewRef view_ref;
206 auto status = zx::eventpair::create(
207 /*options*/ 0u, &view_ref_control.reference, &view_ref.reference);
208 ASSERT_EQ(status, ZX_OK);
209 view_ref_control.reference.replace(
210 ZX_DEFAULT_EVENTPAIR_RIGHTS & (~ZX_RIGHT_DUPLICATE),
211 &view_ref_control.reference);
212 view_ref.reference.replace(ZX_RIGHTS_BASIC, &view_ref.reference);
213
214 host_view_ref_ = std::move(view_ref);
215
216 fup_RegistryHandle registry;
217 registry_ = std::make_unique<MockInjectorRegistry>(registry.NewRequest());
218
219 fuv_ViewRef host_view_ref_clone;
220 fidl::Clone(host_view_ref_, &host_view_ref_clone);
221
222 pointer_injector_delegate_ = std::make_unique<PointerInjectorDelegate>(
223 std::move(registry), std::move(host_view_ref_clone));
224 }
fuchsia::ui::pointerinjector::RegistryHandle fup_RegistryHandle

Member Data Documentation

◆ host_view_ref_

fuv_ViewRef flutter_runner::testing::PointerInjectorDelegateTest::host_view_ref_
protected

Definition at line 249 of file pointer_injector_delegate_unittest.cc.

◆ pointer_injector_delegate_

std::unique_ptr<PointerInjectorDelegate> flutter_runner::testing::PointerInjectorDelegateTest::pointer_injector_delegate_
protected

Definition at line 247 of file pointer_injector_delegate_unittest.cc.

◆ registry_

std::unique_ptr<MockInjectorRegistry> flutter_runner::testing::PointerInjectorDelegateTest::registry_
protected

Definition at line 248 of file pointer_injector_delegate_unittest.cc.


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