| 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 "remoting/base/auto_thread_task_runner.h" | 9 #include "remoting/base/auto_thread_task_runner.h" |
| 10 #include "remoting/capturer/video_frame_capturer_fake.h" | |
| 11 #include "remoting/host/audio_capturer.h" | 10 #include "remoting/host/audio_capturer.h" |
| 12 #include "remoting/host/chromoting_host.h" | 11 #include "remoting/host/chromoting_host.h" |
| 13 #include "remoting/host/chromoting_host_context.h" | 12 #include "remoting/host/chromoting_host_context.h" |
| 14 #include "remoting/host/desktop_environment.h" | |
| 15 #include "remoting/host/desktop_environment_factory.h" | 13 #include "remoting/host/desktop_environment_factory.h" |
| 16 #include "remoting/host/event_executor_fake.h" | 14 #include "remoting/host/desktop_environment_fake.h" |
| 17 #include "remoting/host/host_mock_objects.h" | 15 #include "remoting/host/host_mock_objects.h" |
| 18 #include "remoting/host/it2me_host_user_interface.h" | 16 #include "remoting/host/it2me_host_user_interface.h" |
| 19 #include "remoting/jingle_glue/mock_objects.h" | 17 #include "remoting/jingle_glue/mock_objects.h" |
| 20 #include "remoting/proto/video.pb.h" | 18 #include "remoting/proto/video.pb.h" |
| 21 #include "remoting/protocol/errors.h" | 19 #include "remoting/protocol/errors.h" |
| 22 #include "remoting/protocol/protocol_mock_objects.h" | 20 #include "remoting/protocol/protocol_mock_objects.h" |
| 23 #include "remoting/protocol/session_config.h" | 21 #include "remoting/protocol/session_config.h" |
| 24 #include "testing/gmock_mutant.h" | 22 #include "testing/gmock_mutant.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 public: | 109 public: |
| 112 ChromotingHostTest() { | 110 ChromotingHostTest() { |
| 113 } | 111 } |
| 114 | 112 |
| 115 virtual void SetUp() OVERRIDE { | 113 virtual void SetUp() OVERRIDE { |
| 116 ui_task_runner_ = new AutoThreadTaskRunner( | 114 ui_task_runner_ = new AutoThreadTaskRunner( |
| 117 message_loop_.message_loop_proxy(), | 115 message_loop_.message_loop_proxy(), |
| 118 base::Bind(&ChromotingHostTest::QuitMainMessageLoop, | 116 base::Bind(&ChromotingHostTest::QuitMainMessageLoop, |
| 119 base::Unretained(this))); | 117 base::Unretained(this))); |
| 120 | 118 |
| 121 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); | 119 desktop_environment_factory_.reset( |
| 120 new MockDesktopEnvironmentFactory(ui_task_runner_)); |
| 122 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) | 121 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) |
| 123 .Times(AnyNumber()) | 122 .Times(AnyNumber()) |
| 124 .WillRepeatedly(Invoke(this, | 123 .WillRepeatedly(Invoke(this, |
| 125 &ChromotingHostTest::CreateDesktopEnvironment)); | 124 &ChromotingHostTest::CreateDesktopEnvironment)); |
| 126 | 125 |
| 127 session_manager_ = new protocol::MockSessionManager(); | 126 session_manager_ = new protocol::MockSessionManager(); |
| 128 | 127 |
| 129 host_ = new ChromotingHost( | 128 host_ = new ChromotingHost( |
| 130 &signal_strategy_, | 129 &signal_strategy_, |
| 131 desktop_environment_factory_.get(), | 130 desktop_environment_factory_.get(), |
| 132 scoped_ptr<protocol::SessionManager>(session_manager_), | 131 scoped_ptr<protocol::SessionManager>(session_manager_), |
| 133 ui_task_runner_, // Audio | 132 ui_task_runner_, // Audio |
| 133 ui_task_runner_, // Input |
| 134 ui_task_runner_, // Video capture | 134 ui_task_runner_, // Video capture |
| 135 ui_task_runner_, // Video encode | 135 ui_task_runner_, // Video encode |
| 136 ui_task_runner_); // Network | 136 ui_task_runner_, // Network |
| 137 ui_task_runner_); // UI |
| 137 host_->AddStatusObserver(&host_status_observer_); | 138 host_->AddStatusObserver(&host_status_observer_); |
| 138 | 139 |
| 139 disconnect_window_ = new MockDisconnectWindow(); | 140 disconnect_window_ = new MockDisconnectWindow(); |
| 140 continue_window_ = new MockContinueWindow(); | 141 continue_window_ = new MockContinueWindow(); |
| 141 local_input_monitor_ = new MockLocalInputMonitor(); | 142 local_input_monitor_ = new MockLocalInputMonitor(); |
| 142 it2me_host_user_interface_.reset( | 143 it2me_host_user_interface_.reset( |
| 143 new MockIt2MeHostUserInterface(ui_task_runner_, ui_task_runner_)); | 144 new MockIt2MeHostUserInterface(ui_task_runner_, ui_task_runner_)); |
| 144 it2me_host_user_interface_->InitFrom( | 145 it2me_host_user_interface_->InitFrom( |
| 145 scoped_ptr<DisconnectWindow>(disconnect_window_), | 146 scoped_ptr<DisconnectWindow>(disconnect_window_), |
| 146 scoped_ptr<ContinueWindow>(continue_window_), | 147 scoped_ptr<ContinueWindow>(continue_window_), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // Helper method to pretend a client is connected to ChromotingHost. | 231 // Helper method to pretend a client is connected to ChromotingHost. |
| 231 void SimulateClientConnection(int connection_index, bool authenticate, | 232 void SimulateClientConnection(int connection_index, bool authenticate, |
| 232 bool reject) { | 233 bool reject) { |
| 233 scoped_ptr<protocol::ConnectionToClient> connection = | 234 scoped_ptr<protocol::ConnectionToClient> connection = |
| 234 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). | 235 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). |
| 235 PassAs<protocol::ConnectionToClient>(); | 236 PassAs<protocol::ConnectionToClient>(); |
| 236 protocol::ConnectionToClient* connection_ptr = connection.get(); | 237 protocol::ConnectionToClient* connection_ptr = connection.get(); |
| 237 scoped_refptr<ClientSession> client = new ClientSession( | 238 scoped_refptr<ClientSession> client = new ClientSession( |
| 238 host_.get(), | 239 host_.get(), |
| 239 ui_task_runner_, // Audio | 240 ui_task_runner_, // Audio |
| 241 ui_task_runner_, // Input |
| 240 ui_task_runner_, // Video capture | 242 ui_task_runner_, // Video capture |
| 241 ui_task_runner_, // Video encode | 243 ui_task_runner_, // Video encode |
| 242 ui_task_runner_, // Network | 244 ui_task_runner_, // Network |
| 245 ui_task_runner_, // UI |
| 243 connection.Pass(), | 246 connection.Pass(), |
| 244 desktop_environment_factory_.get(), | 247 desktop_environment_factory_.get(), |
| 245 base::TimeDelta()); | 248 base::TimeDelta()); |
| 246 connection_ptr->set_host_stub(client); | 249 connection_ptr->set_host_stub(client); |
| 247 connection_ptr->set_input_stub( | 250 connection_ptr->set_input_stub(client->desktop_environment()); |
| 248 client->desktop_environment()->event_executor()); | |
| 249 | 251 |
| 250 ui_task_runner_->PostTask( | 252 ui_task_runner_->PostTask( |
| 251 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, | 253 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, |
| 252 host_, client)); | 254 host_, client)); |
| 253 | 255 |
| 254 if (authenticate) { | 256 if (authenticate) { |
| 255 ui_task_runner_->PostTask( | 257 ui_task_runner_->PostTask( |
| 256 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated, | 258 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated, |
| 257 client, connection_ptr)); | 259 client, connection_ptr)); |
| 258 if (!reject) { | 260 if (!reject) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 276 DCHECK(host_.get() == NULL); | 278 DCHECK(host_.get() == NULL); |
| 277 } | 279 } |
| 278 | 280 |
| 279 // Change the session route for |client1_|. | 281 // Change the session route for |client1_|. |
| 280 void ChangeSessionRoute(const std::string& channel_name, | 282 void ChangeSessionRoute(const std::string& channel_name, |
| 281 const protocol::TransportRoute& route) { | 283 const protocol::TransportRoute& route) { |
| 282 host_->OnSessionRouteChange(get_client(0), channel_name, route); | 284 host_->OnSessionRouteChange(get_client(0), channel_name, route); |
| 283 } | 285 } |
| 284 | 286 |
| 285 DesktopEnvironment* CreateDesktopEnvironment() { | 287 DesktopEnvironment* CreateDesktopEnvironment() { |
| 286 scoped_ptr<EventExecutor> event_executor(new EventExecutorFake()); | 288 return new DesktopEnvironmentFake(ui_task_runner_); |
| 287 scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake()); | |
| 288 return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL), | |
| 289 event_executor.Pass(), | |
| 290 video_capturer.Pass()); | |
| 291 } | 289 } |
| 292 | 290 |
| 293 void DisconnectAllClients() { | 291 void DisconnectAllClients() { |
| 294 host_->DisconnectAllClients(); | 292 host_->DisconnectAllClients(); |
| 295 } | 293 } |
| 296 | 294 |
| 297 // Helper method to disconnect client 1 from the host. | 295 // Helper method to disconnect client 1 from the host. |
| 298 void DisconnectClient1() { | 296 void DisconnectClient1() { |
| 299 NotifyClientSessionClosed(0); | 297 NotifyClientSessionClosed(0); |
| 300 } | 298 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 331 FROM_HERE, | 329 FROM_HERE, |
| 332 base::Bind(&ChromotingHost::Shutdown, host_, | 330 base::Bind(&ChromotingHost::Shutdown, host_, |
| 333 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner, | 331 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner, |
| 334 base::Unretained(this)))); | 332 base::Unretained(this)))); |
| 335 } | 333 } |
| 336 | 334 |
| 337 void ReleaseUiTaskRunner() { | 335 void ReleaseUiTaskRunner() { |
| 338 it2me_host_user_interface_.reset(); | 336 it2me_host_user_interface_.reset(); |
| 339 ui_task_runner_ = NULL; | 337 ui_task_runner_ = NULL; |
| 340 host_ = NULL; | 338 host_ = NULL; |
| 339 desktop_environment_factory_.reset(); |
| 341 } | 340 } |
| 342 | 341 |
| 343 void QuitMainMessageLoop() { | 342 void QuitMainMessageLoop() { |
| 344 PostQuitTask(&message_loop_); | 343 PostQuitTask(&message_loop_); |
| 345 } | 344 } |
| 346 | 345 |
| 347 // Expect the host to start. | 346 // Expect the host to start. |
| 348 void ExpectHostStart() { | 347 void ExpectHostStart() { |
| 349 EXPECT_CALL(*disconnect_window_, Hide()); | 348 EXPECT_CALL(*disconnect_window_, Hide()); |
| 350 EXPECT_CALL(*continue_window_, Hide()); | 349 EXPECT_CALL(*continue_window_, Hide()); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 ExpectClientDisconnected(0, true, video_packet_sent, | 689 ExpectClientDisconnected(0, true, video_packet_sent, |
| 691 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); | 690 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); |
| 692 EXPECT_CALL(host_status_observer_, OnShutdown()); | 691 EXPECT_CALL(host_status_observer_, OnShutdown()); |
| 693 | 692 |
| 694 host_->Start(xmpp_login_); | 693 host_->Start(xmpp_login_); |
| 695 SimulateClientConnection(0, true, false); | 694 SimulateClientConnection(0, true, false); |
| 696 message_loop_.Run(); | 695 message_loop_.Run(); |
| 697 } | 696 } |
| 698 | 697 |
| 699 } // namespace remoting | 698 } // namespace remoting |
| OLD | NEW |