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 "media/video/capture/screen/screen_capturer_fake.h" | 6 #include "media/video/capture/screen/screen_capturer_fake.h" |
7 #include "media/video/capture/screen/screen_capturer_mock_objects.h" | 7 #include "media/video/capture/screen/screen_capturer_mock_objects.h" |
8 #include "remoting/base/auto_thread_task_runner.h" | 8 #include "remoting/base/auto_thread_task_runner.h" |
9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
10 #include "remoting/host/audio_capturer.h" | 10 #include "remoting/host/audio_capturer.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 void DisconnectClientSession(); | 64 void DisconnectClientSession(); |
65 | 65 |
66 // Stops and releases the ClientSession, allowing the MessageLoop to quit. | 66 // Stops and releases the ClientSession, allowing the MessageLoop to quit. |
67 void StopClientSession(); | 67 void StopClientSession(); |
68 | 68 |
69 protected: | 69 protected: |
70 // Creates a DesktopEnvironment with a fake media::ScreenCapturer, to mock | 70 // Creates a DesktopEnvironment with a fake media::ScreenCapturer, to mock |
71 // DesktopEnvironmentFactory::Create(). | 71 // DesktopEnvironmentFactory::Create(). |
72 DesktopEnvironment* CreateDesktopEnvironment(); | 72 DesktopEnvironment* CreateDesktopEnvironment(); |
73 | 73 |
74 // Returns |event_executor_| created and initialized by SetUp(), to mock | 74 // Returns |input_injector_| created and initialized by SetUp(), to mock |
75 // DesktopEnvironment::CreateEventExecutor(). | 75 // DesktopEnvironment::CreateInputInjector(). |
76 EventExecutor* CreateEventExecutor( | 76 InputInjector* CreateInputInjector( |
77 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 77 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
78 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); | 78 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); |
79 | 79 |
80 // Creates a dummy SessionController, to mock | 80 // Creates a dummy SessionController, to mock |
81 // DesktopEnvironment::CreateSessionController(). | 81 // DesktopEnvironment::CreateSessionController(). |
82 SessionController* CreateSessionController(); | 82 SessionController* CreateSessionController(); |
83 | 83 |
84 // Creates a fake media::ScreenCapturer, to mock | 84 // Creates a fake media::ScreenCapturer, to mock |
85 // DesktopEnvironment::CreateVideoCapturer(). | 85 // DesktopEnvironment::CreateVideoCapturer(). |
86 media::ScreenCapturer* CreateVideoCapturer( | 86 media::ScreenCapturer* CreateVideoCapturer( |
(...skipping 19 matching lines...) Expand all Loading... |
106 MockClientSessionEventHandler session_event_handler_; | 106 MockClientSessionEventHandler session_event_handler_; |
107 | 107 |
108 // Storage for values to be returned by the protocol::Session mock. | 108 // Storage for values to be returned by the protocol::Session mock. |
109 SessionConfig session_config_; | 109 SessionConfig session_config_; |
110 const std::string client_jid_; | 110 const std::string client_jid_; |
111 | 111 |
112 // Stubs returned to |client_session_| components by |connection_|. | 112 // Stubs returned to |client_session_| components by |connection_|. |
113 MockClientStub client_stub_; | 113 MockClientStub client_stub_; |
114 MockVideoStub video_stub_; | 114 MockVideoStub video_stub_; |
115 | 115 |
116 // DesktopEnvironment owns |event_executor_|, but input injection tests need | 116 // DesktopEnvironment owns |input_injector_|, but input injection tests need |
117 // to express expectations on it. | 117 // to express expectations on it. |
118 scoped_ptr<MockEventExecutor> event_executor_; | 118 scoped_ptr<MockInputInjector> input_injector_; |
119 | 119 |
120 // ClientSession owns |connection_| but tests need it to inject fake events. | 120 // ClientSession owns |connection_| but tests need it to inject fake events. |
121 MockConnectionToClient* connection_; | 121 MockConnectionToClient* connection_; |
122 | 122 |
123 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; | 123 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; |
124 }; | 124 }; |
125 | 125 |
126 void ClientSessionTest::SetUp() { | 126 void ClientSessionTest::SetUp() { |
127 // Arrange to run |message_loop_| until no components depend on it. | 127 // Arrange to run |message_loop_| until no components depend on it. |
128 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = new AutoThreadTaskRunner( | 128 scoped_refptr<AutoThreadTaskRunner> ui_task_runner = new AutoThreadTaskRunner( |
129 message_loop_.message_loop_proxy(), | 129 message_loop_.message_loop_proxy(), |
130 base::Bind(&ClientSessionTest::QuitMainMessageLoop, | 130 base::Bind(&ClientSessionTest::QuitMainMessageLoop, |
131 base::Unretained(this))); | 131 base::Unretained(this))); |
132 | 132 |
133 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); | 133 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); |
134 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) | 134 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) |
135 .Times(AnyNumber()) | 135 .Times(AnyNumber()) |
136 .WillRepeatedly(Invoke(this, | 136 .WillRepeatedly(Invoke(this, |
137 &ClientSessionTest::CreateDesktopEnvironment)); | 137 &ClientSessionTest::CreateDesktopEnvironment)); |
138 EXPECT_CALL(*desktop_environment_factory_, SupportsAudioCapture()) | 138 EXPECT_CALL(*desktop_environment_factory_, SupportsAudioCapture()) |
139 .Times(AnyNumber()) | 139 .Times(AnyNumber()) |
140 .WillRepeatedly(Return(false)); | 140 .WillRepeatedly(Return(false)); |
141 | 141 |
142 event_executor_.reset(new MockEventExecutor()); | 142 input_injector_.reset(new MockInputInjector()); |
143 | 143 |
144 session_config_ = SessionConfig::ForTest(); | 144 session_config_ = SessionConfig::ForTest(); |
145 | 145 |
146 // Mock protocol::Session APIs called directly by ClientSession. | 146 // Mock protocol::Session APIs called directly by ClientSession. |
147 protocol::MockSession* session = new MockSession(); | 147 protocol::MockSession* session = new MockSession(); |
148 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(session_config_)); | 148 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(session_config_)); |
149 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); | 149 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); |
150 EXPECT_CALL(*session, SetEventHandler(_)); | 150 EXPECT_CALL(*session, SetEventHandler(_)); |
151 | 151 |
152 // Mock protocol::ConnectionToClient APIs called directly by ClientSession. | 152 // Mock protocol::ConnectionToClient APIs called directly by ClientSession. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 void ClientSessionTest::StopClientSession() { | 188 void ClientSessionTest::StopClientSession() { |
189 client_session_.reset(); | 189 client_session_.reset(); |
190 | 190 |
191 desktop_environment_factory_.reset(); | 191 desktop_environment_factory_.reset(); |
192 } | 192 } |
193 | 193 |
194 DesktopEnvironment* ClientSessionTest::CreateDesktopEnvironment() { | 194 DesktopEnvironment* ClientSessionTest::CreateDesktopEnvironment() { |
195 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment(); | 195 MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment(); |
196 EXPECT_CALL(*desktop_environment, CreateAudioCapturerPtr(_)) | 196 EXPECT_CALL(*desktop_environment, CreateAudioCapturerPtr(_)) |
197 .Times(0); | 197 .Times(0); |
198 EXPECT_CALL(*desktop_environment, CreateEventExecutorPtr(_, _)) | 198 EXPECT_CALL(*desktop_environment, CreateInputInjectorPtr(_, _)) |
199 .WillOnce(Invoke(this, &ClientSessionTest::CreateEventExecutor)); | 199 .WillOnce(Invoke(this, &ClientSessionTest::CreateInputInjector)); |
200 EXPECT_CALL(*desktop_environment, CreateSessionControllerPtr()) | 200 EXPECT_CALL(*desktop_environment, CreateSessionControllerPtr()) |
201 .WillOnce(Invoke(this, &ClientSessionTest::CreateSessionController)); | 201 .WillOnce(Invoke(this, &ClientSessionTest::CreateSessionController)); |
202 EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr(_, _)) | 202 EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr(_, _)) |
203 .WillOnce(Invoke(this, &ClientSessionTest::CreateVideoCapturer)); | 203 .WillOnce(Invoke(this, &ClientSessionTest::CreateVideoCapturer)); |
204 | 204 |
205 return desktop_environment; | 205 return desktop_environment; |
206 } | 206 } |
207 | 207 |
208 EventExecutor* ClientSessionTest::CreateEventExecutor( | 208 InputInjector* ClientSessionTest::CreateInputInjector( |
209 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 209 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
210 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 210 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
211 EXPECT_TRUE(event_executor_); | 211 EXPECT_TRUE(input_injector_); |
212 return event_executor_.release(); | 212 return input_injector_.release(); |
213 } | 213 } |
214 | 214 |
215 SessionController* ClientSessionTest::CreateSessionController() { | 215 SessionController* ClientSessionTest::CreateSessionController() { |
216 return new MockSessionController(); | 216 return new MockSessionController(); |
217 } | 217 } |
218 | 218 |
219 media::ScreenCapturer* ClientSessionTest::CreateVideoCapturer( | 219 media::ScreenCapturer* ClientSessionTest::CreateVideoCapturer( |
220 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, | 220 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, |
221 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) { | 221 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) { |
222 return new media::ScreenCapturerFake(); | 222 return new media::ScreenCapturerFake(); |
(...skipping 21 matching lines...) Expand all Loading... |
244 protocol::ClipboardEvent clipboard_event2; | 244 protocol::ClipboardEvent clipboard_event2; |
245 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); | 245 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); |
246 clipboard_event2.set_data("b"); | 246 clipboard_event2.set_data("b"); |
247 | 247 |
248 protocol::ClipboardEvent clipboard_event3; | 248 protocol::ClipboardEvent clipboard_event3; |
249 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); | 249 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); |
250 clipboard_event3.set_data("c"); | 250 clipboard_event3.set_data("c"); |
251 | 251 |
252 Expectation authenticated = | 252 Expectation authenticated = |
253 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 253 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
254 EXPECT_CALL(*event_executor_, StartPtr(_)) | 254 EXPECT_CALL(*input_injector_, StartPtr(_)) |
255 .After(authenticated); | 255 .After(authenticated); |
256 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 256 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
257 .After(authenticated); | 257 .After(authenticated); |
258 | 258 |
259 // Wait for the first video packet to be captured to make sure that | 259 // Wait for the first video packet to be captured to make sure that |
260 // the injected input will go though. Otherwise mouse events will be blocked | 260 // the injected input will go though. Otherwise mouse events will be blocked |
261 // by the mouse clamping filter. | 261 // by the mouse clamping filter. |
262 Sequence s; | 262 Sequence s; |
263 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 263 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
264 .InSequence(s) | 264 .InSequence(s) |
265 .After(authenticated) | 265 .After(authenticated) |
266 .WillOnce(DoAll( | 266 .WillOnce(DoAll( |
267 // This event should get through to the clipboard stub. | 267 // This event should get through to the clipboard stub. |
268 InjectClipboardEvent(connection_, clipboard_event2), | 268 InjectClipboardEvent(connection_, clipboard_event2), |
269 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 269 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
270 // This event should not get through to the clipboard stub, | 270 // This event should not get through to the clipboard stub, |
271 // because the client has disconnected. | 271 // because the client has disconnected. |
272 InjectClipboardEvent(connection_, clipboard_event3), | 272 InjectClipboardEvent(connection_, clipboard_event3), |
273 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 273 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
274 EXPECT_CALL(*event_executor_, InjectClipboardEvent(EqualsClipboardEvent( | 274 EXPECT_CALL(*input_injector_, InjectClipboardEvent(EqualsClipboardEvent( |
275 kMimeTypeTextUtf8, "b"))) | 275 kMimeTypeTextUtf8, "b"))) |
276 .InSequence(s); | 276 .InSequence(s); |
277 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) | 277 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) |
278 .InSequence(s); | 278 .InSequence(s); |
279 | 279 |
280 // This event should not get through to the clipboard stub, | 280 // This event should not get through to the clipboard stub, |
281 // because the client isn't authenticated yet. | 281 // because the client isn't authenticated yet. |
282 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1); | 282 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1); |
283 | 283 |
284 ConnectClientSession(); | 284 ConnectClientSession(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 protocol::MouseEvent mouse_event2; | 322 protocol::MouseEvent mouse_event2; |
323 mouse_event2.set_x(200); | 323 mouse_event2.set_x(200); |
324 mouse_event2.set_y(201); | 324 mouse_event2.set_y(201); |
325 | 325 |
326 protocol::MouseEvent mouse_event3; | 326 protocol::MouseEvent mouse_event3; |
327 mouse_event3.set_x(300); | 327 mouse_event3.set_x(300); |
328 mouse_event3.set_y(301); | 328 mouse_event3.set_y(301); |
329 | 329 |
330 Expectation authenticated = | 330 Expectation authenticated = |
331 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 331 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
332 EXPECT_CALL(*event_executor_, StartPtr(_)) | 332 EXPECT_CALL(*input_injector_, StartPtr(_)) |
333 .After(authenticated); | 333 .After(authenticated); |
334 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 334 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
335 .After(authenticated); | 335 .After(authenticated); |
336 | 336 |
337 // Wait for the first video packet to be captured to make sure that | 337 // Wait for the first video packet to be captured to make sure that |
338 // the injected input will go though. Otherwise mouse events will be blocked | 338 // the injected input will go though. Otherwise mouse events will be blocked |
339 // by the mouse clamping filter. | 339 // by the mouse clamping filter. |
340 Sequence s; | 340 Sequence s; |
341 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 341 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
342 .InSequence(s) | 342 .InSequence(s) |
343 .After(authenticated) | 343 .After(authenticated) |
344 .WillOnce(DoAll( | 344 .WillOnce(DoAll( |
345 // These events should get through to the input stub. | 345 // These events should get through to the input stub. |
346 InjectKeyEvent(connection_, key_event2_down), | 346 InjectKeyEvent(connection_, key_event2_down), |
347 InjectKeyEvent(connection_, key_event2_up), | 347 InjectKeyEvent(connection_, key_event2_up), |
348 InjectMouseEvent(connection_, mouse_event2), | 348 InjectMouseEvent(connection_, mouse_event2), |
349 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 349 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
350 // These events should not get through to the input stub, | 350 // These events should not get through to the input stub, |
351 // because the client has disconnected. | 351 // because the client has disconnected. |
352 InjectKeyEvent(connection_, key_event3), | 352 InjectKeyEvent(connection_, key_event3), |
353 InjectMouseEvent(connection_, mouse_event3), | 353 InjectMouseEvent(connection_, mouse_event3), |
354 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 354 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
355 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))) | 355 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(2, true))) |
356 .InSequence(s); | 356 .InSequence(s); |
357 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))) | 357 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(2, false))) |
358 .InSequence(s); | 358 .InSequence(s); |
359 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))) | 359 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseEvent(200, 201))) |
360 .InSequence(s); | 360 .InSequence(s); |
361 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) | 361 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) |
362 .InSequence(s); | 362 .InSequence(s); |
363 | 363 |
364 // These events should not get through to the input stub, | 364 // These events should not get through to the input stub, |
365 // because the client isn't authenticated yet. | 365 // because the client isn't authenticated yet. |
366 connection_->input_stub()->InjectKeyEvent(key_event1); | 366 connection_->input_stub()->InjectKeyEvent(key_event1); |
367 connection_->input_stub()->InjectMouseEvent(mouse_event1); | 367 connection_->input_stub()->InjectMouseEvent(mouse_event1); |
368 | 368 |
369 ConnectClientSession(); | 369 ConnectClientSession(); |
370 message_loop_.Run(); | 370 message_loop_.Run(); |
371 } | 371 } |
372 | 372 |
373 TEST_F(ClientSessionTest, LocalInputTest) { | 373 TEST_F(ClientSessionTest, LocalInputTest) { |
374 protocol::MouseEvent mouse_event1; | 374 protocol::MouseEvent mouse_event1; |
375 mouse_event1.set_x(100); | 375 mouse_event1.set_x(100); |
376 mouse_event1.set_y(101); | 376 mouse_event1.set_y(101); |
377 protocol::MouseEvent mouse_event2; | 377 protocol::MouseEvent mouse_event2; |
378 mouse_event2.set_x(200); | 378 mouse_event2.set_x(200); |
379 mouse_event2.set_y(201); | 379 mouse_event2.set_y(201); |
380 protocol::MouseEvent mouse_event3; | 380 protocol::MouseEvent mouse_event3; |
381 mouse_event3.set_x(300); | 381 mouse_event3.set_x(300); |
382 mouse_event3.set_y(301); | 382 mouse_event3.set_y(301); |
383 | 383 |
384 Expectation authenticated = | 384 Expectation authenticated = |
385 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 385 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
386 EXPECT_CALL(*event_executor_, StartPtr(_)) | 386 EXPECT_CALL(*input_injector_, StartPtr(_)) |
387 .After(authenticated); | 387 .After(authenticated); |
388 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 388 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
389 .After(authenticated); | 389 .After(authenticated); |
390 | 390 |
391 // Wait for the first video packet to be captured to make sure that | 391 // Wait for the first video packet to be captured to make sure that |
392 // the injected input will go though. Otherwise mouse events will be blocked | 392 // the injected input will go though. Otherwise mouse events will be blocked |
393 // by the mouse clamping filter. | 393 // by the mouse clamping filter. |
394 Sequence s; | 394 Sequence s; |
395 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 395 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
396 .InSequence(s) | 396 .InSequence(s) |
397 .After(authenticated) | 397 .After(authenticated) |
398 .WillOnce(DoAll( | 398 .WillOnce(DoAll( |
399 // This event should get through to the input stub. | 399 // This event should get through to the input stub. |
400 InjectMouseEvent(connection_, mouse_event1), | 400 InjectMouseEvent(connection_, mouse_event1), |
401 #if !defined(OS_WIN) | 401 #if !defined(OS_WIN) |
402 // The OS echoes the injected event back. | 402 // The OS echoes the injected event back. |
403 LocalMouseMoved(client_session_.get(), mouse_event1), | 403 LocalMouseMoved(client_session_.get(), mouse_event1), |
404 #endif // !defined(OS_WIN) | 404 #endif // !defined(OS_WIN) |
405 // This one should get throught as well. | 405 // This one should get throught as well. |
406 InjectMouseEvent(connection_, mouse_event2), | 406 InjectMouseEvent(connection_, mouse_event2), |
407 // Now this is a genuine local event. | 407 // Now this is a genuine local event. |
408 LocalMouseMoved(client_session_.get(), mouse_event1), | 408 LocalMouseMoved(client_session_.get(), mouse_event1), |
409 // This one should be blocked because of the previous local input | 409 // This one should be blocked because of the previous local input |
410 // event. | 410 // event. |
411 InjectMouseEvent(connection_, mouse_event3), | 411 InjectMouseEvent(connection_, mouse_event3), |
412 // TODO(jamiewalch): Verify that remote inputs are re-enabled | 412 // TODO(jamiewalch): Verify that remote inputs are re-enabled |
413 // eventually (via dependency injection, not sleep!) | 413 // eventually (via dependency injection, not sleep!) |
414 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 414 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
415 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 415 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
416 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(100, 101))) | 416 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseEvent(100, 101))) |
417 .InSequence(s); | 417 .InSequence(s); |
418 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))) | 418 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseEvent(200, 201))) |
419 .InSequence(s); | 419 .InSequence(s); |
420 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) | 420 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) |
421 .InSequence(s); | 421 .InSequence(s); |
422 | 422 |
423 ConnectClientSession(); | 423 ConnectClientSession(); |
424 message_loop_.Run(); | 424 message_loop_.Run(); |
425 } | 425 } |
426 | 426 |
427 TEST_F(ClientSessionTest, RestoreEventState) { | 427 TEST_F(ClientSessionTest, RestoreEventState) { |
428 protocol::KeyEvent key1; | 428 protocol::KeyEvent key1; |
429 key1.set_pressed(true); | 429 key1.set_pressed(true); |
430 key1.set_usb_keycode(1); | 430 key1.set_usb_keycode(1); |
431 | 431 |
432 protocol::KeyEvent key2; | 432 protocol::KeyEvent key2; |
433 key2.set_pressed(true); | 433 key2.set_pressed(true); |
434 key2.set_usb_keycode(2); | 434 key2.set_usb_keycode(2); |
435 | 435 |
436 protocol::MouseEvent mousedown; | 436 protocol::MouseEvent mousedown; |
437 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); | 437 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); |
438 mousedown.set_button_down(true); | 438 mousedown.set_button_down(true); |
439 | 439 |
440 Expectation authenticated = | 440 Expectation authenticated = |
441 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 441 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
442 EXPECT_CALL(*event_executor_, StartPtr(_)) | 442 EXPECT_CALL(*input_injector_, StartPtr(_)) |
443 .After(authenticated); | 443 .After(authenticated); |
444 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 444 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
445 .After(authenticated); | 445 .After(authenticated); |
446 | 446 |
447 // Wait for the first video packet to be captured to make sure that | 447 // Wait for the first video packet to be captured to make sure that |
448 // the injected input will go though. Otherwise mouse events will be blocked | 448 // the injected input will go though. Otherwise mouse events will be blocked |
449 // by the mouse clamping filter. | 449 // by the mouse clamping filter. |
450 Sequence s; | 450 Sequence s; |
451 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 451 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
452 .InSequence(s) | 452 .InSequence(s) |
453 .After(authenticated) | 453 .After(authenticated) |
454 .WillOnce(DoAll( | 454 .WillOnce(DoAll( |
455 InjectKeyEvent(connection_, key1), | 455 InjectKeyEvent(connection_, key1), |
456 InjectKeyEvent(connection_, key2), | 456 InjectKeyEvent(connection_, key2), |
457 InjectMouseEvent(connection_, mousedown), | 457 InjectMouseEvent(connection_, mousedown), |
458 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 458 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
459 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 459 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
460 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, true))) | 460 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(1, true))) |
461 .InSequence(s); | 461 .InSequence(s); |
462 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))) | 462 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(2, true))) |
463 .InSequence(s); | 463 .InSequence(s); |
464 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( | 464 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseButtonEvent( |
465 protocol::MouseEvent::BUTTON_LEFT, true))) | 465 protocol::MouseEvent::BUTTON_LEFT, true))) |
466 .InSequence(s); | 466 .InSequence(s); |
467 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, false))) | 467 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(1, false))) |
468 .InSequence(s); | 468 .InSequence(s); |
469 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))) | 469 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(2, false))) |
470 .InSequence(s); | 470 .InSequence(s); |
471 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( | 471 EXPECT_CALL(*input_injector_, InjectMouseEvent(EqualsMouseButtonEvent( |
472 protocol::MouseEvent::BUTTON_LEFT, false))) | 472 protocol::MouseEvent::BUTTON_LEFT, false))) |
473 .InSequence(s); | 473 .InSequence(s); |
474 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) | 474 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) |
475 .InSequence(s); | 475 .InSequence(s); |
476 | 476 |
477 ConnectClientSession(); | 477 ConnectClientSession(); |
478 message_loop_.Run(); | 478 message_loop_.Run(); |
479 } | 479 } |
480 | 480 |
481 TEST_F(ClientSessionTest, ClampMouseEvents) { | 481 TEST_F(ClientSessionTest, ClampMouseEvents) { |
482 Expectation authenticated = | 482 Expectation authenticated = |
483 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 483 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
484 EXPECT_CALL(*event_executor_, StartPtr(_)) | 484 EXPECT_CALL(*input_injector_, StartPtr(_)) |
485 .After(authenticated); | 485 .After(authenticated); |
486 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 486 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
487 .After(authenticated); | 487 .After(authenticated); |
488 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) | 488 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)) |
489 .After(authenticated); | 489 .After(authenticated); |
490 | 490 |
491 Expectation connected = authenticated; | 491 Expectation connected = authenticated; |
492 | 492 |
493 int input_x[3] = { -999, 100, 999 }; | 493 int input_x[3] = { -999, 100, 999 }; |
494 int expected_x[3] = { 0, 100, media::ScreenCapturerFake::kWidth - 1 }; | 494 int expected_x[3] = { 0, 100, media::ScreenCapturerFake::kWidth - 1 }; |
(...skipping 10 matching lines...) Expand all Loading... |
505 if (i == 0 && j == 0) { | 505 if (i == 0 && j == 0) { |
506 // Inject the 1st event once a video packet has been received. | 506 // Inject the 1st event once a video packet has been received. |
507 connected = | 507 connected = |
508 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 508 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
509 .After(connected) | 509 .After(connected) |
510 .WillOnce(InjectMouseEvent(connection_, injected_event)); | 510 .WillOnce(InjectMouseEvent(connection_, injected_event)); |
511 } else { | 511 } else { |
512 // Every next event is injected once the previous event has been | 512 // Every next event is injected once the previous event has been |
513 // received. | 513 // received. |
514 connected = | 514 connected = |
515 EXPECT_CALL(*event_executor_, | 515 EXPECT_CALL(*input_injector_, |
516 InjectMouseEvent(EqualsMouseEvent(expected_event.x(), | 516 InjectMouseEvent(EqualsMouseEvent(expected_event.x(), |
517 expected_event.y()))) | 517 expected_event.y()))) |
518 .After(connected) | 518 .After(connected) |
519 .WillOnce(InjectMouseEvent(connection_, injected_event)); | 519 .WillOnce(InjectMouseEvent(connection_, injected_event)); |
520 } | 520 } |
521 | 521 |
522 expected_event.set_x(expected_x[i]); | 522 expected_event.set_x(expected_x[i]); |
523 expected_event.set_y(expected_y[j]); | 523 expected_event.set_y(expected_y[j]); |
524 } | 524 } |
525 } | 525 } |
526 | 526 |
527 // Shutdown the connection once the last event has been received. | 527 // Shutdown the connection once the last event has been received. |
528 EXPECT_CALL(*event_executor_, | 528 EXPECT_CALL(*input_injector_, |
529 InjectMouseEvent(EqualsMouseEvent(expected_event.x(), | 529 InjectMouseEvent(EqualsMouseEvent(expected_event.x(), |
530 expected_event.y()))) | 530 expected_event.y()))) |
531 .After(connected) | 531 .After(connected) |
532 .WillOnce(DoAll( | 532 .WillOnce(DoAll( |
533 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 533 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
534 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 534 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
535 | 535 |
536 ConnectClientSession(); | 536 ConnectClientSession(); |
537 message_loop_.Run(); | 537 message_loop_.Run(); |
538 } | 538 } |
539 | 539 |
540 } // namespace remoting | 540 } // namespace remoting |
OLD | NEW |