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

Unified Diff: chrome/browser/privacy_blacklist/blacklist_unittest.cc

Issue 149737: Blacklist API change for allowing multiple rule matches... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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
Index: chrome/browser/privacy_blacklist/blacklist_unittest.cc
===================================================================
--- chrome/browser/privacy_blacklist/blacklist_unittest.cc (revision 20880)
+++ chrome/browser/privacy_blacklist/blacklist_unittest.cc (working copy)
@@ -60,10 +60,56 @@
EXPECT_EQ("Sample", blacklist.providers_.front()->name());
EXPECT_EQ("http://www.google.com", blacklist.providers_.front()->url());
- // Empty blacklist should not match any URL.
+ // No match for chrome, about or empty URLs.
EXPECT_FALSE(blacklist.findMatch(GURL()));
- EXPECT_FALSE(blacklist.findMatch(GURL("http://www.google.com")));
+ EXPECT_FALSE(blacklist.findMatch(GURL("chrome://new-tab")));
+ EXPECT_FALSE(blacklist.findMatch(GURL("about:blank")));
+ // Expected rule matches.
+ Blacklist::Match* match;
+ match = blacklist.findMatch(GURL("http://www.google.com"));
+ EXPECT_TRUE(match);
+ if (match) {
+ EXPECT_EQ(Blacklist::kBlockByType|Blacklist::kDontPersistCookies,
+ match->attributes());
+ EXPECT_EQ(1U, match->entries().size());
+ }
+
+ match = blacklist.findMatch(GURL("http://www.site.com/bad/url"));
+ EXPECT_TRUE(match);
+ if (match) {
+ EXPECT_EQ(Blacklist::kBlockAll|
+ Blacklist::kBlockByType|Blacklist::kDontPersistCookies,
+ match->attributes());
+ EXPECT_EQ(2U, match->entries().size());
+ }
+
+ match = blacklist.findMatch(GURL("http://www.site.com/anonymous"));
+ EXPECT_TRUE(match);
+ if (match) {
+ EXPECT_EQ(Blacklist::kBlockByType|Blacklist::kDontPersistCookies,
+ match->attributes());
+ EXPECT_EQ(1U, match->entries().size());
+ }
+
+ match = blacklist.findMatch(GURL("http://www.site.com/anonymous/folder"));
+ EXPECT_TRUE(match);
+ if (match) {
+ EXPECT_EQ(Blacklist::kBlockByType|Blacklist::kDontPersistCookies,
+ match->attributes());
+ EXPECT_EQ(1U, match->entries().size());
+ }
+
+ match = blacklist.findMatch(
+ GURL("http://www.site.com/anonymous/folder/subfolder"));
+ EXPECT_TRUE(match);
+ if (match) {
+ EXPECT_EQ(Blacklist::kDontSendUserAgent|Blacklist::kDontSendReferrer|
+ Blacklist::kBlockByType|Blacklist::kDontPersistCookies,
+ match->attributes());
+ EXPECT_EQ(2U, match->entries().size());
+ }
+
// StripCookieExpiry Tests
std::string cookie1(
"PREF=ID=14a549990453e42a:TM=1245183232:LM=1245183232:S=Occ7khRVIEE36Ao5;"
@@ -74,17 +120,25 @@
std::string cookie3(
"PREF=ID=14a549990453e42a:TM=1245183232:LM=1245183232:S=Occ7khRVIEE36Ao5;"
" expires=Thu, 17-Jun-2011 02:13:52 GMT; path=/; domain=.google.com");
+ std::string cookie4("E=MC^2; path=relative; expires=never;");
+ std::string cookie5("E=MC^2; path=relative;");
// No expiry, should be equal to itself after stripping.
- EXPECT_TRUE(cookie2 == Blacklist::StripCookieExpiry(cookie2));
+ EXPECT_EQ(cookie2, Blacklist::StripCookieExpiry(cookie2));
+ EXPECT_EQ(cookie5, Blacklist::StripCookieExpiry(cookie5));
// Expiry, should be equal to non-expiry version after stripping.
- EXPECT_TRUE(cookie2 == Blacklist::StripCookieExpiry(cookie1));
+ EXPECT_EQ(cookie2, Blacklist::StripCookieExpiry(cookie1));
+ EXPECT_EQ(cookie5, Blacklist::StripCookieExpiry(cookie4));
+ // Same cookie other than expiry should be same after stripping.
+ EXPECT_EQ(Blacklist::StripCookieExpiry(cookie2),
+ Blacklist::StripCookieExpiry(cookie3));
+
// Edge cases.
- EXPECT_TRUE(std::string() == Blacklist::StripCookieExpiry(std::string()));
- EXPECT_TRUE(Blacklist::StripCookieExpiry(cookie2) ==
- Blacklist::StripCookieExpiry(cookie3));
+ std::string invalid("#$%^&*()_+");
+ EXPECT_EQ(invalid, Blacklist::StripCookieExpiry(invalid));
+ EXPECT_EQ(std::string(), Blacklist::StripCookieExpiry(std::string()));
// StripCookies Test. Note that "\r\n" line terminators are used
// because the underlying net util uniformizes those when stripping
@@ -105,3 +159,52 @@
EXPECT_TRUE(header2 == Blacklist::StripCookies(header2));
EXPECT_TRUE(header4 == Blacklist::StripCookies(header3));
}
+
+TEST(BlacklistTest, PatternMatch) {
+ // @ matches all but empty strings.
+ EXPECT_TRUE(Blacklist::Matches("@", "foo.com"));
+ EXPECT_TRUE(Blacklist::Matches("@", "path"));
+ EXPECT_TRUE(Blacklist::Matches("@", "foo.com/path"));
+ EXPECT_TRUE(Blacklist::Matches("@", "x"));
+ EXPECT_FALSE(Blacklist::Matches("@", ""));
+ EXPECT_FALSE(Blacklist::Matches("@", std::string()));
+
+ // Prefix match.
+ EXPECT_TRUE(Blacklist::Matches("prefix@", "prefix.com"));
+ EXPECT_TRUE(Blacklist::Matches("prefix@", "prefix.com/path"));
+ EXPECT_TRUE(Blacklist::Matches("prefix@", "prefix/path"));
+ EXPECT_TRUE(Blacklist::Matches("prefix@", "prefix/prefix"));
+ EXPECT_FALSE(Blacklist::Matches("prefix@", "prefix"));
+ EXPECT_FALSE(Blacklist::Matches("prefix@", "Xprefix"));
+ EXPECT_FALSE(Blacklist::Matches("prefix@", "Y.Xprefix"));
+ EXPECT_FALSE(Blacklist::Matches("prefix@", "Y/Xprefix"));
+
+ // Postfix match.
+ EXPECT_TRUE(Blacklist::Matches("@postfix", "something.postfix"));
+ EXPECT_TRUE(Blacklist::Matches("@postfix", "something/postfix"));
+ EXPECT_TRUE(Blacklist::Matches("@postfix", "foo.com/something/postfix"));
+ EXPECT_FALSE(Blacklist::Matches("@postfix", "postfix"));
+ EXPECT_FALSE(Blacklist::Matches("@postfix", "postfixZ"));
+ EXPECT_FALSE(Blacklist::Matches("@postfix", "postfixZ.Y"));
+
+ // Infix matches.
+ EXPECT_TRUE(Blacklist::Matches("@evil@", "www.evil.com"));
+ EXPECT_TRUE(Blacklist::Matches("@evil@", "www.evil.com/whatever"));
+ EXPECT_TRUE(Blacklist::Matches("@evil@", "www.whatever.com/evilpath"));
+ EXPECT_TRUE(Blacklist::Matches("@evil@", "www.evil.whatever.com"));
+ EXPECT_FALSE(Blacklist::Matches("@evil@", "evil"));
+ EXPECT_FALSE(Blacklist::Matches("@evil@", "evil/"));
+ EXPECT_FALSE(Blacklist::Matches("@evil@", "/evil"));
+
+ // Outfix matches.
+ EXPECT_TRUE(Blacklist::Matches("really@bad", "really/bad"));
+ EXPECT_TRUE(Blacklist::Matches("really@bad", "really.com/bad"));
+ EXPECT_TRUE(Blacklist::Matches("really@bad", "really.com/path/bad"));
+ EXPECT_TRUE(Blacklist::Matches("really@bad", "really.evil.com/path/bad"));
+ EXPECT_FALSE(Blacklist::Matches("really@bad", "really.bad.com"));
+ EXPECT_FALSE(Blacklist::Matches("really@bad", "reallybad"));
+ EXPECT_FALSE(Blacklist::Matches("really@bad", ".reallybad"));
+ EXPECT_FALSE(Blacklist::Matches("really@bad", "reallybad."));
+ EXPECT_FALSE(Blacklist::Matches("really@bad", "really.bad."));
+ EXPECT_FALSE(Blacklist::Matches("really@bad", ".really.bad"));
+}
« no previous file with comments | « chrome/browser/privacy_blacklist/blacklist.cc ('k') | chrome/browser/renderer_host/resource_dispatcher_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698