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

Side by Side Diff: chrome/browser/media/webrtc/media_stream_device_permission_context_unittest.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 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/webrtc/media_stream_device_permission_context.h" 5 #include "chrome/browser/media/webrtc/media_stream_device_permission_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/test/scoped_feature_list.h"
9 #include "build/build_config.h" 10 #include "build/build_config.h"
10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
11 #include "chrome/browser/infobars/infobar_service.h" 12 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/permissions/permission_request_id.h" 13 #include "chrome/browser/permissions/permission_request_id.h"
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
14 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
15 #include "components/content_settings/core/browser/host_content_settings_map.h" 16 #include "components/content_settings/core/browser/host_content_settings_map.h"
16 #include "components/content_settings/core/common/content_settings.h" 17 #include "components/content_settings/core/common/content_settings.h"
17 #include "components/content_settings/core/common/content_settings_types.h" 18 #include "components/content_settings/core/common/content_settings_types.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/content_features.h"
19 #include "content/public/test/mock_render_process_host.h" 21 #include "content/public/test/mock_render_process_host.h"
20 #include "content/public/test/web_contents_tester.h" 22 #include "content/public/test/web_contents_tester.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 24
23 #if !defined(OS_ANDROID) 25 #if !defined(OS_ANDROID)
24 #include "chrome/browser/permissions/permission_request_manager.h" 26 #include "chrome/browser/permissions/permission_request_manager.h"
25 #endif 27 #endif
26 28
27 namespace { 29 namespace {
28 class TestPermissionContext : public MediaStreamDevicePermissionContext { 30 class TestPermissionContext : public MediaStreamDevicePermissionContext {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 permission_context 71 permission_context
70 .GetPermissionStatus(nullptr /* render_frame_host */, 72 .GetPermissionStatus(nullptr /* render_frame_host */,
71 insecure_url, insecure_url) 73 insecure_url, insecure_url)
72 .content_setting); 74 .content_setting);
73 75
74 EXPECT_EQ(CONTENT_SETTING_ASK, 76 EXPECT_EQ(CONTENT_SETTING_ASK,
75 permission_context 77 permission_context
76 .GetPermissionStatus(nullptr /* render_frame_host */, 78 .GetPermissionStatus(nullptr /* render_frame_host */,
77 insecure_url, secure_url) 79 insecure_url, secure_url)
78 .content_setting); 80 .content_setting);
81
82 base::test::ScopedFeatureList scoped_feature_list;
83 scoped_feature_list.InitAndEnableFeature(
84 features::kRequireSecureOriginsForPepperMediaRequests);
85
86 EXPECT_EQ(CONTENT_SETTING_BLOCK,
87 permission_context
88 .GetPermissionStatus(nullptr /* render_frame_host */,
89 insecure_url, insecure_url)
90 .content_setting);
91
92 EXPECT_EQ(CONTENT_SETTING_BLOCK,
93 permission_context
94 .GetPermissionStatus(nullptr /* render_frame_host */,
95 insecure_url, secure_url)
96 .content_setting);
79 } 97 }
80 98
81 void TestSecureQueryingUrl(ContentSettingsType content_settings_type) { 99 void TestSecureQueryingUrl(ContentSettingsType content_settings_type) {
82 TestPermissionContext permission_context(profile(), content_settings_type); 100 TestPermissionContext permission_context(profile(), content_settings_type);
83 GURL secure_url("https://www.example.com"); 101 GURL secure_url("https://www.example.com");
84 102
85 // Check that there is no saved content settings. 103 // Check that there is no saved content settings.
86 EXPECT_EQ(CONTENT_SETTING_ASK, 104 EXPECT_EQ(CONTENT_SETTING_ASK,
87 HostContentSettingsMapFactory::GetForProfile(profile()) 105 HostContentSettingsMapFactory::GetForProfile(profile())
88 ->GetContentSetting(secure_url.GetOrigin(), 106 ->GetContentSetting(secure_url.GetOrigin(),
89 secure_url.GetOrigin(), 107 secure_url.GetOrigin(),
90 content_settings_type, 108 content_settings_type,
91 std::string())); 109 std::string()));
92 110
93 EXPECT_EQ(CONTENT_SETTING_ASK, 111 EXPECT_EQ(CONTENT_SETTING_ASK,
94 permission_context 112 permission_context
95 .GetPermissionStatus(nullptr /* render_frame_host */, 113 .GetPermissionStatus(nullptr /* render_frame_host */,
96 secure_url, secure_url) 114 secure_url, secure_url)
97 .content_setting); 115 .content_setting);
116
117 base::test::ScopedFeatureList scoped_feature_list;
118 scoped_feature_list.InitAndEnableFeature(
119 features::kRequireSecureOriginsForPepperMediaRequests);
120 EXPECT_EQ(CONTENT_SETTING_ASK,
121 permission_context
122 .GetPermissionStatus(nullptr /* render_frame_host */,
123 secure_url, secure_url)
124 .content_setting);
98 } 125 }
99 126
100 private: 127 private:
101 // ChromeRenderViewHostTestHarness: 128 // ChromeRenderViewHostTestHarness:
102 void SetUp() override { 129 void SetUp() override {
103 ChromeRenderViewHostTestHarness::SetUp(); 130 ChromeRenderViewHostTestHarness::SetUp();
104 #if defined(OS_ANDROID) 131 #if defined(OS_ANDROID)
105 InfoBarService::CreateForWebContents(web_contents()); 132 InfoBarService::CreateForWebContents(web_contents());
106 #else 133 #else
107 PermissionRequestManager::CreateForWebContents(web_contents()); 134 PermissionRequestManager::CreateForWebContents(web_contents());
(...skipping 17 matching lines...) Expand all
125 152
126 // MEDIASTREAM_MIC permission status should be ask for Secure origin. 153 // MEDIASTREAM_MIC permission status should be ask for Secure origin.
127 TEST_F(MediaStreamDevicePermissionContextTests, TestMicSecureQueryingUrl) { 154 TEST_F(MediaStreamDevicePermissionContextTests, TestMicSecureQueryingUrl) {
128 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 155 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
129 } 156 }
130 157
131 // MEDIASTREAM_CAMERA permission status should be ask for Secure origin. 158 // MEDIASTREAM_CAMERA permission status should be ask for Secure origin.
132 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraSecureQueryingUrl) { 159 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraSecureQueryingUrl) {
133 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); 160 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
134 } 161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698