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