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

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

Issue 11359217: Move scoped_temp_dir from base to base/files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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/message_loop.h" 8 #include "base/message_loop.h"
8 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.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 "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/dom_storage/dom_storage_area.h"
15 #include "webkit/dom_storage/dom_storage_database.h" 15 #include "webkit/dom_storage/dom_storage_database.h"
16 #include "webkit/dom_storage/dom_storage_database_adapter.h" 16 #include "webkit/dom_storage/dom_storage_database_adapter.h"
17 #include "webkit/dom_storage/dom_storage_task_runner.h" 17 #include "webkit/dom_storage/dom_storage_task_runner.h"
18 #include "webkit/dom_storage/dom_storage_types.h" 18 #include "webkit/dom_storage/dom_storage_types.h"
19 #include "webkit/dom_storage/local_storage_database_adapter.h" 19 #include "webkit/dom_storage/local_storage_database_adapter.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 EXPECT_EQ(0u, area->Length()); 117 EXPECT_EQ(0u, area->Length());
118 EXPECT_TRUE(area->Key(0).is_null()); 118 EXPECT_TRUE(area->Key(0).is_null());
119 EXPECT_TRUE(area->GetItem(kKey).is_null()); 119 EXPECT_TRUE(area->GetItem(kKey).is_null());
120 EXPECT_FALSE(area->SetItem(kKey, kValue, &old_nullable_value)); 120 EXPECT_FALSE(area->SetItem(kKey, kValue, &old_nullable_value));
121 EXPECT_FALSE(area->RemoveItem(kKey, &old_value)); 121 EXPECT_FALSE(area->RemoveItem(kKey, &old_value));
122 EXPECT_FALSE(area->Clear()); 122 EXPECT_FALSE(area->Clear());
123 } 123 }
124 124
125 TEST_F(DomStorageAreaTest, BackingDatabaseOpened) { 125 TEST_F(DomStorageAreaTest, BackingDatabaseOpened) {
126 const int64 kSessionStorageNamespaceId = kLocalStorageNamespaceId + 1; 126 const int64 kSessionStorageNamespaceId = kLocalStorageNamespaceId + 1;
127 ScopedTempDir temp_dir; 127 base::ScopedTempDir temp_dir;
128 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 128 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
129 const FilePath kExpectedOriginFilePath = temp_dir.path().Append( 129 const FilePath kExpectedOriginFilePath = temp_dir.path().Append(
130 DomStorageArea::DatabaseFileNameFromOrigin(kOrigin)); 130 DomStorageArea::DatabaseFileNameFromOrigin(kOrigin));
131 131
132 // No directory, backing should be null. 132 // No directory, backing should be null.
133 { 133 {
134 scoped_refptr<DomStorageArea> area( 134 scoped_refptr<DomStorageArea> area(
135 new DomStorageArea(kOrigin, FilePath(), NULL)); 135 new DomStorageArea(kOrigin, FilePath(), NULL));
136 EXPECT_EQ(NULL, area->backing_.get()); 136 EXPECT_EQ(NULL, area->backing_.get());
137 EXPECT_TRUE(area->is_initial_import_done_); 137 EXPECT_TRUE(area->is_initial_import_done_);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 195
196 // Verify the content made it to the in memory database. 196 // Verify the content made it to the in memory database.
197 ValuesMap values; 197 ValuesMap values;
198 area->backing_->ReadAllValues(&values); 198 area->backing_->ReadAllValues(&values);
199 EXPECT_EQ(1u, values.size()); 199 EXPECT_EQ(1u, values.size());
200 EXPECT_EQ(kValue, values[kKey].string()); 200 EXPECT_EQ(kValue, values[kKey].string());
201 } 201 }
202 } 202 }
203 203
204 TEST_F(DomStorageAreaTest, CommitTasks) { 204 TEST_F(DomStorageAreaTest, CommitTasks) {
205 ScopedTempDir temp_dir; 205 base::ScopedTempDir temp_dir;
206 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 206 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
207 207
208 scoped_refptr<DomStorageArea> area( 208 scoped_refptr<DomStorageArea> area(
209 new DomStorageArea(kOrigin, 209 new DomStorageArea(kOrigin,
210 temp_dir.path(), 210 temp_dir.path(),
211 new MockDomStorageTaskRunner(base::MessageLoopProxy::current()))); 211 new MockDomStorageTaskRunner(base::MessageLoopProxy::current())));
212 // Inject an in-memory db to speed up the test. 212 // Inject an in-memory db to speed up the test.
213 area->backing_.reset(new LocalStorageDatabaseAdapter()); 213 area->backing_.reset(new LocalStorageDatabaseAdapter());
214 214
215 // Unrelated to commits, but while we're here, see that querying Length() 215 // Unrelated to commits, but while we're here, see that querying Length()
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 EXPECT_FALSE(area->HasUncommittedChanges()); 273 EXPECT_FALSE(area->HasUncommittedChanges());
274 // Verify the changes made it to the database. 274 // Verify the changes made it to the database.
275 values.clear(); 275 values.clear();
276 area->backing_->ReadAllValues(&values); 276 area->backing_->ReadAllValues(&values);
277 EXPECT_EQ(2u, values.size()); 277 EXPECT_EQ(2u, values.size());
278 EXPECT_EQ(kValue, values[kKey].string()); 278 EXPECT_EQ(kValue, values[kKey].string());
279 EXPECT_EQ(kValue2, values[kKey2].string()); 279 EXPECT_EQ(kValue2, values[kKey2].string());
280 } 280 }
281 281
282 TEST_F(DomStorageAreaTest, CommitChangesAtShutdown) { 282 TEST_F(DomStorageAreaTest, CommitChangesAtShutdown) {
283 ScopedTempDir temp_dir; 283 base::ScopedTempDir temp_dir;
284 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 284 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
285 scoped_refptr<DomStorageArea> area( 285 scoped_refptr<DomStorageArea> area(
286 new DomStorageArea(kOrigin, 286 new DomStorageArea(kOrigin,
287 temp_dir.path(), 287 temp_dir.path(),
288 new MockDomStorageTaskRunner(base::MessageLoopProxy::current()))); 288 new MockDomStorageTaskRunner(base::MessageLoopProxy::current())));
289 289
290 // Inject an in-memory db to speed up the test and also to verify 290 // Inject an in-memory db to speed up the test and also to verify
291 // the final changes are commited in it's dtor. 291 // the final changes are commited in it's dtor.
292 static_cast<LocalStorageDatabaseAdapter*>(area->backing_.get())->db_.reset( 292 static_cast<LocalStorageDatabaseAdapter*>(area->backing_.get())->db_.reset(
293 new VerifyChangesCommittedDatabase()); 293 new VerifyChangesCommittedDatabase());
294 294
295 ValuesMap values; 295 ValuesMap values;
296 NullableString16 old_value; 296 NullableString16 old_value;
297 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value)); 297 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value));
298 EXPECT_TRUE(area->HasUncommittedChanges()); 298 EXPECT_TRUE(area->HasUncommittedChanges());
299 area->backing_->ReadAllValues(&values); 299 area->backing_->ReadAllValues(&values);
300 EXPECT_TRUE(values.empty()); // not committed yet 300 EXPECT_TRUE(values.empty()); // not committed yet
301 area->Shutdown(); 301 area->Shutdown();
302 MessageLoop::current()->RunAllPending(); 302 MessageLoop::current()->RunAllPending();
303 EXPECT_TRUE(area->HasOneRef()); 303 EXPECT_TRUE(area->HasOneRef());
304 EXPECT_FALSE(area->backing_.get()); 304 EXPECT_FALSE(area->backing_.get());
305 // The VerifyChangesCommittedDatabase destructor verifies values 305 // The VerifyChangesCommittedDatabase destructor verifies values
306 // were committed. 306 // were committed.
307 } 307 }
308 308
309 TEST_F(DomStorageAreaTest, DeleteOrigin) { 309 TEST_F(DomStorageAreaTest, DeleteOrigin) {
310 ScopedTempDir temp_dir; 310 base::ScopedTempDir temp_dir;
311 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 311 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
312 scoped_refptr<DomStorageArea> area( 312 scoped_refptr<DomStorageArea> area(
313 new DomStorageArea(kOrigin, 313 new DomStorageArea(kOrigin,
314 temp_dir.path(), 314 temp_dir.path(),
315 new MockDomStorageTaskRunner(base::MessageLoopProxy::current()))); 315 new MockDomStorageTaskRunner(base::MessageLoopProxy::current())));
316 316
317 // This test puts files on disk. 317 // This test puts files on disk.
318 FilePath db_file_path = static_cast<LocalStorageDatabaseAdapter*>( 318 FilePath db_file_path = static_cast<LocalStorageDatabaseAdapter*>(
319 area->backing_.get())->db_->file_path(); 319 area->backing_.get())->db_->file_path();
320 FilePath db_journal_file_path = 320 FilePath db_journal_file_path =
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 EXPECT_FALSE(area->HasUncommittedChanges()); 361 EXPECT_FALSE(area->HasUncommittedChanges());
362 // Since the area had uncommitted changes at the time delete 362 // Since the area had uncommitted changes at the time delete
363 // was called, the file will linger until the shutdown time. 363 // was called, the file will linger until the shutdown time.
364 EXPECT_TRUE(file_util::PathExists(db_file_path)); 364 EXPECT_TRUE(file_util::PathExists(db_file_path));
365 area->Shutdown(); 365 area->Shutdown();
366 MessageLoop::current()->RunAllPending(); 366 MessageLoop::current()->RunAllPending();
367 EXPECT_FALSE(file_util::PathExists(db_file_path)); 367 EXPECT_FALSE(file_util::PathExists(db_file_path));
368 } 368 }
369 369
370 TEST_F(DomStorageAreaTest, PurgeMemory) { 370 TEST_F(DomStorageAreaTest, PurgeMemory) {
371 ScopedTempDir temp_dir; 371 base::ScopedTempDir temp_dir;
372 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 372 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
373 scoped_refptr<DomStorageArea> area( 373 scoped_refptr<DomStorageArea> area(
374 new DomStorageArea(kOrigin, 374 new DomStorageArea(kOrigin,
375 temp_dir.path(), 375 temp_dir.path(),
376 new MockDomStorageTaskRunner(base::MessageLoopProxy::current()))); 376 new MockDomStorageTaskRunner(base::MessageLoopProxy::current())));
377 377
378 // Inject an in-memory db to speed up the test. 378 // Inject an in-memory db to speed up the test.
379 area->backing_.reset(new LocalStorageDatabaseAdapter()); 379 area->backing_.reset(new LocalStorageDatabaseAdapter());
380 380
381 // Unowned ptrs we use to verify that 'purge' has happened. 381 // Unowned ptrs we use to verify that 'purge' has happened.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 EXPECT_EQ( 463 EXPECT_EQ(
464 FilePath().AppendASCII("-journal"), 464 FilePath().AppendASCII("-journal"),
465 DomStorageDatabase::GetJournalFilePath(FilePath())); 465 DomStorageDatabase::GetJournalFilePath(FilePath()));
466 EXPECT_EQ( 466 EXPECT_EQ(
467 FilePath().AppendASCII(".extensiononly-journal"), 467 FilePath().AppendASCII(".extensiononly-journal"),
468 DomStorageDatabase::GetJournalFilePath( 468 DomStorageDatabase::GetJournalFilePath(
469 FilePath().AppendASCII(".extensiononly"))); 469 FilePath().AppendASCII(".extensiononly")));
470 } 470 }
471 471
472 } // namespace dom_storage 472 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/database/database_tracker_unittest.cc ('k') | webkit/dom_storage/dom_storage_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698