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 "chrome/browser/media/router/presentation_service_delegate_impl.h" | 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
| 6 | 6 |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 11 #include "chrome/browser/media/router/media_source.h" | 9 #include "chrome/browser/media/router/media_source.h" |
| 12 #include "chrome/browser/media/router/media_source_helper.h" | 10 #include "chrome/browser/media/router/media_source_helper.h" |
| 13 #include "chrome/browser/media/router/mock_media_router.h" | 11 #include "chrome/browser/media/router/mock_media_router.h" |
| 14 #include "chrome/browser/media/router/mock_screen_availability_listener.h" | 12 #include "chrome/browser/media/router/mock_screen_availability_listener.h" |
| 15 #include "chrome/browser/media/router/route_request_result.h" | 13 #include "chrome/browser/media/router/route_request_result.h" |
| 16 #include "chrome/browser/media/router/test_helper.h" | 14 #include "chrome/browser/media/router/test_helper.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 19 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 20 #include "content/public/browser/presentation_screen_availability_listener.h" | 18 #include "content/public/browser/presentation_screen_availability_listener.h" |
| 21 #include "content/public/browser/presentation_session.h" | 19 #include "content/public/browser/presentation_session.h" |
| 22 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 23 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/test/web_contents_tester.h" | 22 #include "content/public/test/web_contents_tester.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 26 | 24 |
| 27 using ::testing::_; | 25 using ::testing::_; |
| 28 using ::testing::Mock; | 26 using ::testing::Mock; |
| 29 using ::testing::Return; | 27 using ::testing::Return; |
| 30 using ::testing::SaveArg; | 28 using ::testing::SaveArg; |
| 31 using ::testing::StrictMock; | 29 using ::testing::StrictMock; |
| 32 | 30 |
| 31 namespace { | |
| 32 | |
| 33 const char* const kPresentationUrl1 = "http://foo.fakeUrl.com/"; | |
|
dcheng
2016/08/30 05:47:31
Nit: const char kPresentationUrl1[] here and below
mark a. foltz
2016/08/30 19:57:54
Done.
| |
| 34 const char* const kPresentationUrl2 = "http://bar.fakeUrl.com/"; | |
| 35 const char* const kFrameUrl = "http://anotherFrameUrl.fakeUrl.com/"; | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 33 namespace media_router { | 39 namespace media_router { |
| 34 | 40 |
| 35 class MockDelegateObserver | 41 class MockDelegateObserver |
| 36 : public content::PresentationServiceDelegate::Observer { | 42 : public content::PresentationServiceDelegate::Observer { |
| 37 public: | 43 public: |
| 38 MOCK_METHOD0(OnDelegateDestroyed, void()); | 44 MOCK_METHOD0(OnDelegateDestroyed, void()); |
| 39 MOCK_METHOD1(OnDefaultPresentationStarted, | 45 MOCK_METHOD1(OnDefaultPresentationStarted, |
| 40 void(const content::PresentationSessionInfo&)); | 46 void(const content::PresentationSessionInfo&)); |
| 41 }; | 47 }; |
| 42 | 48 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 | 84 |
| 79 void RunDefaultPresentationUrlCallbackTest(bool incognito) { | 85 void RunDefaultPresentationUrlCallbackTest(bool incognito) { |
| 80 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 86 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 81 ASSERT_TRUE(main_frame); | 87 ASSERT_TRUE(main_frame); |
| 82 int render_process_id = main_frame->GetProcess()->GetID(); | 88 int render_process_id = main_frame->GetProcess()->GetID(); |
| 83 int routing_id = main_frame->GetRoutingID(); | 89 int routing_id = main_frame->GetRoutingID(); |
| 84 | 90 |
| 85 auto callback = base::Bind( | 91 auto callback = base::Bind( |
| 86 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, | 92 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, |
| 87 base::Unretained(this)); | 93 base::Unretained(this)); |
| 88 std::string presentation_url1("http://foo.fakeUrl"); | 94 std::vector<std::string> urls({kPresentationUrl1}); |
| 89 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, | 95 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id, |
| 90 presentation_url1, callback); | 96 urls, callback); |
| 91 | 97 |
| 92 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); | 98 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); |
| 93 PresentationRequest request = | 99 PresentationRequest request = |
| 94 delegate_impl_->GetDefaultPresentationRequest(); | 100 delegate_impl_->GetDefaultPresentationRequest(); |
| 95 | 101 |
| 96 // Should not trigger callback since route response is error. | 102 // Should not trigger callback since route response is error. |
| 97 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( | 103 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( |
| 98 "Error", RouteRequestResult::UNKNOWN_ERROR); | 104 "Error", RouteRequestResult::UNKNOWN_ERROR); |
| 99 delegate_impl_->OnRouteResponse(request, *result); | 105 delegate_impl_->OnRouteResponse(request, *result); |
| 100 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); | 106 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); |
| 101 | 107 |
| 102 // Should not trigger callback since request doesn't match. | 108 // Should not trigger callback since request doesn't match. |
| 103 std::string presentation_url2("http://bar.fakeUrl"); | 109 PresentationRequest different_request(RenderFrameHostId(100, 200), |
| 104 PresentationRequest different_request( | 110 kPresentationUrl2, GURL(kFrameUrl)); |
| 105 RenderFrameHostId(100, 200), presentation_url2, | |
| 106 GURL("http://anotherFrameUrl.fakeUrl")); | |
| 107 MediaRoute* media_route = new MediaRoute( | 111 MediaRoute* media_route = new MediaRoute( |
| 108 "differentRouteId", MediaSourceForPresentationUrl(presentation_url2), | 112 "differentRouteId", MediaSourceForPresentationUrl(kPresentationUrl2), |
| 109 "mediaSinkId", "", true, "", true); | 113 "mediaSinkId", "", true, "", true); |
| 110 media_route->set_incognito(incognito); | 114 media_route->set_incognito(incognito); |
| 111 result = RouteRequestResult::FromSuccess(base::WrapUnique(media_route), | 115 result = RouteRequestResult::FromSuccess(base::WrapUnique(media_route), |
| 112 "differentPresentationId"); | 116 "differentPresentationId"); |
| 113 delegate_impl_->OnRouteResponse(different_request, *result); | 117 delegate_impl_->OnRouteResponse(different_request, *result); |
| 114 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); | 118 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); |
| 115 | 119 |
| 116 // Should trigger callback since request matches. | 120 // Should trigger callback since request matches. |
| 117 EXPECT_CALL(*this, OnDefaultPresentationStarted(_)).Times(1); | 121 EXPECT_CALL(*this, OnDefaultPresentationStarted(_)).Times(1); |
| 118 MediaRoute* media_route2 = new MediaRoute( | 122 MediaRoute* media_route2 = new MediaRoute( |
| 119 "routeId", MediaSourceForPresentationUrl(presentation_url1), | 123 "routeId", MediaSourceForPresentationUrl(kPresentationUrl1), |
| 120 "mediaSinkId", "", true, "", true); | 124 "mediaSinkId", "", true, "", true); |
| 121 media_route2->set_incognito(incognito); | 125 media_route2->set_incognito(incognito); |
| 122 result = RouteRequestResult::FromSuccess(base::WrapUnique(media_route2), | 126 result = RouteRequestResult::FromSuccess(base::WrapUnique(media_route2), |
| 123 "presentationId"); | 127 "presentationId"); |
| 124 delegate_impl_->OnRouteResponse(request, *result); | 128 delegate_impl_->OnRouteResponse(request, *result); |
| 125 } | 129 } |
| 126 | 130 |
| 127 PresentationServiceDelegateImpl* delegate_impl_; | 131 PresentationServiceDelegateImpl* delegate_impl_; |
| 128 MockMediaRouter router_; | 132 MockMediaRouter router_; |
| 129 }; | 133 }; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 150 // require RenderViewHost, etc., that in turn are deleted by | 154 // require RenderViewHost, etc., that in turn are deleted by |
| 151 // RenderViewHostTestHarness::TearDown(). | 155 // RenderViewHostTestHarness::TearDown(). |
| 152 delete incognito_web_contents_; | 156 delete incognito_web_contents_; |
| 153 PresentationServiceDelegateImplTest::TearDown(); | 157 PresentationServiceDelegateImplTest::TearDown(); |
| 154 } | 158 } |
| 155 | 159 |
| 156 content::WebContents* incognito_web_contents_; | 160 content::WebContents* incognito_web_contents_; |
| 157 }; | 161 }; |
| 158 | 162 |
| 159 TEST_F(PresentationServiceDelegateImplTest, AddScreenAvailabilityListener) { | 163 TEST_F(PresentationServiceDelegateImplTest, AddScreenAvailabilityListener) { |
| 160 std::string presentation_url1("http://url1.fakeUrl"); | 164 MediaSource source1 = MediaSourceForPresentationUrl(kPresentationUrl1); |
| 161 std::string presentation_url2("http://url2.fakeUrl"); | 165 MediaSource source2 = MediaSourceForPresentationUrl(kPresentationUrl2); |
| 162 MediaSource source1 = MediaSourceForPresentationUrl(presentation_url1); | 166 MockScreenAvailabilityListener listener1(kPresentationUrl1); |
| 163 MediaSource source2 = MediaSourceForPresentationUrl(presentation_url2); | 167 MockScreenAvailabilityListener listener2(kPresentationUrl2); |
| 164 MockScreenAvailabilityListener listener1(presentation_url1); | |
| 165 MockScreenAvailabilityListener listener2(presentation_url2); | |
| 166 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 168 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 167 ASSERT_TRUE(main_frame); | 169 ASSERT_TRUE(main_frame); |
| 168 int render_process_id = main_frame->GetProcess()->GetID(); | 170 int render_process_id = main_frame->GetProcess()->GetID(); |
| 169 int render_frame_id1 = main_frame->GetRoutingID(); | 171 int render_frame_id1 = main_frame->GetRoutingID(); |
| 170 | 172 |
| 171 // Note that |render_frame_id2| does not correspond to a real frame. As a | 173 // Note that |render_frame_id2| does not correspond to a real frame. As a |
| 172 // result, the observer added with have an empty GURL as origin. | 174 // result, the observer added with have an empty GURL as origin. |
| 173 int render_frame_id2 = 2; | 175 int render_frame_id2 = 2; |
| 174 | 176 |
| 175 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) | 177 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 193 render_process_id, render_frame_id2, &listener2); | 195 render_process_id, render_frame_id2, &listener2); |
| 194 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( | 196 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( |
| 195 render_process_id, render_frame_id1, source1.id())); | 197 render_process_id, render_frame_id1, source1.id())); |
| 196 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( | 198 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( |
| 197 render_process_id, render_frame_id2, source2.id())); | 199 render_process_id, render_frame_id2, source2.id())); |
| 198 } | 200 } |
| 199 | 201 |
| 200 TEST_F(PresentationServiceDelegateImplTest, AddMultipleListenersToFrame) { | 202 TEST_F(PresentationServiceDelegateImplTest, AddMultipleListenersToFrame) { |
| 201 ON_CALL(router_, RegisterMediaSinksObserver(_)).WillByDefault(Return(true)); | 203 ON_CALL(router_, RegisterMediaSinksObserver(_)).WillByDefault(Return(true)); |
| 202 | 204 |
| 203 std::string presentation_url1("http://url1.com"); | 205 MediaSource source1 = MediaSourceForPresentationUrl(kPresentationUrl1); |
| 204 std::string presentation_url2("http://url2.com"); | 206 MediaSource source2 = MediaSourceForPresentationUrl(kPresentationUrl2); |
| 205 MediaSource source1 = MediaSourceForPresentationUrl(presentation_url1); | 207 MockScreenAvailabilityListener listener1(kPresentationUrl1); |
| 206 MediaSource source2 = MediaSourceForPresentationUrl(presentation_url2); | 208 MockScreenAvailabilityListener listener2(kPresentationUrl2); |
| 207 MockScreenAvailabilityListener listener1(presentation_url1); | |
| 208 MockScreenAvailabilityListener listener2(presentation_url2); | |
| 209 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 209 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 210 ASSERT_TRUE(main_frame); | 210 ASSERT_TRUE(main_frame); |
| 211 int render_process_id = main_frame->GetProcess()->GetID(); | 211 int render_process_id = main_frame->GetProcess()->GetID(); |
| 212 int render_frame_id = main_frame->GetRoutingID(); | 212 int render_frame_id = main_frame->GetRoutingID(); |
| 213 | 213 |
| 214 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).Times(2); | 214 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).Times(2); |
| 215 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( | 215 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( |
| 216 render_process_id, render_frame_id, &listener1)); | 216 render_process_id, render_frame_id, &listener1)); |
| 217 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( | 217 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( |
| 218 render_process_id, render_frame_id, &listener2)); | 218 render_process_id, render_frame_id, &listener2)); |
| 219 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( | 219 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( |
| 220 render_process_id, render_frame_id, source1.id())) | 220 render_process_id, render_frame_id, source1.id())) |
| 221 << "Mapping not found for " << source1.ToString(); | 221 << "Mapping not found for " << source1.ToString(); |
| 222 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( | 222 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( |
| 223 render_process_id, render_frame_id, source2.id())) | 223 render_process_id, render_frame_id, source2.id())) |
| 224 << "Mapping not found for " << source2.ToString(); | 224 << "Mapping not found for " << source2.ToString(); |
| 225 | 225 |
| 226 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(2); | 226 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(2); |
| 227 delegate_impl_->RemoveScreenAvailabilityListener( | 227 delegate_impl_->RemoveScreenAvailabilityListener( |
| 228 render_process_id, render_frame_id, &listener1); | 228 render_process_id, render_frame_id, &listener1); |
| 229 delegate_impl_->RemoveScreenAvailabilityListener( | 229 delegate_impl_->RemoveScreenAvailabilityListener( |
| 230 render_process_id, render_frame_id, &listener2); | 230 render_process_id, render_frame_id, &listener2); |
| 231 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( | 231 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( |
| 232 render_process_id, render_frame_id, source1.id())); | 232 render_process_id, render_frame_id, source1.id())); |
| 233 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( | 233 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( |
| 234 render_process_id, render_frame_id, source2.id())); | 234 render_process_id, render_frame_id, source2.id())); |
| 235 } | 235 } |
| 236 | 236 |
| 237 TEST_F(PresentationServiceDelegateImplTest, AddSameListenerTwice) { | 237 TEST_F(PresentationServiceDelegateImplTest, AddSameListenerTwice) { |
| 238 std::string presentation_url1("http://url1.fakeUrl"); | 238 MediaSource source1(MediaSourceForPresentationUrl(kPresentationUrl1)); |
| 239 MediaSource source1(MediaSourceForPresentationUrl(presentation_url1)); | 239 MockScreenAvailabilityListener listener1(kPresentationUrl1); |
| 240 MockScreenAvailabilityListener listener1(presentation_url1); | |
| 241 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 240 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 242 ASSERT_TRUE(main_frame); | 241 ASSERT_TRUE(main_frame); |
| 243 int render_process_id = main_frame->GetProcess()->GetID(); | 242 int render_process_id = main_frame->GetProcess()->GetID(); |
| 244 int render_frame_id = main_frame->GetRoutingID(); | 243 int render_frame_id = main_frame->GetRoutingID(); |
| 245 | 244 |
| 246 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(true)); | 245 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(true)); |
| 247 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( | 246 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( |
| 248 render_process_id, render_frame_id, &listener1)); | 247 render_process_id, render_frame_id, &listener1)); |
| 249 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( | 248 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( |
| 250 render_process_id, render_frame_id, &listener1)); | 249 render_process_id, render_frame_id, &listener1)); |
| 251 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( | 250 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( |
| 252 render_process_id, render_frame_id, source1.id())); | 251 render_process_id, render_frame_id, source1.id())); |
| 253 | 252 |
| 254 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(1); | 253 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(1); |
| 255 delegate_impl_->RemoveScreenAvailabilityListener(render_process_id, | 254 delegate_impl_->RemoveScreenAvailabilityListener(render_process_id, |
| 256 render_frame_id, &listener1); | 255 render_frame_id, &listener1); |
| 257 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( | 256 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( |
| 258 render_process_id, render_frame_id, source1.id())); | 257 render_process_id, render_frame_id, source1.id())); |
| 259 } | 258 } |
| 260 | 259 |
| 261 // TODO(imcheng): Add a test to set default presentation URL in a different | 260 // TODO(imcheng): Add a test to set default presentation URL in a different |
| 262 // RenderFrameHost and verify that it is ignored. | 261 // RenderFrameHost and verify that it is ignored. |
| 263 TEST_F(PresentationServiceDelegateImplTest, SetDefaultPresentationUrl) { | 262 TEST_F(PresentationServiceDelegateImplTest, SetDefaultPresentationUrl) { |
| 264 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest()); | 263 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest()); |
| 265 | 264 |
| 266 GURL frame_url("http://www.google.com"); | 265 GURL frame_url(kFrameUrl); |
| 267 content::WebContentsTester::For(GetWebContents()) | 266 content::WebContentsTester::For(GetWebContents()) |
| 268 ->NavigateAndCommit(frame_url); | 267 ->NavigateAndCommit(frame_url); |
| 269 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 268 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 270 ASSERT_TRUE(main_frame); | 269 ASSERT_TRUE(main_frame); |
| 271 int render_process_id = main_frame->GetProcess()->GetID(); | 270 int render_process_id = main_frame->GetProcess()->GetID(); |
| 272 int routing_id = main_frame->GetRoutingID(); | 271 int routing_id = main_frame->GetRoutingID(); |
| 273 | 272 |
| 274 auto callback = base::Bind( | 273 auto callback = base::Bind( |
| 275 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, | 274 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, |
| 276 base::Unretained(this)); | 275 base::Unretained(this)); |
| 277 std::string presentation_url1("http://foo.fakeUrl"); | 276 std::vector<std::string> urls({kPresentationUrl1}); |
| 278 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, | 277 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id, |
| 279 presentation_url1, callback); | 278 urls, callback); |
| 280 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); | 279 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); |
| 281 PresentationRequest request1 = | 280 PresentationRequest request1 = |
| 282 delegate_impl_->GetDefaultPresentationRequest(); | 281 delegate_impl_->GetDefaultPresentationRequest(); |
| 283 EXPECT_EQ(presentation_url1, request1.presentation_url()); | 282 EXPECT_EQ(kPresentationUrl1, request1.presentation_url()); |
| 284 EXPECT_EQ(RenderFrameHostId(render_process_id, routing_id), | 283 EXPECT_EQ(RenderFrameHostId(render_process_id, routing_id), |
| 285 request1.render_frame_host_id()); | 284 request1.render_frame_host_id()); |
| 286 EXPECT_EQ(frame_url, request1.frame_url()); | 285 EXPECT_EQ(frame_url, request1.frame_url()); |
| 287 | 286 |
| 288 // Set to a new default presentation URL | 287 // Set to a new default presentation URL |
| 289 std::string presentation_url2("https://youtube.com"); | 288 std::vector<std::string> new_urls({kPresentationUrl2}); |
| 290 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, | 289 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id, |
| 291 presentation_url2, callback); | 290 new_urls, callback); |
| 292 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); | 291 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); |
| 293 PresentationRequest request2 = | 292 PresentationRequest request2 = |
| 294 delegate_impl_->GetDefaultPresentationRequest(); | 293 delegate_impl_->GetDefaultPresentationRequest(); |
| 295 EXPECT_EQ(presentation_url2, request2.presentation_url()); | 294 EXPECT_EQ(kPresentationUrl2, request2.presentation_url()); |
| 296 EXPECT_EQ(RenderFrameHostId(render_process_id, routing_id), | 295 EXPECT_EQ(RenderFrameHostId(render_process_id, routing_id), |
| 297 request2.render_frame_host_id()); | 296 request2.render_frame_host_id()); |
| 298 EXPECT_EQ(frame_url, request2.frame_url()); | 297 EXPECT_EQ(frame_url, request2.frame_url()); |
| 299 | 298 |
| 300 // Remove default presentation URL. | 299 // Remove default presentation URL. |
| 301 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, "", | 300 delegate_impl_->SetDefaultPresentationUrls( |
| 302 callback); | 301 render_process_id, routing_id, std::vector<std::string>(), callback); |
| 303 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest()); | 302 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest()); |
| 304 } | 303 } |
| 305 | 304 |
| 306 TEST_F(PresentationServiceDelegateImplTest, DefaultPresentationUrlCallback) { | 305 TEST_F(PresentationServiceDelegateImplTest, DefaultPresentationUrlCallback) { |
| 307 RunDefaultPresentationUrlCallbackTest(false); | 306 RunDefaultPresentationUrlCallbackTest(false); |
| 308 } | 307 } |
| 309 | 308 |
| 310 TEST_F(PresentationServiceDelegateImplIncognitoTest, | 309 TEST_F(PresentationServiceDelegateImplIncognitoTest, |
| 311 DefaultPresentationUrlCallback) { | 310 DefaultPresentationUrlCallback) { |
| 312 RunDefaultPresentationUrlCallbackTest(true); | 311 RunDefaultPresentationUrlCallbackTest(true); |
| 313 } | 312 } |
| 314 | 313 |
| 315 TEST_F(PresentationServiceDelegateImplTest, | 314 TEST_F(PresentationServiceDelegateImplTest, |
| 316 DefaultPresentationRequestObserver) { | 315 DefaultPresentationRequestObserver) { |
| 317 auto callback = base::Bind( | 316 auto callback = base::Bind( |
| 318 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, | 317 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, |
| 319 base::Unretained(this)); | 318 base::Unretained(this)); |
| 320 | 319 |
| 321 StrictMock<MockDefaultPresentationRequestObserver> observer; | 320 StrictMock<MockDefaultPresentationRequestObserver> observer; |
| 322 delegate_impl_->AddDefaultPresentationRequestObserver(&observer); | 321 delegate_impl_->AddDefaultPresentationRequestObserver(&observer); |
| 323 | 322 |
| 324 GURL frame_url("http://www.google.com"); | 323 GURL frame_url(kFrameUrl); |
| 325 content::WebContentsTester::For(GetWebContents()) | 324 content::WebContentsTester::For(GetWebContents()) |
| 326 ->NavigateAndCommit(frame_url); | 325 ->NavigateAndCommit(frame_url); |
| 327 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 326 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 328 ASSERT_TRUE(main_frame); | 327 ASSERT_TRUE(main_frame); |
| 329 int render_process_id = main_frame->GetProcess()->GetID(); | 328 int render_process_id = main_frame->GetProcess()->GetID(); |
| 330 int routing_id = main_frame->GetRoutingID(); | 329 int routing_id = main_frame->GetRoutingID(); |
| 331 | 330 |
| 332 std::string url1("http://foo.fakeUrl"); | |
| 333 PresentationRequest observed_request1( | 331 PresentationRequest observed_request1( |
| 334 RenderFrameHostId(render_process_id, routing_id), url1, frame_url); | 332 RenderFrameHostId(render_process_id, routing_id), kPresentationUrl1, |
| 333 frame_url); | |
| 335 EXPECT_CALL(observer, OnDefaultPresentationChanged(Equals(observed_request1))) | 334 EXPECT_CALL(observer, OnDefaultPresentationChanged(Equals(observed_request1))) |
| 336 .Times(1); | 335 .Times(1); |
| 337 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, url1, | 336 std::vector<std::string> request1_urls({kPresentationUrl1}); |
| 338 callback); | 337 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id, |
| 338 request1_urls, callback); | |
| 339 | 339 |
| 340 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); | 340 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); |
| 341 PresentationRequest request1 = | 341 PresentationRequest request1 = |
| 342 delegate_impl_->GetDefaultPresentationRequest(); | 342 delegate_impl_->GetDefaultPresentationRequest(); |
| 343 EXPECT_TRUE(request1.Equals(observed_request1)); | 343 EXPECT_TRUE(request1.Equals(observed_request1)); |
| 344 | 344 |
| 345 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); | 345 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); |
| 346 | 346 |
| 347 std::string url2("http://youtube.com"); | |
| 348 PresentationRequest observed_request2( | 347 PresentationRequest observed_request2( |
| 349 RenderFrameHostId(render_process_id, routing_id), url2, frame_url); | 348 RenderFrameHostId(render_process_id, routing_id), kPresentationUrl2, |
| 349 frame_url); | |
| 350 EXPECT_CALL(observer, OnDefaultPresentationChanged(Equals(observed_request2))) | 350 EXPECT_CALL(observer, OnDefaultPresentationChanged(Equals(observed_request2))) |
| 351 .Times(1); | 351 .Times(1); |
| 352 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, url2, | 352 std::vector<std::string> request2_urls({kPresentationUrl2}); |
| 353 callback); | 353 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id, |
| 354 request2_urls, callback); | |
| 354 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); | 355 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); |
| 355 PresentationRequest request2 = | 356 PresentationRequest request2 = |
| 356 delegate_impl_->GetDefaultPresentationRequest(); | 357 delegate_impl_->GetDefaultPresentationRequest(); |
| 357 EXPECT_TRUE(request2.Equals(observed_request2)); | 358 EXPECT_TRUE(request2.Equals(observed_request2)); |
| 358 | 359 |
| 359 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); | 360 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); |
| 360 | 361 |
| 361 // Remove default presentation URL. | 362 // Remove default presentation URL. |
| 362 EXPECT_CALL(observer, OnDefaultPresentationRemoved()).Times(1); | 363 EXPECT_CALL(observer, OnDefaultPresentationRemoved()).Times(1); |
| 363 delegate_impl_->SetDefaultPresentationUrl(render_process_id, routing_id, "", | 364 delegate_impl_->SetDefaultPresentationUrls( |
| 364 callback); | 365 render_process_id, routing_id, std::vector<std::string>(), callback); |
| 365 } | 366 } |
| 366 | 367 |
| 367 TEST_F(PresentationServiceDelegateImplTest, ListenForConnnectionStateChange) { | 368 TEST_F(PresentationServiceDelegateImplTest, ListenForConnnectionStateChange) { |
| 368 GURL frame_url("http://www.google.com"); | 369 GURL frame_url(kFrameUrl); |
| 369 content::WebContentsTester::For(GetWebContents()) | 370 content::WebContentsTester::For(GetWebContents()) |
| 370 ->NavigateAndCommit(frame_url); | 371 ->NavigateAndCommit(frame_url); |
| 371 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 372 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 372 ASSERT_TRUE(main_frame); | 373 ASSERT_TRUE(main_frame); |
| 373 int render_process_id = main_frame->GetProcess()->GetID(); | 374 int render_process_id = main_frame->GetProcess()->GetID(); |
| 374 int routing_id = main_frame->GetRoutingID(); | 375 int routing_id = main_frame->GetRoutingID(); |
| 375 | 376 |
| 376 // Set up a PresentationConnection so we can listen to it. | 377 // Set up a PresentationConnection so we can listen to it. |
| 377 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 378 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 378 EXPECT_CALL(router_, JoinRoute(_, _, _, _, _, _, false)) | 379 EXPECT_CALL(router_, JoinRoute(_, _, _, _, _, _, false)) |
| 379 .WillOnce(SaveArg<4>(&route_response_callbacks)); | 380 .WillOnce(SaveArg<4>(&route_response_callbacks)); |
| 380 | 381 |
| 381 const std::string kPresentationUrl("http://url1.fakeUrl"); | |
| 382 const std::string kPresentationId("pid"); | 382 const std::string kPresentationId("pid"); |
| 383 std::vector<std::string> join_urls({kPresentationUrl1}); | |
| 383 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; | 384 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; |
| 384 delegate_impl_->JoinSession( | 385 delegate_impl_->JoinSession( |
| 385 render_process_id, routing_id, kPresentationUrl, kPresentationId, | 386 render_process_id, routing_id, join_urls, kPresentationId, |
| 386 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 387 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 387 OnCreateConnectionSuccess, | 388 OnCreateConnectionSuccess, |
| 388 base::Unretained(&mock_create_connection_callbacks)), | 389 base::Unretained(&mock_create_connection_callbacks)), |
| 389 base::Bind( | 390 base::Bind( |
| 390 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 391 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 391 base::Unretained(&mock_create_connection_callbacks))); | 392 base::Unretained(&mock_create_connection_callbacks))); |
| 392 | 393 |
| 393 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_)) | 394 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_)) |
| 394 .Times(1); | 395 .Times(1); |
| 395 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess( | 396 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess( |
| 396 base::WrapUnique(new MediaRoute( | 397 base::WrapUnique(new MediaRoute( |
| 397 "routeId", MediaSourceForPresentationUrl(kPresentationUrl), | 398 "routeId", MediaSourceForPresentationUrl(kPresentationUrl1), |
| 398 "mediaSinkId", "description", true, "", true)), | 399 "mediaSinkId", "description", true, "", true)), |
| 399 kPresentationId); | 400 kPresentationId); |
| 400 for (const auto& route_response_callback : route_response_callbacks) | 401 for (const auto& route_response_callback : route_response_callbacks) |
| 401 route_response_callback.Run(*result); | 402 route_response_callback.Run(*result); |
| 402 | 403 |
| 403 MockPresentationConnectionStateChangedCallback mock_callback; | 404 MockPresentationConnectionStateChangedCallback mock_callback; |
| 404 content::PresentationConnectionStateChangedCallback callback = | 405 content::PresentationConnectionStateChangedCallback callback = |
| 405 base::Bind(&MockPresentationConnectionStateChangedCallback::Run, | 406 base::Bind(&MockPresentationConnectionStateChangedCallback::Run, |
| 406 base::Unretained(&mock_callback)); | 407 base::Unretained(&mock_callback)); |
| 407 content::PresentationSessionInfo connection(kPresentationUrl, | 408 content::PresentationSessionInfo connection(kPresentationUrl1, |
| 408 kPresentationId); | 409 kPresentationId); |
| 409 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked( | 410 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked( |
| 410 Equals(callback))); | 411 Equals(callback))); |
| 411 delegate_impl_->ListenForConnectionStateChange(render_process_id, routing_id, | 412 delegate_impl_->ListenForConnectionStateChange(render_process_id, routing_id, |
| 412 connection, callback); | 413 connection, callback); |
| 413 } | 414 } |
| 414 | 415 |
| 415 TEST_F(PresentationServiceDelegateImplTest, Reset) { | 416 TEST_F(PresentationServiceDelegateImplTest, Reset) { |
| 416 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) | 417 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) |
| 417 .WillRepeatedly(Return(true)); | 418 .WillRepeatedly(Return(true)); |
| 418 | 419 |
| 419 std::string presentation_url1("http://url1.fakeUrl"); | 420 MediaSource source = MediaSourceForPresentationUrl(kPresentationUrl1); |
| 420 MediaSource source = MediaSourceForPresentationUrl(presentation_url1); | 421 MockScreenAvailabilityListener listener1(kPresentationUrl1); |
| 421 MockScreenAvailabilityListener listener1(presentation_url1); | |
| 422 | 422 |
| 423 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 423 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 424 ASSERT_TRUE(main_frame); | 424 ASSERT_TRUE(main_frame); |
| 425 int render_process_id = main_frame->GetProcess()->GetID(); | 425 int render_process_id = main_frame->GetProcess()->GetID(); |
| 426 int render_frame_id = main_frame->GetRoutingID(); | 426 int render_frame_id = main_frame->GetRoutingID(); |
| 427 | 427 |
| 428 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( | 428 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( |
| 429 render_process_id, render_frame_id, &listener1)); | 429 render_process_id, render_frame_id, &listener1)); |
| 430 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( | 430 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( |
| 431 render_process_id, render_frame_id, source.id())); | 431 render_process_id, render_frame_id, source.id())); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 447 manager->AddObserver(345, 456, &delegate_observer2); | 447 manager->AddObserver(345, 456, &delegate_observer2); |
| 448 | 448 |
| 449 // Removes |delegate_observer2|. | 449 // Removes |delegate_observer2|. |
| 450 manager->RemoveObserver(345, 456); | 450 manager->RemoveObserver(345, 456); |
| 451 | 451 |
| 452 EXPECT_CALL(delegate_observer1, OnDelegateDestroyed()).Times(1); | 452 EXPECT_CALL(delegate_observer1, OnDelegateDestroyed()).Times(1); |
| 453 manager.reset(); | 453 manager.reset(); |
| 454 } | 454 } |
| 455 | 455 |
| 456 TEST_F(PresentationServiceDelegateImplTest, SinksObserverCantRegister) { | 456 TEST_F(PresentationServiceDelegateImplTest, SinksObserverCantRegister) { |
| 457 const std::string presentation_url("http://url1.fakeUrl"); | 457 MockScreenAvailabilityListener listener(kPresentationUrl1); |
| 458 MockScreenAvailabilityListener listener(presentation_url); | |
| 459 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 458 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 460 ASSERT_TRUE(main_frame); | 459 ASSERT_TRUE(main_frame); |
| 461 int render_process_id = main_frame->GetProcess()->GetID(); | 460 int render_process_id = main_frame->GetProcess()->GetID(); |
| 462 int render_frame_id = main_frame->GetRoutingID(); | 461 int render_frame_id = main_frame->GetRoutingID(); |
| 463 | 462 |
| 464 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); | 463 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); |
| 465 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); | 464 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); |
| 466 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( | 465 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( |
| 467 render_process_id, render_frame_id, &listener)); | 466 render_process_id, render_frame_id, &listener)); |
| 468 } | 467 } |
| 469 | 468 |
| 470 } // namespace media_router | 469 } // namespace media_router |
| OLD | NEW |