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

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: Fix a compile glitch on Windows 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
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();
90 user_authenticator_ = new MockUserAuthenticator();
96 DesktopEnvironment* desktop = 91 DesktopEnvironment* desktop =
97 new DesktopEnvironment(capturer, input_stub_, curtain_); 92 new DesktopEnvironment(capturer, event_executor_, curtain_);
98 host_ = ChromotingHost::Create(&context_, config_, desktop); 93 host_ = ChromotingHost::Create(&context_, config_, desktop);
99 credentials_good_.set_type(protocol::PASSWORD); 94 credentials_.set_type(protocol::PASSWORD);
100 credentials_good_.set_username("user"); 95 credentials_.set_username("user");
101 credentials_good_.set_credential("password"); 96 credentials_.set_credential("password");
102 credentials_bad_.set_type(protocol::PASSWORD); 97 connection_ = new MockConnectionToClient(
Lambros 2011/04/01 15:54:00 Nit: indentation
dmac 2011/04/01 21:15:07 Done.
103 credentials_bad_.set_username(UserAuthenticatorFake::fail_username()); 98 &message_loop_, &handler_, host_stub_, event_executor_);
104 credentials_bad_.set_credential(UserAuthenticatorFake::fail_password());
105 connection_ = new MockConnectionToClient(
106 &message_loop_, &handler_, host_stub_, input_stub_);
107 connection2_ = new MockConnectionToClient( 99 connection2_ = new MockConnectionToClient(
108 &message_loop_, &handler_, host_stub2_, input_stub2_); 100 &message_loop_, &handler_, host_stub2_, event_executor2_);
109 session_ = new MockSession(); 101 session_ = new MockSession();
110 session2_ = new MockSession(); 102 session2_ = new MockSession();
111 session_config_.reset(SessionConfig::CreateDefault()); 103 session_config_.reset(SessionConfig::CreateDefault());
112 session_config2_.reset(SessionConfig::CreateDefault()); 104 session_config2_.reset(SessionConfig::CreateDefault());
113 105
114 ON_CALL(video_stub_, ProcessVideoPacket(_, _)) 106 ON_CALL(video_stub_, ProcessVideoPacket(_, _))
115 .WillByDefault( 107 .WillByDefault(
116 DoAll(DeleteArg<0>(), DeleteArg<1>())); 108 DoAll(DeleteArg<0>(), DeleteArg<1>()));
117 ON_CALL(video_stub2_, ProcessVideoPacket(_, _)) 109 ON_CALL(video_stub2_, ProcessVideoPacket(_, _))
118 .WillByDefault( 110 .WillByDefault(
(...skipping 25 matching lines...) Expand all
144 EXPECT_CALL(*connection2_.get(), client_stub()) 136 EXPECT_CALL(*connection2_.get(), client_stub())
145 .Times(AnyNumber()); 137 .Times(AnyNumber());
146 EXPECT_CALL(*connection2_.get(), session()) 138 EXPECT_CALL(*connection2_.get(), session())
147 .Times(AnyNumber()); 139 .Times(AnyNumber());
148 EXPECT_CALL(*session_.get(), config()) 140 EXPECT_CALL(*session_.get(), config())
149 .Times(AnyNumber()); 141 .Times(AnyNumber());
150 EXPECT_CALL(*session2_.get(), config()) 142 EXPECT_CALL(*session2_.get(), config())
151 .Times(AnyNumber()); 143 .Times(AnyNumber());
152 } 144 }
153 145
154 virtual void TearDown() {
155 }
156
157 // Helper method to pretend a client is connected to ChromotingHost. 146 // Helper method to pretend a client is connected to ChromotingHost.
158 void SimulateClientConnection(int connection_index, bool authenticate) { 147 void SimulateClientConnection(int connection_index) {
159 scoped_refptr<MockConnectionToClient> connection = 148 scoped_refptr<MockConnectionToClient> connection =
160 (connection_index == 0) ? connection_ : connection2_; 149 (connection_index == 0) ? connection_ : connection2_;
161 protocol::LocalLoginCredentials& credentials =
162 authenticate ? credentials_good_ : credentials_bad_;
163 scoped_refptr<ClientSession> client = new ClientSession( 150 scoped_refptr<ClientSession> client = new ClientSession(
164 host_.get(), 151 host_.get(),
165 base::Bind(MakeUserAuthenticator), 152 base::Bind(&ChromotingHostTest::user_authenticator,
153 base::Unretained(this)),
166 connection, 154 connection,
167 input_stub_); 155 event_executor_);
168 connection->set_host_stub(client.get()); 156 connection->set_host_stub(client.get());
169 157
170 context_.network_message_loop()->PostTask( 158 context_.network_message_loop()->PostTask(
171 FROM_HERE, 159 FROM_HERE,
172 NewRunnableMethod(host_.get(), 160 NewRunnableMethod(host_.get(),
173 &ChromotingHost::AddClient, 161 &ChromotingHost::AddClient,
174 client)); 162 client));
175 context_.network_message_loop()->PostTask( 163 context_.network_message_loop()->PostTask(
176 FROM_HERE, 164 FROM_HERE,
177 NewRunnableMethod(host_.get(), 165 NewRunnableMethod(host_.get(),
178 &ChromotingHost::OnClientConnected, 166 &ChromotingHost::OnClientConnected,
179 connection)); 167 connection));
168
simonmorris 2011/04/01 10:29:34 Nit: extra line.
dmac 2011/04/01 21:15:07 Done.
180 context_.network_message_loop()->PostTask( 169 context_.network_message_loop()->PostTask(
181 FROM_HERE, 170 FROM_HERE,
182 NewRunnableMethod(client.get(), 171 NewRunnableMethod(client.get(),
183 &ClientSession::BeginSessionRequest, 172 &ClientSession::BeginSessionRequest,
184 &credentials, 173 &credentials_,
185 NewRunnableFunction(&DummyDoneTask))); 174 NewRunnableFunction(&DummyDoneTask)));
186 } 175 }
187 176
188 // Helper method to remove a client connection from ChromotingHost. 177 // Helper method to remove a client connection from ChromotingHost.
189 void RemoveClientConnection() { 178 void RemoveClientConnection() {
190 context_.network_message_loop()->PostTask( 179 context_.network_message_loop()->PostTask(
191 FROM_HERE, 180 FROM_HERE,
192 NewRunnableMethod(host_.get(), 181 NewRunnableMethod(host_.get(),
193 &ChromotingHost::OnClientDisconnected, 182 &ChromotingHost::OnClientDisconnected,
194 connection_)); 183 connection_));
195 } 184 }
196 185
186 UserAuthenticator* user_authenticator() {
187 return user_authenticator_.get();
188 }
189
197 protected: 190 protected:
198 MessageLoop message_loop_; 191 MessageLoop message_loop_;
199 MockConnectionToClientEventHandler handler_; 192 MockConnectionToClientEventHandler handler_;
200 scoped_refptr<ChromotingHost> host_; 193 scoped_refptr<ChromotingHost> host_;
201 scoped_refptr<InMemoryHostConfig> config_; 194 scoped_refptr<InMemoryHostConfig> config_;
202 MockChromotingHostContext context_; 195 MockChromotingHostContext context_;
203 protocol::LocalLoginCredentials credentials_good_; 196 protocol::LocalLoginCredentials credentials_;
204 protocol::LocalLoginCredentials credentials_bad_;
205 scoped_refptr<MockConnectionToClient> connection_; 197 scoped_refptr<MockConnectionToClient> connection_;
206 scoped_refptr<MockSession> session_; 198 scoped_refptr<MockSession> session_;
207 scoped_ptr<SessionConfig> session_config_; 199 scoped_ptr<SessionConfig> session_config_;
208 MockVideoStub video_stub_; 200 MockVideoStub video_stub_;
209 MockClientStub client_stub_; 201 MockClientStub client_stub_;
210 MockHostStub* host_stub_; 202 MockHostStub* host_stub_;
211 MockInputStub* input_stub_; 203 MockEventExecutor* event_executor_;
212 MockCurtain* curtain_; 204 MockCurtain* curtain_;
213 scoped_refptr<MockConnectionToClient> connection2_; 205 scoped_refptr<MockConnectionToClient> connection2_;
214 scoped_refptr<MockSession> session2_; 206 scoped_refptr<MockSession> session2_;
207 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
215 scoped_ptr<SessionConfig> session_config2_; 208 scoped_ptr<SessionConfig> session_config2_;
216 MockVideoStub video_stub2_; 209 MockVideoStub video_stub2_;
217 MockClientStub client_stub2_; 210 MockClientStub client_stub2_;
218 MockHostStub* host_stub2_; 211 MockHostStub* host_stub2_;
219 MockInputStub* input_stub2_; 212 MockEventExecutor* event_executor2_;
220 }; 213 };
221 214
222 TEST_F(ChromotingHostTest, StartAndShutdown) { 215 TEST_F(ChromotingHostTest, StartAndShutdown) {
223 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); 216 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
224 217
225 message_loop_.PostTask(FROM_HERE, 218 message_loop_.PostTask(FROM_HERE,
226 NewRunnableMethod(host_.get(), 219 NewRunnableMethod(host_.get(),
227 &ChromotingHost::Shutdown)); 220 &ChromotingHost::Shutdown));
228 message_loop_.Run(); 221 message_loop_.Run();
229 } 222 }
230 223
231 TEST_F(ChromotingHostTest, Connect) { 224 TEST_F(ChromotingHostTest, Connect) {
232 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); 225 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
233 226
234 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) 227 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
235 .WillOnce(RunDoneTask()); 228 .WillOnce(RunDoneTask());
229 EXPECT_CALL(*user_authenticator_, Authenticate(_, _))
230 .WillOnce(Return(true));
236 231
237 // When the video packet is received we first shutdown ChromotingHost 232 // When the video packet is received we first shutdown ChromotingHost
238 // then execute the done task. 233 // then execute the done task.
239 InSequence s; 234 InSequence s;
240 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) 235 EXPECT_CALL(*curtain_, EnableCurtainMode(true))
241 .Times(1); 236 .Times(1);
242 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 237 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
243 .WillOnce(DoAll( 238 .WillOnce(DoAll(
244 InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown), 239 InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown),
245 RunDoneTask())) 240 RunDoneTask()))
246 .RetiresOnSaturation(); 241 .RetiresOnSaturation();
247 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 242 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
248 .Times(AnyNumber()); 243 .Times(AnyNumber());
249 EXPECT_CALL(*connection_.get(), Disconnect()) 244 EXPECT_CALL(*connection_.get(), Disconnect())
250 .RetiresOnSaturation(); 245 .RetiresOnSaturation();
251 246 SimulateClientConnection(0);
252 SimulateClientConnection(0, true);
253 message_loop_.Run(); 247 message_loop_.Run();
254 } 248 }
255 249
256 TEST_F(ChromotingHostTest, Reconnect) { 250 TEST_F(ChromotingHostTest, Reconnect) {
257 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); 251 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
258 252
259 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) 253 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
260 .Times(2) 254 .Times(2)
261 .WillRepeatedly(RunDoneTask()); 255 .WillRepeatedly(RunDoneTask());
256 EXPECT_CALL(*user_authenticator_, Authenticate(_, _))
257 .Times(2)
258 .WillRepeatedly(Return(true));
262 259
263 // When the video packet is received we first disconnect the mock 260 // When the video packet is received we first disconnect the mock
264 // connection. 261 // connection.
265 { 262 {
266 InSequence s; 263 InSequence s;
267 // Ensure that curtain mode is activated before the first video packet. 264 // Ensure that curtain mode is activated before the first video packet.
268 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) 265 EXPECT_CALL(*curtain_, EnableCurtainMode(true))
269 .Times(1); 266 .Times(1);
270 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 267 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
271 .WillOnce(DoAll( 268 .WillOnce(DoAll(
272 InvokeWithoutArgs(this, 269 InvokeWithoutArgs(this,
273 &ChromotingHostTest::RemoveClientConnection), 270 &ChromotingHostTest::RemoveClientConnection),
274 RunDoneTask())) 271 RunDoneTask()))
275 .RetiresOnSaturation(); 272 .RetiresOnSaturation();
276 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 273 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
277 .Times(AnyNumber()); 274 .Times(AnyNumber());
278 EXPECT_CALL(*curtain_, EnableCurtainMode(false)) 275 EXPECT_CALL(*curtain_, EnableCurtainMode(false))
279 .Times(1); 276 .Times(1);
280 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 277 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
281 .Times(AnyNumber()); 278 .Times(AnyNumber());
282 } 279 }
283 280
284 // If Disconnect() is called we can break the main message loop. 281 // If Disconnect() is called we can break the main message loop.
285 EXPECT_CALL(*connection_.get(), Disconnect()) 282 EXPECT_CALL(*connection_.get(), Disconnect())
286 .WillOnce(QuitMainMessageLoop(&message_loop_)) 283 .WillOnce(QuitMainMessageLoop(&message_loop_))
287 .RetiresOnSaturation(); 284 .RetiresOnSaturation();
288 285
289 SimulateClientConnection(0, true); 286 SimulateClientConnection(0);
290 message_loop_.Run(); 287 message_loop_.Run();
291 288
292 // Connect the client again. 289 // Connect the client again.
293 { 290 {
294 InSequence s; 291 InSequence s;
295 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) 292 EXPECT_CALL(*curtain_, EnableCurtainMode(true))
296 .Times(1); 293 .Times(1);
297 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 294 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
298 .WillOnce(DoAll( 295 .WillOnce(DoAll(
299 InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown), 296 InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown),
300 RunDoneTask())) 297 RunDoneTask()))
301 .RetiresOnSaturation(); 298 .RetiresOnSaturation();
302 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 299 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
303 .Times(AnyNumber()); 300 .Times(AnyNumber());
304 } 301 }
305 EXPECT_CALL(*connection_.get(), Disconnect()) 302 EXPECT_CALL(*connection_.get(), Disconnect())
306 .RetiresOnSaturation(); 303 .RetiresOnSaturation();
307 304
308 SimulateClientConnection(0, true); 305 SimulateClientConnection(0);
309 message_loop_.Run(); 306 message_loop_.Run();
310 } 307 }
311 308
312 TEST_F(ChromotingHostTest, ConnectTwice) { 309 TEST_F(ChromotingHostTest, ConnectTwice) {
313 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); 310 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
314 311
315 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) 312 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
316 .Times(1) 313 .Times(1)
317 .WillRepeatedly(RunDoneTask()); 314 .WillRepeatedly(RunDoneTask());
318 315
319 EXPECT_CALL(client_stub2_, BeginSessionResponse(_, _)) 316 EXPECT_CALL(client_stub2_, BeginSessionResponse(_, _))
320 .Times(1) 317 .Times(1)
321 .WillRepeatedly(RunDoneTask()); 318 .WillRepeatedly(RunDoneTask());
322 319
320 EXPECT_CALL(*user_authenticator_, Authenticate(_, _))
321 .Times(2)
322 .WillRepeatedly(Return(true));
323
323 // When a video packet is received we connect the second mock 324 // When a video packet is received we connect the second mock
324 // connection. 325 // connection.
325 { 326 {
326 InSequence s; 327 InSequence s;
327 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) 328 EXPECT_CALL(*curtain_, EnableCurtainMode(true))
328 .Times(1) 329 .Times(1)
329 .WillOnce(QuitMainMessageLoop(&message_loop_)); 330 .WillOnce(QuitMainMessageLoop(&message_loop_));
330 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 331 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
331 .WillOnce(DoAll( 332 .WillOnce(DoAll(
332 InvokeWithoutArgs( 333 InvokeWithoutArgs(
333 CreateFunctor( 334 CreateFunctor(
334 this, 335 this,
335 &ChromotingHostTest::SimulateClientConnection, 1, true)), 336 &ChromotingHostTest::SimulateClientConnection, 1)),
336 RunDoneTask())) 337 RunDoneTask()))
337 .RetiresOnSaturation(); 338 .RetiresOnSaturation();
338 // Check that the second connection does not affect curtain mode. 339 // Check that the second connection does not affect curtain mode.
339 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) 340 EXPECT_CALL(*curtain_, EnableCurtainMode(_))
340 .Times(0); 341 .Times(0);
341 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 342 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
342 .Times(AnyNumber()); 343 .Times(AnyNumber());
343 EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _)) 344 EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _))
344 .WillOnce(DoAll( 345 .WillOnce(DoAll(
345 InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown), 346 InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown),
346 RunDoneTask())) 347 RunDoneTask()))
347 .RetiresOnSaturation(); 348 .RetiresOnSaturation();
348 EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _)) 349 EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _))
349 .Times(AnyNumber()); 350 .Times(AnyNumber());
350 } 351 }
351 352
352 EXPECT_CALL(*connection_.get(), Disconnect()) 353 EXPECT_CALL(*connection_.get(), Disconnect())
353 .RetiresOnSaturation(); 354 .RetiresOnSaturation();
354 EXPECT_CALL(*connection2_.get(), Disconnect()) 355 EXPECT_CALL(*connection2_.get(), Disconnect())
355 .RetiresOnSaturation(); 356 .RetiresOnSaturation();
356 357
357 SimulateClientConnection(0, true); 358 SimulateClientConnection(0);
358 message_loop_.Run(); 359 message_loop_.Run();
359 } 360 }
360 361
361 TEST_F(ChromotingHostTest, CurtainModeFail) { 362 TEST_F(ChromotingHostTest, CurtainModeFail) {
362 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); 363 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
363 364
364 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) 365 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
365 .Times(1) 366 .WillOnce(RunDoneTask());
366 .WillRepeatedly(RunDoneTask()); 367 EXPECT_CALL(*user_authenticator_, Authenticate(_, _))
368 .WillOnce(Return(false));
367 369
368 // Ensure that curtain mode is not activated if a connection does not 370 // Ensure that curtain mode is not activated if a connection does not
369 // authenticate. 371 // authenticate.
370 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) 372 EXPECT_CALL(*curtain_, EnableCurtainMode(_))
371 .Times(0); 373 .Times(0);
372 EXPECT_CALL(*connection_.get(), Disconnect()) 374 EXPECT_CALL(*connection_.get(), Disconnect())
373 .WillOnce(QuitMainMessageLoop(&message_loop_)); 375 .WillOnce(QuitMainMessageLoop(&message_loop_));
374 SimulateClientConnection(0, false); 376 SimulateClientConnection(0);
375 RemoveClientConnection(); 377 RemoveClientConnection();
376 message_loop_.Run(); 378 message_loop_.Run();
377 } 379 }
378 380
379 TEST_F(ChromotingHostTest, CurtainModeFailSecond) { 381 TEST_F(ChromotingHostTest, CurtainModeFailSecond) {
380 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_)); 382 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
381 383
382 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _)) 384 EXPECT_CALL(client_stub_, BeginSessionResponse(_, _))
383 .Times(1) 385 .WillOnce(RunDoneTask());
384 .WillRepeatedly(RunDoneTask());
385 386
386 EXPECT_CALL(client_stub2_, BeginSessionResponse(_, _)) 387 EXPECT_CALL(client_stub2_, BeginSessionResponse(_, _))
387 .Times(1) 388 .WillOnce(RunDoneTask());
388 .WillRepeatedly(RunDoneTask()); 389
390 EXPECT_CALL(*user_authenticator_, Authenticate(_, _))
391 .WillOnce(Return(true))
392 .WillOnce(Return(false));
389 393
390 // When a video packet is received we connect the second mock 394 // When a video packet is received we connect the second mock
391 // connection. 395 // connection.
392 { 396 {
393 InSequence s; 397 InSequence s;
394 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) 398 EXPECT_CALL(*curtain_, EnableCurtainMode(true))
395 .Times(1)
396 .WillOnce(QuitMainMessageLoop(&message_loop_)); 399 .WillOnce(QuitMainMessageLoop(&message_loop_));
397 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 400 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
398 .WillOnce(DoAll( 401 .WillOnce(DoAll(
399 InvokeWithoutArgs( 402 InvokeWithoutArgs(
400 CreateFunctor( 403 CreateFunctor(
401 this, 404 this,
402 &ChromotingHostTest::SimulateClientConnection, 1, false)), 405 &ChromotingHostTest::SimulateClientConnection, 1)),
403 RunDoneTask())) 406 RunDoneTask()))
404 .RetiresOnSaturation(); 407 .RetiresOnSaturation();
405 // Check that the second connection does not affect curtain mode. 408 // Check that the second connection does not affect curtain mode.
406 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) 409 EXPECT_CALL(*curtain_, EnableCurtainMode(_))
407 .Times(0); 410 .Times(0);
408 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) 411 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
409 .Times(AnyNumber()); 412 .Times(AnyNumber());
410 EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _)) 413 EXPECT_CALL(video_stub2_, ProcessVideoPacket(_, _))
411 .Times(0); 414 .Times(0);
412 } 415 }
413 416
414 SimulateClientConnection(0, true); 417 SimulateClientConnection(0);
415 message_loop_.Run(); 418 message_loop_.Run();
416 } 419 }
417 420
418 } // namespace remoting 421 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698