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

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

Issue 10894050: Remove support for Windows-style keycodes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Linux EventExecutor typo. Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | remoting/client/plugin/chromoting_instance.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 "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 using ::testing::_; 12 using ::testing::_;
13 using ::testing::ExpectationSet; 13 using ::testing::ExpectationSet;
14 using ::testing::InSequence; 14 using ::testing::InSequence;
15 15
16 namespace remoting { 16 namespace remoting {
17 17
18 using protocol::InputStub; 18 using protocol::InputStub;
19 using protocol::KeyEvent; 19 using protocol::KeyEvent;
20 using protocol::MockInputStub; 20 using protocol::MockInputStub;
21 21
22 MATCHER_P2(EqualsVkeyEvent, keycode, pressed, "") {
23 return arg.keycode() == keycode && arg.pressed() == pressed;
24 }
25
26 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") { 22 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") {
27 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) && 23 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
28 arg.pressed() == pressed; 24 arg.pressed() == pressed;
29 } 25 }
30 26
31 static KeyEvent NewVkeyEvent(int keycode, bool pressed) {
32 KeyEvent event;
33 event.set_keycode(keycode);
34 event.set_pressed(pressed);
35 return event;
36 }
37
38 static void PressAndReleaseVkey(InputStub* input_stub, int keycode) {
39 input_stub->InjectKeyEvent(NewVkeyEvent(keycode, true));
40 input_stub->InjectKeyEvent(NewVkeyEvent(keycode, false));
41 }
42
43 static KeyEvent NewUsbEvent(uint32 usb_keycode, bool pressed) { 27 static KeyEvent NewUsbEvent(uint32 usb_keycode, bool pressed) {
44 KeyEvent event; 28 KeyEvent event;
45 event.set_usb_keycode(usb_keycode); 29 event.set_usb_keycode(usb_keycode);
46 event.set_pressed(pressed); 30 event.set_pressed(pressed);
47 return event; 31 return event;
48 } 32 }
49 33
50 static void PressAndReleaseUsb(InputStub* input_stub, 34 static void PressAndReleaseUsb(InputStub* input_stub,
51 uint32 usb_keycode) { 35 uint32 usb_keycode) {
52 input_stub->InjectKeyEvent(NewUsbEvent(usb_keycode, true)); 36 input_stub->InjectKeyEvent(NewUsbEvent(usb_keycode, true));
(...skipping 11 matching lines...) Expand all
64 KeyEventMapper event_mapper(&mock_stub); 48 KeyEventMapper event_mapper(&mock_stub);
65 49
66 { 50 {
67 InSequence s; 51 InSequence s;
68 52
69 for (int i = 1; i <= 5; ++i) { 53 for (int i = 1; i <= 5; ++i) {
70 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(i, true))); 54 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(i, true)));
71 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(i, false))); 55 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(i, false)));
72 } 56 }
73 57
74 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsVkeyEvent(3, true))); 58 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, true)));
75 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsVkeyEvent(3, false))); 59 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, false)));
76 } 60 }
77 61
78 InjectTestSequence(&event_mapper); 62 InjectTestSequence(&event_mapper);
79 PressAndReleaseVkey(&event_mapper, 3); 63 PressAndReleaseUsb(&event_mapper, 3);
80 } 64 }
81 65
82 // Verify that USB keys are remapped at most once, and VKEYs are not mapped. 66 // Verify that USB keys are remapped at most once.
83 TEST(KeyEventMapperTest, RemapKeys) { 67 TEST(KeyEventMapperTest, RemapKeys) {
84 MockInputStub mock_stub; 68 MockInputStub mock_stub;
85 KeyEventMapper event_mapper(&mock_stub); 69 KeyEventMapper event_mapper(&mock_stub);
86 event_mapper.RemapKey(3, 4); 70 event_mapper.RemapKey(3, 4);
87 event_mapper.RemapKey(4, 3); 71 event_mapper.RemapKey(4, 3);
88 event_mapper.RemapKey(5, 3); 72 event_mapper.RemapKey(5, 3);
89 73
90 { 74 {
91 InSequence s; 75 InSequence s;
92 76
93 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, true))); 77 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, true)));
94 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, false))); 78 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, false)));
95 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(2, true))); 79 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(2, true)));
96 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(2, false))); 80 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(2, false)));
97 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(4, true))); 81 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(4, true)));
98 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(4, false))); 82 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(4, false)));
99 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, true))); 83 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, true)));
100 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, false))); 84 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, false)));
101 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, true))); 85 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, true)));
102 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, false))); 86 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(3, false)));
103
104 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsVkeyEvent(3, true)));
105 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsVkeyEvent(3, false)));
106 } 87 }
107 88
108 InjectTestSequence(&event_mapper); 89 InjectTestSequence(&event_mapper);
109 PressAndReleaseVkey(&event_mapper, 3);
110 } 90 }
111 91
112 static void HandleTrappedKey(MockInputStub* stub, uint32 keycode, bool down) { 92 static void HandleTrappedKey(MockInputStub* stub, uint32 keycode, bool down) {
113 stub->InjectKeyEvent(NewUsbEvent(keycode, down)); 93 stub->InjectKeyEvent(NewUsbEvent(keycode, down));
114 } 94 }
115 95
116 // Verify that USB keys are trapped, not remapped, and VKEYs are not trapped. 96 // Verify that trapped and mapped USB keys are trapped but not remapped.
117 TEST(KeyEventMapperTest, TrapKeys) { 97 TEST(KeyEventMapperTest, TrapKeys) {
118 MockInputStub mock_stub; 98 MockInputStub mock_stub;
119 MockInputStub trap_stub; 99 MockInputStub trap_stub;
120 KeyEventMapper event_mapper(&mock_stub); 100 KeyEventMapper event_mapper(&mock_stub);
121 KeyEventMapper::KeyTrapCallback callback = 101 KeyEventMapper::KeyTrapCallback callback =
122 base::Bind(&HandleTrappedKey, base::Unretained(&trap_stub)); 102 base::Bind(&HandleTrappedKey, base::Unretained(&trap_stub));
123 event_mapper.SetTrapCallback(callback); 103 event_mapper.SetTrapCallback(callback);
124 event_mapper.TrapKey(4, true); 104 event_mapper.TrapKey(4, true);
125 event_mapper.TrapKey(5, true); 105 event_mapper.TrapKey(5, true);
126 event_mapper.RemapKey(3, 4); 106 event_mapper.RemapKey(3, 4);
127 event_mapper.RemapKey(4, 3); 107 event_mapper.RemapKey(4, 3);
128 event_mapper.RemapKey(5, 3); 108 event_mapper.RemapKey(5, 3);
129 109
130 { 110 {
131 InSequence s; 111 InSequence s;
132 112
133 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, true))); 113 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, true)));
134 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, false))); 114 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, false)));
135 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(2, true))); 115 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(2, true)));
136 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(2, false))); 116 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(2, false)));
137 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(4, true))); 117 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(4, true)));
138 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(4, false))); 118 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(4, false)));
139 119
140 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsUsbEvent(4, true))); 120 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsUsbEvent(4, true)));
141 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsUsbEvent(4, false))); 121 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsUsbEvent(4, false)));
142 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsUsbEvent(5, true))); 122 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsUsbEvent(5, true)));
143 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsUsbEvent(5, false))); 123 EXPECT_CALL(trap_stub, InjectKeyEvent(EqualsUsbEvent(5, false)));
144
145 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsVkeyEvent(3, true)));
146 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsVkeyEvent(3, false)));
147 } 124 }
148 125
149 InjectTestSequence(&event_mapper); 126 InjectTestSequence(&event_mapper);
150 PressAndReleaseVkey(&event_mapper, 3);
151 } 127 }
152 128
153 } // namespace remoting 129 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/client/plugin/chromoting_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698