| 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 <list> | 10 #include <list> |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 class ProbablySameFilterMatcher | 354 class ProbablySameFilterMatcher |
| 355 : public MatcherInterface<const base::Callback<bool(const GURL&)>&> { | 355 : public MatcherInterface<const base::Callback<bool(const GURL&)>&> { |
| 356 public: | 356 public: |
| 357 explicit ProbablySameFilterMatcher( | 357 explicit ProbablySameFilterMatcher( |
| 358 const base::Callback<bool(const GURL&)>& filter) | 358 const base::Callback<bool(const GURL&)>& filter) |
| 359 : to_match_(filter) { | 359 : to_match_(filter) { |
| 360 } | 360 } |
| 361 | 361 |
| 362 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter, | 362 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter, |
| 363 MatchResultListener* listener) const { | 363 MatchResultListener* listener) const { |
| 364 if (filter.is_null() && to_match_.is_null()) |
| 365 return true; |
| 366 if (filter.is_null() != to_match_.is_null()) |
| 367 return false; |
| 368 |
| 364 const GURL urls_to_test_[] = | 369 const GURL urls_to_test_[] = |
| 365 {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")}; | 370 {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")}; |
| 366 for (GURL url : urls_to_test_) { | 371 for (GURL url : urls_to_test_) { |
| 367 if (filter.Run(url) != to_match_.Run(url)) { | 372 if (filter.Run(url) != to_match_.Run(url)) { |
| 368 if (listener) | 373 if (listener) |
| 369 *listener << "The filters differ on the URL " << url; | 374 *listener << "The filters differ on the URL " << url; |
| 370 return false; | 375 return false; |
| 371 } | 376 } |
| 372 } | 377 } |
| 373 return true; | 378 return true; |
| (...skipping 2121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2495 EXPECT_CALL( | 2500 EXPECT_CALL( |
| 2496 *tester.download_manager(), | 2501 *tester.download_manager(), |
| 2497 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); | 2502 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); |
| 2498 | 2503 |
| 2499 BlockUntilOriginDataRemoved(browsing_data::ALL_TIME, | 2504 BlockUntilOriginDataRemoved(browsing_data::ALL_TIME, |
| 2500 BrowsingDataRemover::REMOVE_DOWNLOADS, builder); | 2505 BrowsingDataRemover::REMOVE_DOWNLOADS, builder); |
| 2501 } | 2506 } |
| 2502 | 2507 |
| 2503 TEST_F(BrowsingDataRemoverTest, RemovePasswordStatistics) { | 2508 TEST_F(BrowsingDataRemoverTest, RemovePasswordStatistics) { |
| 2504 RemovePasswordsTester tester(GetProfile()); | 2509 RemovePasswordsTester tester(GetProfile()); |
| 2510 base::Callback<bool(const GURL&)> empty_filter; |
| 2505 | 2511 |
| 2506 EXPECT_CALL(*tester.store(), RemoveStatisticsCreatedBetweenImpl( | 2512 EXPECT_CALL(*tester.store(), RemoveStatisticsByOriginAndTimeImpl( |
| 2513 ProbablySameFilter(empty_filter), |
| 2507 base::Time(), base::Time::Max())); | 2514 base::Time(), base::Time::Max())); |
| 2508 BlockUntilBrowsingDataRemoved(browsing_data::ALL_TIME, | 2515 BlockUntilBrowsingDataRemoved(browsing_data::ALL_TIME, |
| 2509 BrowsingDataRemover::REMOVE_HISTORY, false); | 2516 BrowsingDataRemover::REMOVE_HISTORY, false); |
| 2510 } | 2517 } |
| 2511 | 2518 |
| 2519 TEST_F(BrowsingDataRemoverTest, RemovePasswordStatisticsByOrigin) { |
| 2520 RemovePasswordsTester tester(GetProfile()); |
| 2521 |
| 2522 RegistrableDomainFilterBuilder builder( |
| 2523 RegistrableDomainFilterBuilder::WHITELIST); |
| 2524 builder.AddRegisterableDomain(kTestRegisterableDomain1); |
| 2525 base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter(); |
| 2526 |
| 2527 EXPECT_CALL(*tester.store(), |
| 2528 RemoveStatisticsByOriginAndTimeImpl( |
| 2529 ProbablySameFilter(filter), base::Time(), base::Time::Max())); |
| 2530 BlockUntilOriginDataRemoved(browsing_data::ALL_TIME, |
| 2531 BrowsingDataRemover::REMOVE_HISTORY, builder); |
| 2532 } |
| 2533 |
| 2512 TEST_F(BrowsingDataRemoverTest, RemovePasswordsByTimeOnly) { | 2534 TEST_F(BrowsingDataRemoverTest, RemovePasswordsByTimeOnly) { |
| 2513 RemovePasswordsTester tester(GetProfile()); | 2535 RemovePasswordsTester tester(GetProfile()); |
| 2514 base::Callback<bool(const GURL&)> filter = | 2536 base::Callback<bool(const GURL&)> filter = |
| 2515 BrowsingDataFilterBuilder::BuildNoopFilter(); | 2537 BrowsingDataFilterBuilder::BuildNoopFilter(); |
| 2516 | 2538 |
| 2517 EXPECT_CALL(*tester.store(), | 2539 EXPECT_CALL(*tester.store(), |
| 2518 RemoveLoginsByURLAndTimeImpl(ProbablySameFilter(filter), _, _)) | 2540 RemoveLoginsByURLAndTimeImpl(ProbablySameFilter(filter), _, _)) |
| 2519 .WillOnce(Return(password_manager::PasswordStoreChangeList())); | 2541 .WillOnce(Return(password_manager::PasswordStoreChangeList())); |
| 2520 BlockUntilBrowsingDataRemoved(browsing_data::ALL_TIME, | 2542 BlockUntilBrowsingDataRemoved(browsing_data::ALL_TIME, |
| 2521 BrowsingDataRemover::REMOVE_PASSWORDS, false); | 2543 BrowsingDataRemover::REMOVE_PASSWORDS, false); |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3070 EXPECT_TRUE(remover->is_removing()); | 3092 EXPECT_TRUE(remover->is_removing()); |
| 3071 | 3093 |
| 3072 // Add one more deletion and wait for it. | 3094 // Add one more deletion and wait for it. |
| 3073 BlockUntilBrowsingDataRemoved( | 3095 BlockUntilBrowsingDataRemoved( |
| 3074 browsing_data::ALL_TIME, | 3096 browsing_data::ALL_TIME, |
| 3075 BrowsingDataRemover::REMOVE_COOKIES, | 3097 BrowsingDataRemover::REMOVE_COOKIES, |
| 3076 BrowsingDataHelper::UNPROTECTED_WEB); | 3098 BrowsingDataHelper::UNPROTECTED_WEB); |
| 3077 | 3099 |
| 3078 EXPECT_FALSE(remover->is_removing()); | 3100 EXPECT_FALSE(remover->is_removing()); |
| 3079 } | 3101 } |
| OLD | NEW |