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/test/mock_callback.h" |
8 #include "chrome/browser/media/router/media_source.h" | 9 #include "chrome/browser/media/router/media_source.h" |
9 #include "chrome/browser/media/router/media_source_helper.h" | 10 #include "chrome/browser/media/router/media_source_helper.h" |
10 #include "chrome/browser/media/router/mock_media_router.h" | 11 #include "chrome/browser/media/router/mock_media_router.h" |
11 #include "chrome/browser/media/router/mock_screen_availability_listener.h" | 12 #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.h" |
13 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" | 14 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" |
14 #include "chrome/browser/media/router/route_request_result.h" | 15 #include "chrome/browser/media/router/route_request_result.h" |
15 #include "chrome/browser/media/router/test_helper.h" | 16 #include "chrome/browser/media/router/test_helper.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 manager.reset(); | 479 manager.reset(); |
479 } | 480 } |
480 | 481 |
481 TEST_F(PresentationServiceDelegateImplTest, SinksObserverCantRegister) { | 482 TEST_F(PresentationServiceDelegateImplTest, SinksObserverCantRegister) { |
482 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); | 483 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); |
483 EXPECT_CALL(listener1_, OnScreenAvailabilityNotSupported()); | 484 EXPECT_CALL(listener1_, OnScreenAvailabilityNotSupported()); |
484 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( | 485 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( |
485 main_frame_process_id_, main_frame_routing_id_, &listener1_)); | 486 main_frame_process_id_, main_frame_routing_id_, &listener1_)); |
486 } | 487 } |
487 | 488 |
488 TEST_F(PresentationServiceDelegateImplTest, ConnectToOffscreenPresentation) { | 489 TEST_F(PresentationServiceDelegateImplTest, ConnectToPresentation) { |
489 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | 490 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
490 ASSERT_TRUE(main_frame); | 491 ASSERT_TRUE(main_frame); |
491 int render_process_id = main_frame->GetProcess()->GetID(); | 492 int render_process_id = main_frame->GetProcess()->GetID(); |
492 int render_frame_id = main_frame->GetRoutingID(); | 493 int render_frame_id = main_frame->GetRoutingID(); |
493 std::string presentation_id = "presentation_id"; | 494 std::string presentation_id = "presentation_id"; |
494 GURL presentation_url = GURL("http://www.example.com/presentation.html"); | 495 GURL presentation_url = GURL("http://www.example.com/presentation.html"); |
495 content::PresentationSessionInfo session_info(presentation_url, | 496 content::PresentationSessionInfo session_info(presentation_url, |
496 presentation_id); | 497 presentation_id); |
497 | 498 |
| 499 base::MockCallback< |
| 500 base::Callback<void(const content::PresentationSessionInfo&)>> |
| 501 mock_callback; |
| 502 EXPECT_CALL(mock_callback, Run(_)); |
| 503 MediaRoute media_route( |
| 504 "route_id", MediaSourceForPresentationUrl(session_info.presentation_url), |
| 505 "mediaSinkId", "", true, "", true); |
| 506 media_route.set_offscreen_presentation(true); |
| 507 delegate_impl_->OnStartSessionSucceeded(render_process_id, render_frame_id, |
| 508 mock_callback.Get(), session_info, |
| 509 media_route); |
| 510 |
498 OffscreenPresentationManagerFactory::GetInstanceForTest()->SetTestingFactory( | 511 OffscreenPresentationManagerFactory::GetInstanceForTest()->SetTestingFactory( |
499 profile(), &BuildMockOffscreenPresentationManager); | 512 profile(), &BuildMockOffscreenPresentationManager); |
500 MockOffscreenPresentationManager* mock_offscreen_manager = | 513 MockOffscreenPresentationManager* mock_offscreen_manager = |
501 static_cast<MockOffscreenPresentationManager*>( | 514 static_cast<MockOffscreenPresentationManager*>( |
502 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( | 515 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( |
503 profile())); | 516 profile())); |
504 EXPECT_CALL(*mock_offscreen_manager, | 517 EXPECT_CALL(*mock_offscreen_manager, |
505 RegisterOffscreenPresentationController( | 518 RegisterOffscreenPresentationController( |
506 presentation_id, presentation_url, | 519 presentation_id, presentation_url, |
507 RenderFrameHostId(render_process_id, render_frame_id))); | 520 RenderFrameHostId(render_process_id, render_frame_id))); |
508 | 521 |
509 content::PresentationConnectionPtr connection_ptr; | 522 content::PresentationConnectionPtr connection_ptr; |
510 content::PresentationConnectionRequest connection_request; | 523 content::PresentationConnectionRequest connection_request; |
511 delegate_impl_->ConnectToOffscreenPresentation( | 524 delegate_impl_->ConnectToPresentation(render_process_id, render_frame_id, |
512 render_process_id, render_frame_id, session_info, | 525 session_info, std::move(connection_ptr), |
513 std::move(connection_ptr), std::move(connection_request)); | 526 std::move(connection_request)); |
| 527 |
| 528 EXPECT_CALL(*mock_offscreen_manager, |
| 529 UnregisterOffscreenPresentationController( |
| 530 presentation_id, |
| 531 RenderFrameHostId(render_process_id, render_frame_id))); |
| 532 EXPECT_CALL(router_, DetachRoute("route_id")); |
| 533 delegate_impl_->Reset(render_process_id, render_frame_id); |
514 } | 534 } |
515 | 535 |
516 #if !defined(OS_ANDROID) | 536 #if !defined(OS_ANDROID) |
517 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { | 537 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { |
518 GURL frame_url(kFrameUrl); | 538 GURL frame_url(kFrameUrl); |
519 std::string origin(url::Origin(frame_url).Serialize()); | 539 std::string origin(url::Origin(frame_url).Serialize()); |
520 content::WebContentsTester::For(GetWebContents()) | 540 content::WebContentsTester::For(GetWebContents()) |
521 ->NavigateAndCommit(frame_url); | 541 ->NavigateAndCommit(frame_url); |
522 | 542 |
523 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; | 543 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 636 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
617 OnCreateConnectionSuccess, | 637 OnCreateConnectionSuccess, |
618 base::Unretained(&mock_create_connection_callbacks)), | 638 base::Unretained(&mock_create_connection_callbacks)), |
619 base::Bind( | 639 base::Bind( |
620 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 640 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
621 base::Unretained(&mock_create_connection_callbacks))); | 641 base::Unretained(&mock_create_connection_callbacks))); |
622 } | 642 } |
623 #endif // !defined(OS_ANDROID) | 643 #endif // !defined(OS_ANDROID) |
624 | 644 |
625 } // namespace media_router | 645 } // namespace media_router |
OLD | NEW |