| 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 "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/test/mock_callback.h" | 8 #include "base/test/mock_callback.h" |
| 9 #include "chrome/browser/media/router/media_source.h" | 9 #include "chrome/browser/media/router/media_source.h" |
| 10 #include "chrome/browser/media/router/media_source_helper.h" | 10 #include "chrome/browser/media/router/media_source_helper.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 void(const content::PresentationError& error)); | 70 void(const content::PresentationError& error)); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 class MockOffscreenPresentationManager : public OffscreenPresentationManager { | 73 class MockOffscreenPresentationManager : public OffscreenPresentationManager { |
| 74 public: | 74 public: |
| 75 void RegisterOffscreenPresentationController( | 75 void RegisterOffscreenPresentationController( |
| 76 const std::string& presentation_id, | 76 const std::string& presentation_id, |
| 77 const GURL& presentation_url, | 77 const GURL& presentation_url, |
| 78 const RenderFrameHostId& render_frame_id, | 78 const RenderFrameHostId& render_frame_id, |
| 79 content::PresentationConnectionPtr controller, | 79 content::PresentationConnectionPtr controller, |
| 80 content::PresentationConnectionRequest) override { | 80 content::PresentationConnectionRequest, |
| 81 const MediaRoute& route) override { |
| 81 RegisterOffscreenPresentationController(presentation_id, presentation_url, | 82 RegisterOffscreenPresentationController(presentation_id, presentation_url, |
| 82 render_frame_id); | 83 render_frame_id, route); |
| 83 } | 84 } |
| 84 | 85 |
| 85 MOCK_METHOD3(RegisterOffscreenPresentationController, | 86 MOCK_METHOD4(RegisterOffscreenPresentationController, |
| 86 void(const std::string& presentation_id, | 87 void(const std::string& presentation_id, |
| 87 const GURL& presentation_url, | 88 const GURL& presentation_url, |
| 88 const RenderFrameHostId& render_frame_id)); | 89 const RenderFrameHostId& render_frame_id, |
| 90 const MediaRoute& route)); |
| 89 MOCK_METHOD2(UnregisterOffscreenPresentationController, | 91 MOCK_METHOD2(UnregisterOffscreenPresentationController, |
| 90 void(const std::string& presentation_id, | 92 void(const std::string& presentation_id, |
| 91 const RenderFrameHostId& render_frame_id)); | 93 const RenderFrameHostId& render_frame_id)); |
| 92 MOCK_METHOD3(OnOffscreenPresentationReceiverCreated, | 94 MOCK_METHOD3(OnOffscreenPresentationReceiverCreated, |
| 93 void(const std::string& presentation_id, | 95 void(const std::string& presentation_id, |
| 94 const GURL& presentation_url, | 96 const GURL& presentation_url, |
| 95 const content::ReceiverConnectionAvailableCallback& | 97 const content::ReceiverConnectionAvailableCallback& |
| 96 receiver_callback)); | 98 receiver_callback)); |
| 97 MOCK_METHOD1(OnOffscreenPresentationReceiverTerminated, | 99 MOCK_METHOD1(OnOffscreenPresentationReceiverTerminated, |
| 98 void(const std::string& presentation_id)); | 100 void(const std::string& presentation_id)); |
| 101 MOCK_METHOD1(IsOffscreenPresentation, |
| 102 bool(const std::string& presentation_id)); |
| 103 MOCK_METHOD1(GetRoute, MediaRoute*(const std::string& presentation_id)); |
| 99 }; | 104 }; |
| 100 | 105 |
| 101 std::unique_ptr<KeyedService> BuildMockOffscreenPresentationManager( | 106 std::unique_ptr<KeyedService> BuildMockOffscreenPresentationManager( |
| 102 content::BrowserContext* context) { | 107 content::BrowserContext* context) { |
| 103 return base::MakeUnique<MockOffscreenPresentationManager>(); | 108 return base::MakeUnique<MockOffscreenPresentationManager>(); |
| 104 } | 109 } |
| 105 | 110 |
| 106 class PresentationServiceDelegateImplTest | 111 class PresentationServiceDelegateImplTest |
| 107 : public ChromeRenderViewHostTestHarness { | 112 : public ChromeRenderViewHostTestHarness { |
| 108 public: | 113 public: |
| 109 PresentationServiceDelegateImplTest() | 114 PresentationServiceDelegateImplTest() |
| 110 : delegate_impl_(nullptr), | 115 : delegate_impl_(nullptr), |
| 111 presentation_url1_(kPresentationUrl1), | 116 presentation_url1_(kPresentationUrl1), |
| 112 presentation_url2_(kPresentationUrl2), | 117 presentation_url2_(kPresentationUrl2), |
| 113 source1_(MediaSourceForPresentationUrl(presentation_url1_)), | 118 source1_(MediaSourceForPresentationUrl(presentation_url1_)), |
| 114 source2_(MediaSourceForPresentationUrl(presentation_url2_)), | 119 source2_(MediaSourceForPresentationUrl(presentation_url2_)), |
| 115 listener1_(presentation_url1_), | 120 listener1_(presentation_url1_), |
| 116 listener2_(presentation_url2_) {} | 121 listener2_(presentation_url2_) {} |
| 117 | 122 |
| 118 void SetUp() override { | 123 void SetUp() override { |
| 119 ChromeRenderViewHostTestHarness::SetUp(); | 124 ChromeRenderViewHostTestHarness::SetUp(); |
| 120 content::WebContents* wc = GetWebContents(); | 125 content::WebContents* wc = GetWebContents(); |
| 121 ASSERT_TRUE(wc); | 126 ASSERT_TRUE(wc); |
| 122 PresentationServiceDelegateImpl::CreateForWebContents(wc); | 127 PresentationServiceDelegateImpl::CreateForWebContents(wc); |
| 123 delegate_impl_ = PresentationServiceDelegateImpl::FromWebContents(wc); | 128 delegate_impl_ = PresentationServiceDelegateImpl::FromWebContents(wc); |
| 124 delegate_impl_->SetMediaRouterForTest(&router_); | 129 delegate_impl_->SetMediaRouterForTest(&router_); |
| 125 presentation_urls_.push_back(presentation_url1_); | 130 presentation_urls_.push_back(presentation_url1_); |
| 126 SetMainFrame(); | 131 SetMainFrame(); |
| 132 SetMockOffscreenPresentationManager(); |
| 127 } | 133 } |
| 128 | 134 |
| 129 MOCK_METHOD1(OnDefaultPresentationStarted, | 135 MOCK_METHOD1(OnDefaultPresentationStarted, |
| 130 void(const content::PresentationSessionInfo& session_info)); | 136 void(const content::PresentationSessionInfo& session_info)); |
| 131 | 137 |
| 132 protected: | 138 protected: |
| 133 virtual content::WebContents* GetWebContents() { return web_contents(); } | 139 virtual content::WebContents* GetWebContents() { return web_contents(); } |
| 134 | 140 |
| 141 MockOffscreenPresentationManager& GetMockOffscreenPresentationManager() { |
| 142 return *mock_offscreen_manager_; |
| 143 } |
| 144 |
| 135 void RunDefaultPresentationUrlCallbackTest(bool incognito) { | 145 void RunDefaultPresentationUrlCallbackTest(bool incognito) { |
| 136 auto callback = base::Bind( | 146 auto callback = base::Bind( |
| 137 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, | 147 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, |
| 138 base::Unretained(this)); | 148 base::Unretained(this)); |
| 139 std::vector<std::string> urls({kPresentationUrl1}); | 149 std::vector<std::string> urls({kPresentationUrl1}); |
| 140 delegate_impl_->SetDefaultPresentationUrls(main_frame_process_id_, | 150 delegate_impl_->SetDefaultPresentationUrls(main_frame_process_id_, |
| 141 main_frame_routing_id_, | 151 main_frame_routing_id_, |
| 142 presentation_urls_, callback); | 152 presentation_urls_, callback); |
| 143 | 153 |
| 144 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); | 154 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 172 delegate_impl_->OnRouteResponse(request, *result); | 182 delegate_impl_->OnRouteResponse(request, *result); |
| 173 } | 183 } |
| 174 | 184 |
| 175 void SetMainFrame() { | 185 void SetMainFrame() { |
| 176 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 186 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 177 ASSERT_TRUE(main_frame); | 187 ASSERT_TRUE(main_frame); |
| 178 main_frame_process_id_ = main_frame->GetProcess()->GetID(); | 188 main_frame_process_id_ = main_frame->GetProcess()->GetID(); |
| 179 main_frame_routing_id_ = main_frame->GetRoutingID(); | 189 main_frame_routing_id_ = main_frame->GetRoutingID(); |
| 180 } | 190 } |
| 181 | 191 |
| 192 void SetMockOffscreenPresentationManager() { |
| 193 OffscreenPresentationManagerFactory::GetInstanceForTest() |
| 194 ->SetTestingFactory(profile(), &BuildMockOffscreenPresentationManager); |
| 195 mock_offscreen_manager_ = static_cast<MockOffscreenPresentationManager*>( |
| 196 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( |
| 197 profile())); |
| 198 } |
| 199 |
| 182 PresentationServiceDelegateImpl* delegate_impl_; | 200 PresentationServiceDelegateImpl* delegate_impl_; |
| 183 MockMediaRouter router_; | 201 MockMediaRouter router_; |
| 184 const GURL presentation_url1_; | 202 const GURL presentation_url1_; |
| 185 const GURL presentation_url2_; | 203 const GURL presentation_url2_; |
| 186 std::vector<GURL> presentation_urls_; | 204 std::vector<GURL> presentation_urls_; |
| 205 MockOffscreenPresentationManager* mock_offscreen_manager_; |
| 187 | 206 |
| 188 // |source1_| and |source2_| correspond to |presentation_url1_| and | 207 // |source1_| and |source2_| correspond to |presentation_url1_| and |
| 189 // |presentation_url2_|, respectively. | 208 // |presentation_url2_|, respectively. |
| 190 MediaSource source1_; | 209 MediaSource source1_; |
| 191 MediaSource source2_; | 210 MediaSource source2_; |
| 192 | 211 |
| 193 // |listener1_| and |listener2_| correspond to |presentation_url1_| and | 212 // |listener1_| and |listener2_| correspond to |presentation_url1_| and |
| 194 // |presentation_url2_|, respectively. | 213 // |presentation_url2_|, respectively. |
| 195 MockScreenAvailabilityListener listener1_; | 214 MockScreenAvailabilityListener listener1_; |
| 196 MockScreenAvailabilityListener listener2_; | 215 MockScreenAvailabilityListener listener2_; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 content::WebContentsTester::For(GetWebContents()) | 427 content::WebContentsTester::For(GetWebContents()) |
| 409 ->NavigateAndCommit(frame_url); | 428 ->NavigateAndCommit(frame_url); |
| 410 | 429 |
| 411 // Set up a PresentationConnection so we can listen to it. | 430 // Set up a PresentationConnection so we can listen to it. |
| 412 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 431 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 413 EXPECT_CALL(router_, JoinRoute(_, _, _, _, _, _, false)) | 432 EXPECT_CALL(router_, JoinRoute(_, _, _, _, _, _, false)) |
| 414 .WillOnce(SaveArg<4>(&route_response_callbacks)); | 433 .WillOnce(SaveArg<4>(&route_response_callbacks)); |
| 415 | 434 |
| 416 const std::string kPresentationId("pid"); | 435 const std::string kPresentationId("pid"); |
| 417 presentation_urls_.push_back(GURL(kPresentationUrl3)); | 436 presentation_urls_.push_back(GURL(kPresentationUrl3)); |
| 437 |
| 438 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); |
| 439 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(kPresentationId)) |
| 440 .WillRepeatedly(Return(false)); |
| 441 |
| 418 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; | 442 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; |
| 419 delegate_impl_->JoinSession( | 443 delegate_impl_->JoinSession( |
| 420 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, | 444 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, |
| 421 kPresentationId, | 445 kPresentationId, |
| 422 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 446 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 423 OnCreateConnectionSuccess, | 447 OnCreateConnectionSuccess, |
| 424 base::Unretained(&mock_create_connection_callbacks)), | 448 base::Unretained(&mock_create_connection_callbacks)), |
| 425 base::Bind( | 449 base::Bind( |
| 426 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 450 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 427 base::Unretained(&mock_create_connection_callbacks))); | 451 base::Unretained(&mock_create_connection_callbacks))); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 manager.reset(); | 502 manager.reset(); |
| 479 } | 503 } |
| 480 | 504 |
| 481 TEST_F(PresentationServiceDelegateImplTest, SinksObserverCantRegister) { | 505 TEST_F(PresentationServiceDelegateImplTest, SinksObserverCantRegister) { |
| 482 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); | 506 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); |
| 483 EXPECT_CALL(listener1_, OnScreenAvailabilityNotSupported()); | 507 EXPECT_CALL(listener1_, OnScreenAvailabilityNotSupported()); |
| 484 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( | 508 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( |
| 485 main_frame_process_id_, main_frame_routing_id_, &listener1_)); | 509 main_frame_process_id_, main_frame_routing_id_, &listener1_)); |
| 486 } | 510 } |
| 487 | 511 |
| 512 TEST_F(PresentationServiceDelegateImplTest, |
| 513 TestCloseConnectionForOffscreenPresentation) { |
| 514 std::string presentation_id = "presentation_id"; |
| 515 GURL presentation_url = GURL("http://www.example.com/presentation.html"); |
| 516 content::PresentationSessionInfo session_info(presentation_url, |
| 517 presentation_id); |
| 518 RenderFrameHostId rfh_id(main_frame_process_id_, main_frame_routing_id_); |
| 519 MediaRoute media_route("route_id", |
| 520 MediaSourceForPresentationUrl(presentation_url), |
| 521 "mediaSinkId", "", true, "", true); |
| 522 media_route.set_offscreen_presentation(true); |
| 523 |
| 524 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); |
| 525 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(presentation_id)) |
| 526 .WillRepeatedly(Return(true)); |
| 527 |
| 528 base::MockCallback<content::PresentationSessionStartedCallback> success_cb; |
| 529 EXPECT_CALL(success_cb, Run(_)); |
| 530 |
| 531 delegate_impl_->OnStartSessionSucceeded( |
| 532 main_frame_process_id_, main_frame_routing_id_, success_cb.Get(), |
| 533 session_info, media_route); |
| 534 |
| 535 EXPECT_CALL(mock_offscreen_manager, UnregisterOffscreenPresentationController( |
| 536 presentation_id, rfh_id)) |
| 537 .Times(1); |
| 538 EXPECT_CALL(router_, DetachRoute(_)).Times(0); |
| 539 |
| 540 delegate_impl_->CloseConnection(main_frame_process_id_, |
| 541 main_frame_routing_id_, presentation_id); |
| 542 delegate_impl_->CloseConnection(main_frame_process_id_, |
| 543 main_frame_routing_id_, presentation_id); |
| 544 } |
| 545 |
| 546 TEST_F(PresentationServiceDelegateImplTest, |
| 547 TestJoinSessionForOffscreenPresentation) { |
| 548 std::string presentation_id = "presentation_id"; |
| 549 GURL presentation_url = GURL("http://www.example.com/presentation.html"); |
| 550 MediaRoute media_route("route_id", |
| 551 MediaSourceForPresentationUrl(presentation_url), |
| 552 "mediaSinkId", "", true, "", true); |
| 553 media_route.set_offscreen_presentation(true); |
| 554 |
| 555 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); |
| 556 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(presentation_id)) |
| 557 .WillRepeatedly(Return(true)); |
| 558 EXPECT_CALL(mock_offscreen_manager, GetRoute(presentation_id)) |
| 559 .WillRepeatedly(Return(&media_route)); |
| 560 |
| 561 std::vector<GURL> urls = {presentation_url}; |
| 562 base::MockCallback<content::PresentationSessionStartedCallback> success_cb; |
| 563 base::MockCallback<content::PresentationSessionErrorCallback> error_cb; |
| 564 EXPECT_CALL(success_cb, Run(_)); |
| 565 EXPECT_CALL(mock_offscreen_manager, |
| 566 UnregisterOffscreenPresentationController( |
| 567 presentation_id, RenderFrameHostId(main_frame_process_id_, |
| 568 main_frame_routing_id_))); |
| 569 |
| 570 delegate_impl_->JoinSession(main_frame_process_id_, main_frame_routing_id_, |
| 571 urls, presentation_id, success_cb.Get(), |
| 572 error_cb.Get()); |
| 573 delegate_impl_->Reset(main_frame_process_id_, main_frame_routing_id_); |
| 574 } |
| 575 |
| 488 TEST_F(PresentationServiceDelegateImplTest, ConnectToPresentation) { | 576 TEST_F(PresentationServiceDelegateImplTest, ConnectToPresentation) { |
| 489 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 577 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 490 ASSERT_TRUE(main_frame); | 578 ASSERT_TRUE(main_frame); |
| 491 int render_process_id = main_frame->GetProcess()->GetID(); | 579 int render_process_id = main_frame->GetProcess()->GetID(); |
| 492 int render_frame_id = main_frame->GetRoutingID(); | 580 int render_frame_id = main_frame->GetRoutingID(); |
| 493 std::string presentation_id = "presentation_id"; | 581 std::string presentation_id = "presentation_id"; |
| 494 GURL presentation_url = GURL("http://www.example.com/presentation.html"); | 582 GURL presentation_url = GURL("http://www.example.com/presentation.html"); |
| 495 content::PresentationSessionInfo session_info(presentation_url, | 583 content::PresentationSessionInfo session_info(presentation_url, |
| 496 presentation_id); | 584 presentation_id); |
| 497 | |
| 498 base::MockCallback< | |
| 499 base::Callback<void(const content::PresentationSessionInfo&)>> | |
| 500 mock_callback; | |
| 501 EXPECT_CALL(mock_callback, Run(_)); | |
| 502 MediaRoute media_route( | 585 MediaRoute media_route( |
| 503 "route_id", MediaSourceForPresentationUrl(session_info.presentation_url), | 586 "route_id", MediaSourceForPresentationUrl(session_info.presentation_url), |
| 504 "mediaSinkId", "", true, "", true); | 587 "mediaSinkId", "", true, "", true); |
| 505 media_route.set_offscreen_presentation(true); | 588 media_route.set_offscreen_presentation(true); |
| 589 |
| 590 base::MockCallback<content::PresentationSessionStartedCallback> success_cb; |
| 591 EXPECT_CALL(success_cb, Run(_)); |
| 592 |
| 506 delegate_impl_->OnStartSessionSucceeded(render_process_id, render_frame_id, | 593 delegate_impl_->OnStartSessionSucceeded(render_process_id, render_frame_id, |
| 507 mock_callback.Get(), session_info, | 594 success_cb.Get(), session_info, |
| 508 media_route); | 595 media_route); |
| 509 | 596 |
| 510 OffscreenPresentationManagerFactory::GetInstanceForTest()->SetTestingFactory( | 597 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); |
| 511 profile(), &BuildMockOffscreenPresentationManager); | 598 EXPECT_CALL(mock_offscreen_manager, |
| 512 MockOffscreenPresentationManager* mock_offscreen_manager = | |
| 513 static_cast<MockOffscreenPresentationManager*>( | |
| 514 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( | |
| 515 profile())); | |
| 516 EXPECT_CALL(*mock_offscreen_manager, | |
| 517 RegisterOffscreenPresentationController( | 599 RegisterOffscreenPresentationController( |
| 518 presentation_id, presentation_url, | 600 presentation_id, presentation_url, |
| 519 RenderFrameHostId(render_process_id, render_frame_id))); | 601 RenderFrameHostId(render_process_id, render_frame_id), |
| 602 Equals(media_route))); |
| 520 | 603 |
| 521 content::PresentationConnectionPtr connection_ptr; | 604 content::PresentationConnectionPtr connection_ptr; |
| 522 content::PresentationConnectionRequest connection_request; | 605 content::PresentationConnectionRequest connection_request; |
| 523 delegate_impl_->ConnectToPresentation(render_process_id, render_frame_id, | 606 delegate_impl_->ConnectToPresentation(render_process_id, render_frame_id, |
| 524 session_info, std::move(connection_ptr), | 607 session_info, std::move(connection_ptr), |
| 525 std::move(connection_request)); | 608 std::move(connection_request)); |
| 526 | 609 |
| 527 EXPECT_CALL(*mock_offscreen_manager, | 610 EXPECT_CALL(mock_offscreen_manager, |
| 528 UnregisterOffscreenPresentationController( | 611 UnregisterOffscreenPresentationController( |
| 529 presentation_id, | 612 presentation_id, |
| 530 RenderFrameHostId(render_process_id, render_frame_id))); | 613 RenderFrameHostId(render_process_id, render_frame_id))); |
| 531 EXPECT_CALL(router_, DetachRoute("route_id")); | 614 EXPECT_CALL(router_, DetachRoute("route_id")).Times(0); |
| 532 delegate_impl_->Reset(render_process_id, render_frame_id); | 615 delegate_impl_->Reset(render_process_id, render_frame_id); |
| 533 } | 616 } |
| 534 | 617 |
| 535 #if !defined(OS_ANDROID) | 618 #if !defined(OS_ANDROID) |
| 536 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { | 619 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { |
| 537 GURL frame_url(kFrameUrl); | 620 GURL frame_url(kFrameUrl); |
| 538 std::string origin(url::Origin(frame_url).Serialize()); | 621 std::string origin(url::Origin(frame_url).Serialize()); |
| 539 content::WebContentsTester::For(GetWebContents()) | 622 content::WebContentsTester::For(GetWebContents()) |
| 540 ->NavigateAndCommit(frame_url); | 623 ->NavigateAndCommit(frame_url); |
| 541 | 624 |
| 542 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; | 625 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; |
| 543 const std::string kPresentationId("auto-join"); | 626 const std::string kPresentationId("auto-join"); |
| 544 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); | 627 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); |
| 545 | 628 |
| 546 // Set the user preference for |origin| to prefer tab mirroring. | 629 // Set the user preference for |origin| to prefer tab mirroring. |
| 547 { | 630 { |
| 548 ListPrefUpdate update(profile()->GetPrefs(), | 631 ListPrefUpdate update(profile()->GetPrefs(), |
| 549 prefs::kMediaRouterTabMirroringSources); | 632 prefs::kMediaRouterTabMirroringSources); |
| 550 update->AppendIfNotPresent(base::MakeUnique<base::Value>(origin)); | 633 update->AppendIfNotPresent(base::MakeUnique<base::Value>(origin)); |
| 551 } | 634 } |
| 552 | 635 |
| 636 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); |
| 637 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(kPresentationId)) |
| 638 .WillRepeatedly(Return(false)); |
| 639 |
| 553 // Auto-join requests should be rejected. | 640 // Auto-join requests should be rejected. |
| 554 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); | 641 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); |
| 555 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); | 642 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); |
| 556 delegate_impl_->JoinSession( | 643 delegate_impl_->JoinSession( |
| 557 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, | 644 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, |
| 558 kPresentationId, | 645 kPresentationId, |
| 559 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 646 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 560 OnCreateConnectionSuccess, | 647 OnCreateConnectionSuccess, |
| 561 base::Unretained(&mock_create_connection_callbacks)), | 648 base::Unretained(&mock_create_connection_callbacks)), |
| 562 base::Bind( | 649 base::Bind( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 593 const std::string kPresentationId("auto-join"); | 680 const std::string kPresentationId("auto-join"); |
| 594 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); | 681 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); |
| 595 | 682 |
| 596 // Set the user preference for |origin| to prefer tab mirroring. | 683 // Set the user preference for |origin| to prefer tab mirroring. |
| 597 { | 684 { |
| 598 ListPrefUpdate update(profile()->GetOffTheRecordProfile()->GetPrefs(), | 685 ListPrefUpdate update(profile()->GetOffTheRecordProfile()->GetPrefs(), |
| 599 prefs::kMediaRouterTabMirroringSources); | 686 prefs::kMediaRouterTabMirroringSources); |
| 600 update->AppendIfNotPresent(base::MakeUnique<base::Value>(origin)); | 687 update->AppendIfNotPresent(base::MakeUnique<base::Value>(origin)); |
| 601 } | 688 } |
| 602 | 689 |
| 690 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); |
| 691 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(kPresentationId)) |
| 692 .WillRepeatedly(Return(false)); |
| 693 |
| 603 // Setting the pref in incognito shouldn't set it for the non-incognito | 694 // Setting the pref in incognito shouldn't set it for the non-incognito |
| 604 // profile. | 695 // profile. |
| 605 const base::ListValue* non_incognito_origins = | 696 const base::ListValue* non_incognito_origins = |
| 606 profile()->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources); | 697 profile()->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources); |
| 607 EXPECT_EQ(non_incognito_origins->Find(base::Value(origin)), | 698 EXPECT_EQ(non_incognito_origins->Find(base::Value(origin)), |
| 608 non_incognito_origins->end()); | 699 non_incognito_origins->end()); |
| 609 | 700 |
| 610 // Auto-join requests should be rejected. | 701 // Auto-join requests should be rejected. |
| 611 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); | 702 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); |
| 612 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); | 703 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 635 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 726 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 636 OnCreateConnectionSuccess, | 727 OnCreateConnectionSuccess, |
| 637 base::Unretained(&mock_create_connection_callbacks)), | 728 base::Unretained(&mock_create_connection_callbacks)), |
| 638 base::Bind( | 729 base::Bind( |
| 639 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 730 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 640 base::Unretained(&mock_create_connection_callbacks))); | 731 base::Unretained(&mock_create_connection_callbacks))); |
| 641 } | 732 } |
| 642 #endif // !defined(OS_ANDROID) | 733 #endif // !defined(OS_ANDROID) |
| 643 | 734 |
| 644 } // namespace media_router | 735 } // namespace media_router |
| OLD | NEW |