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 4573d3d95e49b64b4a43fbdf751c69ff77f3f5ba..b580d6f3fb7e6fd050365ebe430f29d6d71d20e3 100644 |
--- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc |
+++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc |
@@ -1278,6 +1278,137 @@ TEST_F(HostContentSettingsMapTest, MigrateKeygenSettings) { |
host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
} |
+TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) { |
+ TestingProfile profile; |
+ HostContentSettingsMap* host_content_settings_map = |
+ HostContentSettingsMapFactory::GetForProfile(&profile); |
+ |
+ // Set old formatted http settings. |
+ 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); |
+ EXPECT_EQ( |
+ CONTENT_SETTING_BLOCK, |
+ host_content_settings_map->GetContentSetting( |
+ http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
+ // Patterns generated for cookies used to be domain scoped. |
+ 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 also 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())); |
+ |
+ ContentSettingsForOneType settings; |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &settings); |
+ // |host_content_settings_map| contains default setting and a custom setting. |
+ EXPECT_EQ(2U, settings.size()); |
+ bool found_setting = false; |
msramek
2016/06/30 16:16:21
This can be simplified as:
EXPECT_TRUE(settings[0
lshang
2016/07/04 02:46:00
Done.
|
+ for (const ContentSettingPatternSource& setting_entry : settings) { |
+ if (setting_entry.primary_pattern.ToString() == "[*.]example.com") { |
+ EXPECT_FALSE(found_setting); |
+ found_setting = true; |
+ } |
+ } |
+ EXPECT_TRUE(found_setting); |
+ |
+ // Set old formatted https settings. |
+ GURL https_host("https://example.com/"); |
+ GURL https_host_narrower("https://a.example.com/"); |
+ |
+ // Change default setting to BLOCK. |
+ host_content_settings_map->SetDefaultContentSetting( |
+ CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_BLOCK); |
+ EXPECT_EQ( |
+ CONTENT_SETTING_BLOCK, |
+ host_content_settings_map->GetContentSetting( |
+ https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
+ // Patterns generated for popups used to be domain scoped. |
+ host_content_settings_map->SetContentSettingCustomScope( |
+ ContentSettingsPattern::FromURL(https_host), |
+ ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS, |
+ std::string(), CONTENT_SETTING_ALLOW); |
+ EXPECT_EQ( |
+ CONTENT_SETTING_ALLOW, |
+ host_content_settings_map->GetContentSetting( |
+ https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
+ // Settings also apply to subdomains. |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ host_content_settings_map->GetContentSetting( |
+ https_host_narrower, https_host_narrower, |
+ CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
+ |
+ host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, |
+ std::string(), &settings); |
+ // |host_content_settings_map| contains default setting and a custom setting. |
+ EXPECT_EQ(2U, settings.size()); |
+ found_setting = false; |
+ for (const ContentSettingPatternSource& setting_entry : settings) { |
+ if (setting_entry.primary_pattern.ToString() == |
+ "https://[*.]example.com:443") { |
+ EXPECT_FALSE(found_setting); |
+ found_setting = true; |
+ } |
+ } |
+ EXPECT_TRUE(found_setting); |
+ |
+ host_content_settings_map->MigrateDomainScopedSettings(); |
+ |
+ // After migration, settings only affect origins. |
+ EXPECT_EQ( |
+ CONTENT_SETTING_ALLOW, |
+ host_content_settings_map->GetContentSetting( |
+ http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ host_content_settings_map->GetContentSetting( |
+ http_host_narrower, http_host_narrower, |
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &settings); |
+ // |host_content_settings_map| contains default setting and a custom setting. |
msramek
2016/06/30 16:16:21
In my understanding, "custom setting" is a setting
lshang
2016/07/04 02:46:00
Done.
Yeah you're right, 'custom setting' should r
|
+ EXPECT_EQ(2U, settings.size()); |
+ found_setting = false; |
+ for (const ContentSettingPatternSource& setting_entry : settings) { |
+ if (setting_entry.primary_pattern.ToString() == "http://example.com:80") { |
+ EXPECT_FALSE(found_setting); |
+ found_setting = true; |
+ } |
+ } |
+ EXPECT_TRUE(found_setting); |
+ |
+ EXPECT_EQ( |
+ CONTENT_SETTING_ALLOW, |
+ host_content_settings_map->GetContentSetting( |
+ https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ host_content_settings_map->GetContentSetting( |
+ https_host_narrower, https_host_narrower, |
+ CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
+ host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, |
+ std::string(), &settings); |
+ // |host_content_settings_map| contains default setting and a custom setting. |
+ EXPECT_EQ(2U, settings.size()); |
+ found_setting = false; |
+ for (const ContentSettingPatternSource& setting_entry : settings) { |
+ if (setting_entry.primary_pattern.ToString() == "https://example.com:443") { |
+ EXPECT_FALSE(found_setting); |
+ found_setting = true; |
+ } |
+ } |
+ EXPECT_TRUE(found_setting); |
+} |
+ |
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 |