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

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

Issue 799233004: Add touch events to the protocol, the stub layer, and to the client plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add more comments to event proto Created 5 years, 10 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
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 "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
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
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 ExpectationSet injects;
264
265 std::set<uint32> expected_ids1;
266 expected_ids1.insert(1);
267 expected_ids1.insert(2);
268 std::set<uint32> expected_ids2;
269 expected_ids2.insert(3);
270 expected_ids2.insert(5);
271 expected_ids2.insert(8);
272
273 {
274 InSequence s;
275 injects += EXPECT_CALL(
276 mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual(
277 expected_ids1, TouchEvent::TOUCH_POINT_START)));
278 injects += EXPECT_CALL(
279 mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual(
280 expected_ids2, TouchEvent::TOUCH_POINT_START)));
281 }
Wez 2015/02/05 02:09:07 nit: Blank line between this and the next block
Rintaro Kuroiwa 2015/02/06 23:35:02 Done.
282 std::set<uint32> all_touch_point_ids;
283 all_touch_point_ids.insert(expected_ids1.begin(), expected_ids1.end());
284 all_touch_point_ids.insert(expected_ids2.begin(), expected_ids2.end());
285 EXPECT_CALL(mock_stub,
286 InjectTouchEvent(TouchPointIdsAndTypeEqual(
287 all_touch_point_ids, TouchEvent::TOUCH_POINT_CANCEL)))
288 .After(injects);
Wez 2015/02/05 02:09:07 Why is this not just in the sequence |s|?
Rintaro Kuroiwa 2015/02/06 23:35:02 This test works with InSequence. Removed Expecatat
289
290 TouchEvent start_event1;
291 start_event1.set_event_type(TouchEvent::TOUCH_POINT_START);
292 AddTouchPoint(1, &start_event1);
293 AddTouchPoint(2, &start_event1);
294 input_tracker.InjectTouchEvent(start_event1);
295
296 TouchEvent start_event2;
297 start_event2.set_event_type(TouchEvent::TOUCH_POINT_START);
298 AddTouchPoint(3, &start_event2);
299 AddTouchPoint(5, &start_event2);
300 AddTouchPoint(8, &start_event2);
301 input_tracker.InjectTouchEvent(start_event2);
302
303 input_tracker.ReleaseAll();
304 }
305
306 // Add some touch points and remove only a subset of them. ReleaseAll() should
307 // cancel all the remaining touch points.
308 TEST(InputEventTrackerTest, ReleaseAllRemainingTouchPoints) {
309 MockInputStub mock_stub;
310 InputEventTracker input_tracker(&mock_stub);
311 ExpectationSet injects;
312
313 std::set<uint32> start_expected_ids;
314 start_expected_ids.insert(1);
315 start_expected_ids.insert(2);
316 std::set<uint32> end_expected_ids;
317 end_expected_ids.insert(1);
318
319 {
320 InSequence s;
321 injects += EXPECT_CALL(
322 mock_stub,
323 InjectTouchEvent(TouchPointIdsAndTypeEqual(
324 start_expected_ids, TouchEvent::TOUCH_POINT_START)));
325 injects += EXPECT_CALL(
326 mock_stub,
327 InjectTouchEvent(TouchPointIdsAndTypeEqual(
328 end_expected_ids, TouchEvent::TOUCH_POINT_END)));
329 }
Wez 2015/02/05 02:09:07 nit: Blank line before next logical block.
Rintaro Kuroiwa 2015/02/06 23:35:02 Done.
330 std::set<uint32> all_remaining_touch_point_ids;
331 all_remaining_touch_point_ids.insert(2);
332 EXPECT_CALL(mock_stub, InjectTouchEvent(TouchPointIdsAndTypeEqual(
333 all_remaining_touch_point_ids,
334 TouchEvent::TOUCH_POINT_CANCEL)))
335 .After(injects);
Wez 2015/02/05 02:09:07 Why is this not just in the sequence |s|?
Rintaro Kuroiwa 2015/02/06 23:35:02 This test works with InSequence. Removed Expecatat
336
337 TouchEvent start_event;
338 start_event.set_event_type(TouchEvent::TOUCH_POINT_START);
339 AddTouchPoint(1, &start_event);
340 AddTouchPoint(2, &start_event);
341 input_tracker.InjectTouchEvent(start_event);
342
343 TouchEvent end_event;
344 end_event.set_event_type(TouchEvent::TOUCH_POINT_END);
345 AddTouchPoint(1, &end_event);
346 input_tracker.InjectTouchEvent(end_event);
347
348 input_tracker.ReleaseAll();
349 }
350
351 // All touch points are released before ReleaseAll() is called.
Wez 2015/02/05 02:09:08 Do you mean "test that no touch events are generat
Rintaro Kuroiwa 2015/02/06 23:35:02 Yes, that's what I meant :) True, the test above
352 TEST(InputEventTrackerTest, NoTouchPointsForReleaseAll) {
353 ::testing::StrictMock<MockInputStub> mock_stub;
354 InputEventTracker input_tracker(&mock_stub);
355
356 std::set<uint32> expected_ids;
357 expected_ids.insert(13);
358 expected_ids.insert(59);
359 {
360 InSequence s;
361 EXPECT_CALL(mock_stub,
362 InjectTouchEvent(TouchPointIdsAndTypeEqual(
363 expected_ids, TouchEvent::TOUCH_POINT_START)));
364 EXPECT_CALL(mock_stub,
365 InjectTouchEvent(TouchPointIdsAndTypeEqual(
366 expected_ids, TouchEvent::TOUCH_POINT_END)));
367 }
368
369 TouchEvent start_touch_event;
370 start_touch_event.set_event_type(TouchEvent::TOUCH_POINT_START);
371 AddTouchPoint(13, &start_touch_event);
372 AddTouchPoint(59, &start_touch_event);
373 input_tracker.InjectTouchEvent(start_touch_event);
374
375 TouchEvent end_touch_event;
376 end_touch_event.set_event_type(TouchEvent::TOUCH_POINT_END);
377 AddTouchPoint(13, &end_touch_event);
378 AddTouchPoint(59, &end_touch_event);
379 input_tracker.InjectTouchEvent(end_touch_event);
380
381 input_tracker.ReleaseAll();
382 }
383
242 } // namespace protocol 384 } // namespace protocol
243 } // namespace remoting 385 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698