Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
fuchsia_test_utils::PortableUITest Class Referenceabstract

#include <portable_ui_test.h>

Inheritance diagram for fuchsia_test_utils::PortableUITest:

Public Member Functions

void SetUp (bool build_realm=true)
 
void BuildRealm ()
 
void LaunchClient ()
 
void LaunchClientWithEmbeddedView ()
 
bool HasViewConnected (zx_koid_t view_ref_koid)
 
void RegisterTouchScreen ()
 
void RegisterMouse ()
 
void RegisterKeyboard ()
 
void InjectTap (int32_t x, int32_t y)
 
void SimulateMouseEvent (std::vector< fuchsia::ui::test::input::MouseButton > pressed_buttons, int movement_x, int movement_y)
 
void SimulateMouseScroll (std::vector< fuchsia::ui::test::input::MouseButton > pressed_buttons, int scroll_x, int scroll_y, bool use_physical_units=false)
 
void SimulateTextEntry (std::string text)
 

Static Public Attributes

static constexpr auto kVulkanLoaderServiceName
 
static constexpr auto kPosixSocketProviderName
 
static constexpr auto kPointerInjectorRegistryName
 
static constexpr auto kTestUIStack = "ui"
 
static constexpr auto kTestUIStackRef
 
static constexpr auto kFlutterJitRunner = "flutter_jit_runner"
 
static constexpr auto kFlutterJitRunnerRef
 
static constexpr auto kFlutterJitRunnerUrl
 
static constexpr auto kFlutterRunnerEnvironment = "flutter_runner_env"
 

Protected Member Functions

component_testing::RealmBuilder * realm_builder ()
 
component_testing::RealmRoot * realm_root ()
 
int touch_injection_request_count () const
 

Protected Attributes

uint32_t display_width_ = 0
 
uint32_t display_height_ = 0
 

Private Member Functions

virtual void ExtendRealm ()=0
 
virtual std::string GetTestUIStackUrl ()=0
 

Detailed Description

Definition at line 24 of file portable_ui_test.h.

Member Function Documentation

◆ BuildRealm()

void fuchsia_test_utils::PortableUITest::BuildRealm ( )

Definition at line 44 of file portable_ui_test.cc.

44 {
45 realm_ = std::make_unique<RealmRoot>(realm_builder_.Build());
46}

◆ ExtendRealm()

virtual void fuchsia_test_utils::PortableUITest::ExtendRealm ( )
privatepure virtual

◆ GetTestUIStackUrl()

virtual std::string fuchsia_test_utils::PortableUITest::GetTestUIStackUrl ( )
privatepure virtual

◆ HasViewConnected()

bool fuchsia_test_utils::PortableUITest::HasViewConnected ( zx_koid_t  view_ref_koid)

Definition at line 147 of file portable_ui_test.cc.

147 {
148 return last_view_tree_snapshot_.has_value() &&
149 CheckViewExistsInSnapshot(*last_view_tree_snapshot_, view_ref_koid);
150}
bool CheckViewExistsInSnapshot(const fuchsia::ui::observation::geometry::ViewTreeSnapshot &snapshot, zx_koid_t view_ref_koid)
Definition: check_view.cc:11

◆ InjectTap()

void fuchsia_test_utils::PortableUITest::InjectTap ( int32_t  x,
int32_t  y 
)

Definition at line 281 of file portable_ui_test.cc.

281 {
282 fuchsia::ui::test::input::TouchScreenSimulateTapRequest tap_request;
283 tap_request.mutable_tap_location()->x = x;
284 tap_request.mutable_tap_location()->y = y;
285
286 FML_LOG(INFO) << "Injecting tap at (" << tap_request.tap_location().x << ", "
287 << tap_request.tap_location().y << ")";
288 fake_touchscreen_->SimulateTap(std::move(tap_request), [this]() {
289 ++touch_injection_request_count_;
290 FML_LOG(INFO) << "*** Tap injected, count: "
291 << touch_injection_request_count_;
292 });
293}
#define FML_LOG(severity)
Definition: logging.h:82
double y
double x

◆ LaunchClient()

void fuchsia_test_utils::PortableUITest::LaunchClient ( )

