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

Side by Side Diff: remoting/protocol/input_event_tracker_unittest.cc

Issue 1542203002: Switch to standard integer types in remoting/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@int-remoting-host
Patch Set: Created 5 years 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/protocol/input_event_tracker.h ('k') | remoting/protocol/input_filter.h » ('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/protocol/input_event_tracker.h" 5 #include "remoting/protocol/input_event_tracker.h"
6 6
7 #include <stdint.h>
8
7 #include "remoting/proto/event.pb.h" 9 #include "remoting/proto/event.pb.h"
8 #include "remoting/protocol/protocol_mock_objects.h" 10 #include "remoting/protocol/protocol_mock_objects.h"
9 #include "remoting/protocol/test_event_matchers.h" 11 #include "remoting/protocol/test_event_matchers.h"
10 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 14
13 using ::testing::_; 15 using ::testing::_;
14 using ::testing::ExpectationSet; 16 using ::testing::ExpectationSet;
15 using ::testing::InSequence; 17 using ::testing::InSequence;
16 18
17 namespace remoting { 19 namespace remoting {
18 namespace protocol { 20 namespace protocol {
19 21
20 using test::EqualsKeyEventWithCapsLock; 22 using test::EqualsKeyEventWithCapsLock;
21 using test::EqualsMouseEvent; 23 using test::EqualsMouseEvent;
22 using test::EqualsKeyEventWithoutLockStates; 24 using test::EqualsKeyEventWithoutLockStates;
23 25
24 namespace { 26 namespace {
25 27
26 static const MouseEvent::MouseButton BUTTON_LEFT = MouseEvent::BUTTON_LEFT; 28 static const MouseEvent::MouseButton BUTTON_LEFT = MouseEvent::BUTTON_LEFT;
27 static const MouseEvent::MouseButton BUTTON_RIGHT = MouseEvent::BUTTON_RIGHT; 29 static const MouseEvent::MouseButton BUTTON_RIGHT = MouseEvent::BUTTON_RIGHT;
28 30
29 MATCHER_P2(TouchPointIdsAndTypeEqual, ids, type, "") { 31 MATCHER_P2(TouchPointIdsAndTypeEqual, ids, type, "") {
30 if (arg.event_type() != type) 32 if (arg.event_type() != type)
31 return false; 33 return false;
32 34
33 std::set<uint32> touch_ids; 35 std::set<uint32_t> touch_ids;
34 for (const TouchEventPoint& point : arg.touch_points()) { 36 for (const TouchEventPoint& point : arg.touch_points()) {
35 touch_ids.insert(point.id()); 37 touch_ids.insert(point.id());
36 } 38 }
37 return touch_ids == ids; 39 return touch_ids == ids;
38 } 40 }
39 41
40 static KeyEvent NewUsbEvent(uint32 usb_keycode, bool pressed) { 42 static KeyEvent NewUsbEvent(uint32_t usb_keycode, bool pressed) {
41 KeyEvent event; 43 KeyEvent event;
42 event.set_usb_keycode(usb_keycode); 44 event.set_usb_keycode(usb_keycode);
43 event.set_pressed(pressed); 45 event.set_pressed(pressed);
44 // Create all key events with the hardcoded |lock_state| in this test. 46 // Create all key events with the hardcoded |lock_state| in this test.
45 event.set_lock_states(KeyEvent::LOCK_STATES_CAPSLOCK); 47 event.set_lock_states(KeyEvent::LOCK_STATES_CAPSLOCK);
46 return event; 48 return event;
47 } 49 }
48 50
49 static void PressAndReleaseUsb(InputStub* input_stub, uint32 usb_keycode) { 51 static void PressAndReleaseUsb(InputStub* input_stub, uint32_t usb_keycode) {
50 input_stub->InjectKeyEvent(NewUsbEvent(usb_keycode, true)); 52 input_stub->InjectKeyEvent(NewUsbEvent(usb_keycode, true));
51 input_stub->InjectKeyEvent(NewUsbEvent(usb_keycode, false)); 53 input_stub->InjectKeyEvent(NewUsbEvent(usb_keycode, false));
52 } 54 }
53 55
54 static MouseEvent NewMouseEvent(int x, 56 static MouseEvent NewMouseEvent(int x,
55 int y, 57 int y,
56 MouseEvent::MouseButton button, 58 MouseEvent::MouseButton button,
57 bool down) { 59 bool down) {
58 MouseEvent event; 60 MouseEvent event;
59 event.set_x(x); 61 event.set_x(x);
60 event.set_y(y); 62 event.set_y(y);
61 event.set_button(button); 63 event.set_button(button);
62 event.set_button_down(down); 64 event.set_button_down(down);
63 return event; 65 return event;
64 } 66 }
65 67
66 void AddTouchPoint(uint32 id, TouchEvent* event) { 68 void AddTouchPoint(uint32_t id, TouchEvent* event) {
67 TouchEventPoint* p = event->add_touch_points(); 69 TouchEventPoint* p = event->add_touch_points();
68 p->set_id(id); 70 p->set_id(id);
69 } 71 }
70 72
71 } // namespace 73 } // namespace
72 74
73 // Verify that keys that were pressed and released aren't re-released. 75 // Verify that keys that were pressed and released aren't re-released.
74 TEST(InputEventTrackerTest, NothingToRelease) { 76 TEST(InputEventTrackerTest, NothingToRelease) {
75 MockInputStub mock_stub; 77 MockInputStub mock_stub;
76 InputEventTracker input_tracker(&mock_stub); 78 InputEventTracker input_tracker(&mock_stub);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 255
254 input_tracker.ReleaseAll(); 256 input_tracker.ReleaseAll();
255 } 257 }
256 258
257 // All touch points added with multiple touch events should be released as a 259 // All touch points added with multiple touch events should be released as a
258 // cancel event. 260 // cancel event.
259 TEST(InputEventTrackerTest, ReleaseAllTouchPoints) { 261 TEST(InputEventTrackerTest, ReleaseAllTouchPoints) {
260 MockInputStub mock_stub; 262 MockInputStub mock_stub;
261 InputEventTracker input_tracker(&mock_stub); 263 InputEventTracker input_tracker(&mock_stub);
262 264
263 std::set<uint32> expected_ids1; 265 std::set<uint32_t> expected_ids1;
264 expected_ids1.insert(1); 266 expected_ids1.insert(1);
265 expected_ids1.insert(2); 267 expected_ids1.insert(2);
266 std::set<uint32> expected_ids2; 268 std::set<uint32_t> expected_ids2;
267 expected_ids2.insert(3); 269 expected_ids2.insert(3);
268 expected_ids2.insert(5); 270 expected_ids2.insert(5);
269 expected_ids2.insert(8); 271 expected_ids2.insert(8);
270 272
271 std::set<uint32> all_touch_point_ids; 273 std::set<uint32_t> all_touch_point_ids;
272 all_touch_point_ids.insert(expected_ids1.begin(), expected_ids1.end()); 274 all_touch_point_ids.insert(expected_ids1.begin(), expected_ids1.end());
273 all_touch_point_ids.insert(expected_ids2.begin(), expected_ids2.end()); 275 all_touch_point_ids.insert(expected_ids2.begin(), expected_ids2.end());
274 276
275 InSequence s; 277 InSequence s;
276 EXPECT_CALL(mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual( 278 EXPECT_CALL(mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual(
277 expected_ids1, TouchEvent::TOUCH_POINT_START))); 279 expected_ids1, TouchEvent::TOUCH_POINT_START)));
278 EXPECT_CALL(mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual( 280 EXPECT_CALL(mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual(
279 expected_ids2, TouchEvent::TOUCH_POINT_START))); 281 expected_ids2, TouchEvent::TOUCH_POINT_START)));
280 282
281 EXPECT_CALL(mock_stub, 283 EXPECT_CALL(mock_stub,
(...skipping 15 matching lines...) Expand all
297 299
298 input_tracker.ReleaseAll(); 300 input_tracker.ReleaseAll();
299 } 301 }
300 302
301 // Add some touch points and remove only a subset of them. ReleaseAll() should 303 // Add some touch points and remove only a subset of them. ReleaseAll() should
302 // cancel all the remaining touch points. 304 // cancel all the remaining touch points.
303 TEST(InputEventTrackerTest, ReleaseAllRemainingTouchPoints) { 305 TEST(InputEventTrackerTest, ReleaseAllRemainingTouchPoints) {
304 MockInputStub mock_stub; 306 MockInputStub mock_stub;
305 InputEventTracker input_tracker(&mock_stub); 307 InputEventTracker input_tracker(&mock_stub);
306 308
307 std::set<uint32> start_expected_ids; 309 std::set<uint32_t> start_expected_ids;
308 start_expected_ids.insert(1); 310 start_expected_ids.insert(1);
309 start_expected_ids.insert(2); 311 start_expected_ids.insert(2);
310 start_expected_ids.insert(3); 312 start_expected_ids.insert(3);
311 313
312 std::set<uint32> end_expected_ids; 314 std::set<uint32_t> end_expected_ids;
313 end_expected_ids.insert(1); 315 end_expected_ids.insert(1);
314 std::set<uint32> cancel_expected_ids; 316 std::set<uint32_t> cancel_expected_ids;
315 cancel_expected_ids.insert(3); 317 cancel_expected_ids.insert(3);
316 318
317 std::set<uint32> all_remaining_touch_point_ids; 319 std::set<uint32_t> all_remaining_touch_point_ids;
318 all_remaining_touch_point_ids.insert(2); 320 all_remaining_touch_point_ids.insert(2);
319 321
320 InSequence s; 322 InSequence s;
321 EXPECT_CALL(mock_stub, 323 EXPECT_CALL(mock_stub,
322 InjectTouchEvent(TouchPointIdsAndTypeEqual( 324 InjectTouchEvent(TouchPointIdsAndTypeEqual(
323 start_expected_ids, TouchEvent::TOUCH_POINT_START))); 325 start_expected_ids, TouchEvent::TOUCH_POINT_START)));
324 EXPECT_CALL(mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual( 326 EXPECT_CALL(mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual(
325 end_expected_ids, TouchEvent::TOUCH_POINT_END))); 327 end_expected_ids, TouchEvent::TOUCH_POINT_END)));
326 EXPECT_CALL(mock_stub, 328 EXPECT_CALL(mock_stub,
327 InjectTouchEvent(TouchPointIdsAndTypeEqual( 329 InjectTouchEvent(TouchPointIdsAndTypeEqual(
(...skipping 18 matching lines...) Expand all
346 TouchEvent cancel_event; 348 TouchEvent cancel_event;
347 cancel_event.set_event_type(TouchEvent::TOUCH_POINT_CANCEL); 349 cancel_event.set_event_type(TouchEvent::TOUCH_POINT_CANCEL);
348 AddTouchPoint(3, &cancel_event); 350 AddTouchPoint(3, &cancel_event);
349 input_tracker.InjectTouchEvent(cancel_event); 351 input_tracker.InjectTouchEvent(cancel_event);
350 352
351 input_tracker.ReleaseAll(); 353 input_tracker.ReleaseAll();
352 } 354 }
353 355
354 } // namespace protocol 356 } // namespace protocol
355 } // namespace remoting 357 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/input_event_tracker.h ('k') | remoting/protocol/input_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698