Index: chrome/browser/content_settings/content_settings_pref_provider_unittest.cc |
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 033b69bb057a5cd28f7a43cf0cc0939b4841595e..2b64990b946e5df996d4da2a6ca1dae572d0a297 100644 |
--- a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc |
+++ b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc |
@@ -661,7 +661,7 @@ TEST_F(PrefProviderTest, SyncObsoleteGeolocationPref) { |
key, settings_dictionary->DeepCopy()); |
key = std::string( |
- primary_pattern_2.ToString()+ "," + |
+ primary_pattern_2.ToString() + "," + |
secondary_pattern.ToString()); |
all_settings_dictionary->SetWithoutPathExpansion( |
key, settings_dictionary->DeepCopy()); |
@@ -688,4 +688,140 @@ TEST_F(PrefProviderTest, SyncObsoleteGeolocationPref) { |
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. |
+ ListValue* allowed_origin_list = new ListValue(); |
battre
2011/08/22 15:00:57
memory leak
markusheintz_
2011/08/24 00:47:12
Done.
|
+ allowed_origin_list->AppendIfNotPresent( |
+ Value::CreateStringValue(allowed_url.spec())); |
+ prefs->Set(prefs::kDesktopNotificationAllowedOrigins, |
+ *allowed_origin_list); |
+ |
+ ListValue* denied_origin_list = new ListValue(); |
battre
2011/08/22 15:00:57
memory leak
markusheintz_
2011/08/24 00:47:12
Done.
|
+ 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, provider.GetContentSetting( |
+ allowed_url, |
+ allowed_url, |
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
+ "")); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, provider.GetContentSetting( |
+ denied_url, |
+ denied_url, |
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
+ "")); |
+ EXPECT_EQ(CONTENT_SETTING_DEFAULT, provider.GetContentSetting( |
+ allowed_url2, |
+ allowed_url2, |
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
+ "")); |
+ // 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()); |
+ |
+ // Change obsolete preference. This could be triggered by sync if sync is used |
+ // with an old version of chrome. |
+ allowed_origin_list = new ListValue(); |
battre
2011/08/22 15:00:57
memory leak
markusheintz_
2011/08/24 00:47:12
Done.
|
+ allowed_origin_list->AppendIfNotPresent( |
+ Value::CreateStringValue(allowed_url2.spec())); |
+ prefs->Set(prefs::kDesktopNotificationAllowedOrigins, |
+ *allowed_origin_list); |
+ |
+ // Test if the changed obsolete preference was migrated correctly. |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, provider.GetContentSetting( |
+ allowed_url2, |
+ allowed_url2, |
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
+ "")); |
+ EXPECT_EQ(CONTENT_SETTING_DEFAULT, provider.GetContentSetting( |
+ allowed_url, |
+ allowed_url, |
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
+ "")); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, provider.GetContentSetting( |
+ denied_url, |
+ denied_url, |
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
+ "")); |
+ // Check that geolocation settings were not synced to the obsolete content |
+ // settings pattern preference. |
+ const_obsolete_patterns_dictionary = |
+ prefs->GetDictionary(prefs::kContentSettingsPatterns); |
+ EXPECT_TRUE(const_obsolete_patterns_dictionary->empty()); |
+ |
+ provider.ShutdownOnUIThread(); |
+} |
+ |
+TEST_F(PrefProviderTest, SyncObsoleteNotificationsPref) { |
+ TestingProfile profile; |
+ PrefService* prefs = profile.GetPrefs(); |
+ |
+ content_settings::PrefProvider provider(prefs, false); |
+ |
+ // Changing the preferences prefs::kContentSettingsPatternPairs. |
+ ContentSettingsPattern primary_pattern= |
+ ContentSettingsPattern::FromString("http://www.bar.com"); |
+ ContentSettingsPattern primary_pattern_2 = |
+ ContentSettingsPattern::FromString("http://www.example.com"); |
+ ContentSettingsPattern secondary_pattern = |
+ ContentSettingsPattern::Wildcard(); |
battre
2011/08/22 15:00:57
nit: single line?
markusheintz_
2011/08/24 00:47:12
No 81 characters :(
|
+ GURL primary_url("http://www.bar.com"); |
+ GURL primary_url_2("http://www.example.com"); |
+ |
+ { |
+ DictionaryPrefUpdate update(prefs, |
+ prefs::kContentSettingsPatternPairs); |
+ DictionaryValue* all_settings_dictionary = update.Get(); |
battre
2011/08/22 15:00:57
nit/opt: You can also do something like:
Dictionar
markusheintz_
2011/08/24 00:47:12
Cool. Thanks for pointing this out to me :).
|
+ |
+ scoped_ptr<DictionaryValue> settings_dictionary(new DictionaryValue()); |
+ settings_dictionary->SetInteger("notifications", CONTENT_SETTING_BLOCK); |
+ std::string key( |
+ primary_pattern.ToString() + "," + |
+ secondary_pattern.ToString()); |
+ all_settings_dictionary->SetWithoutPathExpansion( |
+ key, settings_dictionary->DeepCopy()); |
+ |
+ settings_dictionary.reset(new DictionaryValue()); |
+ settings_dictionary->SetInteger("notifications", CONTENT_SETTING_ALLOW); |
+ key = primary_pattern_2.ToString() + "," + secondary_pattern.ToString(); |
+ all_settings_dictionary->SetWithoutPathExpansion( |
+ key, settings_dictionary->DeepCopy()); |
+ } |
+ |
+ // Test if the obsolete notifications preference is kept in sync if the new |
+ // preference is changed by a sync. |
+ const ListValue* denied_origin_list = |
+ prefs->GetList(prefs::kDesktopNotificationAllowedOrigins); |
+ EXPECT_EQ(1U, denied_origin_list->GetSize()); |
+ const ListValue* allowed_origin_list = |
+ prefs->GetList(prefs::kDesktopNotificationDeniedOrigins); |
+ EXPECT_EQ(1U, allowed_origin_list->GetSize()); |
+ |
+ provider.ShutdownOnUIThread(); |
+} |
+ |
} // namespace content_settings |