| 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 "chrome/browser/content_settings/content_settings_policy_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_policy_provider.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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 scoped_ptr<RuleIterator> rule_iterator( | 55 scoped_ptr<RuleIterator> rule_iterator( |
| 56 provider.GetRuleIterator( | 56 provider.GetRuleIterator( |
| 57 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 57 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 58 std::string(), | 58 std::string(), |
| 59 false)); | 59 false)); |
| 60 EXPECT_FALSE(rule_iterator->HasNext()); | 60 EXPECT_FALSE(rule_iterator->HasNext()); |
| 61 | 61 |
| 62 // Change the managed value of the default geolocation setting | 62 // Change the managed value of the default geolocation setting |
| 63 prefs->SetManagedPref(prefs::kManagedDefaultGeolocationSetting, | 63 prefs->SetManagedPref(prefs::kManagedDefaultGeolocationSetting, |
| 64 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 64 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 65 | 65 |
| 66 rule_iterator.reset( | 66 rule_iterator.reset( |
| 67 provider.GetRuleIterator( | 67 provider.GetRuleIterator( |
| 68 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 68 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 69 std::string(), | 69 std::string(), |
| 70 false)); | 70 false)); |
| 71 EXPECT_TRUE(rule_iterator->HasNext()); | 71 EXPECT_TRUE(rule_iterator->HasNext()); |
| 72 Rule rule = rule_iterator->Next(); | 72 Rule rule = rule_iterator->Next(); |
| 73 EXPECT_FALSE(rule_iterator->HasNext()); | 73 EXPECT_FALSE(rule_iterator->HasNext()); |
| 74 | 74 |
| 75 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); | 75 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); |
| 76 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); | 76 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); |
| 77 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); | 77 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); |
| 78 | 78 |
| 79 provider.ShutdownOnUIThread(); | 79 provider.ShutdownOnUIThread(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST_F(PolicyProviderTest, ManagedDefaultContentSettings) { | 82 TEST_F(PolicyProviderTest, ManagedDefaultContentSettings) { |
| 83 TestingProfile profile; | 83 TestingProfile profile; |
| 84 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | 84 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
| 85 PolicyProvider provider(prefs); | 85 PolicyProvider provider(prefs); |
| 86 | 86 |
| 87 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, | 87 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, |
| 88 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 88 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 89 | 89 |
| 90 scoped_ptr<RuleIterator> rule_iterator( | 90 scoped_ptr<RuleIterator> rule_iterator( |
| 91 provider.GetRuleIterator( | 91 provider.GetRuleIterator( |
| 92 CONTENT_SETTINGS_TYPE_PLUGINS, | 92 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 93 std::string(), | 93 std::string(), |
| 94 false)); | 94 false)); |
| 95 EXPECT_TRUE(rule_iterator->HasNext()); | 95 EXPECT_TRUE(rule_iterator->HasNext()); |
| 96 Rule rule = rule_iterator->Next(); | 96 Rule rule = rule_iterator->Next(); |
| 97 EXPECT_FALSE(rule_iterator->HasNext()); | 97 EXPECT_FALSE(rule_iterator->HasNext()); |
| 98 | 98 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 114 MockObserver mock_observer; | 114 MockObserver mock_observer; |
| 115 EXPECT_CALL(mock_observer, | 115 EXPECT_CALL(mock_observer, |
| 116 OnContentSettingChanged(_, | 116 OnContentSettingChanged(_, |
| 117 _, | 117 _, |
| 118 CONTENT_SETTINGS_TYPE_DEFAULT, | 118 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 119 "")); | 119 "")); |
| 120 provider.AddObserver(&mock_observer); | 120 provider.AddObserver(&mock_observer); |
| 121 | 121 |
| 122 // Set the managed default-content-setting. | 122 // Set the managed default-content-setting. |
| 123 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, | 123 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, |
| 124 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 124 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 125 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); | 125 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); |
| 126 EXPECT_CALL(mock_observer, | 126 EXPECT_CALL(mock_observer, |
| 127 OnContentSettingChanged(_, | 127 OnContentSettingChanged(_, |
| 128 _, | 128 _, |
| 129 CONTENT_SETTINGS_TYPE_DEFAULT, | 129 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 130 "")); | 130 "")); |
| 131 // Remove the managed default-content-setting. | 131 // Remove the managed default-content-setting. |
| 132 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); | 132 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); |
| 133 provider.ShutdownOnUIThread(); | 133 provider.ShutdownOnUIThread(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST_F(PolicyProviderTest, GettingManagedContentSettings) { | 136 TEST_F(PolicyProviderTest, GettingManagedContentSettings) { |
| 137 TestingProfile profile; | 137 TestingProfile profile; |
| 138 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | 138 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
| 139 | 139 |
| 140 ListValue* value = new ListValue(); | 140 base::ListValue* value = new base::ListValue(); |
| 141 value->Append(Value::CreateStringValue("[*.]google.com")); | 141 value->Append(base::Value::CreateStringValue("[*.]google.com")); |
| 142 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls, | 142 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls, |
| 143 value); | 143 value); |
| 144 | 144 |
| 145 PolicyProvider provider(prefs); | 145 PolicyProvider provider(prefs); |
| 146 | 146 |
| 147 ContentSettingsPattern yt_url_pattern = | 147 ContentSettingsPattern yt_url_pattern = |
| 148 ContentSettingsPattern::FromString("www.youtube.com"); | 148 ContentSettingsPattern::FromString("www.youtube.com"); |
| 149 GURL youtube_url("http://www.youtube.com"); | 149 GURL youtube_url("http://www.youtube.com"); |
| 150 GURL google_url("http://mail.google.com"); | 150 GURL google_url("http://mail.google.com"); |
| 151 | 151 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 164 std::string(), | 164 std::string(), |
| 165 false)); | 165 false)); |
| 166 | 166 |
| 167 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 167 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 168 GetContentSetting(&provider, | 168 GetContentSetting(&provider, |
| 169 google_url, | 169 google_url, |
| 170 google_url, | 170 google_url, |
| 171 CONTENT_SETTINGS_TYPE_IMAGES, | 171 CONTENT_SETTINGS_TYPE_IMAGES, |
| 172 std::string(), | 172 std::string(), |
| 173 false)); | 173 false)); |
| 174 scoped_ptr<Value> value_ptr( | 174 scoped_ptr<base::Value> value_ptr( |
| 175 GetContentSettingValue(&provider, | 175 GetContentSettingValue(&provider, |
| 176 google_url, | 176 google_url, |
| 177 google_url, | 177 google_url, |
| 178 CONTENT_SETTINGS_TYPE_IMAGES, | 178 CONTENT_SETTINGS_TYPE_IMAGES, |
| 179 std::string(), | 179 std::string(), |
| 180 false)); | 180 false)); |
| 181 | 181 |
| 182 int int_value = -1; | 182 int int_value = -1; |
| 183 value_ptr->GetAsInteger(&int_value); | 183 value_ptr->GetAsInteger(&int_value); |
| 184 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); | 184 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); |
| 185 | 185 |
| 186 // The PolicyProvider does not allow setting content settings as they are | 186 // The PolicyProvider does not allow setting content settings as they are |
| 187 // enforced via policies and not set by the user or extension. So a call to | 187 // enforced via policies and not set by the user or extension. So a call to |
| 188 // SetWebsiteSetting does nothing. | 188 // SetWebsiteSetting does nothing. |
| 189 scoped_ptr<base::Value> value_block( | 189 scoped_ptr<base::Value> value_block( |
| 190 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 190 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 191 bool owned = provider.SetWebsiteSetting(yt_url_pattern, | 191 bool owned = provider.SetWebsiteSetting(yt_url_pattern, |
| 192 yt_url_pattern, | 192 yt_url_pattern, |
| 193 CONTENT_SETTINGS_TYPE_COOKIES, | 193 CONTENT_SETTINGS_TYPE_COOKIES, |
| 194 std::string(), | 194 std::string(), |
| 195 value_block.get()); | 195 value_block.get()); |
| 196 EXPECT_FALSE(owned); | 196 EXPECT_FALSE(owned); |
| 197 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 197 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 198 GetContentSetting(&provider, | 198 GetContentSetting(&provider, |
| 199 youtube_url, | 199 youtube_url, |
| 200 youtube_url, | 200 youtube_url, |
| 201 CONTENT_SETTINGS_TYPE_COOKIES, | 201 CONTENT_SETTINGS_TYPE_COOKIES, |
| 202 std::string(), | 202 std::string(), |
| 203 false)); | 203 false)); |
| 204 | 204 |
| 205 provider.ShutdownOnUIThread(); | 205 provider.ShutdownOnUIThread(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 TEST_F(PolicyProviderTest, ResourceIdentifier) { | 208 TEST_F(PolicyProviderTest, ResourceIdentifier) { |
| 209 TestingProfile profile; | 209 TestingProfile profile; |
| 210 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | 210 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
| 211 | 211 |
| 212 ListValue* value = new ListValue(); | 212 base::ListValue* value = new base::ListValue(); |
| 213 value->Append(Value::CreateStringValue("[*.]google.com")); | 213 value->Append(base::Value::CreateStringValue("[*.]google.com")); |
| 214 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, | 214 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, |
| 215 value); | 215 value); |
| 216 | 216 |
| 217 PolicyProvider provider(prefs); | 217 PolicyProvider provider(prefs); |
| 218 | 218 |
| 219 GURL youtube_url("http://www.youtube.com"); | 219 GURL youtube_url("http://www.youtube.com"); |
| 220 GURL google_url("http://mail.google.com"); | 220 GURL google_url("http://mail.google.com"); |
| 221 | 221 |
| 222 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 222 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 223 GetContentSetting( | 223 GetContentSetting( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 google_url, | 255 google_url, |
| 256 google_url, | 256 google_url, |
| 257 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 257 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 258 std::string(), | 258 std::string(), |
| 259 false)); | 259 false)); |
| 260 | 260 |
| 261 // Set the content settings pattern list for origins to auto select | 261 // Set the content settings pattern list for origins to auto select |
| 262 // certificates. | 262 // certificates. |
| 263 std::string pattern_str("\"pattern\":\"[*.]google.com\""); | 263 std::string pattern_str("\"pattern\":\"[*.]google.com\""); |
| 264 std::string filter_str("\"filter\":{\"ISSUER\":{\"CN\":\"issuer name\"}}"); | 264 std::string filter_str("\"filter\":{\"ISSUER\":{\"CN\":\"issuer name\"}}"); |
| 265 ListValue* value = new ListValue(); | 265 base::ListValue* value = new base::ListValue(); |
| 266 value->Append(Value::CreateStringValue( | 266 value->Append(base::Value::CreateStringValue( |
| 267 "{" + pattern_str + "," + filter_str + "}")); | 267 "{" + pattern_str + "," + filter_str + "}")); |
| 268 prefs->SetManagedPref(prefs::kManagedAutoSelectCertificateForUrls, | 268 prefs->SetManagedPref(prefs::kManagedAutoSelectCertificateForUrls, |
| 269 value); | 269 value); |
| 270 GURL youtube_url("https://www.youtube.com"); | 270 GURL youtube_url("https://www.youtube.com"); |
| 271 EXPECT_EQ( | 271 EXPECT_EQ( |
| 272 NULL, | 272 NULL, |
| 273 GetContentSettingValue(&provider, | 273 GetContentSettingValue(&provider, |
| 274 youtube_url, | 274 youtube_url, |
| 275 youtube_url, | 275 youtube_url, |
| 276 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 276 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 277 std::string(), | 277 std::string(), |
| 278 false)); | 278 false)); |
| 279 scoped_ptr<Value> cert_filter( | 279 scoped_ptr<base::Value> cert_filter( |
| 280 GetContentSettingValue(&provider, | 280 GetContentSettingValue(&provider, |
| 281 google_url, | 281 google_url, |
| 282 google_url, | 282 google_url, |
| 283 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 283 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 284 std::string(), | 284 std::string(), |
| 285 false)); | 285 false)); |
| 286 | 286 |
| 287 ASSERT_EQ(Value::TYPE_DICTIONARY, cert_filter->GetType()); | 287 ASSERT_EQ(base::Value::TYPE_DICTIONARY, cert_filter->GetType()); |
| 288 DictionaryValue* dict_value = | 288 base::DictionaryValue* dict_value = |
| 289 static_cast<DictionaryValue*>(cert_filter.get()); | 289 static_cast<base::DictionaryValue*>(cert_filter.get()); |
| 290 std::string actual_common_name; | 290 std::string actual_common_name; |
| 291 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); | 291 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); |
| 292 EXPECT_EQ("issuer name", actual_common_name); | 292 EXPECT_EQ("issuer name", actual_common_name); |
| 293 provider.ShutdownOnUIThread(); | 293 provider.ShutdownOnUIThread(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 } // namespace content_settings | 296 } // namespace content_settings |
| OLD | NEW |