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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/content_settings_pattern.h" 5 #include "chrome/common/content_settings_pattern.h"
6 6
7 #include "googleurl/src/gurl.h" 7 #include "googleurl/src/gurl.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 EXPECT_TRUE(Pattern("https://www.example.com:443").IsValid()); 165 EXPECT_TRUE(Pattern("https://www.example.com:443").IsValid());
166 EXPECT_STREQ("https://www.example.com:443", 166 EXPECT_STREQ("https://www.example.com:443",
167 Pattern("https://www.example.com:443").ToString().c_str()); 167 Pattern("https://www.example.com:443").ToString().c_str());
168 // HTTPS patterns with none default port. 168 // HTTPS patterns with none default port.
169 EXPECT_TRUE(Pattern("https://www.example.com:8080").IsValid()); 169 EXPECT_TRUE(Pattern("https://www.example.com:8080").IsValid());
170 EXPECT_STREQ("https://www.example.com:8080", 170 EXPECT_STREQ("https://www.example.com:8080",
171 Pattern("https://www.example.com:8080").ToString().c_str()); 171 Pattern("https://www.example.com:8080").ToString().c_str());
172 } 172 }
173 173
174 TEST(ContentSettingsPatternTest, FromString_FilePatterns) { 174 TEST(ContentSettingsPatternTest, FromString_FilePatterns) {
175 // "/" is an invalid file path.
175 EXPECT_FALSE(Pattern("file:///").IsValid()); 176 EXPECT_FALSE(Pattern("file:///").IsValid());
176 177
177 // Non-empty domains aren't allowed in file patterns. 178 // Non-empty domains aren't allowed in file patterns.
178 EXPECT_FALSE(Pattern("file://foo/").IsValid()); 179 EXPECT_FALSE(Pattern("file://foo/").IsValid());
179 180 EXPECT_FALSE(Pattern("file://localhost/foo/bar/test.html").IsValid());
180 // Domain wildcards aren't allowed in file patterns. 181 EXPECT_FALSE(Pattern("file://*").IsValid());
181 EXPECT_FALSE(Pattern("file://*/").IsValid()); 182 EXPECT_FALSE(Pattern("file://*/").IsValid());
183 EXPECT_FALSE(Pattern("file://*/*").IsValid());
184 EXPECT_FALSE(Pattern("file://*/foo/bar/test.html").IsValid());
markusheintz_ 2012/01/09 15:01:00 Maybe we could also add: EXPECT_FALSE(Pattern("fi
Francois 2012/01/09 15:33:01 Done, but added it a few lines further down.
182 EXPECT_FALSE(Pattern("file://[*.]/").IsValid()); 185 EXPECT_FALSE(Pattern("file://[*.]/").IsValid());
183 186
184 // These specify a path that contains '*', which isn't allowed to avoid 187 // This is the only valid file path wildcard format.
185 // user confusion. 188 EXPECT_TRUE(Pattern("file:///*").IsValid());
186 EXPECT_FALSE(Pattern("file:///*").IsValid()); 189 EXPECT_STREQ("file:///*", Pattern("file:///*").ToString().c_str());
Bernhard Bauer 2012/01/09 13:23:41 You can use EXPECT_EQ and remove the |.c_str()|.
Francois 2012/01/09 14:51:03 Done.
190
191 // Wildcards are not allowed anywhere in the file path.
192 EXPECT_FALSE(Pattern("file:///*/bar/file.html").IsValid());
193 EXPECT_FALSE(Pattern("file:///f*o/bar/file.html").IsValid());
194 EXPECT_FALSE(Pattern("file:///foo/*/file.html").IsValid());
195 EXPECT_FALSE(Pattern("file:///foo/bar/*.html").IsValid());
196 EXPECT_FALSE(Pattern("file:///foo/bar/file.*").IsValid());
187 EXPECT_FALSE(Pattern("file:///foo/bar/*").IsValid()); 197 EXPECT_FALSE(Pattern("file:///foo/bar/*").IsValid());
188 198
189 EXPECT_TRUE(Pattern("file:///tmp/test.html").IsValid()); 199 EXPECT_TRUE(Pattern("file:///tmp/test.html").IsValid());
190 EXPECT_STREQ("file:///tmp/file.html", 200 EXPECT_STREQ("file:///tmp/file.html",
191 Pattern("file:///tmp/file.html").ToString().c_str()); 201 Pattern("file:///tmp/file.html").ToString().c_str());
192 EXPECT_TRUE(Pattern("file:///tmp/test.html").Matches( 202 EXPECT_TRUE(Pattern("file:///tmp/test.html").Matches(
193 GURL("file:///tmp/test.html"))); 203 GURL("file:///tmp/test.html")));
194 EXPECT_FALSE(Pattern("file:///tmp/test.html").Matches( 204 EXPECT_FALSE(Pattern("file:///tmp/test.html").Matches(
195 GURL("file:///tmp/other.html"))); 205 GURL("file:///tmp/other.html")));
196 EXPECT_FALSE(Pattern("file:///tmp/test.html").Matches( 206 EXPECT_FALSE(Pattern("file:///tmp/test.html").Matches(
197 GURL("http://example.org/"))); 207 GURL("http://example.org/")));
208
209 EXPECT_TRUE(Pattern("file:///*").Matches(GURL("file:///tmp/test.html")));
210 EXPECT_TRUE(Pattern("file:///*").Matches(
211 GURL("file://localhost/tmp/test.html")));
198 } 212 }
199 213
200 TEST(ContentSettingsPatternTest, FromString_ExtensionPatterns) { 214 TEST(ContentSettingsPatternTest, FromString_ExtensionPatterns) {
201 EXPECT_TRUE(Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/") 215 EXPECT_TRUE(Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/")
202 .IsValid()); 216 .IsValid());
203 EXPECT_STREQ("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/", 217 EXPECT_STREQ("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/",
204 Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/") 218 Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/")
205 .ToString().c_str()); 219 .ToString().c_str());
206 EXPECT_TRUE(Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/") 220 EXPECT_TRUE(Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/")
207 .Matches(GURL("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/"))); 221 .Matches(GURL("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/")));
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 // file:/// normalization. 599 // file:/// normalization.
586 EXPECT_STREQ("file:///tmp/test.html", 600 EXPECT_STREQ("file:///tmp/test.html",
587 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); 601 Pattern("file:///tmp/bar/../test.html").ToString().c_str());
588 602
589 // Invalid patterns. 603 // Invalid patterns.
590 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); 604 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str());
591 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); 605 EXPECT_STREQ("", Pattern("example.*").ToString().c_str());
592 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); 606 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str());
593 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); 607 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str());
594 } 608 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698