Chromium Code Reviews| 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..c29d2f9e81a4ce381e0dd78a547130f45f797993 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,127 @@ 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_settings| contains default setting and a custom setting. |
|
raymes
2016/06/27 07:23:29
host_content_settings_map? (here and below)
lshang
2016/06/28 07:14:41
Done.
|
| + EXPECT_EQ(2U, settings.size()); |
| + for (const ContentSettingPatternSource& setting_entry : settings) { |
| + if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard()) |
| + continue; |
| + EXPECT_EQ("[*.]example.com", setting_entry.primary_pattern.ToString()); |
|
raymes
2016/06/27 07:23:29
This won't exactly check that things are what we e
lshang
2016/06/28 07:14:41
There should be a default setting (*, *) and a cus
raymes
2016/06/30 01:11:27
Note: as discussed we should still change this :)
lshang
2016/06/30 05:10:35
Done.
|
| + } |
| + |
| + // 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_settings| contains default setting and a custom setting. |
| + EXPECT_EQ(2U, settings.size()); |
| + for (const ContentSettingPatternSource& setting_entry : settings) { |
| + if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard()) |
| + continue; |
| + EXPECT_EQ("https://[*.]example.com:443", |
| + setting_entry.primary_pattern.ToString()); |
| + } |
| + |
| + 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_settings| contains default setting and a custom setting. |
| + EXPECT_EQ(2U, settings.size()); |
| + for (const ContentSettingPatternSource& setting_entry : settings) { |
| + if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard()) |
| + continue; |
| + EXPECT_EQ("http://example.com:80", |
| + setting_entry.primary_pattern.ToString()); |
| + } |
| + |
| + 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_settings| contains default setting and a custom setting. |
| + EXPECT_EQ(2U, settings.size()); |
| + for (const ContentSettingPatternSource& setting_entry : settings) { |
| + if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard()) |
| + continue; |
| + EXPECT_EQ("https://example.com:443", |
| + setting_entry.primary_pattern.ToString()); |
| + } |
| +} |
| + |
| 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 |