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

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: CR feedback. 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
« no previous file with comments | « remoting/host/client_session.cc ('k') | no next file » | 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) 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 Expectation authenticated =
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 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 255 .After(authenticated);
256 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
257 .After(authenticated);
256 258
257 // Wait for the first video packet to be captured to make sure that 259 // 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 260 // the injected input will go though. Otherwise mouse events will be blocked
259 // by the mouse clamping filter. 261 // by the mouse clamping filter.
262 Sequence s;
260 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 263 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
264 .InSequence(s)
265 .After(authenticated)
261 .WillOnce(DoAll( 266 .WillOnce(DoAll(
262 // This event should get through to the clipboard stub. 267 // This event should get through to the clipboard stub.
263 InjectClipboardEvent(connection_, clipboard_event2), 268 InjectClipboardEvent(connection_, clipboard_event2),
264 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 269 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
265 // This event should not get through to the clipboard stub, 270 // This event should not get through to the clipboard stub,
266 // because the client has disconnected. 271 // because the client has disconnected.
267 InjectClipboardEvent(connection_, clipboard_event3), 272 InjectClipboardEvent(connection_, clipboard_event3),
268 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 273 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
269 EXPECT_CALL(*event_executor_, InjectClipboardEvent(EqualsClipboardEvent( 274 EXPECT_CALL(*event_executor_, InjectClipboardEvent(EqualsClipboardEvent(
270 kMimeTypeTextUtf8, "b"))); 275 kMimeTypeTextUtf8, "b")))
271 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 276 .InSequence(s);
277 EXPECT_CALL(session_event_handler_, OnSessionClosed(_))
278 .InSequence(s);
272 279
273 // This event should not get through to the clipboard stub, 280 // This event should not get through to the clipboard stub,
274 // because the client isn't authenticated yet. 281 // because the client isn't authenticated yet.
275 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1); 282 connection_->clipboard_stub()->InjectClipboardEvent(clipboard_event1);
276 283
277 ConnectClientSession(); 284 ConnectClientSession();
278 message_loop_.Run(); 285 message_loop_.Run();
279 } 286 }
280 287
281 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") { 288 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 mouse_event1.set_y(101); 320 mouse_event1.set_y(101);
314 321
315 protocol::MouseEvent mouse_event2; 322 protocol::MouseEvent mouse_event2;
316 mouse_event2.set_x(200); 323 mouse_event2.set_x(200);
317 mouse_event2.set_y(201); 324 mouse_event2.set_y(201);
318 325
319 protocol::MouseEvent mouse_event3; 326 protocol::MouseEvent mouse_event3;
320 mouse_event3.set_x(300); 327 mouse_event3.set_x(300);
321 mouse_event3.set_y(301); 328 mouse_event3.set_y(301);
322 329
323 InSequence s; 330 Expectation authenticated =
324 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 331 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
325 EXPECT_CALL(*event_executor_, StartPtr(_)); 332 EXPECT_CALL(*event_executor_, StartPtr(_))
326 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 333 .After(authenticated);
334 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
335 .After(authenticated);
327 336
328 // Wait for the first video packet to be captured to make sure that 337 // 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 338 // the injected input will go though. Otherwise mouse events will be blocked
330 // by the mouse clamping filter. 339 // by the mouse clamping filter.
340 Sequence s;
331 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 341 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
342 .InSequence(s)
343 .After(authenticated)
332 .WillOnce(DoAll( 344 .WillOnce(DoAll(
333 // These events should get through to the input stub. 345 // These events should get through to the input stub.
334 InjectKeyEvent(connection_, key_event2_down), 346 InjectKeyEvent(connection_, key_event2_down),
335 InjectKeyEvent(connection_, key_event2_up), 347 InjectKeyEvent(connection_, key_event2_up),
336 InjectMouseEvent(connection_, mouse_event2), 348 InjectMouseEvent(connection_, mouse_event2),
337 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 349 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
338 // These events should not get through to the input stub, 350 // These events should not get through to the input stub,
339 // because the client has disconnected. 351 // because the client has disconnected.
340 InjectKeyEvent(connection_, key_event3), 352 InjectKeyEvent(connection_, key_event3),
341 InjectMouseEvent(connection_, mouse_event3), 353 InjectMouseEvent(connection_, mouse_event3),
342 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 354 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
343 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))); 355 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true)))
344 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))); 356 .InSequence(s);
345 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))); 357 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false)))
346 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 358 .InSequence(s);
359 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201)))
360 .InSequence(s);
361 EXPECT_CALL(session_event_handler_, OnSessionClosed(_))
362 .InSequence(s);
347 363
348 // These events should not get through to the input stub, 364 // These events should not get through to the input stub,
349 // because the client isn't authenticated yet. 365 // because the client isn't authenticated yet.
350 connection_->input_stub()->InjectKeyEvent(key_event1); 366 connection_->input_stub()->InjectKeyEvent(key_event1);
351 connection_->input_stub()->InjectMouseEvent(mouse_event1); 367 connection_->input_stub()->InjectMouseEvent(mouse_event1);
352 368
353 ConnectClientSession(); 369 ConnectClientSession();
354 message_loop_.Run(); 370 message_loop_.Run();
355 } 371 }
356 372
357 TEST_F(ClientSessionTest, LocalInputTest) { 373 TEST_F(ClientSessionTest, LocalInputTest) {
358 protocol::MouseEvent mouse_event1; 374 protocol::MouseEvent mouse_event1;
359 mouse_event1.set_x(100); 375 mouse_event1.set_x(100);
360 mouse_event1.set_y(101); 376 mouse_event1.set_y(101);
361 protocol::MouseEvent mouse_event2; 377 protocol::MouseEvent mouse_event2;
362 mouse_event2.set_x(200); 378 mouse_event2.set_x(200);
363 mouse_event2.set_y(201); 379 mouse_event2.set_y(201);
364 protocol::MouseEvent mouse_event3; 380 protocol::MouseEvent mouse_event3;
365 mouse_event3.set_x(300); 381 mouse_event3.set_x(300);
366 mouse_event3.set_y(301); 382 mouse_event3.set_y(301);
367 383
368 InSequence s; 384 Expectation authenticated =
369 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 385 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
370 EXPECT_CALL(*event_executor_, StartPtr(_)); 386 EXPECT_CALL(*event_executor_, StartPtr(_))
371 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 387 .After(authenticated);
388 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
389 .After(authenticated);
372 390
373 // Wait for the first video packet to be captured to make sure that 391 // 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 392 // the injected input will go though. Otherwise mouse events will be blocked
375 // by the mouse clamping filter. 393 // by the mouse clamping filter.
394 Sequence s;
376 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 395 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
396 .InSequence(s)
397 .After(authenticated)
377 .WillOnce(DoAll( 398 .WillOnce(DoAll(
378 // This event should get through to the input stub. 399 // This event should get through to the input stub.
379 InjectMouseEvent(connection_, mouse_event1), 400 InjectMouseEvent(connection_, mouse_event1),
380 #if !defined(OS_WIN) 401 #if !defined(OS_WIN)
381 // The OS echoes the injected event back. 402 // The OS echoes the injected event back.
382 LocalMouseMoved(client_session_.get(), mouse_event1), 403 LocalMouseMoved(client_session_.get(), mouse_event1),
383 #endif // !defined(OS_WIN) 404 #endif // !defined(OS_WIN)
384 // This one should get throught as well. 405 // This one should get throught as well.
385 InjectMouseEvent(connection_, mouse_event2), 406 InjectMouseEvent(connection_, mouse_event2),
386 // Now this is a genuine local event. 407 // Now this is a genuine local event.
387 LocalMouseMoved(client_session_.get(), mouse_event1), 408 LocalMouseMoved(client_session_.get(), mouse_event1),
388 // This one should be blocked because of the previous local input 409 // This one should be blocked because of the previous local input
389 // event. 410 // event.
390 InjectMouseEvent(connection_, mouse_event3), 411 InjectMouseEvent(connection_, mouse_event3),
391 // TODO(jamiewalch): Verify that remote inputs are re-enabled 412 // TODO(jamiewalch): Verify that remote inputs are re-enabled
392 // eventually (via dependency injection, not sleep!) 413 // eventually (via dependency injection, not sleep!)
393 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 414 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
394 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 415 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
395 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(100, 101))); 416 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(100, 101)))
396 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201))); 417 .InSequence(s);
397 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 418 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseEvent(200, 201)))
419 .InSequence(s);
420 EXPECT_CALL(session_event_handler_, OnSessionClosed(_))
421 .InSequence(s);
398 422
399 ConnectClientSession(); 423 ConnectClientSession();
400 message_loop_.Run(); 424 message_loop_.Run();
401 } 425 }
402 426
403 TEST_F(ClientSessionTest, RestoreEventState) { 427 TEST_F(ClientSessionTest, RestoreEventState) {
404 protocol::KeyEvent key1; 428 protocol::KeyEvent key1;
405 key1.set_pressed(true); 429 key1.set_pressed(true);
406 key1.set_usb_keycode(1); 430 key1.set_usb_keycode(1);
407 431
408 protocol::KeyEvent key2; 432 protocol::KeyEvent key2;
409 key2.set_pressed(true); 433 key2.set_pressed(true);
410 key2.set_usb_keycode(2); 434 key2.set_usb_keycode(2);
411 435
412 protocol::MouseEvent mousedown; 436 protocol::MouseEvent mousedown;
413 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); 437 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT);
414 mousedown.set_button_down(true); 438 mousedown.set_button_down(true);
415 439
416 InSequence s; 440 Expectation authenticated =
417 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 441 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
418 EXPECT_CALL(*event_executor_, StartPtr(_)); 442 EXPECT_CALL(*event_executor_, StartPtr(_))
419 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 443 .After(authenticated);
444 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
445 .After(authenticated);
420 446
421 // Wait for the first video packet to be captured to make sure that 447 // 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 448 // the injected input will go though. Otherwise mouse events will be blocked
423 // by the mouse clamping filter. 449 // by the mouse clamping filter.
450 Sequence s;
424 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 451 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
452 .InSequence(s)
453 .After(authenticated)
425 .WillOnce(DoAll( 454 .WillOnce(DoAll(
426 InjectKeyEvent(connection_, key1), 455 InjectKeyEvent(connection_, key1),
427 InjectKeyEvent(connection_, key2), 456 InjectKeyEvent(connection_, key2),
428 InjectMouseEvent(connection_, mousedown), 457 InjectMouseEvent(connection_, mousedown),
429 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 458 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
430 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 459 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
431 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, true))); 460 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, true)))
432 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true))); 461 .InSequence(s);
462 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, true)))
463 .InSequence(s);
433 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( 464 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent(
434 protocol::MouseEvent::BUTTON_LEFT, true))); 465 protocol::MouseEvent::BUTTON_LEFT, true)))
435 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, false))); 466 .InSequence(s);
436 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false))); 467 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(1, false)))
468 .InSequence(s);
469 EXPECT_CALL(*event_executor_, InjectKeyEvent(EqualsUsbEvent(2, false)))
470 .InSequence(s);
437 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent( 471 EXPECT_CALL(*event_executor_, InjectMouseEvent(EqualsMouseButtonEvent(
438 protocol::MouseEvent::BUTTON_LEFT, false))); 472 protocol::MouseEvent::BUTTON_LEFT, false)))
439 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 473 .InSequence(s);
474 EXPECT_CALL(session_event_handler_, OnSessionClosed(_))
475 .InSequence(s);
440 476
441 ConnectClientSession(); 477 ConnectClientSession();
442 message_loop_.Run(); 478 message_loop_.Run();
443 } 479 }
444 480
445 TEST_F(ClientSessionTest, ClampMouseEvents) { 481 TEST_F(ClientSessionTest, ClampMouseEvents) {
446 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); 482 Expectation authenticated =
447 EXPECT_CALL(*event_executor_, StartPtr(_)); 483 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_));
448 Expectation connected = 484 EXPECT_CALL(*event_executor_, StartPtr(_))
449 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); 485 .After(authenticated);
450 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); 486 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
487 .After(authenticated);
488 EXPECT_CALL(session_event_handler_, OnSessionClosed(_))
489 .After(authenticated);
490
491 Expectation connected = authenticated;
451 492
452 int input_x[3] = { -999, 100, 999 }; 493 int input_x[3] = { -999, 100, 999 };
453 int expected_x[3] = { 0, 100, media::ScreenCapturerFake::kWidth - 1 }; 494 int expected_x[3] = { 0, 100, media::ScreenCapturerFake::kWidth - 1 };
454 int input_y[3] = { -999, 50, 999 }; 495 int input_y[3] = { -999, 50, 999 };
455 int expected_y[3] = { 0, 50, media::ScreenCapturerFake::kHeight - 1 }; 496 int expected_y[3] = { 0, 50, media::ScreenCapturerFake::kHeight - 1 };
456 497
457 protocol::MouseEvent expected_event; 498 protocol::MouseEvent expected_event;
458 for (int j = 0; j < 3; j++) { 499 for (int j = 0; j < 3; j++) {
459 for (int i = 0; i < 3; i++) { 500 for (int i = 0; i < 3; i++) {
460 protocol::MouseEvent injected_event; 501 protocol::MouseEvent injected_event;
(...skipping 29 matching lines...) Expand all
490 .After(connected) 531 .After(connected)
491 .WillOnce(DoAll( 532 .WillOnce(DoAll(
492 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 533 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
493 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 534 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
494 535
495 ConnectClientSession(); 536 ConnectClientSession();
496 message_loop_.Run(); 537 message_loop_.Run();
497 } 538 }
498 539
499 } // namespace remoting 540 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/client_session.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698