Chromium Code Reviews| Index: chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc |
| diff --git a/chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc b/chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc |
| index 55c550ee91f0fd0fa91bdc19a4a3af9ddfe0f85d..00d335ae9ce1a93caf9cc971084526f3d1083b3b 100644 |
| --- a/chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc |
| +++ b/chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc |
| @@ -12,14 +12,17 @@ |
| #include "chrome/browser/media/router/route_request_result.h" |
| #include "chrome/browser/media/router/test_helper.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/pref_names.h" |
| #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| #include "chrome/test/base/testing_profile.h" |
| +#include "components/prefs/scoped_user_pref_update.h" |
| #include "content/public/browser/presentation_screen_availability_listener.h" |
| #include "content/public/browser/presentation_session.h" |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/test/web_contents_tester.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| +#include "url/origin.h" |
| using ::testing::_; |
| using ::testing::Mock; |
| @@ -470,4 +473,55 @@ TEST_F(PresentationServiceDelegateImplTest, SinksObserverCantRegister) { |
| render_process_id, render_frame_id, &listener)); |
| } |
| +TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { |
|
imcheng
2016/12/05 20:12:33
Consider adding a PresentationServiceDelegateImplI
takumif
2016/12/06 02:21:58
Added.
|
| + GURL frame_url(kFrameUrl); |
| + std::string origin(url::Origin(frame_url).Serialize()); |
| + content::WebContentsTester::For(GetWebContents()) |
| + ->NavigateAndCommit(frame_url); |
| + content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame(); |
| + ASSERT_TRUE(main_frame); |
| + int render_process_id = main_frame->GetProcess()->GetID(); |
| + int routing_id = main_frame->GetRoutingID(); |
| + |
| + MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; |
| + const std::string kPresentationId("auto-join"); |
| + ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); |
| + |
| + // Set the user preference for |origin| to prefer tab mirroring. |
| + std::unique_ptr<ListPrefUpdate> update = base::MakeUnique<ListPrefUpdate>( |
| + profile()->GetPrefs(), prefs::kMediaRouterTabMirroringSources); |
| + (*update.get()) |
| + ->AppendIfNotPresent(base::MakeUnique<base::StringValue>(origin)); |
| + update.reset(); |
| + |
| + // Auto-join requests should be rejected. |
| + EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); |
| + EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); |
| + delegate_impl_->JoinSession( |
| + render_process_id, routing_id, presentation_urls_, kPresentationId, |
| + base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| + OnCreateConnectionSuccess, |
| + base::Unretained(&mock_create_connection_callbacks)), |
| + base::Bind( |
| + &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| + base::Unretained(&mock_create_connection_callbacks))); |
| + |
| + // Remove the user preference for |origin|. |
| + update = base::MakeUnique<ListPrefUpdate>( |
| + profile()->GetPrefs(), prefs::kMediaRouterTabMirroringSources); |
| + (*update.get())->Remove(base::StringValue(origin), nullptr); |
| + update.reset(); |
| + |
| + // Auto-join requests should now go through. |
| + EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1); |
| + delegate_impl_->JoinSession( |
| + render_process_id, routing_id, presentation_urls_, kPresentationId, |
| + base::Bind(&MockCreatePresentationConnnectionCallbacks:: |
| + OnCreateConnectionSuccess, |
| + base::Unretained(&mock_create_connection_callbacks)), |
| + base::Bind( |
| + &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, |
| + base::Unretained(&mock_create_connection_callbacks))); |
| +} |
| + |
| } // namespace media_router |