Definition at line 152 of file portable_ui_test.cc.

152 {
153 scene_provider_ =
154 realm_->component().Connect<fuchsia::ui::test::scene::Controller>();
155 scene_provider_.set_error_handler([](auto) {
156 FML_LOG(ERROR) << "Error from test scene provider: "
157 << &zx_status_get_string;
158 });
159
160 fuchsia::ui::test::scene::ControllerAttachClientViewRequest request;
161 request.set_view_provider(
162 realm_->component().Connect<fuchsia::ui::app::ViewProvider>());
163 scene_provider_->RegisterViewTreeWatcher(view_tree_watcher_.NewRequest(),
164 []() {});
165 scene_provider_->AttachClientView(
166 std::move(request), [this](auto client_view_ref_koid) {
167 client_root_view_ref_koid_ = client_view_ref_koid;
168 });
169
170 FML_LOG(INFO) << "Waiting for client view ref koid";
171 RunLoopUntil([this] { return client_root_view_ref_koid_.has_value(); });
172
173 WatchViewGeometry();
174
175 FML_LOG(INFO) << "Waiting for client view to connect";
176 // Wait for the client view to get attached to the view tree.
177 RunLoopUntil(
178 [this] { return HasViewConnected(*client_root_view_ref_koid_); });
179 FML_LOG(INFO) << "Client view has rendered";
180}
bool HasViewConnected(zx_koid_t view_ref_koid)
#define ERROR(message)
Definition: elf_loader.cc:260

◆ LaunchClientWithEmbeddedView()

void fuchsia_test_utils::PortableUITest::LaunchClientWithEmbeddedView ( )

Definition at line 182 of file portable_ui_test.cc.

182 {
183 LaunchClient();
184 // At this point, the parent view must have rendered, so we just need to wait
185 // for the embedded view.
186 RunLoopUntil([this] {
187 if (!last_view_tree_snapshot_.has_value() ||
188 !last_view_tree_snapshot_->has_views()) {
189 return false;
190 }
191
192 if (!client_root_view_ref_koid_.has_value()) {
193 return false;
194 }
195
196 for (const auto& view : last_view_tree_snapshot_->views()) {
197 if (!view.has_view_ref_koid() ||
198 view.view_ref_koid() != *client_root_view_ref_koid_) {
199 continue;
200 }
201
202 if (view.children().empty()) {
203 return false;
204 }
205
206 // NOTE: We can't rely on the presence of the child view in
207 // `view.children()` to guarantee that it has rendered. The child view
208 // also needs to be present in `last_view_tree_snapshot_->views`.
209 return std::count_if(
210 last_view_tree_snapshot_->views().begin(),
211 last_view_tree_snapshot_->views().end(),
212 [view_to_find =
213 view.children().back()](const auto& view_to_check) {
214 return view_to_check.has_view_ref_koid() &&
215 view_to_check.view_ref_koid() == view_to_find;
216 }) > 0;
217 }
218
219 return false;
220 });
221
222 FML_LOG(INFO) << "Embedded view has rendered";
223}
for(const auto glyph :glyphs)
Definition: FontMgrTest.cpp:52
if(end==-1)

◆ realm_builder()

component_testing::RealmBuilder * fuchsia_test_utils::PortableUITest::realm_builder ( )
inlineprotected

Definition at line 99 of file portable_ui_test.h.

99{ return &realm_builder_; }

◆ realm_root()

component_testing::RealmRoot * fuchsia_test_utils::PortableUITest::realm_root ( )
inlineprotected

Definition at line 100 of file portable_ui_test.h.

100{ return realm_.get(); }

◆ RegisterKeyboard()

void fuchsia_test_utils::PortableUITest::RegisterKeyboard ( )

Definition at line 262 of file portable_ui_test.cc.

