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

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

Issue 10915264: [remoting_unittests] Moving the variable used to mock VideoFrameCapturer::size_most_recent() to the… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
« no previous file with comments | « no previous file | remoting/host/client_session_unittest.cc » ('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) 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/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 "remoting/base/auto_thread_task_runner.h" 8 #include "remoting/base/auto_thread_task_runner.h"
9 #include "remoting/jingle_glue/mock_objects.h" 9 #include "remoting/jingle_glue/mock_objects.h"
10 #include "remoting/host/audio_capturer.h" 10 #include "remoting/host/audio_capturer.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 .Times(AnyNumber()); 208 .Times(AnyNumber());
209 EXPECT_CALL(*connection2_, session()) 209 EXPECT_CALL(*connection2_, session())
210 .Times(AnyNumber()); 210 .Times(AnyNumber());
211 211
212 empty_candidate_config_ = 212 empty_candidate_config_ =
213 protocol::CandidateSessionConfig::CreateEmpty(); 213 protocol::CandidateSessionConfig::CreateEmpty();
214 default_candidate_config_ = 214 default_candidate_config_ =
215 protocol::CandidateSessionConfig::CreateDefault(); 215 protocol::CandidateSessionConfig::CreateDefault();
216 } 216 }
217 217
218 virtual void TearDown() OVERRIDE {
219 // Run the message loop to finish outstanding tasks.
220 message_loop_.Run();
simonmorris 2012/09/13 16:51:40 I'm not convinced the benefits of this exceed the
alexeypa (please no reviews) 2012/09/13 18:06:17 Done.
221 }
222
218 // Helper method to pretend a client is connected to ChromotingHost. 223 // Helper method to pretend a client is connected to ChromotingHost.
219 void SimulateClientConnection(int connection_index, bool authenticate, 224 void SimulateClientConnection(int connection_index, bool authenticate,
220 bool reject) { 225 bool reject) {
221 scoped_ptr<protocol::ConnectionToClient> connection = 226 scoped_ptr<protocol::ConnectionToClient> connection =
222 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). 227 ((connection_index == 0) ? owned_connection1_ : owned_connection2_).
223 PassAs<protocol::ConnectionToClient>(); 228 PassAs<protocol::ConnectionToClient>();
224 protocol::ConnectionToClient* connection_ptr = connection.get(); 229 protocol::ConnectionToClient* connection_ptr = connection.get();
225 scoped_ptr<DesktopEnvironment> desktop_environment = 230 scoped_ptr<DesktopEnvironment> desktop_environment =
226 host_->desktop_environment_factory_->Create(&context_); 231 host_->desktop_environment_factory_->Create(&context_);
227 connection_ptr->set_input_stub(desktop_environment->event_executor()); 232 connection_ptr->set_input_stub(desktop_environment->event_executor());
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 return (connection_index == 0) ? video_stub1_ : video_stub2_; 468 return (connection_index == 0) ? video_stub1_ : video_stub2_;
464 } 469 }
465 }; 470 };
466 471
467 TEST_F(ChromotingHostTest, StartAndShutdown) { 472 TEST_F(ChromotingHostTest, StartAndShutdown) {
468 Expectation start = ExpectHostAndSessionManagerStart(); 473 Expectation start = ExpectHostAndSessionManagerStart();
469 EXPECT_CALL(host_status_observer_, OnShutdown()).After(start); 474 EXPECT_CALL(host_status_observer_, OnShutdown()).After(start);
470 475
471 host_->Start(xmpp_login_); 476 host_->Start(xmpp_login_);
472 ShutdownHost(); 477 ShutdownHost();
473 message_loop_.Run();
474 } 478 }
475 479
476 TEST_F(ChromotingHostTest, Connect) { 480 TEST_F(ChromotingHostTest, Connect) {
477 ExpectHostAndSessionManagerStart(); 481 ExpectHostAndSessionManagerStart();
478 482
479 // Shut down the host when the first video packet is received. 483 // Shut down the host when the first video packet is received.
480 Expectation video_packet_sent = ExpectClientConnected( 484 Expectation video_packet_sent = ExpectClientConnected(
481 0, InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 485 0, InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
482 Expectation client_disconnected = ExpectClientDisconnected( 486 Expectation client_disconnected = ExpectClientDisconnected(
483 0, true, video_packet_sent, InvokeWithoutArgs(DoNothing)); 487 0, true, video_packet_sent, InvokeWithoutArgs(DoNothing));
484 EXPECT_CALL(host_status_observer_, OnShutdown()).After(client_disconnected); 488 EXPECT_CALL(host_status_observer_, OnShutdown()).After(client_disconnected);
485 489
486 host_->Start(xmpp_login_); 490 host_->Start(xmpp_login_);
487 SimulateClientConnection(0, true, false); 491 SimulateClientConnection(0, true, false);
488 message_loop_.Run();
489 } 492 }
490 493
491 TEST_F(ChromotingHostTest, RejectAuthenticatingClient) { 494 TEST_F(ChromotingHostTest, RejectAuthenticatingClient) {
492 Expectation start = ExpectHostAndSessionManagerStart(); 495 Expectation start = ExpectHostAndSessionManagerStart();
493 EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid1_)) 496 EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid1_))
494 .WillOnce(InvokeWithoutArgs( 497 .WillOnce(InvokeWithoutArgs(
495 this, &ChromotingHostTest::RejectAuthenticatingClient)); 498 this, &ChromotingHostTest::RejectAuthenticatingClient));
496 ExpectClientDisconnected( 499 ExpectClientDisconnected(
497 0, true, start, 500 0, true, start,
498 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 501 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
499 EXPECT_CALL(host_status_observer_, OnShutdown()); 502 EXPECT_CALL(host_status_observer_, OnShutdown());
500 503
501 host_->Start(xmpp_login_); 504 host_->Start(xmpp_login_);
502 SimulateClientConnection(0, true, true); 505 SimulateClientConnection(0, true, true);
503 message_loop_.Run();
504 } 506 }
505 507
506 TEST_F(ChromotingHostTest, AuthenticationFailed) { 508 TEST_F(ChromotingHostTest, AuthenticationFailed) {
507 ExpectHostAndSessionManagerStart(); 509 ExpectHostAndSessionManagerStart();
508 EXPECT_CALL(host_status_observer_, OnAccessDenied(session_jid1_)) 510 EXPECT_CALL(host_status_observer_, OnAccessDenied(session_jid1_))
509 .WillOnce(InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 511 .WillOnce(InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
510 EXPECT_CALL(host_status_observer_, OnShutdown()); 512 EXPECT_CALL(host_status_observer_, OnShutdown());
511 513
512 host_->Start(xmpp_login_); 514 host_->Start(xmpp_login_);
513 SimulateClientConnection(0, false, false); 515 SimulateClientConnection(0, false, false);
514 message_loop_.Run();
515 } 516 }
516 517
517 TEST_F(ChromotingHostTest, Reconnect) { 518 TEST_F(ChromotingHostTest, Reconnect) {
518 ExpectHostAndSessionManagerStart(); 519 ExpectHostAndSessionManagerStart();
519 520
520 // When a video packet is received on the first connection, disconnect it, 521 // When a video packet is received on the first connection, disconnect it,
521 // then quit the message loop. 522 // then quit the message loop.
522 Expectation video_packet_sent1 = ExpectClientConnected(0, DoAll( 523 Expectation video_packet_sent1 = ExpectClientConnected(0, DoAll(
523 InvokeWithoutArgs(this, &ChromotingHostTest::DisconnectClient1), 524 InvokeWithoutArgs(this, &ChromotingHostTest::DisconnectClient1),
524 InvokeWithoutArgs(this, &ChromotingHostTest::QuitMainMessageLoop))); 525 InvokeWithoutArgs(this, &ChromotingHostTest::QuitMainMessageLoop)));
525 ExpectClientDisconnectEffects( 526 ExpectClientDisconnectEffects(
526 0, true, video_packet_sent1, InvokeWithoutArgs(DoNothing)); 527 0, true, video_packet_sent1, InvokeWithoutArgs(DoNothing));
527 528
528 // When a video packet is received on the second connection, shut down the 529 // When a video packet is received on the second connection, shut down the
529 // host. 530 // host.
530 Expectation video_packet_sent2 = ExpectClientConnected( 531 Expectation video_packet_sent2 = ExpectClientConnected(
531 1, InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 532 1, InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
532 Expectation client_disconnected2 = ExpectClientDisconnected( 533 Expectation client_disconnected2 = ExpectClientDisconnected(
533 1, true, video_packet_sent2, InvokeWithoutArgs(DoNothing)); 534 1, true, video_packet_sent2, InvokeWithoutArgs(DoNothing));
534 EXPECT_CALL(host_status_observer_, OnShutdown()).After(client_disconnected2); 535 EXPECT_CALL(host_status_observer_, OnShutdown()).After(client_disconnected2);
535 536
536 host_->Start(xmpp_login_); 537 host_->Start(xmpp_login_);
537 SimulateClientConnection(0, true, false); 538 SimulateClientConnection(0, true, false);
538 message_loop_.Run(); 539 message_loop_.Run();
539 SimulateClientConnection(1, true, false); 540 SimulateClientConnection(1, true, false);
540 message_loop_.Run();
541 } 541 }
542 542
543 TEST_F(ChromotingHostTest, ConnectWhenAnotherClientIsConnected) { 543 TEST_F(ChromotingHostTest, ConnectWhenAnotherClientIsConnected) {
544 ExpectHostAndSessionManagerStart(); 544 ExpectHostAndSessionManagerStart();
545 545
546 // When a video packet is received, connect the second connection. 546 // When a video packet is received, connect the second connection.
547 // This should disconnect the first connection. 547 // This should disconnect the first connection.
548 Expectation video_packet_sent1 = ExpectClientConnected( 548 Expectation video_packet_sent1 = ExpectClientConnected(
549 0, 549 0,
550 InvokeWithoutArgs( 550 InvokeWithoutArgs(
551 CreateFunctor( 551 CreateFunctor(
552 this, 552 this,
553 &ChromotingHostTest::SimulateClientConnection, 1, true, false))); 553 &ChromotingHostTest::SimulateClientConnection, 1, true, false)));
554 ExpectClientDisconnected( 554 ExpectClientDisconnected(
555 0, true, video_packet_sent1, InvokeWithoutArgs(DoNothing)); 555 0, true, video_packet_sent1, InvokeWithoutArgs(DoNothing));
556 Expectation video_packet_sent2 = ExpectClientConnected( 556 Expectation video_packet_sent2 = ExpectClientConnected(
557 1, InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 557 1, InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
558 Expectation client_disconnected2 = ExpectClientDisconnected( 558 Expectation client_disconnected2 = ExpectClientDisconnected(
559 1, true, video_packet_sent2, InvokeWithoutArgs(DoNothing)); 559 1, true, video_packet_sent2, InvokeWithoutArgs(DoNothing));
560 EXPECT_CALL(host_status_observer_, OnShutdown()).After(client_disconnected2); 560 EXPECT_CALL(host_status_observer_, OnShutdown()).After(client_disconnected2);
561 561
562 host_->Start(xmpp_login_); 562 host_->Start(xmpp_login_);
563 SimulateClientConnection(0, true, false); 563 SimulateClientConnection(0, true, false);
564 message_loop_.Run();
565 } 564 }
566 565
567 TEST_F(ChromotingHostTest, IncomingSessionDeclined) { 566 TEST_F(ChromotingHostTest, IncomingSessionDeclined) {
568 ExpectHostStart(); 567 ExpectHostStart();
569 protocol::SessionManager::IncomingSessionResponse response = 568 protocol::SessionManager::IncomingSessionResponse response =
570 protocol::SessionManager::ACCEPT; 569 protocol::SessionManager::ACCEPT;
571 host_->OnIncomingSession(session1_, &response); 570 host_->OnIncomingSession(session1_, &response);
572 EXPECT_EQ(protocol::SessionManager::DECLINE, response); 571 EXPECT_EQ(protocol::SessionManager::DECLINE, response);
573 572
574 ShutdownHost(); 573 ShutdownHost();
575 message_loop_.Run();
576 } 574 }
577 575
578 TEST_F(ChromotingHostTest, IncomingSessionIncompatible) { 576 TEST_F(ChromotingHostTest, IncomingSessionIncompatible) {
579 ExpectHostAndSessionManagerStart(); 577 ExpectHostAndSessionManagerStart();
580 EXPECT_CALL(*session_unowned1_, candidate_config()).WillOnce(Return( 578 EXPECT_CALL(*session_unowned1_, candidate_config()).WillOnce(Return(
581 empty_candidate_config_.get())); 579 empty_candidate_config_.get()));
582 EXPECT_CALL(host_status_observer_, OnShutdown()); 580 EXPECT_CALL(host_status_observer_, OnShutdown());
583 581
584 host_->set_protocol_config( 582 host_->set_protocol_config(
585 protocol::CandidateSessionConfig::CreateDefault().release()); 583 protocol::CandidateSessionConfig::CreateDefault().release());
586 host_->Start(xmpp_login_); 584 host_->Start(xmpp_login_);
587 585
588 protocol::SessionManager::IncomingSessionResponse response = 586 protocol::SessionManager::IncomingSessionResponse response =
589 protocol::SessionManager::ACCEPT; 587 protocol::SessionManager::ACCEPT;
590 host_->OnIncomingSession(session_unowned1_.get(), &response); 588 host_->OnIncomingSession(session_unowned1_.get(), &response);
591 EXPECT_EQ(protocol::SessionManager::INCOMPATIBLE, response); 589 EXPECT_EQ(protocol::SessionManager::INCOMPATIBLE, response);
592 590
593 ShutdownHost(); 591 ShutdownHost();
594 message_loop_.Run();
595 } 592 }
596 593
597 TEST_F(ChromotingHostTest, IncomingSessionAccepted) { 594 TEST_F(ChromotingHostTest, IncomingSessionAccepted) {
598 ExpectHostAndSessionManagerStart(); 595 ExpectHostAndSessionManagerStart();
599 EXPECT_CALL(*session_unowned1_, candidate_config()).WillOnce(Return( 596 EXPECT_CALL(*session_unowned1_, candidate_config()).WillOnce(Return(
600 default_candidate_config_.get())); 597 default_candidate_config_.get()));
601 EXPECT_CALL(*session_unowned1_, set_config(_)); 598 EXPECT_CALL(*session_unowned1_, set_config(_));
602 EXPECT_CALL(*session_unowned1_, Close()).WillOnce(InvokeWithoutArgs( 599 EXPECT_CALL(*session_unowned1_, Close()).WillOnce(InvokeWithoutArgs(
603 this, &ChromotingHostTest::NotifyConnectionClosed)); 600 this, &ChromotingHostTest::NotifyConnectionClosed));
604 EXPECT_CALL(host_status_observer_, OnAccessDenied(_)); 601 EXPECT_CALL(host_status_observer_, OnAccessDenied(_));
605 EXPECT_CALL(host_status_observer_, OnShutdown()); 602 EXPECT_CALL(host_status_observer_, OnShutdown());
606 603
607 host_->set_protocol_config( 604 host_->set_protocol_config(
608 protocol::CandidateSessionConfig::CreateDefault().release()); 605 protocol::CandidateSessionConfig::CreateDefault().release());
609 host_->Start(xmpp_login_); 606 host_->Start(xmpp_login_);
610 607
611 protocol::SessionManager::IncomingSessionResponse response = 608 protocol::SessionManager::IncomingSessionResponse response =
612 protocol::SessionManager::DECLINE; 609 protocol::SessionManager::DECLINE;
613 host_->OnIncomingSession(session_unowned1_.release(), &response); 610 host_->OnIncomingSession(session_unowned1_.release(), &response);
614 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 611 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
615 612
616 ShutdownHost(); 613 ShutdownHost();
617 message_loop_.Run();
618 } 614 }
619 615
620 TEST_F(ChromotingHostTest, IncomingSessionOverload) { 616 TEST_F(ChromotingHostTest, IncomingSessionOverload) {
621 ExpectHostAndSessionManagerStart(); 617 ExpectHostAndSessionManagerStart();
622 EXPECT_CALL(*session_unowned1_, candidate_config()).WillOnce(Return( 618 EXPECT_CALL(*session_unowned1_, candidate_config()).WillOnce(Return(
623 default_candidate_config_.get())); 619 default_candidate_config_.get()));
624 EXPECT_CALL(*session_unowned1_, set_config(_)); 620 EXPECT_CALL(*session_unowned1_, set_config(_));
625 EXPECT_CALL(*session_unowned1_, Close()).WillOnce(InvokeWithoutArgs( 621 EXPECT_CALL(*session_unowned1_, Close()).WillOnce(InvokeWithoutArgs(
626 this, &ChromotingHostTest::NotifyConnectionClosed)); 622 this, &ChromotingHostTest::NotifyConnectionClosed));
627 EXPECT_CALL(host_status_observer_, OnAccessDenied(_)); 623 EXPECT_CALL(host_status_observer_, OnAccessDenied(_));
628 EXPECT_CALL(host_status_observer_, OnShutdown()); 624 EXPECT_CALL(host_status_observer_, OnShutdown());
629 625
630 host_->set_protocol_config( 626 host_->set_protocol_config(
631 protocol::CandidateSessionConfig::CreateDefault().release()); 627 protocol::CandidateSessionConfig::CreateDefault().release());
632 host_->Start(xmpp_login_); 628 host_->Start(xmpp_login_);
633 629
634 protocol::SessionManager::IncomingSessionResponse response = 630 protocol::SessionManager::IncomingSessionResponse response =
635 protocol::SessionManager::DECLINE; 631 protocol::SessionManager::DECLINE;
636 host_->OnIncomingSession(session_unowned1_.release(), &response); 632 host_->OnIncomingSession(session_unowned1_.release(), &response);
637 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 633 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
638 634
639 host_->OnIncomingSession(session_unowned2_.get(), &response); 635 host_->OnIncomingSession(session_unowned2_.get(), &response);
640 EXPECT_EQ(protocol::SessionManager::OVERLOAD, response); 636 EXPECT_EQ(protocol::SessionManager::OVERLOAD, response);
641 637
642 ShutdownHost(); 638 ShutdownHost();
643 message_loop_.Run();
644 } 639 }
645 640
646 TEST_F(ChromotingHostTest, OnSessionRouteChange) { 641 TEST_F(ChromotingHostTest, OnSessionRouteChange) {
647 std::string channel_name("ChannelName"); 642 std::string channel_name("ChannelName");
648 protocol::TransportRoute route; 643 protocol::TransportRoute route;
649 644
650 ExpectHostAndSessionManagerStart(); 645 ExpectHostAndSessionManagerStart();
651 Expectation video_packet_sent = ExpectClientConnected( 646 Expectation video_packet_sent = ExpectClientConnected(
652 0, InvokeWithoutArgs(CreateFunctor( 647 0, InvokeWithoutArgs(CreateFunctor(
653 this, &ChromotingHostTest::ChangeSessionRoute, channel_name, route))); 648 this, &ChromotingHostTest::ChangeSessionRoute, channel_name, route)));
654 Expectation route_change = 649 Expectation route_change =
655 EXPECT_CALL(host_status_observer_, OnClientRouteChange( 650 EXPECT_CALL(host_status_observer_, OnClientRouteChange(
656 session_jid1_, channel_name, _)) 651 session_jid1_, channel_name, _))
657 .After(video_packet_sent) 652 .After(video_packet_sent)
658 .WillOnce(InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 653 .WillOnce(InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
659 ExpectClientDisconnected(0, true, route_change, InvokeWithoutArgs(DoNothing)); 654 ExpectClientDisconnected(0, true, route_change, InvokeWithoutArgs(DoNothing));
660 EXPECT_CALL(host_status_observer_, OnShutdown()); 655 EXPECT_CALL(host_status_observer_, OnShutdown());
661 656
662 host_->Start(xmpp_login_); 657 host_->Start(xmpp_login_);
663 SimulateClientConnection(0, true, false); 658 SimulateClientConnection(0, true, false);
664 message_loop_.Run();
665 } 659 }
666 660
667 TEST_F(ChromotingHostTest, DisconnectAllClients) { 661 TEST_F(ChromotingHostTest, DisconnectAllClients) {
668 ExpectHostAndSessionManagerStart(); 662 ExpectHostAndSessionManagerStart();
669 Expectation video_packet_sent = ExpectClientConnected( 663 Expectation video_packet_sent = ExpectClientConnected(
670 0, InvokeWithoutArgs(this, &ChromotingHostTest::DisconnectAllClients)); 664 0, InvokeWithoutArgs(this, &ChromotingHostTest::DisconnectAllClients));
671 ExpectClientDisconnected(0, true, video_packet_sent, 665 ExpectClientDisconnected(0, true, video_packet_sent,
672 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 666 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
673 EXPECT_CALL(host_status_observer_, OnShutdown()); 667 EXPECT_CALL(host_status_observer_, OnShutdown());
674 668
675 host_->Start(xmpp_login_); 669 host_->Start(xmpp_login_);
676 SimulateClientConnection(0, true, false); 670 SimulateClientConnection(0, true, false);
677 message_loop_.Run();
678 } 671 }
679 672
680 } // namespace remoting 673 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/host/client_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698