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

Unified Diff: chrome/common/content_settings_pattern_unittest.cc

Issue 9133002: Added support for file URI path wildcards in content settings (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 8 years, 11 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 | « chrome/common/content_settings_pattern_parser_unittest.cc ('k') | chrome/common/render_messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/content_settings_pattern_unittest.cc
===================================================================
--- chrome/common/content_settings_pattern_unittest.cc (revision 118265)
+++ chrome/common/content_settings_pattern_unittest.cc (working copy)
@@ -52,6 +52,9 @@
// - A domain wildcard is added to the GURL host.
// - A port wildcard is used instead of the schemes default port.
// In case of non-default ports the specific GURL port is used.
+ // - In the case of a file URI the path is set to the GURL path, unless the
+ // GURL is "file:///", in which case the GURL path ("/", in this case) is
+ // ignored and the wildcard flag set.
ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(
GURL("http://www.youtube.com"));
EXPECT_TRUE(pattern.IsValid());
@@ -84,9 +87,17 @@
pattern = ContentSettingsPattern::FromURL(GURL("http://[::1]"));
EXPECT_TRUE(pattern.IsValid());
+ GURL url("file:///foo/bar.html");
pattern = ContentSettingsPattern::FromURL(GURL("file:///foo/bar.html"));
EXPECT_TRUE(pattern.IsValid());
- EXPECT_STREQ("file:///foo/bar.html", pattern.ToString().c_str());
+ EXPECT_EQ("file:///foo/bar.html", pattern.ToString());
+
+ pattern = ContentSettingsPattern::FromURL(GURL("file:///"));
+ EXPECT_TRUE(pattern.IsValid());
+ EXPECT_TRUE(pattern.Matches(GURL("file:///")));
+ EXPECT_TRUE(pattern.Matches(GURL("file:///foo")));
+ EXPECT_TRUE(pattern.Matches(GURL("file:///foo/bar.html")));
+ EXPECT_EQ("file:///*", pattern.ToString());
}
TEST(ContentSettingsPatternTest, FromURLNoWildcard) {
@@ -172,37 +183,51 @@
}
TEST(ContentSettingsPatternTest, FromString_FilePatterns) {
+ // The only valid wildcard pattern is "file:///*". (Note, however, that
+ // "file:///" equates to the wildcard when constructing from a URL.)
+ EXPECT_TRUE(Pattern("file:///*").IsValid());
+ EXPECT_EQ("file:///*", Pattern("file:///*").ToString());
EXPECT_FALSE(Pattern("file:///").IsValid());
-
+
// Non-empty domains aren't allowed in file patterns.
EXPECT_FALSE(Pattern("file://foo/").IsValid());
-
- // Domain wildcards aren't allowed in file patterns.
+ EXPECT_FALSE(Pattern("file://localhost/foo/bar/test.html").IsValid());
+ EXPECT_FALSE(Pattern("file://*").IsValid());
EXPECT_FALSE(Pattern("file://*/").IsValid());
+ EXPECT_FALSE(Pattern("file://*/*").IsValid());
+ EXPECT_FALSE(Pattern("file://*/foo/bar/test.html").IsValid());
EXPECT_FALSE(Pattern("file://[*.]/").IsValid());
- // These specify a path that contains '*', which isn't allowed to avoid
- // user confusion.
- EXPECT_FALSE(Pattern("file:///*").IsValid());
+ // Wildcards are not allowed anywhere in the file path.
+ EXPECT_FALSE(Pattern("file:///f*o/bar/file.html").IsValid());
+ EXPECT_FALSE(Pattern("file:///*/bar/file.html").IsValid());
+ EXPECT_FALSE(Pattern("file:///foo/*").IsValid());
EXPECT_FALSE(Pattern("file:///foo/bar/*").IsValid());
+ EXPECT_FALSE(Pattern("file:///foo/*/file.html").IsValid());
+ EXPECT_FALSE(Pattern("file:///foo/bar/*.html").IsValid());
+ EXPECT_FALSE(Pattern("file:///foo/bar/file.*").IsValid());
EXPECT_TRUE(Pattern("file:///tmp/test.html").IsValid());
- EXPECT_STREQ("file:///tmp/file.html",
- Pattern("file:///tmp/file.html").ToString().c_str());
+ EXPECT_EQ("file:///tmp/file.html",
+ Pattern("file:///tmp/file.html").ToString());
EXPECT_TRUE(Pattern("file:///tmp/test.html").Matches(
GURL("file:///tmp/test.html")));
EXPECT_FALSE(Pattern("file:///tmp/test.html").Matches(
GURL("file:///tmp/other.html")));
EXPECT_FALSE(Pattern("file:///tmp/test.html").Matches(
GURL("http://example.org/")));
+
+ EXPECT_TRUE(Pattern("file:///*").Matches(GURL("file:///tmp/test.html")));
+ EXPECT_TRUE(Pattern("file:///*").Matches(
+ GURL("file://localhost/tmp/test.html")));
}
TEST(ContentSettingsPatternTest, FromString_ExtensionPatterns) {
EXPECT_TRUE(Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/")
.IsValid());
- EXPECT_STREQ("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/",
+ EXPECT_EQ("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/",
Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/")
- .ToString().c_str());
+ .ToString());
EXPECT_TRUE(Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/")
.Matches(GURL("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/")));
}
« no previous file with comments | « chrome/common/content_settings_pattern_parser_unittest.cc ('k') | chrome/common/render_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698