From ddb41c503395efc5092381cc6c8b9cd5f8e7a749 Mon Sep 17 00:00:00 2001 From: Loic Sharma Date: Fri, 27 Jan 2023 13:57:20 -0800 Subject: [PATCH 1/4] [Windows] Refactor the keyboard unit tests --- shell/platform/windows/keyboard_unittests.cc | 655 +++++++++---------- 1 file changed, 308 insertions(+), 347 deletions(-) diff --git a/shell/platform/windows/keyboard_unittests.cc b/shell/platform/windows/keyboard_unittests.cc index 30aeb3192a766..4baeaa4e52674 100644 --- a/shell/platform/windows/keyboard_unittests.cc +++ b/shell/platform/windows/keyboard_unittests.cc @@ -13,8 +13,10 @@ #include "flutter/shell/platform/windows/keyboard_key_handler.h" #include "flutter/shell/platform/windows/keyboard_manager.h" #include "flutter/shell/platform/windows/testing/engine_modifier.h" +#include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h" #include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h" #include "flutter/shell/platform/windows/testing/test_keyboard.h" +#include "flutter/shell/platform/windows/testing/windows_test.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -260,7 +262,7 @@ class MockKeyboardManagerDelegate : public KeyboardManager::WindowDelegate, } // This method is called for each message injected by test cases with - // `tester.InjectMessages`. + // `InjectMessages`. LRESULT Win32SendMessage(UINT const message, WPARAM const wparam, LPARAM const lparam) override { @@ -409,12 +411,12 @@ void clear_key_calls() { key_calls.clear(); } -class KeyboardTester { +class KeyboardTest : public WindowsTest { public: using ResponseHandler = std::function; - explicit KeyboardTester() + explicit KeyboardTest() : callback_handler_(RespondValue(false)), map_virtual_key_layout_(LayoutDefault) { view_ = std::make_unique( @@ -497,15 +499,11 @@ class KeyboardTester { // Returns an engine instance configured with dummy project path values, and // overridden methods for sending platform messages, so that the engine can // respond as if the framework were connected. - static std::unique_ptr GetTestEngine( + std::unique_ptr GetTestEngine( MockKeyResponseController::EmbedderCallbackHandler embedder_callback_handler) { - FlutterDesktopEngineProperties properties = {}; - properties.assets_path = L"C:\\foo\\flutter_assets"; - properties.icu_data_path = L"C:\\foo\\icudtl.dat"; - properties.aot_library_path = L"C:\\foo\\aot.so"; - FlutterProjectBundle project(properties); - auto engine = std::make_unique(project); + FlutterWindowsEngineBuilder builder{GetContext()}; + auto engine = builder.Build(); EngineModifier modifier(engine.get()); @@ -556,14 +554,13 @@ class KeyboardTester { EXPECT_EQ(_key_call.type, KeyCall::kKeyCallTextMethodCall); \ EXPECT_STREQ(_key_call.text_method_call.c_str(), json_string); -TEST(KeyboardTest, LowerCaseAHandled) { - KeyboardTester tester; - tester.Responding(true); +TEST_F(KeyboardTest, LowerCaseAHandled) { + Responding(true); // US Keyboard layout // Press A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -573,10 +570,10 @@ TEST(KeyboardTest, LowerCaseAHandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); // Release A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); @@ -584,17 +581,16 @@ TEST(KeyboardTest, LowerCaseAHandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); } -TEST(KeyboardTest, LowerCaseAUnhandled) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, LowerCaseAUnhandled) { + Responding(false); // US Keyboard layout // Press A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -605,10 +601,10 @@ TEST(KeyboardTest, LowerCaseAUnhandled) { kLogicalKeyA, "a", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"a"); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); @@ -616,17 +612,16 @@ TEST(KeyboardTest, LowerCaseAUnhandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, ArrowLeftHandled) { - KeyboardTester tester; - tester.Responding(true); +TEST_F(KeyboardTest, ArrowLeftHandled) { + Responding(true); // US Keyboard layout // Press ArrowLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{VK_LEFT, kScanCodeArrowLeft, kExtended, kWasUp}.Build( kWmResultZero)}); @@ -635,10 +630,10 @@ TEST(KeyboardTest, ArrowLeftHandled) { kPhysicalArrowLeft, kLogicalArrowLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); // Release ArrowLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{VK_LEFT, kScanCodeArrowLeft, kExtended}.Build( kWmResultZero)}); @@ -646,17 +641,16 @@ TEST(KeyboardTest, ArrowLeftHandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalArrowLeft, kLogicalArrowLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); } -TEST(KeyboardTest, ArrowLeftUnhandled) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, ArrowLeftUnhandled) { + Responding(false); // US Keyboard layout // Press ArrowLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{VK_LEFT, kScanCodeArrowLeft, kExtended, kWasUp}.Build( kWmResultZero)}); @@ -665,10 +659,10 @@ TEST(KeyboardTest, ArrowLeftUnhandled) { kPhysicalArrowLeft, kLogicalArrowLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release ArrowLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{VK_LEFT, kScanCodeArrowLeft, kExtended}.Build( kWmResultZero)}); @@ -676,17 +670,16 @@ TEST(KeyboardTest, ArrowLeftUnhandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalArrowLeft, kLogicalArrowLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, ShiftLeftUnhandled) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, ShiftLeftUnhandled) { + Responding(false); // US Keyboard layout // Press ShiftLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, true, false}, WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -696,10 +689,10 @@ TEST(KeyboardTest, ShiftLeftUnhandled) { kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Hold ShiftLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasDown}.Build( kWmResultZero)}); @@ -708,10 +701,10 @@ TEST(KeyboardTest, ShiftLeftUnhandled) { kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release ShiftLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, false, true}, WmKeyUpInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended}.Build( kWmResultZero)}); @@ -720,17 +713,16 @@ TEST(KeyboardTest, ShiftLeftUnhandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, ShiftRightUnhandled) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, ShiftRightUnhandled) { + Responding(false); // US Keyboard layout // Press ShiftRight - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RSHIFT, true, false}, WmKeyDownInfo{VK_SHIFT, kScanCodeShiftRight, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -740,10 +732,10 @@ TEST(KeyboardTest, ShiftRightUnhandled) { kPhysicalShiftRight, kLogicalShiftRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release ShiftRight - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RSHIFT, false, true}, WmKeyUpInfo{VK_SHIFT, kScanCodeShiftRight, kNotExtended}.Build( kWmResultZero)}); @@ -753,17 +745,16 @@ TEST(KeyboardTest, ShiftRightUnhandled) { kPhysicalShiftRight, kLogicalShiftRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, CtrlLeftUnhandled) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, CtrlLeftUnhandled) { + Responding(false); // US Keyboard layout // Press CtrlLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, false}, WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -773,10 +764,10 @@ TEST(KeyboardTest, CtrlLeftUnhandled) { kPhysicalControlLeft, kLogicalControlLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release CtrlLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, true}, WmKeyUpInfo{VK_SHIFT, kScanCodeControl, kNotExtended}.Build( kWmResultZero)}); @@ -786,17 +777,16 @@ TEST(KeyboardTest, CtrlLeftUnhandled) { kPhysicalControlLeft, kLogicalControlLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, CtrlRightUnhandled) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, CtrlRightUnhandled) { + Responding(false); // US Keyboard layout // Press CtrlRight - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RCONTROL, true, false}, WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kExtended, kWasUp}.Build( kWmResultZero)}); @@ -806,10 +796,10 @@ TEST(KeyboardTest, CtrlRightUnhandled) { kPhysicalControlRight, kLogicalControlRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release CtrlRight - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RCONTROL, false, true}, WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kExtended}.Build( kWmResultZero)}); @@ -819,17 +809,16 @@ TEST(KeyboardTest, CtrlRightUnhandled) { kPhysicalControlRight, kLogicalControlRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, AltLeftUnhandled) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, AltLeftUnhandled) { + Responding(false); // US Keyboard layout // Press AltLeft. AltLeft is a SysKeyDown event. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LMENU, true, false}, WmSysKeyDownInfo{VK_MENU, kScanCodeAlt, kNotExtended, kWasUp}.Build( kWmResultDefault)}); // Always pass to the default WndProc. @@ -839,10 +828,10 @@ TEST(KeyboardTest, AltLeftUnhandled) { kLogicalAltLeft, "", kNotSynthesized); clear_key_calls(); // Don't redispatch sys messages. - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); // Release AltLeft. AltLeft is a SysKeyUp event. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LMENU, false, true}, WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kNotExtended}.Build( kWmResultDefault)}); // Always pass to the default WndProc. @@ -852,17 +841,16 @@ TEST(KeyboardTest, AltLeftUnhandled) { kLogicalAltLeft, "", kNotSynthesized); clear_key_calls(); // Don't redispatch sys messages. - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); } -TEST(KeyboardTest, AltRightUnhandled) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, AltRightUnhandled) { + Responding(false); // US Keyboard layout // Press AltRight. AltRight is a SysKeyDown event. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RMENU, true, false}, WmSysKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build( kWmResultDefault)}); // Always pass to the default WndProc. @@ -873,10 +861,10 @@ TEST(KeyboardTest, AltRightUnhandled) { kNotSynthesized); clear_key_calls(); // Don't redispatch sys messages. - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); // Release AltRight. AltRight is a SysKeyUp event. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RMENU, false, true}, WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build( kWmResultDefault)}); // Always pass to the default WndProc. @@ -886,17 +874,16 @@ TEST(KeyboardTest, AltRightUnhandled) { kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); // Don't redispatch sys messages. - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); } -TEST(KeyboardTest, MetaLeftUnhandled) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, MetaLeftUnhandled) { + Responding(false); // US Keyboard layout // Press MetaLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LWIN, true, false}, WmKeyDownInfo{VK_LWIN, kScanCodeMetaLeft, kExtended, kWasUp}.Build( kWmResultZero)}); @@ -906,10 +893,10 @@ TEST(KeyboardTest, MetaLeftUnhandled) { kPhysicalMetaLeft, kLogicalMetaLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release MetaLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LWIN, false, true}, WmKeyUpInfo{VK_LWIN, kScanCodeMetaLeft, kExtended}.Build(kWmResultZero)}); @@ -917,17 +904,16 @@ TEST(KeyboardTest, MetaLeftUnhandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalMetaLeft, kLogicalMetaLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, MetaRightUnhandled) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, MetaRightUnhandled) { + Responding(false); // US Keyboard layout // Press MetaRight - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RWIN, true, false}, WmKeyDownInfo{VK_RWIN, kScanCodeMetaRight, kExtended, kWasUp}.Build( kWmResultZero)}); @@ -937,10 +923,10 @@ TEST(KeyboardTest, MetaRightUnhandled) { kPhysicalMetaRight, kLogicalMetaRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release MetaRight - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RWIN, false, true}, WmKeyUpInfo{VK_RWIN, kScanCodeMetaRight, kExtended}.Build( kWmResultZero)}); @@ -949,19 +935,18 @@ TEST(KeyboardTest, MetaRightUnhandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalMetaRight, kLogicalMetaRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } // Press Shift-A. This is special because Win32 gives 'A' as character for the // KeyA press. -TEST(KeyboardTest, ShiftLeftKeyA) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, ShiftLeftKeyA) { + Responding(false); // US Keyboard layout // Press ShiftLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, true, true}, WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -971,10 +956,10 @@ TEST(KeyboardTest, ShiftLeftKeyA) { kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Press A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'A', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -985,10 +970,10 @@ TEST(KeyboardTest, ShiftLeftKeyA) { kLogicalKeyA, "A", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"A"); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release ShiftLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, false, true}, WmKeyUpInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended}.Build( kWmResultZero)}); @@ -997,10 +982,10 @@ TEST(KeyboardTest, ShiftLeftKeyA) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); @@ -1008,19 +993,18 @@ TEST(KeyboardTest, ShiftLeftKeyA) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } // Press Ctrl-A. This is special because Win32 gives 0x01 as character for the // KeyA press. -TEST(KeyboardTest, CtrlLeftKeyA) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, CtrlLeftKeyA) { + Responding(false); // US Keyboard layout // Press ControlLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, true}, WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -1030,10 +1014,10 @@ TEST(KeyboardTest, CtrlLeftKeyA) { kPhysicalControlLeft, kLogicalControlLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Press A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{0x01, kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -1043,10 +1027,10 @@ TEST(KeyboardTest, CtrlLeftKeyA) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); @@ -1054,10 +1038,10 @@ TEST(KeyboardTest, CtrlLeftKeyA) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release ControlLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, true}, WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build( kWmResultZero)}); @@ -1067,18 +1051,17 @@ TEST(KeyboardTest, CtrlLeftKeyA) { kPhysicalControlLeft, kLogicalControlLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } // Press Ctrl-1. This is special because it yields no WM_CHAR for the 1. -TEST(KeyboardTest, CtrlLeftDigit1) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, CtrlLeftDigit1) { + Responding(false); // US Keyboard layout // Press ControlLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, true}, WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -1088,10 +1071,10 @@ TEST(KeyboardTest, CtrlLeftDigit1) { kPhysicalControlLeft, kLogicalControlLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Press 1 - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp} .Build(kWmResultZero)}); @@ -1099,10 +1082,10 @@ TEST(KeyboardTest, CtrlLeftDigit1) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release 1 - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build( kWmResultZero)}); @@ -1110,10 +1093,10 @@ TEST(KeyboardTest, CtrlLeftDigit1) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release ControlLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, true}, WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build( kWmResultZero)}); @@ -1123,19 +1106,18 @@ TEST(KeyboardTest, CtrlLeftDigit1) { kPhysicalControlLeft, kLogicalControlLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } // Press 1 on a French keyboard. This is special because it yields WM_CHAR // with char_code '&'. -TEST(KeyboardTest, Digit1OnFrenchLayout) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, Digit1OnFrenchLayout) { + Responding(false); - tester.SetLayout(LayoutFrench); + SetLayout(LayoutFrench); // Press 1 - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp} .Build(kWmResultZero), WmCharInfo{'&', kScanCodeDigit1, kNotExtended, kWasUp}.Build( @@ -1146,10 +1128,10 @@ TEST(KeyboardTest, Digit1OnFrenchLayout) { kLogicalDigit1, "&", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"&"); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release 1 - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build( kWmResultZero)}); @@ -1157,18 +1139,17 @@ TEST(KeyboardTest, Digit1OnFrenchLayout) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } // This tests AltGr-Q on a German keyboard, which should print '@'. -TEST(KeyboardTest, AltGrModifiedKey) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, AltGrModifiedKey) { + Responding(false); // German Keyboard layout // Press AltGr, which Win32 precedes with a ContrlLeft down. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, true}, WmKeyDownInfo{VK_LCONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build( kWmResultZero), @@ -1184,10 +1165,10 @@ TEST(KeyboardTest, AltGrModifiedKey) { kPhysicalAltRight, kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Press Q - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyQ, kScanCodeKeyQ, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'@', kScanCodeKeyQ, kNotExtended, kWasUp}.Build( @@ -1198,10 +1179,10 @@ TEST(KeyboardTest, AltGrModifiedKey) { kLogicalKeyQ, "@", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"@"); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release Q - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyQ, kScanCodeKeyQ, kNotExtended}.Build( kWmResultZero)}); @@ -1209,12 +1190,12 @@ TEST(KeyboardTest, AltGrModifiedKey) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyQ, kLogicalKeyQ, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release AltGr. Win32 doesn't dispatch ControlLeft up. Instead Flutter will // forge one. The AltGr is a system key, therefore will be handled by Win32's // default WndProc. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, true}, ExpectForgedMessage{ WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build( @@ -1231,7 +1212,7 @@ TEST(KeyboardTest, AltGrModifiedKey) { kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); // The sys key up must not be redispatched. The forged ControlLeft up will. - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } // Test the following two key sequences at the same time: @@ -1247,15 +1228,14 @@ TEST(KeyboardTest, AltGrModifiedKey) { // // This is because pressing AltGr alone causes Win32 to send a fake "CtrlLeft // down" event first (see |IsKeyDownAltRight| for detailed explanation). -TEST(KeyboardTest, AltGrTwice) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, AltGrTwice) { + Responding(false); // 1. AltGr down. // The key down event causes a ControlLeft down and a AltRight (extended // AltLeft) down. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, true}, WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build( kWmResultZero), @@ -1271,12 +1251,12 @@ TEST(KeyboardTest, AltGrTwice) { kPhysicalAltRight, kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // 2. AltGr up. // The key up event only causes a AltRight (extended AltLeft) up. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, true}, ExpectForgedMessage{ WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build( @@ -1292,11 +1272,11 @@ TEST(KeyboardTest, AltGrTwice) { kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); // The sys key up must not be redispatched. The forged ControlLeft up will. - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // 3. AltGr down (or: ControlLeft down then AltRight down.) - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, false}, WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build( kWmResultZero), @@ -1312,12 +1292,12 @@ TEST(KeyboardTest, AltGrTwice) { kPhysicalAltRight, kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // 4. AltGr up. // The key up event only causes a AltRight (extended AltLeft) up. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, false}, ExpectForgedMessage{ WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build( @@ -1333,29 +1313,28 @@ TEST(KeyboardTest, AltGrTwice) { kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); // The sys key up must not be redispatched. The forged ControlLeft up will. - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // 5. For key sequence 2: a real ControlLeft up. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build( kWmResultZero)}); EXPECT_EQ(key_calls.size(), 1); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); } // This tests dead key ^ then E on a French keyboard, which should be combined // into ê. -TEST(KeyboardTest, DeadKeyThatCombines) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, DeadKeyThatCombines) { + Responding(false); - tester.SetLayout(LayoutFrench); + SetLayout(LayoutFrench); // Press ^¨ (US: Left bracket) - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{0xDD, kScanCodeBracketLeft, kNotExtended, kWasUp}.Build( kWmResultZero), WmDeadCharInfo{'^', kScanCodeBracketLeft, kNotExtended, kWasUp}.Build( @@ -1366,10 +1345,10 @@ TEST(KeyboardTest, DeadKeyThatCombines) { kPhysicalBracketLeft, kLogicalBracketRight, "^", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release ^¨ - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{0xDD, kScanCodeBracketLeft, kNotExtended}.Build( kWmResultZero)}); @@ -1378,10 +1357,10 @@ TEST(KeyboardTest, DeadKeyThatCombines) { kPhysicalBracketLeft, kLogicalBracketRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Press E - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{0xEA, kScanCodeKeyE, kNotExtended, kWasUp}.Build( @@ -1392,10 +1371,10 @@ TEST(KeyboardTest, DeadKeyThatCombines) { kLogicalKeyE, "ê", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"ê"); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release E - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended}.Build( kWmResultZero)}); @@ -1403,7 +1382,7 @@ TEST(KeyboardTest, DeadKeyThatCombines) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyE, kLogicalKeyE, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } // This tests dead key ^ then E on a US INTL keyboard, which should be combined @@ -1411,12 +1390,11 @@ TEST(KeyboardTest, DeadKeyThatCombines) { // // It is different from French AZERTY because the character that the ^ key is // mapped to does not contain the dead key character somehow. -TEST(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { + Responding(false); // Press ShiftLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, true, true}, WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -1426,10 +1404,10 @@ TEST(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Press 6^ - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{'6', kScanCodeDigit6, kNotExtended, kWasUp}.Build( kWmResultZero), WmDeadCharInfo{'^', kScanCodeDigit6, kNotExtended, kWasUp}.Build( @@ -1439,20 +1417,20 @@ TEST(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalDigit6, kLogicalDigit6, "6", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release 6^ - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{'6', kScanCodeDigit6, kNotExtended}.Build(kWmResultZero)}); EXPECT_EQ(key_calls.size(), 1); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalDigit6, kLogicalDigit6, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release ShiftLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, false, true}, WmKeyUpInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended}.Build( kWmResultZero)}); @@ -1461,10 +1439,10 @@ TEST(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Press E - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{0xEA, kScanCodeKeyE, kNotExtended, kWasUp}.Build( @@ -1475,10 +1453,10 @@ TEST(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { kLogicalKeyE, "ê", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"ê"); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release E - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended}.Build( kWmResultZero)}); @@ -1486,19 +1464,18 @@ TEST(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyE, kLogicalKeyE, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } // This tests dead key ^ then & (US: 1) on a French keyboard, which do not // combine and should output "^&". -TEST(KeyboardTest, DeadKeyThatDoesNotCombine) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, DeadKeyThatDoesNotCombine) { + Responding(false); - tester.SetLayout(LayoutFrench); + SetLayout(LayoutFrench); // Press ^¨ (US: Left bracket) - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{0xDD, kScanCodeBracketLeft, kNotExtended, kWasUp}.Build( kWmResultZero), WmDeadCharInfo{'^', kScanCodeBracketLeft, kNotExtended, kWasUp}.Build( @@ -1509,10 +1486,10 @@ TEST(KeyboardTest, DeadKeyThatDoesNotCombine) { kPhysicalBracketLeft, kLogicalBracketRight, "^", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release ^¨ - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{0xDD, kScanCodeBracketLeft, kNotExtended}.Build( kWmResultZero)}); @@ -1521,10 +1498,10 @@ TEST(KeyboardTest, DeadKeyThatDoesNotCombine) { kPhysicalBracketLeft, kLogicalBracketRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Press 1 - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp} .Build(kWmResultZero), WmCharInfo{'^', kScanCodeDigit1, kNotExtended, kWasUp}.Build( @@ -1543,10 +1520,10 @@ TEST(KeyboardTest, DeadKeyThatDoesNotCombine) { // not handled by the framework, while the '&' message is not redispatched // for being a standalone message. We should resolve this inconsistency. // https://github.com/flutter/flutter/issues/98306 - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release 1 - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build( kWmResultZero)}); @@ -1554,20 +1531,19 @@ TEST(KeyboardTest, DeadKeyThatDoesNotCombine) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } // This tests dead key `, then dead key `, then e. // // It should output ``e, instead of `è. -TEST(KeyboardTest, DeadKeyTwiceThenLetter) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, DeadKeyTwiceThenLetter) { + Responding(false); // US INTL layout. // Press ` - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{0xC0, kScanCodeBackquote, kNotExtended, kWasUp}.Build( kWmResultZero), WmDeadCharInfo{'`', kScanCodeBackquote, kNotExtended, kWasUp}.Build( @@ -1578,10 +1554,10 @@ TEST(KeyboardTest, DeadKeyTwiceThenLetter) { kPhysicalBackquote, kLogicalBackquote, "`", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release ` - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{0xC0, kScanCodeBackquote, kNotExtended}.Build( kWmResultZero)}); @@ -1589,19 +1565,18 @@ TEST(KeyboardTest, DeadKeyTwiceThenLetter) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalBackquote, kLogicalBackquote, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Press ` again. // The response should be slow. std::vector recorded_callbacks; - tester.LateResponding( - [&recorded_callbacks]( - const FlutterKeyEvent* event, - MockKeyResponseController::ResponseCallback callback) { - recorded_callbacks.push_back(callback); - }); + LateResponding([&recorded_callbacks]( + const FlutterKeyEvent* event, + MockKeyResponseController::ResponseCallback callback) { + recorded_callbacks.push_back(callback); + }); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{0xC0, kScanCodeBackquote, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'`', kScanCodeBackquote, kNotExtended, kWasUp, kBeingReleased, @@ -1625,12 +1600,12 @@ TEST(KeyboardTest, DeadKeyTwiceThenLetter) { // TODO(dkwingsmt): This count should probably be 3. See the comment above // that is marked with the same issue. // https://github.com/flutter/flutter/issues/98306 - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); - tester.Responding(false); + Responding(false); // Release ` - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{0xC0, kScanCodeBackquote, kNotExtended}.Build( kWmResultZero)}); @@ -1638,19 +1613,18 @@ TEST(KeyboardTest, DeadKeyTwiceThenLetter) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalBackquote, kLogicalBackquote, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } // This tests when the resulting character needs to be combined with surrogates. -TEST(KeyboardTest, MultibyteCharacter) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, MultibyteCharacter) { + Responding(false); // Gothic Keyboard layout. (We need a layout that yields non-BMP characters // without IME, which is actually very rare.) // Press key W of a US keyboard, which should yield character '𐍅'. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyW, kScanCodeKeyW, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{0xd800, kScanCodeKeyW, kNotExtended, kWasUp}.Build( @@ -1665,10 +1639,10 @@ TEST(KeyboardTest, MultibyteCharacter) { kLogicalKeyW, "𐍅", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"𐍅"); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 3); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 3); // Release W - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyW, kScanCodeKeyW, kNotExtended}.Build( kWmResultZero)}); @@ -1676,12 +1650,11 @@ TEST(KeyboardTest, MultibyteCharacter) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyW, kLogicalKeyW, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, SynthesizeModifiers) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, SynthesizeModifiers) { + Responding(false); // Two dummy events used to trigger synthesization. Win32Message event1 = @@ -1692,150 +1665,150 @@ TEST(KeyboardTest, SynthesizeModifiers) { kWmResultZero); // ShiftLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalShiftLeft, kLogicalShiftLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalShiftLeft, kLogicalShiftLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // ShiftRight - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RSHIFT, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalShiftRight, kLogicalShiftRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RSHIFT, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalShiftRight, kLogicalShiftRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // ControlLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalControlLeft, kLogicalControlLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalControlLeft, kLogicalControlLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // ControlRight - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RCONTROL, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalControlRight, kLogicalControlRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RCONTROL, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalControlRight, kLogicalControlRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // AltLeft - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LMENU, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalAltLeft, kLogicalAltLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LMENU, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalAltLeft, kLogicalAltLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // AltRight - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RMENU, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalAltRight, kLogicalAltRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RMENU, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalAltRight, kLogicalAltRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // MetaLeft - tester.InjectKeyboardChanges( + InjectKeyboardChanges( std::vector{KeyStateChange{VK_LWIN, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalMetaLeft, kLogicalMetaLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LWIN, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalMetaLeft, kLogicalMetaLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // MetaRight - tester.InjectKeyboardChanges( + InjectKeyboardChanges( std::vector{KeyStateChange{VK_RWIN, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalMetaRight, kLogicalMetaRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RWIN, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalMetaRight, kLogicalMetaRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // CapsLock, phase 0 -> 2 -> 0. // (For phases, see |SynchronizeCriticalToggledStates|.) - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_CAPITAL, false, true}, event1}); EXPECT_EQ(key_calls.size(), 3); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, @@ -1843,9 +1816,9 @@ TEST(KeyboardTest, SynthesizeModifiers) { EXPECT_CALL_IS_EVENT(key_calls[1], kFlutterKeyEventTypeUp, kPhysicalCapsLock, kLogicalCapsLock, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_CAPITAL, false, false}, event2}); EXPECT_EQ(key_calls.size(), 3); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, @@ -1853,19 +1826,19 @@ TEST(KeyboardTest, SynthesizeModifiers) { EXPECT_CALL_IS_EVENT(key_calls[1], kFlutterKeyEventTypeUp, kPhysicalCapsLock, kLogicalCapsLock, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // ScrollLock, phase 0 -> 1 -> 3 - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_SCROLL, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalScrollLock, kLogicalScrollLock, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_SCROLL, true, false}, event2}); EXPECT_EQ(key_calls.size(), 3); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, @@ -1875,10 +1848,10 @@ TEST(KeyboardTest, SynthesizeModifiers) { kPhysicalScrollLock, kLogicalScrollLock, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // NumLock, phase 0 -> 3 -> 2 - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_NUMLOCK, true, false}, event1}); // TODO(dkwingsmt): Synthesizing from phase 0 to 3 should yield a full key // tap and a key down. Fix the algorithm so that the following result becomes @@ -1888,9 +1861,9 @@ TEST(KeyboardTest, SynthesizeModifiers) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalNumLock, kLogicalNumLock, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_NUMLOCK, false, true}, event2}); EXPECT_EQ(key_calls.size(), 4); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalNumLock, @@ -1900,16 +1873,15 @@ TEST(KeyboardTest, SynthesizeModifiers) { EXPECT_CALL_IS_EVENT(key_calls[2], kFlutterKeyEventTypeUp, kPhysicalNumLock, kLogicalNumLock, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); } // Pressing extended keys during IME events should work properly by not sending // any events. // // Regression test for https://github.com/flutter/flutter/issues/95888 . -TEST(KeyboardTest, ImeExtendedEventsAreIgnored) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, ImeExtendedEventsAreIgnored) { + Responding(false); // US Keyboard layout. @@ -1917,7 +1889,7 @@ TEST(KeyboardTest, ImeExtendedEventsAreIgnored) { // Omit them in this test since they are not relavent. // Press CtrlRight in IME mode. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RCONTROL, true, false}, WmKeyDownInfo{VK_PROCESSKEY, kScanCodeControl, kExtended, kWasUp}.Build( kWmResultZero)}); @@ -1926,7 +1898,7 @@ TEST(KeyboardTest, ImeExtendedEventsAreIgnored) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); } // Ensures that synthesization works correctly when a Shift key is pressed and @@ -1935,14 +1907,13 @@ TEST(KeyboardTest, ImeExtendedEventsAreIgnored) { // Regression test for https://github.com/flutter/flutter/issues/104169. These // are real messages recorded when pressing Shift-2 using Microsoft Pinyin IME // on Win 10 Enterprise, which crashed the app before the fix. -TEST(KeyboardTest, UpOnlyImeEventsAreCorrectlyHandled) { - KeyboardTester tester; - tester.Responding(true); +TEST_F(KeyboardTest, UpOnlyImeEventsAreCorrectlyHandled) { + Responding(true); // US Keyboard layout. // Press CtrlRight in IME mode. - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, true, false}, WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build( kWmResultZero), @@ -1973,28 +1944,25 @@ TEST(KeyboardTest, UpOnlyImeEventsAreCorrectlyHandled) { // arrive earlier than the framework response, and if the 2nd event has an // identical hash as the one waiting for response, an earlier implementation // will crash upon the response. -TEST(KeyboardTest, SlowFrameworkResponse) { - KeyboardTester tester; - +TEST_F(KeyboardTest, SlowFrameworkResponse) { std::vector recorded_callbacks; // Store callbacks to manually call them. - tester.LateResponding( - [&recorded_callbacks]( - const FlutterKeyEvent* event, - MockKeyResponseController::ResponseCallback callback) { - recorded_callbacks.push_back(callback); - }); + LateResponding([&recorded_callbacks]( + const FlutterKeyEvent* event, + MockKeyResponseController::ResponseCallback callback) { + recorded_callbacks.push_back(callback); + }); // Press A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero)}); // Hold A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasDown}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasDown}.Build( @@ -2004,7 +1972,7 @@ TEST(KeyboardTest, SlowFrameworkResponse) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized); EXPECT_EQ(recorded_callbacks.size(), 1); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); // The first response. recorded_callbacks.front()(false); @@ -2014,7 +1982,7 @@ TEST(KeyboardTest, SlowFrameworkResponse) { EXPECT_CALL_IS_TEXT(key_calls[1], u"a"); EXPECT_CALL_IS_EVENT(key_calls[2], kFlutterKeyEventTypeRepeat, kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // The second response. recorded_callbacks.back()(false); @@ -2022,7 +1990,7 @@ TEST(KeyboardTest, SlowFrameworkResponse) { EXPECT_EQ(key_calls.size(), 4); EXPECT_CALL_IS_TEXT(key_calls[3], u"a"); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); } // Regression test for https://github.com/flutter/flutter/issues/84210. @@ -2036,21 +2004,18 @@ TEST(KeyboardTest, SlowFrameworkResponse) { // KeyA down, KeyA up, (down event responded with false), KeyA down, KeyA up, // // The code must not take the 2nd real key down events as a redispatched event. -TEST(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) { - KeyboardTester tester; - +TEST_F(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) { std::vector recorded_callbacks; // Store callbacks to manually call them. - tester.LateResponding( - [&recorded_callbacks]( - const FlutterKeyEvent* event, - MockKeyResponseController::ResponseCallback callback) { - recorded_callbacks.push_back(callback); - }); + LateResponding([&recorded_callbacks]( + const FlutterKeyEvent* event, + MockKeyResponseController::ResponseCallback callback) { + recorded_callbacks.push_back(callback); + }); // Press A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -2060,15 +2025,15 @@ TEST(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); // Release A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); EXPECT_EQ(key_calls.size(), 0); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); // The first down event responded with false. EXPECT_EQ(recorded_callbacks.size(), 1); @@ -2079,10 +2044,10 @@ TEST(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) { EXPECT_CALL_IS_EVENT(key_calls[1], kFlutterKeyEventTypeUp, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Press A again - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -2092,7 +2057,7 @@ TEST(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) { // responded yet. EXPECT_EQ(recorded_callbacks.size(), 2); EXPECT_EQ(key_calls.size(), 0); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); // The first up event responded with false, which was redispatched, and caused // the down event to be dispatched. @@ -2102,29 +2067,28 @@ TEST(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) { kLogicalKeyA, "a", kNotSynthesized); clear_key_calls(); EXPECT_EQ(recorded_callbacks.size(), 3); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Release A again - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); EXPECT_EQ(key_calls.size(), 0); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); } -TEST(KeyboardTest, TextInputSubmit) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, TextInputSubmit) { + Responding(false); // US Keyboard layout - tester.GetView().HandleMessage( + GetView().HandleMessage( "flutter/textinput", "TextInput.setClient", R"|([108, {"inputAction": "TextInputAction.none"}])|"); // Press Enter - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{VK_RETURN, kScanCodeEnter, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'\n', kScanCodeEnter, kNotExtended, kWasUp}.Build( @@ -2140,10 +2104,10 @@ TEST(KeyboardTest, TextInputSubmit) { R"|("args":[108,"TextInputAction.none"])|" "}"); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release Enter - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{VK_RETURN, kScanCodeEnter, kNotExtended}.Build( kWmResultZero)}); @@ -2151,14 +2115,14 @@ TEST(KeyboardTest, TextInputSubmit) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalEnter, kLogicalEnter, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Make sure OnText is not obstructed after pressing Enter. // // Regression test for https://github.com/flutter/flutter/issues/97706. // Press A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -2171,7 +2135,7 @@ TEST(KeyboardTest, TextInputSubmit) { clear_key_calls(); // Release A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); @@ -2181,7 +2145,7 @@ TEST(KeyboardTest, TextInputSubmit) { clear_key_calls(); } -TEST(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { +TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { // In this test, the user presses the folloing keys: // // Key Current text @@ -2191,13 +2155,12 @@ TEST(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { // // And the Backspace event is responded immediately. - KeyboardTester tester; - tester.Responding(false); + Responding(false); // US Keyboard layout // Press A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -2208,10 +2171,10 @@ TEST(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { kLogicalKeyA, "a", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"a"); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); // Release A - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); @@ -2219,12 +2182,12 @@ TEST(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); // Press F, which is translated to: // // Backspace down, char & up, then VK_PACKET('à'). - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{VK_BACK, kScanCodeBackspace, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{0x8, kScanCodeBackspace, kNotExtended, kWasUp}.Build( @@ -2248,10 +2211,10 @@ TEST(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { // not handled by the framework, while the 'à' message is not redispatched // for being a standalone message. We should resolve this inconsistency. // https://github.com/flutter/flutter/issues/98306 - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 3); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 3); // Release F - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyF, kScanCodeKeyF, kNotExtended, /* overwrite_prev_state_0 */ true} .Build(kWmResultZero)}); @@ -2260,11 +2223,12 @@ TEST(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); } -void VietnameseTelexAddDiacriticWithSlowResponse(bool backspace_response) { - // In this test, the user presses the folloing keys: +void VietnameseTelexAddDiacriticWithSlowResponse(KeyboardTest& tester, + bool backspace_response) { + // In this test, the user presses the following keys: // // Key Current text // =========================== @@ -2272,8 +2236,6 @@ void VietnameseTelexAddDiacriticWithSlowResponse(bool backspace_response) { // F à // // And the Backspace down event is responded slowly with `backspace_response`. - - KeyboardTester tester; tester.Responding(false); // US Keyboard layout @@ -2368,21 +2330,20 @@ void VietnameseTelexAddDiacriticWithSlowResponse(bool backspace_response) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } -TEST(KeyboardTest, VietnameseTelexAddDiacriticWithSlowFalseResponse) { - VietnameseTelexAddDiacriticWithSlowResponse(false); +TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithSlowFalseResponse) { + VietnameseTelexAddDiacriticWithSlowResponse(*this, false); } -TEST(KeyboardTest, VietnameseTelexAddDiacriticWithSlowTrueResponse) { - VietnameseTelexAddDiacriticWithSlowResponse(true); +TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithSlowTrueResponse) { + VietnameseTelexAddDiacriticWithSlowResponse(*this, true); } // Ensure that the scancode-less key events issued by Narrator // when toggling caps lock don't violate assert statements. -TEST(KeyboardTest, DoubleCapsLock) { - KeyboardTester tester; - tester.Responding(false); +TEST_F(KeyboardTest, DoubleCapsLock) { + Responding(false); - tester.InjectKeyboardChanges(std::vector{ + InjectKeyboardChanges(std::vector{ WmKeyDownInfo{VK_CAPITAL, 0, kNotExtended}.Build(), WmKeyUpInfo{VK_CAPITAL, 0, kNotExtended}.Build()}); From f2112c2b737864b9169fa74c390a5f9be1a09482 Mon Sep 17 00:00:00 2001 From: Loic Sharma Date: Fri, 27 Jan 2023 16:50:31 -0800 Subject: [PATCH 2/4] Kick CI From 6404bc7b4ebb99e586d1754c0c9c3f0fc4f390fa Mon Sep 17 00:00:00 2001 From: Loic Sharma Date: Fri, 27 Jan 2023 17:34:07 -0800 Subject: [PATCH 3/4] Second approach --- shell/platform/windows/keyboard_unittests.cc | 580 ++++++++++--------- 1 file changed, 309 insertions(+), 271 deletions(-) diff --git a/shell/platform/windows/keyboard_unittests.cc b/shell/platform/windows/keyboard_unittests.cc index 4baeaa4e52674..ad5ade50afa3b 100644 --- a/shell/platform/windows/keyboard_unittests.cc +++ b/shell/platform/windows/keyboard_unittests.cc @@ -411,12 +411,12 @@ void clear_key_calls() { key_calls.clear(); } -class KeyboardTest : public WindowsTest { +class KeyboardTester { public: using ResponseHandler = std::function; - explicit KeyboardTest() + explicit KeyboardTester(WindowsTestContext& context) : callback_handler_(RespondValue(false)), map_virtual_key_layout_(LayoutDefault) { view_ = std::make_unique( @@ -436,9 +436,9 @@ class KeyboardTest : public WindowsTest { virtual_key, extended ? MAPVK_VK_TO_VSC_EX : MAPVK_VK_TO_VSC); }); view_->SetEngine(GetTestEngine( - [&callback_handler = callback_handler_]( - const FlutterKeyEvent* event, - MockKeyResponseController::ResponseCallback callback) { + context, [&callback_handler = callback_handler_]( + const FlutterKeyEvent* event, + MockKeyResponseController::ResponseCallback callback) { FlutterKeyEvent clone_event = *event; clone_event.character = event->character == nullptr ? nullptr @@ -500,9 +500,10 @@ class KeyboardTest : public WindowsTest { // overridden methods for sending platform messages, so that the engine can // respond as if the framework were connected. std::unique_ptr GetTestEngine( + WindowsTestContext& context, MockKeyResponseController::EmbedderCallbackHandler embedder_callback_handler) { - FlutterWindowsEngineBuilder builder{GetContext()}; + FlutterWindowsEngineBuilder builder{context}; auto engine = builder.Build(); EngineModifier modifier(engine.get()); @@ -537,6 +538,8 @@ class KeyboardTest : public WindowsTest { } }; +class KeyboardTest : public WindowsTest {}; + } // namespace // Define compound `expect` in macros. If they're defined in functions, the @@ -555,12 +558,13 @@ class KeyboardTest : public WindowsTest { EXPECT_STREQ(_key_call.text_method_call.c_str(), json_string); TEST_F(KeyboardTest, LowerCaseAHandled) { - Responding(true); + KeyboardTester tester{GetContext()}; + tester.Responding(true); // US Keyboard layout // Press A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -570,10 +574,10 @@ TEST_F(KeyboardTest, LowerCaseAHandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); // Release A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); @@ -581,16 +585,17 @@ TEST_F(KeyboardTest, LowerCaseAHandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } TEST_F(KeyboardTest, LowerCaseAUnhandled) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -601,10 +606,10 @@ TEST_F(KeyboardTest, LowerCaseAUnhandled) { kLogicalKeyA, "a", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"a"); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); @@ -612,16 +617,17 @@ TEST_F(KeyboardTest, LowerCaseAUnhandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } TEST_F(KeyboardTest, ArrowLeftHandled) { - Responding(true); + KeyboardTester tester{GetContext()}; + tester.Responding(true); // US Keyboard layout // Press ArrowLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{VK_LEFT, kScanCodeArrowLeft, kExtended, kWasUp}.Build( kWmResultZero)}); @@ -630,10 +636,10 @@ TEST_F(KeyboardTest, ArrowLeftHandled) { kPhysicalArrowLeft, kLogicalArrowLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); // Release ArrowLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{VK_LEFT, kScanCodeArrowLeft, kExtended}.Build( kWmResultZero)}); @@ -641,16 +647,17 @@ TEST_F(KeyboardTest, ArrowLeftHandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalArrowLeft, kLogicalArrowLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } TEST_F(KeyboardTest, ArrowLeftUnhandled) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press ArrowLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{VK_LEFT, kScanCodeArrowLeft, kExtended, kWasUp}.Build( kWmResultZero)}); @@ -659,10 +666,10 @@ TEST_F(KeyboardTest, ArrowLeftUnhandled) { kPhysicalArrowLeft, kLogicalArrowLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release ArrowLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{VK_LEFT, kScanCodeArrowLeft, kExtended}.Build( kWmResultZero)}); @@ -670,16 +677,17 @@ TEST_F(KeyboardTest, ArrowLeftUnhandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalArrowLeft, kLogicalArrowLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } TEST_F(KeyboardTest, ShiftLeftUnhandled) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press ShiftLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, true, false}, WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -689,10 +697,10 @@ TEST_F(KeyboardTest, ShiftLeftUnhandled) { kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Hold ShiftLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasDown}.Build( kWmResultZero)}); @@ -701,10 +709,10 @@ TEST_F(KeyboardTest, ShiftLeftUnhandled) { kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release ShiftLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, false, true}, WmKeyUpInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended}.Build( kWmResultZero)}); @@ -713,16 +721,17 @@ TEST_F(KeyboardTest, ShiftLeftUnhandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } TEST_F(KeyboardTest, ShiftRightUnhandled) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press ShiftRight - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RSHIFT, true, false}, WmKeyDownInfo{VK_SHIFT, kScanCodeShiftRight, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -732,10 +741,10 @@ TEST_F(KeyboardTest, ShiftRightUnhandled) { kPhysicalShiftRight, kLogicalShiftRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release ShiftRight - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RSHIFT, false, true}, WmKeyUpInfo{VK_SHIFT, kScanCodeShiftRight, kNotExtended}.Build( kWmResultZero)}); @@ -745,16 +754,17 @@ TEST_F(KeyboardTest, ShiftRightUnhandled) { kPhysicalShiftRight, kLogicalShiftRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } TEST_F(KeyboardTest, CtrlLeftUnhandled) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press CtrlLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, false}, WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -764,10 +774,10 @@ TEST_F(KeyboardTest, CtrlLeftUnhandled) { kPhysicalControlLeft, kLogicalControlLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release CtrlLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, true}, WmKeyUpInfo{VK_SHIFT, kScanCodeControl, kNotExtended}.Build( kWmResultZero)}); @@ -777,16 +787,17 @@ TEST_F(KeyboardTest, CtrlLeftUnhandled) { kPhysicalControlLeft, kLogicalControlLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } TEST_F(KeyboardTest, CtrlRightUnhandled) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press CtrlRight - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RCONTROL, true, false}, WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kExtended, kWasUp}.Build( kWmResultZero)}); @@ -796,10 +807,10 @@ TEST_F(KeyboardTest, CtrlRightUnhandled) { kPhysicalControlRight, kLogicalControlRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release CtrlRight - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RCONTROL, false, true}, WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kExtended}.Build( kWmResultZero)}); @@ -809,16 +820,17 @@ TEST_F(KeyboardTest, CtrlRightUnhandled) { kPhysicalControlRight, kLogicalControlRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } TEST_F(KeyboardTest, AltLeftUnhandled) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press AltLeft. AltLeft is a SysKeyDown event. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LMENU, true, false}, WmSysKeyDownInfo{VK_MENU, kScanCodeAlt, kNotExtended, kWasUp}.Build( kWmResultDefault)}); // Always pass to the default WndProc. @@ -828,10 +840,10 @@ TEST_F(KeyboardTest, AltLeftUnhandled) { kLogicalAltLeft, "", kNotSynthesized); clear_key_calls(); // Don't redispatch sys messages. - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); // Release AltLeft. AltLeft is a SysKeyUp event. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LMENU, false, true}, WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kNotExtended}.Build( kWmResultDefault)}); // Always pass to the default WndProc. @@ -841,16 +853,17 @@ TEST_F(KeyboardTest, AltLeftUnhandled) { kLogicalAltLeft, "", kNotSynthesized); clear_key_calls(); // Don't redispatch sys messages. - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } TEST_F(KeyboardTest, AltRightUnhandled) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press AltRight. AltRight is a SysKeyDown event. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RMENU, true, false}, WmSysKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build( kWmResultDefault)}); // Always pass to the default WndProc. @@ -861,10 +874,10 @@ TEST_F(KeyboardTest, AltRightUnhandled) { kNotSynthesized); clear_key_calls(); // Don't redispatch sys messages. - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); // Release AltRight. AltRight is a SysKeyUp event. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RMENU, false, true}, WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build( kWmResultDefault)}); // Always pass to the default WndProc. @@ -874,16 +887,17 @@ TEST_F(KeyboardTest, AltRightUnhandled) { kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); // Don't redispatch sys messages. - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } TEST_F(KeyboardTest, MetaLeftUnhandled) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press MetaLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LWIN, true, false}, WmKeyDownInfo{VK_LWIN, kScanCodeMetaLeft, kExtended, kWasUp}.Build( kWmResultZero)}); @@ -893,10 +907,10 @@ TEST_F(KeyboardTest, MetaLeftUnhandled) { kPhysicalMetaLeft, kLogicalMetaLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release MetaLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LWIN, false, true}, WmKeyUpInfo{VK_LWIN, kScanCodeMetaLeft, kExtended}.Build(kWmResultZero)}); @@ -904,16 +918,17 @@ TEST_F(KeyboardTest, MetaLeftUnhandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalMetaLeft, kLogicalMetaLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } TEST_F(KeyboardTest, MetaRightUnhandled) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press MetaRight - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RWIN, true, false}, WmKeyDownInfo{VK_RWIN, kScanCodeMetaRight, kExtended, kWasUp}.Build( kWmResultZero)}); @@ -923,10 +938,10 @@ TEST_F(KeyboardTest, MetaRightUnhandled) { kPhysicalMetaRight, kLogicalMetaRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release MetaRight - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RWIN, false, true}, WmKeyUpInfo{VK_RWIN, kScanCodeMetaRight, kExtended}.Build( kWmResultZero)}); @@ -935,18 +950,19 @@ TEST_F(KeyboardTest, MetaRightUnhandled) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalMetaRight, kLogicalMetaRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } // Press Shift-A. This is special because Win32 gives 'A' as character for the // KeyA press. TEST_F(KeyboardTest, ShiftLeftKeyA) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press ShiftLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, true, true}, WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -956,10 +972,10 @@ TEST_F(KeyboardTest, ShiftLeftKeyA) { kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Press A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'A', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -970,10 +986,10 @@ TEST_F(KeyboardTest, ShiftLeftKeyA) { kLogicalKeyA, "A", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"A"); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release ShiftLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, false, true}, WmKeyUpInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended}.Build( kWmResultZero)}); @@ -982,10 +998,10 @@ TEST_F(KeyboardTest, ShiftLeftKeyA) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); @@ -993,18 +1009,19 @@ TEST_F(KeyboardTest, ShiftLeftKeyA) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } // Press Ctrl-A. This is special because Win32 gives 0x01 as character for the // KeyA press. TEST_F(KeyboardTest, CtrlLeftKeyA) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press ControlLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, true}, WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -1014,10 +1031,10 @@ TEST_F(KeyboardTest, CtrlLeftKeyA) { kPhysicalControlLeft, kLogicalControlLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Press A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{0x01, kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -1027,10 +1044,10 @@ TEST_F(KeyboardTest, CtrlLeftKeyA) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); @@ -1038,10 +1055,10 @@ TEST_F(KeyboardTest, CtrlLeftKeyA) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release ControlLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, true}, WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build( kWmResultZero)}); @@ -1051,17 +1068,18 @@ TEST_F(KeyboardTest, CtrlLeftKeyA) { kPhysicalControlLeft, kLogicalControlLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } // Press Ctrl-1. This is special because it yields no WM_CHAR for the 1. TEST_F(KeyboardTest, CtrlLeftDigit1) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout // Press ControlLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, true}, WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -1071,10 +1089,10 @@ TEST_F(KeyboardTest, CtrlLeftDigit1) { kPhysicalControlLeft, kLogicalControlLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Press 1 - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp} .Build(kWmResultZero)}); @@ -1082,10 +1100,10 @@ TEST_F(KeyboardTest, CtrlLeftDigit1) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release 1 - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build( kWmResultZero)}); @@ -1093,10 +1111,10 @@ TEST_F(KeyboardTest, CtrlLeftDigit1) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release ControlLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, true}, WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build( kWmResultZero)}); @@ -1106,18 +1124,19 @@ TEST_F(KeyboardTest, CtrlLeftDigit1) { kPhysicalControlLeft, kLogicalControlLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } // Press 1 on a French keyboard. This is special because it yields WM_CHAR // with char_code '&'. TEST_F(KeyboardTest, Digit1OnFrenchLayout) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); - SetLayout(LayoutFrench); + tester.SetLayout(LayoutFrench); // Press 1 - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp} .Build(kWmResultZero), WmCharInfo{'&', kScanCodeDigit1, kNotExtended, kWasUp}.Build( @@ -1128,10 +1147,10 @@ TEST_F(KeyboardTest, Digit1OnFrenchLayout) { kLogicalDigit1, "&", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"&"); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release 1 - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build( kWmResultZero)}); @@ -1139,17 +1158,18 @@ TEST_F(KeyboardTest, Digit1OnFrenchLayout) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } // This tests AltGr-Q on a German keyboard, which should print '@'. TEST_F(KeyboardTest, AltGrModifiedKey) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // German Keyboard layout // Press AltGr, which Win32 precedes with a ContrlLeft down. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, true}, WmKeyDownInfo{VK_LCONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build( kWmResultZero), @@ -1165,10 +1185,10 @@ TEST_F(KeyboardTest, AltGrModifiedKey) { kPhysicalAltRight, kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Press Q - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyQ, kScanCodeKeyQ, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'@', kScanCodeKeyQ, kNotExtended, kWasUp}.Build( @@ -1179,10 +1199,10 @@ TEST_F(KeyboardTest, AltGrModifiedKey) { kLogicalKeyQ, "@", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"@"); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release Q - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyQ, kScanCodeKeyQ, kNotExtended}.Build( kWmResultZero)}); @@ -1190,12 +1210,12 @@ TEST_F(KeyboardTest, AltGrModifiedKey) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyQ, kLogicalKeyQ, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release AltGr. Win32 doesn't dispatch ControlLeft up. Instead Flutter will // forge one. The AltGr is a system key, therefore will be handled by Win32's // default WndProc. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, true}, ExpectForgedMessage{ WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build( @@ -1212,7 +1232,7 @@ TEST_F(KeyboardTest, AltGrModifiedKey) { kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); // The sys key up must not be redispatched. The forged ControlLeft up will. - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } // Test the following two key sequences at the same time: @@ -1229,13 +1249,14 @@ TEST_F(KeyboardTest, AltGrModifiedKey) { // This is because pressing AltGr alone causes Win32 to send a fake "CtrlLeft // down" event first (see |IsKeyDownAltRight| for detailed explanation). TEST_F(KeyboardTest, AltGrTwice) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // 1. AltGr down. // The key down event causes a ControlLeft down and a AltRight (extended // AltLeft) down. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, true}, WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build( kWmResultZero), @@ -1251,12 +1272,12 @@ TEST_F(KeyboardTest, AltGrTwice) { kPhysicalAltRight, kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // 2. AltGr up. // The key up event only causes a AltRight (extended AltLeft) up. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, true}, ExpectForgedMessage{ WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build( @@ -1272,11 +1293,11 @@ TEST_F(KeyboardTest, AltGrTwice) { kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); // The sys key up must not be redispatched. The forged ControlLeft up will. - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // 3. AltGr down (or: ControlLeft down then AltRight down.) - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, false}, WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build( kWmResultZero), @@ -1292,12 +1313,12 @@ TEST_F(KeyboardTest, AltGrTwice) { kPhysicalAltRight, kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // 4. AltGr up. // The key up event only causes a AltRight (extended AltLeft) up. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, false}, ExpectForgedMessage{ WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build( @@ -1313,28 +1334,29 @@ TEST_F(KeyboardTest, AltGrTwice) { kLogicalAltRight, "", kNotSynthesized); clear_key_calls(); // The sys key up must not be redispatched. The forged ControlLeft up will. - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // 5. For key sequence 2: a real ControlLeft up. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build( kWmResultZero)}); EXPECT_EQ(key_calls.size(), 1); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } // This tests dead key ^ then E on a French keyboard, which should be combined // into ê. TEST_F(KeyboardTest, DeadKeyThatCombines) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); - SetLayout(LayoutFrench); + tester.SetLayout(LayoutFrench); // Press ^¨ (US: Left bracket) - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{0xDD, kScanCodeBracketLeft, kNotExtended, kWasUp}.Build( kWmResultZero), WmDeadCharInfo{'^', kScanCodeBracketLeft, kNotExtended, kWasUp}.Build( @@ -1345,10 +1367,10 @@ TEST_F(KeyboardTest, DeadKeyThatCombines) { kPhysicalBracketLeft, kLogicalBracketRight, "^", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release ^¨ - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{0xDD, kScanCodeBracketLeft, kNotExtended}.Build( kWmResultZero)}); @@ -1357,10 +1379,10 @@ TEST_F(KeyboardTest, DeadKeyThatCombines) { kPhysicalBracketLeft, kLogicalBracketRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Press E - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{0xEA, kScanCodeKeyE, kNotExtended, kWasUp}.Build( @@ -1371,10 +1393,10 @@ TEST_F(KeyboardTest, DeadKeyThatCombines) { kLogicalKeyE, "ê", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"ê"); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release E - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended}.Build( kWmResultZero)}); @@ -1382,7 +1404,7 @@ TEST_F(KeyboardTest, DeadKeyThatCombines) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyE, kLogicalKeyE, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } // This tests dead key ^ then E on a US INTL keyboard, which should be combined @@ -1391,10 +1413,11 @@ TEST_F(KeyboardTest, DeadKeyThatCombines) { // It is different from French AZERTY because the character that the ^ key is // mapped to does not contain the dead key character somehow. TEST_F(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // Press ShiftLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, true, true}, WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build( kWmResultZero)}); @@ -1404,10 +1427,10 @@ TEST_F(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Press 6^ - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{'6', kScanCodeDigit6, kNotExtended, kWasUp}.Build( kWmResultZero), WmDeadCharInfo{'^', kScanCodeDigit6, kNotExtended, kWasUp}.Build( @@ -1417,20 +1440,20 @@ TEST_F(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalDigit6, kLogicalDigit6, "6", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release 6^ - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{'6', kScanCodeDigit6, kNotExtended}.Build(kWmResultZero)}); EXPECT_EQ(key_calls.size(), 1); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalDigit6, kLogicalDigit6, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release ShiftLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, false, true}, WmKeyUpInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended}.Build( kWmResultZero)}); @@ -1439,10 +1462,10 @@ TEST_F(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalShiftLeft, kLogicalShiftLeft, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Press E - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{0xEA, kScanCodeKeyE, kNotExtended, kWasUp}.Build( @@ -1453,10 +1476,10 @@ TEST_F(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { kLogicalKeyE, "ê", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"ê"); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release E - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended}.Build( kWmResultZero)}); @@ -1464,18 +1487,19 @@ TEST_F(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyE, kLogicalKeyE, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } // This tests dead key ^ then & (US: 1) on a French keyboard, which do not // combine and should output "^&". TEST_F(KeyboardTest, DeadKeyThatDoesNotCombine) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); - SetLayout(LayoutFrench); + tester.SetLayout(LayoutFrench); // Press ^¨ (US: Left bracket) - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{0xDD, kScanCodeBracketLeft, kNotExtended, kWasUp}.Build( kWmResultZero), WmDeadCharInfo{'^', kScanCodeBracketLeft, kNotExtended, kWasUp}.Build( @@ -1486,10 +1510,10 @@ TEST_F(KeyboardTest, DeadKeyThatDoesNotCombine) { kPhysicalBracketLeft, kLogicalBracketRight, "^", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release ^¨ - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{0xDD, kScanCodeBracketLeft, kNotExtended}.Build( kWmResultZero)}); @@ -1498,10 +1522,10 @@ TEST_F(KeyboardTest, DeadKeyThatDoesNotCombine) { kPhysicalBracketLeft, kLogicalBracketRight, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Press 1 - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp} .Build(kWmResultZero), WmCharInfo{'^', kScanCodeDigit1, kNotExtended, kWasUp}.Build( @@ -1520,10 +1544,10 @@ TEST_F(KeyboardTest, DeadKeyThatDoesNotCombine) { // not handled by the framework, while the '&' message is not redispatched // for being a standalone message. We should resolve this inconsistency. // https://github.com/flutter/flutter/issues/98306 - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release 1 - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build( kWmResultZero)}); @@ -1531,19 +1555,20 @@ TEST_F(KeyboardTest, DeadKeyThatDoesNotCombine) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } // This tests dead key `, then dead key `, then e. // // It should output ``e, instead of `è. TEST_F(KeyboardTest, DeadKeyTwiceThenLetter) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US INTL layout. // Press ` - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{0xC0, kScanCodeBackquote, kNotExtended, kWasUp}.Build( kWmResultZero), WmDeadCharInfo{'`', kScanCodeBackquote, kNotExtended, kWasUp}.Build( @@ -1554,10 +1579,10 @@ TEST_F(KeyboardTest, DeadKeyTwiceThenLetter) { kPhysicalBackquote, kLogicalBackquote, "`", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release ` - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{0xC0, kScanCodeBackquote, kNotExtended}.Build( kWmResultZero)}); @@ -1565,18 +1590,19 @@ TEST_F(KeyboardTest, DeadKeyTwiceThenLetter) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalBackquote, kLogicalBackquote, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Press ` again. // The response should be slow. std::vector recorded_callbacks; - LateResponding([&recorded_callbacks]( - const FlutterKeyEvent* event, - MockKeyResponseController::ResponseCallback callback) { - recorded_callbacks.push_back(callback); - }); + tester.LateResponding( + [&recorded_callbacks]( + const FlutterKeyEvent* event, + MockKeyResponseController::ResponseCallback callback) { + recorded_callbacks.push_back(callback); + }); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{0xC0, kScanCodeBackquote, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'`', kScanCodeBackquote, kNotExtended, kWasUp, kBeingReleased, @@ -1600,12 +1626,12 @@ TEST_F(KeyboardTest, DeadKeyTwiceThenLetter) { // TODO(dkwingsmt): This count should probably be 3. See the comment above // that is marked with the same issue. // https://github.com/flutter/flutter/issues/98306 - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); - Responding(false); + tester.Responding(false); // Release ` - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{0xC0, kScanCodeBackquote, kNotExtended}.Build( kWmResultZero)}); @@ -1613,18 +1639,19 @@ TEST_F(KeyboardTest, DeadKeyTwiceThenLetter) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalBackquote, kLogicalBackquote, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } // This tests when the resulting character needs to be combined with surrogates. TEST_F(KeyboardTest, MultibyteCharacter) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // Gothic Keyboard layout. (We need a layout that yields non-BMP characters // without IME, which is actually very rare.) // Press key W of a US keyboard, which should yield character '𐍅'. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyW, kScanCodeKeyW, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{0xd800, kScanCodeKeyW, kNotExtended, kWasUp}.Build( @@ -1639,10 +1666,10 @@ TEST_F(KeyboardTest, MultibyteCharacter) { kLogicalKeyW, "𐍅", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"𐍅"); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 3); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 3); // Release W - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyW, kScanCodeKeyW, kNotExtended}.Build( kWmResultZero)}); @@ -1650,11 +1677,12 @@ TEST_F(KeyboardTest, MultibyteCharacter) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyW, kLogicalKeyW, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } TEST_F(KeyboardTest, SynthesizeModifiers) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // Two dummy events used to trigger synthesization. Win32Message event1 = @@ -1665,150 +1693,150 @@ TEST_F(KeyboardTest, SynthesizeModifiers) { kWmResultZero); // ShiftLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalShiftLeft, kLogicalShiftLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalShiftLeft, kLogicalShiftLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // ShiftRight - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RSHIFT, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalShiftRight, kLogicalShiftRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RSHIFT, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalShiftRight, kLogicalShiftRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // ControlLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalControlLeft, kLogicalControlLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LCONTROL, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalControlLeft, kLogicalControlLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // ControlRight - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RCONTROL, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalControlRight, kLogicalControlRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RCONTROL, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalControlRight, kLogicalControlRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // AltLeft - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LMENU, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalAltLeft, kLogicalAltLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LMENU, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalAltLeft, kLogicalAltLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // AltRight - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RMENU, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalAltRight, kLogicalAltRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RMENU, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalAltRight, kLogicalAltRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // MetaLeft - InjectKeyboardChanges( + tester.InjectKeyboardChanges( std::vector{KeyStateChange{VK_LWIN, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalMetaLeft, kLogicalMetaLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LWIN, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalMetaLeft, kLogicalMetaLeft, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // MetaRight - InjectKeyboardChanges( + tester.InjectKeyboardChanges( std::vector{KeyStateChange{VK_RWIN, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalMetaRight, kLogicalMetaRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RWIN, false, true}, event2}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalMetaRight, kLogicalMetaRight, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // CapsLock, phase 0 -> 2 -> 0. // (For phases, see |SynchronizeCriticalToggledStates|.) - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_CAPITAL, false, true}, event1}); EXPECT_EQ(key_calls.size(), 3); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, @@ -1816,9 +1844,9 @@ TEST_F(KeyboardTest, SynthesizeModifiers) { EXPECT_CALL_IS_EVENT(key_calls[1], kFlutterKeyEventTypeUp, kPhysicalCapsLock, kLogicalCapsLock, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_CAPITAL, false, false}, event2}); EXPECT_EQ(key_calls.size(), 3); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, @@ -1826,19 +1854,19 @@ TEST_F(KeyboardTest, SynthesizeModifiers) { EXPECT_CALL_IS_EVENT(key_calls[1], kFlutterKeyEventTypeUp, kPhysicalCapsLock, kLogicalCapsLock, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // ScrollLock, phase 0 -> 1 -> 3 - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_SCROLL, true, true}, event1}); EXPECT_EQ(key_calls.size(), 2); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalScrollLock, kLogicalScrollLock, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_SCROLL, true, false}, event2}); EXPECT_EQ(key_calls.size(), 3); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, @@ -1848,10 +1876,10 @@ TEST_F(KeyboardTest, SynthesizeModifiers) { kPhysicalScrollLock, kLogicalScrollLock, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // NumLock, phase 0 -> 3 -> 2 - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_NUMLOCK, true, false}, event1}); // TODO(dkwingsmt): Synthesizing from phase 0 to 3 should yield a full key // tap and a key down. Fix the algorithm so that the following result becomes @@ -1861,9 +1889,9 @@ TEST_F(KeyboardTest, SynthesizeModifiers) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalNumLock, kLogicalNumLock, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_NUMLOCK, false, true}, event2}); EXPECT_EQ(key_calls.size(), 4); EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalNumLock, @@ -1873,7 +1901,7 @@ TEST_F(KeyboardTest, SynthesizeModifiers) { EXPECT_CALL_IS_EVENT(key_calls[2], kFlutterKeyEventTypeUp, kPhysicalNumLock, kLogicalNumLock, "", kSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } // Pressing extended keys during IME events should work properly by not sending @@ -1881,7 +1909,8 @@ TEST_F(KeyboardTest, SynthesizeModifiers) { // // Regression test for https://github.com/flutter/flutter/issues/95888 . TEST_F(KeyboardTest, ImeExtendedEventsAreIgnored) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout. @@ -1889,7 +1918,7 @@ TEST_F(KeyboardTest, ImeExtendedEventsAreIgnored) { // Omit them in this test since they are not relavent. // Press CtrlRight in IME mode. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_RCONTROL, true, false}, WmKeyDownInfo{VK_PROCESSKEY, kScanCodeControl, kExtended, kWasUp}.Build( kWmResultZero)}); @@ -1898,7 +1927,7 @@ TEST_F(KeyboardTest, ImeExtendedEventsAreIgnored) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } // Ensures that synthesization works correctly when a Shift key is pressed and @@ -1908,12 +1937,13 @@ TEST_F(KeyboardTest, ImeExtendedEventsAreIgnored) { // are real messages recorded when pressing Shift-2 using Microsoft Pinyin IME // on Win 10 Enterprise, which crashed the app before the fix. TEST_F(KeyboardTest, UpOnlyImeEventsAreCorrectlyHandled) { - Responding(true); + KeyboardTester tester{GetContext()}; + tester.Responding(true); // US Keyboard layout. // Press CtrlRight in IME mode. - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ KeyStateChange{VK_LSHIFT, true, false}, WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build( kWmResultZero), @@ -1945,24 +1975,26 @@ TEST_F(KeyboardTest, UpOnlyImeEventsAreCorrectlyHandled) { // identical hash as the one waiting for response, an earlier implementation // will crash upon the response. TEST_F(KeyboardTest, SlowFrameworkResponse) { + KeyboardTester tester{GetContext()}; std::vector recorded_callbacks; // Store callbacks to manually call them. - LateResponding([&recorded_callbacks]( - const FlutterKeyEvent* event, - MockKeyResponseController::ResponseCallback callback) { - recorded_callbacks.push_back(callback); - }); + tester.LateResponding( + [&recorded_callbacks]( + const FlutterKeyEvent* event, + MockKeyResponseController::ResponseCallback callback) { + recorded_callbacks.push_back(callback); + }); // Press A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero)}); // Hold A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasDown}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasDown}.Build( @@ -1972,7 +2004,7 @@ TEST_F(KeyboardTest, SlowFrameworkResponse) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized); EXPECT_EQ(recorded_callbacks.size(), 1); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); // The first response. recorded_callbacks.front()(false); @@ -1982,7 +2014,7 @@ TEST_F(KeyboardTest, SlowFrameworkResponse) { EXPECT_CALL_IS_TEXT(key_calls[1], u"a"); EXPECT_CALL_IS_EVENT(key_calls[2], kFlutterKeyEventTypeRepeat, kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // The second response. recorded_callbacks.back()(false); @@ -1990,7 +2022,7 @@ TEST_F(KeyboardTest, SlowFrameworkResponse) { EXPECT_EQ(key_calls.size(), 4); EXPECT_CALL_IS_TEXT(key_calls[3], u"a"); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); } // Regression test for https://github.com/flutter/flutter/issues/84210. @@ -2005,17 +2037,19 @@ TEST_F(KeyboardTest, SlowFrameworkResponse) { // // The code must not take the 2nd real key down events as a redispatched event. TEST_F(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) { + KeyboardTester tester{GetContext()}; std::vector recorded_callbacks; // Store callbacks to manually call them. - LateResponding([&recorded_callbacks]( - const FlutterKeyEvent* event, - MockKeyResponseController::ResponseCallback callback) { - recorded_callbacks.push_back(callback); - }); + tester.LateResponding( + [&recorded_callbacks]( + const FlutterKeyEvent* event, + MockKeyResponseController::ResponseCallback callback) { + recorded_callbacks.push_back(callback); + }); // Press A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -2025,15 +2059,15 @@ TEST_F(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); // Release A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); EXPECT_EQ(key_calls.size(), 0); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); // The first down event responded with false. EXPECT_EQ(recorded_callbacks.size(), 1); @@ -2044,10 +2078,10 @@ TEST_F(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) { EXPECT_CALL_IS_EVENT(key_calls[1], kFlutterKeyEventTypeUp, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Press A again - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -2057,7 +2091,7 @@ TEST_F(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) { // responded yet. EXPECT_EQ(recorded_callbacks.size(), 2); EXPECT_EQ(key_calls.size(), 0); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); // The first up event responded with false, which was redispatched, and caused // the down event to be dispatched. @@ -2067,28 +2101,29 @@ TEST_F(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) { kLogicalKeyA, "a", kNotSynthesized); clear_key_calls(); EXPECT_EQ(recorded_callbacks.size(), 3); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Release A again - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); EXPECT_EQ(key_calls.size(), 0); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } TEST_F(KeyboardTest, TextInputSubmit) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); // US Keyboard layout - GetView().HandleMessage( + tester.GetView().HandleMessage( "flutter/textinput", "TextInput.setClient", R"|([108, {"inputAction": "TextInputAction.none"}])|"); // Press Enter - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{VK_RETURN, kScanCodeEnter, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'\n', kScanCodeEnter, kNotExtended, kWasUp}.Build( @@ -2104,10 +2139,10 @@ TEST_F(KeyboardTest, TextInputSubmit) { R"|("args":[108,"TextInputAction.none"])|" "}"); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release Enter - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{VK_RETURN, kScanCodeEnter, kNotExtended}.Build( kWmResultZero)}); @@ -2115,14 +2150,14 @@ TEST_F(KeyboardTest, TextInputSubmit) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalEnter, kLogicalEnter, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Make sure OnText is not obstructed after pressing Enter. // // Regression test for https://github.com/flutter/flutter/issues/97706. // Press A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -2135,7 +2170,7 @@ TEST_F(KeyboardTest, TextInputSubmit) { clear_key_calls(); // Release A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); @@ -2146,6 +2181,7 @@ TEST_F(KeyboardTest, TextInputSubmit) { } TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { + KeyboardTester tester{GetContext()}; // In this test, the user presses the folloing keys: // // Key Current text @@ -2155,12 +2191,12 @@ TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { // // And the Backspace event is responded immediately. - Responding(false); + tester.Responding(false); // US Keyboard layout // Press A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build( @@ -2171,10 +2207,10 @@ TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { kLogicalKeyA, "a", kNotSynthesized); EXPECT_CALL_IS_TEXT(key_calls[1], u"a"); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 2); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2); // Release A - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build( kWmResultZero)}); @@ -2182,12 +2218,12 @@ TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 1); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); // Press F, which is translated to: // // Backspace down, char & up, then VK_PACKET('à'). - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{VK_BACK, kScanCodeBackspace, kNotExtended, kWasUp}.Build( kWmResultZero), WmCharInfo{0x8, kScanCodeBackspace, kNotExtended, kWasUp}.Build( @@ -2211,10 +2247,10 @@ TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { // not handled by the framework, while the 'à' message is not redispatched // for being a standalone message. We should resolve this inconsistency. // https://github.com/flutter/flutter/issues/98306 - EXPECT_EQ(RedispatchedMessageCountAndClear(), 3); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 3); // Release F - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyUpInfo{kVirtualKeyF, kScanCodeKeyF, kNotExtended, /* overwrite_prev_state_0 */ true} .Build(kWmResultZero)}); @@ -2223,11 +2259,12 @@ TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "", kNotSynthesized); clear_key_calls(); - EXPECT_EQ(RedispatchedMessageCountAndClear(), 0); + EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } -void VietnameseTelexAddDiacriticWithSlowResponse(KeyboardTest& tester, +void VietnameseTelexAddDiacriticWithSlowResponse(WindowsTestContext& context, bool backspace_response) { + KeyboardTester tester{context}; // In this test, the user presses the following keys: // // Key Current text @@ -2331,19 +2368,20 @@ void VietnameseTelexAddDiacriticWithSlowResponse(KeyboardTest& tester, } TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithSlowFalseResponse) { - VietnameseTelexAddDiacriticWithSlowResponse(*this, false); + VietnameseTelexAddDiacriticWithSlowResponse(GetContext(), false); } TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithSlowTrueResponse) { - VietnameseTelexAddDiacriticWithSlowResponse(*this, true); + VietnameseTelexAddDiacriticWithSlowResponse(GetContext(), true); } // Ensure that the scancode-less key events issued by Narrator // when toggling caps lock don't violate assert statements. TEST_F(KeyboardTest, DoubleCapsLock) { - Responding(false); + KeyboardTester tester{GetContext()}; + tester.Responding(false); - InjectKeyboardChanges(std::vector{ + tester.InjectKeyboardChanges(std::vector{ WmKeyDownInfo{VK_CAPITAL, 0, kNotExtended}.Build(), WmKeyUpInfo{VK_CAPITAL, 0, kNotExtended}.Build()}); From 2a44465ab97f87850fedcbc3d331a049928e6117 Mon Sep 17 00:00:00 2001 From: Loic Sharma Date: Fri, 27 Jan 2023 17:36:50 -0800 Subject: [PATCH 4/4] Undo unnecessary changes --- shell/platform/windows/keyboard_unittests.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/shell/platform/windows/keyboard_unittests.cc b/shell/platform/windows/keyboard_unittests.cc index ad5ade50afa3b..351b56be39f2a 100644 --- a/shell/platform/windows/keyboard_unittests.cc +++ b/shell/platform/windows/keyboard_unittests.cc @@ -262,7 +262,7 @@ class MockKeyboardManagerDelegate : public KeyboardManager::WindowDelegate, } // This method is called for each message injected by test cases with - // `InjectMessages`. + // `tester.InjectMessages`. LRESULT Win32SendMessage(UINT const message, WPARAM const wparam, LPARAM const lparam) override { @@ -1976,6 +1976,7 @@ TEST_F(KeyboardTest, UpOnlyImeEventsAreCorrectlyHandled) { // will crash upon the response. TEST_F(KeyboardTest, SlowFrameworkResponse) { KeyboardTester tester{GetContext()}; + std::vector recorded_callbacks; // Store callbacks to manually call them. @@ -2181,7 +2182,6 @@ TEST_F(KeyboardTest, TextInputSubmit) { } TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { - KeyboardTester tester{GetContext()}; // In this test, the user presses the folloing keys: // // Key Current text @@ -2191,6 +2191,7 @@ TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { // // And the Backspace event is responded immediately. + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -2264,7 +2265,6 @@ TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { void VietnameseTelexAddDiacriticWithSlowResponse(WindowsTestContext& context, bool backspace_response) { - KeyboardTester tester{context}; // In this test, the user presses the following keys: // // Key Current text @@ -2273,6 +2273,8 @@ void VietnameseTelexAddDiacriticWithSlowResponse(WindowsTestContext& context, // F à // // And the Backspace down event is responded slowly with `backspace_response`. + + KeyboardTester tester{context}; tester.Responding(false); // US Keyboard layout