5 #include "flutter/fml/logging.h"
7 #include "flutter/shell/platform/embedder/embedder.h"
8 #include "flutter/shell/platform/embedder/test_utils/key_codes.g.h"
15 #include "flutter/shell/platform/windows/testing/engine_modifier.h"
16 #include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h"
17 #include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h"
18 #include "flutter/shell/platform/windows/testing/test_keyboard.h"
19 #include "flutter/shell/platform/windows/testing/windows_test.h"
21 #include "gmock/gmock.h"
22 #include "gtest/gtest.h"
23 #include "rapidjson/stringbuffer.h"
24 #include "rapidjson/writer.h"
31 using testing::Invoke;
32 using testing::Return;
33 using namespace ::flutter::testing::keycodes;
40 constexpr SHORT kStateMaskToggled = 0x01;
41 constexpr SHORT kStateMaskPressed = 0x80;
43 constexpr uint64_t kScanCodeBackquote = 0x29;
45 constexpr uint64_t kScanCodeKeyB = 0x30;
46 constexpr uint64_t kScanCodeKeyE = 0x12;
47 constexpr uint64_t kScanCodeKeyF = 0x21;
48 constexpr uint64_t kScanCodeKeyO = 0x18;
49 constexpr uint64_t kScanCodeKeyQ = 0x10;
50 constexpr uint64_t kScanCodeKeyW = 0x11;
51 constexpr uint64_t kScanCodeDigit1 = 0x02;
52 constexpr uint64_t kScanCodeDigit2 = 0x03;
53 constexpr uint64_t kScanCodeDigit6 = 0x07;
56 constexpr uint64_t kScanCodeControl = 0x1d;
57 constexpr uint64_t kScanCodeMetaLeft = 0x5b;
58 constexpr uint64_t kScanCodeMetaRight = 0x5c;
59 constexpr uint64_t kScanCodeAlt = 0x38;
62 constexpr uint64_t kScanCodeBracketLeft = 0x1a;
63 constexpr uint64_t kScanCodeArrowLeft = 0x4b;
64 constexpr uint64_t kScanCodeEnter = 0x1c;
65 constexpr uint64_t kScanCodeBackspace = 0x0e;
67 constexpr uint64_t kVirtualDigit1 = 0x31;
69 constexpr uint64_t kVirtualKeyB = 0x42;
70 constexpr uint64_t kVirtualKeyE = 0x45;
71 constexpr uint64_t kVirtualKeyF = 0x46;
72 constexpr uint64_t kVirtualKeyO = 0x4f;
73 constexpr uint64_t kVirtualKeyQ = 0x51;
74 constexpr uint64_t kVirtualKeyW = 0x57;
76 constexpr
bool kSynthesized =
true;
77 constexpr
bool kNotSynthesized =
false;
79 typedef UINT (*MapVirtualKeyLayout)(UINT uCode, UINT uMapType);
80 typedef std::function<UINT(UINT)> MapVirtualKeyToChar;
82 UINT LayoutDefault(UINT uCode, UINT uMapType) {
83 return MapVirtualKey(uCode, uMapType);
86 UINT LayoutFrench(UINT uCode, UINT uMapType) {
88 case MAPVK_VK_TO_CHAR:
93 return MapVirtualKey(uCode, MAPVK_VK_TO_CHAR);
96 return MapVirtualKey(uCode, uMapType);
100 class TestKeyboardManager :
public KeyboardManager {
102 explicit TestKeyboardManager(WindowDelegate* delegate)
103 : KeyboardManager(delegate) {}
105 bool DuringRedispatch() {
return during_redispatch_; }
108 void RedispatchEvent(std::unique_ptr<PendingEvent> event)
override {
109 FML_DCHECK(!during_redispatch_)
110 <<
"RedispatchEvent called while already redispatching an event";
111 during_redispatch_ =
true;
113 during_redispatch_ =
false;
117 bool during_redispatch_ =
false;
119 FML_DISALLOW_COPY_AND_ASSIGN(TestKeyboardManager);
124 struct KeyStateChange {
136 struct ExpectForgedMessage {
142 struct KeyboardChange {
145 KeyboardChange(Win32Message
message) :
type(kMessage) {
149 KeyboardChange(KeyStateChange change) :
type(kKeyStateChange) {
150 content.key_state_change = change;
153 KeyboardChange(ExpectForgedMessage forged_message)
154 :
type(kExpectForgedMessage) {
155 content.expected_forged_message = forged_message.message;
161 kExpectForgedMessage,
174 state_[virtual_key] = (
pressed ? kStateMaskPressed : 0) |
178 SHORT Get(uint32_t virtual_key) {
return state_[virtual_key]; }
181 std::map<uint32_t, SHORT> state_;
184 class MockKeyboardManagerDelegate :
public KeyboardManager::WindowDelegate,
185 protected MockMessageQueue {
187 MockKeyboardManagerDelegate(WindowBindingHandlerDelegate* view,
188 MapVirtualKeyToChar map_vk_to_char)
189 : view_(view), map_vk_to_char_(std::move(map_vk_to_char)) {
190 keyboard_manager_ = std::make_unique<TestKeyboardManager>(
this);
192 virtual ~MockKeyboardManagerDelegate() {}
201 KeyEventCallback
callback)
override {
207 void OnText(
const std::u16string&
text)
override { view_->OnText(
text); }
209 SHORT GetKeyState(
int virtual_key) {
return key_state_.Get(virtual_key); }
211 void InjectKeyboardChanges(std::vector<KeyboardChange> changes) {
213 for (
const KeyboardChange& change : changes) {
214 switch (change.type) {
215 case KeyboardChange::kMessage:
216 PushBack(&change.content.message);
222 for (
const KeyboardChange& change : changes) {
223 switch (change.type) {
224 case KeyboardChange::kMessage:
227 case KeyboardChange::kExpectForgedMessage:
228 forged_message_expectations_.push_back(ForgedMessageExpectation{
229 .message = change.content.expected_forged_message,
232 case KeyboardChange::kKeyStateChange: {
233 const KeyStateChange& state_change = change.content.key_state_change;
234 if (forged_message_expectations_.empty()) {
235 key_state_.Set(state_change.key, state_change.pressed,
236 state_change.toggled_on);
238 forged_message_expectations_.back()
239 .state_changes_afterwards.push_back(state_change);
244 FML_LOG(FATAL) <<
"Unhandled KeyboardChange type " << change.type;
249 std::list<Win32Message>& RedispatchedMessages() {
250 return redispatched_messages_;
254 BOOL Win32PeekMessage(LPMSG lpMsg,
257 UINT wRemoveMsg)
override {
258 return MockMessageQueue::Win32PeekMessage(lpMsg, wMsgFilterMin,
259 wMsgFilterMax, wRemoveMsg);
262 uint32_t Win32MapVkToChar(uint32_t virtual_key)
override {
263 return map_vk_to_char_(virtual_key);
268 LRESULT Win32SendMessage(UINT
const message,
270 LPARAM
const lparam)
override {
271 return keyboard_manager_->HandleMessage(
message, wparam, lparam)
278 UINT Win32DispatchMessage(UINT Msg, WPARAM wParam, LPARAM lParam)
override {
279 bool handled = keyboard_manager_->HandleMessage(Msg, wParam, lParam);
280 if (keyboard_manager_->DuringRedispatch()) {
281 redispatched_messages_.push_back(Win32Message{
286 EXPECT_FALSE(handled);
288 EXPECT_FALSE(forged_message_expectations_.empty());
289 ForgedMessageExpectation expectation =
290 forged_message_expectations_.front();
291 forged_message_expectations_.pop_front();
292 EXPECT_EQ(expectation.message.message, Msg);
293 EXPECT_EQ(expectation.message.wParam, wParam);
294 EXPECT_EQ(expectation.message.lParam, lParam);
295 if (expectation.message.expected_result != kWmResultDontCheck) {
296 EXPECT_EQ(expectation.message.expected_result,
297 handled ? kWmResultZero : kWmResultDefault);
299 for (
const KeyStateChange& change :
300 expectation.state_changes_afterwards) {
301 key_state_.Set(change.key, change.pressed, change.toggled_on);
308 struct ForgedMessageExpectation {
313 WindowBindingHandlerDelegate* view_;
314 std::unique_ptr<TestKeyboardManager> keyboard_manager_;
315 std::list<ForgedMessageExpectation> forged_message_expectations_;
316 MapVirtualKeyToChar map_vk_to_char_;
317 TestKeystate key_state_;
318 std::list<Win32Message> redispatched_messages_;
320 FML_DISALLOW_COPY_AND_ASSIGN(MockKeyboardManagerDelegate);
327 kKeyCallTextMethodCall,
337 class TestFlutterWindowsView :
public FlutterWindowsView {
339 TestFlutterWindowsView(FlutterWindowsEngine* engine,
340 std::unique_ptr<WindowBindingHandler> window,
341 std::function<
void(KeyCall)> on_key_call)
342 : on_key_call_(on_key_call),
345 void OnText(
const std::u16string&
text)
override {
346 on_key_call_(KeyCall{
347 .type = KeyCall::kKeyCallOnText,
353 std::function<void(KeyCall)> on_key_call_;
355 FML_DISALLOW_COPY_AND_ASSIGN(TestFlutterWindowsView);
358 class KeyboardTester {
360 using ResponseHandler =
361 std::function<void(MockKeyResponseController::ResponseCallback)>;
363 explicit KeyboardTester(WindowsTestContext& context)
364 : callback_handler_(RespondValue(false)),
365 map_virtual_key_layout_(LayoutDefault) {
366 engine_ = GetTestEngine(context);
367 view_ = std::make_unique<TestFlutterWindowsView>(
371 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>(),
372 [
this](KeyCall key_call) { key_calls.push_back(key_call); });
374 EngineModifier modifier{engine_.get()};
375 modifier.SetImplicitView(view_.get());
376 modifier.InitializeKeyboard();
378 window_ = std::make_unique<MockKeyboardManagerDelegate>(
379 view_.get(), [
this](UINT virtual_key) -> SHORT {
380 return map_virtual_key_layout_(virtual_key, MAPVK_VK_TO_CHAR);
384 TestFlutterWindowsView& GetView() {
return *view_; }
385 MockKeyboardManagerDelegate& GetWindow() {
return *window_; }
388 void ResetKeyboard() { EngineModifier{engine_.get()}.Restart(); }
391 void Responding(
bool response) { callback_handler_ = RespondValue(response); }
400 MockKeyResponseController::EmbedderCallbackHandler handler) {
401 callback_handler_ = std::move(handler);
404 void SetLayout(MapVirtualKeyLayout layout) {
405 map_virtual_key_layout_ = layout ==
nullptr ? LayoutDefault : layout;
408 void InjectKeyboardChanges(std::vector<KeyboardChange> changes) {
409 FML_DCHECK(window_ !=
nullptr);
410 window_->InjectKeyboardChanges(std::move(changes));
414 void InjectPlatformMessage(
const char* channel,
417 rapidjson::Document args_doc;
418 args_doc.Parse(args);
419 FML_DCHECK(!args_doc.HasParseError());
421 rapidjson::Document message_doc(rapidjson::kObjectType);
422 auto& allocator = message_doc.GetAllocator();
423 message_doc.AddMember(
"method", rapidjson::Value(method, allocator),
425 message_doc.AddMember(
"args", args_doc, allocator);
427 rapidjson::StringBuffer buffer;
428 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
429 message_doc.Accept(writer);
431 std::unique_ptr<std::vector<uint8_t>> data =
433 FlutterPlatformMessageResponseHandle response_handle;
434 const FlutterPlatformMessage
message = {
435 sizeof(FlutterPlatformMessage),
441 view_->GetEngine()->HandlePlatformMessage(&
message);
446 size_t RedispatchedMessageCountAndClear() {
447 auto& messages = window_->RedispatchedMessages();
448 size_t count = messages.size();
453 void clear_key_calls() {
455 if (key_call.type == KeyCall::kKeyCallOnKey &&
456 key_call.key_event.character !=
nullptr) {
457 delete[] key_call.key_event.character;
466 std::unique_ptr<FlutterWindowsEngine> engine_;
467 std::unique_ptr<TestFlutterWindowsView> view_;
468 std::unique_ptr<MockKeyboardManagerDelegate> window_;
469 MockKeyResponseController::EmbedderCallbackHandler callback_handler_;
470 MapVirtualKeyLayout map_virtual_key_layout_;
475 std::unique_ptr<FlutterWindowsEngine> GetTestEngine(
476 WindowsTestContext& context) {
477 FlutterWindowsEngineBuilder builder{context};
479 builder.SetCreateKeyboardHandlerCallbacks(
480 [
this](
int virtual_key) -> SHORT {
483 return window_ ? window_->GetKeyState(virtual_key) : 0;
485 [
this](UINT virtual_key,
bool extended) -> SHORT {
486 return map_virtual_key_layout_(
487 virtual_key,
extended ? MAPVK_VK_TO_VSC_EX : MAPVK_VK_TO_VSC);
490 auto engine = builder.Build();
492 EngineModifier modifier(engine.get());
494 auto key_response_controller =
495 std::make_shared<MockKeyResponseController>();
496 key_response_controller->SetEmbedderResponse(
498 const FlutterKeyEvent* event,
499 MockKeyResponseController::ResponseCallback
callback) {
500 FlutterKeyEvent clone_event = *event;
501 clone_event.character =
event->character ==
nullptr
503 : clone_string(event->character);
505 .type = KeyCall::kKeyCallOnKey,
506 .key_event = clone_event,
510 key_response_controller->SetTextInputResponse(
512 key_calls](std::unique_ptr<rapidjson::Document> document) {
513 rapidjson::StringBuffer buffer;
514 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
515 document->Accept(writer);
517 .type = KeyCall::kKeyCallTextMethodCall,
518 .text_method_call = buffer.GetString(),
521 MockEmbedderApiForKeyboard(modifier, key_response_controller);
528 static MockKeyResponseController::EmbedderCallbackHandler RespondValue(
530 return [value](
const FlutterKeyEvent* event,
531 MockKeyResponseController::ResponseCallback
callback) {
537 FML_DISALLOW_COPY_AND_ASSIGN(KeyboardTester);
540 class KeyboardTest :
public WindowsTest {
542 KeyboardTest() =
default;
543 virtual ~KeyboardTest() =
default;
546 FML_DISALLOW_COPY_AND_ASSIGN(KeyboardTest);
554 #define EXPECT_CALL_IS_EVENT(_key_call, _type, _physical, _logical, \
555 _character, _synthesized) \
556 EXPECT_EQ(_key_call.type, KeyCall::kKeyCallOnKey); \
557 EXPECT_EVENT_EQUALS(_key_call.key_event, _type, _physical, _logical, \
558 _character, _synthesized);
560 #define EXPECT_CALL_IS_TEXT(_key_call, u16_string) \
561 EXPECT_EQ(_key_call.type, KeyCall::kKeyCallOnText); \
562 EXPECT_EQ(_key_call.text, u16_string);
564 #define EXPECT_CALL_IS_TEXT_METHOD_CALL(_key_call, json_string) \
565 EXPECT_EQ(_key_call.type, KeyCall::kKeyCallTextMethodCall); \
566 EXPECT_STREQ(_key_call.text_method_call.c_str(), json_string);
568 TEST_F(KeyboardTest, LowerCaseAHandled) {
569 KeyboardTester tester{GetContext()};
570 tester.Responding(
true);
575 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
581 EXPECT_EQ(tester.key_calls.size(), 1);
583 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
584 tester.clear_key_calls();
585 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
588 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
592 EXPECT_EQ(tester.key_calls.size(), 1);
594 kPhysicalKeyA, kLogicalKeyA,
"", kNotSynthesized);
595 tester.clear_key_calls();
596 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
599 TEST_F(KeyboardTest, LowerCaseAUnhandled) {
600 KeyboardTester tester{GetContext()};
601 tester.Responding(
false);
606 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
612 EXPECT_EQ(tester.key_calls.size(), 2);
614 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
616 tester.clear_key_calls();
617 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
620 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
624 EXPECT_EQ(tester.key_calls.size(), 1);
626 kPhysicalKeyA, kLogicalKeyA,
"", kNotSynthesized);
627 tester.clear_key_calls();
628 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
632 KeyboardTester tester{GetContext()};
633 tester.Responding(
true);
638 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
639 WmKeyDownInfo{VK_LEFT, kScanCodeArrowLeft, kExtended, kWasUp}.Build(
642 EXPECT_EQ(tester.key_calls.size(), 1);
644 kPhysicalArrowLeft, kLogicalArrowLeft,
"",
646 tester.clear_key_calls();
647 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
650 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
651 WmKeyUpInfo{VK_LEFT, kScanCodeArrowLeft, kExtended}.Build(
654 EXPECT_EQ(tester.key_calls.size(), 1);
656 kPhysicalArrowLeft, kLogicalArrowLeft,
"",
658 tester.clear_key_calls();
659 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
662 TEST_F(KeyboardTest, ArrowLeftUnhandled) {
663 KeyboardTester tester{GetContext()};
664 tester.Responding(
false);
669 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
670 WmKeyDownInfo{VK_LEFT, kScanCodeArrowLeft, kExtended, kWasUp}.Build(
673 EXPECT_EQ(tester.key_calls.size(), 1);
675 kPhysicalArrowLeft, kLogicalArrowLeft,
"",
677 tester.clear_key_calls();
678 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
681 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
682 WmKeyUpInfo{VK_LEFT, kScanCodeArrowLeft, kExtended}.Build(
685 EXPECT_EQ(tester.key_calls.size(), 1);
687 kPhysicalArrowLeft, kLogicalArrowLeft,
"",
689 tester.clear_key_calls();
690 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
693 TEST_F(KeyboardTest, ShiftLeftUnhandled) {
694 KeyboardTester tester{GetContext()};
695 tester.Responding(
false);
700 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
701 KeyStateChange{VK_LSHIFT,
true,
false},
705 EXPECT_EQ(tester.key_calls.size(), 1);
707 kPhysicalShiftLeft, kLogicalShiftLeft,
"",
709 tester.clear_key_calls();
710 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
713 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
717 EXPECT_EQ(tester.key_calls.size(), 1);
719 kPhysicalShiftLeft, kLogicalShiftLeft,
"",
721 tester.clear_key_calls();
722 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
725 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
726 KeyStateChange{VK_LSHIFT,
false,
true},
730 EXPECT_EQ(tester.key_calls.size(), 1);
732 kPhysicalShiftLeft, kLogicalShiftLeft,
"",
734 tester.clear_key_calls();
735 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
738 TEST_F(KeyboardTest, ShiftRightUnhandled) {
739 KeyboardTester tester{GetContext()};
740 tester.Responding(
false);
745 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
746 KeyStateChange{VK_RSHIFT,
true,
false},
750 EXPECT_EQ(tester.key_calls.size(), 1);
752 kPhysicalShiftRight, kLogicalShiftRight,
"",
754 tester.clear_key_calls();
755 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
758 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
759 KeyStateChange{VK_RSHIFT,
false,
true},
763 EXPECT_EQ(tester.key_calls.size(), 1);
765 kPhysicalShiftRight, kLogicalShiftRight,
"",
767 tester.clear_key_calls();
768 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
771 TEST_F(KeyboardTest, CtrlLeftUnhandled) {
772 KeyboardTester tester{GetContext()};
773 tester.Responding(
false);
778 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
779 KeyStateChange{VK_LCONTROL,
true,
false},
780 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
783 EXPECT_EQ(tester.key_calls.size(), 1);
785 kPhysicalControlLeft, kLogicalControlLeft,
"",
787 tester.clear_key_calls();
788 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
791 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
792 KeyStateChange{VK_LCONTROL,
false,
true},
793 WmKeyUpInfo{VK_SHIFT, kScanCodeControl, kNotExtended}.Build(
796 EXPECT_EQ(tester.key_calls.size(), 1);
798 kPhysicalControlLeft, kLogicalControlLeft,
"",
800 tester.clear_key_calls();
801 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
804 TEST_F(KeyboardTest, CtrlRightUnhandled) {
805 KeyboardTester tester{GetContext()};
806 tester.Responding(
false);
811 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
812 KeyStateChange{VK_RCONTROL,
true,
false},
813 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kExtended, kWasUp}.Build(
816 EXPECT_EQ(tester.key_calls.size(), 1);
818 kPhysicalControlRight, kLogicalControlRight,
"",
820 tester.clear_key_calls();
821 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
824 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
825 KeyStateChange{VK_RCONTROL,
false,
true},
826 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kExtended}.Build(
829 EXPECT_EQ(tester.key_calls.size(), 1);
831 kPhysicalControlRight, kLogicalControlRight,
"",
833 tester.clear_key_calls();
834 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
838 KeyboardTester tester{GetContext()};
839 tester.Responding(
false);
844 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
845 KeyStateChange{VK_LMENU,
true,
false},
846 WmSysKeyDownInfo{VK_MENU, kScanCodeAlt, kNotExtended, kWasUp}.Build(
849 EXPECT_EQ(tester.key_calls.size(), 1);
851 kPhysicalAltLeft, kLogicalAltLeft,
"", kNotSynthesized);
852 tester.clear_key_calls();
854 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
857 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
858 KeyStateChange{VK_LMENU,
false,
true},
859 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kNotExtended}.Build(
862 EXPECT_EQ(tester.key_calls.size(), 1);
864 kPhysicalAltLeft, kLogicalAltLeft,
"", kNotSynthesized);
865 tester.clear_key_calls();
867 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
870 TEST_F(KeyboardTest, AltRightUnhandled) {
871 KeyboardTester tester{GetContext()};
872 tester.Responding(
false);
877 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
878 KeyStateChange{VK_RMENU,
true,
false},
879 WmSysKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build(
882 EXPECT_EQ(tester.key_calls.size(), 1);
884 kPhysicalAltRight, kLogicalAltRight,
"",
886 tester.clear_key_calls();
888 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
891 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
892 KeyStateChange{VK_RMENU,
false,
true},
893 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build(
896 EXPECT_EQ(tester.key_calls.size(), 1);
898 kPhysicalAltRight, kLogicalAltRight,
"",
900 tester.clear_key_calls();
902 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
905 TEST_F(KeyboardTest, MetaLeftUnhandled) {
906 KeyboardTester tester{GetContext()};
907 tester.Responding(
false);
912 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
913 KeyStateChange{VK_LWIN,
true,
false},
914 WmKeyDownInfo{VK_LWIN, kScanCodeMetaLeft, kExtended, kWasUp}.Build(
917 EXPECT_EQ(tester.key_calls.size(), 1);
919 kPhysicalMetaLeft, kLogicalMetaLeft,
"",
921 tester.clear_key_calls();
922 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
925 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
926 KeyStateChange{VK_LWIN,
false,
true},
927 WmKeyUpInfo{VK_LWIN, kScanCodeMetaLeft, kExtended}.Build(kWmResultZero)});
929 EXPECT_EQ(tester.key_calls.size(), 1);
931 kPhysicalMetaLeft, kLogicalMetaLeft,
"",
933 tester.clear_key_calls();
934 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
937 TEST_F(KeyboardTest, MetaRightUnhandled) {
938 KeyboardTester tester{GetContext()};
939 tester.Responding(
false);
944 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
945 KeyStateChange{VK_RWIN,
true,
false},
946 WmKeyDownInfo{VK_RWIN, kScanCodeMetaRight, kExtended, kWasUp}.Build(
949 EXPECT_EQ(tester.key_calls.size(), 1);
951 kPhysicalMetaRight, kLogicalMetaRight,
"",
953 tester.clear_key_calls();
954 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
957 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
958 KeyStateChange{VK_RWIN,
false,
true},
959 WmKeyUpInfo{VK_RWIN, kScanCodeMetaRight, kExtended}.Build(
962 EXPECT_EQ(tester.key_calls.size(), 1);
964 kPhysicalMetaRight, kLogicalMetaRight,
"",
966 tester.clear_key_calls();
967 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
972 KeyboardTester tester{GetContext()};
973 tester.Responding(
true);
976 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
983 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
986 WmCharInfo{
'a',
kScanCodeKeyA, kNotExtended, kWasDown}.Build(
989 EXPECT_EQ(tester.key_calls.size(), 2);
991 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
993 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
994 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
1000 TEST_F(KeyboardTest, RestartClearsKeyboardState) {
1001 KeyboardTester tester{GetContext()};
1002 tester.Responding(
true);
1005 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1012 tester.ResetKeyboard();
1016 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1019 WmCharInfo{
'a',
kScanCodeKeyA, kNotExtended, kWasDown}.Build(
1022 EXPECT_EQ(tester.key_calls.size(), 2);
1024 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
1026 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
1027 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
1033 KeyboardTester tester{GetContext()};
1034 tester.Responding(
false);
1039 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1040 KeyStateChange{VK_LSHIFT,
true,
true},
1044 EXPECT_EQ(tester.key_calls.size(), 1);
1046 kPhysicalShiftLeft, kLogicalShiftLeft,
"",
1048 tester.clear_key_calls();
1049 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1052 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1058 EXPECT_EQ(tester.key_calls.size(), 2);
1060 kPhysicalKeyA, kLogicalKeyA,
"A", kNotSynthesized);
1062 tester.clear_key_calls();
1063 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1066 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1067 KeyStateChange{VK_LSHIFT,
false,
true},
1071 EXPECT_EQ(tester.key_calls.size(), 1);
1073 kPhysicalShiftLeft, kLogicalShiftLeft,
"",
1075 tester.clear_key_calls();
1076 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1079 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1083 EXPECT_EQ(tester.key_calls.size(), 1);
1085 kPhysicalKeyA, kLogicalKeyA,
"", kNotSynthesized);
1086 tester.clear_key_calls();
1087 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1093 KeyboardTester tester{GetContext()};
1094 tester.Responding(
false);
1099 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1100 KeyStateChange{VK_LCONTROL,
true,
true},
1101 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1104 EXPECT_EQ(tester.key_calls.size(), 1);
1106 kPhysicalControlLeft, kLogicalControlLeft,
"",
1108 tester.clear_key_calls();
1109 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1112 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1115 WmCharInfo{0x01,
kScanCodeKeyA, kNotExtended, kWasUp}.Build(
1118 EXPECT_EQ(tester.key_calls.size(), 1);
1120 kPhysicalKeyA, kLogicalKeyA,
"", kNotSynthesized);
1121 tester.clear_key_calls();
1122 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1125 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1129 EXPECT_EQ(tester.key_calls.size(), 1);
1131 kPhysicalKeyA, kLogicalKeyA,
"", kNotSynthesized);
1132 tester.clear_key_calls();
1133 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1136 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1137 KeyStateChange{VK_LCONTROL,
false,
true},
1138 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1141 EXPECT_EQ(tester.key_calls.size(), 1);
1143 kPhysicalControlLeft, kLogicalControlLeft,
"",
1145 tester.clear_key_calls();
1146 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1151 KeyboardTester tester{GetContext()};
1152 tester.Responding(
false);
1157 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1158 KeyStateChange{VK_LCONTROL,
true,
true},
1159 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1162 EXPECT_EQ(tester.key_calls.size(), 1);
1164 kPhysicalControlLeft, kLogicalControlLeft,
"",
1166 tester.clear_key_calls();
1167 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1170 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1171 WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp}
1172 .Build(kWmResultZero)});
1174 EXPECT_EQ(tester.key_calls.size(), 1);
1176 kPhysicalDigit1, kLogicalDigit1,
"", kNotSynthesized);
1177 tester.clear_key_calls();
1178 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1181 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1182 WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build(
1185 EXPECT_EQ(tester.key_calls.size(), 1);
1187 kPhysicalDigit1, kLogicalDigit1,
"", kNotSynthesized);
1188 tester.clear_key_calls();
1189 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1192 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1193 KeyStateChange{VK_LCONTROL,
false,
true},
1194 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1197 EXPECT_EQ(tester.key_calls.size(), 1);
1199 kPhysicalControlLeft, kLogicalControlLeft,
"",
1201 tester.clear_key_calls();
1202 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1208 KeyboardTester tester{GetContext()};
1209 tester.Responding(
false);
1211 tester.SetLayout(LayoutFrench);
1214 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1215 WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp}
1216 .Build(kWmResultZero),
1217 WmCharInfo{
'&', kScanCodeDigit1, kNotExtended, kWasUp}.Build(
1220 EXPECT_EQ(tester.key_calls.size(), 2);
1222 kPhysicalDigit1, kLogicalDigit1,
"&", kNotSynthesized);
1224 tester.clear_key_calls();
1225 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1228 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1229 WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build(
1232 EXPECT_EQ(tester.key_calls.size(), 1);
1234 kPhysicalDigit1, kLogicalDigit1,
"", kNotSynthesized);
1235 tester.clear_key_calls();
1236 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1241 KeyboardTester tester{GetContext()};
1242 tester.Responding(
false);
1247 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1248 KeyStateChange{VK_LCONTROL,
true,
true},
1249 WmKeyDownInfo{VK_LCONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1251 KeyStateChange{VK_RMENU,
true,
true},
1252 WmKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build(
1255 EXPECT_EQ(tester.key_calls.size(), 2);
1257 kPhysicalControlLeft, kLogicalControlLeft,
"",
1260 kPhysicalAltRight, kLogicalAltRight,
"",
1262 tester.clear_key_calls();
1263 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1266 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1267 WmKeyDownInfo{kVirtualKeyQ, kScanCodeKeyQ, kNotExtended, kWasUp}.Build(
1269 WmCharInfo{
'@', kScanCodeKeyQ, kNotExtended, kWasUp}.Build(
1272 EXPECT_EQ(tester.key_calls.size(), 2);
1274 kPhysicalKeyQ, kLogicalKeyQ,
"@", kNotSynthesized);
1276 tester.clear_key_calls();
1277 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1280 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1281 WmKeyUpInfo{kVirtualKeyQ, kScanCodeKeyQ, kNotExtended}.Build(
1284 EXPECT_EQ(tester.key_calls.size(), 1);
1286 kPhysicalKeyQ, kLogicalKeyQ,
"", kNotSynthesized);
1287 tester.clear_key_calls();
1288 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1293 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1294 KeyStateChange{VK_LCONTROL,
false,
true},
1295 ExpectForgedMessage{
1296 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1298 KeyStateChange{VK_RMENU,
false,
true},
1299 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build(
1300 kWmResultDefault)});
1302 EXPECT_EQ(tester.key_calls.size(), 2);
1304 kPhysicalControlLeft, kLogicalControlLeft,
"",
1307 kPhysicalAltRight, kLogicalAltRight,
"",
1309 tester.clear_key_calls();
1311 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1328 KeyboardTester tester{GetContext()};
1329 tester.Responding(
false);
1335 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1336 KeyStateChange{VK_LCONTROL,
true,
true},
1337 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1339 KeyStateChange{VK_RMENU,
true,
true},
1340 WmKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build(
1343 EXPECT_EQ(tester.key_calls.size(), 2);
1345 kPhysicalControlLeft, kLogicalControlLeft,
"",
1348 kPhysicalAltRight, kLogicalAltRight,
"",
1350 tester.clear_key_calls();
1351 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1356 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1357 KeyStateChange{VK_LCONTROL,
false,
true},
1358 ExpectForgedMessage{
1359 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1361 KeyStateChange{VK_RMENU,
false,
true},
1362 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build(
1363 kWmResultDefault)});
1364 EXPECT_EQ(tester.key_calls.size(), 2);
1366 kPhysicalControlLeft, kLogicalControlLeft,
"",
1369 kPhysicalAltRight, kLogicalAltRight,
"",
1371 tester.clear_key_calls();
1373 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1377 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1378 KeyStateChange{VK_LCONTROL,
true,
false},
1379 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1381 KeyStateChange{VK_RMENU,
true,
true},
1382 WmKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build(
1385 EXPECT_EQ(tester.key_calls.size(), 2);
1387 kPhysicalControlLeft, kLogicalControlLeft,
"",
1390 kPhysicalAltRight, kLogicalAltRight,
"",
1392 tester.clear_key_calls();
1393 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1398 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1399 KeyStateChange{VK_LCONTROL,
false,
false},
1400 ExpectForgedMessage{
1401 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1403 KeyStateChange{VK_RMENU,
false,
false},
1404 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build(
1405 kWmResultDefault)});
1406 EXPECT_EQ(tester.key_calls.size(), 2);
1408 kPhysicalControlLeft, kLogicalControlLeft,
"",
1411 kPhysicalAltRight, kLogicalAltRight,
"",
1413 tester.clear_key_calls();
1415 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1418 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1419 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1421 EXPECT_EQ(tester.key_calls.size(), 1);
1424 tester.clear_key_calls();
1425 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
1431 KeyboardTester tester{GetContext()};
1432 tester.Responding(
false);
1434 tester.SetLayout(LayoutFrench);
1437 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1438 WmKeyDownInfo{0xDD, kScanCodeBracketLeft, kNotExtended, kWasUp}.Build(
1440 WmDeadCharInfo{
'^', kScanCodeBracketLeft, kNotExtended, kWasUp}.Build(
1443 EXPECT_EQ(tester.key_calls.size(), 1);
1445 kPhysicalBracketLeft, kLogicalBracketRight,
"^",
1447 tester.clear_key_calls();
1448 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1451 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1452 WmKeyUpInfo{0xDD, kScanCodeBracketLeft, kNotExtended}.Build(
1455 EXPECT_EQ(tester.key_calls.size(), 1);
1457 kPhysicalBracketLeft, kLogicalBracketRight,
"",
1459 tester.clear_key_calls();
1460 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1463 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1464 WmKeyDownInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended, kWasUp}.Build(
1466 WmCharInfo{0xEA, kScanCodeKeyE, kNotExtended, kWasUp}.Build(
1469 EXPECT_EQ(tester.key_calls.size(), 2);
1471 kPhysicalKeyE, kLogicalKeyE,
"ê", kNotSynthesized);
1473 tester.clear_key_calls();
1474 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1477 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1478 WmKeyUpInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended}.Build(
1481 EXPECT_EQ(tester.key_calls.size(), 1);
1483 kPhysicalKeyE, kLogicalKeyE,
"", kNotSynthesized);
1484 tester.clear_key_calls();
1485 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1493 TEST_F(KeyboardTest, DeadKeyWithoutDeadMaskThatCombines) {
1494 KeyboardTester tester{GetContext()};
1495 tester.Responding(
false);
1498 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1499 KeyStateChange{VK_LSHIFT,
true,
true},
1503 EXPECT_EQ(tester.key_calls.size(), 1);
1505 kPhysicalShiftLeft, kLogicalShiftLeft,
"",
1507 tester.clear_key_calls();
1508 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1511 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1512 WmKeyDownInfo{
'6', kScanCodeDigit6, kNotExtended, kWasUp}.Build(
1514 WmDeadCharInfo{
'^', kScanCodeDigit6, kNotExtended, kWasUp}.Build(
1517 EXPECT_EQ(tester.key_calls.size(), 1);
1519 kPhysicalDigit6, kLogicalDigit6,
"6", kNotSynthesized);
1520 tester.clear_key_calls();
1521 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1524 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1525 WmKeyUpInfo{
'6', kScanCodeDigit6, kNotExtended}.Build(kWmResultZero)});
1527 EXPECT_EQ(tester.key_calls.size(), 1);
1529 kPhysicalDigit6, kLogicalDigit6,
"", kNotSynthesized);
1530 tester.clear_key_calls();
1531 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1534 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1535 KeyStateChange{VK_LSHIFT,
false,
true},
1539 EXPECT_EQ(tester.key_calls.size(), 1);
1541 kPhysicalShiftLeft, kLogicalShiftLeft,
"",
1543 tester.clear_key_calls();
1544 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1547 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1548 WmKeyDownInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended, kWasUp}.Build(
1550 WmCharInfo{0xEA, kScanCodeKeyE, kNotExtended, kWasUp}.Build(
1553 EXPECT_EQ(tester.key_calls.size(), 2);
1555 kPhysicalKeyE, kLogicalKeyE,
"ê", kNotSynthesized);
1557 tester.clear_key_calls();
1558 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1561 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1562 WmKeyUpInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended}.Build(
1565 EXPECT_EQ(tester.key_calls.size(), 1);
1567 kPhysicalKeyE, kLogicalKeyE,
"", kNotSynthesized);
1568 tester.clear_key_calls();
1569 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1574 TEST_F(KeyboardTest, DeadKeyThatDoesNotCombine) {
1575 KeyboardTester tester{GetContext()};
1576 tester.Responding(
false);
1578 tester.SetLayout(LayoutFrench);
1581 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1582 WmKeyDownInfo{0xDD, kScanCodeBracketLeft, kNotExtended, kWasUp}.Build(
1584 WmDeadCharInfo{
'^', kScanCodeBracketLeft, kNotExtended, kWasUp}.Build(
1587 EXPECT_EQ(tester.key_calls.size(), 1);
1589 kPhysicalBracketLeft, kLogicalBracketRight,
"^",
1591 tester.clear_key_calls();
1592 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1595 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1596 WmKeyUpInfo{0xDD, kScanCodeBracketLeft, kNotExtended}.Build(
1599 EXPECT_EQ(tester.key_calls.size(), 1);
1601 kPhysicalBracketLeft, kLogicalBracketRight,
"",
1603 tester.clear_key_calls();
1604 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1607 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1608 WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp}
1609 .Build(kWmResultZero),
1610 WmCharInfo{
'^', kScanCodeDigit1, kNotExtended, kWasUp}.Build(
1612 WmCharInfo{
'&', kScanCodeDigit1, kNotExtended, kWasUp}.Build(
1615 EXPECT_EQ(tester.key_calls.size(), 3);
1617 kPhysicalDigit1, kLogicalDigit1,
"^", kNotSynthesized);
1620 tester.clear_key_calls();
1626 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1629 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1630 WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build(
1633 EXPECT_EQ(tester.key_calls.size(), 1);
1635 kPhysicalDigit1, kLogicalDigit1,
"", kNotSynthesized);
1636 tester.clear_key_calls();
1637 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1643 TEST_F(KeyboardTest, DeadKeyTwiceThenLetter) {
1644 KeyboardTester tester{GetContext()};
1645 tester.Responding(
false);
1650 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1651 WmKeyDownInfo{0xC0, kScanCodeBackquote, kNotExtended, kWasUp}.Build(
1653 WmDeadCharInfo{
'`', kScanCodeBackquote, kNotExtended, kWasUp}.Build(
1656 EXPECT_EQ(tester.key_calls.size(), 1);
1658 kPhysicalBackquote, kLogicalBackquote,
"`",
1660 tester.clear_key_calls();
1661 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1664 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1665 WmKeyUpInfo{0xC0, kScanCodeBackquote, kNotExtended}.Build(
1668 EXPECT_EQ(tester.key_calls.size(), 1);
1670 kPhysicalBackquote, kLogicalBackquote,
"",
1672 tester.clear_key_calls();
1673 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1677 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
1678 tester.LateResponding(
1679 [&recorded_callbacks](
1680 const FlutterKeyEvent* event,
1681 MockKeyResponseController::ResponseCallback
callback) {
1682 recorded_callbacks.push_back(
callback);
1685 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1686 WmKeyDownInfo{0xC0, kScanCodeBackquote, kNotExtended, kWasUp}.Build(
1688 WmCharInfo{
'`', kScanCodeBackquote, kNotExtended, kWasUp, kBeingReleased,
1689 kNoContext, 1,
true}
1690 .Build(kWmResultZero),
1691 WmCharInfo{
'`', kScanCodeBackquote, kNotExtended, kWasUp}.Build(
1694 EXPECT_EQ(recorded_callbacks.size(), 1);
1695 EXPECT_EQ(tester.key_calls.size(), 1);
1697 kPhysicalBackquote, kLogicalBackquote,
"`",
1699 tester.clear_key_calls();
1701 recorded_callbacks.front()(
false);
1702 EXPECT_EQ(tester.key_calls.size(), 2);
1705 tester.clear_key_calls();
1709 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1711 tester.Responding(
false);
1714 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1715 WmKeyUpInfo{0xC0, kScanCodeBackquote, kNotExtended}.Build(
1718 EXPECT_EQ(tester.key_calls.size(), 1);
1720 kPhysicalBackquote, kLogicalBackquote,
"",
1722 tester.clear_key_calls();
1723 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1728 KeyboardTester tester{GetContext()};
1729 tester.Responding(
false);
1735 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1736 WmKeyDownInfo{kVirtualKeyW, kScanCodeKeyW, kNotExtended, kWasUp}.Build(
1738 WmCharInfo{0xd800, kScanCodeKeyW, kNotExtended, kWasUp}.Build(
1740 WmCharInfo{0xdf45, kScanCodeKeyW, kNotExtended, kWasUp}.Build(
1743 const char* st = tester.key_calls[0].key_event.character;
1745 EXPECT_EQ(tester.key_calls.size(), 2);
1747 kPhysicalKeyW, kLogicalKeyW,
"𐍅", kNotSynthesized);
1749 tester.clear_key_calls();
1750 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 3);
1753 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1754 WmKeyUpInfo{kVirtualKeyW, kScanCodeKeyW, kNotExtended}.Build(
1757 EXPECT_EQ(tester.key_calls.size(), 1);
1759 kPhysicalKeyW, kLogicalKeyW,
"", kNotSynthesized);
1760 tester.clear_key_calls();
1761 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1765 KeyboardTester tester{GetContext()};
1766 tester.Responding(
false);
1769 Win32Message event1 =
1770 WmKeyDownInfo{VK_BACK, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
1772 Win32Message event2 =
1773 WmKeyUpInfo{VK_BACK, kScanCodeBackspace, kNotExtended}.Build(
1777 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1778 KeyStateChange{VK_LSHIFT,
true,
true}, event1});
1779 EXPECT_EQ(tester.key_calls.size(), 2);
1781 kPhysicalShiftLeft, kLogicalShiftLeft,
"", kSynthesized);
1782 tester.clear_key_calls();
1783 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1785 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1786 KeyStateChange{VK_LSHIFT,
false,
true}, event2});
1787 EXPECT_EQ(tester.key_calls.size(), 2);
1789 kPhysicalShiftLeft, kLogicalShiftLeft,
"", kSynthesized);
1790 tester.clear_key_calls();
1791 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1794 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1795 KeyStateChange{VK_RSHIFT,
true,
true}, event1});
1796 EXPECT_EQ(tester.key_calls.size(), 2);
1798 kPhysicalShiftRight, kLogicalShiftRight,
"",
1800 tester.clear_key_calls();
1801 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1803 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1804 KeyStateChange{VK_RSHIFT,
false,
true}, event2});
1805 EXPECT_EQ(tester.key_calls.size(), 2);
1807 kPhysicalShiftRight, kLogicalShiftRight,
"",
1809 tester.clear_key_calls();
1810 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1813 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1814 KeyStateChange{VK_LCONTROL,
true,
true}, event1});
1815 EXPECT_EQ(tester.key_calls.size(), 2);
1817 kPhysicalControlLeft, kLogicalControlLeft,
"",
1819 tester.clear_key_calls();
1820 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1822 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1823 KeyStateChange{VK_LCONTROL,
false,
true}, event2});
1824 EXPECT_EQ(tester.key_calls.size(), 2);
1826 kPhysicalControlLeft, kLogicalControlLeft,
"",
1828 tester.clear_key_calls();
1829 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1832 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1833 KeyStateChange{VK_RCONTROL,
true,
true}, event1});
1834 EXPECT_EQ(tester.key_calls.size(), 2);
1836 kPhysicalControlRight, kLogicalControlRight,
"",
1838 tester.clear_key_calls();
1839 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1841 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1842 KeyStateChange{VK_RCONTROL,
false,
true}, event2});
1843 EXPECT_EQ(tester.key_calls.size(), 2);
1845 kPhysicalControlRight, kLogicalControlRight,
"",
1847 tester.clear_key_calls();
1848 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1851 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1852 KeyStateChange{VK_LMENU,
true,
true}, event1});
1853 EXPECT_EQ(tester.key_calls.size(), 2);
1855 kPhysicalAltLeft, kLogicalAltLeft,
"", kSynthesized);
1856 tester.clear_key_calls();
1857 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1859 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1860 KeyStateChange{VK_LMENU,
false,
true}, event2});
1861 EXPECT_EQ(tester.key_calls.size(), 2);
1863 kPhysicalAltLeft, kLogicalAltLeft,
"", kSynthesized);
1864 tester.clear_key_calls();
1865 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1868 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1869 KeyStateChange{VK_RMENU,
true,
true}, event1});
1870 EXPECT_EQ(tester.key_calls.size(), 2);
1872 kPhysicalAltRight, kLogicalAltRight,
"", kSynthesized);
1873 tester.clear_key_calls();
1874 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1876 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1877 KeyStateChange{VK_RMENU,
false,
true}, event2});
1878 EXPECT_EQ(tester.key_calls.size(), 2);
1880 kPhysicalAltRight, kLogicalAltRight,
"", kSynthesized);
1881 tester.clear_key_calls();
1882 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1885 tester.InjectKeyboardChanges(
1886 std::vector<KeyboardChange>{KeyStateChange{VK_LWIN,
true,
true}, event1});
1887 EXPECT_EQ(tester.key_calls.size(), 2);
1889 kPhysicalMetaLeft, kLogicalMetaLeft,
"", kSynthesized);
1890 tester.clear_key_calls();
1891 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1893 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1894 KeyStateChange{VK_LWIN,
false,
true}, event2});
1895 EXPECT_EQ(tester.key_calls.size(), 2);
1897 kPhysicalMetaLeft, kLogicalMetaLeft,
"", kSynthesized);
1898 tester.clear_key_calls();
1899 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1902 tester.InjectKeyboardChanges(
1903 std::vector<KeyboardChange>{KeyStateChange{VK_RWIN,
true,
true}, event1});
1904 EXPECT_EQ(tester.key_calls.size(), 2);
1906 kPhysicalMetaRight, kLogicalMetaRight,
"", kSynthesized);
1907 tester.clear_key_calls();
1908 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1910 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1911 KeyStateChange{VK_RWIN,
false,
true}, event2});
1912 EXPECT_EQ(tester.key_calls.size(), 2);
1914 kPhysicalMetaRight, kLogicalMetaRight,
"", kSynthesized);
1915 tester.clear_key_calls();
1916 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1920 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1921 KeyStateChange{VK_CAPITAL,
false,
true}, event1});
1922 EXPECT_EQ(tester.key_calls.size(), 3);
1924 kPhysicalCapsLock, kLogicalCapsLock,
"", kSynthesized);
1926 kPhysicalCapsLock, kLogicalCapsLock,
"", kSynthesized);
1927 tester.clear_key_calls();
1928 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1930 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1931 KeyStateChange{VK_CAPITAL,
false,
false}, event2});
1932 EXPECT_EQ(tester.key_calls.size(), 3);
1934 kPhysicalCapsLock, kLogicalCapsLock,
"", kSynthesized);
1936 kPhysicalCapsLock, kLogicalCapsLock,
"", kSynthesized);
1937 tester.clear_key_calls();
1938 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1941 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1942 KeyStateChange{VK_SCROLL,
true,
true}, event1});
1943 EXPECT_EQ(tester.key_calls.size(), 2);
1945 kPhysicalScrollLock, kLogicalScrollLock,
"",
1947 tester.clear_key_calls();
1948 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1950 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1951 KeyStateChange{VK_SCROLL,
true,
false}, event2});
1952 EXPECT_EQ(tester.key_calls.size(), 3);
1954 kPhysicalScrollLock, kLogicalScrollLock,
"",
1957 kPhysicalScrollLock, kLogicalScrollLock,
"",
1959 tester.clear_key_calls();
1960 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1963 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1964 KeyStateChange{VK_NUMLOCK,
true,
false}, event1});
1969 EXPECT_EQ(tester.key_calls.size(), 2);
1971 kPhysicalNumLock, kLogicalNumLock,
"", kSynthesized);
1972 tester.clear_key_calls();
1973 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1975 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1976 KeyStateChange{VK_NUMLOCK,
false,
true}, event2});
1977 EXPECT_EQ(tester.key_calls.size(), 4);
1979 kPhysicalNumLock, kLogicalNumLock,
"", kSynthesized);
1981 kPhysicalNumLock, kLogicalNumLock,
"", kSynthesized);
1983 kPhysicalNumLock, kLogicalNumLock,
"", kSynthesized);
1984 tester.clear_key_calls();
1985 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1992 TEST_F(KeyboardTest, ImeExtendedEventsAreIgnored) {
1993 KeyboardTester tester{GetContext()};
1994 tester.Responding(
false);
2002 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2003 KeyStateChange{VK_RCONTROL,
true,
false},
2004 WmKeyDownInfo{VK_PROCESSKEY, kScanCodeControl, kExtended, kWasUp}.Build(
2007 EXPECT_EQ(tester.key_calls.size(), 1);
2010 tester.clear_key_calls();
2011 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2020 TEST_F(KeyboardTest, UpOnlyImeEventsAreCorrectlyHandled) {
2021 KeyboardTester tester{GetContext()};
2022 tester.Responding(
true);
2027 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2028 KeyStateChange{VK_LSHIFT,
true,
false},
2031 WmKeyDownInfo{VK_PROCESSKEY, kScanCodeDigit2, kNotExtended, kWasUp}.Build(
2033 KeyStateChange{VK_LSHIFT,
false,
true},
2036 WmKeyUpInfo{
'2', kScanCodeDigit2, kNotExtended, kWasUp}.Build(
2039 EXPECT_EQ(tester.key_calls.size(), 4);
2041 kPhysicalShiftLeft, kLogicalShiftLeft,
"",
2046 kPhysicalShiftLeft, kLogicalShiftLeft,
"",
2050 tester.clear_key_calls();
2059 TEST_F(KeyboardTest, SlowFrameworkResponse) {
2060 KeyboardTester tester{GetContext()};
2062 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
2065 tester.LateResponding(
2066 [&recorded_callbacks](
2067 const FlutterKeyEvent* event,
2068 MockKeyResponseController::ResponseCallback
callback) {
2069 recorded_callbacks.push_back(
callback);
2073 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2080 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2083 WmCharInfo{
'a',
kScanCodeKeyA, kNotExtended, kWasDown}.Build(
2086 EXPECT_EQ(tester.key_calls.size(), 1);
2088 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
2089 EXPECT_EQ(recorded_callbacks.size(), 1);
2090 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2093 recorded_callbacks.front()(
false);
2095 EXPECT_EQ(tester.key_calls.size(), 3);
2096 EXPECT_EQ(recorded_callbacks.size(), 2);
2099 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
2100 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2103 recorded_callbacks.back()(
false);
2105 EXPECT_EQ(tester.key_calls.size(), 4);
2107 tester.clear_key_calls();
2108 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2122 TEST_F(KeyboardTest, SlowFrameworkResponseForIdenticalEvents) {
2123 KeyboardTester tester{GetContext()};
2124 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
2127 tester.LateResponding(
2128 [&recorded_callbacks](
2129 const FlutterKeyEvent* event,
2130 MockKeyResponseController::ResponseCallback
callback) {
2131 recorded_callbacks.push_back(
callback);
2135 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2141 EXPECT_EQ(tester.key_calls.size(), 1);
2143 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
2144 tester.clear_key_calls();
2145 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2148 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2152 EXPECT_EQ(tester.key_calls.size(), 0);
2153 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2156 EXPECT_EQ(recorded_callbacks.size(), 1);
2157 recorded_callbacks.front()(
false);
2159 EXPECT_EQ(tester.key_calls.size(), 2);
2162 kPhysicalKeyA, kLogicalKeyA,
"", kNotSynthesized);
2163 tester.clear_key_calls();
2164 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2167 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2175 EXPECT_EQ(recorded_callbacks.size(), 2);
2176 EXPECT_EQ(tester.key_calls.size(), 0);
2177 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2181 recorded_callbacks.back()(
false);
2182 EXPECT_EQ(tester.key_calls.size(), 1);
2184 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
2185 tester.clear_key_calls();
2186 EXPECT_EQ(recorded_callbacks.size(), 3);
2187 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2190 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2194 EXPECT_EQ(tester.key_calls.size(), 0);
2195 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2199 KeyboardTester tester{GetContext()};
2200 tester.Responding(
false);
2204 tester.InjectPlatformMessage(
2205 "flutter/textinput",
"TextInput.setClient",
2206 R
"|([108, {"inputAction": "TextInputAction.none"}])|");
2209 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2210 WmKeyDownInfo{VK_RETURN, kScanCodeEnter, kNotExtended, kWasUp}.Build(
2212 WmCharInfo{
'\n', kScanCodeEnter, kNotExtended, kWasUp}.Build(
2215 EXPECT_EQ(tester.key_calls.size(), 2);
2217 kPhysicalEnter, kLogicalEnter,
"", kNotSynthesized);
2219 tester.key_calls[1],
2221 R
"|("method":"TextInputClient.performAction",)|"
2222 R"|("args":[108,"TextInputAction.none"])|"
2224 tester.clear_key_calls();
2225 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2228 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2229 WmKeyUpInfo{VK_RETURN, kScanCodeEnter, kNotExtended}.Build(
2232 EXPECT_EQ(tester.key_calls.size(), 1);
2234 kPhysicalEnter, kLogicalEnter,
"", kNotSynthesized);
2235 tester.clear_key_calls();
2236 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2243 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2249 EXPECT_EQ(tester.key_calls.size(), 2);
2251 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
2253 tester.clear_key_calls();
2256 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2260 EXPECT_EQ(tester.key_calls.size(), 1);
2262 kPhysicalKeyA, kLogicalKeyA,
"", kNotSynthesized);
2263 tester.clear_key_calls();
2266 TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse) {
2276 KeyboardTester tester{GetContext()};
2277 tester.Responding(
false);
2282 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2288 EXPECT_EQ(tester.key_calls.size(), 2);
2290 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
2292 tester.clear_key_calls();
2293 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2296 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2300 EXPECT_EQ(tester.key_calls.size(), 1);
2302 kPhysicalKeyA, kLogicalKeyA,
"", kNotSynthesized);
2303 tester.clear_key_calls();
2304 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2309 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2310 WmKeyDownInfo{VK_BACK, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
2312 WmCharInfo{0x8, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
2314 WmKeyUpInfo{VK_BACK, kScanCodeBackspace, kNotExtended}.Build(
2316 WmKeyDownInfo{VK_PACKET, 0, kNotExtended, kWasUp}.Build(kWmResultDefault),
2317 WmCharInfo{0xe0 , 0, kNotExtended, kWasUp}.Build(kWmResultZero),
2318 WmKeyUpInfo{VK_PACKET, 0, kNotExtended}.Build(kWmResultDefault)});
2320 EXPECT_EQ(tester.key_calls.size(), 3);
2322 kPhysicalBackspace, kLogicalBackspace,
"",
2325 kPhysicalBackspace, kLogicalBackspace,
"",
2328 tester.clear_key_calls();
2334 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 3);
2337 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2338 WmKeyUpInfo{kVirtualKeyF, kScanCodeKeyF, kNotExtended,
2340 .Build(kWmResultZero)});
2342 EXPECT_EQ(tester.key_calls.size(), 1);
2345 tester.clear_key_calls();
2346 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2350 bool backspace_response) {
2360 KeyboardTester tester{context};
2361 tester.Responding(
false);
2366 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2372 EXPECT_EQ(tester.key_calls.size(), 2);
2374 kPhysicalKeyA, kLogicalKeyA,
"a", kNotSynthesized);
2376 tester.clear_key_calls();
2377 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2380 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2384 EXPECT_EQ(tester.key_calls.size(), 1);
2386 kPhysicalKeyA, kLogicalKeyA,
"", kNotSynthesized);
2387 tester.clear_key_calls();
2388 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2390 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
2391 tester.LateResponding(
2392 [&recorded_callbacks](
2393 const FlutterKeyEvent* event,
2394 MockKeyResponseController::ResponseCallback
callback) {
2395 recorded_callbacks.push_back(
callback);
2401 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2402 WmKeyDownInfo{VK_BACK, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
2404 WmCharInfo{0x8, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
2406 WmKeyUpInfo{VK_BACK, kScanCodeBackspace, kNotExtended}.Build(
2408 WmKeyDownInfo{VK_PACKET, 0, kNotExtended, kWasUp}.Build(kWmResultDefault),
2409 WmCharInfo{0xe0 , 0, kNotExtended, kWasUp}.Build(kWmResultZero),
2410 WmKeyUpInfo{VK_PACKET, 0, kNotExtended}.Build(kWmResultDefault)});
2417 EXPECT_EQ(tester.key_calls.size(), 1);
2419 kPhysicalBackspace, kLogicalBackspace,
"",
2421 tester.clear_key_calls();
2422 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2424 EXPECT_EQ(recorded_callbacks.size(), 1);
2425 recorded_callbacks[0](backspace_response);
2427 EXPECT_EQ(tester.key_calls.size(), 1);
2429 kPhysicalBackspace, kLogicalBackspace,
"",
2431 tester.clear_key_calls();
2432 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(),
2433 backspace_response ? 0 : 2);
2435 recorded_callbacks[1](
false);
2436 EXPECT_EQ(tester.key_calls.size(), 1);
2438 tester.clear_key_calls();
2439 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2441 tester.Responding(
false);
2444 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2445 WmKeyUpInfo{kVirtualKeyF, kScanCodeKeyF, kNotExtended,
2447 .Build(kWmResultZero)});
2449 EXPECT_EQ(tester.key_calls.size(), 1);
2452 tester.clear_key_calls();
2453 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2456 TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithSlowFalseResponse) {
2460 TEST_F(KeyboardTest, VietnameseTelexAddDiacriticWithSlowTrueResponse) {
2467 KeyboardTester tester{GetContext()};
2468 tester.Responding(
false);
2470 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2471 WmKeyDownInfo{VK_CAPITAL, 0, kNotExtended}.Build(),
2472 WmKeyUpInfo{VK_CAPITAL, 0, kNotExtended}.Build()});
2474 tester.clear_key_calls();