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

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

Issue 1605453003: Ensure content settings aren't persisted in the guest profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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/host_content_settings_map_unittest.cc
diff --git a/chrome/browser/content_settings/host_content_settings_map_unittest.cc b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
index 0be5dea1bd5f01290ac2e59a7471b4e3a8f0dea5..9036309dcd09672724cd6b31aab1624513305812 100644
--- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc
+++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
@@ -1162,3 +1162,75 @@ TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) {
std::string(),
CONTENT_SETTING_DEFAULT);
}
+
+TEST_F(HostContentSettingsMapTest, GuestProfile) {
+ TestingProfile profile;
+ profile.SetGuestSession(true);
+ HostContentSettingsMap* host_content_settings_map =
+ HostContentSettingsMapFactory::GetForProfile(&profile);
+
+ GURL host("http://example.com/");
+ ContentSettingsPattern pattern =
+ ContentSettingsPattern::FromString("[*.]example.com");
+
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
+
+ // Changing content settings should not result in any prefs being stored
+ // however the value should be set in memory.
+ host_content_settings_map->SetContentSetting(
+ pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
+ std::string(), CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ host_content_settings_map->GetContentSetting(
+ host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
+
+ const base::DictionaryValue* all_settings_dictionary =
+ profile.GetPrefs()->GetDictionary(
+ GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES));
+ EXPECT_TRUE(all_settings_dictionary->empty());
+}
+
+// Default settings should not be modifiable for the guest profile (there is no
+// UI to do this).
+TEST_F(HostContentSettingsMapTest, GuestProfileDefaultSetting) {
+ TestingProfile profile;
+ profile.SetGuestSession(true);
+ HostContentSettingsMap* host_content_settings_map =
+ HostContentSettingsMapFactory::GetForProfile(&profile);
+
+ GURL host("http://example.com/");
+
+ // There are no custom rules, so this should be the default.
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
+
+ host_content_settings_map->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
+
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
+}
+
+// We used to incorrectly store content settings in prefs for the guest profile.
+// We need to ensure these get deleted appropriately.
+TEST_F(HostContentSettingsMapTest, GuestProfileMigration) {
+ TestingProfile profile;
+ profile.SetGuestSession(true);
+
+ // Set a pref manually in the guest profile.
+ scoped_ptr<base::Value> value =
+ base::JSONReader::Read("{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}");
+ profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value);
+
+ // Test that during construction all the prefs get cleared.
+ HostContentSettingsMapFactory::GetForProfile(&profile);
+
+ const base::DictionaryValue* all_settings_dictionary =
+ profile.GetPrefs()->GetDictionary(
+ GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES));
+ EXPECT_TRUE(all_settings_dictionary->empty());
+}

Powered by Google App Engine
This is Rietveld 408576698