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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 MOCK_METHOD0(InvokeObserver, void()); | 119 MOCK_METHOD0(InvokeObserver, void()); |
120 | 120 |
121 private: | 121 private: |
122 ScopedVector<content::PresentationSessionMessage> expected_messages_; | 122 ScopedVector<content::PresentationSessionMessage> expected_messages_; |
123 bool pass_ownership_; | 123 bool pass_ownership_; |
124 }; | 124 }; |
125 | 125 |
126 class PresentationConnectionStateChangeHandler { | |
mark a. foltz
2015/11/12 04:19:38
How about PresentatonConnectionStateChangeCallback
imcheng
2015/11/16 23:52:01
Done.
| |
127 public: | |
128 MOCK_METHOD2(Invoke, | |
129 void(const content::PresentationSessionInfo&, | |
130 content::PresentationConnectionState)); | |
131 }; | |
132 | |
126 template <typename T> | 133 template <typename T> |
127 void StoreAndRun(T* result, const base::Closure& closure, const T& result_val) { | 134 void StoreAndRun(T* result, const base::Closure& closure, const T& result_val) { |
128 *result = result_val; | 135 *result = result_val; |
129 closure.Run(); | 136 closure.Run(); |
130 } | 137 } |
131 | 138 |
132 class MediaRouterMojoImplTest : public MediaRouterMojoTest { | 139 class MediaRouterMojoImplTest : public MediaRouterMojoTest { |
133 public: | 140 public: |
134 MediaRouterMojoImplTest() {} | 141 MediaRouterMojoImplTest() {} |
135 ~MediaRouterMojoImplTest() override {} | 142 ~MediaRouterMojoImplTest() override {} |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
731 | 738 |
732 mojo_callback.Run(mojo::Array<interfaces::RouteMessagePtr>(0), true); | 739 mojo_callback.Run(mojo::Array<interfaces::RouteMessagePtr>(0), true); |
733 ProcessEventLoop(); | 740 ProcessEventLoop(); |
734 } | 741 } |
735 | 742 |
736 TEST_F(MediaRouterMojoImplTest, PresentationConnectionStateObserver) { | 743 TEST_F(MediaRouterMojoImplTest, PresentationConnectionStateObserver) { |
737 using PresentationConnectionState = | 744 using PresentationConnectionState = |
738 interfaces::MediaRouter::PresentationConnectionState; | 745 interfaces::MediaRouter::PresentationConnectionState; |
739 | 746 |
740 MediaRoute::Id route_id("route-id"); | 747 MediaRoute::Id route_id("route-id"); |
741 MockPresentationConnectionStateObserver observer(router(), route_id); | 748 const std::string kPresentationUrl("http://foo.fakeUrl"); |
749 const std::string kPresentationId("pid"); | |
750 content::PresentationSessionInfo connection(kPresentationUrl, | |
751 kPresentationId); | |
752 PresentationConnectionStateChangeHandler handler; | |
753 PresentationConnectionStateObserver observer( | |
754 base::Bind(&PresentationConnectionStateChangeHandler::Invoke, | |
755 base::Unretained(&handler)), | |
756 connection, route_id, router()); | |
742 | 757 |
743 EXPECT_CALL(observer, | 758 EXPECT_CALL(handler, Invoke(_, content::PRESENTATION_CONNECTION_STATE_CLOSED)) |
744 OnStateChanged(content::PRESENTATION_CONNECTION_STATE_CLOSED)); | 759 .Times(1); |
745 media_router_proxy_->OnPresentationConnectionStateChanged( | 760 media_router_proxy_->OnPresentationConnectionStateChanged( |
746 route_id, | 761 route_id, |
747 PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CLOSED); | 762 PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CLOSED); |
748 ProcessEventLoop(); | 763 ProcessEventLoop(); |
749 | 764 |
750 EXPECT_CALL(observer, OnStateChanged( | 765 EXPECT_CALL(handler, |
751 content::PRESENTATION_CONNECTION_STATE_TERMINATED)); | 766 Invoke(_, content::PRESENTATION_CONNECTION_STATE_TERMINATED)) |
767 .Times(1); | |
752 media_router_proxy_->OnPresentationConnectionStateChanged( | 768 media_router_proxy_->OnPresentationConnectionStateChanged( |
753 route_id, | 769 route_id, |
754 PresentationConnectionState::PRESENTATION_CONNECTION_STATE_TERMINATED); | 770 PresentationConnectionState::PRESENTATION_CONNECTION_STATE_TERMINATED); |
755 ProcessEventLoop(); | 771 ProcessEventLoop(); |
756 } | 772 } |
757 | 773 |
758 TEST_F(MediaRouterMojoImplTest, QueuedWhileAsleep) { | 774 TEST_F(MediaRouterMojoImplTest, QueuedWhileAsleep) { |
759 EXPECT_CALL(mock_event_page_tracker_, IsEventPageSuspended(extension_id())) | 775 EXPECT_CALL(mock_event_page_tracker_, IsEventPageSuspended(extension_id())) |
760 .Times(2) | 776 .Times(2) |
761 .WillRepeatedly(Return(true)); | 777 .WillRepeatedly(Return(true)); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
970 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))); | 986 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))); |
971 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) | 987 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) |
972 .WillOnce(Return(false)); | 988 .WillOnce(Return(false)); |
973 EXPECT_CALL(mock_media_route_provider_, CloseRoute(mojo::String(kRouteId2))) | 989 EXPECT_CALL(mock_media_route_provider_, CloseRoute(mojo::String(kRouteId2))) |
974 .Times(kMaxPendingRequests); | 990 .Times(kMaxPendingRequests); |
975 RegisterMediaRouteProvider(); | 991 RegisterMediaRouteProvider(); |
976 ProcessEventLoop(); | 992 ProcessEventLoop(); |
977 } | 993 } |
978 | 994 |
979 } // namespace media_router | 995 } // namespace media_router |
OLD | NEW |