Chromium Code Reviews| 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; | |
| 36 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); | |
| 37 | |
|
hidehiko
2013/05/24 04:45:14
How about check
ASSERT_EQ(FILE_ERROR_NOT_FOUND, Ge
kinaba
2013/05/24 05:05:42
Sounds good. Done.
| |
| 38 FileError error = FILE_ERROR_FAILED; | |
| 39 operation_->Move(src_path, | |
| 40 dest_path, | |
| 41 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 42 google_apis::test_util::RunBlockingPoolTask(); | |
| 43 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 44 | |
| 45 ResourceEntry dest_entry; | |
| 46 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | |
| 47 EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); | |
| 48 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | |
| 49 | |
| 50 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | |
| 51 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); | |
| 52 } | |
| 53 | |
| 54 TEST_F(MoveOperationTest, MoveFileFromRootToSubDirectory) { | |
| 55 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
| 56 base::FilePath dest_path( | |
| 57 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); | |
| 58 | |
| 59 ResourceEntry src_entry; | |
| 60 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); | |
| 61 | |
| 62 FileError error = FILE_ERROR_FAILED; | |
| 63 operation_->Move(src_path, | |
| 64 dest_path, | |
| 65 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 66 google_apis::test_util::RunBlockingPoolTask(); | |
| 67 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 68 | |
| 69 ResourceEntry dest_entry; | |
| 70 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | |
| 71 EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); | |
| 72 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | |
| 73 | |
| 74 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | |
| 75 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); | |
| 76 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); | |
| 77 } | |
| 78 | |
| 79 TEST_F(MoveOperationTest, MoveFileFromSubDirectoryToRoot) { | |
| 80 base::FilePath src_path( | |
| 81 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | |
| 82 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); | |
| 83 | |
| 84 ResourceEntry src_entry; | |
| 85 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); | |
| 86 | |
| 87 FileError error = FILE_ERROR_FAILED; | |
| 88 operation_->Move(src_path, | |
| 89 dest_path, | |
| 90 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 91 google_apis::test_util::RunBlockingPoolTask(); | |
| 92 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 93 | |
| 94 ResourceEntry dest_entry; | |
| 95 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | |
| 96 EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); | |
| 97 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | |
| 98 | |
| 99 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | |
| 100 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); | |
| 101 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); | |
| 102 } | |
| 103 | |
| 104 TEST_F(MoveOperationTest, MoveFileBetweenSubDirectories) { | |
| 105 base::FilePath src_path( | |
| 106 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | |
| 107 base::FilePath dest_path( | |
| 108 FILE_PATH_LITERAL("drive/root/Directory 1/Sub Directory Folder/Test")); | |
| 109 | |
| 110 ResourceEntry src_entry; | |
| 111 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); | |
| 112 | |
| 113 FileError error = FILE_ERROR_FAILED; | |
| 114 operation_->Move(src_path, | |
| 115 dest_path, | |
| 116 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 117 google_apis::test_util::RunBlockingPoolTask(); | |
| 118 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 119 | |
| 120 ResourceEntry dest_entry; | |
| 121 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | |
| 122 EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); | |
| 123 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | |
| 124 | |
| 125 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | |
| 126 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); | |
| 127 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); | |
| 128 } | |
| 129 | |
| 130 TEST_F(MoveOperationTest, MoveFileBetweenSubDirectoriesNoRename) { | |
| 131 base::FilePath src_path( | |
| 132 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | |
| 133 base::FilePath dest_path(FILE_PATH_LITERAL( | |
| 134 "drive/root/Directory 1/Sub Directory Folder/SubDirectory File 1.txt")); | |
| 135 | |
| 136 ResourceEntry src_entry; | |
| 137 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); | |
| 138 | |
| 139 FileError error = FILE_ERROR_FAILED; | |
| 140 operation_->Move(src_path, | |
| 141 dest_path, | |
| 142 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 143 google_apis::test_util::RunBlockingPoolTask(); | |
| 144 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 145 | |
| 146 ResourceEntry dest_entry; | |
| 147 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | |
| 148 EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); | |
| 149 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | |
| 150 | |
| 151 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | |
| 152 EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); | |
| 153 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); | |
| 154 } | |
| 155 | |
| 156 TEST_F(MoveOperationTest, MoveNotExistingFile) { | |
| 157 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); | |
| 158 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); | |
| 159 | |
| 160 FileError error = FILE_ERROR_OK; | |
| 161 operation_->Move(src_path, | |
| 162 dest_path, | |
| 163 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 164 google_apis::test_util::RunBlockingPoolTask(); | |
| 165 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | |
| 166 | |
| 167 ResourceEntry entry; | |
| 168 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); | |
| 169 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); | |
| 170 } | |
| 171 | |
| 172 TEST_F(MoveOperationTest, MoveFileToNonExistingDirectory) { | |
| 173 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
| 174 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); | |
| 175 | |
| 176 FileError error = FILE_ERROR_OK; | |
| 177 operation_->Move(src_path, | |
| 178 dest_path, | |
| 179 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 180 google_apis::test_util::RunBlockingPoolTask(); | |
| 181 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | |
| 182 | |
| 183 ResourceEntry entry; | |
| 184 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | |
| 185 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); | |
| 186 } | |
| 187 | |
| 188 // Test the case where the parent of |dest_file_path| is a existing file, | |
| 189 // not a directory. | |
| 190 TEST_F(MoveOperationTest, MoveFileToInvalidPath) { | |
| 191 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
| 192 base::FilePath dest_path( | |
| 193 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt/Test.log")); | |
| 194 | |
| 195 FileError error = FILE_ERROR_OK; | |
| 196 operation_->Move(src_path, | |
| 197 dest_path, | |
| 198 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 199 google_apis::test_util::RunBlockingPoolTask(); | |
| 200 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); | |
| 201 | |
| 202 ResourceEntry entry; | |
| 203 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | |
| 204 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); | |
| 205 } | |
| 206 | |
| 207 } // namespace file_system | |
| 208 } // namespace drive | |
| OLD | NEW |