7 #include "gtest/gtest.h"
9 #include "flutter/shell/platform/embedder/test_utils/key_codes.g.h"
10 #include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
13 #include "flutter/shell/platform/linux/testing/fl_test.h"
16 constexpr gboolean kRelease = FALSE;
17 constexpr gboolean kPress =
TRUE;
19 constexpr guint16 kKeyCodeDigit1 = 0x0au;
20 constexpr guint16 kKeyCodeKeyA = 0x26u;
21 constexpr guint16 kKeyCodeShiftLeft = 0x32u;
22 constexpr guint16 kKeyCodeShiftRight = 0x3Eu;
23 constexpr guint16 kKeyCodeAltLeft = 0x40u;
24 constexpr guint16 kKeyCodeAltRight = 0x6Cu;
25 constexpr guint16 kKeyCodeNumpad1 = 0x57u;
26 constexpr guint16 kKeyCodeNumLock = 0x4Du;
27 constexpr guint16 kKeyCodeCapsLock = 0x42u;
28 constexpr guint16 kKeyCodeControlLeft = 0x25u;
29 constexpr guint16 kKeyCodeControlRight = 0x69u;
31 using namespace ::flutter::testing::keycodes;
35 g_ptr_array_remove_range(array, 0, array->len);
39 fl_key_embedder_call_record,
41 KEY_EMBEDDER_CALL_RECORD,
53 fl_key_embedder_call_record,
56 static void fl_key_embedder_call_record_init(FlKeyEmbedderCallRecord*
self) {}
60 g_return_if_fail(FL_IS_KEY_EMBEDDER_CALL_RECORD(
object));
62 FlKeyEmbedderCallRecord*
self = FL_KEY_EMBEDDER_CALL_RECORD(
object);
63 if (self->event !=
nullptr) {
64 g_free(
const_cast<char*
>(self->event->character));
67 G_OBJECT_CLASS(fl_key_embedder_call_record_parent_class)->dispose(
object);
72 FlKeyEmbedderCallRecordClass* klass) {
77 const FlutterKeyEvent*
event,
80 g_return_val_if_fail(
event !=
nullptr,
nullptr);
82 FlKeyEmbedderCallRecord*
self = FL_KEY_EMBEDDER_CALL_RECORD(
83 g_object_new(fl_key_embedder_call_record_get_type(),
nullptr));
85 FlutterKeyEvent* clone_event = g_new(FlutterKeyEvent, 1);
86 *clone_event = *
event;
87 if (
event->character !=
nullptr) {
88 size_t character_length = strlen(
event->character);
89 char* clone_character = g_new(
char, character_length + 1);
90 strncpy(clone_character,
event->character, character_length + 1);
91 clone_event->character = clone_character;
93 self->event = clone_event;
109 void* expected_user_data) {
110 g_return_if_fail(record->callback !=
nullptr);
117 GPtrArray* g_call_records;
122 void* callback_user_data,
123 void* send_key_event_user_data) {
124 GPtrArray* records_array =
125 reinterpret_cast<GPtrArray*
>(send_key_event_user_data);
126 if (records_array !=
nullptr) {
133 g_ptr_array_free(g_call_records,
TRUE);
134 g_call_records =
nullptr;
138 TEST(FlKeyEmbedderResponderTest, SendKeyEvent) {
139 EXPECT_EQ(g_call_records,
nullptr);
140 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
141 FlKeyResponder* responder = FL_KEY_RESPONDER(
145 FlKeyEmbedderCallRecord* record;
149 g_autoptr(FlKeyEvent) event1 =
151 static_cast<GdkModifierType
>(0), 0);
155 EXPECT_EQ(g_call_records->len, 1u);
156 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
157 EXPECT_EQ(record->event->struct_size,
sizeof(FlutterKeyEvent));
158 EXPECT_EQ(record->event->timestamp, 12345000);
159 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
160 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
161 EXPECT_EQ(record->event->logical, kLogicalKeyA);
162 EXPECT_STREQ(record->event->character,
"a");
163 EXPECT_EQ(record->event->synthesized,
false);
169 g_autoptr(FlKeyEvent) event2 =
171 static_cast<GdkModifierType
>(0), 0);
175 EXPECT_EQ(g_call_records->len, 1u);
176 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
177 EXPECT_EQ(record->event->struct_size,
sizeof(FlutterKeyEvent));
178 EXPECT_EQ(record->event->timestamp, 12346000);
179 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
180 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
181 EXPECT_EQ(record->event->logical, kLogicalKeyA);
182 EXPECT_STREQ(record->event->character,
nullptr);
183 EXPECT_EQ(record->event->synthesized,
false);
190 g_autoptr(FlKeyEvent) event3 =
192 static_cast<GdkModifierType
>(0), 0);
196 EXPECT_EQ(g_call_records->len, 1u);
197 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
198 EXPECT_EQ(record->event->struct_size,
sizeof(FlutterKeyEvent));
199 EXPECT_EQ(record->event->timestamp, 12347000);
200 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
201 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
202 EXPECT_EQ(record->event->logical, kLogicalKeyQ);
203 EXPECT_STREQ(record->event->character,
"q");
204 EXPECT_EQ(record->event->synthesized,
false);
210 g_autoptr(FlKeyEvent) event4 =
212 static_cast<GdkModifierType
>(0), 0);
216 EXPECT_EQ(g_call_records->len, 1u);
217 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
218 EXPECT_EQ(record->event->struct_size,
sizeof(FlutterKeyEvent));
219 EXPECT_EQ(record->event->timestamp, 12348000);
220 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
221 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
222 EXPECT_EQ(record->event->logical, kLogicalKeyQ);
223 EXPECT_STREQ(record->event->character,
nullptr);
224 EXPECT_EQ(record->event->synthesized,
false);
230 g_object_unref(responder);
234 TEST(FlKeyEmbedderResponderTest, UsesSpecifiedLogicalKey) {
235 EXPECT_EQ(g_call_records,
nullptr);
236 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
237 FlKeyResponder* responder = FL_KEY_RESPONDER(
241 FlKeyEmbedderCallRecord* record;
245 g_autoptr(FlKeyEvent)
event =
247 static_cast<GdkModifierType
>(0), 0);
251 EXPECT_EQ(g_call_records->len, 1u);
252 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
253 EXPECT_EQ(record->event->struct_size,
sizeof(FlutterKeyEvent));
254 EXPECT_EQ(record->event->timestamp, 12345000);
255 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
256 EXPECT_EQ(record->event->physical, kPhysicalDigit1);
257 EXPECT_EQ(record->event->logical, kLogicalDigit1);
258 EXPECT_STREQ(record->event->character,
"&");
259 EXPECT_EQ(record->event->synthesized,
false);
265 g_object_unref(responder);
269 TEST(FlKeyEmbedderResponderTest, PressShiftDuringLetterKeyTap) {
270 EXPECT_EQ(g_call_records,
nullptr);
271 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
272 FlKeyResponder* responder = FL_KEY_RESPONDER(
276 FlKeyEmbedderCallRecord* record;
279 g_autoptr(FlKeyEvent) event1 =
281 static_cast<GdkModifierType
>(0), 0);
285 EXPECT_EQ(g_call_records->len, 1u);
286 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
287 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
288 EXPECT_EQ(record->event->physical, kPhysicalShiftRight);
289 EXPECT_EQ(record->event->logical, kLogicalShiftRight);
290 EXPECT_STREQ(record->event->character,
nullptr);
291 EXPECT_EQ(record->event->synthesized,
false);
297 g_autoptr(FlKeyEvent) event2 =
302 EXPECT_EQ(g_call_records->len, 1u);
303 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
304 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
305 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
306 EXPECT_EQ(record->event->logical, kLogicalKeyA);
307 EXPECT_STREQ(record->event->character,
"A");
308 EXPECT_EQ(record->event->synthesized,
false);
315 103, kRelease, kKeyCodeShiftRight, GDK_KEY_Shift_R, GDK_SHIFT_MASK, 0);
319 EXPECT_EQ(g_call_records->len, 1u);
320 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
321 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
322 EXPECT_EQ(record->event->physical, kPhysicalShiftRight);
323 EXPECT_EQ(record->event->logical, kLogicalShiftRight);
324 EXPECT_STREQ(record->event->character,
nullptr);
325 EXPECT_EQ(record->event->synthesized,
false);
331 g_autoptr(FlKeyEvent) event4 =
333 static_cast<GdkModifierType
>(0), 0);
337 EXPECT_EQ(g_call_records->len, 1u);
338 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
339 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
340 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
341 EXPECT_EQ(record->event->logical, kLogicalKeyA);
342 EXPECT_STREQ(record->event->character,
nullptr);
343 EXPECT_EQ(record->event->synthesized,
false);
349 g_object_unref(responder);
360 TEST(FlKeyEmbedderResponderTest, TapNumPadKeysBetweenNumLockEvents) {
361 EXPECT_EQ(g_call_records,
nullptr);
362 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
363 FlKeyResponder* responder = FL_KEY_RESPONDER(
367 FlKeyEmbedderCallRecord* record;
370 g_autoptr(FlKeyEvent) event1 =
372 static_cast<GdkModifierType
>(0), 0);
376 EXPECT_EQ(g_call_records->len, 1u);
377 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
378 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
379 EXPECT_EQ(record->event->physical, kPhysicalNumpad1);
380 EXPECT_EQ(record->event->logical, kLogicalNumpad1);
381 EXPECT_STREQ(record->event->character,
nullptr);
382 EXPECT_EQ(record->event->synthesized,
false);
388 g_autoptr(FlKeyEvent) event2 =
390 static_cast<GdkModifierType
>(0), 0);
394 EXPECT_EQ(g_call_records->len, 1u);
395 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
396 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
397 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
398 EXPECT_EQ(record->event->logical, kLogicalNumLock);
399 EXPECT_STREQ(record->event->character,
nullptr);
400 EXPECT_EQ(record->event->synthesized,
false);
407 104, kRelease, kKeyCodeNumpad1, GDK_KEY_KP_1, GDK_MOD2_MASK, 0);
411 EXPECT_EQ(g_call_records->len, 1u);
412 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
413 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
414 EXPECT_EQ(record->event->physical, kPhysicalNumpad1);
415 EXPECT_EQ(record->event->logical, kLogicalNumpad1);
416 EXPECT_STREQ(record->event->character,
nullptr);
417 EXPECT_EQ(record->event->synthesized,
false);
424 103, kRelease, kKeyCodeNumLock, GDK_KEY_Num_Lock, GDK_MOD2_MASK, 0);
428 EXPECT_EQ(g_call_records->len, 1u);
429 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
430 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
431 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
432 EXPECT_EQ(record->event->logical, kLogicalNumLock);
433 EXPECT_STREQ(record->event->character,
nullptr);
434 EXPECT_EQ(record->event->synthesized,
false);
441 101, kPress, kKeyCodeNumpad1, GDK_KEY_KP_End, GDK_MOD2_MASK, 0);
445 EXPECT_EQ(g_call_records->len, 1u);
446 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
447 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
448 EXPECT_EQ(record->event->physical, kPhysicalNumpad1);
449 EXPECT_EQ(record->event->logical, kLogicalNumpad1);
450 EXPECT_STREQ(record->event->character,
nullptr);
451 EXPECT_EQ(record->event->synthesized,
false);
458 102, kPress, kKeyCodeNumLock, GDK_KEY_Num_Lock, GDK_MOD2_MASK, 0);
462 EXPECT_EQ(g_call_records->len, 1u);
463 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
464 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
465 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
466 EXPECT_EQ(record->event->logical, kLogicalNumLock);
467 EXPECT_STREQ(record->event->character,
nullptr);
468 EXPECT_EQ(record->event->synthesized,
false);
475 104, kRelease, kKeyCodeNumpad1, GDK_KEY_KP_1, GDK_MOD2_MASK, 0);
479 EXPECT_EQ(g_call_records->len, 1u);
480 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
481 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
482 EXPECT_EQ(record->event->physical, kPhysicalNumpad1);
483 EXPECT_EQ(record->event->logical, kLogicalNumpad1);
484 EXPECT_STREQ(record->event->character,
nullptr);
485 EXPECT_EQ(record->event->synthesized,
false);
492 103, kRelease, kKeyCodeNumLock, GDK_KEY_Num_Lock, GDK_MOD2_MASK, 0);
496 EXPECT_EQ(g_call_records->len, 1u);
497 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
498 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
499 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
500 EXPECT_EQ(record->event->logical, kLogicalNumLock);
501 EXPECT_STREQ(record->event->character,
nullptr);
502 EXPECT_EQ(record->event->synthesized,
false);
508 g_object_unref(responder);
515 TEST(FlKeyEmbedderResponderTest, ReleaseShiftKeyBetweenDigitKeyEvents) {
516 EXPECT_EQ(g_call_records,
nullptr);
517 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
518 FlKeyResponder* responder = FL_KEY_RESPONDER(
522 FlKeyEmbedderCallRecord* record;
524 GdkModifierType
state =
static_cast<GdkModifierType
>(0);
528 101, kPress, kKeyCodeShiftLeft, GDK_KEY_Shift_L,
state, 0);
532 EXPECT_EQ(g_call_records->len, 1u);
533 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
534 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
535 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
536 EXPECT_EQ(record->event->logical, kLogicalShiftLeft);
537 EXPECT_STREQ(record->event->character,
nullptr);
538 EXPECT_EQ(record->event->synthesized,
false);
543 state = GDK_SHIFT_MASK;
546 g_autoptr(FlKeyEvent) event2 =
551 EXPECT_EQ(g_call_records->len, 1u);
552 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
553 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
554 EXPECT_EQ(record->event->physical, kPhysicalDigit1);
555 EXPECT_EQ(record->event->logical, kLogicalExclamation);
556 EXPECT_STREQ(record->event->character,
"!");
557 EXPECT_EQ(record->event->synthesized,
false);
564 103, kRelease, kKeyCodeShiftLeft, GDK_KEY_Shift_L,
state, 0);
568 EXPECT_EQ(g_call_records->len, 1u);
569 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
570 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
571 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
572 EXPECT_EQ(record->event->logical, kLogicalShiftLeft);
573 EXPECT_STREQ(record->event->character,
nullptr);
574 EXPECT_EQ(record->event->synthesized,
false);
579 state =
static_cast<GdkModifierType
>(0);
582 g_autoptr(FlKeyEvent) event4 =
587 EXPECT_EQ(g_call_records->len, 1u);
588 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
589 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
590 EXPECT_EQ(record->event->physical, kPhysicalDigit1);
591 EXPECT_EQ(record->event->logical, kLogicalExclamation);
592 EXPECT_STREQ(record->event->character,
nullptr);
593 EXPECT_EQ(record->event->synthesized,
false);
599 g_object_unref(responder);
606 TEST(FlKeyEmbedderResponderTest, TapLetterKeysBetweenCapsLockEvents) {
607 EXPECT_EQ(g_call_records,
nullptr);
608 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
609 FlKeyResponder* responder = FL_KEY_RESPONDER(
613 FlKeyEmbedderCallRecord* record;
616 g_autoptr(FlKeyEvent) event1 =
618 static_cast<GdkModifierType
>(0), 0);
622 EXPECT_EQ(g_call_records->len, 1u);
623 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
624 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
625 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
626 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
627 EXPECT_STREQ(record->event->character,
nullptr);
628 EXPECT_EQ(record->event->synthesized,
false);
634 g_autoptr(FlKeyEvent) event2 =
639 EXPECT_EQ(g_call_records->len, 1u);
640 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
641 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
642 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
643 EXPECT_EQ(record->event->logical, kLogicalKeyA);
644 EXPECT_STREQ(record->event->character,
"A");
645 EXPECT_EQ(record->event->synthesized,
false);
652 103, kRelease, kKeyCodeCapsLock, GDK_KEY_Caps_Lock, GDK_LOCK_MASK, 0);
656 EXPECT_EQ(g_call_records->len, 1u);
657 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
658 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
659 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
660 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
661 EXPECT_STREQ(record->event->character,
nullptr);
662 EXPECT_EQ(record->event->synthesized,
false);
668 g_autoptr(FlKeyEvent) event4 =
fl_key_event_new(104, kRelease, kKeyCodeKeyA,
669 GDK_KEY_A, GDK_LOCK_MASK, 0);
673 EXPECT_EQ(g_call_records->len, 1u);
674 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
675 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
676 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
677 EXPECT_EQ(record->event->logical, kLogicalKeyA);
678 EXPECT_STREQ(record->event->character,
nullptr);
679 EXPECT_EQ(record->event->synthesized,
false);
686 105, kPress, kKeyCodeCapsLock, GDK_KEY_Caps_Lock, GDK_LOCK_MASK, 0);
690 EXPECT_EQ(g_call_records->len, 1u);
691 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
692 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
693 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
694 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
695 EXPECT_STREQ(record->event->character,
nullptr);
696 EXPECT_EQ(record->event->synthesized,
false);
702 g_autoptr(FlKeyEvent) event6 =
707 EXPECT_EQ(g_call_records->len, 1u);
708 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
709 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
710 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
711 EXPECT_EQ(record->event->logical, kLogicalKeyA);
712 EXPECT_STREQ(record->event->character,
"A");
713 EXPECT_EQ(record->event->synthesized,
false);
720 107, kRelease, kKeyCodeCapsLock, GDK_KEY_Caps_Lock, GDK_LOCK_MASK, 0);
724 EXPECT_EQ(g_call_records->len, 1u);
725 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
726 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
727 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
728 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
729 EXPECT_STREQ(record->event->character,
nullptr);
730 EXPECT_EQ(record->event->synthesized,
false);
736 g_autoptr(FlKeyEvent) event8 =
738 static_cast<GdkModifierType
>(0), 0);
742 EXPECT_EQ(g_call_records->len, 1u);
743 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
744 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
745 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
746 EXPECT_EQ(record->event->logical, kLogicalKeyA);
747 EXPECT_STREQ(record->event->character,
nullptr);
748 EXPECT_EQ(record->event->synthesized,
false);
754 g_object_unref(responder);
761 TEST(FlKeyEmbedderResponderTest, TapLetterKeysBetweenCapsLockEventsReversed) {
762 EXPECT_EQ(g_call_records,
nullptr);
763 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
764 FlKeyResponder* responder = FL_KEY_RESPONDER(
768 FlKeyEmbedderCallRecord* record;
772 101, kPress, kKeyCodeKeyA, GDK_KEY_a,
static_cast<GdkModifierType
>(0), 0);
776 EXPECT_EQ(g_call_records->len, 1u);
777 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
778 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
779 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
780 EXPECT_EQ(record->event->logical, kLogicalKeyA);
781 EXPECT_STREQ(record->event->character,
"a");
782 EXPECT_EQ(record->event->synthesized,
false);
789 102, kPress, kKeyCodeCapsLock, GDK_KEY_Caps_Lock, GDK_LOCK_MASK, 0);
793 EXPECT_EQ(g_call_records->len, 1u);
794 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
795 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
796 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
797 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
798 EXPECT_STREQ(record->event->character,
nullptr);
799 EXPECT_EQ(record->event->synthesized,
false);
806 103, kRelease, kKeyCodeCapsLock, GDK_KEY_Caps_Lock, GDK_LOCK_MASK, 0);
810 EXPECT_EQ(g_call_records->len, 1u);
811 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
812 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
813 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
814 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
815 EXPECT_STREQ(record->event->character,
nullptr);
816 EXPECT_EQ(record->event->synthesized,
false);
822 g_autoptr(FlKeyEvent) event4 =
fl_key_event_new(104, kRelease, kKeyCodeKeyA,
823 GDK_KEY_A, GDK_LOCK_MASK, 0);
827 EXPECT_EQ(g_call_records->len, 1u);
828 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
829 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
830 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
831 EXPECT_EQ(record->event->logical, kLogicalKeyA);
832 EXPECT_STREQ(record->event->character,
nullptr);
833 EXPECT_EQ(record->event->synthesized,
false);
839 g_autoptr(FlKeyEvent) event5 =
844 EXPECT_EQ(g_call_records->len, 1u);
845 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
846 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
847 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
848 EXPECT_EQ(record->event->logical, kLogicalKeyA);
849 EXPECT_STREQ(record->event->character,
"A");
850 EXPECT_EQ(record->event->synthesized,
false);
856 g_autoptr(FlKeyEvent) event6 =
858 static_cast<GdkModifierType
>(0), 0);
862 EXPECT_EQ(g_call_records->len, 1u);
863 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
864 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
865 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
866 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
867 EXPECT_STREQ(record->event->character,
nullptr);
868 EXPECT_EQ(record->event->synthesized,
false);
875 107, kRelease, kKeyCodeCapsLock, GDK_KEY_Caps_Lock, GDK_LOCK_MASK, 0);
879 EXPECT_EQ(g_call_records->len, 1u);
880 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
881 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
882 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
883 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
884 EXPECT_STREQ(record->event->character,
nullptr);
885 EXPECT_EQ(record->event->synthesized,
false);
891 g_autoptr(FlKeyEvent) event8 =
893 static_cast<GdkModifierType
>(0), 0);
897 EXPECT_EQ(g_call_records->len, 1u);
898 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
899 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
900 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
901 EXPECT_EQ(record->event->logical, kLogicalKeyA);
902 EXPECT_STREQ(record->event->character,
nullptr);
903 EXPECT_EQ(record->event->synthesized,
false);
909 g_object_unref(responder);
912 TEST(FlKeyEmbedderResponderTest, TurnDuplicateDownEventsToRepeats) {
913 EXPECT_EQ(g_call_records,
nullptr);
914 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
915 FlKeyResponder* responder = FL_KEY_RESPONDER(
919 FlKeyEmbedderCallRecord* record;
923 101, kPress, kKeyCodeKeyA, GDK_KEY_a,
static_cast<GdkModifierType
>(0), 0);
927 EXPECT_EQ(g_call_records->len, 1u);
929 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
936 102, kPress, kKeyCodeKeyA, GDK_KEY_a,
static_cast<GdkModifierType
>(0), 0);
940 EXPECT_EQ(g_call_records->len, 1u);
942 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
943 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeRepeat);
944 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
945 EXPECT_EQ(record->event->logical, kLogicalKeyA);
946 EXPECT_STREQ(record->event->character,
"a");
947 EXPECT_EQ(record->event->synthesized,
false);
948 EXPECT_NE(record->callback,
nullptr);
954 g_autoptr(FlKeyEvent) event3 =
956 static_cast<GdkModifierType
>(0), 0);
960 EXPECT_EQ(g_call_records->len, 1u);
961 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
966 g_object_unref(responder);
969 TEST(FlKeyEmbedderResponderTest, IgnoreAbruptUpEvent) {
970 FlKeyEmbedderCallRecord* record;
972 EXPECT_EQ(g_call_records,
nullptr);
973 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
974 FlKeyResponder* responder = FL_KEY_RESPONDER(
980 g_autoptr(FlKeyEvent)
event =
982 static_cast<GdkModifierType
>(0), 0);
986 EXPECT_EQ(g_call_records->len, 1u);
988 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
989 EXPECT_EQ(record->event->physical, 0ull);
990 EXPECT_EQ(record->event->logical, 0ull);
991 EXPECT_STREQ(record->event->character,
nullptr);
992 EXPECT_EQ(record->event->synthesized,
false);
993 EXPECT_EQ(record->callback,
nullptr);
996 g_object_unref(responder);
1001 TEST(FlKeyEmbedderResponderTest, SynthesizeForDesyncPressingStateOnSelfEvents) {
1002 EXPECT_EQ(g_call_records,
nullptr);
1003 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1004 FlKeyResponder* responder = FL_KEY_RESPONDER(
1008 FlKeyEmbedderCallRecord* record;
1013 GdkModifierType
state = GDK_CONTROL_MASK;
1017 101, kRelease, kKeyCodeControlLeft, GDK_KEY_Control_L,
state, 0);
1021 EXPECT_EQ(g_call_records->len, 2u);
1022 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1023 EXPECT_EQ(record->event->timestamp, 101000);
1024 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1025 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1026 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1027 EXPECT_STREQ(record->event->character,
nullptr);
1028 EXPECT_EQ(record->event->synthesized,
true);
1030 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1031 EXPECT_EQ(record->event->timestamp, 101000);
1032 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1033 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1034 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1035 EXPECT_STREQ(record->event->character,
nullptr);
1036 EXPECT_EQ(record->event->synthesized,
false);
1044 state =
static_cast<GdkModifierType
>(0);
1046 102, kPress, kKeyCodeControlLeft, GDK_KEY_Control_L,
state, 0);
1049 EXPECT_EQ(g_call_records->len, 1u);
1050 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1055 state =
static_cast<GdkModifierType
>(0);
1059 103, kPress, kKeyCodeControlLeft, GDK_KEY_Control_L,
state, 0);
1063 EXPECT_EQ(g_call_records->len, 2u);
1064 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1065 EXPECT_EQ(record->event->timestamp, 103000);
1066 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1067 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1068 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1069 EXPECT_STREQ(record->event->character,
nullptr);
1070 EXPECT_EQ(record->event->synthesized,
true);
1072 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1073 EXPECT_EQ(record->event->timestamp, 103000);
1074 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1075 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1076 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1077 EXPECT_STREQ(record->event->character,
nullptr);
1078 EXPECT_EQ(record->event->synthesized,
false);
1084 state = GDK_CONTROL_MASK;
1086 104, kRelease, kKeyCodeControlLeft, GDK_KEY_Control_L,
state, 0);
1089 EXPECT_EQ(g_call_records->len, 1u);
1090 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1097 state = GDK_CONTROL_MASK;
1101 105, kRelease, kKeyCodeControlRight, GDK_KEY_Control_R,
state, 0);
1109 EXPECT_EQ(g_call_records->len, 1u);
1110 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1111 EXPECT_EQ(record->event->timestamp, 105000);
1112 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1113 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1114 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1115 EXPECT_STREQ(record->event->character,
nullptr);
1116 EXPECT_EQ(record->event->synthesized,
true);
1121 g_object_unref(responder);
1127 SynthesizeForDesyncPressingStateOnNonSelfEvents) {
1128 EXPECT_EQ(g_call_records,
nullptr);
1129 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1130 FlKeyResponder* responder = FL_KEY_RESPONDER(
1134 FlKeyEmbedderCallRecord* record;
1137 GdkModifierType
state = GDK_CONTROL_MASK;
1140 g_autoptr(FlKeyEvent) event1 =
1145 EXPECT_EQ(g_call_records->len, 2u);
1146 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1147 EXPECT_EQ(record->event->timestamp, 101000);
1148 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1149 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1150 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1151 EXPECT_STREQ(record->event->character,
nullptr);
1152 EXPECT_EQ(record->event->synthesized,
true);
1154 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1155 EXPECT_EQ(record->event->timestamp, 101000);
1156 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1157 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1158 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1159 EXPECT_STREQ(record->event->character,
"a");
1160 EXPECT_EQ(record->event->synthesized,
false);
1166 state =
static_cast<GdkModifierType
>(0);
1169 g_autoptr(FlKeyEvent) event2 =
1174 EXPECT_EQ(g_call_records->len, 2u);
1175 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1176 EXPECT_EQ(record->event->timestamp, 102000);
1177 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1178 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1179 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1180 EXPECT_STREQ(record->event->character,
nullptr);
1181 EXPECT_EQ(record->event->synthesized,
true);
1183 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1184 EXPECT_EQ(record->event->timestamp, 102000);
1185 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1186 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1187 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1188 EXPECT_STREQ(record->event->character,
nullptr);
1189 EXPECT_EQ(record->event->synthesized,
false);
1197 state =
static_cast<GdkModifierType
>(0);
1199 g_autoptr(FlKeyEvent) event3 =
fl_key_event_new(101, kPress, kKeyCodeCapsLock,
1200 GDK_KEY_Control_L,
state, 0);
1204 EXPECT_EQ(g_call_records->len, 1u);
1205 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1206 EXPECT_EQ(record->event->timestamp, 101000);
1207 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1208 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
1209 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1210 EXPECT_STREQ(record->event->character,
nullptr);
1211 EXPECT_EQ(record->event->synthesized,
false);
1217 state =
static_cast<GdkModifierType
>(0);
1220 g_autoptr(FlKeyEvent) event4 =
1227 EXPECT_EQ(g_call_records->len, 2u);
1228 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1229 EXPECT_EQ(record->event->timestamp, 102000);
1230 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1231 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
1232 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1233 EXPECT_STREQ(record->event->character,
nullptr);
1234 EXPECT_EQ(record->event->synthesized,
true);
1236 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1237 EXPECT_EQ(record->event->timestamp, 102000);
1238 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1239 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1240 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1241 EXPECT_STREQ(record->event->character,
"A");
1242 EXPECT_EQ(record->event->synthesized,
false);
1248 g_object_unref(responder);
1254 SynthesizeForDesyncPressingStateOnRemappedEvents) {
1255 EXPECT_EQ(g_call_records,
nullptr);
1256 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1257 FlKeyResponder* responder = FL_KEY_RESPONDER(
1261 FlKeyEmbedderCallRecord* record;
1264 GdkModifierType
state =
static_cast<GdkModifierType
>(0);
1266 g_autoptr(FlKeyEvent) event1 =
fl_key_event_new(101, kPress, kKeyCodeCapsLock,
1267 GDK_KEY_Control_L,
state, 0);
1271 EXPECT_EQ(g_call_records->len, 1u);
1272 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1273 EXPECT_EQ(record->event->timestamp, 101000);
1274 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1275 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
1276 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1277 EXPECT_STREQ(record->event->character,
nullptr);
1278 EXPECT_EQ(record->event->synthesized,
false);
1284 state =
static_cast<GdkModifierType
>(0);
1287 g_autoptr(FlKeyEvent) event2 =
1294 EXPECT_EQ(g_call_records->len, 2u);
1295 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1296 EXPECT_EQ(record->event->timestamp, 102000);
1297 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1298 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
1299 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1300 EXPECT_STREQ(record->event->character,
nullptr);
1301 EXPECT_EQ(record->event->synthesized,
true);
1303 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1304 EXPECT_EQ(record->event->timestamp, 102000);
1305 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1306 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1307 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1308 EXPECT_STREQ(record->event->character,
"A");
1309 EXPECT_EQ(record->event->synthesized,
false);
1315 g_object_unref(responder);
1320 TEST(FlKeyEmbedderResponderTest, SynthesizeForDesyncLockModeOnNonSelfEvents) {
1321 EXPECT_EQ(g_call_records,
nullptr);
1322 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1323 FlKeyResponder* responder = FL_KEY_RESPONDER(
1327 FlKeyEmbedderCallRecord* record;
1330 GdkModifierType
state = GDK_MOD2_MASK;
1333 g_autoptr(FlKeyEvent) event1 =
1338 EXPECT_EQ(g_call_records->len, 2u);
1339 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1340 EXPECT_EQ(record->event->timestamp, 101000);
1341 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1342 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1343 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1344 EXPECT_STREQ(record->event->character,
nullptr);
1345 EXPECT_EQ(record->event->synthesized,
true);
1347 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1348 EXPECT_EQ(record->event->timestamp, 101000);
1349 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1350 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1351 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1352 EXPECT_STREQ(record->event->character,
"a");
1353 EXPECT_EQ(record->event->synthesized,
false);
1359 state =
static_cast<GdkModifierType
>(0);
1362 g_autoptr(FlKeyEvent) event2 =
1367 EXPECT_EQ(g_call_records->len, 4u);
1368 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1369 EXPECT_EQ(record->event->timestamp, 102000);
1370 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1371 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1372 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1373 EXPECT_STREQ(record->event->character,
nullptr);
1374 EXPECT_EQ(record->event->synthesized,
true);
1376 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1377 EXPECT_EQ(record->event->timestamp, 102000);
1378 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1379 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1380 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1381 EXPECT_STREQ(record->event->character,
nullptr);
1382 EXPECT_EQ(record->event->synthesized,
true);
1384 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 2));
1385 EXPECT_EQ(record->event->timestamp, 102000);
1386 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1387 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1388 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1389 EXPECT_STREQ(record->event->character,
nullptr);
1390 EXPECT_EQ(record->event->synthesized,
true);
1392 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 3));
1393 EXPECT_EQ(record->event->timestamp, 102000);
1394 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1395 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1396 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1397 EXPECT_STREQ(record->event->character,
nullptr);
1398 EXPECT_EQ(record->event->synthesized,
false);
1407 103, kRelease, kKeyCodeNumLock, GDK_KEY_Num_Lock,
state, 0);
1411 EXPECT_EQ(g_call_records->len, 1u);
1412 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1413 EXPECT_EQ(record->event->physical, 0ull);
1414 EXPECT_EQ(record->event->logical, 0ull);
1415 EXPECT_STREQ(record->event->character,
nullptr);
1416 EXPECT_EQ(record->event->synthesized,
false);
1417 EXPECT_EQ(record->callback,
nullptr);
1420 g_object_unref(responder);
1425 TEST(FlKeyEmbedderResponderTest, SynthesizeForDesyncLockModeOnSelfEvents) {
1426 EXPECT_EQ(g_call_records,
nullptr);
1427 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1428 FlKeyResponder* responder = FL_KEY_RESPONDER(
1432 FlKeyEmbedderCallRecord* record;
1435 GdkModifierType
state = GDK_MOD2_MASK;
1438 g_autoptr(FlKeyEvent) event1 =
fl_key_event_new(101, kPress, kKeyCodeNumLock,
1439 GDK_KEY_Num_Lock,
state, 0);
1443 EXPECT_EQ(g_call_records->len, 3u);
1444 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1445 EXPECT_EQ(record->event->timestamp, 101000);
1446 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1447 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1448 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1449 EXPECT_STREQ(record->event->character,
nullptr);
1450 EXPECT_EQ(record->event->synthesized,
true);
1452 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1453 EXPECT_EQ(record->event->timestamp, 101000);
1454 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1455 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1456 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1457 EXPECT_STREQ(record->event->character,
nullptr);
1458 EXPECT_EQ(record->event->synthesized,
true);
1460 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 2));
1461 EXPECT_EQ(record->event->timestamp, 101000);
1462 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1463 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1464 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1465 EXPECT_STREQ(record->event->character,
nullptr);
1466 EXPECT_EQ(record->event->synthesized,
false);
1472 state = GDK_MOD2_MASK;
1475 g_autoptr(FlKeyEvent) event2 =
fl_key_event_new(102, kPress, kKeyCodeNumLock,
1476 GDK_KEY_Num_Lock,
state, 0);
1480 EXPECT_EQ(g_call_records->len, 4u);
1481 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1482 EXPECT_EQ(record->event->timestamp, 102000);
1483 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1484 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1485 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1486 EXPECT_STREQ(record->event->character,
nullptr);
1487 EXPECT_EQ(record->event->synthesized,
true);
1489 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1490 EXPECT_EQ(record->event->timestamp, 102000);
1491 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1492 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1493 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1494 EXPECT_STREQ(record->event->character,
nullptr);
1495 EXPECT_EQ(record->event->synthesized,
true);
1497 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 2));
1498 EXPECT_EQ(record->event->timestamp, 102000);
1499 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1500 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1501 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1502 EXPECT_STREQ(record->event->character,
nullptr);
1503 EXPECT_EQ(record->event->synthesized,
true);
1505 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 3));
1506 EXPECT_EQ(record->event->timestamp, 102000);
1507 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1508 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1509 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1510 EXPECT_STREQ(record->event->character,
nullptr);
1511 EXPECT_EQ(record->event->synthesized,
false);
1517 g_object_unref(responder);
1522 TEST(FlKeyEmbedderResponderTest, SynthesizationOccursOnIgnoredEvents) {
1523 EXPECT_EQ(g_call_records,
nullptr);
1524 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1525 FlKeyResponder* responder = FL_KEY_RESPONDER(
1529 FlKeyEmbedderCallRecord* record;
1532 GdkModifierType
state =
1533 static_cast<GdkModifierType
>(GDK_MOD2_MASK | GDK_CONTROL_MASK);
1537 g_autoptr(FlKeyEvent)
event =
1542 EXPECT_EQ(g_call_records->len, 2u);
1543 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1544 EXPECT_EQ(record->event->timestamp, 101000);
1545 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1546 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1547 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1548 EXPECT_STREQ(record->event->character,
nullptr);
1549 EXPECT_EQ(record->event->synthesized,
true);
1551 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1552 EXPECT_EQ(record->event->timestamp, 101000);
1553 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1554 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1555 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1556 EXPECT_STREQ(record->event->character,
nullptr);
1557 EXPECT_EQ(record->event->synthesized,
true);
1562 g_object_unref(responder);
1575 TEST(FlKeyEmbedderResponderTest, HandlesShiftAltVersusGroupNext) {
1576 EXPECT_EQ(g_call_records,
nullptr);
1577 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1578 FlKeyResponder* responder = FL_KEY_RESPONDER(
1582 guint32 now_time = 1;
1584 auto send_key_event = [responder, &now_time](
bool is_press, guint keyval,
1586 GdkModifierType
state) {
1589 g_autoptr(FlKeyEvent)
event =
1595 FlKeyEmbedderCallRecord* record;
1598 GDK_MODIFIER_RESERVED_25_MASK);
1599 EXPECT_EQ(g_call_records->len, 1u);
1600 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1601 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1602 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
1603 EXPECT_EQ(record->event->logical, kLogicalShiftLeft);
1604 EXPECT_EQ(record->event->synthesized,
false);
1607 static_cast<GdkModifierType
>(GDK_SHIFT_MASK |
1608 GDK_MODIFIER_RESERVED_25_MASK));
1609 EXPECT_EQ(g_call_records->len, 2u);
1610 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1611 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1612 EXPECT_EQ(record->event->physical, kPhysicalAltRight);
1613 EXPECT_EQ(record->event->logical, kLogicalMetaRight);
1614 EXPECT_EQ(record->event->synthesized,
false);
1616 send_key_event(kRelease, GDK_KEY_ISO_Next_Group, kKeyCodeShiftLeft,
1617 static_cast<GdkModifierType
>(GDK_SHIFT_MASK | GDK_MOD1_MASK |
1618 GDK_MODIFIER_RESERVED_25_MASK));
1619 EXPECT_EQ(g_call_records->len, 5u);
1620 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 2));
1621 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1622 EXPECT_EQ(record->event->physical, kPhysicalAltLeft);
1623 EXPECT_EQ(record->event->logical, kLogicalAltLeft);
1624 EXPECT_EQ(record->event->synthesized,
true);
1626 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 3));
1627 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1628 EXPECT_EQ(record->event->physical, kPhysicalAltRight);
1629 EXPECT_EQ(record->event->logical, kLogicalMetaRight);
1630 EXPECT_EQ(record->event->synthesized,
true);
1632 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 4));
1633 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1634 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
1635 EXPECT_EQ(record->event->logical, kLogicalShiftLeft);
1636 EXPECT_EQ(record->event->synthesized,
false);
1638 send_key_event(kPress, GDK_KEY_ISO_Next_Group, kKeyCodeShiftLeft,
1639 static_cast<GdkModifierType
>(GDK_MOD1_MASK |
1640 GDK_MODIFIER_RESERVED_25_MASK));
1641 EXPECT_EQ(g_call_records->len, 6u);
1642 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 5));
1643 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1644 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
1645 EXPECT_EQ(record->event->logical, kLogicalGroupNext);
1646 EXPECT_EQ(record->event->synthesized,
false);
1648 send_key_event(kRelease, GDK_KEY_ISO_Level3_Shift, kKeyCodeAltRight,
1649 static_cast<GdkModifierType
>(GDK_MOD1_MASK |
1650 GDK_MODIFIER_RESERVED_13_MASK |
1651 GDK_MODIFIER_RESERVED_25_MASK));
1652 EXPECT_EQ(g_call_records->len, 7u);
1653 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 6));
1654 EXPECT_EQ(record->event->physical, 0u);
1655 EXPECT_EQ(record->event->logical, 0u);
1658 static_cast<GdkModifierType
>(GDK_MODIFIER_RESERVED_13_MASK |
1659 GDK_MODIFIER_RESERVED_25_MASK));
1660 EXPECT_EQ(g_call_records->len, 9u);
1661 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 7));
1662 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1663 EXPECT_EQ(record->event->physical, kPhysicalAltLeft);
1664 EXPECT_EQ(record->event->logical, kLogicalAltLeft);
1665 EXPECT_EQ(record->event->synthesized,
true);
1667 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 8));
1668 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1669 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
1670 EXPECT_EQ(record->event->logical, kLogicalGroupNext);
1671 EXPECT_EQ(record->event->synthesized,
false);
1674 g_object_unref(responder);
1683 TEST(FlKeyEmbedderResponderTest, HandlesShiftAltLeftIsMetaLeft) {
1684 EXPECT_EQ(g_call_records,
nullptr);
1685 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1686 FlKeyResponder* responder = FL_KEY_RESPONDER(
1690 guint32 now_time = 1;
1692 auto send_key_event = [responder, &now_time](
bool is_press, guint keyval,
1694 GdkModifierType
state) {
1697 g_autoptr(FlKeyEvent)
event =
1703 FlKeyEmbedderCallRecord* record;
1707 GDK_MODIFIER_RESERVED_25_MASK);
1708 EXPECT_EQ(g_call_records->len, 1u);
1709 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1710 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1711 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
1712 EXPECT_EQ(record->event->logical, kLogicalShiftLeft);
1713 EXPECT_EQ(record->event->synthesized,
false);
1716 static_cast<GdkModifierType
>(GDK_SHIFT_MASK |
1717 GDK_MODIFIER_RESERVED_25_MASK));
1718 EXPECT_EQ(g_call_records->len, 2u);
1719 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1720 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1721 EXPECT_EQ(record->event->physical, kPhysicalMetaLeft);
1722 EXPECT_EQ(record->event->logical, kLogicalMetaLeft);
1723 EXPECT_EQ(record->event->synthesized,
false);
1726 static_cast<GdkModifierType
>(GDK_MODIFIER_RESERVED_13_MASK |
1727 GDK_MODIFIER_RESERVED_25_MASK));
1729 GDK_MODIFIER_RESERVED_25_MASK);
1734 GDK_MODIFIER_RESERVED_25_MASK);
1735 EXPECT_EQ(g_call_records->len, 1u);
1736 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1737 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1738 EXPECT_EQ(record->event->physical, kPhysicalShiftRight);
1739 EXPECT_EQ(record->event->logical, kLogicalShiftRight);
1740 EXPECT_EQ(record->event->synthesized,
false);
1743 static_cast<GdkModifierType
>(GDK_SHIFT_MASK |
1744 GDK_MODIFIER_RESERVED_25_MASK));
1745 EXPECT_EQ(g_call_records->len, 2u);
1746 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1747 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1748 EXPECT_EQ(record->event->physical, kPhysicalMetaLeft);
1749 EXPECT_EQ(record->event->logical, kLogicalMetaLeft);
1750 EXPECT_EQ(record->event->synthesized,
false);
1753 g_object_unref(responder);