| Flutter Linux Embedder |

Functions | Variables
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/fl_engine_private.h"`
`#include "flutter/shell/platform/linux/testing/fl_test.h"`

Go to the source code of this file.

## Functions
static FlValue * | echo_response_cb (FlValue *echoed_value)
static void | responder_callback (bool handled, gpointer user_data)
static FlKeyEvent * | fl_key_event_new_by_mock (guint32 time_in_milliseconds, bool is_press, guint keyval, guint16 keycode, int state, const char *string, gboolean is_modifier)
| 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)

## Variables
static const char * | expected_value = nullptr
static gboolean | expected_handled = FALSE

## Function Documentation

## ◆ echo_response_cb()

static FlValue* echo_response_cb | ( | FlValue * | echoed_value | ) |
| static

Definition at line 16 of file fl_key_channel_responder_test.cc.

16 {
17 gchar* text = fl_value_to_string(echoed_value);
18 EXPECT_STREQ(text, expected_value);
19 g_free(text);
20
21 FlValue* value = fl_value_new_map();
22 fl_value_set_string_take(value, "handled",
23 fl_value_new_bool(expected_handled));
24 return value;
25 }

References expected_handled, expected_value, fl_value_new_bool(), fl_value_new_map(), fl_value_set_string_take(), fl_value_to_string(), and value.

Referenced by TEST(), and test_lock_event().

## ◆ fl_key_event_new_by_mock()

static FlKeyEvent* fl_key_event_new_by_mock | ( | guint32 | time_in_milliseconds,
|  | bool | is_press,
|  | guint | keyval,
|  | guint16 | keycode,
|  | int | state,
|  | const char * | string,
|  | gboolean | is_modifier
| ) |  |
| static

Definition at line 44 of file fl_key_channel_responder_test.cc.

50 {
51 if (_g_key_event.string != nullptr) {
52 g_free(const_cast<char*>(_g_key_event.string));
53 }
54 _g_key_event.is_press = is_press;
55 _g_key_event.time = time_in_milliseconds;
56 _g_key_event.state = state;
57 _g_key_event.keyval = keyval;
58 _g_key_event.string = g_strdup(string);
59 _g_key_event.keycode = keycode;
60 _g_key_event.origin = nullptr;
61 _g_key_event.dispose_origin = nullptr;
62 return &_g_key_event;
63 }

References state.

Referenced by TEST(), and test_lock_event().

## ◆ responder_callback()

