OLD | NEW |
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/protocol/input_event_tracker.h" | 5 #include "remoting/protocol/input_event_tracker.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" |
(...skipping 26 matching lines...) Expand all Loading... |
37 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) && | 37 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) && |
38 arg.pressed() == pressed && | 38 arg.pressed() == pressed && |
39 arg.lock_states() == kTestLockStates; | 39 arg.lock_states() == kTestLockStates; |
40 } | 40 } |
41 | 41 |
42 MATCHER_P4(EqualsMouseEvent, x, y, button, down, "") { | 42 MATCHER_P4(EqualsMouseEvent, x, y, button, down, "") { |
43 return arg.x() == x && arg.y() == y && arg.button() == button && | 43 return arg.x() == x && arg.y() == y && arg.button() == button && |
44 arg.button_down() == down; | 44 arg.button_down() == down; |
45 } | 45 } |
46 | 46 |
| 47 MATCHER_P2(TouchPointIdsAndTypeEqual, ids, type, "") { |
| 48 if (arg.event_type() != type) |
| 49 return false; |
| 50 |
| 51 std::set<uint32> touch_ids; |
| 52 for (const TouchEventPoint& point : arg.touch_points()) { |
| 53 touch_ids.insert(point.id()); |
| 54 } |
| 55 return touch_ids == ids; |
| 56 } |
| 57 |
47 static KeyEvent NewUsbEvent(uint32 usb_keycode, | 58 static KeyEvent NewUsbEvent(uint32 usb_keycode, |
48 bool pressed) { | 59 bool pressed) { |
49 KeyEvent event; | 60 KeyEvent event; |
50 event.set_usb_keycode(usb_keycode); | 61 event.set_usb_keycode(usb_keycode); |
51 event.set_pressed(pressed); | 62 event.set_pressed(pressed); |
52 // Create all key events with the hardcoded |lock_state| in this test. | 63 // Create all key events with the hardcoded |lock_state| in this test. |
53 event.set_lock_states(kTestLockStates); | 64 event.set_lock_states(kTestLockStates); |
54 return event; | 65 return event; |
55 } | 66 } |
56 | 67 |
57 static void PressAndReleaseUsb(InputStub* input_stub, | 68 static void PressAndReleaseUsb(InputStub* input_stub, |
58 uint32 usb_keycode) { | 69 uint32 usb_keycode) { |
59 input_stub->InjectKeyEvent(NewUsbEvent(usb_keycode, true)); | 70 input_stub->InjectKeyEvent(NewUsbEvent(usb_keycode, true)); |
60 input_stub->InjectKeyEvent(NewUsbEvent(usb_keycode, false)); | 71 input_stub->InjectKeyEvent(NewUsbEvent(usb_keycode, false)); |
61 } | 72 } |
62 | 73 |
63 static MouseEvent NewMouseEvent(int x, int y, | 74 static MouseEvent NewMouseEvent(int x, int y, |
64 MouseEvent::MouseButton button, bool down) { | 75 MouseEvent::MouseButton button, bool down) { |
65 MouseEvent event; | 76 MouseEvent event; |
66 event.set_x(x); | 77 event.set_x(x); |
67 event.set_y(y); | 78 event.set_y(y); |
68 event.set_button(button); | 79 event.set_button(button); |
69 event.set_button_down(down); | 80 event.set_button_down(down); |
70 return event; | 81 return event; |
71 } | 82 } |
72 | 83 |
| 84 void AddTouchPoint(uint32 id, TouchEvent* event) { |
| 85 TouchEventPoint* p = event->add_touch_points(); |
| 86 p->set_id(id); |
73 } | 87 } |
74 | 88 |
| 89 } // namespace |
| 90 |
75 // Verify that keys that were pressed and released aren't re-released. | 91 // Verify that keys that were pressed and released aren't re-released. |
76 TEST(InputEventTrackerTest, NothingToRelease) { | 92 TEST(InputEventTrackerTest, NothingToRelease) { |
77 MockInputStub mock_stub; | 93 MockInputStub mock_stub; |
78 InputEventTracker input_tracker(&mock_stub); | 94 InputEventTracker input_tracker(&mock_stub); |
79 | 95 |
80 { | 96 { |
81 InSequence s; | 97 InSequence s; |
82 | 98 |
83 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, true))); | 99 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, true))); |
84 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, false))); | 100 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(1, false))); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 PressAndReleaseUsb(&input_tracker, 2); | 248 PressAndReleaseUsb(&input_tracker, 2); |
233 | 249 |
234 EXPECT_FALSE(input_tracker.IsKeyPressed(1)); | 250 EXPECT_FALSE(input_tracker.IsKeyPressed(1)); |
235 EXPECT_FALSE(input_tracker.IsKeyPressed(2)); | 251 EXPECT_FALSE(input_tracker.IsKeyPressed(2)); |
236 EXPECT_TRUE(input_tracker.IsKeyPressed(3)); | 252 EXPECT_TRUE(input_tracker.IsKeyPressed(3)); |
237 EXPECT_EQ(1, input_tracker.PressedKeyCount()); | 253 EXPECT_EQ(1, input_tracker.PressedKeyCount()); |
238 | 254 |
239 input_tracker.ReleaseAll(); | 255 input_tracker.ReleaseAll(); |
240 } | 256 } |
241 | 257 |
| 258 // All touch points added with multiple touch events should be released as a |
| 259 // cancel event. |
| 260 TEST(InputEventTrackerTest, ReleaseAllTouchPoints) { |
| 261 MockInputStub mock_stub; |
| 262 InputEventTracker input_tracker(&mock_stub); |
| 263 |
| 264 std::set<uint32> expected_ids1; |
| 265 expected_ids1.insert(1); |
| 266 expected_ids1.insert(2); |
| 267 std::set<uint32> expected_ids2; |
| 268 expected_ids2.insert(3); |
| 269 expected_ids2.insert(5); |
| 270 expected_ids2.insert(8); |
| 271 |
| 272 std::set<uint32> all_touch_point_ids; |
| 273 all_touch_point_ids.insert(expected_ids1.begin(), expected_ids1.end()); |
| 274 all_touch_point_ids.insert(expected_ids2.begin(), expected_ids2.end()); |
| 275 |
| 276 InSequence s; |
| 277 EXPECT_CALL(mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual( |
| 278 expected_ids1, TouchEvent::TOUCH_POINT_START))); |
| 279 EXPECT_CALL(mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual( |
| 280 expected_ids2, TouchEvent::TOUCH_POINT_START))); |
| 281 |
| 282 EXPECT_CALL(mock_stub, |
| 283 InjectTouchEvent(TouchPointIdsAndTypeEqual( |
| 284 all_touch_point_ids, TouchEvent::TOUCH_POINT_CANCEL))); |
| 285 |
| 286 TouchEvent start_event1; |
| 287 start_event1.set_event_type(TouchEvent::TOUCH_POINT_START); |
| 288 AddTouchPoint(1, &start_event1); |
| 289 AddTouchPoint(2, &start_event1); |
| 290 input_tracker.InjectTouchEvent(start_event1); |
| 291 |
| 292 TouchEvent start_event2; |
| 293 start_event2.set_event_type(TouchEvent::TOUCH_POINT_START); |
| 294 AddTouchPoint(3, &start_event2); |
| 295 AddTouchPoint(5, &start_event2); |
| 296 AddTouchPoint(8, &start_event2); |
| 297 input_tracker.InjectTouchEvent(start_event2); |
| 298 |
| 299 input_tracker.ReleaseAll(); |
| 300 } |
| 301 |
| 302 // Add some touch points and remove only a subset of them. ReleaseAll() should |
| 303 // cancel all the remaining touch points. |
| 304 TEST(InputEventTrackerTest, ReleaseAllRemainingTouchPoints) { |
| 305 MockInputStub mock_stub; |
| 306 InputEventTracker input_tracker(&mock_stub); |
| 307 |
| 308 std::set<uint32> start_expected_ids; |
| 309 start_expected_ids.insert(1); |
| 310 start_expected_ids.insert(2); |
| 311 start_expected_ids.insert(3); |
| 312 |
| 313 std::set<uint32> end_expected_ids; |
| 314 end_expected_ids.insert(1); |
| 315 std::set<uint32> cancel_expected_ids; |
| 316 cancel_expected_ids.insert(3); |
| 317 |
| 318 std::set<uint32> all_remaining_touch_point_ids; |
| 319 all_remaining_touch_point_ids.insert(2); |
| 320 |
| 321 InSequence s; |
| 322 EXPECT_CALL(mock_stub, |
| 323 InjectTouchEvent(TouchPointIdsAndTypeEqual( |
| 324 start_expected_ids, TouchEvent::TOUCH_POINT_START))); |
| 325 EXPECT_CALL(mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual( |
| 326 end_expected_ids, TouchEvent::TOUCH_POINT_END))); |
| 327 EXPECT_CALL(mock_stub, |
| 328 InjectTouchEvent(TouchPointIdsAndTypeEqual( |
| 329 cancel_expected_ids, TouchEvent::TOUCH_POINT_CANCEL))); |
| 330 |
| 331 EXPECT_CALL(mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual( |
| 332 all_remaining_touch_point_ids, |
| 333 TouchEvent::TOUCH_POINT_CANCEL))); |
| 334 |
| 335 TouchEvent start_event; |
| 336 start_event.set_event_type(TouchEvent::TOUCH_POINT_START); |
| 337 AddTouchPoint(1, &start_event); |
| 338 AddTouchPoint(2, &start_event); |
| 339 AddTouchPoint(3, &start_event); |
| 340 input_tracker.InjectTouchEvent(start_event); |
| 341 |
| 342 TouchEvent end_event; |
| 343 end_event.set_event_type(TouchEvent::TOUCH_POINT_END); |
| 344 AddTouchPoint(1, &end_event); |
| 345 input_tracker.InjectTouchEvent(end_event); |
| 346 |
| 347 TouchEvent cancel_event; |
| 348 cancel_event.set_event_type(TouchEvent::TOUCH_POINT_CANCEL); |
| 349 AddTouchPoint(3, &cancel_event); |
| 350 input_tracker.InjectTouchEvent(cancel_event); |
| 351 |
| 352 input_tracker.ReleaseAll(); |
| 353 } |
| 354 |
242 } // namespace protocol | 355 } // namespace protocol |
243 } // namespace remoting | 356 } // namespace remoting |
OLD | NEW |