| 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 "base/test/mock_callback.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" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 base::Unretained(this)); | 138 base::Unretained(this)); |
| 139 std::vector<std::string> urls({kPresentationUrl1}); | 139 std::vector<std::string> urls({kPresentationUrl1}); |
| 140 delegate_impl_->SetDefaultPresentationUrls(main_frame_process_id_, | 140 delegate_impl_->SetDefaultPresentationUrls(main_frame_process_id_, |
| 141 main_frame_routing_id_, | 141 main_frame_routing_id_, |
| 142 presentation_urls_, callback); | 142 presentation_urls_, callback); |
| 143 | 143 |
| 144 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); | 144 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); |
| 145 PresentationRequest request = | 145 PresentationRequest request = |
| 146 delegate_impl_->GetDefaultPresentationRequest(); | 146 delegate_impl_->GetDefaultPresentationRequest(); |
| 147 | 147 |
| 148 EXPECT_CALL(router_, RegisterPresentationRoute(_, _)).Times(2); |
| 149 |
| 148 // Should not trigger callback since route response is error. | 150 // Should not trigger callback since route response is error. |
| 149 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( | 151 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( |
| 150 "Error", RouteRequestResult::UNKNOWN_ERROR); | 152 "Error", RouteRequestResult::UNKNOWN_ERROR); |
| 151 delegate_impl_->OnRouteResponse(request, *result); | 153 delegate_impl_->OnRouteResponse(request, *result); |
| 152 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); | 154 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); |
| 153 | 155 |
| 154 // Should not trigger callback since request doesn't match. | 156 // Should not trigger callback since request doesn't match. |
| 155 PresentationRequest different_request(RenderFrameHostId(100, 200), | 157 PresentationRequest different_request(RenderFrameHostId(100, 200), |
| 156 {presentation_url2_}, | 158 {presentation_url2_}, |
| 157 url::Origin(GURL(kFrameUrl))); | 159 url::Origin(GURL(kFrameUrl))); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 kPresentationId, | 423 kPresentationId, |
| 422 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 424 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 423 OnCreateConnectionSuccess, | 425 OnCreateConnectionSuccess, |
| 424 base::Unretained(&mock_create_connection_callbacks)), | 426 base::Unretained(&mock_create_connection_callbacks)), |
| 425 base::Bind( | 427 base::Bind( |
| 426 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 428 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 427 base::Unretained(&mock_create_connection_callbacks))); | 429 base::Unretained(&mock_create_connection_callbacks))); |
| 428 | 430 |
| 429 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_)) | 431 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_)) |
| 430 .Times(1); | 432 .Times(1); |
| 431 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess( | 433 MediaRoute media_route("routeId", source1_, "mediaSinkId", "description", |
| 432 MediaRoute("routeId", source1_, "mediaSinkId", "description", true, "", | 434 true, "", true); |
| 433 true), | 435 std::unique_ptr<RouteRequestResult> result = |
| 434 kPresentationId); | 436 RouteRequestResult::FromSuccess(media_route, kPresentationId); |
| 437 EXPECT_CALL(router_, |
| 438 RegisterPresentationRoute(kPresentationId, Equals(media_route))); |
| 439 |
| 435 for (const auto& route_response_callback : route_response_callbacks) | 440 for (const auto& route_response_callback : route_response_callbacks) |
| 436 route_response_callback.Run(*result); | 441 route_response_callback.Run(*result); |
| 437 | 442 |
| 438 base::MockCallback<content::PresentationConnectionStateChangedCallback> | 443 base::MockCallback<content::PresentationConnectionStateChangedCallback> |
| 439 mock_callback; | 444 mock_callback; |
| 440 auto callback = mock_callback.Get(); | 445 auto callback = mock_callback.Get(); |
| 441 content::PresentationSessionInfo connection(presentation_url1_, | 446 content::PresentationSessionInfo connection(presentation_url1_, |
| 442 kPresentationId); | 447 kPresentationId); |
| 443 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked( | 448 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked( |
| 444 Equals(callback))); | 449 Equals(callback))); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 presentation_id); | 501 presentation_id); |
| 497 | 502 |
| 498 base::MockCallback< | 503 base::MockCallback< |
| 499 base::Callback<void(const content::PresentationSessionInfo&)>> | 504 base::Callback<void(const content::PresentationSessionInfo&)>> |
| 500 mock_callback; | 505 mock_callback; |
| 501 EXPECT_CALL(mock_callback, Run(_)); | 506 EXPECT_CALL(mock_callback, Run(_)); |
| 502 MediaRoute media_route( | 507 MediaRoute media_route( |
| 503 "route_id", MediaSourceForPresentationUrl(session_info.presentation_url), | 508 "route_id", MediaSourceForPresentationUrl(session_info.presentation_url), |
| 504 "mediaSinkId", "", true, "", true); | 509 "mediaSinkId", "", true, "", true); |
| 505 media_route.set_offscreen_presentation(true); | 510 media_route.set_offscreen_presentation(true); |
| 511 EXPECT_CALL(router_, |
| 512 RegisterPresentationRoute(presentation_id, Equals(media_route))); |
| 513 |
| 506 delegate_impl_->OnStartSessionSucceeded(render_process_id, render_frame_id, | 514 delegate_impl_->OnStartSessionSucceeded(render_process_id, render_frame_id, |
| 507 mock_callback.Get(), session_info, | 515 mock_callback.Get(), session_info, |
| 508 media_route); | 516 media_route); |
| 509 | 517 |
| 510 OffscreenPresentationManagerFactory::GetInstanceForTest()->SetTestingFactory( | 518 OffscreenPresentationManagerFactory::GetInstanceForTest()->SetTestingFactory( |
| 511 profile(), &BuildMockOffscreenPresentationManager); | 519 profile(), &BuildMockOffscreenPresentationManager); |
| 512 MockOffscreenPresentationManager* mock_offscreen_manager = | 520 MockOffscreenPresentationManager* mock_offscreen_manager = |
| 513 static_cast<MockOffscreenPresentationManager*>( | 521 static_cast<MockOffscreenPresentationManager*>( |
| 514 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( | 522 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( |
| 515 profile())); | 523 profile())); |
| 516 EXPECT_CALL(*mock_offscreen_manager, | 524 EXPECT_CALL(*mock_offscreen_manager, |
| 517 RegisterOffscreenPresentationController( | 525 RegisterOffscreenPresentationController( |
| 518 presentation_id, presentation_url, | 526 presentation_id, presentation_url, |
| 519 RenderFrameHostId(render_process_id, render_frame_id))); | 527 RenderFrameHostId(render_process_id, render_frame_id))); |
| 520 | 528 |
| 521 content::PresentationConnectionPtr connection_ptr; | 529 content::PresentationConnectionPtr connection_ptr; |
| 522 content::PresentationConnectionRequest connection_request; | 530 content::PresentationConnectionRequest connection_request; |
| 523 delegate_impl_->ConnectToPresentation(render_process_id, render_frame_id, | 531 delegate_impl_->ConnectToPresentation(render_process_id, render_frame_id, |
| 524 session_info, std::move(connection_ptr), | 532 session_info, std::move(connection_ptr), |
| 525 std::move(connection_request)); | 533 std::move(connection_request)); |
| 526 | 534 |
| 527 EXPECT_CALL(*mock_offscreen_manager, | 535 EXPECT_CALL(*mock_offscreen_manager, |
| 528 UnregisterOffscreenPresentationController( | 536 UnregisterOffscreenPresentationController( |
| 529 presentation_id, | 537 presentation_id, |
| 530 RenderFrameHostId(render_process_id, render_frame_id))); | 538 RenderFrameHostId(render_process_id, render_frame_id))); |
| 531 EXPECT_CALL(router_, DetachRoute("route_id")); | 539 EXPECT_CALL(router_, DetachRoute("route_id")); |
| 540 EXPECT_CALL(router_, UnregisterPresentationRoute(presentation_id)); |
| 541 |
| 532 delegate_impl_->Reset(render_process_id, render_frame_id); | 542 delegate_impl_->Reset(render_process_id, render_frame_id); |
| 533 } | 543 } |
| 534 | 544 |
| 535 #if !defined(OS_ANDROID) | 545 #if !defined(OS_ANDROID) |
| 536 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { | 546 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { |
| 537 GURL frame_url(kFrameUrl); | 547 GURL frame_url(kFrameUrl); |
| 538 std::string origin(url::Origin(frame_url).Serialize()); | 548 std::string origin(url::Origin(frame_url).Serialize()); |
| 539 content::WebContentsTester::For(GetWebContents()) | 549 content::WebContentsTester::For(GetWebContents()) |
| 540 ->NavigateAndCommit(frame_url); | 550 ->NavigateAndCommit(frame_url); |
| 541 | 551 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | 645 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 636 OnCreateConnectionSuccess, | 646 OnCreateConnectionSuccess, |
| 637 base::Unretained(&mock_create_connection_callbacks)), | 647 base::Unretained(&mock_create_connection_callbacks)), |
| 638 base::Bind( | 648 base::Bind( |
| 639 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | 649 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 640 base::Unretained(&mock_create_connection_callbacks))); | 650 base::Unretained(&mock_create_connection_callbacks))); |
| 641 } | 651 } |
| 642 #endif // !defined(OS_ANDROID) | 652 #endif // !defined(OS_ANDROID) |
| 643 | 653 |
| 644 } // namespace media_router | 654 } // namespace media_router |
| OLD | NEW |