Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc

Issue 2880503002: Block insecure pepper requests (Closed)
Patch Set: Block insecure pepper requests Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" 25 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" 26 #include "chrome/browser/ui/tabs/tab_strip_model.h"
27 #include "chrome/common/chrome_features.h" 27 #include "chrome/common/chrome_features.h"
28 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
29 #include "chrome/test/base/ui_test_utils.h" 29 #include "chrome/test/base/ui_test_utils.h"
30 #include "components/content_settings/core/browser/host_content_settings_map.h" 30 #include "components/content_settings/core/browser/host_content_settings_map.h"
31 #include "components/prefs/pref_service.h" 31 #include "components/prefs/pref_service.h"
32 #include "components/variations/variations_associated_data.h" 32 #include "components/variations/variations_associated_data.h"
33 #include "content/public/browser/render_frame_host.h" 33 #include "content/public/browser/render_frame_host.h"
34 #include "content/public/common/content_features.h"
34 #include "content/public/common/media_stream_request.h" 35 #include "content/public/common/media_stream_request.h"
35 #include "content/public/test/mock_render_process_host.h" 36 #include "content/public/test/mock_render_process_host.h"
36 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
37 38
38 enum class TestType { 39 enum class TestType {
39 DEFAULT, 40 DEFAULT,
40 TEST_WITH_GROUPED_MEDIA_REQUESTS, 41 TEST_WITH_GROUPED_MEDIA_REQUESTS,
41 }; 42 };
42 43
43 class MediaStreamDevicesControllerTest 44 class MediaStreamDevicesControllerTest
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); 841 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result());
841 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); 842 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
842 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); 843 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE));
843 } 844 }
844 845
845 // For Pepper request from insecure origin, even if it's ALLOW, it won't be 846 // For Pepper request from insecure origin, even if it's ALLOW, it won't be
846 // changed to ASK. 847 // changed to ASK.
847 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerTest, 848 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerTest,
848 PepperRequestInsecure) { 849 PepperRequestInsecure) {
849 InitWithUrl(GURL("http://www.example.com")); 850 InitWithUrl(GURL("http://www.example.com"));
850 SetContentSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW); 851
852 SetPromptResponseType(PermissionRequestManager::ACCEPT_ALL);
851 853
852 RequestPermissions( 854 RequestPermissions(
853 GetWebContents(), 855 GetWebContents(),
854 CreateRequestWithType(example_audio_id(), std::string(), 856 CreateRequestWithType(example_audio_id(), std::string(),
855 content::MEDIA_OPEN_DEVICE_PEPPER_ONLY), 857 content::MEDIA_OPEN_DEVICE_PEPPER_ONLY),
856 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 858 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
857 base::Unretained(this))); 859 base::Unretained(this)));
860 ASSERT_EQ(2u, TotalPromptRequestCount());
861
862 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result());
863 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
864 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE));
865
866 // Test that with the kRequireSecureOriginsForPepperMediaRequests flag enabled
867 // that permission will be denied.
868 ResetPromptCounters();
869 base::test::ScopedFeatureList scoped_feature_list;
870 scoped_feature_list.InitAndEnableFeature(
871 features::kRequireSecureOriginsForPepperMediaRequests);
872 RequestPermissions(
873 GetWebContents(),
874 CreateRequestWithType(example_audio_id(), example_video_id(),
875 content::MEDIA_OPEN_DEVICE_PEPPER_ONLY),
876 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
877 base::Unretained(this)));
858 ASSERT_EQ(0u, TotalPromptRequestCount()); 878 ASSERT_EQ(0u, TotalPromptRequestCount());
879
880 ASSERT_EQ(content::MEDIA_DEVICE_PERMISSION_DENIED, media_stream_result());
881 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
882 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE));
859 } 883 }
860 884
861 // Request and block microphone and camera access with kill switch. 885 // Request and block microphone and camera access with kill switch.
862 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerTest, 886 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerTest,
863 RequestAndKillSwitchMicCam) { 887 RequestAndKillSwitchMicCam) {
864 std::map<std::string, std::string> params; 888 std::map<std::string, std::string> params;
865 params[PermissionUtil::GetPermissionString( 889 params[PermissionUtil::GetPermissionString(
866 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)] = 890 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)] =
867 PermissionContextBase::kPermissionsKillSwitchBlockedValue; 891 PermissionContextBase::kPermissionsKillSwitchBlockedValue;
868 params[PermissionUtil::GetPermissionString( 892 params[PermissionUtil::GetPermissionString(
(...skipping 18 matching lines...) Expand all
887 ASSERT_EQ(content::MEDIA_DEVICE_KILL_SWITCH_ON, media_stream_result()); 911 ASSERT_EQ(content::MEDIA_DEVICE_KILL_SWITCH_ON, media_stream_result());
888 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); 912 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
889 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); 913 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE));
890 } 914 }
891 915
892 INSTANTIATE_TEST_CASE_P( 916 INSTANTIATE_TEST_CASE_P(
893 MediaStreamDevicesControllerTestInstance, 917 MediaStreamDevicesControllerTestInstance,
894 MediaStreamDevicesControllerTest, 918 MediaStreamDevicesControllerTest,
895 ::testing::Values(TestType::DEFAULT, 919 ::testing::Values(TestType::DEFAULT,
896 TestType::TEST_WITH_GROUPED_MEDIA_REQUESTS)); 920 TestType::TEST_WITH_GROUPED_MEDIA_REQUESTS));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698