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/host/remote_input_filter.h" | 5 #include "remoting/host/remote_input_filter.h" |
6 | 6 |
7 #include "remoting/proto/event.pb.h" | 7 #include "remoting/proto/event.pb.h" |
8 #include "remoting/protocol/input_event_tracker.h" | 8 #include "remoting/protocol/input_event_tracker.h" |
9 #include "remoting/protocol/protocol_mock_objects.h" | 9 #include "remoting/protocol/protocol_mock_objects.h" |
| 10 #include "remoting/protocol/test_event_matchers.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 using ::testing::_; | 14 using ::testing::_; |
14 using ::testing::ExpectationSet; | 15 using ::testing::ExpectationSet; |
15 using ::testing::InSequence; | 16 using ::testing::InSequence; |
16 | 17 |
17 namespace remoting { | 18 namespace remoting { |
18 | 19 |
| 20 using protocol::EqualsTouchEventTypeAndId; |
| 21 using protocol::EqualsUsbEvent; |
| 22 using protocol::InputEventTracker; |
19 using protocol::MockInputStub; | 23 using protocol::MockInputStub; |
20 using protocol::InputEventTracker; | |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") { | |
25 return arg.usb_keycode() == (unsigned int)usb_keycode && | |
26 arg.pressed() == pressed; | |
27 } | |
28 | |
29 static protocol::MouseEvent MouseMoveEvent(int x, int y) { | 27 static protocol::MouseEvent MouseMoveEvent(int x, int y) { |
30 protocol::MouseEvent event; | 28 protocol::MouseEvent event; |
31 event.set_x(x); | 29 event.set_x(x); |
32 event.set_y(y); | 30 event.set_y(y); |
33 return event; | 31 return event; |
34 } | 32 } |
35 | 33 |
36 static protocol::KeyEvent UsbKeyEvent(int usb_keycode, bool pressed) { | 34 static protocol::KeyEvent UsbKeyEvent(int usb_keycode, bool pressed) { |
37 protocol::KeyEvent event; | 35 protocol::KeyEvent event; |
38 event.set_usb_keycode(usb_keycode); | 36 event.set_usb_keycode(usb_keycode); |
39 event.set_pressed(pressed); | 37 event.set_pressed(pressed); |
40 return event; | 38 return event; |
41 } | 39 } |
42 | 40 |
43 MATCHER_P2(EqualsTouchEvent, type, id, "") { | |
44 if (arg.event_type() != type) | |
45 return false; | |
46 | |
47 // Expect only one touch point. | |
48 if (arg.touch_points().size() != 1) | |
49 return false; | |
50 | |
51 return arg.touch_points(0).id() == id; | |
52 } | |
53 | |
54 protocol::TouchEvent TouchStartEvent(uint32_t id) { | 41 protocol::TouchEvent TouchStartEvent(uint32_t id) { |
55 protocol::TouchEvent event; | 42 protocol::TouchEvent event; |
56 event.set_event_type(protocol::TouchEvent::TOUCH_POINT_START); | 43 event.set_event_type(protocol::TouchEvent::TOUCH_POINT_START); |
57 | 44 |
58 protocol::TouchEventPoint* point = event.add_touch_points(); | 45 protocol::TouchEventPoint* point = event.add_touch_points(); |
59 point->set_id(id); | 46 point->set_id(id); |
60 point->set_x(0.0f); | 47 point->set_x(0.0f); |
61 point->set_y(0.0f); | 48 point->set_y(0.0f); |
62 point->set_radius_x(0.0f); | 49 point->set_radius_x(0.0f); |
63 point->set_radius_y(0.0f); | 50 point->set_radius_y(0.0f); |
64 point->set_angle(0.0f); | 51 point->set_angle(0.0f); |
65 point->set_pressure(0.0f); | 52 point->set_pressure(0.0f); |
66 return event; | 53 return event; |
67 } | 54 } |
68 | 55 |
69 } | 56 } // namespace |
70 | 57 |
71 // Verify that events get through if there is no local activity. | 58 // Verify that events get through if there is no local activity. |
72 TEST(RemoteInputFilterTest, NoLocalActivity) { | 59 TEST(RemoteInputFilterTest, NoLocalActivity) { |
73 MockInputStub mock_stub; | 60 MockInputStub mock_stub; |
74 InputEventTracker input_tracker(&mock_stub); | 61 InputEventTracker input_tracker(&mock_stub); |
75 RemoteInputFilter input_filter(&input_tracker); | 62 RemoteInputFilter input_filter(&input_tracker); |
76 | 63 |
77 EXPECT_CALL(mock_stub, InjectMouseEvent(_)) | 64 EXPECT_CALL(mock_stub, InjectMouseEvent(_)).Times(10); |
78 .Times(10); | |
79 | 65 |
80 for (int i = 0; i < 10; ++i) | 66 for (int i = 0; i < 10; ++i) |
81 input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); | 67 input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); |
82 } | 68 } |
83 | 69 |
84 // Verify that events get through until there is local activity. | 70 // Verify that events get through until there is local activity. |
85 TEST(RemoteInputFilterTest, MismatchedLocalActivity) { | 71 TEST(RemoteInputFilterTest, MismatchedLocalActivity) { |
86 MockInputStub mock_stub; | 72 MockInputStub mock_stub; |
87 InputEventTracker input_tracker(&mock_stub); | 73 InputEventTracker input_tracker(&mock_stub); |
88 RemoteInputFilter input_filter(&input_tracker); | 74 RemoteInputFilter input_filter(&input_tracker); |
89 | 75 |
90 EXPECT_CALL(mock_stub, InjectMouseEvent(_)) | 76 EXPECT_CALL(mock_stub, InjectMouseEvent(_)).Times(5); |
91 .Times(5); | |
92 | 77 |
93 for (int i = 0; i < 10; ++i) { | 78 for (int i = 0; i < 10; ++i) { |
94 input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); | 79 input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); |
95 if (i == 4) | 80 if (i == 4) |
96 input_filter.LocalMouseMoved(webrtc::DesktopVector(1, 1)); | 81 input_filter.LocalMouseMoved(webrtc::DesktopVector(1, 1)); |
97 } | 82 } |
98 } | 83 } |
99 | 84 |
100 // Verify that echos of injected events don't block activity. | 85 // Verify that echos of injected events don't block activity. |
101 TEST(RemoteInputFilterTest, LocalEchoesOfRemoteActivity) { | 86 TEST(RemoteInputFilterTest, LocalEchoesOfRemoteActivity) { |
102 MockInputStub mock_stub; | 87 MockInputStub mock_stub; |
103 InputEventTracker input_tracker(&mock_stub); | 88 InputEventTracker input_tracker(&mock_stub); |
104 RemoteInputFilter input_filter(&input_tracker); | 89 RemoteInputFilter input_filter(&input_tracker); |
105 | 90 |
106 EXPECT_CALL(mock_stub, InjectMouseEvent(_)) | 91 EXPECT_CALL(mock_stub, InjectMouseEvent(_)).Times(10); |
107 .Times(10); | |
108 | 92 |
109 for (int i = 0; i < 10; ++i) { | 93 for (int i = 0; i < 10; ++i) { |
110 input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); | 94 input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); |
111 input_filter.LocalMouseMoved(webrtc::DesktopVector(0, 0)); | 95 input_filter.LocalMouseMoved(webrtc::DesktopVector(0, 0)); |
112 } | 96 } |
113 } | 97 } |
114 | 98 |
115 // Verify that echos followed by a mismatch blocks activity. | 99 // Verify that echos followed by a mismatch blocks activity. |
116 TEST(RemoteInputFilterTest, LocalEchosAndLocalActivity) { | 100 TEST(RemoteInputFilterTest, LocalEchosAndLocalActivity) { |
117 MockInputStub mock_stub; | 101 MockInputStub mock_stub; |
118 InputEventTracker input_tracker(&mock_stub); | 102 InputEventTracker input_tracker(&mock_stub); |
119 RemoteInputFilter input_filter(&input_tracker); | 103 RemoteInputFilter input_filter(&input_tracker); |
120 | 104 |
121 EXPECT_CALL(mock_stub, InjectMouseEvent(_)) | 105 EXPECT_CALL(mock_stub, InjectMouseEvent(_)).Times(5); |
122 .Times(5); | |
123 | 106 |
124 for (int i = 0; i < 10; ++i) { | 107 for (int i = 0; i < 10; ++i) { |
125 input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); | 108 input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); |
126 input_filter.LocalMouseMoved(webrtc::DesktopVector(0, 0)); | 109 input_filter.LocalMouseMoved(webrtc::DesktopVector(0, 0)); |
127 if (i == 4) | 110 if (i == 4) |
128 input_filter.LocalMouseMoved(webrtc::DesktopVector(1, 1)); | 111 input_filter.LocalMouseMoved(webrtc::DesktopVector(1, 1)); |
129 } | 112 } |
130 } | 113 } |
131 | 114 |
132 // Verify that local activity also causes buttons, keys, and touches to be | 115 // Verify that local activity also causes buttons, keys, and touches to be |
133 // released. | 116 // released. |
134 TEST(RemoteInputFilterTest, LocalActivityReleasesAll) { | 117 TEST(RemoteInputFilterTest, LocalActivityReleasesAll) { |
135 MockInputStub mock_stub; | 118 MockInputStub mock_stub; |
136 InputEventTracker input_tracker(&mock_stub); | 119 InputEventTracker input_tracker(&mock_stub); |
137 RemoteInputFilter input_filter(&input_tracker); | 120 RemoteInputFilter input_filter(&input_tracker); |
138 | 121 |
139 EXPECT_CALL(mock_stub, InjectMouseEvent(_)) | 122 EXPECT_CALL(mock_stub, InjectMouseEvent(_)).Times(5); |
140 .Times(5); | |
141 | 123 |
142 // Use release of a key as a proxy for InputEventTracker::ReleaseAll() | 124 // Use release of a key as a proxy for InputEventTracker::ReleaseAll() |
143 // having been called, rather than mocking it. | 125 // having been called, rather than mocking it. |
144 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(0, true))); | 126 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(0, true))); |
145 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(0, false))); | 127 EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(0, false))); |
146 input_filter.InjectKeyEvent(UsbKeyEvent(0, true)); | 128 input_filter.InjectKeyEvent(UsbKeyEvent(0, true)); |
147 | 129 |
148 // Touch points that are down should be canceled. | 130 // Touch points that are down should be canceled. |
149 EXPECT_CALL(mock_stub, InjectTouchEvent(EqualsTouchEvent( | 131 EXPECT_CALL(mock_stub, InjectTouchEvent(EqualsTouchEventTypeAndId( |
150 protocol::TouchEvent::TOUCH_POINT_START, 0u))); | 132 protocol::TouchEvent::TOUCH_POINT_START, 0u))); |
151 EXPECT_CALL(mock_stub, InjectTouchEvent(EqualsTouchEvent( | 133 EXPECT_CALL(mock_stub, InjectTouchEvent(EqualsTouchEventTypeAndId( |
152 protocol::TouchEvent::TOUCH_POINT_CANCEL, 0u))); | 134 protocol::TouchEvent::TOUCH_POINT_CANCEL, 0u))); |
153 input_filter.InjectTouchEvent(TouchStartEvent(0u)); | 135 input_filter.InjectTouchEvent(TouchStartEvent(0u)); |
154 | 136 |
155 for (int i = 0; i < 10; ++i) { | 137 for (int i = 0; i < 10; ++i) { |
156 input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); | 138 input_filter.InjectMouseEvent(MouseMoveEvent(0, 0)); |
157 input_filter.LocalMouseMoved(webrtc::DesktopVector(0, 0)); | 139 input_filter.LocalMouseMoved(webrtc::DesktopVector(0, 0)); |
158 if (i == 4) | 140 if (i == 4) |
159 input_filter.LocalMouseMoved(webrtc::DesktopVector(1, 1)); | 141 input_filter.LocalMouseMoved(webrtc::DesktopVector(1, 1)); |
160 } | 142 } |
161 } | 143 } |
162 | 144 |
163 } // namespace remoting | 145 } // namespace remoting |
OLD | NEW |