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

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

Issue 9465035: Move ClientSession's input logic into separate components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replace |authenticated_| with an InputFilter. Created 8 years, 8 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/protocol/input_event_tracker.h"
6
7 #include "remoting/proto/event.pb.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 using ::testing::_;
12 using ::testing::ExpectationSet;
13 using ::testing::InSequence;
14
15 namespace remoting {
16
17 static const protocol::MouseEvent::MouseButton BUTTON_LEFT =
18 protocol::MouseEvent::BUTTON_LEFT;
19 static const protocol::MouseEvent::MouseButton BUTTON_RIGHT =
20 protocol::MouseEvent::BUTTON_RIGHT;
21
22 MATCHER_P2(EqualsKeyEvent, keycode, pressed, "") {
23 return arg.keycode() == keycode && arg.pressed() == pressed;
24 }
25
26 MATCHER_P4(EqualsMouseEvent, x, y, button, down, "") {
27 return arg.x() == x && arg.y() == y && arg.button() == button &&
28 arg.button_down() == down;
29 }
30
31 class MockInputStub : public protocol::InputStub {
32 public:
33 MockInputStub() {}
34
35 MOCK_METHOD1(InjectKeyEvent, void(const protocol::KeyEvent&));
36 MOCK_METHOD1(InjectMouseEvent, void(const protocol::MouseEvent&));
37 private:
38 DISALLOW_COPY_AND_ASSIGN(MockInputStub);
39 };
40
41 static protocol::KeyEvent NewKeyEvent(int keycode, bool pressed) {
42 protocol::KeyEvent event;
43 event.set_keycode(keycode);
44 event.set_pressed(pressed);
45 return event;
46 }
47
48 static void PressAndReleaseKey(protocol::InputStub* input_stub, int keycode) {
49 input_stub->InjectKeyEvent(NewKeyEvent(keycode, true));
50 input_stub->InjectKeyEvent(NewKeyEvent(keycode, false));
51 }
52
53 static protocol::MouseEvent NewMouseEvent(int x, int y,
54 protocol::MouseEvent::MouseButton button, bool down) {
55 protocol::MouseEvent event;
56 event.set_x(x);
57 event.set_y(y);
58 event.set_button(button);
59 event.set_button_down(down);
60 return event;
61 }
62
63 // Verify that keys that were pressed and released aren't re-released.
64 TEST(InputEventTrackerTest, NothingToRelease) {
65 MockInputStub mock_stub;
66 protocol::InputEventTracker input_tracker(&mock_stub);
67
68 {
69 InSequence s;
70
71 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, true)));
72 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, false)));
73 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, true)));
74 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, false)));
75
76 EXPECT_CALL(mock_stub,
77 InjectMouseEvent(EqualsMouseEvent(0, 0, BUTTON_LEFT, true)));
78 EXPECT_CALL(mock_stub,
79 InjectMouseEvent(EqualsMouseEvent(0, 0, BUTTON_LEFT, false)));
80 }
81
82 PressAndReleaseKey(&input_tracker, 1);
83 PressAndReleaseKey(&input_tracker, 2);
84
85 input_tracker.InjectMouseEvent(NewMouseEvent(0, 0, BUTTON_LEFT, true));
86 input_tracker.InjectMouseEvent(NewMouseEvent(0, 0, BUTTON_LEFT, false));
87
88 input_tracker.ReleaseAll();
89 }
90
91 // Verify that keys that were left pressed get released.
92 TEST(InputEventTrackerTest, ReleaseAllKeys) {
93 MockInputStub mock_stub;
94 protocol::InputEventTracker input_tracker(&mock_stub);
95 ExpectationSet injects;
96
97 {
98 InSequence s;
99
100 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(3, true)));
101 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, true)));
102 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(1, false)));
103 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, true)));
104 injects += EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(2, false)));
105
106 injects += EXPECT_CALL(mock_stub,
107 InjectMouseEvent(EqualsMouseEvent(0, 0, BUTTON_RIGHT, true)));
108 injects += EXPECT_CALL(mock_stub,
109 InjectMouseEvent(EqualsMouseEvent(0, 0, BUTTON_LEFT, true)));
110 injects += EXPECT_CALL(mock_stub,
111 InjectMouseEvent(EqualsMouseEvent(1, 1, BUTTON_LEFT, false)));
112 }
113
114 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsKeyEvent(3, false)))
115 .After(injects);
116 EXPECT_CALL(mock_stub,
117 InjectMouseEvent(EqualsMouseEvent(1, 1, BUTTON_RIGHT, false)))
Sergey Ulanov 2012/03/30 20:33:54 nit: alight this line with (
Wez 2012/04/01 00:47:15 Done.
118 .After(injects);
119
120 input_tracker.InjectKeyEvent(NewKeyEvent(3, true));
121 PressAndReleaseKey(&input_tracker, 1);
122 PressAndReleaseKey(&input_tracker, 2);
123
124 input_tracker.InjectMouseEvent(NewMouseEvent(0, 0, BUTTON_RIGHT, true));
125 input_tracker.InjectMouseEvent(NewMouseEvent(0, 0, BUTTON_LEFT, true));
126 input_tracker.InjectMouseEvent(NewMouseEvent(1, 1, BUTTON_LEFT, false));
127
128 input_tracker.ReleaseAll();
129 }
130
131 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698