From 39dc5717d5996d3ede0a732670d022321d01cf8c Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 12 Mar 2025 04:30:09 +1300 Subject: [PATCH] Consolidate GTK mocks (#164890) This was split across three files, consolidate into one. --------- Co-authored-by: Harlen Batagelo --- .../src/flutter/shell/platform/linux/BUILD.gn | 4 +- .../linux/fl_keyboard_handler_test.cc | 4 +- .../linux/fl_keyboard_manager_test.cc | 26 +-- .../linux/fl_text_input_handler_test.cc | 78 +++---- .../shell/platform/linux/fl_view_test.cc | 2 +- .../linux/fl_window_state_monitor_test.cc | 34 +-- .../linux/fl_windowing_handler_test.cc | 88 ++++---- .../shell/platform/linux/testing/mock_gtk.cc | 210 ++++++++++++++++++ .../shell/platform/linux/testing/mock_gtk.h | 85 +++++++ .../platform/linux/testing/mock_im_context.cc | 92 -------- .../platform/linux/testing/mock_im_context.h | 55 ----- .../platform/linux/testing/mock_keymap.cc | 46 ---- .../platform/linux/testing/mock_keymap.h | 29 --- .../platform/linux/testing/mock_window.cc | 111 --------- .../platform/linux/testing/mock_window.h | 51 ----- 15 files changed, 412 insertions(+), 503 deletions(-) create mode 100644 engine/src/flutter/shell/platform/linux/testing/mock_gtk.cc create mode 100644 engine/src/flutter/shell/platform/linux/testing/mock_gtk.h delete mode 100644 engine/src/flutter/shell/platform/linux/testing/mock_im_context.cc delete mode 100644 engine/src/flutter/shell/platform/linux/testing/mock_im_context.h delete mode 100644 engine/src/flutter/shell/platform/linux/testing/mock_keymap.cc delete mode 100644 engine/src/flutter/shell/platform/linux/testing/mock_keymap.h delete mode 100644 engine/src/flutter/shell/platform/linux/testing/mock_window.cc delete mode 100644 engine/src/flutter/shell/platform/linux/testing/mock_window.h diff --git a/engine/src/flutter/shell/platform/linux/BUILD.gn b/engine/src/flutter/shell/platform/linux/BUILD.gn index 4394c37013..4607d30b95 100644 --- a/engine/src/flutter/shell/platform/linux/BUILD.gn +++ b/engine/src/flutter/shell/platform/linux/BUILD.gn @@ -258,14 +258,12 @@ executable("flutter_linux_unittests") { "testing/fl_test_gtk_logs.h", "testing/mock_engine.cc", "testing/mock_epoxy.cc", - "testing/mock_im_context.cc", - "testing/mock_keymap.cc", + "testing/mock_gtk.cc", "testing/mock_plugin_registrar.cc", "testing/mock_renderer.cc", "testing/mock_settings.cc", "testing/mock_signal_handler.cc", "testing/mock_texture_registrar.cc", - "testing/mock_window.cc", ] public_configs = [ "//flutter:config" ] diff --git a/engine/src/flutter/shell/platform/linux/fl_keyboard_handler_test.cc b/engine/src/flutter/shell/platform/linux/fl_keyboard_handler_test.cc index 756a1e348f..d4b6811f7f 100644 --- a/engine/src/flutter/shell/platform/linux/fl_keyboard_handler_test.cc +++ b/engine/src/flutter/shell/platform/linux/fl_keyboard_handler_test.cc @@ -10,7 +10,7 @@ #include "flutter/shell/platform/linux/fl_method_codec_private.h" #include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h" #include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h" -#include "flutter/shell/platform/linux/testing/mock_keymap.h" +#include "flutter/shell/platform/linux/testing/mock_gtk.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -24,7 +24,7 @@ using ::flutter::testing::keycodes::kPhysicalKeyA; constexpr guint16 kKeyCodeKeyA = 0x26u; TEST(FlKeyboardHandlerTest, KeyboardChannelGetPressedState) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = diff --git a/engine/src/flutter/shell/platform/linux/fl_keyboard_manager_test.cc b/engine/src/flutter/shell/platform/linux/fl_keyboard_manager_test.cc index ed2f9cbd2d..dedf8d428a 100644 --- a/engine/src/flutter/shell/platform/linux/fl_keyboard_manager_test.cc +++ b/engine/src/flutter/shell/platform/linux/fl_keyboard_manager_test.cc @@ -12,7 +12,7 @@ #include "flutter/shell/platform/linux/fl_engine_private.h" #include "flutter/shell/platform/linux/key_mapping.h" #include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h" -#include "flutter/shell/platform/linux/testing/mock_keymap.h" +#include "flutter/shell/platform/linux/testing/mock_gtk.h" #include "gtest/gtest.h" @@ -109,7 +109,7 @@ extern const MockLayoutData kLayoutRussian; extern const MockLayoutData kLayoutFrench; TEST(FlKeyboardManagerTest, EngineNoResponseChannelHandled) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); // Channel handles all events. @@ -174,7 +174,7 @@ TEST(FlKeyboardManagerTest, EngineNoResponseChannelHandled) { } TEST(FlKeyboardManagerTest, EngineHandledChannelNotHandledSync) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); @@ -219,7 +219,7 @@ TEST(FlKeyboardManagerTest, EngineHandledChannelNotHandledSync) { } TEST(FlKeyboardManagerTest, EngineNotHandledChannelHandledSync) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); @@ -264,7 +264,7 @@ TEST(FlKeyboardManagerTest, EngineNotHandledChannelHandledSync) { } TEST(FlKeyboardManagerTest, EngineHandledChannelHandledSync) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); @@ -309,7 +309,7 @@ TEST(FlKeyboardManagerTest, EngineHandledChannelHandledSync) { } TEST(FlKeyboardManagerTest, EngineNotHandledChannelNotHandledSync) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); @@ -362,7 +362,7 @@ static void channel_respond(FlMockBinaryMessenger* messenger, } TEST(FlKeyboardManagerTest, EngineHandledChannelNotHandledAsync) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); @@ -423,7 +423,7 @@ TEST(FlKeyboardManagerTest, EngineHandledChannelNotHandledAsync) { } TEST(FlKeyboardManagerTest, EngineNotHandledChannelHandledAsync) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); @@ -484,7 +484,7 @@ TEST(FlKeyboardManagerTest, EngineNotHandledChannelHandledAsync) { } TEST(FlKeyboardManagerTest, EngineHandledChannelHandledAsync) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); @@ -545,7 +545,7 @@ TEST(FlKeyboardManagerTest, EngineHandledChannelHandledAsync) { } TEST(FlKeyboardManagerTest, EngineNotHandledChannelNotHandledAsync) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); @@ -606,7 +606,7 @@ TEST(FlKeyboardManagerTest, EngineNotHandledChannelNotHandledAsync) { } TEST(FlKeyboardManagerTest, CorrectLogicalKeyForLayouts) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlDartProject) project = fl_dart_project_new(); g_autoptr(FlEngine) engine = fl_engine_new(project); @@ -739,7 +739,7 @@ TEST(FlKeyboardManagerTest, CorrectLogicalKeyForLayouts) { } TEST(FlKeyboardManagerTest, SynthesizeModifiersIfNeeded) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlDartProject) project = fl_dart_project_new(); g_autoptr(FlEngine) engine = fl_engine_new(project); @@ -801,7 +801,7 @@ TEST(FlKeyboardManagerTest, SynthesizeModifiersIfNeeded) { } TEST(FlKeyboardManagerTest, GetPressedState) { - ::testing::NiceMock mock_keymap; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = diff --git a/engine/src/flutter/shell/platform/linux/fl_text_input_handler_test.cc b/engine/src/flutter/shell/platform/linux/fl_text_input_handler_test.cc index b86509013d..31505a1943 100644 --- a/engine/src/flutter/shell/platform/linux/fl_text_input_handler_test.cc +++ b/engine/src/flutter/shell/platform/linux/fl_text_input_handler_test.cc @@ -9,7 +9,7 @@ #include "flutter/shell/platform/linux/fl_text_input_handler.h" #include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h" #include "flutter/shell/platform/linux/testing/fl_test.h" -#include "flutter/shell/platform/linux/testing/mock_im_context.h" +#include "flutter/shell/platform/linux/testing/mock_gtk.h" #include "flutter/testing/testing.h" #include "gmock/gmock.h" @@ -152,7 +152,7 @@ static void send_key_event(FlTextInputHandler* handler, TEST(FlTextInputHandlerTest, MessageHandler) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); @@ -166,7 +166,7 @@ TEST(FlTextInputHandlerTest, MessageHandler) { TEST(FlTextInputHandlerTest, SetClient) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); @@ -179,13 +179,13 @@ TEST(FlTextInputHandlerTest, SetClient) { TEST(FlTextInputHandlerTest, Show) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); EXPECT_NE(handler, nullptr); - EXPECT_CALL(context, gtk_im_context_focus_in); + EXPECT_CALL(mock_gtk, gtk_im_context_focus_in); gboolean called = FALSE; fl_mock_binary_messenger_invoke_json_method( @@ -210,13 +210,13 @@ TEST(FlTextInputHandlerTest, Show) { TEST(FlTextInputHandlerTest, Hide) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); EXPECT_NE(handler, nullptr); - EXPECT_CALL(context, gtk_im_context_focus_out); + EXPECT_CALL(mock_gtk, gtk_im_context_focus_out); gboolean called = FALSE; fl_mock_binary_messenger_invoke_json_method( @@ -241,7 +241,7 @@ TEST(FlTextInputHandlerTest, Hide) { TEST(FlTextInputHandlerTest, ClearClient) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); @@ -270,7 +270,7 @@ TEST(FlTextInputHandlerTest, ClearClient) { TEST(FlTextInputHandlerTest, PerformAction) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); @@ -330,7 +330,7 @@ TEST(FlTextInputHandlerTest, PerformAction) { // Regression test for https://github.com/flutter/flutter/issues/125879. TEST(FlTextInputHandlerTest, MultilineWithSendAction) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); @@ -388,7 +388,7 @@ TEST(FlTextInputHandlerTest, MultilineWithSendAction) { TEST(FlTextInputHandlerTest, MoveCursor) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); @@ -453,7 +453,7 @@ TEST(FlTextInputHandlerTest, MoveCursor) { TEST(FlTextInputHandlerTest, Select) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); @@ -518,16 +518,16 @@ TEST(FlTextInputHandlerTest, Select) { TEST(FlTextInputHandlerTest, Composing) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); EXPECT_NE(handler, nullptr); // update - EXPECT_CALL(context, gtk_im_context_get_preedit_string( - ::testing::_, ::testing::A(), ::testing::_, - ::testing::A())) + EXPECT_CALL(mock_gtk, gtk_im_context_get_preedit_string( + ::testing::_, ::testing::A(), ::testing::_, + ::testing::A())) .WillOnce( ::testing::DoAll(::testing::SetArgPointee<1>(g_strdup("Flutter")), ::testing::SetArgPointee<3>(0))); @@ -602,7 +602,7 @@ TEST(FlTextInputHandlerTest, Composing) { TEST(FlTextInputHandlerTest, SurroundingText) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); @@ -616,8 +616,8 @@ TEST(FlTextInputHandlerTest, SurroundingText) { }); // retrieve - EXPECT_CALL(context, gtk_im_context_set_surrounding( - ::testing::_, ::testing::StrEq("Flutter"), -1, 3)); + EXPECT_CALL(mock_gtk, gtk_im_context_set_surrounding( + ::testing::_, ::testing::StrEq("Flutter"), -1, 3)); gboolean retrieved = false; g_signal_emit_by_name(fl_text_input_handler_get_im_context(handler), @@ -667,7 +667,7 @@ TEST(FlTextInputHandlerTest, SurroundingText) { TEST(FlTextInputHandlerTest, SetMarkedTextRect) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); @@ -719,20 +719,20 @@ TEST(FlTextInputHandlerTest, SetMarkedTextRect) { &called); EXPECT_TRUE(called); - EXPECT_CALL(context, gtk_widget_translate_coordinates( - ::testing::_, ::testing::_, ::testing::Eq(27), - ::testing::Eq(32), ::testing::_, ::testing::_)) + EXPECT_CALL(mock_gtk, gtk_widget_translate_coordinates( + ::testing::_, ::testing::_, ::testing::Eq(27), + ::testing::Eq(32), ::testing::_, ::testing::_)) .WillOnce(::testing::DoAll(::testing::SetArgPointee<4>(123), ::testing::SetArgPointee<5>(456), ::testing::Return(true))); - EXPECT_CALL(context, gtk_im_context_set_cursor_location( - ::testing::_, - ::testing::Pointee(::testing::AllOf( - ::testing::Field(&GdkRectangle::x, 123), - ::testing::Field(&GdkRectangle::y, 456), - ::testing::Field(&GdkRectangle::width, 0), - ::testing::Field(&GdkRectangle::height, 0))))); + EXPECT_CALL(mock_gtk, gtk_im_context_set_cursor_location( + ::testing::_, + ::testing::Pointee(::testing::AllOf( + ::testing::Field(&GdkRectangle::x, 123), + ::testing::Field(&GdkRectangle::y, 456), + ::testing::Field(&GdkRectangle::width, 0), + ::testing::Field(&GdkRectangle::height, 0))))); // set marked text rect g_autoptr(FlValue) rect = build_map({ @@ -764,7 +764,7 @@ TEST(FlTextInputHandlerTest, SetMarkedTextRect) { TEST(FlTextInputHandlerTest, TextInputTypeNone) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); @@ -775,8 +775,8 @@ TEST(FlTextInputHandlerTest, TextInputTypeNone) { .input_type = "TextInputType.none", }); - EXPECT_CALL(context, gtk_im_context_focus_in).Times(0); - EXPECT_CALL(context, gtk_im_context_focus_out); + EXPECT_CALL(mock_gtk, gtk_im_context_focus_in).Times(0); + EXPECT_CALL(mock_gtk, gtk_im_context_focus_out); gboolean called = FALSE; fl_mock_binary_messenger_invoke_json_method( @@ -801,7 +801,7 @@ TEST(FlTextInputHandlerTest, TextInputTypeNone) { TEST(FlTextInputHandlerTest, TextEditingDelta) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); @@ -865,7 +865,7 @@ TEST(FlTextInputHandlerTest, TextEditingDelta) { TEST(FlTextInputHandlerTest, ComposingDelta) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); @@ -881,9 +881,9 @@ TEST(FlTextInputHandlerTest, ComposingDelta) { "preedit-start", nullptr); // update - EXPECT_CALL(context, gtk_im_context_get_preedit_string( - ::testing::_, ::testing::A(), ::testing::_, - ::testing::A())) + EXPECT_CALL(mock_gtk, gtk_im_context_get_preedit_string( + ::testing::_, ::testing::A(), ::testing::_, + ::testing::A())) .WillOnce( ::testing::DoAll(::testing::SetArgPointee<1>(g_strdup("Flutter ")), ::testing::SetArgPointee<3>(8))); @@ -979,7 +979,7 @@ TEST(FlTextInputHandlerTest, ComposingDelta) { TEST(FlTextInputHandlerTest, NonComposingDelta) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock context; + ::testing::NiceMock mock_gtk; g_autoptr(FlTextInputHandler) handler = fl_text_input_handler_new(FL_BINARY_MESSENGER(messenger)); diff --git a/engine/src/flutter/shell/platform/linux/fl_view_test.cc b/engine/src/flutter/shell/platform/linux/fl_view_test.cc index fcb0aec526..24e2d5c617 100644 --- a/engine/src/flutter/shell/platform/linux/fl_view_test.cc +++ b/engine/src/flutter/shell/platform/linux/fl_view_test.cc @@ -7,7 +7,7 @@ #include "flutter/shell/platform/linux/fl_engine_private.h" #include "flutter/shell/platform/linux/testing/fl_test.h" #include "flutter/shell/platform/linux/testing/fl_test_gtk_logs.h" -#include "flutter/shell/platform/linux/testing/mock_window.h" +#include "flutter/shell/platform/linux/testing/mock_gtk.h" #include "gtest/gtest.h" diff --git a/engine/src/flutter/shell/platform/linux/fl_window_state_monitor_test.cc b/engine/src/flutter/shell/platform/linux/fl_window_state_monitor_test.cc index c92b822e67..0db4e4f8e1 100644 --- a/engine/src/flutter/shell/platform/linux/fl_window_state_monitor_test.cc +++ b/engine/src/flutter/shell/platform/linux/fl_window_state_monitor_test.cc @@ -6,17 +6,17 @@ #include "flutter/shell/platform/linux/fl_binary_messenger_private.h" #include "flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h" #include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h" -#include "flutter/shell/platform/linux/testing/mock_window.h" +#include "flutter/shell/platform/linux/testing/mock_gtk.h" #include "gtest/gtest.h" TEST(FlWindowStateMonitorTest, GainFocus) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; gtk_init(0, nullptr); - EXPECT_CALL(mock_window, gdk_window_get_state) + EXPECT_CALL(mock_gtk, gdk_window_get_state) .WillOnce(::testing::Return(static_cast(0))); gboolean called = TRUE; @@ -47,11 +47,11 @@ TEST(FlWindowStateMonitorTest, GainFocus) { TEST(FlWindowStateMonitorTest, LoseFocus) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; gtk_init(0, nullptr); - EXPECT_CALL(mock_window, gdk_window_get_state) + EXPECT_CALL(mock_gtk, gdk_window_get_state) .WillOnce(::testing::Return(GDK_WINDOW_STATE_FOCUSED)); gboolean called = TRUE; fl_mock_binary_messenger_set_string_message_channel( @@ -82,11 +82,11 @@ TEST(FlWindowStateMonitorTest, LoseFocus) { TEST(FlWindowStateMonitorTest, EnterIconified) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; gtk_init(0, nullptr); - EXPECT_CALL(mock_window, gdk_window_get_state) + EXPECT_CALL(mock_gtk, gdk_window_get_state) .WillOnce(::testing::Return(static_cast(0))); gboolean called = TRUE; fl_mock_binary_messenger_set_string_message_channel( @@ -116,11 +116,11 @@ TEST(FlWindowStateMonitorTest, EnterIconified) { TEST(FlWindowStateMonitorTest, LeaveIconified) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; gtk_init(0, nullptr); - EXPECT_CALL(mock_window, gdk_window_get_state) + EXPECT_CALL(mock_gtk, gdk_window_get_state) .WillOnce(::testing::Return(GDK_WINDOW_STATE_ICONIFIED)); gboolean called = TRUE; fl_mock_binary_messenger_set_string_message_channel( @@ -151,11 +151,11 @@ TEST(FlWindowStateMonitorTest, LeaveIconified) { TEST(FlWindowStateMonitorTest, LeaveIconifiedFocused) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; gtk_init(0, nullptr); - EXPECT_CALL(mock_window, gdk_window_get_state) + EXPECT_CALL(mock_gtk, gdk_window_get_state) .WillOnce(::testing::Return(GDK_WINDOW_STATE_ICONIFIED)); gboolean called = TRUE; fl_mock_binary_messenger_set_string_message_channel( @@ -186,11 +186,11 @@ TEST(FlWindowStateMonitorTest, LeaveIconifiedFocused) { TEST(FlWindowStateMonitorTest, EnterWithdrawn) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; gtk_init(0, nullptr); - EXPECT_CALL(mock_window, gdk_window_get_state) + EXPECT_CALL(mock_gtk, gdk_window_get_state) .WillOnce(::testing::Return(static_cast(0))); gboolean called = TRUE; fl_mock_binary_messenger_set_string_message_channel( @@ -220,11 +220,11 @@ TEST(FlWindowStateMonitorTest, EnterWithdrawn) { TEST(FlWindowStateMonitorTest, LeaveWithdrawn) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; gtk_init(0, nullptr); - EXPECT_CALL(mock_window, gdk_window_get_state) + EXPECT_CALL(mock_gtk, gdk_window_get_state) .WillOnce(::testing::Return(GDK_WINDOW_STATE_WITHDRAWN)); gboolean called = TRUE; fl_mock_binary_messenger_set_string_message_channel( @@ -255,11 +255,11 @@ TEST(FlWindowStateMonitorTest, LeaveWithdrawn) { TEST(FlWindowStateMonitorTest, LeaveWithdrawnFocused) { g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; gtk_init(0, nullptr); - EXPECT_CALL(mock_window, gdk_window_get_state) + EXPECT_CALL(mock_gtk, gdk_window_get_state) .WillOnce(::testing::Return(GDK_WINDOW_STATE_WITHDRAWN)); gboolean called = TRUE; fl_mock_binary_messenger_set_string_message_channel( diff --git a/engine/src/flutter/shell/platform/linux/fl_windowing_handler_test.cc b/engine/src/flutter/shell/platform/linux/fl_windowing_handler_test.cc index 5660cc2452..5ac36d783e 100644 --- a/engine/src/flutter/shell/platform/linux/fl_windowing_handler_test.cc +++ b/engine/src/flutter/shell/platform/linux/fl_windowing_handler_test.cc @@ -7,7 +7,7 @@ #include "flutter/shell/platform/linux/fl_engine_private.h" #include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h" #include "flutter/shell/platform/linux/testing/fl_test_gtk_logs.h" -#include "flutter/shell/platform/linux/testing/mock_window.h" +#include "flutter/shell/platform/linux/testing/mock_gtk.h" #include "flutter/testing/testing.h" #include "gmock/gmock.h" @@ -72,15 +72,15 @@ static FlValue* make_destroy_window_args(int64_t view_id) { TEST(FlWindowingHandlerTest, CreateRegular) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); - EXPECT_CALL(mock_window, gtk_window_set_default_size(::testing::_, 800, 600)); + EXPECT_CALL(mock_gtk, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_window_set_default_size(::testing::_, 800, 600)); g_autoptr(FlValue) args = make_create_regular_args(800, 600); @@ -101,15 +101,15 @@ TEST(FlWindowingHandlerTest, CreateRegular) { TEST(FlWindowingHandlerTest, CreateRegularMinSize) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); - EXPECT_CALL(mock_window, + EXPECT_CALL(mock_gtk, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_window_set_geometry_hints( ::testing::_, nullptr, ::testing::Pointee(::testing::AllOf( @@ -137,15 +137,15 @@ TEST(FlWindowingHandlerTest, CreateRegularMinSize) { TEST(FlWindowingHandlerTest, CreateRegularMaxSize) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); - EXPECT_CALL(mock_window, + EXPECT_CALL(mock_gtk, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_window_set_geometry_hints( ::testing::_, nullptr, ::testing::Pointee(::testing::AllOf( @@ -173,15 +173,15 @@ TEST(FlWindowingHandlerTest, CreateRegularMaxSize) { TEST(FlWindowingHandlerTest, CreateRegularWithTitle) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); - EXPECT_CALL(mock_window, + EXPECT_CALL(mock_gtk, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_window_set_title(::testing::_, ::testing::StrEq("TITLE"))); g_autoptr(FlValue) args = make_create_regular_args(800, 600); @@ -204,15 +204,15 @@ TEST(FlWindowingHandlerTest, CreateRegularWithTitle) { TEST(FlWindowingHandlerTest, CreateRegularMaximized) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); - EXPECT_CALL(mock_window, gtk_window_maximize(::testing::_)); + EXPECT_CALL(mock_gtk, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_window_maximize(::testing::_)); g_autoptr(FlValue) args = make_create_regular_args(800, 600); fl_value_set_string_take(args, "state", @@ -235,15 +235,15 @@ TEST(FlWindowingHandlerTest, CreateRegularMaximized) { TEST(FlWindowingHandlerTest, CreateRegularMinimized) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); - EXPECT_CALL(mock_window, gtk_window_iconify(::testing::_)); + EXPECT_CALL(mock_gtk, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_window_iconify(::testing::_)); g_autoptr(FlValue) args = make_create_regular_args(800, 600); fl_value_set_string_take(args, "state", @@ -266,15 +266,15 @@ TEST(FlWindowingHandlerTest, CreateRegularMinimized) { TEST(FlWindowingHandlerTest, ModifyRegularSize) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); - EXPECT_CALL(mock_window, gtk_window_resize(::testing::_, 1024, 768)); + EXPECT_CALL(mock_gtk, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_window_resize(::testing::_, 1024, 768)); g_autoptr(FlValue) create_args = make_create_regular_args(800, 600); @@ -309,15 +309,15 @@ TEST(FlWindowingHandlerTest, ModifyRegularSize) { TEST(FlWindowingHandlerTest, ModifyRegularTitle) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); - EXPECT_CALL(mock_window, + EXPECT_CALL(mock_gtk, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_window_set_title(::testing::_, ::testing::StrEq("TITLE"))); g_autoptr(FlValue) create_args = make_create_regular_args(800, 600); @@ -353,14 +353,14 @@ TEST(FlWindowingHandlerTest, ModifyRegularTitle) { TEST(FlWindowingHandlerTest, ModifyRegularMaximize) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_window_new); g_autoptr(FlValue) create_args = make_create_regular_args(800, 600); @@ -375,7 +375,7 @@ TEST(FlWindowingHandlerTest, ModifyRegularMaximize) { &view_id); EXPECT_GT(view_id, 0); - EXPECT_CALL(mock_window, gtk_window_maximize(::testing::_)); + EXPECT_CALL(mock_gtk, gtk_window_maximize(::testing::_)); g_autoptr(FlValue) modify_args = make_modify_regular_args(view_id); fl_value_set_string_take(modify_args, "state", @@ -398,15 +398,15 @@ TEST(FlWindowingHandlerTest, ModifyRegularMaximize) { TEST(FlWindowingHandlerTest, ModifyRegularUnmaximize) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); - EXPECT_CALL(mock_window, gtk_window_maximize(::testing::_)); + EXPECT_CALL(mock_gtk, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_window_maximize(::testing::_)); g_autoptr(FlValue) create_args = make_create_regular_args(800, 600); fl_value_set_string_take(create_args, "state", @@ -423,9 +423,9 @@ TEST(FlWindowingHandlerTest, ModifyRegularUnmaximize) { &view_id); EXPECT_GT(view_id, 0); - EXPECT_CALL(mock_window, gtk_window_is_maximized(::testing::_)) + EXPECT_CALL(mock_gtk, gtk_window_is_maximized(::testing::_)) .WillOnce(::testing::Return(TRUE)); - EXPECT_CALL(mock_window, gtk_window_unmaximize(::testing::_)); + EXPECT_CALL(mock_gtk, gtk_window_unmaximize(::testing::_)); g_autoptr(FlValue) modify_args = make_modify_regular_args(view_id); fl_value_set_string_take(modify_args, "state", @@ -448,14 +448,14 @@ TEST(FlWindowingHandlerTest, ModifyRegularUnmaximize) { TEST(FlWindowingHandlerTest, ModifyRegularMinimize) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_window_new); g_autoptr(FlValue) create_args = make_create_regular_args(800, 600); @@ -470,7 +470,7 @@ TEST(FlWindowingHandlerTest, ModifyRegularMinimize) { &view_id); EXPECT_GT(view_id, 0); - EXPECT_CALL(mock_window, gtk_window_iconify(::testing::_)); + EXPECT_CALL(mock_gtk, gtk_window_iconify(::testing::_)); g_autoptr(FlValue) modify_args = make_modify_regular_args(view_id); fl_value_set_string_take(modify_args, "state", @@ -493,15 +493,15 @@ TEST(FlWindowingHandlerTest, ModifyRegularMinimize) { TEST(FlWindowingHandlerTest, ModifyRegularUnminimize) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); - EXPECT_CALL(mock_window, gtk_window_iconify(::testing::_)); + EXPECT_CALL(mock_gtk, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_window_iconify(::testing::_)); g_autoptr(FlValue) create_args = make_create_regular_args(800, 600); fl_value_set_string_take(create_args, "state", @@ -518,9 +518,9 @@ TEST(FlWindowingHandlerTest, ModifyRegularUnminimize) { &view_id); EXPECT_GT(view_id, 0); - EXPECT_CALL(mock_window, gdk_window_get_state(::testing::_)) + EXPECT_CALL(mock_gtk, gdk_window_get_state(::testing::_)) .WillOnce(::testing::Return(GDK_WINDOW_STATE_ICONIFIED)); - EXPECT_CALL(mock_window, gtk_window_deiconify(::testing::_)); + EXPECT_CALL(mock_gtk, gtk_window_deiconify(::testing::_)); g_autoptr(FlValue) modify_args = make_modify_regular_args(view_id); fl_value_set_string_take(modify_args, "state", @@ -572,15 +572,15 @@ TEST(FlWindowingHandlerTest, ModifyUnknownWindow) { TEST(FlWindowingHandlerTest, DestroyWindow) { flutter::testing::fl_ensure_gtk_init(); - ::testing::NiceMock mock_window; + ::testing::NiceMock mock_gtk; g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new(); g_autoptr(FlEngine) engine = fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger)); g_autoptr(FlWindowingHandler) handler = fl_windowing_handler_new(engine); - EXPECT_CALL(mock_window, gtk_window_new); - EXPECT_CALL(mock_window, gtk_widget_destroy); + EXPECT_CALL(mock_gtk, gtk_window_new); + EXPECT_CALL(mock_gtk, gtk_widget_destroy); g_autoptr(FlValue) create_args = make_create_regular_args(800, 600); diff --git a/engine/src/flutter/shell/platform/linux/testing/mock_gtk.cc b/engine/src/flutter/shell/platform/linux/testing/mock_gtk.cc new file mode 100644 index 0000000000..3b34c99a88 --- /dev/null +++ b/engine/src/flutter/shell/platform/linux/testing/mock_gtk.cc @@ -0,0 +1,210 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include + +#include "flutter/shell/platform/linux/testing/mock_gtk.h" + +using namespace flutter::testing; + +G_DECLARE_FINAL_TYPE(FlMockKeymap, fl_mock_keymap, FL, MOCK_KEYMAP, GObject) + +struct _FlMockKeymap { + GObject parent_instance; +}; + +G_DEFINE_TYPE(FlMockKeymap, fl_mock_keymap, G_TYPE_OBJECT) + +static void fl_mock_keymap_class_init(FlMockKeymapClass* klass) { + g_signal_new("keys-changed", fl_mock_keymap_get_type(), G_SIGNAL_RUN_LAST, 0, + nullptr, nullptr, nullptr, G_TYPE_NONE, 0); +} + +static void fl_mock_keymap_init(FlMockKeymap* self) {} + +static MockGtk* mock = nullptr; + +MockGtk::MockGtk() { + mock = this; +} + +MockGtk::~MockGtk() { + if (mock == this) { + mock = nullptr; + } +} + +GdkKeymap* gdk_keymap_get_for_display(GdkDisplay* display) { + FlMockKeymap* keymap = + FL_MOCK_KEYMAP(g_object_new(fl_mock_keymap_get_type(), nullptr)); + (void)FL_IS_MOCK_KEYMAP(keymap); + return reinterpret_cast(keymap); +} + +guint gdk_keymap_lookup_key(GdkKeymap* keymap, const GdkKeymapKey* key) { + return mock->gdk_keymap_lookup_key(keymap, key); +} + +GdkDisplay* gdk_display_get_default() { + return GDK_DISPLAY(g_object_new(gdk_display_get_type(), nullptr)); +} + +void gdk_display_beep(GdkDisplay* display) {} + +GdkWindowState gdk_window_get_state(GdkWindow* window) { + return mock->gdk_window_get_state(window); +} + +GdkDisplay* gdk_window_get_display(GdkWindow* window) { + return GDK_DISPLAY(g_object_new(gdk_display_get_type(), nullptr)); +} + +int gdk_display_get_n_monitors(GdkDisplay* display) { + return 1; +} + +GdkMonitor* gdk_display_get_monitor(GdkDisplay* display, int n) { + return GDK_MONITOR(g_object_new(gdk_monitor_get_type(), nullptr)); +} + +GdkMonitor* gdk_display_get_monitor_at_window(GdkDisplay* display, + GdkWindow* window) { + return nullptr; +} + +GdkCursor* gdk_cursor_new_from_name(GdkDisplay* display, const gchar* name) { + return nullptr; +} + +void gdk_window_set_cursor(GdkWindow* window, GdkCursor* cursor) {} + +GtkWidget* gtk_window_new(GtkWindowType type) { + GtkWindow* window = GTK_WINDOW(g_object_new(gtk_window_get_type(), nullptr)); + mock->gtk_window_new(window, type); + return GTK_WIDGET(window); +} + +void gtk_window_set_default_size(GtkWindow* window, gint width, gint height) { + mock->gtk_window_set_default_size(window, width, height); +} + +void gtk_window_set_title(GtkWindow* window, const gchar* title) { + mock->gtk_window_set_title(window, title); +} + +void gtk_window_set_geometry_hints(GtkWindow* window, + GtkWidget* widget, + GdkGeometry* geometry, + GdkWindowHints geometry_mask) { + mock->gtk_window_set_geometry_hints(window, widget, geometry, geometry_mask); +} + +void gtk_window_resize(GtkWindow* window, gint width, gint height) { + mock->gtk_window_resize(window, width, height); +} + +void gtk_window_maximize(GtkWindow* window) { + mock->gtk_window_maximize(window); +} + +void gtk_window_unmaximize(GtkWindow* window) { + mock->gtk_window_unmaximize(window); +} + +gboolean gtk_window_is_maximized(GtkWindow* window) { + return mock->gtk_window_is_maximized(window); +} + +void gtk_window_iconify(GtkWindow* window) { + mock->gtk_window_iconify(window); +} + +void gtk_window_deiconify(GtkWindow* window) { + mock->gtk_window_deiconify(window); +} + +void gtk_widget_show(GtkWidget* widget) {} + +void gtk_widget_destroy(GtkWidget* widget) { + mock->gtk_widget_destroy(widget); +} + +void fl_gtk_widget_destroy(GtkWidget* widget) { + void (*destroy)(GtkWidget*) = reinterpret_cast( + dlsym(RTLD_NEXT, "gtk_widget_destroy")); + destroy(widget); +} + +gboolean gtk_widget_translate_coordinates(GtkWidget* src_widget, + GtkWidget* dest_widget, + gint src_x, + gint src_y, + gint* dest_x, + gint* dest_y) { + if (mock == nullptr) { + *dest_x = src_x; + *dest_y = src_y; + return TRUE; + } + + return mock->gtk_widget_translate_coordinates(src_widget, dest_widget, src_x, + src_y, dest_x, dest_y); +} + +GtkWidget* gtk_widget_get_toplevel(GtkWidget* widget) { + return widget; +} + +void gtk_im_context_set_client_window(GtkIMContext* context, + GdkWindow* window) { + if (mock != nullptr) { + mock->gtk_im_context_set_client_window(context, window); + } +} + +void gtk_im_context_get_preedit_string(GtkIMContext* context, + gchar** str, + PangoAttrList** attrs, + gint* cursor_pos) { + if (mock != nullptr) { + mock->gtk_im_context_get_preedit_string(context, str, attrs, cursor_pos); + } +} + +gboolean gtk_im_context_filter_keypress(GtkIMContext* context, + GdkEventKey* event) { + if (mock == nullptr) { + return TRUE; + } + + return mock->gtk_im_context_filter_keypress(context, event); +} + +void gtk_im_context_focus_in(GtkIMContext* context) { + if (mock != nullptr) { + mock->gtk_im_context_focus_in(context); + } +} + +void gtk_im_context_focus_out(GtkIMContext* context) { + if (mock != nullptr) { + mock->gtk_im_context_focus_out(context); + } +} + +void gtk_im_context_set_cursor_location(GtkIMContext* context, + const GdkRectangle* area) { + if (mock != nullptr) { + mock->gtk_im_context_set_cursor_location(context, area); + } +} + +void gtk_im_context_set_surrounding(GtkIMContext* context, + const gchar* text, + gint len, + gint cursor_index) { + if (mock != nullptr) { + mock->gtk_im_context_set_surrounding(context, text, len, cursor_index); + } +} diff --git a/engine/src/flutter/shell/platform/linux/testing/mock_gtk.h b/engine/src/flutter/shell/platform/linux/testing/mock_gtk.h new file mode 100644 index 0000000000..735dc88ac4 --- /dev/null +++ b/engine/src/flutter/shell/platform/linux/testing/mock_gtk.h @@ -0,0 +1,85 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_GTK_H_ +#define FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_GTK_H_ + +#include "gmock/gmock.h" + +#include + +namespace flutter { +namespace testing { + +class MockGtk { + public: + MockGtk(); + ~MockGtk(); + + MOCK_METHOD(GdkKeymap*, gdk_keymap_get_for_display, (GdkDisplay * display)); + MOCK_METHOD(guint, + gdk_keymap_lookup_key, + (GdkKeymap * keymap, const GdkKeymapKey* key)); + MOCK_METHOD(GdkWindowState, gdk_window_get_state, (GdkWindow * window)); + MOCK_METHOD(void, gtk_window_new, (GtkWindow * window, GtkWindowType type)); + MOCK_METHOD(void, + gtk_window_set_default_size, + (GtkWindow * window, gint width, gint height)); + MOCK_METHOD(void, + gtk_window_set_title, + (GtkWindow * window, const gchar* title)); + MOCK_METHOD(void, + gtk_window_set_geometry_hints, + (GtkWindow * window, + GtkWidget* widget, + GdkGeometry* geometry, + GdkWindowHints geometry_mask)); + MOCK_METHOD(void, + gtk_window_resize, + (GtkWindow * window, gint width, gint height)); + MOCK_METHOD(void, gtk_window_maximize, (GtkWindow * window)); + MOCK_METHOD(void, gtk_window_unmaximize, (GtkWindow * window)); + MOCK_METHOD(gboolean, gtk_window_is_maximized, (GtkWindow * window)); + MOCK_METHOD(void, gtk_window_iconify, (GtkWindow * window)); + MOCK_METHOD(void, gtk_window_deiconify, (GtkWindow * window)); + MOCK_METHOD(void, gtk_widget_destroy, (GtkWidget * widget)); + MOCK_METHOD(gboolean, + gtk_widget_translate_coordinates, + (GtkWidget * src_widget, + GtkWidget* dest_widget, + gint src_x, + gint src_y, + gint* dest_x, + gint* dest_y)); + MOCK_METHOD(GtkWidget*, gtk_widget_get_toplevel, (GtkWidget * widget)); + MOCK_METHOD(void, + gtk_im_context_set_client_window, + (GtkIMContext * context, GdkWindow* window)); + MOCK_METHOD(void, + gtk_im_context_get_preedit_string, + (GtkIMContext * context, + gchar** str, + PangoAttrList** attrs, + gint* cursor_pos)); + MOCK_METHOD(gboolean, + gtk_im_context_filter_keypress, + (GtkIMContext * context, GdkEventKey* event)); + MOCK_METHOD(gboolean, gtk_im_context_focus_in, (GtkIMContext * context)); + MOCK_METHOD(void, gtk_im_context_focus_out, (GtkIMContext * context)); + MOCK_METHOD(void, + gtk_im_context_set_cursor_location, + (GtkIMContext * context, const GdkRectangle* area)); + MOCK_METHOD( + void, + gtk_im_context_set_surrounding, + (GtkIMContext * context, const gchar* text, gint len, gint cursor_index)); +}; + +} // namespace testing +} // namespace flutter + +// Calls original gtk_widget_destroy. +void fl_gtk_widget_destroy(GtkWidget* widget); + +#endif // FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_GTK_H_ diff --git a/engine/src/flutter/shell/platform/linux/testing/mock_im_context.cc b/engine/src/flutter/shell/platform/linux/testing/mock_im_context.cc deleted file mode 100644 index 4984452fb1..0000000000 --- a/engine/src/flutter/shell/platform/linux/testing/mock_im_context.cc +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/shell/platform/linux/testing/mock_im_context.h" - -using namespace flutter::testing; - -static MockIMContext* mock = nullptr; - -MockIMContext::MockIMContext() { - mock = this; -} - -MockIMContext::~MockIMContext() { - if (mock == this) { - mock = nullptr; - } -} - -void gtk_im_context_set_client_window(GtkIMContext* context, - GdkWindow* window) { - if (mock != nullptr) { - mock->gtk_im_context_set_client_window(context, window); - } -} - -void gtk_im_context_get_preedit_string(GtkIMContext* context, - gchar** str, - PangoAttrList** attrs, - gint* cursor_pos) { - if (mock != nullptr) { - mock->gtk_im_context_get_preedit_string(context, str, attrs, cursor_pos); - } -} - -gboolean gtk_im_context_filter_keypress(GtkIMContext* context, - GdkEventKey* event) { - if (mock == nullptr) { - return TRUE; - } - - return mock->gtk_im_context_filter_keypress(context, event); -} - -void gtk_im_context_focus_in(GtkIMContext* context) { - if (mock != nullptr) { - mock->gtk_im_context_focus_in(context); - } -} - -void gtk_im_context_focus_out(GtkIMContext* context) { - if (mock != nullptr) { - mock->gtk_im_context_focus_out(context); - } -} - -void gtk_im_context_set_cursor_location(GtkIMContext* context, - const GdkRectangle* area) { - if (mock != nullptr) { - mock->gtk_im_context_set_cursor_location(context, area); - } -} - -void gtk_im_context_set_surrounding(GtkIMContext* context, - const gchar* text, - gint len, - gint cursor_index) { - if (mock != nullptr) { - mock->gtk_im_context_set_surrounding(context, text, len, cursor_index); - } -} - -gboolean gtk_widget_translate_coordinates(GtkWidget* src_widget, - GtkWidget* dest_widget, - gint src_x, - gint src_y, - gint* dest_x, - gint* dest_y) { - if (mock == nullptr) { - *dest_x = src_x; - *dest_y = src_y; - return TRUE; - } - - return mock->gtk_widget_translate_coordinates(src_widget, dest_widget, src_x, - src_y, dest_x, dest_y); -} - -GtkWidget* gtk_widget_get_toplevel(GtkWidget* widget) { - return widget; -} diff --git a/engine/src/flutter/shell/platform/linux/testing/mock_im_context.h b/engine/src/flutter/shell/platform/linux/testing/mock_im_context.h deleted file mode 100644 index 3e1d784950..0000000000 --- a/engine/src/flutter/shell/platform/linux/testing/mock_im_context.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_IM_CONTEXT_H_ -#define FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_IM_CONTEXT_H_ - -#include - -#include "gmock/gmock.h" - -namespace flutter { -namespace testing { - -class MockIMContext { - public: - MockIMContext(); - ~MockIMContext(); - - MOCK_METHOD(void, - gtk_im_context_set_client_window, - (GtkIMContext * context, GdkWindow* window)); - MOCK_METHOD(void, - gtk_im_context_get_preedit_string, - (GtkIMContext * context, - gchar** str, - PangoAttrList** attrs, - gint* cursor_pos)); - MOCK_METHOD(gboolean, - gtk_im_context_filter_keypress, - (GtkIMContext * context, GdkEventKey* event)); - MOCK_METHOD(gboolean, gtk_im_context_focus_in, (GtkIMContext * context)); - MOCK_METHOD(void, gtk_im_context_focus_out, (GtkIMContext * context)); - MOCK_METHOD(void, - gtk_im_context_set_cursor_location, - (GtkIMContext * context, const GdkRectangle* area)); - MOCK_METHOD( - void, - gtk_im_context_set_surrounding, - (GtkIMContext * context, const gchar* text, gint len, gint cursor_index)); - MOCK_METHOD(gboolean, - gtk_widget_translate_coordinates, - (GtkWidget * src_widget, - GtkWidget* dest_widget, - gint src_x, - gint src_y, - gint* dest_x, - gint* dest_y)); - MOCK_METHOD(GtkWidget*, gtk_widget_get_toplevel, (GtkWidget * widget)); -}; - -} // namespace testing -} // namespace flutter - -#endif // FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_IM_CONTEXT_H_ diff --git a/engine/src/flutter/shell/platform/linux/testing/mock_keymap.cc b/engine/src/flutter/shell/platform/linux/testing/mock_keymap.cc deleted file mode 100644 index c510eda802..0000000000 --- a/engine/src/flutter/shell/platform/linux/testing/mock_keymap.cc +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/shell/platform/linux/testing/mock_keymap.h" - -using namespace flutter::testing; - -G_DECLARE_FINAL_TYPE(FlMockKeymap, fl_mock_keymap, FL, MOCK_KEYMAP, GObject) - -struct _FlMockKeymap { - GObject parent_instance; - MockKeymap* mock; -}; - -G_DEFINE_TYPE(FlMockKeymap, fl_mock_keymap, G_TYPE_OBJECT) - -static void fl_mock_keymap_class_init(FlMockKeymapClass* klass) { - g_signal_new("keys-changed", fl_mock_keymap_get_type(), G_SIGNAL_RUN_LAST, 0, - nullptr, nullptr, nullptr, G_TYPE_NONE, 0); -} - -static void fl_mock_keymap_init(FlMockKeymap* self) {} - -static MockKeymap* mock = nullptr; - -MockKeymap::MockKeymap() { - mock = this; -} - -MockKeymap::~MockKeymap() { - if (mock == this) { - mock = nullptr; - } -} - -GdkKeymap* gdk_keymap_get_for_display(GdkDisplay* display) { - FlMockKeymap* keymap = - FL_MOCK_KEYMAP(g_object_new(fl_mock_keymap_get_type(), nullptr)); - (void)FL_IS_MOCK_KEYMAP(keymap); - return reinterpret_cast(keymap); -} - -guint gdk_keymap_lookup_key(GdkKeymap* keymap, const GdkKeymapKey* key) { - return mock->gdk_keymap_lookup_key(keymap, key); -} diff --git a/engine/src/flutter/shell/platform/linux/testing/mock_keymap.h b/engine/src/flutter/shell/platform/linux/testing/mock_keymap.h deleted file mode 100644 index b47304b050..0000000000 --- a/engine/src/flutter/shell/platform/linux/testing/mock_keymap.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_KEYMAP_H_ -#define FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_KEYMAP_H_ - -#include "gmock/gmock.h" - -#include - -namespace flutter { -namespace testing { - -class MockKeymap { - public: - MockKeymap(); - ~MockKeymap(); - - MOCK_METHOD(GdkKeymap*, gdk_keymap_get_for_display, (GdkDisplay * display)); - MOCK_METHOD(guint, - gdk_keymap_lookup_key, - (GdkKeymap * keymap, const GdkKeymapKey* key)); -}; - -} // namespace testing -} // namespace flutter - -#endif // FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_KEYMAP_H_ diff --git a/engine/src/flutter/shell/platform/linux/testing/mock_window.cc b/engine/src/flutter/shell/platform/linux/testing/mock_window.cc deleted file mode 100644 index 69a3de2e49..0000000000 --- a/engine/src/flutter/shell/platform/linux/testing/mock_window.cc +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include - -#include "flutter/shell/platform/linux/testing/mock_window.h" - -using namespace flutter::testing; - -static MockWindow* mock = nullptr; - -MockWindow::MockWindow() { - mock = this; -} - -MockWindow::~MockWindow() { - if (mock == this) { - mock = nullptr; - } -} - -GdkDisplay* gdk_display_get_default() { - return GDK_DISPLAY(g_object_new(gdk_display_get_type(), nullptr)); -} - -void gdk_display_beep(GdkDisplay* display) {} - -GdkWindowState gdk_window_get_state(GdkWindow* window) { - return mock->gdk_window_get_state(window); -} - -GdkDisplay* gdk_window_get_display(GdkWindow* window) { - return GDK_DISPLAY(g_object_new(gdk_display_get_type(), nullptr)); -} - -int gdk_display_get_n_monitors(GdkDisplay* display) { - return 1; -} - -GdkMonitor* gdk_display_get_monitor(GdkDisplay* display, int n) { - return GDK_MONITOR(g_object_new(gdk_monitor_get_type(), nullptr)); -} - -GdkMonitor* gdk_display_get_monitor_at_window(GdkDisplay* display, - GdkWindow* window) { - return nullptr; -} - -GdkCursor* gdk_cursor_new_from_name(GdkDisplay* display, const gchar* name) { - return nullptr; -} - -void gdk_window_set_cursor(GdkWindow* window, GdkCursor* cursor) {} - -GtkWidget* gtk_window_new(GtkWindowType type) { - GtkWindow* window = GTK_WINDOW(g_object_new(gtk_window_get_type(), nullptr)); - mock->gtk_window_new(window, type); - return GTK_WIDGET(window); -} - -void gtk_window_set_default_size(GtkWindow* window, gint width, gint height) { - mock->gtk_window_set_default_size(window, width, height); -} - -void gtk_window_set_title(GtkWindow* window, const gchar* title) { - mock->gtk_window_set_title(window, title); -} - -void gtk_window_set_geometry_hints(GtkWindow* window, - GtkWidget* widget, - GdkGeometry* geometry, - GdkWindowHints geometry_mask) { - mock->gtk_window_set_geometry_hints(window, widget, geometry, geometry_mask); -} - -void gtk_window_resize(GtkWindow* window, gint width, gint height) { - mock->gtk_window_resize(window, width, height); -} - -void gtk_window_maximize(GtkWindow* window) { - mock->gtk_window_maximize(window); -} - -void gtk_window_unmaximize(GtkWindow* window) { - mock->gtk_window_unmaximize(window); -} - -gboolean gtk_window_is_maximized(GtkWindow* window) { - return mock->gtk_window_is_maximized(window); -} - -void gtk_window_iconify(GtkWindow* window) { - mock->gtk_window_iconify(window); -} - -void gtk_window_deiconify(GtkWindow* window) { - mock->gtk_window_deiconify(window); -} - -void gtk_widget_show(GtkWidget* widget) {} - -void gtk_widget_destroy(GtkWidget* widget) { - mock->gtk_widget_destroy(widget); -} - -void fl_gtk_widget_destroy(GtkWidget* widget) { - void (*destroy)(GtkWidget*) = reinterpret_cast( - dlsym(RTLD_NEXT, "gtk_widget_destroy")); - destroy(widget); -} diff --git a/engine/src/flutter/shell/platform/linux/testing/mock_window.h b/engine/src/flutter/shell/platform/linux/testing/mock_window.h deleted file mode 100644 index 61d7be1ac2..0000000000 --- a/engine/src/flutter/shell/platform/linux/testing/mock_window.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_WINDOW_H_ -#define FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_WINDOW_H_ - -#include "gmock/gmock.h" - -#include - -namespace flutter { -namespace testing { - -class MockWindow { - public: - MockWindow(); - ~MockWindow(); - - MOCK_METHOD(GdkWindowState, gdk_window_get_state, (GdkWindow * window)); - MOCK_METHOD(void, gtk_window_new, (GtkWindow * window, GtkWindowType type)); - MOCK_METHOD(void, - gtk_window_set_default_size, - (GtkWindow * window, gint width, gint height)); - MOCK_METHOD(void, - gtk_window_set_title, - (GtkWindow * window, const gchar* title)); - MOCK_METHOD(void, - gtk_window_set_geometry_hints, - (GtkWindow * window, - GtkWidget* widget, - GdkGeometry* geometry, - GdkWindowHints geometry_mask)); - MOCK_METHOD(void, - gtk_window_resize, - (GtkWindow * window, gint width, gint height)); - MOCK_METHOD(void, gtk_window_maximize, (GtkWindow * window)); - MOCK_METHOD(void, gtk_window_unmaximize, (GtkWindow * window)); - MOCK_METHOD(gboolean, gtk_window_is_maximized, (GtkWindow * window)); - MOCK_METHOD(void, gtk_window_iconify, (GtkWindow * window)); - MOCK_METHOD(void, gtk_window_deiconify, (GtkWindow * window)); - MOCK_METHOD(void, gtk_widget_destroy, (GtkWidget * widget)); -}; - -} // namespace testing -} // namespace flutter - -// Calls original gtk_widget_destroy. -void fl_gtk_widget_destroy(GtkWidget* widget); - -#endif // FLUTTER_SHELL_PLATFORM_LINUX_TESTING_MOCK_WINDOW_H_