| 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..616f2527c5e95430c478e4dd2e7f02f57ffd97ca 100644
|
| --- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc
|
| +++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
|
| @@ -301,12 +301,16 @@ TEST_F(HostContentSettingsMapTest, Patterns) {
|
| GURL host1("http://example.com/");
|
| GURL host2("http://www.example.com/");
|
| GURL host3("http://example.org/");
|
| + ContentSettingsPattern pattern1 =
|
| + ContentSettingsPattern::FromString("[*.]example.com");
|
| + ContentSettingsPattern pattern2 =
|
| + ContentSettingsPattern::FromString("example.org");
|
| EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| host_content_settings_map->GetContentSetting(
|
| host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
|
| - host_content_settings_map->SetContentSettingDefaultScope(
|
| - host1, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
|
| - CONTENT_SETTING_BLOCK);
|
| + host_content_settings_map->SetContentSettingCustomScope(
|
| + pattern1, ContentSettingsPattern::Wildcard(),
|
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK);
|
| EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| host_content_settings_map->GetContentSetting(
|
| host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
|
| @@ -316,9 +320,9 @@ TEST_F(HostContentSettingsMapTest, Patterns) {
|
| EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| host_content_settings_map->GetContentSetting(
|
| host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
|
| - host_content_settings_map->SetContentSettingDefaultScope(
|
| - host3, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
|
| - CONTENT_SETTING_BLOCK);
|
| + host_content_settings_map->SetContentSettingCustomScope(
|
| + pattern2, ContentSettingsPattern::Wildcard(),
|
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK);
|
| EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| host_content_settings_map->GetContentSetting(
|
| host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
|
| @@ -332,7 +336,7 @@ TEST_F(HostContentSettingsMapTest, Observer) {
|
|
|
| GURL host("http://example.com/");
|
| ContentSettingsPattern primary_pattern =
|
| - ContentSettingsPattern::FromString("[*.]example.com");
|
| + ContentSettingsPattern::FromString("http://example.com:80");
|
| ContentSettingsPattern secondary_pattern =
|
| ContentSettingsPattern::Wildcard();
|
| EXPECT_CALL(observer, OnContentSettingsChanged(host_content_settings_map,
|
| @@ -577,19 +581,24 @@ TEST_F(HostContentSettingsMapTest, NestedSettings) {
|
| HostContentSettingsMapFactory::GetForProfile(&profile);
|
|
|
| GURL host("http://a.b.example.com/");
|
| - GURL host1("http://example.com/");
|
| - GURL host2("http://b.example.com/");
|
| + ContentSettingsPattern pattern1 =
|
| + ContentSettingsPattern::FromString("[*.]example.com");
|
| + ContentSettingsPattern pattern2 =
|
| + ContentSettingsPattern::FromString("[*.]b.example.com");
|
| + ContentSettingsPattern pattern3 =
|
| + ContentSettingsPattern::FromString("a.b.example.com");
|
|
|
| - host_content_settings_map->SetContentSettingDefaultScope(
|
| - host1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(),
|
| - CONTENT_SETTING_BLOCK);
|
| + host_content_settings_map->SetContentSettingCustomScope(
|
| + pattern1, ContentSettingsPattern::Wildcard(),
|
| + CONTENT_SETTINGS_TYPE_POPUPS, std::string(), CONTENT_SETTING_BLOCK);
|
|
|
| - host_content_settings_map->SetContentSettingDefaultScope(
|
| - host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
|
| - CONTENT_SETTING_BLOCK);
|
| + host_content_settings_map->SetContentSettingCustomScope(
|
| + pattern2, ContentSettingsPattern::Wildcard(),
|
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK);
|
|
|
| - host_content_settings_map->SetContentSettingDefaultScope(
|
| - host, GURL(), CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(),
|
| + host_content_settings_map->SetContentSettingCustomScope(
|
| + pattern3, ContentSettingsPattern::Wildcard(),
|
| + CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(),
|
| CONTENT_SETTING_BLOCK);
|
| host_content_settings_map->SetDefaultContentSetting(
|
| CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
|
| @@ -876,7 +885,7 @@ TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) {
|
|
|
| base::DictionaryValue* dummy_payload = new base::DictionaryValue;
|
| dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW);
|
| - all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*",
|
| + all_settings_dictionary->SetWithoutPathExpansion("www.\xC4\x87ira.com,*",
|
| dummy_payload);
|
| }
|
|
|
| @@ -886,9 +895,9 @@ TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) {
|
| prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES));
|
| const base::DictionaryValue* result = NULL;
|
| EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
|
| - "[*.]\xC4\x87ira.com,*", &result));
|
| + "www.\xC4\x87ira.com,*", &result));
|
| EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
|
| - "[*.]xn--ira-ppa.com,*", &result));
|
| + "www.xn--ira-ppa.com,*", &result));
|
| }
|
|
|
| // If both Unicode and its punycode pattern exist, make sure we don't touch the
|
| @@ -1141,7 +1150,7 @@ TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) {
|
|
|
| GURL host("http://example.com/");
|
| ContentSettingsPattern pattern =
|
| - ContentSettingsPattern::FromString("[*.]example.com");
|
| + ContentSettingsPattern::FromString("http://example.com:80");
|
| EXPECT_CALL(mock_observer, OnContentSettingChanged(
|
| pattern, ContentSettingsPattern::Wildcard(),
|
| CONTENT_SETTINGS_TYPE_COOKIES, ""));
|
| @@ -1278,6 +1287,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.
|
| + 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.
|
| + 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
|
|
|