Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
portable_ui_test.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_PORTABLE_UI_TEST_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_PORTABLE_UI_TEST_H_
7
8#include <fuchsia/sysmem/cpp/fidl.h>
9#include <fuchsia/ui/app/cpp/fidl.h>
10#include <fuchsia/ui/composition/cpp/fidl.h>
11#include <fuchsia/ui/display/singleton/cpp/fidl.h>
12#include <fuchsia/ui/input/cpp/fidl.h>
13#include <fuchsia/ui/test/input/cpp/fidl.h>
14#include <fuchsia/ui/test/scene/cpp/fidl.h>
15#include <lib/async-loop/testing/cpp/real_loop.h>
16#include <lib/sys/component/cpp/testing/realm_builder.h>
17#include <lib/sys/component/cpp/testing/realm_builder_types.h>
18#include <zircon/status.h>
19
20#include <optional>
21#include <vector>
22
23namespace fuchsia_test_utils {
24class PortableUITest : public ::loop_fixture::RealLoop {
25 public:
26 // The FIDL bindings for these services are not exposed in the Fuchsia SDK so
27 // we must encode the names manually here.
28 static constexpr auto kVulkanLoaderServiceName =
29 "fuchsia.vulkan.loader.Loader";
30 static constexpr auto kPosixSocketProviderName =
31 "fuchsia.posix.socket.Provider";
32 static constexpr auto kPointerInjectorRegistryName =
33 "fuchsia.ui.pointerinjector.Registry";
34
35 // The naming and references used by Realm Builder
36 static constexpr auto kTestUIStack = "ui";
37 static constexpr auto kTestUIStackRef =
38 component_testing::ChildRef{kTestUIStack};
39 static constexpr auto kFlutterJitRunner = "flutter_jit_runner";
40 static constexpr auto kFlutterJitRunnerRef =
41 component_testing::ChildRef{kFlutterJitRunner};
42 static constexpr auto kFlutterJitRunnerUrl =
43 "fuchsia-pkg://fuchsia.com/oot_flutter_jit_runner#meta/"
44 "flutter_jit_runner.cm";
45 static constexpr auto kFlutterRunnerEnvironment = "flutter_runner_env";
46
47 void SetUp(bool build_realm = true);
48
49 // Calls the Build method for Realm Builder to build the realm
50 // Can only be called once, panics otherwise
51 void BuildRealm();
52
53 // Attaches a client view to the scene, and waits for it to render.
54 void LaunchClient();
55 // Attaches a view with an embedded child view to the scene, and waits for it
56 // to render.
58
59 // Returns true when the specified view is fully connected to the scene AND
60 // has presented at least one frame of content.
61 bool HasViewConnected(zx_koid_t view_ref_koid);
62
63 // Registers a fake touch screen device with an injection coordinate space
64 // spanning [-1000, 1000] on both axes.
66
67 // Registers a fake mouse device, for which mouse movement is measured on a
68 // scale of [-1000, 1000] on both axes and scroll is measured from [-100, 100]
69 // on both axes.
70 void RegisterMouse();
71
72 // Register a fake keyboard
73 void RegisterKeyboard();
74
75 // Simulates a tap at location (x, y).
76 void InjectTap(int32_t x, int32_t y);
77
78 // Helper method to simulate combinations of button presses/releases and/or
79 // mouse movements.
81 std::vector<fuchsia::ui::test::input::MouseButton> pressed_buttons,
82 int movement_x,
83 int movement_y);
84
85 // Helper method to simulate a mouse scroll event.
86 //
87 // Set `use_physical_units` to true to specify scroll in physical pixels and
88 // false to specify scroll in detents.
90 std::vector<fuchsia::ui::test::input::MouseButton> pressed_buttons,
91 int scroll_x,
92 int scroll_y,
93 bool use_physical_units = false);
94
95 // Helper method to simluate text input
96 void SimulateTextEntry(std::string text);
97
98 protected:
99 component_testing::RealmBuilder* realm_builder() { return &realm_builder_; }
100 component_testing::RealmRoot* realm_root() { return realm_.get(); }
101
102 uint32_t display_width_ = 0;
103 uint32_t display_height_ = 0;
104
106 return touch_injection_request_count_;
107 }
108
109 private:
110 void SetUpRealmBase();
111
112 // Configures the test-specific component topology.
113 virtual void ExtendRealm() = 0;
114
115 // Returns the test-specific test-ui-stack component url to use.
116 // Usually overridden to return a value from gtest GetParam()
117 virtual std::string GetTestUIStackUrl() = 0;
118
119 // Helper method to watch for view geometry updates.
120 void WatchViewGeometry();
121
122 // Helper method to process a view geometry update.
123 void ProcessViewGeometryResponse(
124 fuchsia::ui::observation::geometry::WatchResponse response);
125
126 fuchsia::ui::test::input::RegistryPtr input_registry_;
127 fuchsia::ui::test::input::TouchScreenPtr fake_touchscreen_;
128 fuchsia::ui::test::input::MousePtr fake_mouse_;
129 fuchsia::ui::test::input::KeyboardPtr fake_keyboard_;
130 fuchsia::ui::test::scene::ControllerPtr scene_provider_;
131 fuchsia::ui::observation::geometry::ViewTreeWatcherPtr view_tree_watcher_;
132
133 component_testing::RealmBuilder realm_builder_ =
134 component_testing::RealmBuilder::Create();
135 std::unique_ptr<component_testing::RealmRoot> realm_;
136
137 // Counts the number of completed requests to inject touch reports into input
138 // pipeline.
139 int touch_injection_request_count_ = 0;
140
141 // The KOID of the client root view's `ViewRef`.
142 std::optional<zx_koid_t> client_root_view_ref_koid_;
143
144 // Holds the most recent view tree snapshot received from the view tree
145 // watcher.
146 //
147 // From this snapshot, we can retrieve relevant view tree state on demand,
148 // e.g. if the client view is rendering content.
149 std::optional<fuchsia::ui::observation::geometry::ViewTreeSnapshot>
150 last_view_tree_snapshot_;
151};
152
153} // namespace fuchsia_test_utils
154
155#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_PORTABLE_UI_TEST_H_
static constexpr auto kFlutterRunnerEnvironment
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)
static constexpr auto kFlutterJitRunnerRef
static constexpr auto kPointerInjectorRegistryName
void InjectTap(int32_t x, int32_t y)
virtual std::string GetTestUIStackUrl()=0
bool HasViewConnected(zx_koid_t view_ref_koid)
static constexpr auto kTestUIStackRef
void SimulateTextEntry(std::string text)
component_testing::RealmRoot * realm_root()
static constexpr auto kFlutterJitRunner
static constexpr auto kFlutterJitRunnerUrl
static constexpr auto kVulkanLoaderServiceName
static constexpr auto kPosixSocketProviderName
void SetUp(bool build_realm=true)
component_testing::RealmBuilder * realm_builder()
std::u16string text
double y
double x