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/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.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" | |
14 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" | |
13 #include "chrome/browser/media/router/route_request_result.h" | 15 #include "chrome/browser/media/router/route_request_result.h" |
14 #include "chrome/browser/media/router/test_helper.h" | 16 #include "chrome/browser/media/router/test_helper.h" |
15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.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 "content/public/browser/presentation_screen_availability_listener.h" | 20 #include "content/public/browser/presentation_screen_availability_listener.h" |
19 #include "content/public/browser/presentation_session.h" | 21 #include "content/public/browser/presentation_session.h" |
20 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
22 #include "content/public/test/web_contents_tester.h" | 24 #include "content/public/test/web_contents_tester.h" |
25 #include "mojo/public/cpp/bindings/binding.h" | |
23 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
24 | 27 |
25 using ::testing::_; | 28 using ::testing::_; |
26 using ::testing::Mock; | 29 using ::testing::Mock; |
27 using ::testing::Return; | 30 using ::testing::Return; |
28 using ::testing::SaveArg; | 31 using ::testing::SaveArg; |
29 using ::testing::StrictMock; | 32 using ::testing::StrictMock; |
30 | 33 |
31 namespace { | 34 namespace { |
32 | 35 |
33 const char kPresentationUrl1[] = "http://foo.fakeurl.com/"; | 36 const char kPresentationUrl1[] = "http://foo.fakeurl.com/"; |
34 const char kPresentationUrl2[] = "http://bar.fakeurl.com/"; | 37 const char kPresentationUrl2[] = "http://bar.fakeurl.com/"; |
35 const char kFrameUrl[] = "http://anotherframeurl.fakeurl.com/"; | 38 const char kFrameUrl[] = "http://anotherframeurl.fakeurl.com/"; |
36 | 39 |
37 } // namespace | 40 } // namespace |
38 | 41 |
39 namespace media_router { | 42 namespace media_router { |
40 | 43 |
41 class MockDelegateObserver | 44 class MockDelegateObserver |
42 : public content::PresentationServiceDelegate::Observer { | 45 : public content::PresentationServiceDelegateBase::Observer { |
43 public: | 46 public: |
44 MOCK_METHOD0(OnDelegateDestroyed, void()); | 47 MOCK_METHOD0(OnDelegateDestroyed, void()); |
45 MOCK_METHOD1(OnDefaultPresentationStarted, | 48 MOCK_METHOD1(OnDefaultPresentationStarted, |
46 void(const content::PresentationSessionInfo&)); | 49 void(const content::PresentationSessionInfo&)); |
47 }; | 50 }; |
48 | 51 |
49 class MockDefaultPresentationRequestObserver | 52 class MockDefaultPresentationRequestObserver |
50 : public PresentationServiceDelegateImpl:: | 53 : public PresentationServiceDelegateImpl:: |
51 DefaultPresentationRequestObserver { | 54 DefaultPresentationRequestObserver { |
52 public: | 55 public: |
53 MOCK_METHOD1(OnDefaultPresentationChanged, void(const PresentationRequest&)); | 56 MOCK_METHOD1(OnDefaultPresentationChanged, void(const PresentationRequest&)); |
54 MOCK_METHOD0(OnDefaultPresentationRemoved, void()); | 57 MOCK_METHOD0(OnDefaultPresentationRemoved, void()); |
55 }; | 58 }; |
56 | 59 |
57 class MockCreatePresentationConnnectionCallbacks { | 60 class MockCreatePresentationConnnectionCallbacks { |
58 public: | 61 public: |
59 MOCK_METHOD1(OnCreateConnectionSuccess, | 62 MOCK_METHOD1(OnCreateConnectionSuccess, |
60 void(const content::PresentationSessionInfo& connection)); | 63 void(const content::PresentationSessionInfo& connection)); |
61 MOCK_METHOD1(OnCreateConnectionError, | 64 MOCK_METHOD1(OnCreateConnectionError, |
62 void(const content::PresentationError& error)); | 65 void(const content::PresentationError& error)); |
63 }; | 66 }; |
64 | 67 |
68 class MockOffscreenPresentationManager : public OffscreenPresentationManager { | |
69 public: | |
70 void RegisterOffscreenPresentationController( | |
71 const std::string& presentation_id, | |
72 const GURL& presentation_url, | |
73 const RenderFrameHostId& render_frame_id, | |
74 content::PresentationConnectionPtr controller) override { | |
75 RegisterOffscreenPresentationController(presentation_id, presentation_url, | |
76 render_frame_id); | |
77 } | |
78 | |
79 MOCK_METHOD3(RegisterOffscreenPresentationController, | |
80 void(const std::string& presentation_id, | |
81 const GURL& presentation_url, | |
82 const RenderFrameHostId& render_frame_id)); | |
83 MOCK_METHOD2(UnregisterOffscreenPresentationController, | |
84 void(const std::string& presentation_id, | |
85 const RenderFrameHostId& render_frame_id)); | |
86 MOCK_METHOD3(OnOffscreenPresentationReceiverCreated, | |
87 void(const std::string& presentation_id, | |
88 const GURL& presentation_url, | |
89 const content::ReceiverConnectionAvailableCallback& | |
90 receiver_callback)); | |
91 MOCK_METHOD1(OnOffscreenPresentationReceiverTerminated, | |
92 void(const std::string& presentation_id)); | |
93 }; | |
94 | |
95 std::unique_ptr<KeyedService> BuildMockOffscreenPresentationManager( | |
96 content::BrowserContext* context) { | |
97 return base::MakeUnique<MockOffscreenPresentationManager>(); | |
98 } | |
99 | |
65 class PresentationServiceDelegateImplTest | 100 class PresentationServiceDelegateImplTest |
66 : public ChromeRenderViewHostTestHarness { | 101 : public ChromeRenderViewHostTestHarness { |
67 public: | 102 public: |
68 PresentationServiceDelegateImplTest() | 103 PresentationServiceDelegateImplTest() |
69 : delegate_impl_(nullptr), | 104 : delegate_impl_(nullptr), |
70 presentation_url1_(kPresentationUrl1), | 105 presentation_url1_(kPresentationUrl1), |
71 presentation_url2_(kPresentationUrl2) {} | 106 presentation_url2_(kPresentationUrl2) {} |
72 | 107 |
73 void SetUp() override { | 108 void SetUp() override { |
74 ChromeRenderViewHostTestHarness::SetUp(); | 109 ChromeRenderViewHostTestHarness::SetUp(); |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 ASSERT_TRUE(main_frame); | 499 ASSERT_TRUE(main_frame); |
465 int render_process_id = main_frame->GetProcess()->GetID(); | 500 int render_process_id = main_frame->GetProcess()->GetID(); |
466 int render_frame_id = main_frame->GetRoutingID(); | 501 int render_frame_id = main_frame->GetRoutingID(); |
467 | 502 |
468 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); | 503 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); |
469 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); | 504 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); |
470 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( | 505 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( |
471 render_process_id, render_frame_id, &listener)); | 506 render_process_id, render_frame_id, &listener)); |
472 } | 507 } |
473 | 508 |
509 TEST_F(PresentationServiceDelegateImplTest, ConnectToOffscreenPresentation) { | |
510 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | |
511 ASSERT_TRUE(main_frame); | |
512 int render_process_id = main_frame->GetProcess()->GetID(); | |
513 int render_frame_id = main_frame->GetRoutingID(); | |
514 content::PresentationSessionInfo session_info( | |
515 GURL("http://www.example.com/presentation.html"), "presentation_id", | |
516 true); | |
517 | |
518 OffscreenPresentationManagerFactory::GetInstance()->SetTestingFactory( | |
519 profile(), &BuildMockOffscreenPresentationManager); | |
520 MockOffscreenPresentationManager* mock_offscreen_manager = | |
521 static_cast<MockOffscreenPresentationManager*>( | |
522 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( | |
523 profile())); | |
524 EXPECT_CALL(*mock_offscreen_manager, | |
525 RegisterOffscreenPresentationController(_, _, _)); | |
mark a. foltz
2016/11/15 23:41:46
Please validate arguments passed to RegisterOffscr
zhaobin
2016/11/16 18:02:41
Done.
| |
526 | |
527 content::PresentationConnectionPtr connection_ptr; | |
528 delegate_impl_->ConnectToOffscreenPresentation(render_process_id, | |
529 render_frame_id, session_info, | |
530 std::move(connection_ptr)); | |
531 } | |
532 | |
474 } // namespace media_router | 533 } // namespace media_router |
OLD | NEW |