summaryrefslogtreecommitdiffstats
path: root/chrome/browser/content_settings
diff options
context:
space:
mode:
authormarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-21 16:21:53 +0000
committermarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-21 16:21:53 +0000
commit7b1d739df1f27aeff134e06edfc62cb0542f6736 (patch)
treef79b4ddbc518fb56e59a43edb436848e92c2637b /chrome/browser/content_settings
parentc4c3e61a37f371783cd223d3f93f630aa196e50a (diff)
downloadchromium_src-7b1d739df1f27aeff134e06edfc62cb0542f6736.zip
chromium_src-7b1d739df1f27aeff134e06edfc62cb0542f6736.tar.gz
chromium_src-7b1d739df1f27aeff134e06edfc62cb0542f6736.tar.bz2
Remove code for migrating obsolete location, notification and content settnigs prefs
BUG=101877 Review URL: https://chromiumcodereview.appspot.com/11280055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169058 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/content_settings')
-rw-r--r--chrome/browser/content_settings/content_settings_pref_provider.cc319
-rw-r--r--chrome/browser/content_settings/content_settings_pref_provider.h12
-rw-r--r--chrome/browser/content_settings/content_settings_pref_provider_unittest.cc193
3 files changed, 58 insertions, 466 deletions
diff --git a/chrome/browser/content_settings/content_settings_pref_provider.cc b/chrome/browser/content_settings/content_settings_pref_provider.cc
index 7f500fa..cf2c0fc 100644
--- a/chrome/browser/content_settings/content_settings_pref_provider.cc
+++ b/chrome/browser/content_settings/content_settings_pref_provider.cc
@@ -76,16 +76,6 @@ void PrefProvider::RegisterUserPrefs(PrefService* prefs) {
PrefService::UNSYNCABLE_PREF);
prefs->RegisterDictionaryPref(prefs::kContentSettingsPatternPairs,
PrefService::SYNCABLE_PREF);
-
- // Obsolete prefs, for migration:
- prefs->RegisterDictionaryPref(prefs::kGeolocationContentSettings,
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns,
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterListPref(prefs::kDesktopNotificationAllowedOrigins,
- PrefService::UNSYNCABLE_PREF);
- prefs->RegisterListPref(prefs::kDesktopNotificationDeniedOrigins,
- PrefService::UNSYNCABLE_PREF);
}
PrefProvider::PrefProvider(PrefService* prefs,
@@ -94,12 +84,6 @@ PrefProvider::PrefProvider(PrefService* prefs,
is_incognito_(incognito),
updating_preferences_(false) {
DCHECK(prefs_);
- if (!is_incognito_) {
- // Migrate obsolete preferences.
- MigrateObsoleteContentSettingsPatternPref();
- MigrateObsoleteGeolocationPref();
- MigrateObsoleteNotificationsPrefs();
- }
// Verify preferences version.
if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) {
@@ -253,12 +237,62 @@ void PrefProvider::UpdatePref(
DictionaryPrefUpdate update(prefs_,
prefs::kContentSettingsPatternPairs);
DictionaryValue* pattern_pairs_settings = update.Get();
- UpdatePatternPairsSettings(primary_pattern,
- secondary_pattern,
- content_type,
- resource_identifier,
- value,
- pattern_pairs_settings);
+
+ // Get settings dictionary for the given patterns.
+ std::string pattern_str(CreatePatternString(primary_pattern,
+ secondary_pattern));
+ DictionaryValue* settings_dictionary = NULL;
+ bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion(
+ pattern_str, &settings_dictionary);
+
+ if (!found && value) {
+ settings_dictionary = new DictionaryValue;
+ pattern_pairs_settings->SetWithoutPathExpansion(
+ pattern_str, settings_dictionary);
+ }
+
+ if (settings_dictionary) {
+ std::string res_dictionary_path;
+ if (GetResourceTypeName(content_type, &res_dictionary_path) &&
+ !resource_identifier.empty()) {
+ DictionaryValue* resource_dictionary = NULL;
+ found = settings_dictionary->GetDictionary(
+ res_dictionary_path, &resource_dictionary);
+ if (!found) {
+ if (value == NULL)
+ return; // Nothing to remove. Exit early.
+ resource_dictionary = new DictionaryValue;
+ settings_dictionary->Set(res_dictionary_path, resource_dictionary);
+ }
+ // Update resource dictionary.
+ if (value == NULL) {
+ resource_dictionary->RemoveWithoutPathExpansion(resource_identifier,
+ NULL);
+ if (resource_dictionary->empty()) {
+ settings_dictionary->RemoveWithoutPathExpansion(
+ res_dictionary_path, NULL);
+ }
+ } else {
+ resource_dictionary->SetWithoutPathExpansion(
+ resource_identifier, value->DeepCopy());
+ }
+ } else {
+ // Update settings dictionary.
+ std::string setting_path = GetTypeName(content_type);
+ if (value == NULL) {
+ settings_dictionary->RemoveWithoutPathExpansion(setting_path,
+ NULL);
+ } else {
+ settings_dictionary->SetWithoutPathExpansion(
+ setting_path, value->DeepCopy());
+ }
+ }
+ // Remove the settings dictionary if it is empty.
+ if (settings_dictionary->empty()) {
+ pattern_pairs_settings->RemoveWithoutPathExpansion(
+ pattern_str, NULL);
+ }
+ }
}
}
@@ -384,70 +418,6 @@ void PrefProvider::OnContentSettingsPatternPairsChanged() {
std::string());
}
-void PrefProvider::UpdatePatternPairsSettings(
- const ContentSettingsPattern& primary_pattern,
- const ContentSettingsPattern& secondary_pattern,
- ContentSettingsType content_type,
- const ResourceIdentifier& resource_identifier,
- const base::Value* value,
- DictionaryValue* pattern_pairs_settings) {
- // Get settings dictionary for the given patterns.
- std::string pattern_str(CreatePatternString(primary_pattern,
- secondary_pattern));
- DictionaryValue* settings_dictionary = NULL;
- bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion(
- pattern_str, &settings_dictionary);
-
- if (!found && value) {
- settings_dictionary = new DictionaryValue;
- pattern_pairs_settings->SetWithoutPathExpansion(
- pattern_str, settings_dictionary);
- }
-
- if (settings_dictionary) {
- std::string res_dictionary_path;
- if (GetResourceTypeName(content_type, &res_dictionary_path) &&
- !resource_identifier.empty()) {
- DictionaryValue* resource_dictionary = NULL;
- found = settings_dictionary->GetDictionary(
- res_dictionary_path, &resource_dictionary);
- if (!found) {
- if (value == NULL)
- return; // Nothing to remove. Exit early.
- resource_dictionary = new DictionaryValue;
- settings_dictionary->Set(res_dictionary_path, resource_dictionary);
- }
- // Update resource dictionary.
- if (value == NULL) {
- resource_dictionary->RemoveWithoutPathExpansion(resource_identifier,
- NULL);
- if (resource_dictionary->empty()) {
- settings_dictionary->RemoveWithoutPathExpansion(
- res_dictionary_path, NULL);
- }
- } else {
- resource_dictionary->SetWithoutPathExpansion(
- resource_identifier, value->DeepCopy());
- }
- } else {
- // Update settings dictionary.
- std::string setting_path = GetTypeName(content_type);
- if (value == NULL) {
- settings_dictionary->RemoveWithoutPathExpansion(setting_path,
- NULL);
- } else {
- settings_dictionary->SetWithoutPathExpansion(
- setting_path, value->DeepCopy());
- }
- }
- // Remove the settings dictionary if it is empty.
- if (settings_dictionary->empty()) {
- pattern_pairs_settings->RemoveWithoutPathExpansion(
- pattern_str, NULL);
- }
- }
-}
-
// static
void PrefProvider::CanonicalizeContentSettingsExceptions(
DictionaryValue* all_settings_dictionary) {
@@ -511,183 +481,6 @@ void PrefProvider::ShutdownOnUIThread() {
prefs_ = NULL;
}
-void PrefProvider::MigrateObsoleteContentSettingsPatternPref() {
- // Ensure that |lock_| is not held by this thread, since this function will
- // send out notifications (by |~DictionaryPrefUpdate|).
- AssertLockNotHeld();
-
- if (!prefs_->HasPrefPath(prefs::kContentSettingsPatterns))
- return;
-
- const DictionaryValue* patterns_dictionary =
- prefs_->GetDictionary(prefs::kContentSettingsPatterns);
- {
- DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs);
- DictionaryValue* pattern_pairs_dictionary = update.Get();
- for (DictionaryValue::key_iterator i(
- patterns_dictionary->begin_keys());
- i != patterns_dictionary->end_keys();
- ++i) {
- const std::string& key(*i);
- // In the past a bug once corrupted dictionary keys. Test if the |key| is
- // corrupted and skip a corrupted key. A dictionary |key| can contain two
- // content settings patterns, a primary pattern and a secondary pattern.
- // If the |key| contains two patterns than they are concataneted with a
- // ','.
- size_t sep_pos = key.find(",");
- ContentSettingsPattern pattern =
- ContentSettingsPattern::FromString(key.substr(0, sep_pos));
- // Skip the current |key| if the primary |pattern| is invalid.
- if (!pattern.IsValid())
- continue;
- // If the |key| contains a secondary pattern, and the obsolete pref
- // dictionary also contains a key that equals the primary |pattern| then
- // skip the current |key|.
- if (sep_pos != std::string::npos &&
- patterns_dictionary->HasKey(pattern.ToString())) {
- continue;
- }
-
- // Copy the legacy content settings for the current |key| from the
- // obsolete pref prefs::kContentSettingsPatterns to the pref
- // prefs::kContentSettingsPatternPairs.
- const DictionaryValue* dictionary = NULL;
- bool found = patterns_dictionary->GetDictionaryWithoutPathExpansion(
- key, &dictionary);
- DCHECK(found);
- std::string new_key = CreatePatternString(
- pattern, ContentSettingsPattern::Wildcard());
- // Existing values are overwritten.
- pattern_pairs_dictionary->SetWithoutPathExpansion(
- new_key, dictionary->DeepCopy());
- }
- }
- prefs_->ClearPref(prefs::kContentSettingsPatterns);
-}
-
-void PrefProvider::MigrateObsoleteGeolocationPref() {
- // Ensure that |lock_| is not held by this thread, since this function will
- // send out notifications (by |~DictionaryPrefUpdate|).
- AssertLockNotHeld();
-
- if (!prefs_->HasPrefPath(prefs::kGeolocationContentSettings))
- return;
-
- DictionaryPrefUpdate update(prefs_,
- prefs::kContentSettingsPatternPairs);
- DictionaryValue* pattern_pairs_settings = update.Get();
-
- const DictionaryValue* geolocation_settings =
- prefs_->GetDictionary(prefs::kGeolocationContentSettings);
-
- std::vector<std::pair<std::string, std::string> > corrupted_keys;
- for (DictionaryValue::key_iterator i =
- geolocation_settings->begin_keys();
- i != geolocation_settings->end_keys();
- ++i) {
- const std::string& primary_key(*i);
- GURL primary_url(primary_key);
- DCHECK(primary_url.is_valid());
-
- const DictionaryValue* requesting_origin_settings = NULL;
- // The method GetDictionaryWithoutPathExpansion() returns false if the
- // value for the given key is not a |DictionaryValue|. If the value for the
- // |primary_key| is not a |DictionaryValue| then the location settings for
- // this key are corrupted. Therefore they are ignored.
- if (!geolocation_settings->GetDictionaryWithoutPathExpansion(
- primary_key, &requesting_origin_settings))
- continue;
-
- for (DictionaryValue::key_iterator j =
- requesting_origin_settings->begin_keys();
- j != requesting_origin_settings->end_keys();
- ++j) {
- const std::string& secondary_key(*j);
- GURL secondary_url(secondary_key);
- // Save corrupted keys to remove them later.
- if (!secondary_url.is_valid()) {
- corrupted_keys.push_back(std::make_pair(primary_key, secondary_key));
- continue;
- }
-
- const base::Value* value = NULL;
- bool found = requesting_origin_settings->GetWithoutPathExpansion(
- secondary_key, &value);
- DCHECK(found);
-
- ContentSettingsPattern primary_pattern =
- ContentSettingsPattern::FromURLNoWildcard(primary_url);
- ContentSettingsPattern secondary_pattern =
- ContentSettingsPattern::FromURLNoWildcard(secondary_url);
- DCHECK(primary_pattern.IsValid() && secondary_pattern.IsValid());
-
- UpdatePatternPairsSettings(primary_pattern,
- secondary_pattern,
- CONTENT_SETTINGS_TYPE_GEOLOCATION,
- std::string(),
- value,
- pattern_pairs_settings);
- }
- }
-
- prefs_->ClearPref(prefs::kGeolocationContentSettings);
-}
-
-void PrefProvider::MigrateObsoleteNotificationsPrefs() {
- // Ensure that |lock_| is not held by this thread, since this function will
- // send out notifications (by |~DictionaryPrefUpdate|).
- AssertLockNotHeld();
-
- if (!prefs_->HasPrefPath(prefs::kDesktopNotificationAllowedOrigins) &&
- !prefs_->HasPrefPath(prefs::kDesktopNotificationDeniedOrigins)) {
- return;
- }
-
- DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs);
- DictionaryValue* pattern_pairs_settings = update.Get();
-
- const ListValue* allowed_origins =
- prefs_->GetList(prefs::kDesktopNotificationAllowedOrigins);
- for (size_t i = 0; i < allowed_origins->GetSize(); ++i) {
- std::string url_string;
- bool status = allowed_origins->GetString(i, &url_string);
- DCHECK(status);
- ContentSettingsPattern primary_pattern =
- ContentSettingsPattern::FromURLNoWildcard(GURL(url_string));
- DCHECK(primary_pattern.IsValid());
- scoped_ptr<base::Value> value(
- Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
- UpdatePatternPairsSettings(primary_pattern,
- ContentSettingsPattern::Wildcard(),
- CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
- std::string(),
- value.get(),
- pattern_pairs_settings);
- }
-
- const ListValue* denied_origins =
- prefs_->GetList(prefs::kDesktopNotificationDeniedOrigins);
- for (size_t i = 0; i < denied_origins->GetSize(); ++i) {
- std::string url_string;
- bool status = denied_origins->GetString(i, &url_string);
- DCHECK(status);
- ContentSettingsPattern primary_pattern =
- ContentSettingsPattern::FromURLNoWildcard(GURL(url_string));
- DCHECK(primary_pattern.IsValid());
- scoped_ptr<base::Value> value(
- Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
- UpdatePatternPairsSettings(primary_pattern,
- ContentSettingsPattern::Wildcard(),
- CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
- std::string(),
- value.get(),
- pattern_pairs_settings);
- }
-
- prefs_->ClearPref(prefs::kDesktopNotificationAllowedOrigins);
- prefs_->ClearPref(prefs::kDesktopNotificationDeniedOrigins);
-}
-
void PrefProvider::AssertLockNotHeld() const {
#if !defined(NDEBUG)
// |Lock::Acquire()| will assert if the lock is held by this thread.
diff --git a/chrome/browser/content_settings/content_settings_pref_provider.h b/chrome/browser/content_settings/content_settings_pref_provider.h
index 17fda76..a397211 100644
--- a/chrome/browser/content_settings/content_settings_pref_provider.h
+++ b/chrome/browser/content_settings/content_settings_pref_provider.h
@@ -73,19 +73,7 @@ class PrefProvider : public ObservableProvider {
const ResourceIdentifier& resource_identifier,
const base::Value* value);
- // Updates the given |pattern_pairs_settings| dictionary value.
- void UpdatePatternPairsSettings(
- const ContentSettingsPattern& primary_pattern,
- const ContentSettingsPattern& secondary_pattern,
- ContentSettingsType content_type,
- const ResourceIdentifier& resource_identifier,
- const base::Value* value,
- DictionaryValue* pattern_pairs_settings);
-
void MigrateObsoleteClearOnExitPref();
- void MigrateObsoleteContentSettingsPatternPref();
- void MigrateObsoleteGeolocationPref();
- void MigrateObsoleteNotificationsPrefs();
static void CanonicalizeContentSettingsExceptions(
base::DictionaryValue* all_settings_dictionary);
diff --git a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
index 0a56381..6b92b21 100644
--- a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
+++ b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
@@ -173,7 +173,8 @@ TEST_F(PrefProviderTest, Incognito) {
&pref_content_settings_provider_incognito,
host, host, CONTENT_SETTINGS_TYPE_IMAGES, "", false));
// But the value should not be overridden in the OTR user prefs accidentally.
- EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(prefs::kContentSettingsPatterns));
+ EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(
+ prefs::kContentSettingsPatternPairs));
pref_content_settings_provider.ShutdownOnUIThread();
pref_content_settings_provider_incognito.ShutdownOnUIThread();
@@ -328,126 +329,6 @@ TEST_F(PrefProviderTest, ResourceIdentifier) {
pref_content_settings_provider.ShutdownOnUIThread();
}
-TEST_F(PrefProviderTest, MigrateObsoleteContentSettingsPatternPref) {
- // Setup single pattern settings.
- TestingProfile profile;
- PrefService* prefs = profile.GetPrefs();
-
- // Set obsolete preference for content settings pattern.
- DictionaryValue* settings_dictionary = new DictionaryValue();
- settings_dictionary->SetInteger("cookies", 2);
- settings_dictionary->SetInteger("images", 2);
- settings_dictionary->SetInteger("popups", 2);
- ContentSettingsPattern pattern =
- ContentSettingsPattern::FromString("http://www.example.com");
- scoped_ptr<DictionaryValue> all_settings_dictionary(new DictionaryValue());
- all_settings_dictionary->SetWithoutPathExpansion(
- pattern.ToString(), settings_dictionary);
- prefs->Set(prefs::kContentSettingsPatterns, *all_settings_dictionary);
-
- content_settings::PrefProvider provider(prefs, false);
-
- // Test if single pattern settings are properly migrated.
- const DictionaryValue* const_all_settings_dictionary =
- prefs->GetDictionary(prefs::kContentSettingsPatternPairs);
- EXPECT_EQ(1U, const_all_settings_dictionary->size());
- EXPECT_FALSE(const_all_settings_dictionary->HasKey(pattern.ToString()));
- EXPECT_TRUE(const_all_settings_dictionary->HasKey(
- pattern.ToString() + "," +
- ContentSettingsPattern::Wildcard().ToString()));
- EXPECT_EQ(CONTENT_SETTING_BLOCK, GetContentSetting(
- &provider,
- GURL("http://www.example.com"),
- GURL("http://www.example.com"),
- CONTENT_SETTINGS_TYPE_IMAGES,
- "",
- false));
- EXPECT_EQ(CONTENT_SETTING_BLOCK, GetContentSetting(
- &provider,
- GURL("http://www.example.com"),
- GURL("http://www.example.com"),
- CONTENT_SETTINGS_TYPE_POPUPS,
- "",
- false));
- // Test if single pattern settings are properly migrated.
- const_all_settings_dictionary = prefs->GetDictionary(
- prefs::kContentSettingsPatternPairs);
- EXPECT_EQ(1U, const_all_settings_dictionary->size());
- EXPECT_FALSE(const_all_settings_dictionary->HasKey(pattern.ToString()));
- EXPECT_TRUE(const_all_settings_dictionary->HasKey(
- pattern.ToString() + "," +
- ContentSettingsPattern::Wildcard().ToString()));
-
- EXPECT_TRUE(prefs->GetDictionary(prefs::kContentSettingsPatterns)->empty());
- provider.ShutdownOnUIThread();
-}
-
-TEST_F(PrefProviderTest, MigrateObsoleteGeolocationPref) {
- TestingProfile profile;
- PrefService* prefs = profile.GetPrefs();
- GURL secondary_url("http://www.foo.com");
- GURL primary_url("http://www.bar.com");
- GURL corrupted_setting_url("http://www.corruptedsetting.com");
-
- // Set obsolete preference.
- DictionaryValue* secondary_patterns_dictionary = new DictionaryValue();
- secondary_patterns_dictionary->SetWithoutPathExpansion(
- secondary_url.spec(),
- Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
- scoped_ptr<DictionaryValue> geolocation_settings_dictionary(
- new DictionaryValue());
- geolocation_settings_dictionary->SetWithoutPathExpansion(
- primary_url.spec(), secondary_patterns_dictionary);
- // Add a non dictionary value to the geolocation settings dictionary to test
- // that corrupted settings are ignored (See http://crbug.com/125009).
- geolocation_settings_dictionary->SetWithoutPathExpansion(
- corrupted_setting_url.spec(), Value::CreateIntegerValue(0));
- prefs->Set(prefs::kGeolocationContentSettings,
- *geolocation_settings_dictionary);
-
- content_settings::PrefProvider provider(prefs, false);
-
- // Test if the migrated settings are loaded and available.
- EXPECT_EQ(CONTENT_SETTING_BLOCK, GetContentSetting(
- &provider,
- primary_url,
- secondary_url,
- CONTENT_SETTINGS_TYPE_GEOLOCATION,
- "",
- false));
- EXPECT_EQ(CONTENT_SETTING_DEFAULT, GetContentSetting(
- &provider,
- GURL("http://www.example.com"),
- secondary_url,
- CONTENT_SETTINGS_TYPE_GEOLOCATION,
- "",
- false));
- EXPECT_EQ(CONTENT_SETTING_DEFAULT, GetContentSetting(
- &provider,
- corrupted_setting_url,
- corrupted_setting_url,
- CONTENT_SETTINGS_TYPE_GEOLOCATION,
- "",
- false));
- // Check if the settings where migrated correctly.
- const DictionaryValue* const_all_settings_dictionary =
- prefs->GetDictionary(prefs::kContentSettingsPatternPairs);
- EXPECT_EQ(1U, const_all_settings_dictionary->size());
- EXPECT_TRUE(const_all_settings_dictionary->HasKey(
- ContentSettingsPattern::FromURLNoWildcard(primary_url).ToString() + "," +
- ContentSettingsPattern::FromURLNoWildcard(secondary_url).ToString()));
- // Check that geolocation settings were not synced to the obsolete content
- // settings pattern preference.
- const DictionaryValue* const_obsolete_patterns_dictionary =
- prefs->GetDictionary(prefs::kContentSettingsPatterns);
- EXPECT_TRUE(const_obsolete_patterns_dictionary->empty());
-
- EXPECT_TRUE(
- prefs->GetDictionary(prefs::kGeolocationContentSettings)->empty());
-
- provider.ShutdownOnUIThread();
-}
-
TEST_F(PrefProviderTest, AutoSubmitCertificateContentSetting) {
TestingProfile profile;
TestingPrefService* prefs = profile.GetTestingPrefService();
@@ -482,76 +363,6 @@ TEST_F(PrefProviderTest, AutoSubmitCertificateContentSetting) {
provider.ShutdownOnUIThread();
}
-TEST_F(PrefProviderTest, MigrateObsoleteNotificationsPref) {
- TestingProfile profile;
- PrefService* prefs = profile.GetPrefs();
- GURL allowed_url("http://www.foo.com");
- GURL allowed_url2("http://www.example.com");
- GURL denied_url("http://www.bar.com");
-
- // Set obsolete preference.
- scoped_ptr<ListValue> allowed_origin_list(new ListValue());
- allowed_origin_list->AppendIfNotPresent(
- Value::CreateStringValue(allowed_url.spec()));
- prefs->Set(prefs::kDesktopNotificationAllowedOrigins,
- *allowed_origin_list);
-
- scoped_ptr<ListValue> denied_origin_list(new ListValue());
- denied_origin_list->AppendIfNotPresent(
- Value::CreateStringValue(denied_url.spec()));
- prefs->Set(prefs::kDesktopNotificationDeniedOrigins,
- *denied_origin_list);
-
- content_settings::PrefProvider provider(prefs, false);
-
- // Test if the migrated settings are loaded and available.
- EXPECT_EQ(CONTENT_SETTING_ALLOW, GetContentSetting(
- &provider,
- allowed_url,
- allowed_url,
- CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
- "",
- false));
- EXPECT_EQ(CONTENT_SETTING_BLOCK, GetContentSetting(
- &provider,
- denied_url,
- denied_url,
- CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
- "",
- false));
- EXPECT_EQ(CONTENT_SETTING_DEFAULT, GetContentSetting(
- &provider,
- allowed_url2,
- allowed_url2,
- CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
- "",
- false));
- // Check if the settings where migrated correctly.
- const DictionaryValue* const_all_settings_dictionary =
- prefs->GetDictionary(prefs::kContentSettingsPatternPairs);
- EXPECT_EQ(2U, const_all_settings_dictionary->size());
- EXPECT_TRUE(const_all_settings_dictionary->HasKey(
- ContentSettingsPattern::FromURLNoWildcard(allowed_url).ToString() + "," +
- ContentSettingsPattern::Wildcard().ToString()));
- EXPECT_TRUE(const_all_settings_dictionary->HasKey(
- ContentSettingsPattern::FromURLNoWildcard(denied_url).ToString() + "," +
- ContentSettingsPattern::Wildcard().ToString()));
-
- // Check that notifications settings were not synced to the obsolete content
- // settings pattern preference.
- const DictionaryValue* const_obsolete_patterns_dictionary =
- prefs->GetDictionary(prefs::kContentSettingsPatterns);
- EXPECT_TRUE(const_obsolete_patterns_dictionary->empty());
-
- // Test that the obsolete notifications settings were cleared.
- EXPECT_TRUE(
- prefs->GetList(prefs::kDesktopNotificationAllowedOrigins)->empty());
- EXPECT_TRUE(
- prefs->GetList(prefs::kDesktopNotificationDeniedOrigins)->empty());
-
- provider.ShutdownOnUIThread();
-}
-
// http://crosbug.com/17760
TEST_F(PrefProviderTest, Deadlock) {
TestingPrefService prefs;