Index: remoting/host/chromoting_host_unittest.cc |
diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc |
index 6fa50a19f504d35e171fe5c2950a2fc68f3105bb..ef570cb86d9b62b62ff7f0f613265dfa6f5d0176 100644 |
--- a/remoting/host/chromoting_host_unittest.cc |
+++ b/remoting/host/chromoting_host_unittest.cc |
@@ -10,7 +10,6 @@ |
#include "remoting/host/chromoting_host_context.h" |
#include "remoting/host/host_mock_objects.h" |
#include "remoting/host/in_memory_host_config.h" |
-#include "remoting/host/user_authenticator_fake.h" |
#include "remoting/proto/video.pb.h" |
#include "remoting/protocol/protocol_mock_objects.h" |
#include "remoting/protocol/session_config.h" |
@@ -23,7 +22,6 @@ using ::remoting::protocol::MockClientStub; |
using ::remoting::protocol::MockConnectionToClient; |
using ::remoting::protocol::MockConnectionToClientEventHandler; |
using ::remoting::protocol::MockHostStub; |
-using ::remoting::protocol::MockInputStub; |
using ::remoting::protocol::MockSession; |
using ::remoting::protocol::MockVideoStub; |
using ::remoting::protocol::SessionConfig; |
@@ -43,10 +41,6 @@ namespace remoting { |
namespace { |
-UserAuthenticator* MakeUserAuthenticator() { |
- return new UserAuthenticatorFake(); |
-} |
- |
void PostQuitTask(MessageLoop* message_loop) { |
message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
} |
@@ -90,22 +84,20 @@ class ChromotingHostTest : public testing::Test { |
Capturer* capturer = new CapturerFake(); |
host_stub_ = new MockHostStub(); |
host_stub2_ = new MockHostStub(); |
- input_stub_ = new MockInputStub(); |
- input_stub2_ = new MockInputStub(); |
+ event_executor_ = new MockEventExecutor(); |
+ event_executor2_ = new MockEventExecutor(); |
curtain_ = new MockCurtain(); |
+ user_authenticator_ = new MockUserAuthenticator(); |
DesktopEnvironment* desktop = |
- new DesktopEnvironment(capturer, input_stub_, curtain_); |
+ new DesktopEnvironment(capturer, event_executor_, curtain_); |
host_ = ChromotingHost::Create(&context_, config_, desktop); |
- credentials_good_.set_type(protocol::PASSWORD); |
- credentials_good_.set_username("user"); |
- credentials_good_.set_credential("password"); |
- credentials_bad_.set_type(protocol::PASSWORD); |
- credentials_bad_.set_username(UserAuthenticatorFake::fail_username()); |
- credentials_bad_.set_credential(UserAuthenticatorFake::fail_password()); |
- connection_ = new MockConnectionToClient( |
- &message_loop_, &handler_, host_stub_, input_stub_); |
+ credentials_.set_type(protocol::PASSWORD); |
+ credentials_.set_username("user"); |
+ credentials_.set_credential("password"); |
+ connection_ = new MockConnectionToClient( |
Lambros
2011/04/01 15:54:00
Nit: indentation
dmac
2011/04/01 21:15:07
Done.
|
+ &message_loop_, &handler_, host_stub_, event_executor_); |
connection2_ = new MockConnectionToClient( |
- &message_loop_, &handler_, host_stub2_, input_stub2_); |
+ &message_loop_, &handler_, host_stub2_, event_executor2_); |
session_ = new MockSession(); |
session2_ = new MockSession(); |
session_config_.reset(SessionConfig::CreateDefault()); |
@@ -151,20 +143,16 @@ class ChromotingHostTest : public testing::Test { |
.Times(AnyNumber()); |
} |
- virtual void TearDown() { |
- } |
- |
// Helper method to pretend a client is connected to ChromotingHost. |
- void SimulateClientConnection(int connection_index, bool authenticate) { |
+ void SimulateClientConnection(int connection_index) { |
scoped_refptr<MockConnectionToClient> connection = |
(connection_index == 0) ? connection_ : connection2_; |
- protocol::LocalLoginCredentials& credentials = |
- authenticate ? credentials_good_ : credentials_bad_; |
scoped_refptr<ClientSession> client = new ClientSession( |
host_.get(), |
- base::Bind(MakeUserAuthenticator), |
+ base::Bind(&ChromotingHostTest::user_authenticator, |
+ base::Unretained(this)), |
connection, |
- input_stub_); |
+ event_executor_); |
connection->set_host_stub(client.get()); |
context_.network_message_loop()->PostTask( |
@@ -177,11 +165,12 @@ class ChromotingHostTest : public testing::Test { |
NewRunnableMethod(host_.get(), |
&ChromotingHost::OnClientConnected, |
connection)); |
+ |
simonmorris
2011/04/01 10:29:34
Nit: extra line.
dmac
2011/04/01 21:15:07
Done.
|
context_.network_message_loop()->PostTask( |
FROM_HERE, |
NewRunnableMethod(client.get(), |
&ClientSession::BeginSessionRequest, |
- &credentials, |
+ &credentials_, |
NewRunnableFunction(&DummyDoneTask))); |
} |
@@ -194,29 +183,33 @@ class ChromotingHostTest : public testing::Test { |
connection_)); |
} |
+ UserAuthenticator* user_authenticator() { |
+ return user_authenticator_.get(); |
+ } |
+ |
protected: |
MessageLoop message_loop_; |
MockConnectionToClientEventHandler handler_; |
scoped_refptr<ChromotingHost> host_; |
scoped_refptr<InMemoryHostConfig> config_; |
MockChromotingHostContext context_; |
- protocol::LocalLoginCredentials credentials_good_; |
- protocol::LocalLoginCredentials credentials_bad_; |
+ protocol::LocalLoginCredentials credentials_; |
scoped_refptr<MockConnectionToClient> connection_; |
scoped_refptr<MockSession> session_; |
scoped_ptr<SessionConfig> session_config_; |
MockVideoStub video_stub_; |
MockClientStub client_stub_; |
MockHostStub* host_stub_; |
- MockInputStub* input_stub_; |
+ MockEventExecutor* event_executor_; |
MockCurtain* curtain_; |
scoped_refptr<MockConnectionToClient> connection2_; |
scoped_refptr<MockSession> session2_; |
+ scoped_refptr<MockUserAuthenticator> user_authenticator_; |
simonmorris
2011/04/01 10:29:34
It's sad to scatter refcounts throughout the code
simonmorris
2011/04/01 10:52:43
After a chat with Jamie, I realise that wouldn't w
|
scoped_ptr<SessionConfig> session_config2_; |
MockVideoStub video_stub2_; |
MockClientStub client_stub2_; |
MockHostStub* host_stub2_; |
- MockInputStub* input_stub2_; |
+ MockEventExecutor* event_executor2_; |
}; |
TEST_F(ChromotingHostTest, StartAndShutdown) { |
@@ -233,6 +226,8 @@ TEST_F(ChromotingHostTest, Connect) { |
EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) |
.WillOnce(RunDoneTask()); |
+ EXPECT_CALL(*user_authenticator_, Authenticate(_, _)) |
+ .WillOnce(Return(true)); |
// When the video packet is received we first shutdown ChromotingHost |
// then execute the done task. |
@@ -248,8 +243,7 @@ TEST_F(ChromotingHostTest, Connect) { |
.Times(AnyNumber()); |
EXPECT_CALL(*connection_.get(), Disconnect()) |
.RetiresOnSaturation(); |
- |
- SimulateClientConnection(0, true); |
+ SimulateClientConnection(0); |
message_loop_.Run(); |
} |
@@ -259,6 +253,9 @@ TEST_F(ChromotingHostTest, Reconnect) { |
EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) |
.Times(2) |
.WillRepeatedly(RunDoneTask()); |
+ EXPECT_CALL(*user_authenticator_, Authenticate(_, _)) |
+ .Times(2) |
+ .WillRepeatedly(Return(true)); |
// When the video packet is received we first disconnect the mock |
// connection. |
@@ -286,7 +283,7 @@ TEST_F(ChromotingHostTest, Reconnect) { |
.WillOnce(QuitMainMessageLoop(&message_loop_)) |
.RetiresOnSaturation(); |
- SimulateClientConnection(0, true); |
+ SimulateClientConnection(0); |
message_loop_.Run(); |
// Connect the client again. |
@@ -305,7 +302,7 @@ TEST_F(ChromotingHostTest, Reconnect) { |
EXPECT_CALL(*connection_.get(), Disconnect()) |
.RetiresOnSaturation(); |
- SimulateClientConnection(0, true); |
+ SimulateClientConnection(0); |
message_loop_.Run(); |
} |
@@ -320,6 +317,10 @@ TEST_F(ChromotingHostTest, ConnectTwice) { |
.Times(1) |
.WillRepeatedly(RunDoneTask()); |
+ EXPECT_CALL(*user_authenticator_, Authenticate(_, _)) |
+ .Times(2) |
+ .WillRepeatedly(Return(true)); |
+ |
// When a video packet is received we connect the second mock |
// connection. |
{ |
@@ -332,7 +333,7 @@ TEST_F(ChromotingHostTest, ConnectTwice) { |
InvokeWithoutArgs( |
CreateFunctor( |
this, |
- &ChromotingHostTest::SimulateClientConnection, 1, true)), |
+ &ChromotingHostTest::SimulateClientConnection, 1)), |
RunDoneTask())) |
.RetiresOnSaturation(); |
// Check that the second connection does not affect curtain mode. |
@@ -354,7 +355,7 @@ TEST_F(ChromotingHostTest, ConnectTwice) { |
EXPECT_CALL(*connection2_.get(), Disconnect()) |
.RetiresOnSaturation(); |
- SimulateClientConnection(0, true); |
+ SimulateClientConnection(0); |
message_loop_.Run(); |
} |
@@ -362,8 +363,9 @@ TEST_F(ChromotingHostTest, CurtainModeFail) { |
host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); |
EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) |
- .Times(1) |
- .WillRepeatedly(RunDoneTask()); |
+ .WillOnce(RunDoneTask()); |
+ EXPECT_CALL(*user_authenticator_, Authenticate(_, _)) |
+ .WillOnce(Return(false)); |
// Ensure that curtain mode is not activated if a connection does not |
// authenticate. |
@@ -371,7 +373,7 @@ TEST_F(ChromotingHostTest, CurtainModeFail) { |
.Times(0); |
EXPECT_CALL(*connection_.get(), Disconnect()) |
.WillOnce(QuitMainMessageLoop(&message_loop_)); |
- SimulateClientConnection(0, false); |
+ SimulateClientConnection(0); |
RemoveClientConnection(); |
message_loop_.Run(); |
} |
@@ -380,26 +382,27 @@ TEST_F(ChromotingHostTest, CurtainModeFailSecond) { |
host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); |
EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) |
- .Times(1) |
- .WillRepeatedly(RunDoneTask()); |
+ .WillOnce(RunDoneTask()); |
EXPECT_CALL(client_stub2_, BeginSessionResponse(_, _)) |
- .Times(1) |
- .WillRepeatedly(RunDoneTask()); |
+ .WillOnce(RunDoneTask()); |
+ |
+ EXPECT_CALL(*user_authenticator_, Authenticate(_, _)) |
+ .WillOnce(Return(true)) |
+ .WillOnce(Return(false)); |
// When a video packet is received we connect the second mock |
// connection. |
{ |
InSequence s; |
EXPECT_CALL(*curtain_, EnableCurtainMode(true)) |
- .Times(1) |
.WillOnce(QuitMainMessageLoop(&message_loop_)); |
EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) |
.WillOnce(DoAll( |
InvokeWithoutArgs( |
CreateFunctor( |
this, |
- &ChromotingHostTest::SimulateClientConnection, 1, false)), |
+ &ChromotingHostTest::SimulateClientConnection, 1)), |
RunDoneTask())) |
.RetiresOnSaturation(); |
// Check that the second connection does not affect curtain mode. |
@@ -411,7 +414,7 @@ TEST_F(ChromotingHostTest, CurtainModeFailSecond) { |
.Times(0); |
} |
- SimulateClientConnection(0, true); |
+ SimulateClientConnection(0); |
message_loop_.Run(); |
} |