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..3934d3be55deb0ce09fd8aa14b0c98f01d6457e0 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,85 @@ 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 BLCOK. |
raymes
2016/06/20 04:03:26
nit: BLOCK
lshang
2016/06/23 01:32:31
Done.
|
+ 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 images 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())); |
+ |
+ // Set old formatted https settings. |
+ GURL https_host("https://example.com/"); |
+ GURL https_host_narrower("https://a.example.com/"); |
+ |
+ // Change default setting to BLCOK. |
raymes
2016/06/20 04:03:25
nit: BLOCK
lshang
2016/06/23 01:32:31
Done.
|
+ 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 cookies 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->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())); |
+ |
+ 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())); |
+} |
+ |
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 |