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" |
23 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
24 | 26 |
25 using ::testing::_; | 27 using ::testing::_; |
26 using ::testing::Mock; | 28 using ::testing::Mock; |
27 using ::testing::Return; | 29 using ::testing::Return; |
28 using ::testing::SaveArg; | 30 using ::testing::SaveArg; |
29 using ::testing::StrictMock; | 31 using ::testing::StrictMock; |
30 | 32 |
31 namespace { | 33 namespace { |
32 | 34 |
33 const char kPresentationUrl1[] = "http://foo.fakeurl.com/"; | 35 const char kPresentationUrl1[] = "http://foo.fakeurl.com/"; |
34 const char kPresentationUrl2[] = "http://bar.fakeurl.com/"; | 36 const char kPresentationUrl2[] = "http://bar.fakeurl.com/"; |
35 const char kFrameUrl[] = "http://anotherframeurl.fakeurl.com/"; | 37 const char kFrameUrl[] = "http://anotherframeurl.fakeurl.com/"; |
36 | 38 |
37 } // namespace | 39 } // namespace |
38 | 40 |
39 namespace media_router { | 41 namespace media_router { |
40 | 42 |
41 class MockDelegateObserver | 43 class MockDelegateObserver |
42 : public content::PresentationServiceDelegate::Observer { | 44 : public content::PresentationServiceDelegateBase::Observer { |
43 public: | 45 public: |
44 MOCK_METHOD0(OnDelegateDestroyed, void()); | 46 MOCK_METHOD0(OnDelegateDestroyed, void()); |
45 MOCK_METHOD1(OnDefaultPresentationStarted, | 47 MOCK_METHOD1(OnDefaultPresentationStarted, |
46 void(const content::PresentationSessionInfo&)); | 48 void(const content::PresentationSessionInfo&)); |
47 }; | 49 }; |
48 | 50 |
49 class MockDefaultPresentationRequestObserver | 51 class MockDefaultPresentationRequestObserver |
50 : public PresentationServiceDelegateImpl:: | 52 : public PresentationServiceDelegateImpl:: |
51 DefaultPresentationRequestObserver { | 53 DefaultPresentationRequestObserver { |
52 public: | 54 public: |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 ASSERT_TRUE(main_frame); | 466 ASSERT_TRUE(main_frame); |
465 int render_process_id = main_frame->GetProcess()->GetID(); | 467 int render_process_id = main_frame->GetProcess()->GetID(); |
466 int render_frame_id = main_frame->GetRoutingID(); | 468 int render_frame_id = main_frame->GetRoutingID(); |
467 | 469 |
468 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); | 470 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); |
469 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); | 471 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); |
470 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( | 472 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( |
471 render_process_id, render_frame_id, &listener)); | 473 render_process_id, render_frame_id, &listener)); |
472 } | 474 } |
473 | 475 |
476 TEST_F(PresentationServiceDelegateImplTest, ConnectToOffscreenPresentation) { | |
477 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | |
478 ASSERT_TRUE(main_frame); | |
479 int render_process_id = main_frame->GetProcess()->GetID(); | |
480 int render_frame_id = main_frame->GetRoutingID(); | |
481 | |
482 OffscreenPresentationManager* presentation_manager = | |
483 OffscreenPresentationManagerFactory:: | |
484 GetOrCreateForControllerBrowserContext(GetWebContents()); | |
485 | |
486 content::PresentationSessionInfo session_info(GURL("presentation_url"), | |
mark a. foltz
2016/11/08 23:40:51
Please use an obviously-valid URL like http://www.
zhaobin
2016/11/10 04:14:00
Done.
| |
487 "presentation_id"); | |
488 | |
489 EXPECT_EQ(size_t(0), presentation_manager->offscreen_presentations_.size()); | |
490 content::PresentationConnectionPtr connection; | |
491 delegate_impl_->ConnectToOffscreenPresentation( | |
492 render_process_id, render_frame_id, session_info, std::move(connection)); | |
493 EXPECT_EQ(size_t(1), presentation_manager->offscreen_presentations_.size()); | |
mark a. foltz
2016/11/08 23:40:51
It would be a more thorough test to inject a mock
zhaobin
2016/11/10 04:14:00
Done.
| |
494 } | |
495 | |
474 } // namespace media_router | 496 } // namespace media_router |
OLD | NEW |