static void responder_callback | ( | bool | handled,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 27 of file fl_key_channel_responder_test.cc.

27 {
28 EXPECT_EQ(handled, expected_handled);
29 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
30 }

References expected_handled, and user_data.

Referenced by TEST(), and test_lock_event().

## ◆ TEST() [1/6]

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

Definition at line 150 of file fl_key_channel_responder_test.cc.

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

References test_lock_event().

## ◆ TEST() [2/6]

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

Definition at line 66 of file fl_key_channel_responder_test.cc.

66 {
67 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
68
69 g_autoptr(FlEngine) engine = make_mock_engine();
70 g_autoptr(FlBinaryMessenger) messenger = fl_binary_messenger_new(engine);
71 FlKeyChannelResponderMock mock{
72 .value_converter = echo_response_cb,
73 .channel_name = "test/echo",
74 };
75 g_autoptr(FlKeyResponder) responder =
76 FL_KEY_RESPONDER(fl_key_channel_responder_new(messenger, &mock));
77
78 fl_key_responder_handle_event(
79 responder,
80 fl_key_event_new_by_mock(12345, true, GDK_KEY_A, 0x04, 0x0, "A", false),
81 responder_callback, loop);
82 expected_value =
83 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65, "
84 "modifiers: 0, unicodeScalarValues: 65}";
85 expected_handled = FALSE;
86
87 // Blocks here until echo_response_cb is called.
88 g_main_loop_run(loop);
89
90 fl_key_responder_handle_event(
91 responder,
92 fl_key_event_new_by_mock(23456, false, GDK_KEY_A, 0x04, 0x0, "A", false),
93 responder_callback, loop);
94 expected_value =
95 "{type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65, "
96 "modifiers: 0, unicodeScalarValues: 65}";
97 expected_handled = FALSE;
98
99 // Blocks here until echo_response_cb is called.
100 g_main_loop_run(loop);
101 }

References echo_response_cb(), engine, expected_handled, expected_value, fl_binary_messenger_new(), fl_key_channel_responder_new(), fl_key_event_new_by_mock(), fl_key_responder_handle_event(), make_mock_engine(), responder_callback(), and _FlKeyChannelResponderMock::value_converter.

## ◆ TEST() [3/6]

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

Definition at line 141 of file fl_key_channel_responder_test.cc.

141 {
142 test_lock_event(GDK_KEY_Num_Lock,
143 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
144 "keyCode: 65407, modifiers: 16}",
145 "{type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, "
146 "keyCode: 65407, modifiers: 0}");
147 }

References test_lock_event().

## ◆ TEST() [4/6]

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

Definition at line 159 of file fl_key_channel_responder_test.cc.

159 {
160 test_lock_event(GDK_KEY_Shift_Lock,
161 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
162 "keyCode: 65510, modifiers: 2}",
163 "{type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, "
164 "keyCode: 65510, modifiers: 0}");
165 }

References test_lock_event().

## ◆ TEST() [5/6]

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

Definition at line 167 of file fl_key_channel_responder_test.cc.

167 {
168 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
169
170 g_autoptr(FlEngine) engine = make_mock_engine();
171 g_autoptr(FlBinaryMessenger) messenger = fl_binary_messenger_new(engine);
172 FlKeyChannelResponderMock mock{
173 .value_converter = echo_response_cb,
174 .channel_name = "test/echo",
175 };
176 g_autoptr(FlKeyResponder) responder =
177 FL_KEY_RESPONDER(fl_key_channel_responder_new(messenger, &mock));
178
179 fl_key_responder_handle_event(
180 responder,
181 fl_key_event_new_by_mock(12345, true, GDK_KEY_A, 0x04, 0x0, nullptr,
182 false),
183 responder_callback, loop);
184 expected_handled = TRUE;
185 expected_value =
186 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
187 "keyCode: 65, modifiers: 0, unicodeScalarValues: 65}";
188
189 // Blocks here until echo_response_cb is called.
190 g_main_loop_run(loop);
191 }

References echo_response_cb(), engine, expected_handled, expected_value, fl_binary_messenger_new(), fl_key_channel_responder_new(), fl_key_event_new_by_mock(), fl_key_responder_handle_event(), make_mock_engine(), responder_callback(), TRUE, and _FlKeyChannelResponderMock::value_converter.

## ◆ TEST() [6/6]

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

Definition at line 193 of file fl_key_channel_responder_test.cc.

193 {
194 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
195
196 g_autoptr(FlEngine) engine = make_mock_engine();
197 g_autoptr(FlBinaryMessenger) messenger = fl_binary_messenger_new(engine);
198 FlKeyChannelResponderMock mock{
199 .value_converter = echo_response_cb,
200 .channel_name = "test/echo",
201 };
202 g_autoptr(FlKeyResponder) responder =
203 FL_KEY_RESPONDER(fl_key_channel_responder_new(messenger, &mock));
204
205 fl_key_responder_handle_event(
206 responder,
207 fl_key_event_new_by_mock(12345, true, GDK_KEY_A, 0x04, 0x0, nullptr,
208 false),
209 responder_callback, loop, 888);
210 expected_handled = TRUE;
211 expected_value =
212 "{type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
213 "keyCode: 65, modifiers: 0, unicodeScalarValues: 65, "
214 "specifiedLogicalKey: 888}";
215
216 // Blocks here until echo_response_cb is called.
217 g_main_loop_run(loop);
218 }

References echo_response_cb(), engine, expected_handled, expected_value, fl_binary_messenger_new(), fl_key_channel_responder_new(), fl_key_event_new_by_mock(), fl_key_responder_handle_event(), make_mock_engine(), responder_callback(), TRUE, and _FlKeyChannelResponderMock::value_converter.

## ◆ test_lock_event()

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

Definition at line 103 of file fl_key_channel_responder_test.cc.

105 {
106 g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);
107
108 g_autoptr(FlEngine) engine = make_mock_engine();
109 g_autoptr(FlBinaryMessenger) messenger = fl_binary_messenger_new(engine);
110 FlKeyChannelResponderMock mock{
111 .value_converter = echo_response_cb,
112 .channel_name = "test/echo",
113 };
114 g_autoptr(FlKeyResponder) responder =
115 FL_KEY_RESPONDER(fl_key_channel_responder_new(messenger, &mock));
116
117 fl_key_responder_handle_event(
118 responder,
119 fl_key_event_new_by_mock(12345, true, key_code, 0x04, 0x0, nullptr,
120 false),
121 responder_callback, loop);
122 expected_value = down_expected;
123 expected_handled = FALSE;
124
125 // Blocks here until echo_response_cb is called.
126 g_main_loop_run(loop);
127
128 expected_value = up_expected;
129 expected_handled = FALSE;
130 fl_key_responder_handle_event(
131 responder,
132 fl_key_event_new_by_mock(12346, false, key_code, 0x04, 0x0, nullptr,
133 false),
134 responder_callback, loop);
135
136 // Blocks here until echo_response_cb is called.
137 g_main_loop_run(loop);
138 }

