@@ -35,17 +35,13 @@ static constexpr int32_t kDefaultPointerDeviceId = 0;
3535class SpyKeyboardKeyHandler : public KeyboardHandlerBase {
3636 public:
3737 SpyKeyboardKeyHandler (flutter::BinaryMessenger* messenger,
38- KeyboardKeyHandler::EventDispatcher redispatch_event) {
39- real_implementation_ =
40- std::make_unique<KeyboardKeyHandler>(redispatch_event);
38+ KeyboardKeyHandler::EventDispatcher dispatch_event) {
39+ real_implementation_ = std::make_unique<KeyboardKeyHandler>(dispatch_event);
4140 real_implementation_->AddDelegate (
4241 std::make_unique<KeyboardKeyChannelHandler>(messenger));
4342 ON_CALL (*this , KeyboardHook (_, _, _, _, _, _))
4443 .WillByDefault (Invoke (real_implementation_.get (),
4544 &KeyboardKeyHandler::KeyboardHook));
46- ON_CALL (*this , TextHook (_))
47- .WillByDefault (
48- Invoke (real_implementation_.get (), &KeyboardKeyHandler::TextHook));
4945 }
5046
5147 MOCK_METHOD6 (KeyboardHook,
@@ -55,7 +51,6 @@ class SpyKeyboardKeyHandler : public KeyboardHandlerBase {
5551 char32_t character,
5652 bool extended,
5753 bool was_down));
58- MOCK_METHOD1 (TextHook, void (const std::u16string& text));
5954 MOCK_METHOD0 (ComposeBeginHook, void ());
6055 MOCK_METHOD0 (ComposeCommitHook, void ());
6156 MOCK_METHOD0 (ComposeEndHook, void ());
@@ -68,10 +63,11 @@ class SpyKeyboardKeyHandler : public KeyboardHandlerBase {
6863
6964// A text input plugin that can be spied on while it forwards calls to the real
7065// text input plugin.
71- class SpyTextInputPlugin : public KeyboardHandlerBase ,
66+ class SpyTextInputPlugin : public TextInputPlugin ,
7267 public TextInputPluginDelegate {
7368 public:
74- SpyTextInputPlugin (flutter::BinaryMessenger* messenger) {
69+ SpyTextInputPlugin (flutter::BinaryMessenger* messenger)
70+ : TextInputPlugin(messenger, this ) {
7571 real_implementation_ = std::make_unique<TextInputPlugin>(messenger, this );
7672 ON_CALL (*this , KeyboardHook (_, _, _, _, _, _))
7773 .WillByDefault (
@@ -82,7 +78,7 @@ class SpyTextInputPlugin : public KeyboardHandlerBase,
8278 }
8379
8480 MOCK_METHOD6 (KeyboardHook,
85- bool (int key,
81+ void (int key,
8682 int scancode,
8783 int action,
8884 char32_t character,
@@ -246,7 +242,7 @@ class TestFlutterWindowsView : public FlutterWindowsView {
246242 }
247243
248244 protected:
249- void RegisterKeyboardHandlers (
245+ std::unique_ptr<KeyboardHandlerBase> CreateKeyboardKeyHandler (
250246 flutter::BinaryMessenger* messenger,
251247 flutter::KeyboardKeyHandler::EventDispatcher dispatch_event,
252248 flutter::KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state)
@@ -255,12 +251,16 @@ class TestFlutterWindowsView : public FlutterWindowsView {
255251 messenger, [this ](UINT cInputs, LPINPUT pInputs, int cbSize) -> UINT {
256252 return this ->SendInput (cInputs, pInputs, cbSize);
257253 });
258- auto spy_text_input_plugin =
259- std::make_unique<SpyTextInputPlugin>(messenger);
260254 key_event_handler = spy_key_event_handler.get ();
261- text_input_plugin = spy_text_input_plugin.get ();
262- AddKeyboardHandler (std::move (spy_key_event_handler));
263- AddKeyboardHandler (std::move (spy_text_input_plugin));
255+ return spy_key_event_handler;
256+ }
257+
258+ std::unique_ptr<TextInputPlugin> CreateTextInputPlugin (
259+ flutter::BinaryMessenger* messenger) override {
260+ auto spy_key_event_handler =
261+ std::make_unique<SpyTextInputPlugin>(messenger);
262+ text_input_plugin = spy_key_event_handler.get ();
263+ return spy_key_event_handler;
264264 }
265265
266266 private:
@@ -357,7 +357,6 @@ TEST(FlutterWindowWin32Test, NonPrintableKeyDownPropagation) {
357357 KeyboardHook (_, _, _, _, _, _))
358358 .Times (1 )
359359 .RetiresOnSaturation ();
360- EXPECT_CALL (*flutter_windows_view.key_event_handler , TextHook (_)).Times (0 );
361360 EXPECT_CALL (*flutter_windows_view.text_input_plugin , TextHook (_)).Times (0 );
362361 win32window.InjectMessages (1 ,
363362 Win32Message{WM_KEYDOWN, virtual_key, lparam});
@@ -410,7 +409,6 @@ TEST(FlutterWindowWin32Test, SystemKeyDownPropagation) {
410409 KeyboardHook (_, _, _, _, _, _))
411410 .Times (1 )
412411 .RetiresOnSaturation ();
413- EXPECT_CALL (*flutter_windows_view.key_event_handler , TextHook (_)).Times (0 );
414412 EXPECT_CALL (*flutter_windows_view.text_input_plugin , TextHook (_)).Times (0 );
415413 win32window.InjectMessages (
416414 1 , Win32Message{WM_SYSKEYDOWN, virtual_key, lparam, kWmResultDefault });
@@ -436,7 +434,7 @@ TEST(FlutterWindowWin32Test, SystemKeyDownPropagation) {
436434// differ from non-printable characters in that they follow a different code
437435// path in the WndProc (HandleMessage), producing a follow-on WM_CHAR event.
438436TEST (FlutterWindowWin32Test, CharKeyDownPropagation) {
439- // ::testing::InSequence in_sequence;
437+ ::testing::InSequence in_sequence;
440438
441439 constexpr WPARAM virtual_key = 65 ; // The "A" key, which produces a character
442440 constexpr WPARAM scan_code = 30 ;
@@ -463,9 +461,6 @@ TEST(FlutterWindowWin32Test, CharKeyDownPropagation) {
463461 KeyboardHook (_, _, _, _, _, _))
464462 .Times (1 )
465463 .RetiresOnSaturation ();
466- EXPECT_CALL (*flutter_windows_view.key_event_handler , TextHook (_))
467- .Times (1 )
468- .RetiresOnSaturation ();
469464 EXPECT_CALL (*flutter_windows_view.text_input_plugin , TextHook (_))
470465 .Times (1 )
471466 .RetiresOnSaturation ();
@@ -485,7 +480,6 @@ TEST(FlutterWindowWin32Test, CharKeyDownPropagation) {
485480 EXPECT_CALL (*flutter_windows_view.text_input_plugin ,
486481 KeyboardHook (_, _, _, _, _, _))
487482 .Times (0 );
488- EXPECT_CALL (*flutter_windows_view.key_event_handler , TextHook (_)).Times (0 );
489483 EXPECT_CALL (*flutter_windows_view.text_input_plugin , TextHook (_)).Times (0 );
490484 win32window.InjectMessages (2 , Win32Message{WM_KEYDOWN, virtual_key, lparam},
491485 Win32Message{WM_CHAR, virtual_key, lparam});
@@ -521,7 +515,6 @@ TEST(FlutterWindowWin32Test, ModifierKeyDownPropagation) {
521515 KeyboardHook (_, _, _, _, _, _))
522516 .Times (1 )
523517 .RetiresOnSaturation ();
524- EXPECT_CALL (*flutter_windows_view.key_event_handler , TextHook (_)).Times (0 );
525518 EXPECT_CALL (*flutter_windows_view.text_input_plugin , TextHook (_)).Times (0 );
526519 EXPECT_EQ (win32window.InjectWindowMessage (WM_KEYDOWN, virtual_key, lparam),
527520 0 );
0 commit comments