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

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

Issue 2158743002: Register a pref to control migration status (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@change_scoping_type
Patch Set: address review comments Created 4 years, 5 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
« no previous file with comments | « no previous file | components/content_settings/core/browser/host_content_settings_map.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ee7029cd6e3c42171b8a51a084bdbaf57cf28339..2fee449e3612cdf2de23f9a73225f8f6bf56ef21 100644
--- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc
+++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
@@ -1426,7 +1426,7 @@ TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) {
"https://[*.]example.com:443");
EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*");
- host_content_settings_map->MigrateDomainScopedSettings();
+ host_content_settings_map->MigrateDomainScopedSettings(false);
// After migration, settings only affect origins.
EXPECT_EQ(
@@ -1464,6 +1464,106 @@ TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) {
EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*");
}
+// Ensure that migration only happens once upon construction of the HCSM and
+// once after syncing (even when these events occur multiple times).
+TEST_F(HostContentSettingsMapTest, DomainToOriginMigrationStatus) {
+ TestingProfile profile;
+
+ HostContentSettingsMap* host_content_settings_map =
+ HostContentSettingsMapFactory::GetForProfile(&profile);
+
+ GURL http_host("http://example.com/");
+ GURL http_host_narrower("http://a.example.com/");
+
+ // Change default setting to BLOCK.
+ host_content_settings_map->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
+ // Set domain scoped settings.
+ host_content_settings_map->SetContentSettingCustomScope(
+ ContentSettingsPattern::FromURL(http_host),
+ ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES,
+ std::string(), CONTENT_SETTING_ALLOW);
+ EXPECT_EQ(
+ CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
+ // Settings apply to subdomains.
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ http_host_narrower, http_host_narrower,
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
+
+ // Do migration before sync.
+ host_content_settings_map->MigrateDomainScopedSettings(false);
+
+ // Settings only apply to origins. Migration got executed.
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ host_content_settings_map->GetContentSetting(
+ http_host_narrower, http_host_narrower,
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
+
+ GURL https_host("https://example.com/");
+ GURL https_host_narrower("https://a.example.com/");
+
+ host_content_settings_map->SetContentSettingCustomScope(
+ ContentSettingsPattern::FromURL(https_host),
+ ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES,
+ std::string(), CONTENT_SETTING_ALLOW);
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ https_host, https_host, CONTENT_SETTINGS_TYPE_COOKIES,
+ std::string()));
+ // Settings apply to subdomains.
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ https_host_narrower, https_host_narrower,
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
+
+ // Try to do migration again before sync.
+ host_content_settings_map->MigrateDomainScopedSettings(false);
+
+ // Settings still apply to subdomains. Migration didn't get executed.
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ https_host_narrower, https_host_narrower,
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
+
+ // Do migration after sync.
+ host_content_settings_map->MigrateDomainScopedSettings(true);
+
+ // Settings only apply to origins. Migration got executed.
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ host_content_settings_map->GetContentSetting(
+ https_host_narrower, https_host_narrower,
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
+
+ GURL http1_host("http://google.com/");
+ GURL http1_host_narrower("http://a.google.com/");
+
+ host_content_settings_map->SetContentSettingCustomScope(
+ ContentSettingsPattern::FromURL(http1_host),
+ ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES,
+ std::string(), CONTENT_SETTING_ALLOW);
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ http1_host, http1_host, CONTENT_SETTINGS_TYPE_COOKIES,
+ std::string()));
+ // Settings apply to subdomains.
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ http1_host_narrower, http1_host_narrower,
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
+
+ // Try to do migration again after sync.
+ host_content_settings_map->MigrateDomainScopedSettings(true);
+
+ // Settings still apply to subdomains. Migration didn't get executed.
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ http1_host_narrower, http1_host_narrower,
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
+}
+
TEST_F(HostContentSettingsMapTest, InvalidPattern) {
// This is a regression test for crbug.com/618529, which fixed a memory leak
// when a website setting was set under a URL that mapped to an invalid
« no previous file with comments | « no previous file | components/content_settings/core/browser/host_content_settings_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698