Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 0 additions & 210 deletions shell/platform/windows/flutter_window_win32_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,216 +328,6 @@ TEST(FlutterWindowWin32Test, CreateDestroy) {
ASSERT_TRUE(TRUE);
}

// Tests key event propagation of non-printable, non-modifier key down events.
TEST(FlutterWindowWin32Test, NonPrintableKeyDownPropagation) {
::testing::InSequence in_sequence;

constexpr WPARAM virtual_key = VK_LEFT;
constexpr WPARAM scan_code = 10;
constexpr char32_t character = 0;
MockFlutterWindowWin32 win32window;
auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
TestFlutterWindowsView flutter_windows_view(
std::move(window_binding_handler), virtual_key, false /* is_printable */);
win32window.SetView(&flutter_windows_view);
LPARAM lparam = CreateKeyEventLparam(scan_code, false, false);

// Test an event not handled by the framework
{
test_response = false;
flutter_windows_view.SetEngine(std::move(GetTestEngine()));
EXPECT_CALL(*flutter_windows_view.key_event_handler,
KeyboardHook(virtual_key, scan_code, WM_KEYDOWN, character,
false /* extended */, _))
.Times(2)
.RetiresOnSaturation();
EXPECT_CALL(*flutter_windows_view.text_input_plugin,
KeyboardHook(_, _, _, _, _, _))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*flutter_windows_view.text_input_plugin, TextHook(_)).Times(0);
win32window.InjectMessages(1,
Win32Message{WM_KEYDOWN, virtual_key, lparam});
flutter_windows_view.InjectPendingEvents(&win32window);
}

// Test an event handled by the framework
{
test_response = true;
EXPECT_CALL(*flutter_windows_view.key_event_handler,
KeyboardHook(virtual_key, scan_code, WM_KEYDOWN, character,
false /* extended */, false /* PrevState */))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*flutter_windows_view.text_input_plugin,
KeyboardHook(_, _, _, _, _, _))
.Times(0);
win32window.InjectMessages(1,
Win32Message{WM_KEYDOWN, virtual_key, lparam});
flutter_windows_view.InjectPendingEvents(&win32window);
}
}

// Tests key event propagation of system (WM_SYSKEYDOWN) key down events.
TEST(FlutterWindowWin32Test, SystemKeyDownPropagation) {
::testing::InSequence in_sequence;

constexpr WPARAM virtual_key = VK_LEFT;
constexpr WPARAM scan_code = 10;
constexpr char32_t character = 0;
MockFlutterWindowWin32 win32window;
auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
TestFlutterWindowsView flutter_windows_view(
std::move(window_binding_handler), virtual_key, false /* is_printable */);
win32window.SetView(&flutter_windows_view);
LPARAM lparam = CreateKeyEventLparam(scan_code, false, false);

// Test an event not handled by the framework
{
test_response = false;
flutter_windows_view.SetEngine(std::move(GetTestEngine()));
EXPECT_CALL(*flutter_windows_view.key_event_handler,
KeyboardHook(virtual_key, scan_code, WM_SYSKEYDOWN, character,
false /* extended */, _))
.Times(2)
.RetiresOnSaturation();
// Syskey events are not redispatched, so TextInputPlugin, which relies on
// them to receive events, no longer works.
EXPECT_CALL(*flutter_windows_view.text_input_plugin,
KeyboardHook(_, _, _, _, _, _))
.Times(0)
.RetiresOnSaturation();
EXPECT_CALL(*flutter_windows_view.text_input_plugin, TextHook(_)).Times(0);
win32window.InjectMessages(
1, Win32Message{WM_SYSKEYDOWN, virtual_key, lparam, kWmResultDefault});
flutter_windows_view.InjectPendingEvents(&win32window);
}

// Test an event handled by the framework
{
test_response = true;
EXPECT_CALL(*flutter_windows_view.key_event_handler,
KeyboardHook(_, _, _, _, _, _))
.Times(0);
EXPECT_CALL(*flutter_windows_view.text_input_plugin,
KeyboardHook(_, _, _, _, _, _))
.Times(0);
win32window.InjectMessages(
1, Win32Message{WM_SYSKEYDOWN, virtual_key, lparam, kWmResultDefault});
flutter_windows_view.InjectPendingEvents(&win32window);
}
}

