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" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 61 } |
62 | 62 |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 class ChromotingHostTest : public testing::Test { | 65 class ChromotingHostTest : public testing::Test { |
66 public: | 66 public: |
67 ChromotingHostTest() { | 67 ChromotingHostTest() { |
68 } | 68 } |
69 | 69 |
70 virtual void SetUp() OVERRIDE { | 70 virtual void SetUp() OVERRIDE { |
71 ui_task_runner_ = new AutoThreadTaskRunner( | 71 task_runner_ = new AutoThreadTaskRunner( |
72 message_loop_.message_loop_proxy(), | 72 message_loop_.message_loop_proxy(), |
73 base::Bind(&ChromotingHostTest::QuitMainMessageLoop, | 73 base::Bind(&ChromotingHostTest::QuitMainMessageLoop, |
74 base::Unretained(this))); | 74 base::Unretained(this))); |
75 | 75 |
76 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); | 76 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); |
77 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) | 77 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) |
78 .Times(AnyNumber()) | 78 .Times(AnyNumber()) |
79 .WillRepeatedly(Invoke(this, | 79 .WillRepeatedly(Invoke(this, |
80 &ChromotingHostTest::CreateDesktopEnvironment)); | 80 &ChromotingHostTest::CreateDesktopEnvironment)); |
81 EXPECT_CALL(*desktop_environment_factory_, SupportsAudioCapture()) | 81 EXPECT_CALL(*desktop_environment_factory_, SupportsAudioCapture()) |
82 .Times(AnyNumber()) | 82 .Times(AnyNumber()) |
83 .WillRepeatedly(Return(false)); | 83 .WillRepeatedly(Return(false)); |
84 | 84 |
85 session_manager_ = new protocol::MockSessionManager(); | 85 session_manager_ = new protocol::MockSessionManager(); |
86 | 86 |
87 host_ = new ChromotingHost( | 87 host_.reset(new ChromotingHost( |
88 &signal_strategy_, | 88 &signal_strategy_, |
89 desktop_environment_factory_.get(), | 89 desktop_environment_factory_.get(), |
90 scoped_ptr<protocol::SessionManager>(session_manager_), | 90 scoped_ptr<protocol::SessionManager>(session_manager_), |
91 ui_task_runner_, // Audio | 91 task_runner_, // Audio |
92 ui_task_runner_, // Input | 92 task_runner_, // Input |
93 ui_task_runner_, // Video capture | 93 task_runner_, // Video capture |
94 ui_task_runner_, // Video encode | 94 task_runner_, // Video encode |
95 ui_task_runner_, // Network | 95 task_runner_, // Network |
96 ui_task_runner_); // UI | 96 task_runner_)); // UI |
97 host_->AddStatusObserver(&host_status_observer_); | 97 host_->AddStatusObserver(&host_status_observer_); |
98 | 98 |
99 xmpp_login_ = "host@domain"; | 99 xmpp_login_ = "host@domain"; |
100 session1_ = new MockSession(); | 100 session1_ = new MockSession(); |
101 session2_ = new MockSession(); | 101 session2_ = new MockSession(); |
102 session_unowned1_.reset(new MockSession()); | 102 session_unowned1_.reset(new MockSession()); |
103 session_unowned2_.reset(new MockSession()); | 103 session_unowned2_.reset(new MockSession()); |
104 session_config1_ = SessionConfig::ForTest(); | 104 session_config1_ = SessionConfig::ForTest(); |
105 session_jid1_ = "user@domain/rest-of-jid"; | 105 session_jid1_ = "user@domain/rest-of-jid"; |
106 session_config2_ = SessionConfig::ForTest(); | 106 session_config2_ = SessionConfig::ForTest(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 176 |
177 // Helper method to pretend a client is connected to ChromotingHost. | 177 // Helper method to pretend a client is connected to ChromotingHost. |
178 void SimulateClientConnection(int connection_index, bool authenticate, | 178 void SimulateClientConnection(int connection_index, bool authenticate, |
179 bool reject) { | 179 bool reject) { |
180 scoped_ptr<protocol::ConnectionToClient> connection = | 180 scoped_ptr<protocol::ConnectionToClient> connection = |
181 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). | 181 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). |
182 PassAs<protocol::ConnectionToClient>(); | 182 PassAs<protocol::ConnectionToClient>(); |
183 protocol::ConnectionToClient* connection_ptr = connection.get(); | 183 protocol::ConnectionToClient* connection_ptr = connection.get(); |
184 scoped_ptr<ClientSession> client(new ClientSession( | 184 scoped_ptr<ClientSession> client(new ClientSession( |
185 host_.get(), | 185 host_.get(), |
186 ui_task_runner_, // Audio | 186 task_runner_, // Audio |
187 ui_task_runner_, // Input | 187 task_runner_, // Input |
188 ui_task_runner_, // Video capture | 188 task_runner_, // Video capture |
189 ui_task_runner_, // Video encode | 189 task_runner_, // Video encode |
190 ui_task_runner_, // Network | 190 task_runner_, // Network |
191 ui_task_runner_, // UI | 191 task_runner_, // UI |
192 connection.Pass(), | 192 connection.Pass(), |
193 desktop_environment_factory_.get(), | 193 desktop_environment_factory_.get(), |
194 base::TimeDelta())); | 194 base::TimeDelta())); |
195 | 195 |
196 ClientSession* client_raw = client.get(); | 196 connection_ptr->set_host_stub(client.get()); |
197 connection_ptr->set_host_stub(client_raw); | |
198 | |
199 ui_task_runner_->PostTask( | |
200 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, | |
201 host_, base::Passed(&client))); | |
202 | 197 |
203 if (authenticate) { | 198 if (authenticate) { |
204 ui_task_runner_->PostTask( | 199 task_runner_->PostTask( |
205 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated, | 200 FROM_HERE, |
206 base::Unretained(client_raw), connection_ptr)); | 201 base::Bind(&ClientSession::OnConnectionAuthenticated, |
| 202 base::Unretained(client.get()), connection_ptr)); |
207 if (!reject) { | 203 if (!reject) { |
208 ui_task_runner_->PostTask( | 204 task_runner_->PostTask( |
209 FROM_HERE, | 205 FROM_HERE, |
210 base::Bind(&ClientSession::OnConnectionChannelsConnected, | 206 base::Bind(&ClientSession::OnConnectionChannelsConnected, |
211 base::Unretained(client_raw), connection_ptr)); | 207 base::Unretained(client.get()), connection_ptr)); |
212 } | 208 } |
213 } else { | 209 } else { |
214 ui_task_runner_->PostTask( | 210 task_runner_->PostTask( |
215 FROM_HERE, base::Bind(&ClientSession::OnConnectionClosed, | 211 FROM_HERE, base::Bind(&ClientSession::OnConnectionClosed, |
216 base::Unretained(client_raw), connection_ptr, | 212 base::Unretained(client.get()), connection_ptr, |
217 protocol::AUTHENTICATION_FAILED)); | 213 protocol::AUTHENTICATION_FAILED)); |
218 } | 214 } |
219 | 215 |
220 get_client(connection_index) = client_raw; | 216 get_client(connection_index) = client.get(); |
| 217 |
| 218 // |host| is responsible for deleting |client| from now on. |
| 219 host_->clients_.push_back(client.release()); |
221 } | 220 } |
222 | 221 |
223 virtual void TearDown() OVERRIDE { | 222 virtual void TearDown() OVERRIDE { |
224 // Make sure that the host has been properly deleted. | 223 // Make sure that the host has been properly deleted. |
225 DCHECK(host_.get() == NULL); | 224 DCHECK(host_.get() == NULL); |
226 } | 225 } |
227 | 226 |
228 // Change the session route for |client1_|. | 227 // Change the session route for |client1_|. |
229 void ChangeSessionRoute(const std::string& channel_name, | 228 void ChangeSessionRoute(const std::string& channel_name, |
230 const protocol::TransportRoute& route) { | 229 const protocol::TransportRoute& route) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 void SetEventHandler(protocol::Session::EventHandler* event_handler) { | 289 void SetEventHandler(protocol::Session::EventHandler* event_handler) { |
291 session_event_handler_ = event_handler; | 290 session_event_handler_ = event_handler; |
292 } | 291 } |
293 | 292 |
294 void NotifyConnectionClosed() { | 293 void NotifyConnectionClosed() { |
295 if (session_event_handler_) { | 294 if (session_event_handler_) { |
296 session_event_handler_->OnSessionStateChange(protocol::Session::CLOSED); | 295 session_event_handler_->OnSessionStateChange(protocol::Session::CLOSED); |
297 } | 296 } |
298 } | 297 } |
299 | 298 |
300 static void AddClientToHost(scoped_refptr<ChromotingHost> host, | 299 void ShutdownHost() { |
301 scoped_ptr<ClientSession> client) { | 300 task_runner_->PostTask( |
302 // |host| is responsible for deleting |client| from now on. | 301 FROM_HERE, |
303 host->clients_.push_back(client.release()); | 302 base::Bind(&ChromotingHostTest::StopAndReleaseTaskRunner, |
| 303 base::Unretained(this))); |
304 } | 304 } |
305 | 305 |
306 void ShutdownHost() { | 306 void StopAndReleaseTaskRunner() { |
307 ui_task_runner_->PostTask( | 307 host_.reset(); |
308 FROM_HERE, | 308 task_runner_ = NULL; |
309 base::Bind(&ChromotingHost::Shutdown, host_, | |
310 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner, | |
311 base::Unretained(this)))); | |
312 } | |
313 | |
314 void ReleaseUiTaskRunner() { | |
315 ui_task_runner_ = NULL; | |
316 host_ = NULL; | |
317 desktop_environment_factory_.reset(); | 309 desktop_environment_factory_.reset(); |
318 } | 310 } |
319 | 311 |
320 void QuitMainMessageLoop() { | 312 void QuitMainMessageLoop() { |
321 PostQuitTask(&message_loop_); | 313 PostQuitTask(&message_loop_); |
322 } | 314 } |
323 | 315 |
324 // Expect the host and session manager to start, and return the expectation | 316 // Expect the host and session manager to start, and return the expectation |
325 // that the session manager has started. | 317 // that the session manager has started. |
326 Expectation ExpectHostAndSessionManagerStart() { | 318 Expectation ExpectHostAndSessionManagerStart() { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 if (expect_host_status_change) { | 384 if (expect_host_status_change) { |
393 EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid)) | 385 EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid)) |
394 .After(after) | 386 .After(after) |
395 .WillOnce(action) | 387 .WillOnce(action) |
396 .RetiresOnSaturation(); | 388 .RetiresOnSaturation(); |
397 } | 389 } |
398 } | 390 } |
399 | 391 |
400 protected: | 392 protected: |
401 MessageLoop message_loop_; | 393 MessageLoop message_loop_; |
402 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; | 394 scoped_refptr<AutoThreadTaskRunner> task_runner_; |
403 MockConnectionToClientEventHandler handler_; | 395 MockConnectionToClientEventHandler handler_; |
404 MockSignalStrategy signal_strategy_; | 396 MockSignalStrategy signal_strategy_; |
405 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; | 397 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; |
406 scoped_refptr<ChromotingHost> host_; | 398 scoped_ptr<ChromotingHost> host_; |
407 MockHostStatusObserver host_status_observer_; | 399 MockHostStatusObserver host_status_observer_; |
408 protocol::MockSessionManager* session_manager_; | 400 protocol::MockSessionManager* session_manager_; |
409 std::string xmpp_login_; | 401 std::string xmpp_login_; |
410 MockConnectionToClient* connection1_; | 402 MockConnectionToClient* connection1_; |
411 scoped_ptr<MockConnectionToClient> owned_connection1_; | 403 scoped_ptr<MockConnectionToClient> owned_connection1_; |
412 ClientSession* client1_; | 404 ClientSession* client1_; |
413 std::string session_jid1_; | 405 std::string session_jid1_; |
414 MockSession* session1_; // Owned by |connection_|. | 406 MockSession* session1_; // Owned by |connection_|. |
415 SessionConfig session_config1_; | 407 SessionConfig session_config1_; |
416 MockVideoStub video_stub1_; | 408 MockVideoStub video_stub1_; |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 ExpectClientDisconnected(0, true, video_packet_sent, | 645 ExpectClientDisconnected(0, true, video_packet_sent, |
654 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); | 646 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); |
655 EXPECT_CALL(host_status_observer_, OnShutdown()); | 647 EXPECT_CALL(host_status_observer_, OnShutdown()); |
656 | 648 |
657 host_->Start(xmpp_login_); | 649 host_->Start(xmpp_login_); |
658 SimulateClientConnection(0, true, false); | 650 SimulateClientConnection(0, true, false); |
659 message_loop_.Run(); | 651 message_loop_.Run(); |
660 } | 652 } |
661 | 653 |
662 } // namespace remoting | 654 } // namespace remoting |
OLD | NEW |