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
3 // found in the LICENSE file.
5 #include "webkit/fileapi/file_system_directory_database.h"
9 #include "base/file_util.h"
10 #include "base/platform_file.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/scoped_temp_dir.h"
13 #include "base/string_number_conversions.h"
14 #include "base/string_util.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/leveldatabase/src/include/leveldb/db.h"
17 #include "webkit/fileapi/file_system_database_test_helper.h"
18 #include "webkit/fileapi/file_system_util.h"
20 #define FPL(x) FILE_PATH_LITERAL(x)
25 const FilePath::CharType kDirectoryDatabaseName
[] = FPL("Paths");
28 class FileSystemDirectoryDatabaseTest
: public testing::Test
{
30 typedef FileSystemDirectoryDatabase::FileId FileId
;
31 typedef FileSystemDirectoryDatabase::FileInfo FileInfo
;
33 FileSystemDirectoryDatabaseTest() {
34 EXPECT_TRUE(base_
.CreateUniqueTempDir());
38 FileSystemDirectoryDatabase
* db() {
43 // Call CloseDatabase() to avoid having multiple database instances for
44 // single directory at once.
46 db_
.reset(new FileSystemDirectoryDatabase(path()));
49 void CloseDatabase() {
53 bool AddFileInfo(FileId parent_id
, const FilePath::StringType
& name
) {
56 info
.parent_id
= parent_id
;
58 return db_
->AddFileInfo(info
, &file_id
);
61 void CreateDirectory(FileId parent_id
,
62 const FilePath::StringType
& name
,
63 FileId
* file_id_out
) {
65 info
.parent_id
= parent_id
;
67 ASSERT_TRUE(db_
->AddFileInfo(info
, file_id_out
));
70 void CreateFile(FileId parent_id
,
71 const FilePath::StringType
& name
,
72 const FilePath::StringType
& data_path
,
73 FileId
* file_id_out
) {
77 info
.parent_id
= parent_id
;
79 info
.data_path
= FilePath(data_path
).NormalizePathSeparators();
80 ASSERT_TRUE(db_
->AddFileInfo(info
, &file_id
));
82 FilePath local_path
= path().Append(data_path
);
83 if (!file_util::DirectoryExists(local_path
.DirName()))
84 ASSERT_TRUE(file_util::CreateDirectory(local_path
.DirName()));
87 base::PlatformFileError error
= base::PLATFORM_FILE_ERROR_FAILED
;
88 base::PlatformFile file
= base::CreatePlatformFile(
90 base::PLATFORM_FILE_CREATE
| base::PLATFORM_FILE_WRITE
,
92 ASSERT_EQ(base::PLATFORM_FILE_OK
, error
);
94 ASSERT_TRUE(base::ClosePlatformFile(file
));
97 *file_id_out
= file_id
;
100 void ClearDatabaseAndDirectory() {
102 ASSERT_TRUE(file_util::Delete(path(), true /* recursive */));
103 ASSERT_TRUE(file_util::CreateDirectory(path()));
104 db_
.reset(new FileSystemDirectoryDatabase(path()));
107 bool RepairDatabase() {
108 return db()->RepairDatabase(
109 FilePathToString(path().Append(kDirectoryDatabaseName
)));
112 const FilePath
& path() {
116 // Makes link from |parent_id| to |child_id| with |name|.
117 void MakeHierarchyLink(FileId parent_id
,
119 const FilePath::StringType
& name
) {
120 ASSERT_TRUE(db()->db_
->Put(
121 leveldb::WriteOptions(),
122 "CHILD_OF:" + base::Int64ToString(parent_id
) + ":" +
123 FilePathToString(FilePath(name
)),
124 base::Int64ToString(child_id
)).ok());
127 // Deletes link from parent of |file_id| to |file_id|.
128 void DeleteHierarchyLink(FileId file_id
) {
130 ASSERT_TRUE(db()->GetFileInfo(file_id
, &file_info
));
131 ASSERT_TRUE(db()->db_
->Delete(
132 leveldb::WriteOptions(),
133 "CHILD_OF:" + base::Int64ToString(file_info
.parent_id
) + ":" +
134 FilePathToString(FilePath(file_info
.name
))).ok());
138 // Common temp base for nondestructive uses.
140 scoped_ptr
<FileSystemDirectoryDatabase
> db_
;
142 DISALLOW_COPY_AND_ASSIGN(FileSystemDirectoryDatabaseTest
);
145 TEST_F(FileSystemDirectoryDatabaseTest
, TestMissingFileGetInfo
) {
146 FileId file_id
= 888;
148 EXPECT_FALSE(db()->GetFileInfo(file_id
, &info
));
151 TEST_F(FileSystemDirectoryDatabaseTest
, TestGetRootFileInfoBeforeCreate
) {
154 EXPECT_TRUE(db()->GetFileInfo(file_id
, &info
));
155 EXPECT_EQ(0, info
.parent_id
);
156 EXPECT_TRUE(info
.name
.empty());
157 EXPECT_TRUE(info
.data_path
.empty());
160 TEST_F(FileSystemDirectoryDatabaseTest
, TestMissingParentAddFileInfo
) {
161 FileId parent_id
= 7;
162 EXPECT_FALSE(AddFileInfo(parent_id
, FILE_PATH_LITERAL("foo")));
165 TEST_F(FileSystemDirectoryDatabaseTest
, TestAddNameClash
) {
169 info
.name
= FILE_PATH_LITERAL("dir 0");
170 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id
));
172 // Check for name clash in the root directory.
173 FilePath::StringType name
= info
.name
;
174 EXPECT_FALSE(AddFileInfo(0, name
));
175 name
= FILE_PATH_LITERAL("dir 1");
176 EXPECT_TRUE(AddFileInfo(0, name
));
178 name
= FILE_PATH_LITERAL("subdir 0");
179 EXPECT_TRUE(AddFileInfo(file_id
, name
));
181 // Check for name clash in a subdirectory.
182 EXPECT_FALSE(AddFileInfo(file_id
, name
));
183 name
= FILE_PATH_LITERAL("subdir 1");
184 EXPECT_TRUE(AddFileInfo(file_id
, name
));
187 TEST_F(FileSystemDirectoryDatabaseTest
, TestRenameNoMoveNameClash
) {
190 FilePath::StringType name0
= FILE_PATH_LITERAL("foo");
191 FilePath::StringType name1
= FILE_PATH_LITERAL("bar");
192 FilePath::StringType name2
= FILE_PATH_LITERAL("bas");
195 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id0
));
196 EXPECT_TRUE(AddFileInfo(0, name1
));
198 EXPECT_FALSE(db()->UpdateFileInfo(file_id0
, info
));
200 EXPECT_TRUE(db()->UpdateFileInfo(file_id0
, info
));
203 TEST_F(FileSystemDirectoryDatabaseTest
, TestMoveSameNameNameClash
) {
207 FilePath::StringType name0
= FILE_PATH_LITERAL("foo");
208 FilePath::StringType name1
= FILE_PATH_LITERAL("bar");
211 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id0
));
212 info
.parent_id
= file_id0
;
213 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id1
));
215 EXPECT_FALSE(db()->UpdateFileInfo(file_id1
, info
));
217 EXPECT_TRUE(db()->UpdateFileInfo(file_id1
, info
));
220 TEST_F(FileSystemDirectoryDatabaseTest
, TestMoveRenameNameClash
) {
224 FilePath::StringType name0
= FILE_PATH_LITERAL("foo");
225 FilePath::StringType name1
= FILE_PATH_LITERAL("bar");
226 FilePath::StringType name2
= FILE_PATH_LITERAL("bas");
229 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id0
));
230 info
.parent_id
= file_id0
;
232 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id1
));
235 EXPECT_FALSE(db()->UpdateFileInfo(file_id1
, info
));
237 EXPECT_TRUE(db()->UpdateFileInfo(file_id1
, info
));
238 // Also test a successful move+rename.
239 info
.parent_id
= file_id0
;
241 EXPECT_TRUE(db()->UpdateFileInfo(file_id1
, info
));
244 TEST_F(FileSystemDirectoryDatabaseTest
, TestRemoveWithChildren
) {
249 info
.name
= FILE_PATH_LITERAL("foo");
250 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id0
));
251 info
.parent_id
= file_id0
;
252 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id1
));
253 EXPECT_FALSE(db()->RemoveFileInfo(file_id0
));
254 EXPECT_TRUE(db()->RemoveFileInfo(file_id1
));
255 EXPECT_TRUE(db()->RemoveFileInfo(file_id0
));
258 TEST_F(FileSystemDirectoryDatabaseTest
, TestGetChildWithName
) {
262 FilePath::StringType name0
= FILE_PATH_LITERAL("foo");
263 FilePath::StringType name1
= FILE_PATH_LITERAL("bar");
266 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id0
));
267 info
.parent_id
= file_id0
;
269 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id1
));
270 EXPECT_NE(file_id0
, file_id1
);
272 FileId check_file_id
;
273 EXPECT_FALSE(db()->GetChildWithName(0, name1
, &check_file_id
));
274 EXPECT_TRUE(db()->GetChildWithName(0, name0
, &check_file_id
));
275 EXPECT_EQ(file_id0
, check_file_id
);
276 EXPECT_FALSE(db()->GetChildWithName(file_id0
, name0
, &check_file_id
));
277 EXPECT_TRUE(db()->GetChildWithName(file_id0
, name1
, &check_file_id
));
278 EXPECT_EQ(file_id1
, check_file_id
);
281 TEST_F(FileSystemDirectoryDatabaseTest
, TestGetFileWithPath
) {
286 FilePath::StringType name0
= FILE_PATH_LITERAL("foo");
287 FilePath::StringType name1
= FILE_PATH_LITERAL("bar");
288 FilePath::StringType name2
= FILE_PATH_LITERAL("dog");
292 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id0
));
293 info
.parent_id
= file_id0
;
295 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id1
));
296 EXPECT_NE(file_id0
, file_id1
);
297 info
.parent_id
= file_id1
;
299 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id2
));
300 EXPECT_NE(file_id0
, file_id2
);
301 EXPECT_NE(file_id1
, file_id2
);
303 FileId check_file_id
;
304 FilePath path
= FilePath(name0
);
305 EXPECT_TRUE(db()->GetFileWithPath(path
, &check_file_id
));
306 EXPECT_EQ(file_id0
, check_file_id
);
308 path
= path
.Append(name1
);
309 EXPECT_TRUE(db()->GetFileWithPath(path
, &check_file_id
));
310 EXPECT_EQ(file_id1
, check_file_id
);
312 path
= path
.Append(name2
);
313 EXPECT_TRUE(db()->GetFileWithPath(path
, &check_file_id
));
314 EXPECT_EQ(file_id2
, check_file_id
);
317 TEST_F(FileSystemDirectoryDatabaseTest
, TestListChildren
) {
318 // No children in the root.
319 std::vector
<FileId
> children
;
320 EXPECT_TRUE(db()->ListChildren(0, &children
));
321 EXPECT_TRUE(children
.empty());
323 // One child in the root.
327 info
.name
= FILE_PATH_LITERAL("foo");
328 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id0
));
329 EXPECT_TRUE(db()->ListChildren(0, &children
));
330 EXPECT_EQ(children
.size(), 1UL);
331 EXPECT_EQ(children
[0], file_id0
);
333 // Two children in the root.
335 info
.name
= FILE_PATH_LITERAL("bar");
336 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id1
));
337 EXPECT_TRUE(db()->ListChildren(0, &children
));
338 EXPECT_EQ(2UL, children
.size());
339 if (children
[0] == file_id0
) {
340 EXPECT_EQ(children
[1], file_id1
);
342 EXPECT_EQ(children
[1], file_id0
);
343 EXPECT_EQ(children
[0], file_id1
);
346 // No children in a subdirectory.
347 EXPECT_TRUE(db()->ListChildren(file_id0
, &children
));
348 EXPECT_TRUE(children
.empty());
350 // One child in a subdirectory.
351 info
.parent_id
= file_id0
;
352 info
.name
= FILE_PATH_LITERAL("foo");
355 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id2
));
356 EXPECT_TRUE(db()->ListChildren(file_id0
, &children
));
357 EXPECT_EQ(1UL, children
.size());
358 EXPECT_EQ(children
[0], file_id2
);
360 // Two children in a subdirectory.
361 info
.name
= FILE_PATH_LITERAL("bar");
362 EXPECT_TRUE(db()->AddFileInfo(info
, &file_id3
));
363 EXPECT_TRUE(db()->ListChildren(file_id0
, &children
));
364 EXPECT_EQ(2UL, children
.size());
365 if (children
[0] == file_id2
) {
366 EXPECT_EQ(children
[1], file_id3
);
368 EXPECT_EQ(children
[1], file_id2
);
369 EXPECT_EQ(children
[0], file_id3
);
373 TEST_F(FileSystemDirectoryDatabaseTest
, TestUpdateModificationTime
) {
377 info0
.name
= FILE_PATH_LITERAL("name");
378 info0
.data_path
= FilePath(FILE_PATH_LITERAL("fake path"));
379 info0
.modification_time
= base::Time::Now();
380 EXPECT_TRUE(db()->AddFileInfo(info0
, &file_id
));
382 EXPECT_TRUE(db()->GetFileInfo(file_id
, &info1
));
383 EXPECT_EQ(info0
.name
, info1
.name
);
384 EXPECT_EQ(info0
.parent_id
, info1
.parent_id
);
385 EXPECT_EQ(info0
.data_path
, info1
.data_path
);
387 floor(info0
.modification_time
.ToDoubleT()),
388 info1
.modification_time
.ToDoubleT());
390 EXPECT_TRUE(db()->UpdateModificationTime(file_id
, base::Time::UnixEpoch()));
391 EXPECT_TRUE(db()->GetFileInfo(file_id
, &info1
));
392 EXPECT_EQ(info0
.name
, info1
.name
);
393 EXPECT_EQ(info0
.parent_id
, info1
.parent_id
);
394 EXPECT_EQ(info0
.data_path
, info1
.data_path
);
395 EXPECT_NE(info0
.modification_time
, info1
.modification_time
);
397 info1
.modification_time
.ToDoubleT(),
398 floor(base::Time::UnixEpoch().ToDoubleT()));
400 EXPECT_FALSE(db()->UpdateModificationTime(999, base::Time::UnixEpoch()));
403 TEST_F(FileSystemDirectoryDatabaseTest
, TestSimpleFileOperations
) {
404 FileId file_id
= 888;
406 EXPECT_FALSE(db()->GetFileInfo(file_id
, &info0
));
408 info0
.data_path
= FilePath(FILE_PATH_LITERAL("foo"));
409 info0
.name
= FILE_PATH_LITERAL("file name");
410 info0
.modification_time
= base::Time::Now();
411 EXPECT_TRUE(db()->AddFileInfo(info0
, &file_id
));
413 EXPECT_TRUE(db()->GetFileInfo(file_id
, &info1
));
414 EXPECT_EQ(info0
.parent_id
, info1
.parent_id
);
415 EXPECT_EQ(info0
.data_path
, info1
.data_path
);
416 EXPECT_EQ(info0
.name
, info1
.name
);
418 floor(info0
.modification_time
.ToDoubleT()),
419 info1
.modification_time
.ToDoubleT());
422 TEST_F(FileSystemDirectoryDatabaseTest
, TestOverwritingMoveFileSrcDirectory
) {
426 info0
.name
= FILE_PATH_LITERAL("directory");
427 info0
.modification_time
= base::Time::Now();
428 EXPECT_TRUE(db()->AddFileInfo(info0
, &directory_id
));
433 info1
.data_path
= FilePath(FILE_PATH_LITERAL("bar"));
434 info1
.name
= FILE_PATH_LITERAL("file");
435 info1
.modification_time
= base::Time::UnixEpoch();
436 EXPECT_TRUE(db()->AddFileInfo(info1
, &file_id
));
438 EXPECT_FALSE(db()->OverwritingMoveFile(directory_id
, file_id
));
441 TEST_F(FileSystemDirectoryDatabaseTest
, TestOverwritingMoveFileDestDirectory
) {
445 info0
.name
= FILE_PATH_LITERAL("file");
446 info0
.data_path
= FilePath(FILE_PATH_LITERAL("bar"));
447 info0
.modification_time
= base::Time::Now();
448 EXPECT_TRUE(db()->AddFileInfo(info0
, &file_id
));
453 info1
.name
= FILE_PATH_LITERAL("directory");
454 info1
.modification_time
= base::Time::UnixEpoch();
455 EXPECT_TRUE(db()->AddFileInfo(info1
, &directory_id
));
457 EXPECT_FALSE(db()->OverwritingMoveFile(file_id
, directory_id
));
460 TEST_F(FileSystemDirectoryDatabaseTest
, TestOverwritingMoveFileSuccess
) {
464 info0
.data_path
= FilePath(FILE_PATH_LITERAL("foo"));
465 info0
.name
= FILE_PATH_LITERAL("file name 0");
466 info0
.modification_time
= base::Time::Now();
467 EXPECT_TRUE(db()->AddFileInfo(info0
, &file_id0
));
471 dir_info
.parent_id
= 0;
472 dir_info
.name
= FILE_PATH_LITERAL("directory name");
473 EXPECT_TRUE(db()->AddFileInfo(dir_info
, &dir_id
));
477 info1
.parent_id
= dir_id
;
478 info1
.data_path
= FilePath(FILE_PATH_LITERAL("bar"));
479 info1
.name
= FILE_PATH_LITERAL("file name 1");
480 info1
.modification_time
= base::Time::UnixEpoch();
481 EXPECT_TRUE(db()->AddFileInfo(info1
, &file_id1
));
483 EXPECT_TRUE(db()->OverwritingMoveFile(file_id0
, file_id1
));
488 EXPECT_FALSE(db()->GetFileWithPath(FilePath(info0
.name
), &check_id
));
489 EXPECT_TRUE(db()->GetFileWithPath(
490 FilePath(dir_info
.name
).Append(info1
.name
), &check_id
));
491 EXPECT_TRUE(db()->GetFileInfo(check_id
, &check_info
));
493 EXPECT_EQ(info0
.data_path
, check_info
.data_path
);
496 TEST_F(FileSystemDirectoryDatabaseTest
, TestGetNextInteger
) {
498 EXPECT_TRUE(db()->GetNextInteger(&next
));
500 EXPECT_TRUE(db()->GetNextInteger(&next
));
503 EXPECT_TRUE(db()->GetNextInteger(&next
));
505 EXPECT_TRUE(db()->GetNextInteger(&next
));
508 EXPECT_TRUE(db()->GetNextInteger(&next
));
512 TEST_F(FileSystemDirectoryDatabaseTest
, TestConsistencyCheck_Empty
) {
513 EXPECT_TRUE(db()->IsFileSystemConsistent());
516 EXPECT_TRUE(db()->GetNextInteger(&next
));
518 EXPECT_TRUE(db()->IsFileSystemConsistent());
521 TEST_F(FileSystemDirectoryDatabaseTest
, TestConsistencyCheck_Consistent
) {
523 CreateFile(0, FPL("foo"), FPL("hoge"), NULL
);
524 CreateDirectory(0, FPL("bar"), &dir_id
);
525 CreateFile(dir_id
, FPL("baz"), FPL("fuga"), NULL
);
526 CreateFile(dir_id
, FPL("fizz"), FPL("buzz"), NULL
);
528 EXPECT_TRUE(db()->IsFileSystemConsistent());
531 TEST_F(FileSystemDirectoryDatabaseTest
,
532 TestConsistencyCheck_BackingMultiEntry
) {
533 const FilePath::CharType kBackingFileName
[] = FPL("the celeb");
534 CreateFile(0, FPL("foo"), kBackingFileName
, NULL
);
536 EXPECT_TRUE(db()->IsFileSystemConsistent());
537 ASSERT_TRUE(file_util::Delete(path().Append(kBackingFileName
), false));
538 CreateFile(0, FPL("bar"), kBackingFileName
, NULL
);
539 EXPECT_FALSE(db()->IsFileSystemConsistent());
542 TEST_F(FileSystemDirectoryDatabaseTest
, TestConsistencyCheck_FileLost
) {
543 const FilePath::CharType kBackingFileName
[] = FPL("hoge");
544 CreateFile(0, FPL("foo"), kBackingFileName
, NULL
);
546 EXPECT_TRUE(db()->IsFileSystemConsistent());
547 ASSERT_TRUE(file_util::Delete(path().Append(kBackingFileName
), false));
548 EXPECT_TRUE(db()->IsFileSystemConsistent());
551 TEST_F(FileSystemDirectoryDatabaseTest
, TestConsistencyCheck_OrphanFile
) {
552 CreateFile(0, FPL("foo"), FPL("hoge"), NULL
);
554 EXPECT_TRUE(db()->IsFileSystemConsistent());
556 bool created
= false;
557 base::PlatformFileError error
= base::PLATFORM_FILE_ERROR_FAILED
;
558 base::PlatformFile file
= base::CreatePlatformFile(
559 path().Append(FPL("Orphan File")),
560 base::PLATFORM_FILE_CREATE
| base::PLATFORM_FILE_WRITE
,
562 ASSERT_EQ(base::PLATFORM_FILE_OK
, error
);
563 ASSERT_TRUE(created
);
564 ASSERT_TRUE(base::ClosePlatformFile(file
));
566 EXPECT_TRUE(db()->IsFileSystemConsistent());
569 TEST_F(FileSystemDirectoryDatabaseTest
, TestConsistencyCheck_RootLoop
) {
570 EXPECT_TRUE(db()->IsFileSystemConsistent());
571 MakeHierarchyLink(0, 0, FPL(""));
572 EXPECT_FALSE(db()->IsFileSystemConsistent());
575 TEST_F(FileSystemDirectoryDatabaseTest
, TestConsistencyCheck_DirectoryLoop
) {
578 FilePath::StringType dir1_name
= FPL("foo");
579 CreateDirectory(0, dir1_name
, &dir1_id
);
580 CreateDirectory(dir1_id
, FPL("bar"), &dir2_id
);
582 EXPECT_TRUE(db()->IsFileSystemConsistent());
583 MakeHierarchyLink(dir2_id
, dir1_id
, dir1_name
);
584 EXPECT_FALSE(db()->IsFileSystemConsistent());
587 TEST_F(FileSystemDirectoryDatabaseTest
, TestConsistencyCheck_NameMismatch
) {
590 CreateDirectory(0, FPL("foo"), &dir_id
);
591 CreateFile(dir_id
, FPL("bar"), FPL("hoge/fuga/piyo"), &file_id
);
593 EXPECT_TRUE(db()->IsFileSystemConsistent());
594 DeleteHierarchyLink(file_id
);
595 MakeHierarchyLink(dir_id
, file_id
, FPL("baz"));
596 EXPECT_FALSE(db()->IsFileSystemConsistent());
599 TEST_F(FileSystemDirectoryDatabaseTest
, TestConsistencyCheck_WreckedEntries
) {
602 CreateDirectory(0, FPL("foo"), &dir1_id
);
603 CreateDirectory(dir1_id
, FPL("bar"), &dir2_id
);
604 CreateFile(dir2_id
, FPL("baz"), FPL("fizz/buzz"), NULL
);
606 EXPECT_TRUE(db()->IsFileSystemConsistent());
607 DeleteHierarchyLink(dir2_id
); // Delete link from |dir1_id| to |dir2_id|.
608 EXPECT_FALSE(db()->IsFileSystemConsistent());
611 TEST_F(FileSystemDirectoryDatabaseTest
, TestRepairDatabase_Success
) {
612 FilePath::StringType kFileName
= FPL("bar");
615 CreateFile(0, FPL("foo"), FPL("hoge"), NULL
);
616 CreateFile(0, kFileName
, FPL("fuga"), &file_id_prev
);
618 const FilePath kDatabaseDirectory
= path().Append(kDirectoryDatabaseName
);
620 CorruptDatabase(kDatabaseDirectory
, leveldb::kDescriptorFile
,
621 0, std::numeric_limits
<size_t>::max());
623 EXPECT_FALSE(db()->IsFileSystemConsistent());
626 EXPECT_TRUE(db()->GetChildWithName(0, kFileName
, &file_id
));
627 EXPECT_EQ(file_id_prev
, file_id
);
629 EXPECT_TRUE(db()->IsFileSystemConsistent());
632 TEST_F(FileSystemDirectoryDatabaseTest
, TestRepairDatabase_Failure
) {
633 FilePath::StringType kFileName
= FPL("bar");
635 CreateFile(0, FPL("foo"), FPL("hoge"), NULL
);
636 CreateFile(0, kFileName
, FPL("fuga"), NULL
);
638 const FilePath kDatabaseDirectory
= path().Append(kDirectoryDatabaseName
);
640 CorruptDatabase(kDatabaseDirectory
, leveldb::kDescriptorFile
,
641 0, std::numeric_limits
<size_t>::max());
642 CorruptDatabase(kDatabaseDirectory
, leveldb::kLogFile
,
645 EXPECT_FALSE(db()->IsFileSystemConsistent());
648 EXPECT_FALSE(db()->GetChildWithName(0, kFileName
, &file_id
));
649 EXPECT_TRUE(db()->IsFileSystemConsistent());
652 } // namespace fileapi