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

Unified Diff: chrome/browser/browsing_data/browsing_data_remover_filter_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: Renamed class, comments Created 4 years, 8 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/browsing_data_remover_filter_unittest.cc
diff --git a/chrome/browser/browsing_data/browsing_data_remover_filter_unittest.cc b/chrome/browser/browsing_data/browsing_data_remover_filter_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6ae46e618c99abf57a3439a532d49cc9ee9a6833
--- /dev/null
+++ b/chrome/browser/browsing_data/browsing_data_remover_filter_unittest.cc
@@ -0,0 +1,397 @@
+// Copyright 2015 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.
+
+#include "chrome/browser/browsing_data/browsing_data_remover_filter.h"
+
+#include <algorithm>
+#include <string>
+#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"
+
+namespace url {
+
+namespace {
+
+struct TestCase {
+ std::string url;
+ bool should_match;
+};
+
+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.";
+ EXPECT_EQ(test_case.should_match, filter.Run(pattern)) << pattern.ToString();
+}
+
+void RunTestCase(
+ TestCase test_case,
+ const base::Callback<bool(const net::CanonicalCookie&)>& filter) {
+ // Test with regular cookie, http only, domain, and secure.
+ std::string cookie_line = "A=2";
+ GURL test_url(test_case.url);
+ EXPECT_TRUE(test_url.is_valid()) << test_case.url;
+ scoped_ptr<net::CanonicalCookie> cookie = net::CanonicalCookie::Create(
+ test_url, cookie_line, base::Time::Now(), net::CookieOptions());
+ EXPECT_TRUE(cookie) << cookie_line << " from " << test_case.url
+ << " is not a valid cookie";
+ if (cookie)
+ EXPECT_EQ(test_case.should_match, filter.Run(*cookie))
+ << cookie->DebugString();
+
+ cookie_line = std::string("A=2;domain=") + test_url.host();
+ cookie = net::CanonicalCookie::Create(
+ test_url, cookie_line, base::Time::Now(), net::CookieOptions());
+ if (cookie)
+ EXPECT_EQ(test_case.should_match, filter.Run(*cookie))
+ << cookie->DebugString();
+
+ cookie_line = std::string("A=2; HttpOnly;") + test_url.host();
+ cookie = net::CanonicalCookie::Create(
+ test_url, cookie_line, base::Time::Now(), net::CookieOptions());
+ if (cookie)
+ EXPECT_EQ(test_case.should_match, filter.Run(*cookie))
+ << cookie->DebugString();
+
+ cookie_line = std::string("A=2; HttpOnly; Secure;") + test_url.host();
+ cookie = net::CanonicalCookie::Create(
+ test_url, cookie_line, base::Time::Now(), net::CookieOptions());
+ if (cookie)
+ EXPECT_EQ(test_case.should_match, filter.Run(*cookie))
+ << cookie->DebugString();
+}
+
+} // namespace
+
+TEST(BrowsingDataRemoverFilterTest, Noop) {
+ // An no-op filter matches everything.
+ base::Callback<bool(const GURL&)> filter =
+ BrowsingDataRemoverFilter::BuildNoopFilter();
+
+ TestCase test_cases[] = {
+ {"https://www.google.com", true}, {"https://www.chrome.com", true},
+ };
+
+ for (TestCase test_case : test_cases)
+ RunTestCase(test_case, filter);
+}
+
+TEST(BrowsingDataRemoverFilterTest, Whitelist) {
+ BrowsingDataRemoverFilter builder(BrowsingDataRemoverFilter::WHITELIST);
+ builder.AddOrigin(Origin(GURL("https://www.google.com")));
+ builder.AddOrigin(Origin(GURL("http://www.example.com")));
+ builder.AddRegisterableDomain("foo.bar");
+ base::Callback<bool(const GURL&)> filter =
+ builder.BuildSameOriginOrDomainFilter();
+
+ TestCase test_cases[] = {
+ // Whitelist matches any URL on the specified origins,
+ {"https://www.google.com", true},
+ {"https://www.google.com/?q=test", true},
+ {"http://www.example.com", true},
+ {"http://www.example.com/index.html", true},
+ {"http://www.example.com/foo/bar", true},
+
+ // and matches any URL on the specified domains.
+ {"http://www.foo.bar/foo/bar", true},
+ {"https://www.sub.foo.bar/foo/bar", true},
+ {"http://www.sub.foo.bar:8000/foo/bar", true},
+
+ // Subdomains are different origins.
+ {"https://test.www.google.com", false},
+
+ // Different scheme or port is a different origin.
+ {"https://www.google.com: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},
+ {"http://www.chromium.org", false},
+ };
+
+ for (TestCase test_case : test_cases)
+ RunTestCase(test_case, filter);
+}
+
+TEST(BrowsingDataRemoverFilterTest, WhitelistContentSettings) {
+ BrowsingDataRemoverFilter builder(BrowsingDataRemoverFilter::WHITELIST);
+ builder.AddOrigin(Origin(GURL("https://www.google.com")));
+ builder.AddOrigin(Origin(GURL("http://www.example.com")));
+ builder.AddRegisterableDomain("foo.bar");
+ base::Callback<bool(const ContentSettingsPattern&)> filter =
+ builder.BuildWebsiteSettingsPatternMatchesFilter();
+
+ TestCase test_cases[] = {
+ // Whitelist matches any patterns that include the whitelist origins or
+ // registerable domains.
+ {"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},
+ {"http://www.foo.bar/foo/bar", true},
+ {"[*.]foo.bar", true},
+ {"www.sub.foo.bar/foo/bar", true},
+ {"http://www.sub.foo.bar:8000/foo/bar", 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.
+ {"www.sub.foo.bar.bar2/foo/bar", false},
+ {"https://www.youtube.com", false},
+ {"https://www.chromium.org", false},
+ {"[*.]youtube", false},
+ };
+
+ for (TestCase test_case : test_cases)
+ RunTestCase(test_case, filter);
+}
+
+TEST(BrowsingDataRemoverFilterTest, Blacklist) {
+ BrowsingDataRemoverFilter builder(BrowsingDataRemoverFilter::BLACKLIST);
+ builder.AddOrigin(Origin(GURL("https://www.google.com")));
+ builder.AddOrigin(Origin(GURL("http://www.example.com")));
+ builder.AddRegisterableDomain("foo.bar");
+ base::Callback<bool(const GURL&)> filter =
+ builder.BuildSameOriginOrDomainFilter();
+
+ TestCase test_cases[] = {
+ // URLS on explicitly specified origins or domains are not matched.
+ {"https://www.google.com", false},
+ {"https://www.google.com/?q=test", false},
+ {"http://www.example.com", false},
+ {"http://www.example.com/index.html", false},
+ {"http://www.example.com/foo/bar", false},
+ {"http://www.foo.bar/foo/bar", false},
+ {"https://www.sub.foo.bar/foo/bar", false},
+ {"http://www.sub.foo.bar:8000/foo/bar", false},
+
+ // Subdomains are different origins.
+ {"https://test.www.google.com", true},
+
+ // The same hosts but with different schemes and ports
+ // are not blacklisted.
+ {"https://www.google.com:8000", true},
+ {"https://www.example.com/index.html", true},
+
+ // Different hosts are not blacklisted.
+ {"https://www.chrome.com", true},
+ {"https://www.youtube.com", true},
+ };
+
+ for (TestCase test_case : test_cases)
+ RunTestCase(test_case, filter);
+}
+
+TEST(BrowsingDataRemoverFilterTest, BlacklistContentSettings) {
+ BrowsingDataRemoverFilter builder(BrowsingDataRemoverFilter::BLACKLIST);
+ builder.AddOrigin(Origin(GURL("https://www.google.com")));
+ builder.AddOrigin(Origin(GURL("http://www.example.com")));
+ builder.AddRegisterableDomain("foo.bar");
+ base::Callback<bool(const ContentSettingsPattern&)> filter =
+ builder.BuildWebsiteSettingsPatternMatchesFilter();
+
+ 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},
+ {"http://www.foo.bar/foo/bar", false},
+ {"[*.]foo.bar", false},
+ {"www.sub.foo.bar/foo/bar", false},
+ {"http://www.sub.foo.bar:8000/foo/bar", 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.
+ {"www.sub.foo.bar.bar2/foo/bar", true},
+ {"https://www.youtube.com", true},
+ {"https://www.chromium.org", true},
+ {"[*.]youtube", true},
+ };
+
+ for (TestCase test_case : test_cases)
+ RunTestCase(test_case, filter);
+}
+
+TEST(BrowsingDataRemoverFilterTest, MatchesCookiesWhitelist) {
+ BrowsingDataRemoverFilter builder(BrowsingDataRemoverFilter::WHITELIST);
+ // Regular site.
+ builder.AddOrigin(Origin(GURL("https://www.google.com")));
+ // sp.nom.br is a TLD.
+ builder.AddOrigin(Origin(GURL("https://www.website.sp.nom.br")));
+ // misawa.aomori.jp is a TLD and possibly not, as using the address without
+ // a subdomain is also a valid url.
+ builder.AddOrigin(Origin(GURL("http://www.misawa.aomori.jp")));
+ builder.AddOrigin(Origin(GURL("http://example.com")));
+ builder.AddOrigin(Origin(GURL("http://192.168.1.1:80")));
+ builder.AddOrigin(Origin(GURL("https://sub.sub.sub.subdomaincrazy.com")));
+ builder.AddRegisterableDomain("foo.bar");
+ base::Callback<bool(const net::CanonicalCookie&)> filter =
+ builder.BuildDomainCookieFilter();
+
+ TestCase test_cases[] = {
+ // Any cookie with the same registerable domain as the origins is matched.
+ {"https://www.google.com", true},
+ {"http://www.google.com", true},
+ {"http://www.google.com:300", true},
+ {"https://mail.google.com", true},
+ {"http://mail.google.com", true},
+ {"http://google.com", true},
+ {"https://website.sp.nom.br", true},
+ {"https://sub.website.sp.nom.br", true},
+ {"http://www.misawa.aomori.jp", true},
+ {"http://sub.www.misawa.aomori.jp", true},
+ {"http://www.example.com", true},
+ {"http://192.168.1.1", true},
+ {"http://192.168.1.1:10", true},
+ {"https://sub.sub.subdomaincrazy.com", true},
+ {"http://sub.subdomaincrazy.com", true},
+ {"https://subdomaincrazy.com", true},
+ {"http://www.subdomaincrazy.com", true},
+ {"https://www.foo.bar", true},
+ {"http://www.foo.bar/foo/bar", true},
+ {"https://www.sub.foo.bar/foo/bar", true},
+ {"http://www.sub.foo.bar:8000/foo/bar", true},
+
+ // Different tlds.
+ {"https://www.google.org", false},
+
+ // We treat tld+1 and bare tld as different domains.
+ {"https://www.sp.nom.br", false},
+ {"https://sp.nom.br", false},
+ {"http://www.hospital.misawa.aomori.jp/", false},
+
+ // Different hosts in general.
+ {"https://www.chrome.com", false},
+ {"https://www.foo.bar.bar2", false},
+ {"http://youtube.com", false},
+ {"http://192.168.2.1", false}};
+
+ for (TestCase test_case : test_cases)
+ RunTestCase(test_case, filter);
+}
+
+TEST(BrowsingDataRemoverFilterTest, MatchesCookiesBlacklist) {
+ BrowsingDataRemoverFilter builder(BrowsingDataRemoverFilter::BLACKLIST);
+ // Regular site.
+ builder.AddOrigin(Origin(GURL("https://www.google.com")));
+ // sp.nom.br is a TLD.
msramek 2016/04/07 16:19:13 nit: eTLD? Here and elsewhere.
dmurph 2016/04/08 23:33:45 Done.
+ builder.AddOrigin(Origin(GURL("https://www.website.sp.nom.br")));
+ // misawa.aomori.jp is a TLD and possibly not, as using the address without
+ // a subdomain is also a valid url.
+ builder.AddOrigin(Origin(GURL("http://www.misawa.aomori.jp")));
+ // Here we're doing no subdomain.
+ builder.AddOrigin(Origin(GURL("http://example.com")));
+ builder.AddOrigin(Origin(GURL("http://192.168.1.1:80")));
+ builder.AddOrigin(Origin(GURL("https://sub.sub.sub.subdomaincrazy.com")));
+ builder.AddRegisterableDomain("foo.bar");
+ base::Callback<bool(const net::CanonicalCookie&)> filter =
+ builder.BuildDomainCookieFilter();
+
+ TestCase test_cases[] = {
+ // Any cookie with the same registerable domain as the origins is matched.
+ {"https://www.google.com", false},
+ {"http://www.google.com", false},
+ {"http://www.google.com:300", false},
+ {"https://mail.google.com", false},
+ {"http://mail.google.com", false},
+ {"http://google.com", false},
+ {"https://website.sp.nom.br", false},
+ {"https://sub.website.sp.nom.br", false},
+ {"http://www.misawa.aomori.jp", false},
+ {"http://sub.www.misawa.aomori.jp", false},
+ {"http://www.example.com", false},
+ {"http://192.168.1.1", false},
+ {"http://192.168.1.1:10", false},
+ {"https://sub.sub.subdomaincrazy.com", false},
+ {"http://sub.subdomaincrazy.com", false},
+ {"https://subdomaincrazy.com", false},
+ {"http://www.subdomaincrazy.com", false},
+ {"https://www.foo.bar", false},
+ {"http://www.foo.bar/foo/bar", false},
+ {"https://www.sub.foo.bar/foo/bar", false},
+ {"http://www.sub.foo.bar:8000/foo/bar", false},
+
+ // Different tlds.
+ {"https://www.google.org", true},
+
+ // We treat tld+1 and bare tld as different domains.
+ {"https://www.sp.nom.br", true},
+ {"https://sp.nom.br", true},
+ {"http://www.hospital.misawa.aomori.jp/", true},
+
+ // Different hosts in general.
+ {"https://www.chrome.com", true},
+ {"https://www.foo.bar.bar2", true},
+ {"http://youtube.com", true},
+ {"http://192.168.2.1", true}};
+
+ for (TestCase test_case : test_cases)
+ RunTestCase(test_case, filter);
+}
+
+} // namespace url

Powered by Google App Engine
This is Rietveld 408576698