| 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..aef9d28c680eaf7ad85792754746316e6fc161ba 100644
|
| --- a/webkit/dom_storage/dom_storage_context_unittest.cc
|
| +++ b/webkit/dom_storage/dom_storage_context_unittest.cc
|
| @@ -51,6 +51,14 @@ class DomStorageContextTest : public testing::Test {
|
| MessageLoop::current()->RunAllPending();
|
| }
|
|
|
| + void RemoveDataSince(const base::Time& cutoff,
|
| + int origin_set_mask) {
|
| + // 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, origin_set_mask);
|
| + }
|
| +
|
| void VerifySingleOriginRemains(const GURL& origin) {
|
| // Use a new instance to examine the contexts of temp_dir_.
|
| scoped_refptr<DomStorageContext> context =
|
| @@ -58,7 +66,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 +87,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 +98,74 @@ 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(), quota::SpecialStoragePolicy::UNPROTECTED_WEB);
|
| + VerifySingleOriginRemains(kProtectedOrigin);
|
| +}
|
| +
|
| +TEST_F(DomStorageContextTest, RemoveNonextensionOriginData) {
|
| + const GURL kProtectedOrigin("http://www.protected.com/");
|
| + storage_policy_->AddProtected(kProtectedOrigin);
|
| + const GURL kExtensionOrigin("chrome-extension://abcdefghijklmnopqrstuvwxyz/");
|
| + storage_policy_->AddProtected(kExtensionOrigin);
|
| +
|
| + // Store data for a normal origin, a protected origin, and an extension, 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));
|
| + EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
|
| + OpenStorageArea(kExtensionOrigin)->SetItem(kKey, kValue, &old_value));
|
| + context_ = NULL;
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + RemoveDataSince(base::Time(),
|
| + quota::SpecialStoragePolicy::UNPROTECTED_WEB |
|
| + quota::SpecialStoragePolicy::PROTECTED_WEB);
|
| + VerifySingleOriginRemains(kExtensionOrigin);
|
| +}
|
| +
|
| +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(),
|
| + quota::SpecialStoragePolicy::UNPROTECTED_WEB |
|
| + quota::SpecialStoragePolicy::PROTECTED_WEB);
|
| +
|
| + // 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;
|
|
|