| 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..5a24871cbf6f22b5e575df5edb2033ad0b69070d 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"
|
| @@ -14,6 +15,10 @@
|
|
|
| namespace fileapi {
|
|
|
| +namespace {
|
| +const FilePath::CharType kDirectoryDatabaseName[] = FILE_PATH_LITERAL("Paths");
|
| +}
|
| +
|
| class FileSystemDirectoryDatabaseTest : public testing::Test {
|
| public:
|
| typedef FileSystemDirectoryDatabase::FileId FileId;
|
| @@ -29,9 +34,12 @@ class FileSystemDirectoryDatabaseTest : public testing::Test {
|
| }
|
|
|
| void InitDatabase() {
|
| + CloseDatabase();
|
| + db_.reset(new FileSystemDirectoryDatabase(sandbox_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 +50,10 @@ class FileSystemDirectoryDatabaseTest : public testing::Test {
|
| return db_->AddFileInfo(info, &file_id);
|
| }
|
|
|
| + FilePath sandbox_path() const {
|
| + return base_.path();
|
| + }
|
| +
|
| protected:
|
| // Common temp base for nondestructive uses.
|
| ScopedTempDir base_;
|
| @@ -417,4 +429,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(
|
| + sandbox_path().Append(kDirectoryDatabaseName).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
|
|
|