| Index: webkit/fileapi/file_system_directory_database_unittest.cc
|
| diff --git a/webkit/fileapi/file_system_directory_database_unittest.cc b/webkit/fileapi/file_system_directory_database_unittest.cc
|
| index 3a47c91c8d0ca286439120e87466bca7cd35964e..82c94d75ad035457476f050d8cf9ed94f822abd8 100644
|
| --- a/webkit/fileapi/file_system_directory_database_unittest.cc
|
| +++ b/webkit/fileapi/file_system_directory_database_unittest.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include <math.h>
|
|
|
| +#include "base/platform_file.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/scoped_temp_dir.h"
|
| #include "base/string_number_conversions.h"
|
| @@ -29,9 +30,12 @@ class FileSystemDirectoryDatabaseTest : public testing::Test {
|
| }
|
|
|
| void InitDatabase() {
|
| + CloseDatabase();
|
| + db_.reset(new FileSystemDirectoryDatabase(db_path()));
|
| + }
|
| +
|
| + void CloseDatabase() {
|
| db_.reset();
|
| - FilePath path = base_.path().AppendASCII("db");
|
| - db_.reset(new FileSystemDirectoryDatabase(path));
|
| }
|
|
|
| bool AddFileInfo(FileId parent_id, const FilePath::StringType& name) {
|
| @@ -42,6 +46,10 @@ class FileSystemDirectoryDatabaseTest : public testing::Test {
|
| return db_->AddFileInfo(info, &file_id);
|
| }
|
|
|
| + FilePath db_path() const {
|
| + return base_.path().AppendASCII("db");
|
| + }
|
| +
|
| protected:
|
| // Common temp base for nondestructive uses.
|
| ScopedTempDir base_;
|
| @@ -417,4 +425,28 @@ TEST_F(FileSystemDirectoryDatabaseTest, TestGetNextInteger) {
|
| EXPECT_EQ(4, next);
|
| }
|
|
|
| +TEST_F(FileSystemDirectoryDatabaseTest, TestDatabaseRecovery) {
|
| + int64 next = -1;
|
| + EXPECT_TRUE(db()->GetNextInteger(&next));
|
| + EXPECT_EQ(0, next);
|
| + InitDatabase();
|
| + EXPECT_TRUE(db()->GetNextInteger(&next));
|
| + EXPECT_EQ(1, next);
|
| + CloseDatabase();
|
| +
|
| + bool created = false;
|
| + base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED;
|
| + base::PlatformFile file = base::CreatePlatformFile(
|
| + db_path().AppendASCII("CURRENT"),
|
| + base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE,
|
| + &created, &error);
|
| + EXPECT_EQ(base::PLATFORM_FILE_OK, error);
|
| + EXPECT_TRUE(created);
|
| + EXPECT_TRUE(base::ClosePlatformFile(file));
|
| +
|
| + InitDatabase();
|
| + EXPECT_TRUE(db()->GetNextInteger(&next));
|
| + EXPECT_EQ(0, next);
|
| +}
|
| +
|
| } // namespace fileapi
|
|
|