| 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" |
| 11 #include "chrome/browser/media/router/mock_media_router.h" | 11 #include "chrome/browser/media/router/mock_media_router.h" |
| 12 #include "chrome/browser/media/router/mock_screen_availability_listener.h" | 12 #include "chrome/browser/media/router/mock_screen_availability_listener.h" |
| 13 #include "chrome/browser/media/router/offscreen_presentation_manager.h" | 13 #include "chrome/browser/media/router/offscreen_presentation_manager.h" |
| 14 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" | 14 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" |
| 15 #include "chrome/browser/media/router/route_request_result.h" | 15 #include "chrome/browser/media/router/route_request_result.h" |
| 16 #include "chrome/browser/media/router/test_helper.h" | 16 #include "chrome/browser/media/router/test_helper.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 21 #include "components/prefs/scoped_user_pref_update.h" | 21 #include "components/prefs/scoped_user_pref_update.h" |
| 22 #include "content/public/browser/presentation_screen_availability_listener.h" | 22 #include "content/public/browser/presentation_screen_availability_listener.h" |
| 23 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/common/presentation_session.h" | 25 #include "content/public/common/presentation_info.h" |
| 26 #include "content/public/test/web_contents_tester.h" | 26 #include "content/public/test/web_contents_tester.h" |
| 27 #include "mojo/public/cpp/bindings/binding.h" | 27 #include "mojo/public/cpp/bindings/binding.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "url/origin.h" | 29 #include "url/origin.h" |
| 30 | 30 |
| 31 using ::testing::_; | 31 using ::testing::_; |
| 32 using ::testing::Mock; | 32 using ::testing::Mock; |
| 33 using ::testing::Return; | 33 using ::testing::Return; |
| 34 using ::testing::SaveArg; | 34 using ::testing::SaveArg; |
| 35 using ::testing::StrictMock; | 35 using ::testing::StrictMock; |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 const char kPresentationUrl1[] = "http://foo.fakeurl.com/"; | 39 const char kPresentationUrl1[] = "http://foo.fakeurl.com/"; |
| 40 const char kPresentationUrl2[] = "http://bar.fakeurl.com/"; | 40 const char kPresentationUrl2[] = "http://bar.fakeurl.com/"; |
| 41 const char kPresentationUrl3[] = | 41 const char kPresentationUrl3[] = |
| 42 "https://google.com/cast#__castAppId__=233637DE"; | 42 "https://google.com/cast#__castAppId__=233637DE"; |
| 43 const char kFrameUrl[] = "http://anotherframeurl.fakeurl.com/"; | 43 const char kFrameUrl[] = "http://anotherframeurl.fakeurl.com/"; |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 namespace media_router { | 47 namespace media_router { |
| 48 | 48 |
| 49 class MockDelegateObserver | 49 class MockDelegateObserver |
| 50 : public content::PresentationServiceDelegate::Observer { | 50 : public content::PresentationServiceDelegate::Observer { |
| 51 public: | 51 public: |
| 52 MOCK_METHOD0(OnDelegateDestroyed, void()); | 52 MOCK_METHOD0(OnDelegateDestroyed, void()); |
| 53 MOCK_METHOD1(OnDefaultPresentationStarted, | 53 MOCK_METHOD1(OnDefaultPresentationStarted, |
| 54 void(const content::PresentationSessionInfo&)); | 54 void(const content::PresentationInfo&)); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class MockDefaultPresentationRequestObserver | 57 class MockDefaultPresentationRequestObserver |
| 58 : public PresentationServiceDelegateImpl:: | 58 : public PresentationServiceDelegateImpl:: |
| 59 DefaultPresentationRequestObserver { | 59 DefaultPresentationRequestObserver { |
| 60 public: | 60 public: |
| 61 MOCK_METHOD1(OnDefaultPresentationChanged, void(const PresentationRequest&)); | 61 MOCK_METHOD1(OnDefaultPresentationChanged, void(const PresentationRequest&)); |
| 62 MOCK_METHOD0(OnDefaultPresentationRemoved, void()); | 62 MOCK_METHOD0(OnDefaultPresentationRemoved, void()); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 class MockCreatePresentationConnnectionCallbacks { | 65 class MockCreatePresentationConnnectionCallbacks { |
| 66 public: | 66 public: |
| 67 MOCK_METHOD1(OnCreateConnectionSuccess, | 67 MOCK_METHOD1(OnCreateConnectionSuccess, |
| 68 void(const content::PresentationSessionInfo& connection)); | 68 void(const content::PresentationInfo& connection)); |
| 69 MOCK_METHOD1(OnCreateConnectionError, | 69 MOCK_METHOD1(OnCreateConnectionError, |
| 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, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 ASSERT_TRUE(wc); | 126 ASSERT_TRUE(wc); |
| 127 PresentationServiceDelegateImpl::CreateForWebContents(wc); | 127 PresentationServiceDelegateImpl::CreateForWebContents(wc); |
| 128 delegate_impl_ = PresentationServiceDelegateImpl::FromWebContents(wc); | 128 delegate_impl_ = PresentationServiceDelegateImpl::FromWebContents(wc); |
| 129 delegate_impl_->SetMediaRouterForTest(&router_); | 129 delegate_impl_->SetMediaRouterForTest(&router_); |
| 130 presentation_urls_.push_back(presentation_url1_); | 130 presentation_urls_.push_back(presentation_url1_); |
| 131 SetMainFrame(); | 131 SetMainFrame(); |
| 132 SetMockOffscreenPresentationManager(); | 132 SetMockOffscreenPresentationManager(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 MOCK_METHOD1(OnDefaultPresentationStarted, | 135 MOCK_METHOD1(OnDefaultPresentationStarted, |
| 136 void(const content::PresentationSessionInfo& session_info)); | 136 void(const content::PresentationInfo& presentation_info)); |
| 137 | 137 |
| 138 protected: | 138 protected: |
| 139 virtual content::WebContents* GetWebContents() { return web_contents(); } | 139 virtual content::WebContents* GetWebContents() { return web_contents(); } |
| 140 | 140 |
| 141 MockOffscreenPresentationManager& GetMockOffscreenPresentationManager() { | 141 MockOffscreenPresentationManager& GetMockOffscreenPresentationManager() { |
| 142 return *mock_offscreen_manager_; | 142 return *mock_offscreen_manager_; |
| 143 } | 143 } |
| 144 | 144 |
| 145 void RunDefaultPresentationUrlCallbackTest(bool incognito) { | 145 void RunDefaultPresentationUrlCallbackTest(bool incognito) { |
| 146 auto callback = base::Bind( | 146 auto callback = base::Bind( |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 .WillOnce(SaveArg<4>(&route_response_callbacks)); | 433 .WillOnce(SaveArg<4>(&route_response_callbacks)); |
| 434 | 434 |
| 435 const std::string kPresentationId("pid"); | 435 const std::string kPresentationId("pid"); |
| 436 presentation_urls_.push_back(GURL(kPresentationUrl3)); | 436 presentation_urls_.push_back(GURL(kPresentationUrl3)); |
| 437 | 437 |
| 438 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); | 438 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); |
| 439 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(kPresentationId)) | 439 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(kPresentationId)) |
| 440 .WillRepeatedly(Return(false)); | 440 .WillRepeatedly(Return(false)); |
| 441 | 441 |
| 442 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; | 442 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; |
| 443 delegate_impl_->JoinSession( | 443 delegate_impl_->ReconnectPresentation( |
| 444 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, | 444 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, |
| 445 kPresentationId, | 445 kPresentationId, |
| 446 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 446 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 447 OnCreateConnectionSuccess, | 447 OnCreateConnectionSuccess, |
| 448 base::Unretained(&mock_create_connection_callbacks)), | 448 base::Unretained(&mock_create_connection_callbacks)), |
| 449 base::Bind( | 449 base::Bind( |
| 450 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 450 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 451 base::Unretained(&mock_create_connection_callbacks))); | 451 base::Unretained(&mock_create_connection_callbacks))); |
| 452 | 452 |
| 453 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_)) | 453 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_)) |
| 454 .Times(1); | 454 .Times(1); |
| 455 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess( | 455 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess( |
| 456 MediaRoute("routeId", source1_, "mediaSinkId", "description", true, "", | 456 MediaRoute("routeId", source1_, "mediaSinkId", "description", true, "", |
| 457 true), | 457 true), |
| 458 kPresentationId); | 458 kPresentationId); |
| 459 for (const auto& route_response_callback : route_response_callbacks) | 459 for (const auto& route_response_callback : route_response_callbacks) |
| 460 route_response_callback.Run(*result); | 460 route_response_callback.Run(*result); |
| 461 | 461 |
| 462 base::MockCallback<content::PresentationConnectionStateChangedCallback> | 462 base::MockCallback<content::PresentationConnectionStateChangedCallback> |
| 463 mock_callback; | 463 mock_callback; |
| 464 auto callback = mock_callback.Get(); | 464 auto callback = mock_callback.Get(); |
| 465 content::PresentationSessionInfo connection(presentation_url1_, | 465 content::PresentationInfo connection(presentation_url1_, kPresentationId); |
| 466 kPresentationId); | |
| 467 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked( | 466 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked( |
| 468 Equals(callback))); | 467 Equals(callback))); |
| 469 delegate_impl_->ListenForConnectionStateChange( | 468 delegate_impl_->ListenForConnectionStateChange( |
| 470 main_frame_process_id_, main_frame_routing_id_, connection, callback); | 469 main_frame_process_id_, main_frame_routing_id_, connection, callback); |
| 471 } | 470 } |
| 472 | 471 |
| 473 TEST_F(PresentationServiceDelegateImplTest, Reset) { | 472 TEST_F(PresentationServiceDelegateImplTest, Reset) { |
| 474 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) | 473 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) |
| 475 .WillRepeatedly(Return(true)); | 474 .WillRepeatedly(Return(true)); |
| 476 | 475 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 506 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); | 505 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); |
| 507 EXPECT_CALL(listener1_, OnScreenAvailabilityNotSupported()); | 506 EXPECT_CALL(listener1_, OnScreenAvailabilityNotSupported()); |
| 508 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( | 507 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( |
| 509 main_frame_process_id_, main_frame_routing_id_, &listener1_)); | 508 main_frame_process_id_, main_frame_routing_id_, &listener1_)); |
| 510 } | 509 } |
| 511 | 510 |
| 512 TEST_F(PresentationServiceDelegateImplTest, | 511 TEST_F(PresentationServiceDelegateImplTest, |
| 513 TestCloseConnectionForOffscreenPresentation) { | 512 TestCloseConnectionForOffscreenPresentation) { |
| 514 std::string presentation_id = "presentation_id"; | 513 std::string presentation_id = "presentation_id"; |
| 515 GURL presentation_url = GURL("http://www.example.com/presentation.html"); | 514 GURL presentation_url = GURL("http://www.example.com/presentation.html"); |
| 516 content::PresentationSessionInfo session_info(presentation_url, | 515 content::PresentationInfo presentation_info(presentation_url, |
| 517 presentation_id); | 516 presentation_id); |
| 518 RenderFrameHostId rfh_id(main_frame_process_id_, main_frame_routing_id_); | 517 RenderFrameHostId rfh_id(main_frame_process_id_, main_frame_routing_id_); |
| 519 MediaRoute media_route("route_id", | 518 MediaRoute media_route("route_id", |
| 520 MediaSourceForPresentationUrl(presentation_url), | 519 MediaSourceForPresentationUrl(presentation_url), |
| 521 "mediaSinkId", "", true, "", true); | 520 "mediaSinkId", "", true, "", true); |
| 522 media_route.set_offscreen_presentation(true); | 521 media_route.set_offscreen_presentation(true); |
| 523 | 522 |
| 524 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); | 523 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); |
| 525 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(presentation_id)) | 524 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(presentation_id)) |
| 526 .WillRepeatedly(Return(true)); | 525 .WillRepeatedly(Return(true)); |
| 527 | 526 |
| 528 base::MockCallback<content::PresentationSessionStartedCallback> success_cb; | 527 base::MockCallback<content::PresentationConnectionCallback> success_cb; |
| 529 EXPECT_CALL(success_cb, Run(_)); | 528 EXPECT_CALL(success_cb, Run(_)); |
| 530 | 529 |
| 531 delegate_impl_->OnStartSessionSucceeded( | 530 delegate_impl_->OnStartPresentationSucceeded( |
| 532 main_frame_process_id_, main_frame_routing_id_, success_cb.Get(), | 531 main_frame_process_id_, main_frame_routing_id_, success_cb.Get(), |
| 533 session_info, media_route); | 532 presentation_info, media_route); |
| 534 | 533 |
| 535 EXPECT_CALL(mock_offscreen_manager, UnregisterOffscreenPresentationController( | 534 EXPECT_CALL(mock_offscreen_manager, UnregisterOffscreenPresentationController( |
| 536 presentation_id, rfh_id)) | 535 presentation_id, rfh_id)) |
| 537 .Times(1); | 536 .Times(1); |
| 538 EXPECT_CALL(router_, DetachRoute(_)).Times(0); | 537 EXPECT_CALL(router_, DetachRoute(_)).Times(0); |
| 539 | 538 |
| 540 delegate_impl_->CloseConnection(main_frame_process_id_, | 539 delegate_impl_->CloseConnection(main_frame_process_id_, |
| 541 main_frame_routing_id_, presentation_id); | 540 main_frame_routing_id_, presentation_id); |
| 542 delegate_impl_->CloseConnection(main_frame_process_id_, | 541 delegate_impl_->CloseConnection(main_frame_process_id_, |
| 543 main_frame_routing_id_, presentation_id); | 542 main_frame_routing_id_, presentation_id); |
| 544 } | 543 } |
| 545 | 544 |
| 546 TEST_F(PresentationServiceDelegateImplTest, | 545 TEST_F(PresentationServiceDelegateImplTest, |
| 547 TestJoinSessionForOffscreenPresentation) { | 546 TestReconnectPresentationForOffscreenPresentation) { |
| 548 std::string presentation_id = "presentation_id"; | 547 std::string presentation_id = "presentation_id"; |
| 549 GURL presentation_url = GURL("http://www.example.com/presentation.html"); | 548 GURL presentation_url = GURL("http://www.example.com/presentation.html"); |
| 550 MediaRoute media_route("route_id", | 549 MediaRoute media_route("route_id", |
| 551 MediaSourceForPresentationUrl(presentation_url), | 550 MediaSourceForPresentationUrl(presentation_url), |
| 552 "mediaSinkId", "", true, "", true); | 551 "mediaSinkId", "", true, "", true); |
| 553 media_route.set_offscreen_presentation(true); | 552 media_route.set_offscreen_presentation(true); |
| 554 | 553 |
| 555 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); | 554 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); |
| 556 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(presentation_id)) | 555 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(presentation_id)) |
| 557 .WillRepeatedly(Return(true)); | 556 .WillRepeatedly(Return(true)); |
| 558 EXPECT_CALL(mock_offscreen_manager, GetRoute(presentation_id)) | 557 EXPECT_CALL(mock_offscreen_manager, GetRoute(presentation_id)) |
| 559 .WillRepeatedly(Return(&media_route)); | 558 .WillRepeatedly(Return(&media_route)); |
| 560 | 559 |
| 561 std::vector<GURL> urls = {presentation_url}; | 560 std::vector<GURL> urls = {presentation_url}; |
| 562 base::MockCallback<content::PresentationSessionStartedCallback> success_cb; | 561 base::MockCallback<content::PresentationConnectionCallback> success_cb; |
| 563 base::MockCallback<content::PresentationSessionErrorCallback> error_cb; | 562 base::MockCallback<content::PresentationConnectionErrorCallback> error_cb; |
| 564 EXPECT_CALL(success_cb, Run(_)); | 563 EXPECT_CALL(success_cb, Run(_)); |
| 565 EXPECT_CALL(mock_offscreen_manager, | 564 EXPECT_CALL(mock_offscreen_manager, |
| 566 UnregisterOffscreenPresentationController( | 565 UnregisterOffscreenPresentationController( |
| 567 presentation_id, RenderFrameHostId(main_frame_process_id_, | 566 presentation_id, RenderFrameHostId(main_frame_process_id_, |
| 568 main_frame_routing_id_))); | 567 main_frame_routing_id_))); |
| 569 | 568 |
| 570 delegate_impl_->JoinSession(main_frame_process_id_, main_frame_routing_id_, | 569 delegate_impl_->ReconnectPresentation( |
| 571 urls, presentation_id, success_cb.Get(), | 570 main_frame_process_id_, main_frame_routing_id_, urls, presentation_id, |
| 572 error_cb.Get()); | 571 success_cb.Get(), error_cb.Get()); |
| 573 delegate_impl_->Reset(main_frame_process_id_, main_frame_routing_id_); | 572 delegate_impl_->Reset(main_frame_process_id_, main_frame_routing_id_); |
| 574 } | 573 } |
| 575 | 574 |
| 576 TEST_F(PresentationServiceDelegateImplTest, ConnectToPresentation) { | 575 TEST_F(PresentationServiceDelegateImplTest, ConnectToPresentation) { |
| 577 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 576 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 578 ASSERT_TRUE(main_frame); | 577 ASSERT_TRUE(main_frame); |
| 579 int render_process_id = main_frame->GetProcess()->GetID(); | 578 int render_process_id = main_frame->GetProcess()->GetID(); |
| 580 int render_frame_id = main_frame->GetRoutingID(); | 579 int render_frame_id = main_frame->GetRoutingID(); |
| 581 std::string presentation_id = "presentation_id"; | 580 std::string presentation_id = "presentation_id"; |
| 582 GURL presentation_url = GURL("http://www.example.com/presentation.html"); | 581 GURL presentation_url = GURL("http://www.example.com/presentation.html"); |
| 583 content::PresentationSessionInfo session_info(presentation_url, | 582 content::PresentationInfo presentation_info(presentation_url, |
| 584 presentation_id); | 583 presentation_id); |
| 584 |
| 585 MediaRoute media_route( | 585 MediaRoute media_route( |
| 586 "route_id", MediaSourceForPresentationUrl(session_info.presentation_url), | 586 "route_id", |
| 587 MediaSourceForPresentationUrl(presentation_info.presentation_url), |
| 587 "mediaSinkId", "", true, "", true); | 588 "mediaSinkId", "", true, "", true); |
| 588 media_route.set_offscreen_presentation(true); | 589 media_route.set_offscreen_presentation(true); |
| 589 | 590 |
| 590 base::MockCallback<content::PresentationSessionStartedCallback> success_cb; | 591 base::MockCallback<content::PresentationConnectionCallback> success_cb; |
| 591 EXPECT_CALL(success_cb, Run(_)); | 592 EXPECT_CALL(success_cb, Run(_)); |
| 592 | 593 |
| 593 delegate_impl_->OnStartSessionSucceeded(render_process_id, render_frame_id, | 594 delegate_impl_->OnStartPresentationSucceeded( |
| 594 success_cb.Get(), session_info, | 595 render_process_id, render_frame_id, success_cb.Get(), presentation_info, |
| 595 media_route); | 596 media_route); |
| 596 | 597 |
| 597 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); | 598 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); |
| 598 EXPECT_CALL(mock_offscreen_manager, | 599 EXPECT_CALL(mock_offscreen_manager, |
| 599 RegisterOffscreenPresentationController( | 600 RegisterOffscreenPresentationController( |
| 600 presentation_id, presentation_url, | 601 presentation_id, presentation_url, |
| 601 RenderFrameHostId(render_process_id, render_frame_id), | 602 RenderFrameHostId(render_process_id, render_frame_id), |
| 602 Equals(media_route))); | 603 Equals(media_route))); |
| 603 | 604 |
| 604 content::PresentationConnectionPtr connection_ptr; | 605 content::PresentationConnectionPtr connection_ptr; |
| 605 content::PresentationConnectionRequest connection_request; | 606 content::PresentationConnectionRequest connection_request; |
| 606 delegate_impl_->ConnectToPresentation(render_process_id, render_frame_id, | 607 delegate_impl_->ConnectToPresentation( |
| 607 session_info, std::move(connection_ptr), | 608 render_process_id, render_frame_id, presentation_info, |
| 608 std::move(connection_request)); | 609 std::move(connection_ptr), std::move(connection_request)); |
| 609 | 610 |
| 610 EXPECT_CALL(mock_offscreen_manager, | 611 EXPECT_CALL(mock_offscreen_manager, |
| 611 UnregisterOffscreenPresentationController( | 612 UnregisterOffscreenPresentationController( |
| 612 presentation_id, | 613 presentation_id, |
| 613 RenderFrameHostId(render_process_id, render_frame_id))); | 614 RenderFrameHostId(render_process_id, render_frame_id))); |
| 614 EXPECT_CALL(router_, DetachRoute("route_id")).Times(0); | 615 EXPECT_CALL(router_, DetachRoute("route_id")).Times(0); |
| 615 delegate_impl_->Reset(render_process_id, render_frame_id); | 616 delegate_impl_->Reset(render_process_id, render_frame_id); |
| 616 } | 617 } |
| 617 | 618 |
| 618 #if !defined(OS_ANDROID) | 619 #if !defined(OS_ANDROID) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 633 update->AppendIfNotPresent(base::MakeUnique<base::Value>(origin)); | 634 update->AppendIfNotPresent(base::MakeUnique<base::Value>(origin)); |
| 634 } | 635 } |
| 635 | 636 |
| 636 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); | 637 auto& mock_offscreen_manager = GetMockOffscreenPresentationManager(); |
| 637 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(kPresentationId)) | 638 EXPECT_CALL(mock_offscreen_manager, IsOffscreenPresentation(kPresentationId)) |
| 638 .WillRepeatedly(Return(false)); | 639 .WillRepeatedly(Return(false)); |
| 639 | 640 |
| 640 // Auto-join requests should be rejected. | 641 // Auto-join requests should be rejected. |
| 641 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); | 642 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); |
| 642 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); | 643 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); |
| 643 delegate_impl_->JoinSession( | 644 delegate_impl_->ReconnectPresentation( |
| 644 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, | 645 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, |
| 645 kPresentationId, | 646 kPresentationId, |
| 646 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 647 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 647 OnCreateConnectionSuccess, | 648 OnCreateConnectionSuccess, |
| 648 base::Unretained(&mock_create_connection_callbacks)), | 649 base::Unretained(&mock_create_connection_callbacks)), |
| 649 base::Bind( | 650 base::Bind( |
| 650 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 651 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 651 base::Unretained(&mock_create_connection_callbacks))); | 652 base::Unretained(&mock_create_connection_callbacks))); |
| 652 | 653 |
| 653 // Remove the user preference for |origin|. | 654 // Remove the user preference for |origin|. |
| 654 { | 655 { |
| 655 ListPrefUpdate update(profile()->GetPrefs(), | 656 ListPrefUpdate update(profile()->GetPrefs(), |
| 656 prefs::kMediaRouterTabMirroringSources); | 657 prefs::kMediaRouterTabMirroringSources); |
| 657 update->Remove(base::Value(origin), nullptr); | 658 update->Remove(base::Value(origin), nullptr); |
| 658 } | 659 } |
| 659 | 660 |
| 660 // Auto-join requests should now go through. | 661 // Auto-join requests should now go through. |
| 661 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1); | 662 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1); |
| 662 delegate_impl_->JoinSession( | 663 delegate_impl_->ReconnectPresentation( |
| 663 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, | 664 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, |
| 664 kPresentationId, | 665 kPresentationId, |
| 665 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 666 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 666 OnCreateConnectionSuccess, | 667 OnCreateConnectionSuccess, |
| 667 base::Unretained(&mock_create_connection_callbacks)), | 668 base::Unretained(&mock_create_connection_callbacks)), |
| 668 base::Bind( | 669 base::Bind( |
| 669 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 670 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 670 base::Unretained(&mock_create_connection_callbacks))); | 671 base::Unretained(&mock_create_connection_callbacks))); |
| 671 } | 672 } |
| 672 | 673 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 694 // 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 |
| 695 // profile. | 696 // profile. |
| 696 const base::ListValue* non_incognito_origins = | 697 const base::ListValue* non_incognito_origins = |
| 697 profile()->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources); | 698 profile()->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources); |
| 698 EXPECT_EQ(non_incognito_origins->Find(base::Value(origin)), | 699 EXPECT_EQ(non_incognito_origins->Find(base::Value(origin)), |
| 699 non_incognito_origins->end()); | 700 non_incognito_origins->end()); |
| 700 | 701 |
| 701 // Auto-join requests should be rejected. | 702 // Auto-join requests should be rejected. |
| 702 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); | 703 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); |
| 703 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); | 704 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); |
| 704 delegate_impl_->JoinSession( | 705 delegate_impl_->ReconnectPresentation( |
| 705 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, | 706 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, |
| 706 kPresentationId, | 707 kPresentationId, |
| 707 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 708 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 708 OnCreateConnectionSuccess, | 709 OnCreateConnectionSuccess, |
| 709 base::Unretained(&mock_create_connection_callbacks)), | 710 base::Unretained(&mock_create_connection_callbacks)), |
| 710 base::Bind( | 711 base::Bind( |
| 711 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 712 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 712 base::Unretained(&mock_create_connection_callbacks))); | 713 base::Unretained(&mock_create_connection_callbacks))); |
| 713 | 714 |
| 714 // Remove the user preference for |origin| in incognito. | 715 // Remove the user preference for |origin| in incognito. |
| 715 { | 716 { |
| 716 ListPrefUpdate update(profile()->GetOffTheRecordProfile()->GetPrefs(), | 717 ListPrefUpdate update(profile()->GetOffTheRecordProfile()->GetPrefs(), |
| 717 prefs::kMediaRouterTabMirroringSources); | 718 prefs::kMediaRouterTabMirroringSources); |
| 718 update->Remove(base::Value(origin), nullptr); | 719 update->Remove(base::Value(origin), nullptr); |
| 719 } | 720 } |
| 720 | 721 |
| 721 // Auto-join requests should now go through. | 722 // Auto-join requests should now go through. |
| 722 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1); | 723 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1); |
| 723 delegate_impl_->JoinSession( | 724 delegate_impl_->ReconnectPresentation( |
| 724 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, | 725 main_frame_process_id_, main_frame_routing_id_, presentation_urls_, |
| 725 kPresentationId, | 726 kPresentationId, |
| 726 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 727 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 727 OnCreateConnectionSuccess, | 728 OnCreateConnectionSuccess, |
| 728 base::Unretained(&mock_create_connection_callbacks)), | 729 base::Unretained(&mock_create_connection_callbacks)), |
| 729 base::Bind( | 730 base::Bind( |
| 730 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 731 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 731 base::Unretained(&mock_create_connection_callbacks))); | 732 base::Unretained(&mock_create_connection_callbacks))); |
| 732 } | 733 } |
| 733 #endif // !defined(OS_ANDROID) | 734 #endif // !defined(OS_ANDROID) |
| 734 | 735 |
| 735 } // namespace media_router | 736 } // namespace media_router |
| OLD | NEW |