7#include "flutter/shell/platform/windows/testing/mock_direct_manipulation.h"
8#include "flutter/shell/platform/windows/testing/mock_text_input_manager.h"
9#include "flutter/shell/platform/windows/testing/mock_window.h"
10#include "flutter/shell/platform/windows/testing/mock_windows_proc_table.h"
11#include "gmock/gmock.h"
12#include "gtest/gtest.h"
16using testing::InSequence;
30 ASSERT_TRUE(
window.GetDpi() > 0);
35 const int scroll_amount = 10;
38 EXPECT_CALL(
window, OnScroll(0, -scroll_amount / 120.0,
42 window.InjectWindowMessage(WM_MOUSEWHEEL, MAKEWPARAM(0, scroll_amount), 0);
46 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
48 std::unique_ptr<TextInputManager> text_input_manager_ptr(text_input_manager);
50 std::move(text_input_manager_ptr));
51 EXPECT_CALL(*text_input_manager, GetComposingString())
53 Return(std::optional<std::u16string>(std::u16string(u
"nihao"))));
54 EXPECT_CALL(*text_input_manager, GetResultString())
56 Return(std::optional<std::u16string>(std::u16string(u
"`}"))));
57 EXPECT_CALL(*text_input_manager, GetComposingCursorPosition())
58 .WillRepeatedly(Return((
int)0));
60 EXPECT_CALL(
window, OnComposeChange(std::u16string(u
"nihao"), 0)).Times(1);
61 EXPECT_CALL(
window, OnComposeChange(std::u16string(u
"`}"), 0)).Times(0);
62 EXPECT_CALL(
window, OnComposeCommit()).Times(0);
63 ON_CALL(
window, OnImeComposition)
65 EXPECT_CALL(
window, OnImeComposition(_, _, _)).Times(1);
68 window.InjectWindowMessage(WM_IME_COMPOSITION, 0, GCS_COMPSTR);
72 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
74 std::unique_ptr<TextInputManager> text_input_manager_ptr(text_input_manager);
76 std::move(text_input_manager_ptr));
77 EXPECT_CALL(*text_input_manager, GetComposingString())
79 Return(std::optional<std::u16string>(std::u16string(u
"nihao"))));
80 EXPECT_CALL(*text_input_manager, GetResultString())
82 Return(std::optional<std::u16string>(std::u16string(u
"`}"))));
83 EXPECT_CALL(*text_input_manager, GetComposingCursorPosition())
84 .WillRepeatedly(Return((
int)0));
86 EXPECT_CALL(
window, OnComposeChange(std::u16string(u
"nihao"), 0)).Times(0);
87 EXPECT_CALL(
window, OnComposeChange(std::u16string(u
"`}"), 0)).Times(1);
88 EXPECT_CALL(
window, OnComposeCommit()).Times(1);
89 ON_CALL(
window, OnImeComposition)
91 EXPECT_CALL(
window, OnImeComposition(_, _, _)).Times(1);
94 window.InjectWindowMessage(WM_IME_COMPOSITION, 0, GCS_RESULTSTR);
98 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
100 std::unique_ptr<TextInputManager> text_input_manager_ptr(text_input_manager);
102 std::move(text_input_manager_ptr));
108 EXPECT_CALL(*text_input_manager, GetResultString())
110 Return(std::optional<std::u16string>(std::u16string(u
"今日"))));
111 EXPECT_CALL(*text_input_manager, GetComposingString())
113 Return(std::optional<std::u16string>(std::u16string(u
"は"))));
117 EXPECT_CALL(
window, OnComposeChange(std::u16string(u
"今日"), 0)).Times(1);
118 EXPECT_CALL(
window, OnComposeCommit()).Times(1);
119 EXPECT_CALL(
window, OnComposeChange(std::u16string(u
"は"), 0)).Times(1);
122 EXPECT_CALL(*text_input_manager, GetComposingCursorPosition())
123 .WillRepeatedly(Return((
int)0));
125 ON_CALL(
window, OnImeComposition)
127 EXPECT_CALL(
window, OnImeComposition(_, _, _)).Times(1);
131 window.InjectWindowMessage(WM_IME_COMPOSITION, 0,
132 GCS_COMPSTR | GCS_RESULTSTR);
136 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
138 std::unique_ptr<TextInputManager> text_input_manager_ptr(text_input_manager);
140 std::move(text_input_manager_ptr));
141 EXPECT_CALL(
window, OnComposeChange(std::u16string(u
""), 0)).Times(1);
142 EXPECT_CALL(
window, OnComposeCommit()).Times(1);
143 ON_CALL(
window, OnImeComposition)
145 EXPECT_CALL(
window, OnImeComposition(_, _, _)).Times(1);
149 window.InjectWindowMessage(WM_IME_COMPOSITION, 0, 0);
154 const int scroll_amount = 10;
156 EXPECT_CALL(
window, OnScroll(scroll_amount / 120.0, 0,
160 window.InjectWindowMessage(WM_MOUSEHWHEEL, MAKEWPARAM(0, scroll_amount), 0);
165 const double mouse_x = 10.0;
166 const double mouse_y = 20.0;
168 EXPECT_CALL(
window, OnPointerMove(mouse_x, mouse_y,
171 EXPECT_CALL(
window, OnPointerLeave(mouse_x, mouse_y,
175 window.InjectWindowMessage(WM_MOUSEMOVE, 0, MAKELPARAM(mouse_x, mouse_y));
176 window.InjectWindowMessage(WM_MOUSELEAVE, 0, 0);
181 EXPECT_CALL(
window, OnKey(_, _, _, _, _, _, _)).Times(1);
184 window.InjectWindowMessage(WM_KEYDOWN, 16, lparam);
189 EXPECT_CALL(
window, OnKey(_, _, _, _, _, _, _)).Times(1);
192 window.InjectWindowMessage(WM_KEYUP, 16, lparam);
197 EXPECT_CALL(
window, OnKey(_, _, _, _, _, _, _)).Times(1);
200 window.InjectWindowMessage(WM_SYSKEYDOWN, 16, lparam);
205 EXPECT_CALL(
window, OnKey(_, _, _, _, _, _, _)).Times(1);
208 window.InjectWindowMessage(WM_SYSKEYUP, 16, lparam);
220 EXPECT_CALL(
window, OnKey(65, 30, WM_KEYDOWN, 0,
false,
false, _))
222 .WillOnce(respond_false);
223 EXPECT_CALL(
window, OnText(_)).Times(1);
224 std::array<Win32Message, 2> messages = {
227 window.InjectMessageList(2, messages.data());
234 std::array<BYTE, 256> keyboard_state;
235 keyboard_state[VK_CONTROL] = -1;
236 SetKeyboardState(keyboard_state.data());
242 EXPECT_CALL(
window, OnKey(65, 30, WM_KEYDOWN, 0,
false,
false, _)).Times(1);
243 EXPECT_CALL(
window, OnText(_)).Times(0);
245 window.InjectWindowMessage(WM_KEYDOWN, 65, lparam);
247 keyboard_state.fill(0);
248 SetKeyboardState(keyboard_state.data());
261 std::array<BYTE, 256> keyboard_state;
262 keyboard_state[VK_CONTROL] = 1;
263 SetKeyboardState(keyboard_state.data());
267 EXPECT_CALL(
window, OnKey(65, 30, WM_KEYDOWN, 0,
false,
false, _))
269 .WillOnce(respond_false);
270 EXPECT_CALL(
window, OnText(_)).Times(1);
275 window.InjectMessageList(2, messages);
277 keyboard_state.fill(0);
278 SetKeyboardState(keyboard_state.data());
283 EXPECT_CALL(
window, OnPaint()).Times(1);
284 window.InjectWindowMessage(WM_PAINT, 0, 0);
289 UINT32 pointer_id = 123;
290 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
291 auto text_input_manager = std::make_unique<MockTextInputManager>();
293 EXPECT_CALL(*windows_proc_table, GetPointerType(Eq(pointer_id), _))
295 .WillOnce([](UINT32 pointer_id, POINTER_INPUT_TYPE*
type) {
301 std::move(text_input_manager));
303 auto direct_manipulation =
304 std::make_unique<MockDirectManipulationOwner>(&
window);
306 EXPECT_CALL(*direct_manipulation, SetContact).Times(0);
308 window.SetDirectManipulationOwner(std::move(direct_manipulation));
309 window.InjectWindowMessage(DM_POINTERHITTEST, MAKEWPARAM(pointer_id, 0), 0);
314 UINT32 pointer_id = 123;
315 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
316 auto text_input_manager = std::make_unique<MockTextInputManager>();
318 EXPECT_CALL(*windows_proc_table, GetPointerType(Eq(pointer_id), _))
320 .WillOnce([](UINT32 pointer_id, POINTER_INPUT_TYPE*
type) {
326 std::move(text_input_manager));
328 auto direct_manipulation =
329 std::make_unique<MockDirectManipulationOwner>(&
window);
331 EXPECT_CALL(*direct_manipulation, SetContact(Eq(pointer_id))).Times(1);
333 window.SetDirectManipulationOwner(std::move(direct_manipulation));
334 window.InjectWindowMessage(DM_POINTERHITTEST, MAKEWPARAM(pointer_id, 0), 0);
342 UINT32 pointer_id = 123;
343 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
344 auto text_input_manager = std::make_unique<MockTextInputManager>();
346 EXPECT_CALL(*windows_proc_table, GetPointerType(Eq(pointer_id), _))
349 [](UINT32 pointer_id, POINTER_INPUT_TYPE*
type) {
return FALSE; });
352 std::move(text_input_manager));
354 auto direct_manipulation =
355 std::make_unique<MockDirectManipulationOwner>(&
window);
357 EXPECT_CALL(*direct_manipulation, SetContact).Times(0);
359 window.SetDirectManipulationOwner(std::move(direct_manipulation));
360 window.InjectWindowMessage(DM_POINTERHITTEST, MAKEWPARAM(pointer_id, 0), 0);
366 bool uia_called =
false;
367 ON_CALL(
window, OnGetObject)
369#ifdef FLUTTER_ENGINE_USE_UIA
372 return static_cast<LRESULT>(0);
374 EXPECT_CALL(
window, OnGetObject).Times(1);
376 window.InjectWindowMessage(WM_GETOBJECT, 0, UiaRootObjectId);
Mock for the |Window| base class.
Mock for the |FlutterWindow| base class.
void CallOnImeComposition(UINT const message, WPARAM const wparam, LPARAM const lparam)
@ kFlutterPointerDeviceKindMouse
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Dart_NativeFunction function
ObjectPtr Invoke(const Library &lib, const char *name)
constexpr LRESULT kWmResultDontCheck
LPARAM CreateKeyEventLparam(USHORT scancode, bool extended, bool was_down, USHORT repeat_count, bool context_code, bool transition_state)
TEST(DisplayListComplexity, EmptyDisplayList)
#define EXPECT_TRUE(handle)