Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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
 

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 46 of file portable_ui_test.cc.

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

Referenced by SetUp().

◆ HasViewConnected()

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

Definition at line 151 of file portable_ui_test.cc.

151 {
152 return last_view_tree_snapshot_.has_value() &&
153 CheckViewExistsInSnapshot(*last_view_tree_snapshot_, view_ref_koid);
154}
bool CheckViewExistsInSnapshot(const fuchsia::ui::observation::geometry::ViewTreeSnapshot &snapshot, zx_koid_t view_ref_koid)
Definition check_view.cc:11

References fuchsia_test_utils::CheckViewExistsInSnapshot().

Referenced by LaunchClient().

◆ InjectTap()

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

Definition at line 285 of file portable_ui_test.cc.

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

References FML_LOG, x, and y.

◆ LaunchClient()

void fuchsia_test_utils::PortableUITest::LaunchClient ( )

Definition at line 156 of file portable_ui_test.cc.

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

References FML_LOG, and HasViewConnected().

Referenced by LaunchClientWithEmbeddedView().

◆ LaunchClientWithEmbeddedView()

void fuchsia_test_utils::PortableUITest::LaunchClientWithEmbeddedView ( )

Definition at line 186 of file portable_ui_test.cc.

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

References FML_LOG, if(), LaunchClient(), and view.

◆ realm_builder()

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

Definition at line 98 of file portable_ui_test.h.

98{ return &realm_builder_; }

◆ realm_root()

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

Definition at line 99 of file portable_ui_test.h.

99{ return realm_.get(); }

◆ RegisterKeyboard()

void fuchsia_test_utils::PortableUITest::RegisterKeyboard ( )

Definition at line 266 of file portable_ui_test.cc.

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

References FML_LOG.

◆ RegisterMouse()

void fuchsia_test_utils::PortableUITest::RegisterMouse ( )

Definition at line 248 of file portable_ui_test.cc.

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

References FML_LOG.

◆ RegisterTouchScreen()

void fuchsia_test_utils::PortableUITest::RegisterTouchScreen ( )

Definition at line 229 of file portable_ui_test.cc.

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

References FML_LOG.

◆ SetUp()

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

Definition at line 37 of file portable_ui_test.cc.

37 {
38 SetUpRealmBase();
39 ExtendRealm();
40
41 if (build_realm) {
42 BuildRealm();
43 }
44}

References BuildRealm().

◆ 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 299 of file portable_ui_test.cc.

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

References FML_LOG.

◆ 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 314 of file portable_ui_test.cc.

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

References FML_LOG.

◆ SimulateTextEntry()

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

Definition at line 335 of file portable_ui_test.cc.

335 {
336 FML_LOG(INFO) << "Sending text request";
337 bool done = false;
338
339 fuchsia::ui::test::input::KeyboardSimulateUsAsciiTextEntryRequest request;
340 request.set_text(text);
341 fake_keyboard_->SimulateUsAsciiTextEntry(std::move(request),
342 [&done]() { done = true; });
343
344 RunLoopUntil([&] { return done; });
345 FML_LOG(INFO) << "Text request sent";
346}
std::u16string text

References FML_LOG, and text.

◆ touch_injection_request_count()

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

Definition at line 104 of file portable_ui_test.h.

104 {
105 return touch_injection_request_count_;
106 }

Member Data Documentation

◆ display_height_

uint32_t fuchsia_test_utils::PortableUITest::display_height_ = 0
protected

Definition at line 102 of file portable_ui_test.h.

◆ display_width_

uint32_t fuchsia_test_utils::PortableUITest::display_width_ = 0
protected

Definition at line 101 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:
=
"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 44 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}

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: