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