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 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { | |
imcheng
2016/12/05 20:12:33
Consider adding a PresentationServiceDelegateImplI
takumif
2016/12/06 02:21:58
Added.
| |
477 GURL frame_url(kFrameUrl); | |
478 std::string origin(url::Origin(frame_url).Serialize()); | |
479 content::WebContentsTester::For(GetWebContents()) | |
480 ->NavigateAndCommit(frame_url); | |
481 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); | |
482 ASSERT_TRUE(main_frame); | |
483 int render_process_id = main_frame->GetProcess()->GetID(); | |
484 int routing_id = main_frame->GetRoutingID(); | |
485 | |
486 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; | |
487 const std::string kPresentationId("auto-join"); | |
488 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); | |
489 | |
490 // Set the user preference for |origin| to prefer tab mirroring. | |
491 std::unique_ptr<ListPrefUpdate> update = base::MakeUnique<ListPrefUpdate>( | |
492 profile()->GetPrefs(), prefs::kMediaRouterTabMirroringSources); | |
493 (*update.get()) | |
494 ->AppendIfNotPresent(base::MakeUnique<base::StringValue>(origin)); | |
495 update.reset(); | |
496 | |
497 // Auto-join requests should be rejected. | |
498 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); | |
499 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); | |
500 delegate_impl_->JoinSession( | |
501 render_process_id, routing_id, presentation_urls_, kPresentationId, | |
502 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | |
503 OnCreateConnectionSuccess, | |
504 base::Unretained(&mock_create_connection_callbacks)), | |
505 base::Bind( | |
506 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | |
507 base::Unretained(&mock_create_connection_callbacks))); | |
508 | |
509 // Remove the user preference for |origin|. | |
510 update = base::MakeUnique<ListPrefUpdate>( | |
511 profile()->GetPrefs(), prefs::kMediaRouterTabMirroringSources); | |
512 (*update.get())->Remove(base::StringValue(origin), nullptr); | |
513 update.reset(); | |
514 | |
515 // Auto-join requests should now go through. | |
516 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1); | |
517 delegate_impl_->JoinSession( | |
518 render_process_id, routing_id, presentation_urls_, kPresentationId, | |
519 base::Bind(&MockCreatePresentationConnnectionCallbacks:: | |
520 OnCreateConnectionSuccess, | |
521 base::Unretained(&mock_create_connection_callbacks)), | |
522 base::Bind( | |
523 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, | |
524 base::Unretained(&mock_create_connection_callbacks))); | |
525 } | |
526 | |
473 } // namespace media_router | 527 } // namespace media_router |
OLD | NEW |