OLD | NEW |
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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 .WillOnce(Invoke(client_session_.get(), &ClientSession::SetCapabilities)); | 323 .WillOnce(Invoke(client_session_.get(), &ClientSession::SetCapabilities)); |
324 } | 324 } |
325 | 325 |
326 void ClientSessionTest::SetSendMessageAndDisconnectExpectation( | 326 void ClientSessionTest::SetSendMessageAndDisconnectExpectation( |
327 const std::string& message_type) { | 327 const std::string& message_type) { |
328 protocol::ExtensionMessage message; | 328 protocol::ExtensionMessage message; |
329 message.set_type(message_type); | 329 message.set_type(message_type); |
330 message.set_data("data"); | 330 message.set_data("data"); |
331 | 331 |
332 Expectation authenticated = | 332 Expectation authenticated = |
333 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) | 333 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
334 .WillOnce(Return(true)); | |
335 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 334 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
336 .After(authenticated) | 335 .After(authenticated) |
337 .WillOnce(DoAll( | 336 .WillOnce(DoAll( |
338 DeliverClientMessage(client_session_.get(), message), | 337 DeliverClientMessage(client_session_.get(), message), |
339 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 338 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
340 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 339 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
341 } | 340 } |
342 | 341 |
343 TEST_F(ClientSessionTest, ClipboardStubFilter) { | 342 TEST_F(ClientSessionTest, ClipboardStubFilter) { |
344 CreateClientSession(); | 343 CreateClientSession(); |
345 | 344 |
346 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) | 345 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
347 .WillOnce(Return(true)); | |
348 EXPECT_CALL(*input_injector_, StartPtr(_)); | 346 EXPECT_CALL(*input_injector_, StartPtr(_)); |
349 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 347 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
350 | 348 |
351 // Wait for the first video packet to be captured to make sure that | 349 // Wait for the first video packet to be captured to make sure that |
352 // the injected input will go though. Otherwise mouse events will be blocked | 350 // the injected input will go though. Otherwise mouse events will be blocked |
353 // by the mouse clamping filter. | 351 // by the mouse clamping filter. |
354 base::RunLoop run_loop; | 352 base::RunLoop run_loop; |
355 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 353 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
356 .Times(AtLeast(1)) | 354 .Times(AtLeast(1)) |
357 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 355 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 mouse_event1.set_x(100); | 440 mouse_event1.set_x(100); |
443 mouse_event1.set_y(101); | 441 mouse_event1.set_y(101); |
444 protocol::MouseEvent mouse_event2; | 442 protocol::MouseEvent mouse_event2; |
445 mouse_event2.set_x(200); | 443 mouse_event2.set_x(200); |
446 mouse_event2.set_y(201); | 444 mouse_event2.set_y(201); |
447 protocol::MouseEvent mouse_event3; | 445 protocol::MouseEvent mouse_event3; |
448 mouse_event3.set_x(300); | 446 mouse_event3.set_x(300); |
449 mouse_event3.set_y(301); | 447 mouse_event3.set_y(301); |
450 | 448 |
451 Expectation authenticated = | 449 Expectation authenticated = |
452 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) | 450 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
453 .WillOnce(Return(true)); | |
454 EXPECT_CALL(*input_injector_, StartPtr(_)) | 451 EXPECT_CALL(*input_injector_, StartPtr(_)) |
455 .After(authenticated); | 452 .After(authenticated); |
456 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 453 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
457 .After(authenticated); | 454 .After(authenticated); |
458 | 455 |
459 // Wait for the first video packet to be captured to make sure that | 456 // Wait for the first video packet to be captured to make sure that |
460 // the injected input will go though. Otherwise mouse events will be blocked | 457 // the injected input will go though. Otherwise mouse events will be blocked |
461 // by the mouse clamping filter. | 458 // by the mouse clamping filter. |
462 Sequence s; | 459 Sequence s; |
463 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 460 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 | 496 |
500 protocol::KeyEvent key2; | 497 protocol::KeyEvent key2; |
501 key2.set_pressed(true); | 498 key2.set_pressed(true); |
502 key2.set_usb_keycode(2); | 499 key2.set_usb_keycode(2); |
503 | 500 |
504 protocol::MouseEvent mousedown; | 501 protocol::MouseEvent mousedown; |
505 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); | 502 mousedown.set_button(protocol::MouseEvent::BUTTON_LEFT); |
506 mousedown.set_button_down(true); | 503 mousedown.set_button_down(true); |
507 | 504 |
508 Expectation authenticated = | 505 Expectation authenticated = |
509 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) | 506 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
510 .WillOnce(Return(true)); | |
511 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated); | 507 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated); |
512 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 508 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
513 .After(authenticated); | 509 .After(authenticated); |
514 | 510 |
515 // Wait for the first video packet to be captured to make sure that | 511 // Wait for the first video packet to be captured to make sure that |
516 // the injected input will go though. Otherwise mouse events will be blocked | 512 // the injected input will go though. Otherwise mouse events will be blocked |
517 // by the mouse clamping filter. | 513 // by the mouse clamping filter. |
518 Sequence s; | 514 Sequence s; |
519 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 515 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
520 .InSequence(s) | 516 .InSequence(s) |
(...skipping 19 matching lines...) Expand all Loading... |
540 .InSequence(s); | 536 .InSequence(s); |
541 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)).InSequence(s); | 537 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)).InSequence(s); |
542 | 538 |
543 ConnectClientSession(); | 539 ConnectClientSession(); |
544 } | 540 } |
545 | 541 |
546 TEST_F(ClientSessionTest, ClampMouseEvents) { | 542 TEST_F(ClientSessionTest, ClampMouseEvents) { |
547 CreateClientSession(); | 543 CreateClientSession(); |
548 | 544 |
549 Expectation authenticated = | 545 Expectation authenticated = |
550 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) | 546 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
551 .WillOnce(Return(true)); | |
552 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated); | 547 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated); |
553 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 548 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
554 .After(authenticated); | 549 .After(authenticated); |
555 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)).After(authenticated); | 550 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)).After(authenticated); |
556 | 551 |
557 Expectation connected = authenticated; | 552 Expectation connected = authenticated; |
558 | 553 |
559 int input_x[3] = { -999, 100, 999 }; | 554 int input_x[3] = { -999, 100, 999 }; |
560 int expected_x[3] = { 0, 100, protocol::FakeDesktopCapturer::kWidth - 1 }; | 555 int expected_x[3] = { 0, 100, protocol::FakeDesktopCapturer::kWidth - 1 }; |
561 int input_y[3] = { -999, 50, 999 }; | 556 int input_y[3] = { -999, 50, 999 }; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 } | 597 } |
603 | 598 |
604 TEST_F(ClientSessionTest, NoGnubbyAuth) { | 599 TEST_F(ClientSessionTest, NoGnubbyAuth) { |
605 CreateClientSession(); | 600 CreateClientSession(); |
606 | 601 |
607 protocol::ExtensionMessage message; | 602 protocol::ExtensionMessage message; |
608 message.set_type("gnubby-auth"); | 603 message.set_type("gnubby-auth"); |
609 message.set_data("test"); | 604 message.set_data("test"); |
610 | 605 |
611 Expectation authenticated = | 606 Expectation authenticated = |
612 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) | 607 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
613 .WillOnce(Return(true)); | |
614 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated); | 608 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated); |
615 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 609 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
616 .After(authenticated) | 610 .After(authenticated) |
617 .WillOnce(DoAll( | 611 .WillOnce(DoAll( |
618 DeliverClientMessage(client_session_.get(), message), | 612 DeliverClientMessage(client_session_.get(), message), |
619 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 613 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
620 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 614 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
621 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 615 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
622 | 616 |
623 ConnectClientSession(); | 617 ConnectClientSession(); |
624 } | 618 } |
625 | 619 |
626 TEST_F(ClientSessionTest, EnableGnubbyAuth) { | 620 TEST_F(ClientSessionTest, EnableGnubbyAuth) { |
627 CreateClientSession(); | 621 CreateClientSession(); |
628 | 622 |
629 // Lifetime controlled by object under test. | 623 // Lifetime controlled by object under test. |
630 MockGnubbyAuthHandler* gnubby_auth_handler = new MockGnubbyAuthHandler(); | 624 MockGnubbyAuthHandler* gnubby_auth_handler = new MockGnubbyAuthHandler(); |
631 | 625 |
632 protocol::ExtensionMessage message; | 626 protocol::ExtensionMessage message; |
633 message.set_type("gnubby-auth"); | 627 message.set_type("gnubby-auth"); |
634 message.set_data("test"); | 628 message.set_data("test"); |
635 | 629 |
636 Expectation authenticated = | 630 Expectation authenticated = |
637 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) | 631 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
638 .WillOnce(Return(true)); | |
639 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated); | 632 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated); |
640 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) | 633 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)) |
641 .After(authenticated) | 634 .After(authenticated) |
642 .WillOnce(DoAll( | 635 .WillOnce(DoAll( |
643 SetGnubbyAuthHandlerForTesting(client_session_.get(), | 636 SetGnubbyAuthHandlerForTesting(client_session_.get(), |
644 gnubby_auth_handler), | 637 gnubby_auth_handler), |
645 DeliverClientMessage(client_session_.get(), message), | 638 DeliverClientMessage(client_session_.get(), message), |
646 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 639 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
647 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 640 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
648 EXPECT_CALL(*gnubby_auth_handler, DeliverClientMessage(_)); | 641 EXPECT_CALL(*gnubby_auth_handler, DeliverClientMessage(_)); |
649 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); | 642 EXPECT_CALL(session_event_handler_, OnSessionClosed(_)); |
650 | 643 |
651 ConnectClientSession(); | 644 ConnectClientSession(); |
652 } | 645 } |
653 | 646 |
654 // Verifies that the client's video pipeline can be reset mid-session. | 647 // Verifies that the client's video pipeline can be reset mid-session. |
655 TEST_F(ClientSessionTest, ResetVideoPipeline) { | 648 TEST_F(ClientSessionTest, ResetVideoPipeline) { |
656 CreateClientSession(); | 649 CreateClientSession(); |
657 | 650 |
658 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) | 651 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
659 .WillOnce(Return(true)); | |
660 | 652 |
661 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 653 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
662 .WillOnce(DoAll( | 654 .WillOnce(DoAll( |
663 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), | 655 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), |
664 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); | 656 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); |
665 | 657 |
666 ConnectClientSession(); | 658 ConnectClientSession(); |
667 | 659 |
668 client_session_->ResetVideoPipeline(); | 660 client_session_->ResetVideoPipeline(); |
669 } | 661 } |
(...skipping 10 matching lines...) Expand all Loading... |
680 extensions_.push_back(&extension2); | 672 extensions_.push_back(&extension2); |
681 FakeExtension extension3("ext3", "cap3"); | 673 FakeExtension extension3("ext3", "cap3"); |
682 extensions_.push_back(&extension3); | 674 extensions_.push_back(&extension3); |
683 | 675 |
684 // Set the second extension to request to modify the video pipeline. | 676 // Set the second extension to request to modify the video pipeline. |
685 extension2.set_steal_video_capturer(true); | 677 extension2.set_steal_video_capturer(true); |
686 | 678 |
687 CreateClientSession(); | 679 CreateClientSession(); |
688 | 680 |
689 Expectation authenticated = | 681 Expectation authenticated = |
690 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) | 682 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
691 .WillOnce(Return(true)); | |
692 | 683 |
693 // Verify that the ClientSession reports the correct capabilities, and mimic | 684 // Verify that the ClientSession reports the correct capabilities, and mimic |
694 // the client reporting an overlapping set of capabilities. | 685 // the client reporting an overlapping set of capabilities. |
695 EXPECT_CALL(client_stub_, | 686 EXPECT_CALL(client_stub_, |
696 SetCapabilities(EqCapabilities("cap1 cap3 default"))) | 687 SetCapabilities(EqCapabilities("cap1 cap3 default"))) |
697 .After(authenticated) | 688 .After(authenticated) |
698 .WillOnce(SetCapabilities(client_session_.get(), "cap1 cap4 default")); | 689 .WillOnce(SetCapabilities(client_session_.get(), "cap1 cap4 default")); |
699 | 690 |
700 // Verify that the correct extension messages are delivered, and dropped. | 691 // Verify that the correct extension messages are delivered, and dropped. |
701 protocol::ExtensionMessage message1; | 692 protocol::ExtensionMessage message1; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 // Verifies that an extension can "steal" the video capture, in which case no | 727 // Verifies that an extension can "steal" the video capture, in which case no |
737 // VideoFramePump is instantiated. | 728 // VideoFramePump is instantiated. |
738 TEST_F(ClientSessionTest, StealVideoCapturer) { | 729 TEST_F(ClientSessionTest, StealVideoCapturer) { |
739 FakeExtension extension("ext1", "cap1"); | 730 FakeExtension extension("ext1", "cap1"); |
740 extensions_.push_back(&extension); | 731 extensions_.push_back(&extension); |
741 | 732 |
742 CreateClientSession(); | 733 CreateClientSession(); |
743 | 734 |
744 SetMatchCapabilitiesExpectation(); | 735 SetMatchCapabilitiesExpectation(); |
745 | 736 |
746 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)) | 737 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
747 .WillOnce(Return(true)); | |
748 | 738 |
749 ConnectClientSession(); | 739 ConnectClientSession(); |
750 | 740 |
751 base::RunLoop().RunUntilIdle(); | 741 base::RunLoop().RunUntilIdle(); |
752 | 742 |
753 extension.set_steal_video_capturer(true); | 743 extension.set_steal_video_capturer(true); |
754 client_session_->ResetVideoPipeline(); | 744 client_session_->ResetVideoPipeline(); |
755 | 745 |
756 base::RunLoop().RunUntilIdle(); | 746 base::RunLoop().RunUntilIdle(); |
757 | 747 |
(...skipping 10 matching lines...) Expand all Loading... |
768 | 758 |
769 DisconnectClientSession(); | 759 DisconnectClientSession(); |
770 StopClientSession(); | 760 StopClientSession(); |
771 | 761 |
772 // ext1 was instantiated and wrapped the video capturer. | 762 // ext1 was instantiated and wrapped the video capturer. |
773 EXPECT_TRUE(extension.was_instantiated()); | 763 EXPECT_TRUE(extension.was_instantiated()); |
774 EXPECT_TRUE(extension.has_wrapped_video_capturer()); | 764 EXPECT_TRUE(extension.has_wrapped_video_capturer()); |
775 } | 765 } |
776 | 766 |
777 } // namespace remoting | 767 } // namespace remoting |
OLD | NEW |