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

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

Issue 8495024: Access ChromotingHost::clients_ only on network thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 1 month 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
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/client_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop_proxy.h" 7 #include "base/message_loop_proxy.h"
8 #include "base/task.h" 8 #include "base/task.h"
9 #include "remoting/host/capturer_fake.h" 9 #include "remoting/host/capturer_fake.h"
10 #include "remoting/host/chromoting_host.h" 10 #include "remoting/host/chromoting_host.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 .Times(AnyNumber()); 149 .Times(AnyNumber());
150 EXPECT_CALL(*connection2_.get(), video_stub()) 150 EXPECT_CALL(*connection2_.get(), video_stub())
151 .Times(AnyNumber()); 151 .Times(AnyNumber());
152 EXPECT_CALL(*connection2_.get(), client_stub()) 152 EXPECT_CALL(*connection2_.get(), client_stub())
153 .Times(AnyNumber()); 153 .Times(AnyNumber());
154 EXPECT_CALL(*connection2_.get(), session()) 154 EXPECT_CALL(*connection2_.get(), session())
155 .Times(AnyNumber()); 155 .Times(AnyNumber());
156 } 156 }
157 157
158 virtual void TearDown() OVERRIDE { 158 virtual void TearDown() OVERRIDE {
159 connection_ = NULL;
160 client_ = NULL;
161 connection2_ = NULL;
162 client2_ = NULL;
163 host_ = NULL;
159 message_loop_.RunAllPending(); 164 message_loop_.RunAllPending();
160 } 165 }
161 166
162 // Helper method to pretend a client is connected to ChromotingHost. 167 // Helper method to pretend a client is connected to ChromotingHost.
163 void SimulateClientConnection(int connection_index, bool authenticate) { 168 void SimulateClientConnection(int connection_index, bool authenticate) {
164 scoped_refptr<protocol::ConnectionToClient> connection = 169 scoped_refptr<protocol::ConnectionToClient> connection =
165 (connection_index == 0) ? connection_ : connection2_; 170 (connection_index == 0) ? connection_ : connection2_;
166 scoped_refptr<ClientSession> client = new ClientSession( 171 scoped_refptr<ClientSession> client = new ClientSession(
167 host_.get(), 172 host_.get(),
168 connection, 173 connection,
(...skipping 12 matching lines...) Expand all
181 186
182 if (connection_index == 0) { 187 if (connection_index == 0) {
183 client_ = client; 188 client_ = client;
184 } else { 189 } else {
185 client2_ = client; 190 client2_ = client;
186 } 191 }
187 } 192 }
188 193
189 // Helper method to remove a client connection from ChromotingHost. 194 // Helper method to remove a client connection from ChromotingHost.
190 void RemoveClientSession() { 195 void RemoveClientSession() {
191 context_.network_message_loop()->PostTask( 196 client_->OnConnectionClosed(connection_);
192 FROM_HERE, base::Bind(
193 &ClientSession::OnConnectionClosed, client_, connection_));
194 } 197 }
195 198
196 static void AddClientToHost(scoped_refptr<ChromotingHost> host, 199 static void AddClientToHost(scoped_refptr<ChromotingHost> host,
197 scoped_refptr<ClientSession> session) { 200 scoped_refptr<ClientSession> session) {
198 host->clients_.push_back(session); 201 host->clients_.push_back(session);
199 } 202 }
200 203
201 void ShutdownHost() { 204 void ShutdownHost() {
202 host_->Shutdown(base::Bind(&PostQuitTask, &message_loop_)); 205 message_loop_.PostTask(
206 FROM_HERE, base::Bind(&ChromotingHost::Shutdown, host_,
207 base::Bind(&PostQuitTask, &message_loop_)));
203 } 208 }
204 209
205 protected: 210 protected:
206 MessageLoop message_loop_; 211 MessageLoop message_loop_;
207 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 212 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
208 MockConnectionToClientEventHandler handler_; 213 MockConnectionToClientEventHandler handler_;
209 scoped_ptr<DesktopEnvironment> desktop_environment_; 214 scoped_ptr<DesktopEnvironment> desktop_environment_;
210 scoped_refptr<ChromotingHost> host_; 215 scoped_refptr<ChromotingHost> host_;
211 scoped_refptr<InMemoryHostConfig> config_; 216 scoped_refptr<InMemoryHostConfig> config_;
212 MockChromotingHostContext context_; 217 MockChromotingHostContext context_;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 379
375 TEST_F(ChromotingHostTest, CurtainModeFail) { 380 TEST_F(ChromotingHostTest, CurtainModeFail) {
376 host_->Start(); 381 host_->Start();
377 382
378 // Ensure that curtain mode is not activated if a connection does not 383 // Ensure that curtain mode is not activated if a connection does not
379 // authenticate. 384 // authenticate.
380 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) 385 EXPECT_CALL(*curtain_, EnableCurtainMode(_))
381 .Times(0); 386 .Times(0);
382 EXPECT_CALL(*disconnect_window_, Show(_, _)) 387 EXPECT_CALL(*disconnect_window_, Show(_, _))
383 .Times(0); 388 .Times(0);
384 EXPECT_CALL(*connection_.get(), Disconnect()) 389 EXPECT_CALL(*continue_window_, Hide())
385 .WillOnce(QuitMainMessageLoop(&message_loop_)); 390 .Times(AnyNumber());
391 EXPECT_CALL(*disconnect_window_, Hide())
392 .Times(AnyNumber());
386 SimulateClientConnection(0, false); 393 SimulateClientConnection(0, false);
387 RemoveClientSession(); 394 context_.network_message_loop()->PostTask(
395 FROM_HERE, base::Bind(&ChromotingHostTest::RemoveClientSession,
396 base::Unretained(this)));
397 PostQuitTask(&message_loop_);
388 message_loop_.Run(); 398 message_loop_.Run();
389 } 399 }
390 400
391 TEST_F(ChromotingHostTest, CurtainModeFailSecond) { 401 TEST_F(ChromotingHostTest, CurtainModeFailSecond) {
392 host_->Start(); 402 host_->Start();
393 403
394 // When a video packet is received we connect the second mock 404 // When a video packet is received we connect the second mock
395 // connection. 405 // connection.
396 { 406 {
397 InSequence s; 407 InSequence s;
398 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) 408 EXPECT_CALL(*curtain_, EnableCurtainMode(true))
399 .WillOnce(QuitMainMessageLoop(&message_loop_)); 409 .WillOnce(QuitMainMessageLoop(&message_loop_));
400 EXPECT_CALL(*disconnect_window_, Show(_, _)) 410 EXPECT_CALL(*local_input_monitor_, Start(_))
401 .Times(0); 411 .Times(1);
412 EXPECT_CALL(*disconnect_window_, Show(_, "user@domain"))
413 .Times(1);
402 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 414 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
403 .WillOnce(DoAll( 415 .WillOnce(DoAll(
404 InvokeWithoutArgs( 416 InvokeWithoutArgs(
405 CreateFunctor( 417 CreateFunctor(
406 this, 418 this,
407 &ChromotingHostTest::SimulateClientConnection, 1, false)), 419 &ChromotingHostTest::SimulateClientConnection, 1, false)),
408 RunDoneTask())) 420 RunDoneTask()))
409 .RetiresOnSaturation(); 421 .RetiresOnSaturation();
410 // Check that the second connection does not affect curtain mode. 422 // Check that the second connection does not affect curtain mode.
411 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) 423 EXPECT_CALL(*curtain_, EnableCurtainMode(_))
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 .Times(1) 457 .Times(1)
446 .InSequence(s2); 458 .InSequence(s2);
447 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 459 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
448 .InSequence(s1, s2) 460 .InSequence(s1, s2)
449 .WillOnce(DoAll( 461 .WillOnce(DoAll(
450 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost), 462 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost),
451 RunDoneTask())) 463 RunDoneTask()))
452 .RetiresOnSaturation(); 464 .RetiresOnSaturation();
453 EXPECT_CALL(*connection_.get(), Disconnect()) 465 EXPECT_CALL(*connection_.get(), Disconnect())
454 .InSequence(s1, s2) 466 .InSequence(s1, s2)
467 .WillOnce(InvokeWithoutArgs(
468 this, &ChromotingHostTest::RemoveClientSession))
455 .RetiresOnSaturation(); 469 .RetiresOnSaturation();
456 EXPECT_CALL(*local_input_monitor_, Stop()) 470 EXPECT_CALL(*local_input_monitor_, Stop())
457 .Times(1) 471 .Times(1)
458 .InSequence(s1, s2); 472 .InSequence(s1, s2);
459 EXPECT_CALL(*continue_window_, Hide()) 473 EXPECT_CALL(*continue_window_, Hide())
460 .Times(1) 474 .Times(1)
461 .InSequence(s1); 475 .InSequence(s1);
462 EXPECT_CALL(*disconnect_window_, Hide()) 476 EXPECT_CALL(*disconnect_window_, Hide())
463 .Times(1) 477 .Times(1)
464 .InSequence(s2); 478 .InSequence(s2);
465 } 479 }
466 SimulateClientConnection(0, true); 480 SimulateClientConnection(0, true);
467 message_loop_.Run(); 481 message_loop_.Run();
468 host_->set_it2me(false); 482 host_->set_it2me(false);
469 EXPECT_THAT(curtain_activated, false); 483 EXPECT_THAT(curtain_activated, false);
470 } 484 }
471 485
472 } // namespace remoting 486 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/client_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698