Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(806)

Side by Side Diff: remoting/host/chromoting_host_unittest.cc

Issue 13466014: Made the ChromotingHost class not ref-counted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cosmetic Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 } // namespace 62 } // namespace
63 63
64 class ChromotingHostTest : public testing::Test { 64 class ChromotingHostTest : public testing::Test {
65 public: 65 public:
66 ChromotingHostTest() { 66 ChromotingHostTest() {
67 } 67 }
68 68
69 virtual void SetUp() OVERRIDE { 69 virtual void SetUp() OVERRIDE {
70 ui_task_runner_ = new AutoThreadTaskRunner( 70 task_runner_ = new AutoThreadTaskRunner(
71 message_loop_.message_loop_proxy(), 71 message_loop_.message_loop_proxy(),
72 base::Bind(&ChromotingHostTest::QuitMainMessageLoop, 72 base::Bind(&ChromotingHostTest::QuitMainMessageLoop,
73 base::Unretained(this))); 73 base::Unretained(this)));
74 74
75 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); 75 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory());
76 EXPECT_CALL(*desktop_environment_factory_, CreatePtr()) 76 EXPECT_CALL(*desktop_environment_factory_, CreatePtr())
77 .Times(AnyNumber()) 77 .Times(AnyNumber())
78 .WillRepeatedly(Invoke(this, 78 .WillRepeatedly(Invoke(this,
79 &ChromotingHostTest::CreateDesktopEnvironment)); 79 &ChromotingHostTest::CreateDesktopEnvironment));
80 EXPECT_CALL(*desktop_environment_factory_, SupportsAudioCapture()) 80 EXPECT_CALL(*desktop_environment_factory_, SupportsAudioCapture())
81 .Times(AnyNumber()) 81 .Times(AnyNumber())
82 .WillRepeatedly(Return(false)); 82 .WillRepeatedly(Return(false));
83 83
84 session_manager_ = new protocol::MockSessionManager(); 84 session_manager_ = new protocol::MockSessionManager();
85 85
86 host_ = new ChromotingHost( 86 host_.reset(new ChromotingHost(
87 &signal_strategy_, 87 &signal_strategy_,
88 desktop_environment_factory_.get(), 88 desktop_environment_factory_.get(),
89 scoped_ptr<protocol::SessionManager>(session_manager_), 89 scoped_ptr<protocol::SessionManager>(session_manager_),
90 ui_task_runner_, // Audio 90 task_runner_, // Audio
Wez 2013/04/02 19:58:33 nit: In codereview these indents look different fr
alexeypa (please no reviews) 2013/04/08 23:28:17 They don't have to be the same. There is additiona
91 ui_task_runner_, // Input 91 task_runner_, // Input
92 ui_task_runner_, // Video capture 92 task_runner_, // Video capture
93 ui_task_runner_, // Video encode 93 task_runner_, // Video encode
94 ui_task_runner_, // Network 94 task_runner_, // Network
95 ui_task_runner_); // UI 95 task_runner_)); // UI
96 host_->AddStatusObserver(&host_status_observer_); 96 host_->AddStatusObserver(&host_status_observer_);
97 97
98 xmpp_login_ = "host@domain"; 98 xmpp_login_ = "host@domain";
99 session1_ = new MockSession(); 99 session1_ = new MockSession();
100 session2_ = new MockSession(); 100 session2_ = new MockSession();
101 session_unowned1_.reset(new MockSession()); 101 session_unowned1_.reset(new MockSession());
102 session_unowned2_.reset(new MockSession()); 102 session_unowned2_.reset(new MockSession());
103 session_config1_ = SessionConfig::ForTest(); 103 session_config1_ = SessionConfig::ForTest();
104 session_jid1_ = "user@domain/rest-of-jid"; 104 session_jid1_ = "user@domain/rest-of-jid";
105 session_config2_ = SessionConfig::ForTest(); 105 session_config2_ = SessionConfig::ForTest();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 // Helper method to pretend a client is connected to ChromotingHost. 176 // Helper method to pretend a client is connected to ChromotingHost.
177 void SimulateClientConnection(int connection_index, bool authenticate, 177 void SimulateClientConnection(int connection_index, bool authenticate,
178 bool reject) { 178 bool reject) {
179 scoped_ptr<protocol::ConnectionToClient> connection = 179 scoped_ptr<protocol::ConnectionToClient> connection =
180 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). 180 ((connection_index == 0) ? owned_connection1_ : owned_connection2_).
181 PassAs<protocol::ConnectionToClient>(); 181 PassAs<protocol::ConnectionToClient>();
182 protocol::ConnectionToClient* connection_ptr = connection.get(); 182 protocol::ConnectionToClient* connection_ptr = connection.get();
183 scoped_ptr<ClientSession> client(new ClientSession( 183 scoped_ptr<ClientSession> client(new ClientSession(
184 host_.get(), 184 host_.get(),
185 ui_task_runner_, // Audio 185 task_runner_, // Audio
186 ui_task_runner_, // Input 186 task_runner_, // Input
187 ui_task_runner_, // Video capture 187 task_runner_, // Video capture
188 ui_task_runner_, // Video encode 188 task_runner_, // Video encode
189 ui_task_runner_, // Network 189 task_runner_, // Network
190 ui_task_runner_, // UI 190 task_runner_, // UI
191 connection.Pass(), 191 connection.Pass(),
192 desktop_environment_factory_.get(), 192 desktop_environment_factory_.get(),
193 base::TimeDelta())); 193 base::TimeDelta()));
194 194
195 ClientSession* client_raw = client.get(); 195 connection_ptr->set_host_stub(client.get());
196 connection_ptr->set_host_stub(client_raw);
197
198 ui_task_runner_->PostTask(
199 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost,
200 host_, base::Passed(&client)));
201 196
202 if (authenticate) { 197 if (authenticate) {
203 ui_task_runner_->PostTask( 198 task_runner_->PostTask(
204 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated, 199 FROM_HERE,
205 base::Unretained(client_raw), connection_ptr)); 200 base::Bind(&ClientSession::OnConnectionAuthenticated,
201 base::Unretained(client.get()), connection_ptr));
206 if (!reject) { 202 if (!reject) {
207 ui_task_runner_->PostTask( 203 task_runner_->PostTask(
208 FROM_HERE, 204 FROM_HERE,
209 base::Bind(&ClientSession::OnConnectionChannelsConnected, 205 base::Bind(&ClientSession::OnConnectionChannelsConnected,
210 base::Unretained(client_raw), connection_ptr)); 206 base::Unretained(client.get()), connection_ptr));
211 } 207 }
212 } else { 208 } else {
213 ui_task_runner_->PostTask( 209 task_runner_->PostTask(
214 FROM_HERE, base::Bind(&ClientSession::OnConnectionClosed, 210 FROM_HERE, base::Bind(&ClientSession::OnConnectionClosed,
215 base::Unretained(client_raw), connection_ptr, 211 base::Unretained(client.get()), connection_ptr,
216 protocol::AUTHENTICATION_FAILED)); 212 protocol::AUTHENTICATION_FAILED));
217 } 213 }
218 214
219 get_client(connection_index) = client_raw; 215 get_client(connection_index) = client.get();
Wez 2013/04/02 19:58:33 Ick. Assigning to a getter doesn't seem right...
alexeypa (please no reviews) 2013/04/08 23:28:17 Let's fix it in a separate CL.
216
217 // |host| is responsible for deleting |client| from now on.
218 host_->clients_.push_back(client.release());
220 } 219 }
221 220
222 virtual void TearDown() OVERRIDE { 221 virtual void TearDown() OVERRIDE {
223 // Make sure that the host has been properly deleted. 222 // Make sure that the host has been properly deleted.
224 DCHECK(host_.get() == NULL); 223 DCHECK(host_.get() == NULL);
225 } 224 }
226 225
227 // Change the session route for |client1_|. 226 // Change the session route for |client1_|.
228 void ChangeSessionRoute(const std::string& channel_name, 227 void ChangeSessionRoute(const std::string& channel_name,
229 const protocol::TransportRoute& route) { 228 const protocol::TransportRoute& route) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 void SetEventHandler(protocol::Session::EventHandler* event_handler) { 284 void SetEventHandler(protocol::Session::EventHandler* event_handler) {
286 session_event_handler_ = event_handler; 285 session_event_handler_ = event_handler;
287 } 286 }
288 287
289 void NotifyConnectionClosed() { 288 void NotifyConnectionClosed() {
290 if (session_event_handler_) { 289 if (session_event_handler_) {
291 session_event_handler_->OnSessionStateChange(protocol::Session::CLOSED); 290 session_event_handler_->OnSessionStateChange(protocol::Session::CLOSED);
292 } 291 }
293 } 292 }
294 293
295 static void AddClientToHost(scoped_refptr<ChromotingHost> host, 294 void ShutdownHost() {
296 scoped_ptr<ClientSession> client) { 295 task_runner_->PostTask(
297 // |host| is responsible for deleting |client| from now on. 296 FROM_HERE,
298 host->clients_.push_back(client.release()); 297 base::Bind(&ChromotingHostTest::ShutdownAndReleaseTaskRunner,
298 base::Unretained(this)));
299 } 299 }
300 300
301 void ShutdownHost() { 301 void ShutdownAndReleaseTaskRunner() {
302 ui_task_runner_->PostTask( 302 host_->Shutdown();
303 FROM_HERE, 303 host_.reset();
304 base::Bind(&ChromotingHost::Shutdown, host_,
305 base::Bind(&ChromotingHostTest::ReleaseUiTaskRunner,
306 base::Unretained(this))));
307 }
308 304
309 void ReleaseUiTaskRunner() { 305 task_runner_ = NULL;
310 ui_task_runner_ = NULL;
311 host_ = NULL;
312 desktop_environment_factory_.reset(); 306 desktop_environment_factory_.reset();
313 } 307 }
314 308
315 void QuitMainMessageLoop() { 309 void QuitMainMessageLoop() {
316 PostQuitTask(&message_loop_); 310 PostQuitTask(&message_loop_);
317 } 311 }
318 312
319 // Expect the host and session manager to start, and return the expectation 313 // Expect the host and session manager to start, and return the expectation
320 // that the session manager has started. 314 // that the session manager has started.
321 Expectation ExpectHostAndSessionManagerStart() { 315 Expectation ExpectHostAndSessionManagerStart() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 if (expect_host_status_change) { 381 if (expect_host_status_change) {
388 EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid)) 382 EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid))
389 .After(after) 383 .After(after)
390 .WillOnce(action) 384 .WillOnce(action)
391 .RetiresOnSaturation(); 385 .RetiresOnSaturation();
392 } 386 }
393 } 387 }
394 388
395 protected: 389 protected:
396 MessageLoop message_loop_; 390 MessageLoop message_loop_;
397 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; 391 scoped_refptr<AutoThreadTaskRunner> task_runner_;
398 MockConnectionToClientEventHandler handler_; 392 MockConnectionToClientEventHandler handler_;
399 MockSignalStrategy signal_strategy_; 393 MockSignalStrategy signal_strategy_;
400 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; 394 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_;
401 scoped_refptr<ChromotingHost> host_; 395 scoped_ptr<ChromotingHost> host_;
402 MockHostStatusObserver host_status_observer_; 396 MockHostStatusObserver host_status_observer_;
403 protocol::MockSessionManager* session_manager_; 397 protocol::MockSessionManager* session_manager_;
404 std::string xmpp_login_; 398 std::string xmpp_login_;
405 MockConnectionToClient* connection1_; 399 MockConnectionToClient* connection1_;
406 scoped_ptr<MockConnectionToClient> owned_connection1_; 400 scoped_ptr<MockConnectionToClient> owned_connection1_;
407 ClientSession* client1_; 401 ClientSession* client1_;
408 std::string session_jid1_; 402 std::string session_jid1_;
409 MockSession* session1_; // Owned by |connection_|. 403 MockSession* session1_; // Owned by |connection_|.
410 SessionConfig session_config1_; 404 SessionConfig session_config1_;
411 MockVideoStub video_stub1_; 405 MockVideoStub video_stub1_;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 ExpectClientDisconnected(0, true, video_packet_sent, 642 ExpectClientDisconnected(0, true, video_packet_sent,
649 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 643 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
650 EXPECT_CALL(host_status_observer_, OnShutdown()); 644 EXPECT_CALL(host_status_observer_, OnShutdown());
651 645
652 host_->Start(xmpp_login_); 646 host_->Start(xmpp_login_);
653 SimulateClientConnection(0, true, false); 647 SimulateClientConnection(0, true, false);
654 message_loop_.Run(); 648 message_loop_.Run();
655 } 649 }
656 650
657 } // namespace remoting 651 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698