| Index: webkit/dom_storage/dom_storage_context_unittest.cc
|
| diff --git a/webkit/dom_storage/dom_storage_context_unittest.cc b/webkit/dom_storage/dom_storage_context_unittest.cc
|
| index da6a2ad970d0aa14608be1cd5cd54cf03ec6c38c..a098d0fd9b80ebceea3bf7b55e5306cf405e173c 100644
|
| --- a/webkit/dom_storage/dom_storage_context_unittest.cc
|
| +++ b/webkit/dom_storage/dom_storage_context_unittest.cc
|
| @@ -10,6 +10,7 @@
|
| #include "base/threading/sequenced_worker_pool.h"
|
| #include "base/time.h"
|
| #include "base/utf_string_conversions.h"
|
| +#include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "webkit/dom_storage/dom_storage_area.h"
|
| #include "webkit/dom_storage/dom_storage_context.h"
|
| @@ -51,6 +52,14 @@ class DomStorageContextTest : public testing::Test {
|
| MessageLoop::current()->RunAllPending();
|
| }
|
|
|
| + void RemoveDataSince(const base::Time& cutoff,
|
| + bool include_protected_origins) {
|
| + // Use a new instance to remove the contexts of temp_dir_.
|
| + scoped_refptr<DomStorageContext> context = new DomStorageContext(
|
| + temp_dir_.path(), FilePath(), storage_policy_, NULL);
|
| + context->DeleteDataModifiedSince(cutoff, include_protected_origins);
|
| + }
|
| +
|
| void VerifySingleOriginRemains(const GURL& origin) {
|
| // Use a new instance to examine the contexts of temp_dir_.
|
| scoped_refptr<DomStorageContext> context =
|
| @@ -58,7 +67,8 @@ class DomStorageContextTest : public testing::Test {
|
| std::vector<DomStorageContext::UsageInfo> infos;
|
| context->GetUsageInfo(&infos, kDontIncludeFileInfo);
|
| EXPECT_EQ(1u, infos.size());
|
| - EXPECT_EQ(origin, infos[0].origin);
|
| + if (infos.size() > 0)
|
| + EXPECT_EQ(origin, infos[0].origin);
|
| }
|
|
|
| protected:
|
| @@ -78,7 +88,7 @@ TEST_F(DomStorageContextTest, Basics) {
|
| EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get());
|
| context_->PurgeMemory();
|
| context_->DeleteOrigin(GURL("http://chromium.org/"));
|
| - context_->DeleteDataModifiedSince(base::Time::Now());
|
| + context_->DeleteDataModifiedSince(base::Time::Now(), false);
|
| const int kFirstSessionStorageNamespaceId = 1;
|
| EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId));
|
| EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId));
|
| @@ -89,6 +99,48 @@ TEST_F(DomStorageContextTest, Basics) {
|
| context_->Shutdown();
|
| }
|
|
|
| +TEST_F(DomStorageContextTest, RemoveUnprotectedOriginData) {
|
| + const GURL kProtectedOrigin("http://www.protected.com/");
|
| + storage_policy_->AddProtected(kProtectedOrigin);
|
| +
|
| + // Store data for a normal and a protected origin, then remove data since
|
| + // the epoch.
|
| + NullableString16 old_value;
|
| + EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
|
| + OpenStorageArea(kOrigin)->SetItem(kKey, kValue, &old_value));
|
| + EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
|
| + OpenStorageArea(kProtectedOrigin)->SetItem(kKey, kValue, &old_value));
|
| + context_ = NULL;
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + RemoveDataSince(base::Time(), false);
|
| + VerifySingleOriginRemains(kProtectedOrigin);
|
| +}
|
| +
|
| +TEST_F(DomStorageContextTest, RemoveProtectedOriginData) {
|
| + const GURL kProtectedOrigin("http://www.protected.com/");
|
| + storage_policy_->AddProtected(kProtectedOrigin);
|
| +
|
| + // Store data for a normal and a protected origin, then remove data since
|
| + // the epoch.
|
| + NullableString16 old_value;
|
| + EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
|
| + OpenStorageArea(kOrigin)->SetItem(kKey, kValue, &old_value));
|
| + EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
|
| + OpenStorageArea(kProtectedOrigin)->SetItem(kKey, kValue, &old_value));
|
| + context_ = NULL;
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + RemoveDataSince(base::Time(), true);
|
| +
|
| + // Create a new context that points to the same directory, see that
|
| + // both origins have been removed.
|
| + std::vector<DomStorageContext::UsageInfo> infos;
|
| + context_ = new DomStorageContext(temp_dir_.path(), FilePath(), NULL, NULL);
|
| + context_->GetUsageInfo(&infos, kDontIncludeFileInfo);
|
| + EXPECT_TRUE(infos.empty());
|
| +}
|
| +
|
| TEST_F(DomStorageContextTest, UsageInfo) {
|
| // Should be empty initially
|
| std::vector<DomStorageContext::UsageInfo> infos;
|
|
|