2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
- #include " flutter/shell/platform/common/json_message_codec.h"
6
- #include " flutter/shell/platform/embedder/embedder.h"
7
- #include " flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
8
- #include " flutter/shell/platform/windows/flutter_windows_engine.h"
9
- #include " flutter/shell/platform/windows/keyboard_key_channel_handler.h"
10
- #include " flutter/shell/platform/windows/keyboard_key_handler.h"
11
- #include " flutter/shell/platform/windows/testing/engine_modifier.h"
12
5
#include " flutter/shell/platform/windows/testing/flutter_window_test.h"
13
6
#include " flutter/shell/platform/windows/testing/mock_window_binding_handler.h"
14
7
#include " flutter/shell/platform/windows/testing/mock_window_binding_handler_delegate.h"
15
- #include " flutter/shell/platform/windows/testing/test_keyboard.h"
16
- #include " flutter/shell/platform/windows/text_input_plugin.h"
17
- #include " flutter/shell/platform/windows/text_input_plugin_delegate.h"
8
+ #include " flutter/shell/platform/windows/testing/wm_builders.h"
18
9
19
10
#include " gmock/gmock.h"
20
11
#include " gtest/gtest.h"
21
12
22
- #include < rapidjson/document.h>
23
-
24
13
using testing::_;
25
14
using testing::Invoke;
26
15
using testing::Return;
@@ -31,74 +20,6 @@ namespace testing {
31
20
namespace {
32
21
static constexpr int32_t kDefaultPointerDeviceId = 0 ;
33
22
34
- // A key event handler that can be spied on while it forwards calls to the real
35
- // key event handler.
36
- class SpyKeyboardKeyHandler : public KeyboardHandlerBase {
37
- public:
38
- SpyKeyboardKeyHandler (flutter::BinaryMessenger* messenger) {
39
- real_implementation_ = std::make_unique<KeyboardKeyHandler>();
40
- real_implementation_->AddDelegate (
41
- std::make_unique<KeyboardKeyChannelHandler>(messenger));
42
- ON_CALL (*this , KeyboardHook (_, _, _, _, _, _, _))
43
- .WillByDefault (Invoke (real_implementation_.get (),
44
- &KeyboardKeyHandler::KeyboardHook));
45
- ON_CALL (*this , SyncModifiersIfNeeded (_))
46
- .WillByDefault (Invoke (real_implementation_.get (),
47
- &KeyboardKeyHandler::SyncModifiersIfNeeded));
48
- }
49
-
50
- MOCK_METHOD7 (KeyboardHook,
51
- void (int key,
52
- int scancode,
53
- int action,
54
- char32_t character,
55
- bool extended,
56
- bool was_down,
57
- KeyEventCallback callback));
58
-
59
- MOCK_METHOD1 (SyncModifiersIfNeeded, void (int modifiers_state));
60
-
61
- private:
62
- std::unique_ptr<KeyboardKeyHandler> real_implementation_;
63
- };
64
-
65
- // A text input plugin that can be spied on while it forwards calls to the real
66
- // text input plugin.
67
- class SpyTextInputPlugin : public TextInputPlugin ,
68
- public TextInputPluginDelegate {
69
- public:
70
- SpyTextInputPlugin (flutter::BinaryMessenger* messenger)
71
- : TextInputPlugin(messenger, this ) {
72
- real_implementation_ = std::make_unique<TextInputPlugin>(messenger, this );
73
- ON_CALL (*this , KeyboardHook (_, _, _, _, _, _))
74
- .WillByDefault (
75
- Invoke (real_implementation_.get (), &TextInputPlugin::KeyboardHook));
76
- ON_CALL (*this , TextHook (_))
77
- .WillByDefault (
78
- Invoke (real_implementation_.get (), &TextInputPlugin::TextHook));
79
- }
80
-
81
- MOCK_METHOD6 (KeyboardHook,
82
- void (int key,
83
- int scancode,
84
- int action,
85
- char32_t character,
86
- bool extended,
87
- bool was_down));
88
- MOCK_METHOD1 (TextHook, void (const std::u16string& text));
89
- MOCK_METHOD0 (ComposeBeginHook, void ());
90
- MOCK_METHOD0 (ComposeCommitHook, void ());
91
- MOCK_METHOD0 (ComposeEndHook, void ());
92
- MOCK_METHOD2 (ComposeChangeHook,
93
- void (const std::u16string& text, int cursor_pos));
94
-
95
- virtual void OnCursorRectUpdated (const Rect & rect) {}
96
- virtual void OnResetImeComposing () {}
97
-
98
- private:
99
- std::unique_ptr<TextInputPlugin> real_implementation_;
100
- };
101
-
102
23
class MockFlutterWindow : public FlutterWindow {
103
24
public:
104
25
MockFlutterWindow () : FlutterWindow(800 , 600 ) {
@@ -154,68 +75,16 @@ class MockFlutterWindow : public FlutterWindow {
154
75
}
155
76
};
156
77
157
- // A FlutterWindowsView that overrides the RegisterKeyboardHandlers function
158
- // to register the keyboard hook handlers that can be spied upon.
159
- class TestFlutterWindowsView : public FlutterWindowsView {
78
+ class MockFlutterWindowsView : public FlutterWindowsView {
160
79
public:
161
- TestFlutterWindowsView (std::unique_ptr<WindowBindingHandler> window_binding)
80
+ MockFlutterWindowsView (std::unique_ptr<WindowBindingHandler> window_binding)
162
81
: FlutterWindowsView(std::move(window_binding)) {}
163
- ~TestFlutterWindowsView () {}
164
-
165
- SpyKeyboardKeyHandler* key_event_handler;
166
- SpyTextInputPlugin* text_input_plugin;
82
+ ~MockFlutterWindowsView () {}
167
83
168
84
MOCK_METHOD2 (NotifyWinEventWrapper,
169
85
void (ui::AXPlatformNodeWin*, ax::mojom::Event));
170
-
171
- protected:
172
- std::unique_ptr<KeyboardHandlerBase> CreateKeyboardKeyHandler (
173
- flutter::BinaryMessenger* messenger,
174
- flutter::KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state,
175
- KeyboardKeyEmbedderHandler::MapVirtualKeyToScanCode map_vk_to_scan)
176
- override {
177
- auto spy_key_event_handler =
178
- std::make_unique<SpyKeyboardKeyHandler>(messenger);
179
- key_event_handler = spy_key_event_handler.get ();
180
- return spy_key_event_handler;
181
- }
182
-
183
- std::unique_ptr<TextInputPlugin> CreateTextInputPlugin (
184
- flutter::BinaryMessenger* messenger) override {
185
- auto spy_key_event_handler =
186
- std::make_unique<SpyTextInputPlugin>(messenger);
187
- text_input_plugin = spy_key_event_handler.get ();
188
- return spy_key_event_handler;
189
- }
190
86
};
191
87
192
- // The static value to return as the "handled" value from the framework for key
193
- // events. Individual tests set this to change the framework response that the
194
- // test engine simulates.
195
- static bool test_response = false ;
196
-
197
- // Returns an engine instance configured with dummy project path values, and
198
- // overridden methods for sending platform messages, so that the engine can
199
- // respond as if the framework were connected.
200
- std::unique_ptr<FlutterWindowsEngine> GetTestEngine () {
201
- FlutterDesktopEngineProperties properties = {};
202
- properties.assets_path = L" C:\\ foo\\ flutter_assets" ;
203
- properties.icu_data_path = L" C:\\ foo\\ icudtl.dat" ;
204
- properties.aot_library_path = L" C:\\ foo\\ aot.so" ;
205
- FlutterProjectBundle project (properties);
206
- auto engine = std::make_unique<FlutterWindowsEngine>(project);
207
-
208
- EngineModifier modifier (engine.get ());
209
- auto key_response_controller = std::make_shared<MockKeyResponseController>();
210
- key_response_controller->SetChannelResponse (
211
- [](MockKeyResponseController::ResponseCallback callback) {
212
- callback (test_response);
213
- });
214
- MockEmbedderApiForKeyboard (modifier, key_response_controller);
215
-
216
- return engine;
217
- }
218
-
219
88
} // namespace
220
89
221
90
TEST (FlutterWindowTest, CreateDestroy) {
@@ -419,7 +288,7 @@ TEST(FlutterWindowTest, AlertNode) {
419
288
ON_CALL (*win32window, GetPlatformWindow ()).WillByDefault (Return (nullptr ));
420
289
ON_CALL (*win32window, GetAxFragmentRootDelegate ())
421
290
.WillByDefault (Return (nullptr ));
422
- TestFlutterWindowsView view (std::move (win32window));
291
+ MockFlutterWindowsView view (std::move (win32window));
423
292
std::wstring message = L" Test alert" ;
424
293
EXPECT_CALL (view, NotifyWinEventWrapper (_, ax::mojom::Event::kAlert ))
425
294
.Times (1 );
0 commit comments