262 {
263 FML_LOG(INFO) << "Registering fake keyboard";
264 input_registry_ =
265 realm_->component().Connect<fuchsia::ui::test::input::Registry>();
266 input_registry_.set_error_handler([](auto) {
267 FML_LOG(ERROR) << "Error from input helper: " << &zx_status_get_string;
268 });
269
270 bool keyboard_registered = false;
271 fuchsia::ui::test::input::RegistryRegisterKeyboardRequest request;
272 request.set_device(fake_keyboard_.NewRequest());
273 input_registry_->RegisterKeyboard(
274 std::move(request),
275 [&keyboard_registered]() { keyboard_registered = true; });
276
277 RunLoopUntil([&keyboard_registered] { return keyboard_registered; });
278 FML_LOG(INFO) << "Keyboard registered";
279}

◆ RegisterMouse()

void fuchsia_test_utils::PortableUITest::RegisterMouse ( )

Definition at line 244 of file portable_ui_test.cc.

244 {
245 FML_LOG(INFO) << "Registering fake mouse";
246 input_registry_ =
247 realm_->component().Connect<fuchsia::ui::test::input::Registry>();
248 input_registry_.set_error_handler([](auto) {
249 FML_LOG(ERROR) << "Error from input helper: " << &zx_status_get_string;
250 });
251
252 bool mouse_registered = false;
253 fuchsia::ui::test::input::RegistryRegisterMouseRequest request;
254 request.set_device(fake_mouse_.NewRequest());
255 input_registry_->RegisterMouse(
256 std::move(request), [&mouse_registered]() { mouse_registered = true; });
257
258 RunLoopUntil([&mouse_registered] { return mouse_registered; });
259 FML_LOG(INFO) << "Mouse registered";
260}

◆ RegisterTouchScreen()

void fuchsia_test_utils::PortableUITest::RegisterTouchScreen ( )

Definition at line 225 of file portable_ui_test.cc.

225 {
226 FML_LOG(INFO) << "Registering fake touch screen";
227 input_registry_ =
228 realm_->component().Connect<fuchsia::ui::test::input::Registry>();
229 input_registry_.set_error_handler([](auto) {
230 FML_LOG(ERROR) << "Error from input helper: " << &zx_status_get_string;
231 });
232
233 bool touchscreen_registered = false;
234 fuchsia::ui::test::input::RegistryRegisterTouchScreenRequest request;
235 request.set_device(fake_touchscreen_.NewRequest());
236 input_registry_->RegisterTouchScreen(
237 std::move(request),
238 [&touchscreen_registered]() { touchscreen_registered = true; });
239
240 RunLoopUntil([&touchscreen_registered] { return touchscreen_registered; });
241 FML_LOG(INFO) << "Touchscreen registered";
242}

◆ SetUp()

void fuchsia_test_utils::PortableUITest::SetUp ( bool  build_realm = true)

Definition at line 35 of file portable_ui_test.cc.

35 {
36 SetUpRealmBase();
38
39 if (build_realm) {
40 BuildRealm();
41 }
42}

◆ SimulateMouseEvent()

void fuchsia_test_utils::PortableUITest::SimulateMouseEvent ( std::vector< fuchsia::ui::test::input::MouseButton >  pressed_buttons,
int  movement_x,
int  movement_y 
)

Definition at line 295 of file portable_ui_test.cc.

298 {
299 fuchsia::ui::test::input::MouseSimulateMouseEventRequest request;
300 request.set_pressed_buttons(std::move(pressed_buttons));
301 request.set_movement_x(movement_x);
302 request.set_movement_y(movement_y);
303
304 FML_LOG(INFO) << "Injecting mouse input";
305
306 fake_mouse_->SimulateMouseEvent(
307 std::move(request), [] { FML_LOG(INFO) << "Mouse event injected"; });
308}

◆ SimulateMouseScroll()

void fuchsia_test_utils::PortableUITest::SimulateMouseScroll ( std::vector< fuchsia::ui::test::input::MouseButton >  pressed_buttons,
int  scroll_x,
int  scroll_y,
bool  use_physical_units = false 
)

Definition at line 310 of file portable_ui_test.cc.

314 {
315 FML_LOG(INFO) << "Requesting mouse scroll";
316 fuchsia::ui::test::input::MouseSimulateMouseEventRequest request;
317 request.set_pressed_buttons(std::move(pressed_buttons));
318 if (use_physical_units) {
319 request.set_scroll_h_physical_pixel(scroll_x);
320 request.set_scroll_v_physical_pixel(scroll_y);
321 } else {
322 request.set_scroll_h_detent(scroll_x);
323 request.set_scroll_v_detent(scroll_y);
324 }
325
326 fake_mouse_->SimulateMouseEvent(std::move(request), [] {
327 FML_LOG(INFO) << "Mouse scroll event injected";
328 });
329}

