| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory( | 395 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory( |
| 396 new MockDesktopEnvironmentFactory()); | 396 new MockDesktopEnvironmentFactory()); |
| 397 EXPECT_CALL(*desktop_environment_factory, CreatePtr()) | 397 EXPECT_CALL(*desktop_environment_factory, CreatePtr()) |
| 398 .Times(AnyNumber()) | 398 .Times(AnyNumber()) |
| 399 .WillRepeatedly(Invoke( | 399 .WillRepeatedly(Invoke( |
| 400 this, &IpcDesktopEnvironmentTest::CreateDesktopEnvironment)); | 400 this, &IpcDesktopEnvironmentTest::CreateDesktopEnvironment)); |
| 401 EXPECT_CALL(*desktop_environment_factory, SupportsAudioCapture()) | 401 EXPECT_CALL(*desktop_environment_factory, SupportsAudioCapture()) |
| 402 .Times(AnyNumber()) | 402 .Times(AnyNumber()) |
| 403 .WillRepeatedly(Return(false)); | 403 .WillRepeatedly(Return(false)); |
| 404 | 404 |
| 405 EXPECT_TRUE(desktop_process_->Start( | 405 EXPECT_TRUE(desktop_process_->Start(desktop_environment_factory.Pass())); |
| 406 desktop_environment_factory.PassAs<DesktopEnvironmentFactory>())); | |
| 407 } | 406 } |
| 408 | 407 |
| 409 void IpcDesktopEnvironmentTest::DestoyDesktopProcess() { | 408 void IpcDesktopEnvironmentTest::DestoyDesktopProcess() { |
| 410 desktop_channel_.reset(); | 409 desktop_channel_.reset(); |
| 411 if (desktop_process_) { | 410 if (desktop_process_) { |
| 412 desktop_process_->OnChannelError(); | 411 desktop_process_->OnChannelError(); |
| 413 desktop_process_.reset(); | 412 desktop_process_.reset(); |
| 414 } | 413 } |
| 415 remote_input_injector_ = NULL; | 414 remote_input_injector_ = NULL; |
| 416 } | 415 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 428 } | 427 } |
| 429 | 428 |
| 430 // Runs until the desktop is attached and exits immediately after that. | 429 // Runs until the desktop is attached and exits immediately after that. |
| 431 TEST_F(IpcDesktopEnvironmentTest, Basic) { | 430 TEST_F(IpcDesktopEnvironmentTest, Basic) { |
| 432 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 431 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
| 433 new protocol::MockClipboardStub()); | 432 new protocol::MockClipboardStub()); |
| 434 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 433 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 435 .Times(0); | 434 .Times(0); |
| 436 | 435 |
| 437 // Start the input injector and screen capturer. | 436 // Start the input injector and screen capturer. |
| 438 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 437 input_injector_->Start(clipboard_stub.Pass()); |
| 439 | 438 |
| 440 // Run the message loop until the desktop is attached. | 439 // Run the message loop until the desktop is attached. |
| 441 setup_run_loop_->Run(); | 440 setup_run_loop_->Run(); |
| 442 | 441 |
| 443 // Stop the test. | 442 // Stop the test. |
| 444 DeleteDesktopEnvironment(); | 443 DeleteDesktopEnvironment(); |
| 445 | 444 |
| 446 task_runner_ = NULL; | 445 task_runner_ = NULL; |
| 447 io_task_runner_ = NULL; | 446 io_task_runner_ = NULL; |
| 448 main_run_loop_.Run(); | 447 main_run_loop_.Run(); |
| 449 } | 448 } |
| 450 | 449 |
| 451 // Tests that the video capturer receives a frame over IPC. | 450 // Tests that the video capturer receives a frame over IPC. |
| 452 TEST_F(IpcDesktopEnvironmentTest, CaptureFrame) { | 451 TEST_F(IpcDesktopEnvironmentTest, CaptureFrame) { |
| 453 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 452 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
| 454 new protocol::MockClipboardStub()); | 453 new protocol::MockClipboardStub()); |
| 455 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 454 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 456 .Times(0); | 455 .Times(0); |
| 457 | 456 |
| 458 // Start the input injector and screen capturer. | 457 // Start the input injector and screen capturer. |
| 459 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 458 input_injector_->Start(clipboard_stub.Pass()); |
| 460 video_capturer_->Start(&desktop_capturer_callback_); | 459 video_capturer_->Start(&desktop_capturer_callback_); |
| 461 | 460 |
| 462 // Run the message loop until the desktop is attached. | 461 // Run the message loop until the desktop is attached. |
| 463 setup_run_loop_->Run(); | 462 setup_run_loop_->Run(); |
| 464 | 463 |
| 465 // Stop the test when the first frame is captured. | 464 // Stop the test when the first frame is captured. |
| 466 EXPECT_CALL(desktop_capturer_callback_, OnCaptureCompleted(_)) | 465 EXPECT_CALL(desktop_capturer_callback_, OnCaptureCompleted(_)) |
| 467 .WillOnce(DoAll( | 466 .WillOnce(DoAll( |
| 468 DeleteArg<0>(), | 467 DeleteArg<0>(), |
| 469 InvokeWithoutArgs( | 468 InvokeWithoutArgs( |
| 470 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment))); | 469 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment))); |
| 471 | 470 |
| 472 // Capture a single frame. | 471 // Capture a single frame. |
| 473 video_capturer_->Capture(webrtc::DesktopRegion()); | 472 video_capturer_->Capture(webrtc::DesktopRegion()); |
| 474 | 473 |
| 475 task_runner_ = NULL; | 474 task_runner_ = NULL; |
| 476 io_task_runner_ = NULL; | 475 io_task_runner_ = NULL; |
| 477 main_run_loop_.Run(); | 476 main_run_loop_.Run(); |
| 478 } | 477 } |
| 479 | 478 |
| 480 // Tests that attaching to a new desktop works. | 479 // Tests that attaching to a new desktop works. |
| 481 TEST_F(IpcDesktopEnvironmentTest, Reattach) { | 480 TEST_F(IpcDesktopEnvironmentTest, Reattach) { |
| 482 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 481 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
| 483 new protocol::MockClipboardStub()); | 482 new protocol::MockClipboardStub()); |
| 484 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 483 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 485 .Times(0); | 484 .Times(0); |
| 486 | 485 |
| 487 // Start the input injector and screen capturer. | 486 // Start the input injector and screen capturer. |
| 488 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 487 input_injector_->Start(clipboard_stub.Pass()); |
| 489 video_capturer_->Start(&desktop_capturer_callback_); | 488 video_capturer_->Start(&desktop_capturer_callback_); |
| 490 | 489 |
| 491 // Run the message loop until the desktop is attached. | 490 // Run the message loop until the desktop is attached. |
| 492 setup_run_loop_->Run(); | 491 setup_run_loop_->Run(); |
| 493 | 492 |
| 494 // Create and start a new desktop process object. | 493 // Create and start a new desktop process object. |
| 495 setup_run_loop_.reset(new base::RunLoop()); | 494 setup_run_loop_.reset(new base::RunLoop()); |
| 496 DestoyDesktopProcess(); | 495 DestoyDesktopProcess(); |
| 497 CreateDesktopProcess(); | 496 CreateDesktopProcess(); |
| 498 setup_run_loop_->Run(); | 497 setup_run_loop_->Run(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 511 new protocol::MockClipboardStub()); | 510 new protocol::MockClipboardStub()); |
| 512 clipboard_stub_ = clipboard_stub.get(); | 511 clipboard_stub_ = clipboard_stub.get(); |
| 513 | 512 |
| 514 // Stop the test when a clipboard event is received from the desktop process. | 513 // Stop the test when a clipboard event is received from the desktop process. |
| 515 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 514 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 516 .Times(1) | 515 .Times(1) |
| 517 .WillOnce(InvokeWithoutArgs( | 516 .WillOnce(InvokeWithoutArgs( |
| 518 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); | 517 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 519 | 518 |
| 520 // Start the input injector and screen capturer. | 519 // Start the input injector and screen capturer. |
| 521 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 520 input_injector_->Start(clipboard_stub.Pass()); |
| 522 video_capturer_->Start(&desktop_capturer_callback_); | 521 video_capturer_->Start(&desktop_capturer_callback_); |
| 523 | 522 |
| 524 // Run the message loop until the desktop is attached. | 523 // Run the message loop until the desktop is attached. |
| 525 setup_run_loop_->Run(); | 524 setup_run_loop_->Run(); |
| 526 | 525 |
| 527 // Expect a single clipboard event. | 526 // Expect a single clipboard event. |
| 528 EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_)) | 527 EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_)) |
| 529 .Times(1) | 528 .Times(1) |
| 530 .WillOnce(Invoke(this, | 529 .WillOnce(Invoke(this, |
| 531 &IpcDesktopEnvironmentTest::ReflectClipboardEvent)); | 530 &IpcDesktopEnvironmentTest::ReflectClipboardEvent)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 542 } | 541 } |
| 543 | 542 |
| 544 // Tests injection of key events. | 543 // Tests injection of key events. |
| 545 TEST_F(IpcDesktopEnvironmentTest, InjectKeyEvent) { | 544 TEST_F(IpcDesktopEnvironmentTest, InjectKeyEvent) { |
| 546 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 545 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
| 547 new protocol::MockClipboardStub()); | 546 new protocol::MockClipboardStub()); |
| 548 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 547 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 549 .Times(0); | 548 .Times(0); |
| 550 | 549 |
| 551 // Start the input injector and screen capturer. | 550 // Start the input injector and screen capturer. |
| 552 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 551 input_injector_->Start(clipboard_stub.Pass()); |
| 553 video_capturer_->Start(&desktop_capturer_callback_); | 552 video_capturer_->Start(&desktop_capturer_callback_); |
| 554 | 553 |
| 555 // Run the message loop until the desktop is attached. | 554 // Run the message loop until the desktop is attached. |
| 556 setup_run_loop_->Run(); | 555 setup_run_loop_->Run(); |
| 557 | 556 |
| 558 // Expect a single key event. | 557 // Expect a single key event. |
| 559 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_)) | 558 EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_)) |
| 560 .Times(AtLeast(1)) | 559 .Times(AtLeast(1)) |
| 561 .WillRepeatedly(InvokeWithoutArgs( | 560 .WillRepeatedly(InvokeWithoutArgs( |
| 562 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); | 561 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 573 } | 572 } |
| 574 | 573 |
| 575 // Tests injection of text events. | 574 // Tests injection of text events. |
| 576 TEST_F(IpcDesktopEnvironmentTest, InjectTextEvent) { | 575 TEST_F(IpcDesktopEnvironmentTest, InjectTextEvent) { |
| 577 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 576 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
| 578 new protocol::MockClipboardStub()); | 577 new protocol::MockClipboardStub()); |
| 579 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 578 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 580 .Times(0); | 579 .Times(0); |
| 581 | 580 |
| 582 // Start the input injector and screen capturer. | 581 // Start the input injector and screen capturer. |
| 583 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 582 input_injector_->Start(clipboard_stub.Pass()); |
| 584 video_capturer_->Start(&desktop_capturer_callback_); | 583 video_capturer_->Start(&desktop_capturer_callback_); |
| 585 | 584 |
| 586 // Run the message loop until the desktop is attached. | 585 // Run the message loop until the desktop is attached. |
| 587 setup_run_loop_->Run(); | 586 setup_run_loop_->Run(); |
| 588 | 587 |
| 589 // Expect a single text event. | 588 // Expect a single text event. |
| 590 EXPECT_CALL(*remote_input_injector_, InjectTextEvent(_)) | 589 EXPECT_CALL(*remote_input_injector_, InjectTextEvent(_)) |
| 591 .Times(AtLeast(1)) | 590 .Times(AtLeast(1)) |
| 592 .WillRepeatedly(InvokeWithoutArgs( | 591 .WillRepeatedly(InvokeWithoutArgs( |
| 593 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); | 592 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 594 | 593 |
| 595 // Send a text event. | 594 // Send a text event. |
| 596 protocol::TextEvent event; | 595 protocol::TextEvent event; |
| 597 event.set_text("hello"); | 596 event.set_text("hello"); |
| 598 input_injector_->InjectTextEvent(event); | 597 input_injector_->InjectTextEvent(event); |
| 599 | 598 |
| 600 task_runner_ = NULL; | 599 task_runner_ = NULL; |
| 601 io_task_runner_ = NULL; | 600 io_task_runner_ = NULL; |
| 602 main_run_loop_.Run(); | 601 main_run_loop_.Run(); |
| 603 } | 602 } |
| 604 | 603 |
| 605 // Tests injection of mouse events. | 604 // Tests injection of mouse events. |
| 606 TEST_F(IpcDesktopEnvironmentTest, InjectMouseEvent) { | 605 TEST_F(IpcDesktopEnvironmentTest, InjectMouseEvent) { |
| 607 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 606 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
| 608 new protocol::MockClipboardStub()); | 607 new protocol::MockClipboardStub()); |
| 609 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 608 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 610 .Times(0); | 609 .Times(0); |
| 611 | 610 |
| 612 // Start the input injector and screen capturer. | 611 // Start the input injector and screen capturer. |
| 613 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 612 input_injector_->Start(clipboard_stub.Pass()); |
| 614 video_capturer_->Start(&desktop_capturer_callback_); | 613 video_capturer_->Start(&desktop_capturer_callback_); |
| 615 | 614 |
| 616 // Run the message loop until the desktop is attached. | 615 // Run the message loop until the desktop is attached. |
| 617 setup_run_loop_->Run(); | 616 setup_run_loop_->Run(); |
| 618 | 617 |
| 619 // Expect a single mouse event. | 618 // Expect a single mouse event. |
| 620 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_)) | 619 EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_)) |
| 621 .Times(1) | 620 .Times(1) |
| 622 .WillOnce(InvokeWithoutArgs( | 621 .WillOnce(InvokeWithoutArgs( |
| 623 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); | 622 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 634 } | 633 } |
| 635 | 634 |
| 636 // Tests that setting the desktop resolution works. | 635 // Tests that setting the desktop resolution works. |
| 637 TEST_F(IpcDesktopEnvironmentTest, SetScreenResolution) { | 636 TEST_F(IpcDesktopEnvironmentTest, SetScreenResolution) { |
| 638 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( | 637 scoped_ptr<protocol::MockClipboardStub> clipboard_stub( |
| 639 new protocol::MockClipboardStub()); | 638 new protocol::MockClipboardStub()); |
| 640 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) | 639 EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 641 .Times(0); | 640 .Times(0); |
| 642 | 641 |
| 643 // Start the input injector and screen capturer. | 642 // Start the input injector and screen capturer. |
| 644 input_injector_->Start(clipboard_stub.PassAs<protocol::ClipboardStub>()); | 643 input_injector_->Start(clipboard_stub.Pass()); |
| 645 video_capturer_->Start(&desktop_capturer_callback_); | 644 video_capturer_->Start(&desktop_capturer_callback_); |
| 646 | 645 |
| 647 // Run the message loop until the desktop is attached. | 646 // Run the message loop until the desktop is attached. |
| 648 setup_run_loop_->Run(); | 647 setup_run_loop_->Run(); |
| 649 | 648 |
| 650 EXPECT_CALL(daemon_channel_, SetScreenResolution(_, _)) | 649 EXPECT_CALL(daemon_channel_, SetScreenResolution(_, _)) |
| 651 .Times(1) | 650 .Times(1) |
| 652 .WillOnce(InvokeWithoutArgs( | 651 .WillOnce(InvokeWithoutArgs( |
| 653 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); | 652 this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 654 | 653 |
| 655 // Change the desktop resolution. | 654 // Change the desktop resolution. |
| 656 screen_controls_->SetScreenResolution(ScreenResolution( | 655 screen_controls_->SetScreenResolution(ScreenResolution( |
| 657 webrtc::DesktopSize(100, 100), | 656 webrtc::DesktopSize(100, 100), |
| 658 webrtc::DesktopVector(96, 96))); | 657 webrtc::DesktopVector(96, 96))); |
| 659 | 658 |
| 660 task_runner_ = NULL; | 659 task_runner_ = NULL; |
| 661 io_task_runner_ = NULL; | 660 io_task_runner_ = NULL; |
| 662 main_run_loop_.Run(); | 661 main_run_loop_.Run(); |
| 663 } | 662 } |
| 664 | 663 |
| 665 } // namespace remoting | 664 } // namespace remoting |
| OLD | NEW |