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

Unified Diff: remoting/host/chromoting_host_unittest.cc

Issue 6711033: A new authenticated connection evicts an old one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/chromoting_host_unittest.cc
diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc
index 23295ae92cfa1b31bb156aff2f225251109beb8f..494e9c33923654bfd25d3e9898ca2fa0dcb79599 100644
--- a/remoting/host/chromoting_host_unittest.cc
+++ b/remoting/host/chromoting_host_unittest.cc
@@ -41,7 +41,8 @@ void PostQuitTask(MessageLoop* message_loop) {
message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
}
-void BeginSessionRequest(protocol::HostStub* host_stub) {
+void BeginSessionRequest(protocol::ConnectionToClient* connection,
+ protocol::HostStub* host_stub) {
LocalLoginCredentials* credentials =
new LocalLoginCredentials();
credentials->set_type(protocol::PASSWORD);
@@ -51,6 +52,7 @@ void BeginSessionRequest(protocol::HostStub* host_stub) {
credentials->set_credential(password.data(), password.length());
host_stub->BeginSessionRequest(
+ connection,
credentials,
new DeleteTask<LocalLoginCredentials>(credentials));
}
@@ -90,57 +92,92 @@ class ChromotingHostTest : public testing::Test {
Capturer* capturer = new CapturerFake(context_.main_message_loop());
host_stub_ = new MockHostStub();
+ host_stub2_ = new MockHostStub();
input_stub_ = new MockInputStub();
+ input_stub2_ = new MockInputStub();
DesktopEnvironment* desktop =
new DesktopEnvironmentFake(capturer, input_stub_);
host_ = ChromotingHost::Create(&context_, config_, desktop);
connection_ = new MockConnectionToClient(
&message_loop_, &handler_, host_stub_, input_stub_);
+ connection2_ = new MockConnectionToClient(
+ &message_loop_, &handler_, host_stub2_, input_stub2_);
session_ = new MockSession();
+ session2_ = new MockSession();
session_config_.reset(SessionConfig::CreateDefault());
+ session_config2_.reset(SessionConfig::CreateDefault());
ON_CALL(video_stub_, ProcessVideoPacket(_, _))
.WillByDefault(
DoAll(DeleteArg<0>(), DeleteArg<1>()));
+ ON_CALL(video_stub2_, ProcessVideoPacket(_, _))
+ .WillByDefault(
+ DoAll(DeleteArg<0>(), DeleteArg<1>()));
ON_CALL(*connection_.get(), video_stub())
.WillByDefault(Return(&video_stub_));
ON_CALL(*connection_.get(), client_stub())
.WillByDefault(Return(&client_stub_));
ON_CALL(*connection_.get(), session())
.WillByDefault(Return(session_));
+ ON_CALL(*connection2_.get(), video_stub())
+ .WillByDefault(Return(&video_stub2_));
+ ON_CALL(*connection2_.get(), client_stub())
+ .WillByDefault(Return(&client_stub2_));
+ ON_CALL(*connection2_.get(), session())
+ .WillByDefault(Return(session2_));
ON_CALL(*session_.get(), config())
.WillByDefault(Return(session_config_.get()));
+ ON_CALL(*session2_.get(), config())
+ .WillByDefault(Return(session_config2_.get()));
EXPECT_CALL(*connection_.get(), video_stub())
.Times(AnyNumber());
EXPECT_CALL(*connection_.get(), client_stub())
.Times(AnyNumber());
EXPECT_CALL(*connection_.get(), session())
.Times(AnyNumber());
+ EXPECT_CALL(*connection2_.get(), video_stub())
+ .Times(AnyNumber());
+ EXPECT_CALL(*connection2_.get(), client_stub())
+ .Times(AnyNumber());
+ EXPECT_CALL(*connection2_.get(), session())
+ .Times(AnyNumber());
EXPECT_CALL(*session_.get(), config())
.Times(AnyNumber());
+ EXPECT_CALL(*session2_.get(), config())
+ .Times(AnyNumber());
+
}
virtual void TearDown() {
}
- // Helper metjod to pretend a client is connected to ChromotingHost.
- void SimulateClientConnection() {
+ // Helper method to pretend a client is connected to ChromotingHost.
+ void SimulateClientConnection(int connection_index) {
+ scoped_refptr<MockConnectionToClient> connection =
+ (connection_index == 0) ? connection_ : connection2_;
+
context_.network_message_loop()->PostTask(
FROM_HERE,
NewRunnableMethod(host_.get(),
- &ChromotingHost::set_connection,
- connection_));
+ &ChromotingHost::add_connection,
+ connection));
context_.network_message_loop()->PostTask(
FROM_HERE,
NewRunnableMethod(host_.get(),
&ChromotingHost::OnClientConnected,
- connection_));
+ connection));
context_.network_message_loop()->PostTask(
FROM_HERE,
- NewRunnableFunction(&BeginSessionRequest, host_->host_stub()));
+ NewRunnableFunction(&BeginSessionRequest,
+ connection,
+ host_->host_stub()));
}
- // Helper method to remove a client connection from ChromotongHost.
+ void SimulateSecondClientConnection() {
+ SimulateClientConnection(1);
+ }
+
+ // Helper method to remove a client connection from ChromotingHost.
void RemoveClientConnection() {
context_.network_message_loop()->PostTask(
FROM_HERE,
@@ -162,6 +199,13 @@ class ChromotingHostTest : public testing::Test {
MockClientStub client_stub_;
MockHostStub* host_stub_;
MockInputStub* input_stub_;
+ scoped_refptr<MockConnectionToClient> connection2_;
+ scoped_refptr<MockSession> session2_;
+ scoped_ptr<SessionConfig> session_config2_;
+ MockVideoStub video_stub2_;
+ MockClientStub client_stub2_;
+ MockHostStub* host_stub2_;
+ MockInputStub* input_stub2_;
};
TEST_F(ChromotingHostTest, StartAndShutdown) {
@@ -192,7 +236,7 @@ TEST_F(ChromotingHostTest, Connect) {
EXPECT_CALL(*connection_.get(), Disconnect())
.RetiresOnSaturation();
- SimulateClientConnection();
+ SimulateClientConnection(0);
message_loop_.Run();
}
@@ -222,7 +266,7 @@ TEST_F(ChromotingHostTest, Reconnect) {
.WillOnce(QuitMainMessageLoop(&message_loop_))
.RetiresOnSaturation();
- SimulateClientConnection();
+ SimulateClientConnection(0);
message_loop_.Run();
// Connect the client again.
@@ -239,7 +283,48 @@ TEST_F(ChromotingHostTest, Reconnect) {
EXPECT_CALL(*connection_.get(), Disconnect())
.RetiresOnSaturation();
- SimulateClientConnection();
+ SimulateClientConnection(0);
+ message_loop_.Run();
+}
+
+TEST_F(ChromotingHostTest, ConnectTwice) {
+ host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
+
+ EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
+ .Times(1)
+ .WillRepeatedly(RunDoneTask());
+
+ EXPECT_CALL(client_stub2_, BeginSessionResponse(_, _))
+ .Times(1)
+ .WillRepeatedly(RunDoneTask());
+
+ // When a video packet is received we connect the second mock
+ // connection.
+ {
+ InSequence s;
+ EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
+ .WillOnce(DoAll(
+ InvokeWithoutArgs(
+ this, &ChromotingHostTest::SimulateSecondClientConnection),
+ RunDoneTask()))
+ .RetiresOnSaturation();
+ EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
+ .Times(AnyNumber());
+ EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _))
+ .WillOnce(DoAll(
+ InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown),
+ RunDoneTask()))
+ .RetiresOnSaturation();
+ EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _))
+ .Times(AnyNumber());
+ }
+
+ EXPECT_CALL(*connection_.get(), Disconnect())
+ .RetiresOnSaturation();
+ EXPECT_CALL(*connection2_.get(), Disconnect())
+ .RetiresOnSaturation();
+
+ SimulateClientConnection(0);
message_loop_.Run();
}

Powered by Google App Engine
This is Rietveld 408576698