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 e4b790967b284bb02f743cdb696c7123c4fff752..4822c208705c4f1cb7821c782dd210d059d07729 100644 |
--- a/content/browser/storage_partition_impl_unittest.cc |
+++ b/content/browser/storage_partition_impl_unittest.cc |
@@ -66,6 +66,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) {} |
@@ -298,6 +306,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, |
@@ -826,6 +847,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 = |