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

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

Issue 2316043002: //content: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Just rebased Created 4 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/dom_storage/dom_storage_database.h" 5 #include "content/browser/dom_storage/dom_storage_database.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 EXPECT_TRUE(db.IsOpen()); 108 EXPECT_TRUE(db.IsOpen());
109 EXPECT_EQ(DOMStorageDatabase::V2, db.DetectSchemaVersion()); 109 EXPECT_EQ(DOMStorageDatabase::V2, db.DetectSchemaVersion());
110 db.Close(); 110 db.Close();
111 EXPECT_FALSE(db.IsOpen()); 111 EXPECT_FALSE(db.IsOpen());
112 } 112 }
113 113
114 TEST(DOMStorageDatabaseTest, CloseEmptyDatabaseDeletesFile) { 114 TEST(DOMStorageDatabaseTest, CloseEmptyDatabaseDeletesFile) {
115 base::ScopedTempDir temp_dir; 115 base::ScopedTempDir temp_dir;
116 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 116 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
117 base::FilePath file_name = 117 base::FilePath file_name =
118 temp_dir.path().AppendASCII("TestDOMStorageDatabase.db"); 118 temp_dir.GetPath().AppendASCII("TestDOMStorageDatabase.db");
119 DOMStorageValuesMap storage; 119 DOMStorageValuesMap storage;
120 CreateMapWithValues(&storage); 120 CreateMapWithValues(&storage);
121 121
122 // First test the case that explicitly clearing the database will 122 // First test the case that explicitly clearing the database will
123 // trigger its deletion from disk. 123 // trigger its deletion from disk.
124 { 124 {
125 DOMStorageDatabase db(file_name); 125 DOMStorageDatabase db(file_name);
126 EXPECT_EQ(file_name, db.file_path()); 126 EXPECT_EQ(file_name, db.file_path());
127 ASSERT_TRUE(db.CommitChanges(false, storage)); 127 ASSERT_TRUE(db.CommitChanges(false, storage));
128 } 128 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 166 }
167 EXPECT_FALSE(base::PathExists(file_name)); 167 EXPECT_FALSE(base::PathExists(file_name));
168 } 168 }
169 169
170 TEST(DOMStorageDatabaseTest, TestLazyOpenIsLazy) { 170 TEST(DOMStorageDatabaseTest, TestLazyOpenIsLazy) {
171 // 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
172 // open a file that already exists when only invoking ReadAllValues. 172 // open a file that already exists when only invoking ReadAllValues.
173 base::ScopedTempDir temp_dir; 173 base::ScopedTempDir temp_dir;
174 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 174 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
175 base::FilePath file_name = 175 base::FilePath file_name =
176 temp_dir.path().AppendASCII("TestDOMStorageDatabase.db"); 176 temp_dir.GetPath().AppendASCII("TestDOMStorageDatabase.db");
177 177
178 DOMStorageDatabase db(file_name); 178 DOMStorageDatabase db(file_name);
179 EXPECT_FALSE(db.IsOpen()); 179 EXPECT_FALSE(db.IsOpen());
180 DOMStorageValuesMap values; 180 DOMStorageValuesMap values;
181 db.ReadAllValues(&values); 181 db.ReadAllValues(&values);
182 // Reading an empty db should not open the database. 182 // Reading an empty db should not open the database.
183 EXPECT_FALSE(db.IsOpen()); 183 EXPECT_FALSE(db.IsOpen());
184 184
185 values[ASCIIToUTF16("key")] = 185 values[ASCIIToUTF16("key")] =
186 base::NullableString16(ASCIIToUTF16("value"), false); 186 base::NullableString16(ASCIIToUTF16("value"), false);
(...skipping 28 matching lines...) Expand all
215 } 215 }
216 216
217 TEST(DOMStorageDatabaseTest, TestLazyOpenUpgradesDatabase) { 217 TEST(DOMStorageDatabaseTest, TestLazyOpenUpgradesDatabase) {
218 // This test needs to operate with a file on disk so that we 218 // This test needs to operate with a file on disk so that we
219 // can create a table at version 1 and then close it again 219 // can create a table at version 1 and then close it again
220 // so that LazyOpen sees there is work to do (LazyOpen will return 220 // so that LazyOpen sees there is work to do (LazyOpen will return
221 // early if the database is already open). 221 // early if the database is already open).
222 base::ScopedTempDir temp_dir; 222 base::ScopedTempDir temp_dir;
223 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 223 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
224 base::FilePath file_name = 224 base::FilePath file_name =
225 temp_dir.path().AppendASCII("TestDOMStorageDatabase.db"); 225 temp_dir.GetPath().AppendASCII("TestDOMStorageDatabase.db");
226 226
227 DOMStorageDatabase db(file_name); 227 DOMStorageDatabase db(file_name);
228 db.db_.reset(new sql::Connection()); 228 db.db_.reset(new sql::Connection());
229 ASSERT_TRUE(db.db_->Open(file_name)); 229 ASSERT_TRUE(db.db_->Open(file_name));
230 CreateV1Table(db.db_.get()); 230 CreateV1Table(db.db_.get());
231 db.Close(); 231 db.Close();
232 232
233 EXPECT_TRUE(db.LazyOpen(true)); 233 EXPECT_TRUE(db.LazyOpen(true));
234 EXPECT_EQ(DOMStorageDatabase::V2, db.DetectSchemaVersion()); 234 EXPECT_EQ(DOMStorageDatabase::V2, db.DetectSchemaVersion());
235 } 235 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 334
335 it = values.find(ASCIIToUTF16("not_there")); 335 it = values.find(ASCIIToUTF16("not_there"));
336 EXPECT_TRUE(it == values.end()); 336 EXPECT_TRUE(it == values.end());
337 } 337 }
338 338
339 TEST(DOMStorageDatabaseTest, TestCanOpenFileThatIsNotADatabase) { 339 TEST(DOMStorageDatabaseTest, TestCanOpenFileThatIsNotADatabase) {
340 // Write into the temporary file first. 340 // Write into the temporary file first.
341 base::ScopedTempDir temp_dir; 341 base::ScopedTempDir temp_dir;
342 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 342 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
343 base::FilePath file_name = 343 base::FilePath file_name =
344 temp_dir.path().AppendASCII("TestDOMStorageDatabase.db"); 344 temp_dir.GetPath().AppendASCII("TestDOMStorageDatabase.db");
345 345
346 const char kData[] = "I am not a database."; 346 const char kData[] = "I am not a database.";
347 base::WriteFile(file_name, kData, strlen(kData)); 347 base::WriteFile(file_name, kData, strlen(kData));
348 348
349 { 349 {
350 sql::test::ScopedErrorExpecter expecter; 350 sql::test::ScopedErrorExpecter expecter;
351 351
352 // Earlier versions of Chromium compiled against SQLite 3.6.7.3, which 352 // Earlier versions of Chromium compiled against SQLite 3.6.7.3, which
353 // returned SQLITE_IOERR_SHORT_READ in this case. Some platforms may still 353 // returned SQLITE_IOERR_SHORT_READ in this case. Some platforms may still
354 // compile against an earlier SQLite via USE_SYSTEM_SQLITE. 354 // compile against an earlier SQLite via USE_SYSTEM_SQLITE.
(...skipping 17 matching lines...) Expand all
372 372
373 ASSERT_TRUE(expecter.SawExpectedErrors()); 373 ASSERT_TRUE(expecter.SawExpectedErrors());
374 } 374 }
375 375
376 { 376 {
377 sql::test::ScopedErrorExpecter expecter; 377 sql::test::ScopedErrorExpecter expecter;
378 expecter.ExpectError(SQLITE_CANTOPEN); 378 expecter.ExpectError(SQLITE_CANTOPEN);
379 379
380 // Try to open a directory, we should fail gracefully and not attempt 380 // Try to open a directory, we should fail gracefully and not attempt
381 // to delete it. 381 // to delete it.
382 DOMStorageDatabase db(temp_dir.path()); 382 DOMStorageDatabase db(temp_dir.GetPath());
383 DOMStorageValuesMap values; 383 DOMStorageValuesMap values;
384 CreateMapWithValues(&values); 384 CreateMapWithValues(&values);
385 EXPECT_FALSE(db.CommitChanges(true, values)); 385 EXPECT_FALSE(db.CommitChanges(true, values));
386 EXPECT_FALSE(db.CommitChanges(false, values)); 386 EXPECT_FALSE(db.CommitChanges(false, values));
387 EXPECT_FALSE(db.IsOpen()); 387 EXPECT_FALSE(db.IsOpen());
388 388
389 values.clear(); 389 values.clear();
390 390
391 db.ReadAllValues(&values); 391 db.ReadAllValues(&values);
392 EXPECT_EQ(0u, values.size()); 392 EXPECT_EQ(0u, values.size());
393 EXPECT_FALSE(db.IsOpen()); 393 EXPECT_FALSE(db.IsOpen());
394 394
395 EXPECT_TRUE(base::PathExists(temp_dir.path())); 395 EXPECT_TRUE(base::PathExists(temp_dir.GetPath()));
396 396
397 ASSERT_TRUE(expecter.SawExpectedErrors()); 397 ASSERT_TRUE(expecter.SawExpectedErrors());
398 } 398 }
399 } 399 }
400 400
401 } // namespace content 401 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698