Flutter Engine
 
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 44 of file portable_ui_test.cc.

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

Referenced by SetUp().

◆ HasViewConnected()

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

Definition at line 143 of file portable_ui_test.cc.

143 {
144 return last_view_tree_snapshot_.has_value() &&
145 CheckViewExistsInSnapshot(*last_view_tree_snapshot_, view_ref_koid);
146}
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 277 of file portable_ui_test.cc.

277 {
278 fuchsia::ui::test::input::TouchScreenSimulateTapRequest tap_request;
279 tap_request.mutable_tap_location()->x = x;
280 tap_request.mutable_tap_location()->y = y;
281
282 FML_LOG(INFO) << "Injecting tap at (" << tap_request.tap_location().x << ", "
283 << tap_request.tap_location().y << ")";
284 fake_touchscreen_->SimulateTap(std::move(tap_request), [this]() {
285 ++touch_injection_request_count_;
286 FML_LOG(INFO) << "*** Tap injected, count: "
287 << touch_injection_request_count_;
288 });
289}
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 148 of file portable_ui_test.cc.

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

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

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

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

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

References FML_LOG.

◆ RegisterMouse()

void fuchsia_test_utils::PortableUITest::RegisterMouse ( )

Definition at line 240 of file portable_ui_test.cc.

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

References FML_LOG.

◆ RegisterTouchScreen()

void fuchsia_test_utils::PortableUITest::RegisterTouchScreen ( )

Definition at line 221 of file portable_ui_test.cc.

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

References FML_LOG.

◆ SetUp()

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

Definition at line 35 of file portable_ui_test.cc.

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

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

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

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

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

References FML_LOG.

◆ SimulateTextEntry()

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

Definition at line 327 of file portable_ui_test.cc.

327 {
328 FML_LOG(INFO) << "Sending text request";
329 bool done = false;
330
331 fuchsia::ui::test::input::KeyboardSimulateUsAsciiTextEntryRequest request;
332 request.set_text(text);
333 fake_keyboard_->SimulateUsAsciiTextEntry(std::move(request),
334 [&done]() { done = true; });
335
336 RunLoopUntil([&] { return done; });
337 FML_LOG(INFO) << "Text request sent";
338}
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 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}

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: