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 <memory> | 10 #include <memory> |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 const base::Callback<bool(const GURL&)>& filter) | 342 const base::Callback<bool(const GURL&)>& filter) |
343 : to_match_(filter) { | 343 : to_match_(filter) { |
344 } | 344 } |
345 | 345 |
346 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter, | 346 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter, |
347 MatchResultListener* listener) const { | 347 MatchResultListener* listener) const { |
348 const GURL urls_to_test_[] = | 348 const GURL urls_to_test_[] = |
349 {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")}; | 349 {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")}; |
350 for (GURL url : urls_to_test_) { | 350 for (GURL url : urls_to_test_) { |
351 if (filter.Run(url) != to_match_.Run(url)) { | 351 if (filter.Run(url) != to_match_.Run(url)) { |
352 *listener << "The filters differ on the URL " << url; | 352 if (listener) |
| 353 *listener << "The filters differ on the URL " << url; |
353 return false; | 354 return false; |
354 } | 355 } |
355 } | 356 } |
356 return true; | 357 return true; |
357 } | 358 } |
358 | 359 |
359 virtual void DescribeTo(::std::ostream* os) const { | 360 virtual void DescribeTo(::std::ostream* os) const { |
360 *os << "is probably the same url filter as " << &to_match_; | 361 *os << "is probably the same url filter as " << &to_match_; |
361 } | 362 } |
362 | 363 |
363 virtual void DescribeNegationTo(::std::ostream* os) const { | 364 virtual void DescribeNegationTo(::std::ostream* os) const { |
364 *os << "is definitely NOT the same url filter as " << &to_match_; | 365 *os << "is definitely NOT the same url filter as " << &to_match_; |
365 } | 366 } |
366 | 367 |
367 private: | 368 private: |
368 const base::Callback<bool(const GURL&)>& to_match_; | 369 const base::Callback<bool(const GURL&)>& to_match_; |
369 }; | 370 }; |
370 | 371 |
371 inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter( | 372 inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter( |
372 const base::Callback<bool(const GURL&)>& filter) { | 373 const base::Callback<bool(const GURL&)>& filter) { |
373 return MakeMatcher(new ProbablySameFilterMatcher(filter)); | 374 return MakeMatcher(new ProbablySameFilterMatcher(filter)); |
374 } | 375 } |
375 | 376 |
| 377 bool ProbablySameFilters( |
| 378 const base::Callback<bool(const GURL&)>& filter1, |
| 379 const base::Callback<bool(const GURL&)>& filter2) { |
| 380 return ProbablySameFilter(filter1).MatchAndExplain(filter2, nullptr); |
| 381 } |
| 382 |
376 } // namespace | 383 } // namespace |
377 | 384 |
378 // Testers ------------------------------------------------------------------- | 385 // Testers ------------------------------------------------------------------- |
379 | 386 |
380 class RemoveCookieTester { | 387 class RemoveCookieTester { |
381 public: | 388 public: |
382 RemoveCookieTester() {} | 389 RemoveCookieTester() {} |
383 | 390 |
384 // Returns true, if the given cookie exists in the cookie store. | 391 // Returns true, if the given cookie exists in the cookie store. |
385 bool ContainsCookie() { | 392 bool ContainsCookie() { |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 | 847 |
841 ~MockDomainReliabilityService() override {} | 848 ~MockDomainReliabilityService() override {} |
842 | 849 |
843 std::unique_ptr<DomainReliabilityMonitor> CreateMonitor( | 850 std::unique_ptr<DomainReliabilityMonitor> CreateMonitor( |
844 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) | 851 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) |
845 override { | 852 override { |
846 NOTREACHED(); | 853 NOTREACHED(); |
847 return std::unique_ptr<DomainReliabilityMonitor>(); | 854 return std::unique_ptr<DomainReliabilityMonitor>(); |
848 } | 855 } |
849 | 856 |
850 void ClearBrowsingData(DomainReliabilityClearMode clear_mode, | 857 void ClearBrowsingData( |
851 const base::Closure& callback) override { | 858 DomainReliabilityClearMode clear_mode, |
| 859 const base::Callback<bool(const GURL&)>& origin_filter, |
| 860 const base::Closure& callback) override { |
852 clear_count_++; | 861 clear_count_++; |
853 last_clear_mode_ = clear_mode; | 862 last_clear_mode_ = clear_mode; |
| 863 last_filter_ = origin_filter; |
854 callback.Run(); | 864 callback.Run(); |
855 } | 865 } |
856 | 866 |
857 void GetWebUIData(const base::Callback<void(std::unique_ptr<base::Value>)>& | 867 void GetWebUIData(const base::Callback<void(std::unique_ptr<base::Value>)>& |
858 callback) const override { | 868 callback) const override { |
859 NOTREACHED(); | 869 NOTREACHED(); |
860 } | 870 } |
861 | 871 |
862 int clear_count() const { return clear_count_; } | 872 int clear_count() const { return clear_count_; } |
863 | 873 |
864 DomainReliabilityClearMode last_clear_mode() const { | 874 DomainReliabilityClearMode last_clear_mode() const { |
865 return last_clear_mode_; | 875 return last_clear_mode_; |
866 } | 876 } |
867 | 877 |
| 878 const base::Callback<bool(const GURL&)>& last_filter() const { |
| 879 return last_filter_; |
| 880 } |
| 881 |
868 private: | 882 private: |
869 unsigned clear_count_ = 0; | 883 unsigned clear_count_ = 0; |
870 DomainReliabilityClearMode last_clear_mode_; | 884 DomainReliabilityClearMode last_clear_mode_; |
| 885 base::Callback<bool(const GURL&)> last_filter_; |
871 }; | 886 }; |
872 | 887 |
873 struct TestingDomainReliabilityServiceFactoryUserData | 888 struct TestingDomainReliabilityServiceFactoryUserData |
874 : public base::SupportsUserData::Data { | 889 : public base::SupportsUserData::Data { |
875 TestingDomainReliabilityServiceFactoryUserData( | 890 TestingDomainReliabilityServiceFactoryUserData( |
876 content::BrowserContext* context, | 891 content::BrowserContext* context, |
877 MockDomainReliabilityService* service) | 892 MockDomainReliabilityService* service) |
878 : context(context), | 893 : context(context), |
879 service(service), | 894 service(service), |
880 attached(false) {} | 895 attached(false) {} |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 mock_service_(new MockDomainReliabilityService()) { | 928 mock_service_(new MockDomainReliabilityService()) { |
914 AttachService(); | 929 AttachService(); |
915 } | 930 } |
916 | 931 |
917 unsigned clear_count() const { return mock_service_->clear_count(); } | 932 unsigned clear_count() const { return mock_service_->clear_count(); } |
918 | 933 |
919 DomainReliabilityClearMode last_clear_mode() const { | 934 DomainReliabilityClearMode last_clear_mode() const { |
920 return mock_service_->last_clear_mode(); | 935 return mock_service_->last_clear_mode(); |
921 } | 936 } |
922 | 937 |
| 938 const base::Callback<bool(const GURL&)>& last_filter() const { |
| 939 return mock_service_->last_filter(); |
| 940 } |
| 941 |
923 private: | 942 private: |
924 void AttachService() { | 943 void AttachService() { |
925 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey; | 944 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey; |
926 | 945 |
927 // Attach kludgey UserData struct to profile. | 946 // Attach kludgey UserData struct to profile. |
928 TestingDomainReliabilityServiceFactoryUserData* data = | 947 TestingDomainReliabilityServiceFactoryUserData* data = |
929 new TestingDomainReliabilityServiceFactoryUserData(profile_, | 948 new TestingDomainReliabilityServiceFactoryUserData(profile_, |
930 mock_service_); | 949 mock_service_); |
931 EXPECT_FALSE(profile_->GetUserData(kKey)); | 950 EXPECT_FALSE(profile_->GetUserData(kKey)); |
932 profile_->SetUserData(kKey, data); | 951 profile_->SetUserData(kKey, data); |
(...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2267 } | 2286 } |
2268 | 2287 |
2269 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) { | 2288 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) { |
2270 const ClearDomainReliabilityTester& tester = | 2289 const ClearDomainReliabilityTester& tester = |
2271 clear_domain_reliability_tester(); | 2290 clear_domain_reliability_tester(); |
2272 | 2291 |
2273 BlockUntilBrowsingDataRemoved(browsing_data::EVERYTHING, | 2292 BlockUntilBrowsingDataRemoved(browsing_data::EVERYTHING, |
2274 BrowsingDataRemover::REMOVE_HISTORY, false); | 2293 BrowsingDataRemover::REMOVE_HISTORY, false); |
2275 EXPECT_EQ(1u, tester.clear_count()); | 2294 EXPECT_EQ(1u, tester.clear_count()); |
2276 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode()); | 2295 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode()); |
| 2296 EXPECT_TRUE(ProbablySameFilters( |
| 2297 BrowsingDataFilterBuilder::BuildNoopFilter(), tester.last_filter())); |
| 2298 } |
| 2299 |
| 2300 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons_WithFilter) { |
| 2301 const ClearDomainReliabilityTester& tester = |
| 2302 clear_domain_reliability_tester(); |
| 2303 |
| 2304 RegistrableDomainFilterBuilder builder( |
| 2305 RegistrableDomainFilterBuilder::WHITELIST); |
| 2306 builder.AddRegisterableDomain(kTestRegisterableDomain1); |
| 2307 |
| 2308 BlockUntilOriginDataRemoved(browsing_data::EVERYTHING, |
| 2309 BrowsingDataRemover::REMOVE_HISTORY, builder); |
| 2310 EXPECT_EQ(1u, tester.clear_count()); |
| 2311 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode()); |
| 2312 EXPECT_TRUE(ProbablySameFilters( |
| 2313 builder.BuildGeneralFilter(), tester.last_filter())); |
2277 } | 2314 } |
2278 | 2315 |
2279 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) { | 2316 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) { |
2280 const ClearDomainReliabilityTester& tester = | 2317 const ClearDomainReliabilityTester& tester = |
2281 clear_domain_reliability_tester(); | 2318 clear_domain_reliability_tester(); |
2282 | 2319 |
2283 BlockUntilBrowsingDataRemoved(browsing_data::EVERYTHING, | 2320 BlockUntilBrowsingDataRemoved(browsing_data::EVERYTHING, |
2284 BrowsingDataRemover::REMOVE_COOKIES, false); | 2321 BrowsingDataRemover::REMOVE_COOKIES, false); |
2285 EXPECT_EQ(1u, tester.clear_count()); | 2322 EXPECT_EQ(1u, tester.clear_count()); |
2286 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); | 2323 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); |
| 2324 EXPECT_TRUE(ProbablySameFilters( |
| 2325 BrowsingDataFilterBuilder::BuildNoopFilter(), tester.last_filter())); |
| 2326 } |
| 2327 |
| 2328 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts_WithFilter) { |
| 2329 const ClearDomainReliabilityTester& tester = |
| 2330 clear_domain_reliability_tester(); |
| 2331 |
| 2332 RegistrableDomainFilterBuilder builder( |
| 2333 RegistrableDomainFilterBuilder::WHITELIST); |
| 2334 builder.AddRegisterableDomain(kTestRegisterableDomain1); |
| 2335 |
| 2336 BlockUntilOriginDataRemoved(browsing_data::EVERYTHING, |
| 2337 BrowsingDataRemover::REMOVE_COOKIES, builder); |
| 2338 EXPECT_EQ(1u, tester.clear_count()); |
| 2339 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); |
| 2340 EXPECT_TRUE(ProbablySameFilters( |
| 2341 builder.BuildGeneralFilter(), tester.last_filter())); |
2287 } | 2342 } |
2288 | 2343 |
2289 TEST_F(BrowsingDataRemoverTest, DomainReliability_ContextsWin) { | 2344 TEST_F(BrowsingDataRemoverTest, DomainReliability_ContextsWin) { |
2290 const ClearDomainReliabilityTester& tester = | 2345 const ClearDomainReliabilityTester& tester = |
2291 clear_domain_reliability_tester(); | 2346 clear_domain_reliability_tester(); |
2292 | 2347 |
2293 BlockUntilBrowsingDataRemoved( | 2348 BlockUntilBrowsingDataRemoved( |
2294 browsing_data::EVERYTHING, | 2349 browsing_data::EVERYTHING, |
2295 BrowsingDataRemover::REMOVE_HISTORY | BrowsingDataRemover::REMOVE_COOKIES, | 2350 BrowsingDataRemover::REMOVE_HISTORY | BrowsingDataRemover::REMOVE_COOKIES, |
2296 false); | 2351 false); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2528 BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate( | 2583 BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate( |
2529 host_content_settings_map, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, | 2584 host_content_settings_map, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
2530 base::Bind(&MatchPrimaryPattern, http_pattern)); | 2585 base::Bind(&MatchPrimaryPattern, http_pattern)); |
2531 // Verify we only have one, and it's url1. | 2586 // Verify we only have one, and it's url1. |
2532 host_content_settings_map->GetSettingsForOneType( | 2587 host_content_settings_map->GetSettingsForOneType( |
2533 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | 2588 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
2534 EXPECT_EQ(1u, host_settings.size()); | 2589 EXPECT_EQ(1u, host_settings.size()); |
2535 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), | 2590 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), |
2536 host_settings[0].primary_pattern); | 2591 host_settings[0].primary_pattern); |
2537 } | 2592 } |
OLD | NEW |