Chromium Code Reviews| 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_CALL(callback, Run(content::PRESENTATION_CONNECTION_STATE_CLOSED)) | |
| 781 .Times(0); | |
| 782 media_router_proxy_->OnPresentationConnectionStateChanged( | |
| 783 route_id, | |
| 784 PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CLOSED); | |
| 763 ProcessEventLoop(); | 785 ProcessEventLoop(); |
|
mark a. foltz
2015/11/18 00:39:38
Is there test coverage for the removal callback?
imcheng
2015/11/19 23:39:53
Added assertion that the CallbackList entry is rem
| |
| 764 } | 786 } |
| 765 | 787 |
| 766 TEST_F(MediaRouterMojoImplTest, HasLocalRoute) { | 788 TEST_F(MediaRouterMojoImplTest, HasLocalRoute) { |
| 767 EXPECT_FALSE(router()->HasLocalDisplayRoute()); | 789 EXPECT_FALSE(router()->HasLocalDisplayRoute()); |
| 768 interfaces::MediaRoutePtr mojo_route1 = interfaces::MediaRoute::New(); | 790 interfaces::MediaRoutePtr mojo_route1 = interfaces::MediaRoute::New(); |
| 769 mojo_route1->media_route_id = "routeId1"; | 791 mojo_route1->media_route_id = "routeId1"; |
| 770 mojo_route1->media_sink_id = "sinkId"; | 792 mojo_route1->media_sink_id = "sinkId"; |
| 771 mojo_route1->is_local = false; | 793 mojo_route1->is_local = false; |
| 772 mojo_route1->for_display = false; | 794 mojo_route1->for_display = false; |
| 773 router()->RouteResponseReceived("presentationId1", | 795 router()->RouteResponseReceived("presentationId1", |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1021 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))); | 1043 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))); |
| 1022 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) | 1044 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) |
| 1023 .WillOnce(Return(false)); | 1045 .WillOnce(Return(false)); |
| 1024 EXPECT_CALL(mock_media_route_provider_, CloseRoute(mojo::String(kRouteId2))) | 1046 EXPECT_CALL(mock_media_route_provider_, CloseRoute(mojo::String(kRouteId2))) |
| 1025 .Times(kMaxPendingRequests); | 1047 .Times(kMaxPendingRequests); |
| 1026 RegisterMediaRouteProvider(); | 1048 RegisterMediaRouteProvider(); |
| 1027 ProcessEventLoop(); | 1049 ProcessEventLoop(); |
| 1028 } | 1050 } |
| 1029 | 1051 |
| 1030 } // namespace media_router | 1052 } // namespace media_router |
| OLD | NEW |