| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/task/cancelable_task_tracker.h" | 24 #include "base/task/cancelable_task_tracker.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 26 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 27 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 27 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 28 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 28 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 29 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 29 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 30 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 30 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
| 31 #include "chrome/browser/browsing_data/origin_filter_builder.h" |
| 31 #include "chrome/browser/domain_reliability/service_factory.h" | 32 #include "chrome/browser/domain_reliability/service_factory.h" |
| 32 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 33 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 33 #include "chrome/browser/favicon/favicon_service_factory.h" | 34 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 34 #include "chrome/browser/history/history_service_factory.h" | 35 #include "chrome/browser/history/history_service_factory.h" |
| 35 #include "chrome/browser/password_manager/password_store_factory.h" | 36 #include "chrome/browser/password_manager/password_store_factory.h" |
| 36 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 37 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 37 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 38 #include "chrome/test/base/testing_browser_process.h" | 39 #include "chrome/test/base/testing_browser_process.h" |
| 39 #include "chrome/test/base/testing_profile.h" | 40 #include "chrome/test/base/testing_profile.h" |
| 40 #include "components/autofill/core/browser/autofill_profile.h" | 41 #include "components/autofill/core/browser/autofill_profile.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 257 |
| 257 StoragePartitionRemovalData storage_partition_removal_data_; | 258 StoragePartitionRemovalData storage_partition_removal_data_; |
| 258 | 259 |
| 259 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); | 260 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); |
| 260 }; | 261 }; |
| 261 | 262 |
| 262 // Custom matcher to verify is-same-origin relationship to given reference | 263 // Custom matcher to verify is-same-origin relationship to given reference |
| 263 // origin. | 264 // origin. |
| 264 // (We cannot use equality-based matching because operator== is not defined for | 265 // (We cannot use equality-based matching because operator== is not defined for |
| 265 // Origin, and we in fact want to rely on IsSameOrigin for matching purposes.) | 266 // Origin, and we in fact want to rely on IsSameOrigin for matching purposes.) |
| 267 // TODO(msramek): This is only used for backends that take url::Origin instead |
| 268 // of an url filter predicate to match URLs. Remove this when we fully switch |
| 269 // to url filter predicates. |
| 266 class SameOriginMatcher : public MatcherInterface<const url::Origin&> { | 270 class SameOriginMatcher : public MatcherInterface<const url::Origin&> { |
| 267 public: | 271 public: |
| 268 explicit SameOriginMatcher(const url::Origin& reference) | 272 explicit SameOriginMatcher(const url::Origin& reference) |
| 269 : reference_(reference) {} | 273 : reference_(reference) {} |
| 270 | 274 |
| 271 virtual bool MatchAndExplain(const url::Origin& origin, | 275 virtual bool MatchAndExplain(const url::Origin& origin, |
| 272 MatchResultListener* listener) const { | 276 MatchResultListener* listener) const { |
| 273 return reference_.IsSameOriginWith(origin); | 277 return reference_.IsSameOriginWith(origin); |
| 274 } | 278 } |
| 275 | 279 |
| 276 virtual void DescribeTo(::std::ostream* os) const { | 280 virtual void DescribeTo(::std::ostream* os) const { |
| 277 *os << "is same origin with " << reference_; | 281 *os << "is same origin with " << reference_; |
| 278 } | 282 } |
| 279 | 283 |
| 280 virtual void DescribeNegationTo(::std::ostream* os) const { | 284 virtual void DescribeNegationTo(::std::ostream* os) const { |
| 281 *os << "is not same origin with " << reference_; | 285 *os << "is not same origin with " << reference_; |
| 282 } | 286 } |
| 283 | 287 |
| 284 private: | 288 private: |
| 285 const url::Origin& reference_; | 289 const url::Origin& reference_; |
| 286 }; | 290 }; |
| 287 | 291 |
| 288 inline Matcher<const url::Origin&> SameOrigin(const url::Origin& reference) { | 292 inline Matcher<const url::Origin&> SameOrigin(const url::Origin& reference) { |
| 289 return MakeMatcher(new SameOriginMatcher(reference)); | 293 return MakeMatcher(new SameOriginMatcher(reference)); |
| 290 } | 294 } |
| 291 | 295 |
| 296 // Custom matcher to test the equivalence of two URL filters. Since those are |
| 297 // blackbox predicates, we can only approximate the equivalence by testing |
| 298 // whether the filter give the same answer for several URLs. This is currently |
| 299 // good enough for our testing purposes, to distinguish whitelists |
| 300 // and blacklists, empty and non-empty filters and such. |
| 301 // TODO(msramek): BrowsingDataRemover and some of its backends support URL |
| 302 // filters, but its constructor currently only takes a single URL and constructs |
| 303 // its own url filter. If an url filter was directly passed to |
| 304 // BrowsingDataRemover (what should eventually be the case), we can use the same |
| 305 // instance in the test as well, and thus simply test base::Callback::Equals() |
| 306 // in this matcher. |
| 307 class ProbablySameFilterMatcher |
| 308 : public MatcherInterface<const base::Callback<bool(const GURL&)>&> { |
| 309 public: |
| 310 explicit ProbablySameFilterMatcher( |
| 311 const base::Callback<bool(const GURL&)>& filter) |
| 312 : to_match_(filter) { |
| 313 } |
| 314 |
| 315 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter, |
| 316 MatchResultListener* listener) const { |
| 317 const GURL urls_to_test_[] = |
| 318 {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")}; |
| 319 for (GURL url : urls_to_test_) { |
| 320 if (filter.Run(url) != to_match_.Run(url)) { |
| 321 *listener << "The filters differ on the URL " << url; |
| 322 return false; |
| 323 } |
| 324 } |
| 325 return true; |
| 326 } |
| 327 |
| 328 virtual void DescribeTo(::std::ostream* os) const { |
| 329 *os << "is probably the same url filter as " << &to_match_; |
| 330 } |
| 331 |
| 332 virtual void DescribeNegationTo(::std::ostream* os) const { |
| 333 *os << "is definitely NOT the same url filter as " << &to_match_; |
| 334 } |
| 335 |
| 336 private: |
| 337 const base::Callback<bool(const GURL&)>& to_match_; |
| 338 }; |
| 339 |
| 340 inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter( |
| 341 const base::Callback<bool(const GURL&)>& filter) { |
| 342 return MakeMatcher(new ProbablySameFilterMatcher(filter)); |
| 343 } |
| 344 |
| 292 } // namespace | 345 } // namespace |
| 293 | 346 |
| 294 // Testers ------------------------------------------------------------------- | 347 // Testers ------------------------------------------------------------------- |
| 295 | 348 |
| 296 class RemoveCookieTester { | 349 class RemoveCookieTester { |
| 297 public: | 350 public: |
| 298 RemoveCookieTester() {} | 351 RemoveCookieTester() {} |
| 299 | 352 |
| 300 // Returns true, if the given cookie exists in the cookie store. | 353 // Returns true, if the given cookie exists in the cookie store. |
| 301 bool ContainsCookie() { | 354 bool ContainsCookie() { |
| (...skipping 1861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2163 // monitor case again. | 2216 // monitor case again. |
| 2164 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) { | 2217 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) { |
| 2165 BlockUntilBrowsingDataRemoved( | 2218 BlockUntilBrowsingDataRemoved( |
| 2166 BrowsingDataRemover::EVERYTHING, | 2219 BrowsingDataRemover::EVERYTHING, |
| 2167 BrowsingDataRemover::REMOVE_HISTORY | | 2220 BrowsingDataRemover::REMOVE_HISTORY | |
| 2168 BrowsingDataRemover::REMOVE_COOKIES, false); | 2221 BrowsingDataRemover::REMOVE_COOKIES, false); |
| 2169 } | 2222 } |
| 2170 | 2223 |
| 2171 TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByTimeOnly) { | 2224 TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByTimeOnly) { |
| 2172 RemoveDownloadsTester tester(GetProfile()); | 2225 RemoveDownloadsTester tester(GetProfile()); |
| 2226 base::Callback<bool(const GURL&)> filter = |
| 2227 OriginFilterBuilder::BuildEmptyFilter(); |
| 2173 | 2228 |
| 2174 EXPECT_CALL(*tester.download_manager(), RemoveDownloadsBetween(_, _)); | 2229 EXPECT_CALL( |
| 2230 *tester.download_manager(), |
| 2231 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); |
| 2175 | 2232 |
| 2176 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 2233 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 2177 BrowsingDataRemover::REMOVE_DOWNLOADS, false); | 2234 BrowsingDataRemover::REMOVE_DOWNLOADS, false); |
| 2178 } | 2235 } |
| 2179 | 2236 |
| 2180 TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByOrigin) { | 2237 TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByOrigin) { |
| 2181 RemoveDownloadsTester tester(GetProfile()); | 2238 RemoveDownloadsTester tester(GetProfile()); |
| 2182 const url::Origin expectedOrigin(kOrigin1); | 2239 OriginFilterBuilder builder(OriginFilterBuilder::WHITELIST); |
| 2240 builder.AddOrigin(url::Origin(kOrigin1)); |
| 2241 base::Callback<bool(const GURL&)> filter = builder.BuildSameOriginFilter(); |
| 2183 | 2242 |
| 2184 EXPECT_CALL(*tester.download_manager(), | 2243 EXPECT_CALL( |
| 2185 RemoveDownloadsByOriginAndTime(SameOrigin(expectedOrigin), _, _)); | 2244 *tester.download_manager(), |
| 2245 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); |
| 2186 | 2246 |
| 2187 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, | 2247 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 2188 BrowsingDataRemover::REMOVE_DOWNLOADS, kOrigin1); | 2248 BrowsingDataRemover::REMOVE_DOWNLOADS, kOrigin1); |
| 2189 } | 2249 } |
| 2190 | 2250 |
| 2191 TEST_F(BrowsingDataRemoverTest, RemovePasswordStatistics) { | 2251 TEST_F(BrowsingDataRemoverTest, RemovePasswordStatistics) { |
| 2192 RemovePasswordsTester tester(GetProfile()); | 2252 RemovePasswordsTester tester(GetProfile()); |
| 2193 | 2253 |
| 2194 EXPECT_CALL(*tester.store(), RemoveStatisticsCreatedBetweenImpl( | 2254 EXPECT_CALL(*tester.store(), RemoveStatisticsCreatedBetweenImpl( |
| 2195 base::Time(), base::Time::Max())); | 2255 base::Time(), base::Time::Max())); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2210 TEST_F(BrowsingDataRemoverTest, RemovePasswordsByOrigin) { | 2270 TEST_F(BrowsingDataRemoverTest, RemovePasswordsByOrigin) { |
| 2211 RemovePasswordsTester tester(GetProfile()); | 2271 RemovePasswordsTester tester(GetProfile()); |
| 2212 const url::Origin expectedOrigin(kOrigin1); | 2272 const url::Origin expectedOrigin(kOrigin1); |
| 2213 | 2273 |
| 2214 EXPECT_CALL(*tester.store(), | 2274 EXPECT_CALL(*tester.store(), |
| 2215 RemoveLoginsByOriginAndTimeImpl(SameOrigin(expectedOrigin), _, _)) | 2275 RemoveLoginsByOriginAndTimeImpl(SameOrigin(expectedOrigin), _, _)) |
| 2216 .WillOnce(Return(password_manager::PasswordStoreChangeList())); | 2276 .WillOnce(Return(password_manager::PasswordStoreChangeList())); |
| 2217 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, | 2277 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 2218 BrowsingDataRemover::REMOVE_PASSWORDS, kOrigin1); | 2278 BrowsingDataRemover::REMOVE_PASSWORDS, kOrigin1); |
| 2219 } | 2279 } |
| OLD | NEW |