Chromium Code Reviews| 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..492c17a18f186ea42a9af3594c500d0078b64ca4 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,7 @@ 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 currently response. |
|
Timo Reimann
2016/02/05 19:01:24
nit-pick: Sentence incomplete/grammar? I'm not ent
msramek
2016/02/10 14:30:36
Done. Sorry, I must have been interrupted while wr
|
| class SameOriginMatcher : public MatcherInterface<const url::Origin&> { |
| public: |
| explicit SameOriginMatcher(const url::Origin& reference) |
| @@ -289,6 +291,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 OriginFilterBuilder. If an instance of OriginFilter was passed |
|
Timo Reimann
2016/02/05 19:01:24
We don't have OriginFilter as a class anymore, do
msramek
2016/02/10 14:30:36
Done. Nope, this is supposed to refer to url filte
|
| +// to BrowsingDataRemover (what should evenetually be the case), we can |
|
Timo Reimann
2016/02/05 19:01:24
Nit-pick: Typo (evenetually -> eventually).
msramek
2016/02/10 14:30:36
Done.
|
| +// 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 +2221,13 @@ TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) { |
| TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByTimeOnly) { |
| RemoveDownloadsTester tester(GetProfile()); |
| + scoped_ptr<OriginFilterBuilder> builder = |
| + OriginFilterBuilder::Empty(); |
| - EXPECT_CALL(*tester.download_manager(), RemoveDownloadsBetween(_, _)); |
| + EXPECT_CALL( |
| + *tester.download_manager(), |
| + RemoveDownloadsByOriginAndTime( |
| + ProbablySameFilter(builder->GetSameOriginFilter()), _, _)); |
| BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
| BrowsingDataRemover::REMOVE_DOWNLOADS, false); |
| @@ -2179,10 +2235,15 @@ TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByTimeOnly) { |
| TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByOrigin) { |
| RemoveDownloadsTester tester(GetProfile()); |
| - const url::Origin expectedOrigin(kOrigin1); |
| - |
| - EXPECT_CALL(*tester.download_manager(), |
| - RemoveDownloadsByOriginAndTime(SameOrigin(expectedOrigin), _, _)); |
| + std::vector<url::Origin> whitelist; |
| + whitelist.push_back(url::Origin(kOrigin1)); |
| + scoped_ptr<OriginFilterBuilder> builder = |
| + OriginFilterBuilder::AsWhitelist(whitelist); |
| + |
| + EXPECT_CALL( |
| + *tester.download_manager(), |
| + RemoveDownloadsByOriginAndTime( |
| + ProbablySameFilter(builder->GetSameOriginFilter()), _, _)); |
| BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, |
| BrowsingDataRemover::REMOVE_DOWNLOADS, kOrigin1); |