| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" |
| 6 |
| 7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
| 8 #include "chrome/browser/google_apis/test_util.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace drive { |
| 12 namespace file_system { |
| 13 |
| 14 class MoveOperationTest : public OperationTestBase { |
| 15 protected: |
| 16 virtual void SetUp() OVERRIDE { |
| 17 OperationTestBase::SetUp(); |
| 18 operation_.reset(new MoveOperation(observer(), scheduler(), metadata())); |
| 19 } |
| 20 |
| 21 virtual void TearDown() OVERRIDE { |
| 22 operation_.reset(); |
| 23 OperationTestBase::TearDown(); |
| 24 } |
| 25 |
| 26 scoped_ptr<MoveOperation> operation_; |
| 27 }; |
| 28 |
| 29 TEST_F(MoveOperationTest, MoveFileInSameDirectory) { |
| 30 const base::FilePath src_path( |
| 31 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 32 const base::FilePath dest_path( |
| 33 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); |
| 34 |
| 35 ResourceEntry src_entry, dest_entry; |
| 36 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| 37 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
| 38 GetLocalResourceEntry(dest_path, &dest_entry)); |
| 39 |
| 40 FileError error = FILE_ERROR_FAILED; |
| 41 operation_->Move(src_path, |
| 42 dest_path, |
| 43 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 44 google_apis::test_util::RunBlockingPoolTask(); |
| 45 EXPECT_EQ(FILE_ERROR_OK, error); |
| 46 |
| 47 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 48 EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); |
| 49 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| 50 |
| 51 EXPECT_EQ(1U, observer()->get_changed_paths().size()); |
| 52 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| 53 } |
| 54 |
| 55 TEST_F(MoveOperationTest, MoveFileFromRootToSubDirectory) { |
| 56 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 57 base::FilePath dest_path( |
| 58 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); |
| 59 |
| 60 ResourceEntry src_entry, dest_entry; |
| 61 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| 62 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
| 63 GetLocalResourceEntry(dest_path, &dest_entry)); |
| 64 |
| 65 FileError error = FILE_ERROR_FAILED; |
| 66 operation_->Move(src_path, |
| 67 dest_path, |
| 68 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 69 google_apis::test_util::RunBlockingPoolTask(); |
| 70 EXPECT_EQ(FILE_ERROR_OK, error); |
| 71 |
| 72 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 73 EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); |
| 74 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| 75 |
| 76 EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| 77 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| 78 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| 79 } |
| 80 |
| 81 TEST_F(MoveOperationTest, MoveFileFromSubDirectoryToRoot) { |
| 82 base::FilePath src_path( |
| 83 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 84 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 85 |
| 86 ResourceEntry src_entry, dest_entry; |
| 87 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| 88 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
| 89 GetLocalResourceEntry(dest_path, &dest_entry)); |
| 90 |
| 91 FileError error = FILE_ERROR_FAILED; |
| 92 operation_->Move(src_path, |
| 93 dest_path, |
| 94 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 95 google_apis::test_util::RunBlockingPoolTask(); |
| 96 EXPECT_EQ(FILE_ERROR_OK, error); |
| 97 |
| 98 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 99 EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); |
| 100 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| 101 |
| 102 EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| 103 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| 104 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| 105 } |
| 106 |
| 107 TEST_F(MoveOperationTest, MoveFileBetweenSubDirectories) { |
| 108 base::FilePath src_path( |
| 109 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 110 base::FilePath dest_path( |
| 111 FILE_PATH_LITERAL("drive/root/Directory 1/Sub Directory Folder/Test")); |
| 112 |
| 113 ResourceEntry src_entry, dest_entry; |
| 114 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| 115 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
| 116 GetLocalResourceEntry(dest_path, &dest_entry)); |
| 117 |
| 118 FileError error = FILE_ERROR_FAILED; |
| 119 operation_->Move(src_path, |
| 120 dest_path, |
| 121 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 122 google_apis::test_util::RunBlockingPoolTask(); |
| 123 EXPECT_EQ(FILE_ERROR_OK, error); |
| 124 |
| 125 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 126 EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); |
| 127 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| 128 |
| 129 EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| 130 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| 131 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| 132 } |
| 133 |
| 134 TEST_F(MoveOperationTest, MoveFileBetweenSubDirectoriesNoRename) { |
| 135 base::FilePath src_path( |
| 136 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 137 base::FilePath dest_path(FILE_PATH_LITERAL( |
| 138 "drive/root/Directory 1/Sub Directory Folder/SubDirectory File 1.txt")); |
| 139 |
| 140 ResourceEntry src_entry, dest_entry; |
| 141 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| 142 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
| 143 GetLocalResourceEntry(dest_path, &dest_entry)); |
| 144 |
| 145 FileError error = FILE_ERROR_FAILED; |
| 146 operation_->Move(src_path, |
| 147 dest_path, |
| 148 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 149 google_apis::test_util::RunBlockingPoolTask(); |
| 150 EXPECT_EQ(FILE_ERROR_OK, error); |
| 151 |
| 152 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 153 EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); |
| 154 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| 155 |
| 156 EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| 157 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| 158 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| 159 } |
| 160 |
| 161 TEST_F(MoveOperationTest, MoveNotExistingFile) { |
| 162 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
| 163 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 164 |
| 165 FileError error = FILE_ERROR_OK; |
| 166 operation_->Move(src_path, |
| 167 dest_path, |
| 168 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 169 google_apis::test_util::RunBlockingPoolTask(); |
| 170 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
| 171 |
| 172 ResourceEntry entry; |
| 173 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); |
| 174 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
| 175 } |
| 176 |
| 177 TEST_F(MoveOperationTest, MoveFileToNonExistingDirectory) { |
| 178 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 179 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); |
| 180 |
| 181 FileError error = FILE_ERROR_OK; |
| 182 operation_->Move(src_path, |
| 183 dest_path, |
| 184 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 185 google_apis::test_util::RunBlockingPoolTask(); |
| 186 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
| 187 |
| 188 ResourceEntry entry; |
| 189 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
| 190 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
| 191 } |
| 192 |
| 193 // Test the case where the parent of |dest_file_path| is a existing file, |
| 194 // not a directory. |
| 195 TEST_F(MoveOperationTest, MoveFileToInvalidPath) { |
| 196 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 197 base::FilePath dest_path( |
| 198 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt/Test.log")); |
| 199 |
| 200 FileError error = FILE_ERROR_OK; |
| 201 operation_->Move(src_path, |
| 202 dest_path, |
| 203 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 204 google_apis::test_util::RunBlockingPoolTask(); |
| 205 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); |
| 206 |
| 207 ResourceEntry entry; |
| 208 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
| 209 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
| 210 } |
| 211 |
| 212 } // namespace file_system |
| 213 } // namespace drive |
| OLD | NEW |