References echo_response_cb(), engine, expected_handled, expected_value, fl_binary_messenger_new(), fl_key_channel_responder_new(), fl_key_event_new_by_mock(), fl_key_responder_handle_event(), make_mock_engine(), responder_callback(), and _FlKeyChannelResponderMock::value_converter.

Referenced by TEST().

## Variable Documentation

## ◆ expected_handled

gboolean expected_handled = FALSE
| static

Definition at line 14 of file fl_key_channel_responder_test.cc.

Referenced by echo_response_cb(), invoke_record_callback_and_verify(), responder_callback(), TEST(), and test_lock_event().

## ◆ expected_value

const char* expected_value = nullptr
| static

Definition at line 13 of file fl_key_channel_responder_test.cc.

Referenced by echo_response_cb(), TEST(), and test_lock_event().

responder_callback
static void responder_callback(bool handled, gpointer user_data)
Definition: fl_key_channel_responder_test.cc:27
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:610
fl_key_event_new_by_mock
static FlKeyEvent * fl_key_event_new_by_mock(guint32 time_in_milliseconds, bool is_press, guint keyval, guint16 keycode, int state, const char *string, gboolean is_modifier)
Definition: fl_key_channel_responder_test.cc:44
fl_value_new_bool
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:244
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
user_data
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
Definition: fl_key_channel_responder.cc:121
expected_value
static const char * expected_value
Definition: fl_key_channel_responder_test.cc:13
state
AtkStateType state
Definition: fl_accessible_node.cc:10
fl_binary_messenger_new
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
Definition: fl_binary_messenger.cc:406
fl_key_channel_responder_new
FlKeyChannelResponder * fl_key_channel_responder_new(FlBinaryMessenger *messenger, FlKeyChannelResponderMock *mock)
Definition: fl_key_channel_responder.cc:186
make_mock_engine
static FlEngine * make_mock_engine()
Definition: fl_event_channel_test.cc:24
_FlKeyChannelResponderMock::value_converter
FlValueConverter value_converter
Definition: fl_key_channel_responder.h:29
fl_value_new_map
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:355
fl_key_responder_handle_event
void fl_key_responder_handle_event(FlKeyResponder *self, FlKeyEvent *event, FlKeyResponderAsyncCallback callback, gpointer user_data, uint64_t specified_logical_key)
Definition: fl_key_responder.cc:11
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
echo_response_cb
static FlValue * echo_response_cb(FlValue *echoed_value)
Definition: fl_key_channel_responder_test.cc:16
_FlKeyChannelResponderMock
Definition: fl_key_channel_responder.h:23
engine
FlEngine * engine
Definition: fl_view_accessible.cc:29
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:103
value
uint8_t value
Definition: fl_standard_message_codec.cc:41
fl_value_to_string
G_MODULE_EXPORT gchar * fl_value_to_string(FlValue *value)
Definition: fl_value.cc:781
expected_handled
static gboolean expected_handled
Definition: fl_key_channel_responder_test.cc:14