Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: content/browser/storage_partition_impl_unittest.cc

Issue 1741123002: Add removal filter support for Cookies, Storage, and Content Settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Android Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/storage_partition_impl.cc ('k') | content/public/browser/storage_partition.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 const storage::StorageType kPersistent = storage::kStorageTypePersistent; 62 const storage::StorageType kPersistent = storage::kStorageTypePersistent;
63 63
64 const storage::QuotaClient::ID kClientFile = storage::QuotaClient::kFileSystem; 64 const storage::QuotaClient::ID kClientFile = storage::QuotaClient::kFileSystem;
65 65
66 const uint32_t kAllQuotaRemoveMask = 66 const uint32_t kAllQuotaRemoveMask =
67 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 67 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
68 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 68 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
69 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | 69 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB |
70 StoragePartition::REMOVE_DATA_MASK_WEBSQL; 70 StoragePartition::REMOVE_DATA_MASK_WEBSQL;
71 71
72 bool AlwaysTrueCookiePredicate(const net::CanonicalCookie& cookie) {
73 return true;
74 }
75
76 bool AlwaysFalseCookiePredicate(const net::CanonicalCookie& cookie) {
77 return false;
78 }
79
72 class AwaitCompletionHelper { 80 class AwaitCompletionHelper {
73 public: 81 public:
74 AwaitCompletionHelper() : start_(false), already_quit_(false) {} 82 AwaitCompletionHelper() : start_(false), already_quit_(false) {}
75 virtual ~AwaitCompletionHelper() {} 83 virtual ~AwaitCompletionHelper() {}
76 84
77 void BlockUntilNotified() { 85 void BlockUntilNotified() {
78 if (!already_quit_) { 86 if (!already_quit_) {
79 DCHECK(!start_); 87 DCHECK(!start_);
80 start_ = true; 88 start_ = true;
81 base::MessageLoop::current()->Run(); 89 base::MessageLoop::current()->Run();
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 const base::Time delete_begin, 302 const base::Time delete_begin,
295 const base::Time delete_end, 303 const base::Time delete_end,
296 base::RunLoop* run_loop) { 304 base::RunLoop* run_loop) {
297 partition->ClearData( 305 partition->ClearData(
298 StoragePartition::REMOVE_DATA_MASK_COOKIES, 306 StoragePartition::REMOVE_DATA_MASK_COOKIES,
299 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, 307 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
300 GURL(), StoragePartition::OriginMatcherFunction(), 308 GURL(), StoragePartition::OriginMatcherFunction(),
301 delete_begin, delete_end, run_loop->QuitClosure()); 309 delete_begin, delete_end, run_loop->QuitClosure());
302 } 310 }
303 311
312 void ClearCookiesWithMatcher(
313 content::StoragePartition* partition,
314 const base::Time delete_begin,
315 const base::Time delete_end,
316 const StoragePartition::CookieMatcherFunction& cookie_matcher,
317 base::RunLoop* run_loop) {
318 partition->ClearData(StoragePartition::REMOVE_DATA_MASK_COOKIES,
319 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
320 StoragePartition::OriginMatcherFunction(),
321 cookie_matcher, delete_begin, delete_end,
322 run_loop->QuitClosure());
323 }
324
304 void ClearStuff(uint32_t remove_mask, 325 void ClearStuff(uint32_t remove_mask,
305 content::StoragePartition* partition, 326 content::StoragePartition* partition,
306 const base::Time delete_begin, 327 const base::Time delete_begin,
307 const base::Time delete_end, 328 const base::Time delete_end,
308 const StoragePartition::OriginMatcherFunction& origin_matcher, 329 const StoragePartition::OriginMatcherFunction& origin_matcher,
309 base::RunLoop* run_loop) { 330 base::RunLoop* run_loop) {
310 partition->ClearData( 331 partition->ClearData(
311 remove_mask, StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, 332 remove_mask, StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
312 GURL(), origin_matcher, delete_begin, delete_end, 333 GURL(), origin_matcher, delete_begin, delete_end,
313 run_loop->QuitClosure()); 334 run_loop->QuitClosure());
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 843
823 base::RunLoop run_loop; 844 base::RunLoop run_loop;
824 base::ThreadTaskRunnerHandle::Get()->PostTask( 845 base::ThreadTaskRunnerHandle::Get()->PostTask(
825 FROM_HERE, base::Bind(&ClearCookies, partition, an_hour_ago, 846 FROM_HERE, base::Bind(&ClearCookies, partition, an_hour_ago,
826 base::Time::Max(), &run_loop)); 847 base::Time::Max(), &run_loop));
827 run_loop.Run(); 848 run_loop.Run();
828 849
829 EXPECT_FALSE(tester.ContainsCookie()); 850 EXPECT_FALSE(tester.ContainsCookie());
830 } 851 }
831 852
853 TEST_F(StoragePartitionImplTest, RemoveCookieWithMatcher) {
854 RemoveCookieTester tester(browser_context());
855 StoragePartition::CookieMatcherFunction true_predicate =
856 base::Bind(&AlwaysTrueCookiePredicate);
857
858 StoragePartition::CookieMatcherFunction false_predicate =
859 base::Bind(&AlwaysFalseCookiePredicate);
860
861 tester.AddCookie();
862 ASSERT_TRUE(tester.ContainsCookie());
863
864 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
865 BrowserContext::GetDefaultStoragePartition(browser_context()));
866 partition->SetURLRequestContext(browser_context()->GetRequestContext());
867
868 // Return false from our predicate, and make sure the cookies is still around.
869 base::RunLoop run_loop;
870 base::ThreadTaskRunnerHandle::Get()->PostTask(
871 FROM_HERE, base::Bind(&ClearCookiesWithMatcher, partition, base::Time(),
872 base::Time::Max(), false_predicate, &run_loop));
873 run_loop.RunUntilIdle();
874 EXPECT_TRUE(tester.ContainsCookie());
875
876 // Now we return true from our predicate.
877 base::RunLoop run_loop2;
878 base::ThreadTaskRunnerHandle::Get()->PostTask(
879 FROM_HERE, base::Bind(&ClearCookiesWithMatcher, partition, base::Time(),
880 base::Time::Max(), true_predicate, &run_loop2));
881 run_loop2.RunUntilIdle();
882 EXPECT_FALSE(tester.ContainsCookie());
883 }
884
832 TEST_F(StoragePartitionImplTest, RemoveUnprotectedLocalStorageForever) { 885 TEST_F(StoragePartitionImplTest, RemoveUnprotectedLocalStorageForever) {
833 // Protect kOrigin1. 886 // Protect kOrigin1.
834 scoped_refptr<MockSpecialStoragePolicy> mock_policy = 887 scoped_refptr<MockSpecialStoragePolicy> mock_policy =
835 new MockSpecialStoragePolicy; 888 new MockSpecialStoragePolicy;
836 mock_policy->AddProtected(kOrigin1.GetOrigin()); 889 mock_policy->AddProtected(kOrigin1.GetOrigin());
837 890
838 RemoveLocalStorageTester tester(browser_context()); 891 RemoveLocalStorageTester tester(browser_context());
839 892
840 tester.AddDOMStorageTestData(); 893 tester.AddDOMStorageTestData();
841 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1)); 894 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1));
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options)); 997 CanonicalCookie::Create(url2, "A=B;domain=.example.com", now, options));
945 invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options)); 998 invalid_cookies.push_back(CanonicalCookie::Create(url3, "A=B", now, options));
946 999
947 for (const auto& cookie : valid_cookies) 1000 for (const auto& cookie : valid_cookies)
948 EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString(); 1001 EXPECT_TRUE(predicate.Run(*cookie)) << cookie->DebugString();
949 for (const auto& cookie : invalid_cookies) 1002 for (const auto& cookie : invalid_cookies)
950 EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString(); 1003 EXPECT_FALSE(predicate.Run(*cookie)) << cookie->DebugString();
951 } 1004 }
952 1005
953 } // namespace content 1006 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/storage_partition_impl.cc ('k') | content/public/browser/storage_partition.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698