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 28 matching lines...) Expand all Loading... |
55 } | 54 } |
56 | 55 |
57 // Run the task and delete it afterwards. This action is used to deal with | 56 // Run the task and delete it afterwards. This action is used to deal with |
58 // done callbacks. | 57 // done callbacks. |
59 ACTION(RunDoneTask) { | 58 ACTION(RunDoneTask) { |
60 arg1.Run(); | 59 arg1.Run(); |
61 } | 60 } |
62 | 61 |
63 } // namespace | 62 } // namespace |
64 | 63 |
65 class MockIt2MeHostUserInterface : public It2MeHostUserInterface { | |
66 public: | |
67 MockIt2MeHostUserInterface( | |
68 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | |
69 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); | |
70 | |
71 void InitFrom(scoped_ptr<ContinueWindow> continue_window); | |
72 | |
73 // A test-only version of Start that does not register a HostStatusObserver. | |
74 // TODO(rmsousa): Make the unit tests work with the regular Start(). | |
75 virtual void Start(ChromotingHost* host, | |
76 const base::Closure& disconnect_callback) OVERRIDE; | |
77 }; | |
78 | |
79 MockIt2MeHostUserInterface::MockIt2MeHostUserInterface( | |
80 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | |
81 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) | |
82 : It2MeHostUserInterface(network_task_runner, ui_task_runner, UiStrings()) { | |
83 } | |
84 | |
85 void MockIt2MeHostUserInterface::InitFrom( | |
86 scoped_ptr<ContinueWindow> continue_window) { | |
87 DCHECK(ui_task_runner()->BelongsToCurrentThread()); | |
88 | |
89 continue_window_ = continue_window.Pass(); | |
90 } | |
91 | |
92 void MockIt2MeHostUserInterface::Start( | |
93 ChromotingHost* host, const base::Closure& disconnect_callback) { | |
94 DCHECK(network_task_runner()->BelongsToCurrentThread()); | |
95 DCHECK(host_ == NULL); | |
96 | |
97 host_ = host; | |
98 disconnect_callback_ = disconnect_callback; | |
99 } | |
100 | |
101 class ChromotingHostTest : public testing::Test { | 64 class ChromotingHostTest : public testing::Test { |
102 public: | 65 public: |
103 ChromotingHostTest() { | 66 ChromotingHostTest() { |
104 } | 67 } |
105 | 68 |
106 virtual void SetUp() OVERRIDE { | 69 virtual void SetUp() OVERRIDE { |
107 ui_task_runner_ = new AutoThreadTaskRunner( | 70 ui_task_runner_ = new AutoThreadTaskRunner( |
108 message_loop_.message_loop_proxy(), | 71 message_loop_.message_loop_proxy(), |
109 base::Bind(&ChromotingHostTest::QuitMainMessageLoop, | 72 base::Bind(&ChromotingHostTest::QuitMainMessageLoop, |
110 base::Unretained(this))); | 73 base::Unretained(this))); |
(...skipping 14 matching lines...) Expand all Loading... |
125 desktop_environment_factory_.get(), | 88 desktop_environment_factory_.get(), |
126 scoped_ptr<protocol::SessionManager>(session_manager_), | 89 scoped_ptr<protocol::SessionManager>(session_manager_), |
127 ui_task_runner_, // Audio | 90 ui_task_runner_, // Audio |
128 ui_task_runner_, // Input | 91 ui_task_runner_, // Input |
129 ui_task_runner_, // Video capture | 92 ui_task_runner_, // Video capture |
130 ui_task_runner_, // Video encode | 93 ui_task_runner_, // Video encode |
131 ui_task_runner_, // Network | 94 ui_task_runner_, // Network |
132 ui_task_runner_); // UI | 95 ui_task_runner_); // UI |
133 host_->AddStatusObserver(&host_status_observer_); | 96 host_->AddStatusObserver(&host_status_observer_); |
134 | 97 |
135 continue_window_ = new MockContinueWindow(); | |
136 it2me_host_user_interface_.reset( | |
137 new MockIt2MeHostUserInterface(ui_task_runner_, ui_task_runner_)); | |
138 it2me_host_user_interface_->InitFrom( | |
139 scoped_ptr<ContinueWindow>(continue_window_)); | |
140 | |
141 it2me_host_user_interface_->Start( | |
142 host_, base::Bind(&ChromotingHost::Shutdown, host_, base::Closure())); | |
143 | |
144 xmpp_login_ = "host@domain"; | 98 xmpp_login_ = "host@domain"; |
145 session1_ = new MockSession(); | 99 session1_ = new MockSession(); |
146 session2_ = new MockSession(); | 100 session2_ = new MockSession(); |
147 session_unowned1_.reset(new MockSession()); | 101 session_unowned1_.reset(new MockSession()); |
148 session_unowned2_.reset(new MockSession()); | 102 session_unowned2_.reset(new MockSession()); |
149 session_config1_ = SessionConfig::ForTest(); | 103 session_config1_ = SessionConfig::ForTest(); |
150 session_jid1_ = "user@domain/rest-of-jid"; | 104 session_jid1_ = "user@domain/rest-of-jid"; |
151 session_config2_ = SessionConfig::ForTest(); | 105 session_config2_ = SessionConfig::ForTest(); |
152 session_jid2_ = "user2@domain/rest-of-jid"; | 106 session_jid2_ = "user2@domain/rest-of-jid"; |
153 session_unowned_config1_ = SessionConfig::ForTest(); | 107 session_unowned_config1_ = SessionConfig::ForTest(); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 300 |
347 void ShutdownHost() { | 301 void ShutdownHost() { |
348 ui_task_runner_->PostTask( | 302 ui_task_runner_->PostTask( |
349 FROM_HERE, | 303 FROM_HERE, |
350 base::Bind(&ChromotingHost::Shutdown, host_, | 304 base::Bind(&ChromotingHost::Shutdown, host_, |
351 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner, | 305 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner, |
352 base::Unretained(this)))); | 306 base::Unretained(this)))); |
353 } | 307 } |
354 | 308 |
355 void ReleaseUiTaskRunner() { | 309 void ReleaseUiTaskRunner() { |
356 it2me_host_user_interface_.reset(); | |
357 ui_task_runner_ = NULL; | 310 ui_task_runner_ = NULL; |
358 host_ = NULL; | 311 host_ = NULL; |
359 desktop_environment_factory_.reset(); | 312 desktop_environment_factory_.reset(); |
360 } | 313 } |
361 | 314 |
362 void QuitMainMessageLoop() { | 315 void QuitMainMessageLoop() { |
363 PostQuitTask(&message_loop_); | 316 PostQuitTask(&message_loop_); |
364 } | 317 } |
365 | 318 |
366 // Expect the host to start. | |
367 void ExpectHostStart() { | |
368 EXPECT_CALL(*continue_window_, Hide()); | |
369 } | |
370 | |
371 // Expect the host and session manager to start, and return the expectation | 319 // Expect the host and session manager to start, and return the expectation |
372 // that the session manager has started. | 320 // that the session manager has started. |
373 Expectation ExpectHostAndSessionManagerStart() { | 321 Expectation ExpectHostAndSessionManagerStart() { |
374 ExpectHostStart(); | |
375 EXPECT_CALL(host_status_observer_, OnStart(xmpp_login_)); | 322 EXPECT_CALL(host_status_observer_, OnStart(xmpp_login_)); |
376 return EXPECT_CALL(*session_manager_, Init(_, host_.get())); | 323 return EXPECT_CALL(*session_manager_, Init(_, host_.get())); |
377 } | 324 } |
378 | 325 |
379 // Expect a client to connect. | 326 // Expect a client to connect. |
380 // Return an expectation that a session has started, and that the first | 327 // Return an expectation that a session has started, and that the first |
381 // video packet has been sent to the client. | 328 // video packet has been sent to the client. |
382 // Do |action| when that happens. | 329 // Do |action| when that happens. |
383 template <class A> | 330 template <class A> |
384 Expectation ExpectClientConnected(int connection_index, A action) { | 331 Expectation ExpectClientConnected(int connection_index, A action) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 .RetiresOnSaturation(); | 391 .RetiresOnSaturation(); |
445 } | 392 } |
446 } | 393 } |
447 | 394 |
448 protected: | 395 protected: |
449 MessageLoop message_loop_; | 396 MessageLoop message_loop_; |
450 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; | 397 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
451 MockConnectionToClientEventHandler handler_; | 398 MockConnectionToClientEventHandler handler_; |
452 MockSignalStrategy signal_strategy_; | 399 MockSignalStrategy signal_strategy_; |
453 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; | 400 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; |
454 scoped_ptr<MockIt2MeHostUserInterface> it2me_host_user_interface_; | |
455 scoped_refptr<ChromotingHost> host_; | 401 scoped_refptr<ChromotingHost> host_; |
456 MockHostStatusObserver host_status_observer_; | 402 MockHostStatusObserver host_status_observer_; |
457 protocol::MockSessionManager* session_manager_; | 403 protocol::MockSessionManager* session_manager_; |
458 std::string xmpp_login_; | 404 std::string xmpp_login_; |
459 MockConnectionToClient* connection1_; | 405 MockConnectionToClient* connection1_; |
460 scoped_ptr<MockConnectionToClient> owned_connection1_; | 406 scoped_ptr<MockConnectionToClient> owned_connection1_; |
461 ClientSession* client1_; | 407 ClientSession* client1_; |
462 std::string session_jid1_; | 408 std::string session_jid1_; |
463 MockSession* session1_; // Owned by |connection_|. | 409 MockSession* session1_; // Owned by |connection_|. |
464 SessionConfig session_config1_; | 410 SessionConfig session_config1_; |
(...skipping 12 matching lines...) Expand all Loading... |
477 scoped_ptr<MockSession> session_unowned1_; // Not owned by a connection. | 423 scoped_ptr<MockSession> session_unowned1_; // Not owned by a connection. |
478 SessionConfig session_unowned_config1_; | 424 SessionConfig session_unowned_config1_; |
479 std::string session_unowned_jid1_; | 425 std::string session_unowned_jid1_; |
480 scoped_ptr<MockSession> session_unowned2_; // Not owned by a connection. | 426 scoped_ptr<MockSession> session_unowned2_; // Not owned by a connection. |
481 SessionConfig session_unowned_config2_; | 427 SessionConfig session_unowned_config2_; |
482 std::string session_unowned_jid2_; | 428 std::string session_unowned_jid2_; |
483 protocol::Session::EventHandler* session_event_handler_; | 429 protocol::Session::EventHandler* session_event_handler_; |
484 scoped_ptr<protocol::CandidateSessionConfig> empty_candidate_config_; | 430 scoped_ptr<protocol::CandidateSessionConfig> empty_candidate_config_; |
485 scoped_ptr<protocol::CandidateSessionConfig> default_candidate_config_; | 431 scoped_ptr<protocol::CandidateSessionConfig> default_candidate_config_; |
486 | 432 |
487 // Owned by |host_|. | |
488 MockContinueWindow* continue_window_; | |
489 | |
490 MockConnectionToClient*& get_connection(int connection_index) { | 433 MockConnectionToClient*& get_connection(int connection_index) { |
491 return (connection_index == 0) ? connection1_ : connection2_; | 434 return (connection_index == 0) ? connection1_ : connection2_; |
492 } | 435 } |
493 | 436 |
494 ClientSession*& get_client(int connection_index) { | 437 ClientSession*& get_client(int connection_index) { |
495 return (connection_index == 0) ? client1_ : client2_; | 438 return (connection_index == 0) ? client1_ : client2_; |
496 } | 439 } |
497 | 440 |
498 const std::string& get_session_jid(int connection_index) { | 441 const std::string& get_session_jid(int connection_index) { |
499 return (connection_index == 0) ? session_jid1_ : session_jid2_; | 442 return (connection_index == 0) ? session_jid1_ : session_jid2_; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 Expectation client_disconnected2 = ExpectClientDisconnected( | 541 Expectation client_disconnected2 = ExpectClientDisconnected( |
599 1, true, video_packet_sent2, InvokeWithoutArgs(base::DoNothing)); | 542 1, true, video_packet_sent2, InvokeWithoutArgs(base::DoNothing)); |
600 EXPECT_CALL(host_status_observer_, OnShutdown()).After(client_disconnected2); | 543 EXPECT_CALL(host_status_observer_, OnShutdown()).After(client_disconnected2); |
601 | 544 |
602 host_->Start(xmpp_login_); | 545 host_->Start(xmpp_login_); |
603 SimulateClientConnection(0, true, false); | 546 SimulateClientConnection(0, true, false); |
604 message_loop_.Run(); | 547 message_loop_.Run(); |
605 } | 548 } |
606 | 549 |
607 TEST_F(ChromotingHostTest, IncomingSessionDeclined) { | 550 TEST_F(ChromotingHostTest, IncomingSessionDeclined) { |
608 ExpectHostStart(); | |
609 protocol::SessionManager::IncomingSessionResponse response = | 551 protocol::SessionManager::IncomingSessionResponse response = |
610 protocol::SessionManager::ACCEPT; | 552 protocol::SessionManager::ACCEPT; |
611 host_->OnIncomingSession(session1_, &response); | 553 host_->OnIncomingSession(session1_, &response); |
612 EXPECT_EQ(protocol::SessionManager::DECLINE, response); | 554 EXPECT_EQ(protocol::SessionManager::DECLINE, response); |
613 | 555 |
614 ShutdownHost(); | 556 ShutdownHost(); |
615 message_loop_.Run(); | 557 message_loop_.Run(); |
616 } | 558 } |
617 | 559 |
618 TEST_F(ChromotingHostTest, IncomingSessionIncompatible) { | 560 TEST_F(ChromotingHostTest, IncomingSessionIncompatible) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 ExpectClientDisconnected(0, true, video_packet_sent, | 648 ExpectClientDisconnected(0, true, video_packet_sent, |
707 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); | 649 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); |
708 EXPECT_CALL(host_status_observer_, OnShutdown()); | 650 EXPECT_CALL(host_status_observer_, OnShutdown()); |
709 | 651 |
710 host_->Start(xmpp_login_); | 652 host_->Start(xmpp_login_); |
711 SimulateClientConnection(0, true, false); | 653 SimulateClientConnection(0, true, false); |
712 message_loop_.Run(); | 654 message_loop_.Run(); |
713 } | 655 } |
714 | 656 |
715 } // namespace remoting | 657 } // namespace remoting |
OLD | NEW |