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

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: 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 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 "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 {
124 DomStorageDatabase db(file_name);
125 ASSERT_TRUE(db.CommitChanges(false, storage));
126 }
127
128 EXPECT_TRUE(file_util::PathExists(file_name));
129 storage.clear();
130
131 {
132 DomStorageDatabase db(file_name);
133 ASSERT_TRUE(db.CommitChanges(true, storage));
134 }
135 EXPECT_FALSE(file_util::PathExists(file_name));
136 }
137
116 TEST(DomStorageDatabaseTest, TestLazyOpenIsLazy) { 138 TEST(DomStorageDatabaseTest, TestLazyOpenIsLazy) {
117 // This test needs to operate with a file on disk to ensure that we will 139 // 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. 140 // open a file that already exists when only invoking ReadAllValues.
119 ScopedTempDir temp_dir; 141 ScopedTempDir temp_dir;
120 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 142 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
121 FilePath file_name = temp_dir.path().AppendASCII("TestDomStorageDatabase.db"); 143 FilePath file_name = temp_dir.path().AppendASCII("TestDomStorageDatabase.db");
122 144
123 DomStorageDatabase db(file_name); 145 DomStorageDatabase db(file_name);
124 EXPECT_FALSE(db.IsOpen()); 146 EXPECT_FALSE(db.IsOpen());
125 ValuesMap values; 147 ValuesMap values;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 340
319 db.ReadAllValues(&values); 341 db.ReadAllValues(&values);
320 EXPECT_EQ(0u, values.size()); 342 EXPECT_EQ(0u, values.size());
321 EXPECT_FALSE(db.IsOpen()); 343 EXPECT_FALSE(db.IsOpen());
322 344
323 EXPECT_TRUE(file_util::PathExists(temp_dir.path())); 345 EXPECT_TRUE(file_util::PathExists(temp_dir.path()));
324 } 346 }
325 } 347 }
326 348
327 } // namespace dom_storage 349 } // namespace dom_storage
OLDNEW
« webkit/dom_storage/dom_storage_database.cc ('K') | « 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