| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "components/content_settings/core/browser/content_settings_policy_provi
der.h" | 5 #include "components/content_settings/core/browser/content_settings_policy_provi
der.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 value); | 134 value); |
| 135 | 135 |
| 136 PolicyProvider provider(prefs); | 136 PolicyProvider provider(prefs); |
| 137 | 137 |
| 138 ContentSettingsPattern yt_url_pattern = | 138 ContentSettingsPattern yt_url_pattern = |
| 139 ContentSettingsPattern::FromString("www.youtube.com"); | 139 ContentSettingsPattern::FromString("www.youtube.com"); |
| 140 GURL youtube_url("http://www.youtube.com"); | 140 GURL youtube_url("http://www.youtube.com"); |
| 141 GURL google_url("http://mail.google.com"); | 141 GURL google_url("http://mail.google.com"); |
| 142 | 142 |
| 143 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 143 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 144 GetContentSetting(&provider, | 144 TestUtils::GetContentSetting(&provider, youtube_url, youtube_url, |
| 145 youtube_url, | 145 CONTENT_SETTINGS_TYPE_COOKIES, |
| 146 youtube_url, | 146 std::string(), false)); |
| 147 CONTENT_SETTINGS_TYPE_COOKIES, | 147 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( |
| 148 std::string(), | 148 &provider, youtube_url, youtube_url, |
| 149 false)); | 149 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); |
| 150 EXPECT_EQ(NULL, | |
| 151 GetContentSettingValue(&provider, | |
| 152 youtube_url, | |
| 153 youtube_url, | |
| 154 CONTENT_SETTINGS_TYPE_COOKIES, | |
| 155 std::string(), | |
| 156 false)); | |
| 157 | 150 |
| 158 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 151 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 159 GetContentSetting(&provider, | 152 TestUtils::GetContentSetting(&provider, google_url, google_url, |
| 160 google_url, | 153 CONTENT_SETTINGS_TYPE_IMAGES, |
| 161 google_url, | 154 std::string(), false)); |
| 162 CONTENT_SETTINGS_TYPE_IMAGES, | 155 scoped_ptr<base::Value> value_ptr(TestUtils::GetContentSettingValue( |
| 163 std::string(), | 156 &provider, google_url, google_url, CONTENT_SETTINGS_TYPE_IMAGES, |
| 164 false)); | 157 std::string(), false)); |
| 165 scoped_ptr<base::Value> value_ptr( | |
| 166 GetContentSettingValue(&provider, | |
| 167 google_url, | |
| 168 google_url, | |
| 169 CONTENT_SETTINGS_TYPE_IMAGES, | |
| 170 std::string(), | |
| 171 false)); | |
| 172 | 158 |
| 173 int int_value = -1; | 159 int int_value = -1; |
| 174 value_ptr->GetAsInteger(&int_value); | 160 value_ptr->GetAsInteger(&int_value); |
| 175 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); | 161 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); |
| 176 | 162 |
| 177 // The PolicyProvider does not allow setting content settings as they are | 163 // The PolicyProvider does not allow setting content settings as they are |
| 178 // enforced via policies and not set by the user or extension. So a call to | 164 // enforced via policies and not set by the user or extension. So a call to |
| 179 // SetWebsiteSetting does nothing. | 165 // SetWebsiteSetting does nothing. |
| 180 scoped_ptr<base::Value> value_block( | 166 scoped_ptr<base::Value> value_block( |
| 181 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 167 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); |
| 182 bool owned = provider.SetWebsiteSetting(yt_url_pattern, | 168 bool owned = provider.SetWebsiteSetting(yt_url_pattern, |
| 183 yt_url_pattern, | 169 yt_url_pattern, |
| 184 CONTENT_SETTINGS_TYPE_COOKIES, | 170 CONTENT_SETTINGS_TYPE_COOKIES, |
| 185 std::string(), | 171 std::string(), |
| 186 value_block.get()); | 172 value_block.get()); |
| 187 EXPECT_FALSE(owned); | 173 EXPECT_FALSE(owned); |
| 188 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 174 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 189 GetContentSetting(&provider, | 175 TestUtils::GetContentSetting(&provider, youtube_url, youtube_url, |
| 190 youtube_url, | 176 CONTENT_SETTINGS_TYPE_COOKIES, |
| 191 youtube_url, | 177 std::string(), false)); |
| 192 CONTENT_SETTINGS_TYPE_COOKIES, | |
| 193 std::string(), | |
| 194 false)); | |
| 195 | 178 |
| 196 provider.ShutdownOnUIThread(); | 179 provider.ShutdownOnUIThread(); |
| 197 } | 180 } |
| 198 | 181 |
| 199 TEST_F(PolicyProviderTest, ResourceIdentifier) { | 182 TEST_F(PolicyProviderTest, ResourceIdentifier) { |
| 200 TestingProfile profile; | 183 TestingProfile profile; |
| 201 syncable_prefs::TestingPrefServiceSyncable* prefs = | 184 syncable_prefs::TestingPrefServiceSyncable* prefs = |
| 202 profile.GetTestingPrefService(); | 185 profile.GetTestingPrefService(); |
| 203 | 186 |
| 204 base::ListValue* value = new base::ListValue(); | 187 base::ListValue* value = new base::ListValue(); |
| 205 value->Append(new base::StringValue("[*.]google.com")); | 188 value->Append(new base::StringValue("[*.]google.com")); |
| 206 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, | 189 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, |
| 207 value); | 190 value); |
| 208 | 191 |
| 209 PolicyProvider provider(prefs); | 192 PolicyProvider provider(prefs); |
| 210 | 193 |
| 211 GURL youtube_url("http://www.youtube.com"); | 194 GURL youtube_url("http://www.youtube.com"); |
| 212 GURL google_url("http://mail.google.com"); | 195 GURL google_url("http://mail.google.com"); |
| 213 | 196 |
| 214 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 197 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 215 GetContentSetting( | 198 TestUtils::GetContentSetting(&provider, youtube_url, youtube_url, |
| 216 &provider, youtube_url, youtube_url, | 199 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 217 CONTENT_SETTINGS_TYPE_PLUGINS, "someplugin", false)); | 200 "someplugin", false)); |
| 218 | 201 |
| 219 // There is currently no policy support for resource content settings. | 202 // There is currently no policy support for resource content settings. |
| 220 // Resource identifiers are simply ignored by the PolicyProvider. | 203 // Resource identifiers are simply ignored by the PolicyProvider. |
| 221 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 204 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 222 GetContentSetting(&provider, | 205 TestUtils::GetContentSetting(&provider, google_url, google_url, |
| 223 google_url, | 206 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 224 google_url, | 207 std::string(), false)); |
| 225 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 226 std::string(), | |
| 227 false)); | |
| 228 | 208 |
| 229 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 209 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 230 GetContentSetting( | 210 TestUtils::GetContentSetting(&provider, google_url, google_url, |
| 231 &provider, google_url, google_url, | 211 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 232 CONTENT_SETTINGS_TYPE_PLUGINS, "someplugin", false)); | 212 "someplugin", false)); |
| 233 | 213 |
| 234 provider.ShutdownOnUIThread(); | 214 provider.ShutdownOnUIThread(); |
| 235 } | 215 } |
| 236 | 216 |
| 237 TEST_F(PolicyProviderTest, AutoSelectCertificateList) { | 217 TEST_F(PolicyProviderTest, AutoSelectCertificateList) { |
| 238 TestingProfile profile; | 218 TestingProfile profile; |
| 239 syncable_prefs::TestingPrefServiceSyncable* prefs = | 219 syncable_prefs::TestingPrefServiceSyncable* prefs = |
| 240 profile.GetTestingPrefService(); | 220 profile.GetTestingPrefService(); |
| 241 | 221 |
| 242 PolicyProvider provider(prefs); | 222 PolicyProvider provider(prefs); |
| 243 GURL google_url("https://mail.google.com"); | 223 GURL google_url("https://mail.google.com"); |
| 244 // Tests the default setting for auto selecting certificates | 224 // Tests the default setting for auto selecting certificates |
| 245 EXPECT_EQ( | 225 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( |
| 246 NULL, | 226 &provider, google_url, google_url, |
| 247 GetContentSettingValue(&provider, | 227 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 248 google_url, | 228 std::string(), false)); |
| 249 google_url, | |
| 250 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | |
| 251 std::string(), | |
| 252 false)); | |
| 253 | 229 |
| 254 // Set the content settings pattern list for origins to auto select | 230 // Set the content settings pattern list for origins to auto select |
| 255 // certificates. | 231 // certificates. |
| 256 std::string pattern_str("\"pattern\":\"[*.]google.com\""); | 232 std::string pattern_str("\"pattern\":\"[*.]google.com\""); |
| 257 std::string filter_str("\"filter\":{\"ISSUER\":{\"CN\":\"issuer name\"}}"); | 233 std::string filter_str("\"filter\":{\"ISSUER\":{\"CN\":\"issuer name\"}}"); |
| 258 base::ListValue* value = new base::ListValue(); | 234 base::ListValue* value = new base::ListValue(); |
| 259 value->Append( | 235 value->Append( |
| 260 new base::StringValue("{" + pattern_str + "," + filter_str + "}")); | 236 new base::StringValue("{" + pattern_str + "," + filter_str + "}")); |
| 261 prefs->SetManagedPref(prefs::kManagedAutoSelectCertificateForUrls, | 237 prefs->SetManagedPref(prefs::kManagedAutoSelectCertificateForUrls, |
| 262 value); | 238 value); |
| 263 GURL youtube_url("https://www.youtube.com"); | 239 GURL youtube_url("https://www.youtube.com"); |
| 264 EXPECT_EQ( | 240 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( |
| 265 NULL, | 241 &provider, youtube_url, youtube_url, |
| 266 GetContentSettingValue(&provider, | 242 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 267 youtube_url, | 243 std::string(), false)); |
| 268 youtube_url, | 244 scoped_ptr<base::Value> cert_filter(TestUtils::GetContentSettingValue( |
| 269 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 245 &provider, google_url, google_url, |
| 270 std::string(), | 246 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), false)); |
| 271 false)); | |
| 272 scoped_ptr<base::Value> cert_filter( | |
| 273 GetContentSettingValue(&provider, | |
| 274 google_url, | |
| 275 google_url, | |
| 276 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | |
| 277 std::string(), | |
| 278 false)); | |
| 279 | 247 |
| 280 ASSERT_EQ(base::Value::TYPE_DICTIONARY, cert_filter->GetType()); | 248 ASSERT_EQ(base::Value::TYPE_DICTIONARY, cert_filter->GetType()); |
| 281 base::DictionaryValue* dict_value = | 249 base::DictionaryValue* dict_value = |
| 282 static_cast<base::DictionaryValue*>(cert_filter.get()); | 250 static_cast<base::DictionaryValue*>(cert_filter.get()); |
| 283 std::string actual_common_name; | 251 std::string actual_common_name; |
| 284 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); | 252 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); |
| 285 EXPECT_EQ("issuer name", actual_common_name); | 253 EXPECT_EQ("issuer name", actual_common_name); |
| 286 provider.ShutdownOnUIThread(); | 254 provider.ShutdownOnUIThread(); |
| 287 } | 255 } |
| 288 | 256 |
| 289 } // namespace content_settings | 257 } // namespace content_settings |
| OLD | NEW |