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 gboolean kIsModifier =
TRUE;
20 constexpr gboolean kIsNotModifier = FALSE;
22 constexpr guint16 kKeyCodeDigit1 = 0x0au;
23 constexpr guint16 kKeyCodeKeyA = 0x26u;
24 constexpr guint16 kKeyCodeShiftLeft = 0x32u;
25 constexpr guint16 kKeyCodeShiftRight = 0x3Eu;
26 constexpr guint16 kKeyCodeAltLeft = 0x40u;
27 constexpr guint16 kKeyCodeAltRight = 0x6Cu;
28 constexpr guint16 kKeyCodeNumpad1 = 0x57u;
29 constexpr guint16 kKeyCodeNumLock = 0x4Du;
30 constexpr guint16 kKeyCodeCapsLock = 0x42u;
31 constexpr guint16 kKeyCodeControlLeft = 0x25u;
32 constexpr guint16 kKeyCodeControlRight = 0x69u;
34 using namespace ::flutter::testing::keycodes;
38 g_ptr_array_remove_range(array, 0, array->len);
42 fl_key_embedder_call_record,
44 KEY_EMBEDDER_CALL_RECORD,
56 fl_key_embedder_call_record,
59 static void fl_key_embedder_call_record_init(FlKeyEmbedderCallRecord*
self) {}
63 g_return_if_fail(FL_IS_KEY_EMBEDDER_CALL_RECORD(
object));
65 FlKeyEmbedderCallRecord*
self = FL_KEY_EMBEDDER_CALL_RECORD(
object);
66 if (self->event !=
nullptr) {
67 g_free(
const_cast<char*
>(self->event->character));
70 G_OBJECT_CLASS(fl_key_embedder_call_record_parent_class)->dispose(
object);
75 FlKeyEmbedderCallRecordClass* klass) {
80 const FlutterKeyEvent*
event,
83 g_return_val_if_fail(
event !=
nullptr,
nullptr);
85 FlKeyEmbedderCallRecord*
self = FL_KEY_EMBEDDER_CALL_RECORD(
86 g_object_new(fl_key_embedder_call_record_get_type(),
nullptr));
88 FlutterKeyEvent* clone_event = g_new(FlutterKeyEvent, 1);
89 *clone_event = *
event;
90 if (
event->character !=
nullptr) {
91 size_t character_length = strlen(
event->character);
92 char* clone_character = g_new(
char, character_length + 1);
93 strncpy(clone_character,
event->character, character_length + 1);
94 clone_event->character = clone_character;
96 self->event = clone_event;
119 GdkModifierType
state,
120 gboolean is_modifier) {
122 _g_key_event.time = time_in_milliseconds;
123 _g_key_event.state =
state;
124 _g_key_event.keyval = keyval;
125 _g_key_event.keycode = keycode;
126 _g_key_event.origin =
nullptr;
127 return &_g_key_event;
139 void* expected_user_data) {
140 g_return_if_fail(record->callback !=
nullptr);
147 GPtrArray* g_call_records;
152 void* callback_user_data,
153 void* send_key_event_user_data) {
154 GPtrArray* records_array =
155 reinterpret_cast<GPtrArray*
>(send_key_event_user_data);
156 if (records_array !=
nullptr) {
163 g_ptr_array_free(g_call_records,
TRUE);
164 g_call_records =
nullptr;
168 TEST(FlKeyEmbedderResponderTest, SendKeyEvent) {
169 EXPECT_EQ(g_call_records,
nullptr);
170 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
171 FlKeyResponder* responder = FL_KEY_RESPONDER(
175 FlKeyEmbedderCallRecord* record;
182 static_cast<GdkModifierType
>(0), kIsNotModifier),
185 EXPECT_EQ(g_call_records->len, 1u);
186 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
187 EXPECT_EQ(record->event->struct_size,
sizeof(FlutterKeyEvent));
188 EXPECT_EQ(record->event->timestamp, 12345000);
189 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
190 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
191 EXPECT_EQ(record->event->logical, kLogicalKeyA);
192 EXPECT_STREQ(record->event->character,
"a");
193 EXPECT_EQ(record->event->synthesized,
false);
202 static_cast<GdkModifierType
>(0), kIsNotModifier),
205 EXPECT_EQ(g_call_records->len, 1u);
206 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
207 EXPECT_EQ(record->event->struct_size,
sizeof(FlutterKeyEvent));
208 EXPECT_EQ(record->event->timestamp, 12346000);
209 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
210 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
211 EXPECT_EQ(record->event->logical, kLogicalKeyA);
212 EXPECT_STREQ(record->event->character,
nullptr);
213 EXPECT_EQ(record->event->synthesized,
false);
223 static_cast<GdkModifierType
>(0), kIsNotModifier),
226 EXPECT_EQ(g_call_records->len, 1u);
227 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
228 EXPECT_EQ(record->event->struct_size,
sizeof(FlutterKeyEvent));
229 EXPECT_EQ(record->event->timestamp, 12347000);
230 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
231 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
232 EXPECT_EQ(record->event->logical, kLogicalKeyQ);
233 EXPECT_STREQ(record->event->character,
"q");
234 EXPECT_EQ(record->event->synthesized,
false);
243 static_cast<GdkModifierType
>(0), kIsNotModifier),
246 EXPECT_EQ(g_call_records->len, 1u);
247 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
248 EXPECT_EQ(record->event->struct_size,
sizeof(FlutterKeyEvent));
249 EXPECT_EQ(record->event->timestamp, 12348000);
250 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
251 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
252 EXPECT_EQ(record->event->logical, kLogicalKeyQ);
253 EXPECT_STREQ(record->event->character,
nullptr);
254 EXPECT_EQ(record->event->synthesized,
false);
260 g_object_unref(responder);
264 TEST(FlKeyEmbedderResponderTest, UsesSpecifiedLogicalKey) {
265 EXPECT_EQ(g_call_records,
nullptr);
266 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
267 FlKeyResponder* responder = FL_KEY_RESPONDER(
271 FlKeyEmbedderCallRecord* record;
278 static_cast<GdkModifierType
>(0), kIsNotModifier),
281 EXPECT_EQ(g_call_records->len, 1u);
282 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
283 EXPECT_EQ(record->event->struct_size,
sizeof(FlutterKeyEvent));
284 EXPECT_EQ(record->event->timestamp, 12345000);
285 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
286 EXPECT_EQ(record->event->physical, kPhysicalDigit1);
287 EXPECT_EQ(record->event->logical, kLogicalDigit1);
288 EXPECT_STREQ(record->event->character,
"&");
289 EXPECT_EQ(record->event->synthesized,
false);
295 g_object_unref(responder);
299 TEST(FlKeyEmbedderResponderTest, PressShiftDuringLetterKeyTap) {
300 EXPECT_EQ(g_call_records,
nullptr);
301 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
302 FlKeyResponder* responder = FL_KEY_RESPONDER(
306 FlKeyEmbedderCallRecord* record;
312 static_cast<GdkModifierType
>(0), kIsModifier),
315 EXPECT_EQ(g_call_records->len, 1u);
316 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
317 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
318 EXPECT_EQ(record->event->physical, kPhysicalShiftRight);
319 EXPECT_EQ(record->event->logical, kLogicalShiftRight);
320 EXPECT_STREQ(record->event->character,
nullptr);
321 EXPECT_EQ(record->event->synthesized,
false);
330 GDK_SHIFT_MASK, kIsNotModifier),
333 EXPECT_EQ(g_call_records->len, 1u);
334 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
335 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
336 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
337 EXPECT_EQ(record->event->logical, kLogicalKeyA);
338 EXPECT_STREQ(record->event->character,
"A");
339 EXPECT_EQ(record->event->synthesized,
false);
348 kKeyCodeShiftRight, GDK_SHIFT_MASK, kIsModifier),
351 EXPECT_EQ(g_call_records->len, 1u);
352 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
353 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
354 EXPECT_EQ(record->event->physical, kPhysicalShiftRight);
355 EXPECT_EQ(record->event->logical, kLogicalShiftRight);
356 EXPECT_STREQ(record->event->character,
nullptr);
357 EXPECT_EQ(record->event->synthesized,
false);
366 static_cast<GdkModifierType
>(0), kIsNotModifier),
369 EXPECT_EQ(g_call_records->len, 1u);
370 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
371 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
372 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
373 EXPECT_EQ(record->event->logical, kLogicalKeyA);
374 EXPECT_STREQ(record->event->character,
nullptr);
375 EXPECT_EQ(record->event->synthesized,
false);
381 g_object_unref(responder);
392 TEST(FlKeyEmbedderResponderTest, TapNumPadKeysBetweenNumLockEvents) {
393 EXPECT_EQ(g_call_records,
nullptr);
394 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
395 FlKeyResponder* responder = FL_KEY_RESPONDER(
399 FlKeyEmbedderCallRecord* record;
405 static_cast<GdkModifierType
>(0), kIsNotModifier),
408 EXPECT_EQ(g_call_records->len, 1u);
409 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
410 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
411 EXPECT_EQ(record->event->physical, kPhysicalNumpad1);
412 EXPECT_EQ(record->event->logical, kLogicalNumpad1);
413 EXPECT_STREQ(record->event->character,
nullptr);
414 EXPECT_EQ(record->event->synthesized,
false);
423 static_cast<GdkModifierType
>(0), kIsNotModifier),
426 EXPECT_EQ(g_call_records->len, 1u);
427 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
428 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
429 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
430 EXPECT_EQ(record->event->logical, kLogicalNumLock);
431 EXPECT_STREQ(record->event->character,
nullptr);
432 EXPECT_EQ(record->event->synthesized,
false);
441 GDK_MOD2_MASK, kIsNotModifier),
444 EXPECT_EQ(g_call_records->len, 1u);
445 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
446 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
447 EXPECT_EQ(record->event->physical, kPhysicalNumpad1);
448 EXPECT_EQ(record->event->logical, kLogicalNumpad1);
449 EXPECT_STREQ(record->event->character,
nullptr);
450 EXPECT_EQ(record->event->synthesized,
false);
459 GDK_MOD2_MASK, kIsModifier),
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, kFlutterKeyEventTypeUp);
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);
477 GDK_MOD2_MASK, kIsNotModifier),
480 EXPECT_EQ(g_call_records->len, 1u);
481 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
482 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
483 EXPECT_EQ(record->event->physical, kPhysicalNumpad1);
484 EXPECT_EQ(record->event->logical, kLogicalNumpad1);
485 EXPECT_STREQ(record->event->character,
nullptr);
486 EXPECT_EQ(record->event->synthesized,
false);
495 GDK_MOD2_MASK, kIsNotModifier),
498 EXPECT_EQ(g_call_records->len, 1u);
499 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
500 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
501 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
502 EXPECT_EQ(record->event->logical, kLogicalNumLock);
503 EXPECT_STREQ(record->event->character,
nullptr);
504 EXPECT_EQ(record->event->synthesized,
false);
513 GDK_MOD2_MASK, kIsNotModifier),
516 EXPECT_EQ(g_call_records->len, 1u);
517 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
518 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
519 EXPECT_EQ(record->event->physical, kPhysicalNumpad1);
520 EXPECT_EQ(record->event->logical, kLogicalNumpad1);
521 EXPECT_STREQ(record->event->character,
nullptr);
522 EXPECT_EQ(record->event->synthesized,
false);
531 GDK_MOD2_MASK, kIsModifier),
534 EXPECT_EQ(g_call_records->len, 1u);
535 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
536 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
537 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
538 EXPECT_EQ(record->event->logical, kLogicalNumLock);
539 EXPECT_STREQ(record->event->character,
nullptr);
540 EXPECT_EQ(record->event->synthesized,
false);
546 g_object_unref(responder);
553 TEST(FlKeyEmbedderResponderTest, ReleaseShiftKeyBetweenDigitKeyEvents) {
554 EXPECT_EQ(g_call_records,
nullptr);
555 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
556 FlKeyResponder* responder = FL_KEY_RESPONDER(
560 FlKeyEmbedderCallRecord* record;
562 GdkModifierType
state =
static_cast<GdkModifierType
>(0);
571 EXPECT_EQ(g_call_records->len, 1u);
572 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
573 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
574 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
575 EXPECT_EQ(record->event->logical, kLogicalShiftLeft);
576 EXPECT_STREQ(record->event->character,
nullptr);
577 EXPECT_EQ(record->event->synthesized,
false);
582 state = GDK_SHIFT_MASK;
588 state, kIsNotModifier),
591 EXPECT_EQ(g_call_records->len, 1u);
592 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
593 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
594 EXPECT_EQ(record->event->physical, kPhysicalDigit1);
595 EXPECT_EQ(record->event->logical, kLogicalExclamation);
596 EXPECT_STREQ(record->event->character,
"!");
597 EXPECT_EQ(record->event->synthesized,
false);
606 kKeyCodeShiftLeft,
state, kIsModifier),
609 EXPECT_EQ(g_call_records->len, 1u);
610 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
611 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
612 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
613 EXPECT_EQ(record->event->logical, kLogicalShiftLeft);
614 EXPECT_STREQ(record->event->character,
nullptr);
615 EXPECT_EQ(record->event->synthesized,
false);
620 state =
static_cast<GdkModifierType
>(0);
629 EXPECT_EQ(g_call_records->len, 1u);
630 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
631 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
632 EXPECT_EQ(record->event->physical, kPhysicalDigit1);
633 EXPECT_EQ(record->event->logical, kLogicalExclamation);
634 EXPECT_STREQ(record->event->character,
nullptr);
635 EXPECT_EQ(record->event->synthesized,
false);
641 g_object_unref(responder);
648 TEST(FlKeyEmbedderResponderTest, TapLetterKeysBetweenCapsLockEvents) {
649 EXPECT_EQ(g_call_records,
nullptr);
650 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
651 FlKeyResponder* responder = FL_KEY_RESPONDER(
655 FlKeyEmbedderCallRecord* record;
661 static_cast<GdkModifierType
>(0), kIsModifier),
664 EXPECT_EQ(g_call_records->len, 1u);
665 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
666 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
667 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
668 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
669 EXPECT_STREQ(record->event->character,
nullptr);
670 EXPECT_EQ(record->event->synthesized,
false);
679 GDK_LOCK_MASK, kIsNotModifier),
682 EXPECT_EQ(g_call_records->len, 1u);
683 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
684 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
685 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
686 EXPECT_EQ(record->event->logical, kLogicalKeyA);
687 EXPECT_STREQ(record->event->character,
"A");
688 EXPECT_EQ(record->event->synthesized,
false);
697 kKeyCodeCapsLock, GDK_LOCK_MASK, kIsModifier),
700 EXPECT_EQ(g_call_records->len, 1u);
701 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
702 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
703 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
704 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
705 EXPECT_STREQ(record->event->character,
nullptr);
706 EXPECT_EQ(record->event->synthesized,
false);
715 GDK_LOCK_MASK, kIsNotModifier),
718 EXPECT_EQ(g_call_records->len, 1u);
719 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
720 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
721 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
722 EXPECT_EQ(record->event->logical, kLogicalKeyA);
723 EXPECT_STREQ(record->event->character,
nullptr);
724 EXPECT_EQ(record->event->synthesized,
false);
733 GDK_LOCK_MASK, kIsModifier),
736 EXPECT_EQ(g_call_records->len, 1u);
737 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
738 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
739 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
740 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
741 EXPECT_STREQ(record->event->character,
nullptr);
742 EXPECT_EQ(record->event->synthesized,
false);
751 GDK_LOCK_MASK, kIsNotModifier),
754 EXPECT_EQ(g_call_records->len, 1u);
755 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
756 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
757 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
758 EXPECT_EQ(record->event->logical, kLogicalKeyA);
759 EXPECT_STREQ(record->event->character,
"A");
760 EXPECT_EQ(record->event->synthesized,
false);
769 kKeyCodeCapsLock, GDK_LOCK_MASK, kIsModifier),
772 EXPECT_EQ(g_call_records->len, 1u);
773 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
774 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
775 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
776 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
777 EXPECT_STREQ(record->event->character,
nullptr);
778 EXPECT_EQ(record->event->synthesized,
false);
787 static_cast<GdkModifierType
>(0), kIsNotModifier),
790 EXPECT_EQ(g_call_records->len, 1u);
791 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
792 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
793 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
794 EXPECT_EQ(record->event->logical, kLogicalKeyA);
795 EXPECT_STREQ(record->event->character,
nullptr);
796 EXPECT_EQ(record->event->synthesized,
false);
802 g_object_unref(responder);
809 TEST(FlKeyEmbedderResponderTest, TapLetterKeysBetweenCapsLockEventsReversed) {
810 EXPECT_EQ(g_call_records,
nullptr);
811 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
812 FlKeyResponder* responder = FL_KEY_RESPONDER(
816 FlKeyEmbedderCallRecord* record;
822 static_cast<GdkModifierType
>(0), kIsNotModifier),
825 EXPECT_EQ(g_call_records->len, 1u);
826 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
827 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
828 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
829 EXPECT_EQ(record->event->logical, kLogicalKeyA);
830 EXPECT_STREQ(record->event->character,
"a");
831 EXPECT_EQ(record->event->synthesized,
false);
840 GDK_LOCK_MASK, kIsModifier),
843 EXPECT_EQ(g_call_records->len, 1u);
844 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
845 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
846 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
847 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
848 EXPECT_STREQ(record->event->character,
nullptr);
849 EXPECT_EQ(record->event->synthesized,
false);
858 kKeyCodeCapsLock, GDK_LOCK_MASK, kIsModifier),
861 EXPECT_EQ(g_call_records->len, 1u);
862 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
863 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
864 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
865 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
866 EXPECT_STREQ(record->event->character,
nullptr);
867 EXPECT_EQ(record->event->synthesized,
false);
876 GDK_LOCK_MASK, kIsNotModifier),
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, kPhysicalKeyA);
883 EXPECT_EQ(record->event->logical, kLogicalKeyA);
884 EXPECT_STREQ(record->event->character,
nullptr);
885 EXPECT_EQ(record->event->synthesized,
false);
894 GDK_LOCK_MASK, kIsNotModifier),
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, kFlutterKeyEventTypeDown);
900 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
901 EXPECT_EQ(record->event->logical, kLogicalKeyA);
902 EXPECT_STREQ(record->event->character,
"A");
903 EXPECT_EQ(record->event->synthesized,
false);
912 static_cast<GdkModifierType
>(0), kIsModifier),
915 EXPECT_EQ(g_call_records->len, 1u);
916 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
917 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
918 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
919 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
920 EXPECT_STREQ(record->event->character,
nullptr);
921 EXPECT_EQ(record->event->synthesized,
false);
930 kKeyCodeCapsLock, GDK_LOCK_MASK, kIsModifier),
933 EXPECT_EQ(g_call_records->len, 1u);
934 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
935 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
936 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
937 EXPECT_EQ(record->event->logical, kLogicalCapsLock);
938 EXPECT_STREQ(record->event->character,
nullptr);
939 EXPECT_EQ(record->event->synthesized,
false);
948 static_cast<GdkModifierType
>(0), kIsNotModifier),
951 EXPECT_EQ(g_call_records->len, 1u);
952 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
953 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
954 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
955 EXPECT_EQ(record->event->logical, kLogicalKeyA);
956 EXPECT_STREQ(record->event->character,
nullptr);
957 EXPECT_EQ(record->event->synthesized,
false);
963 g_object_unref(responder);
966 TEST(FlKeyEmbedderResponderTest, TurnDuplicateDownEventsToRepeats) {
967 EXPECT_EQ(g_call_records,
nullptr);
968 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
969 FlKeyResponder* responder = FL_KEY_RESPONDER(
973 FlKeyEmbedderCallRecord* record;
979 static_cast<GdkModifierType
>(0), kIsNotModifier),
982 EXPECT_EQ(g_call_records->len, 1u);
984 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
993 static_cast<GdkModifierType
>(0), kIsNotModifier),
996 EXPECT_EQ(g_call_records->len, 1u);
998 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
999 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeRepeat);
1000 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1001 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1002 EXPECT_STREQ(record->event->character,
"a");
1003 EXPECT_EQ(record->event->synthesized,
false);
1004 EXPECT_NE(record->callback,
nullptr);
1013 static_cast<GdkModifierType
>(0), kIsNotModifier),
1016 EXPECT_EQ(g_call_records->len, 1u);
1017 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1022 g_object_unref(responder);
1025 TEST(FlKeyEmbedderResponderTest, IgnoreAbruptUpEvent) {
1026 FlKeyEmbedderCallRecord* record;
1028 EXPECT_EQ(g_call_records,
nullptr);
1029 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1030 FlKeyResponder* responder = FL_KEY_RESPONDER(
1039 static_cast<GdkModifierType
>(0), kIsNotModifier),
1042 EXPECT_EQ(g_call_records->len, 1u);
1044 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1045 EXPECT_EQ(record->event->physical, 0ull);
1046 EXPECT_EQ(record->event->logical, 0ull);
1047 EXPECT_STREQ(record->event->character,
nullptr);
1048 EXPECT_EQ(record->event->synthesized,
false);
1049 EXPECT_EQ(record->callback,
nullptr);
1052 g_object_unref(responder);
1057 TEST(FlKeyEmbedderResponderTest, SynthesizeForDesyncPressingStateOnSelfEvents) {
1058 EXPECT_EQ(g_call_records,
nullptr);
1059 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1060 FlKeyResponder* responder = FL_KEY_RESPONDER(
1064 FlKeyEmbedderCallRecord* record;
1069 GdkModifierType
state = GDK_CONTROL_MASK;
1075 kKeyCodeControlLeft,
state, kIsModifier),
1078 EXPECT_EQ(g_call_records->len, 2u);
1079 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1080 EXPECT_EQ(record->event->timestamp, 101000);
1081 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1082 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1083 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1084 EXPECT_STREQ(record->event->character,
nullptr);
1085 EXPECT_EQ(record->event->synthesized,
true);
1087 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1088 EXPECT_EQ(record->event->timestamp, 101000);
1089 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1090 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1091 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1092 EXPECT_STREQ(record->event->character,
nullptr);
1093 EXPECT_EQ(record->event->synthesized,
false);
1101 state =
static_cast<GdkModifierType
>(0);
1105 kKeyCodeControlLeft,
state, kIsModifier),
1107 EXPECT_EQ(g_call_records->len, 1u);
1108 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1113 state =
static_cast<GdkModifierType
>(0);
1119 kKeyCodeControlLeft,
state, kIsModifier),
1122 EXPECT_EQ(g_call_records->len, 2u);
1123 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1124 EXPECT_EQ(record->event->timestamp, 103000);
1125 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1126 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1127 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1128 EXPECT_STREQ(record->event->character,
nullptr);
1129 EXPECT_EQ(record->event->synthesized,
true);
1131 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1132 EXPECT_EQ(record->event->timestamp, 103000);
1133 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1134 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1135 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1136 EXPECT_STREQ(record->event->character,
nullptr);
1137 EXPECT_EQ(record->event->synthesized,
false);
1143 state = GDK_CONTROL_MASK;
1147 kKeyCodeControlLeft,
state, kIsModifier),
1149 EXPECT_EQ(g_call_records->len, 1u);
1150 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1157 state = GDK_CONTROL_MASK;
1163 kKeyCodeControlRight,
state, kIsModifier),
1170 EXPECT_EQ(g_call_records->len, 1u);
1171 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1172 EXPECT_EQ(record->event->timestamp, 105000);
1173 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1174 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1175 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1176 EXPECT_STREQ(record->event->character,
nullptr);
1177 EXPECT_EQ(record->event->synthesized,
true);
1182 g_object_unref(responder);
1188 SynthesizeForDesyncPressingStateOnNonSelfEvents) {
1189 EXPECT_EQ(g_call_records,
nullptr);
1190 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1191 FlKeyResponder* responder = FL_KEY_RESPONDER(
1195 FlKeyEmbedderCallRecord* record;
1198 GdkModifierType
state = GDK_CONTROL_MASK;
1207 EXPECT_EQ(g_call_records->len, 2u);
1208 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1209 EXPECT_EQ(record->event->timestamp, 101000);
1210 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1211 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1212 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1213 EXPECT_STREQ(record->event->character,
nullptr);
1214 EXPECT_EQ(record->event->synthesized,
true);
1216 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1217 EXPECT_EQ(record->event->timestamp, 101000);
1218 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1219 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1220 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1221 EXPECT_STREQ(record->event->character,
"a");
1222 EXPECT_EQ(record->event->synthesized,
false);
1228 state =
static_cast<GdkModifierType
>(0);
1237 EXPECT_EQ(g_call_records->len, 2u);
1238 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1239 EXPECT_EQ(record->event->timestamp, 102000);
1240 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1241 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1242 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1243 EXPECT_STREQ(record->event->character,
nullptr);
1244 EXPECT_EQ(record->event->synthesized,
true);
1246 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1247 EXPECT_EQ(record->event->timestamp, 102000);
1248 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1249 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1250 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1251 EXPECT_STREQ(record->event->character,
nullptr);
1252 EXPECT_EQ(record->event->synthesized,
false);
1260 state =
static_cast<GdkModifierType
>(0);
1265 state, kIsModifier),
1268 EXPECT_EQ(g_call_records->len, 1u);
1269 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1270 EXPECT_EQ(record->event->timestamp, 101000);
1271 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1272 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
1273 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1274 EXPECT_STREQ(record->event->character,
nullptr);
1275 EXPECT_EQ(record->event->synthesized,
false);
1281 state =
static_cast<GdkModifierType
>(0);
1292 EXPECT_EQ(g_call_records->len, 2u);
1293 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1294 EXPECT_EQ(record->event->timestamp, 102000);
1295 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1296 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
1297 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1298 EXPECT_STREQ(record->event->character,
nullptr);
1299 EXPECT_EQ(record->event->synthesized,
true);
1301 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1302 EXPECT_EQ(record->event->timestamp, 102000);
1303 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1304 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1305 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1306 EXPECT_STREQ(record->event->character,
"A");
1307 EXPECT_EQ(record->event->synthesized,
false);
1313 g_object_unref(responder);
1319 SynthesizeForDesyncPressingStateOnRemappedEvents) {
1320 EXPECT_EQ(g_call_records,
nullptr);
1321 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1322 FlKeyResponder* responder = FL_KEY_RESPONDER(
1326 FlKeyEmbedderCallRecord* record;
1329 GdkModifierType
state =
static_cast<GdkModifierType
>(0);
1334 state, kIsModifier),
1337 EXPECT_EQ(g_call_records->len, 1u);
1338 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1339 EXPECT_EQ(record->event->timestamp, 101000);
1340 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1341 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
1342 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1343 EXPECT_STREQ(record->event->character,
nullptr);
1344 EXPECT_EQ(record->event->synthesized,
false);
1350 state =
static_cast<GdkModifierType
>(0);
1361 EXPECT_EQ(g_call_records->len, 2u);
1362 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1363 EXPECT_EQ(record->event->timestamp, 102000);
1364 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1365 EXPECT_EQ(record->event->physical, kPhysicalCapsLock);
1366 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1367 EXPECT_STREQ(record->event->character,
nullptr);
1368 EXPECT_EQ(record->event->synthesized,
true);
1370 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1371 EXPECT_EQ(record->event->timestamp, 102000);
1372 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1373 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1374 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1375 EXPECT_STREQ(record->event->character,
"A");
1376 EXPECT_EQ(record->event->synthesized,
false);
1382 g_object_unref(responder);
1387 TEST(FlKeyEmbedderResponderTest, SynthesizeForDesyncLockModeOnNonSelfEvents) {
1388 EXPECT_EQ(g_call_records,
nullptr);
1389 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1390 FlKeyResponder* responder = FL_KEY_RESPONDER(
1394 FlKeyEmbedderCallRecord* record;
1397 GdkModifierType
state = GDK_MOD2_MASK;
1406 EXPECT_EQ(g_call_records->len, 2u);
1407 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1408 EXPECT_EQ(record->event->timestamp, 101000);
1409 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1410 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1411 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1412 EXPECT_STREQ(record->event->character,
nullptr);
1413 EXPECT_EQ(record->event->synthesized,
true);
1415 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1416 EXPECT_EQ(record->event->timestamp, 101000);
1417 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1418 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1419 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1420 EXPECT_STREQ(record->event->character,
"a");
1421 EXPECT_EQ(record->event->synthesized,
false);
1427 state =
static_cast<GdkModifierType
>(0);
1436 EXPECT_EQ(g_call_records->len, 4u);
1437 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1438 EXPECT_EQ(record->event->timestamp, 102000);
1439 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1440 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1441 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1442 EXPECT_STREQ(record->event->character,
nullptr);
1443 EXPECT_EQ(record->event->synthesized,
true);
1445 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1446 EXPECT_EQ(record->event->timestamp, 102000);
1447 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1448 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1449 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1450 EXPECT_STREQ(record->event->character,
nullptr);
1451 EXPECT_EQ(record->event->synthesized,
true);
1453 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 2));
1454 EXPECT_EQ(record->event->timestamp, 102000);
1455 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1456 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1457 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1458 EXPECT_STREQ(record->event->character,
nullptr);
1459 EXPECT_EQ(record->event->synthesized,
true);
1461 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 3));
1462 EXPECT_EQ(record->event->timestamp, 102000);
1463 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1464 EXPECT_EQ(record->event->physical, kPhysicalKeyA);
1465 EXPECT_EQ(record->event->logical, kLogicalKeyA);
1466 EXPECT_STREQ(record->event->character,
nullptr);
1467 EXPECT_EQ(record->event->synthesized,
false);
1478 state, kIsModifier),
1481 EXPECT_EQ(g_call_records->len, 1u);
1482 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1483 EXPECT_EQ(record->event->physical, 0ull);
1484 EXPECT_EQ(record->event->logical, 0ull);
1485 EXPECT_STREQ(record->event->character,
nullptr);
1486 EXPECT_EQ(record->event->synthesized,
false);
1487 EXPECT_EQ(record->callback,
nullptr);
1490 g_object_unref(responder);
1495 TEST(FlKeyEmbedderResponderTest, SynthesizeForDesyncLockModeOnSelfEvents) {
1496 EXPECT_EQ(g_call_records,
nullptr);
1497 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1498 FlKeyResponder* responder = FL_KEY_RESPONDER(
1502 FlKeyEmbedderCallRecord* record;
1505 GdkModifierType
state = GDK_MOD2_MASK;
1511 state, kIsModifier),
1514 EXPECT_EQ(g_call_records->len, 3u);
1515 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1516 EXPECT_EQ(record->event->timestamp, 101000);
1517 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1518 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1519 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1520 EXPECT_STREQ(record->event->character,
nullptr);
1521 EXPECT_EQ(record->event->synthesized,
true);
1523 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1524 EXPECT_EQ(record->event->timestamp, 101000);
1525 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1526 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1527 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1528 EXPECT_STREQ(record->event->character,
nullptr);
1529 EXPECT_EQ(record->event->synthesized,
true);
1531 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 2));
1532 EXPECT_EQ(record->event->timestamp, 101000);
1533 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1534 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1535 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1536 EXPECT_STREQ(record->event->character,
nullptr);
1537 EXPECT_EQ(record->event->synthesized,
false);
1543 state = GDK_MOD2_MASK;
1549 state, kIsModifier),
1552 EXPECT_EQ(g_call_records->len, 4u);
1553 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1554 EXPECT_EQ(record->event->timestamp, 102000);
1555 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1556 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1557 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1558 EXPECT_STREQ(record->event->character,
nullptr);
1559 EXPECT_EQ(record->event->synthesized,
true);
1561 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1562 EXPECT_EQ(record->event->timestamp, 102000);
1563 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1564 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1565 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1566 EXPECT_STREQ(record->event->character,
nullptr);
1567 EXPECT_EQ(record->event->synthesized,
true);
1569 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 2));
1570 EXPECT_EQ(record->event->timestamp, 102000);
1571 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1572 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1573 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1574 EXPECT_STREQ(record->event->character,
nullptr);
1575 EXPECT_EQ(record->event->synthesized,
true);
1577 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 3));
1578 EXPECT_EQ(record->event->timestamp, 102000);
1579 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1580 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1581 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1582 EXPECT_STREQ(record->event->character,
nullptr);
1583 EXPECT_EQ(record->event->synthesized,
false);
1589 g_object_unref(responder);
1594 TEST(FlKeyEmbedderResponderTest, SynthesizationOccursOnIgnoredEvents) {
1595 EXPECT_EQ(g_call_records,
nullptr);
1596 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1597 FlKeyResponder* responder = FL_KEY_RESPONDER(
1601 FlKeyEmbedderCallRecord* record;
1604 GdkModifierType
state =
1605 static_cast<GdkModifierType
>(GDK_MOD2_MASK | GDK_CONTROL_MASK);
1615 EXPECT_EQ(g_call_records->len, 2u);
1616 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1617 EXPECT_EQ(record->event->timestamp, 101000);
1618 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1619 EXPECT_EQ(record->event->physical, kPhysicalNumLock);
1620 EXPECT_EQ(record->event->logical, kLogicalNumLock);
1621 EXPECT_STREQ(record->event->character,
nullptr);
1622 EXPECT_EQ(record->event->synthesized,
true);
1624 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1625 EXPECT_EQ(record->event->timestamp, 101000);
1626 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1627 EXPECT_EQ(record->event->physical, kPhysicalControlLeft);
1628 EXPECT_EQ(record->event->logical, kLogicalControlLeft);
1629 EXPECT_STREQ(record->event->character,
nullptr);
1630 EXPECT_EQ(record->event->synthesized,
true);
1635 g_object_unref(responder);
1648 TEST(FlKeyEmbedderResponderTest, HandlesShiftAltVersusGroupNext) {
1649 EXPECT_EQ(g_call_records,
nullptr);
1650 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1651 FlKeyResponder* responder = FL_KEY_RESPONDER(
1655 guint32 now_time = 1;
1657 auto send_key_event = [responder, &now_time](
bool is_press, guint keyval,
1659 GdkModifierType
state) {
1669 FlKeyEmbedderCallRecord* record;
1672 GDK_MODIFIER_RESERVED_25_MASK);
1673 EXPECT_EQ(g_call_records->len, 1u);
1674 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1675 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1676 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
1677 EXPECT_EQ(record->event->logical, kLogicalShiftLeft);
1678 EXPECT_EQ(record->event->synthesized,
false);
1681 static_cast<GdkModifierType
>(GDK_SHIFT_MASK |
1682 GDK_MODIFIER_RESERVED_25_MASK));
1683 EXPECT_EQ(g_call_records->len, 2u);
1684 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1685 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1686 EXPECT_EQ(record->event->physical, kPhysicalAltRight);
1687 EXPECT_EQ(record->event->logical, kLogicalMetaRight);
1688 EXPECT_EQ(record->event->synthesized,
false);
1690 send_key_event(kRelease, GDK_KEY_ISO_Next_Group, kKeyCodeShiftLeft,
1691 static_cast<GdkModifierType
>(GDK_SHIFT_MASK | GDK_MOD1_MASK |
1692 GDK_MODIFIER_RESERVED_25_MASK));
1693 EXPECT_EQ(g_call_records->len, 5u);
1694 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 2));
1695 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1696 EXPECT_EQ(record->event->physical, kPhysicalAltLeft);
1697 EXPECT_EQ(record->event->logical, kLogicalAltLeft);
1698 EXPECT_EQ(record->event->synthesized,
true);
1700 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 3));
1701 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1702 EXPECT_EQ(record->event->physical, kPhysicalAltRight);
1703 EXPECT_EQ(record->event->logical, kLogicalMetaRight);
1704 EXPECT_EQ(record->event->synthesized,
true);
1706 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 4));
1707 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1708 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
1709 EXPECT_EQ(record->event->logical, kLogicalShiftLeft);
1710 EXPECT_EQ(record->event->synthesized,
false);
1712 send_key_event(kPress, GDK_KEY_ISO_Next_Group, kKeyCodeShiftLeft,
1713 static_cast<GdkModifierType
>(GDK_MOD1_MASK |
1714 GDK_MODIFIER_RESERVED_25_MASK));
1715 EXPECT_EQ(g_call_records->len, 6u);
1716 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 5));
1717 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1718 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
1719 EXPECT_EQ(record->event->logical, kLogicalGroupNext);
1720 EXPECT_EQ(record->event->synthesized,
false);
1722 send_key_event(kRelease, GDK_KEY_ISO_Level3_Shift, kKeyCodeAltRight,
1723 static_cast<GdkModifierType
>(GDK_MOD1_MASK |
1724 GDK_MODIFIER_RESERVED_13_MASK |
1725 GDK_MODIFIER_RESERVED_25_MASK));
1726 EXPECT_EQ(g_call_records->len, 7u);
1727 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 6));
1728 EXPECT_EQ(record->event->physical, 0u);
1729 EXPECT_EQ(record->event->logical, 0u);
1732 static_cast<GdkModifierType
>(GDK_MODIFIER_RESERVED_13_MASK |
1733 GDK_MODIFIER_RESERVED_25_MASK));
1734 EXPECT_EQ(g_call_records->len, 9u);
1735 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 7));
1736 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1737 EXPECT_EQ(record->event->physical, kPhysicalAltLeft);
1738 EXPECT_EQ(record->event->logical, kLogicalAltLeft);
1739 EXPECT_EQ(record->event->synthesized,
true);
1741 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 8));
1742 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeUp);
1743 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
1744 EXPECT_EQ(record->event->logical, kLogicalGroupNext);
1745 EXPECT_EQ(record->event->synthesized,
false);
1748 g_object_unref(responder);
1757 TEST(FlKeyEmbedderResponderTest, HandlesShiftAltLeftIsMetaLeft) {
1758 EXPECT_EQ(g_call_records,
nullptr);
1759 g_call_records = g_ptr_array_new_with_free_func(g_object_unref);
1760 FlKeyResponder* responder = FL_KEY_RESPONDER(
1764 guint32 now_time = 1;
1766 auto send_key_event = [responder, &now_time](
bool is_press, guint keyval,
1768 GdkModifierType
state) {
1778 FlKeyEmbedderCallRecord* record;
1782 GDK_MODIFIER_RESERVED_25_MASK);
1783 EXPECT_EQ(g_call_records->len, 1u);
1784 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1785 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1786 EXPECT_EQ(record->event->physical, kPhysicalShiftLeft);
1787 EXPECT_EQ(record->event->logical, kLogicalShiftLeft);
1788 EXPECT_EQ(record->event->synthesized,
false);
1791 static_cast<GdkModifierType
>(GDK_SHIFT_MASK |
1792 GDK_MODIFIER_RESERVED_25_MASK));
1793 EXPECT_EQ(g_call_records->len, 2u);
1794 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1795 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1796 EXPECT_EQ(record->event->physical, kPhysicalMetaLeft);
1797 EXPECT_EQ(record->event->logical, kLogicalMetaLeft);
1798 EXPECT_EQ(record->event->synthesized,
false);
1801 static_cast<GdkModifierType
>(GDK_MODIFIER_RESERVED_13_MASK |
1802 GDK_MODIFIER_RESERVED_25_MASK));
1804 GDK_MODIFIER_RESERVED_25_MASK);
1809 GDK_MODIFIER_RESERVED_25_MASK);
1810 EXPECT_EQ(g_call_records->len, 1u);
1811 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 0));
1812 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1813 EXPECT_EQ(record->event->physical, kPhysicalShiftRight);
1814 EXPECT_EQ(record->event->logical, kLogicalShiftRight);
1815 EXPECT_EQ(record->event->synthesized,
false);
1818 static_cast<GdkModifierType
>(GDK_SHIFT_MASK |
1819 GDK_MODIFIER_RESERVED_25_MASK));
1820 EXPECT_EQ(g_call_records->len, 2u);
1821 record = FL_KEY_EMBEDDER_CALL_RECORD(g_ptr_array_index(g_call_records, 1));
1822 EXPECT_EQ(record->event->type, kFlutterKeyEventTypeDown);
1823 EXPECT_EQ(record->event->physical, kPhysicalMetaLeft);
1824 EXPECT_EQ(record->event->logical, kLogicalMetaLeft);
1825 EXPECT_EQ(record->event->synthesized,
false);
1828 g_object_unref(responder);