// Tests key event propagation of printable character key down events. These
// differ from non-printable characters in that they follow a different code
// path in the WndProc (HandleMessage), producing a follow-on WM_CHAR event.
TEST(FlutterWindowWin32Test, CharKeyDownPropagation) {
::testing::InSequence in_sequence;

constexpr WPARAM virtual_key = 65; // The "A" key, which produces a character
constexpr WPARAM scan_code = 30;
constexpr char32_t character = 65;

MockFlutterWindowWin32 win32window;
auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
TestFlutterWindowsView flutter_windows_view(
std::move(window_binding_handler), virtual_key, true /* is_printable */);
win32window.SetView(&flutter_windows_view);
LPARAM lparam = CreateKeyEventLparam(scan_code, false, false);
flutter_windows_view.SetEngine(std::move(GetTestEngine()));

// Test an event not handled by the framework
{
test_response = false;
EXPECT_CALL(*flutter_windows_view.key_event_handler,
KeyboardHook(virtual_key, scan_code, WM_KEYDOWN, character,
false, false))
.Times(2)
.RetiresOnSaturation();
EXPECT_CALL(*flutter_windows_view.text_input_plugin,
KeyboardHook(_, _, _, _, _, _))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*flutter_windows_view.text_input_plugin, TextHook(_))
.Times(1)
.RetiresOnSaturation();
win32window.InjectMessages(2, Win32Message{WM_KEYDOWN, virtual_key, lparam},
Win32Message{WM_CHAR, virtual_key, lparam});
flutter_windows_view.InjectPendingEvents(&win32window);
}

// Test an event handled by the framework
{
test_response = true;
EXPECT_CALL(*flutter_windows_view.key_event_handler,
KeyboardHook(virtual_key, scan_code, WM_KEYDOWN, character,
false, false))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*flutter_windows_view.text_input_plugin,
KeyboardHook(_, _, _, _, _, _))
.Times(0);
EXPECT_CALL(*flutter_windows_view.text_input_plugin, TextHook(_)).Times(0);
win32window.InjectMessages(2, Win32Message{WM_KEYDOWN, virtual_key, lparam},
Win32Message{WM_CHAR, virtual_key, lparam});
flutter_windows_view.InjectPendingEvents(&win32window);
}
}

// Tests key event propagation of modifier key down events. This is different
// from non-printable events in that they call MapVirtualKey, resulting in a
// slightly different code path.
TEST(FlutterWindowWin32Test, ModifierKeyDownPropagation) {
constexpr WPARAM virtual_key = VK_LSHIFT;
constexpr WPARAM scan_code = 0x2a;
constexpr char32_t character = 0;
MockFlutterWindowWin32 win32window;
auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
TestFlutterWindowsView flutter_windows_view(
std::move(window_binding_handler), virtual_key, false /* is_printable */);
win32window.SetView(&flutter_windows_view);
LPARAM lparam = CreateKeyEventLparam(scan_code, false, false);

// Test an event not handled by the framework
{
test_response = false;
flutter_windows_view.SetEngine(std::move(GetTestEngine()));
EXPECT_CALL(*flutter_windows_view.key_event_handler,
KeyboardHook(virtual_key, scan_code, WM_KEYDOWN, character,
false /* extended */, false))
.Times(2)
.RetiresOnSaturation();
EXPECT_CALL(*flutter_windows_view.text_input_plugin,
KeyboardHook(_, _, _, _, _, _))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*flutter_windows_view.text_input_plugin, TextHook(_)).Times(0);
EXPECT_EQ(win32window.InjectWindowMessage(WM_KEYDOWN, virtual_key, lparam),
0);
flutter_windows_view.InjectPendingEvents(&win32window);
}

// Test an event handled by the framework
{
test_response = true;
EXPECT_CALL(*flutter_windows_view.key_event_handler,
KeyboardHook(virtual_key, scan_code, WM_KEYDOWN, character,
false /* extended */, false))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*flutter_windows_view.text_input_plugin,
KeyboardHook(_, _, _, _, _, _))
.Times(0);
EXPECT_EQ(win32window.InjectWindowMessage(WM_KEYDOWN, virtual_key, lparam),
0);
flutter_windows_view.InjectPendingEvents(&win32window);
}
}

// Tests that composing rect updates are transformed from Flutter logical
// coordinates to device coordinates and passed to the text input manager
// when the DPI scale is 100% (96 DPI).
Expand Down
3 changes: 2 additions & 1 deletion shell/platform/windows/keyboard_key_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ KeyboardKeyHandler::KeyboardKeyHandlerDelegate::~KeyboardKeyHandlerDelegate() =
KeyboardKeyHandler::KeyboardKeyHandler(EventDispatcher dispatch_event)
: dispatch_event_(dispatch_event),
last_sequence_id_(1),
last_key_is_ctrl_left_down(false) {}
last_key_is_ctrl_left_down(false),
should_synthesize_ctrl_left_up(false) {}

KeyboardKeyHandler::~KeyboardKeyHandler() = default;

Expand Down
Loading