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

Unified Diff: webkit/dom_storage/dom_storage_area_unittest.cc

Issue 10556009: DomStorageArea -> DomStorageDatabase indirection; add *StorageDatabaseAdapter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops Created 8 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 side-by-side diff with in-line comments
Download patch
Index: webkit/dom_storage/dom_storage_area_unittest.cc
diff --git a/webkit/dom_storage/dom_storage_area_unittest.cc b/webkit/dom_storage/dom_storage_area_unittest.cc
index f9d428474cb6da97e3496453a4fac3678d8fedff..5d382a1adedafdf95de6689d7eb807b4d204e224 100644
--- a/webkit/dom_storage/dom_storage_area_unittest.cc
+++ b/webkit/dom_storage/dom_storage_area_unittest.cc
@@ -12,8 +12,11 @@
#include "base/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/dom_storage/dom_storage_area.h"
+#include "webkit/dom_storage/dom_storage_database.h"
+#include "webkit/dom_storage/dom_storage_database_adapter.h"
#include "webkit/dom_storage/dom_storage_task_runner.h"
#include "webkit/dom_storage/dom_storage_types.h"
+#include "webkit/dom_storage/local_storage_database_adapter.h"
namespace dom_storage {
@@ -162,14 +165,16 @@ TEST_F(DomStorageAreaTest, BackingDatabaseOpened) {
new MockDomStorageTaskRunner(base::MessageLoopProxy::current())));
EXPECT_TRUE(area->backing_.get());
- EXPECT_FALSE(area->backing_->IsOpen());
+ DomStorageDatabase* database = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
+ EXPECT_FALSE(database->IsOpen());
EXPECT_FALSE(area->is_initial_import_done_);
// Inject an in-memory db to speed up the test.
// We will verify that something is written into the database but not
// that a file is written to disk - DOMStorageDatabase unit tests cover
// that.
- area->backing_.reset(new DomStorageDatabase());
+ area->backing_.reset(new LocalStorageDatabaseAdapter());
// Need to write something to ensure that the database is created.
NullableString16 old_value;
@@ -183,7 +188,9 @@ TEST_F(DomStorageAreaTest, BackingDatabaseOpened) {
EXPECT_FALSE(area->commit_batch_.get());
EXPECT_EQ(0, area->commit_batches_in_flight_);
- EXPECT_TRUE(area->backing_->IsOpen());
+ database = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
+ EXPECT_TRUE(database->IsOpen());
EXPECT_EQ(1u, area->Length());
EXPECT_EQ(kValue, area->GetItem(kKey).string());
@@ -204,7 +211,7 @@ TEST_F(DomStorageAreaTest, CommitTasks) {
temp_dir.path(),
new MockDomStorageTaskRunner(base::MessageLoopProxy::current())));
// Inject an in-memory db to speed up the test.
- area->backing_.reset(new DomStorageDatabase());
+ area->backing_.reset(new LocalStorageDatabaseAdapter());
// Unrelated to commits, but while we're here, see that querying Length()
// causes the backing database to be opened and presumably read from.
@@ -283,7 +290,8 @@ TEST_F(DomStorageAreaTest, CommitChangesAtShutdown) {
// Inject an in-memory db to speed up the test and also to verify
// the final changes are commited in it's dtor.
- area->backing_.reset(new VerifyChangesCommittedDatabase());
+ static_cast<LocalStorageDatabaseAdapter*>(area->backing_.get())->db_.reset(
+ new VerifyChangesCommittedDatabase());
ValuesMap values;
NullableString16 old_value;
@@ -308,7 +316,8 @@ TEST_F(DomStorageAreaTest, DeleteOrigin) {
new MockDomStorageTaskRunner(base::MessageLoopProxy::current())));
// This test puts files on disk.
- FilePath db_file_path = area->backing_->file_path();
+ FilePath db_file_path = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_->file_path();
FilePath db_journal_file_path =
DomStorageDatabase::GetJournalFilePath(db_file_path);
@@ -368,17 +377,21 @@ TEST_F(DomStorageAreaTest, PurgeMemory) {
new MockDomStorageTaskRunner(base::MessageLoopProxy::current())));
// Inject an in-memory db to speed up the test.
- area->backing_.reset(new DomStorageDatabase());
+ area->backing_.reset(new LocalStorageDatabaseAdapter());
// Unowned ptrs we use to verify that 'purge' has happened.
- DomStorageDatabase* original_backing = area->backing_.get();
+ DomStorageDatabase* original_backing =
+ static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
DomStorageMap* original_map = area->map_.get();
// Should do no harm when called on a newly constructed object.
EXPECT_FALSE(area->is_initial_import_done_);
area->PurgeMemory();
EXPECT_FALSE(area->is_initial_import_done_);
- EXPECT_EQ(original_backing, area->backing_.get());
+ DomStorageDatabase* new_backing = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
+ EXPECT_EQ(original_backing, new_backing);
EXPECT_EQ(original_map, area->map_.get());
// Should not do anything when commits are pending.
@@ -389,20 +402,26 @@ TEST_F(DomStorageAreaTest, PurgeMemory) {
area->PurgeMemory();
EXPECT_TRUE(area->is_initial_import_done_);
EXPECT_TRUE(area->HasUncommittedChanges());
- EXPECT_EQ(original_backing, area->backing_.get());
+ new_backing = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
+ EXPECT_EQ(original_backing, new_backing);
EXPECT_EQ(original_map, area->map_.get());
// Commit the changes from above,
MessageLoop::current()->RunAllPending();
EXPECT_FALSE(area->HasUncommittedChanges());
- EXPECT_EQ(original_backing, area->backing_.get());
+ new_backing = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
+ EXPECT_EQ(original_backing, new_backing);
EXPECT_EQ(original_map, area->map_.get());
// Should drop caches and reset database connections
// when invoked on an area that's loaded up primed.
area->PurgeMemory();
EXPECT_FALSE(area->is_initial_import_done_);
- EXPECT_NE(original_backing, area->backing_.get());
+ new_backing = static_cast<LocalStorageDatabaseAdapter*>(
+ area->backing_.get())->db_.get();
+ EXPECT_NE(original_backing, new_backing);
EXPECT_NE(original_map, area->map_.get());
}

Powered by Google App Engine
This is Rietveld 408576698