Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4713)

Unified Diff: chrome/browser/content_settings/content_settings_pref_provider_unittest.cc

Issue 7655019: Migrate Obsolete NotificationsSettings and remove content_settings::NotificationsProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove include of deleted notifications_prefs_cache.h Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 01177c1c5c03169c38adc533c10ac87e9b7b5dd7..e15d4fd37652ebe0201baddab226206287a84d83 100644
--- a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
+++ b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
@@ -6,6 +6,7 @@
#include "base/auto_reset.h"
#include "base/command_line.h"
+#include "base/memory/scoped_ptr.h"
#include "chrome/browser/content_settings/content_settings_mock_observer.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/prefs/default_pref_store.h"
@@ -677,7 +678,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());
@@ -734,4 +735,140 @@ 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, 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.reset(new ListValue());
+ 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();
+ 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();
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698