OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 new PresentationSessionMessagesObserver( | 734 new PresentationSessionMessagesObserver( |
735 base::Bind(&ListenForMessagesCallbackHandler::Invoke, | 735 base::Bind(&ListenForMessagesCallbackHandler::Invoke, |
736 base::Unretained(&handler)), | 736 base::Unretained(&handler)), |
737 expected_route_id, router())); | 737 expected_route_id, router())); |
738 ProcessEventLoop(); | 738 ProcessEventLoop(); |
739 | 739 |
740 mojo_callback.Run(mojo::Array<interfaces::RouteMessagePtr>(0), true); | 740 mojo_callback.Run(mojo::Array<interfaces::RouteMessagePtr>(0), true); |
741 ProcessEventLoop(); | 741 ProcessEventLoop(); |
742 } | 742 } |
743 | 743 |
744 TEST_F(MediaRouterMojoImplTest, PresentationConnectionStateObserver) { | 744 TEST_F(MediaRouterMojoImplTest, PresentationConnectionStateChangedCallback) { |
745 using PresentationConnectionState = | 745 using PresentationConnectionState = |
746 interfaces::MediaRouter::PresentationConnectionState; | 746 interfaces::MediaRouter::PresentationConnectionState; |
747 | 747 |
748 MediaRoute::Id route_id("route-id"); | 748 MediaRoute::Id route_id("route-id"); |
749 MockPresentationConnectionStateObserver observer(router(), route_id); | 749 const std::string kPresentationUrl("http://foo.fakeUrl"); |
| 750 const std::string kPresentationId("pid"); |
| 751 content::PresentationSessionInfo connection(kPresentationUrl, |
| 752 kPresentationId); |
| 753 MockPresentationConnectionStateChangedCallback callback; |
| 754 scoped_ptr<PresentationConnectionStateSubscription> subscription = |
| 755 router()->AddPresentationConnectionStateChangedCallback( |
| 756 route_id, |
| 757 base::Bind(&MockPresentationConnectionStateChangedCallback::Run, |
| 758 base::Unretained(&callback))); |
750 | 759 |
751 EXPECT_CALL(observer, | 760 EXPECT_CALL(callback, Run(content::PRESENTATION_CONNECTION_STATE_CLOSED)) |
752 OnStateChanged(content::PRESENTATION_CONNECTION_STATE_CLOSED)); | 761 .Times(1); |
753 media_router_proxy_->OnPresentationConnectionStateChanged( | 762 media_router_proxy_->OnPresentationConnectionStateChanged( |
754 route_id, | 763 route_id, |
755 PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CLOSED); | 764 PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CLOSED); |
756 ProcessEventLoop(); | 765 ProcessEventLoop(); |
757 | 766 |
758 EXPECT_CALL(observer, OnStateChanged( | 767 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&callback)); |
759 content::PRESENTATION_CONNECTION_STATE_TERMINATED)); | 768 |
| 769 // Right now we don't keep track of previous state so the callback will be |
| 770 // invoked with the same state again. |
| 771 EXPECT_CALL(callback, Run(content::PRESENTATION_CONNECTION_STATE_CLOSED)) |
| 772 .Times(1); |
760 media_router_proxy_->OnPresentationConnectionStateChanged( | 773 media_router_proxy_->OnPresentationConnectionStateChanged( |
761 route_id, | 774 route_id, |
762 PresentationConnectionState::PRESENTATION_CONNECTION_STATE_TERMINATED); | 775 PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CLOSED); |
| 776 ProcessEventLoop(); |
| 777 |
| 778 // Callback has been removed, so we don't expect it to be called anymore. |
| 779 subscription.reset(); |
| 780 EXPECT_TRUE(router()->presentation_connection_state_callbacks_.empty()); |
| 781 |
| 782 EXPECT_CALL(callback, Run(content::PRESENTATION_CONNECTION_STATE_CLOSED)) |
| 783 .Times(0); |
| 784 media_router_proxy_->OnPresentationConnectionStateChanged( |
| 785 route_id, |
| 786 PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CLOSED); |
763 ProcessEventLoop(); | 787 ProcessEventLoop(); |
764 } | 788 } |
765 | 789 |
766 TEST_F(MediaRouterMojoImplTest, HasLocalRoute) { | 790 TEST_F(MediaRouterMojoImplTest, HasLocalRoute) { |
767 EXPECT_FALSE(router()->HasLocalDisplayRoute()); | 791 EXPECT_FALSE(router()->HasLocalDisplayRoute()); |
768 interfaces::MediaRoutePtr mojo_route1 = interfaces::MediaRoute::New(); | 792 interfaces::MediaRoutePtr mojo_route1 = interfaces::MediaRoute::New(); |
769 mojo_route1->media_route_id = "routeId1"; | 793 mojo_route1->media_route_id = "routeId1"; |
770 mojo_route1->media_sink_id = "sinkId"; | 794 mojo_route1->media_sink_id = "sinkId"; |
771 mojo_route1->is_local = false; | 795 mojo_route1->is_local = false; |
772 mojo_route1->for_display = false; | 796 mojo_route1->for_display = false; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))); | 1045 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))); |
1022 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) | 1046 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) |
1023 .WillOnce(Return(false)); | 1047 .WillOnce(Return(false)); |
1024 EXPECT_CALL(mock_media_route_provider_, CloseRoute(mojo::String(kRouteId2))) | 1048 EXPECT_CALL(mock_media_route_provider_, CloseRoute(mojo::String(kRouteId2))) |
1025 .Times(kMaxPendingRequests); | 1049 .Times(kMaxPendingRequests); |
1026 RegisterMediaRouteProvider(); | 1050 RegisterMediaRouteProvider(); |
1027 ProcessEventLoop(); | 1051 ProcessEventLoop(); |
1028 } | 1052 } |
1029 | 1053 |
1030 } // namespace media_router | 1054 } // namespace media_router |
OLD | NEW |