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

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

Issue 2900203002: Moving input filter files and keymap to input directory. (Closed)
Patch Set: Fix include for input. Created 3 years, 7 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 | « remoting/client/key_event_mapper.cc ('k') | remoting/client/normalizing_input_filter_cros.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/client/key_event_mapper.h"
6
7 #include <stdint.h>
8
9 #include "base/bind.h"
10 #include "remoting/proto/event.pb.h"
11 #include "remoting/protocol/protocol_mock_objects.h"
12 #include "remoting/protocol/test_event_matchers.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using ::testing::_;
17 using ::testing::ExpectationSet;
18 using ::testing::InSequence;
19
20 namespace remoting {
21
22 using protocol::InputStub;
23 using protocol::KeyEvent;
24 using protocol::MockInputStub;
25 using protocol::test::EqualsKeyEventWithCapsLock;
26
27 static KeyEvent NewUsbEvent(uint32_t usb_keycode,
28 bool pressed,
29 uint32_t lock_states) {
30 KeyEvent event;
31 event.set_usb_keycode(usb_keycode);
32 event.set_pressed(pressed);
33 event.set_lock_states(lock_states);
34
35 return event;
36 }
37
38 static void PressAndReleaseUsb(InputStub* input_stub, uint32_t usb_keycode) {
39 input_stub->InjectKeyEvent(
40 NewUsbEvent(usb_keycode, true, KeyEvent::LOCK_STATES_CAPSLOCK));
41 input_stub->InjectKeyEvent(
42 NewUsbEvent(usb_keycode, false, KeyEvent::LOCK_STATES_CAPSLOCK));
43 }
44
45 static void InjectTestSequence(InputStub* input_stub) {
46 for (int i = 1; i <= 5; ++i)
47 PressAndReleaseUsb(input_stub, i);
48 }
49
50 // Verify that keys are passed through the KeyEventMapper by default.
51 TEST(KeyEventMapperTest, NoMappingOrTrapping) {
52 MockInputStub mock_stub;
53 KeyEventMapper event_mapper(&mock_stub);
54
55 {
56 InSequence s;
57
58 for (int i = 1; i <= 5; ++i) {
59 EXPECT_CALL(mock_stub,
60 InjectKeyEvent(EqualsKeyEventWithCapsLock(i, true)));
61 EXPECT_CALL(mock_stub,
62 InjectKeyEvent(EqualsKeyEventWithCapsLock(i, false)));
63 }
64
65 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(3, true)));
66 EXPECT_CALL(mock_stub,
67 InjectKeyEvent(EqualsKeyEventWithCapsLock(3, false)));
68 }
69
70 InjectTestSequence(&event_mapper);
71 PressAndReleaseUsb(&event_mapper, 3);
72 }
73
74 // Verify that USB keys are remapped at most once.
75 TEST(KeyEventMapperTest, RemapKeys) {
76 MockInputStub mock_stub;
77 KeyEventMapper event_mapper(&mock_stub);
78 event_mapper.RemapKey(3, 4);
79 event_mapper.RemapKey(4, 3);
80 event_mapper.RemapKey(5, 3);
81
82 {
83 InSequence s;
84
85 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(1, true)));
86 EXPECT_CALL(mock_stub,
87 InjectKeyEvent(EqualsKeyEventWithCapsLock(1, false)));
88 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(2, true)));
89 EXPECT_CALL(mock_stub,
90 InjectKeyEvent(EqualsKeyEventWithCapsLock(2, false)));
91 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(4, true)));
92 EXPECT_CALL(mock_stub,
93 InjectKeyEvent(EqualsKeyEventWithCapsLock(4, false)));
94 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(3, true)));
95 EXPECT_CALL(mock_stub,
96 InjectKeyEvent(EqualsKeyEventWithCapsLock(3, false)));
97 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(3, true)));
98 EXPECT_CALL(mock_stub,
99 InjectKeyEvent(EqualsKeyEventWithCapsLock(3, false)));
100 }
101
102 InjectTestSequence(&event_mapper);
103 }
104
105 static void HandleTrappedKey(MockInputStub* stub, const KeyEvent& event) {
106 stub->InjectKeyEvent(event);
107 }
108
109 // Verify that trapped and mapped USB keys are trapped but not remapped.
110 TEST(KeyEventMapperTest, TrapKeys) {
111 MockInputStub mock_stub;
112 MockInputStub trap_stub;
113 KeyEventMapper event_mapper(&mock_stub);
114 KeyEventMapper::KeyTrapCallback callback =
115 base::Bind(&HandleTrappedKey, base::Unretained(&trap_stub));
116 event_mapper.SetTrapCallback(callback);
117 event_mapper.TrapKey(4, true);
118 event_mapper.TrapKey(5, true);
119 event_mapper.RemapKey(3, 4);
120 event_mapper.RemapKey(4, 3);
121 event_mapper.RemapKey(5, 3);
122
123 {
124 InSequence s;
125
126 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(1, true)));
127 EXPECT_CALL(mock_stub,
128 InjectKeyEvent(EqualsKeyEventWithCapsLock(1, false)));
129 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(2, true)));
130 EXPECT_CALL(mock_stub,
131 InjectKeyEvent(EqualsKeyEventWithCapsLock(2, false)));
132 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(4, true)));
133 EXPECT_CALL(mock_stub,
134 InjectKeyEvent(EqualsKeyEventWithCapsLock(4, false)));
135
136 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(4, true)));
137 EXPECT_CALL(trap_stub,
138 InjectKeyEvent(EqualsKeyEventWithCapsLock(4, false)));
139 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsKeyEventWithCapsLock(5, true)));
140 EXPECT_CALL(trap_stub,
141 InjectKeyEvent(EqualsKeyEventWithCapsLock(5, false)));
142 }
143
144 InjectTestSequence(&event_mapper);
145 }
146
147 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/key_event_mapper.cc ('k') | remoting/client/normalizing_input_filter_cros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698