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

Side by Side 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, 9 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_database.cc ('k') | no next file » | 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 "webkit/dom_storage/dom_storage_database.h" 5 #include "webkit/dom_storage/dom_storage_database.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 TEST(DomStorageDatabaseTest, SimpleOpenAndClose) { 106 TEST(DomStorageDatabaseTest, SimpleOpenAndClose) {
107 DomStorageDatabase db; 107 DomStorageDatabase db;
108 EXPECT_FALSE(db.IsOpen()); 108 EXPECT_FALSE(db.IsOpen());
109 ASSERT_TRUE(db.LazyOpen(true)); 109 ASSERT_TRUE(db.LazyOpen(true));
110 EXPECT_TRUE(db.IsOpen()); 110 EXPECT_TRUE(db.IsOpen());
111 EXPECT_EQ(DomStorageDatabase::V2, db.DetectSchemaVersion()); 111 EXPECT_EQ(DomStorageDatabase::V2, db.DetectSchemaVersion());
112 db.Close(); 112 db.Close();
113 EXPECT_FALSE(db.IsOpen()); 113 EXPECT_FALSE(db.IsOpen());
114 } 114 }
115 115
116 TEST(DomStorageDatabaseTest, CloseEmptyDatabaseDeletesFile) {
117 ScopedTempDir temp_dir;
118 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
119 FilePath file_name = temp_dir.path().AppendASCII("TestDomStorageDatabase.db");
120 ValuesMap storage;
121 CreateMapWithValues(&storage);
122
123 // First test the case that explicitly clearing the database will
124 // trigger it's deletion from disk.
125 {
126 DomStorageDatabase db(file_name);
127 ASSERT_TRUE(db.CommitChanges(false, storage));
128 }
129 EXPECT_TRUE(file_util::PathExists(file_name));
130
131 {
132 // Check that reading an existing db with data in it
133 // keeps the DB on disk on close.
134 DomStorageDatabase db(file_name);
135 ValuesMap values;
136 db.ReadAllValues(&values);
137 EXPECT_EQ(storage.size(), values.size());
138 }
139
140 EXPECT_TRUE(file_util::PathExists(file_name));
141 storage.clear();
142
143 {
144 DomStorageDatabase db(file_name);
145 ASSERT_TRUE(db.CommitChanges(true, storage));
146 }
147 EXPECT_FALSE(file_util::PathExists(file_name));
148
149 // Now ensure that a series of updates and removals whose net effect
150 // is an empty database also triggers deletion.
151 CreateMapWithValues(&storage);
152 {
153 DomStorageDatabase db(file_name);
154 ASSERT_TRUE(db.CommitChanges(false, storage));
155 }
156
157 EXPECT_TRUE(file_util::PathExists(file_name));
158
159 {
160 DomStorageDatabase db(file_name);
161 ASSERT_TRUE(db.CommitChanges(false, storage));
162 ValuesMap::iterator it = storage.begin();
163 for (; it != storage.end(); ++it)
164 it->second = NullableString16(true);
165 ASSERT_TRUE(db.CommitChanges(false, storage));
166 }
167 EXPECT_FALSE(file_util::PathExists(file_name));
168 }
169
116 TEST(DomStorageDatabaseTest, TestLazyOpenIsLazy) { 170 TEST(DomStorageDatabaseTest, TestLazyOpenIsLazy) {
117 // This test needs to operate with a file on disk to ensure that we will 171 // This test needs to operate with a file on disk to ensure that we will
118 // open a file that already exists when only invoking ReadAllValues. 172 // open a file that already exists when only invoking ReadAllValues.
119 ScopedTempDir temp_dir; 173 ScopedTempDir temp_dir;
120 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 174 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
121 FilePath file_name = temp_dir.path().AppendASCII("TestDomStorageDatabase.db"); 175 FilePath file_name = temp_dir.path().AppendASCII("TestDomStorageDatabase.db");
122 176
123 DomStorageDatabase db(file_name); 177 DomStorageDatabase db(file_name);
124 EXPECT_FALSE(db.IsOpen()); 178 EXPECT_FALSE(db.IsOpen());
125 ValuesMap values; 179 ValuesMap values;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 372
319 db.ReadAllValues(&values); 373 db.ReadAllValues(&values);
320 EXPECT_EQ(0u, values.size()); 374 EXPECT_EQ(0u, values.size());
321 EXPECT_FALSE(db.IsOpen()); 375 EXPECT_FALSE(db.IsOpen());
322 376
323 EXPECT_TRUE(file_util::PathExists(temp_dir.path())); 377 EXPECT_TRUE(file_util::PathExists(temp_dir.path()));
324 } 378 }
325 } 379 }
326 380
327 } // namespace dom_storage 381 } // namespace dom_storage
OLDNEW
« 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