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

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

Issue 16155009: Update webkit/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/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
« no previous file with comments | « webkit/dom_storage/dom_storage_context.cc ('k') | webkit/dom_storage/dom_storage_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 25 matching lines...) Expand all
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(temp_dir_.path(),
219 temp_dir_.path(), temp_dir_.path(), storage_policy_, task_runner_); 219 temp_dir_.path(),
220 storage_policy_.get(),
221 task_runner_.get());
220 context_->SetSaveSessionStorageOnDisk(); 222 context_->SetSaveSessionStorageOnDisk();
221 223
222 // Read the data back. 224 // Read the data back.
223 context_->CreateSessionNamespace(kSessionStorageNamespaceId, 225 context_->CreateSessionNamespace(kSessionStorageNamespaceId,
224 kPersistentId); 226 kPersistentId);
225 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId); 227 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId);
226 area = dom_namespace->OpenStorageArea(kOrigin); 228 area = dom_namespace->OpenStorageArea(kOrigin);
227 NullableString16 read_value; 229 NullableString16 read_value;
228 read_value = area->GetItem(kKey); 230 read_value = area->GetItem(kKey);
229 EXPECT_EQ(kValue, read_value.string()); 231 EXPECT_EQ(kValue, read_value.string());
230 dom_namespace->CloseStorageArea(area); 232 dom_namespace->CloseStorageArea(area);
231 233
232 SessionStorageUsageInfo info; 234 SessionStorageUsageInfo info;
233 info.origin = kOrigin; 235 info.origin = kOrigin;
234 info.persistent_namespace_id = kPersistentId; 236 info.persistent_namespace_id = kPersistentId;
235 context_->DeleteSessionStorage(info); 237 context_->DeleteSessionStorage(info);
236 238
237 // Destroy and recreate again. 239 // Destroy and recreate again.
238 context_->Shutdown(); 240 context_->Shutdown();
239 context_ = NULL; 241 context_ = NULL;
240 base::MessageLoop::current()->RunUntilIdle(); 242 base::MessageLoop::current()->RunUntilIdle();
241 context_ = new DomStorageContext( 243 context_ = new DomStorageContext(temp_dir_.path(),
242 temp_dir_.path(), temp_dir_.path(), storage_policy_, task_runner_); 244 temp_dir_.path(),
245 storage_policy_.get(),
246 task_runner_.get());
243 context_->SetSaveSessionStorageOnDisk(); 247 context_->SetSaveSessionStorageOnDisk();
244 248
245 // Now there should be no data. 249 // Now there should be no data.
246 context_->CreateSessionNamespace(kSessionStorageNamespaceId, 250 context_->CreateSessionNamespace(kSessionStorageNamespaceId,
247 kPersistentId); 251 kPersistentId);
248 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId); 252 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId);
249 area = dom_namespace->OpenStorageArea(kOrigin); 253 area = dom_namespace->OpenStorageArea(kOrigin);
250 read_value = area->GetItem(kKey); 254 read_value = area->GetItem(kKey);
251 EXPECT_TRUE(read_value.is_null()); 255 EXPECT_TRUE(read_value.is_null());
252 dom_namespace->CloseStorageArea(area); 256 dom_namespace->CloseStorageArea(area);
253 context_->Shutdown(); 257 context_->Shutdown();
254 context_ = NULL; 258 context_ = NULL;
255 base::MessageLoop::current()->RunUntilIdle(); 259 base::MessageLoop::current()->RunUntilIdle();
256 } 260 }
257 261
258 } // namespace dom_storage 262 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/dom_storage/dom_storage_context.cc ('k') | webkit/dom_storage/dom_storage_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698