| 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/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" |
| 8 #include "chrome/browser/google_apis/test_util.h" | 10 #include "chrome/browser/google_apis/test_util.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 12 |
| 11 namespace drive { | 13 namespace drive { |
| 12 namespace file_system { | 14 namespace file_system { |
| 13 | 15 |
| 14 class MoveOperationTest : public OperationTestBase { | 16 class MoveOperationTest : public OperationTestBase { |
| 15 protected: | 17 protected: |
| 16 virtual void SetUp() OVERRIDE { | 18 virtual void SetUp() OVERRIDE { |
| 17 OperationTestBase::SetUp(); | 19 OperationTestBase::SetUp(); |
| 18 operation_.reset(new MoveOperation(observer(), scheduler(), metadata())); | 20 operation_.reset(new MoveOperation(blocking_task_runner(), |
| 21 observer(), |
| 22 scheduler(), |
| 23 metadata())); |
| 24 copy_operation_.reset(new CopyOperation(blocking_task_runner(), |
| 25 observer(), |
| 26 scheduler(), |
| 27 metadata(), |
| 28 cache(), |
| 29 fake_service(), |
| 30 temp_dir())); |
| 19 } | 31 } |
| 20 | 32 |
| 21 scoped_ptr<MoveOperation> operation_; | 33 scoped_ptr<MoveOperation> operation_; |
| 34 scoped_ptr<CopyOperation> copy_operation_; |
| 22 }; | 35 }; |
| 23 | 36 |
| 24 TEST_F(MoveOperationTest, MoveFileInSameDirectory) { | 37 TEST_F(MoveOperationTest, MoveFileInSameDirectory) { |
| 25 const base::FilePath src_path( | 38 const base::FilePath src_path( |
| 26 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | 39 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 27 const base::FilePath dest_path( | 40 const base::FilePath dest_path( |
| 28 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); | 41 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); |
| 29 | 42 |
| 30 ResourceEntry src_entry, dest_entry; | 43 ResourceEntry src_entry, dest_entry; |
| 31 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); | 44 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 159 |
| 147 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | 160 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 148 EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); | 161 EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); |
| 149 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | 162 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| 150 | 163 |
| 151 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | 164 EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| 152 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); | 165 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| 153 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); | 166 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| 154 } | 167 } |
| 155 | 168 |
| 169 TEST_F(MoveOperationTest, MoveFileBetweenSubDirectoriesRenameWithTitle) { |
| 170 base::FilePath src_path( |
| 171 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 172 base::FilePath dest_path(FILE_PATH_LITERAL( |
| 173 "drive/root/Directory 1/Sub Directory Folder/" |
| 174 "SubDirectory File 1 (1).txt")); |
| 175 |
| 176 ResourceEntry src_entry, dest_entry; |
| 177 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| 178 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
| 179 GetLocalResourceEntry(dest_path, &dest_entry)); |
| 180 |
| 181 FileError error = FILE_ERROR_FAILED; |
| 182 // Copy the src file into the same directory. This will make inconsistency |
| 183 // between title and path of the copied file. |
| 184 copy_operation_->Copy( |
| 185 src_path, |
| 186 src_path, |
| 187 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 188 test_util::RunBlockingPoolTask(); |
| 189 EXPECT_EQ(FILE_ERROR_OK, error); |
| 190 base::FilePath copied_path( |
| 191 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1 (1).txt")); |
| 192 ResourceEntry copied_entry; |
| 193 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(copied_path, &copied_entry)); |
| 194 ASSERT_EQ("SubDirectory File 1.txt", copied_entry.title()); |
| 195 |
| 196 // Move the copied file. |
| 197 operation_->Move(copied_path, |
| 198 dest_path, |
| 199 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 200 test_util::RunBlockingPoolTask(); |
| 201 EXPECT_EQ(FILE_ERROR_OK, error); |
| 202 |
| 203 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 204 EXPECT_EQ("SubDirectory File 1 (1).txt", dest_entry.title()); |
| 205 EXPECT_EQ(copied_entry.resource_id(), dest_entry.resource_id()); |
| 206 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
| 207 GetLocalResourceEntry(copied_path, &copied_entry)); |
| 208 |
| 209 EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| 210 EXPECT_TRUE(observer()->get_changed_paths().count(copied_path.DirName())); |
| 211 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| 212 } |
| 213 |
| 156 TEST_F(MoveOperationTest, MoveNotExistingFile) { | 214 TEST_F(MoveOperationTest, MoveNotExistingFile) { |
| 157 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); | 215 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
| 158 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); | 216 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 159 | 217 |
| 160 FileError error = FILE_ERROR_OK; | 218 FileError error = FILE_ERROR_OK; |
| 161 operation_->Move(src_path, | 219 operation_->Move(src_path, |
| 162 dest_path, | 220 dest_path, |
| 163 google_apis::test_util::CreateCopyResultCallback(&error)); | 221 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 164 test_util::RunBlockingPoolTask(); | 222 test_util::RunBlockingPoolTask(); |
| 165 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 223 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 test_util::RunBlockingPoolTask(); | 257 test_util::RunBlockingPoolTask(); |
| 200 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); | 258 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); |
| 201 | 259 |
| 202 ResourceEntry entry; | 260 ResourceEntry entry; |
| 203 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | 261 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
| 204 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); | 262 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
| 205 } | 263 } |
| 206 | 264 |
| 207 } // namespace file_system | 265 } // namespace file_system |
| 208 } // namespace drive | 266 } // namespace drive |
| OLD | NEW |