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

Unified Diff: chrome/browser/browsing_data/origin_filter_builder_unittest.cc

Issue 1741123002: Add removal filter support for Cookies, Storage, and Content Settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added SafeBrowsing cookie support Created 4 years, 9 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/browsing_data/origin_filter_builder_unittest.cc
diff --git a/chrome/browser/browsing_data/origin_filter_builder_unittest.cc b/chrome/browser/browsing_data/origin_filter_builder_unittest.cc
index 32fef25dadf3028c49a8e48852343732e3b5e3fd..e0430bb23a422b9796a26bd29fe6eee496d46085 100644
--- a/chrome/browser/browsing_data/origin_filter_builder_unittest.cc
+++ b/chrome/browser/browsing_data/origin_filter_builder_unittest.cc
@@ -9,6 +9,7 @@
#include <vector>
#include "base/callback.h"
+#include "components/content_settings/core/common/content_settings_pattern.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"
@@ -17,6 +18,12 @@ namespace url {
namespace {
+struct CookieTestCase {
+ std::string url;
+ std::string cookie_domain;
+ bool should_match;
+};
+
struct TestCase {
std::string url;
bool should_match;
@@ -24,12 +31,47 @@ struct TestCase {
void RunTestCase(
TestCase test_case, const base::Callback<bool(const GURL&)>& filter) {
+ GURL url(test_case.url);
+ EXPECT_TRUE(url.is_valid()) << test_case.url << " is not valid.";
if (test_case.should_match)
EXPECT_TRUE(filter.Run(GURL(test_case.url)));
else
EXPECT_FALSE(filter.Run(GURL(test_case.url)));
}
+void RunTestCase(
+ TestCase test_case,
+ const base::Callback<bool(const ContentSettingsPattern&)>& filter) {
+ ContentSettingsPattern pattern =
+ ContentSettingsPattern::FromString(test_case.url);
+ EXPECT_TRUE(pattern.IsValid()) << test_case.url << " is not valid.";
+ if (test_case.should_match)
+ EXPECT_TRUE(filter.Run(pattern)) << pattern.ToString() << " should match.";
+ else
+ EXPECT_FALSE(filter.Run(pattern)) << pattern.ToString()
+ << " should not match.";
+}
+
+void RunTestCase(
+ CookieTestCase test_case,
+ const base::Callback<bool(const net::CanonicalCookie&)>& filter) {
+ std::string cookie_line =
+ std::string("A=2; Domain=") + test_case.cookie_domain;
+ scoped_ptr<net::CanonicalCookie> cookie =
+ net::CanonicalCookie::Create(GURL(test_case.url), cookie_line,
+ base::Time::Now(), net::CookieOptions());
+ EXPECT_TRUE(cookie) << cookie_line << " from " << test_case.url
+ << " is not a valid cookie";
+ if (cookie) {
+ if (test_case.should_match)
+ EXPECT_TRUE(filter.Run(*cookie)) << cookie->DebugString()
+ << " should match.";
+ else
+ EXPECT_FALSE(filter.Run(*cookie)) << cookie->DebugString()
+ << " should not match.";
+ }
+}
+
} // namespace
TEST(OriginFilterBuilderTest, Noop) {
@@ -77,6 +119,54 @@ TEST(OriginFilterBuilderTest, Whitelist) {
RunTestCase(test_case, filter);
}
+TEST(OriginFilterBuilderTest, WhitelistContentSettings) {
+ OriginFilterBuilder builder(OriginFilterBuilder::WHITELIST);
+ builder.AddOrigin(Origin(GURL("https://www.google.com")));
+ builder.AddOrigin(Origin(GURL("http://www.example.com")));
+ base::Callback<bool(const ContentSettingsPattern&)> filter =
+ builder.BuildSameOriginContentSettingsFilter();
+
+ TestCase test_cases[] = {
+ // Whitelist matches any patterns that include the whitelist origins.
+ {"https://www.google.com", true},
+ {"https://[*.]google.com", true},
+ {"https://[*.]google.com:443", true},
+ {"[*.]google.com", true},
+ {"[*.]google.com/foo/bar", true},
+ {"www.google.com/?q=test", true},
+ {"http://www.example.com", true},
+ {"[*.]example.com:80", true},
+ {"http://www.example.com/index.html", true},
+ {"http://www.example.com/foo/bar", true},
+ {"*", true},
+ {"*:80", true},
+ {"*:443", true},
+
+ // Subdomains are different origins.
+ {"https://test.www.google.com", false},
+ {"https://google.com", false},
+
+ // Different TLDs are different origins.
+ {"[*.]google", false},
+ {"[*.]google.net", false},
+ {"https://[*.]google.org", false},
+
+ // Different scheme or port is a different origin.
+ {"http://www.google.com", false},
+ {"http://[*.].google.com", false},
+ {"*:8000", false},
+ {"https://www.example.com/index.html", false},
+
+ // Different host is a different origin.
+ {"https://www.youtube.com", false},
+ {"https://www.chromium.org", false},
+ {"[*.]youtube", false},
+ };
+
+ for (TestCase test_case : test_cases)
+ RunTestCase(test_case, filter);
+}
+
TEST(OriginFilterBuilderTest, Blacklist) {
OriginFilterBuilder builder(OriginFilterBuilder::BLACKLIST);
builder.AddOrigin(Origin(GURL("https://www.google.com")));
@@ -108,6 +198,112 @@ TEST(OriginFilterBuilderTest, Blacklist) {
RunTestCase(test_case, filter);
}
+TEST(OriginFilterBuilderTest, BlacklistContentSettings) {
+ OriginFilterBuilder builder(OriginFilterBuilder::BLACKLIST);
+ builder.AddOrigin(Origin(GURL("https://www.google.com")));
+ builder.AddOrigin(Origin(GURL("http://www.example.com")));
+ base::Callback<bool(const ContentSettingsPattern&)> filter =
+ builder.BuildSameOriginContentSettingsFilter();
+
+ TestCase test_cases[] = {
+ // Blacklist matches any patterns that don't include the origins.
+ {"https://www.google.com", false},
+ {"https://[*.]google.com", false},
+ {"https://[*.]google.com:443", false},
+ {"[*.]google.com", false},
+ {"[*.]google.com/foo/bar", false},
+ {"www.google.com/?q=test", false},
+ {"http://www.example.com", false},
+ {"[*.]example.com:80", false},
+ {"http://www.example.com/index.html", false},
+ {"http://www.example.com/foo/bar", false},
+ {"*", false},
+ {"*:80", false},
+ {"*:443", false},
+
+ // Subdomains are different origins.
+ {"https://test.www.google.com", true},
+ {"https://google.com", true},
+
+ // Different TLDs are different origins.
+ {"[*.]google", true},
+ {"[*.]google.net", true},
+ {"https://[*.]google.org", true},
+
+ // Different scheme or port is a different origin.
+ {"http://www.google.com", true},
+ {"http://[*.].google.com", true},
+ {"*:8000", true},
+ {"https://www.example.com/index.html", true},
+
+ // Different host is a different origin.
+ {"https://www.youtube.com", true},
+ {"https://www.chromium.org", true},
+ {"[*.]youtube", true},
+ };
+
+ for (TestCase test_case : test_cases)
+ RunTestCase(test_case, filter);
+}
+
+TEST(OriginFilterBuilderTest, MatchesCookiesWhitelist) {
+ OriginFilterBuilder builder(OriginFilterBuilder::WHITELIST);
+ builder.AddOrigin(Origin(GURL("https://www.google.com")));
+ base::Callback<bool(const net::CanonicalCookie&)> filter =
+ builder.BuildDomainCookieFilter();
+
+ CookieTestCase test_cases[] = {
+ // Any URL on the specified origin is matched.
+ {"https://www.google.com", ".google.com", true},
+ {"https://mail.google.com", ".google.com", true},
+ {"http://google.com", ".google.com", true},
+ {"https://www.google.com", "www.google.com", true},
+ {"http://www.google.com", "www.google.com", true},
+
+ // Different tlds, and subdomains.
+ {"https://www.google.org", ".google.org", false},
+ {"https://www.google.org", ".google.org", false},
+ {"http://mail.google.com", "mail.google.com", false},
+ {"https://mail.google.com", "mail.google.com", false},
+
+ // Different hosts in general.
+ {"https://www.chrome.com", "www.chrome.com", false},
+ {"http://youtube.com", ".youtube.com", false},
+ };
+
+ for (CookieTestCase test_case : test_cases)
+ RunTestCase(test_case, filter);
+}
+
+TEST(OriginFilterBuilderTest, MatchesCookiesBlacklist) {
+ OriginFilterBuilder builder(OriginFilterBuilder::BLACKLIST);
+ builder.AddOrigin(Origin(GURL("https://www.google.com")));
+ base::Callback<bool(const net::CanonicalCookie&)> filter =
+ builder.BuildDomainCookieFilter();
+
+ CookieTestCase test_cases[] = {
+ // Any URL on the specified origin is matched.
+ {"https://www.google.com", ".google.com", false},
+ {"https://mail.google.com", ".google.com", false},
+ {"http://google.com", ".google.com", false},
+ {"https://www.google.com", "www.google.com", false},
+ {"http://www.google.com", "www.google.com", false},
+
+ // Different tlds, and subdomains.
+ {"https://www.google.org", ".google.org", true},
+ {"https://www.google.org", ".google.org", true},
+ {"http://mail.google.com", "mail.google.com", true},
+ {"https://mail.google.com", "mail.google.com", true},
+
+ // Different hosts in general.
+ {"https://www.chrome.com", "www.chrome.com", true},
+ {"http://youtube.com", ".youtube.com", true},
+ };
+
+ for (CookieTestCase test_case : test_cases)
+ RunTestCase(test_case, filter);
+}
+
TEST(OriginFilterBuilderTest, MatchesURLWithSubdomain) {
OriginFilterBuilder builder(OriginFilterBuilder::WHITELIST);
builder.AddOrigin(Origin(GURL("https://www.google.com")));

Powered by Google App Engine
This is Rietveld 408576698