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

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

Issue 2471573005: [Presentation API] (5th) (1-UA) integrate controller and receiver side for 1-UA messaging (Closed)
Patch Set: add unit test for browser_presentation_connection_proxy Created 3 years, 10 months 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 "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"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 receiver_callback)); 95 receiver_callback));
96 MOCK_METHOD1(OnOffscreenPresentationReceiverTerminated, 96 MOCK_METHOD1(OnOffscreenPresentationReceiverTerminated,
97 void(const std::string& presentation_id)); 97 void(const std::string& presentation_id));
98 }; 98 };
99 99
100 std::unique_ptr<KeyedService> BuildMockOffscreenPresentationManager( 100 std::unique_ptr<KeyedService> BuildMockOffscreenPresentationManager(
101 content::BrowserContext* context) { 101 content::BrowserContext* context) {
102 return base::MakeUnique<MockOffscreenPresentationManager>(); 102 return base::MakeUnique<MockOffscreenPresentationManager>();
103 } 103 }
104 104
105 class MockPresentationSessionStartedCallback {
imcheng 2017/01/31 01:53:25 Use MockCallback
zhaobin 2017/01/31 18:44:16 Done.
106 public:
107 MOCK_METHOD1(OnPresentationSessionStartedCallback,
108 void(const content::PresentationSessionInfo&));
109 };
110
105 class PresentationServiceDelegateImplTest 111 class PresentationServiceDelegateImplTest
106 : public ChromeRenderViewHostTestHarness { 112 : public ChromeRenderViewHostTestHarness {
107 public: 113 public:
108 PresentationServiceDelegateImplTest() 114 PresentationServiceDelegateImplTest()
109 : delegate_impl_(nullptr), 115 : delegate_impl_(nullptr),
110 presentation_url1_(kPresentationUrl1), 116 presentation_url1_(kPresentationUrl1),
111 presentation_url2_(kPresentationUrl2), 117 presentation_url2_(kPresentationUrl2),
112 source1_(MediaSourceForPresentationUrl(presentation_url1_)), 118 source1_(MediaSourceForPresentationUrl(presentation_url1_)),
113 source2_(MediaSourceForPresentationUrl(presentation_url2_)), 119 source2_(MediaSourceForPresentationUrl(presentation_url2_)),
114 listener1_(presentation_url1_), 120 listener1_(presentation_url1_),
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 manager.reset(); 484 manager.reset();
479 } 485 }
480 486
481 TEST_F(PresentationServiceDelegateImplTest, SinksObserverCantRegister) { 487 TEST_F(PresentationServiceDelegateImplTest, SinksObserverCantRegister) {
482 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); 488 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false));
483 EXPECT_CALL(listener1_, OnScreenAvailabilityNotSupported()); 489 EXPECT_CALL(listener1_, OnScreenAvailabilityNotSupported());
484 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( 490 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener(
485 main_frame_process_id_, main_frame_routing_id_, &listener1_)); 491 main_frame_process_id_, main_frame_routing_id_, &listener1_));
486 } 492 }
487 493
488 TEST_F(PresentationServiceDelegateImplTest, ConnectToOffscreenPresentation) { 494 TEST_F(PresentationServiceDelegateImplTest, ConnectToPresentation) {
489 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); 495 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
490 ASSERT_TRUE(main_frame); 496 ASSERT_TRUE(main_frame);
491 int render_process_id = main_frame->GetProcess()->GetID(); 497 int render_process_id = main_frame->GetProcess()->GetID();
492 int render_frame_id = main_frame->GetRoutingID(); 498 int render_frame_id = main_frame->GetRoutingID();
493 std::string presentation_id = "presentation_id"; 499 std::string presentation_id = "presentation_id";
494 GURL presentation_url = GURL("http://www.example.com/presentation.html"); 500 GURL presentation_url = GURL("http://www.example.com/presentation.html");
495 content::PresentationSessionInfo session_info(presentation_url, 501 content::PresentationSessionInfo session_info(presentation_url,
496 presentation_id); 502 presentation_id);
497 503
504 MockPresentationSessionStartedCallback mock_callback;
505 EXPECT_CALL(mock_callback, OnPresentationSessionStartedCallback(_));
506 MediaRoute media_route(
507 "route_id", MediaSourceForPresentationUrl(session_info.presentation_url),
508 "mediaSinkId", "", true, "", true);
509 media_route.set_offscreen_presentation(true);
510 delegate_impl_->OnStartSessionSucceeded(
511 render_process_id, render_frame_id,
512 base::Bind(&MockPresentationSessionStartedCallback::
513 OnPresentationSessionStartedCallback,
514 base::Unretained(&mock_callback)),
515 session_info, media_route);
516
498 OffscreenPresentationManagerFactory::GetInstanceForTest()->SetTestingFactory( 517 OffscreenPresentationManagerFactory::GetInstanceForTest()->SetTestingFactory(
499 profile(), &BuildMockOffscreenPresentationManager); 518 profile(), &BuildMockOffscreenPresentationManager);
500 MockOffscreenPresentationManager* mock_offscreen_manager = 519 MockOffscreenPresentationManager* mock_offscreen_manager =
501 static_cast<MockOffscreenPresentationManager*>( 520 static_cast<MockOffscreenPresentationManager*>(
502 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( 521 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext(
503 profile())); 522 profile()));
504 EXPECT_CALL(*mock_offscreen_manager, 523 EXPECT_CALL(*mock_offscreen_manager,
505 RegisterOffscreenPresentationController( 524 RegisterOffscreenPresentationController(
506 presentation_id, presentation_url, 525 presentation_id, presentation_url,
507 RenderFrameHostId(render_process_id, render_frame_id))); 526 RenderFrameHostId(render_process_id, render_frame_id)));
508 527
509 content::PresentationConnectionPtr connection_ptr; 528 content::PresentationConnectionPtr connection_ptr;
510 content::PresentationConnectionRequest connection_request; 529 content::PresentationConnectionRequest connection_request;
511 delegate_impl_->ConnectToOffscreenPresentation( 530 delegate_impl_->ConnectToPresentation(render_process_id, render_frame_id,
512 render_process_id, render_frame_id, session_info, 531 session_info, std::move(connection_ptr),
513 std::move(connection_ptr), std::move(connection_request)); 532 std::move(connection_request));
533
534 EXPECT_CALL(*mock_offscreen_manager,
535 UnregisterOffscreenPresentationController(
536 presentation_id,
537 RenderFrameHostId(render_process_id, render_frame_id)));
538 EXPECT_CALL(router_, DetachRoute("route_id"));
539 delegate_impl_->Reset(render_process_id, render_frame_id);
514 } 540 }
515 541
516 #if !defined(OS_ANDROID) 542 #if !defined(OS_ANDROID)
517 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { 543 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) {
518 GURL frame_url(kFrameUrl); 544 GURL frame_url(kFrameUrl);
519 std::string origin(url::Origin(frame_url).Serialize()); 545 std::string origin(url::Origin(frame_url).Serialize());
520 content::WebContentsTester::For(GetWebContents()) 546 content::WebContentsTester::For(GetWebContents())
521 ->NavigateAndCommit(frame_url); 547 ->NavigateAndCommit(frame_url);
522 548
523 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; 549 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 base::Bind(&MockCreatePresentationConnnectionCallbacks:: 642 base::Bind(&MockCreatePresentationConnnectionCallbacks::
617 OnCreateConnectionSuccess, 643 OnCreateConnectionSuccess,
618 base::Unretained(&mock_create_connection_callbacks)), 644 base::Unretained(&mock_create_connection_callbacks)),
619 base::Bind( 645 base::Bind(
620 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, 646 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError,
621 base::Unretained(&mock_create_connection_callbacks))); 647 base::Unretained(&mock_create_connection_callbacks)));
622 } 648 }
623 #endif // !defined(OS_ANDROID) 649 #endif // !defined(OS_ANDROID)
624 650
625 } // namespace media_router 651 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698