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 "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() { | |
|
mark a. foltz
2017/03/16 23:02:17
Maybe return MockOffscreenPresentationManager& to
zhaobin
2017/03/17 00:31:51
Done.
| |
| 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( | |
| 536 *mock_offscreen_manager, | |
| 537 UnregisterOffscreenPresentationController(presentation_id, rfh_id)) | |
| 538 .Times(1); | |
| 539 EXPECT_CALL(router_, DetachRoute(_)).Times(0); | |
| 540 | |
| 541 delegate_impl_->CloseConnection(main_frame_process_id_, | |
| 542 main_frame_routing_id_, presentation_id); | |
| 543 delegate_impl_->CloseConnection(main_frame_process_id_, | |
| 544 main_frame_routing_id_, presentation_id); | |
| 545 } | |
| 546 | |
| 547 TEST_F(PresentationServiceDelegateImplTest, | |
| 548 TestJoinSessionForOffscreenPresentation) { | |
| 549 std::string presentation_id = "presentation_id"; | |
| 550 GURL presentation_url = GURL("http://www.example.com/presentation.html"); | |
| 551 MediaRoute media_route("route_id", | |
| 552 MediaSourceForPresentationUrl(presentation_url), | |
| 553 "mediaSinkId", "", true, "", true); | |
| 554 media_route.set_offscreen_presentation(true); | |
| 555 | |
| 556 auto* mock_offscreen_manager = GetMockOffscreenPresentationManager(); | |
| 557 EXPECT_CALL(*mock_offscreen_manager, IsOffscreenPresentation(presentation_id)) | |
| 558 .WillRepeatedly(Return(true)); | |
| 559 EXPECT_CALL(*mock_offscreen_manager, GetRoute(presentation_id)) | |
| 560 .WillRepeatedly(Return(&media_route)); | |
| 561 | |
| 562 std::vector<GURL> urls = {presentation_url}; | |
| 563 base::MockCallback<content::PresentationSessionStartedCallback> success_cb; | |
| 564 base::MockCallback<content::PresentationSessionErrorCallback> error_cb; | |
| 565 EXPECT_CALL(success_cb, Run(_)); | |
| 566 EXPECT_CALL(*mock_offscreen_manager, | |
| 567 UnregisterOffscreenPresentationController( | |
| 568 presentation_id, RenderFrameHostId(main_frame_process_id_, | |
| 569 main_frame_routing_id_))); | |
| 570 | |
| 571 delegate_impl_->JoinSession(main_frame_process_id_, main_frame_routing_id_, | |
| 572 urls, presentation_id, success_cb.Get(), | |
| 573 error_cb.Get()); | |
| 574 delegate_impl_->Reset(main_frame_process_id_, main_frame_routing_id_); | |
| 575 } | |
| 576 | |
| 488 TEST_F(PresentationServiceDelegateImplTest, ConnectToPresentation) { | 577 TEST_F(PresentationServiceDelegateImplTest, ConnectToPresentation) { |
| 489 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 578 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 490 ASSERT_TRUE(main_frame); | 579 ASSERT_TRUE(main_frame); |
| 491 int render_process_id = main_frame->GetProcess()->GetID(); | 580 int render_process_id = main_frame->GetProcess()->GetID(); |
| 492 int render_frame_id = main_frame->GetRoutingID(); | 581 int render_frame_id = main_frame->GetRoutingID(); |
| 493 std::string presentation_id = "presentation_id"; | 582 std::string presentation_id = "presentation_id"; |
| 494 GURL presentation_url = GURL("http://www.example.com/presentation.html"); | 583 GURL presentation_url = GURL("http://www.example.com/presentation.html"); |
| 495 content::PresentationSessionInfo session_info(presentation_url, | 584 content::PresentationSessionInfo session_info(presentation_url, |
| 496 presentation_id); | 585 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( | 586 MediaRoute media_route( |
| 503 "route_id", MediaSourceForPresentationUrl(session_info.presentation_url), | 587 "route_id", MediaSourceForPresentationUrl(session_info.presentation_url), |
| 504 "mediaSinkId", "", true, "", true); | 588 "mediaSinkId", "", true, "", true); |
| 505 media_route.set_offscreen_presentation(true); | 589 media_route.set_offscreen_presentation(true); |
| 590 | |
| 591 base::MockCallback<content::PresentationSessionStartedCallback> success_cb; | |
| 592 EXPECT_CALL(success_cb, Run(_)); | |
| 593 | |
| 506 delegate_impl_->OnStartSessionSucceeded(render_process_id, render_frame_id, | 594 delegate_impl_->OnStartSessionSucceeded(render_process_id, render_frame_id, |
| 507 mock_callback.Get(), session_info, | 595 success_cb.Get(), session_info, |
| 508 media_route); | 596 media_route); |
| 509 | 597 |
| 510 OffscreenPresentationManagerFactory::GetInstanceForTest()->SetTestingFactory( | 598 auto* mock_offscreen_manager = GetMockOffscreenPresentationManager(); |
| 511 profile(), &BuildMockOffscreenPresentationManager); | |
| 512 MockOffscreenPresentationManager* mock_offscreen_manager = | |
| 513 static_cast<MockOffscreenPresentationManager*>( | |
| 514 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( | |
| 515 profile())); | |
| 516 EXPECT_CALL(*mock_offscreen_manager, | 599 EXPECT_CALL(*mock_offscreen_manager, |
| 517 RegisterOffscreenPresentationController( | 600 RegisterOffscreenPresentationController( |
| 518 presentation_id, presentation_url, | 601 presentation_id, presentation_url, |
| 519 RenderFrameHostId(render_process_id, render_frame_id))); | 602 RenderFrameHostId(render_process_id, render_frame_id), |
| 603 Equals(media_route))); | |
| 520 | 604 |
| 521 content::PresentationConnectionPtr connection_ptr; | 605 content::PresentationConnectionPtr connection_ptr; |
| 522 content::PresentationConnectionRequest connection_request; | 606 content::PresentationConnectionRequest connection_request; |
| 523 delegate_impl_->ConnectToPresentation(render_process_id, render_frame_id, | 607 delegate_impl_->ConnectToPresentation(render_process_id, render_frame_id, |
| 524 session_info, std::move(connection_ptr), | 608 session_info, std::move(connection_ptr), |
| 525 std::move(connection_request)); | 609 std::move(connection_request)); |
| 526 | 610 |
| 527 EXPECT_CALL(*mock_offscreen_manager, | 611 EXPECT_CALL(*mock_offscreen_manager, |
| 528 UnregisterOffscreenPresentationController( | 612 UnregisterOffscreenPresentationController( |
| 529 presentation_id, | 613 presentation_id, |
| 530 RenderFrameHostId(render_process_id, render_frame_id))); | 614 RenderFrameHostId(render_process_id, render_frame_id))); |
| 531 EXPECT_CALL(router_, DetachRoute("route_id")); | 615 EXPECT_CALL(router_, DetachRoute("route_id")).Times(0); |
| 532 delegate_impl_->Reset(render_process_id, render_frame_id); | 616 delegate_impl_->Reset(render_process_id, render_frame_id); |
| 533 } | 617 } |
| 534 | 618 |
| 535 #if !defined(OS_ANDROID) | 619 #if !defined(OS_ANDROID) |
| 536 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { | 620 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { |
| 537 GURL frame_url(kFrameUrl); | 621 GURL frame_url(kFrameUrl); |
| 538 std::string origin(url::Origin(frame_url).Serialize()); | 622 std::string origin(url::Origin(frame_url).Serialize()); |
| 539 content::WebContentsTester::For(GetWebContents()) | 623 content::WebContentsTester::For(GetWebContents()) |
| 540 ->NavigateAndCommit(frame_url); | 624 ->NavigateAndCommit(frame_url); |
| 541 | 625 |
| 542 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; | 626 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; |
| 543 const std::string kPresentationId("auto-join"); | 627 const std::string kPresentationId("auto-join"); |
| 544 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); | 628 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); |
| 545 | 629 |
| 546 // Set the user preference for |origin| to prefer tab mirroring. | 630 // Set the user preference for |origin| to prefer tab mirroring. |
| 547 { | 631 { |
| 548 ListPrefUpdate update(profile()->GetPrefs(), | 632 ListPrefUpdate update(profile()->GetPrefs(), |
| 549 prefs::kMediaRouterTabMirroringSources); | 633 prefs::kMediaRouterTabMirroringSources); |
| 550 update->AppendIfNotPresent(base::MakeUnique<base::Value>(origin)); | 634 update->AppendIfNotPresent(base::MakeUnique<base::Value>(origin)); |
| 551 } | 635 } |
| 552 | 636 |
| 637 auto* mock_offscreen_manager = GetMockOffscreenPresentationManager(); | |
| 638 EXPECT_CALL(*mock_offscreen_manager, IsOffscreenPresentation(kPresentationId)) | |
| 639 .WillRepeatedly(Return(false)); | |
| 640 | |
| 553 // Auto-join requests should be rejected. | 641 // Auto-join requests should be rejected. |
| 554 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); | 642 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); |
| 555 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); | 643 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); |
| 556 delegate_impl_->JoinSession( | 644 delegate_impl_->JoinSession( |
| 557 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, | 645 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, |
| 558 kPresentationId, | 646 kPresentationId, |
| 559 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 647 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 560 OnCreateConnectionSuccess, | 648 OnCreateConnectionSuccess, |
| 561 base::Unretained(&mock_create_connection_callbacks)), | 649 base::Unretained(&mock_create_connection_callbacks)), |
| 562 base::Bind( | 650 base::Bind( |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 593 const std::string kPresentationId("auto-join"); | 681 const std::string kPresentationId("auto-join"); |
| 594 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); | 682 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); |
| 595 | 683 |
| 596 // Set the user preference for |origin| to prefer tab mirroring. | 684 // Set the user preference for |origin| to prefer tab mirroring. |
| 597 { | 685 { |
| 598 ListPrefUpdate update(profile()->GetOffTheRecordProfile()->GetPrefs(), | 686 ListPrefUpdate update(profile()->GetOffTheRecordProfile()->GetPrefs(), |
| 599 prefs::kMediaRouterTabMirroringSources); | 687 prefs::kMediaRouterTabMirroringSources); |
| 600 update->AppendIfNotPresent(base::MakeUnique<base::Value>(origin)); | 688 update->AppendIfNotPresent(base::MakeUnique<base::Value>(origin)); |
| 601 } | 689 } |
| 602 | 690 |
| 691 auto* mock_offscreen_manager = GetMockOffscreenPresentationManager(); | |
| 692 EXPECT_CALL(*mock_offscreen_manager, IsOffscreenPresentation(kPresentationId)) | |
| 693 .WillRepeatedly(Return(false)); | |
| 694 | |
| 603 // Setting the pref in incognito shouldn't set it for the non-incognito | 695 // Setting the pref in incognito shouldn't set it for the non-incognito |
| 604 // profile. | 696 // profile. |
| 605 const base::ListValue* non_incognito_origins = | 697 const base::ListValue* non_incognito_origins = |
| 606 profile()->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources); | 698 profile()->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources); |
| 607 EXPECT_EQ(non_incognito_origins->Find(base::Value(origin)), | 699 EXPECT_EQ(non_incognito_origins->Find(base::Value(origin)), |
| 608 non_incognito_origins->end()); | 700 non_incognito_origins->end()); |
| 609 | 701 |
| 610 // Auto-join requests should be rejected. | 702 // Auto-join requests should be rejected. |
| 611 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); | 703 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); |
| 612 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); | 704 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 635 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 727 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 636 OnCreateConnectionSuccess, | 728 OnCreateConnectionSuccess, |
| 637 base::Unretained(&mock_create_connection_callbacks)), | 729 base::Unretained(&mock_create_connection_callbacks)), |
| 638 base::Bind( | 730 base::Bind( |
| 639 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 731 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 640 base::Unretained(&mock_create_connection_callbacks))); | 732 base::Unretained(&mock_create_connection_callbacks))); |
| 641 } | 733 } |
| 642 #endif // !defined(OS_ANDROID) | 734 #endif // !defined(OS_ANDROID) |
| 643 | 735 |
| 644 } // namespace media_router | 736 } // namespace media_router |
| OLD | NEW |