44
55#include " flutter/shell/platform/linux/fl_key_event_plugin.h"
66
7- #include " gtest/gtest.h"
87#include < iostream>
8+ #include " gtest/gtest.h"
99
1010#include " flutter/shell/platform/linux/fl_binary_messenger_private.h"
1111#include " flutter/shell/platform/linux/fl_engine_private.h"
@@ -51,69 +51,77 @@ TEST(FlKeyEventPluginTest, SendKeyEvent) {
5151
5252 g_autoptr (FlEngine) engine = make_mock_engine ();
5353 FlBinaryMessenger* messenger = fl_binary_messenger_new (engine);
54- g_autoptr (FlKeyEventPlugin) plugin = fl_key_event_plugin_new (messenger, echo_response_cb, " test/echo" );
54+ g_autoptr (FlKeyEventPlugin) plugin =
55+ fl_key_event_plugin_new (messenger, echo_response_cb, " test/echo" );
5556
5657 char string[] = " A" ;
5758 GdkEventKey key_event = GdkEventKey{
58- GDK_KEY_PRESS, // event type
59- nullptr , // window (not needed)
60- FALSE , // event was sent explicitly
61- 12345 , // time
62- 0x0 , // modifier state
63- GDK_KEY_A, // key code
64- 1 , // length of string representation
65- reinterpret_cast <gchar*>(&string[0 ]), // string representation
66- 0x04 , // scan code
67- 0 , // keyboard group
68- 0 , // is a modifier
59+ GDK_KEY_PRESS, // event type
60+ nullptr , // window (not needed)
61+ FALSE , // event was sent explicitly
62+ 12345 , // time
63+ 0x0 , // modifier state
64+ GDK_KEY_A, // key code
65+ 1 , // length of string representation
66+ reinterpret_cast <gchar*>(&string[0 ]), // string representation
67+ 0x04 , // scan code
68+ 0 , // keyboard group
69+ 0 , // is a modifier
6970 };
7071
71- expected_value = " {type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65, modifiers: 0, unicodeScalarValues: 65}" ;
72+ expected_value =
73+ " {type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65, "
74+ " modifiers: 0, unicodeScalarValues: 65}" ;
7275 fl_key_event_plugin_send_key_event (plugin, &key_event, loop);
7376
7477 // Blocks here until echo_response_cb is called.
7578 g_main_loop_run (loop);
7679
7780 key_event = GdkEventKey{
78- GDK_KEY_RELEASE, // event type
79- nullptr , // window (not needed)
80- FALSE , // event was sent explicitly
81- 12345 , // time
82- 0x0 , // modifier state
83- GDK_KEY_A, // key code
84- 1 , // length of string representation
85- reinterpret_cast <gchar*>(&string[0 ]), // string representation
86- 0x04 , // scan code
87- 0 , // keyboard group
88- 0 , // is a modifier
81+ GDK_KEY_RELEASE, // event type
82+ nullptr , // window (not needed)
83+ FALSE , // event was sent explicitly
84+ 12345 , // time
85+ 0x0 , // modifier state
86+ GDK_KEY_A, // key code
87+ 1 , // length of string representation
88+ reinterpret_cast <gchar*>(&string[0 ]), // string representation
89+ 0x04 , // scan code
90+ 0 , // keyboard group
91+ 0 , // is a modifier
8992 };
9093
91- expected_value = " {type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65, modifiers: 0, unicodeScalarValues: 65}" ;
94+ expected_value =
95+ " {type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65, "
96+ " modifiers: 0, unicodeScalarValues: 65}" ;
9297 fl_key_event_plugin_send_key_event (plugin, &key_event, loop);
9398
9499 // Blocks here until echo_response_cb is called.
95100 g_main_loop_run (loop);
96101}
97102
98- void test_lock_event (guint key_code, const char * down_expected, const char * up_expected) {
103+ void test_lock_event (guint key_code,
104+ const char * down_expected,
105+ const char * up_expected) {
99106 g_autoptr (GMainLoop) loop = g_main_loop_new (nullptr , 0 );
100107
101108 g_autoptr (FlEngine) engine = make_mock_engine ();
102109 FlBinaryMessenger* messenger = fl_binary_messenger_new (engine);
103- g_autoptr (FlKeyEventPlugin) plugin = fl_key_event_plugin_new (messenger, echo_response_cb, " test/echo" );
110+ g_autoptr (FlKeyEventPlugin) plugin =
111+ fl_key_event_plugin_new (messenger, echo_response_cb, " test/echo" );
104112
105113 GdkEventKey key_event = GdkEventKey{
106- GDK_KEY_PRESS, // event type
107- nullptr , // window (not needed)
108- FALSE , // event was sent explicitly
109- 12345 , // time
110- 0x10 , // modifier state
111- key_code, // key code
112- 1 , // length of string representation
113- nullptr , // string representation
114- 0x04 , // scan code
115- 0 , // keyboard group
116- 0 , // is a modifier
114+ GDK_KEY_PRESS, // event type
115+ nullptr , // window (not needed)
116+ FALSE , // event was sent explicitly
117+ 12345 , // time
118+ 0x10 , // modifier state
119+ key_code, // key code
120+ 1 , // length of string representation
121+ nullptr , // string representation
122+ 0x04 , // scan code
123+ 0 , // keyboard group
124+ 0 , // is a modifier
117125 };
118126
119127 expected_value = down_expected;
@@ -133,27 +141,27 @@ void test_lock_event(guint key_code, const char* down_expected, const char* up_e
133141
134142// Test sending a "NumLock" keypress.
135143TEST (FlKeyEventPluginTest, SendNumLockKeyEvent) {
136- test_lock_event (
137- GDK_KEY_Num_Lock,
138- " {type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65407, modifiers: 16}" ,
139- " {type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65407, modifiers: 0} "
140- );
144+ test_lock_event (GDK_KEY_Num_Lock,
145+ " {type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
146+ " keyCode: 65407, modifiers: 16}" ,
147+ " {type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, "
148+ " keyCode: 65407, modifiers: 0} " );
141149}
142150
143151// Test sending a "CapsLock" keypress.
144152TEST (FlKeyEventPluginTest, SendCapsLockKeyEvent) {
145- test_lock_event (
146- GDK_KEY_Caps_Lock,
147- " {type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65509, modifiers: 2}" ,
148- " {type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65509, modifiers: 0} "
149- );
153+ test_lock_event (GDK_KEY_Caps_Lock,
154+ " {type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
155+ " keyCode: 65509, modifiers: 2}" ,
156+ " {type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, "
157+ " keyCode: 65509, modifiers: 0} " );
150158}
151159
152160// Test sending a "ShiftLock" keypress.
153161TEST (FlKeyEventPluginTest, SendShiftLockKeyEvent) {
154- test_lock_event (
155- GDK_KEY_Shift_Lock,
156- " {type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65510, modifiers: 2}" ,
157- " {type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, keyCode: 65510, modifiers: 0} "
158- );
162+ test_lock_event (GDK_KEY_Shift_Lock,
163+ " {type: keydown, keymap: linux, scanCode: 4, toolkit: gtk, "
164+ " keyCode: 65510, modifiers: 2}" ,
165+ " {type: keyup, keymap: linux, scanCode: 4, toolkit: gtk, "
166+ " keyCode: 65510, modifiers: 0} " );
159167}
0 commit comments