| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/fileapi/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 fileapi::FileSystemOperation* operation() { | 79 fileapi::FileSystemOperation* operation() { |
| 80 request_id_ = ++last_request_id; | 80 request_id_ = ++last_request_id; |
| 81 mock_dispatcher_ = new MockDispatcher(request_id_); | 81 mock_dispatcher_ = new MockDispatcher(request_id_); |
| 82 operation_.reset(new fileapi::FileSystemOperation( | 82 operation_.reset(new fileapi::FileSystemOperation( |
| 83 mock_dispatcher_, base::MessageLoopProxy::CreateForCurrentThread())); | 83 mock_dispatcher_, base::MessageLoopProxy::CreateForCurrentThread())); |
| 84 return operation_.get(); | 84 return operation_.get(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 protected: | 87 protected: |
| 88 // Common temp base for all non-existing file/dir path test cases. | 88 // Common temp base for nondestructive uses. |
| 89 // This is in case a dir on test machine exists. It's better to | |
| 90 // create temp and then create non-existing file paths under it. | |
| 91 ScopedTempDir base_; | 89 ScopedTempDir base_; |
| 92 | 90 |
| 93 int request_id_; | 91 int request_id_; |
| 94 scoped_ptr<fileapi::FileSystemOperation> operation_; | 92 scoped_ptr<fileapi::FileSystemOperation> operation_; |
| 95 | 93 |
| 96 // Owned by |operation_|. | 94 // Owned by |operation_|. |
| 97 MockDispatcher* mock_dispatcher_; | 95 MockDispatcher* mock_dispatcher_; |
| 98 | 96 |
| 99 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); | 97 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); |
| 100 }; | 98 }; |
| 101 | 99 |
| 102 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { | 100 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { |
| 103 FilePath src(base_.path().Append(FILE_PATH_LITERAL("a"))); | 101 FilePath src(base_.path().Append(FILE_PATH_LITERAL("a"))); |
| 104 FilePath dest(base_.path().Append(FILE_PATH_LITERAL("b"))); | 102 FilePath dest(base_.path().Append(FILE_PATH_LITERAL("b"))); |
| 105 operation()->Move(src, dest); | 103 operation()->Move(src, dest); |
| 106 MessageLoop::current()->RunAllPending(); | 104 MessageLoop::current()->RunAllPending(); |
| 107 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, mock_dispatcher_->status()); | 105 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, mock_dispatcher_->status()); |
| 108 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 106 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 109 } | 107 } |
| 110 | 108 |
| 111 | 109 |
| 112 TEST_F(FileSystemOperationTest, TestMoveFailureContainsPath) { | 110 TEST_F(FileSystemOperationTest, TestMoveFailureContainsPath) { |
| 113 ScopedTempDir dir_under_base; | 111 ScopedTempDir src_dir; |
| 114 dir_under_base.CreateUniqueTempDirUnderPath(base_.path()); | 112 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 115 operation()->Move(base_.path(), dir_under_base.path()); | 113 FilePath dest_dir_path; |
| 114 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(src_dir.path(), |
| 115 &dest_dir_path)); |
| 116 operation()->Move(src_dir.path(), dest_dir_path); |
| 116 MessageLoop::current()->RunAllPending(); | 117 MessageLoop::current()->RunAllPending(); |
| 117 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, | 118 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, |
| 118 mock_dispatcher_->status()); | 119 mock_dispatcher_->status()); |
| 119 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 120 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 120 } | 121 } |
| 121 | 122 |
| 122 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) { | 123 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) { |
| 123 // Src exists and is dir. Dest is a file. | 124 // Src exists and is dir. Dest is a file. |
| 125 ScopedTempDir src_dir; |
| 126 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 127 |
| 124 ScopedTempDir dest_dir; | 128 ScopedTempDir dest_dir; |
| 125 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); | 129 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); |
| 126 FilePath dest_file; | 130 FilePath dest_file; |
| 127 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file); | 131 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file); |
| 128 | 132 |
| 129 operation()->Move(base_.path(), dest_file); | 133 operation()->Move(src_dir.path(), dest_file); |
| 130 MessageLoop::current()->RunAllPending(); | 134 MessageLoop::current()->RunAllPending(); |
| 131 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, mock_dispatcher_->status()); | 135 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, |
| 136 mock_dispatcher_->status()); |
| 132 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 137 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 133 } | 138 } |
| 134 | 139 |
| 140 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestNonEmptyDir) { |
| 141 // Src exists and is a directory. Dest is a non-empty directory. |
| 142 ScopedTempDir src_dir; |
| 143 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 144 |
| 145 ScopedTempDir dest_dir; |
| 146 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); |
| 147 FilePath child_file; |
| 148 file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file); |
| 149 |
| 150 operation()->Move(src_dir.path(), dest_dir.path()); |
| 151 MessageLoop::current()->RunAllPending(); |
| 152 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, mock_dispatcher_->status()); |
| 153 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 154 } |
| 155 |
| 156 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) { |
| 157 // Src exists and is a file. Dest is a directory. |
| 158 ScopedTempDir src_dir; |
| 159 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 160 FilePath src_file; |
| 161 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file); |
| 162 |
| 163 ScopedTempDir dest_dir; |
| 164 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); |
| 165 |
| 166 operation()->Move(src_file, dest_dir.path()); |
| 167 MessageLoop::current()->RunAllPending(); |
| 168 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, |
| 169 mock_dispatcher_->status()); |
| 170 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 171 } |
| 172 |
| 135 TEST_F(FileSystemOperationTest, TestMoveFailureDestParentDoesntExist) { | 173 TEST_F(FileSystemOperationTest, TestMoveFailureDestParentDoesntExist) { |
| 136 // Dest. parent path does not exist. | 174 // Dest. parent path does not exist. |
| 137 ScopedTempDir src_dir; | 175 ScopedTempDir src_dir; |
| 138 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); | 176 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 139 FilePath nonexisting_file = base_.path().Append( | 177 FilePath nonexisting_file = base_.path().Append( |
| 140 FILE_PATH_LITERAL("NonexistingDir")).Append( | 178 FILE_PATH_LITERAL("NonexistingDir")).Append( |
| 141 FILE_PATH_LITERAL("NonexistingFile"));; | 179 FILE_PATH_LITERAL("NonexistingFile")); |
| 142 | 180 |
| 143 operation()->Move(src_dir.path(), nonexisting_file); | 181 operation()->Move(src_dir.path(), nonexisting_file); |
| 144 MessageLoop::current()->RunAllPending(); | 182 MessageLoop::current()->RunAllPending(); |
| 145 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, mock_dispatcher_->status()); | 183 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, mock_dispatcher_->status()); |
| 146 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 184 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 147 } | 185 } |
| 148 | 186 |
| 149 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { | 187 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { |
| 150 ScopedTempDir src_dir; | 188 ScopedTempDir src_dir; |
| 151 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); | 189 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 174 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); | 212 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); |
| 175 FilePath dest_file(dest_dir.path().Append(FILE_PATH_LITERAL("NewFile"))); | 213 FilePath dest_file(dest_dir.path().Append(FILE_PATH_LITERAL("NewFile"))); |
| 176 | 214 |
| 177 operation()->Move(src_file, dest_file); | 215 operation()->Move(src_file, dest_file); |
| 178 MessageLoop::current()->RunAllPending(); | 216 MessageLoop::current()->RunAllPending(); |
| 179 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); | 217 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 180 EXPECT_TRUE(FileExists(dest_file)); | 218 EXPECT_TRUE(FileExists(dest_file)); |
| 181 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 219 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 182 } | 220 } |
| 183 | 221 |
| 222 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) { |
| 223 ScopedTempDir src_dir; |
| 224 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 225 |
| 226 ScopedTempDir dest_dir; |
| 227 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); |
| 228 |
| 229 operation()->Move(src_dir.path(), dest_dir.path()); |
| 230 MessageLoop::current()->RunAllPending(); |
| 231 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 232 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 233 EXPECT_FALSE(file_util::DirectoryExists(src_dir.path())); |
| 234 |
| 235 // Make sure we've overwritten but not moved the source under the |dest_dir|. |
| 236 EXPECT_TRUE(file_util::DirectoryExists(dest_dir.path())); |
| 237 EXPECT_FALSE(file_util::DirectoryExists( |
| 238 dest_dir.path().Append(src_dir.path().BaseName()))); |
| 239 } |
| 240 |
| 241 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndNew) { |
| 242 ScopedTempDir src_dir; |
| 243 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 244 |
| 245 ScopedTempDir dir; |
| 246 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| 247 FilePath dest_dir_path(dir.path().Append(FILE_PATH_LITERAL("NewDirectory"))); |
| 248 |
| 249 operation()->Move(src_dir.path(), dest_dir_path); |
| 250 MessageLoop::current()->RunAllPending(); |
| 251 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 252 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 253 EXPECT_FALSE(file_util::DirectoryExists(src_dir.path())); |
| 254 EXPECT_TRUE(file_util::DirectoryExists(dest_dir_path)); |
| 255 } |
| 256 |
| 257 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) { |
| 258 ScopedTempDir src_dir; |
| 259 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 260 FilePath child_file; |
| 261 file_util::CreateTemporaryFileInDir(src_dir.path(), &child_file); |
| 262 |
| 263 ScopedTempDir dest_dir; |
| 264 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); |
| 265 |
| 266 operation()->Move(src_dir.path(), dest_dir.path()); |
| 267 MessageLoop::current()->RunAllPending(); |
| 268 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 269 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 270 EXPECT_TRUE(FileExists(dest_dir.path().Append(child_file.BaseName()))); |
| 271 } |
| 272 |
| 184 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) { | 273 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) { |
| 185 FilePath src(base_.path().Append(FILE_PATH_LITERAL("a"))); | 274 FilePath src(base_.path().Append(FILE_PATH_LITERAL("a"))); |
| 186 FilePath dest(base_.path().Append(FILE_PATH_LITERAL("b"))); | 275 FilePath dest(base_.path().Append(FILE_PATH_LITERAL("b"))); |
| 187 operation()->Copy(src, dest); | 276 operation()->Copy(src, dest); |
| 188 MessageLoop::current()->RunAllPending(); | 277 MessageLoop::current()->RunAllPending(); |
| 189 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, mock_dispatcher_->status()); | 278 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, mock_dispatcher_->status()); |
| 190 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 279 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 191 } | 280 } |
| 192 | 281 |
| 193 TEST_F(FileSystemOperationTest, TestCopyFailureContainsPath) { | 282 TEST_F(FileSystemOperationTest, TestCopyFailureContainsPath) { |
| 194 FilePath file_under_base = base_.path().Append(FILE_PATH_LITERAL("b")); | 283 ScopedTempDir src_dir; |
| 195 operation()->Copy(base_.path(), file_under_base); | 284 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 285 FilePath dest_dir_path; |
| 286 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(src_dir.path(), |
| 287 &dest_dir_path)); |
| 288 operation()->Copy(src_dir.path(), dest_dir_path); |
| 196 MessageLoop::current()->RunAllPending(); | 289 MessageLoop::current()->RunAllPending(); |
| 197 EXPECT_EQ(base::PLATFORM_FILE_ERROR_FAILED, mock_dispatcher_->status()); | 290 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, |
| 291 mock_dispatcher_->status()); |
| 198 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 292 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 199 } | 293 } |
| 200 | 294 |
| 201 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) { | 295 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) { |
| 202 // Src exists and is dir. Dest is a file. | 296 // Src exists and is dir. Dest is a file. |
| 203 ScopedTempDir dir; | 297 ScopedTempDir src_dir; |
| 204 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 298 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 299 |
| 300 ScopedTempDir dest_dir; |
| 301 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); |
| 205 FilePath dest_file; | 302 FilePath dest_file; |
| 206 file_util::CreateTemporaryFileInDir(dir.path(), &dest_file); | 303 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file); |
| 207 | 304 |
| 208 operation()->Copy(base_.path(), dest_file); | 305 operation()->Copy(src_dir.path(), dest_file); |
| 209 MessageLoop::current()->RunAllPending(); | 306 MessageLoop::current()->RunAllPending(); |
| 210 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, | 307 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, |
| 211 mock_dispatcher_->status()); | 308 mock_dispatcher_->status()); |
| 212 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 309 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 213 } | 310 } |
| 214 | 311 |
| 312 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestNonEmptyDir) { |
| 313 // Src exists and is a directory. Dest is a non-empty directory. |
| 314 ScopedTempDir src_dir; |
| 315 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 316 |
| 317 ScopedTempDir dest_dir; |
| 318 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); |
| 319 FilePath child_file; |
| 320 file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file); |
| 321 |
| 322 operation()->Copy(src_dir.path(), dest_dir.path()); |
| 323 MessageLoop::current()->RunAllPending(); |
| 324 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, mock_dispatcher_->status()); |
| 325 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 326 } |
| 327 |
| 328 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) { |
| 329 // Src exists and is a file. Dest is a directory. |
| 330 ScopedTempDir src_dir; |
| 331 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 332 FilePath src_file; |
| 333 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file); |
| 334 |
| 335 ScopedTempDir dest_dir; |
| 336 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); |
| 337 |
| 338 operation()->Copy(src_file, dest_dir.path()); |
| 339 MessageLoop::current()->RunAllPending(); |
| 340 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, |
| 341 mock_dispatcher_->status()); |
| 342 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 343 } |
| 344 |
| 215 TEST_F(FileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { | 345 TEST_F(FileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { |
| 216 // Dest. parent path does not exist. | 346 // Dest. parent path does not exist. |
| 217 ScopedTempDir dir; | 347 ScopedTempDir dir; |
| 218 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 348 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| 219 FilePath src_dir = dir.path(); | 349 FilePath src_dir = dir.path(); |
| 220 | 350 |
| 221 FilePath nonexisting(base_.path().Append(FILE_PATH_LITERAL("DontExistDir"))); | 351 FilePath nonexisting(base_.path().Append(FILE_PATH_LITERAL("DontExistDir"))); |
| 222 file_util::EnsureEndsWithSeparator(&nonexisting); | 352 file_util::EnsureEndsWithSeparator(&nonexisting); |
| 223 FilePath nonexisting_file = nonexisting.Append( | 353 FilePath nonexisting_file = nonexisting.Append( |
| 224 FILE_PATH_LITERAL("DontExistFile")); | 354 FILE_PATH_LITERAL("DontExistFile")); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); | 387 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); |
| 258 FilePath dest_file(dest_dir.path().Append(FILE_PATH_LITERAL("NewFile"))); | 388 FilePath dest_file(dest_dir.path().Append(FILE_PATH_LITERAL("NewFile"))); |
| 259 | 389 |
| 260 operation()->Copy(src_file, dest_file); | 390 operation()->Copy(src_file, dest_file); |
| 261 MessageLoop::current()->RunAllPending(); | 391 MessageLoop::current()->RunAllPending(); |
| 262 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); | 392 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 263 EXPECT_TRUE(FileExists(dest_file)); | 393 EXPECT_TRUE(FileExists(dest_file)); |
| 264 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 394 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 265 } | 395 } |
| 266 | 396 |
| 267 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDir) { | 397 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { |
| 268 ScopedTempDir src_dir; | 398 ScopedTempDir src_dir; |
| 269 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); | 399 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 270 | 400 |
| 271 ScopedTempDir dest_dir; | 401 ScopedTempDir dest_dir; |
| 272 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); | 402 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); |
| 273 | 403 |
| 274 operation()->Copy(src_dir.path(), dest_dir.path()); | 404 operation()->Copy(src_dir.path(), dest_dir.path()); |
| 275 MessageLoop::current()->RunAllPending(); | 405 MessageLoop::current()->RunAllPending(); |
| 276 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); | 406 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 277 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 407 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 408 |
| 409 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
| 410 EXPECT_TRUE(file_util::DirectoryExists(dest_dir.path())); |
| 411 EXPECT_FALSE(file_util::DirectoryExists( |
| 412 dest_dir.path().Append(src_dir.path().BaseName()))); |
| 278 } | 413 } |
| 279 | 414 |
| 280 TEST_F(FileSystemOperationTest, TestCopyDestParentExistsSuccess) { | 415 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) { |
| 281 ScopedTempDir src_dir; | 416 ScopedTempDir src_dir; |
| 282 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); | 417 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 283 FilePath src_file; | 418 |
| 284 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file); | 419 ScopedTempDir dir; |
| 420 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| 421 FilePath dest_dir(dir.path().Append(FILE_PATH_LITERAL("NewDirectory"))); |
| 422 |
| 423 operation()->Copy(src_dir.path(), dest_dir); |
| 424 MessageLoop::current()->RunAllPending(); |
| 425 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 426 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 427 EXPECT_TRUE(file_util::DirectoryExists(dest_dir)); |
| 428 } |
| 429 |
| 430 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirRecursive) { |
| 431 ScopedTempDir src_dir; |
| 432 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 433 FilePath child_file; |
| 434 file_util::CreateTemporaryFileInDir(src_dir.path(), &child_file); |
| 285 | 435 |
| 286 ScopedTempDir dest_dir; | 436 ScopedTempDir dest_dir; |
| 287 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); | 437 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); |
| 288 | 438 |
| 289 operation()->Copy(src_file, dest_dir.path()); | 439 operation()->Copy(src_dir.path(), dest_dir.path()); |
| 290 MessageLoop::current()->RunAllPending(); | 440 MessageLoop::current()->RunAllPending(); |
| 291 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); | 441 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 292 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 442 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 293 | 443 EXPECT_TRUE(FileExists(dest_dir.path().Append(child_file.BaseName()))); |
| 294 FilePath src_filename(src_file.BaseName()); | |
| 295 EXPECT_TRUE(FileExists(dest_dir.path().Append(src_filename))); | |
| 296 } | 444 } |
| 297 | 445 |
| 298 TEST_F(FileSystemOperationTest, TestCreateFileFailure) { | 446 TEST_F(FileSystemOperationTest, TestCreateFileFailure) { |
| 299 // Already existing file and exclusive true. | 447 // Already existing file and exclusive true. |
| 300 ScopedTempDir dir; | 448 ScopedTempDir dir; |
| 301 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 449 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| 302 FilePath file; | 450 FilePath file; |
| 303 | 451 |
| 304 file_util::CreateTemporaryFileInDir(dir.path(), &file); | 452 file_util::CreateTemporaryFileInDir(dir.path(), &file); |
| 305 operation()->CreateFile(file, true); | 453 operation()->CreateFile(file, true); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 MessageLoop::current()->RunAllPending(); | 491 MessageLoop::current()->RunAllPending(); |
| 344 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); | 492 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 345 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 493 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 346 } | 494 } |
| 347 | 495 |
| 348 TEST_F(FileSystemOperationTest, | 496 TEST_F(FileSystemOperationTest, |
| 349 TestCreateDirFailureDestParentDoesntExist) { | 497 TestCreateDirFailureDestParentDoesntExist) { |
| 350 // Dest. parent path does not exist. | 498 // Dest. parent path does not exist. |
| 351 FilePath nonexisting(base_.path().Append( | 499 FilePath nonexisting(base_.path().Append( |
| 352 FILE_PATH_LITERAL("DirDoesntExist"))); | 500 FILE_PATH_LITERAL("DirDoesntExist"))); |
| 353 file_util::EnsureEndsWithSeparator(&nonexisting); | |
| 354 FilePath nonexisting_file = nonexisting.Append( | 501 FilePath nonexisting_file = nonexisting.Append( |
| 355 FILE_PATH_LITERAL("FileDoesntExist")); | 502 FILE_PATH_LITERAL("FileDoesntExist")); |
| 356 operation()->CreateDirectory(nonexisting_file, false, false); | 503 operation()->CreateDirectory(nonexisting_file, false, false); |
| 357 MessageLoop::current()->RunAllPending(); | 504 MessageLoop::current()->RunAllPending(); |
| 358 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, mock_dispatcher_->status()); | 505 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, mock_dispatcher_->status()); |
| 359 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 506 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 360 } | 507 } |
| 361 | 508 |
| 362 TEST_F(FileSystemOperationTest, TestCreateDirFailureDirExists) { | 509 TEST_F(FileSystemOperationTest, TestCreateDirFailureDirExists) { |
| 363 // Exclusive and dir existing at path. | 510 // Exclusive and dir existing at path. |
| 364 operation()->CreateDirectory(base_.path(), true, false); | 511 ScopedTempDir src_dir; |
| 512 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); |
| 513 operation()->CreateDirectory(src_dir.path(), true, false); |
| 365 MessageLoop::current()->RunAllPending(); | 514 MessageLoop::current()->RunAllPending(); |
| 366 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, mock_dispatcher_->status()); | 515 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, mock_dispatcher_->status()); |
| 367 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 516 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 368 } | 517 } |
| 369 | 518 |
| 370 TEST_F(FileSystemOperationTest, TestCreateDirFailureFileExists) { | 519 TEST_F(FileSystemOperationTest, TestCreateDirFailureFileExists) { |
| 371 // Exclusive true and file existing at path. | 520 // Exclusive true and file existing at path. |
| 372 ScopedTempDir dir; | 521 ScopedTempDir dir; |
| 373 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 522 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| 374 FilePath file; | 523 FilePath file; |
| 375 file_util::CreateTemporaryFileInDir(dir.path(), &file); | 524 file_util::CreateTemporaryFileInDir(dir.path(), &file); |
| 376 operation()->CreateDirectory(file, true, false); | 525 operation()->CreateDirectory(file, true, false); |
| 377 MessageLoop::current()->RunAllPending(); | 526 MessageLoop::current()->RunAllPending(); |
| 378 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, mock_dispatcher_->status()); | 527 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, mock_dispatcher_->status()); |
| 379 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 528 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 380 } | 529 } |
| 381 | 530 |
| 382 TEST_F(FileSystemOperationTest, TestCreateDirSuccess) { | 531 TEST_F(FileSystemOperationTest, TestCreateDirSuccess) { |
| 383 // Dir exists and exclusive is false. | 532 // Dir exists and exclusive is false. |
| 384 ScopedTempDir dir; | 533 ScopedTempDir dir; |
| 385 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 534 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| 386 operation()->CreateDirectory(dir.path(), false, false); | 535 operation()->CreateDirectory(dir.path(), false, false); |
| 387 MessageLoop::current()->RunAllPending(); | 536 MessageLoop::current()->RunAllPending(); |
| 388 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); | 537 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 389 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 538 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 390 | 539 |
| 391 // Dir doesn't exist. | 540 // Dir doesn't exist. |
| 392 FilePath nonexisting_dir_path(FILE_PATH_LITERAL("nonexistingdir")); | 541 FilePath nonexisting_dir_path(base_.path().Append( |
| 542 FILE_PATH_LITERAL("nonexistingdir"))); |
| 393 operation()->CreateDirectory(nonexisting_dir_path, false, false); | 543 operation()->CreateDirectory(nonexisting_dir_path, false, false); |
| 394 MessageLoop::current()->RunAllPending(); | 544 MessageLoop::current()->RunAllPending(); |
| 395 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); | 545 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 396 EXPECT_TRUE(file_util::DirectoryExists(nonexisting_dir_path)); | 546 EXPECT_TRUE(file_util::DirectoryExists(nonexisting_dir_path)); |
| 397 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 547 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 398 } | 548 } |
| 399 | 549 |
| 400 TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) { | 550 TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) { |
| 401 // Dir doesn't exist. | 551 // Dir doesn't exist. |
| 402 ScopedTempDir dir; | 552 FilePath nonexisting_dir_path(base_.path().Append( |
| 403 ASSERT_TRUE(dir.CreateUniqueTempDir()); | |
| 404 FilePath nonexisting_dir_path(dir.path().Append( | |
| 405 FILE_PATH_LITERAL("nonexistingdir"))); | 553 FILE_PATH_LITERAL("nonexistingdir"))); |
| 406 | 554 |
| 407 operation()->CreateDirectory(nonexisting_dir_path, true, false); | 555 operation()->CreateDirectory(nonexisting_dir_path, true, false); |
| 408 MessageLoop::current()->RunAllPending(); | 556 MessageLoop::current()->RunAllPending(); |
| 409 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); | 557 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 410 EXPECT_TRUE(file_util::DirectoryExists(nonexisting_dir_path)); | 558 EXPECT_TRUE(file_util::DirectoryExists(nonexisting_dir_path)); |
| 411 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 559 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 412 } | 560 } |
| 413 | 561 |
| 414 TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) { | 562 TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 } | 658 } |
| 511 } | 659 } |
| 512 } | 660 } |
| 513 | 661 |
| 514 TEST_F(FileSystemOperationTest, TestRemoveFailure) { | 662 TEST_F(FileSystemOperationTest, TestRemoveFailure) { |
| 515 // Path doesn't exist. | 663 // Path doesn't exist. |
| 516 FilePath nonexisting(base_.path().Append( | 664 FilePath nonexisting(base_.path().Append( |
| 517 FILE_PATH_LITERAL("NonExistingDir"))); | 665 FILE_PATH_LITERAL("NonExistingDir"))); |
| 518 file_util::EnsureEndsWithSeparator(&nonexisting); | 666 file_util::EnsureEndsWithSeparator(&nonexisting); |
| 519 | 667 |
| 520 operation()->Remove(nonexisting); | 668 operation()->Remove(nonexisting, false /* recursive */); |
| 521 MessageLoop::current()->RunAllPending(); | 669 MessageLoop::current()->RunAllPending(); |
| 522 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, mock_dispatcher_->status()); | 670 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, mock_dispatcher_->status()); |
| 523 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 671 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 524 | 672 |
| 525 // By spec recursive is always false. Non-empty dir should fail. | 673 // It's an error to try to remove a non-empty directory if recursive flag |
| 674 // is false. |
| 526 // parent_dir | 675 // parent_dir |
| 527 // | | | 676 // | | |
| 528 // child_dir child_file | 677 // child_dir child_file |
| 529 // Verify deleting parent_dir. | 678 // Verify deleting parent_dir. |
| 530 ScopedTempDir parent_dir; | 679 ScopedTempDir parent_dir; |
| 531 ASSERT_TRUE(parent_dir.CreateUniqueTempDir()); | 680 ASSERT_TRUE(parent_dir.CreateUniqueTempDir()); |
| 532 FilePath child_file; | 681 FilePath child_file; |
| 533 file_util::CreateTemporaryFileInDir(parent_dir.path(), &child_file); | 682 file_util::CreateTemporaryFileInDir(parent_dir.path(), &child_file); |
| 534 FilePath child_dir; | 683 FilePath child_dir; |
| 535 ASSERT_TRUE(file_util::CreateTemporaryDirInDir( | 684 ASSERT_TRUE(file_util::CreateTemporaryDirInDir( |
| 536 parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir)); | 685 parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir)); |
| 537 | 686 |
| 538 operation()->Remove(parent_dir.path()); | 687 operation()->Remove(parent_dir.path(), false /* recursive */); |
| 539 MessageLoop::current()->RunAllPending(); | 688 MessageLoop::current()->RunAllPending(); |
| 540 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, | 689 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, |
| 541 mock_dispatcher_->status()); | 690 mock_dispatcher_->status()); |
| 542 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 691 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 543 } | 692 } |
| 544 | 693 |
| 545 TEST_F(FileSystemOperationTest, TestRemoveSuccess) { | 694 TEST_F(FileSystemOperationTest, TestRemoveSuccess) { |
| 546 ScopedTempDir empty_dir; | 695 ScopedTempDir empty_dir; |
| 547 ASSERT_TRUE(empty_dir.CreateUniqueTempDir()); | 696 ASSERT_TRUE(empty_dir.CreateUniqueTempDir()); |
| 548 EXPECT_TRUE(file_util::DirectoryExists(empty_dir.path())); | 697 EXPECT_TRUE(file_util::DirectoryExists(empty_dir.path())); |
| 549 | 698 |
| 550 operation()->Remove(empty_dir.path()); | 699 operation()->Remove(empty_dir.path(), false /* recursive */); |
| 551 MessageLoop::current()->RunAllPending(); | 700 MessageLoop::current()->RunAllPending(); |
| 552 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); | 701 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 553 EXPECT_FALSE(file_util::DirectoryExists(empty_dir.path())); | 702 EXPECT_FALSE(file_util::DirectoryExists(empty_dir.path())); |
| 554 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); | 703 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 704 |
| 705 // Removing a non-empty directory with recursive flag == true should be ok. |
| 706 // parent_dir |
| 707 // | | |
| 708 // child_dir child_file |
| 709 // Verify deleting parent_dir. |
| 710 ScopedTempDir parent_dir; |
| 711 ASSERT_TRUE(parent_dir.CreateUniqueTempDir()); |
| 712 FilePath child_file; |
| 713 file_util::CreateTemporaryFileInDir(parent_dir.path(), &child_file); |
| 714 FilePath child_dir; |
| 715 ASSERT_TRUE(file_util::CreateTemporaryDirInDir( |
| 716 parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir)); |
| 717 |
| 718 operation()->Remove(parent_dir.path(), true /* recursive */); |
| 719 MessageLoop::current()->RunAllPending(); |
| 720 EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status()); |
| 721 EXPECT_FALSE(file_util::DirectoryExists(parent_dir.path())); |
| 722 EXPECT_EQ(request_id_, mock_dispatcher_->request_id()); |
| 555 } | 723 } |
| OLD | NEW |