| Flutter Linux Embedder |

Functions | Variables
fl_keyboard_handler_test.cc File Reference
`#include "flutter/shell/platform/linux/fl_keyboard_handler.h"`
`#include "flutter/shell/platform/embedder/test_utils/key_codes.g.h"`
`#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"`
`#include "flutter/shell/platform/linux/fl_engine_private.h"`
`#include "flutter/shell/platform/linux/fl_method_codec_private.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"`
`#include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h"`
`#include "flutter/shell/platform/linux/testing/mock_gtk.h"`
`#include "gmock/gmock.h"`
`#include "gtest/gtest.h"`

Go to the source code of this file.

## Functions
| TEST (FlKeyboardHandlerTest, KeyboardChannelGetPressedState)

## Variables
static constexpr char | kKeyboardChannelName [] = "flutter/keyboard"
static constexpr char | kGetKeyboardStateMethod [] = "getKeyboardState"
constexpr guint16 | kKeyCodeKeyA = 0x26u

## Function Documentation

## ◆ TEST()

TEST | ( | FlKeyboardHandlerTest | ,
|  | KeyboardChannelGetPressedState |
| ) |  |

Definition at line 26 of file fl_keyboard_handler_test.cc.

26 {
27 ::testing::NiceMock<flutter::testing::MockGtk> mock_gtk;
28
29 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
30 g_autoptr(FlEngine) engine =
31 fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
32 g_autoptr(FlKeyboardManager) manager = fl_keyboard_manager_new(engine);
33
34 EXPECT_TRUE(fl_engine_start(engine, nullptr));
35
36 g_autoptr(FlKeyboardHandler) handler =
37 fl_keyboard_handler_new(FL_BINARY_MESSENGER(messenger), manager);
38 EXPECT_NE(handler, nullptr);
39
40 // Send key event to set pressed state.
41 fl_mock_binary_messenger_set_json_message_channel(
42 messenger, "flutter/keyevent",
43 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
44 gpointer user_data) {
45 FlValue* response = fl_value_new_map();
46 fl_value_set_string_take(response, "handled", fl_value_new_bool(FALSE));
47 return response;
48 },
49 nullptr);
50 fl_engine_get_embedder_api(engine)->SendKeyEvent = MOCK_ENGINE_PROC(
51 SendKeyEvent, ([](auto engine, const FlutterKeyEvent* event,
52 FlutterKeyEventCallback callback, void* user_data) {
53 callback(false, user_data);
54 return kSuccess;
55 }));
56 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
57 g_autoptr(FlKeyEvent) event = fl_key_event_new(
58 0, TRUE, kKeyCodeKeyA, GDK_KEY_a, static_cast<GdkModifierType>(0), 0);
59 fl_keyboard_manager_handle_event(
60 manager, event, nullptr,
61 [](GObject* object, GAsyncResult* result, gpointer user_data) {
62 g_autoptr(FlKeyEvent) redispatched_event = nullptr;
63 EXPECT_TRUE(fl_keyboard_manager_handle_event_finish(
64 FL_KEYBOARD_MANAGER(object), result, &redispatched_event, nullptr));
65 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
66 },
67 loop);
68 g_main_loop_run(loop);
69
70 gboolean called = FALSE;
71 fl_mock_binary_messenger_invoke_standard_method(
72 messenger, kKeyboardChannelName, kGetKeyboardStateMethod, nullptr,
73 [](FlMockBinaryMessenger* messenger, FlMethodResponse* response,
74 gpointer user_data) {
75 gboolean* called = static_cast<gboolean*>(user_data);
76 *called = TRUE;
77
78 EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
79
80 g_autoptr(FlValue) expected_result = fl_value_new_map();
81 fl_value_set_take(expected_result, fl_value_new_int(kPhysicalKeyA),
82 fl_value_new_int(kLogicalKeyA));
83 EXPECT_TRUE(fl_value_equal(fl_method_success_response_get_result(
84 FL_METHOD_SUCCESS_RESPONSE(response)),
85 expected_result));
86 },
87 &called);
88
89 EXPECT_TRUE(called);
90 }
g_autoptr
g_autoptr(GMutexLocker) locker
TRUE
return TRUE
Definition: fl_compositor_software.cc:68
fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:864
fl_engine_start
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:726
fl_engine_new_with_binary_messenger
FlEngine * fl_engine_new_with_binary_messenger(FlBinaryMessenger *binary_messenger)
Definition: fl_engine.cc:701
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90
fl_key_event_new
FlKeyEvent * fl_key_event_new(guint32 time, gboolean is_press, guint16 keycode, guint keyval, GdkModifierType state, guint8 group)
Definition: fl_key_event.cc:34
fl_keyboard_handler_new
FlKeyboardHandler * fl_keyboard_handler_new(FlBinaryMessenger *messenger, FlKeyboardManager *keyboard_manager)
Definition: fl_keyboard_handler.cc:63
kKeyboardChannelName
static constexpr char kKeyboardChannelName[]
Definition: fl_keyboard_handler_test.cc:18
kKeyCodeKeyA
constexpr guint16 kKeyCodeKeyA
Definition: fl_keyboard_handler_test.cc:24
kGetKeyboardStateMethod
static constexpr char kGetKeyboardStateMethod[]
Definition: fl_keyboard_handler_test.cc:19
fl_keyboard_manager_new
FlKeyboardManager * fl_keyboard_manager_new(FlEngine *engine)
Definition: fl_keyboard_manager.cc:356
fl_keyboard_manager_handle_event
void fl_keyboard_manager_handle_event(FlKeyboardManager *self, FlKeyEvent *event, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_keyboard_manager.cc:374
fl_keyboard_manager_handle_event_finish
gboolean fl_keyboard_manager_handle_event_finish(FlKeyboardManager *self, GAsyncResult *result, FlKeyEvent **redispatched_event, GError **error)
Definition: fl_keyboard_manager.cc:410
fl_method_success_response_get_result
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)
Definition: fl_method_response.cc:138
fl_value_set_string_take
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:650
fl_value_new_bool
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255
fl_value_set_take
G_MODULE_EXPORT void fl_value_set_take(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:618
fl_value_equal
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
fl_value_new_map
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:366
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42

References fl_engine_get_embedder_api(), fl_engine_new_with_binary_messenger(), fl_engine_start(), fl_key_event_new(), fl_keyboard_handler_new(), fl_keyboard_manager_handle_event(), fl_keyboard_manager_handle_event_finish(), fl_keyboard_manager_new(), fl_method_success_response_get_result(), fl_value_equal(), fl_value_new_bool(), fl_value_new_int(), fl_value_new_map(), fl_value_set_string_take(), fl_value_set_take(), g_autoptr(), kGetKeyboardStateMethod, kKeyboardChannelName, kKeyCodeKeyA, TRUE, and user_data.

## Variable Documentation

## ◆ kGetKeyboardStateMethod

constexpr char kGetKeyboardStateMethod[] = "getKeyboardState"
| staticconstexpr

Definition at line 19 of file fl_keyboard_handler_test.cc.

Referenced by TEST().

## ◆ kKeyboardChannelName

constexpr char kKeyboardChannelName[] = "flutter/keyboard"
| staticconstexpr

Definition at line 18 of file fl_keyboard_handler_test.cc.

Referenced by TEST().

## ◆ kKeyCodeKeyA

constexpr guint16 kKeyCodeKeyA = 0x26u
| constexpr

Definition at line 24 of file fl_keyboard_handler_test.cc.

Referenced by TEST().