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

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

Issue 12544019: Create a desktop environment instance late so that it will see the curtain_required flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased on top of https://chromiumcodereview.appspot.com/12794004/ Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "media/video/capture/screen/screen_capturer_fake.h" 6 #include "media/video/capture/screen/screen_capturer_fake.h"
7 #include "media/video/capture/screen/screen_capturer_mock_objects.h" 7 #include "media/video/capture/screen/screen_capturer_mock_objects.h"
8 #include "remoting/base/auto_thread_task_runner.h" 8 #include "remoting/base/auto_thread_task_runner.h"
9 #include "remoting/base/constants.h" 9 #include "remoting/base/constants.h"
10 #include "remoting/host/audio_capturer.h" 10 #include "remoting/host/audio_capturer.h"
(...skipping 11 matching lines...) Expand all
22 using protocol::MockInputStub; 22 using protocol::MockInputStub;
23 using protocol::MockSession; 23 using protocol::MockSession;
24 using protocol::MockVideoStub; 24 using protocol::MockVideoStub;
25 using protocol::SessionConfig; 25 using protocol::SessionConfig;
26 26
27 using testing::_; 27 using testing::_;
28 using testing::AnyNumber; 28 using testing::AnyNumber;
29 using testing::DeleteArg; 29 using testing::DeleteArg;
30 using testing::DoAll; 30 using testing::DoAll;
31 using testing::Expectation; 31 using testing::Expectation;
32 using testing::InSequence;
33 using testing::Return; 32 using testing::Return;
34 using testing::ReturnRef; 33 using testing::ReturnRef;
34 using testing::Sequence;
35 35
36 namespace { 36 namespace {
37 37
38 ACTION_P2(InjectClipboardEvent, connection, event) { 38 ACTION_P2(InjectClipboardEvent, connection, event) {
39 connection->clipboard_stub()->InjectClipboardEvent(event); 39 connection->clipboard_stub()->InjectClipboardEvent(event);
40 } 40 }
41 41
42 ACTION_P2(InjectKeyEvent, connection, event) { 42 ACTION_P2(InjectKeyEvent, connection, event) {
43 connection->input_stub()->InjectKeyEvent(event); 43 connection->input_stub()->InjectKeyEvent(event);
44 } 44 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 clipboard_event1.set_data("a"); 242 clipboard_event1.set_data("a");
243 243
244 protocol::ClipboardEvent clipboard_event2; 244 protocol::ClipboardEvent clipboard_event2;
245 clipboard_event2.set_mime_type(kMimeTypeTextUtf8); 245 clipboard_event2.set_mime_type(kMimeTypeTextUtf8);
246 clipboard_event2.set_data("b"); 246 clipboard_event2.set_data("b");
247 247
248 protocol::ClipboardEvent clipboard_event3; 248 protocol::ClipboardEvent clipboard_event3;
249 clipboard_event3.set_mime_type(kMimeTypeTextUtf8); 249 clipboard_event3.set_mime_type(kMimeTypeTextUtf8);
250 clipboard_event3.set_data("c"); 250 clipboard_event3.set_data("c");
251 251
252 InSequence s; 252 Sequence s;
253 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 253 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
254 EXPECT_CALL(*event_executor_, StartPtr(_)); 254 EXPECT_CALL(*event_executor_, StartPtr(_))
255 .InSequence(s);
255 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 256 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
256 257
257 // Wait for the first video packet to be captured to make sure that 258 // Wait for the first video packet to be captured to make sure that
258 // the injected input will go though. Otherwise mouse events will be blocked 259 // the injected input will go though. Otherwise mouse events will be blocked
259 // by the mouse clamping filter. 260 // by the mouse clamping filter.
260 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 261 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
262 .InSequence(s)
Wez 2013/03/14 04:15:54 Aren't you effectively saying that you expect the
alexeypa (please no reviews) 2013/03/14 19:09:06 It is not guaranteed if we assume that video sched
Wez 2013/03/15 00:15:26 nit: If you instead save the OnSessionAuthenticate
alexeypa (please no reviews) 2013/03/15 00:28:02 Done.
261 .WillOnce(DoAll( 263 .WillOnce(DoAll(
262 // This event should get through to the clipboard stub. 264 // This event should get through to the clipboard stub.
263 InjectClipboardEvent(connection_, clipboard_event2), 265 InjectClipboardEvent(connection_, clipboard_event2),
264 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 266 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
265 // This event should not get through to the clipboard stub, 267 // This event should not get through to the clipboard stub,
266 // because the client has disconnected. 268 // because the client has disconnected.
267 InjectClipboardEvent(connection_, clipboard_event3), 269 InjectClipboardEvent(connection_, clipboard_event3),
268 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 270 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
269 EXPECT_CALL(*event_executor_, InjectClipboardEvent(EqualsClipboardEvent( 271 EXPECT_CALL(*event_executor_, InjectClipboardEvent(EqualsClipboardEvent(
270 kMimeTypeTextUtf8, "b"))); 272 kMimeTypeTextUtf8, "b")))
271 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 273 .InSequence(s);
274 EXPECT_CALL(session_event_handler_, OnSessionClosed(_))
275 .InSequence(s);
272 276
273 // This event should not get through to the clipboard stub, 277 // This event should not get through to the clipboard stub,
274 // because the client isn't authenticated yet. 278 // because the client isn't authenticated yet.
275 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1); 279 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1);
276 280
277 ConnectClientSession(); 281 ConnectClientSession();
278 message_loop_.Run(); 282 message_loop_.Run();
279 } 283 }
280 284
281 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") { 285 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 mouse_event1.set_y(101); 317 mouse_event1.set_y(101);
314 318
315 protocol::MouseEvent mouse_event2; 319 protocol::MouseEvent mouse_event2;
316 mouse_event2.set_x(200); 320 mouse_event2.set_x(200);
317 mouse_event2.set_y(201); 321 mouse_event2.set_y(201);
318 322
319 protocol::MouseEvent mouse_event3; 323 protocol::MouseEvent mouse_event3;
320 mouse_event3.set_x(300); 324 mouse_event3.set_x(300);
321 mouse_event3.set_y(301); 325 mouse_event3.set_y(301);
322 326
323 InSequence s; 327 Sequence s;
324 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 328 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
325 EXPECT_CALL(*event_executor_, StartPtr(_)); 329 EXPECT_CALL(*event_executor_, StartPtr(_))
330 .InSequence(s);
326 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 331 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
327 332
328 // Wait for the first video packet to be captured to make sure that 333 // Wait for the first video packet to be captured to make sure that
329 // the injected input will go though. Otherwise mouse events will be blocked 334 // the injected input will go though. Otherwise mouse events will be blocked
330 // by the mouse clamping filter. 335 // by the mouse clamping filter.
331 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 336 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
337 .InSequence(s)
Wez 2013/03/14 04:15:54 See above.
332 .WillOnce(DoAll( 338 .WillOnce(DoAll(
333 // These events should get through to the input stub. 339 // These events should get through to the input stub.
334 InjectKeyEvent(connection_, key_event2_down), 340 InjectKeyEvent(connection_, key_event2_down),
335 InjectKeyEvent(connection_, key_event2_up), 341 InjectKeyEvent(connection_, key_event2_up),
336 InjectMouseEvent(connection_, mouse_event2), 342 InjectMouseEvent(connection_, mouse_event2),
337 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 343 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
338 // These events should not get through to the input stub, 344 // These events should not get through to the input stub,
339 // because the client has disconnected. 345 // because the client has disconnected.
340 InjectKeyEvent(connection_, key_event3), 346 InjectKeyEvent(connection_, key_event3),
341 InjectMouseEvent(connection_, mouse_event3), 347 InjectMouseEvent(connection_, mouse_event3),
342 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 348 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
343 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))); 349 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true)))
344 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))); 350 .InSequence(s);
345 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))); 351 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false)))
346 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 352 .InSequence(s);
353 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201)))
354 .InSequence(s);
355 EXPECT_CALL(session_event_handler_, OnSessionClosed(_))
356 .InSequence(s);
347 357
348 // These events should not get through to the input stub, 358 // These events should not get through to the input stub,
349 // because the client isn't authenticated yet. 359 // because the client isn't authenticated yet.
350 connection_->input_stub()->InjectKeyEvent(key_event1); 360 connection_->input_stub()->InjectKeyEvent(key_event1);
351 connection_->input_stub()->InjectMouseEvent(mouse_event1); 361 connection_->input_stub()->InjectMouseEvent(mouse_event1);
352 362
353 ConnectClientSession(); 363 ConnectClientSession();
354 message_loop_.Run(); 364 message_loop_.Run();
355 } 365 }
356 366
357 TEST_F(ClientSessionTest, LocalInputTest) { 367 TEST_F(ClientSessionTest, LocalInputTest) {
358 protocol::MouseEvent mouse_event1; 368 protocol::MouseEvent mouse_event1;
359 mouse_event1.set_x(100); 369 mouse_event1.set_x(100);
360 mouse_event1.set_y(101); 370 mouse_event1.set_y(101);
361 protocol::MouseEvent mouse_event2; 371 protocol::MouseEvent mouse_event2;
362 mouse_event2.set_x(200); 372 mouse_event2.set_x(200);
363 mouse_event2.set_y(201); 373 mouse_event2.set_y(201);
364 protocol::MouseEvent mouse_event3; 374 protocol::MouseEvent mouse_event3;
365 mouse_event3.set_x(300); 375 mouse_event3.set_x(300);
366 mouse_event3.set_y(301); 376 mouse_event3.set_y(301);
367 377
368 InSequence s; 378 Sequence s;
369 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 379 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
370 EXPECT_CALL(*event_executor_, StartPtr(_)); 380 EXPECT_CALL(*event_executor_, StartPtr(_))
381 .InSequence(s);
371 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 382 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
372 383
373 // Wait for the first video packet to be captured to make sure that 384 // Wait for the first video packet to be captured to make sure that
374 // the injected input will go though. Otherwise mouse events will be blocked 385 // the injected input will go though. Otherwise mouse events will be blocked
375 // by the mouse clamping filter. 386 // by the mouse clamping filter.
376 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 387 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
388 .InSequence(s)
Wez 2013/03/14 04:15:54 See above.
377 .WillOnce(DoAll( 389 .WillOnce(DoAll(
378 // This event should get through to the input stub. 390 // This event should get through to the input stub.
379 InjectMouseEvent(connection_, mouse_event1), 391 InjectMouseEvent(connection_, mouse_event1),
380 #if !defined(OS_WIN) 392 #if !defined(OS_WIN)
381 // The OS echoes the injected event back. 393 // The OS echoes the injected event back.
382 LocalMouseMoved(client_session_.get(), mouse_event1), 394 LocalMouseMoved(client_session_.get(), mouse_event1),
383 #endif // !defined(OS_WIN) 395 #endif // !defined(OS_WIN)
384 // This one should get throught as well. 396 // This one should get throught as well.
385 InjectMouseEvent(connection_, mouse_event2), 397 InjectMouseEvent(connection_, mouse_event2),
386 // Now this is a genuine local event. 398 // Now this is a genuine local event.
387 LocalMouseMoved(client_session_.get(), mouse_event1), 399 LocalMouseMoved(client_session_.get(), mouse_event1),
388 // This one should be blocked because of the previous local input 400 // This one should be blocked because of the previous local input
389 // event. 401 // event.
390 InjectMouseEvent(connection_, mouse_event3), 402 InjectMouseEvent(connection_, mouse_event3),
391 // TODO(jamiewalch): Verify that remote inputs are re-enabled 403 // TODO(jamiewalch): Verify that remote inputs are re-enabled
392 // eventually (via dependency injection, not sleep!) 404 // eventually (via dependency injection, not sleep!)
393 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 405 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
394 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 406 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
395 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(100, 101))); 407 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(100, 101)))
396 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))); 408 .InSequence(s);
397 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 409 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201)))
410 .InSequence(s);
411 EXPECT_CALL(session_event_handler_, OnSessionClosed(_))
412 .InSequence(s);
398 413
399 ConnectClientSession(); 414 ConnectClientSession();
400 message_loop_.Run(); 415 message_loop_.Run();
401 } 416 }
402 417
403 TEST_F(ClientSessionTest, RestoreEventState) { 418 TEST_F(ClientSessionTest, RestoreEventState) {
404 protocol::KeyEvent key1; 419 protocol::KeyEvent key1;
405 key1.set_pressed(true); 420 key1.set_pressed(true);
406 key1.set_usb_keycode(1); 421 key1.set_usb_keycode(1);
407 422
408 protocol::KeyEvent key2; 423 protocol::KeyEvent key2;
409 key2.set_pressed(true); 424 key2.set_pressed(true);
410 key2.set_usb_keycode(2); 425 key2.set_usb_keycode(2);
411 426
412 protocol::MouseEvent mousedown; 427 protocol::MouseEvent mousedown;
413 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); 428 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT);
414 mousedown.set_button_down(true); 429 mousedown.set_button_down(true);
415 430
416 InSequence s; 431 Sequence s;
417 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 432 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
418 EXPECT_CALL(*event_executor_, StartPtr(_)); 433 EXPECT_CALL(*event_executor_, StartPtr(_))
434 .InSequence(s);
419 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 435 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
420 436
421 // Wait for the first video packet to be captured to make sure that 437 // Wait for the first video packet to be captured to make sure that
422 // the injected input will go though. Otherwise mouse events will be blocked 438 // the injected input will go though. Otherwise mouse events will be blocked
423 // by the mouse clamping filter. 439 // by the mouse clamping filter.
424 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 440 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
441 .InSequence(s)
Wez 2013/03/14 04:15:54 See above.
425 .WillOnce(DoAll( 442 .WillOnce(DoAll(
426 InjectKeyEvent(connection_, key1), 443 InjectKeyEvent(connection_, key1),
427 InjectKeyEvent(connection_, key2), 444 InjectKeyEvent(connection_, key2),
428 InjectMouseEvent(connection_, mousedown), 445 InjectMouseEvent(connection_, mousedown),
429 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 446 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
430 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 447 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
431 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, true))); 448 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, true)))
432 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))); 449 .InSequence(s);
450 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true)))
451 .InSequence(s);
433 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( 452 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent(
434 protocol::MouseEvent::BUTTON_LEFT, true))); 453 protocol::MouseEvent::BUTTON_LEFT, true)))
435 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, false))); 454 .InSequence(s);
436 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))); 455 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, false)))
456 .InSequence(s);
457 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false)))
458 .InSequence(s);
437 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( 459 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent(
438 protocol::MouseEvent::BUTTON_LEFT, false))); 460 protocol::MouseEvent::BUTTON_LEFT, false)))
439 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 461 .InSequence(s);
462 EXPECT_CALL(session_event_handler_, OnSessionClosed(_))
463 .InSequence(s);
440 464
441 ConnectClientSession(); 465 ConnectClientSession();
442 message_loop_.Run(); 466 message_loop_.Run();
443 } 467 }
444 468
445 TEST_F(ClientSessionTest, ClampMouseEvents) { 469 TEST_F(ClientSessionTest, ClampMouseEvents) {
446 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 470 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
447 EXPECT_CALL(*event_executor_, StartPtr(_)); 471 EXPECT_CALL(*event_executor_, StartPtr(_));
448 Expectation connected = 472 Expectation connected =
449 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 473 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 .After(connected) 514 .After(connected)
491 .WillOnce(DoAll( 515 .WillOnce(DoAll(
492 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 516 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
493 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 517 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
494 518
495 ConnectClientSession(); 519 ConnectClientSession();
496 message_loop_.Run(); 520 message_loop_.Run();
497 } 521 }
498 522
499 } // namespace remoting 523 } // namespace remoting
OLDNEW
« remoting/host/client_session.cc ('K') | « remoting/host/client_session.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698