◆ SimulateTextEntry()

void fuchsia_test_utils::PortableUITest::SimulateTextEntry ( std::string  text)

Definition at line 331 of file portable_ui_test.cc.

331 {
332 FML_LOG(INFO) << "Sending text request";
333 bool done = false;
334
335 fuchsia::ui::test::input::KeyboardSimulateUsAsciiTextEntryRequest request;
336 request.set_text(text);
337 fake_keyboard_->SimulateUsAsciiTextEntry(std::move(request),
338 [&done]() { done = true; });
339
340 RunLoopUntil([&] { return done; });
341 FML_LOG(INFO) << "Text request sent";
342}
static void done(const char *config, const char *src, const char *srcOptions, const char *name)
Definition: DM.cpp:263
std::u16string text

◆ touch_injection_request_count()

int fuchsia_test_utils::PortableUITest::touch_injection_request_count ( ) const
inlineprotected

Definition at line 105 of file portable_ui_test.h.

105 {
106 return touch_injection_request_count_;
107 }

Member Data Documentation

◆ display_height_

uint32_t fuchsia_test_utils::PortableUITest::display_height_ = 0
protected

Definition at line 103 of file portable_ui_test.h.

◆ display_width_

uint32_t fuchsia_test_utils::PortableUITest::display_width_ = 0
protected

Definition at line 102 of file portable_ui_test.h.

◆ kFlutterJitRunner

constexpr auto fuchsia_test_utils::PortableUITest::kFlutterJitRunner = "flutter_jit_runner"
staticconstexpr

Definition at line 39 of file portable_ui_test.h.

◆ kFlutterJitRunnerRef

constexpr auto fuchsia_test_utils::PortableUITest::kFlutterJitRunnerRef
staticconstexpr
Initial value:
=
component_testing::ChildRef{kFlutterJitRunner}
static constexpr auto kFlutterJitRunner

Definition at line 40 of file portable_ui_test.h.

◆ kFlutterJitRunnerUrl

constexpr auto fuchsia_test_utils::PortableUITest::kFlutterJitRunnerUrl
staticconstexpr
Initial value:
=
"fuchsia-pkg://fuchsia.com/oot_flutter_jit_runner#meta/"
"flutter_jit_runner.cm"

Definition at line 42 of file portable_ui_test.h.

◆ kFlutterRunnerEnvironment

constexpr auto fuchsia_test_utils::PortableUITest::kFlutterRunnerEnvironment = "flutter_runner_env"
staticconstexpr

Definition at line 45 of file portable_ui_test.h.

◆ kPointerInjectorRegistryName

constexpr auto fuchsia_test_utils::PortableUITest::kPointerInjectorRegistryName
staticconstexpr
Initial value:
=
"fuchsia.ui.pointerinjector.Registry"

Definition at line 32 of file portable_ui_test.h.

◆ kPosixSocketProviderName

constexpr auto fuchsia_test_utils::PortableUITest::kPosixSocketProviderName
staticconstexpr
Initial value:
=
"fuchsia.posix.socket.Provider"

Definition at line 30 of file portable_ui_test.h.

◆ kTestUIStack

constexpr auto fuchsia_test_utils::PortableUITest::kTestUIStack = "ui"
staticconstexpr

Definition at line 36 of file portable_ui_test.h.

◆ kTestUIStackRef

constexpr auto fuchsia_test_utils::PortableUITest::kTestUIStackRef
staticconstexpr
Initial value:
=
component_testing::ChildRef{kTestUIStack}
static constexpr auto kTestUIStack

Definition at line 37 of file portable_ui_test.h.

◆ kVulkanLoaderServiceName

constexpr auto fuchsia_test_utils::PortableUITest::kVulkanLoaderServiceName
staticconstexpr
Initial value:
=
"fuchsia.vulkan.loader.Loader"

Definition at line 28 of file portable_ui_test.h.


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