| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/fileapi/local_file_system_operation.h" | 5 #include "webkit/browser/fileapi/file_system_operation_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 38 const int kFileOperationStatusNotSet = 1; | 38 const int kFileOperationStatusNotSet = 1; |
| 39 | 39 |
| 40 void AssertFileErrorEq(const tracked_objects::Location& from_here, | 40 void AssertFileErrorEq(const tracked_objects::Location& from_here, |
| 41 base::PlatformFileError expected, | 41 base::PlatformFileError expected, |
| 42 base::PlatformFileError actual) { | 42 base::PlatformFileError actual) { |
| 43 ASSERT_EQ(expected, actual) << from_here.ToString(); | 43 ASSERT_EQ(expected, actual) << from_here.ToString(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 } // namespace (anonymous) | 46 } // namespace (anonymous) |
| 47 | 47 |
| 48 // Test class for LocalFileSystemOperation. | 48 // Test class for FileSystemOperationImpl. |
| 49 class LocalFileSystemOperationTest | 49 class FileSystemOperationImplTest |
| 50 : public testing::Test, | 50 : public testing::Test, |
| 51 public base::SupportsWeakPtr<LocalFileSystemOperationTest> { | 51 public base::SupportsWeakPtr<FileSystemOperationImplTest> { |
| 52 public: | 52 public: |
| 53 LocalFileSystemOperationTest() | 53 FileSystemOperationImplTest() |
| 54 : status_(kFileOperationStatusNotSet) {} | 54 : status_(kFileOperationStatusNotSet) {} |
| 55 | 55 |
| 56 protected: | 56 protected: |
| 57 virtual void SetUp() OVERRIDE { | 57 virtual void SetUp() OVERRIDE { |
| 58 EXPECT_TRUE(base_.CreateUniqueTempDir()); | 58 EXPECT_TRUE(base_.CreateUniqueTempDir()); |
| 59 change_observers_ = MockFileChangeObserver::CreateList(&change_observer_); | 59 change_observers_ = MockFileChangeObserver::CreateList(&change_observer_); |
| 60 | 60 |
| 61 base::FilePath base_dir = base_.path().AppendASCII("filesystem"); | 61 base::FilePath base_dir = base_.path().AppendASCII("filesystem"); |
| 62 quota_manager_ = | 62 quota_manager_ = |
| 63 new quota::MockQuotaManager(false /* is_incognito */, | 63 new quota::MockQuotaManager(false /* is_incognito */, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 158 } |
| 159 | 159 |
| 160 int64 GetFileSize(const std::string& path) { | 160 int64 GetFileSize(const std::string& path) { |
| 161 base::PlatformFileInfo info; | 161 base::PlatformFileInfo info; |
| 162 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(path), &info)); | 162 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(path), &info)); |
| 163 return info.size; | 163 return info.size; |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Callbacks for recording test results. | 166 // Callbacks for recording test results. |
| 167 FileSystemOperation::StatusCallback RecordStatusCallback() { | 167 FileSystemOperation::StatusCallback RecordStatusCallback() { |
| 168 return base::Bind(&LocalFileSystemOperationTest::DidFinish, AsWeakPtr()); | 168 return base::Bind(&FileSystemOperationImplTest::DidFinish, AsWeakPtr()); |
| 169 } | 169 } |
| 170 | 170 |
| 171 FileSystemOperation::ReadDirectoryCallback | 171 FileSystemOperation::ReadDirectoryCallback |
| 172 RecordReadDirectoryCallback() { | 172 RecordReadDirectoryCallback() { |
| 173 return base::Bind(&LocalFileSystemOperationTest::DidReadDirectory, | 173 return base::Bind(&FileSystemOperationImplTest::DidReadDirectory, |
| 174 AsWeakPtr()); | 174 AsWeakPtr()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 FileSystemOperation::GetMetadataCallback RecordMetadataCallback() { | 177 FileSystemOperation::GetMetadataCallback RecordMetadataCallback() { |
| 178 return base::Bind(&LocalFileSystemOperationTest::DidGetMetadata, | 178 return base::Bind(&FileSystemOperationImplTest::DidGetMetadata, |
| 179 AsWeakPtr()); | 179 AsWeakPtr()); |
| 180 } | 180 } |
| 181 | 181 |
| 182 FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback() { | 182 FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback() { |
| 183 return base::Bind(&LocalFileSystemOperationTest::DidCreateSnapshotFile, | 183 return base::Bind(&FileSystemOperationImplTest::DidCreateSnapshotFile, |
| 184 AsWeakPtr()); | 184 AsWeakPtr()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void DidFinish(base::PlatformFileError status) { | 187 void DidFinish(base::PlatformFileError status) { |
| 188 status_ = status; | 188 status_ = status; |
| 189 } | 189 } |
| 190 | 190 |
| 191 void DidReadDirectory( | 191 void DidReadDirectory( |
| 192 base::PlatformFileError status, | 192 base::PlatformFileError status, |
| 193 const std::vector<DirectoryEntry>& entries, | 193 const std::vector<DirectoryEntry>& entries, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // For post-operation status. | 280 // For post-operation status. |
| 281 int status_; | 281 int status_; |
| 282 base::PlatformFileInfo info_; | 282 base::PlatformFileInfo info_; |
| 283 base::FilePath path_; | 283 base::FilePath path_; |
| 284 std::vector<DirectoryEntry> entries_; | 284 std::vector<DirectoryEntry> entries_; |
| 285 scoped_refptr<ShareableFileReference> shareable_file_ref_; | 285 scoped_refptr<ShareableFileReference> shareable_file_ref_; |
| 286 | 286 |
| 287 MockFileChangeObserver change_observer_; | 287 MockFileChangeObserver change_observer_; |
| 288 ChangeObserverList change_observers_; | 288 ChangeObserverList change_observers_; |
| 289 | 289 |
| 290 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperationTest); | 290 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest); |
| 291 }; | 291 }; |
| 292 | 292 |
| 293 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcDoesntExist) { | 293 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) { |
| 294 change_observer()->ResetCount(); | 294 change_observer()->ResetCount(); |
| 295 operation_runner()->Move(URLForPath("a"), URLForPath("b"), | 295 operation_runner()->Move(URLForPath("a"), URLForPath("b"), |
| 296 RecordStatusCallback()); | 296 RecordStatusCallback()); |
| 297 base::MessageLoop::current()->RunUntilIdle(); | 297 base::MessageLoop::current()->RunUntilIdle(); |
| 298 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 298 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 299 EXPECT_TRUE(change_observer()->HasNoChange()); | 299 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 300 } | 300 } |
| 301 | 301 |
| 302 TEST_F(LocalFileSystemOperationTest, TestMoveFailureContainsPath) { | 302 TEST_F(FileSystemOperationImplTest, TestMoveFailureContainsPath) { |
| 303 FileSystemURL src_dir(CreateDirectory("src")); | 303 FileSystemURL src_dir(CreateDirectory("src")); |
| 304 FileSystemURL dest_dir(CreateDirectory("src/dest")); | 304 FileSystemURL dest_dir(CreateDirectory("src/dest")); |
| 305 | 305 |
| 306 operation_runner()->Move(src_dir, dest_dir, RecordStatusCallback()); | 306 operation_runner()->Move(src_dir, dest_dir, RecordStatusCallback()); |
| 307 base::MessageLoop::current()->RunUntilIdle(); | 307 base::MessageLoop::current()->RunUntilIdle(); |
| 308 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 308 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 309 EXPECT_TRUE(change_observer()->HasNoChange()); | 309 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 310 } | 310 } |
| 311 | 311 |
| 312 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) { | 312 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDirExistsDestFile) { |
| 313 // Src exists and is dir. Dest is a file. | 313 // Src exists and is dir. Dest is a file. |
| 314 FileSystemURL src_dir(CreateDirectory("src")); | 314 FileSystemURL src_dir(CreateDirectory("src")); |
| 315 FileSystemURL dest_dir(CreateDirectory("dest")); | 315 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 316 FileSystemURL dest_file(CreateFile("dest/file")); | 316 FileSystemURL dest_file(CreateFile("dest/file")); |
| 317 | 317 |
| 318 operation_runner()->Move(src_dir, dest_file, RecordStatusCallback()); | 318 operation_runner()->Move(src_dir, dest_file, RecordStatusCallback()); |
| 319 base::MessageLoop::current()->RunUntilIdle(); | 319 base::MessageLoop::current()->RunUntilIdle(); |
| 320 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 320 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 321 EXPECT_TRUE(change_observer()->HasNoChange()); | 321 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 322 } | 322 } |
| 323 | 323 |
| 324 TEST_F(LocalFileSystemOperationTest, | 324 TEST_F(FileSystemOperationImplTest, |
| 325 TestMoveFailureSrcFileExistsDestNonEmptyDir) { | 325 TestMoveFailureSrcFileExistsDestNonEmptyDir) { |
| 326 // Src exists and is a directory. Dest is a non-empty directory. | 326 // Src exists and is a directory. Dest is a non-empty directory. |
| 327 FileSystemURL src_dir(CreateDirectory("src")); | 327 FileSystemURL src_dir(CreateDirectory("src")); |
| 328 FileSystemURL dest_dir(CreateDirectory("dest")); | 328 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 329 FileSystemURL dest_file(CreateFile("dest/file")); | 329 FileSystemURL dest_file(CreateFile("dest/file")); |
| 330 | 330 |
| 331 operation_runner()->Move(src_dir, dest_dir, RecordStatusCallback()); | 331 operation_runner()->Move(src_dir, dest_dir, RecordStatusCallback()); |
| 332 base::MessageLoop::current()->RunUntilIdle(); | 332 base::MessageLoop::current()->RunUntilIdle(); |
| 333 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); | 333 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); |
| 334 EXPECT_TRUE(change_observer()->HasNoChange()); | 334 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 335 } | 335 } |
| 336 | 336 |
| 337 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) { | 337 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcFileExistsDestDir) { |
| 338 // Src exists and is a file. Dest is a directory. | 338 // Src exists and is a file. Dest is a directory. |
| 339 FileSystemURL src_dir(CreateDirectory("src")); | 339 FileSystemURL src_dir(CreateDirectory("src")); |
| 340 FileSystemURL src_file(CreateFile("src/file")); | 340 FileSystemURL src_file(CreateFile("src/file")); |
| 341 FileSystemURL dest_dir(CreateDirectory("dest")); | 341 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 342 | 342 |
| 343 operation_runner()->Move(src_file, dest_dir, RecordStatusCallback()); | 343 operation_runner()->Move(src_file, dest_dir, RecordStatusCallback()); |
| 344 base::MessageLoop::current()->RunUntilIdle(); | 344 base::MessageLoop::current()->RunUntilIdle(); |
| 345 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 345 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 346 EXPECT_TRUE(change_observer()->HasNoChange()); | 346 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 347 } | 347 } |
| 348 | 348 |
| 349 TEST_F(LocalFileSystemOperationTest, TestMoveFailureDestParentDoesntExist) { | 349 TEST_F(FileSystemOperationImplTest, TestMoveFailureDestParentDoesntExist) { |
| 350 // Dest. parent path does not exist. | 350 // Dest. parent path does not exist. |
| 351 FileSystemURL src_dir(CreateDirectory("src")); | 351 FileSystemURL src_dir(CreateDirectory("src")); |
| 352 operation_runner()->Move(src_dir, URLForPath("nonexistent/deset"), | 352 operation_runner()->Move(src_dir, URLForPath("nonexistent/deset"), |
| 353 RecordStatusCallback()); | 353 RecordStatusCallback()); |
| 354 base::MessageLoop::current()->RunUntilIdle(); | 354 base::MessageLoop::current()->RunUntilIdle(); |
| 355 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 355 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 356 EXPECT_TRUE(change_observer()->HasNoChange()); | 356 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 357 } | 357 } |
| 358 | 358 |
| 359 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { | 359 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) { |
| 360 FileSystemURL src_file(CreateFile("src")); | 360 FileSystemURL src_file(CreateFile("src")); |
| 361 FileSystemURL dest_file(CreateFile("dest")); | 361 FileSystemURL dest_file(CreateFile("dest")); |
| 362 | 362 |
| 363 operation_runner()->Move(src_file, dest_file, RecordStatusCallback()); | 363 operation_runner()->Move(src_file, dest_file, RecordStatusCallback()); |
| 364 base::MessageLoop::current()->RunUntilIdle(); | 364 base::MessageLoop::current()->RunUntilIdle(); |
| 365 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 365 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 366 EXPECT_TRUE(FileExists("dest")); | 366 EXPECT_TRUE(FileExists("dest")); |
| 367 | 367 |
| 368 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 368 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| 369 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 369 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
| 370 EXPECT_TRUE(change_observer()->HasNoChange()); | 370 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 371 | 371 |
| 372 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 372 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 373 } | 373 } |
| 374 | 374 |
| 375 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { | 375 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndNew) { |
| 376 FileSystemURL src_file(CreateFile("src")); | 376 FileSystemURL src_file(CreateFile("src")); |
| 377 | 377 |
| 378 operation_runner()->Move(src_file, URLForPath("new"), RecordStatusCallback()); | 378 operation_runner()->Move(src_file, URLForPath("new"), RecordStatusCallback()); |
| 379 base::MessageLoop::current()->RunUntilIdle(); | 379 base::MessageLoop::current()->RunUntilIdle(); |
| 380 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 380 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 381 EXPECT_TRUE(FileExists("new")); | 381 EXPECT_TRUE(FileExists("new")); |
| 382 | 382 |
| 383 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 383 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
| 384 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 384 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
| 385 EXPECT_TRUE(change_observer()->HasNoChange()); | 385 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 386 } | 386 } |
| 387 | 387 |
| 388 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) { | 388 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndOverwrite) { |
| 389 FileSystemURL src_dir(CreateDirectory("src")); | 389 FileSystemURL src_dir(CreateDirectory("src")); |
| 390 FileSystemURL dest_dir(CreateDirectory("dest")); | 390 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 391 | 391 |
| 392 operation_runner()->Move(src_dir, dest_dir, RecordStatusCallback()); | 392 operation_runner()->Move(src_dir, dest_dir, RecordStatusCallback()); |
| 393 base::MessageLoop::current()->RunUntilIdle(); | 393 base::MessageLoop::current()->RunUntilIdle(); |
| 394 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 394 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 395 EXPECT_FALSE(DirectoryExists("src")); | 395 EXPECT_FALSE(DirectoryExists("src")); |
| 396 | 396 |
| 397 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 397 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 398 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); | 398 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); |
| 399 EXPECT_TRUE(change_observer()->HasNoChange()); | 399 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 400 | 400 |
| 401 // Make sure we've overwritten but not moved the source under the |dest_dir|. | 401 // Make sure we've overwritten but not moved the source under the |dest_dir|. |
| 402 EXPECT_TRUE(DirectoryExists("dest")); | 402 EXPECT_TRUE(DirectoryExists("dest")); |
| 403 EXPECT_FALSE(DirectoryExists("dest/src")); | 403 EXPECT_FALSE(DirectoryExists("dest/src")); |
| 404 } | 404 } |
| 405 | 405 |
| 406 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirAndNew) { | 406 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndNew) { |
| 407 FileSystemURL src_dir(CreateDirectory("src")); | 407 FileSystemURL src_dir(CreateDirectory("src")); |
| 408 FileSystemURL dest_dir(CreateDirectory("dest")); | 408 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 409 | 409 |
| 410 operation_runner()->Move(src_dir, URLForPath("dest/new"), | 410 operation_runner()->Move(src_dir, URLForPath("dest/new"), |
| 411 RecordStatusCallback()); | 411 RecordStatusCallback()); |
| 412 base::MessageLoop::current()->RunUntilIdle(); | 412 base::MessageLoop::current()->RunUntilIdle(); |
| 413 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 413 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 414 EXPECT_FALSE(DirectoryExists("src")); | 414 EXPECT_FALSE(DirectoryExists("src")); |
| 415 EXPECT_TRUE(DirectoryExists("dest/new")); | 415 EXPECT_TRUE(DirectoryExists("dest/new")); |
| 416 | 416 |
| 417 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 417 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
| 418 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 418 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 419 EXPECT_TRUE(change_observer()->HasNoChange()); | 419 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 420 } | 420 } |
| 421 | 421 |
| 422 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirRecursive) { | 422 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) { |
| 423 FileSystemURL src_dir(CreateDirectory("src")); | 423 FileSystemURL src_dir(CreateDirectory("src")); |
| 424 CreateDirectory("src/dir"); | 424 CreateDirectory("src/dir"); |
| 425 CreateFile("src/dir/sub"); | 425 CreateFile("src/dir/sub"); |
| 426 | 426 |
| 427 FileSystemURL dest_dir(CreateDirectory("dest")); | 427 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 428 | 428 |
| 429 operation_runner()->Move(src_dir, dest_dir, RecordStatusCallback()); | 429 operation_runner()->Move(src_dir, dest_dir, RecordStatusCallback()); |
| 430 base::MessageLoop::current()->RunUntilIdle(); | 430 base::MessageLoop::current()->RunUntilIdle(); |
| 431 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 431 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 432 EXPECT_TRUE(DirectoryExists("dest/dir")); | 432 EXPECT_TRUE(DirectoryExists("dest/dir")); |
| 433 EXPECT_TRUE(FileExists("dest/dir/sub")); | 433 EXPECT_TRUE(FileExists("dest/dir/sub")); |
| 434 | 434 |
| 435 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count()); | 435 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count()); |
| 436 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 436 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
| 437 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 437 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
| 438 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 438 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
| 439 EXPECT_TRUE(change_observer()->HasNoChange()); | 439 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 440 } | 440 } |
| 441 | 441 |
| 442 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcDoesntExist) { | 442 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) { |
| 443 operation_runner()->Copy(URLForPath("a"), URLForPath("b"), | 443 operation_runner()->Copy(URLForPath("a"), URLForPath("b"), |
| 444 RecordStatusCallback()); | 444 RecordStatusCallback()); |
| 445 base::MessageLoop::current()->RunUntilIdle(); | 445 base::MessageLoop::current()->RunUntilIdle(); |
| 446 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 446 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 447 EXPECT_TRUE(change_observer()->HasNoChange()); | 447 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 448 } | 448 } |
| 449 | 449 |
| 450 TEST_F(LocalFileSystemOperationTest, TestCopyFailureContainsPath) { | 450 TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) { |
| 451 FileSystemURL src_dir(CreateDirectory("src")); | 451 FileSystemURL src_dir(CreateDirectory("src")); |
| 452 FileSystemURL dest_dir(CreateDirectory("src/dir")); | 452 FileSystemURL dest_dir(CreateDirectory("src/dir")); |
| 453 | 453 |
| 454 operation_runner()->Copy(src_dir, dest_dir, RecordStatusCallback()); | 454 operation_runner()->Copy(src_dir, dest_dir, RecordStatusCallback()); |
| 455 base::MessageLoop::current()->RunUntilIdle(); | 455 base::MessageLoop::current()->RunUntilIdle(); |
| 456 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 456 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 457 EXPECT_TRUE(change_observer()->HasNoChange()); | 457 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 458 } | 458 } |
| 459 | 459 |
| 460 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) { | 460 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) { |
| 461 // Src exists and is dir. Dest is a file. | 461 // Src exists and is dir. Dest is a file. |
| 462 FileSystemURL src_dir(CreateDirectory("src")); | 462 FileSystemURL src_dir(CreateDirectory("src")); |
| 463 FileSystemURL dest_dir(CreateDirectory("dest")); | 463 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 464 FileSystemURL dest_file(CreateFile("dest/file")); | 464 FileSystemURL dest_file(CreateFile("dest/file")); |
| 465 | 465 |
| 466 operation_runner()->Copy(src_dir, dest_file, RecordStatusCallback()); | 466 operation_runner()->Copy(src_dir, dest_file, RecordStatusCallback()); |
| 467 base::MessageLoop::current()->RunUntilIdle(); | 467 base::MessageLoop::current()->RunUntilIdle(); |
| 468 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 468 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 469 EXPECT_TRUE(change_observer()->HasNoChange()); | 469 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 470 } | 470 } |
| 471 | 471 |
| 472 TEST_F(LocalFileSystemOperationTest, | 472 TEST_F(FileSystemOperationImplTest, |
| 473 TestCopyFailureSrcFileExistsDestNonEmptyDir) { | 473 TestCopyFailureSrcFileExistsDestNonEmptyDir) { |
| 474 // Src exists and is a directory. Dest is a non-empty directory. | 474 // Src exists and is a directory. Dest is a non-empty directory. |
| 475 FileSystemURL src_dir(CreateDirectory("src")); | 475 FileSystemURL src_dir(CreateDirectory("src")); |
| 476 FileSystemURL dest_dir(CreateDirectory("dest")); | 476 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 477 FileSystemURL dest_file(CreateFile("dest/file")); | 477 FileSystemURL dest_file(CreateFile("dest/file")); |
| 478 | 478 |
| 479 operation_runner()->Copy(src_dir, dest_dir, RecordStatusCallback()); | 479 operation_runner()->Copy(src_dir, dest_dir, RecordStatusCallback()); |
| 480 base::MessageLoop::current()->RunUntilIdle(); | 480 base::MessageLoop::current()->RunUntilIdle(); |
| 481 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); | 481 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); |
| 482 EXPECT_TRUE(change_observer()->HasNoChange()); | 482 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 483 } | 483 } |
| 484 | 484 |
| 485 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) { | 485 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { |
| 486 // Src exists and is a file. Dest is a directory. | 486 // Src exists and is a file. Dest is a directory. |
| 487 FileSystemURL src_file(CreateFile("src")); | 487 FileSystemURL src_file(CreateFile("src")); |
| 488 FileSystemURL dest_dir(CreateDirectory("dest")); | 488 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 489 | 489 |
| 490 operation_runner()->Copy(src_file, dest_dir, RecordStatusCallback()); | 490 operation_runner()->Copy(src_file, dest_dir, RecordStatusCallback()); |
| 491 base::MessageLoop::current()->RunUntilIdle(); | 491 base::MessageLoop::current()->RunUntilIdle(); |
| 492 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 492 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 493 EXPECT_TRUE(change_observer()->HasNoChange()); | 493 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 494 } | 494 } |
| 495 | 495 |
| 496 TEST_F(LocalFileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { | 496 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { |
| 497 // Dest. parent path does not exist. | 497 // Dest. parent path does not exist. |
| 498 FileSystemURL src_dir(CreateDirectory("src")); | 498 FileSystemURL src_dir(CreateDirectory("src")); |
| 499 | 499 |
| 500 operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), | 500 operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), |
| 501 RecordStatusCallback()); | 501 RecordStatusCallback()); |
| 502 base::MessageLoop::current()->RunUntilIdle(); | 502 base::MessageLoop::current()->RunUntilIdle(); |
| 503 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 503 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 504 EXPECT_TRUE(change_observer()->HasNoChange()); | 504 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 505 } | 505 } |
| 506 | 506 |
| 507 TEST_F(LocalFileSystemOperationTest, TestCopyFailureByQuota) { | 507 TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) { |
| 508 FileSystemURL src_dir(CreateDirectory("src")); | 508 FileSystemURL src_dir(CreateDirectory("src")); |
| 509 FileSystemURL src_file(CreateFile("src/file")); | 509 FileSystemURL src_file(CreateFile("src/file")); |
| 510 FileSystemURL dest_dir(CreateDirectory("dest")); | 510 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 511 operation_runner()->Truncate(src_file, 6, RecordStatusCallback()); | 511 operation_runner()->Truncate(src_file, 6, RecordStatusCallback()); |
| 512 base::MessageLoop::current()->RunUntilIdle(); | 512 base::MessageLoop::current()->RunUntilIdle(); |
| 513 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 513 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 514 EXPECT_EQ(6, GetFileSize("src/file")); | 514 EXPECT_EQ(6, GetFileSize("src/file")); |
| 515 | 515 |
| 516 FileSystemURL dest_file(URLForPath("dest/file")); | 516 FileSystemURL dest_file(URLForPath("dest/file")); |
| 517 int64 dest_path_cost = ComputePathCost(dest_file); | 517 int64 dest_path_cost = ComputePathCost(dest_file); |
| 518 GrantQuotaForCurrentUsage(); | 518 GrantQuotaForCurrentUsage(); |
| 519 AddQuota(6 + dest_path_cost - 1); | 519 AddQuota(6 + dest_path_cost - 1); |
| 520 | 520 |
| 521 operation_runner()->Copy(src_file, dest_file, RecordStatusCallback()); | 521 operation_runner()->Copy(src_file, dest_file, RecordStatusCallback()); |
| 522 base::MessageLoop::current()->RunUntilIdle(); | 522 base::MessageLoop::current()->RunUntilIdle(); |
| 523 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 523 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
| 524 EXPECT_FALSE(FileExists("dest/file")); | 524 EXPECT_FALSE(FileExists("dest/file")); |
| 525 } | 525 } |
| 526 | 526 |
| 527 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) { | 527 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) { |
| 528 FileSystemURL src_file(CreateFile("src")); | 528 FileSystemURL src_file(CreateFile("src")); |
| 529 FileSystemURL dest_file(CreateFile("dest")); | 529 FileSystemURL dest_file(CreateFile("dest")); |
| 530 | 530 |
| 531 operation_runner()->Copy(src_file, dest_file, RecordStatusCallback()); | 531 operation_runner()->Copy(src_file, dest_file, RecordStatusCallback()); |
| 532 base::MessageLoop::current()->RunUntilIdle(); | 532 base::MessageLoop::current()->RunUntilIdle(); |
| 533 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 533 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 534 EXPECT_TRUE(FileExists("dest")); | 534 EXPECT_TRUE(FileExists("dest")); |
| 535 EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count()); | 535 EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count()); |
| 536 | 536 |
| 537 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 537 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| 538 EXPECT_TRUE(change_observer()->HasNoChange()); | 538 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 539 } | 539 } |
| 540 | 540 |
| 541 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndNew) { | 541 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { |
| 542 FileSystemURL src_file(CreateFile("src")); | 542 FileSystemURL src_file(CreateFile("src")); |
| 543 | 543 |
| 544 operation_runner()->Copy(src_file, URLForPath("new"), | 544 operation_runner()->Copy(src_file, URLForPath("new"), |
| 545 RecordStatusCallback()); | 545 RecordStatusCallback()); |
| 546 base::MessageLoop::current()->RunUntilIdle(); | 546 base::MessageLoop::current()->RunUntilIdle(); |
| 547 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 547 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 548 EXPECT_TRUE(FileExists("new")); | 548 EXPECT_TRUE(FileExists("new")); |
| 549 EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count()); | 549 EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count()); |
| 550 | 550 |
| 551 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 551 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
| 552 EXPECT_TRUE(change_observer()->HasNoChange()); | 552 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 553 } | 553 } |
| 554 | 554 |
| 555 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { | 555 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { |
| 556 FileSystemURL src_dir(CreateDirectory("src")); | 556 FileSystemURL src_dir(CreateDirectory("src")); |
| 557 FileSystemURL dest_dir(CreateDirectory("dest")); | 557 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 558 | 558 |
| 559 operation_runner()->Copy(src_dir, dest_dir, RecordStatusCallback()); | 559 operation_runner()->Copy(src_dir, dest_dir, RecordStatusCallback()); |
| 560 base::MessageLoop::current()->RunUntilIdle(); | 560 base::MessageLoop::current()->RunUntilIdle(); |
| 561 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 561 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 562 | 562 |
| 563 // Make sure we've overwritten but not copied the source under the |dest_dir|. | 563 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
| 564 EXPECT_TRUE(DirectoryExists("dest")); | 564 EXPECT_TRUE(DirectoryExists("dest")); |
| 565 EXPECT_FALSE(DirectoryExists("dest/src")); | 565 EXPECT_FALSE(DirectoryExists("dest/src")); |
| 566 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); | 566 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); |
| 567 | 567 |
| 568 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 568 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
| 569 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 569 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 570 EXPECT_TRUE(change_observer()->HasNoChange()); | 570 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 571 } | 571 } |
| 572 | 572 |
| 573 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndNew) { | 573 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { |
| 574 FileSystemURL src_dir(CreateDirectory("src")); | 574 FileSystemURL src_dir(CreateDirectory("src")); |
| 575 FileSystemURL dest_dir_new(URLForPath("dest")); | 575 FileSystemURL dest_dir_new(URLForPath("dest")); |
| 576 | 576 |
| 577 operation_runner()->Copy(src_dir, dest_dir_new, RecordStatusCallback()); | 577 operation_runner()->Copy(src_dir, dest_dir_new, RecordStatusCallback()); |
| 578 base::MessageLoop::current()->RunUntilIdle(); | 578 base::MessageLoop::current()->RunUntilIdle(); |
| 579 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 579 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 580 EXPECT_TRUE(DirectoryExists("dest")); | 580 EXPECT_TRUE(DirectoryExists("dest")); |
| 581 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 2); | 581 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 2); |
| 582 | 582 |
| 583 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 583 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 584 EXPECT_TRUE(change_observer()->HasNoChange()); | 584 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 585 } | 585 } |
| 586 | 586 |
| 587 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirRecursive) { | 587 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) { |
| 588 FileSystemURL src_dir(CreateDirectory("src")); | 588 FileSystemURL src_dir(CreateDirectory("src")); |
| 589 CreateDirectory("src/dir"); | 589 CreateDirectory("src/dir"); |
| 590 CreateFile("src/dir/sub"); | 590 CreateFile("src/dir/sub"); |
| 591 | 591 |
| 592 FileSystemURL dest_dir(CreateDirectory("dest")); | 592 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 593 | 593 |
| 594 operation_runner()->Copy(src_dir, dest_dir, RecordStatusCallback()); | 594 operation_runner()->Copy(src_dir, dest_dir, RecordStatusCallback()); |
| 595 base::MessageLoop::current()->RunUntilIdle(); | 595 base::MessageLoop::current()->RunUntilIdle(); |
| 596 | 596 |
| 597 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 597 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 598 EXPECT_TRUE(DirectoryExists("dest/dir")); | 598 EXPECT_TRUE(DirectoryExists("dest/dir")); |
| 599 EXPECT_TRUE(FileExists("dest/dir/sub")); | 599 EXPECT_TRUE(FileExists("dest/dir/sub")); |
| 600 | 600 |
| 601 // For recursive copy we may record multiple read access. | 601 // For recursive copy we may record multiple read access. |
| 602 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); | 602 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); |
| 603 | 603 |
| 604 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 604 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
| 605 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 605 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
| 606 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 606 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
| 607 EXPECT_TRUE(change_observer()->HasNoChange()); | 607 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 608 } | 608 } |
| 609 | 609 |
| 610 TEST_F(LocalFileSystemOperationTest, TestCopyInForeignFileSuccess) { | 610 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileSuccess) { |
| 611 base::FilePath src_local_disk_file_path; | 611 base::FilePath src_local_disk_file_path; |
| 612 file_util::CreateTemporaryFile(&src_local_disk_file_path); | 612 file_util::CreateTemporaryFile(&src_local_disk_file_path); |
| 613 const char test_data[] = "foo"; | 613 const char test_data[] = "foo"; |
| 614 int data_size = ARRAYSIZE_UNSAFE(test_data); | 614 int data_size = ARRAYSIZE_UNSAFE(test_data); |
| 615 file_util::WriteFile(src_local_disk_file_path, test_data, data_size); | 615 file_util::WriteFile(src_local_disk_file_path, test_data, data_size); |
| 616 | 616 |
| 617 FileSystemURL dest_dir(CreateDirectory("dest")); | 617 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 618 | 618 |
| 619 int64 before_usage; | 619 int64 before_usage; |
| 620 GetUsageAndQuota(&before_usage, NULL); | 620 GetUsageAndQuota(&before_usage, NULL); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 633 EXPECT_GT(after_usage, before_usage); | 633 EXPECT_GT(after_usage, before_usage); |
| 634 | 634 |
| 635 // Compare contents of src and copied file. | 635 // Compare contents of src and copied file. |
| 636 char buffer[100]; | 636 char buffer[100]; |
| 637 EXPECT_EQ(data_size, file_util::ReadFile(PlatformPath("dest/file"), | 637 EXPECT_EQ(data_size, file_util::ReadFile(PlatformPath("dest/file"), |
| 638 buffer, data_size)); | 638 buffer, data_size)); |
| 639 for (int i = 0; i < data_size; ++i) | 639 for (int i = 0; i < data_size; ++i) |
| 640 EXPECT_EQ(test_data[i], buffer[i]); | 640 EXPECT_EQ(test_data[i], buffer[i]); |
| 641 } | 641 } |
| 642 | 642 |
| 643 TEST_F(LocalFileSystemOperationTest, TestCopyInForeignFileFailureByQuota) { | 643 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileFailureByQuota) { |
| 644 base::FilePath src_local_disk_file_path; | 644 base::FilePath src_local_disk_file_path; |
| 645 file_util::CreateTemporaryFile(&src_local_disk_file_path); | 645 file_util::CreateTemporaryFile(&src_local_disk_file_path); |
| 646 const char test_data[] = "foo"; | 646 const char test_data[] = "foo"; |
| 647 file_util::WriteFile(src_local_disk_file_path, test_data, | 647 file_util::WriteFile(src_local_disk_file_path, test_data, |
| 648 ARRAYSIZE_UNSAFE(test_data)); | 648 ARRAYSIZE_UNSAFE(test_data)); |
| 649 | 649 |
| 650 FileSystemURL dest_dir(CreateDirectory("dest")); | 650 FileSystemURL dest_dir(CreateDirectory("dest")); |
| 651 | 651 |
| 652 GrantQuotaForCurrentUsage(); | 652 GrantQuotaForCurrentUsage(); |
| 653 operation_runner()->CopyInForeignFile(src_local_disk_file_path, | 653 operation_runner()->CopyInForeignFile(src_local_disk_file_path, |
| 654 URLForPath("dest/file"), | 654 URLForPath("dest/file"), |
| 655 RecordStatusCallback()); | 655 RecordStatusCallback()); |
| 656 base::MessageLoop::current()->RunUntilIdle(); | 656 base::MessageLoop::current()->RunUntilIdle(); |
| 657 | 657 |
| 658 EXPECT_FALSE(FileExists("dest/file")); | 658 EXPECT_FALSE(FileExists("dest/file")); |
| 659 EXPECT_EQ(0, change_observer()->create_file_count()); | 659 EXPECT_EQ(0, change_observer()->create_file_count()); |
| 660 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 660 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
| 661 } | 661 } |
| 662 | 662 |
| 663 TEST_F(LocalFileSystemOperationTest, TestCreateFileFailure) { | 663 TEST_F(FileSystemOperationImplTest, TestCreateFileFailure) { |
| 664 // Already existing file and exclusive true. | 664 // Already existing file and exclusive true. |
| 665 FileSystemURL file(CreateFile("file")); | 665 FileSystemURL file(CreateFile("file")); |
| 666 operation_runner()->CreateFile(file, true, RecordStatusCallback()); | 666 operation_runner()->CreateFile(file, true, RecordStatusCallback()); |
| 667 base::MessageLoop::current()->RunUntilIdle(); | 667 base::MessageLoop::current()->RunUntilIdle(); |
| 668 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 668 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
| 669 EXPECT_TRUE(change_observer()->HasNoChange()); | 669 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 670 } | 670 } |
| 671 | 671 |
| 672 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessFileExists) { | 672 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileExists) { |
| 673 // Already existing file and exclusive false. | 673 // Already existing file and exclusive false. |
| 674 FileSystemURL file(CreateFile("file")); | 674 FileSystemURL file(CreateFile("file")); |
| 675 operation_runner()->CreateFile(file, false, RecordStatusCallback()); | 675 operation_runner()->CreateFile(file, false, RecordStatusCallback()); |
| 676 base::MessageLoop::current()->RunUntilIdle(); | 676 base::MessageLoop::current()->RunUntilIdle(); |
| 677 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 677 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 678 EXPECT_TRUE(FileExists("file")); | 678 EXPECT_TRUE(FileExists("file")); |
| 679 | 679 |
| 680 // The file was already there; did nothing. | 680 // The file was already there; did nothing. |
| 681 EXPECT_TRUE(change_observer()->HasNoChange()); | 681 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 682 } | 682 } |
| 683 | 683 |
| 684 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessExclusive) { | 684 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessExclusive) { |
| 685 // File doesn't exist but exclusive is true. | 685 // File doesn't exist but exclusive is true. |
| 686 operation_runner()->CreateFile(URLForPath("new"), true, | 686 operation_runner()->CreateFile(URLForPath("new"), true, |
| 687 RecordStatusCallback()); | 687 RecordStatusCallback()); |
| 688 base::MessageLoop::current()->RunUntilIdle(); | 688 base::MessageLoop::current()->RunUntilIdle(); |
| 689 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 689 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 690 EXPECT_TRUE(FileExists("new")); | 690 EXPECT_TRUE(FileExists("new")); |
| 691 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 691 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
| 692 } | 692 } |
| 693 | 693 |
| 694 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) { | 694 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileDoesntExist) { |
| 695 // Non existing file. | 695 // Non existing file. |
| 696 operation_runner()->CreateFile(URLForPath("nonexistent"), false, | 696 operation_runner()->CreateFile(URLForPath("nonexistent"), false, |
| 697 RecordStatusCallback()); | 697 RecordStatusCallback()); |
| 698 base::MessageLoop::current()->RunUntilIdle(); | 698 base::MessageLoop::current()->RunUntilIdle(); |
| 699 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 699 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 700 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 700 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
| 701 } | 701 } |
| 702 | 702 |
| 703 TEST_F(LocalFileSystemOperationTest, | 703 TEST_F(FileSystemOperationImplTest, |
| 704 TestCreateDirFailureDestParentDoesntExist) { | 704 TestCreateDirFailureDestParentDoesntExist) { |
| 705 // Dest. parent path does not exist. | 705 // Dest. parent path does not exist. |
| 706 operation_runner()->CreateDirectory( | 706 operation_runner()->CreateDirectory( |
| 707 URLForPath("nonexistent/dir"), false, false, | 707 URLForPath("nonexistent/dir"), false, false, |
| 708 RecordStatusCallback()); | 708 RecordStatusCallback()); |
| 709 base::MessageLoop::current()->RunUntilIdle(); | 709 base::MessageLoop::current()->RunUntilIdle(); |
| 710 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 710 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 711 EXPECT_TRUE(change_observer()->HasNoChange()); | 711 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 712 } | 712 } |
| 713 | 713 |
| 714 TEST_F(LocalFileSystemOperationTest, TestCreateDirFailureDirExists) { | 714 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureDirExists) { |
| 715 // Exclusive and dir existing at path. | 715 // Exclusive and dir existing at path. |
| 716 FileSystemURL dir(CreateDirectory("dir")); | 716 FileSystemURL dir(CreateDirectory("dir")); |
| 717 operation_runner()->CreateDirectory(dir, true, false, | 717 operation_runner()->CreateDirectory(dir, true, false, |
| 718 RecordStatusCallback()); | 718 RecordStatusCallback()); |
| 719 base::MessageLoop::current()->RunUntilIdle(); | 719 base::MessageLoop::current()->RunUntilIdle(); |
| 720 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 720 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
| 721 EXPECT_TRUE(change_observer()->HasNoChange()); | 721 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 722 } | 722 } |
| 723 | 723 |
| 724 TEST_F(LocalFileSystemOperationTest, TestCreateDirFailureFileExists) { | 724 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureFileExists) { |
| 725 // Exclusive true and file existing at path. | 725 // Exclusive true and file existing at path. |
| 726 FileSystemURL file(CreateFile("file")); | 726 FileSystemURL file(CreateFile("file")); |
| 727 operation_runner()->CreateDirectory(file, true, false, | 727 operation_runner()->CreateDirectory(file, true, false, |
| 728 RecordStatusCallback()); | 728 RecordStatusCallback()); |
| 729 base::MessageLoop::current()->RunUntilIdle(); | 729 base::MessageLoop::current()->RunUntilIdle(); |
| 730 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 730 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
| 731 EXPECT_TRUE(change_observer()->HasNoChange()); | 731 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 732 } | 732 } |
| 733 | 733 |
| 734 TEST_F(LocalFileSystemOperationTest, TestCreateDirSuccess) { | 734 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccess) { |
| 735 // Dir exists and exclusive is false. | 735 // Dir exists and exclusive is false. |
| 736 FileSystemURL dir(CreateDirectory("dir")); | 736 FileSystemURL dir(CreateDirectory("dir")); |
| 737 operation_runner()->CreateDirectory(dir, false, false, | 737 operation_runner()->CreateDirectory(dir, false, false, |
| 738 RecordStatusCallback()); | 738 RecordStatusCallback()); |
| 739 base::MessageLoop::current()->RunUntilIdle(); | 739 base::MessageLoop::current()->RunUntilIdle(); |
| 740 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 740 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 741 EXPECT_TRUE(change_observer()->HasNoChange()); | 741 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 742 | 742 |
| 743 // Dir doesn't exist. | 743 // Dir doesn't exist. |
| 744 operation_runner()->CreateDirectory(URLForPath("new"), false, false, | 744 operation_runner()->CreateDirectory(URLForPath("new"), false, false, |
| 745 RecordStatusCallback()); | 745 RecordStatusCallback()); |
| 746 base::MessageLoop::current()->RunUntilIdle(); | 746 base::MessageLoop::current()->RunUntilIdle(); |
| 747 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 747 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 748 EXPECT_TRUE(DirectoryExists("new")); | 748 EXPECT_TRUE(DirectoryExists("new")); |
| 749 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 749 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 750 } | 750 } |
| 751 | 751 |
| 752 TEST_F(LocalFileSystemOperationTest, TestCreateDirSuccessExclusive) { | 752 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccessExclusive) { |
| 753 // Dir doesn't exist. | 753 // Dir doesn't exist. |
| 754 operation_runner()->CreateDirectory(URLForPath("new"), true, false, | 754 operation_runner()->CreateDirectory(URLForPath("new"), true, false, |
| 755 RecordStatusCallback()); | 755 RecordStatusCallback()); |
| 756 base::MessageLoop::current()->RunUntilIdle(); | 756 base::MessageLoop::current()->RunUntilIdle(); |
| 757 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 757 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 758 EXPECT_TRUE(DirectoryExists("new")); | 758 EXPECT_TRUE(DirectoryExists("new")); |
| 759 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 759 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 760 EXPECT_TRUE(change_observer()->HasNoChange()); | 760 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 761 } | 761 } |
| 762 | 762 |
| 763 TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataFailure) { | 763 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataFailure) { |
| 764 operation_runner()->GetMetadata(URLForPath("nonexistent"), | 764 operation_runner()->GetMetadata(URLForPath("nonexistent"), |
| 765 RecordMetadataCallback()); | 765 RecordMetadataCallback()); |
| 766 base::MessageLoop::current()->RunUntilIdle(); | 766 base::MessageLoop::current()->RunUntilIdle(); |
| 767 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 767 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 768 | 768 |
| 769 operation_runner()->FileExists(URLForPath("nonexistent"), | 769 operation_runner()->FileExists(URLForPath("nonexistent"), |
| 770 RecordStatusCallback()); | 770 RecordStatusCallback()); |
| 771 base::MessageLoop::current()->RunUntilIdle(); | 771 base::MessageLoop::current()->RunUntilIdle(); |
| 772 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 772 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 773 | 773 |
| 774 operation_runner()->DirectoryExists(URLForPath("nonexistent"), | 774 operation_runner()->DirectoryExists(URLForPath("nonexistent"), |
| 775 RecordStatusCallback()); | 775 RecordStatusCallback()); |
| 776 base::MessageLoop::current()->RunUntilIdle(); | 776 base::MessageLoop::current()->RunUntilIdle(); |
| 777 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 777 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 778 EXPECT_TRUE(change_observer()->HasNoChange()); | 778 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 779 } | 779 } |
| 780 | 780 |
| 781 TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataSuccess) { | 781 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) { |
| 782 FileSystemURL dir(CreateDirectory("dir")); | 782 FileSystemURL dir(CreateDirectory("dir")); |
| 783 FileSystemURL file(CreateFile("dir/file")); | 783 FileSystemURL file(CreateFile("dir/file")); |
| 784 int read_access = 0; | 784 int read_access = 0; |
| 785 | 785 |
| 786 operation_runner()->DirectoryExists(dir, RecordStatusCallback()); | 786 operation_runner()->DirectoryExists(dir, RecordStatusCallback()); |
| 787 base::MessageLoop::current()->RunUntilIdle(); | 787 base::MessageLoop::current()->RunUntilIdle(); |
| 788 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 788 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 789 ++read_access; | 789 ++read_access; |
| 790 | 790 |
| 791 operation_runner()->GetMetadata(dir, RecordMetadataCallback()); | 791 operation_runner()->GetMetadata(dir, RecordMetadataCallback()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 803 base::MessageLoop::current()->RunUntilIdle(); | 803 base::MessageLoop::current()->RunUntilIdle(); |
| 804 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 804 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 805 EXPECT_FALSE(info().is_directory); | 805 EXPECT_FALSE(info().is_directory); |
| 806 ++read_access; | 806 ++read_access; |
| 807 | 807 |
| 808 EXPECT_EQ(read_access, | 808 EXPECT_EQ(read_access, |
| 809 quota_manager_proxy()->notify_storage_accessed_count()); | 809 quota_manager_proxy()->notify_storage_accessed_count()); |
| 810 EXPECT_TRUE(change_observer()->HasNoChange()); | 810 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 811 } | 811 } |
| 812 | 812 |
| 813 TEST_F(LocalFileSystemOperationTest, TestTypeMismatchErrors) { | 813 TEST_F(FileSystemOperationImplTest, TestTypeMismatchErrors) { |
| 814 FileSystemURL dir(CreateDirectory("dir")); | 814 FileSystemURL dir(CreateDirectory("dir")); |
| 815 operation_runner()->FileExists(dir, RecordStatusCallback()); | 815 operation_runner()->FileExists(dir, RecordStatusCallback()); |
| 816 base::MessageLoop::current()->RunUntilIdle(); | 816 base::MessageLoop::current()->RunUntilIdle(); |
| 817 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); | 817 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); |
| 818 | 818 |
| 819 FileSystemURL file(CreateFile("file")); | 819 FileSystemURL file(CreateFile("file")); |
| 820 operation_runner()->DirectoryExists(file, RecordStatusCallback()); | 820 operation_runner()->DirectoryExists(file, RecordStatusCallback()); |
| 821 base::MessageLoop::current()->RunUntilIdle(); | 821 base::MessageLoop::current()->RunUntilIdle(); |
| 822 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); | 822 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); |
| 823 } | 823 } |
| 824 | 824 |
| 825 TEST_F(LocalFileSystemOperationTest, TestReadDirFailure) { | 825 TEST_F(FileSystemOperationImplTest, TestReadDirFailure) { |
| 826 // Path doesn't exist | 826 // Path doesn't exist |
| 827 operation_runner()->ReadDirectory(URLForPath("nonexistent"), | 827 operation_runner()->ReadDirectory(URLForPath("nonexistent"), |
| 828 RecordReadDirectoryCallback()); | 828 RecordReadDirectoryCallback()); |
| 829 base::MessageLoop::current()->RunUntilIdle(); | 829 base::MessageLoop::current()->RunUntilIdle(); |
| 830 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 830 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 831 | 831 |
| 832 // File exists. | 832 // File exists. |
| 833 FileSystemURL file(CreateFile("file")); | 833 FileSystemURL file(CreateFile("file")); |
| 834 operation_runner()->ReadDirectory(file, RecordReadDirectoryCallback()); | 834 operation_runner()->ReadDirectory(file, RecordReadDirectoryCallback()); |
| 835 base::MessageLoop::current()->RunUntilIdle(); | 835 base::MessageLoop::current()->RunUntilIdle(); |
| 836 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); | 836 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); |
| 837 EXPECT_TRUE(change_observer()->HasNoChange()); | 837 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 838 } | 838 } |
| 839 | 839 |
| 840 TEST_F(LocalFileSystemOperationTest, TestReadDirSuccess) { | 840 TEST_F(FileSystemOperationImplTest, TestReadDirSuccess) { |
| 841 // parent_dir | 841 // parent_dir |
| 842 // | | | 842 // | | |
| 843 // child_dir child_file | 843 // child_dir child_file |
| 844 // Verify reading parent_dir. | 844 // Verify reading parent_dir. |
| 845 FileSystemURL parent_dir(CreateDirectory("dir")); | 845 FileSystemURL parent_dir(CreateDirectory("dir")); |
| 846 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); | 846 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); |
| 847 FileSystemURL child_file(CreateFile("dir/child_file")); | 847 FileSystemURL child_file(CreateFile("dir/child_file")); |
| 848 | 848 |
| 849 operation_runner()->ReadDirectory(parent_dir, RecordReadDirectoryCallback()); | 849 operation_runner()->ReadDirectory(parent_dir, RecordReadDirectoryCallback()); |
| 850 base::MessageLoop::current()->RunUntilIdle(); | 850 base::MessageLoop::current()->RunUntilIdle(); |
| 851 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 851 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 852 EXPECT_EQ(2u, entries().size()); | 852 EXPECT_EQ(2u, entries().size()); |
| 853 | 853 |
| 854 for (size_t i = 0; i < entries().size(); ++i) { | 854 for (size_t i = 0; i < entries().size(); ++i) { |
| 855 if (entries()[i].is_directory) | 855 if (entries()[i].is_directory) |
| 856 EXPECT_EQ(FILE_PATH_LITERAL("child_dir"), entries()[i].name); | 856 EXPECT_EQ(FILE_PATH_LITERAL("child_dir"), entries()[i].name); |
| 857 else | 857 else |
| 858 EXPECT_EQ(FILE_PATH_LITERAL("child_file"), entries()[i].name); | 858 EXPECT_EQ(FILE_PATH_LITERAL("child_file"), entries()[i].name); |
| 859 } | 859 } |
| 860 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 860 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 861 EXPECT_TRUE(change_observer()->HasNoChange()); | 861 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 862 } | 862 } |
| 863 | 863 |
| 864 TEST_F(LocalFileSystemOperationTest, TestRemoveFailure) { | 864 TEST_F(FileSystemOperationImplTest, TestRemoveFailure) { |
| 865 // Path doesn't exist. | 865 // Path doesn't exist. |
| 866 operation_runner()->Remove(URLForPath("nonexistent"), false /* recursive */, | 866 operation_runner()->Remove(URLForPath("nonexistent"), false /* recursive */, |
| 867 RecordStatusCallback()); | 867 RecordStatusCallback()); |
| 868 base::MessageLoop::current()->RunUntilIdle(); | 868 base::MessageLoop::current()->RunUntilIdle(); |
| 869 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 869 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 870 | 870 |
| 871 // It's an error to try to remove a non-empty directory if recursive flag | 871 // It's an error to try to remove a non-empty directory if recursive flag |
| 872 // is false. | 872 // is false. |
| 873 // parent_dir | 873 // parent_dir |
| 874 // | | | 874 // | | |
| 875 // child_dir child_file | 875 // child_dir child_file |
| 876 // Verify deleting parent_dir. | 876 // Verify deleting parent_dir. |
| 877 FileSystemURL parent_dir(CreateDirectory("dir")); | 877 FileSystemURL parent_dir(CreateDirectory("dir")); |
| 878 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); | 878 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); |
| 879 FileSystemURL child_file(CreateFile("dir/child_file")); | 879 FileSystemURL child_file(CreateFile("dir/child_file")); |
| 880 | 880 |
| 881 operation_runner()->Remove(parent_dir, false /* recursive */, | 881 operation_runner()->Remove(parent_dir, false /* recursive */, |
| 882 RecordStatusCallback()); | 882 RecordStatusCallback()); |
| 883 base::MessageLoop::current()->RunUntilIdle(); | 883 base::MessageLoop::current()->RunUntilIdle(); |
| 884 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); | 884 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); |
| 885 EXPECT_TRUE(change_observer()->HasNoChange()); | 885 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 886 } | 886 } |
| 887 | 887 |
| 888 TEST_F(LocalFileSystemOperationTest, TestRemoveSuccess) { | 888 TEST_F(FileSystemOperationImplTest, TestRemoveSuccess) { |
| 889 FileSystemURL empty_dir(CreateDirectory("empty_dir")); | 889 FileSystemURL empty_dir(CreateDirectory("empty_dir")); |
| 890 EXPECT_TRUE(DirectoryExists("empty_dir")); | 890 EXPECT_TRUE(DirectoryExists("empty_dir")); |
| 891 operation_runner()->Remove(empty_dir, false /* recursive */, | 891 operation_runner()->Remove(empty_dir, false /* recursive */, |
| 892 RecordStatusCallback()); | 892 RecordStatusCallback()); |
| 893 base::MessageLoop::current()->RunUntilIdle(); | 893 base::MessageLoop::current()->RunUntilIdle(); |
| 894 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 894 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 895 EXPECT_FALSE(DirectoryExists("empty_dir")); | 895 EXPECT_FALSE(DirectoryExists("empty_dir")); |
| 896 | 896 |
| 897 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 897 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
| 898 EXPECT_TRUE(change_observer()->HasNoChange()); | 898 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 899 } | 899 } |
| 900 | 900 |
| 901 TEST_F(LocalFileSystemOperationTest, TestRemoveSuccessRecursive) { | 901 TEST_F(FileSystemOperationImplTest, TestRemoveSuccessRecursive) { |
| 902 // Removing a non-empty directory with recursive flag == true should be ok. | 902 // Removing a non-empty directory with recursive flag == true should be ok. |
| 903 // parent_dir | 903 // parent_dir |
| 904 // | | | 904 // | | |
| 905 // child_dir child_files | 905 // child_dir child_files |
| 906 // | | 906 // | |
| 907 // child_files | 907 // child_files |
| 908 // | 908 // |
| 909 // Verify deleting parent_dir. | 909 // Verify deleting parent_dir. |
| 910 FileSystemURL parent_dir(CreateDirectory("dir")); | 910 FileSystemURL parent_dir(CreateDirectory("dir")); |
| 911 for (int i = 0; i < 8; ++i) | 911 for (int i = 0; i < 8; ++i) |
| 912 CreateFile(base::StringPrintf("dir/file-%d", i)); | 912 CreateFile(base::StringPrintf("dir/file-%d", i)); |
| 913 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); | 913 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); |
| 914 for (int i = 0; i < 8; ++i) | 914 for (int i = 0; i < 8; ++i) |
| 915 CreateFile(base::StringPrintf("dir/child_dir/file-%d", i)); | 915 CreateFile(base::StringPrintf("dir/child_dir/file-%d", i)); |
| 916 | 916 |
| 917 operation_runner()->Remove(parent_dir, true /* recursive */, | 917 operation_runner()->Remove(parent_dir, true /* recursive */, |
| 918 RecordStatusCallback()); | 918 RecordStatusCallback()); |
| 919 base::MessageLoop::current()->RunUntilIdle(); | 919 base::MessageLoop::current()->RunUntilIdle(); |
| 920 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 920 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 921 EXPECT_FALSE(DirectoryExists("parent_dir")); | 921 EXPECT_FALSE(DirectoryExists("parent_dir")); |
| 922 | 922 |
| 923 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); | 923 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); |
| 924 EXPECT_EQ(16, change_observer()->get_and_reset_remove_file_count()); | 924 EXPECT_EQ(16, change_observer()->get_and_reset_remove_file_count()); |
| 925 EXPECT_TRUE(change_observer()->HasNoChange()); | 925 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 926 } | 926 } |
| 927 | 927 |
| 928 TEST_F(LocalFileSystemOperationTest, TestTruncate) { | 928 TEST_F(FileSystemOperationImplTest, TestTruncate) { |
| 929 FileSystemURL file(CreateFile("file")); | 929 FileSystemURL file(CreateFile("file")); |
| 930 base::FilePath platform_path = PlatformPath("file"); | 930 base::FilePath platform_path = PlatformPath("file"); |
| 931 | 931 |
| 932 char test_data[] = "test data"; | 932 char test_data[] = "test data"; |
| 933 int data_size = static_cast<int>(sizeof(test_data)); | 933 int data_size = static_cast<int>(sizeof(test_data)); |
| 934 EXPECT_EQ(data_size, | 934 EXPECT_EQ(data_size, |
| 935 file_util::WriteFile(platform_path, test_data, data_size)); | 935 file_util::WriteFile(platform_path, test_data, data_size)); |
| 936 | 936 |
| 937 // Check that its length is the size of the data written. | 937 // Check that its length is the size of the data written. |
| 938 operation_runner()->GetMetadata(file, RecordMetadataCallback()); | 938 operation_runner()->GetMetadata(file, RecordMetadataCallback()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 EXPECT_EQ(length, GetFileSize("file")); | 975 EXPECT_EQ(length, GetFileSize("file")); |
| 976 EXPECT_EQ(length, file_util::ReadFile(platform_path, data, length)); | 976 EXPECT_EQ(length, file_util::ReadFile(platform_path, data, length)); |
| 977 for (int i = 0; i < length; ++i) | 977 for (int i = 0; i < length; ++i) |
| 978 EXPECT_EQ(test_data[i], data[i]); | 978 EXPECT_EQ(test_data[i], data[i]); |
| 979 | 979 |
| 980 // Truncate is not a 'read' access. (Here expected access count is 1 | 980 // Truncate is not a 'read' access. (Here expected access count is 1 |
| 981 // since we made 1 read access for GetMetadata.) | 981 // since we made 1 read access for GetMetadata.) |
| 982 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 982 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 983 } | 983 } |
| 984 | 984 |
| 985 TEST_F(LocalFileSystemOperationTest, TestTruncateFailureByQuota) { | 985 TEST_F(FileSystemOperationImplTest, TestTruncateFailureByQuota) { |
| 986 FileSystemURL dir(CreateDirectory("dir")); | 986 FileSystemURL dir(CreateDirectory("dir")); |
| 987 FileSystemURL file(CreateFile("dir/file")); | 987 FileSystemURL file(CreateFile("dir/file")); |
| 988 | 988 |
| 989 GrantQuotaForCurrentUsage(); | 989 GrantQuotaForCurrentUsage(); |
| 990 AddQuota(10); | 990 AddQuota(10); |
| 991 | 991 |
| 992 operation_runner()->Truncate(file, 10, RecordStatusCallback()); | 992 operation_runner()->Truncate(file, 10, RecordStatusCallback()); |
| 993 base::MessageLoop::current()->RunUntilIdle(); | 993 base::MessageLoop::current()->RunUntilIdle(); |
| 994 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 994 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 995 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 995 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| 996 EXPECT_TRUE(change_observer()->HasNoChange()); | 996 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 997 | 997 |
| 998 EXPECT_EQ(10, GetFileSize("dir/file")); | 998 EXPECT_EQ(10, GetFileSize("dir/file")); |
| 999 | 999 |
| 1000 operation_runner()->Truncate(file, 11, RecordStatusCallback()); | 1000 operation_runner()->Truncate(file, 11, RecordStatusCallback()); |
| 1001 base::MessageLoop::current()->RunUntilIdle(); | 1001 base::MessageLoop::current()->RunUntilIdle(); |
| 1002 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 1002 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
| 1003 EXPECT_TRUE(change_observer()->HasNoChange()); | 1003 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1004 | 1004 |
| 1005 EXPECT_EQ(10, GetFileSize("dir/file")); | 1005 EXPECT_EQ(10, GetFileSize("dir/file")); |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 TEST_F(LocalFileSystemOperationTest, TestTouchFile) { | 1008 TEST_F(FileSystemOperationImplTest, TestTouchFile) { |
| 1009 FileSystemURL file(CreateFile("file")); | 1009 FileSystemURL file(CreateFile("file")); |
| 1010 base::FilePath platform_path = PlatformPath("file"); | 1010 base::FilePath platform_path = PlatformPath("file"); |
| 1011 | 1011 |
| 1012 base::PlatformFileInfo info; | 1012 base::PlatformFileInfo info; |
| 1013 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); | 1013 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); |
| 1014 EXPECT_FALSE(info.is_directory); | 1014 EXPECT_FALSE(info.is_directory); |
| 1015 EXPECT_EQ(0, info.size); | 1015 EXPECT_EQ(0, info.size); |
| 1016 const base::Time last_modified = info.last_modified; | 1016 const base::Time last_modified = info.last_modified; |
| 1017 const base::Time last_accessed = info.last_accessed; | 1017 const base::Time last_accessed = info.last_accessed; |
| 1018 | 1018 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1029 EXPECT_TRUE(change_observer()->HasNoChange()); | 1029 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1030 | 1030 |
| 1031 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); | 1031 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); |
| 1032 // We compare as time_t here to lower our resolution, to avoid false | 1032 // We compare as time_t here to lower our resolution, to avoid false |
| 1033 // negatives caused by conversion to the local filesystem's native | 1033 // negatives caused by conversion to the local filesystem's native |
| 1034 // representation and back. | 1034 // representation and back. |
| 1035 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); | 1035 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); |
| 1036 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); | 1036 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); |
| 1037 } | 1037 } |
| 1038 | 1038 |
| 1039 TEST_F(LocalFileSystemOperationTest, TestCreateSnapshotFile) { | 1039 TEST_F(FileSystemOperationImplTest, TestCreateSnapshotFile) { |
| 1040 FileSystemURL dir(CreateDirectory("dir")); | 1040 FileSystemURL dir(CreateDirectory("dir")); |
| 1041 | 1041 |
| 1042 // Create a file for the testing. | 1042 // Create a file for the testing. |
| 1043 operation_runner()->DirectoryExists(dir, RecordStatusCallback()); | 1043 operation_runner()->DirectoryExists(dir, RecordStatusCallback()); |
| 1044 FileSystemURL file(CreateFile("dir/file")); | 1044 FileSystemURL file(CreateFile("dir/file")); |
| 1045 operation_runner()->FileExists(file, RecordStatusCallback()); | 1045 operation_runner()->FileExists(file, RecordStatusCallback()); |
| 1046 base::MessageLoop::current()->RunUntilIdle(); | 1046 base::MessageLoop::current()->RunUntilIdle(); |
| 1047 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1047 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 1048 | 1048 |
| 1049 // See if we can get a 'snapshot' file info for the file. | 1049 // See if we can get a 'snapshot' file info for the file. |
| 1050 // Since LocalFileSystemOperation assumes the file exists in the local | 1050 // Since FileSystemOperationImpl assumes the file exists in the local |
| 1051 // directory it should just returns the same metadata and platform_path | 1051 // directory it should just returns the same metadata and platform_path |
| 1052 // as the file itself. | 1052 // as the file itself. |
| 1053 operation_runner()->CreateSnapshotFile(file, RecordSnapshotFileCallback()); | 1053 operation_runner()->CreateSnapshotFile(file, RecordSnapshotFileCallback()); |
| 1054 base::MessageLoop::current()->RunUntilIdle(); | 1054 base::MessageLoop::current()->RunUntilIdle(); |
| 1055 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1055 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 1056 EXPECT_FALSE(info().is_directory); | 1056 EXPECT_FALSE(info().is_directory); |
| 1057 EXPECT_EQ(PlatformPath("dir/file"), path()); | 1057 EXPECT_EQ(PlatformPath("dir/file"), path()); |
| 1058 EXPECT_TRUE(change_observer()->HasNoChange()); | 1058 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1059 | 1059 |
| 1060 // The FileSystemOpration implementation does not create a | 1060 // The FileSystemOpration implementation does not create a |
| 1061 // shareable file reference. | 1061 // shareable file reference. |
| 1062 EXPECT_EQ(NULL, shareable_file_ref()); | 1062 EXPECT_EQ(NULL, shareable_file_ref()); |
| 1063 } | 1063 } |
| 1064 | 1064 |
| 1065 TEST_F(LocalFileSystemOperationTest, | 1065 TEST_F(FileSystemOperationImplTest, |
| 1066 TestMoveSuccessSrcDirRecursiveWithQuota) { | 1066 TestMoveSuccessSrcDirRecursiveWithQuota) { |
| 1067 FileSystemURL src(CreateDirectory("src")); | 1067 FileSystemURL src(CreateDirectory("src")); |
| 1068 int src_path_cost = GetUsage(); | 1068 int src_path_cost = GetUsage(); |
| 1069 | 1069 |
| 1070 FileSystemURL dest(CreateDirectory("dest")); | 1070 FileSystemURL dest(CreateDirectory("dest")); |
| 1071 FileSystemURL child_file1(CreateFile("src/file1")); | 1071 FileSystemURL child_file1(CreateFile("src/file1")); |
| 1072 FileSystemURL child_file2(CreateFile("src/file2")); | 1072 FileSystemURL child_file2(CreateFile("src/file2")); |
| 1073 FileSystemURL child_dir(CreateDirectory("src/dir")); | 1073 FileSystemURL child_dir(CreateDirectory("src/dir")); |
| 1074 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); | 1074 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); |
| 1075 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); | 1075 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1103 EXPECT_FALSE(DirectoryExists("src/dir")); | 1103 EXPECT_FALSE(DirectoryExists("src/dir")); |
| 1104 EXPECT_FALSE(FileExists("src/dir/file2")); | 1104 EXPECT_FALSE(FileExists("src/dir/file2")); |
| 1105 EXPECT_TRUE(DirectoryExists("dest/dir")); | 1105 EXPECT_TRUE(DirectoryExists("dest/dir")); |
| 1106 EXPECT_TRUE(FileExists("dest/dir/file2")); | 1106 EXPECT_TRUE(FileExists("dest/dir/file2")); |
| 1107 | 1107 |
| 1108 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); | 1108 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); |
| 1109 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, | 1109 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, |
| 1110 GetUsage()); | 1110 GetUsage()); |
| 1111 } | 1111 } |
| 1112 | 1112 |
| 1113 TEST_F(LocalFileSystemOperationTest, | 1113 TEST_F(FileSystemOperationImplTest, |
| 1114 TestCopySuccessSrcDirRecursiveWithQuota) { | 1114 TestCopySuccessSrcDirRecursiveWithQuota) { |
| 1115 FileSystemURL src(CreateDirectory("src")); | 1115 FileSystemURL src(CreateDirectory("src")); |
| 1116 FileSystemURL dest1(CreateDirectory("dest1")); | 1116 FileSystemURL dest1(CreateDirectory("dest1")); |
| 1117 FileSystemURL dest2(CreateDirectory("dest2")); | 1117 FileSystemURL dest2(CreateDirectory("dest2")); |
| 1118 | 1118 |
| 1119 int64 usage = GetUsage(); | 1119 int64 usage = GetUsage(); |
| 1120 FileSystemURL child_file1(CreateFile("src/file1")); | 1120 FileSystemURL child_file1(CreateFile("src/file1")); |
| 1121 FileSystemURL child_file2(CreateFile("src/file2")); | 1121 FileSystemURL child_file2(CreateFile("src/file2")); |
| 1122 FileSystemURL child_dir(CreateDirectory("src/dir")); | 1122 FileSystemURL child_dir(CreateDirectory("src/dir")); |
| 1123 int64 child_path_cost = GetUsage() - usage; | 1123 int64 child_path_cost = GetUsage() - usage; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 base::MessageLoop::current()->RunUntilIdle(); | 1175 base::MessageLoop::current()->RunUntilIdle(); |
| 1176 | 1176 |
| 1177 expected_usage += grandchild_file_size + grandchild_path_cost; | 1177 expected_usage += grandchild_file_size + grandchild_path_cost; |
| 1178 usage = GetUsage(); | 1178 usage = GetUsage(); |
| 1179 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, | 1179 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, |
| 1180 GetDataSizeOnDisk()); | 1180 GetDataSizeOnDisk()); |
| 1181 EXPECT_EQ(expected_usage, usage); | 1181 EXPECT_EQ(expected_usage, usage); |
| 1182 } | 1182 } |
| 1183 | 1183 |
| 1184 } // namespace fileapi | 1184 } // namespace fileapi |
| OLD | NEW |