diff options
author | markusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-23 17:52:08 +0000 |
---|---|---|
committer | markusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-23 17:52:08 +0000 |
commit | ae689aab246d7763cb04ecba1bd382749c599ee7 (patch) | |
tree | 28c10be46648b3327e04b9a3ef78d312851013cd /chrome/common/content_settings_pattern_unittest.cc | |
parent | aff8b47835f1f9faa471fd23b8db782cdb492ddd (diff) | |
download | chromium_src-ae689aab246d7763cb04ecba1bd382749c599ee7.zip chromium_src-ae689aab246d7763cb04ecba1bd382749c599ee7.tar.gz chromium_src-ae689aab246d7763cb04ecba1bd382749c599ee7.tar.bz2 |
Added support for file URI path wildcards in content settings
patterns. I.e. "file:///*" matches all file URIs.
Full/explicit/absolute paths (e.g. "file:///foo/bar.html") are still supported.
contributed by Francois Kritzinger (francoisk777@gmail.com)
BUG=77149
TEST=ContentSettingsPattern*
Review URL: http://codereview.chromium.org/9254028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/content_settings_pattern_unittest.cc')
-rw-r--r-- | chrome/common/content_settings_pattern_unittest.cc | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/chrome/common/content_settings_pattern_unittest.cc b/chrome/common/content_settings_pattern_unittest.cc index 254df17..f0eeca5 100644 --- a/chrome/common/content_settings_pattern_unittest.cc +++ b/chrome/common/content_settings_pattern_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -86,7 +86,7 @@ TEST(ContentSettingsPatternTest, FromURL) { 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()); } TEST(ContentSettingsPatternTest, FromURLNoWildcard) { @@ -172,37 +172,52 @@ TEST(ContentSettingsPatternTest, FromString_WithNoWildcards) { } TEST(ContentSettingsPatternTest, FromString_FilePatterns) { + // "/" is an invalid file path. 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()); + // This is the only valid file path wildcard format. + EXPECT_TRUE(Pattern("file:///*").IsValid()); + EXPECT_EQ("file:///*", Pattern("file:///*").ToString()); + + // 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/"))); } |