Chromium Code Reviews| Index: content/browser/fileapi/file_system_operation_impl_unittest.cc |
| diff --git a/content/browser/fileapi/file_system_operation_impl_unittest.cc b/content/browser/fileapi/file_system_operation_impl_unittest.cc |
| index 392f1c07a090c740bfd12f79852e1ceac9dbd01b..d3e735d5b74af0fabe9f5060eb7467d5fcb33535 100644 |
| --- a/content/browser/fileapi/file_system_operation_impl_unittest.cc |
| +++ b/content/browser/fileapi/file_system_operation_impl_unittest.cc |
| @@ -44,12 +44,6 @@ namespace { |
| const int kFileOperationStatusNotSet = 1; |
| -void AssertFileErrorEq(const tracked_objects::Location& from_here, |
| - base::File::Error expected, |
| - base::File::Error actual) { |
| - ASSERT_EQ(expected, actual) << from_here.ToString(); |
| -} |
| - |
| void AssertFileErrorEqWithClosure(const tracked_objects::Location& from_here, |
| base::File::Error expected, |
| base::Closure closure, |
| @@ -186,39 +180,48 @@ class FileSystemOperationImplTest |
| } |
| FileSystemOperation::ReadDirectoryCallback |
| - RecordReadDirectoryCallback() { |
| + RecordReadDirectoryCallback(base::Closure closure) { |
|
tzik
2014/09/10 08:45:14
const ref, here and elsewhere?
iseki
2014/09/11 01:07:32
Done.
|
| return base::Bind(&FileSystemOperationImplTest::DidReadDirectory, |
| - weak_factory_.GetWeakPtr()); |
| + weak_factory_.GetWeakPtr(), closure); |
| } |
| - FileSystemOperation::GetMetadataCallback RecordMetadataCallback() { |
| - return base::Bind(&FileSystemOperationImplTest::DidGetMetadata, |
| - weak_factory_.GetWeakPtr()); |
| + FileSystemOperation::GetMetadataCallback RecordMetadataCallback( |
| + base::Closure closure) { |
| + return base::Bind( |
| + &FileSystemOperationImplTest::DidGetMetadata, |
| + weak_factory_.GetWeakPtr(), closure); |
| } |
| - FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback() { |
| + FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback( |
| + base::Closure closure) { |
| return base::Bind(&FileSystemOperationImplTest::DidCreateSnapshotFile, |
| - weak_factory_.GetWeakPtr()); |
| + weak_factory_.GetWeakPtr(), closure); |
| } |
| void DidFinish(base::File::Error status) { |
| status_ = status; |
| } |
| - void DidReadDirectory(base::File::Error status, |
| + void DidReadDirectory(base::Closure closure, |
| + base::File::Error status, |
| const std::vector<storage::DirectoryEntry>& entries, |
| bool /* has_more */) { |
| entries_ = entries; |
| status_ = status; |
| + closure.Run(); |
| } |
| - void DidGetMetadata(base::File::Error status, |
| - const base::File::Info& info) { |
| + void DidGetMetadata( |
| + base::Closure closure, |
| + base::File::Error status, |
| + const base::File::Info& info) { |
| info_ = info; |
| status_ = status; |
| + closure.Run(); |
| } |
| void DidCreateSnapshotFile( |
| + base::Closure closure, |
| base::File::Error status, |
| const base::File::Info& info, |
| const base::FilePath& platform_path, |
| @@ -227,6 +230,7 @@ class FileSystemOperationImplTest |
| path_ = platform_path; |
| status_ = status; |
| shareable_file_ref_ = shareable_file_ref; |
| + closure.Run(); |
| } |
| int64 GetDataSizeOnDisk() { |
| @@ -251,10 +255,9 @@ class FileSystemOperationImplTest |
| AsyncFileTestHelper::CreateFile( |
| sandbox_file_system_.file_system_context(), url); |
| - operation_runner()->Remove(url, false /* recursive */, |
| - base::Bind(&AssertFileErrorEq, FROM_HERE, |
| - base::File::FILE_OK)); |
| - base::RunLoop().RunUntilIdle(); |
| + RemoveTest(url, false /* recursive */, |
|
tzik
2014/09/10 08:45:14
Can this be pushed into one line?
iseki
2014/09/11 01:07:33
Done.
|
| + base::File::FILE_OK); |
| + |
| change_observer()->ResetCount(); |
| int64 total_usage; |
| @@ -284,6 +287,171 @@ class FileSystemOperationImplTest |
| quota + quota_delta); |
| } |
| + void MoveTest( |
|
tzik
2014/09/10 08:45:14
Could you change the return type from void to base
iseki
2014/09/11 01:07:32
Done.
|
| + const FileSystemURL& src, |
|
tzik
2014/09/10 08:45:14
Can you push these param to previous line, here an
iseki
2014/09/11 01:07:32
Done.
|
| + const FileSystemURL& dest, |
| + storage::FileSystemOperation::CopyOrMoveOption option, |
| + base::File::Error expected) { |
| + base::RunLoop run_loop; |
| + operation_runner()->Move( |
| + src, dest, option, |
| + base::Bind(&AssertFileErrorEqWithClosure, |
| + FROM_HERE, |
| + expected, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| + void CopyTest( |
| + const FileSystemURL& src, |
| + const FileSystemURL& dest, |
| + storage::FileSystemOperation::CopyOrMoveOption option, |
| + base::File::Error expected) { |
| + base::RunLoop run_loop; |
| + operation_runner()->Copy( |
| + src, dest, option, |
| + FileSystemOperationRunner::CopyProgressCallback(), |
| + base::Bind(&AssertFileErrorEqWithClosure, |
| + FROM_HERE, |
| + expected, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| + void CopyInForeignFileTest( |
| + const base::FilePath& src, |
| + const FileSystemURL& dest, |
| + base::File::Error expected) { |
| + base::RunLoop run_loop; |
| + operation_runner()->CopyInForeignFile( |
| + src, dest, |
| + base::Bind(&AssertFileErrorEqWithClosure, |
| + FROM_HERE, |
| + expected, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| + void TruncateTest( |
| + const FileSystemURL& url, |
| + int size, |
| + base::File::Error expected) { |
| + base::RunLoop run_loop; |
| + operation_runner()->Truncate(url, size, |
| + base::Bind(&AssertFileErrorEqWithClosure, |
| + FROM_HERE, |
| + expected, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| + void CreateFileTest( |
| + const FileSystemURL& url, |
| + bool exclusive, |
| + base::File::Error expected) { |
| + base::RunLoop run_loop; |
| + operation_runner()->CreateFile( |
| + url, exclusive, |
| + base::Bind(&AssertFileErrorEqWithClosure, |
| + FROM_HERE, |
| + expected, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| + void RemoveTest( |
| + const FileSystemURL& url, |
| + bool recursive, |
| + base::File::Error expected) { |
| + base::RunLoop run_loop; |
| + operation_runner()->Remove( |
| + url, recursive, |
| + base::Bind(&AssertFileErrorEqWithClosure, |
| + FROM_HERE, |
| + expected, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| + void CreateDirectoryTest( |
| + const FileSystemURL& url, |
| + bool exclusive, |
| + bool recursive, |
| + base::File::Error expected) { |
| + base::RunLoop run_loop; |
| + operation_runner()->CreateDirectory( |
| + url, exclusive, recursive, |
| + base::Bind(&AssertFileErrorEqWithClosure, |
| + FROM_HERE, |
| + expected, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| + void GetMetadataTest(const FileSystemURL& url) { |
| + base::RunLoop run_loop; |
| + operation_runner()->GetMetadata( |
| + url, |
| + RecordMetadataCallback( |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| + void ReadDirectoryTest(const FileSystemURL& url) { |
| + base::RunLoop run_loop; |
| + operation_runner()->ReadDirectory( |
| + url, RecordReadDirectoryCallback(run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| + void CreateSnapshotFileTest(const FileSystemURL& url) { |
| + base::RunLoop run_loop; |
| + operation_runner()->CreateSnapshotFile( |
| + url, RecordSnapshotFileCallback(run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| + void FileExistsTest( |
| + const FileSystemURL& url, |
| + base::File::Error expected) { |
| + base::RunLoop run_loop; |
| + operation_runner()->FileExists( |
| + url, |
| + base::Bind(&AssertFileErrorEqWithClosure, |
| + FROM_HERE, |
| + expected, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| + void DirectoryExistsTest( |
| + const FileSystemURL& url, |
| + base::File::Error expected) { |
| + base::RunLoop run_loop; |
| + operation_runner()->DirectoryExists( |
| + url, |
| + base::Bind(&AssertFileErrorEqWithClosure, |
| + FROM_HERE, |
| + expected, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| + void TouchFileTest( |
| + const FileSystemURL& url, |
| + const base::Time& last_access_time, |
| + const base::Time& last_modified_time, |
| + base::File::Error expected) { |
| + base::RunLoop run_loop; |
| + operation_runner()->TouchFile( |
| + url, last_access_time, last_modified_time, |
| + base::Bind(&AssertFileErrorEqWithClosure, |
| + FROM_HERE, |
| + expected, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| + } |
| + |
| private: |
| base::MessageLoopForIO message_loop_; |
| scoped_refptr<QuotaManager> quota_manager_; |
| @@ -311,11 +479,8 @@ class FileSystemOperationImplTest |
| TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) { |
| change_observer()->ResetCount(); |
| - operation_runner()->Move(URLForPath("a"), URLForPath("b"), |
| - FileSystemOperation::OPTION_NONE, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); |
| + MoveTest(URLForPath("a"), URLForPath("b"), FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_NOT_FOUND); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -323,11 +488,8 @@ TEST_F(FileSystemOperationImplTest, TestMoveFailureContainsPath) { |
| FileSystemURL src_dir(CreateDirectory("src")); |
| FileSystemURL dest_dir(CreateDirectory("src/dest")); |
| - operation_runner()->Move(src_dir, dest_dir, |
| - FileSystemOperation::OPTION_NONE, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); |
| + MoveTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_INVALID_OPERATION); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -337,11 +499,8 @@ TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDirExistsDestFile) { |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| FileSystemURL dest_file(CreateFile("dest/file")); |
| - operation_runner()->Move(src_dir, dest_file, |
| - FileSystemOperation::OPTION_NONE, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); |
| + MoveTest(src_dir, dest_file, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_INVALID_OPERATION); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -352,11 +511,8 @@ TEST_F(FileSystemOperationImplTest, |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| FileSystemURL dest_file(CreateFile("dest/file")); |
| - operation_runner()->Move(src_dir, dest_dir, |
| - FileSystemOperation::OPTION_NONE, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status()); |
| + MoveTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_NOT_EMPTY); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -366,22 +522,17 @@ TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcFileExistsDestDir) { |
| FileSystemURL src_file(CreateFile("src/file")); |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| - operation_runner()->Move(src_file, dest_dir, |
| - FileSystemOperation::OPTION_NONE, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); |
| + MoveTest(src_file, dest_dir, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_INVALID_OPERATION); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| TEST_F(FileSystemOperationImplTest, TestMoveFailureDestParentDoesntExist) { |
| // Dest. parent path does not exist. |
| FileSystemURL src_dir(CreateDirectory("src")); |
| - operation_runner()->Move(src_dir, URLForPath("nonexistent/deset"), |
| - FileSystemOperation::OPTION_NONE, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); |
| + MoveTest(src_dir, URLForPath("nonexistent/deset"), |
| + FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_NOT_FOUND); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -389,11 +540,8 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) { |
| FileSystemURL src_file(CreateFile("src")); |
| FileSystemURL dest_file(CreateFile("dest")); |
| - operation_runner()->Move(src_file, dest_file, |
| - FileSystemOperation::OPTION_NONE, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + MoveTest(src_file, dest_file, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| EXPECT_TRUE(FileExists("dest")); |
| EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| @@ -406,11 +554,8 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) { |
| TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndNew) { |
| FileSystemURL src_file(CreateFile("src")); |
| - operation_runner()->Move(src_file, URLForPath("new"), |
| - FileSystemOperation::OPTION_NONE, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + MoveTest(src_file, URLForPath("new"), FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| EXPECT_TRUE(FileExists("new")); |
| EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
| @@ -422,11 +567,8 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndOverwrite) { |
| FileSystemURL src_dir(CreateDirectory("src")); |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| - operation_runner()->Move(src_dir, dest_dir, |
| - FileSystemOperation::OPTION_NONE, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + MoveTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| EXPECT_FALSE(DirectoryExists("src")); |
| EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| @@ -442,11 +584,8 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndNew) { |
| FileSystemURL src_dir(CreateDirectory("src")); |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| - operation_runner()->Move(src_dir, URLForPath("dest/new"), |
| - FileSystemOperation::OPTION_NONE, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + MoveTest(src_dir, URLForPath("dest/new"), FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| EXPECT_FALSE(DirectoryExists("src")); |
| EXPECT_TRUE(DirectoryExists("dest/new")); |
| @@ -462,11 +601,8 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) { |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| - operation_runner()->Move(src_dir, dest_dir, |
| - FileSystemOperation::OPTION_NONE, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + MoveTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| EXPECT_TRUE(DirectoryExists("dest/dir")); |
| EXPECT_TRUE(FileExists("dest/dir/sub")); |
| @@ -482,11 +618,8 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSamePath) { |
| CreateDirectory("src/dir"); |
| CreateFile("src/dir/sub"); |
| - operation_runner()->Move(src_dir, src_dir, |
| - FileSystemOperation::OPTION_NONE, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + MoveTest(src_dir, src_dir, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| EXPECT_TRUE(DirectoryExists("src/dir")); |
| EXPECT_TRUE(FileExists("src/dir/sub")); |
| @@ -498,12 +631,8 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSamePath) { |
| } |
| TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) { |
| - operation_runner()->Copy(URLForPath("a"), URLForPath("b"), |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); |
| + CopyTest(URLForPath("a"), URLForPath("b"), FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_NOT_FOUND); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -511,12 +640,8 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) { |
| FileSystemURL src_dir(CreateDirectory("src")); |
| FileSystemURL dest_dir(CreateDirectory("src/dir")); |
| - operation_runner()->Copy(src_dir, dest_dir, |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); |
| + CopyTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_INVALID_OPERATION); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -526,12 +651,8 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) { |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| FileSystemURL dest_file(CreateFile("dest/file")); |
| - operation_runner()->Copy(src_dir, dest_file, |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); |
| + CopyTest(src_dir, dest_file, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_INVALID_OPERATION); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -542,12 +663,8 @@ TEST_F(FileSystemOperationImplTest, |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| FileSystemURL dest_file(CreateFile("dest/file")); |
| - operation_runner()->Copy(src_dir, dest_dir, |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status()); |
| + CopyTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_NOT_EMPTY); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -556,12 +673,8 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { |
| FileSystemURL src_file(CreateFile("src")); |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| - operation_runner()->Copy(src_file, dest_dir, |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); |
| + CopyTest(src_file, dest_dir, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_INVALID_OPERATION); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -569,12 +682,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { |
| // Dest. parent path does not exist. |
| FileSystemURL src_dir(CreateDirectory("src")); |
| - operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); |
| + CopyTest(src_dir, URLForPath("nonexistent/dest"), |
| + FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_NOT_FOUND); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -582,9 +692,7 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) { |
| FileSystemURL src_dir(CreateDirectory("src")); |
| FileSystemURL src_file(CreateFile("src/file")); |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| - operation_runner()->Truncate(src_file, 6, RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + TruncateTest(src_file, 6, base::File::FILE_OK); |
| EXPECT_EQ(6, GetFileSize("src/file")); |
| FileSystemURL dest_file(URLForPath("dest/file")); |
| @@ -592,12 +700,8 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) { |
| GrantQuotaForCurrentUsage(); |
| AddQuota(6 + dest_path_cost - 1); |
| - operation_runner()->Copy(src_file, dest_file, |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status()); |
| + CopyTest(src_file, dest_file, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_ERROR_NO_SPACE); |
| EXPECT_FALSE(FileExists("dest/file")); |
| } |
| @@ -605,12 +709,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) { |
| FileSystemURL src_file(CreateFile("src")); |
| FileSystemURL dest_file(CreateFile("dest")); |
| - operation_runner()->Copy(src_file, dest_file, |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + CopyTest(src_file, dest_file, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| + |
| EXPECT_TRUE(FileExists("dest")); |
| EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); |
| EXPECT_EQ(2, change_observer()->get_and_reset_modify_file_count()); |
| @@ -621,12 +722,8 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) { |
| TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { |
| FileSystemURL src_file(CreateFile("src")); |
| - operation_runner()->Copy(src_file, URLForPath("new"), |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + CopyTest(src_file, URLForPath("new"), FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| EXPECT_TRUE(FileExists("new")); |
| EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); |
| @@ -639,12 +736,8 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { |
| FileSystemURL src_dir(CreateDirectory("src")); |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| - operation_runner()->Copy(src_dir, dest_dir, |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + CopyTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| // Make sure we've overwritten but not copied the source under the |dest_dir|. |
| EXPECT_TRUE(DirectoryExists("dest")); |
| @@ -660,12 +753,8 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { |
| FileSystemURL src_dir(CreateDirectory("src")); |
| FileSystemURL dest_dir_new(URLForPath("dest")); |
| - operation_runner()->Copy(src_dir, dest_dir_new, |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + CopyTest(src_dir, dest_dir_new, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| EXPECT_TRUE(DirectoryExists("dest")); |
| EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 2); |
| @@ -680,13 +769,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) { |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| - operation_runner()->Copy(src_dir, dest_dir, |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| + CopyTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| EXPECT_TRUE(DirectoryExists("dest/dir")); |
| EXPECT_TRUE(FileExists("dest/dir/sub")); |
| @@ -705,13 +790,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { |
| CreateDirectory("src/dir"); |
| CreateFile("src/dir/sub"); |
| - operation_runner()->Copy(src_dir, src_dir, |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| + CopyTest(src_dir, src_dir, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| EXPECT_TRUE(DirectoryExists("src/dir")); |
| EXPECT_TRUE(FileExists("src/dir/sub")); |
| @@ -734,13 +815,12 @@ TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileSuccess) { |
| GetUsageAndQuota(&before_usage, NULL); |
| // Check that the file copied and corresponding usage increased. |
| - operation_runner()->CopyInForeignFile(src_local_disk_file_path, |
| - URLForPath("dest/file"), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| + CopyInForeignFileTest( |
| + src_local_disk_file_path, |
| + URLForPath("dest/file"), |
| + base::File::FILE_OK); |
| EXPECT_EQ(1, change_observer()->create_file_count()); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| EXPECT_TRUE(FileExists("dest/file")); |
| int64 after_usage; |
| GetUsageAndQuota(&after_usage, NULL); |
| @@ -764,31 +844,26 @@ TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileFailureByQuota) { |
| FileSystemURL dest_dir(CreateDirectory("dest")); |
| GrantQuotaForCurrentUsage(); |
| - operation_runner()->CopyInForeignFile(src_local_disk_file_path, |
| - URLForPath("dest/file"), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| + CopyInForeignFileTest( |
| + src_local_disk_file_path, |
| + URLForPath("dest/file"), |
| + base::File::FILE_ERROR_NO_SPACE); |
| EXPECT_FALSE(FileExists("dest/file")); |
| EXPECT_EQ(0, change_observer()->create_file_count()); |
| - EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status()); |
| } |
| TEST_F(FileSystemOperationImplTest, TestCreateFileFailure) { |
| // Already existing file and exclusive true. |
| FileSystemURL file(CreateFile("file")); |
| - operation_runner()->CreateFile(file, true, RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status()); |
| + CreateFileTest(file, true, base::File::FILE_ERROR_EXISTS); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileExists) { |
| // Already existing file and exclusive false. |
| FileSystemURL file(CreateFile("file")); |
| - operation_runner()->CreateFile(file, false, RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + CreateFileTest(file, false, base::File::FILE_OK); |
| EXPECT_TRUE(FileExists("file")); |
| // The file was already there; did nothing. |
| @@ -797,98 +872,74 @@ TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileExists) { |
| TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessExclusive) { |
| // File doesn't exist but exclusive is true. |
| - operation_runner()->CreateFile(URLForPath("new"), true, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + CreateFileTest(URLForPath("new"), true, base::File::FILE_OK); |
| EXPECT_TRUE(FileExists("new")); |
| EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
| } |
| TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileDoesntExist) { |
| // Non existing file. |
| - operation_runner()->CreateFile(URLForPath("nonexistent"), false, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + CreateFileTest(URLForPath("nonexistent"), false, base::File::FILE_OK); |
| EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
| } |
| TEST_F(FileSystemOperationImplTest, |
| TestCreateDirFailureDestParentDoesntExist) { |
| // Dest. parent path does not exist. |
| - operation_runner()->CreateDirectory( |
| - URLForPath("nonexistent/dir"), false, false, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); |
| + CreateDirectoryTest(URLForPath("nonexistent/dir"), false, false, |
| + base::File::FILE_ERROR_NOT_FOUND); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| TEST_F(FileSystemOperationImplTest, TestCreateDirFailureDirExists) { |
| // Exclusive and dir existing at path. |
| FileSystemURL dir(CreateDirectory("dir")); |
| - operation_runner()->CreateDirectory(dir, true, false, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status()); |
| + CreateDirectoryTest(dir, true, false, |
| + base::File::FILE_ERROR_EXISTS); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| TEST_F(FileSystemOperationImplTest, TestCreateDirFailureFileExists) { |
| // Exclusive true and file existing at path. |
| FileSystemURL file(CreateFile("file")); |
| - operation_runner()->CreateDirectory(file, true, false, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status()); |
| + CreateDirectoryTest(file, true, false, |
| + base::File::FILE_ERROR_EXISTS); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| TEST_F(FileSystemOperationImplTest, TestCreateDirSuccess) { |
| // Dir exists and exclusive is false. |
| FileSystemURL dir(CreateDirectory("dir")); |
| - operation_runner()->CreateDirectory(dir, false, false, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + CreateDirectoryTest(dir, false, false, |
| + base::File::FILE_OK); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| // Dir doesn't exist. |
| - operation_runner()->CreateDirectory(URLForPath("new"), false, false, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + CreateDirectoryTest(URLForPath("new"), false, false, |
| + base::File::FILE_OK); |
| EXPECT_TRUE(DirectoryExists("new")); |
| EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| } |
| TEST_F(FileSystemOperationImplTest, TestCreateDirSuccessExclusive) { |
| // Dir doesn't exist. |
| - operation_runner()->CreateDirectory(URLForPath("new"), true, false, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + CreateDirectoryTest(URLForPath("new"), true, false, |
| + base::File::FILE_OK); |
| EXPECT_TRUE(DirectoryExists("new")); |
| EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataFailure) { |
| - operation_runner()->GetMetadata(URLForPath("nonexistent"), |
| - RecordMetadataCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| + GetMetadataTest(URLForPath("nonexistent")); |
| EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); |
| - operation_runner()->FileExists(URLForPath("nonexistent"), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); |
| + FileExistsTest( |
| + URLForPath("nonexistent"), |
| + base::File::FILE_ERROR_NOT_FOUND); |
| - operation_runner()->DirectoryExists(URLForPath("nonexistent"), |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); |
| + DirectoryExistsTest(URLForPath("nonexistent"), |
| + base::File::FILE_ERROR_NOT_FOUND); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -897,24 +948,18 @@ TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) { |
| FileSystemURL file(CreateFile("dir/file")); |
| int read_access = 0; |
| - operation_runner()->DirectoryExists(dir, RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + DirectoryExistsTest(dir, base::File::FILE_OK); |
| ++read_access; |
| - operation_runner()->GetMetadata(dir, RecordMetadataCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| + GetMetadataTest(dir); |
| EXPECT_EQ(base::File::FILE_OK, status()); |
| EXPECT_TRUE(info().is_directory); |
| ++read_access; |
| - operation_runner()->FileExists(file, RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + FileExistsTest(file, base::File::FILE_OK); |
| ++read_access; |
| - operation_runner()->GetMetadata(file, RecordMetadataCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| + GetMetadataTest(file); |
| EXPECT_EQ(base::File::FILE_OK, status()); |
| EXPECT_FALSE(info().is_directory); |
| ++read_access; |
| @@ -926,27 +971,20 @@ TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) { |
| TEST_F(FileSystemOperationImplTest, TestTypeMismatchErrors) { |
| FileSystemURL dir(CreateDirectory("dir")); |
| - operation_runner()->FileExists(dir, RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, status()); |
| + FileExistsTest(dir, base::File::FILE_ERROR_NOT_A_FILE); |
| FileSystemURL file(CreateFile("file")); |
| - operation_runner()->DirectoryExists(file, RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status()); |
| + DirectoryExistsTest(file, base::File::FILE_ERROR_NOT_A_DIRECTORY); |
| } |
| TEST_F(FileSystemOperationImplTest, TestReadDirFailure) { |
| // Path doesn't exist |
| - operation_runner()->ReadDirectory(URLForPath("nonexistent"), |
| - RecordReadDirectoryCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| + ReadDirectoryTest(URLForPath("nonexistent")); |
| EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); |
| // File exists. |
| FileSystemURL file(CreateFile("file")); |
| - operation_runner()->ReadDirectory(file, RecordReadDirectoryCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| + ReadDirectoryTest(file); |
| EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status()); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| @@ -960,8 +998,7 @@ TEST_F(FileSystemOperationImplTest, TestReadDirSuccess) { |
| FileSystemURL child_dir(CreateDirectory("dir/child_dir")); |
| FileSystemURL child_file(CreateFile("dir/child_file")); |
| - operation_runner()->ReadDirectory(parent_dir, RecordReadDirectoryCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| + ReadDirectoryTest(parent_dir); |
| EXPECT_EQ(base::File::FILE_OK, status()); |
| EXPECT_EQ(2u, entries().size()); |
| @@ -977,10 +1014,8 @@ TEST_F(FileSystemOperationImplTest, TestReadDirSuccess) { |
| TEST_F(FileSystemOperationImplTest, TestRemoveFailure) { |
| // Path doesn't exist. |
| - operation_runner()->Remove(URLForPath("nonexistent"), false /* recursive */, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); |
| + RemoveTest(URLForPath("nonexistent"), false /* recursive */, |
| + base::File::FILE_ERROR_NOT_FOUND); |
| // It's an error to try to remove a non-empty directory if recursive flag |
| // is false. |
| @@ -992,20 +1027,16 @@ TEST_F(FileSystemOperationImplTest, TestRemoveFailure) { |
| FileSystemURL child_dir(CreateDirectory("dir/child_dir")); |
| FileSystemURL child_file(CreateFile("dir/child_file")); |
| - operation_runner()->Remove(parent_dir, false /* recursive */, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status()); |
| + RemoveTest(parent_dir, false /* recursive */, |
| + base::File::FILE_ERROR_NOT_EMPTY); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| } |
| TEST_F(FileSystemOperationImplTest, TestRemoveSuccess) { |
| FileSystemURL empty_dir(CreateDirectory("empty_dir")); |
| EXPECT_TRUE(DirectoryExists("empty_dir")); |
| - operation_runner()->Remove(empty_dir, false /* recursive */, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + RemoveTest(empty_dir, false /* recursive */, |
| + base::File::FILE_OK); |
| EXPECT_FALSE(DirectoryExists("empty_dir")); |
| EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
| @@ -1028,10 +1059,8 @@ TEST_F(FileSystemOperationImplTest, TestRemoveSuccessRecursive) { |
| for (int i = 0; i < 8; ++i) |
| CreateFile(base::StringPrintf("dir/child_dir/file-%d", i)); |
| - operation_runner()->Remove(parent_dir, true /* recursive */, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + RemoveTest(parent_dir, true /* recursive */, |
| + base::File::FILE_OK); |
| EXPECT_FALSE(DirectoryExists("parent_dir")); |
| EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); |
| @@ -1049,17 +1078,14 @@ TEST_F(FileSystemOperationImplTest, TestTruncate) { |
| base::WriteFile(platform_path, test_data, data_size)); |
| // Check that its length is the size of the data written. |
| - operation_runner()->GetMetadata(file, RecordMetadataCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| + GetMetadataTest(file); |
| EXPECT_EQ(base::File::FILE_OK, status()); |
| EXPECT_FALSE(info().is_directory); |
| EXPECT_EQ(data_size, info().size); |
| // Extend the file by truncating it. |
| int length = 17; |
| - operation_runner()->Truncate(file, length, RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + TruncateTest(file, length, base::File::FILE_OK); |
| EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| @@ -1078,9 +1104,7 @@ TEST_F(FileSystemOperationImplTest, TestTruncate) { |
| // Shorten the file by truncating it. |
| length = 3; |
| - operation_runner()->Truncate(file, length, RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + TruncateTest(file, length, base::File::FILE_OK); |
| EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| @@ -1103,17 +1127,13 @@ TEST_F(FileSystemOperationImplTest, TestTruncateFailureByQuota) { |
| GrantQuotaForCurrentUsage(); |
| AddQuota(10); |
| - operation_runner()->Truncate(file, 10, RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + TruncateTest(file, 10, base::File::FILE_OK); |
| EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| EXPECT_EQ(10, GetFileSize("dir/file")); |
| - operation_runner()->Truncate(file, 11, RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status()); |
| + TruncateTest(file, 11, base::File::FILE_ERROR_NO_SPACE); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| EXPECT_EQ(10, GetFileSize("dir/file")); |
| @@ -1136,10 +1156,8 @@ TEST_F(FileSystemOperationImplTest, TestTouchFile) { |
| ASSERT_NE(last_modified, new_modified_time); |
| ASSERT_NE(last_accessed, new_accessed_time); |
| - operation_runner()->TouchFile(file, new_accessed_time, new_modified_time, |
| - RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + TouchFileTest(file, new_accessed_time, new_modified_time, |
| + base::File::FILE_OK); |
| EXPECT_TRUE(change_observer()->HasNoChange()); |
| EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); |
| @@ -1154,18 +1172,15 @@ TEST_F(FileSystemOperationImplTest, TestCreateSnapshotFile) { |
| FileSystemURL dir(CreateDirectory("dir")); |
| // Create a file for the testing. |
| - operation_runner()->DirectoryExists(dir, RecordStatusCallback()); |
| + DirectoryExistsTest(dir, base::File::FILE_OK); |
| FileSystemURL file(CreateFile("dir/file")); |
| - operation_runner()->FileExists(file, RecordStatusCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(base::File::FILE_OK, status()); |
| + FileExistsTest(file, base::File::FILE_OK); |
| // See if we can get a 'snapshot' file info for the file. |
| // Since FileSystemOperationImpl assumes the file exists in the local |
| // directory it should just returns the same metadata and platform_path |
| // as the file itself. |
| - operation_runner()->CreateSnapshotFile(file, RecordSnapshotFileCallback()); |
| - base::RunLoop().RunUntilIdle(); |
| + CreateSnapshotFileTest(file); |
| EXPECT_EQ(base::File::FILE_OK, status()); |
| EXPECT_FALSE(info().is_directory); |
| EXPECT_EQ(PlatformPath("dir/file"), path()); |
| @@ -1191,28 +1206,17 @@ TEST_F(FileSystemOperationImplTest, |
| int total_path_cost = GetUsage(); |
| EXPECT_EQ(0, GetDataSizeOnDisk()); |
| - operation_runner()->Truncate( |
| - child_file1, 5000, |
| - base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); |
| - operation_runner()->Truncate( |
| - child_file2, 400, |
| - base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); |
| - operation_runner()->Truncate( |
| - grandchild_file1, 30, |
| - base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); |
| - operation_runner()->Truncate( |
| - grandchild_file2, 2, |
| - base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); |
| - base::RunLoop().RunUntilIdle(); |
| + TruncateTest(child_file1, 5000, base::File::FILE_OK); |
| + TruncateTest(child_file2, 400, base::File::FILE_OK); |
| + TruncateTest(grandchild_file1, 30, base::File::FILE_OK); |
| + TruncateTest(grandchild_file2, 2, base::File::FILE_OK); |
| const int64 all_file_size = 5000 + 400 + 30 + 2; |
| EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); |
| EXPECT_EQ(all_file_size + total_path_cost, GetUsage()); |
| - operation_runner()->Move( |
| - src, dest, FileSystemOperation::OPTION_NONE, |
| - base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); |
| - base::RunLoop().RunUntilIdle(); |
| + MoveTest(src, dest, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| EXPECT_FALSE(DirectoryExists("src/dir")); |
| EXPECT_FALSE(FileExists("src/dir/file2")); |
| @@ -1244,19 +1248,10 @@ TEST_F(FileSystemOperationImplTest, |
| EXPECT_EQ(0, GetDataSizeOnDisk()); |
| - operation_runner()->Truncate( |
| - child_file1, 8000, |
| - base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); |
| - operation_runner()->Truncate( |
| - child_file2, 700, |
| - base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); |
| - operation_runner()->Truncate( |
| - grandchild_file1, 60, |
| - base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); |
| - operation_runner()->Truncate( |
| - grandchild_file2, 5, |
| - base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); |
| - base::RunLoop().RunUntilIdle(); |
| + TruncateTest(child_file1, 8000, base::File::FILE_OK); |
| + TruncateTest(child_file2, 700, base::File::FILE_OK); |
| + TruncateTest(grandchild_file1, 60, base::File::FILE_OK); |
| + TruncateTest(grandchild_file2, 5, base::File::FILE_OK); |
| const int64 child_file_size = 8000 + 700; |
| const int64 grandchild_file_size = 60 + 5; |
| @@ -1267,19 +1262,8 @@ TEST_F(FileSystemOperationImplTest, |
| EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); |
| EXPECT_EQ(expected_usage, usage); |
| - { |
| - base::RunLoop run_loop; |
| - // Copy src to dest1. |
| - operation_runner()->Copy(src, |
| - dest1, |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - base::Bind(&AssertFileErrorEqWithClosure, |
| - FROM_HERE, |
| - base::File::FILE_OK, |
| - run_loop.QuitClosure())); |
| - run_loop.Run(); |
| - } |
| + CopyTest(src, dest1, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| expected_usage += all_file_size + child_path_cost + grandchild_path_cost; |
| EXPECT_TRUE(DirectoryExists("src/dir")); |
| @@ -1290,19 +1274,8 @@ TEST_F(FileSystemOperationImplTest, |
| EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk()); |
| EXPECT_EQ(expected_usage, GetUsage()); |
| - { |
| - base::RunLoop run_loop; |
| - // Copy src/dir to dest2. |
| - operation_runner()->Copy(child_dir, |
| - dest2, |
| - FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - base::Bind(&AssertFileErrorEqWithClosure, |
| - FROM_HERE, |
| - base::File::FILE_OK, |
| - run_loop.QuitClosure())); |
| - run_loop.Run(); |
| - } |
| + CopyTest(child_dir, dest2, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| expected_usage += grandchild_file_size + grandchild_path_cost; |
| usage = GetUsage(); |
| @@ -1316,28 +1289,9 @@ TEST_F(FileSystemOperationImplTest, |
| FileSystemURL src_file(CreateFile("src")); |
| FileSystemURL dest_file(CreateFile("dest")); |
| - { |
| - base::RunLoop run_loop; |
| - operation_runner()->Truncate( |
| - dest_file, 6, |
| - base::Bind(&AssertFileErrorEqWithClosure, |
| - FROM_HERE, |
| - base::File::FILE_OK, |
| - run_loop.QuitClosure())); |
| - run_loop.Run(); |
| - } |
| - |
| - { |
| - base::RunLoop run_loop; |
| - operation_runner()->Copy( |
| - src_file, dest_file, FileSystemOperation::OPTION_NONE, |
| - FileSystemOperationRunner::CopyProgressCallback(), |
| - base::Bind(&AssertFileErrorEqWithClosure, |
| - FROM_HERE, |
| - base::File::FILE_OK, |
| - run_loop.QuitClosure())); |
| - run_loop.Run(); |
| - } |
| + TruncateTest(dest_file, 6, base::File::FILE_OK); |
| + CopyTest(src_file, dest_file, FileSystemOperation::OPTION_NONE, |
| + base::File::FILE_OK); |
| EXPECT_EQ(0, GetFileSize("dest")); |
| } |