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

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

Referenced by SetUp().

◆ HasViewConnected()

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

Definition at line 149 of file portable_ui_test.cc.

149 {
150 return last_view_tree_snapshot_.has_value() &&
151 CheckViewExistsInSnapshot(*last_view_tree_snapshot_, view_ref_koid);
152}
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 283 of file portable_ui_test.cc.

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

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

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

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

References FML_LOG.

◆ RegisterMouse()

void fuchsia_test_utils::PortableUITest::RegisterMouse ( )

Definition at line 246 of file portable_ui_test.cc.

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

References FML_LOG.

◆ RegisterTouchScreen()

void fuchsia_test_utils::PortableUITest::RegisterTouchScreen ( )

Definition at line 227 of file portable_ui_test.cc.

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

References FML_LOG.

◆ SetUp()

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

Definition at line 36 of file portable_ui_test.cc.

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

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

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

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

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

References FML_LOG.

◆ SimulateTextEntry()

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

Definition at line 333 of file portable_ui_test.cc.

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