From 033514b3d9eae90cdda17db70c651f6065c36ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Sharma?= <737941+loic-sharma@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:16:37 -0800 Subject: [PATCH 1/2] [Windows] Remove dead code from FlutterWindow tests (#39216) --- .../windows/flutter_window_unittests.cc | 141 +----------------- 1 file changed, 5 insertions(+), 136 deletions(-) diff --git a/shell/platform/windows/flutter_window_unittests.cc b/shell/platform/windows/flutter_window_unittests.cc index 99c612db87671..15b79db02b627 100644 --- a/shell/platform/windows/flutter_window_unittests.cc +++ b/shell/platform/windows/flutter_window_unittests.cc @@ -2,25 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/shell/platform/common/json_message_codec.h" -#include "flutter/shell/platform/embedder/embedder.h" -#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h" -#include "flutter/shell/platform/windows/flutter_windows_engine.h" -#include "flutter/shell/platform/windows/keyboard_key_channel_handler.h" -#include "flutter/shell/platform/windows/keyboard_key_handler.h" -#include "flutter/shell/platform/windows/testing/engine_modifier.h" #include "flutter/shell/platform/windows/testing/flutter_window_test.h" #include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h" #include "flutter/shell/platform/windows/testing/mock_window_binding_handler_delegate.h" -#include "flutter/shell/platform/windows/testing/test_keyboard.h" -#include "flutter/shell/platform/windows/text_input_plugin.h" -#include "flutter/shell/platform/windows/text_input_plugin_delegate.h" +#include "flutter/shell/platform/windows/testing/wm_builders.h" #include "gmock/gmock.h" #include "gtest/gtest.h" -#include - using testing::_; using testing::Invoke; using testing::Return; @@ -31,74 +20,6 @@ namespace testing { namespace { static constexpr int32_t kDefaultPointerDeviceId = 0; -// A key event handler that can be spied on while it forwards calls to the real -// key event handler. -class SpyKeyboardKeyHandler : public KeyboardHandlerBase { - public: - SpyKeyboardKeyHandler(flutter::BinaryMessenger* messenger) { - real_implementation_ = std::make_unique(); - real_implementation_->AddDelegate( - std::make_unique(messenger)); - ON_CALL(*this, KeyboardHook(_, _, _, _, _, _, _)) - .WillByDefault(Invoke(real_implementation_.get(), - &KeyboardKeyHandler::KeyboardHook)); - ON_CALL(*this, SyncModifiersIfNeeded(_)) - .WillByDefault(Invoke(real_implementation_.get(), - &KeyboardKeyHandler::SyncModifiersIfNeeded)); - } - - MOCK_METHOD7(KeyboardHook, - void(int key, - int scancode, - int action, - char32_t character, - bool extended, - bool was_down, - KeyEventCallback callback)); - - MOCK_METHOD1(SyncModifiersIfNeeded, void(int modifiers_state)); - - private: - std::unique_ptr real_implementation_; -}; - -// A text input plugin that can be spied on while it forwards calls to the real -// text input plugin. -class SpyTextInputPlugin : public TextInputPlugin, - public TextInputPluginDelegate { - public: - SpyTextInputPlugin(flutter::BinaryMessenger* messenger) - : TextInputPlugin(messenger, this) { - real_implementation_ = std::make_unique(messenger, this); - ON_CALL(*this, KeyboardHook(_, _, _, _, _, _)) - .WillByDefault( - Invoke(real_implementation_.get(), &TextInputPlugin::KeyboardHook)); - ON_CALL(*this, TextHook(_)) - .WillByDefault( - Invoke(real_implementation_.get(), &TextInputPlugin::TextHook)); - } - - MOCK_METHOD6(KeyboardHook, - void(int key, - int scancode, - int action, - char32_t character, - bool extended, - bool was_down)); - MOCK_METHOD1(TextHook, void(const std::u16string& text)); - MOCK_METHOD0(ComposeBeginHook, void()); - MOCK_METHOD0(ComposeCommitHook, void()); - MOCK_METHOD0(ComposeEndHook, void()); - MOCK_METHOD2(ComposeChangeHook, - void(const std::u16string& text, int cursor_pos)); - - virtual void OnCursorRectUpdated(const Rect& rect) {} - virtual void OnResetImeComposing() {} - - private: - std::unique_ptr real_implementation_; -}; - class MockFlutterWindow : public FlutterWindow { public: MockFlutterWindow() : FlutterWindow(800, 600) { @@ -154,68 +75,16 @@ class MockFlutterWindow : public FlutterWindow { } }; -// A FlutterWindowsView that overrides the RegisterKeyboardHandlers function -// to register the keyboard hook handlers that can be spied upon. -class TestFlutterWindowsView : public FlutterWindowsView { +class MockFlutterWindowsView : public FlutterWindowsView { public: - TestFlutterWindowsView(std::unique_ptr window_binding) + MockFlutterWindowsView(std::unique_ptr window_binding) : FlutterWindowsView(std::move(window_binding)) {} - ~TestFlutterWindowsView() {} - - SpyKeyboardKeyHandler* key_event_handler; - SpyTextInputPlugin* text_input_plugin; + ~MockFlutterWindowsView() {} MOCK_METHOD2(NotifyWinEventWrapper, void(ui::AXPlatformNodeWin*, ax::mojom::Event)); - - protected: - std::unique_ptr CreateKeyboardKeyHandler( - flutter::BinaryMessenger* messenger, - flutter::KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state, - KeyboardKeyEmbedderHandler::MapVirtualKeyToScanCode map_vk_to_scan) - override { - auto spy_key_event_handler = - std::make_unique(messenger); - key_event_handler = spy_key_event_handler.get(); - return spy_key_event_handler; - } - - std::unique_ptr CreateTextInputPlugin( - flutter::BinaryMessenger* messenger) override { - auto spy_key_event_handler = - std::make_unique(messenger); - text_input_plugin = spy_key_event_handler.get(); - return spy_key_event_handler; - } }; -// The static value to return as the "handled" value from the framework for key -// events. Individual tests set this to change the framework response that the -// test engine simulates. -static bool test_response = false; - -// 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. -std::unique_ptr GetTestEngine() { - 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); - - EngineModifier modifier(engine.get()); - auto key_response_controller = std::make_shared(); - key_response_controller->SetChannelResponse( - [](MockKeyResponseController::ResponseCallback callback) { - callback(test_response); - }); - MockEmbedderApiForKeyboard(modifier, key_response_controller); - - return engine; -} - } // namespace TEST(FlutterWindowTest, CreateDestroy) { @@ -419,7 +288,7 @@ TEST(FlutterWindowTest, AlertNode) { ON_CALL(*win32window, GetPlatformWindow()).WillByDefault(Return(nullptr)); ON_CALL(*win32window, GetAxFragmentRootDelegate()) .WillByDefault(Return(nullptr)); - TestFlutterWindowsView view(std::move(win32window)); + MockFlutterWindowsView view(std::move(win32window)); std::wstring message = L"Test alert"; EXPECT_CALL(view, NotifyWinEventWrapper(_, ax::mojom::Event::kAlert)) .Times(1); From daa8eeb7fc0babc173af819e9bcae650236dc5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Sharma?= <737941+loic-sharma@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:19:32 -0800 Subject: [PATCH 2/2] [Windows] Use 'FlutterWindowsEngineBuilder' in keyboard unit tests (#39209) * [Windows] Refactor the keyboard unit tests * Kick CI * Second approach * Undo unnecessary changes --- shell/platform/windows/keyboard_unittests.cc | 163 ++++++++++--------- 1 file changed, 82 insertions(+), 81 deletions(-) diff --git a/shell/platform/windows/keyboard_unittests.cc b/shell/platform/windows/keyboard_unittests.cc index 30aeb3192a766..351b56be39f2a 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" @@ -414,7 +416,7 @@ class KeyboardTester { using ResponseHandler = std::function; - explicit KeyboardTester() + explicit KeyboardTester(WindowsTestContext& context) : callback_handler_(RespondValue(false)), map_virtual_key_layout_(LayoutDefault) { view_ = std::make_unique( @@ -434,9 +436,9 @@ class KeyboardTester { 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 @@ -497,15 +499,12 @@ 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( + WindowsTestContext& context, 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{context}; + auto engine = builder.Build(); EngineModifier modifier(engine.get()); @@ -539,6 +538,8 @@ class KeyboardTester { } }; +class KeyboardTest : public WindowsTest {}; + } // namespace // Define compound `expect` in macros. If they're defined in functions, the @@ -556,8 +557,8 @@ 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; +TEST_F(KeyboardTest, LowerCaseAHandled) { + KeyboardTester tester{GetContext()}; tester.Responding(true); // US Keyboard layout @@ -587,8 +588,8 @@ TEST(KeyboardTest, LowerCaseAHandled) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } -TEST(KeyboardTest, LowerCaseAUnhandled) { - KeyboardTester tester; +TEST_F(KeyboardTest, LowerCaseAUnhandled) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -619,8 +620,8 @@ TEST(KeyboardTest, LowerCaseAUnhandled) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, ArrowLeftHandled) { - KeyboardTester tester; +TEST_F(KeyboardTest, ArrowLeftHandled) { + KeyboardTester tester{GetContext()}; tester.Responding(true); // US Keyboard layout @@ -649,8 +650,8 @@ TEST(KeyboardTest, ArrowLeftHandled) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } -TEST(KeyboardTest, ArrowLeftUnhandled) { - KeyboardTester tester; +TEST_F(KeyboardTest, ArrowLeftUnhandled) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -679,8 +680,8 @@ TEST(KeyboardTest, ArrowLeftUnhandled) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, ShiftLeftUnhandled) { - KeyboardTester tester; +TEST_F(KeyboardTest, ShiftLeftUnhandled) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -723,8 +724,8 @@ TEST(KeyboardTest, ShiftLeftUnhandled) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, ShiftRightUnhandled) { - KeyboardTester tester; +TEST_F(KeyboardTest, ShiftRightUnhandled) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -756,8 +757,8 @@ TEST(KeyboardTest, ShiftRightUnhandled) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, CtrlLeftUnhandled) { - KeyboardTester tester; +TEST_F(KeyboardTest, CtrlLeftUnhandled) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -789,8 +790,8 @@ TEST(KeyboardTest, CtrlLeftUnhandled) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, CtrlRightUnhandled) { - KeyboardTester tester; +TEST_F(KeyboardTest, CtrlRightUnhandled) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -822,8 +823,8 @@ TEST(KeyboardTest, CtrlRightUnhandled) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, AltLeftUnhandled) { - KeyboardTester tester; +TEST_F(KeyboardTest, AltLeftUnhandled) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -855,8 +856,8 @@ TEST(KeyboardTest, AltLeftUnhandled) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } -TEST(KeyboardTest, AltRightUnhandled) { - KeyboardTester tester; +TEST_F(KeyboardTest, AltRightUnhandled) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -889,8 +890,8 @@ TEST(KeyboardTest, AltRightUnhandled) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } -TEST(KeyboardTest, MetaLeftUnhandled) { - KeyboardTester tester; +TEST_F(KeyboardTest, MetaLeftUnhandled) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -920,8 +921,8 @@ TEST(KeyboardTest, MetaLeftUnhandled) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, MetaRightUnhandled) { - KeyboardTester tester; +TEST_F(KeyboardTest, MetaRightUnhandled) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -954,8 +955,8 @@ TEST(KeyboardTest, MetaRightUnhandled) { // Press Shift-A. This is special because Win32 gives 'A' as character for the // KeyA press. -TEST(KeyboardTest, ShiftLeftKeyA) { - KeyboardTester tester; +TEST_F(KeyboardTest, ShiftLeftKeyA) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -1013,8 +1014,8 @@ TEST(KeyboardTest, ShiftLeftKeyA) { // Press Ctrl-A. This is special because Win32 gives 0x01 as character for the // KeyA press. -TEST(KeyboardTest, CtrlLeftKeyA) { - KeyboardTester tester; +TEST_F(KeyboardTest, CtrlLeftKeyA) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -1071,8 +1072,8 @@ TEST(KeyboardTest, CtrlLeftKeyA) { } // Press Ctrl-1. This is special because it yields no WM_CHAR for the 1. -TEST(KeyboardTest, CtrlLeftDigit1) { - KeyboardTester tester; +TEST_F(KeyboardTest, CtrlLeftDigit1) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -1128,8 +1129,8 @@ TEST(KeyboardTest, CtrlLeftDigit1) { // Press 1 on a French keyboard. This is special because it yields WM_CHAR // with char_code '&'. -TEST(KeyboardTest, Digit1OnFrenchLayout) { - KeyboardTester tester; +TEST_F(KeyboardTest, Digit1OnFrenchLayout) { + KeyboardTester tester{GetContext()}; tester.Responding(false); tester.SetLayout(LayoutFrench); @@ -1161,8 +1162,8 @@ TEST(KeyboardTest, Digit1OnFrenchLayout) { } // This tests AltGr-Q on a German keyboard, which should print '@'. -TEST(KeyboardTest, AltGrModifiedKey) { - KeyboardTester tester; +TEST_F(KeyboardTest, AltGrModifiedKey) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // German Keyboard layout @@ -1247,8 +1248,8 @@ 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; +TEST_F(KeyboardTest, AltGrTwice) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // 1. AltGr down. @@ -1348,8 +1349,8 @@ TEST(KeyboardTest, AltGrTwice) { // This tests dead key ^ then E on a French keyboard, which should be combined // into ê. -TEST(KeyboardTest, DeadKeyThatCombines) { - KeyboardTester tester; +TEST_F(KeyboardTest, DeadKeyThatCombines) { + KeyboardTester tester{GetContext()}; tester.Responding(false); tester.SetLayout(LayoutFrench); @@ -1411,8 +1412,8 @@ 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; +TEST_F(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // Press ShiftLeft @@ -1491,8 +1492,8 @@ TEST(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) { // This tests dead key ^ then & (US: 1) on a French keyboard, which do not // combine and should output "^&". -TEST(KeyboardTest, DeadKeyThatDoesNotCombine) { - KeyboardTester tester; +TEST_F(KeyboardTest, DeadKeyThatDoesNotCombine) { + KeyboardTester tester{GetContext()}; tester.Responding(false); tester.SetLayout(LayoutFrench); @@ -1560,8 +1561,8 @@ TEST(KeyboardTest, DeadKeyThatDoesNotCombine) { // This tests dead key `, then dead key `, then e. // // It should output ``e, instead of `è. -TEST(KeyboardTest, DeadKeyTwiceThenLetter) { - KeyboardTester tester; +TEST_F(KeyboardTest, DeadKeyTwiceThenLetter) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US INTL layout. @@ -1642,8 +1643,8 @@ TEST(KeyboardTest, DeadKeyTwiceThenLetter) { } // This tests when the resulting character needs to be combined with surrogates. -TEST(KeyboardTest, MultibyteCharacter) { - KeyboardTester tester; +TEST_F(KeyboardTest, MultibyteCharacter) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // Gothic Keyboard layout. (We need a layout that yields non-BMP characters @@ -1679,8 +1680,8 @@ TEST(KeyboardTest, MultibyteCharacter) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1); } -TEST(KeyboardTest, SynthesizeModifiers) { - KeyboardTester tester; +TEST_F(KeyboardTest, SynthesizeModifiers) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // Two dummy events used to trigger synthesization. @@ -1907,8 +1908,8 @@ TEST(KeyboardTest, SynthesizeModifiers) { // any events. // // Regression test for https://github.com/flutter/flutter/issues/95888 . -TEST(KeyboardTest, ImeExtendedEventsAreIgnored) { - KeyboardTester tester; +TEST_F(KeyboardTest, ImeExtendedEventsAreIgnored) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout. @@ -1935,8 +1936,8 @@ 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; +TEST_F(KeyboardTest, UpOnlyImeEventsAreCorrectlyHandled) { + KeyboardTester tester{GetContext()}; tester.Responding(true); // US Keyboard layout. @@ -1973,8 +1974,8 @@ 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) { + KeyboardTester tester{GetContext()}; std::vector recorded_callbacks; @@ -2036,9 +2037,8 @@ 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) { + KeyboardTester tester{GetContext()}; std::vector recorded_callbacks; // Store callbacks to manually call them. @@ -2113,8 +2113,8 @@ TEST(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } -TEST(KeyboardTest, TextInputSubmit) { - KeyboardTester tester; +TEST_F(KeyboardTest, TextInputSubmit) { + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -2181,7 +2181,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,7 +2191,7 @@ TEST(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { // // And the Backspace event is responded immediately. - KeyboardTester tester; + KeyboardTester tester{GetContext()}; tester.Responding(false); // US Keyboard layout @@ -2263,8 +2263,9 @@ TEST(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } -void VietnameseTelexAddDiacriticWithSlowResponse(bool backspace_response) { - // In this test, the user presses the folloing keys: +void VietnameseTelexAddDiacriticWithSlowResponse(WindowsTestContext& context, + bool backspace_response) { + // In this test, the user presses the following keys: // // Key Current text // =========================== @@ -2273,7 +2274,7 @@ void VietnameseTelexAddDiacriticWithSlowResponse(bool backspace_response) { // // And the Backspace down event is responded slowly with `backspace_response`. - KeyboardTester tester; + KeyboardTester tester{context}; tester.Responding(false); // US Keyboard layout @@ -2368,18 +2369,18 @@ void VietnameseTelexAddDiacriticWithSlowResponse(bool backspace_response) { EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0); } -TEST(KeyboardTest, VietnameseTelexAddDiacriticWithSlowFalseResponse) { - VietnameseTelexAddDiacriticWithSlowResponse(false); +TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithSlowFalseResponse) { + VietnameseTelexAddDiacriticWithSlowResponse(GetContext(), false); } -TEST(KeyboardTest, VietnameseTelexAddDiacriticWithSlowTrueResponse) { - VietnameseTelexAddDiacriticWithSlowResponse(true); +TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithSlowTrueResponse) { + VietnameseTelexAddDiacriticWithSlowResponse(GetContext(), 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; +TEST_F(KeyboardTest, DoubleCapsLock) { + KeyboardTester tester{GetContext()}; tester.Responding(false); tester.InjectKeyboardChanges(std::vector{