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

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

Issue 8351084: Remove old Authentication code that we don't use or need. (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
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"
11 #include "remoting/host/chromoting_host_context.h" 11 #include "remoting/host/chromoting_host_context.h"
12 #include "remoting/host/host_mock_objects.h" 12 #include "remoting/host/host_mock_objects.h"
13 #include "remoting/host/in_memory_host_config.h" 13 #include "remoting/host/in_memory_host_config.h"
14 #include "remoting/proto/video.pb.h" 14 #include "remoting/proto/video.pb.h"
15 #include "remoting/protocol/protocol_mock_objects.h" 15 #include "remoting/protocol/protocol_mock_objects.h"
16 #include "remoting/protocol/session_config.h" 16 #include "remoting/protocol/session_config.h"
17 #include "testing/gmock_mutant.h" 17 #include "testing/gmock_mutant.h"
18 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 using ::remoting::protocol::LocalLoginCredentials;
22 using ::remoting::protocol::MockClientStub; 21 using ::remoting::protocol::MockClientStub;
23 using ::remoting::protocol::MockConnectionToClient; 22 using ::remoting::protocol::MockConnectionToClient;
24 using ::remoting::protocol::MockConnectionToClientEventHandler; 23 using ::remoting::protocol::MockConnectionToClientEventHandler;
25 using ::remoting::protocol::MockHostStub; 24 using ::remoting::protocol::MockHostStub;
26 using ::remoting::protocol::MockSession; 25 using ::remoting::protocol::MockSession;
27 using ::remoting::protocol::MockVideoStub; 26 using ::remoting::protocol::MockVideoStub;
28 using ::remoting::protocol::SessionConfig; 27 using ::remoting::protocol::SessionConfig;
29 28
30 using testing::_; 29 using testing::_;
31 using testing::AnyNumber; 30 using testing::AnyNumber;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 local_input_monitor_ = new MockLocalInputMonitor(); 94 local_input_monitor_ = new MockLocalInputMonitor();
96 desktop_environment_.reset( 95 desktop_environment_.reset(
97 new DesktopEnvironment(&context_, capturer, event_executor_, curtain_, 96 new DesktopEnvironment(&context_, capturer, event_executor_, curtain_,
98 disconnect_window_, continue_window_, 97 disconnect_window_, continue_window_,
99 local_input_monitor_)); 98 local_input_monitor_));
100 MockAccessVerifier* access_verifier = new MockAccessVerifier(); 99 MockAccessVerifier* access_verifier = new MockAccessVerifier();
101 100
102 host_ = ChromotingHost::Create(&context_, config_, 101 host_ = ChromotingHost::Create(&context_, config_,
103 desktop_environment_.get(), 102 desktop_environment_.get(),
104 access_verifier, false); 103 access_verifier, false);
105 credentials_.set_type(protocol::PASSWORD);
106 credentials_.set_username("user");
107 credentials_.set_credential("password");
108 connection_ = new MockConnectionToClient( 104 connection_ = new MockConnectionToClient(
109 &handler_, &host_stub_, event_executor_); 105 &handler_, &host_stub_, event_executor_);
110 connection2_ = new MockConnectionToClient( 106 connection2_ = new MockConnectionToClient(
111 &handler_, &host_stub2_, &event_executor2_); 107 &handler_, &host_stub2_, &event_executor2_);
112 session_.reset(new MockSession()); 108 session_.reset(new MockSession());
113 session2_.reset(new MockSession()); 109 session2_.reset(new MockSession());
114 session_config_ = SessionConfig::GetDefault(); 110 session_config_ = SessionConfig::GetDefault();
115 session_jid_ = "user@domain/rest-of-jid"; 111 session_jid_ = "user@domain/rest-of-jid";
116 session2_jid_ = "user2@domain/rest-of-jid"; 112 session2_jid_ = "user2@domain/rest-of-jid";
117 session_config2_ = SessionConfig::GetDefault(); 113 session_config2_ = SessionConfig::GetDefault();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 156
161 virtual void TearDown() OVERRIDE { 157 virtual void TearDown() OVERRIDE {
162 message_loop_.RunAllPending(); 158 message_loop_.RunAllPending();
163 } 159 }
164 160
165 // Helper method to pretend a client is connected to ChromotingHost. 161 // Helper method to pretend a client is connected to ChromotingHost.
166 void SimulateClientConnection(int connection_index, bool authenticate) { 162 void SimulateClientConnection(int connection_index, bool authenticate) {
167 scoped_refptr<MockConnectionToClient> connection = 163 scoped_refptr<MockConnectionToClient> connection =
168 (connection_index == 0) ? connection_ : connection2_; 164 (connection_index == 0) ? connection_ : connection2_;
169 165
170 MockUserAuthenticator *user_authenticator = new MockUserAuthenticator;
171 EXPECT_CALL(*user_authenticator, Authenticate(_, _))
172 .WillOnce(Return(authenticate));
173
174 scoped_refptr<ClientSession> client = new ClientSession( 166 scoped_refptr<ClientSession> client = new ClientSession(
175 host_.get(), 167 host_.get(),
176 user_authenticator,
177 connection, 168 connection,
178 event_executor_, 169 event_executor_,
179 desktop_environment_->capturer()); 170 desktop_environment_->capturer());
180 connection->set_host_stub(client.get()); 171 connection->set_host_stub(client.get());
181 172
182 context_.network_message_loop()->PostTask( 173 context_.network_message_loop()->PostTask(
183 FROM_HERE, 174 FROM_HERE,
184 NewRunnableFunction(&ChromotingHostTest::AddClientToHost, 175 NewRunnableFunction(&ChromotingHostTest::AddClientToHost,
185 host_, client)); 176 host_, client));
186 context_.network_message_loop()->PostTask( 177 if (authenticate) {
187 FROM_HERE, 178 context_.network_message_loop()->PostTask(
188 NewRunnableMethod(client.get(), 179 FROM_HERE,
189 &ClientSession::BeginSessionRequest, 180 NewRunnableMethod(client.get(),
190 &credentials_, 181 &ClientSession::OnAuthenticationComplete));
191 base::Bind(&DummyDoneTask))); 182 }
192 } 183 }
193 184
194 // Helper method to remove a client connection from ChromotingHost. 185 // Helper method to remove a client connection from ChromotingHost.
195 void RemoveClientConnection() { 186 void RemoveClientConnection() {
196 context_.network_message_loop()->PostTask( 187 context_.network_message_loop()->PostTask(
197 FROM_HERE, 188 FROM_HERE,
198 NewRunnableMethod(host_.get(), 189 NewRunnableMethod(host_.get(),
199 &ChromotingHost::OnClientDisconnected, 190 &ChromotingHost::OnClientDisconnected,
200 connection_)); 191 connection_));
201 } 192 }
202 193
203 static void AddClientToHost(scoped_refptr<ChromotingHost> host, 194 static void AddClientToHost(scoped_refptr<ChromotingHost> host,
204 scoped_refptr<ClientSession> session) { 195 scoped_refptr<ClientSession> session) {
205 host->clients_.push_back(session); 196 host->clients_.push_back(session);
206 } 197 }
207 198
208 void ShutdownHost() { 199 void ShutdownHost() {
209 host_->Shutdown( 200 host_->Shutdown(
210 NewRunnableFunction(&PostQuitTask, &message_loop_)); 201 NewRunnableFunction(&PostQuitTask, &message_loop_));
211 } 202 }
212 203
213 protected: 204 protected:
214 MessageLoop message_loop_; 205 MessageLoop message_loop_;
215 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 206 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
216 MockConnectionToClientEventHandler handler_; 207 MockConnectionToClientEventHandler handler_;
217 scoped_ptr<DesktopEnvironment> desktop_environment_; 208 scoped_ptr<DesktopEnvironment> desktop_environment_;
218 scoped_refptr<ChromotingHost> host_; 209 scoped_refptr<ChromotingHost> host_;
219 scoped_refptr<InMemoryHostConfig> config_; 210 scoped_refptr<InMemoryHostConfig> config_;
220 MockChromotingHostContext context_; 211 MockChromotingHostContext context_;
221 protocol::LocalLoginCredentials credentials_;
222 scoped_refptr<MockConnectionToClient> connection_; 212 scoped_refptr<MockConnectionToClient> connection_;
223 std::string session_jid_; 213 std::string session_jid_;
224 scoped_ptr<MockSession> session_; 214 scoped_ptr<MockSession> session_;
225 SessionConfig session_config_; 215 SessionConfig session_config_;
226 MockVideoStub video_stub_; 216 MockVideoStub video_stub_;
227 MockClientStub client_stub_; 217 MockClientStub client_stub_;
228 MockHostStub host_stub_; 218 MockHostStub host_stub_;
229 scoped_refptr<MockConnectionToClient> connection2_; 219 scoped_refptr<MockConnectionToClient> connection2_;
230 std::string session2_jid_; 220 std::string session2_jid_;
231 scoped_ptr<MockSession> session2_; 221 scoped_ptr<MockSession> session2_;
(...skipping 17 matching lines...) Expand all
249 message_loop_.PostTask( 239 message_loop_.PostTask(
250 FROM_HERE,NewRunnableMethod( 240 FROM_HERE,NewRunnableMethod(
251 host_.get(), &ChromotingHost::Shutdown, 241 host_.get(), &ChromotingHost::Shutdown,
252 NewRunnableFunction(&PostQuitTask, &message_loop_))); 242 NewRunnableFunction(&PostQuitTask, &message_loop_)));
253 message_loop_.Run(); 243 message_loop_.Run();
254 } 244 }
255 245
256 TEST_F(ChromotingHostTest, DISABLED_Connect) { 246 TEST_F(ChromotingHostTest, DISABLED_Connect) {
257 host_->Start(); 247 host_->Start();
258 248
259 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
260 .WillOnce(RunDoneTask());
261
262 // When the video packet is received we first shutdown ChromotingHost 249 // When the video packet is received we first shutdown ChromotingHost
263 // then execute the done task. 250 // then execute the done task.
264 { 251 {
265 InSequence s; 252 InSequence s;
266 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) 253 EXPECT_CALL(*curtain_, EnableCurtainMode(true))
267 .Times(1); 254 .Times(1);
268 EXPECT_CALL(*disconnect_window_, Show(_, _)) 255 EXPECT_CALL(*disconnect_window_, Show(_, _))
269 .Times(0); 256 .Times(0);
270 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 257 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
271 .WillOnce(DoAll( 258 .WillOnce(DoAll(
272 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost), 259 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost),
273 RunDoneTask())) 260 RunDoneTask()))
274 .RetiresOnSaturation(); 261 .RetiresOnSaturation();
275 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 262 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
276 .Times(AnyNumber()); 263 .Times(AnyNumber());
277 EXPECT_CALL(*connection_.get(), Disconnect()) 264 EXPECT_CALL(*connection_.get(), Disconnect())
278 .RetiresOnSaturation(); 265 .RetiresOnSaturation();
279 } 266 }
280 SimulateClientConnection(0, true); 267 SimulateClientConnection(0, true);
281 message_loop_.Run(); 268 message_loop_.Run();
282 } 269 }
283 270
284 TEST_F(ChromotingHostTest, DISABLED_Reconnect) { 271 TEST_F(ChromotingHostTest, DISABLED_Reconnect) {
285 host_->Start(); 272 host_->Start();
286 273
287 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
288 .Times(2)
289 .WillRepeatedly(RunDoneTask());
290
291 // When the video packet is received we first disconnect the mock 274 // When the video packet is received we first disconnect the mock
292 // connection. 275 // connection.
293 { 276 {
294 InSequence s; 277 InSequence s;
295 // Ensure that curtain mode is activated before the first video packet. 278 // Ensure that curtain mode is activated before the first video packet.
296 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) 279 EXPECT_CALL(*curtain_, EnableCurtainMode(true))
297 .Times(1); 280 .Times(1);
298 EXPECT_CALL(*disconnect_window_, Show(_, _)) 281 EXPECT_CALL(*disconnect_window_, Show(_, _))
299 .Times(0); 282 .Times(0);
300 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 283 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 EXPECT_CALL(*connection_.get(), Disconnect()) 321 EXPECT_CALL(*connection_.get(), Disconnect())
339 .RetiresOnSaturation(); 322 .RetiresOnSaturation();
340 323
341 SimulateClientConnection(0, true); 324 SimulateClientConnection(0, true);
342 message_loop_.Run(); 325 message_loop_.Run();
343 } 326 }
344 327
345 TEST_F(ChromotingHostTest, DISABLED_ConnectTwice) { 328 TEST_F(ChromotingHostTest, DISABLED_ConnectTwice) {
346 host_->Start(); 329 host_->Start();
347 330
348 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
349 .Times(1)
350 .WillRepeatedly(RunDoneTask());
351
352 EXPECT_CALL(client_stub2_, BeginSessionResponse(_, _))
353 .Times(1)
354 .WillRepeatedly(RunDoneTask());
355
356 // When a video packet is received we connect the second mock 331 // When a video packet is received we connect the second mock
357 // connection. 332 // connection.
358 { 333 {
359 InSequence s; 334 InSequence s;
360 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) 335 EXPECT_CALL(*curtain_, EnableCurtainMode(true))
361 .Times(1) 336 .Times(1)
362 .WillOnce(QuitMainMessageLoop(&message_loop_)); 337 .WillOnce(QuitMainMessageLoop(&message_loop_));
363 EXPECT_CALL(*disconnect_window_, Show(_, _)) 338 EXPECT_CALL(*disconnect_window_, Show(_, _))
364 .Times(0); 339 .Times(0);
365 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 340 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
(...skipping 25 matching lines...) Expand all
391 EXPECT_CALL(*connection2_.get(), Disconnect()) 366 EXPECT_CALL(*connection2_.get(), Disconnect())
392 .RetiresOnSaturation(); 367 .RetiresOnSaturation();
393 368
394 SimulateClientConnection(0, true); 369 SimulateClientConnection(0, true);
395 message_loop_.Run(); 370 message_loop_.Run();
396 } 371 }
397 372
398 TEST_F(ChromotingHostTest, CurtainModeFail) { 373 TEST_F(ChromotingHostTest, CurtainModeFail) {
399 host_->Start(); 374 host_->Start();
400 375
401 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
402 .WillOnce(RunDoneTask());
403
404 // Ensure that curtain mode is not activated if a connection does not 376 // Ensure that curtain mode is not activated if a connection does not
405 // authenticate. 377 // authenticate.
406 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) 378 EXPECT_CALL(*curtain_, EnableCurtainMode(_))
407 .Times(0); 379 .Times(0);
408 EXPECT_CALL(*disconnect_window_, Show(_, _)) 380 EXPECT_CALL(*disconnect_window_, Show(_, _))
409 .Times(0); 381 .Times(0);
410 EXPECT_CALL(*connection_.get(), Disconnect()) 382 EXPECT_CALL(*connection_.get(), Disconnect())
411 .WillOnce(QuitMainMessageLoop(&message_loop_)); 383 .WillOnce(QuitMainMessageLoop(&message_loop_));
412 SimulateClientConnection(0, false); 384 SimulateClientConnection(0, false);
413 RemoveClientConnection(); 385 RemoveClientConnection();
414 message_loop_.Run(); 386 message_loop_.Run();
415 } 387 }
416 388
417 TEST_F(ChromotingHostTest, CurtainModeFailSecond) { 389 TEST_F(ChromotingHostTest, CurtainModeFailSecond) {
418 host_->Start(); 390 host_->Start();
419 391
420 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
421 .WillOnce(RunDoneTask());
422
423 EXPECT_CALL(client_stub2_, BeginSessionResponse(_, _))
424 .WillOnce(RunDoneTask());
425
426
427 // When a video packet is received we connect the second mock 392 // When a video packet is received we connect the second mock
428 // connection. 393 // connection.
429 { 394 {
430 InSequence s; 395 InSequence s;
431 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) 396 EXPECT_CALL(*curtain_, EnableCurtainMode(true))
432 .WillOnce(QuitMainMessageLoop(&message_loop_)); 397 .WillOnce(QuitMainMessageLoop(&message_loop_));
433 EXPECT_CALL(*disconnect_window_, Show(_, _)) 398 EXPECT_CALL(*disconnect_window_, Show(_, _))
434 .Times(0); 399 .Times(0);
435 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 400 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
436 .WillOnce(DoAll( 401 .WillOnce(DoAll(
(...skipping 17 matching lines...) Expand all
454 SimulateClientConnection(0, true); 419 SimulateClientConnection(0, true);
455 message_loop_.Run(); 420 message_loop_.Run();
456 } 421 }
457 422
458 ACTION_P(SetBool, var) { *var = true; } 423 ACTION_P(SetBool, var) { *var = true; }
459 424
460 TEST_F(ChromotingHostTest, CurtainModeIT2Me) { 425 TEST_F(ChromotingHostTest, CurtainModeIT2Me) {
461 host_->Start(); 426 host_->Start();
462 host_->set_it2me(true); 427 host_->set_it2me(true);
463 428
464 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
465 .WillOnce(RunDoneTask());
466
467 // When the video packet is received we first shutdown ChromotingHost 429 // When the video packet is received we first shutdown ChromotingHost
468 // then execute the done task. 430 // then execute the done task.
469 bool curtain_activated = false; 431 bool curtain_activated = false;
470 { 432 {
471 Sequence s1, s2; 433 Sequence s1, s2;
472 // Can't just expect Times(0) because if it fails then the host will 434 // Can't just expect Times(0) because if it fails then the host will
473 // not be shut down and the message loop will never exit. 435 // not be shut down and the message loop will never exit.
474 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) 436 EXPECT_CALL(*curtain_, EnableCurtainMode(_))
475 .Times(AnyNumber()) 437 .Times(AnyNumber())
476 .WillRepeatedly(SetBool(&curtain_activated)); 438 .WillRepeatedly(SetBool(&curtain_activated));
477 EXPECT_CALL(*disconnect_window_, Show(_, "user@domain")) 439 EXPECT_CALL(*disconnect_window_, Show(_, "user@domain"))
478 .Times(1) 440 .Times(1)
479 .InSequence(s1); 441 .InSequence(s1);
480 EXPECT_CALL(*local_input_monitor_, Start(_)) 442 EXPECT_CALL(*local_input_monitor_, Start(_))
481 .Times(1) 443 .Times(1)
482 .InSequence(s2); 444 .InSequence(s2);
483 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 445 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
484 .InSequence(s1, s2) 446 .InSequence(s1, s2)
485 .WillOnce(DoAll( 447 .WillOnce(DoAll(
486 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost), 448 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost),
487 RunDoneTask())) 449 RunDoneTask()))
488 .RetiresOnSaturation(); 450 .RetiresOnSaturation();
489 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 451 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
490 .Times(AnyNumber()) 452 .Times(AnyNumber())
491 .InSequence(s1, s2); 453 .InSequence(s1, s2);
492 EXPECT_CALL(*connection_.get(), Disconnect()) 454 EXPECT_CALL(*connection_.get(), Disconnect())
493 .InSequence(s1, s2) 455 .InSequence(s1, s2)
494 .RetiresOnSaturation(); 456 .RetiresOnSaturation();
457 EXPECT_CALL(*local_input_monitor_, Stop())
458 .Times(1)
459 .InSequence(s1, s2);
460 EXPECT_CALL(*continue_window_, Hide())
461 .Times(1)
462 .InSequence(s1);
463 EXPECT_CALL(*disconnect_window_, Hide())
464 .Times(1)
465 .InSequence(s2);
495 } 466 }
496 SimulateClientConnection(0, true); 467 SimulateClientConnection(0, true);
497 message_loop_.Run(); 468 message_loop_.Run();
498 host_->set_it2me(false); 469 host_->set_it2me(false);
499 EXPECT_THAT(curtain_activated, false); 470 EXPECT_THAT(curtain_activated, false);
500 } 471 }
501 472
502 } // namespace remoting 473 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698