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

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

Issue 15990007: Move dom_storage to new locations. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 6 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/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.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 "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webkit/dom_storage/dom_storage_area.h" 14 #include "webkit/browser/dom_storage/dom_storage_area.h"
15 #include "webkit/dom_storage/dom_storage_context.h" 15 #include "webkit/browser/dom_storage/dom_storage_context.h"
16 #include "webkit/dom_storage/dom_storage_namespace.h" 16 #include "webkit/browser/dom_storage/dom_storage_namespace.h"
17 #include "webkit/dom_storage/dom_storage_task_runner.h" 17 #include "webkit/browser/dom_storage/dom_storage_task_runner.h"
18 #include "webkit/dom_storage/dom_storage_types.h" 18 #include "webkit/browser/quota/mock_special_storage_policy.h"
19 #include "webkit/quota/mock_special_storage_policy.h" 19 #include "webkit/common/dom_storage/dom_storage_types.h"
20 20
21 namespace dom_storage { 21 namespace dom_storage {
22 22
23 class DomStorageContextTest : public testing::Test { 23 class DomStorageContextTest : public testing::Test {
24 public: 24 public:
25 DomStorageContextTest() 25 DomStorageContextTest()
26 : kOrigin(GURL("http://dom_storage/")), 26 : kOrigin(GURL("http://dom_storage/")),
27 kKey(ASCIIToUTF16("key")), 27 kKey(ASCIIToUTF16("key")),
28 kValue(ASCIIToUTF16("value")), 28 kValue(ASCIIToUTF16("value")),
29 kDontIncludeFileInfo(false), 29 kDontIncludeFileInfo(false),
30 kDoIncludeFileInfo(true) { 30 kDoIncludeFileInfo(true) {
31 } 31 }
32 32
33 const GURL kOrigin; 33 const GURL kOrigin;
34 const base::string16 kKey; 34 const base::string16 kKey;
35 const base::string16 kValue; 35 const base::string16 kValue;
36 const bool kDontIncludeFileInfo; 36 const bool kDontIncludeFileInfo;
37 const bool kDoIncludeFileInfo; 37 const bool kDoIncludeFileInfo;
38 38
39 virtual void SetUp() { 39 virtual void SetUp() {
40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
41 storage_policy_ = new quota::MockSpecialStoragePolicy; 41 storage_policy_ = new quota::MockSpecialStoragePolicy;
42 task_runner_ = new MockDomStorageTaskRunner( 42 task_runner_ = new MockDomStorageTaskRunner(
43 base::MessageLoopProxy::current()); 43 base::MessageLoopProxy::current());
44 context_ = new DomStorageContext(temp_dir_.path(), 44 context_ = new DomStorageContext(temp_dir_.path(),
45 base::FilePath(), 45 base::FilePath(),
46 storage_policy_, 46 storage_policy_.get(),
47 task_runner_); 47 task_runner_.get());
48 } 48 }
49 49
50 virtual void TearDown() { 50 virtual void TearDown() {
51 base::MessageLoop::current()->RunUntilIdle(); 51 base::MessageLoop::current()->RunUntilIdle();
52 } 52 }
53 53
54 void VerifySingleOriginRemains(const GURL& origin) { 54 void VerifySingleOriginRemains(const GURL& origin) {
55 // Use a new instance to examine the contexts of temp_dir_. 55 // Use a new instance to examine the contexts of temp_dir_.
56 scoped_refptr<DomStorageContext> context = 56 scoped_refptr<DomStorageContext> context =
57 new DomStorageContext(temp_dir_.path(), base::FilePath(), NULL, NULL); 57 new DomStorageContext(temp_dir_.path(), base::FilePath(), NULL, NULL);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 cloned_dom_namespace->persistent_namespace_id()); 185 cloned_dom_namespace->persistent_namespace_id());
186 // Verify that the areas inherit the persistent ID. 186 // Verify that the areas inherit the persistent ID.
187 DomStorageArea* cloned_area = cloned_dom_namespace->OpenStorageArea(kOrigin); 187 DomStorageArea* cloned_area = cloned_dom_namespace->OpenStorageArea(kOrigin);
188 EXPECT_EQ(kClonedPersistentId, cloned_area->persistent_namespace_id_); 188 EXPECT_EQ(kClonedPersistentId, cloned_area->persistent_namespace_id_);
189 } 189 }
190 190
191 TEST_F(DomStorageContextTest, DeleteSessionStorage) { 191 TEST_F(DomStorageContextTest, DeleteSessionStorage) {
192 // Create a DomStorageContext which will save sessionStorage on disk. 192 // Create a DomStorageContext which will save sessionStorage on disk.
193 context_ = new DomStorageContext(temp_dir_.path(), 193 context_ = new DomStorageContext(temp_dir_.path(),
194 temp_dir_.path(), 194 temp_dir_.path(),
195 storage_policy_, 195 storage_policy_.get(),
196 task_runner_); 196 task_runner_.get());
197 context_->SetSaveSessionStorageOnDisk(); 197 context_->SetSaveSessionStorageOnDisk();
198 ASSERT_EQ(temp_dir_.path(), context_->sessionstorage_directory()); 198 ASSERT_EQ(temp_dir_.path(), context_->sessionstorage_directory());
199 199
200 // Write data. 200 // Write data.
201 const int kSessionStorageNamespaceId = 1; 201 const int kSessionStorageNamespaceId = 1;
202 const std::string kPersistentId = "persistent"; 202 const std::string kPersistentId = "persistent";
203 context_->CreateSessionNamespace(kSessionStorageNamespaceId, 203 context_->CreateSessionNamespace(kSessionStorageNamespaceId,
204 kPersistentId); 204 kPersistentId);
205 DomStorageNamespace* dom_namespace = 205 DomStorageNamespace* dom_namespace =
206 context_->GetStorageNamespace(kSessionStorageNamespaceId); 206 context_->GetStorageNamespace(kSessionStorageNamespaceId);
207 DomStorageArea* area = dom_namespace->OpenStorageArea(kOrigin); 207 DomStorageArea* area = dom_namespace->OpenStorageArea(kOrigin);
208 const base::string16 kKey(ASCIIToUTF16("foo")); 208 const base::string16 kKey(ASCIIToUTF16("foo"));
209 const base::string16 kValue(ASCIIToUTF16("bar")); 209 const base::string16 kValue(ASCIIToUTF16("bar"));
210 NullableString16 old_nullable_value; 210 NullableString16 old_nullable_value;
211 area->SetItem(kKey, kValue, &old_nullable_value); 211 area->SetItem(kKey, kValue, &old_nullable_value);
212 dom_namespace->CloseStorageArea(area); 212 dom_namespace->CloseStorageArea(area);
213 213
214 // Destroy and recreate the DomStorageContext. 214 // Destroy and recreate the DomStorageContext.
215 context_->Shutdown(); 215 context_->Shutdown();
216 context_ = NULL; 216 context_ = NULL;
217 base::MessageLoop::current()->RunUntilIdle(); 217 base::MessageLoop::current()->RunUntilIdle();
218 context_ = new DomStorageContext( 218 context_ = new DomStorageContext(
219 temp_dir_.path(), temp_dir_.path(), storage_policy_, task_runner_); 219 temp_dir_.path(), temp_dir_.path(),
220 storage_policy_.get(), task_runner_.get());
220 context_->SetSaveSessionStorageOnDisk(); 221 context_->SetSaveSessionStorageOnDisk();
221 222
222 // Read the data back. 223 // Read the data back.
223 context_->CreateSessionNamespace(kSessionStorageNamespaceId, 224 context_->CreateSessionNamespace(kSessionStorageNamespaceId,
224 kPersistentId); 225 kPersistentId);
225 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId); 226 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId);
226 area = dom_namespace->OpenStorageArea(kOrigin); 227 area = dom_namespace->OpenStorageArea(kOrigin);
227 NullableString16 read_value; 228 NullableString16 read_value;
228 read_value = area->GetItem(kKey); 229 read_value = area->GetItem(kKey);
229 EXPECT_EQ(kValue, read_value.string()); 230 EXPECT_EQ(kValue, read_value.string());
230 dom_namespace->CloseStorageArea(area); 231 dom_namespace->CloseStorageArea(area);
231 232
232 SessionStorageUsageInfo info; 233 SessionStorageUsageInfo info;
233 info.origin = kOrigin; 234 info.origin = kOrigin;
234 info.persistent_namespace_id = kPersistentId; 235 info.persistent_namespace_id = kPersistentId;
235 context_->DeleteSessionStorage(info); 236 context_->DeleteSessionStorage(info);
236 237
237 // Destroy and recreate again. 238 // Destroy and recreate again.
238 context_->Shutdown(); 239 context_->Shutdown();
239 context_ = NULL; 240 context_ = NULL;
240 base::MessageLoop::current()->RunUntilIdle(); 241 base::MessageLoop::current()->RunUntilIdle();
241 context_ = new DomStorageContext( 242 context_ = new DomStorageContext(
242 temp_dir_.path(), temp_dir_.path(), storage_policy_, task_runner_); 243 temp_dir_.path(), temp_dir_.path(),
244 storage_policy_.get(), task_runner_.get());
243 context_->SetSaveSessionStorageOnDisk(); 245 context_->SetSaveSessionStorageOnDisk();
244 246
245 // Now there should be no data. 247 // Now there should be no data.
246 context_->CreateSessionNamespace(kSessionStorageNamespaceId, 248 context_->CreateSessionNamespace(kSessionStorageNamespaceId,
247 kPersistentId); 249 kPersistentId);
248 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId); 250 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId);
249 area = dom_namespace->OpenStorageArea(kOrigin); 251 area = dom_namespace->OpenStorageArea(kOrigin);
250 read_value = area->GetItem(kKey); 252 read_value = area->GetItem(kKey);
251 EXPECT_TRUE(read_value.is_null()); 253 EXPECT_TRUE(read_value.is_null());
252 dom_namespace->CloseStorageArea(area); 254 dom_namespace->CloseStorageArea(area);
253 context_->Shutdown(); 255 context_->Shutdown();
254 context_ = NULL; 256 context_ = NULL;
255 base::MessageLoop::current()->RunUntilIdle(); 257 base::MessageLoop::current()->RunUntilIdle();
256 } 258 }
257 259
258 } // namespace dom_storage 260 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/browser/dom_storage/dom_storage_context.cc ('k') | webkit/browser/dom_storage/dom_storage_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698