5#include <fuchsia/feedback/cpp/fidl.h>
6#include <fuchsia/logger/cpp/fidl.h>
7#include <fuchsia/sysmem/cpp/fidl.h>
8#include <fuchsia/tracing/provider/cpp/fidl.h>
9#include <fuchsia/ui/app/cpp/fidl.h>
10#include <fuchsia/ui/display/singleton/cpp/fidl.h>
11#include <fuchsia/ui/input/cpp/fidl.h>
12#include <fuchsia/ui/test/input/cpp/fidl.h>
13#include <fuchsia/ui/test/scene/cpp/fidl.h>
14#include <lib/async-loop/testing/cpp/real_loop.h>
15#include <lib/async/cpp/task.h>
16#include <lib/fidl/cpp/binding_set.h>
17#include <lib/sys/component/cpp/testing/realm_builder.h>
18#include <lib/sys/component/cpp/testing/realm_builder_types.h>
19#include <lib/zx/clock.h>
20#include <lib/zx/time.h>
21#include <zircon/status.h>
22#include <zircon/types.h>
23#include <zircon/utc.h>
33#include <gtest/gtest.h>
35#include "flutter/fml/logging.h"
36#include "flutter/shell/platform/fuchsia/flutter/tests/integration/utils/check_view.h"
37#include "flutter/shell/platform/fuchsia/flutter/tests/integration/utils/portable_ui_test.h"
42using component_testing::ChildRef;
43using component_testing::LocalComponentImpl;
44using component_testing::ParentRef;
45using component_testing::Protocol;
46using component_testing::RealmBuilder;
47using component_testing::RealmRoot;
48using component_testing::Route;
57constexpr auto kKeyboardInputListener =
"keyboard_input_listener";
58constexpr auto kKeyboardInputListenerRef = ChildRef{kKeyboardInputListener};
60constexpr auto kTextInputView =
"text-input-view";
61constexpr auto kTextInputViewRef = ChildRef{kTextInputView};
62static constexpr auto kTextInputViewUrl =
63 "fuchsia-pkg://fuchsia.com/text-input-view#meta/text-input-view.cm";
65constexpr auto kTestUIStackUrl =
66 "fuchsia-pkg://fuchsia.com/flatland-scene-manager-test-ui-stack#meta/"
75class KeyboardInputListenerServer
76 :
public fuchsia::ui::test::input::KeyboardInputListener,
77 public LocalComponentImpl {
79 explicit KeyboardInputListenerServer(async_dispatcher_t* dispatcher)
80 : dispatcher_(dispatcher) {}
84 fuchsia::ui::test::input::KeyboardInputListenerReportTextInputRequest
86 FML_LOG(INFO) <<
"Flutter app sent: '" << request.text() <<
"'";
87 response_list_.push_back(request.text());
91 void OnStart()
override {
92 FML_LOG(INFO) <<
"Starting KeyboardInputListenerServer";
93 ASSERT_EQ(ZX_OK, outgoing()->AddPublicService(
94 bindings_.GetHandler(
this, dispatcher_)));
98 bool HasResponse(
const std::vector<std::string>& expected) {
99 if (response_list_.size() != expected.size()) {
106 for (
size_t i = 0;
i < expected.size(); ++
i) {
107 if (response_list_[
i] != expected[
i]) {
116 void ReportReady(ReportReadyCallback
callback)
override {
117 FML_LOG(INFO) <<
"ReportReady callback ready";
123 async_dispatcher_t* dispatcher_ =
nullptr;
124 fidl::BindingSet<fuchsia::ui::test::input::KeyboardInputListener> bindings_;
125 std::vector<std::string> response_list_;
129class TextInputTest :
public PortableUITest,
130 public ::testing::Test,
131 public ::testing::WithParamInterface<std::string> {
133 void SetUp()
override {
134 PortableUITest::SetUp();
137 async::PostDelayedTask(
141 <<
"\n\n>> Test did not complete in time, terminating. <<\n\n";
147 <<
"Waiting for display info from fuchsia.ui.display.singleton.Info";
148 fuchsia::ui::display::singleton::InfoPtr display_info =
151 .Connect<fuchsia::ui::display::singleton::Info>();
152 display_info->GetMetrics(
153 [
this](fuchsia::ui::display::singleton::Metrics metrics) {
154 display_width_ = metrics.extent_in_px().width;
155 display_height_ = metrics.extent_in_px().height;
156 FML_LOG(INFO) <<
"Got display_width = " << display_width_
157 <<
" and display_height = " << display_height_;
160 [
this] {
return display_width_ != 0 && display_height_ != 0; });
163 FML_LOG(INFO) <<
"Registering input injection device";
168 uint32_t display_width()
const {
return display_width_; }
169 uint32_t display_height()
const {
return display_height_; }
171 std::string GetTestUIStackUrl()
override {
return GetParam(); };
173 KeyboardInputListenerServer* keyboard_input_listener_server_;
176 void ExtendRealm()
override {
177 FML_LOG(INFO) <<
"Extending realm";
180 auto keyboard_input_listener_server =
181 std::make_unique<KeyboardInputListenerServer>(dispatcher());
182 keyboard_input_listener_server_ = keyboard_input_listener_server.get();
183 realm_builder()->AddLocalChild(
184 kKeyboardInputListener,
185 [keyboard_input_listener_server =
186 std::move(keyboard_input_listener_server)]()
mutable {
187 return std::move(keyboard_input_listener_server);
191 realm_builder()->AddChild(kTextInputView, kTextInputViewUrl,
192 component_testing::ChildOptions{
193 .environment = kFlutterRunnerEnvironment,
197 realm_builder()->AddRoute(
198 Route{.capabilities = {Protocol{
199 fuchsia::ui::test::input::KeyboardInputListener::Name_}},
200 .source = kKeyboardInputListenerRef,
201 .targets = {kFlutterJitRunnerRef, kTextInputViewRef}});
204 realm_builder()->AddRoute(
205 Route{.capabilities = {Protocol{fuchsia::ui::app::ViewProvider::Name_}},
206 .source = kTextInputViewRef,
207 .targets = {ParentRef()}});
209 realm_builder()->AddRoute(Route{
211 {Protocol{fuchsia::ui::input3::Keyboard::Name_},
212 Protocol{
"fuchsia.accessibility.semantics.SemanticsManager"}},
213 .source = kTestUIStackRef,
214 .targets = {ParentRef(), kFlutterJitRunnerRef}});
220 ::testing::Values(kTestUIStackUrl));
222TEST_P(TextInputTest, TextInput) {
224 FML_LOG(INFO) <<
"Initializing scene";
226 FML_LOG(INFO) <<
"Client launched";
228 SimulateTextEntry(
"Hello\nworld!");
229 std::vector<std::string> expected = {
"LEFT_SHIFT",
"H",
"E",
"L",
"L",
"O",
230 "ENTER",
"W",
"O",
"R",
"L",
"D",
231 "LEFT_SHIFT",
"KEY_1"};
234 [&] {
return keyboard_input_listener_server_->HasResponse(expected); });
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_LOG(severity)
static float min(float r, float g, float b)
INSTANTIATE_TEST_SUITE_P(EmbedderTestGlVk, EmbedderTestMultiBackend, ::testing::Values(EmbedderTestContextType::kOpenGLContext, EmbedderTestContextType::kVulkanContext))
bool CheckViewExistsInUpdates(const std::vector< fuchsia::ui::observation::geometry::ViewTreeSnapshot > &updates, zx_koid_t view_ref_koid)
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)