| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "media/video/capture/screen/screen_capturer_fake.h" | 9 #include "media/video/capture/screen/screen_capturer_fake.h" |
| 10 #include "remoting/base/auto_thread_task_runner.h" | 10 #include "remoting/base/auto_thread_task_runner.h" |
| 11 #include "remoting/host/audio_capturer.h" | 11 #include "remoting/host/audio_capturer.h" |
| 12 #include "remoting/host/chromoting_host.h" | 12 #include "remoting/host/chromoting_host.h" |
| 13 #include "remoting/host/chromoting_host_context.h" | 13 #include "remoting/host/chromoting_host_context.h" |
| 14 #include "remoting/host/desktop_environment.h" | 14 #include "remoting/host/desktop_environment.h" |
| 15 #include "remoting/host/host_mock_objects.h" | 15 #include "remoting/host/host_mock_objects.h" |
| 16 #include "remoting/host/it2me_host_user_interface.h" | |
| 17 #include "remoting/jingle_glue/mock_objects.h" | 16 #include "remoting/jingle_glue/mock_objects.h" |
| 18 #include "remoting/proto/video.pb.h" | 17 #include "remoting/proto/video.pb.h" |
| 19 #include "remoting/protocol/errors.h" | 18 #include "remoting/protocol/errors.h" |
| 20 #include "remoting/protocol/protocol_mock_objects.h" | 19 #include "remoting/protocol/protocol_mock_objects.h" |
| 21 #include "remoting/protocol/session_config.h" | 20 #include "remoting/protocol/session_config.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gmock_mutant.h" | 22 #include "testing/gmock_mutant.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 24 |
| 26 using ::remoting::protocol::MockClientStub; | 25 using ::remoting::protocol::MockClientStub; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 56 } | 55 } |
| 57 | 56 |
| 58 // Run the task and delete it afterwards. This action is used to deal with | 57 // Run the task and delete it afterwards. This action is used to deal with |
| 59 // done callbacks. | 58 // done callbacks. |
| 60 ACTION(RunDoneTask) { | 59 ACTION(RunDoneTask) { |
| 61 arg1.Run(); | 60 arg1.Run(); |
| 62 } | 61 } |
| 63 | 62 |
| 64 } // namespace | 63 } // namespace |
| 65 | 64 |
| 66 class MockIt2MeHostUserInterface : public It2MeHostUserInterface { | |
| 67 public: | |
| 68 MockIt2MeHostUserInterface( | |
| 69 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | |
| 70 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); | |
| 71 | |
| 72 void InitFrom(scoped_ptr<ContinueWindow> continue_window); | |
| 73 | |
| 74 // A test-only version of Start that does not register a HostStatusObserver. | |
| 75 // TODO(rmsousa): Make the unit tests work with the regular Start(). | |
| 76 virtual void Start(ChromotingHost* host, | |
| 77 const base::Closure& disconnect_callback) OVERRIDE; | |
| 78 }; | |
| 79 | |
| 80 MockIt2MeHostUserInterface::MockIt2MeHostUserInterface( | |
| 81 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | |
| 82 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) | |
| 83 : It2MeHostUserInterface(network_task_runner, ui_task_runner, UiStrings()) { | |
| 84 } | |
| 85 | |
| 86 void MockIt2MeHostUserInterface::InitFrom( | |
| 87 scoped_ptr<ContinueWindow> continue_window) { | |
| 88 DCHECK(ui_task_runner()->BelongsToCurrentThread()); | |
| 89 | |
| 90 continue_window_ = continue_window.Pass(); | |
| 91 } | |
| 92 | |
| 93 void MockIt2MeHostUserInterface::Start( | |
| 94 ChromotingHost* host, const base::Closure& disconnect_callback) { | |
| 95 DCHECK(network_task_runner()->BelongsToCurrentThread()); | |
| 96 DCHECK(host_ == NULL); | |
| 97 | |
| 98 host_ = host; | |
| 99 disconnect_callback_ = disconnect_callback; | |
| 100 } | |
| 101 | |
| 102 class ChromotingHostTest : public testing::Test { | 65 class ChromotingHostTest : public testing::Test { |
| 103 public: | 66 public: |
| 104 ChromotingHostTest() { | 67 ChromotingHostTest() { |
| 105 } | 68 } |
| 106 | 69 |
| 107 virtual void SetUp() OVERRIDE { | 70 virtual void SetUp() OVERRIDE { |
| 108 ui_task_runner_ = new AutoThreadTaskRunner( | 71 ui_task_runner_ = new AutoThreadTaskRunner( |
| 109 message_loop_.message_loop_proxy(), | 72 message_loop_.message_loop_proxy(), |
| 110 base::Bind(&ChromotingHostTest::QuitMainMessageLoop, | 73 base::Bind(&ChromotingHostTest::QuitMainMessageLoop, |
| 111 base::Unretained(this))); | 74 base::Unretained(this))); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 126 desktop_environment_factory_.get(), | 89 desktop_environment_factory_.get(), |
| 127 scoped_ptr<protocol::SessionManager>(session_manager_), | 90 scoped_ptr<protocol::SessionManager>(session_manager_), |
| 128 ui_task_runner_, // Audio | 91 ui_task_runner_, // Audio |
| 129 ui_task_runner_, // Input | 92 ui_task_runner_, // Input |
| 130 ui_task_runner_, // Video capture | 93 ui_task_runner_, // Video capture |
| 131 ui_task_runner_, // Video encode | 94 ui_task_runner_, // Video encode |
| 132 ui_task_runner_, // Network | 95 ui_task_runner_, // Network |
| 133 ui_task_runner_); // UI | 96 ui_task_runner_); // UI |
| 134 host_->AddStatusObserver(&host_status_observer_); | 97 host_->AddStatusObserver(&host_status_observer_); |
| 135 | 98 |
| 136 continue_window_ = new MockContinueWindow(); | |
| 137 it2me_host_user_interface_.reset( | |
| 138 new MockIt2MeHostUserInterface(ui_task_runner_, ui_task_runner_)); | |
| 139 it2me_host_user_interface_->InitFrom( | |
| 140 scoped_ptr<ContinueWindow>(continue_window_)); | |
| 141 | |
| 142 it2me_host_user_interface_->Start( | |
| 143 host_, base::Bind(&ChromotingHost::Shutdown, host_, base::Closure())); | |
| 144 | |
| 145 xmpp_login_ = "host@domain"; | 99 xmpp_login_ = "host@domain"; |
| 146 session1_ = new MockSession(); | 100 session1_ = new MockSession(); |
| 147 session2_ = new MockSession(); | 101 session2_ = new MockSession(); |
| 148 session_unowned1_.reset(new MockSession()); | 102 session_unowned1_.reset(new MockSession()); |
| 149 session_unowned2_.reset(new MockSession()); | 103 session_unowned2_.reset(new MockSession()); |
| 150 session_config1_ = SessionConfig::ForTest(); | 104 session_config1_ = SessionConfig::ForTest(); |
| 151 session_jid1_ = "user@domain/rest-of-jid"; | 105 session_jid1_ = "user@domain/rest-of-jid"; |
| 152 session_config2_ = SessionConfig::ForTest(); | 106 session_config2_ = SessionConfig::ForTest(); |
| 153 session_jid2_ = "user2@domain/rest-of-jid"; | 107 session_jid2_ = "user2@domain/rest-of-jid"; |
| 154 session_unowned_config1_ = SessionConfig::ForTest(); | 108 session_unowned_config1_ = SessionConfig::ForTest(); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 305 |
| 352 void ShutdownHost() { | 306 void ShutdownHost() { |
| 353 ui_task_runner_->PostTask( | 307 ui_task_runner_->PostTask( |
| 354 FROM_HERE, | 308 FROM_HERE, |
| 355 base::Bind(&ChromotingHost::Shutdown, host_, | 309 base::Bind(&ChromotingHost::Shutdown, host_, |
| 356 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner, | 310 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner, |
| 357 base::Unretained(this)))); | 311 base::Unretained(this)))); |
| 358 } | 312 } |
| 359 | 313 |
| 360 void ReleaseUiTaskRunner() { | 314 void ReleaseUiTaskRunner() { |
| 361 it2me_host_user_interface_.reset(); | |
| 362 ui_task_runner_ = NULL; | 315 ui_task_runner_ = NULL; |
| 363 host_ = NULL; | 316 host_ = NULL; |
| 364 desktop_environment_factory_.reset(); | 317 desktop_environment_factory_.reset(); |
| 365 } | 318 } |
| 366 | 319 |
| 367 void QuitMainMessageLoop() { | 320 void QuitMainMessageLoop() { |
| 368 PostQuitTask(&message_loop_); | 321 PostQuitTask(&message_loop_); |
| 369 } | 322 } |
| 370 | 323 |
| 371 // Expect the host to start. | |
| 372 void ExpectHostStart() { | |
| 373 EXPECT_CALL(*continue_window_, Hide()); | |
| 374 } | |
| 375 | |
| 376 // Expect the host and session manager to start, and return the expectation | 324 // Expect the host and session manager to start, and return the expectation |
| 377 // that the session manager has started. | 325 // that the session manager has started. |
| 378 Expectation ExpectHostAndSessionManagerStart() { | 326 Expectation ExpectHostAndSessionManagerStart() { |
| 379 ExpectHostStart(); | |
| 380 EXPECT_CALL(host_status_observer_, OnStart(xmpp_login_)); | 327 EXPECT_CALL(host_status_observer_, OnStart(xmpp_login_)); |
| 381 return EXPECT_CALL(*session_manager_, Init(_, host_.get())); | 328 return EXPECT_CALL(*session_manager_, Init(_, host_.get())); |
| 382 } | 329 } |
| 383 | 330 |
| 384 // Expect a client to connect. | 331 // Expect a client to connect. |
| 385 // Return an expectation that a session has started, and that the first | 332 // Return an expectation that a session has started, and that the first |
| 386 // video packet has been sent to the client. | 333 // video packet has been sent to the client. |
| 387 // Do |action| when that happens. | 334 // Do |action| when that happens. |
| 388 template <class A> | 335 template <class A> |
| 389 Expectation ExpectClientConnected(int connection_index, A action) { | 336 Expectation ExpectClientConnected(int connection_index, A action) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 .RetiresOnSaturation(); | 396 .RetiresOnSaturation(); |
| 450 } | 397 } |
| 451 } | 398 } |
| 452 | 399 |
| 453 protected: | 400 protected: |
| 454 MessageLoop message_loop_; | 401 MessageLoop message_loop_; |
| 455 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; | 402 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
| 456 MockConnectionToClientEventHandler handler_; | 403 MockConnectionToClientEventHandler handler_; |
| 457 MockSignalStrategy signal_strategy_; | 404 MockSignalStrategy signal_strategy_; |
| 458 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; | 405 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; |
| 459 scoped_ptr<MockIt2MeHostUserInterface> it2me_host_user_interface_; | |
| 460 scoped_refptr<ChromotingHost> host_; | 406 scoped_refptr<ChromotingHost> host_; |
| 461 MockHostStatusObserver host_status_observer_; | 407 MockHostStatusObserver host_status_observer_; |
| 462 protocol::MockSessionManager* session_manager_; | 408 protocol::MockSessionManager* session_manager_; |
| 463 std::string xmpp_login_; | 409 std::string xmpp_login_; |
| 464 MockConnectionToClient* connection1_; | 410 MockConnectionToClient* connection1_; |
| 465 scoped_ptr<MockConnectionToClient> owned_connection1_; | 411 scoped_ptr<MockConnectionToClient> owned_connection1_; |
| 466 ClientSession* client1_; | 412 ClientSession* client1_; |
| 467 std::string session_jid1_; | 413 std::string session_jid1_; |
| 468 MockSession* session1_; // Owned by |connection_|. | 414 MockSession* session1_; // Owned by |connection_|. |
| 469 SessionConfig session_config1_; | 415 SessionConfig session_config1_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 482 scoped_ptr<MockSession> session_unowned1_; // Not owned by a connection. | 428 scoped_ptr<MockSession> session_unowned1_; // Not owned by a connection. |
| 483 SessionConfig session_unowned_config1_; | 429 SessionConfig session_unowned_config1_; |
| 484 std::string session_unowned_jid1_; | 430 std::string session_unowned_jid1_; |
| 485 scoped_ptr<MockSession> session_unowned2_; // Not owned by a connection. | 431 scoped_ptr<MockSession> session_unowned2_; // Not owned by a connection. |
| 486 SessionConfig session_unowned_config2_; | 432 SessionConfig session_unowned_config2_; |
| 487 std::string session_unowned_jid2_; | 433 std::string session_unowned_jid2_; |
| 488 protocol::Session::EventHandler* session_event_handler_; | 434 protocol::Session::EventHandler* session_event_handler_; |
| 489 scoped_ptr<protocol::CandidateSessionConfig> empty_candidate_config_; | 435 scoped_ptr<protocol::CandidateSessionConfig> empty_candidate_config_; |
| 490 scoped_ptr<protocol::CandidateSessionConfig> default_candidate_config_; | 436 scoped_ptr<protocol::CandidateSessionConfig> default_candidate_config_; |
| 491 | 437 |
| 492 // Owned by |host_|. | |
| 493 MockContinueWindow* continue_window_; | |
| 494 | |
| 495 MockConnectionToClient*& get_connection(int connection_index) { | 438 MockConnectionToClient*& get_connection(int connection_index) { |
| 496 return (connection_index == 0) ? connection1_ : connection2_; | 439 return (connection_index == 0) ? connection1_ : connection2_; |
| 497 } | 440 } |
| 498 | 441 |
| 499 ClientSession*& get_client(int connection_index) { | 442 ClientSession*& get_client(int connection_index) { |
| 500 return (connection_index == 0) ? client1_ : client2_; | 443 return (connection_index == 0) ? client1_ : client2_; |
| 501 } | 444 } |
| 502 | 445 |
| 503 const std::string& get_session_jid(int connection_index) { | 446 const std::string& get_session_jid(int connection_index) { |
| 504 return (connection_index == 0) ? session_jid1_ : session_jid2_; | 447 return (connection_index == 0) ? session_jid1_ : session_jid2_; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 Expectation client_disconnected2 = ExpectClientDisconnected( | 546 Expectation client_disconnected2 = ExpectClientDisconnected( |
| 604 1, true, video_packet_sent2, InvokeWithoutArgs(base::DoNothing)); | 547 1, true, video_packet_sent2, InvokeWithoutArgs(base::DoNothing)); |
| 605 EXPECT_CALL(host_status_observer_, OnShutdown()).After(client_disconnected2); | 548 EXPECT_CALL(host_status_observer_, OnShutdown()).After(client_disconnected2); |
| 606 | 549 |
| 607 host_->Start(xmpp_login_); | 550 host_->Start(xmpp_login_); |
| 608 SimulateClientConnection(0, true, false); | 551 SimulateClientConnection(0, true, false); |
| 609 message_loop_.Run(); | 552 message_loop_.Run(); |
| 610 } | 553 } |
| 611 | 554 |
| 612 TEST_F(ChromotingHostTest, IncomingSessionDeclined) { | 555 TEST_F(ChromotingHostTest, IncomingSessionDeclined) { |
| 613 ExpectHostStart(); | |
| 614 protocol::SessionManager::IncomingSessionResponse response = | 556 protocol::SessionManager::IncomingSessionResponse response = |
| 615 protocol::SessionManager::ACCEPT; | 557 protocol::SessionManager::ACCEPT; |
| 616 host_->OnIncomingSession(session1_, &response); | 558 host_->OnIncomingSession(session1_, &response); |
| 617 EXPECT_EQ(protocol::SessionManager::DECLINE, response); | 559 EXPECT_EQ(protocol::SessionManager::DECLINE, response); |
| 618 | 560 |
| 619 ShutdownHost(); | 561 ShutdownHost(); |
| 620 message_loop_.Run(); | 562 message_loop_.Run(); |
| 621 } | 563 } |
| 622 | 564 |
| 623 TEST_F(ChromotingHostTest, IncomingSessionIncompatible) { | 565 TEST_F(ChromotingHostTest, IncomingSessionIncompatible) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 ExpectClientDisconnected(0, true, video_packet_sent, | 653 ExpectClientDisconnected(0, true, video_packet_sent, |
| 712 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); | 654 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); |
| 713 EXPECT_CALL(host_status_observer_, OnShutdown()); | 655 EXPECT_CALL(host_status_observer_, OnShutdown()); |
| 714 | 656 |
| 715 host_->Start(xmpp_login_); | 657 host_->Start(xmpp_login_); |
| 716 SimulateClientConnection(0, true, false); | 658 SimulateClientConnection(0, true, false); |
| 717 message_loop_.Run(); | 659 message_loop_.Run(); |
| 718 } | 660 } |
| 719 | 661 |
| 720 } // namespace remoting | 662 } // namespace remoting |
| OLD | NEW |