5#include "flutter/shell/platform/linux/fl_key_channel_responder.h"
7#include "gtest/gtest.h"
9#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
10#include "flutter/shell/platform/linux/fl_engine_private.h"
11#include "flutter/shell/platform/linux/testing/fl_test.h"
29 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
48 GdkModifierType
state,
49 gboolean is_modifier) {
51 _g_key_event.time = time_in_milliseconds;
52 _g_key_event.state =
state;
53 _g_key_event.keyval = keyval;
54 _g_key_event.keycode = keycode;
55 _g_key_event.origin =
nullptr;
60TEST(FlKeyChannelResponderTest, SendKeyEvent) {
61 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
67 .channel_name =
"test/echo",
69 g_autoptr(FlKeyResponder) responder =
75 static_cast<GdkModifierType
>(0),
false),
78 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65, "
79 "modifiers: 0, unicodeScalarValues: 65}";
83 g_main_loop_run(loop);
88 static_cast<GdkModifierType
>(0),
false),
91 "{type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65, "
92 "modifiers: 0, unicodeScalarValues: 65}";
96 g_main_loop_run(loop);
100 const char* down_expected,
101 const char* up_expected) {
102 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
108 .channel_name =
"test/echo",
110 g_autoptr(FlKeyResponder) responder =
116 static_cast<GdkModifierType
>(0),
false),
122 g_main_loop_run(loop);
129 static_cast<GdkModifierType
>(0),
false),
133 g_main_loop_run(loop);
137TEST(FlKeyChannelResponderTest, SendNumLockKeyEvent) {
139 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
140 "keyCode: 65407, modifiers: 16}",
141 "{type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, "
142 "keyCode: 65407, modifiers: 0}");
146TEST(FlKeyChannelResponderTest, SendCapsLockKeyEvent) {
148 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
149 "keyCode: 65509, modifiers: 2}",
150 "{type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, "
151 "keyCode: 65509, modifiers: 0}");
155TEST(FlKeyChannelResponderTest, SendShiftLockKeyEvent) {
157 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
158 "keyCode: 65510, modifiers: 2}",
159 "{type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, "
160 "keyCode: 65510, modifiers: 0}");
163TEST(FlKeyChannelResponderTest, TestKeyEventHandledByFramework) {
164 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
170 .channel_name =
"test/echo",
172 g_autoptr(FlKeyResponder) responder =
178 static_cast<GdkModifierType
>(0),
false),
182 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
183 "keyCode: 65, modifiers: 0, unicodeScalarValues: 65}";
186 g_main_loop_run(loop);
189TEST(FlKeyChannelResponderTest, UseSpecifiedLogicalKey) {
190 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
196 .channel_name =
"test/echo",
198 g_autoptr(FlKeyResponder) responder =
204 static_cast<GdkModifierType
>(0),
false),
208 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
209 "keyCode: 65, modifiers: 0, unicodeScalarValues: 65, "
210 "specifiedLogicalKey: 888}";
213 g_main_loop_run(loop);
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
static FlEngine * make_mock_engine()
FlKeyChannelResponder * fl_key_channel_responder_new(FlBinaryMessenger *messenger, FlKeyChannelResponderMock *mock)
static const char * expected_value
static void responder_callback(bool handled, gpointer user_data)
void test_lock_event(guint key_code, const char *down_expected, const char *up_expected)
static FlKeyEvent * fl_key_event_new_by_mock(guint32 time_in_milliseconds, bool is_press, guint keyval, guint16 keycode, GdkModifierType state, gboolean is_modifier)
static FlValue * echo_response_cb(FlValue *echoed_value)
static gboolean expected_handled
TEST(FlKeyChannelResponderTest, SendKeyEvent)
void fl_key_responder_handle_event(FlKeyResponder *self, FlKeyEvent *event, FlKeyResponderAsyncCallback callback, gpointer user_data, uint64_t specified_logical_key)
G_MODULE_EXPORT FlValue * fl_value_new_map()
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
G_MODULE_EXPORT gchar * fl_value_to_string(FlValue *value)
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
typedefG_BEGIN_DECLS struct _FlValue FlValue
FlValueConverter value_converter