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

Unified Diff: webkit/dom_storage/dom_storage_database_unittest.cc

Issue 9467003: Delete empty dom storage databases on destruction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 10 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
« no previous file with comments | « webkit/dom_storage/dom_storage_database.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/dom_storage/dom_storage_database_unittest.cc
diff --git a/webkit/dom_storage/dom_storage_database_unittest.cc b/webkit/dom_storage/dom_storage_database_unittest.cc
index 3f2ec2630dcd54abbe7d4e6581158eaa3772ca12..f3a3db0e349a5952e095fed3a6371cb7aca303ad 100644
--- a/webkit/dom_storage/dom_storage_database_unittest.cc
+++ b/webkit/dom_storage/dom_storage_database_unittest.cc
@@ -113,6 +113,60 @@ TEST(DomStorageDatabaseTest, SimpleOpenAndClose) {
EXPECT_FALSE(db.IsOpen());
}
+TEST(DomStorageDatabaseTest, CloseEmptyDatabaseDeletesFile) {
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ FilePath file_name = temp_dir.path().AppendASCII("TestDomStorageDatabase.db");
+ ValuesMap storage;
+ CreateMapWithValues(&storage);
+
+ // First test the case that explicitly clearing the database will
+ // trigger it's deletion from disk.
+ {
+ DomStorageDatabase db(file_name);
+ ASSERT_TRUE(db.CommitChanges(false, storage));
+ }
+ EXPECT_TRUE(file_util::PathExists(file_name));
+
+ {
+ // Check that reading an existing db with data in it
+ // keeps the DB on disk on close.
+ DomStorageDatabase db(file_name);
+ ValuesMap values;
+ db.ReadAllValues(&values);
+ EXPECT_EQ(storage.size(), values.size());
+ }
+
+ EXPECT_TRUE(file_util::PathExists(file_name));
+ storage.clear();
+
+ {
+ DomStorageDatabase db(file_name);
+ ASSERT_TRUE(db.CommitChanges(true, storage));
+ }
+ EXPECT_FALSE(file_util::PathExists(file_name));
+
+ // Now ensure that a series of updates and removals whose net effect
+ // is an empty database also triggers deletion.
+ CreateMapWithValues(&storage);
+ {
+ DomStorageDatabase db(file_name);
+ ASSERT_TRUE(db.CommitChanges(false, storage));
+ }
+
+ EXPECT_TRUE(file_util::PathExists(file_name));
+
+ {
+ DomStorageDatabase db(file_name);
+ ASSERT_TRUE(db.CommitChanges(false, storage));
+ ValuesMap::iterator it = storage.begin();
+ for (; it != storage.end(); ++it)
+ it->second = NullableString16(true);
+ ASSERT_TRUE(db.CommitChanges(false, storage));
+ }
+ EXPECT_FALSE(file_util::PathExists(file_name));
+}
+
TEST(DomStorageDatabaseTest, TestLazyOpenIsLazy) {
// This test needs to operate with a file on disk to ensure that we will
// open a file that already exists when only invoking ReadAllValues.
« no previous file with comments | « webkit/dom_storage/dom_storage_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698