| Index: chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc
|
| diff --git a/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc b/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc
|
| index 85e6056702364b54613b1812805c0d207e4b95a8..5d4fa1ccbb00ef26f68ab7d540ee9992c4829ac0 100644
|
| --- a/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc
|
| +++ b/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc
|
| @@ -10,6 +10,7 @@
|
| #include "chrome/browser/chromeos/drive/file_change.h"
|
| #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
|
| #include "chrome/browser/chromeos/drive/file_system_util.h"
|
| +#include "chrome/browser/chromeos/drive/resource_metadata.h"
|
| #include "chrome/browser/drive/drive_api_util.h"
|
| #include "chrome/browser/drive/fake_drive_service.h"
|
| #include "content/public/test/test_utils.h"
|
| @@ -20,6 +21,20 @@
|
| namespace drive {
|
| namespace file_system {
|
|
|
| +namespace {
|
| +
|
| +// Used to handle WaitForSyncComplete() calls.
|
| +bool CopyWaitForSyncCompleteArguments(std::string* out_local_id,
|
| + FileOperationCallback* out_callback,
|
| + const std::string& local_id,
|
| + const FileOperationCallback& callback) {
|
| + *out_local_id = local_id;
|
| + *out_callback = callback;
|
| + return true;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| class CopyOperationTest : public OperationTestBase {
|
| protected:
|
| virtual void SetUp() OVERRIDE {
|
| @@ -426,5 +441,83 @@ TEST_F(CopyOperationTest, PreserveLastModified) {
|
| entry2.file_info().last_modified());
|
| }
|
|
|
| +TEST_F(CopyOperationTest, WaitForSyncComplete) {
|
| + // Create a directory locally.
|
| + base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
|
| + base::FilePath directory_path(FILE_PATH_LITERAL("drive/root/New Directory"));
|
| + base::FilePath dest_path = directory_path.AppendASCII("File 1.txt");
|
| +
|
| + ResourceEntry directory_parent;
|
| + EXPECT_EQ(FILE_ERROR_OK,
|
| + GetLocalResourceEntry(directory_path.DirName(), &directory_parent));
|
| +
|
| + ResourceEntry directory;
|
| + directory.set_parent_local_id(directory_parent.local_id());
|
| + directory.set_title(directory_path.BaseName().AsUTF8Unsafe());
|
| + directory.mutable_file_info()->set_is_directory(true);
|
| + directory.set_metadata_edit_state(ResourceEntry::DIRTY);
|
| +
|
| + std::string directory_local_id;
|
| + FileError error = FILE_ERROR_FAILED;
|
| + base::PostTaskAndReplyWithResult(
|
| + blocking_task_runner(),
|
| + FROM_HERE,
|
| + base::Bind(&internal::ResourceMetadata::AddEntry,
|
| + base::Unretained(metadata()), directory, &directory_local_id),
|
| + google_apis::test_util::CreateCopyResultCallback(&error));
|
| + content::RunAllBlockingPoolTasksUntilIdle();
|
| + EXPECT_EQ(FILE_ERROR_OK, error);
|
| +
|
| + // Try to copy a file to the new directory which lacks resource ID.
|
| + // This should result in waiting for the directory to sync.
|
| + std::string waited_local_id;
|
| + FileOperationCallback pending_callback;
|
| + observer()->set_wait_for_sync_complete_handler(
|
| + base::Bind(&CopyWaitForSyncCompleteArguments,
|
| + &waited_local_id, &pending_callback));
|
| +
|
| + FileError copy_error = FILE_ERROR_FAILED;
|
| + operation_->Copy(src_path,
|
| + dest_path,
|
| + true, // Preserve last modified.
|
| + google_apis::test_util::CreateCopyResultCallback(
|
| + ©_error));
|
| + content::RunAllBlockingPoolTasksUntilIdle();
|
| + EXPECT_EQ(directory_local_id, waited_local_id);
|
| + ASSERT_FALSE(pending_callback.is_null());
|
| +
|
| + // Add a new directory to the server and store the resource ID locally.
|
| + google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
|
| + scoped_ptr<google_apis::FileResource> file_resource;
|
| + fake_service()->AddNewDirectory(
|
| + directory_parent.resource_id(),
|
| + directory.title(),
|
| + DriveServiceInterface::AddNewDirectoryOptions(),
|
| + google_apis::test_util::CreateCopyResultCallback(
|
| + &status, &file_resource));
|
| + content::RunAllBlockingPoolTasksUntilIdle();
|
| + EXPECT_EQ(google_apis::HTTP_CREATED, status);
|
| + ASSERT_TRUE(file_resource);
|
| +
|
| + directory.set_local_id(directory_local_id);
|
| + directory.set_resource_id(file_resource->file_id());
|
| + base::PostTaskAndReplyWithResult(
|
| + blocking_task_runner(),
|
| + FROM_HERE,
|
| + base::Bind(&internal::ResourceMetadata::RefreshEntry,
|
| + base::Unretained(metadata()), directory),
|
| + google_apis::test_util::CreateCopyResultCallback(&error));
|
| + content::RunAllBlockingPoolTasksUntilIdle();
|
| + EXPECT_EQ(FILE_ERROR_OK, error);
|
| +
|
| + // Resume the copy operation.
|
| + pending_callback.Run(FILE_ERROR_OK);
|
| + content::RunAllBlockingPoolTasksUntilIdle();
|
| +
|
| + EXPECT_EQ(FILE_ERROR_OK, copy_error);
|
| + ResourceEntry entry;
|
| + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &entry));
|
| +}
|
| +
|
| } // namespace file_system
|
| } // namespace drive
|
|
|