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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/storage_partition_impl_unittest.cc
diff --git a/content/browser/storage_partition_impl_unittest.cc b/content/browser/storage_partition_impl_unittest.cc
index 22f0185fee2e586b6d9ee7dea5cf15c8f7710135..b386109b747238275a83a8da73ed5203fba457d2 100644
--- a/content/browser/storage_partition_impl_unittest.cc
+++ b/content/browser/storage_partition_impl_unittest.cc
@@ -69,6 +69,14 @@ const uint32_t kAllQuotaRemoveMask =
StoragePartition::REMOVE_DATA_MASK_INDEXEDDB |
StoragePartition::REMOVE_DATA_MASK_WEBSQL;
+bool AlwaysTrueCookiePredicate(const net::CanonicalCookie& cookie) {
+ return true;
+}
+
+bool AlwaysFalseCookiePredicate(const net::CanonicalCookie& cookie) {
+ return false;
+}
+
class AwaitCompletionHelper {
public:
AwaitCompletionHelper() : start_(false), already_quit_(false) {}
@@ -301,6 +309,19 @@ void ClearCookies(content::StoragePartition* partition,
delete_begin, delete_end, run_loop->QuitClosure());
}
+void ClearCookiesWithMatcher(
+ content::StoragePartition* partition,
+ const base::Time delete_begin,
+ const base::Time delete_end,
+ const StoragePartition::CookieMatcherFunction& cookie_matcher,
+ base::RunLoop* run_loop) {
+ partition->ClearData(StoragePartition::REMOVE_DATA_MASK_COOKIES,
+ StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
+ StoragePartition::OriginMatcherFunction(),
+ cookie_matcher, delete_begin, delete_end,
+ run_loop->QuitClosure());
+}
+
void ClearStuff(uint32_t remove_mask,
content::StoragePartition* partition,
const base::Time delete_begin,
@@ -829,6 +850,38 @@ TEST_F(StoragePartitionImplTest, RemoveCookieLastHour) {
EXPECT_FALSE(tester.ContainsCookie());
}
+TEST_F(StoragePartitionImplTest, RemoveCookieWithMatcher) {
+ RemoveCookieTester tester(browser_context());
+ StoragePartition::CookieMatcherFunction true_predicate =
+ base::Bind(&AlwaysTrueCookiePredicate);
+
+ StoragePartition::CookieMatcherFunction false_predicate =
+ base::Bind(&AlwaysFalseCookiePredicate);
+
+ tester.AddCookie();
+ ASSERT_TRUE(tester.ContainsCookie());
+
+ StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
+ BrowserContext::GetDefaultStoragePartition(browser_context()));
+ partition->SetURLRequestContext(browser_context()->GetRequestContext());
+
+ // Return false from our predicate, and make sure the cookies is still around.
+ base::RunLoop run_loop;
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&ClearCookiesWithMatcher, partition, base::Time(),
+ base::Time::Max(), false_predicate, &run_loop));
+ run_loop.RunUntilIdle();
+ EXPECT_TRUE(tester.ContainsCookie());
+
+ // Now we return true from our predicate.
+ base::RunLoop run_loop2;
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&ClearCookiesWithMatcher, partition, base::Time(),
+ base::Time::Max(), true_predicate, &run_loop2));
+ run_loop2.RunUntilIdle();
+ EXPECT_FALSE(tester.ContainsCookie());
+}
+
TEST_F(StoragePartitionImplTest, RemoveUnprotectedLocalStorageForever) {
// Protect kOrigin1.
scoped_refptr<MockSpecialStoragePolicy> mock_policy =
« 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