| OLD | NEW |
| 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/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
| 6 #include "base/task.h" | 7 #include "base/task.h" |
| 7 #include "remoting/host/capturer_fake.h" | 8 #include "remoting/host/capturer_fake.h" |
| 8 #include "remoting/host/chromoting_host.h" | 9 #include "remoting/host/chromoting_host.h" |
| 9 #include "remoting/host/chromoting_host_context.h" | 10 #include "remoting/host/chromoting_host_context.h" |
| 10 #include "remoting/host/host_mock_objects.h" | 11 #include "remoting/host/host_mock_objects.h" |
| 11 #include "remoting/host/in_memory_host_config.h" | 12 #include "remoting/host/in_memory_host_config.h" |
| 13 #include "remoting/host/user_authenticator_fake.h" |
| 12 #include "remoting/proto/video.pb.h" | 14 #include "remoting/proto/video.pb.h" |
| 13 #include "remoting/protocol/protocol_mock_objects.h" | 15 #include "remoting/protocol/protocol_mock_objects.h" |
| 14 #include "remoting/protocol/session_config.h" | 16 #include "remoting/protocol/session_config.h" |
| 15 #include "testing/gmock_mutant.h" | 17 #include "testing/gmock_mutant.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 20 |
| 19 using ::remoting::protocol::LocalLoginCredentials; | 21 using ::remoting::protocol::LocalLoginCredentials; |
| 20 using ::remoting::protocol::MockClientStub; | 22 using ::remoting::protocol::MockClientStub; |
| 21 using ::remoting::protocol::MockConnectionToClient; | 23 using ::remoting::protocol::MockConnectionToClient; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 using testing::DoAll; | 36 using testing::DoAll; |
| 35 using testing::InSequence; | 37 using testing::InSequence; |
| 36 using testing::InvokeWithoutArgs; | 38 using testing::InvokeWithoutArgs; |
| 37 using testing::Return; | 39 using testing::Return; |
| 38 using testing::Sequence; | 40 using testing::Sequence; |
| 39 | 41 |
| 40 namespace remoting { | 42 namespace remoting { |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 46 UserAuthenticator* MakeUserAuthenticator() { |
| 47 return new UserAuthenticatorFake(); |
| 48 } |
| 49 |
| 44 void PostQuitTask(MessageLoop* message_loop) { | 50 void PostQuitTask(MessageLoop* message_loop) { |
| 45 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 51 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 46 } | 52 } |
| 47 | 53 |
| 48 // Run the task and delete it afterwards. This action is used to deal with | 54 // Run the task and delete it afterwards. This action is used to deal with |
| 49 // done callbacks. | 55 // done callbacks. |
| 50 ACTION(RunDoneTask) { | 56 ACTION(RunDoneTask) { |
| 51 arg1->Run(); | 57 arg1->Run(); |
| 52 delete arg1; | 58 delete arg1; |
| 53 } | 59 } |
| 54 | 60 |
| 55 ACTION_P(QuitMainMessageLoop, message_loop) { | 61 ACTION_P(QuitMainMessageLoop, message_loop) { |
| 56 PostQuitTask(message_loop); | 62 PostQuitTask(message_loop); |
| 57 } | 63 } |
| 58 | 64 |
| 65 void DummyDoneTask() { |
| 66 } |
| 67 |
| 59 } // namespace | 68 } // namespace |
| 60 | 69 |
| 61 class ChromotingHostTest : public testing::Test { | 70 class ChromotingHostTest : public testing::Test { |
| 62 public: | 71 public: |
| 63 ChromotingHostTest() { | 72 ChromotingHostTest() { |
| 64 } | 73 } |
| 65 | 74 |
| 66 virtual void SetUp() { | 75 virtual void SetUp() { |
| 67 config_ = new InMemoryHostConfig(); | 76 config_ = new InMemoryHostConfig(); |
| 68 ON_CALL(context_, main_message_loop()) | 77 ON_CALL(context_, main_message_loop()) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 80 | 89 |
| 81 Capturer* capturer = new CapturerFake(); | 90 Capturer* capturer = new CapturerFake(); |
| 82 host_stub_ = new MockHostStub(); | 91 host_stub_ = new MockHostStub(); |
| 83 host_stub2_ = new MockHostStub(); | 92 host_stub2_ = new MockHostStub(); |
| 84 input_stub_ = new MockInputStub(); | 93 input_stub_ = new MockInputStub(); |
| 85 input_stub2_ = new MockInputStub(); | 94 input_stub2_ = new MockInputStub(); |
| 86 curtain_ = new MockCurtain(); | 95 curtain_ = new MockCurtain(); |
| 87 DesktopEnvironment* desktop = | 96 DesktopEnvironment* desktop = |
| 88 new DesktopEnvironment(capturer, input_stub_, curtain_); | 97 new DesktopEnvironment(capturer, input_stub_, curtain_); |
| 89 host_ = ChromotingHost::Create(&context_, config_, desktop); | 98 host_ = ChromotingHost::Create(&context_, config_, desktop); |
| 99 credentials_good_.set_type(protocol::PASSWORD); |
| 100 credentials_good_.set_username("user"); |
| 101 credentials_good_.set_credential("password"); |
| 102 credentials_bad_.set_type(protocol::PASSWORD); |
| 103 credentials_bad_.set_username(UserAuthenticatorFake::fail_username()); |
| 104 credentials_bad_.set_credential(UserAuthenticatorFake::fail_password()); |
| 90 connection_ = new MockConnectionToClient( | 105 connection_ = new MockConnectionToClient( |
| 91 &message_loop_, &handler_, host_stub_, input_stub_); | 106 &message_loop_, &handler_, host_stub_, input_stub_); |
| 92 connection2_ = new MockConnectionToClient( | 107 connection2_ = new MockConnectionToClient( |
| 93 &message_loop_, &handler_, host_stub2_, input_stub2_); | 108 &message_loop_, &handler_, host_stub2_, input_stub2_); |
| 94 session_ = new MockSession(); | 109 session_ = new MockSession(); |
| 95 session2_ = new MockSession(); | 110 session2_ = new MockSession(); |
| 96 session_config_.reset(SessionConfig::CreateDefault()); | 111 session_config_.reset(SessionConfig::CreateDefault()); |
| 97 session_config2_.reset(SessionConfig::CreateDefault()); | 112 session_config2_.reset(SessionConfig::CreateDefault()); |
| 98 | 113 |
| 99 ON_CALL(video_stub_, ProcessVideoPacket(_, _)) | 114 ON_CALL(video_stub_, ProcessVideoPacket(_, _)) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 .Times(AnyNumber()); | 151 .Times(AnyNumber()); |
| 137 } | 152 } |
| 138 | 153 |
| 139 virtual void TearDown() { | 154 virtual void TearDown() { |
| 140 } | 155 } |
| 141 | 156 |
| 142 // Helper method to pretend a client is connected to ChromotingHost. | 157 // Helper method to pretend a client is connected to ChromotingHost. |
| 143 void SimulateClientConnection(int connection_index, bool authenticate) { | 158 void SimulateClientConnection(int connection_index, bool authenticate) { |
| 144 scoped_refptr<MockConnectionToClient> connection = | 159 scoped_refptr<MockConnectionToClient> connection = |
| 145 (connection_index == 0) ? connection_ : connection2_; | 160 (connection_index == 0) ? connection_ : connection2_; |
| 146 scoped_refptr<ClientSession> client = new ClientSession(host_.get(), | 161 protocol::LocalLoginCredentials& credentials = |
| 147 connection); | 162 authenticate ? credentials_good_ : credentials_bad_; |
| 163 scoped_refptr<ClientSession> client = new ClientSession( |
| 164 host_.get(), |
| 165 base::Bind(MakeUserAuthenticator), |
| 166 connection, |
| 167 input_stub_); |
| 148 connection->set_host_stub(client.get()); | 168 connection->set_host_stub(client.get()); |
| 149 | 169 |
| 150 context_.network_message_loop()->PostTask( | 170 context_.network_message_loop()->PostTask( |
| 151 FROM_HERE, | 171 FROM_HERE, |
| 152 NewRunnableMethod(host_.get(), | 172 NewRunnableMethod(host_.get(), |
| 153 &ChromotingHost::AddClient, | 173 &ChromotingHost::AddClient, |
| 154 client)); | 174 client)); |
| 155 context_.network_message_loop()->PostTask( | 175 context_.network_message_loop()->PostTask( |
| 156 FROM_HERE, | 176 FROM_HERE, |
| 157 NewRunnableMethod(host_.get(), | 177 NewRunnableMethod(host_.get(), |
| 158 &ChromotingHost::OnClientConnected, | 178 &ChromotingHost::OnClientConnected, |
| 159 connection)); | 179 connection)); |
| 160 if (authenticate) { | 180 context_.network_message_loop()->PostTask( |
| 161 context_.network_message_loop()->PostTask( | 181 FROM_HERE, |
| 162 FROM_HERE, | 182 NewRunnableMethod(client.get(), |
| 163 NewRunnableMethod(host_.get(), | 183 &ClientSession::BeginSessionRequest, |
| 164 &ChromotingHost::LocalLoginSucceeded, | 184 &credentials, |
| 165 connection)); | 185 NewRunnableFunction(&DummyDoneTask))); |
| 166 } else { | |
| 167 context_.network_message_loop()->PostTask( | |
| 168 FROM_HERE, | |
| 169 NewRunnableMethod(host_.get(), | |
| 170 &ChromotingHost::LocalLoginFailed, | |
| 171 connection)); | |
| 172 } | |
| 173 } | 186 } |
| 174 | 187 |
| 175 // Helper method to remove a client connection from ChromotingHost. | 188 // Helper method to remove a client connection from ChromotingHost. |
| 176 void RemoveClientConnection() { | 189 void RemoveClientConnection() { |
| 177 context_.network_message_loop()->PostTask( | 190 context_.network_message_loop()->PostTask( |
| 178 FROM_HERE, | 191 FROM_HERE, |
| 179 NewRunnableMethod(host_.get(), | 192 NewRunnableMethod(host_.get(), |
| 180 &ChromotingHost::OnClientDisconnected, | 193 &ChromotingHost::OnClientDisconnected, |
| 181 connection_)); | 194 connection_)); |
| 182 } | 195 } |
| 183 | 196 |
| 184 protected: | 197 protected: |
| 185 MessageLoop message_loop_; | 198 MessageLoop message_loop_; |
| 186 MockConnectionToClientEventHandler handler_; | 199 MockConnectionToClientEventHandler handler_; |
| 187 scoped_refptr<ChromotingHost> host_; | 200 scoped_refptr<ChromotingHost> host_; |
| 188 scoped_refptr<InMemoryHostConfig> config_; | 201 scoped_refptr<InMemoryHostConfig> config_; |
| 189 MockChromotingHostContext context_; | 202 MockChromotingHostContext context_; |
| 203 protocol::LocalLoginCredentials credentials_good_; |
| 204 protocol::LocalLoginCredentials credentials_bad_; |
| 190 scoped_refptr<MockConnectionToClient> connection_; | 205 scoped_refptr<MockConnectionToClient> connection_; |
| 191 scoped_refptr<MockSession> session_; | 206 scoped_refptr<MockSession> session_; |
| 192 scoped_ptr<SessionConfig> session_config_; | 207 scoped_ptr<SessionConfig> session_config_; |
| 193 MockVideoStub video_stub_; | 208 MockVideoStub video_stub_; |
| 194 MockClientStub client_stub_; | 209 MockClientStub client_stub_; |
| 195 MockHostStub* host_stub_; | 210 MockHostStub* host_stub_; |
| 196 MockInputStub* input_stub_; | 211 MockInputStub* input_stub_; |
| 197 MockCurtain* curtain_; | 212 MockCurtain* curtain_; |
| 198 scoped_refptr<MockConnectionToClient> connection2_; | 213 scoped_refptr<MockConnectionToClient> connection2_; |
| 199 scoped_refptr<MockSession> session2_; | 214 scoped_refptr<MockSession> session2_; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 .Times(AnyNumber()); | 409 .Times(AnyNumber()); |
| 395 EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _)) | 410 EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _)) |
| 396 .Times(0); | 411 .Times(0); |
| 397 } | 412 } |
| 398 | 413 |
| 399 SimulateClientConnection(0, true); | 414 SimulateClientConnection(0, true); |
| 400 message_loop_.Run(); | 415 message_loop_.Run(); |
| 401 } | 416 } |
| 402 | 417 |
| 403 } // namespace remoting | 418 } // namespace remoting |
| OLD | NEW |