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 9823dfe5a34976759f533704d9f5450fa0e2aff4..2d501d075c71a33d427a425ed1630e83f56ac862 100644 |
| --- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc |
| +++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc |
| @@ -1369,29 +1369,29 @@ TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) { |
| // Change default setting to BLOCK. |
| host_content_settings_map->SetDefaultContentSetting( |
| - CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
| + CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_BLOCK); |
| EXPECT_EQ( |
| CONTENT_SETTING_BLOCK, |
| host_content_settings_map->GetContentSetting( |
| - http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, 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, |
| + ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 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())); |
| + http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, 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())); |
| + CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| ContentSettingsForOneType settings; |
| - host_content_settings_map->GetSettingsForOneType( |
| - CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &settings); |
| + host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, |
| + std::string(), &settings); |
| // |host_content_settings_map| contains default setting and a domain scoped |
| // setting. |
| EXPECT_EQ(2U, settings.size()); |
| @@ -1404,28 +1404,28 @@ TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) { |
| // 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())); |
| + CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
| + EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| + host_content_settings_map->GetContentSetting( |
| + https_host, https_host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| + 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, |
| + ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 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())); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + https_host, https_host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| + 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())); |
| + CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
| - host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, |
| - std::string(), &settings); |
| + host_content_settings_map->GetSettingsForOneType( |
| + CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), &settings); |
| // |host_content_settings_map| contains default setting and a domain scoped |
| // setting. |
| EXPECT_EQ(2U, settings.size()); |
| @@ -1433,19 +1433,52 @@ TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) { |
| "https://[*.]example.com:443"); |
| EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); |
| + // Set domain scoped settings for cookies. |
| + 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())); |
| + 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())); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + http_host_narrower, http_host_narrower, |
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + 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 also apply to subdomains. |
|
msramek
2016/08/05 09:04:03
nit: This comment seems misplaced, since it also a
|
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + https_host_narrower, https_host_narrower, |
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + |
| host_content_settings_map->MigrateDomainScopedSettings(false); |
| // 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())); |
| + http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, 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); |
| + 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 origin scoped |
| // setting. |
| EXPECT_EQ(2U, settings.size()); |
| @@ -1453,22 +1486,40 @@ TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) { |
| "http://example.com:80"); |
| EXPECT_TRUE(settings[1].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_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + https_host, https_host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| + 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); |
| + CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
| + host_content_settings_map->GetSettingsForOneType( |
| + CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), &settings); |
| // |host_content_settings_map| contains default setting and a origin scoped |
| // setting. |
| EXPECT_EQ(2U, settings.size()); |
| EXPECT_TRUE(settings[0].primary_pattern.ToString() == |
| "https://example.com:443"); |
| EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); |
| + |
| + // Cookie settings didn't get migrated. |
| + EXPECT_EQ( |
| + CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + 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_COOKIES, |
| + std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + https_host_narrower, https_host_narrower, |
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| } |
| // Ensure that migration only happens once upon construction of the HCSM and |
| @@ -1484,7 +1535,7 @@ TEST_F(HostContentSettingsMapTest, DomainToOriginMigrationStatus) { |
| { |
| DictionaryPrefUpdate update(prefs, |
| - GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); |
| + GetPrefName(CONTENT_SETTINGS_TYPE_POPUPS)); |
| base::DictionaryValue* all_settings_dictionary = update.Get(); |
| ASSERT_TRUE(NULL != all_settings_dictionary); |
| @@ -1495,7 +1546,7 @@ TEST_F(HostContentSettingsMapTest, DomainToOriginMigrationStatus) { |
| } |
| const base::DictionaryValue* all_settings_dictionary = |
| - prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); |
| + prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_POPUPS)); |
| const base::DictionaryValue* result = NULL; |
| EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
| "[*.]example.com,*", &result)); |
| @@ -1506,33 +1557,33 @@ TEST_F(HostContentSettingsMapTest, DomainToOriginMigrationStatus) { |
| // Change default setting to BLOCK. |
| host_content_settings_map->SetDefaultContentSetting( |
| - CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
| + CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_BLOCK); |
| EXPECT_EQ( |
| CONTENT_SETTING_ALLOW, |
| host_content_settings_map->GetContentSetting( |
| - http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| // 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())); |
| + CONTENT_SETTINGS_TYPE_POPUPS, 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, |
| + 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_COOKIES, |
| - std::string())); |
| + EXPECT_EQ( |
| + CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, 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())); |
| + CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| // Try to do migration again before sync. |
| host_content_settings_map->MigrateDomainScopedSettings(false); |
| @@ -1541,7 +1592,7 @@ TEST_F(HostContentSettingsMapTest, DomainToOriginMigrationStatus) { |
| EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| host_content_settings_map->GetContentSetting( |
| https_host_narrower, https_host_narrower, |
| - CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| // Do migration after sync. |
| host_content_settings_map->MigrateDomainScopedSettings(true); |
| @@ -1550,24 +1601,24 @@ TEST_F(HostContentSettingsMapTest, DomainToOriginMigrationStatus) { |
| EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| host_content_settings_map->GetContentSetting( |
| https_host_narrower, https_host_narrower, |
| - CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + CONTENT_SETTINGS_TYPE_POPUPS, 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, |
| + ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 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())); |
| + EXPECT_EQ( |
| + CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + http1_host, http1_host, CONTENT_SETTINGS_TYPE_POPUPS, 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())); |
| + CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| // Try to do migration again after sync. |
| host_content_settings_map->MigrateDomainScopedSettings(true); |
| @@ -1576,7 +1627,7 @@ TEST_F(HostContentSettingsMapTest, DomainToOriginMigrationStatus) { |
| EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| host_content_settings_map->GetContentSetting( |
| http1_host_narrower, http1_host_narrower, |
| - CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| } |
| TEST_F(HostContentSettingsMapTest, InvalidPattern) { |