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/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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(file_util::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(true); | 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(file_util::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()); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 ValuesMap expected; | 290 ValuesMap expected; |
291 expected[kCannedKey] = kCannedValue; | 291 expected[kCannedKey] = kCannedValue; |
292 | 292 |
293 // First write some data into the database. | 293 // First write some data into the database. |
294 ASSERT_TRUE(db.CommitChanges(false, expected)); | 294 ASSERT_TRUE(db.CommitChanges(false, expected)); |
295 CheckValuesMatch(&db, expected); | 295 CheckValuesMatch(&db, expected); |
296 | 296 |
297 ValuesMap values; | 297 ValuesMap values; |
298 // A null string in the map should mean that that key gets | 298 // A null string in the map should mean that that key gets |
299 // removed. | 299 // removed. |
300 values[kCannedKey] = base::NullableString16(true); | 300 values[kCannedKey] = base::NullableString16(); |
301 EXPECT_TRUE(db.CommitChanges(false, values)); | 301 EXPECT_TRUE(db.CommitChanges(false, values)); |
302 | 302 |
303 expected.clear(); | 303 expected.clear(); |
304 CheckValuesMatch(&db, expected); | 304 CheckValuesMatch(&db, expected); |
305 } | 305 } |
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"); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(file_util::PathExists(temp_dir.path())); |
378 } | 378 } |
379 } | 379 } |
380 | 380 |
381 } // namespace dom_storage | 381 } // namespace dom_storage |
OLD | NEW |