| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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/plugin/normalizing_input_filter_cros.h" | |
| 6 | |
| 7 #include "remoting/proto/event.pb.h" | |
| 8 #include "remoting/protocol/protocol_mock_objects.h" | |
| 9 #include "remoting/protocol/test_event_matchers.h" | |
| 10 #include "remoting/protocol/usb_key_codes.h" | |
| 11 #include "testing/gmock/include/gmock/gmock.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 using ::testing::InSequence; | |
| 15 using remoting::protocol::InputStub; | |
| 16 using remoting::protocol::KeyEvent; | |
| 17 using remoting::protocol::MockInputStub; | |
| 18 using remoting::protocol::MouseEvent; | |
| 19 using remoting::protocol::test::EqualsKeyEventWithNumLock; | |
| 20 using remoting::protocol::test::EqualsMouseButtonEvent; | |
| 21 using remoting::protocol::test::EqualsMouseMoveEvent; | |
| 22 | |
| 23 namespace remoting { | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 const unsigned int kUsbFunctionKey = 0x07003a; // F1 | |
| 28 const unsigned int kUsbExtendedKey = kUsbInsert; | |
| 29 const unsigned int kUsbOtherKey = kUsbTab; | |
| 30 | |
| 31 KeyEvent MakeKeyEvent(uint32 keycode, bool pressed) { | |
| 32 KeyEvent event; | |
| 33 event.set_usb_keycode(keycode); | |
| 34 event.set_pressed(pressed); | |
| 35 event.set_lock_states(protocol::KeyEvent::LOCK_STATES_NUMLOCK); | |
| 36 return event; | |
| 37 } | |
| 38 | |
| 39 void PressAndReleaseKey(InputStub* input_stub, uint32 keycode) { | |
| 40 input_stub->InjectKeyEvent(MakeKeyEvent(keycode, true)); | |
| 41 input_stub->InjectKeyEvent(MakeKeyEvent(keycode, false)); | |
| 42 } | |
| 43 | |
| 44 static MouseEvent MakeMouseMoveEvent(int x, int y) { | |
| 45 MouseEvent event; | |
| 46 event.set_x(x); | |
| 47 event.set_y(y); | |
| 48 return event; | |
| 49 } | |
| 50 | |
| 51 static MouseEvent MakeMouseButtonEvent(MouseEvent::MouseButton button, | |
| 52 bool button_down) { | |
| 53 MouseEvent event; | |
| 54 event.set_button(button); | |
| 55 event.set_button_down(button_down); | |
| 56 return event; | |
| 57 } | |
| 58 | |
| 59 } // namespace | |
| 60 | |
| 61 // Test OSKey press/release. | |
| 62 TEST(NormalizingInputFilterCrosTest, PressReleaseOsKey) { | |
| 63 MockInputStub stub; | |
| 64 scoped_ptr<protocol::InputFilter> processor( | |
| 65 new NormalizingInputFilterCros(&stub)); | |
| 66 | |
| 67 { | |
| 68 InSequence s; | |
| 69 | |
| 70 EXPECT_CALL(stub, | |
| 71 InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftOs, true))); | |
| 72 EXPECT_CALL( | |
| 73 stub, InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftOs, false))); | |
| 74 | |
| 75 EXPECT_CALL( | |
| 76 stub, InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbRightOs, true))); | |
| 77 EXPECT_CALL( | |
| 78 stub, InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbRightOs, false))); | |
| 79 } | |
| 80 | |
| 81 // Inject press & release events for left & right OSKeys. | |
| 82 PressAndReleaseKey(processor.get(), kUsbLeftOs); | |
| 83 PressAndReleaseKey(processor.get(), kUsbRightOs); | |
| 84 } | |
| 85 | |
| 86 // Test OSKey key repeat switches it to "modifying" mode. | |
| 87 TEST(NormalizingInputFilterCrosTest, OSKeyRepeats) { | |
| 88 MockInputStub stub; | |
| 89 scoped_ptr<protocol::InputFilter> processor( | |
| 90 new NormalizingInputFilterCros(&stub)); | |
| 91 | |
| 92 { | |
| 93 InSequence s; | |
| 94 | |
| 95 EXPECT_CALL(stub, | |
| 96 InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftOs, true))); | |
| 97 EXPECT_CALL(stub, | |
| 98 InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftOs, true))); | |
| 99 EXPECT_CALL(stub, | |
| 100 InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftOs, true))); | |
| 101 } | |
| 102 | |
| 103 // Inject a press and repeats for the left OSKey, but don't release it, and | |
| 104 // verify that the repeats result in press events. | |
| 105 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, true)); | |
| 106 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, true)); | |
| 107 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, true)); | |
| 108 } | |
| 109 | |
| 110 // Test OSKey press followed by function key press and release results in | |
| 111 // just the function key events. | |
| 112 TEST(NormalizingInputFilterCrosTest, FunctionKey) { | |
| 113 MockInputStub stub; | |
| 114 scoped_ptr<protocol::InputFilter> processor( | |
| 115 new NormalizingInputFilterCros(&stub)); | |
| 116 | |
| 117 { | |
| 118 InSequence s; | |
| 119 | |
| 120 EXPECT_CALL( | |
| 121 stub, InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbFunctionKey, true))); | |
| 122 EXPECT_CALL(stub, InjectKeyEvent( | |
| 123 EqualsKeyEventWithNumLock(kUsbFunctionKey, false))); | |
| 124 } | |
| 125 | |
| 126 // Hold the left OSKey while pressing & releasing the function key. | |
| 127 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, true)); | |
| 128 PressAndReleaseKey(processor.get(), kUsbFunctionKey); | |
| 129 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, false)); | |
| 130 } | |
| 131 | |
| 132 // Test OSKey press followed by extended key press and release results in | |
| 133 // just the function key events. | |
| 134 TEST(NormalizingInputFilterCrosTest, ExtendedKey) { | |
| 135 MockInputStub stub; | |
| 136 scoped_ptr<protocol::InputFilter> processor( | |
| 137 new NormalizingInputFilterCros(&stub)); | |
| 138 | |
| 139 { | |
| 140 InSequence s; | |
| 141 | |
| 142 EXPECT_CALL( | |
| 143 stub, InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbExtendedKey, true))); | |
| 144 EXPECT_CALL(stub, InjectKeyEvent( | |
| 145 EqualsKeyEventWithNumLock(kUsbExtendedKey, false))); | |
| 146 } | |
| 147 | |
| 148 // Hold the left OSKey while pressing & releasing the function key. | |
| 149 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, true)); | |
| 150 PressAndReleaseKey(processor.get(), kUsbExtendedKey); | |
| 151 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, false)); | |
| 152 } | |
| 153 | |
| 154 // Test OSKey press followed by non-function, non-extended key press and release | |
| 155 // results in normal-looking sequence. | |
| 156 TEST(NormalizingInputFilterCrosTest, OtherKey) { | |
| 157 MockInputStub stub; | |
| 158 scoped_ptr<protocol::InputFilter> processor( | |
| 159 new NormalizingInputFilterCros(&stub)); | |
| 160 | |
| 161 { | |
| 162 InSequence s; | |
| 163 | |
| 164 EXPECT_CALL(stub, | |
| 165 InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftOs, true))); | |
| 166 EXPECT_CALL(stub, | |
| 167 InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbOtherKey, true))); | |
| 168 EXPECT_CALL(stub, | |
| 169 InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbOtherKey, false))); | |
| 170 EXPECT_CALL( | |
| 171 stub, InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftOs, false))); | |
| 172 } | |
| 173 | |
| 174 // Hold the left OSKey while pressing & releasing the function key. | |
| 175 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, true)); | |
| 176 PressAndReleaseKey(processor.get(), kUsbOtherKey); | |
| 177 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, false)); | |
| 178 } | |
| 179 | |
| 180 // Test OSKey press followed by extended key press, then normal key press | |
| 181 // results in OSKey switching to modifying mode for the normal key. | |
| 182 TEST(NormalizingInputFilterCrosTest, ExtendedThenOtherKey) { | |
| 183 MockInputStub stub; | |
| 184 scoped_ptr<protocol::InputFilter> processor( | |
| 185 new NormalizingInputFilterCros(&stub)); | |
| 186 | |
| 187 { | |
| 188 InSequence s; | |
| 189 | |
| 190 EXPECT_CALL( | |
| 191 stub, InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbExtendedKey, true))); | |
| 192 EXPECT_CALL(stub, InjectKeyEvent( | |
| 193 EqualsKeyEventWithNumLock(kUsbExtendedKey, false))); | |
| 194 EXPECT_CALL(stub, | |
| 195 InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftOs, true))); | |
| 196 EXPECT_CALL(stub, | |
| 197 InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbOtherKey, true))); | |
| 198 EXPECT_CALL(stub, | |
| 199 InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbOtherKey, false))); | |
| 200 EXPECT_CALL( | |
| 201 stub, InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftOs, false))); | |
| 202 } | |
| 203 | |
| 204 // Hold the left OSKey while pressing & releasing the function key. | |
| 205 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, true)); | |
| 206 PressAndReleaseKey(processor.get(), kUsbExtendedKey); | |
| 207 PressAndReleaseKey(processor.get(), kUsbOtherKey); | |
| 208 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, false)); | |
| 209 } | |
| 210 | |
| 211 // Test OSKey press followed by mouse event puts the OSKey into modifying mode. | |
| 212 TEST(NormalizingInputFilterCrosTest, MouseEvent) { | |
| 213 MockInputStub stub; | |
| 214 scoped_ptr<protocol::InputFilter> processor( | |
| 215 new NormalizingInputFilterCros(&stub)); | |
| 216 | |
| 217 { | |
| 218 InSequence s; | |
| 219 | |
| 220 EXPECT_CALL(stub, | |
| 221 InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftOs, true))); | |
| 222 EXPECT_CALL(stub, InjectMouseEvent(EqualsMouseMoveEvent(0, 0))); | |
| 223 EXPECT_CALL( | |
| 224 stub, InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftOs, false))); | |
| 225 } | |
| 226 | |
| 227 // Hold the left OSKey while pressing & releasing the function key. | |
| 228 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, true)); | |
| 229 processor->InjectMouseEvent(MakeMouseMoveEvent(0, 0)); | |
| 230 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOs, false)); | |
| 231 } | |
| 232 | |
| 233 // Test left alt + right click is remapped to left alt + left click. | |
| 234 TEST(NormalizingInputFilterCrosTest, LeftAltClick) { | |
| 235 MockInputStub stub; | |
| 236 scoped_ptr<protocol::InputFilter> processor( | |
| 237 new NormalizingInputFilterCros(&stub)); | |
| 238 | |
| 239 { | |
| 240 InSequence s; | |
| 241 | |
| 242 EXPECT_CALL( | |
| 243 stub, InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftAlt, true))); | |
| 244 EXPECT_CALL(stub, InjectMouseEvent(EqualsMouseButtonEvent( | |
| 245 MouseEvent::BUTTON_LEFT, true))); | |
| 246 EXPECT_CALL(stub, InjectMouseEvent(EqualsMouseButtonEvent( | |
| 247 MouseEvent::BUTTON_LEFT, false))); | |
| 248 EXPECT_CALL( | |
| 249 stub, InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbLeftAlt, false))); | |
| 250 } | |
| 251 | |
| 252 // Hold the left alt key while left-clicking. ChromeOS will rewrite this as | |
| 253 // Alt+RightClick | |
| 254 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftAlt, true)); | |
| 255 processor->InjectMouseEvent( | |
| 256 MakeMouseButtonEvent(MouseEvent::BUTTON_RIGHT, true)); | |
| 257 processor->InjectMouseEvent( | |
| 258 MakeMouseButtonEvent(MouseEvent::BUTTON_RIGHT, false)); | |
| 259 processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftAlt, false)); | |
| 260 } | |
| 261 | |
| 262 // Test that right alt + right click is unchanged. | |
| 263 TEST(NormalizingInputFilterCrosTest, RightAltClick) { | |
| 264 MockInputStub stub; | |
| 265 scoped_ptr<protocol::InputFilter> processor( | |
| 266 new NormalizingInputFilterCros(&stub)); | |
| 267 | |
| 268 { | |
| 269 InSequence s; | |
| 270 | |
| 271 EXPECT_CALL( | |
| 272 stub, InjectKeyEvent(EqualsKeyEventWithNumLock(kUsbRightAlt, true))); | |
| 273 EXPECT_CALL(stub, InjectMouseEvent(EqualsMouseButtonEvent( | |
| 274 MouseEvent::BUTTON_RIGHT, true))); | |
| 275 EXPECT_CALL(stub, InjectMouseEvent(EqualsMouseButtonEvent( | |
| 276 MouseEvent::BUTTON_RIGHT, false))); | |
| 277 EXPECT_CALL(stub, InjectKeyEvent( | |
| 278 EqualsKeyEventWithNumLock(kUsbRightAlt, false))); | |
| 279 } | |
| 280 | |
| 281 // Hold the right alt key while left-clicking. ChromeOS will rewrite this as | |
| 282 // Alt+RightClick | |
| 283 processor->InjectKeyEvent(MakeKeyEvent(kUsbRightAlt, true)); | |
| 284 processor->InjectMouseEvent( | |
| 285 MakeMouseButtonEvent(MouseEvent::BUTTON_RIGHT, true)); | |
| 286 processor->InjectMouseEvent( | |
| 287 MakeMouseButtonEvent(MouseEvent::BUTTON_RIGHT, false)); | |
| 288 processor->InjectKeyEvent(MakeKeyEvent(kUsbRightAlt, false)); | |
| 289 } | |
| 290 | |
| 291 } // namespace remoting | |
| OLD | NEW |