7#include <fuchsia/ui/input/cpp/fidl.h>
8#include <fuchsia/ui/input3/cpp/fidl.h>
9#include <fuchsia/ui/views/cpp/fidl.h>
10#include <gtest/gtest.h>
11#include <lib/async-loop/cpp/loop.h>
12#include <lib/async-loop/default.h>
13#include <lib/fidl/cpp/binding.h>
14#include <lib/fidl/cpp/binding_set.h>
15#include <lib/zx/eventpair.h>
19#include "flutter/lib/ui/window/platform_message.h"
27 const char*
data =
reinterpret_cast<const char*
>(
message.data().GetMapping());
37 fuchsia::ui::views::ViewRef,
38 fidl::InterfaceHandle<fuchsia::ui::input3::KeyboardListener> listener,
39 fuchsia::ui::input3::Keyboard::AddListenerCallback
callback) {
44 fidl::InterfacePtr<fuchsia::ui::input3::KeyboardListener>
listener_;
52 fuchsia::ui::input::KeyboardType keyboard_type,
53 fuchsia::ui::input::InputMethodAction
action,
54 fuchsia::ui::input::TextInputState input_state,
55 fidl::InterfaceHandle<fuchsia::ui::input::InputMethodEditorClient> client,
56 fidl::InterfaceRequest<fuchsia::ui::input::InputMethodEditor> ime) {
61 ime_ = std::move(ime);
73 fuchsia::ui::input::InputMethodAction
action_;
75 fidl::InterfacePtr<fuchsia::ui::input::InputMethodEditorClient>
client_;
76 fidl::InterfaceRequest<fuchsia::ui::input::InputMethodEditor>
ime_;
82 :
loop_(&kAsyncLoopConfigAttachToCurrentThread),
85 fidl::InterfaceHandle<fuchsia::ui::input3::Keyboard> keyboard_handle;
86 auto keyboard_request = keyboard_handle.NewRequest();
89 fidl::InterfaceHandle<fuchsia::ui::input::ImeService> ime_service_handle;
92 fuchsia::ui::views::ViewRefControl view_ref_control;
93 fuchsia::ui::views::ViewRef view_ref;
95 0u, &view_ref_control.reference, &view_ref.reference);
96 ZX_ASSERT(status == ZX_OK);
97 view_ref.reference.replace(ZX_RIGHTS_BASIC, &view_ref.reference);
100 std::move(view_ref), std::move(ime_service_handle),
101 std::move(keyboard_handle),
103 [
this](std::unique_ptr<flutter::PlatformMessage>
message) {
116 ASSERT_EQ(
loop_.ResetQuit(), 0);
144 const auto set_client_msg = R
"(
146 "method": "TextInput.setClient",
151 "name": "TextInputType.multiline",
156 "obscureText": false,
158 "smartDashesType":"1",
159 "smartQuotesType":"1",
160 "enableSuggestions":true,
161 "enableInteractiveSelection":true,
163 "inputAction":"TextInputAction.newline",
164 "textCapitalization":"TextCapitalization.none",
165 "keyboardAppearance":"Brightness.dark",
166 "enableIMEPersonalizedLearning":true,
167 "enableDeltaModel":false
172 auto message = fake_platform_message_response->WithMessage(
174 text_delegate_->HandleFlutterTextInputChannelPlatformMessage(
177 EXPECT_EQ(ime_service_.action_,
178 fuchsia::ui::input::InputMethodAction::NEWLINE);
179 EXPECT_FALSE(ime_service_.IsKeyboardShown());
184 const auto set_client_msg = R
"(
186 "method": "TextInput.show"
189 auto message = fake_platform_message_response->WithMessage(
191 text_delegate_->HandleFlutterTextInputChannelPlatformMessage(
199 const auto set_client_msg = R
"(
201 "method": "TextInput.hide"
204 auto message = fake_platform_message_response->WithMessage(
206 text_delegate_->HandleFlutterTextInputChannelPlatformMessage(
209 EXPECT_FALSE(ime_service_.IsKeyboardShown());
214 fuchsia::ui::input::TextInputState
state = {
217 .selection = fuchsia::ui::input::TextSelection{},
220 auto input_event = std::make_unique<fuchsia::ui::input::InputEvent>();
221 ime_service_.client_->DidUpdateState(std::move(
state),
222 std::move(input_event));
225 R
"({"method":"TextInputClient.updateEditingState","args":[7,{"text":"Foo","selectionBase":0,"selectionExtent":0,"selectionAffinity":"TextAffinity.upstream","selectionIsDirectional":true,"composingBase":-1,"composingExtent":-1}]})",
231 ime_service_.client_->OnAction(fuchsia::ui::input::InputMethodAction::DONE);
234 R
"({"method":"TextInputClient.performAction","args":[7,"TextInputAction.done"]})",
246 *
key_event.mutable_type() = fuchsia::ui::input3::KeyEventType::PRESSED;
248 key_event.mutable_key_meaning()->set_codepoint(
'a');
250 fuchsia::ui::input3::KeyEventStatus status;
251 keyboard_service_.listener_->OnKeyEvent(
252 std::move(
key_event), [&status](fuchsia::ui::input3::KeyEventStatus
s) {
253 status = std::move(
s);
256 EXPECT_EQ(fuchsia::ui::input3::KeyEventStatus::HANDLED, status);
258 R
"({"type":"keydown","keymap":"fuchsia","hidUsage":458756,"codePoint":97,"modifiers":0})",
266 *
key_event.mutable_type() = fuchsia::ui::input3::KeyEventType::SYNC;
268 fuchsia::ui::input3::KeyEventStatus status;
269 keyboard_service_.listener_->OnKeyEvent(
270 std::move(
key_event), [&status](fuchsia::ui::input3::KeyEventStatus
s) {
271 status = std::move(
s);
274 EXPECT_EQ(fuchsia::ui::input3::KeyEventStatus::NOT_HANDLED, status);
281 *
key_event.mutable_type() = fuchsia::ui::input3::KeyEventType::CANCEL;
283 fuchsia::ui::input3::KeyEventStatus status;
284 keyboard_service_.listener_->OnKeyEvent(
285 std::move(
key_event), [&status](fuchsia::ui::input3::KeyEventStatus
s) {
286 status = std::move(
s);
289 EXPECT_EQ(fuchsia::ui::input3::KeyEventStatus::NOT_HANDLED, status);
virtual void HideKeyboard()
fidl::InterfacePtr< fuchsia::ui::input::InputMethodEditorClient > client_
virtual void ShowKeyboard()
fuchsia::ui::input::InputMethodAction action_
fuchsia::ui::input::TextInputState input_state_
fuchsia::ui::input::KeyboardType keyboard_type_
fidl::InterfaceRequest< fuchsia::ui::input::InputMethodEditor > ime_
virtual void GetInputMethodEditor(fuchsia::ui::input::KeyboardType keyboard_type, fuchsia::ui::input::InputMethodAction action, fuchsia::ui::input::TextInputState input_state, fidl::InterfaceHandle< fuchsia::ui::input::InputMethodEditorClient > client, fidl::InterfaceRequest< fuchsia::ui::input::InputMethodEditor > ime)
virtual void AddListener(fuchsia::ui::views::ViewRef, fidl::InterfaceHandle< fuchsia::ui::input3::KeyboardListener > listener, fuchsia::ui::input3::Keyboard::AddListenerCallback callback)
fidl::InterfacePtr< fuchsia::ui::input3::KeyboardListener > listener_
std::unique_ptr< TextDelegate > text_delegate_
fidl::Binding< fuchsia::ui::input3::Keyboard > keyboard_service_binding_
FakeKeyboardService keyboard_service_
fidl::Binding< fuchsia::ui::input::ImeService > ime_service_binding_
std::unique_ptr< flutter::PlatformMessage > last_message_
FakeImeService ime_service_
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
FlutterKeyEvent key_event
static std::string MessageToString(PlatformMessage &message)
TEST_F(FocusDelegateTest, WatchCallbackSeries)
constexpr char kTextInputChannel[]
The channel name used for text editing platofrm messages.
SkRange< size_t > TextRange
std::shared_ptr< const fml::Mapping > data
#define EXPECT_TRUE(handle)