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

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

Issue 205583011: [Draft] Fix canceling pin prompt causes host overload (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Last round of feedbacks Created 6 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
« 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) 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/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "remoting/base/auto_thread_task_runner.h" 9 #include "remoting/base/auto_thread_task_runner.h"
10 #include "remoting/host/audio_capturer.h" 10 #include "remoting/host/audio_capturer.h"
(...skipping 10 matching lines...) Expand all
21 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gmock_mutant.h" 22 #include "testing/gmock_mutant.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 using ::remoting::protocol::MockClientStub; 25 using ::remoting::protocol::MockClientStub;
26 using ::remoting::protocol::MockConnectionToClient; 26 using ::remoting::protocol::MockConnectionToClient;
27 using ::remoting::protocol::MockConnectionToClientEventHandler; 27 using ::remoting::protocol::MockConnectionToClientEventHandler;
28 using ::remoting::protocol::MockHostStub; 28 using ::remoting::protocol::MockHostStub;
29 using ::remoting::protocol::MockSession; 29 using ::remoting::protocol::MockSession;
30 using ::remoting::protocol::MockVideoStub; 30 using ::remoting::protocol::MockVideoStub;
31 using ::remoting::protocol::Session;
31 using ::remoting::protocol::SessionConfig; 32 using ::remoting::protocol::SessionConfig;
32 33
33 using testing::_; 34 using testing::_;
34 using testing::AnyNumber; 35 using testing::AnyNumber;
36 using testing::AtLeast;
35 using testing::AtMost; 37 using testing::AtMost;
36 using testing::AtLeast;
37 using testing::CreateFunctor; 38 using testing::CreateFunctor;
38 using testing::DeleteArg; 39 using testing::DeleteArg;
39 using testing::DoAll; 40 using testing::DoAll;
40 using testing::Expectation; 41 using testing::Expectation;
41 using testing::InSequence; 42 using testing::InSequence;
42 using testing::Invoke; 43 using testing::Invoke;
43 using testing::InvokeArgument; 44 using testing::InvokeArgument;
44 using testing::InvokeWithoutArgs; 45 using testing::InvokeWithoutArgs;
45 using testing::Return; 46 using testing::Return;
46 using testing::ReturnRef; 47 using testing::ReturnRef;
48 using testing::SaveArg;
47 using testing::Sequence; 49 using testing::Sequence;
48 50
49 namespace remoting { 51 namespace remoting {
50 52
51 namespace { 53 namespace {
52 54
53 void PostQuitTask(base::MessageLoop* message_loop) { 55 void PostQuitTask(base::MessageLoop* message_loop) {
54 message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); 56 message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
55 } 57 }
56 58
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 EXPECT_CALL(*session_unowned1_, jid()) 119 EXPECT_CALL(*session_unowned1_, jid())
118 .WillRepeatedly(ReturnRef(session_unowned_jid1_)); 120 .WillRepeatedly(ReturnRef(session_unowned_jid1_));
119 EXPECT_CALL(*session_unowned2_, jid()) 121 EXPECT_CALL(*session_unowned2_, jid())
120 .WillRepeatedly(ReturnRef(session_unowned_jid2_)); 122 .WillRepeatedly(ReturnRef(session_unowned_jid2_));
121 EXPECT_CALL(*session1_, SetEventHandler(_)) 123 EXPECT_CALL(*session1_, SetEventHandler(_))
122 .Times(AnyNumber()); 124 .Times(AnyNumber());
123 EXPECT_CALL(*session2_, SetEventHandler(_)) 125 EXPECT_CALL(*session2_, SetEventHandler(_))
124 .Times(AnyNumber()); 126 .Times(AnyNumber());
125 EXPECT_CALL(*session_unowned1_, SetEventHandler(_)) 127 EXPECT_CALL(*session_unowned1_, SetEventHandler(_))
126 .Times(AnyNumber()) 128 .Times(AnyNumber())
127 .WillRepeatedly(Invoke(this, &ChromotingHostTest::SetEventHandler)); 129 .WillRepeatedly(SaveArg<0>(&session_unowned1_event_handler_));
128 EXPECT_CALL(*session_unowned2_, SetEventHandler(_)) 130 EXPECT_CALL(*session_unowned2_, SetEventHandler(_))
129 .Times(AnyNumber()); 131 .Times(AnyNumber())
132 .WillRepeatedly(SaveArg<0>(&session_unowned2_event_handler_));
130 EXPECT_CALL(*session1_, config()) 133 EXPECT_CALL(*session1_, config())
131 .WillRepeatedly(ReturnRef(session_config1_)); 134 .WillRepeatedly(ReturnRef(session_config1_));
132 EXPECT_CALL(*session2_, config()) 135 EXPECT_CALL(*session2_, config())
133 .WillRepeatedly(ReturnRef(session_config2_)); 136 .WillRepeatedly(ReturnRef(session_config2_));
134 137
135 owned_connection1_.reset(new MockConnectionToClient(session1_, 138 owned_connection1_.reset(new MockConnectionToClient(session1_,
136 &host_stub1_)); 139 &host_stub1_));
137 connection1_ = owned_connection1_.get(); 140 connection1_ = owned_connection1_.get();
138 owned_connection2_.reset(new MockConnectionToClient(session2_, 141 owned_connection2_.reset(new MockConnectionToClient(session2_,
139 &host_stub2_)); 142 &host_stub2_));
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 void RejectAuthenticatingClient() { 283 void RejectAuthenticatingClient() {
281 host_->RejectAuthenticatingClient(); 284 host_->RejectAuthenticatingClient();
282 } 285 }
283 286
284 // Notify |host_| that a client session has closed. 287 // Notify |host_| that a client session has closed.
285 void NotifyClientSessionClosed(int connection_index) { 288 void NotifyClientSessionClosed(int connection_index) {
286 get_client(connection_index)->OnConnectionClosed( 289 get_client(connection_index)->OnConnectionClosed(
287 get_connection(connection_index), protocol::OK); 290 get_connection(connection_index), protocol::OK);
288 } 291 }
289 292
290 void SetEventHandler(protocol::Session::EventHandler* event_handler) { 293 void NotifyConnectionClosed1() {
291 session_event_handler_ = event_handler; 294 if (session_unowned1_event_handler_) {
292 } 295 session_unowned1_event_handler_->OnSessionStateChange(Session::CLOSED);
293
294 void NotifyConnectionClosed() {
295 if (session_event_handler_) {
296 session_event_handler_->OnSessionStateChange(protocol::Session::CLOSED);
297 } 296 }
298 } 297 }
299 298
299 void NotifyConnectionClosed2() {
300 if (session_unowned2_event_handler_) {
301 session_unowned2_event_handler_->OnSessionStateChange(Session::CLOSED);
302 }
303 }
304
300 void ShutdownHost() { 305 void ShutdownHost() {
301 task_runner_->PostTask( 306 task_runner_->PostTask(
302 FROM_HERE, 307 FROM_HERE,
303 base::Bind(&ChromotingHostTest::StopAndReleaseTaskRunner, 308 base::Bind(&ChromotingHostTest::StopAndReleaseTaskRunner,
304 base::Unretained(this))); 309 base::Unretained(this)));
305 } 310 }
306 311
307 void StopAndReleaseTaskRunner() { 312 void StopAndReleaseTaskRunner() {
308 host_.reset(); 313 host_.reset();
309 task_runner_ = NULL; 314 task_runner_ = NULL;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 SessionConfig session_config2_; 422 SessionConfig session_config2_;
418 MockVideoStub video_stub2_; 423 MockVideoStub video_stub2_;
419 MockClientStub client_stub2_; 424 MockClientStub client_stub2_;
420 MockHostStub host_stub2_; 425 MockHostStub host_stub2_;
421 scoped_ptr<MockSession> session_unowned1_; // Not owned by a connection. 426 scoped_ptr<MockSession> session_unowned1_; // Not owned by a connection.
422 SessionConfig session_unowned_config1_; 427 SessionConfig session_unowned_config1_;
423 std::string session_unowned_jid1_; 428 std::string session_unowned_jid1_;
424 scoped_ptr<MockSession> session_unowned2_; // Not owned by a connection. 429 scoped_ptr<MockSession> session_unowned2_; // Not owned by a connection.
425 SessionConfig session_unowned_config2_; 430 SessionConfig session_unowned_config2_;
426 std::string session_unowned_jid2_; 431 std::string session_unowned_jid2_;
427 protocol::Session::EventHandler* session_event_handler_; 432 protocol::Session::EventHandler* session_unowned1_event_handler_;
433 protocol::Session::EventHandler* session_unowned2_event_handler_;
428 scoped_ptr<protocol::CandidateSessionConfig> empty_candidate_config_; 434 scoped_ptr<protocol::CandidateSessionConfig> empty_candidate_config_;
429 scoped_ptr<protocol::CandidateSessionConfig> default_candidate_config_; 435 scoped_ptr<protocol::CandidateSessionConfig> default_candidate_config_;
430 436
431 MockConnectionToClient*& get_connection(int connection_index) { 437 MockConnectionToClient*& get_connection(int connection_index) {
432 return (connection_index == 0) ? connection1_ : connection2_; 438 return (connection_index == 0) ? connection1_ : connection2_;
433 } 439 }
434 440
441 // Returns the cached client pointers client1_ or client2_.
435 ClientSession*& get_client(int connection_index) { 442 ClientSession*& get_client(int connection_index) {
436 return (connection_index == 0) ? client1_ : client2_; 443 return (connection_index == 0) ? client1_ : client2_;
437 } 444 }
438 445
446 // Returns the list of clients of the host_.
447 std::list<ClientSession*>& get_clients_from_host() {
448 return host_->clients_;
449 }
450
439 const std::string& get_session_jid(int connection_index) { 451 const std::string& get_session_jid(int connection_index) {
440 return (connection_index == 0) ? session_jid1_ : session_jid2_; 452 return (connection_index == 0) ? session_jid1_ : session_jid2_;
441 } 453 }
442 454
443 MockVideoStub& get_video_stub(int connection_index) { 455 MockVideoStub& get_video_stub(int connection_index) {
444 return (connection_index == 0) ? video_stub1_ : video_stub2_; 456 return (connection_index == 0) ? video_stub1_ : video_stub2_;
445 } 457 }
446 }; 458 };
447 459
448 TEST_F(ChromotingHostTest, StartAndShutdown) { 460 TEST_F(ChromotingHostTest, StartAndShutdown) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 ShutdownHost(); 583 ShutdownHost();
572 message_loop_.Run(); 584 message_loop_.Run();
573 } 585 }
574 586
575 TEST_F(ChromotingHostTest, IncomingSessionAccepted) { 587 TEST_F(ChromotingHostTest, IncomingSessionAccepted) {
576 ExpectHostAndSessionManagerStart(); 588 ExpectHostAndSessionManagerStart();
577 EXPECT_CALL(*session_unowned1_, candidate_config()).WillOnce(Return( 589 EXPECT_CALL(*session_unowned1_, candidate_config()).WillOnce(Return(
578 default_candidate_config_.get())); 590 default_candidate_config_.get()));
579 EXPECT_CALL(*session_unowned1_, set_config(_)); 591 EXPECT_CALL(*session_unowned1_, set_config(_));
580 EXPECT_CALL(*session_unowned1_, Close()).WillOnce(InvokeWithoutArgs( 592 EXPECT_CALL(*session_unowned1_, Close()).WillOnce(InvokeWithoutArgs(
581 this, &ChromotingHostTest::NotifyConnectionClosed)); 593 this, &ChromotingHostTest::NotifyConnectionClosed1));
582 EXPECT_CALL(host_status_observer_, OnAccessDenied(_)); 594 EXPECT_CALL(host_status_observer_, OnAccessDenied(_));
583 EXPECT_CALL(host_status_observer_, OnShutdown()); 595 EXPECT_CALL(host_status_observer_, OnShutdown());
584 596
585 host_->Start(xmpp_login_); 597 host_->Start(xmpp_login_);
586 598
587 protocol::SessionManager::IncomingSessionResponse response = 599 protocol::SessionManager::IncomingSessionResponse response =
588 protocol::SessionManager::DECLINE; 600 protocol::SessionManager::DECLINE;
589 host_->OnIncomingSession(session_unowned1_.release(), &response); 601 host_->OnIncomingSession(session_unowned1_.release(), &response);
590 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 602 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
591 603
592 ShutdownHost(); 604 ShutdownHost();
593 message_loop_.Run(); 605 message_loop_.Run();
594 } 606 }
595 607
596 TEST_F(ChromotingHostTest, IncomingSessionOverload) { 608 TEST_F(ChromotingHostTest, LoginBackOffUponConnection) {
597 ExpectHostAndSessionManagerStart(); 609 ExpectHostAndSessionManagerStart();
598 EXPECT_CALL(*session_unowned1_, candidate_config()).WillOnce(Return( 610 EXPECT_CALL(*session_unowned1_, candidate_config()).WillOnce(
599 default_candidate_config_.get())); 611 Return(default_candidate_config_.get()));
600 EXPECT_CALL(*session_unowned1_, set_config(_)); 612 EXPECT_CALL(*session_unowned1_, set_config(_));
601 EXPECT_CALL(*session_unowned1_, Close()).WillOnce(InvokeWithoutArgs( 613 EXPECT_CALL(*session_unowned1_, Close()).WillOnce(
602 this, &ChromotingHostTest::NotifyConnectionClosed)); 614 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1));
603 EXPECT_CALL(host_status_observer_, OnAccessDenied(_)); 615 EXPECT_CALL(host_status_observer_, OnAccessDenied(_));
604 EXPECT_CALL(host_status_observer_, OnShutdown()); 616 EXPECT_CALL(host_status_observer_, OnShutdown());
605 617
606 host_->Start(xmpp_login_); 618 host_->Start(xmpp_login_);
607 619
608 protocol::SessionManager::IncomingSessionResponse response = 620 protocol::SessionManager::IncomingSessionResponse response =
609 protocol::SessionManager::DECLINE; 621 protocol::SessionManager::DECLINE;
622
610 host_->OnIncomingSession(session_unowned1_.release(), &response); 623 host_->OnIncomingSession(session_unowned1_.release(), &response);
611 EXPECT_EQ(protocol::SessionManager::ACCEPT, response); 624 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
612 625
626 host_->OnSessionAuthenticating(get_clients_from_host().front());
613 host_->OnIncomingSession(session_unowned2_.get(), &response); 627 host_->OnIncomingSession(session_unowned2_.get(), &response);
614 EXPECT_EQ(protocol::SessionManager::OVERLOAD, response); 628 EXPECT_EQ(protocol::SessionManager::OVERLOAD, response);
615 629
616 ShutdownHost(); 630 ShutdownHost();
617 message_loop_.Run(); 631 message_loop_.Run();
618 } 632 }
619 633
634 TEST_F(ChromotingHostTest, LoginBackOffUponAuthenticating) {
635 Expectation start = ExpectHostAndSessionManagerStart();
636 EXPECT_CALL(*session_unowned1_, candidate_config()).WillOnce(
637 Return(default_candidate_config_.get()));
638 EXPECT_CALL(*session_unowned1_, set_config(_));
639 EXPECT_CALL(*session_unowned1_, Close()).WillOnce(
640 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed1));
641
642 EXPECT_CALL(*session_unowned2_, candidate_config()).WillOnce(
643 Return(default_candidate_config_.get()));
644 EXPECT_CALL(*session_unowned2_, set_config(_));
645 EXPECT_CALL(*session_unowned2_, Close()).WillOnce(
646 InvokeWithoutArgs(this, &ChromotingHostTest::NotifyConnectionClosed2));
647
648 EXPECT_CALL(host_status_observer_, OnShutdown());
649
650 host_->Start(xmpp_login_);
651
652 protocol::SessionManager::IncomingSessionResponse response =
653 protocol::SessionManager::DECLINE;
654
655 host_->OnIncomingSession(session_unowned1_.release(), &response);
656 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
657
658 host_->OnIncomingSession(session_unowned2_.release(), &response);
659 EXPECT_EQ(protocol::SessionManager::ACCEPT, response);
660
661 // This will set the backoff.
662 host_->OnSessionAuthenticating(get_clients_from_host().front());
663
664 // This should disconnect client2.
665 host_->OnSessionAuthenticating(get_clients_from_host().back());
666
667 // Verify that the host only has 1 client at this point.
668 EXPECT_EQ(get_clients_from_host().size(), 1U);
669
670 ShutdownHost();
671 message_loop_.Run();
672 }
673
620 TEST_F(ChromotingHostTest, OnSessionRouteChange) { 674 TEST_F(ChromotingHostTest, OnSessionRouteChange) {
621 std::string channel_name("ChannelName"); 675 std::string channel_name("ChannelName");
622 protocol::TransportRoute route; 676 protocol::TransportRoute route;
623 677
624 ExpectHostAndSessionManagerStart(); 678 ExpectHostAndSessionManagerStart();
625 Expectation video_packet_sent = ExpectClientConnected( 679 Expectation video_packet_sent = ExpectClientConnected(
626 0, InvokeWithoutArgs(CreateFunctor( 680 0, InvokeWithoutArgs(CreateFunctor(
627 this, &ChromotingHostTest::ChangeSessionRoute, channel_name, route))); 681 this, &ChromotingHostTest::ChangeSessionRoute, channel_name, route)));
628 Expectation route_change = 682 Expectation route_change =
629 EXPECT_CALL(host_status_observer_, OnClientRouteChange( 683 EXPECT_CALL(host_status_observer_, OnClientRouteChange(
(...skipping 16 matching lines...) Expand all
646 ExpectClientDisconnected(0, true, video_packet_sent, 700 ExpectClientDisconnected(0, true, video_packet_sent,
647 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); 701 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost));
648 EXPECT_CALL(host_status_observer_, OnShutdown()); 702 EXPECT_CALL(host_status_observer_, OnShutdown());
649 703
650 host_->Start(xmpp_login_); 704 host_->Start(xmpp_login_);
651 SimulateClientConnection(0, true, false); 705 SimulateClientConnection(0, true, false);
652 message_loop_.Run(); 706 message_loop_.Run();
653 } 707 }
654 708
655 } // namespace remoting 709 } // 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