Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1180)

Side by Side Diff: remoting/client/key_event_mapper_unittest.cc

Issue 985863002: Move all protocol event matchers to test_event_matchers.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | remoting/client/plugin/normalizing_input_filter_cros_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/client/key_event_mapper.h" 5 #include "remoting/client/key_event_mapper.h"
6 6
7 #include "remoting/proto/event.pb.h" 7 #include "remoting/proto/event.pb.h"
8 #include "remoting/protocol/protocol_mock_objects.h" 8 #include "remoting/protocol/protocol_mock_objects.h"
9 #include "remoting/protocol/test_event_matchers.h"
9 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 using ::testing::_; 13 using ::testing::_;
13 using ::testing::ExpectationSet; 14 using ::testing::ExpectationSet;
14 using ::testing::InSequence; 15 using ::testing::InSequence;
15 16
16 namespace remoting { 17 namespace remoting {
17 18
18 using protocol::InputStub; 19 using protocol::InputStub;
19 using protocol::KeyEvent; 20 using protocol::KeyEvent;
20 using protocol::MockInputStub; 21 using protocol::MockInputStub;
21 22 using protocol::test::EqualsKeyEventWithCapsLock;
22 // A hardcoded value used to verify |lock_states| is preserved.
23 static const uint32 kTestLockStates = protocol::KeyEvent::LOCK_STATES_CAPSLOCK;
24
25 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") {
26 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
27 arg.pressed() == pressed &&
28 // |lock_states| is hardcoded to kTestLockStates in all key events.
29 arg.lock_states() == kTestLockStates;
30 }
31
32 MATCHER_P2(EqualsUsbEventLockStates, usb_keycode, pressed, "") {
33 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
34 arg.pressed() == pressed &&
35 arg.lock_states() == kTestLockStates;
36 }
37 23
38 static KeyEvent NewUsbEvent(uint32 usb_keycode, 24 static KeyEvent NewUsbEvent(uint32 usb_keycode,
39 bool pressed, 25 bool pressed,
40 uint32 lock_states) { 26 uint32 lock_states) {
41 KeyEvent event; 27 KeyEvent event;
42 event.set_usb_keycode(usb_keycode); 28 event.set_usb_keycode(usb_keycode);
43 event.set_pressed(pressed); 29 event.set_pressed(pressed);
44 event.set_lock_states(lock_states); 30 event.set_lock_states(lock_states);
45 31
46 return event; 32 return event;
47 } 33 }
48 34
49 static void PressAndReleaseUsb(InputStub* input_stub, uint32 usb_keycode) { 35 static void PressAndReleaseUsb(InputStub* input_stub, uint32 usb_keycode) {
50 input_stub->InjectKeyEvent(NewUsbEvent(usb_keycode, true, kTestLockStates)); 36 input_stub->InjectKeyEvent(
51 input_stub->InjectKeyEvent(NewUsbEvent(usb_keycode, false, kTestLockStates)); 37 NewUsbEvent(usb_keycode, true, KeyEvent::LOCK_STATES_CAPSLOCK));
38 input_stub->InjectKeyEvent(
39 NewUsbEvent(usb_keycode, false, KeyEvent::LOCK_STATES_CAPSLOCK));
52 } 40 }
53 41
54 static void InjectTestSequence(InputStub* input_stub) { 42 static void InjectTestSequence(InputStub* input_stub) {
55 for (int i = 1; i <= 5; ++i) 43 for (int i = 1; i <= 5; ++i)
56 PressAndReleaseUsb(input_stub, i); 44 PressAndReleaseUsb(input_stub, i);
57 } 45 }
58 46
59 // Verify that keys are passed through the KeyEventMapper by default. 47 // Verify that keys are passed through the KeyEventMapper by default.
60 TEST(KeyEventMapperTest, NoMappingOrTrapping) { 48 TEST(KeyEventMapperTest, NoMappingOrTrapping) {
61 MockInputStub mock_stub; 49 MockInputStub mock_stub;
62 KeyEventMapper event_mapper(&mock_stub); 50 KeyEventMapper event_mapper(&mock_stub);
63 51
64 { 52 {
65 InSequence s; 53 InSequence s;
66 54
67 for (int i = 1; i <= 5; ++i) { 55 for (int i = 1; i <= 5; ++i) {
68 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(i, true))); 56 EXPECT_CALL(mock_stub,
69 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(i, false))); 57 InjectKeyEvent(EqualsKeyEventWithCapsLock(i, true)));
58 EXPECT_CALL(mock_stub,
59 InjectKeyEvent(EqualsKeyEventWithCapsLock(i, false)));
70 } 60 }
71 61
72 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, true))); 62 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(3, true)));
73 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, false))); 63 EXPECT_CALL(mock_stub,
64 InjectKeyEvent(EqualsKeyEventWithCapsLock(3, false)));
74 } 65 }
75 66
76 InjectTestSequence(&event_mapper); 67 InjectTestSequence(&event_mapper);
77 PressAndReleaseUsb(&event_mapper, 3); 68 PressAndReleaseUsb(&event_mapper, 3);
78 } 69 }
79 70
80 // Verify that USB keys are remapped at most once. 71 // Verify that USB keys are remapped at most once.
81 TEST(KeyEventMapperTest, RemapKeys) { 72 TEST(KeyEventMapperTest, RemapKeys) {
82 MockInputStub mock_stub; 73 MockInputStub mock_stub;
83 KeyEventMapper event_mapper(&mock_stub); 74 KeyEventMapper event_mapper(&mock_stub);
84 event_mapper.RemapKey(3, 4); 75 event_mapper.RemapKey(3, 4);
85 event_mapper.RemapKey(4, 3); 76 event_mapper.RemapKey(4, 3);
86 event_mapper.RemapKey(5, 3); 77 event_mapper.RemapKey(5, 3);
87 78
88 { 79 {
89 InSequence s; 80 InSequence s;
90 81
91 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, true))); 82 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(1, true)));
92 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, false))); 83 EXPECT_CALL(mock_stub,
93 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(2, true))); 84 InjectKeyEvent(EqualsKeyEventWithCapsLock(1, false)));
94 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(2, false))); 85 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(2, true)));
95 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(4, true))); 86 EXPECT_CALL(mock_stub,
96 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(4, false))); 87 InjectKeyEvent(EqualsKeyEventWithCapsLock(2, false)));
97 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, true))); 88 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(4, true)));
98 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, false))); 89 EXPECT_CALL(mock_stub,
99 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, true))); 90 InjectKeyEvent(EqualsKeyEventWithCapsLock(4, false)));
100 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, false))); 91 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(3, true)));
92 EXPECT_CALL(mock_stub,
93 InjectKeyEvent(EqualsKeyEventWithCapsLock(3, false)));
94 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(3, true)));
95 EXPECT_CALL(mock_stub,
96 InjectKeyEvent(EqualsKeyEventWithCapsLock(3, false)));
101 } 97 }
102 98
103 InjectTestSequence(&event_mapper); 99 InjectTestSequence(&event_mapper);
104 } 100 }
105 101
106 static void HandleTrappedKey(MockInputStub* stub, const KeyEvent& event) { 102 static void HandleTrappedKey(MockInputStub* stub, const KeyEvent& event) {
107 stub->InjectKeyEvent(event); 103 stub->InjectKeyEvent(event);
108 } 104 }
109 105
110 // Verify that trapped and mapped USB keys are trapped but not remapped. 106 // Verify that trapped and mapped USB keys are trapped but not remapped.
111 TEST(KeyEventMapperTest, TrapKeys) { 107 TEST(KeyEventMapperTest, TrapKeys) {
112 MockInputStub mock_stub; 108 MockInputStub mock_stub;
113 MockInputStub trap_stub; 109 MockInputStub trap_stub;
114 KeyEventMapper event_mapper(&mock_stub); 110 KeyEventMapper event_mapper(&mock_stub);
115 KeyEventMapper::KeyTrapCallback callback = 111 KeyEventMapper::KeyTrapCallback callback =
116 base::Bind(&HandleTrappedKey, base::Unretained(&trap_stub)); 112 base::Bind(&HandleTrappedKey, base::Unretained(&trap_stub));
117 event_mapper.SetTrapCallback(callback); 113 event_mapper.SetTrapCallback(callback);
118 event_mapper.TrapKey(4, true); 114 event_mapper.TrapKey(4, true);
119 event_mapper.TrapKey(5, true); 115 event_mapper.TrapKey(5, true);
120 event_mapper.RemapKey(3, 4); 116 event_mapper.RemapKey(3, 4);
121 event_mapper.RemapKey(4, 3); 117 event_mapper.RemapKey(4, 3);
122 event_mapper.RemapKey(5, 3); 118 event_mapper.RemapKey(5, 3);
123 119
124 { 120 {
125 InSequence s; 121 InSequence s;
126 122
127 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, true))); 123 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(1, true)));
128 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, false))); 124 EXPECT_CALL(mock_stub,
129 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(2, true))); 125 InjectKeyEvent(EqualsKeyEventWithCapsLock(1, false)));
130 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(2, false))); 126 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(2, true)));
131 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(4, true))); 127 EXPECT_CALL(mock_stub,
132 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(4, false))); 128 InjectKeyEvent(EqualsKeyEventWithCapsLock(2, false)));
129 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(4, true)));
130 EXPECT_CALL(mock_stub,
131 InjectKeyEvent(EqualsKeyEventWithCapsLock(4, false)));
133 132
134 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsUsbEvent(4, true))); 133 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(4, true)));
135 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsUsbEvent(4, false))); 134 EXPECT_CALL(trap_stub,
136 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsUsbEvent(5, true))); 135 InjectKeyEvent(EqualsKeyEventWithCapsLock(4, false)));
137 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsUsbEvent(5, false))); 136 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(5, true)));
137 EXPECT_CALL(trap_stub,
138 InjectKeyEvent(EqualsKeyEventWithCapsLock(5, false)));
138 } 139 }
139 140
140 InjectTestSequence(&event_mapper); 141 InjectTestSequence(&event_mapper);
141 } 142 }
142 143
143 } // namespace remoting 144 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/client/plugin/normalizing_input_filter_cros_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698