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

Side by Side Diff: webkit/browser/dom_storage/dom_storage_database_unittest.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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/browser/dom_storage/dom_storage_database.h" 5 #include "webkit/browser/dom_storage/dom_storage_database.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 ValuesMap storage; 115 ValuesMap storage;
116 CreateMapWithValues(&storage); 116 CreateMapWithValues(&storage);
117 117
118 // First test the case that explicitly clearing the database will 118 // First test the case that explicitly clearing the database will
119 // trigger its deletion from disk. 119 // trigger its deletion from disk.
120 { 120 {
121 DomStorageDatabase db(file_name); 121 DomStorageDatabase db(file_name);
122 EXPECT_EQ(file_name, db.file_path()); 122 EXPECT_EQ(file_name, db.file_path());
123 ASSERT_TRUE(db.CommitChanges(false, storage)); 123 ASSERT_TRUE(db.CommitChanges(false, storage));
124 } 124 }
125 EXPECT_TRUE(file_util::PathExists(file_name)); 125 EXPECT_TRUE(base::PathExists(file_name));
126 126
127 { 127 {
128 // Check that reading an existing db with data in it 128 // Check that reading an existing db with data in it
129 // keeps the DB on disk on close. 129 // keeps the DB on disk on close.
130 DomStorageDatabase db(file_name); 130 DomStorageDatabase db(file_name);
131 ValuesMap values; 131 ValuesMap values;
132 db.ReadAllValues(&values); 132 db.ReadAllValues(&values);
133 EXPECT_EQ(storage.size(), values.size()); 133 EXPECT_EQ(storage.size(), values.size());
134 } 134 }
135 135
136 EXPECT_TRUE(file_util::PathExists(file_name)); 136 EXPECT_TRUE(base::PathExists(file_name));
137 storage.clear(); 137 storage.clear();
138 138
139 { 139 {
140 DomStorageDatabase db(file_name); 140 DomStorageDatabase db(file_name);
141 ASSERT_TRUE(db.CommitChanges(true, storage)); 141 ASSERT_TRUE(db.CommitChanges(true, storage));
142 } 142 }
143 EXPECT_FALSE(file_util::PathExists(file_name)); 143 EXPECT_FALSE(base::PathExists(file_name));
144 144
145 // Now ensure that a series of updates and removals whose net effect 145 // Now ensure that a series of updates and removals whose net effect
146 // is an empty database also triggers deletion. 146 // is an empty database also triggers deletion.
147 CreateMapWithValues(&storage); 147 CreateMapWithValues(&storage);
148 { 148 {
149 DomStorageDatabase db(file_name); 149 DomStorageDatabase db(file_name);
150 ASSERT_TRUE(db.CommitChanges(false, storage)); 150 ASSERT_TRUE(db.CommitChanges(false, storage));
151 } 151 }
152 152
153 EXPECT_TRUE(file_util::PathExists(file_name)); 153 EXPECT_TRUE(base::PathExists(file_name));
154 154
155 { 155 {
156 DomStorageDatabase db(file_name); 156 DomStorageDatabase db(file_name);
157 ASSERT_TRUE(db.CommitChanges(false, storage)); 157 ASSERT_TRUE(db.CommitChanges(false, storage));
158 ValuesMap::iterator it = storage.begin(); 158 ValuesMap::iterator it = storage.begin();
159 for (; it != storage.end(); ++it) 159 for (; it != storage.end(); ++it)
160 it->second = base::NullableString16(); 160 it->second = base::NullableString16();
161 ASSERT_TRUE(db.CommitChanges(false, storage)); 161 ASSERT_TRUE(db.CommitChanges(false, storage));
162 } 162 }
163 EXPECT_FALSE(file_util::PathExists(file_name)); 163 EXPECT_FALSE(base::PathExists(file_name));
164 } 164 }
165 165
166 TEST(DomStorageDatabaseTest, TestLazyOpenIsLazy) { 166 TEST(DomStorageDatabaseTest, TestLazyOpenIsLazy) {
167 // This test needs to operate with a file on disk to ensure that we will 167 // This test needs to operate with a file on disk to ensure that we will
168 // open a file that already exists when only invoking ReadAllValues. 168 // open a file that already exists when only invoking ReadAllValues.
169 base::ScopedTempDir temp_dir; 169 base::ScopedTempDir temp_dir;
170 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 170 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
171 base::FilePath file_name = 171 base::FilePath file_name =
172 temp_dir.path().AppendASCII("TestDomStorageDatabase.db"); 172 temp_dir.path().AppendASCII("TestDomStorageDatabase.db");
173 173
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 306
307 TEST(DomStorageDatabaseTest, TestCanOpenAndReadWebCoreDatabase) { 307 TEST(DomStorageDatabaseTest, TestCanOpenAndReadWebCoreDatabase) {
308 base::FilePath webcore_database; 308 base::FilePath webcore_database;
309 PathService::Get(base::DIR_SOURCE_ROOT, &webcore_database); 309 PathService::Get(base::DIR_SOURCE_ROOT, &webcore_database);
310 webcore_database = webcore_database.AppendASCII("webkit"); 310 webcore_database = webcore_database.AppendASCII("webkit");
311 webcore_database = webcore_database.AppendASCII("data"); 311 webcore_database = webcore_database.AppendASCII("data");
312 webcore_database = webcore_database.AppendASCII("dom_storage"); 312 webcore_database = webcore_database.AppendASCII("dom_storage");
313 webcore_database = 313 webcore_database =
314 webcore_database.AppendASCII("webcore_test_database.localstorage"); 314 webcore_database.AppendASCII("webcore_test_database.localstorage");
315 315
316 ASSERT_TRUE(file_util::PathExists(webcore_database)); 316 ASSERT_TRUE(base::PathExists(webcore_database));
317 317
318 DomStorageDatabase db(webcore_database); 318 DomStorageDatabase db(webcore_database);
319 ValuesMap values; 319 ValuesMap values;
320 db.ReadAllValues(&values); 320 db.ReadAllValues(&values);
321 EXPECT_TRUE(db.IsOpen()); 321 EXPECT_TRUE(db.IsOpen());
322 EXPECT_EQ(2u, values.size()); 322 EXPECT_EQ(2u, values.size());
323 323
324 ValuesMap::const_iterator it = 324 ValuesMap::const_iterator it =
325 values.find(ASCIIToUTF16("value")); 325 values.find(ASCIIToUTF16("value"));
326 EXPECT_TRUE(it != values.end()); 326 EXPECT_TRUE(it != values.end());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 EXPECT_FALSE(db.CommitChanges(true, values)); 367 EXPECT_FALSE(db.CommitChanges(true, values));
368 EXPECT_FALSE(db.CommitChanges(false, values)); 368 EXPECT_FALSE(db.CommitChanges(false, values));
369 EXPECT_FALSE(db.IsOpen()); 369 EXPECT_FALSE(db.IsOpen());
370 370
371 values.clear(); 371 values.clear();
372 372
373 db.ReadAllValues(&values); 373 db.ReadAllValues(&values);
374 EXPECT_EQ(0u, values.size()); 374 EXPECT_EQ(0u, values.size());
375 EXPECT_FALSE(db.IsOpen()); 375 EXPECT_FALSE(db.IsOpen());
376 376
377 EXPECT_TRUE(file_util::PathExists(temp_dir.path())); 377 EXPECT_TRUE(base::PathExists(temp_dir.path()));
378 } 378 }
379 } 379 }
380 380
381 } // namespace dom_storage 381 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/browser/dom_storage/dom_storage_database.cc ('k') | webkit/browser/dom_storage/session_storage_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698