| 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 "components/content_settings/core/browser/content_settings_pref_provide
r.h" | 5 #include "components/content_settings/core/browser/content_settings_pref_provide
r.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 286 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); |
| 287 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 287 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 288 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, | 288 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, |
| 289 host4, CONTENT_SETTINGS_TYPE_COOKIES, | 289 host4, CONTENT_SETTINGS_TYPE_COOKIES, |
| 290 std::string(), false)); | 290 std::string(), false)); |
| 291 | 291 |
| 292 pref_content_settings_provider.ShutdownOnUIThread(); | 292 pref_content_settings_provider.ShutdownOnUIThread(); |
| 293 } | 293 } |
| 294 | 294 |
| 295 #if defined(ENABLE_PLUGINS) | 295 #if defined(ENABLE_PLUGINS) |
| 296 TEST_F(PrefProviderTest, ResourceIdentifier) { | 296 // Old per-plugin pref settings should be deleted when reading settings. |
| 297 TEST_F(PrefProviderTest, DeprecateResourceIdentifierPrefs) { |
| 297 TestingProfile testing_profile; | 298 TestingProfile testing_profile; |
| 298 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), | 299 PrefService* prefs = testing_profile.GetPrefs(); |
| 299 false); | |
| 300 | 300 |
| 301 GURL host("http://example.com/"); | 301 std::string pref_name = |
| 302 ContentSettingsPattern pattern = | 302 content_settings::WebsiteSettingsRegistry::GetInstance() |
| 303 ContentSettingsPattern::FromString("[*.]example.com"); | 303 ->Get(CONTENT_SETTINGS_TYPE_PLUGINS) |
| 304 std::string resource1("someplugin"); | 304 ->pref_name(); |
| 305 std::string resource2("otherplugin"); | |
| 306 | 305 |
| 307 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 306 // Set an old per-plugin setting. |
| 308 TestUtils::GetContentSetting(&pref_content_settings_provider, host, | 307 { |
| 309 host, CONTENT_SETTINGS_TYPE_PLUGINS, | 308 DictionaryPrefUpdate update(prefs, pref_name); |
| 310 resource1, false)); | 309 base::DictionaryValue* all_settings_dictionary = update.Get(); |
| 311 pref_content_settings_provider.SetWebsiteSetting( | |
| 312 pattern, | |
| 313 pattern, | |
| 314 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 315 resource1, | |
| 316 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | |
| 317 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 318 TestUtils::GetContentSetting(&pref_content_settings_provider, host, | |
| 319 host, CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 320 resource1, false)); | |
| 321 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | |
| 322 TestUtils::GetContentSetting(&pref_content_settings_provider, host, | |
| 323 host, CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 324 resource2, false)); | |
| 325 | 310 |
| 326 pref_content_settings_provider.ShutdownOnUIThread(); | 311 base::DictionaryValue* per_resource_dictionary = new base::DictionaryValue; |
| 312 per_resource_dictionary->SetIntegerWithoutPathExpansion( |
| 313 "plugin_name", CONTENT_SETTING_ALLOW); |
| 314 base::DictionaryValue* settings_dictionary = new base::DictionaryValue; |
| 315 settings_dictionary->SetWithoutPathExpansion("per_resource", |
| 316 per_resource_dictionary); |
| 317 |
| 318 base::DictionaryValue* settings_dictionary2 = |
| 319 settings_dictionary->DeepCopy(); |
| 320 settings_dictionary2->SetIntegerWithoutPathExpansion("setting", |
| 321 CONTENT_SETTING_ALLOW); |
| 322 |
| 323 // This only has a per-plugin setting. |
| 324 all_settings_dictionary->SetWithoutPathExpansion("[*.]test.com,*", |
| 325 settings_dictionary); |
| 326 |
| 327 // This has a per-plugin setting and a per-site setting. |
| 328 all_settings_dictionary->SetWithoutPathExpansion("[*.]test2.com,*", |
| 329 settings_dictionary2); |
| 330 } |
| 331 |
| 332 // Create the pref-provider. |
| 333 PrefProvider pref_content_settings_provider(prefs, false); |
| 334 |
| 335 const base::DictionaryValue* all_settings_dictionary = |
| 336 prefs->GetDictionary(pref_name); |
| 337 |
| 338 // The pref that only had the per-plugin setting should be gone. |
| 339 const base::DictionaryValue* result; |
| 340 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
| 341 "[*.]test.com,*", &result)); |
| 342 |
| 343 // The pref that had the per-site setting should still be there, but the |
| 344 // per-plugin part should be gone. |
| 345 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
| 346 "[*.]test2.com,*", &result)); |
| 347 int setting_result; |
| 348 EXPECT_TRUE( |
| 349 result->GetIntegerWithoutPathExpansion("setting", &setting_result)); |
| 350 EXPECT_EQ(CONTENT_SETTING_ALLOW, setting_result); |
| 351 EXPECT_FALSE( |
| 352 result->GetDictionaryWithoutPathExpansion("per_resource", nullptr)); |
| 327 } | 353 } |
| 328 #endif | 354 #endif |
| 329 | 355 |
| 330 // http://crosbug.com/17760 | 356 // http://crosbug.com/17760 |
| 331 TEST_F(PrefProviderTest, Deadlock) { | 357 TEST_F(PrefProviderTest, Deadlock) { |
| 332 syncable_prefs::TestingPrefServiceSyncable prefs; | 358 syncable_prefs::TestingPrefServiceSyncable prefs; |
| 333 PrefProvider::RegisterProfilePrefs(prefs.registry()); | 359 PrefProvider::RegisterProfilePrefs(prefs.registry()); |
| 334 | 360 |
| 335 // Chain of events: a preference changes, |PrefProvider| notices it, and reads | 361 // Chain of events: a preference changes, |PrefProvider| notices it, and reads |
| 336 // and writes the preference. When the preference is written, a notification | 362 // and writes the preference. When the preference is written, a notification |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 for (const char* pref : nonempty_prefs) { | 548 for (const char* pref : nonempty_prefs) { |
| 523 DictionaryPrefUpdate update(&prefs, pref); | 549 DictionaryPrefUpdate update(&prefs, pref); |
| 524 const base::DictionaryValue* dictionary = update.Get(); | 550 const base::DictionaryValue* dictionary = update.Get(); |
| 525 EXPECT_EQ(1u, dictionary->size()); | 551 EXPECT_EQ(1u, dictionary->size()); |
| 526 } | 552 } |
| 527 | 553 |
| 528 provider.ShutdownOnUIThread(); | 554 provider.ShutdownOnUIThread(); |
| 529 } | 555 } |
| 530 | 556 |
| 531 } // namespace content_settings | 557 } // namespace content_settings |
| OLD | NEW |