| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" | 7 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" |
| 8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
| 9 #include "chrome/browser/drive/fake_drive_service.h" | 9 #include "chrome/browser/drive/fake_drive_service.h" |
| 10 #include "chrome/browser/google_apis/test_util.h" | 10 #include "chrome/browser/google_apis/test_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace drive { | 13 namespace drive { |
| 14 namespace file_system { | 14 namespace file_system { |
| 15 | 15 |
| 16 class MoveOperationTest : public OperationTestBase { | 16 class MoveOperationTest : public OperationTestBase { |
| 17 protected: | 17 protected: |
| 18 virtual void SetUp() OVERRIDE { | 18 virtual void SetUp() OVERRIDE { |
| 19 OperationTestBase::SetUp(); | 19 OperationTestBase::SetUp(); |
| 20 operation_.reset(new MoveOperation(blocking_task_runner(), | 20 operation_.reset(new MoveOperation(blocking_task_runner(), |
| 21 observer(), | 21 observer(), |
| 22 scheduler(), | |
| 23 metadata())); | 22 metadata())); |
| 24 copy_operation_.reset(new CopyOperation(blocking_task_runner(), | 23 copy_operation_.reset(new CopyOperation(blocking_task_runner(), |
| 25 observer(), | 24 observer(), |
| 26 scheduler(), | 25 scheduler(), |
| 27 metadata(), | 26 metadata(), |
| 28 cache(), | 27 cache(), |
| 29 fake_service(), | 28 fake_service(), |
| 30 temp_dir())); | 29 temp_dir())); |
| 31 } | 30 } |
| 32 | 31 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 48 FileError error = FILE_ERROR_FAILED; | 47 FileError error = FILE_ERROR_FAILED; |
| 49 operation_->Move(src_path, | 48 operation_->Move(src_path, |
| 50 dest_path, | 49 dest_path, |
| 51 false, | 50 false, |
| 52 google_apis::test_util::CreateCopyResultCallback(&error)); | 51 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 53 test_util::RunBlockingPoolTask(); | 52 test_util::RunBlockingPoolTask(); |
| 54 EXPECT_EQ(FILE_ERROR_OK, error); | 53 EXPECT_EQ(FILE_ERROR_OK, error); |
| 55 | 54 |
| 56 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | 55 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 57 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); | 56 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); |
| 57 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); |
| 58 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | 58 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| 59 | 59 |
| 60 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 60 EXPECT_EQ(1U, observer()->get_changed_paths().size()); |
| 61 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); | 61 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| 62 } | 62 } |
| 63 | 63 |
| 64 TEST_F(MoveOperationTest, MoveFileFromRootToSubDirectory) { | 64 TEST_F(MoveOperationTest, MoveFileFromRootToSubDirectory) { |
| 65 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 65 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 66 base::FilePath dest_path( | 66 base::FilePath dest_path( |
| 67 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); | 67 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); |
| 68 | 68 |
| 69 ResourceEntry src_entry, dest_entry; | 69 ResourceEntry src_entry, dest_entry; |
| 70 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); | 70 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| 71 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | 71 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
| 72 GetLocalResourceEntry(dest_path, &dest_entry)); | 72 GetLocalResourceEntry(dest_path, &dest_entry)); |
| 73 | 73 |
| 74 FileError error = FILE_ERROR_FAILED; | 74 FileError error = FILE_ERROR_FAILED; |
| 75 operation_->Move(src_path, | 75 operation_->Move(src_path, |
| 76 dest_path, | 76 dest_path, |
| 77 false, | 77 false, |
| 78 google_apis::test_util::CreateCopyResultCallback(&error)); | 78 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 79 test_util::RunBlockingPoolTask(); | 79 test_util::RunBlockingPoolTask(); |
| 80 EXPECT_EQ(FILE_ERROR_OK, error); | 80 EXPECT_EQ(FILE_ERROR_OK, error); |
| 81 | 81 |
| 82 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | 82 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 83 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); | 83 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); |
| 84 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); |
| 84 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | 85 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| 85 | 86 |
| 86 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | 87 EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| 87 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); | |
| 88 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); | |
| 89 } | |
| 90 | |
| 91 TEST_F(MoveOperationTest, MoveFileFromSubDirectoryToRoot) { | |
| 92 base::FilePath src_path( | |
| 93 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | |
| 94 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); | |
| 95 | |
| 96 ResourceEntry src_entry, dest_entry; | |
| 97 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); | |
| 98 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | |
| 99 GetLocalResourceEntry(dest_path, &dest_entry)); | |
| 100 | |
| 101 FileError error = FILE_ERROR_FAILED; | |
| 102 operation_->Move(src_path, | |
| 103 dest_path, | |
| 104 false, | |
| 105 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 106 test_util::RunBlockingPoolTask(); | |
| 107 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 108 | |
| 109 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | |
| 110 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); | |
| 111 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | |
| 112 | |
| 113 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | |
| 114 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); | |
| 115 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); | |
| 116 } | |
| 117 | |
| 118 TEST_F(MoveOperationTest, MoveFileBetweenSubDirectories) { | |
| 119 base::FilePath src_path( | |
| 120 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | |
| 121 base::FilePath dest_path( | |
| 122 FILE_PATH_LITERAL("drive/root/Directory 1/Sub Directory Folder/Test")); | |
| 123 | |
| 124 ResourceEntry src_entry, dest_entry; | |
| 125 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); | |
| 126 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | |
| 127 GetLocalResourceEntry(dest_path, &dest_entry)); | |
| 128 | |
| 129 FileError error = FILE_ERROR_FAILED; | |
| 130 operation_->Move(src_path, | |
| 131 dest_path, | |
| 132 false, | |
| 133 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 134 test_util::RunBlockingPoolTask(); | |
| 135 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 136 | |
| 137 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | |
| 138 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); | |
| 139 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | |
| 140 | |
| 141 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | |
| 142 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); | |
| 143 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); | |
| 144 } | |
| 145 | |
| 146 TEST_F(MoveOperationTest, MoveFileBetweenSubDirectoriesNoRename) { | |
| 147 base::FilePath src_path( | |
| 148 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | |
| 149 base::FilePath dest_path(FILE_PATH_LITERAL( | |
| 150 "drive/root/Directory 1/Sub Directory Folder/SubDirectory File 1.txt")); | |
| 151 | |
| 152 ResourceEntry src_entry, dest_entry; | |
| 153 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); | |
| 154 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | |
| 155 GetLocalResourceEntry(dest_path, &dest_entry)); | |
| 156 | |
| 157 FileError error = FILE_ERROR_FAILED; | |
| 158 operation_->Move(src_path, | |
| 159 dest_path, | |
| 160 false, | |
| 161 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 162 test_util::RunBlockingPoolTask(); | |
| 163 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 164 | |
| 165 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | |
| 166 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); | |
| 167 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | |
| 168 | |
| 169 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | |
| 170 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); | 88 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| 171 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); | 89 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| 172 } | 90 } |
| 173 | 91 |
| 174 TEST_F(MoveOperationTest, MoveFileBetweenSubDirectoriesRenameWithTitle) { | 92 TEST_F(MoveOperationTest, MoveFileBetweenSubDirectoriesRenameWithTitle) { |
| 175 base::FilePath src_path( | 93 base::FilePath src_path( |
| 176 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | 94 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 177 base::FilePath dest_path(FILE_PATH_LITERAL( | 95 base::FilePath dest_path(FILE_PATH_LITERAL( |
| 178 "drive/root/Directory 1/Sub Directory Folder/" | 96 "drive/root/Directory 1/Sub Directory Folder/" |
| 179 "SubDirectory File 1 (1).txt")); | 97 "SubDirectory File 1 (1).txt")); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 203 operation_->Move(copied_path, | 121 operation_->Move(copied_path, |
| 204 dest_path, | 122 dest_path, |
| 205 false, | 123 false, |
| 206 google_apis::test_util::CreateCopyResultCallback(&error)); | 124 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 207 test_util::RunBlockingPoolTask(); | 125 test_util::RunBlockingPoolTask(); |
| 208 EXPECT_EQ(FILE_ERROR_OK, error); | 126 EXPECT_EQ(FILE_ERROR_OK, error); |
| 209 | 127 |
| 210 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | 128 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 211 EXPECT_EQ("SubDirectory File 1 (1).txt", dest_entry.title()); | 129 EXPECT_EQ("SubDirectory File 1 (1).txt", dest_entry.title()); |
| 212 EXPECT_EQ(copied_entry.local_id(), dest_entry.local_id()); | 130 EXPECT_EQ(copied_entry.local_id(), dest_entry.local_id()); |
| 131 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); |
| 213 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 132 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
| 214 GetLocalResourceEntry(copied_path, &copied_entry)); | 133 GetLocalResourceEntry(copied_path, &copied_entry)); |
| 215 | 134 |
| 216 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | 135 EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| 217 EXPECT_TRUE(observer()->get_changed_paths().count(copied_path.DirName())); | 136 EXPECT_TRUE(observer()->get_changed_paths().count(copied_path.DirName())); |
| 218 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); | 137 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| 219 } | 138 } |
| 220 | 139 |
| 221 TEST_F(MoveOperationTest, MoveNotExistingFile) { | 140 TEST_F(MoveOperationTest, MoveNotExistingFile) { |
| 222 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); | 141 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 dest_path, | 207 dest_path, |
| 289 true, // Preserve last modified. | 208 true, // Preserve last modified. |
| 290 google_apis::test_util::CreateCopyResultCallback(&error)); | 209 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 291 test_util::RunBlockingPoolTask(); | 210 test_util::RunBlockingPoolTask(); |
| 292 EXPECT_EQ(FILE_ERROR_OK, error); | 211 EXPECT_EQ(FILE_ERROR_OK, error); |
| 293 | 212 |
| 294 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | 213 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 295 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); | 214 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); |
| 296 EXPECT_EQ(src_entry.file_info().last_modified(), | 215 EXPECT_EQ(src_entry.file_info().last_modified(), |
| 297 dest_entry.file_info().last_modified()); | 216 dest_entry.file_info().last_modified()); |
| 217 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); |
| 298 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 218 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
| 299 GetLocalResourceEntry(src_path, &src_entry)); | 219 GetLocalResourceEntry(src_path, &src_entry)); |
| 300 } | 220 } |
| 301 | 221 |
| 302 } // namespace file_system | 222 } // namespace file_system |
| 303 } // namespace drive | 223 } // namespace drive |
| OLD | NEW |