| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_pref_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 ContentSettingsPattern::Wildcard(), | 114 ContentSettingsPattern::Wildcard(), |
| 115 CONTENT_SETTINGS_TYPE_IMAGES, | 115 CONTENT_SETTINGS_TYPE_IMAGES, |
| 116 "")); | 116 "")); |
| 117 | 117 |
| 118 pref_content_settings_provider.AddObserver(&mock_observer); | 118 pref_content_settings_provider.AddObserver(&mock_observer); |
| 119 | 119 |
| 120 pref_content_settings_provider.SetWebsiteSetting( | 120 pref_content_settings_provider.SetWebsiteSetting( |
| 121 pattern, | 121 pattern, |
| 122 ContentSettingsPattern::Wildcard(), | 122 ContentSettingsPattern::Wildcard(), |
| 123 CONTENT_SETTINGS_TYPE_IMAGES, | 123 CONTENT_SETTINGS_TYPE_IMAGES, |
| 124 "", | 124 std::string(), |
| 125 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 125 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
| 126 | 126 |
| 127 pref_content_settings_provider.ShutdownOnUIThread(); | 127 pref_content_settings_provider.ShutdownOnUIThread(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Test for regression in which the PrefProvider modified the user pref store | 130 // Test for regression in which the PrefProvider modified the user pref store |
| 131 // of the OTR unintentionally: http://crbug.com/74466. | 131 // of the OTR unintentionally: http://crbug.com/74466. |
| 132 TEST_F(PrefProviderTest, Incognito) { | 132 TEST_F(PrefProviderTest, Incognito) { |
| 133 PersistentPrefStore* user_prefs = new TestingPrefStore(); | 133 PersistentPrefStore* user_prefs = new TestingPrefStore(); |
| 134 OverlayUserPrefStore* otr_user_prefs = | 134 OverlayUserPrefStore* otr_user_prefs = |
| (...skipping 24 matching lines...) Expand all Loading... |
| 159 profile->SetOffTheRecordProfile(otr_profile); | 159 profile->SetOffTheRecordProfile(otr_profile); |
| 160 | 160 |
| 161 PrefProvider pref_content_settings_provider(regular_prefs, false); | 161 PrefProvider pref_content_settings_provider(regular_prefs, false); |
| 162 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); | 162 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); |
| 163 ContentSettingsPattern pattern = | 163 ContentSettingsPattern pattern = |
| 164 ContentSettingsPattern::FromString("[*.]example.com"); | 164 ContentSettingsPattern::FromString("[*.]example.com"); |
| 165 pref_content_settings_provider.SetWebsiteSetting( | 165 pref_content_settings_provider.SetWebsiteSetting( |
| 166 pattern, | 166 pattern, |
| 167 pattern, | 167 pattern, |
| 168 CONTENT_SETTINGS_TYPE_IMAGES, | 168 CONTENT_SETTINGS_TYPE_IMAGES, |
| 169 "", | 169 std::string(), |
| 170 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 170 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
| 171 | 171 |
| 172 GURL host("http://example.com/"); | 172 GURL host("http://example.com/"); |
| 173 // The value should of course be visible in the regular PrefProvider. | 173 // The value should of course be visible in the regular PrefProvider. |
| 174 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 174 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 175 GetContentSetting( | 175 GetContentSetting(&pref_content_settings_provider, |
| 176 &pref_content_settings_provider, | 176 host, |
| 177 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 177 host, |
| 178 CONTENT_SETTINGS_TYPE_IMAGES, |
| 179 std::string(), |
| 180 false)); |
| 178 // And also in the OTR version. | 181 // And also in the OTR version. |
| 179 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 182 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 180 GetContentSetting( | 183 GetContentSetting(&pref_content_settings_provider_incognito, |
| 181 &pref_content_settings_provider_incognito, | 184 host, |
| 182 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 185 host, |
| 186 CONTENT_SETTINGS_TYPE_IMAGES, |
| 187 std::string(), |
| 188 false)); |
| 183 // But the value should not be overridden in the OTR user prefs accidentally. | 189 // But the value should not be overridden in the OTR user prefs accidentally. |
| 184 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay( | 190 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay( |
| 185 prefs::kContentSettingsPatternPairs)); | 191 prefs::kContentSettingsPatternPairs)); |
| 186 | 192 |
| 187 pref_content_settings_provider.ShutdownOnUIThread(); | 193 pref_content_settings_provider.ShutdownOnUIThread(); |
| 188 pref_content_settings_provider_incognito.ShutdownOnUIThread(); | 194 pref_content_settings_provider_incognito.ShutdownOnUIThread(); |
| 189 } | 195 } |
| 190 | 196 |
| 191 TEST_F(PrefProviderTest, GetContentSettingsValue) { | 197 TEST_F(PrefProviderTest, GetContentSettingsValue) { |
| 192 TestingProfile testing_profile; | 198 TestingProfile testing_profile; |
| 193 PrefProvider provider(testing_profile.GetPrefs(), false); | 199 PrefProvider provider(testing_profile.GetPrefs(), false); |
| 194 | 200 |
| 195 GURL primary_url("http://example.com/"); | 201 GURL primary_url("http://example.com/"); |
| 196 ContentSettingsPattern primary_pattern = | 202 ContentSettingsPattern primary_pattern = |
| 197 ContentSettingsPattern::FromString("[*.]example.com"); | 203 ContentSettingsPattern::FromString("[*.]example.com"); |
| 198 | 204 |
| 199 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 205 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 200 GetContentSetting(&provider, primary_url, primary_url, | 206 GetContentSetting(&provider, |
| 201 CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 207 primary_url, |
| 208 primary_url, |
| 209 CONTENT_SETTINGS_TYPE_IMAGES, |
| 210 std::string(), |
| 211 false)); |
| 202 | 212 |
| 203 EXPECT_EQ(NULL, | 213 EXPECT_EQ(NULL, |
| 204 GetContentSettingValue( | 214 GetContentSettingValue(&provider, |
| 205 &provider, primary_url, primary_url, | 215 primary_url, |
| 206 CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 216 primary_url, |
| 217 CONTENT_SETTINGS_TYPE_IMAGES, |
| 218 std::string(), |
| 219 false)); |
| 207 | 220 |
| 208 provider.SetWebsiteSetting( | 221 provider.SetWebsiteSetting(primary_pattern, |
| 209 primary_pattern, | 222 primary_pattern, |
| 210 primary_pattern, | 223 CONTENT_SETTINGS_TYPE_IMAGES, |
| 211 CONTENT_SETTINGS_TYPE_IMAGES, | 224 std::string(), |
| 212 "", | 225 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 213 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | |
| 214 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 226 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 215 GetContentSetting(&provider, primary_url, primary_url, | 227 GetContentSetting(&provider, |
| 216 CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 228 primary_url, |
| 229 primary_url, |
| 230 CONTENT_SETTINGS_TYPE_IMAGES, |
| 231 std::string(), |
| 232 false)); |
| 217 scoped_ptr<Value> value_ptr( | 233 scoped_ptr<Value> value_ptr( |
| 218 GetContentSettingValue(&provider, primary_url, primary_url, | 234 GetContentSettingValue(&provider, |
| 219 CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 235 primary_url, |
| 236 primary_url, |
| 237 CONTENT_SETTINGS_TYPE_IMAGES, |
| 238 std::string(), |
| 239 false)); |
| 220 int int_value = -1; | 240 int int_value = -1; |
| 221 value_ptr->GetAsInteger(&int_value); | 241 value_ptr->GetAsInteger(&int_value); |
| 222 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); | 242 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); |
| 223 | 243 |
| 224 provider.SetWebsiteSetting(primary_pattern, | 244 provider.SetWebsiteSetting(primary_pattern, |
| 225 primary_pattern, | 245 primary_pattern, |
| 226 CONTENT_SETTINGS_TYPE_IMAGES, | 246 CONTENT_SETTINGS_TYPE_IMAGES, |
| 227 "", | 247 std::string(), |
| 228 NULL); | 248 NULL); |
| 229 EXPECT_EQ(NULL, | 249 EXPECT_EQ(NULL, |
| 230 GetContentSettingValue( | 250 GetContentSettingValue(&provider, |
| 231 &provider, primary_url, primary_url, | 251 primary_url, |
| 232 CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 252 primary_url, |
| 253 CONTENT_SETTINGS_TYPE_IMAGES, |
| 254 std::string(), |
| 255 false)); |
| 233 provider.ShutdownOnUIThread(); | 256 provider.ShutdownOnUIThread(); |
| 234 } | 257 } |
| 235 | 258 |
| 236 TEST_F(PrefProviderTest, Patterns) { | 259 TEST_F(PrefProviderTest, Patterns) { |
| 237 TestingProfile testing_profile; | 260 TestingProfile testing_profile; |
| 238 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), | 261 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), |
| 239 false); | 262 false); |
| 240 | 263 |
| 241 GURL host1("http://example.com/"); | 264 GURL host1("http://example.com/"); |
| 242 GURL host2("http://www.example.com/"); | 265 GURL host2("http://www.example.com/"); |
| 243 GURL host3("http://example.org/"); | 266 GURL host3("http://example.org/"); |
| 244 GURL host4("file:///tmp/test.html"); | 267 GURL host4("file:///tmp/test.html"); |
| 245 ContentSettingsPattern pattern1 = | 268 ContentSettingsPattern pattern1 = |
| 246 ContentSettingsPattern::FromString("[*.]example.com"); | 269 ContentSettingsPattern::FromString("[*.]example.com"); |
| 247 ContentSettingsPattern pattern2 = | 270 ContentSettingsPattern pattern2 = |
| 248 ContentSettingsPattern::FromString("example.org"); | 271 ContentSettingsPattern::FromString("example.org"); |
| 249 ContentSettingsPattern pattern3 = | 272 ContentSettingsPattern pattern3 = |
| 250 ContentSettingsPattern::FromString("file:///tmp/test.html"); | 273 ContentSettingsPattern::FromString("file:///tmp/test.html"); |
| 251 | 274 |
| 252 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 275 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 253 GetContentSetting( | 276 GetContentSetting(&pref_content_settings_provider, |
| 254 &pref_content_settings_provider, | 277 host1, |
| 255 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 278 host1, |
| 279 CONTENT_SETTINGS_TYPE_IMAGES, |
| 280 std::string(), |
| 281 false)); |
| 256 pref_content_settings_provider.SetWebsiteSetting( | 282 pref_content_settings_provider.SetWebsiteSetting( |
| 257 pattern1, | 283 pattern1, |
| 258 pattern1, | 284 pattern1, |
| 259 CONTENT_SETTINGS_TYPE_IMAGES, | 285 CONTENT_SETTINGS_TYPE_IMAGES, |
| 260 "", | 286 std::string(), |
| 261 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 287 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 262 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 288 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 263 GetContentSetting( | 289 GetContentSetting(&pref_content_settings_provider, |
| 264 &pref_content_settings_provider, | 290 host1, |
| 265 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 291 host1, |
| 292 CONTENT_SETTINGS_TYPE_IMAGES, |
| 293 std::string(), |
| 294 false)); |
| 266 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 295 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 267 GetContentSetting( | 296 GetContentSetting(&pref_content_settings_provider, |
| 268 &pref_content_settings_provider, | 297 host2, |
| 269 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 298 host2, |
| 299 CONTENT_SETTINGS_TYPE_IMAGES, |
| 300 std::string(), |
| 301 false)); |
| 270 | 302 |
| 271 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 303 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 272 GetContentSetting( | 304 GetContentSetting(&pref_content_settings_provider, |
| 273 &pref_content_settings_provider, | 305 host3, |
| 274 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 306 host3, |
| 307 CONTENT_SETTINGS_TYPE_IMAGES, |
| 308 std::string(), |
| 309 false)); |
| 275 pref_content_settings_provider.SetWebsiteSetting( | 310 pref_content_settings_provider.SetWebsiteSetting( |
| 276 pattern2, | 311 pattern2, |
| 277 pattern2, | 312 pattern2, |
| 278 CONTENT_SETTINGS_TYPE_IMAGES, | 313 CONTENT_SETTINGS_TYPE_IMAGES, |
| 279 "", | 314 std::string(), |
| 280 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 315 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 281 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 316 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 282 GetContentSetting( | 317 GetContentSetting(&pref_content_settings_provider, |
| 283 &pref_content_settings_provider, | 318 host3, |
| 284 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 319 host3, |
| 320 CONTENT_SETTINGS_TYPE_IMAGES, |
| 321 std::string(), |
| 322 false)); |
| 285 | 323 |
| 286 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 324 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 287 GetContentSetting(&pref_content_settings_provider, | 325 GetContentSetting(&pref_content_settings_provider, |
| 288 host4, host4, CONTENT_SETTINGS_TYPE_IMAGES, "", | 326 host4, |
| 327 host4, |
| 328 CONTENT_SETTINGS_TYPE_IMAGES, |
| 329 std::string(), |
| 289 false)); | 330 false)); |
| 290 pref_content_settings_provider.SetWebsiteSetting( | 331 pref_content_settings_provider.SetWebsiteSetting( |
| 291 pattern3, | 332 pattern3, |
| 292 pattern3, | 333 pattern3, |
| 293 CONTENT_SETTINGS_TYPE_IMAGES, | 334 CONTENT_SETTINGS_TYPE_IMAGES, |
| 294 "", | 335 std::string(), |
| 295 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 336 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 296 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 337 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 297 GetContentSetting( | 338 GetContentSetting(&pref_content_settings_provider, |
| 298 &pref_content_settings_provider, | 339 host4, |
| 299 host4, host4, CONTENT_SETTINGS_TYPE_IMAGES, "", false)); | 340 host4, |
| 341 CONTENT_SETTINGS_TYPE_IMAGES, |
| 342 std::string(), |
| 343 false)); |
| 300 | 344 |
| 301 pref_content_settings_provider.ShutdownOnUIThread(); | 345 pref_content_settings_provider.ShutdownOnUIThread(); |
| 302 } | 346 } |
| 303 | 347 |
| 304 TEST_F(PrefProviderTest, ResourceIdentifier) { | 348 TEST_F(PrefProviderTest, ResourceIdentifier) { |
| 305 TestingProfile testing_profile; | 349 TestingProfile testing_profile; |
| 306 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), | 350 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), |
| 307 false); | 351 false); |
| 308 | 352 |
| 309 GURL host("http://example.com/"); | 353 GURL host("http://example.com/"); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 DictionaryValue* mutable_settings = update.Get(); | 433 DictionaryValue* mutable_settings = update.Get(); |
| 390 mutable_settings->SetWithoutPathExpansion("www.example.com,*", | 434 mutable_settings->SetWithoutPathExpansion("www.example.com,*", |
| 391 new base::DictionaryValue()); | 435 new base::DictionaryValue()); |
| 392 } | 436 } |
| 393 EXPECT_TRUE(observer.notification_received()); | 437 EXPECT_TRUE(observer.notification_received()); |
| 394 | 438 |
| 395 provider.ShutdownOnUIThread(); | 439 provider.ShutdownOnUIThread(); |
| 396 } | 440 } |
| 397 | 441 |
| 398 } // namespace content_settings | 442 } // namespace content_settings |
| OLD | NEW |