| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" | 29 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
| 30 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object
s.h" | 30 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object
s.h" |
| 31 | 31 |
| 32 namespace remoting { | 32 namespace remoting { |
| 33 | 33 |
| 34 using protocol::MockConnectionToClient; | 34 using protocol::MockConnectionToClient; |
| 35 using protocol::MockClientStub; | 35 using protocol::MockClientStub; |
| 36 using protocol::MockHostStub; | 36 using protocol::MockHostStub; |
| 37 using protocol::MockInputStub; | 37 using protocol::MockInputStub; |
| 38 using protocol::MockSession; | 38 using protocol::MockSession; |
| 39 using protocol::MockVideoStub; | 39 using protocol::MockVideoSender; |
| 40 using protocol::SessionConfig; | 40 using protocol::SessionConfig; |
| 41 | 41 |
| 42 using testing::_; | 42 using testing::_; |
| 43 using testing::AnyNumber; | 43 using testing::AnyNumber; |
| 44 using testing::AtMost; | 44 using testing::AtMost; |
| 45 using testing::CreateFunctor; | 45 using testing::CreateFunctor; |
| 46 using testing::DeleteArg; | 46 using testing::DeleteArg; |
| 47 using testing::DoAll; | 47 using testing::DoAll; |
| 48 using testing::Expectation; | 48 using testing::Expectation; |
| 49 using testing::Invoke; | 49 using testing::Invoke; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 // ClientSession::EventHandler mock for use in tests. | 184 // ClientSession::EventHandler mock for use in tests. |
| 185 MockClientSessionEventHandler session_event_handler_; | 185 MockClientSessionEventHandler session_event_handler_; |
| 186 | 186 |
| 187 // Storage for values to be returned by the protocol::Session mock. | 187 // Storage for values to be returned by the protocol::Session mock. |
| 188 SessionConfig session_config_; | 188 SessionConfig session_config_; |
| 189 const std::string client_jid_; | 189 const std::string client_jid_; |
| 190 | 190 |
| 191 // Stubs returned to |client_session_| components by |connection_|. | 191 // Stubs returned to |client_session_| components by |connection_|. |
| 192 MockClientStub client_stub_; | 192 MockClientStub client_stub_; |
| 193 MockVideoStub video_stub_; | 193 MockVideoSender video_sender_; |
| 194 | 194 |
| 195 // DesktopEnvironment owns |input_injector_|, but input injection tests need | 195 // DesktopEnvironment owns |input_injector_|, but input injection tests need |
| 196 // to express expectations on it. | 196 // to express expectations on it. |
| 197 scoped_ptr<MockInputInjector> input_injector_; | 197 scoped_ptr<MockInputInjector> input_injector_; |
| 198 | 198 |
| 199 // ClientSession owns |connection_| but tests need it to inject fake events. | 199 // ClientSession owns |connection_| but tests need it to inject fake events. |
| 200 MockConnectionToClient* connection_; | 200 MockConnectionToClient* connection_; |
| 201 | 201 |
| 202 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; | 202 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; |
| 203 }; | 203 }; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); | 235 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); |
| 236 EXPECT_CALL(*session, SetEventHandler(_)); | 236 EXPECT_CALL(*session, SetEventHandler(_)); |
| 237 | 237 |
| 238 // Mock protocol::ConnectionToClient APIs called directly by ClientSession. | 238 // Mock protocol::ConnectionToClient APIs called directly by ClientSession. |
| 239 // HostStub is not touched by ClientSession, so we can safely pass nullptr. | 239 // HostStub is not touched by ClientSession, so we can safely pass nullptr. |
| 240 scoped_ptr<MockConnectionToClient> connection( | 240 scoped_ptr<MockConnectionToClient> connection( |
| 241 new MockConnectionToClient(session, nullptr)); | 241 new MockConnectionToClient(session, nullptr)); |
| 242 EXPECT_CALL(*connection, session()).WillRepeatedly(Return(session)); | 242 EXPECT_CALL(*connection, session()).WillRepeatedly(Return(session)); |
| 243 EXPECT_CALL(*connection, client_stub()) | 243 EXPECT_CALL(*connection, client_stub()) |
| 244 .WillRepeatedly(Return(&client_stub_)); | 244 .WillRepeatedly(Return(&client_stub_)); |
| 245 EXPECT_CALL(*connection, video_stub()).WillRepeatedly(Return(&video_stub_)); | 245 EXPECT_CALL(*connection, video_sender()) |
| 246 .WillRepeatedly(Return(&video_sender_)); |
| 246 EXPECT_CALL(*connection, Disconnect()); | 247 EXPECT_CALL(*connection, Disconnect()); |
| 247 connection_ = connection.get(); | 248 connection_ = connection.get(); |
| 248 | 249 |
| 249 client_session_.reset(new ClientSession( | 250 client_session_.reset(new ClientSession( |
| 250 &session_event_handler_, | 251 &session_event_handler_, |
| 251 task_runner_, // Audio thread. | 252 task_runner_, // Audio thread. |
| 252 task_runner_, // Input thread. | 253 task_runner_, // Input thread. |
| 253 task_runner_, // Capture thread. | 254 task_runner_, // Capture thread. |
| 254 task_runner_, // Encode thread. | 255 task_runner_, // Encode thread. |
| 255 task_runner_, // Network thread. | 256 task_runner_, // Network thread. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 .WillOnce(Return(true)); | 364 .WillOnce(Return(true)); |
| 364 EXPECT_CALL(*input_injector_, StartPtr(_)) | 365 EXPECT_CALL(*input_injector_, StartPtr(_)) |
| 365 .After(authenticated); | 366 .After(authenticated); |
| 366 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 367 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
| 367 .After(authenticated); | 368 .After(authenticated); |
| 368 | 369 |
| 369 // Wait for the first video packet to be captured to make sure that | 370 // Wait for the first video packet to be captured to make sure that |
| 370 // the injected input will go though. Otherwise mouse events will be blocked | 371 // the injected input will go though. Otherwise mouse events will be blocked |
| 371 // by the mouse clamping filter. | 372 // by the mouse clamping filter. |
| 372 Sequence s; | 373 Sequence s; |
| 373 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 374 EXPECT_CALL(video_sender_, ProcessVideoPacketPtr(_, _)) |
| 374 .InSequence(s) | 375 .InSequence(s) |
| 375 .After(authenticated) | 376 .After(authenticated) |
| 376 .WillOnce(DoAll( | 377 .WillOnce(DoAll( |
| 377 // This event should get through to the clipboard stub. | 378 // This event should get through to the clipboard stub. |
| 378 InjectClipboardEvent(connection_, clipboard_event2), | 379 InjectClipboardEvent(connection_, clipboard_event2), |
| 379 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 380 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
| 380 // This event should not get through to the clipboard stub, | 381 // This event should not get through to the clipboard stub, |
| 381 // because the client has disconnected. | 382 // because the client has disconnected. |
| 382 InjectClipboardEvent(connection_, clipboard_event3), | 383 InjectClipboardEvent(connection_, clipboard_event3), |
| 383 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 384 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 .WillOnce(Return(true)); | 431 .WillOnce(Return(true)); |
| 431 EXPECT_CALL(*input_injector_, StartPtr(_)) | 432 EXPECT_CALL(*input_injector_, StartPtr(_)) |
| 432 .After(authenticated); | 433 .After(authenticated); |
| 433 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 434 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
| 434 .After(authenticated); | 435 .After(authenticated); |
| 435 | 436 |
| 436 // Wait for the first video packet to be captured to make sure that | 437 // Wait for the first video packet to be captured to make sure that |
| 437 // the injected input will go though. Otherwise mouse events will be blocked | 438 // the injected input will go though. Otherwise mouse events will be blocked |
| 438 // by the mouse clamping filter. | 439 // by the mouse clamping filter. |
| 439 Sequence s; | 440 Sequence s; |
| 440 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 441 EXPECT_CALL(video_sender_, ProcessVideoPacketPtr(_, _)) |
| 441 .InSequence(s) | 442 .InSequence(s) |
| 442 .After(authenticated) | 443 .After(authenticated) |
| 443 .WillOnce(DoAll( | 444 .WillOnce(DoAll( |
| 444 // These events should get through to the input stub. | 445 // These events should get through to the input stub. |
| 445 InjectKeyEvent(connection_, key_event2_down), | 446 InjectKeyEvent(connection_, key_event2_down), |
| 446 InjectKeyEvent(connection_, key_event2_up), | 447 InjectKeyEvent(connection_, key_event2_up), |
| 447 InjectMouseEvent(connection_, mouse_event2), | 448 InjectMouseEvent(connection_, mouse_event2), |
| 448 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 449 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
| 449 // These events should not get through to the input stub, | 450 // These events should not get through to the input stub, |
| 450 // because the client has disconnected. | 451 // because the client has disconnected. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 .WillOnce(Return(true)); | 487 .WillOnce(Return(true)); |
| 487 EXPECT_CALL(*input_injector_, StartPtr(_)) | 488 EXPECT_CALL(*input_injector_, StartPtr(_)) |
| 488 .After(authenticated); | 489 .After(authenticated); |
| 489 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 490 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
| 490 .After(authenticated); | 491 .After(authenticated); |
| 491 | 492 |
| 492 // Wait for the first video packet to be captured to make sure that | 493 // Wait for the first video packet to be captured to make sure that |
| 493 // the injected input will go though. Otherwise mouse events will be blocked | 494 // the injected input will go though. Otherwise mouse events will be blocked |
| 494 // by the mouse clamping filter. | 495 // by the mouse clamping filter. |
| 495 Sequence s; | 496 Sequence s; |
| 496 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 497 EXPECT_CALL(video_sender_, ProcessVideoPacketPtr(_, _)) |
| 497 .InSequence(s) | 498 .InSequence(s) |
| 498 .After(authenticated) | 499 .After(authenticated) |
| 499 .WillOnce(DoAll( | 500 .WillOnce(DoAll( |
| 500 // This event should get through to the input stub. | 501 // This event should get through to the input stub. |
| 501 InjectMouseEvent(connection_, mouse_event1), | 502 InjectMouseEvent(connection_, mouse_event1), |
| 502 #if !defined(OS_WIN) | 503 #if !defined(OS_WIN) |
| 503 // The OS echoes the injected event back. | 504 // The OS echoes the injected event back. |
| 504 LocalMouseMoved(client_session_.get(), mouse_event1), | 505 LocalMouseMoved(client_session_.get(), mouse_event1), |
| 505 #endif // !defined(OS_WIN) | 506 #endif // !defined(OS_WIN) |
| 506 // This one should get throught as well. | 507 // This one should get throught as well. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 .WillOnce(Return(true)); | 545 .WillOnce(Return(true)); |
| 545 EXPECT_CALL(*input_injector_, StartPtr(_)) | 546 EXPECT_CALL(*input_injector_, StartPtr(_)) |
| 546 .After(authenticated); | 547 .After(authenticated); |
| 547 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 548 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
| 548 .After(authenticated); | 549 .After(authenticated); |
| 549 | 550 |
| 550 // Wait for the first video packet to be captured to make sure that | 551 // Wait for the first video packet to be captured to make sure that |
| 551 // the injected input will go though. Otherwise mouse events will be blocked | 552 // the injected input will go though. Otherwise mouse events will be blocked |
| 552 // by the mouse clamping filter. | 553 // by the mouse clamping filter. |
| 553 Sequence s; | 554 Sequence s; |
| 554 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 555 EXPECT_CALL(video_sender_, ProcessVideoPacketPtr(_, _)) |
| 555 .InSequence(s) | 556 .InSequence(s) |
| 556 .After(authenticated) | 557 .After(authenticated) |
| 557 .WillOnce(DoAll( | 558 .WillOnce(DoAll( |
| 558 InjectKeyEvent(connection_, key1), | 559 InjectKeyEvent(connection_, key1), |
| 559 InjectKeyEvent(connection_, key2), | 560 InjectKeyEvent(connection_, key2), |
| 560 InjectMouseEvent(connection_, mousedown), | 561 InjectMouseEvent(connection_, mousedown), |
| 561 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 562 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
| 562 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 563 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
| 563 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(1, true))) | 564 EXPECT_CALL(*input_injector_, InjectKeyEvent(EqualsUsbEvent(1, true))) |
| 564 .InSequence(s); | 565 .InSequence(s); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 protocol::MouseEvent expected_event; | 604 protocol::MouseEvent expected_event; |
| 604 for (int j = 0; j < 3; j++) { | 605 for (int j = 0; j < 3; j++) { |
| 605 for (int i = 0; i < 3; i++) { | 606 for (int i = 0; i < 3; i++) { |
| 606 protocol::MouseEvent injected_event; | 607 protocol::MouseEvent injected_event; |
| 607 injected_event.set_x(input_x[i]); | 608 injected_event.set_x(input_x[i]); |
| 608 injected_event.set_y(input_y[j]); | 609 injected_event.set_y(input_y[j]); |
| 609 | 610 |
| 610 if (i == 0 && j == 0) { | 611 if (i == 0 && j == 0) { |
| 611 // Inject the 1st event once a video packet has been received. | 612 // Inject the 1st event once a video packet has been received. |
| 612 connected = | 613 connected = |
| 613 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 614 EXPECT_CALL(video_sender_, ProcessVideoPacketPtr(_, _)) |
| 614 .After(connected) | 615 .After(connected) |
| 615 .WillOnce(InjectMouseEvent(connection_, injected_event)); | 616 .WillOnce(InjectMouseEvent(connection_, injected_event)); |
| 616 } else { | 617 } else { |
| 617 // Every next event is injected once the previous event has been | 618 // Every next event is injected once the previous event has been |
| 618 // received. | 619 // received. |
| 619 connected = | 620 connected = |
| 620 EXPECT_CALL(*input_injector_, | 621 EXPECT_CALL(*input_injector_, |
| 621 InjectMouseEvent(EqualsMouseEvent(expected_event.x(), | 622 InjectMouseEvent(EqualsMouseEvent(expected_event.x(), |
| 622 expected_event.y()))) | 623 expected_event.y()))) |
| 623 .After(connected) | 624 .After(connected) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 ConnectClientSession(); | 692 ConnectClientSession(); |
| 692 } | 693 } |
| 693 | 694 |
| 694 // Verifies that the client's video pipeline can be reset mid-session. | 695 // Verifies that the client's video pipeline can be reset mid-session. |
| 695 TEST_F(ClientSessionTest, ResetVideoPipeline) { | 696 TEST_F(ClientSessionTest, ResetVideoPipeline) { |
| 696 CreateClientSession(); | 697 CreateClientSession(); |
| 697 | 698 |
| 698 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) | 699 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) |
| 699 .WillOnce(Return(true)); | 700 .WillOnce(Return(true)); |
| 700 | 701 |
| 701 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 702 EXPECT_CALL(video_sender_, ProcessVideoPacketPtr(_, _)) |
| 702 .WillOnce(DoAll( | 703 .WillOnce(DoAll( |
| 703 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 704 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
| 704 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 705 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
| 705 | 706 |
| 706 ConnectClientSession(); | 707 ConnectClientSession(); |
| 707 | 708 |
| 708 client_session_->ResetVideoPipeline(); | 709 client_session_->ResetVideoPipeline(); |
| 709 } | 710 } |
| 710 | 711 |
| 711 // Verifies that clients can have extensions registered, resulting in the | 712 // Verifies that clients can have extensions registered, resulting in the |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 | 809 |
| 809 DisconnectClientSession(); | 810 DisconnectClientSession(); |
| 810 StopClientSession(); | 811 StopClientSession(); |
| 811 | 812 |
| 812 // ext1 was instantiated and wrapped the video capturer. | 813 // ext1 was instantiated and wrapped the video capturer. |
| 813 EXPECT_TRUE(extension.was_instantiated()); | 814 EXPECT_TRUE(extension.was_instantiated()); |
| 814 EXPECT_TRUE(extension.has_wrapped_video_capturer()); | 815 EXPECT_TRUE(extension.has_wrapped_video_capturer()); |
| 815 } | 816 } |
| 816 | 817 |
| 817 } // namespace remoting | 818 } // namespace remoting |
| OLD | NEW |