Chromium Code Reviews| 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..e6c1028c051e7944ce3e9272f8b44b624354b7fe 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 content::StoragePartition::CookieMatcherFunction& cookie_matcher, |
|
michaeln
2016/03/09 20:25:51
content:: not needed?
dmurph
2016/03/10 23:00:11
Done.
|
| + 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 = |