Index: components/content_settings/core/common/content_settings_pattern_unittest.cc |
diff --git a/components/content_settings/core/common/content_settings_pattern_unittest.cc b/components/content_settings/core/common/content_settings_pattern_unittest.cc |
index 74e601979446d3c2ef185b6f358f03d05b2ed5f6..38125c49fc47152adee3113823403b4d37b53c5f 100644 |
--- a/components/content_settings/core/common/content_settings_pattern_unittest.cc |
+++ b/components/content_settings/core/common/content_settings_pattern_unittest.cc |
@@ -720,3 +720,92 @@ TEST(ContentSettingsPatternTest, CanonicalizePattern_Legacy) { |
EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); |
EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); |
} |
+ |
+TEST(ContentSettingsPatternTest, MigrateFromDomainToOrigin) { |
+ ContentSettingsPattern origin_pattern; |
+ // Http scheme patterns. |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("http://[*.]example.com"), |
+ &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("http://[*.]example.com:80"), |
+ &origin_pattern)); |
+ |
+ // Https patterns with port wildcard. |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("https://www.google.com"), |
+ &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("https://[*.]google.com"), |
+ &origin_pattern)); |
+ |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("www.google.com"), &origin_pattern)); |
+ |
+ // Patterns with no domain wildcard. |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("*://www.google.com:8080"), |
+ &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("www.example.com:8080"), |
+ &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("www.google.com/*"), &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("google"), &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("https://www.google.com:443"), |
+ &origin_pattern)); |
+ |
+ // Patterns with empty host. |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("*"), &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("[*.]"), &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("http://*"), &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("http://*:8080"), &origin_pattern)); |
+ |
+ // Other schemes and IP address patterns won't be migrated. |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("192.168.0.1"), &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("https://127.0.0.1"), |
+ &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("http://[::1]"), &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("[::1]"), &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("file:///foo/bar.html"), |
+ &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString( |
+ "filesystem:http://www.google.com/temporary/"), |
+ &origin_pattern)); |
+ EXPECT_FALSE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString( |
+ "chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/"), |
+ &origin_pattern)); |
+ |
+ // These are pattern styles which might be generated using FromURL(). |
+ EXPECT_TRUE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("[*.]example.com"), &origin_pattern)); |
+ EXPECT_EQ("http://example.com:80", origin_pattern.ToString()); |
+ |
+ EXPECT_TRUE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("[*.]google.com:80"), |
+ &origin_pattern)); |
+ EXPECT_EQ("http://google.com:80", origin_pattern.ToString()); |
+ |
+ EXPECT_TRUE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("[*.]example.com:123"), |
+ &origin_pattern)); |
+ EXPECT_EQ("http://example.com:123", origin_pattern.ToString()); |
+ |
+ EXPECT_TRUE(ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ ContentSettingsPattern::FromString("https://[*.]google.com:443"), |
+ &origin_pattern)); |
+ EXPECT_EQ("https://google.com:443", origin_pattern.ToString()); |
+} |