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

Side by Side Diff: content/browser/dom_storage/dom_storage_context_impl_unittest.cc

Issue 2316043002: //content: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Just rebased Created 4 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 28 matching lines...) Expand all
39 const base::string16 kKey; 39 const base::string16 kKey;
40 const base::string16 kValue; 40 const base::string16 kValue;
41 const bool kDontIncludeFileInfo; 41 const bool kDontIncludeFileInfo;
42 const bool kDoIncludeFileInfo; 42 const bool kDoIncludeFileInfo;
43 43
44 void SetUp() override { 44 void SetUp() override {
45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
46 storage_policy_ = new MockSpecialStoragePolicy; 46 storage_policy_ = new MockSpecialStoragePolicy;
47 task_runner_ = 47 task_runner_ =
48 new MockDOMStorageTaskRunner(base::ThreadTaskRunnerHandle::Get().get()); 48 new MockDOMStorageTaskRunner(base::ThreadTaskRunnerHandle::Get().get());
49 context_ = new DOMStorageContextImpl(temp_dir_.path(), 49 context_ =
50 base::FilePath(), 50 new DOMStorageContextImpl(temp_dir_.GetPath(), base::FilePath(),
51 storage_policy_.get(), 51 storage_policy_.get(), task_runner_.get());
52 task_runner_.get());
53 } 52 }
54 53
55 void TearDown() override { 54 void TearDown() override {
56 if (context_) 55 if (context_)
57 context_->Shutdown(); 56 context_->Shutdown();
58 base::RunLoop().RunUntilIdle(); 57 base::RunLoop().RunUntilIdle();
59 } 58 }
60 59
61 void VerifySingleOriginRemains(const GURL& origin) { 60 void VerifySingleOriginRemains(const GURL& origin) {
62 // Use a new instance to examine the contexts of temp_dir_. 61 // Use a new instance to examine the contexts of temp_dir_.
63 scoped_refptr<DOMStorageContextImpl> context = 62 scoped_refptr<DOMStorageContextImpl> context = new DOMStorageContextImpl(
64 new DOMStorageContextImpl(temp_dir_.path(), base::FilePath(), 63 temp_dir_.GetPath(), base::FilePath(), NULL, NULL);
65 NULL, NULL);
66 std::vector<LocalStorageUsageInfo> infos; 64 std::vector<LocalStorageUsageInfo> infos;
67 context->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); 65 context->GetLocalStorageUsage(&infos, kDontIncludeFileInfo);
68 ASSERT_EQ(1u, infos.size()); 66 ASSERT_EQ(1u, infos.size());
69 EXPECT_EQ(origin, infos[0].origin); 67 EXPECT_EQ(origin, infos[0].origin);
70 context->Shutdown(); 68 context->Shutdown();
71 } 69 }
72 70
73 int session_id_offset() { return context_->session_id_offset_; } 71 int session_id_offset() { return context_->session_id_offset_; }
74 72
75 protected: 73 protected:
76 base::MessageLoop message_loop_; 74 base::MessageLoop message_loop_;
77 base::ScopedTempDir temp_dir_; 75 base::ScopedTempDir temp_dir_;
78 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; 76 scoped_refptr<MockSpecialStoragePolicy> storage_policy_;
79 scoped_refptr<MockDOMStorageTaskRunner> task_runner_; 77 scoped_refptr<MockDOMStorageTaskRunner> task_runner_;
80 scoped_refptr<DOMStorageContextImpl> context_; 78 scoped_refptr<DOMStorageContextImpl> context_;
81 DISALLOW_COPY_AND_ASSIGN(DOMStorageContextImplTest); 79 DISALLOW_COPY_AND_ASSIGN(DOMStorageContextImplTest);
82 }; 80 };
83 81
84 TEST_F(DOMStorageContextImplTest, Basics) { 82 TEST_F(DOMStorageContextImplTest, Basics) {
85 // This test doesn't do much, checks that the constructor 83 // This test doesn't do much, checks that the constructor
86 // initializes members properly and that invoking methods 84 // initializes members properly and that invoking methods
87 // 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.
88 EXPECT_EQ(temp_dir_.path(), context_->localstorage_directory()); 86 EXPECT_EQ(temp_dir_.GetPath(), context_->localstorage_directory());
89 EXPECT_EQ(base::FilePath(), context_->sessionstorage_directory()); 87 EXPECT_EQ(base::FilePath(), context_->sessionstorage_directory());
90 EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get()); 88 EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get());
91 context_->DeleteLocalStorage(GURL("http://chromium.org/")); 89 context_->DeleteLocalStorage(GURL("http://chromium.org/"));
92 const int kFirstSessionStorageNamespaceId = 1 + session_id_offset(); 90 const int kFirstSessionStorageNamespaceId = 1 + session_id_offset();
93 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)); 91 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId));
94 EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId)); 92 EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId));
95 EXPECT_EQ(kFirstSessionStorageNamespaceId, context_->AllocateSessionId()); 93 EXPECT_EQ(kFirstSessionStorageNamespaceId, context_->AllocateSessionId());
96 std::vector<LocalStorageUsageInfo> infos; 94 std::vector<LocalStorageUsageInfo> infos;
97 context_->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); 95 context_->GetLocalStorageUsage(&infos, kDontIncludeFileInfo);
98 EXPECT_TRUE(infos.empty()); 96 EXPECT_TRUE(infos.empty());
(...skipping 12 matching lines...) Expand all
111 // to ensure data is written to disk. 109 // to ensure data is written to disk.
112 base::NullableString16 old_value; 110 base::NullableString16 old_value;
113 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)-> 111 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)->
114 OpenStorageArea(kOrigin)->SetItem(kKey, kValue, &old_value)); 112 OpenStorageArea(kOrigin)->SetItem(kKey, kValue, &old_value));
115 context_->Shutdown(); 113 context_->Shutdown();
116 context_ = NULL; 114 context_ = NULL;
117 base::RunLoop().RunUntilIdle(); 115 base::RunLoop().RunUntilIdle();
118 116
119 // Create a new context that points to the same directory, see that 117 // Create a new context that points to the same directory, see that
120 // it knows about the origin that we stored data for. 118 // it knows about the origin that we stored data for.
121 context_ = new DOMStorageContextImpl(temp_dir_.path(), base::FilePath(), 119 context_ = new DOMStorageContextImpl(temp_dir_.GetPath(), base::FilePath(),
122 NULL, NULL); 120 NULL, NULL);
123 context_->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); 121 context_->GetLocalStorageUsage(&infos, kDontIncludeFileInfo);
124 EXPECT_EQ(1u, infos.size()); 122 EXPECT_EQ(1u, infos.size());
125 EXPECT_EQ(kOrigin, infos[0].origin); 123 EXPECT_EQ(kOrigin, infos[0].origin);
126 EXPECT_EQ(0u, infos[0].data_size); 124 EXPECT_EQ(0u, infos[0].data_size);
127 EXPECT_EQ(base::Time(), infos[0].last_modified); 125 EXPECT_EQ(base::Time(), infos[0].last_modified);
128 infos.clear(); 126 infos.clear();
129 context_->GetLocalStorageUsage(&infos, kDoIncludeFileInfo); 127 context_->GetLocalStorageUsage(&infos, kDoIncludeFileInfo);
130 EXPECT_EQ(1u, infos.size()); 128 EXPECT_EQ(1u, infos.size());
131 EXPECT_EQ(kOrigin, infos[0].origin); 129 EXPECT_EQ(kOrigin, infos[0].origin);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 EXPECT_EQ(kClonedPersistentId, 193 EXPECT_EQ(kClonedPersistentId,
196 cloned_dom_namespace->persistent_namespace_id()); 194 cloned_dom_namespace->persistent_namespace_id());
197 // Verify that the areas inherit the persistent ID. 195 // Verify that the areas inherit the persistent ID.
198 DOMStorageArea* cloned_area = cloned_dom_namespace->OpenStorageArea(kOrigin); 196 DOMStorageArea* cloned_area = cloned_dom_namespace->OpenStorageArea(kOrigin);
199 EXPECT_EQ(kClonedPersistentId, cloned_area->persistent_namespace_id_); 197 EXPECT_EQ(kClonedPersistentId, cloned_area->persistent_namespace_id_);
200 } 198 }
201 199
202 TEST_F(DOMStorageContextImplTest, DeleteSessionStorage) { 200 TEST_F(DOMStorageContextImplTest, DeleteSessionStorage) {
203 // Create a DOMStorageContextImpl which will save sessionStorage on disk. 201 // Create a DOMStorageContextImpl which will save sessionStorage on disk.
204 context_->Shutdown(); 202 context_->Shutdown();
205 context_ = new DOMStorageContextImpl(temp_dir_.path(), 203 context_ =
206 temp_dir_.path(), 204 new DOMStorageContextImpl(temp_dir_.GetPath(), temp_dir_.GetPath(),
207 storage_policy_.get(), 205 storage_policy_.get(), task_runner_.get());
208 task_runner_.get());
209 context_->SetSaveSessionStorageOnDisk(); 206 context_->SetSaveSessionStorageOnDisk();
210 ASSERT_EQ(temp_dir_.path(), context_->sessionstorage_directory()); 207 ASSERT_EQ(temp_dir_.GetPath(), context_->sessionstorage_directory());
211 208
212 // Write data. 209 // Write data.
213 const int kSessionStorageNamespaceId = 1 + session_id_offset(); 210 const int kSessionStorageNamespaceId = 1 + session_id_offset();
214 const std::string kPersistentId = "persistent"; 211 const std::string kPersistentId = "persistent";
215 context_->CreateSessionNamespace(kSessionStorageNamespaceId, 212 context_->CreateSessionNamespace(kSessionStorageNamespaceId,
216 kPersistentId); 213 kPersistentId);
217 DOMStorageNamespace* dom_namespace = 214 DOMStorageNamespace* dom_namespace =
218 context_->GetStorageNamespace(kSessionStorageNamespaceId); 215 context_->GetStorageNamespace(kSessionStorageNamespaceId);
219 DOMStorageArea* area = dom_namespace->OpenStorageArea(kOrigin); 216 DOMStorageArea* area = dom_namespace->OpenStorageArea(kOrigin);
220 const base::string16 kKey(ASCIIToUTF16("foo")); 217 const base::string16 kKey(ASCIIToUTF16("foo"));
221 const base::string16 kValue(ASCIIToUTF16("bar")); 218 const base::string16 kValue(ASCIIToUTF16("bar"));
222 base::NullableString16 old_nullable_value; 219 base::NullableString16 old_nullable_value;
223 area->SetItem(kKey, kValue, &old_nullable_value); 220 area->SetItem(kKey, kValue, &old_nullable_value);
224 dom_namespace->CloseStorageArea(area); 221 dom_namespace->CloseStorageArea(area);
225 222
226 // Destroy and recreate the DOMStorageContextImpl. 223 // Destroy and recreate the DOMStorageContextImpl.
227 context_->Shutdown(); 224 context_->Shutdown();
228 context_ = NULL; 225 context_ = NULL;
229 base::RunLoop().RunUntilIdle(); 226 base::RunLoop().RunUntilIdle();
230 context_ = new DOMStorageContextImpl( 227 context_ =
231 temp_dir_.path(), temp_dir_.path(), 228 new DOMStorageContextImpl(temp_dir_.GetPath(), temp_dir_.GetPath(),
232 storage_policy_.get(), task_runner_.get()); 229 storage_policy_.get(), task_runner_.get());
233 context_->SetSaveSessionStorageOnDisk(); 230 context_->SetSaveSessionStorageOnDisk();
234 231
235 // Read the data back. 232 // Read the data back.
236 context_->CreateSessionNamespace(kSessionStorageNamespaceId, 233 context_->CreateSessionNamespace(kSessionStorageNamespaceId,
237 kPersistentId); 234 kPersistentId);
238 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId); 235 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId);
239 area = dom_namespace->OpenStorageArea(kOrigin); 236 area = dom_namespace->OpenStorageArea(kOrigin);
240 base::NullableString16 read_value; 237 base::NullableString16 read_value;
241 read_value = area->GetItem(kKey); 238 read_value = area->GetItem(kKey);
242 EXPECT_EQ(kValue, read_value.string()); 239 EXPECT_EQ(kValue, read_value.string());
243 dom_namespace->CloseStorageArea(area); 240 dom_namespace->CloseStorageArea(area);
244 241
245 SessionStorageUsageInfo info; 242 SessionStorageUsageInfo info;
246 info.origin = kOrigin; 243 info.origin = kOrigin;
247 info.persistent_namespace_id = kPersistentId; 244 info.persistent_namespace_id = kPersistentId;
248 context_->DeleteSessionStorage(info); 245 context_->DeleteSessionStorage(info);
249 246
250 // Destroy and recreate again. 247 // Destroy and recreate again.
251 context_->Shutdown(); 248 context_->Shutdown();
252 context_ = NULL; 249 context_ = NULL;
253 base::RunLoop().RunUntilIdle(); 250 base::RunLoop().RunUntilIdle();
254 context_ = new DOMStorageContextImpl( 251 context_ =
255 temp_dir_.path(), temp_dir_.path(), 252 new DOMStorageContextImpl(temp_dir_.GetPath(), temp_dir_.GetPath(),
256 storage_policy_.get(), task_runner_.get()); 253 storage_policy_.get(), task_runner_.get());
257 context_->SetSaveSessionStorageOnDisk(); 254 context_->SetSaveSessionStorageOnDisk();
258 255
259 // Now there should be no data. 256 // Now there should be no data.
260 context_->CreateSessionNamespace(kSessionStorageNamespaceId, 257 context_->CreateSessionNamespace(kSessionStorageNamespaceId,
261 kPersistentId); 258 kPersistentId);
262 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId); 259 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId);
263 area = dom_namespace->OpenStorageArea(kOrigin); 260 area = dom_namespace->OpenStorageArea(kOrigin);
264 read_value = area->GetItem(kKey); 261 read_value = area->GetItem(kKey);
265 EXPECT_TRUE(read_value.is_null()); 262 EXPECT_TRUE(read_value.is_null());
266 dom_namespace->CloseStorageArea(area); 263 dom_namespace->CloseStorageArea(area);
(...skipping 27 matching lines...) Expand all
294 area2->CommitChanges(area2->commit_batch_.get()); 291 area2->CommitChanges(area2->commit_batch_.get());
295 area2->commit_batch_ = nullptr; 292 area2->commit_batch_ = nullptr;
296 293
297 // PURGE_AGGRESSIVE clears the cache in the open area. 294 // PURGE_AGGRESSIVE clears the cache in the open area.
298 EXPECT_NE(0u, dom_namespace->GetUsageStatistics().total_cache_size); 295 EXPECT_NE(0u, dom_namespace->GetUsageStatistics().total_cache_size);
299 context_->PurgeMemory(DOMStorageContextImpl::PURGE_AGGRESSIVE); 296 context_->PurgeMemory(DOMStorageContextImpl::PURGE_AGGRESSIVE);
300 EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_cache_size); 297 EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_cache_size);
301 } 298 }
302 299
303 } // namespace content 300 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_area_unittest.cc ('k') | content/browser/dom_storage/dom_storage_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698