Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: components/content_settings/core/common/content_settings_pattern_unittest.cc

Issue 1895993003: Add migration code to change existing domain scoped content settings to be origin scoped (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/content_settings/core/common/content_settings_pattern.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
+}
« no previous file with comments | « components/content_settings/core/common/content_settings_pattern.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698