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

Side by Side Diff: webkit/dom_storage/dom_storage_context_unittest.cc

Issue 10413072: Teaching BrowsingDataRemover how to delete application data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webkit/dom_storage/dom_storage_area.h" 15 #include "webkit/dom_storage/dom_storage_area.h"
15 #include "webkit/dom_storage/dom_storage_context.h" 16 #include "webkit/dom_storage/dom_storage_context.h"
16 #include "webkit/dom_storage/dom_storage_namespace.h" 17 #include "webkit/dom_storage/dom_storage_namespace.h"
17 #include "webkit/dom_storage/dom_storage_task_runner.h" 18 #include "webkit/dom_storage/dom_storage_task_runner.h"
18 #include "webkit/dom_storage/dom_storage_types.h" 19 #include "webkit/dom_storage/dom_storage_types.h"
19 #include "webkit/quota/mock_special_storage_policy.h" 20 #include "webkit/quota/mock_special_storage_policy.h"
20 21
21 namespace dom_storage { 22 namespace dom_storage {
22 23
(...skipping 21 matching lines...) Expand all
44 context_ = new DomStorageContext(temp_dir_.path(), 45 context_ = new DomStorageContext(temp_dir_.path(),
45 FilePath(), 46 FilePath(),
46 storage_policy_, 47 storage_policy_,
47 task_runner_); 48 task_runner_);
48 } 49 }
49 50
50 virtual void TearDown() { 51 virtual void TearDown() {
51 MessageLoop::current()->RunAllPending(); 52 MessageLoop::current()->RunAllPending();
52 } 53 }
53 54
55 void RemoveDataSince(const base::Time& cutoff,
56 bool include_protected_origins) {
57 // Use a new instance to remove the contexts of temp_dir_.
58 scoped_refptr<DomStorageContext> context = new DomStorageContext(
59 temp_dir_.path(), FilePath(), storage_policy_, NULL);
60 context->DeleteDataModifiedSince(cutoff, include_protected_origins);
61 }
62
54 void VerifySingleOriginRemains(const GURL& origin) { 63 void VerifySingleOriginRemains(const GURL& origin) {
55 // Use a new instance to examine the contexts of temp_dir_. 64 // Use a new instance to examine the contexts of temp_dir_.
56 scoped_refptr<DomStorageContext> context = 65 scoped_refptr<DomStorageContext> context =
57 new DomStorageContext(temp_dir_.path(), FilePath(), NULL, NULL); 66 new DomStorageContext(temp_dir_.path(), FilePath(), NULL, NULL);
58 std::vector<DomStorageContext::UsageInfo> infos; 67 std::vector<DomStorageContext::UsageInfo> infos;
59 context->GetUsageInfo(&infos, kDontIncludeFileInfo); 68 context->GetUsageInfo(&infos, kDontIncludeFileInfo);
60 EXPECT_EQ(1u, infos.size()); 69 EXPECT_EQ(1u, infos.size());
61 EXPECT_EQ(origin, infos[0].origin); 70 if (infos.size() > 0)
71 EXPECT_EQ(origin, infos[0].origin);
62 } 72 }
63 73
64 protected: 74 protected:
65 ScopedTempDir temp_dir_; 75 ScopedTempDir temp_dir_;
66 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy_; 76 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy_;
67 scoped_refptr<MockDomStorageTaskRunner> task_runner_; 77 scoped_refptr<MockDomStorageTaskRunner> task_runner_;
68 scoped_refptr<DomStorageContext> context_; 78 scoped_refptr<DomStorageContext> context_;
69 DISALLOW_COPY_AND_ASSIGN(DomStorageContextTest); 79 DISALLOW_COPY_AND_ASSIGN(DomStorageContextTest);
70 }; 80 };
71 81
72 TEST_F(DomStorageContextTest, Basics) { 82 TEST_F(DomStorageContextTest, Basics) {
73 // This test doesn't do much, checks that the constructor 83 // This test doesn't do much, checks that the constructor
74 // initializes members properly and that invoking methods 84 // initializes members properly and that invoking methods
75 // on a newly created object w/o any data on disk do no harm. 85 // on a newly created object w/o any data on disk do no harm.
76 EXPECT_EQ(temp_dir_.path(), context_->localstorage_directory()); 86 EXPECT_EQ(temp_dir_.path(), context_->localstorage_directory());
77 EXPECT_EQ(FilePath(), context_->sessionstorage_directory()); 87 EXPECT_EQ(FilePath(), context_->sessionstorage_directory());
78 EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get()); 88 EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get());
79 context_->PurgeMemory(); 89 context_->PurgeMemory();
80 context_->DeleteOrigin(GURL("http://chromium.org/")); 90 context_->DeleteOrigin(GURL("http://chromium.org/"));
81 context_->DeleteDataModifiedSince(base::Time::Now()); 91 context_->DeleteDataModifiedSince(base::Time::Now(), false);
82 const int kFirstSessionStorageNamespaceId = 1; 92 const int kFirstSessionStorageNamespaceId = 1;
83 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)); 93 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId));
84 EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId)); 94 EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId));
85 EXPECT_EQ(kFirstSessionStorageNamespaceId, context_->AllocateSessionId()); 95 EXPECT_EQ(kFirstSessionStorageNamespaceId, context_->AllocateSessionId());
86 std::vector<DomStorageContext::UsageInfo> infos; 96 std::vector<DomStorageContext::UsageInfo> infos;
87 context_->GetUsageInfo(&infos, kDontIncludeFileInfo); 97 context_->GetUsageInfo(&infos, kDontIncludeFileInfo);
88 EXPECT_TRUE(infos.empty()); 98 EXPECT_TRUE(infos.empty());
89 context_->Shutdown(); 99 context_->Shutdown();
90 } 100 }
91 101
102 TEST_F(DomStorageContextTest, RemoveUnprotectedOriginData) {
103 const GURL kProtectedOrigin("http://www.protected.com/");
104 storage_policy_->AddProtected(kProtectedOrigin);
105
106 // Store data for a normal and a protected origin, then remove data since
107 // the epoch.
108 NullableString16 old_value;
109 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
110 OpenStorageArea(kOrigin)->SetItem(kKey, kValue, &old_value));
111 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
112 OpenStorageArea(kProtectedOrigin)->SetItem(kKey, kValue, &old_value));
113 context_ = NULL;
114 MessageLoop::current()->RunAllPending();
115
116 RemoveDataSince(base::Time(), false);
117 VerifySingleOriginRemains(kProtectedOrigin);
118 }
119
120 TEST_F(DomStorageContextTest, RemoveProtectedOriginData) {
121 const GURL kProtectedOrigin("http://www.protected.com/");
122 storage_policy_->AddProtected(kProtectedOrigin);
123
124 // Store data for a normal and a protected origin, then remove data since
125 // the epoch.
126 NullableString16 old_value;
127 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
128 OpenStorageArea(kOrigin)->SetItem(kKey, kValue, &old_value));
129 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
130 OpenStorageArea(kProtectedOrigin)->SetItem(kKey, kValue, &old_value));
131 context_ = NULL;
132 MessageLoop::current()->RunAllPending();
133
134 RemoveDataSince(base::Time(), true);
135
136 // Create a new context that points to the same directory, see that
137 // both origins have been removed.
138 std::vector<DomStorageContext::UsageInfo> infos;
139 context_ = new DomStorageContext(temp_dir_.path(), FilePath(), NULL, NULL);
140 context_->GetUsageInfo(&infos, kDontIncludeFileInfo);
141 EXPECT_TRUE(infos.empty());
142 }
143
92 TEST_F(DomStorageContextTest, UsageInfo) { 144 TEST_F(DomStorageContextTest, UsageInfo) {
93 // Should be empty initially 145 // Should be empty initially
94 std::vector<DomStorageContext::UsageInfo> infos; 146 std::vector<DomStorageContext::UsageInfo> infos;
95 context_->GetUsageInfo(&infos, kDontIncludeFileInfo); 147 context_->GetUsageInfo(&infos, kDontIncludeFileInfo);
96 EXPECT_TRUE(infos.empty()); 148 EXPECT_TRUE(infos.empty());
97 context_->GetUsageInfo(&infos, kDoIncludeFileInfo); 149 context_->GetUsageInfo(&infos, kDoIncludeFileInfo);
98 EXPECT_TRUE(infos.empty()); 150 EXPECT_TRUE(infos.empty());
99 151
100 // Put some data into local storage and shutdown the context 152 // Put some data into local storage and shutdown the context
101 // to ensure data is written to disk. 153 // to ensure data is written to disk.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 context_->SetClearLocalState(true); 225 context_->SetClearLocalState(true);
174 context_->SaveSessionState(); // Should override clear behavior. 226 context_->SaveSessionState(); // Should override clear behavior.
175 context_->Shutdown(); 227 context_->Shutdown();
176 context_ = NULL; 228 context_ = NULL;
177 MessageLoop::current()->RunAllPending(); 229 MessageLoop::current()->RunAllPending();
178 230
179 VerifySingleOriginRemains(kSessionOnlyOrigin); 231 VerifySingleOriginRemains(kSessionOnlyOrigin);
180 } 232 }
181 233
182 } // namespace dom_storage 234 } // namespace dom_storage
OLDNEW
« webkit/dom_storage/dom_storage_context.cc ('K') | « webkit/dom_storage/dom_storage_context.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698