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 2de3a32f2cffac2ca4703ebb9cc78c70bdf5837a..a6cfb45e0a90ab9246381b3f209608b2d32da9a1 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; |
@@ -473,4 +476,117 @@ TEST_F(PresentationServiceDelegateImplTest, SinksObserverCantRegister) { |
render_process_id, render_frame_id, &listener)); |
} |
+#if !defined(OS_ANDROID) |
+TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { |
+ 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(); |
mark a. foltz
2016/12/09 04:07:42
A lot of this setup code seems to be duplicated be
takumif
2016/12/09 19:18:12
I'll do that in a separate patch.
|
+ |
+ 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(); |
mark a. foltz
2016/12/09 04:07:42
Instead of manually resetting the unique_ptr, slig
takumif
2016/12/09 19:18:12
Done.
|
+ |
+ // 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))); |
+} |
+ |
+TEST_F(PresentationServiceDelegateImplIncognitoTest, AutoJoinRequest) { |
+ 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()->GetOffTheRecordProfile()->GetPrefs(), |
+ prefs::kMediaRouterTabMirroringSources); |
+ (*update.get()) |
+ ->AppendIfNotPresent(base::MakeUnique<base::StringValue>(origin)); |
+ update.reset(); |
+ |
+ // Setting the pref in incognito shouldn't set it for the non-incognito |
+ // profile. |
+ const base::ListValue* non_incognito_origins = |
+ profile()->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources); |
+ EXPECT_EQ(non_incognito_origins->Find(base::StringValue(origin)), |
+ non_incognito_origins->end()); |
+ |
+ // 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| in incognito. |
+ update = base::MakeUnique<ListPrefUpdate>( |
+ profile()->GetOffTheRecordProfile()->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))); |
+} |
+#endif // !defined(OS_ANDROID) |
+ |
} // namespace media_router |