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

Unified Diff: content/browser/storage_partition_impl_unittest.cc

Issue 37843003: BrowsingDataRemover, (re)use StoragePartition deletion code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments form mkwst@. Created 7 years, 2 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
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 4828ae6529fccae29d94bd7ff6bf6c874fc0739e..7a1880b57fadd8178fcb36e8e01b376e9014a1d0 100644
--- a/content/browser/storage_partition_impl_unittest.cc
+++ b/content/browser/storage_partition_impl_unittest.cc
@@ -10,13 +10,43 @@
#include "content/browser/gpu/shader_disk_cache.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/browser/storage_partition.h"
+#include "content/public/test/test_browser_context.h"
+#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "net/base/test_completion_callback.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/browser/quota/mock_quota_manager.h"
+#include "webkit/browser/quota/mock_special_storage_policy.h"
+#include "webkit/browser/quota/quota_manager.h"
namespace content {
namespace {
+const int kDefaultClientId = 42;
+const char kCacheKey[] = "key";
+const char kCacheValue[] = "cached value";
+
+const char kTestOrigin1[] = "http://host1:1/";
+const char kTestOrigin2[] = "http://host2:1/";
+const char kTestOrigin3[] = "http://host3:1/";
+const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
+
+const GURL kOrigin1(kTestOrigin1);
+const GURL kOrigin2(kTestOrigin2);
+const GURL kOrigin3(kTestOrigin3);
+const GURL kOriginDevTools(kTestOriginDevTools);
+
+const quota::StorageType kTemporary = quota::kStorageTypeTemporary;
+const quota::StorageType kPersistent = quota::kStorageTypePersistent;
+
+const quota::QuotaClient::ID kClientFile = quota::QuotaClient::kFileSystem;
+
+const uint32 kAllQuotaRemoveMask =
+ StoragePartition::REMOVE_DATA_MASK_INDEXEDDB |
+ StoragePartition::REMOVE_DATA_MASK_WEBSQL |
+ StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
+ StoragePartition::REMOVE_DATA_MASK_APPCACHE;
+
class TestClosureCallback {
public:
TestClosureCallback()
@@ -42,12 +72,97 @@ class TestClosureCallback {
DISALLOW_COPY_AND_ASSIGN(TestClosureCallback);
};
-const int kDefaultClientId = 42;
-const char kCacheKey[] = "key";
-const char kCacheValue[] = "cached value";
+bool DoesOriginMatchForUnprotectedWeb(
+ const GURL& origin,
+ quota::SpecialStoragePolicy* special_storage_policy) {
+ // This is used for tests where we are clearing UNPROTECTED_WEB data.
+ return !special_storage_policy->IsStorageProtected(origin.GetOrigin());
+}
+
+bool DoesOriginMatchForBothProtectedAndUnprotectedWeb(
+ const GURL& origin,
+ quota::SpecialStoragePolicy* special_storage_policy) {
+ return true;
+}
+
+bool DoesOriginMatchUnprotected(
+ const GURL& origin,
+ quota::SpecialStoragePolicy* special_storage_policy) {
+ return origin.GetOrigin().scheme() != kOriginDevTools.scheme();
+}
+
+void ClearQuotaData(content::StoragePartition* storage_partition,
+ const base::Closure& cb) {
+ storage_partition->ClearDataForRange(
+ kAllQuotaRemoveMask,
+ StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
+ base::Time(), base::Time::Max(), cb);
+}
+
+void ClearQuotaDataWithOriginMatcher(
+ content::StoragePartition* storage_partition,
+ const GURL& remove_origin,
+ const StoragePartition::OriginMatcherFunction& origin_matcher,
+ const base::Time delete_begin,
+ const base::Closure& cb) {
+ storage_partition->ClearDataForOriginWithinRange(
+ kAllQuotaRemoveMask, StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
+ remove_origin, origin_matcher,
+ delete_begin, base::Time::Max(), cb);
+}
+
+void ClearQuotaDataForOrigin(
+ content::StoragePartition* storage_partition,
+ const GURL& remove_origin,
+ const base::Time delete_begin,
+ const base::Closure& cb) {
+ ClearQuotaDataWithOriginMatcher(
+ storage_partition, remove_origin,
+ StoragePartition::OriginMatcherFunction(), delete_begin, cb);
+}
+
+void ClearQuotaDataForNonPersistent(
+ content::StoragePartition* storage_partition,
+ const base::Time delete_begin,
+ const base::Closure& cb) {
+ uint32 quota_storage_remove_mask_no_persistent =
+ StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL &
+ ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
+ storage_partition->ClearDataForRange(
+ kAllQuotaRemoveMask, quota_storage_remove_mask_no_persistent,
+ delete_begin, base::Time::Max(), cb);
+}
} // namespace
+class StoragePartitionImplTest : public testing::Test {
+ public:
+ StoragePartitionImplTest()
+ : browser_context_(new TestBrowserContext()),
+ thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
+ }
+ virtual ~StoragePartitionImplTest() {}
+
+ quota::MockQuotaManager* GetMockManager() {
+ if (!quota_manager_.get()) {
+ quota_manager_ = new quota::MockQuotaManager(
+ browser_context_->IsOffTheRecord(),
+ browser_context_->GetPath(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(),
+ browser_context_->GetSpecialStoragePolicy());
+ }
+ return quota_manager_.get();
+ }
+
+ private:
+ scoped_ptr<TestBrowserContext> browser_context_;
+ scoped_refptr<quota::MockQuotaManager> quota_manager_;
+ content::TestBrowserThreadBundle thread_bundle_;
+
+ DISALLOW_COPY_AND_ASSIGN(StoragePartitionImplTest);
+};
+
class StoragePartitionShaderClearTest : public testing::Test {
public:
StoragePartitionShaderClearTest()
@@ -109,12 +224,392 @@ TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) {
EXPECT_EQ(1u, Size());
TestClosureCallback clear_cb;
- StoragePartitionImpl sp(
- cache_path(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ StoragePartitionImpl storage_partition(
+ cache_path(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(&ClearData, &sp, clear_cb.callback()));
+ FROM_HERE, base::Bind(&ClearData, &storage_partition,
+ clear_cb.callback()));
clear_cb.WaitForResult();
EXPECT_EQ(0u, Size());
}
+TEST_F(StoragePartitionImplTest, QuotaClientMaskGeneration) {
+ EXPECT_EQ(quota::QuotaClient::kFileSystem,
+ StoragePartitionImpl::GenerateQuotaClientMask(
+ StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS));
+ EXPECT_EQ(quota::QuotaClient::kDatabase,
+ StoragePartitionImpl::GenerateQuotaClientMask(
+ StoragePartition::REMOVE_DATA_MASK_WEBSQL));
+ EXPECT_EQ(quota::QuotaClient::kAppcache,
+ StoragePartitionImpl::GenerateQuotaClientMask(
+ StoragePartition::REMOVE_DATA_MASK_APPCACHE));
+ EXPECT_EQ(quota::QuotaClient::kIndexedDatabase,
+ StoragePartitionImpl::GenerateQuotaClientMask(
+ StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
+ EXPECT_EQ(quota::QuotaClient::kFileSystem |
+ quota::QuotaClient::kDatabase |
+ quota::QuotaClient::kAppcache |
+ quota::QuotaClient::kIndexedDatabase,
+ StoragePartitionImpl::GenerateQuotaClientMask(
+ StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
+ StoragePartition::REMOVE_DATA_MASK_WEBSQL |
+ StoragePartition::REMOVE_DATA_MASK_APPCACHE |
+ StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
+}
+
+void PopulateTestQuotaManagedPersistentData(quota::MockQuotaManager* manager) {
+ manager->AddOrigin(kOrigin2, kPersistent, kClientFile, base::Time());
+ manager->AddOrigin(kOrigin3, kPersistent, kClientFile,
+ base::Time::Now() - base::TimeDelta::FromDays(1));
+
+ EXPECT_FALSE(manager->OriginHasData(kOrigin1, kPersistent, kClientFile));
+ EXPECT_TRUE(manager->OriginHasData(kOrigin2, kPersistent, kClientFile));
+ EXPECT_TRUE(manager->OriginHasData(kOrigin3, kPersistent, kClientFile));
+}
+
+void PopulateTestQuotaManagedTemporaryData(quota::MockQuotaManager* manager) {
+ manager->AddOrigin(kOrigin1, kTemporary, kClientFile, base::Time::Now());
+ manager->AddOrigin(kOrigin3, kTemporary, kClientFile,
+ base::Time::Now() - base::TimeDelta::FromDays(1));
+
+ EXPECT_TRUE(manager->OriginHasData(kOrigin1, kTemporary, kClientFile));
+ EXPECT_FALSE(manager->OriginHasData(kOrigin2, kTemporary, kClientFile));
+ EXPECT_TRUE(manager->OriginHasData(kOrigin3, kTemporary, kClientFile));
+}
+
+void PopulateTestQuotaManagedData(quota::MockQuotaManager* manager) {
+ // Set up kOrigin1 with a temporary quota, kOrigin2 with a persistent
+ // quota, and kOrigin3 with both. kOrigin1 is modified now, kOrigin2
+ // is modified at the beginning of time, and kOrigin3 is modified one day
+ // ago.
+ PopulateTestQuotaManagedPersistentData(manager);
+ PopulateTestQuotaManagedTemporaryData(manager);
+}
+
+void PopulateTestQuotaManagedNonBrowsingData(quota::MockQuotaManager* manager) {
+ manager->AddOrigin(kOriginDevTools, kTemporary, kClientFile, base::Time());
+ manager->AddOrigin(kOriginDevTools, kPersistent, kClientFile, base::Time());
+}
+
+TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverBoth) {
+ PopulateTestQuotaManagedData(GetMockManager());
+
+ TestClosureCallback clear_cb;
+ StoragePartitionImpl sp(
+ base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
+ GetMockManager());
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&ClearQuotaData, &sp, clear_cb.callback()));
+ clear_cb.WaitForResult();
+
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
+ kClientFile));
+}
+
+TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
+ PopulateTestQuotaManagedTemporaryData(GetMockManager());
+
+ TestClosureCallback clear_cb;
+ StoragePartitionImpl sp(
+ base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
+ GetMockManager());
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&ClearQuotaData, &sp, clear_cb.callback()));
+ clear_cb.WaitForResult();
+
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
+ kClientFile));
+}
+
+TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
+ PopulateTestQuotaManagedPersistentData(GetMockManager());
+
+ TestClosureCallback clear_cb;
+ StoragePartitionImpl sp(
+ base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
+ GetMockManager());
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&ClearQuotaData, &sp, clear_cb.callback()));
+ clear_cb.WaitForResult();
+
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
+ kClientFile));
+}
+
+TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverNeither) {
+ TestClosureCallback clear_cb;
+ StoragePartitionImpl sp(
+ base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
+ GetMockManager());
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&ClearQuotaData, &sp, clear_cb.callback()));
+ clear_cb.WaitForResult();
+
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
+ kClientFile));
+}
+
+TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
+ PopulateTestQuotaManagedData(GetMockManager());
+
+ TestClosureCallback clear_cb;
+ StoragePartitionImpl sp(
+ base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
+ GetMockManager());
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&ClearQuotaDataForOrigin,
+ &sp, kOrigin1, base::Time(), clear_cb.callback()));
+ clear_cb.WaitForResult();
+
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
+ kClientFile));
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
+ kClientFile));
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
+ kClientFile));
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
+ kClientFile));
+}
+
+TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastHour) {
+ PopulateTestQuotaManagedData(GetMockManager());
+
+ TestClosureCallback clear_cb;
+ StoragePartitionImpl sp(
+ base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
+ GetMockManager());
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&ClearQuotaDataForOrigin,
+ &sp, GURL(),
+ base::Time::Now() - base::TimeDelta::FromHours(1),
+ clear_cb.callback()));
+ clear_cb.WaitForResult();
+
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
+ kClientFile));
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
+ kClientFile));
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
+ kClientFile));
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
+ kClientFile));
+}
+
+TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastWeek) {
+ PopulateTestQuotaManagedData(GetMockManager());
+
+ TestClosureCallback clear_cb;
+ StoragePartitionImpl sp(
+ base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
+ GetMockManager());
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&ClearQuotaDataForNonPersistent,
+ &sp,
+ base::Time::Now() - base::TimeDelta::FromDays(7),
+ clear_cb.callback()));
+ clear_cb.WaitForResult();
+
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
+ kClientFile));
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
+ kClientFile));
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
+ kClientFile));
+}
+
+TEST_F(StoragePartitionImplTest, RemoveQuotaManagedUnprotectedOrigins) {
+ // Protect kOrigin1.
+ scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy =
+ new quota::MockSpecialStoragePolicy;
+ mock_policy->AddProtected(kOrigin1.GetOrigin());
+
+ PopulateTestQuotaManagedData(GetMockManager());
+
+ TestClosureCallback clear_cb;
+ StoragePartitionImpl sp(
+ base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
+ GetMockManager());
+ static_cast<StoragePartitionImpl*>(
+ &sp)->OverrideSpecialStoragePolicyForTesting(mock_policy);
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher,
+ &sp, GURL(),
+ base::Bind(&DoesOriginMatchForUnprotectedWeb),
+ base::Time(), clear_cb.callback()));
+ clear_cb.WaitForResult();
+
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
+ kClientFile));
+}
+
+TEST_F(StoragePartitionImplTest, RemoveQuotaManagedProtectedSpecificOrigin) {
+ // Protect kOrigin1.
+ scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy =
+ new quota::MockSpecialStoragePolicy;
+ mock_policy->AddProtected(kOrigin1.GetOrigin());
+
+ PopulateTestQuotaManagedData(GetMockManager());
+
+ TestClosureCallback clear_cb;
+ StoragePartitionImpl sp(
+ base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
+ GetMockManager());
+ static_cast<StoragePartitionImpl*>(
+ &sp)->OverrideSpecialStoragePolicyForTesting(mock_policy);
+
+ // Try to remove kOrigin1. Expect failure.
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher,
+ &sp, kOrigin1,
+ base::Bind(&DoesOriginMatchForUnprotectedWeb),
+ base::Time(), clear_cb.callback()));
+ clear_cb.WaitForResult();
+
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
+ kClientFile));
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
+ kClientFile));
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
+ kClientFile));
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
+ kClientFile));
+}
+
+TEST_F(StoragePartitionImplTest, RemoveQuotaManagedProtectedOrigins) {
+ // Protect kOrigin1.
+ scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy =
+ new quota::MockSpecialStoragePolicy;
+ mock_policy->AddProtected(kOrigin1.GetOrigin());
+
+ PopulateTestQuotaManagedData(GetMockManager());
+
+ // Try to remove kOrigin1. Expect success.
+ TestClosureCallback clear_cb;
+ StoragePartitionImpl sp(
+ base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
+ GetMockManager());
+ static_cast<StoragePartitionImpl*>(
+ &sp)->OverrideSpecialStoragePolicyForTesting(mock_policy);
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&ClearQuotaDataWithOriginMatcher,
+ &sp, GURL(),
+ base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb),
+ base::Time(), clear_cb.callback()));
+ clear_cb.WaitForResult();
+
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
+ kClientFile));
+ EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
+ kClientFile));
+}
+
+TEST_F(StoragePartitionImplTest, RemoveQuotaManagedIgnoreDevTools) {
+ PopulateTestQuotaManagedNonBrowsingData(GetMockManager());
+
+ TestClosureCallback clear_cb;
+ StoragePartitionImpl sp(
+ base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
+ GetMockManager());
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher,
+ &sp, GURL(),
+ base::Bind(&DoesOriginMatchUnprotected),
+ base::Time(), clear_cb.callback()));
+ clear_cb.WaitForResult();
+
+ // Check that devtools data isn't removed.
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kTemporary,
+ kClientFile));
+ EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kPersistent,
+ kClientFile));
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698