Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc

Issue 2477573002: [Presentation API] (3rd) (1-UA) Split PresentationServiceDelegateImpl(PSDImpl) (Closed)
Patch Set: resolve code review comments from Derek Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 22 matching lines...) Expand all
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
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 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
519 OffscreenPresentationManagerFactory::GetInstanceForTest()->SetTestingFactory(
520 profile(), &BuildMockOffscreenPresentationManager);
521 MockOffscreenPresentationManager* mock_offscreen_manager =
522 static_cast<MockOffscreenPresentationManager*>(
523 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext(
524 profile()));
525 EXPECT_CALL(*mock_offscreen_manager,
526 RegisterOffscreenPresentationController(
527 presentation_id, presentation_url,
528 RenderFrameHostId(render_process_id, render_frame_id)));
529
530 content::PresentationConnectionPtr connection_ptr;
531 delegate_impl_->ConnectToOffscreenPresentation(render_process_id,
532 render_frame_id, session_info,
533 std::move(connection_ptr));
534 }
535
474 } // namespace media_router 536 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698