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

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

Issue 6780014: Clean up remoting project (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: got rid of ref counting on user authenticator Created 9 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) 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/bind.h"
6 #include "base/scoped_ptr.h" 6 #include "base/scoped_ptr.h"
7 #include "base/task.h" 7 #include "base/task.h"
8 #include "remoting/host/capturer_fake.h" 8 #include "remoting/host/capturer_fake.h"
9 #include "remoting/host/chromoting_host.h" 9 #include "remoting/host/chromoting_host.h"
10 #include "remoting/host/chromoting_host_context.h" 10 #include "remoting/host/chromoting_host_context.h"
11 #include "remoting/host/host_mock_objects.h" 11 #include "remoting/host/host_mock_objects.h"
12 #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"
14 #include "remoting/proto/video.pb.h" 13 #include "remoting/proto/video.pb.h"
15 #include "remoting/protocol/protocol_mock_objects.h" 14 #include "remoting/protocol/protocol_mock_objects.h"
16 #include "remoting/protocol/session_config.h" 15 #include "remoting/protocol/session_config.h"
17 #include "testing/gmock_mutant.h" 16 #include "testing/gmock_mutant.h"
18 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
20 19
21 using ::remoting::protocol::LocalLoginCredentials; 20 using ::remoting::protocol::LocalLoginCredentials;
22 using ::remoting::protocol::MockClientStub; 21 using ::remoting::protocol::MockClientStub;
23 using ::remoting::protocol::MockConnectionToClient; 22 using ::remoting::protocol::MockConnectionToClient;
24 using ::remoting::protocol::MockConnectionToClientEventHandler; 23 using ::remoting::protocol::MockConnectionToClientEventHandler;
25 using ::remoting::protocol::MockHostStub; 24 using ::remoting::protocol::MockHostStub;
26 using ::remoting::protocol::MockInputStub;
27 using ::remoting::protocol::MockSession; 25 using ::remoting::protocol::MockSession;
28 using ::remoting::protocol::MockVideoStub; 26 using ::remoting::protocol::MockVideoStub;
29 using ::remoting::protocol::SessionConfig; 27 using ::remoting::protocol::SessionConfig;
30 28
31 using testing::_; 29 using testing::_;
32 using testing::AnyNumber; 30 using testing::AnyNumber;
33 using testing::AtLeast; 31 using testing::AtLeast;
34 using testing::CreateFunctor; 32 using testing::CreateFunctor;
35 using testing::DeleteArg; 33 using testing::DeleteArg;
36 using testing::DoAll; 34 using testing::DoAll;
37 using testing::InSequence; 35 using testing::InSequence;
38 using testing::InvokeWithoutArgs; 36 using testing::InvokeWithoutArgs;
39 using testing::Return; 37 using testing::Return;
40 using testing::Sequence; 38 using testing::Sequence;
41 39
42 namespace remoting { 40 namespace remoting {
43 41
44 namespace { 42 namespace {
45 43
46 UserAuthenticator* MakeUserAuthenticator() {
47 return new UserAuthenticatorFake();
48 }
49
50 void PostQuitTask(MessageLoop* message_loop) { 44 void PostQuitTask(MessageLoop* message_loop) {
51 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); 45 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
52 } 46 }
53 47
54 // Run the task and delete it afterwards. This action is used to deal with 48 // Run the task and delete it afterwards. This action is used to deal with
55 // done callbacks. 49 // done callbacks.
56 ACTION(RunDoneTask) { 50 ACTION(RunDoneTask) {
57 arg1->Run(); 51 arg1->Run();
58 delete arg1; 52 delete arg1;
59 } 53 }
(...skipping 23 matching lines...) Expand all
83 EXPECT_CALL(context_, main_message_loop()) 77 EXPECT_CALL(context_, main_message_loop())
84 .Times(AnyNumber()); 78 .Times(AnyNumber());
85 EXPECT_CALL(context_, encode_message_loop()) 79 EXPECT_CALL(context_, encode_message_loop())
86 .Times(AnyNumber()); 80 .Times(AnyNumber());
87 EXPECT_CALL(context_, network_message_loop()) 81 EXPECT_CALL(context_, network_message_loop())
88 .Times(AnyNumber()); 82 .Times(AnyNumber());
89 83
90 Capturer* capturer = new CapturerFake(); 84 Capturer* capturer = new CapturerFake();
91 host_stub_ = new MockHostStub(); 85 host_stub_ = new MockHostStub();
92 host_stub2_ = new MockHostStub(); 86 host_stub2_ = new MockHostStub();
93 input_stub_ = new MockInputStub(); 87 event_executor_ = new MockEventExecutor();
94 input_stub2_ = new MockInputStub(); 88 event_executor2_ = new MockEventExecutor();
95 curtain_ = new MockCurtain(); 89 curtain_ = new MockCurtain();
96 DesktopEnvironment* desktop = 90 DesktopEnvironment* desktop =
97 new DesktopEnvironment(capturer, input_stub_, curtain_); 91 new DesktopEnvironment(capturer, event_executor_, curtain_);
98 host_ = ChromotingHost::Create(&context_, config_, desktop); 92 host_ = ChromotingHost::Create(&context_, config_, desktop);
99 credentials_good_.set_type(protocol::PASSWORD); 93 credentials_.set_type(protocol::PASSWORD);
100 credentials_good_.set_username("user"); 94 credentials_.set_username("user");
101 credentials_good_.set_credential("password"); 95 credentials_.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());
105 connection_ = new MockConnectionToClient( 96 connection_ = new MockConnectionToClient(
106 &message_loop_, &handler_, host_stub_, input_stub_); 97 &message_loop_, &handler_, host_stub_, event_executor_);
107 connection2_ = new MockConnectionToClient( 98 connection2_ = new MockConnectionToClient(
108 &message_loop_, &handler_, host_stub2_, input_stub2_); 99 &message_loop_, &handler_, host_stub2_, event_executor2_);
109 session_ = new MockSession(); 100 session_ = new MockSession();
110 session2_ = new MockSession(); 101 session2_ = new MockSession();
111 session_config_.reset(SessionConfig::CreateDefault()); 102 session_config_.reset(SessionConfig::CreateDefault());
112 session_config2_.reset(SessionConfig::CreateDefault()); 103 session_config2_.reset(SessionConfig::CreateDefault());
113 104
114 ON_CALL(video_stub_, ProcessVideoPacket(_, _)) 105 ON_CALL(video_stub_, ProcessVideoPacket(_, _))
115 .WillByDefault( 106 .WillByDefault(
116 DoAll(DeleteArg<0>(), DeleteArg<1>())); 107 DoAll(DeleteArg<0>(), DeleteArg<1>()));
117 ON_CALL(video_stub2_, ProcessVideoPacket(_, _)) 108 ON_CALL(video_stub2_, ProcessVideoPacket(_, _))
118 .WillByDefault( 109 .WillByDefault(
(...skipping 25 matching lines...) Expand all
144 EXPECT_CALL(*connection2_.get(), client_stub()) 135 EXPECT_CALL(*connection2_.get(), client_stub())
145 .Times(AnyNumber()); 136 .Times(AnyNumber());
146 EXPECT_CALL(*connection2_.get(), session()) 137 EXPECT_CALL(*connection2_.get(), session())
147 .Times(AnyNumber()); 138 .Times(AnyNumber());
148 EXPECT_CALL(*session_.get(), config()) 139 EXPECT_CALL(*session_.get(), config())
149 .Times(AnyNumber()); 140 .Times(AnyNumber());
150 EXPECT_CALL(*session2_.get(), config()) 141 EXPECT_CALL(*session2_.get(), config())
151 .Times(AnyNumber()); 142 .Times(AnyNumber());
152 } 143 }
153 144
154 virtual void TearDown() {
155 }
156
157 // Helper method to pretend a client is connected to ChromotingHost. 145 // Helper method to pretend a client is connected to ChromotingHost.
158 void SimulateClientConnection(int connection_index, bool authenticate) { 146 void SimulateClientConnection(int connection_index, bool authenticate) {
159 scoped_refptr<MockConnectionToClient> connection = 147 scoped_refptr<MockConnectionToClient> connection =
160 (connection_index == 0) ? connection_ : connection2_; 148 (connection_index == 0) ? connection_ : connection2_;
161 protocol::LocalLoginCredentials& credentials = 149
162 authenticate ? credentials_good_ : credentials_bad_; 150 MockUserAuthenticator *user_authenticator = new MockUserAuthenticator;
151 EXPECT_CALL(*user_authenticator, Authenticate(_, _))
152 .WillOnce(Return(authenticate));
153
163 scoped_refptr<ClientSession> client = new ClientSession( 154 scoped_refptr<ClientSession> client = new ClientSession(
164 host_.get(), 155 host_.get(),
165 base::Bind(MakeUserAuthenticator), 156 user_authenticator,
166 connection, 157 connection,
167 input_stub_); 158 event_executor_);
168 connection->set_host_stub(client.get()); 159 connection->set_host_stub(client.get());
169 160
170 context_.network_message_loop()->PostTask( 161 context_.network_message_loop()->PostTask(
171 FROM_HERE, 162 FROM_HERE,
172 NewRunnableMethod(host_.get(), 163 NewRunnableMethod(host_.get(),
173 &ChromotingHost::AddClient, 164 &ChromotingHost::AddClient,
174 client)); 165 client));
175 context_.network_message_loop()->PostTask( 166 context_.network_message_loop()->PostTask(
176 FROM_HERE, 167 FROM_HERE,
177 NewRunnableMethod(host_.get(), 168 NewRunnableMethod(host_.get(),
178 &ChromotingHost::OnClientConnected, 169 &ChromotingHost::OnClientConnected,
179 connection)); 170 connection));
180 context_.network_message_loop()->PostTask( 171 context_.network_message_loop()->PostTask(
181 FROM_HERE, 172 FROM_HERE,
182 NewRunnableMethod(client.get(), 173 NewRunnableMethod(client.get(),
183 &ClientSession::BeginSessionRequest, 174 &ClientSession::BeginSessionRequest,
184 &credentials, 175 &credentials_,
185 NewRunnableFunction(&DummyDoneTask))); 176 NewRunnableFunction(&DummyDoneTask)));
186 } 177 }
187 178
188 // Helper method to remove a client connection from ChromotingHost. 179 // Helper method to remove a client connection from ChromotingHost.
189 void RemoveClientConnection() { 180 void RemoveClientConnection() {
190 context_.network_message_loop()->PostTask( 181 context_.network_message_loop()->PostTask(
191 FROM_HERE, 182 FROM_HERE,
192 NewRunnableMethod(host_.get(), 183 NewRunnableMethod(host_.get(),
193 &ChromotingHost::OnClientDisconnected, 184 &ChromotingHost::OnClientDisconnected,
194 connection_)); 185 connection_));
195 } 186 }
196 187
197 protected: 188 protected:
198 MessageLoop message_loop_; 189 MessageLoop message_loop_;
199 MockConnectionToClientEventHandler handler_; 190 MockConnectionToClientEventHandler handler_;
200 scoped_refptr<ChromotingHost> host_; 191 scoped_refptr<ChromotingHost> host_;
201 scoped_refptr<InMemoryHostConfig> config_; 192 scoped_refptr<InMemoryHostConfig> config_;
202 MockChromotingHostContext context_; 193 MockChromotingHostContext context_;
203 protocol::LocalLoginCredentials credentials_good_; 194 protocol::LocalLoginCredentials credentials_;
204 protocol::LocalLoginCredentials credentials_bad_;
205 scoped_refptr<MockConnectionToClient> connection_; 195 scoped_refptr<MockConnectionToClient> connection_;
206 scoped_refptr<MockSession> session_; 196 scoped_refptr<MockSession> session_;
207 scoped_ptr<SessionConfig> session_config_; 197 scoped_ptr<SessionConfig> session_config_;
208 MockVideoStub video_stub_; 198 MockVideoStub video_stub_;
209 MockClientStub client_stub_; 199 MockClientStub client_stub_;
210 MockHostStub* host_stub_; 200 MockHostStub* host_stub_;
211 MockInputStub* input_stub_; 201 MockEventExecutor* event_executor_;
212 MockCurtain* curtain_; 202 MockCurtain* curtain_;
213 scoped_refptr<MockConnectionToClient> connection2_; 203 scoped_refptr<MockConnectionToClient> connection2_;
214 scoped_refptr<MockSession> session2_; 204 scoped_refptr<MockSession> session2_;
215 scoped_ptr<SessionConfig> session_config2_; 205 scoped_ptr<SessionConfig> session_config2_;
216 MockVideoStub video_stub2_; 206 MockVideoStub video_stub2_;
217 MockClientStub client_stub2_; 207 MockClientStub client_stub2_;
218 MockHostStub* host_stub2_; 208 MockHostStub* host_stub2_;
219 MockInputStub* input_stub2_; 209 MockEventExecutor* event_executor2_;
220 }; 210 };
221 211
222 TEST_F(ChromotingHostTest, StartAndShutdown) { 212 TEST_F(ChromotingHostTest, StartAndShutdown) {
223 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); 213 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
224 214
225 message_loop_.PostTask(FROM_HERE, 215 message_loop_.PostTask(FROM_HERE,
226 NewRunnableMethod(host_.get(), 216 NewRunnableMethod(host_.get(),
227 &ChromotingHost::Shutdown)); 217 &ChromotingHost::Shutdown));
228 message_loop_.Run(); 218 message_loop_.Run();
229 } 219 }
230 220
231 TEST_F(ChromotingHostTest, Connect) { 221 TEST_F(ChromotingHostTest, Connect) {
232 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); 222 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
233 223
234 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) 224 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
235 .WillOnce(RunDoneTask()); 225 .WillOnce(RunDoneTask());
236 226
237 // When the video packet is received we first shutdown ChromotingHost 227 // When the video packet is received we first shutdown ChromotingHost
238 // then execute the done task. 228 // then execute the done task.
239 InSequence s; 229 {
240 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) 230 InSequence s;
241 .Times(1); 231 EXPECT_CALL(*curtain_, EnableCurtainMode(true))
242 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 232 .Times(1);
243 .WillOnce(DoAll( 233 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
244 InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown), 234 .WillOnce(DoAll(
245 RunDoneTask())) 235 InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown),
246 .RetiresOnSaturation(); 236 RunDoneTask()))
247 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 237 .RetiresOnSaturation();
248 .Times(AnyNumber()); 238 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
249 EXPECT_CALL(*connection_.get(), Disconnect()) 239 .Times(AnyNumber());
250 .RetiresOnSaturation(); 240 EXPECT_CALL(*connection_.get(), Disconnect())
251 241 .RetiresOnSaturation();
242 }
252 SimulateClientConnection(0, true); 243 SimulateClientConnection(0, true);
253 message_loop_.Run(); 244 message_loop_.Run();
254 } 245 }
255 246
256 TEST_F(ChromotingHostTest, Reconnect) { 247 TEST_F(ChromotingHostTest, Reconnect) {
257 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); 248 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
258 249
259 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) 250 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
260 .Times(2) 251 .Times(2)
261 .WillRepeatedly(RunDoneTask()); 252 .WillRepeatedly(RunDoneTask());
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 .RetiresOnSaturation(); 346 .RetiresOnSaturation();
356 347
357 SimulateClientConnection(0, true); 348 SimulateClientConnection(0, true);
358 message_loop_.Run(); 349 message_loop_.Run();
359 } 350 }
360 351
361 TEST_F(ChromotingHostTest, CurtainModeFail) { 352 TEST_F(ChromotingHostTest, CurtainModeFail) {
362 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); 353 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
363 354
364 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) 355 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
365 .Times(1) 356 .WillOnce(RunDoneTask());
366 .WillRepeatedly(RunDoneTask());
367 357
368 // Ensure that curtain mode is not activated if a connection does not 358 // Ensure that curtain mode is not activated if a connection does not
369 // authenticate. 359 // authenticate.
370 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) 360 EXPECT_CALL(*curtain_, EnableCurtainMode(_))
371 .Times(0); 361 .Times(0);
372 EXPECT_CALL(*connection_.get(), Disconnect()) 362 EXPECT_CALL(*connection_.get(), Disconnect())
373 .WillOnce(QuitMainMessageLoop(&message_loop_)); 363 .WillOnce(QuitMainMessageLoop(&message_loop_));
374 SimulateClientConnection(0, false); 364 SimulateClientConnection(0, false);
375 RemoveClientConnection(); 365 RemoveClientConnection();
376 message_loop_.Run(); 366 message_loop_.Run();
377 } 367 }
378 368
379 TEST_F(ChromotingHostTest, CurtainModeFailSecond) { 369 TEST_F(ChromotingHostTest, CurtainModeFailSecond) {
380 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); 370 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
381 371
382 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) 372 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
383 .Times(1) 373 .WillOnce(RunDoneTask());
384 .WillRepeatedly(RunDoneTask());
385 374
386 EXPECT_CALL(client_stub2_, BeginSessionResponse(_, _)) 375 EXPECT_CALL(client_stub2_, BeginSessionResponse(_, _))
387 .Times(1) 376 .WillOnce(RunDoneTask());
388 .WillRepeatedly(RunDoneTask()); 377
389 378
390 // When a video packet is received we connect the second mock 379 // When a video packet is received we connect the second mock
391 // connection. 380 // connection.
392 { 381 {
393 InSequence s; 382 InSequence s;
394 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) 383 EXPECT_CALL(*curtain_, EnableCurtainMode(true))
395 .Times(1)
396 .WillOnce(QuitMainMessageLoop(&message_loop_)); 384 .WillOnce(QuitMainMessageLoop(&message_loop_));
397 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 385 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
398 .WillOnce(DoAll( 386 .WillOnce(DoAll(
399 InvokeWithoutArgs( 387 InvokeWithoutArgs(
400 CreateFunctor( 388 CreateFunctor(
401 this, 389 this,
402 &ChromotingHostTest::SimulateClientConnection, 1, false)), 390 &ChromotingHostTest::SimulateClientConnection, 1, false)),
403 RunDoneTask())) 391 RunDoneTask()))
404 .RetiresOnSaturation(); 392 .RetiresOnSaturation();
405 // Check that the second connection does not affect curtain mode. 393 // Check that the second connection does not affect curtain mode.
406 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) 394 EXPECT_CALL(*curtain_, EnableCurtainMode(_))
407 .Times(0); 395 .Times(0);
408 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 396 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
409 .Times(AnyNumber()); 397 .Times(AnyNumber());
410 EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _)) 398 EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _))
411 .Times(0); 399 .Times(0);
412 } 400 }
413 401
414 SimulateClientConnection(0, true); 402 SimulateClientConnection(0, true);
415 message_loop_.Run(); 403 message_loop_.Run();
416 } 404 }
417 405
418 } // namespace remoting 406 } // 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