OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 const storage::StorageType kPersistent = storage::kStorageTypePersistent; | 59 const storage::StorageType kPersistent = storage::kStorageTypePersistent; |
60 | 60 |
61 const storage::QuotaClient::ID kClientFile = storage::QuotaClient::kFileSystem; | 61 const storage::QuotaClient::ID kClientFile = storage::QuotaClient::kFileSystem; |
62 | 62 |
63 const uint32_t kAllQuotaRemoveMask = | 63 const uint32_t kAllQuotaRemoveMask = |
64 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | 64 StoragePartition::REMOVE_DATA_MASK_APPCACHE | |
65 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | 65 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | |
66 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | | 66 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | |
67 StoragePartition::REMOVE_DATA_MASK_WEBSQL; | 67 StoragePartition::REMOVE_DATA_MASK_WEBSQL; |
68 | 68 |
| 69 bool AlwaysTrueCookiePredicate(const net::CanonicalCookie& cookie) { |
| 70 return true; |
| 71 } |
| 72 |
| 73 bool AlwaysFalseCookiePredicate(const net::CanonicalCookie& cookie) { |
| 74 return false; |
| 75 } |
| 76 |
69 class AwaitCompletionHelper { | 77 class AwaitCompletionHelper { |
70 public: | 78 public: |
71 AwaitCompletionHelper() : start_(false), already_quit_(false) {} | 79 AwaitCompletionHelper() : start_(false), already_quit_(false) {} |
72 virtual ~AwaitCompletionHelper() {} | 80 virtual ~AwaitCompletionHelper() {} |
73 | 81 |
74 void BlockUntilNotified() { | 82 void BlockUntilNotified() { |
75 if (!already_quit_) { | 83 if (!already_quit_) { |
76 DCHECK(!start_); | 84 DCHECK(!start_); |
77 start_ = true; | 85 start_ = true; |
78 base::MessageLoop::current()->Run(); | 86 base::MessageLoop::current()->Run(); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 const base::Time delete_begin, | 299 const base::Time delete_begin, |
292 const base::Time delete_end, | 300 const base::Time delete_end, |
293 base::RunLoop* run_loop) { | 301 base::RunLoop* run_loop) { |
294 partition->ClearData( | 302 partition->ClearData( |
295 StoragePartition::REMOVE_DATA_MASK_COOKIES, | 303 StoragePartition::REMOVE_DATA_MASK_COOKIES, |
296 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 304 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
297 GURL(), StoragePartition::OriginMatcherFunction(), | 305 GURL(), StoragePartition::OriginMatcherFunction(), |
298 delete_begin, delete_end, run_loop->QuitClosure()); | 306 delete_begin, delete_end, run_loop->QuitClosure()); |
299 } | 307 } |
300 | 308 |
| 309 void ClearCookiesWithMatcher( |
| 310 content::StoragePartition* partition, |
| 311 const base::Time delete_begin, |
| 312 const base::Time delete_end, |
| 313 const StoragePartition::CookieMatcherFunction& cookie_matcher, |
| 314 base::RunLoop* run_loop) { |
| 315 partition->ClearData(StoragePartition::REMOVE_DATA_MASK_COOKIES, |
| 316 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 317 StoragePartition::OriginMatcherFunction(), |
| 318 cookie_matcher, delete_begin, delete_end, |
| 319 run_loop->QuitClosure()); |
| 320 } |
| 321 |
301 void ClearStuff(uint32_t remove_mask, | 322 void ClearStuff(uint32_t remove_mask, |
302 content::StoragePartition* partition, | 323 content::StoragePartition* partition, |
303 const base::Time delete_begin, | 324 const base::Time delete_begin, |
304 const base::Time delete_end, | 325 const base::Time delete_end, |
305 const StoragePartition::OriginMatcherFunction& origin_matcher, | 326 const StoragePartition::OriginMatcherFunction& origin_matcher, |
306 base::RunLoop* run_loop) { | 327 base::RunLoop* run_loop) { |
307 partition->ClearData( | 328 partition->ClearData( |
308 remove_mask, StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 329 remove_mask, StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
309 GURL(), origin_matcher, delete_begin, delete_end, | 330 GURL(), origin_matcher, delete_begin, delete_end, |
310 run_loop->QuitClosure()); | 331 run_loop->QuitClosure()); |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 | 840 |
820 base::RunLoop run_loop; | 841 base::RunLoop run_loop; |
821 base::ThreadTaskRunnerHandle::Get()->PostTask( | 842 base::ThreadTaskRunnerHandle::Get()->PostTask( |
822 FROM_HERE, base::Bind(&ClearCookies, partition, an_hour_ago, | 843 FROM_HERE, base::Bind(&ClearCookies, partition, an_hour_ago, |
823 base::Time::Max(), &run_loop)); | 844 base::Time::Max(), &run_loop)); |
824 run_loop.Run(); | 845 run_loop.Run(); |
825 | 846 |
826 EXPECT_FALSE(tester.ContainsCookie()); | 847 EXPECT_FALSE(tester.ContainsCookie()); |
827 } | 848 } |
828 | 849 |
| 850 TEST_F(StoragePartitionImplTest, RemoveCookieWithMatcher) { |
| 851 RemoveCookieTester tester(browser_context()); |
| 852 StoragePartition::CookieMatcherFunction true_predicate = |
| 853 base::Bind(&AlwaysTrueCookiePredicate); |
| 854 |
| 855 StoragePartition::CookieMatcherFunction false_predicate = |
| 856 base::Bind(&AlwaysFalseCookiePredicate); |
| 857 |
| 858 tester.AddCookie(); |
| 859 ASSERT_TRUE(tester.ContainsCookie()); |
| 860 |
| 861 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
| 862 BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 863 partition->SetURLRequestContext(browser_context()->GetRequestContext()); |
| 864 |
| 865 // Return false from our predicate, and make sure the cookies is still around. |
| 866 base::RunLoop run_loop; |
| 867 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 868 FROM_HERE, base::Bind(&ClearCookiesWithMatcher, partition, base::Time(), |
| 869 base::Time::Max(), false_predicate, &run_loop)); |
| 870 run_loop.RunUntilIdle(); |
| 871 EXPECT_TRUE(tester.ContainsCookie()); |
| 872 |
| 873 // Now we return true from our predicate. |
| 874 base::RunLoop run_loop2; |
| 875 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 876 FROM_HERE, base::Bind(&ClearCookiesWithMatcher, partition, base::Time(), |
| 877 base::Time::Max(), true_predicate, &run_loop2)); |
| 878 run_loop2.RunUntilIdle(); |
| 879 EXPECT_FALSE(tester.ContainsCookie()); |
| 880 } |
| 881 |
829 TEST_F(StoragePartitionImplTest, RemoveUnprotectedLocalStorageForever) { | 882 TEST_F(StoragePartitionImplTest, RemoveUnprotectedLocalStorageForever) { |
830 // Protect kOrigin1. | 883 // Protect kOrigin1. |
831 scoped_refptr<MockSpecialStoragePolicy> mock_policy = | 884 scoped_refptr<MockSpecialStoragePolicy> mock_policy = |
832 new MockSpecialStoragePolicy; | 885 new MockSpecialStoragePolicy; |
833 mock_policy->AddProtected(kOrigin1.GetOrigin()); | 886 mock_policy->AddProtected(kOrigin1.GetOrigin()); |
834 | 887 |
835 RemoveLocalStorageTester tester(browser_context()); | 888 RemoveLocalStorageTester tester(browser_context()); |
836 | 889 |
837 tester.AddDOMStorageTestData(); | 890 tester.AddDOMStorageTestData(); |
838 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1)); | 891 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 &run_loop)); | 966 &run_loop)); |
914 run_loop.Run(); | 967 run_loop.Run(); |
915 | 968 |
916 // kOrigin1 and kOrigin2 do not have age more than a week. | 969 // kOrigin1 and kOrigin2 do not have age more than a week. |
917 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); | 970 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
918 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); | 971 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); |
919 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); | 972 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
920 } | 973 } |
921 | 974 |
922 } // namespace content | 975 } // namespace content |
OLD | NEW |