| Index: chrome/browser/browsing_data/browsing_data_remover_unittest.cc
|
| diff --git a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
|
| index 6aa8694afc017c6a6d4d4fb8118bdd2c45c2f804..406e04fbae19dad0700fc48113d972e2fccb24fa 100644
|
| --- a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
|
| +++ b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
|
| @@ -28,6 +28,7 @@
|
| #include "chrome/browser/browsing_data/browsing_data_helper.h"
|
| #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
|
| #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
|
| +#include "chrome/browser/browsing_data/origin_filter_builder.h"
|
| #include "chrome/browser/domain_reliability/service_factory.h"
|
| #include "chrome/browser/download/chrome_download_manager_delegate.h"
|
| #include "chrome/browser/favicon/favicon_service_factory.h"
|
| @@ -263,6 +264,9 @@ class TestStoragePartition : public StoragePartition {
|
| // origin.
|
| // (We cannot use equality-based matching because operator== is not defined for
|
| // Origin, and we in fact want to rely on IsSameOrigin for matching purposes.)
|
| +// TODO(msramek): This is only used for backends that take url::Origin instead
|
| +// of an url filter predicate to match URLs. Remove this when we fully switch
|
| +// to url filter predicates.
|
| class SameOriginMatcher : public MatcherInterface<const url::Origin&> {
|
| public:
|
| explicit SameOriginMatcher(const url::Origin& reference)
|
| @@ -289,6 +293,55 @@ inline Matcher<const url::Origin&> SameOrigin(const url::Origin& reference) {
|
| return MakeMatcher(new SameOriginMatcher(reference));
|
| }
|
|
|
| +// Custom matcher to test the equivalence of two URL filters. Since those are
|
| +// blackbox predicates, we can only approximate the equivalence by testing
|
| +// whether the filter give the same answer for several URLs. This is currently
|
| +// good enough for our testing purposes, to distinguish whitelists
|
| +// and blacklists, empty and non-empty filters and such.
|
| +// TODO(msramek): BrowsingDataRemover and some of its backends support URL
|
| +// filters, but its constructor currently only takes a single URL and constructs
|
| +// its own url filter. If an url filter was directly passed to
|
| +// BrowsingDataRemover (what should eventually be the case), we can use the same
|
| +// instance in the test as well, and thus simply test base::Callback::Equals()
|
| +// in this matcher.
|
| +class ProbablySameFilterMatcher
|
| + : public MatcherInterface<const base::Callback<bool(const GURL&)>&> {
|
| + public:
|
| + explicit ProbablySameFilterMatcher(
|
| + const base::Callback<bool(const GURL&)>& filter)
|
| + : to_match_(filter) {
|
| + }
|
| +
|
| + virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter,
|
| + MatchResultListener* listener) const {
|
| + const GURL urls_to_test_[] =
|
| + {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")};
|
| + for (GURL url : urls_to_test_) {
|
| + if (filter.Run(url) != to_match_.Run(url)) {
|
| + *listener << "The filters differ on the URL " << url;
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| + }
|
| +
|
| + virtual void DescribeTo(::std::ostream* os) const {
|
| + *os << "is probably the same url filter as " << &to_match_;
|
| + }
|
| +
|
| + virtual void DescribeNegationTo(::std::ostream* os) const {
|
| + *os << "is definitely NOT the same url filter as " << &to_match_;
|
| + }
|
| +
|
| + private:
|
| + const base::Callback<bool(const GURL&)>& to_match_;
|
| +};
|
| +
|
| +inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter(
|
| + const base::Callback<bool(const GURL&)>& filter) {
|
| + return MakeMatcher(new ProbablySameFilterMatcher(filter));
|
| +}
|
| +
|
| } // namespace
|
|
|
| // Testers -------------------------------------------------------------------
|
| @@ -2170,8 +2223,12 @@ TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) {
|
|
|
| TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByTimeOnly) {
|
| RemoveDownloadsTester tester(GetProfile());
|
| + base::Callback<bool(const GURL&)> filter =
|
| + OriginFilterBuilder::BuildEmptyFilter();
|
|
|
| - EXPECT_CALL(*tester.download_manager(), RemoveDownloadsBetween(_, _));
|
| + EXPECT_CALL(
|
| + *tester.download_manager(),
|
| + RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _));
|
|
|
| BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
|
| BrowsingDataRemover::REMOVE_DOWNLOADS, false);
|
| @@ -2179,10 +2236,13 @@ TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByTimeOnly) {
|
|
|
| TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByOrigin) {
|
| RemoveDownloadsTester tester(GetProfile());
|
| - const url::Origin expectedOrigin(kOrigin1);
|
| + OriginFilterBuilder builder(OriginFilterBuilder::WHITELIST);
|
| + builder.AddOrigin(url::Origin(kOrigin1));
|
| + base::Callback<bool(const GURL&)> filter = builder.BuildSameOriginFilter();
|
|
|
| - EXPECT_CALL(*tester.download_manager(),
|
| - RemoveDownloadsByOriginAndTime(SameOrigin(expectedOrigin), _, _));
|
| + EXPECT_CALL(
|
| + *tester.download_manager(),
|
| + RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _));
|
|
|
| BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
|
| BrowsingDataRemover::REMOVE_DOWNLOADS, kOrigin1);
|
|
|