| 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 28494b50b3a0173f913c6f15292239110aabfe0c..ae1f78a2981491b92708d73a9c8dad8148cfe344 100644
 | 
| --- a/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc
 | 
| +++ b/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc
 | 
| @@ -4,6 +4,7 @@
 | 
|  
 | 
|  #include "chrome/browser/chromeos/drive/file_system/copy_operation.h"
 | 
|  
 | 
| +#include "base/file_util.h"
 | 
|  #include "base/task_runner_util.h"
 | 
|  #include "chrome/browser/chromeos/drive/file_cache.h"
 | 
|  #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
 | 
| @@ -217,6 +218,121 @@ TEST_F(CopyOperationTest, CopyFileToInvalidPath) {
 | 
|    EXPECT_TRUE(observer()->get_changed_paths().empty());
 | 
|  }
 | 
|  
 | 
| +TEST_F(CopyOperationTest, CopyDirtyFile) {
 | 
| +  base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
 | 
| +  base::FilePath dest_path(FILE_PATH_LITERAL(
 | 
| +      "drive/root/Directory 1/New File.txt"));
 | 
| +
 | 
| +  ResourceEntry src_entry;
 | 
| +  EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry));
 | 
| +
 | 
| +  // Store a dirty cache file.
 | 
| +  base::FilePath temp_file;
 | 
| +  EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir(), &temp_file));
 | 
| +  std::string contents = "test content";
 | 
| +  EXPECT_TRUE(google_apis::test_util::WriteStringToFile(temp_file, contents));
 | 
| +  FileError error = FILE_ERROR_FAILED;
 | 
| +  base::PostTaskAndReplyWithResult(
 | 
| +      blocking_task_runner(),
 | 
| +      FROM_HERE,
 | 
| +      base::Bind(&internal::FileCache::Store,
 | 
| +                 base::Unretained(cache()),
 | 
| +                 src_entry.local_id(),
 | 
| +                 std::string(),
 | 
| +                 temp_file,
 | 
| +                 internal::FileCache::FILE_OPERATION_MOVE),
 | 
| +      google_apis::test_util::CreateCopyResultCallback(&error));
 | 
| +  test_util::RunBlockingPoolTask();
 | 
| +  EXPECT_EQ(FILE_ERROR_OK, error);
 | 
| +
 | 
| +  // Copy.
 | 
| +  operation_->Copy(src_path,
 | 
| +                   dest_path,
 | 
| +                   false,
 | 
| +                   google_apis::test_util::CreateCopyResultCallback(&error));
 | 
| +  test_util::RunBlockingPoolTask();
 | 
| +  EXPECT_EQ(FILE_ERROR_OK, error);
 | 
| +
 | 
| +  ResourceEntry dest_entry;
 | 
| +  EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry));
 | 
| +  EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state());
 | 
| +
 | 
| +  EXPECT_EQ(1u, observer()->updated_local_ids().size());
 | 
| +  EXPECT_TRUE(observer()->updated_local_ids().count(dest_entry.local_id()));
 | 
| +  EXPECT_EQ(1u, observer()->get_changed_paths().size());
 | 
| +  EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName()));
 | 
| +
 | 
| +  // Copied cache file should be dirty.
 | 
| +  bool success = false;
 | 
| +  FileCacheEntry cache_entry;
 | 
| +  base::PostTaskAndReplyWithResult(
 | 
| +      blocking_task_runner(),
 | 
| +      FROM_HERE,
 | 
| +      base::Bind(&internal::FileCache::GetCacheEntry,
 | 
| +                 base::Unretained(cache()),
 | 
| +                 dest_entry.local_id(),
 | 
| +                 &cache_entry),
 | 
| +      google_apis::test_util::CreateCopyResultCallback(&success));
 | 
| +  test_util::RunBlockingPoolTask();
 | 
| +  EXPECT_TRUE(success);
 | 
| +  EXPECT_TRUE(cache_entry.is_dirty());
 | 
| +
 | 
| +  // File contents should match.
 | 
| +  base::FilePath cache_file_path;
 | 
| +  base::PostTaskAndReplyWithResult(
 | 
| +      blocking_task_runner(),
 | 
| +      FROM_HERE,
 | 
| +      base::Bind(&internal::FileCache::GetFile,
 | 
| +                 base::Unretained(cache()),
 | 
| +                 dest_entry.local_id(),
 | 
| +                 &cache_file_path),
 | 
| +      google_apis::test_util::CreateCopyResultCallback(&error));
 | 
| +  test_util::RunBlockingPoolTask();
 | 
| +  EXPECT_EQ(FILE_ERROR_OK, error);
 | 
| +
 | 
| +  std::string copied_contents;
 | 
| +  EXPECT_TRUE(base::ReadFileToString(cache_file_path, &copied_contents));
 | 
| +  EXPECT_EQ(contents, copied_contents);
 | 
| +}
 | 
| +
 | 
| +TEST_F(CopyOperationTest, CopyFileOverwriteFile) {
 | 
| +  base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
 | 
| +  base::FilePath dest_path(FILE_PATH_LITERAL(
 | 
| +      "drive/root/Directory 1/SubDirectory File 1.txt"));
 | 
| +
 | 
| +  ResourceEntry old_dest_entry;
 | 
| +  EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &old_dest_entry));
 | 
| +
 | 
| +  FileError error = FILE_ERROR_OK;
 | 
| +  operation_->Copy(src_path,
 | 
| +                   dest_path,
 | 
| +                   false,
 | 
| +                   google_apis::test_util::CreateCopyResultCallback(&error));
 | 
| +  test_util::RunBlockingPoolTask();
 | 
| +  EXPECT_EQ(FILE_ERROR_OK, error);
 | 
| +
 | 
| +  ResourceEntry new_dest_entry;
 | 
| +  EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &new_dest_entry));
 | 
| +
 | 
| +  EXPECT_EQ(1u, observer()->updated_local_ids().size());
 | 
| +  EXPECT_TRUE(observer()->updated_local_ids().count(old_dest_entry.local_id()));
 | 
| +  EXPECT_EQ(1u, observer()->get_changed_paths().size());
 | 
| +  EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName()));
 | 
| +}
 | 
| +
 | 
| +TEST_F(CopyOperationTest, CopyFileOverwriteDirectory) {
 | 
| +  base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
 | 
| +  base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Directory 1"));
 | 
| +
 | 
| +  FileError error = FILE_ERROR_OK;
 | 
| +  operation_->Copy(src_path,
 | 
| +                   dest_path,
 | 
| +                   false,
 | 
| +                   google_apis::test_util::CreateCopyResultCallback(&error));
 | 
| +  test_util::RunBlockingPoolTask();
 | 
| +  EXPECT_EQ(FILE_ERROR_INVALID_OPERATION, error);
 | 
| +}
 | 
| +
 | 
|  TEST_F(CopyOperationTest, CopyDirectory) {
 | 
|    base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Directory 1"));
 | 
|    base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/New Directory"));
 | 
| 
 |