| Flutter Linux Embedder |

Classes | Functions
fl_key_channel_responder_test.cc File Reference
`#include "flutter/shell/platform/linux/fl_key_channel_responder.h"`
`#include "gtest/gtest.h"`
`#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"`
`#include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h"`

Go to the source code of this file.

## Classes
struct | KeyEventData

## Functions
static void | set_key_event_channel (FlMockBinaryMessenger *messenger, const gchar *expected_message, gboolean handled)
| TEST (FlKeyChannelResponderTest, SendKeyEvent)
void | test_lock_event (guint key_code, const char *down_expected, const char *up_expected)
| TEST (FlKeyChannelResponderTest, SendNumLockKeyEvent)
| TEST (FlKeyChannelResponderTest, SendCapsLockKeyEvent)
| TEST (FlKeyChannelResponderTest, SendShiftLockKeyEvent)
| TEST (FlKeyChannelResponderTest, TestKeyEventHandledByFramework)
| TEST (FlKeyChannelResponderTest, UseSpecifiedLogicalKey)

## Function Documentation

## ◆ set_key_event_channel()

static void set_key_event_channel | ( | FlMockBinaryMessenger * | messenger,
|  | const gchar * | expected_message,
|  | gboolean | handled
| ) |  |
| static

Definition at line 17 of file fl_key_channel_responder_test.cc.

19 {
20 KeyEventData* data = g_new0(KeyEventData, 1);
21 data->expected_message = expected_message;
22 data->handled = handled;
23 fl_mock_binary_messenger_set_json_message_channel(
24 messenger, "flutter/keyevent",
25 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
26 gpointer user_data) {
27 g_autofree KeyEventData* data = static_cast<KeyEventData*>(user_data);
28
29 g_autofree gchar* message_string = fl_value_to_string(message);
30 EXPECT_STREQ(message_string, data->expected_message);
31
32 FlValue* response = fl_value_new_map();
33 fl_value_set_string_take(response, "handled",
34 fl_value_new_bool(data->handled));
35
36 return response;
37 },
38 data);
39 }
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90
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_to_string
G_MODULE_EXPORT gchar * fl_value_to_string(FlValue *value)
Definition: fl_value.cc:846
fl_value_new_bool
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255
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
KeyEventData
Definition: fl_key_channel_responder_test.cc:12
KeyEventData::handled
gboolean handled
Definition: fl_key_channel_responder_test.cc:14
KeyEventData::expected_message
const gchar * expected_message
Definition: fl_key_channel_responder_test.cc:13

References KeyEventData::expected_message, fl_value_new_bool(), fl_value_new_map(), fl_value_set_string_take(), fl_value_to_string(), KeyEventData::handled, and user_data.

Referenced by TEST(), and test_lock_event().

## ◆ TEST() [1/6]

TEST | ( | FlKeyChannelResponderTest | ,
|  | SendCapsLockKeyEvent |
| ) |  |

Definition at line 142 of file fl_key_channel_responder_test.cc.

142 {
143 test_lock_event(GDK_KEY_Caps_Lock,
144 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
145 "keyCode: 65509, modifiers: 2}",
146 "{type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, "
147 "keyCode: 65509, modifiers: 0}");
148 }
test_lock_event
void test_lock_event(guint key_code, const char *down_expected, const char *up_expected)
Definition: fl_key_channel_responder_test.cc:90

References test_lock_event().

## ◆ TEST() [2/6]

TEST | ( | FlKeyChannelResponderTest | ,
|  | SendKeyEvent |
| ) |  |

Definition at line 42 of file fl_key_channel_responder_test.cc.

