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 "chrome/browser/media/router/media_source.h" | 8 #include "chrome/browser/media/router/media_source.h" |
9 #include "chrome/browser/media/router/media_source_helper.h" | 9 #include "chrome/browser/media/router/media_source_helper.h" |
10 #include "chrome/browser/media/router/mock_media_router.h" | 10 #include "chrome/browser/media/router/mock_media_router.h" |
11 #include "chrome/browser/media/router/mock_screen_availability_listener.h" | 11 #include "chrome/browser/media/router/mock_screen_availability_listener.h" |
| 12 #include "chrome/browser/media/router/offscreen_presentation_manager.h" |
| 13 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" |
12 #include "chrome/browser/media/router/route_request_result.h" | 14 #include "chrome/browser/media/router/route_request_result.h" |
13 #include "chrome/browser/media/router/test_helper.h" | 15 #include "chrome/browser/media/router/test_helper.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
17 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
18 #include "components/prefs/scoped_user_pref_update.h" | 20 #include "components/prefs/scoped_user_pref_update.h" |
19 #include "content/public/browser/presentation_screen_availability_listener.h" | 21 #include "content/public/browser/presentation_screen_availability_listener.h" |
20 #include "content/public/browser/presentation_session.h" | 22 #include "content/public/browser/presentation_session.h" |
21 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
22 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
23 #include "content/public/test/web_contents_tester.h" | 25 #include "content/public/test/web_contents_tester.h" |
| 26 #include "mojo/public/cpp/bindings/binding.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "url/origin.h" | 28 #include "url/origin.h" |
26 | 29 |
27 using ::testing::_; | 30 using ::testing::_; |
28 using ::testing::Mock; | 31 using ::testing::Mock; |
29 using ::testing::Return; | 32 using ::testing::Return; |
30 using ::testing::SaveArg; | 33 using ::testing::SaveArg; |
31 using ::testing::StrictMock; | 34 using ::testing::StrictMock; |
32 | 35 |
33 namespace { | 36 namespace { |
(...skipping 25 matching lines...) Expand all Loading... |
59 }; | 62 }; |
60 | 63 |
61 class MockCreatePresentationConnnectionCallbacks { | 64 class MockCreatePresentationConnnectionCallbacks { |
62 public: | 65 public: |
63 MOCK_METHOD1(OnCreateConnectionSuccess, | 66 MOCK_METHOD1(OnCreateConnectionSuccess, |
64 void(const content::PresentationSessionInfo& connection)); | 67 void(const content::PresentationSessionInfo& connection)); |
65 MOCK_METHOD1(OnCreateConnectionError, | 68 MOCK_METHOD1(OnCreateConnectionError, |
66 void(const content::PresentationError& error)); | 69 void(const content::PresentationError& error)); |
67 }; | 70 }; |
68 | 71 |
| 72 class MockOffscreenPresentationManager : public OffscreenPresentationManager { |
| 73 public: |
| 74 void RegisterOffscreenPresentationController( |
| 75 const std::string& presentation_id, |
| 76 const GURL& presentation_url, |
| 77 const RenderFrameHostId& render_frame_id, |
| 78 content::PresentationConnectionPtr controller) override { |
| 79 RegisterOffscreenPresentationController(presentation_id, presentation_url, |
| 80 render_frame_id); |
| 81 } |
| 82 |
| 83 MOCK_METHOD3(RegisterOffscreenPresentationController, |
| 84 void(const std::string& presentation_id, |
| 85 const GURL& presentation_url, |
| 86 const RenderFrameHostId& render_frame_id)); |
| 87 MOCK_METHOD2(UnregisterOffscreenPresentationController, |
| 88 void(const std::string& presentation_id, |
| 89 const RenderFrameHostId& render_frame_id)); |
| 90 MOCK_METHOD3(OnOffscreenPresentationReceiverCreated, |
| 91 void(const std::string& presentation_id, |
| 92 const GURL& presentation_url, |
| 93 const content::ReceiverConnectionAvailableCallback& |
| 94 receiver_callback)); |
| 95 MOCK_METHOD1(OnOffscreenPresentationReceiverTerminated, |
| 96 void(const std::string& presentation_id)); |
| 97 }; |
| 98 |
| 99 std::unique_ptr<KeyedService> BuildMockOffscreenPresentationManager( |
| 100 content::BrowserContext* context) { |
| 101 return base::MakeUnique<MockOffscreenPresentationManager>(); |
| 102 } |
| 103 |
69 class PresentationServiceDelegateImplTest | 104 class PresentationServiceDelegateImplTest |
70 : public ChromeRenderViewHostTestHarness { | 105 : public ChromeRenderViewHostTestHarness { |
71 public: | 106 public: |
72 PresentationServiceDelegateImplTest() | 107 PresentationServiceDelegateImplTest() |
73 : delegate_impl_(nullptr), | 108 : delegate_impl_(nullptr), |
74 presentation_url1_(kPresentationUrl1), | 109 presentation_url1_(kPresentationUrl1), |
75 presentation_url2_(kPresentationUrl2) {} | 110 presentation_url2_(kPresentationUrl2) {} |
76 | 111 |
77 void SetUp() override { | 112 void SetUp() override { |
78 ChromeRenderViewHostTestHarness::SetUp(); | 113 ChromeRenderViewHostTestHarness::SetUp(); |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 ASSERT_TRUE(main_frame); | 504 ASSERT_TRUE(main_frame); |
470 int render_process_id = main_frame->GetProcess()->GetID(); | 505 int render_process_id = main_frame->GetProcess()->GetID(); |
471 int render_frame_id = main_frame->GetRoutingID(); | 506 int render_frame_id = main_frame->GetRoutingID(); |
472 | 507 |
473 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); | 508 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); |
474 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); | 509 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); |
475 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( | 510 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( |
476 render_process_id, render_frame_id, &listener)); | 511 render_process_id, render_frame_id, &listener)); |
477 } | 512 } |
478 | 513 |
| 514 TEST_F(PresentationServiceDelegateImplTest, ConnectToOffscreenPresentation) { |
| 515 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 516 ASSERT_TRUE(main_frame); |
| 517 int render_process_id = main_frame->GetProcess()->GetID(); |
| 518 int render_frame_id = main_frame->GetRoutingID(); |
| 519 std::string presentation_id = "presentation_id"; |
| 520 GURL presentation_url = GURL("http://www.example.com/presentation.html"); |
| 521 content::PresentationSessionInfo session_info(presentation_url, |
| 522 presentation_id); |
| 523 |
| 524 OffscreenPresentationManagerFactory::GetInstanceForTest()->SetTestingFactory( |
| 525 profile(), &BuildMockOffscreenPresentationManager); |
| 526 MockOffscreenPresentationManager* mock_offscreen_manager = |
| 527 static_cast<MockOffscreenPresentationManager*>( |
| 528 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( |
| 529 profile())); |
| 530 EXPECT_CALL(*mock_offscreen_manager, |
| 531 RegisterOffscreenPresentationController( |
| 532 presentation_id, presentation_url, |
| 533 RenderFrameHostId(render_process_id, render_frame_id))); |
| 534 |
| 535 content::PresentationConnectionPtr connection_ptr; |
| 536 delegate_impl_->ConnectToOffscreenPresentation(render_process_id, |
| 537 render_frame_id, session_info, |
| 538 std::move(connection_ptr)); |
| 539 } |
| 540 |
479 #if !defined(OS_ANDROID) | 541 #if !defined(OS_ANDROID) |
480 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { | 542 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { |
481 GURL frame_url(kFrameUrl); | 543 GURL frame_url(kFrameUrl); |
482 std::string origin(url::Origin(frame_url).Serialize()); | 544 std::string origin(url::Origin(frame_url).Serialize()); |
483 content::WebContentsTester::For(GetWebContents()) | 545 content::WebContentsTester::For(GetWebContents()) |
484 ->NavigateAndCommit(frame_url); | 546 ->NavigateAndCommit(frame_url); |
485 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 547 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
486 ASSERT_TRUE(main_frame); | 548 ASSERT_TRUE(main_frame); |
487 int render_process_id = main_frame->GetProcess()->GetID(); | 549 int render_process_id = main_frame->GetProcess()->GetID(); |
488 int routing_id = main_frame->GetRoutingID(); | 550 int routing_id = main_frame->GetRoutingID(); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 645 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
584 OnCreateConnectionSuccess, | 646 OnCreateConnectionSuccess, |
585 base::Unretained(&mock_create_connection_callbacks)), | 647 base::Unretained(&mock_create_connection_callbacks)), |
586 base::Bind( | 648 base::Bind( |
587 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 649 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
588 base::Unretained(&mock_create_connection_callbacks))); | 650 base::Unretained(&mock_create_connection_callbacks))); |
589 } | 651 } |
590 #endif // !defined(OS_ANDROID) | 652 #endif // !defined(OS_ANDROID) |
591 | 653 |
592 } // namespace media_router | 654 } // namespace media_router |
OLD | NEW |