| 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/fileapi/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 431 |
| 432 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 432 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 433 RecordStatusCallback()); | 433 RecordStatusCallback()); |
| 434 MessageLoop::current()->RunAllPending(); | 434 MessageLoop::current()->RunAllPending(); |
| 435 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 435 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 436 EXPECT_FALSE(VirtualDirectoryExists(src_dir_path)); | 436 EXPECT_FALSE(VirtualDirectoryExists(src_dir_path)); |
| 437 | 437 |
| 438 // Make sure we've overwritten but not moved the source under the |dest_dir|. | 438 // Make sure we've overwritten but not moved the source under the |dest_dir|. |
| 439 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path)); | 439 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path)); |
| 440 EXPECT_FALSE(VirtualDirectoryExists( | 440 EXPECT_FALSE(VirtualDirectoryExists( |
| 441 dest_dir_path.Append(src_dir_path.BaseName()))); | 441 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); |
| 442 } | 442 } |
| 443 | 443 |
| 444 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndNew) { | 444 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndNew) { |
| 445 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 445 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 446 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir()); | 446 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir()); |
| 447 FilePath dest_child_dir_path(dest_parent_dir_path. | 447 FilePath dest_child_dir_path(dest_parent_dir_path. |
| 448 Append(FILE_PATH_LITERAL("NewDirectory"))); | 448 Append(FILE_PATH_LITERAL("NewDirectory"))); |
| 449 | 449 |
| 450 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), | 450 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), |
| 451 RecordStatusCallback()); | 451 RecordStatusCallback()); |
| 452 MessageLoop::current()->RunAllPending(); | 452 MessageLoop::current()->RunAllPending(); |
| 453 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 453 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 454 EXPECT_FALSE(VirtualDirectoryExists(src_dir_path)); | 454 EXPECT_FALSE(VirtualDirectoryExists(src_dir_path)); |
| 455 EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path)); | 455 EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path)); |
| 456 } | 456 } |
| 457 | 457 |
| 458 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) { | 458 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) { |
| 459 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 459 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 460 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); | 460 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); |
| 461 FilePath grandchild_file_path( | 461 FilePath grandchild_file_path( |
| 462 CreateVirtualTemporaryFileInDir(child_dir_path)); | 462 CreateVirtualTemporaryFileInDir(child_dir_path)); |
| 463 | 463 |
| 464 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 464 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 465 | 465 |
| 466 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 466 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 467 RecordStatusCallback()); | 467 RecordStatusCallback()); |
| 468 MessageLoop::current()->RunAllPending(); | 468 MessageLoop::current()->RunAllPending(); |
| 469 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 469 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 470 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( | 470 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( |
| 471 child_dir_path.BaseName()))); | 471 VirtualPath::BaseName(child_dir_path)))); |
| 472 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( | 472 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( |
| 473 child_dir_path.BaseName()).Append( | 473 VirtualPath::BaseName(child_dir_path)).Append( |
| 474 grandchild_file_path.BaseName()))); | 474 VirtualPath::BaseName(grandchild_file_path)))); |
| 475 } | 475 } |
| 476 | 476 |
| 477 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) { | 477 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) { |
| 478 operation()->Copy(URLForPath(FilePath(FILE_PATH_LITERAL("a"))), | 478 operation()->Copy(URLForPath(FilePath(FILE_PATH_LITERAL("a"))), |
| 479 URLForPath(FilePath(FILE_PATH_LITERAL("b"))), | 479 URLForPath(FilePath(FILE_PATH_LITERAL("b"))), |
| 480 RecordStatusCallback()); | 480 RecordStatusCallback()); |
| 481 MessageLoop::current()->RunAllPending(); | 481 MessageLoop::current()->RunAllPending(); |
| 482 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 482 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 483 } | 483 } |
| 484 | 484 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 602 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 603 | 603 |
| 604 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 604 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 605 RecordStatusCallback()); | 605 RecordStatusCallback()); |
| 606 MessageLoop::current()->RunAllPending(); | 606 MessageLoop::current()->RunAllPending(); |
| 607 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 607 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 608 | 608 |
| 609 // Make sure we've overwritten but not copied the source under the |dest_dir|. | 609 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
| 610 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path)); | 610 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path)); |
| 611 EXPECT_FALSE(VirtualDirectoryExists( | 611 EXPECT_FALSE(VirtualDirectoryExists( |
| 612 dest_dir_path.Append(src_dir_path.BaseName()))); | 612 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); |
| 613 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 613 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); |
| 614 } | 614 } |
| 615 | 615 |
| 616 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) { | 616 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) { |
| 617 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 617 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
| 618 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir()); | 618 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir()); |
| 619 FilePath dest_child_dir_path(dest_parent_dir_path. | 619 FilePath dest_child_dir_path(dest_parent_dir_path. |
| 620 Append(FILE_PATH_LITERAL("NewDirectory"))); | 620 Append(FILE_PATH_LITERAL("NewDirectory"))); |
| 621 | 621 |
| 622 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), | 622 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 633 FilePath grandchild_file_path( | 633 FilePath grandchild_file_path( |
| 634 CreateVirtualTemporaryFileInDir(child_dir_path)); | 634 CreateVirtualTemporaryFileInDir(child_dir_path)); |
| 635 | 635 |
| 636 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 636 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
| 637 | 637 |
| 638 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 638 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
| 639 RecordStatusCallback()); | 639 RecordStatusCallback()); |
| 640 MessageLoop::current()->RunAllPending(); | 640 MessageLoop::current()->RunAllPending(); |
| 641 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 641 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 642 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( | 642 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( |
| 643 child_dir_path.BaseName()))); | 643 VirtualPath::BaseName(child_dir_path)))); |
| 644 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( | 644 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( |
| 645 child_dir_path.BaseName()).Append( | 645 VirtualPath::BaseName(child_dir_path)).Append( |
| 646 grandchild_file_path.BaseName()))); | 646 VirtualPath::BaseName(grandchild_file_path)))); |
| 647 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 647 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); |
| 648 } | 648 } |
| 649 | 649 |
| 650 TEST_F(FileSystemOperationTest, TestCreateFileFailure) { | 650 TEST_F(FileSystemOperationTest, TestCreateFileFailure) { |
| 651 // Already existing file and exclusive true. | 651 // Already existing file and exclusive true. |
| 652 FilePath dir_path(CreateVirtualTemporaryDir()); | 652 FilePath dir_path(CreateVirtualTemporaryDir()); |
| 653 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 653 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
| 654 operation()->CreateFile(URLForPath(file_path), true, | 654 operation()->CreateFile(URLForPath(file_path), true, |
| 655 RecordStatusCallback()); | 655 RecordStatusCallback()); |
| 656 MessageLoop::current()->RunAllPending(); | 656 MessageLoop::current()->RunAllPending(); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 ASSERT_FALSE(child_dir_path.empty()); | 848 ASSERT_FALSE(child_dir_path.empty()); |
| 849 | 849 |
| 850 operation()->ReadDirectory(URLForPath(parent_dir_path), | 850 operation()->ReadDirectory(URLForPath(parent_dir_path), |
| 851 RecordReadDirectoryCallback()); | 851 RecordReadDirectoryCallback()); |
| 852 MessageLoop::current()->RunAllPending(); | 852 MessageLoop::current()->RunAllPending(); |
| 853 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 853 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 854 EXPECT_EQ(2u, entries().size()); | 854 EXPECT_EQ(2u, entries().size()); |
| 855 | 855 |
| 856 for (size_t i = 0; i < entries().size(); ++i) { | 856 for (size_t i = 0; i < entries().size(); ++i) { |
| 857 if (entries()[i].is_directory) { | 857 if (entries()[i].is_directory) { |
| 858 EXPECT_EQ(child_dir_path.BaseName().value(), | 858 EXPECT_EQ(VirtualPath::BaseName(child_dir_path).value(), |
| 859 entries()[i].name); | 859 entries()[i].name); |
| 860 } else { | 860 } else { |
| 861 EXPECT_EQ(child_file_path.BaseName().value(), | 861 EXPECT_EQ(VirtualPath::BaseName(child_file_path).value(), |
| 862 entries()[i].name); | 862 entries()[i].name); |
| 863 } | 863 } |
| 864 } | 864 } |
| 865 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | 865 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); |
| 866 } | 866 } |
| 867 | 867 |
| 868 TEST_F(FileSystemOperationTest, TestRemoveFailure) { | 868 TEST_F(FileSystemOperationTest, TestRemoveFailure) { |
| 869 // Path doesn't exist. | 869 // Path doesn't exist. |
| 870 FilePath nonexisting_path(FilePath( | 870 FilePath nonexisting_path(FilePath( |
| 871 FILE_PATH_LITERAL("NonExistingDir"))); | 871 FILE_PATH_LITERAL("NonExistingDir"))); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1058 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 1059 EXPECT_FALSE(info().is_directory); | 1059 EXPECT_FALSE(info().is_directory); |
| 1060 EXPECT_EQ(PlatformPath(file_path), path()); | 1060 EXPECT_EQ(PlatformPath(file_path), path()); |
| 1061 | 1061 |
| 1062 // The FileSystemOpration implementation does not set the deletable | 1062 // The FileSystemOpration implementation does not set the deletable |
| 1063 // file reference. | 1063 // file reference. |
| 1064 EXPECT_EQ(NULL, deletable_file_ref()); | 1064 EXPECT_EQ(NULL, deletable_file_ref()); |
| 1065 } | 1065 } |
| 1066 | 1066 |
| 1067 } // namespace fileapi | 1067 } // namespace fileapi |
| OLD | NEW |