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 "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" |
11 #include "chrome/browser/media/router/mock_screen_availability_listener.h" | 11 #include "chrome/browser/media/router/mock_screen_availability_listener.h" |
12 #include "chrome/browser/media/router/route_request_result.h" | 12 #include "chrome/browser/media/router/route_request_result.h" |
13 #include "chrome/browser/media/router/test_helper.h" | 13 #include "chrome/browser/media/router/test_helper.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
16 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 18 #include "components/prefs/scoped_user_pref_update.h" |
17 #include "content/public/browser/presentation_screen_availability_listener.h" | 19 #include "content/public/browser/presentation_screen_availability_listener.h" |
18 #include "content/public/browser/presentation_session.h" | 20 #include "content/public/browser/presentation_session.h" |
19 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
20 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
21 #include "content/public/test/web_contents_tester.h" | 23 #include "content/public/test/web_contents_tester.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "url/origin.h" |
23 | 26 |
24 using ::testing::_; | 27 using ::testing::_; |
25 using ::testing::Mock; | 28 using ::testing::Mock; |
26 using ::testing::Return; | 29 using ::testing::Return; |
27 using ::testing::SaveArg; | 30 using ::testing::SaveArg; |
28 using ::testing::StrictMock; | 31 using ::testing::StrictMock; |
29 | 32 |
30 namespace { | 33 namespace { |
31 | 34 |
32 const char kPresentationUrl1[] = "http://foo.fakeurl.com/"; | 35 const char kPresentationUrl1[] = "http://foo.fakeurl.com/"; |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 ASSERT_TRUE(main_frame); | 466 ASSERT_TRUE(main_frame); |
464 int render_process_id = main_frame->GetProcess()->GetID(); | 467 int render_process_id = main_frame->GetProcess()->GetID(); |
465 int render_frame_id = main_frame->GetRoutingID(); | 468 int render_frame_id = main_frame->GetRoutingID(); |
466 | 469 |
467 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); | 470 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); |
468 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); | 471 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); |
469 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( | 472 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( |
470 render_process_id, render_frame_id, &listener)); | 473 render_process_id, render_frame_id, &listener)); |
471 } | 474 } |
472 | 475 |
| 476 #if !defined(OS_ANDROID) |
| 477 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { |
| 478 GURL frame_url(kFrameUrl); |
| 479 std::string origin(url::Origin(frame_url).Serialize()); |
| 480 content::WebContentsTester::For(GetWebContents()) |
| 481 ->NavigateAndCommit(frame_url); |
| 482 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 483 ASSERT_TRUE(main_frame); |
| 484 int render_process_id = main_frame->GetProcess()->GetID(); |
| 485 int routing_id = main_frame->GetRoutingID(); |
| 486 |
| 487 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; |
| 488 const std::string kPresentationId("auto-join"); |
| 489 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); |
| 490 |
| 491 // Set the user preference for |origin| to prefer tab mirroring. |
| 492 std::unique_ptr<ListPrefUpdate> update = base::MakeUnique<ListPrefUpdate>( |
| 493 profile()->GetPrefs(), prefs::kMediaRouterTabMirroringSources); |
| 494 (*update.get()) |
| 495 ->AppendIfNotPresent(base::MakeUnique<base::StringValue>(origin)); |
| 496 update.reset(); |
| 497 |
| 498 // Auto-join requests should be rejected. |
| 499 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); |
| 500 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); |
| 501 delegate_impl_->JoinSession( |
| 502 render_process_id, routing_id, presentation_urls_, kPresentationId, |
| 503 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 504 OnCreateConnectionSuccess, |
| 505 base::Unretained(&mock_create_connection_callbacks)), |
| 506 base::Bind( |
| 507 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 508 base::Unretained(&mock_create_connection_callbacks))); |
| 509 |
| 510 // Remove the user preference for |origin|. |
| 511 update = base::MakeUnique<ListPrefUpdate>( |
| 512 profile()->GetPrefs(), prefs::kMediaRouterTabMirroringSources); |
| 513 (*update.get())->Remove(base::StringValue(origin), nullptr); |
| 514 update.reset(); |
| 515 |
| 516 // Auto-join requests should now go through. |
| 517 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1); |
| 518 delegate_impl_->JoinSession( |
| 519 render_process_id, routing_id, presentation_urls_, kPresentationId, |
| 520 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 521 OnCreateConnectionSuccess, |
| 522 base::Unretained(&mock_create_connection_callbacks)), |
| 523 base::Bind( |
| 524 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 525 base::Unretained(&mock_create_connection_callbacks))); |
| 526 } |
| 527 |
| 528 TEST_F(PresentationServiceDelegateImplIncognitoTest, AutoJoinRequest) { |
| 529 GURL frame_url(kFrameUrl); |
| 530 std::string origin(url::Origin(frame_url).Serialize()); |
| 531 content::WebContentsTester::For(GetWebContents()) |
| 532 ->NavigateAndCommit(frame_url); |
| 533 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| 534 ASSERT_TRUE(main_frame); |
| 535 int render_process_id = main_frame->GetProcess()->GetID(); |
| 536 int routing_id = main_frame->GetRoutingID(); |
| 537 |
| 538 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; |
| 539 const std::string kPresentationId("auto-join"); |
| 540 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); |
| 541 |
| 542 // Set the user preference for |origin| to prefer tab mirroring. |
| 543 std::unique_ptr<ListPrefUpdate> update = base::MakeUnique<ListPrefUpdate>( |
| 544 profile()->GetPrefs(), prefs::kMediaRouterTabMirroringSources); |
| 545 (*update.get()) |
| 546 ->AppendIfNotPresent(base::MakeUnique<base::StringValue>(origin)); |
| 547 update.reset(); |
| 548 |
| 549 // Auto-join requests should always go through in incognito. |
| 550 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1); |
| 551 delegate_impl_->JoinSession( |
| 552 render_process_id, routing_id, presentation_urls_, kPresentationId, |
| 553 base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| 554 OnCreateConnectionSuccess, |
| 555 base::Unretained(&mock_create_connection_callbacks)), |
| 556 base::Bind( |
| 557 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| 558 base::Unretained(&mock_create_connection_callbacks))); |
| 559 } |
| 560 #endif // !defined(OS_ANDROID) |
| 561 |
473 } // namespace media_router | 562 } // namespace media_router |
OLD | NEW |