Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 42 of file portable_ui_test.cc.

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

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

140 {
141 return last_view_tree_snapshot_.has_value() &&
142 CheckViewExistsInSnapshot(*last_view_tree_snapshot_, view_ref_koid);
143}
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 274 of file portable_ui_test.cc.

274 {
275 fuchsia::ui::test::input::TouchScreenSimulateTapRequest tap_request;
276 tap_request.mutable_tap_location()->x = x;
277 tap_request.mutable_tap_location()->y = y;
278
279 FML_LOG(INFO) << "Injecting tap at (" << tap_request.tap_location().x << ", "
280 << tap_request.tap_location().y << ")";
281 fake_touchscreen_->SimulateTap(std::move(tap_request), [this]() {
282 ++touch_injection_request_count_;
283 FML_LOG(INFO) << "*** Tap injected, count: "
284 << touch_injection_request_count_;
285 });
286}
#define FML_LOG(severity)
Definition logging.h:82
double y
double x

◆ LaunchClient()

void fuchsia_test_utils::PortableUITest::LaunchClient ( )

Definition at line 145 of file portable_ui_test.cc.

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

◆ LaunchClientWithEmbeddedView()

void fuchsia_test_utils::PortableUITest::LaunchClientWithEmbeddedView ( )

Definition at line 175 of file portable_ui_test.cc.

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

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

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

◆ RegisterMouse()

void fuchsia_test_utils::PortableUITest::RegisterMouse ( )

Definition at line 237 of file portable_ui_test.cc.

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

◆ RegisterTouchScreen()

void fuchsia_test_utils::PortableUITest::RegisterTouchScreen ( )

Definition at line 218 of file portable_ui_test.cc.

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

◆ SetUp()

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

Definition at line 33 of file portable_ui_test.cc.

33 {
34 SetUpRealmBase();
36
37 if (build_realm) {
38 BuildRealm();
39 }
40}

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

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

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

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

◆ SimulateTextEntry()

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

Definition at line 324 of file portable_ui_test.cc.

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

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: