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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "remoting/base/auto_thread_task_runner.h" | 6 #include "remoting/base/auto_thread_task_runner.h" |
7 #include "remoting/base/constants.h" | 7 #include "remoting/base/constants.h" |
8 #include "remoting/capturer/video_capturer_mock_objects.h" | 8 #include "remoting/capturer/video_capturer_mock_objects.h" |
9 #include "remoting/capturer/video_frame_capturer_fake.h" | |
10 #include "remoting/host/audio_capturer.h" | 9 #include "remoting/host/audio_capturer.h" |
11 #include "remoting/host/client_session.h" | 10 #include "remoting/host/client_session.h" |
12 #include "remoting/host/desktop_environment.h" | 11 #include "remoting/host/desktop_environment.h" |
13 #include "remoting/host/host_mock_objects.h" | 12 #include "remoting/host/host_mock_objects.h" |
14 #include "remoting/protocol/protocol_mock_objects.h" | 13 #include "remoting/protocol/protocol_mock_objects.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 namespace remoting { | 16 namespace remoting { |
18 | 17 |
19 using protocol::MockConnectionToClient; | 18 using protocol::MockConnectionToClient; |
20 using protocol::MockClientStub; | 19 using protocol::MockClientStub; |
21 using protocol::MockHostStub; | 20 using protocol::MockHostStub; |
22 using protocol::MockInputStub; | 21 using protocol::MockInputStub; |
23 using protocol::MockSession; | 22 using protocol::MockSession; |
24 using protocol::MockVideoStub; | 23 using protocol::MockVideoStub; |
25 using protocol::SessionConfig; | 24 using protocol::SessionConfig; |
26 | 25 |
27 using testing::_; | 26 using testing::_; |
28 using testing::AnyNumber; | 27 using testing::AnyNumber; |
29 using testing::DeleteArg; | 28 using testing::DeleteArg; |
30 using testing::DoAll; | |
31 using testing::Expectation; | 29 using testing::Expectation; |
32 using testing::InSequence; | 30 using testing::InSequence; |
33 using testing::Return; | 31 using testing::Return; |
34 using testing::ReturnRef; | 32 using testing::ReturnRef; |
35 | 33 |
36 namespace { | |
37 | |
38 ACTION_P2(InjectClipboardEvent, connection, event) { | |
39 connection->clipboard_stub()->InjectClipboardEvent(event); | |
40 } | |
41 | |
42 ACTION_P2(InjectKeyEvent, connection, event) { | |
43 connection->input_stub()->InjectKeyEvent(event); | |
44 } | |
45 | |
46 ACTION_P2(InjectMouseEvent, connection, event) { | |
47 connection->input_stub()->InjectMouseEvent(event); | |
48 } | |
49 | |
50 ACTION_P2(LocalMouseMoved, client_session, event) { | |
51 client_session->LocalMouseMoved(SkIPoint::Make(event.x(), event.y())); | |
52 } | |
53 | |
54 } // namespace | |
55 | |
56 class ClientSessionTest : public testing::Test { | 34 class ClientSessionTest : public testing::Test { |
57 public: | 35 public: |
58 ClientSessionTest() | 36 ClientSessionTest() : event_executor_(NULL) {} |
59 : client_jid_("user@domain/rest-of-jid"), | |
60 event_executor_(NULL) {} | |
61 | 37 |
62 virtual void SetUp() OVERRIDE; | 38 virtual void SetUp() OVERRIDE { |
63 virtual void TearDown() OVERRIDE; | 39 ui_task_runner_ = new AutoThreadTaskRunner( |
| 40 message_loop_.message_loop_proxy(), |
| 41 base::Bind(&ClientSessionTest::QuitMainMessageLoop, |
| 42 base::Unretained(this))); |
64 | 43 |
65 // Disconnects the client session. | 44 client_jid_ = "user@domain/rest-of-jid"; |
66 void DisconnectClientSession(); | |
67 | 45 |
68 // Asynchronously stops the client session. OnClientStopped() will be called | 46 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); |
69 // once the client session is fully stopped. | 47 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) |
70 void StopClientSession(); | 48 .Times(AnyNumber()) |
| 49 .WillRepeatedly(Invoke(this, |
| 50 &ClientSessionTest::CreateDesktopEnvironment)); |
| 51 |
| 52 // Set up a large default screen size that won't affect most tests. |
| 53 screen_size_.set(1000, 1000); |
| 54 |
| 55 session_config_ = SessionConfig::ForTest(); |
| 56 |
| 57 // Mock protocol::Session APIs called directly by ClientSession. |
| 58 protocol::MockSession* session = new MockSession(); |
| 59 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(session_config_)); |
| 60 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); |
| 61 EXPECT_CALL(*session, SetEventHandler(_)); |
| 62 |
| 63 // Mock protocol::ConnectionToClient APIs called directly by ClientSession. |
| 64 // HostStub is not touched by ClientSession, so we can safely pass NULL. |
| 65 scoped_ptr<MockConnectionToClient> connection( |
| 66 new MockConnectionToClient(session, NULL)); |
| 67 EXPECT_CALL(*connection, session()).WillRepeatedly(Return(session)); |
| 68 EXPECT_CALL(*connection, client_stub()) |
| 69 .WillRepeatedly(Return(&client_stub_)); |
| 70 EXPECT_CALL(*connection, video_stub()).WillRepeatedly(Return(&video_stub_)); |
| 71 EXPECT_CALL(*connection, Disconnect()); |
| 72 connection_ = connection.get(); |
| 73 |
| 74 client_session_ = new ClientSession( |
| 75 &session_event_handler_, |
| 76 ui_task_runner_, // Audio thread. |
| 77 ui_task_runner_, // Capture thread. |
| 78 ui_task_runner_, // Encode thread. |
| 79 ui_task_runner_, // Network thread. |
| 80 connection.PassAs<protocol::ConnectionToClient>(), |
| 81 desktop_environment_factory_.get(), |
| 82 base::TimeDelta()); |
| 83 } |
| 84 |
| 85 virtual void TearDown() OVERRIDE { |
| 86 // MockClientSessionEventHandler won't trigger Stop, so fake it. |
| 87 client_session_->Stop(base::Bind( |
| 88 &ClientSessionTest::OnClientStopped, base::Unretained(this))); |
| 89 |
| 90 // Run message loop before destroying because the session is destroyed |
| 91 // asynchronously. |
| 92 ui_task_runner_ = NULL; |
| 93 message_loop_.Run(); |
| 94 |
| 95 // Verify that the client session has been stopped. |
| 96 EXPECT_TRUE(client_session_.get() == NULL); |
| 97 } |
71 | 98 |
72 protected: | 99 protected: |
73 // Creates a DesktopEnvironment with a fake VideoFrameCapturer, to mock | 100 DesktopEnvironment* CreateDesktopEnvironment() { |
74 // DesktopEnvironmentFactory::Create(). | 101 MockVideoFrameCapturer* capturer = new MockVideoFrameCapturer(); |
75 DesktopEnvironment* CreateDesktopEnvironment(); | 102 EXPECT_CALL(*capturer, Start(_)); |
| 103 EXPECT_CALL(*capturer, Stop()); |
| 104 EXPECT_CALL(*capturer, InvalidateRegion(_)).Times(AnyNumber()); |
| 105 EXPECT_CALL(*capturer, CaptureFrame()).Times(AnyNumber()); |
| 106 EXPECT_CALL(*capturer, size_most_recent()) |
| 107 .WillRepeatedly(ReturnRef(screen_size_)); |
76 | 108 |
77 // Notifies the client session that the client connection has been | 109 EXPECT_TRUE(!event_executor_); |
78 // authenticated and channels have been connected. This effectively enables | 110 event_executor_ = new MockEventExecutor(); |
79 // the input pipe line and starts video capturing. | 111 return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL), |
80 void ConnectClientSession(); | 112 scoped_ptr<EventExecutor>(event_executor_), |
| 113 scoped_ptr<VideoFrameCapturer>(capturer)); |
| 114 } |
81 | 115 |
82 // Invoked when the last reference to the AutoThreadTaskRunner has been | 116 void DisconnectClientSession() { |
83 // released and quits the message loop to finish the test. | 117 client_session_->Disconnect(); |
84 void QuitMainMessageLoop(); | 118 // MockSession won't trigger OnConnectionClosed, so fake it. |
| 119 client_session_->OnConnectionClosed(client_session_->connection(), |
| 120 protocol::OK); |
| 121 } |
85 | 122 |
86 // Releases the ClientSession when it has been fully stopped, allowing | 123 void QuitMainMessageLoop() { |
87 // the MessageLoop to quit. | 124 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
88 void OnClientStopped(); | 125 } |
| 126 |
| 127 void OnClientStopped() { |
| 128 client_session_ = NULL; |
| 129 } |
89 | 130 |
90 // Message loop passed to |client_session_| to perform all functions on. | 131 // Message loop passed to |client_session_| to perform all functions on. |
91 MessageLoop message_loop_; | 132 MessageLoop message_loop_; |
| 133 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
92 | 134 |
93 // ClientSession instance under test. | 135 // ClientSession instance under test. |
94 scoped_refptr<ClientSession> client_session_; | 136 scoped_refptr<ClientSession> client_session_; |
95 | 137 |
96 // ClientSession::EventHandler mock for use in tests. | 138 // ClientSession::EventHandler mock for use in tests. |
97 MockClientSessionEventHandler session_event_handler_; | 139 MockClientSessionEventHandler session_event_handler_; |
98 | 140 |
| 141 // Screen size that the fake VideoFrameCapturer should report. |
| 142 SkISize screen_size_; |
| 143 |
99 // Storage for values to be returned by the protocol::Session mock. | 144 // Storage for values to be returned by the protocol::Session mock. |
100 SessionConfig session_config_; | 145 SessionConfig session_config_; |
101 const std::string client_jid_; | 146 std::string client_jid_; |
102 | 147 |
103 // Stubs returned to |client_session_| components by |connection_|. | 148 // Stubs returned to |client_session_| components by |connection_|. |
104 MockClientStub client_stub_; | 149 MockClientStub client_stub_; |
105 MockVideoStub video_stub_; | 150 MockVideoStub video_stub_; |
106 | 151 |
107 // DesktopEnvironment owns |event_executor_|, but input injection tests need | 152 // DesktopEnvironment owns |event_executor_|, but input injection tests need |
108 // to express expectations on it. | 153 // to express expectations on it. |
109 MockEventExecutor* event_executor_; | 154 MockEventExecutor* event_executor_; |
110 | 155 |
111 // ClientSession owns |connection_| but tests need it to inject fake events. | 156 // ClientSession owns |connection_| but tests need it to inject fake events. |
112 MockConnectionToClient* connection_; | 157 MockConnectionToClient* connection_; |
113 | 158 |
114 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; | 159 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; |
115 }; | 160 }; |
116 | 161 |
117 void ClientSessionTest::SetUp() { | |
118 // Arrange to run |message_loop_| until no components depend on it. | |
119 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = new AutoThreadTaskRunner( | |
120 message_loop_.message_loop_proxy(), | |
121 base::Bind(&ClientSessionTest::QuitMainMessageLoop, | |
122 base::Unretained(this))); | |
123 | |
124 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); | |
125 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) | |
126 .Times(AnyNumber()) | |
127 .WillRepeatedly(Invoke(this, | |
128 &ClientSessionTest::CreateDesktopEnvironment)); | |
129 | |
130 session_config_ = SessionConfig::ForTest(); | |
131 | |
132 // Mock protocol::Session APIs called directly by ClientSession. | |
133 protocol::MockSession* session = new MockSession(); | |
134 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(session_config_)); | |
135 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); | |
136 EXPECT_CALL(*session, SetEventHandler(_)); | |
137 | |
138 // Mock protocol::ConnectionToClient APIs called directly by ClientSession. | |
139 // HostStub is not touched by ClientSession, so we can safely pass NULL. | |
140 scoped_ptr<MockConnectionToClient> connection( | |
141 new MockConnectionToClient(session, NULL)); | |
142 EXPECT_CALL(*connection, session()).WillRepeatedly(Return(session)); | |
143 EXPECT_CALL(*connection, client_stub()) | |
144 .WillRepeatedly(Return(&client_stub_)); | |
145 EXPECT_CALL(*connection, video_stub()).WillRepeatedly(Return(&video_stub_)); | |
146 EXPECT_CALL(*connection, Disconnect()); | |
147 connection_ = connection.get(); | |
148 | |
149 client_session_ = new ClientSession( | |
150 &session_event_handler_, | |
151 ui_task_runner, // Audio thread. | |
152 ui_task_runner, // Capture thread. | |
153 ui_task_runner, // Encode thread. | |
154 ui_task_runner, // Network thread. | |
155 connection.PassAs<protocol::ConnectionToClient>(), | |
156 desktop_environment_factory_.get(), | |
157 base::TimeDelta()); | |
158 } | |
159 | |
160 void ClientSessionTest::TearDown() { | |
161 // Verify that the client session has been stopped. | |
162 EXPECT_TRUE(client_session_.get() == NULL); | |
163 } | |
164 | |
165 void ClientSessionTest::DisconnectClientSession() { | |
166 client_session_->Disconnect(); | |
167 // MockSession won't trigger OnConnectionClosed, so fake it. | |
168 client_session_->OnConnectionClosed(client_session_->connection(), | |
169 protocol::OK); | |
170 } | |
171 | |
172 void ClientSessionTest::StopClientSession() { | |
173 // MockClientSessionEventHandler won't trigger Stop, so fake it. | |
174 client_session_->Stop(base::Bind( | |
175 &ClientSessionTest::OnClientStopped, base::Unretained(this))); | |
176 } | |
177 | |
178 DesktopEnvironment* ClientSessionTest::CreateDesktopEnvironment() { | |
179 scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake()); | |
180 | |
181 EXPECT_TRUE(!event_executor_); | |
182 event_executor_ = new MockEventExecutor(); | |
183 return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL), | |
184 scoped_ptr<EventExecutor>(event_executor_), | |
185 video_capturer.Pass()); | |
186 } | |
187 | |
188 void ClientSessionTest::ConnectClientSession() { | |
189 client_session_->OnConnectionAuthenticated(client_session_->connection()); | |
190 client_session_->OnConnectionChannelsConnected(client_session_->connection()); | |
191 } | |
192 | |
193 void ClientSessionTest::QuitMainMessageLoop() { | |
194 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | |
195 } | |
196 | |
197 void ClientSessionTest::OnClientStopped() { | |
198 client_session_ = NULL; | |
199 } | |
200 | |
201 MATCHER_P2(EqualsClipboardEvent, m, d, "") { | 162 MATCHER_P2(EqualsClipboardEvent, m, d, "") { |
202 return (strcmp(arg.mime_type().c_str(), m) == 0 && | 163 return (strcmp(arg.mime_type().c_str(), m) == 0 && |
203 memcmp(arg.data().data(), d, arg.data().size()) == 0); | 164 memcmp(arg.data().data(), d, arg.data().size()) == 0); |
204 } | 165 } |
205 | 166 |
206 TEST_F(ClientSessionTest, ClipboardStubFilter) { | 167 TEST_F(ClientSessionTest, ClipboardStubFilter) { |
207 protocol::ClipboardEvent clipboard_event1; | 168 protocol::ClipboardEvent clipboard_event1; |
208 clipboard_event1.set_mime_type(kMimeTypeTextUtf8); | 169 clipboard_event1.set_mime_type(kMimeTypeTextUtf8); |
209 clipboard_event1.set_data("a"); | 170 clipboard_event1.set_data("a"); |
210 | 171 |
211 protocol::ClipboardEvent clipboard_event2; | 172 protocol::ClipboardEvent clipboard_event2; |
212 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); | 173 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); |
213 clipboard_event2.set_data("b"); | 174 clipboard_event2.set_data("b"); |
214 | 175 |
215 protocol::ClipboardEvent clipboard_event3; | 176 protocol::ClipboardEvent clipboard_event3; |
216 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); | 177 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); |
217 clipboard_event3.set_data("c"); | 178 clipboard_event3.set_data("c"); |
218 | 179 |
219 InSequence s; | 180 InSequence s; |
220 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 181 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
221 EXPECT_CALL(*event_executor_, StartPtr(_)); | 182 EXPECT_CALL(*event_executor_, StartPtr(_)); |
222 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 183 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
223 | |
224 // Wait for the first video packet to be captured to make sure that | |
225 // the injected input will go though. Otherwise mouse events will be blocked | |
226 // by the mouse clamping filter. | |
227 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | |
228 .WillOnce(DoAll( | |
229 // This event should get through to the clipboard stub. | |
230 InjectClipboardEvent(connection_, clipboard_event2), | |
231 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | |
232 // This event should not get through to the clipboard stub, | |
233 // because the client has disconnected. | |
234 InjectClipboardEvent(connection_, clipboard_event3), | |
235 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | |
236 EXPECT_CALL(*event_executor_, InjectClipboardEvent(EqualsClipboardEvent( | 184 EXPECT_CALL(*event_executor_, InjectClipboardEvent(EqualsClipboardEvent( |
237 kMimeTypeTextUtf8, "b"))); | 185 kMimeTypeTextUtf8, "b"))); |
238 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 186 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
239 | 187 |
240 // This event should not get through to the clipboard stub, | 188 // This event should not get through to the clipboard stub, |
241 // because the client isn't authenticated yet. | 189 // because the client isn't authenticated yet. |
242 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1); | 190 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1); |
243 | 191 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
244 ConnectClientSession(); | 192 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
245 message_loop_.Run(); | 193 // This event should get through to the clipboard stub. |
| 194 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event2); |
| 195 DisconnectClientSession(); |
| 196 // This event should not get through to the clipboard stub, |
| 197 // because the client has disconnected. |
| 198 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event3); |
246 } | 199 } |
247 | 200 |
248 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") { | 201 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") { |
249 return arg.usb_keycode() == (unsigned int)usb_keycode && | 202 return arg.usb_keycode() == (unsigned int)usb_keycode && |
250 arg.pressed() == pressed; | 203 arg.pressed() == pressed; |
251 } | 204 } |
252 | 205 |
253 MATCHER_P2(EqualsMouseEvent, x, y, "") { | 206 MATCHER_P2(EqualsMouseEvent, x, y, "") { |
254 return arg.x() == x && arg.y() == y; | 207 return arg.x() == x && arg.y() == y; |
255 } | 208 } |
(...skipping 28 matching lines...) Expand all Loading... |
284 mouse_event2.set_y(201); | 237 mouse_event2.set_y(201); |
285 | 238 |
286 protocol::MouseEvent mouse_event3; | 239 protocol::MouseEvent mouse_event3; |
287 mouse_event3.set_x(300); | 240 mouse_event3.set_x(300); |
288 mouse_event3.set_y(301); | 241 mouse_event3.set_y(301); |
289 | 242 |
290 InSequence s; | 243 InSequence s; |
291 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 244 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
292 EXPECT_CALL(*event_executor_, StartPtr(_)); | 245 EXPECT_CALL(*event_executor_, StartPtr(_)); |
293 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 246 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
294 | |
295 // Wait for the first video packet to be captured to make sure that | |
296 // the injected input will go though. Otherwise mouse events will be blocked | |
297 // by the mouse clamping filter. | |
298 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | |
299 .WillOnce(DoAll( | |
300 // These events should get through to the input stub. | |
301 InjectKeyEvent(connection_, key_event2_down), | |
302 InjectKeyEvent(connection_, key_event2_up), | |
303 InjectMouseEvent(connection_, mouse_event2), | |
304 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | |
305 // These events should not get through to the input stub, | |
306 // because the client has disconnected. | |
307 InjectKeyEvent(connection_, key_event3), | |
308 InjectMouseEvent(connection_, mouse_event3), | |
309 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | |
310 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))); | 247 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))); |
311 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))); | 248 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))); |
312 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))); | 249 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))); |
313 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 250 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
314 | 251 |
315 // These events should not get through to the input stub, | 252 // These events should not get through to the input stub, |
316 // because the client isn't authenticated yet. | 253 // because the client isn't authenticated yet. |
317 connection_->input_stub()->InjectKeyEvent(key_event1); | 254 connection_->input_stub()->InjectKeyEvent(key_event1); |
318 connection_->input_stub()->InjectMouseEvent(mouse_event1); | 255 connection_->input_stub()->InjectMouseEvent(mouse_event1); |
319 | 256 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
320 ConnectClientSession(); | 257 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
321 message_loop_.Run(); | 258 // These events should get through to the input stub. |
| 259 connection_->input_stub()->InjectKeyEvent(key_event2_down); |
| 260 connection_->input_stub()->InjectKeyEvent(key_event2_up); |
| 261 connection_->input_stub()->InjectMouseEvent(mouse_event2); |
| 262 DisconnectClientSession(); |
| 263 // These events should not get through to the input stub, |
| 264 // because the client has disconnected. |
| 265 connection_->input_stub()->InjectKeyEvent(key_event3); |
| 266 connection_->input_stub()->InjectMouseEvent(mouse_event3); |
322 } | 267 } |
323 | 268 |
324 TEST_F(ClientSessionTest, LocalInputTest) { | 269 TEST_F(ClientSessionTest, LocalInputTest) { |
325 protocol::MouseEvent mouse_event1; | 270 protocol::MouseEvent mouse_event1; |
326 mouse_event1.set_x(100); | 271 mouse_event1.set_x(100); |
327 mouse_event1.set_y(101); | 272 mouse_event1.set_y(101); |
328 protocol::MouseEvent mouse_event2; | 273 protocol::MouseEvent mouse_event2; |
329 mouse_event2.set_x(200); | 274 mouse_event2.set_x(200); |
330 mouse_event2.set_y(201); | 275 mouse_event2.set_y(201); |
331 protocol::MouseEvent mouse_event3; | 276 protocol::MouseEvent mouse_event3; |
332 mouse_event3.set_x(300); | 277 mouse_event3.set_x(300); |
333 mouse_event3.set_y(301); | 278 mouse_event3.set_y(301); |
334 | 279 |
335 InSequence s; | 280 InSequence s; |
336 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 281 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
337 EXPECT_CALL(*event_executor_, StartPtr(_)); | 282 EXPECT_CALL(*event_executor_, StartPtr(_)); |
338 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 283 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
339 | |
340 // Wait for the first video packet to be captured to make sure that | |
341 // the injected input will go though. Otherwise mouse events will be blocked | |
342 // by the mouse clamping filter. | |
343 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | |
344 .WillOnce(DoAll( | |
345 // This event should get through to the input stub. | |
346 InjectMouseEvent(connection_, mouse_event1), | |
347 // This one should too because the local event echoes the remote one. | |
348 LocalMouseMoved(client_session_.get(), mouse_event1), | |
349 InjectMouseEvent(connection_, mouse_event2), | |
350 // This one should not. | |
351 LocalMouseMoved(client_session_.get(), mouse_event1), | |
352 InjectMouseEvent(connection_, mouse_event3), | |
353 // TODO(jamiewalch): Verify that remote inputs are re-enabled | |
354 // eventually (via dependency injection, not sleep!) | |
355 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | |
356 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | |
357 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(100, 101))); | 284 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(100, 101))); |
358 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))); | 285 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))); |
359 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 286 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
360 | 287 |
361 ConnectClientSession(); | 288 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
362 message_loop_.Run(); | 289 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 290 // This event should get through to the input stub. |
| 291 connection_->input_stub()->InjectMouseEvent(mouse_event1); |
| 292 // This one should too because the local event echoes the remote one. |
| 293 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), |
| 294 mouse_event1.y())); |
| 295 connection_->input_stub()->InjectMouseEvent(mouse_event2); |
| 296 // This one should not. |
| 297 client_session_->LocalMouseMoved(SkIPoint::Make(mouse_event1.x(), |
| 298 mouse_event1.y())); |
| 299 connection_->input_stub()->InjectMouseEvent(mouse_event3); |
| 300 // TODO(jamiewalch): Verify that remote inputs are re-enabled eventually |
| 301 // (via dependency injection, not sleep!) |
| 302 DisconnectClientSession(); |
363 } | 303 } |
364 | 304 |
365 TEST_F(ClientSessionTest, RestoreEventState) { | 305 TEST_F(ClientSessionTest, RestoreEventState) { |
366 protocol::KeyEvent key1; | 306 protocol::KeyEvent key1; |
367 key1.set_pressed(true); | 307 key1.set_pressed(true); |
368 key1.set_usb_keycode(1); | 308 key1.set_usb_keycode(1); |
369 | 309 |
370 protocol::KeyEvent key2; | 310 protocol::KeyEvent key2; |
371 key2.set_pressed(true); | 311 key2.set_pressed(true); |
372 key2.set_usb_keycode(2); | 312 key2.set_usb_keycode(2); |
373 | 313 |
374 protocol::MouseEvent mousedown; | 314 protocol::MouseEvent mousedown; |
375 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); | 315 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); |
376 mousedown.set_button_down(true); | 316 mousedown.set_button_down(true); |
377 | 317 |
378 InSequence s; | 318 InSequence s; |
379 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 319 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
380 EXPECT_CALL(*event_executor_, StartPtr(_)); | 320 EXPECT_CALL(*event_executor_, StartPtr(_)); |
381 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 321 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
382 | |
383 // Wait for the first video packet to be captured to make sure that | |
384 // the injected input will go though. Otherwise mouse events will be blocked | |
385 // by the mouse clamping filter. | |
386 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | |
387 .WillOnce(DoAll( | |
388 InjectKeyEvent(connection_, key1), | |
389 InjectKeyEvent(connection_, key2), | |
390 InjectMouseEvent(connection_, mousedown), | |
391 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | |
392 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | |
393 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, true))); | 322 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, true))); |
394 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))); | 323 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))); |
395 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( | 324 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( |
396 protocol::MouseEvent::BUTTON_LEFT, true))); | 325 protocol::MouseEvent::BUTTON_LEFT, true))); |
397 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, false))); | 326 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, false))); |
398 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))); | 327 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))); |
399 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( | 328 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( |
400 protocol::MouseEvent::BUTTON_LEFT, false))); | 329 protocol::MouseEvent::BUTTON_LEFT, false))); |
401 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 330 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
402 | 331 |
403 ConnectClientSession(); | 332 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
404 message_loop_.Run(); | 333 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 334 |
| 335 connection_->input_stub()->InjectKeyEvent(key1); |
| 336 connection_->input_stub()->InjectKeyEvent(key2); |
| 337 connection_->input_stub()->InjectMouseEvent(mousedown); |
| 338 |
| 339 DisconnectClientSession(); |
405 } | 340 } |
406 | 341 |
407 TEST_F(ClientSessionTest, ClampMouseEvents) { | 342 TEST_F(ClientSessionTest, ClampMouseEvents) { |
| 343 screen_size_.set(200, 100); |
| 344 |
408 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 345 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
409 EXPECT_CALL(*event_executor_, StartPtr(_)); | 346 EXPECT_CALL(*event_executor_, StartPtr(_)); |
410 Expectation connected = | 347 Expectation connected = |
411 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 348 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
412 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 349 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
413 | 350 |
| 351 client_session_->OnConnectionAuthenticated(client_session_->connection()); |
| 352 client_session_->OnConnectionChannelsConnected(client_session_->connection()); |
| 353 |
414 int input_x[3] = { -999, 100, 999 }; | 354 int input_x[3] = { -999, 100, 999 }; |
415 int expected_x[3] = { 0, 100, VideoFrameCapturerFake::kWidth - 1 }; | 355 int expected_x[3] = { 0, 100, 199 }; |
416 int input_y[3] = { -999, 50, 999 }; | 356 int input_y[3] = { -999, 50, 999 }; |
417 int expected_y[3] = { 0, 50, VideoFrameCapturerFake::kHeight - 1 }; | 357 int expected_y[3] = { 0, 50, 99 }; |
418 | 358 |
419 // Inject the 1st event once a video packet has been received. | 359 protocol::MouseEvent event; |
420 protocol::MouseEvent injected_event; | |
421 injected_event.set_x(input_x[0]); | |
422 injected_event.set_y(input_y[0]); | |
423 connected = | |
424 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | |
425 .After(connected) | |
426 .WillOnce(InjectMouseEvent(connection_, injected_event)); | |
427 | |
428 protocol::MouseEvent expected_event; | |
429 for (int j = 0; j < 3; j++) { | 360 for (int j = 0; j < 3; j++) { |
430 for (int i = 0; i < 3; i++) { | 361 for (int i = 0; i < 3; i++) { |
431 // Skip the first iteration since the 1st event has been injected already. | 362 event.set_x(input_x[i]); |
432 if (i > 0 || j > 0) { | 363 event.set_y(input_y[j]); |
433 injected_event.set_x(input_x[i]); | 364 connected = |
434 injected_event.set_y(input_y[j]); | 365 EXPECT_CALL(*event_executor_, |
435 connected = | 366 InjectMouseEvent(EqualsMouseEvent(expected_x[i], |
436 EXPECT_CALL(*event_executor_, | 367 expected_y[j]))) |
437 InjectMouseEvent(EqualsMouseEvent(expected_event.x(), | 368 .After(connected); |
438 expected_event.y()))) | 369 connection_->input_stub()->InjectMouseEvent(event); |
439 .After(connected) | |
440 .WillOnce(InjectMouseEvent(connection_, injected_event)); | |
441 } | |
442 | |
443 expected_event.set_x(expected_x[i]); | |
444 expected_event.set_y(expected_y[j]); | |
445 } | 370 } |
446 } | 371 } |
447 | 372 |
448 // Shutdown the connection once the last event has been received. | 373 DisconnectClientSession(); |
449 EXPECT_CALL(*event_executor_, | |
450 InjectMouseEvent(EqualsMouseEvent(expected_event.x(), | |
451 expected_event.y()))) | |
452 .After(connected) | |
453 .WillOnce(DoAll( | |
454 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | |
455 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | |
456 | |
457 ConnectClientSession(); | |
458 message_loop_.Run(); | |
459 } | 374 } |
460 | 375 |
461 } // namespace remoting | 376 } // namespace remoting |
OLD | NEW |