42 {
43 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
44
45 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
46 g_autoptr(FlKeyChannelResponder) responder =
47 fl_key_channel_responder_new(FL_BINARY_MESSENGER(messenger));
48
49 set_key_event_channel(
50 messenger,
51 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65, "
52 "modifiers: 0, unicodeScalarValues: 65}",
53 FALSE);
54 g_autoptr(FlKeyEvent) event1 = fl_key_event_new(
55 12345, TRUE, 0x04, GDK_KEY_A, static_cast<GdkModifierType>(0), 0);
56 fl_key_channel_responder_handle_event(
57 responder, event1, 0, nullptr,
58 [](GObject* object, GAsyncResult* result, gpointer user_data) {
59 gboolean handled;
60 EXPECT_TRUE(fl_key_channel_responder_handle_event_finish(
61 FL_KEY_CHANNEL_RESPONDER(object), result, &handled, nullptr));
62 EXPECT_FALSE(handled);
63 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
64 },
65 loop);
66 g_main_loop_run(loop);
67
68 set_key_event_channel(
69 messenger,
70 "{type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65, "
71 "modifiers: 0, unicodeScalarValues: 65}",
72 FALSE);
73 g_autoptr(FlKeyEvent) event2 = fl_key_event_new(
74 23456, FALSE, 0x04, GDK_KEY_A, static_cast<GdkModifierType>(0), 0);
75 fl_key_channel_responder_handle_event(
76 responder, event2, 0, nullptr,
77 [](GObject* object, GAsyncResult* result, gpointer user_data) {
78 gboolean handled;
79 EXPECT_TRUE(fl_key_channel_responder_handle_event_finish(
80 FL_KEY_CHANNEL_RESPONDER(object), result, &handled, nullptr));
81 EXPECT_FALSE(handled);
82 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
83 },
84 loop);
85 g_main_loop_run(loop);
86
87 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
88 }
fl_binary_messenger_shutdown
void fl_binary_messenger_shutdown(FlBinaryMessenger *self)
Definition: fl_binary_messenger.cc:500
g_autoptr
g_autoptr(GMutexLocker) locker
TRUE
return TRUE
Definition: fl_compositor_software.cc:69
fl_key_channel_responder_handle_event
void fl_key_channel_responder_handle_event(FlKeyChannelResponder *self, FlKeyEvent *event, uint64_t specified_logical_key, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_key_channel_responder.cc:71
fl_key_channel_responder_handle_event_finish
gboolean fl_key_channel_responder_handle_event_finish(FlKeyChannelResponder *self, GAsyncResult *result, gboolean *handled, GError **error)
Definition: fl_key_channel_responder.cc:139
fl_key_channel_responder_new
FlKeyChannelResponder * fl_key_channel_responder_new(FlBinaryMessenger *messenger)
Definition: fl_key_channel_responder.cc:59
set_key_event_channel
static void set_key_event_channel(FlMockBinaryMessenger *messenger, const gchar *expected_message, gboolean handled)
Definition: fl_key_channel_responder_test.cc:17
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

References fl_binary_messenger_shutdown(), fl_key_channel_responder_handle_event(), fl_key_channel_responder_handle_event_finish(), fl_key_channel_responder_new(), fl_key_event_new(), g_autoptr(), set_key_event_channel(), TRUE, and user_data.

## ◆ TEST() [3/6]

TEST | ( | FlKeyChannelResponderTest | ,
|  | SendNumLockKeyEvent |
| ) |  |

Definition at line 133 of file fl_key_channel_responder_test.cc.

133 {
134 test_lock_event(GDK_KEY_Num_Lock,
135 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
136 "keyCode: 65407, modifiers: 16}",
137 "{type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, "
138 "keyCode: 65407, modifiers: 0}");
139 }

References test_lock_event().

## ◆ TEST() [4/6]

TEST | ( | FlKeyChannelResponderTest | ,
|  | SendShiftLockKeyEvent |
| ) |  |

Definition at line 151 of file fl_key_channel_responder_test.cc.

151 {
152 test_lock_event(GDK_KEY_Shift_Lock,
153 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
154 "keyCode: 65510, modifiers: 2}",
155 "{type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, "
156 "keyCode: 65510, modifiers: 0}");
157 }

References test_lock_event().

## ◆ TEST() [5/6]

TEST | ( | FlKeyChannelResponderTest | ,
|  | TestKeyEventHandledByFramework |
| ) |  |

Definition at line 159 of file fl_key_channel_responder_test.cc.

159 {
160 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
161
162 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
163 g_autoptr(FlKeyChannelResponder) responder =
164 fl_key_channel_responder_new(FL_BINARY_MESSENGER(messenger));
165
166 set_key_event_channel(
167 messenger,
168 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
169 "keyCode: 65, modifiers: 0, unicodeScalarValues: 65}",
170 TRUE);
171 g_autoptr(FlKeyEvent) event = fl_key_event_new(
172 12345, TRUE, 0x04, GDK_KEY_A, static_cast<GdkModifierType>(0), 0);
173 fl_key_channel_responder_handle_event(
174 responder, event, 0, nullptr,
175 [](GObject* object, GAsyncResult* result, gpointer user_data) {
176 gboolean handled;
177 EXPECT_TRUE(fl_key_channel_responder_handle_event_finish(
178 FL_KEY_CHANNEL_RESPONDER(object), result, &handled, nullptr));
179 EXPECT_TRUE(handled);
180 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
181 },
182 loop);
183 g_main_loop_run(loop);
184
185 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
186 }

References fl_binary_messenger_shutdown(), fl_key_channel_responder_handle_event(), fl_key_channel_responder_handle_event_finish(), fl_key_channel_responder_new(), fl_key_event_new(), g_autoptr(), set_key_event_channel(), TRUE, and user_data.

## ◆ TEST() [6/6]

TEST | ( | FlKeyChannelResponderTest | ,
|  | UseSpecifiedLogicalKey |
| ) |  |

Definition at line 188 of file fl_key_channel_responder_test.cc.

188 {
189 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
190
191 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
192 g_autoptr(FlKeyChannelResponder) responder =
193 fl_key_channel_responder_new(FL_BINARY_MESSENGER(messenger));
194
195 set_key_event_channel(
196 messenger,
197 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
198 "keyCode: 65, modifiers: 0, unicodeScalarValues: 65, "
199 "specifiedLogicalKey: 888}",
200 TRUE);
201 g_autoptr(FlKeyEvent) event = fl_key_event_new(
202 12345, TRUE, 0x04, GDK_KEY_A, static_cast<GdkModifierType>(0), 0);
203 fl_key_channel_responder_handle_event(
204 responder, event, 888, nullptr,
205 [](GObject* object, GAsyncResult* result, gpointer user_data) {
206 gboolean handled;
207 EXPECT_TRUE(fl_key_channel_responder_handle_event_finish(
208 FL_KEY_CHANNEL_RESPONDER(object), result, &handled, nullptr));
209 EXPECT_TRUE(handled);
210 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
211 },
212 loop);
213 g_main_loop_run(loop);
214
215 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
216 }

References fl_binary_messenger_shutdown(), fl_key_channel_responder_handle_event(), fl_key_channel_responder_handle_event_finish(), fl_key_channel_responder_new(), fl_key_event_new(), g_autoptr(), set_key_event_channel(), TRUE, and user_data.

## ◆ test_lock_event()

void test_lock_event | ( | guint | key_code,
|  | const char * | down_expected,
|  | const char * | up_expected
| ) |  |

Definition at line 90 of file fl_key_channel_responder_test.cc.

92 {
93 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
94
95 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
96 g_autoptr(FlKeyChannelResponder) responder =
97 fl_key_channel_responder_new(FL_BINARY_MESSENGER(messenger));
98
99 set_key_event_channel(messenger, down_expected, FALSE);
100 g_autoptr(FlKeyEvent) event1 = fl_key_event_new(
101 12345, TRUE, 0x04, key_code, static_cast<GdkModifierType>(0), 0);
102 fl_key_channel_responder_handle_event(
103 responder, event1, 0, nullptr,
104 [](GObject* object, GAsyncResult* result, gpointer user_data) {
105 gboolean handled;
106 EXPECT_TRUE(fl_key_channel_responder_handle_event_finish(
107 FL_KEY_CHANNEL_RESPONDER(object), result, &handled, nullptr));
108 EXPECT_FALSE(handled);
109 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
110 },
111 loop);
112 g_main_loop_run(loop);
113
114 set_key_event_channel(messenger, up_expected, FALSE);
115 g_autoptr(FlKeyEvent) event2 = fl_key_event_new(
116 12346, FALSE, 0x04, key_code, static_cast<GdkModifierType>(0), 0);
117 fl_key_channel_responder_handle_event(
118 responder, event2, 0, nullptr,
119 [](GObject* object, GAsyncResult* result, gpointer user_data) {
120 gboolean handled;
121 EXPECT_TRUE(fl_key_channel_responder_handle_event_finish(
122 FL_KEY_CHANNEL_RESPONDER(object), result, &handled, nullptr));
123 EXPECT_FALSE(handled);
124 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
125 },
126 loop);
127 g_main_loop_run(loop);
128
129 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
130 }

References fl_binary_messenger_shutdown(), fl_key_channel_responder_handle_event(), fl_key_channel_responder_handle_event_finish(), fl_key_channel_responder_new(), fl_key_event_new(), g_autoptr(), set_key_event_channel(), TRUE, and user_data.

Referenced by TEST().