1515#include " flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h"
1616#include " flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
1717#include " flutter/shell/platform/linux/testing/fl_test.h"
18+ #include " flutter/shell/platform/linux/testing/mock_keymap.h"
1819#include " flutter/shell/platform/linux/testing/mock_text_input_handler.h"
1920#include " flutter/testing/testing.h"
2021
@@ -282,7 +283,6 @@ struct _FlMockViewDelegate {
282283 FlMockKeyBinaryMessenger* messenger;
283284 EmbedderCallHandler embedder_handler;
284285 bool text_filter_result;
285- const MockLayoutData* layout_data;
286286};
287287
288288static void fl_mock_view_keyboard_delegate_iface_init (
@@ -329,24 +329,10 @@ static gboolean fl_mock_view_keyboard_text_filter_key_press(
329329 return self->text_filter_result ;
330330}
331331
332- static guint fl_mock_view_keyboard_lookup_key (
333- FlKeyboardViewDelegate* view_delegate,
334- const GdkKeymapKey* key) {
335- FlMockViewDelegate* self = FL_MOCK_VIEW_DELEGATE (view_delegate);
336- guint8 group = static_cast <guint8>(key->group );
337- EXPECT_LT (group, self->layout_data ->size ());
338- const MockGroupLayoutData* group_layout = (*self->layout_data )[group];
339- EXPECT_TRUE (group_layout != nullptr );
340- EXPECT_TRUE (key->level == 0 || key->level == 1 );
341- bool shift = key->level == 1 ;
342- return (*group_layout)[key->keycode * 2 + shift];
343- }
344-
345332static void fl_mock_view_keyboard_delegate_iface_init (
346333 FlKeyboardViewDelegateInterface* iface) {
347334 iface->send_key_event = fl_mock_view_keyboard_send_key_event;
348335 iface->text_filter_key_press = fl_mock_view_keyboard_text_filter_key_press;
349- iface->lookup_key = fl_mock_view_keyboard_lookup_key;
350336}
351337
352338static FlMockViewDelegate* fl_mock_view_delegate_new () {
@@ -371,11 +357,6 @@ static void fl_mock_view_set_text_filter_result(FlMockViewDelegate* self,
371357 self->text_filter_result = result;
372358}
373359
374- static void fl_mock_view_set_layout (FlMockViewDelegate* self,
375- const MockLayoutData* layout) {
376- self->layout_data = layout;
377- }
378-
379360/* **** End FlMockViewDelegate *****/
380361
381362class KeyboardTester {
@@ -389,6 +370,20 @@ class KeyboardTester {
389370
390371 manager_ = fl_keyboard_manager_new (FL_BINARY_MESSENGER (view_->messenger ),
391372 FL_KEYBOARD_VIEW_DELEGATE (view_));
373+ fl_keyboard_manager_set_lookup_key_handler (
374+ manager_,
375+ [](const GdkKeymapKey* key, gpointer user_data) {
376+ KeyboardTester* self = reinterpret_cast <KeyboardTester*>(user_data);
377+ guint8 group = static_cast <guint8>(key->group );
378+ EXPECT_LT (group, self->layout_data_ ->size ());
379+ const MockGroupLayoutData* group_layout =
380+ (*self->layout_data_ )[group];
381+ EXPECT_TRUE (group_layout != nullptr );
382+ EXPECT_TRUE (key->level == 0 || key->level == 1 );
383+ bool shift = key->level == 1 ;
384+ return (*group_layout)[key->keycode * 2 + shift];
385+ },
386+ this );
392387 fl_keyboard_manager_set_redispatch_handler (
393388 manager_,
394389 [](FlKeyEvent* event, gpointer user_data) {
@@ -516,7 +511,7 @@ class KeyboardTester {
516511 }
517512
518513 void setLayout (const MockLayoutData& layout) {
519- fl_mock_view_set_layout (view_, &layout) ;
514+ layout_data_ = &layout;
520515 if (manager_ != nullptr ) {
521516 fl_keyboard_manager_notify_layout_changed (manager_);
522517 }
@@ -527,6 +522,7 @@ class KeyboardTester {
527522 FlKeyboardManager* manager_ = nullptr ;
528523 GPtrArray* redispatched_events_ = nullptr ;
529524 bool during_redispatch_ = false ;
525+ const MockLayoutData* layout_data_;
530526
531527 static gboolean _flushChannelMessagesCb (gpointer data) {
532528 g_autoptr (GMainLoop) loop = reinterpret_cast <GMainLoop*>(data);
@@ -538,6 +534,7 @@ class KeyboardTester {
538534// Make sure that the keyboard can be disposed without crashes when there are
539535// unresolved pending events.
540536TEST (FlKeyboardManagerTest, DisposeWithUnresolvedPends) {
537+ ::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
541538 KeyboardTester tester;
542539 std::vector<CallRecord> call_records;
543540
@@ -558,6 +555,7 @@ TEST(FlKeyboardManagerTest, DisposeWithUnresolvedPends) {
558555}
559556
560557TEST (FlKeyboardManagerTest, SingleDelegateWithAsyncResponds) {
558+ ::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
561559 KeyboardTester tester;
562560 std::vector<CallRecord> call_records;
563561 g_autoptr (GPtrArray) redispatched =
@@ -645,6 +643,7 @@ TEST(FlKeyboardManagerTest, SingleDelegateWithAsyncResponds) {
645643}
646644
647645TEST (FlKeyboardManagerTest, SingleDelegateWithSyncResponds) {
646+ ::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
648647 KeyboardTester tester;
649648 gboolean handler_handled = false ;
650649 std::vector<CallRecord> call_records;
@@ -692,6 +691,7 @@ TEST(FlKeyboardManagerTest, SingleDelegateWithSyncResponds) {
692691}
693692
694693TEST (FlKeyboardManagerTest, WithTwoAsyncDelegates) {
694+ ::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
695695 KeyboardTester tester;
696696 std::vector<CallRecord> call_records;
697697 g_autoptr (GPtrArray) redispatched =
@@ -751,6 +751,7 @@ TEST(FlKeyboardManagerTest, WithTwoAsyncDelegates) {
751751}
752752
753753TEST (FlKeyboardManagerTest, TextInputHandlerReturnsFalse) {
754+ ::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
754755 KeyboardTester tester;
755756 g_autoptr (GPtrArray) redispatched =
756757 g_ptr_array_new_with_free_func (g_object_unref);
@@ -774,6 +775,7 @@ TEST(FlKeyboardManagerTest, TextInputHandlerReturnsFalse) {
774775}
775776
776777TEST (FlKeyboardManagerTest, TextInputHandlerReturnsTrue) {
778+ ::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
777779 KeyboardTester tester;
778780 g_autoptr (GPtrArray) redispatched =
779781 g_ptr_array_new_with_free_func (g_object_unref);
@@ -794,6 +796,7 @@ TEST(FlKeyboardManagerTest, TextInputHandlerReturnsTrue) {
794796}
795797
796798TEST (FlKeyboardManagerTest, CorrectLogicalKeyForLayouts) {
799+ ::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
797800 KeyboardTester tester;
798801
799802 std::vector<CallRecord> call_records;
@@ -887,6 +890,7 @@ TEST(FlKeyboardManagerTest, CorrectLogicalKeyForLayouts) {
887890}
888891
889892TEST (FlKeyboardManagerTest, SynthesizeModifiersIfNeeded) {
893+ ::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
890894 KeyboardTester tester;
891895 std::vector<CallRecord> call_records;
892896 tester.recordEmbedderCallsTo (call_records);
@@ -925,6 +929,7 @@ TEST(FlKeyboardManagerTest, SynthesizeModifiersIfNeeded) {
925929}
926930
927931TEST (FlKeyboardManagerTest, GetPressedState) {
932+ ::testing::NiceMock<flutter::testing::MockKeymap> mock_keymap;
928933 KeyboardTester tester;
929934 tester.respondToTextInputWith (true );
930935
0 commit comments