OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 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/file_system_operation_impl.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" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 ASSERT_EQ(expected, actual) << from_here.ToString(); | 50 ASSERT_EQ(expected, actual) << from_here.ToString(); |
51 } | 51 } |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 // Test class for FileSystemOperationImpl. | 55 // Test class for FileSystemOperationImpl. |
56 class FileSystemOperationImplTest | 56 class FileSystemOperationImplTest |
57 : public testing::Test { | 57 : public testing::Test { |
58 public: | 58 public: |
59 FileSystemOperationImplTest() | 59 FileSystemOperationImplTest() |
60 : status_(kFileOperationStatusNotSet), | 60 : message_loop_(base::MessageLoop::TYPE_IO), |
| 61 status_(kFileOperationStatusNotSet), |
61 weak_factory_(this) {} | 62 weak_factory_(this) {} |
62 | 63 |
63 protected: | 64 protected: |
64 virtual void SetUp() OVERRIDE { | 65 virtual void SetUp() OVERRIDE { |
65 EXPECT_TRUE(base_.CreateUniqueTempDir()); | 66 EXPECT_TRUE(base_.CreateUniqueTempDir()); |
66 change_observers_ = | 67 change_observers_ = |
67 storage::MockFileChangeObserver::CreateList(&change_observer_); | 68 storage::MockFileChangeObserver::CreateList(&change_observer_); |
68 | 69 |
69 base::FilePath base_dir = base_.path().AppendASCII("filesystem"); | 70 base::FilePath base_dir = base_.path().AppendASCII("filesystem"); |
70 quota_manager_ = | 71 quota_manager_ = |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 271 |
271 void AddQuota(int64 quota_delta) { | 272 void AddQuota(int64 quota_delta) { |
272 int64 quota; | 273 int64 quota; |
273 GetUsageAndQuota(NULL, "a); | 274 GetUsageAndQuota(NULL, "a); |
274 quota_manager()->SetQuota(sandbox_file_system_.origin(), | 275 quota_manager()->SetQuota(sandbox_file_system_.origin(), |
275 sandbox_file_system_.storage_type(), | 276 sandbox_file_system_.storage_type(), |
276 quota + quota_delta); | 277 quota + quota_delta); |
277 } | 278 } |
278 | 279 |
279 private: | 280 private: |
280 base::MessageLoop message_loop_; | 281 base::MessageLoopForIO message_loop_; |
281 scoped_refptr<QuotaManager> quota_manager_; | 282 scoped_refptr<QuotaManager> quota_manager_; |
282 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | 283 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; |
283 | 284 |
284 // Common temp base for nondestructive uses. | 285 // Common temp base for nondestructive uses. |
285 base::ScopedTempDir base_; | 286 base::ScopedTempDir base_; |
286 | 287 |
287 SandboxFileSystemTestHelper sandbox_file_system_; | 288 SandboxFileSystemTestHelper sandbox_file_system_; |
288 | 289 |
289 // For post-operation status. | 290 // For post-operation status. |
290 int status_; | 291 int status_; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { | 547 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { |
547 // Src exists and is a file. Dest is a directory. | 548 // Src exists and is a file. Dest is a directory. |
548 FileSystemURL src_file(CreateFile("src")); | 549 FileSystemURL src_file(CreateFile("src")); |
549 FileSystemURL dest_dir(CreateDirectory("dest")); | 550 FileSystemURL dest_dir(CreateDirectory("dest")); |
550 | 551 |
551 operation_runner()->Copy(src_file, dest_dir, | 552 operation_runner()->Copy(src_file, dest_dir, |
552 FileSystemOperation::OPTION_NONE, | 553 FileSystemOperation::OPTION_NONE, |
553 FileSystemOperationRunner::CopyProgressCallback(), | 554 FileSystemOperationRunner::CopyProgressCallback(), |
554 RecordStatusCallback()); | 555 RecordStatusCallback()); |
555 base::RunLoop().RunUntilIdle(); | 556 base::RunLoop().RunUntilIdle(); |
556 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | 557 EXPECT_EQ(3, quota_manager_proxy()->notify_storage_accessed_count()); |
| 558 |
| 559 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
| 560 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
| 561 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status()); |
557 EXPECT_TRUE(change_observer()->HasNoChange()); | 562 EXPECT_TRUE(change_observer()->HasNoChange()); |
558 } | 563 } |
559 | 564 |
560 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { | 565 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { |
561 // Dest. parent path does not exist. | 566 // Dest. parent path does not exist. |
562 FileSystemURL src_dir(CreateDirectory("src")); | 567 FileSystemURL src_dir(CreateDirectory("src")); |
563 | 568 |
564 operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), | 569 operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), |
565 FileSystemOperation::OPTION_NONE, | 570 FileSystemOperation::OPTION_NONE, |
566 FileSystemOperationRunner::CopyProgressCallback(), | 571 FileSystemOperationRunner::CopyProgressCallback(), |
(...skipping 30 matching lines...) Expand all Loading... |
597 FileSystemURL src_file(CreateFile("src")); | 602 FileSystemURL src_file(CreateFile("src")); |
598 FileSystemURL dest_file(CreateFile("dest")); | 603 FileSystemURL dest_file(CreateFile("dest")); |
599 | 604 |
600 operation_runner()->Copy(src_file, dest_file, | 605 operation_runner()->Copy(src_file, dest_file, |
601 FileSystemOperation::OPTION_NONE, | 606 FileSystemOperation::OPTION_NONE, |
602 FileSystemOperationRunner::CopyProgressCallback(), | 607 FileSystemOperationRunner::CopyProgressCallback(), |
603 RecordStatusCallback()); | 608 RecordStatusCallback()); |
604 base::RunLoop().RunUntilIdle(); | 609 base::RunLoop().RunUntilIdle(); |
605 EXPECT_EQ(base::File::FILE_OK, status()); | 610 EXPECT_EQ(base::File::FILE_OK, status()); |
606 EXPECT_TRUE(FileExists("dest")); | 611 EXPECT_TRUE(FileExists("dest")); |
607 EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count()); | 612 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); |
608 | 613 |
609 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | |
610 EXPECT_TRUE(change_observer()->HasNoChange()); | 614 EXPECT_TRUE(change_observer()->HasNoChange()); |
611 } | 615 } |
612 | 616 |
613 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { | 617 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { |
614 FileSystemURL src_file(CreateFile("src")); | 618 FileSystemURL src_file(CreateFile("src")); |
615 | 619 |
616 operation_runner()->Copy(src_file, URLForPath("new"), | 620 operation_runner()->Copy(src_file, URLForPath("new"), |
617 FileSystemOperation::OPTION_NONE, | 621 FileSystemOperation::OPTION_NONE, |
618 FileSystemOperationRunner::CopyProgressCallback(), | 622 FileSystemOperationRunner::CopyProgressCallback(), |
619 RecordStatusCallback()); | 623 RecordStatusCallback()); |
620 base::RunLoop().RunUntilIdle(); | 624 base::RunLoop().RunUntilIdle(); |
621 EXPECT_EQ(base::File::FILE_OK, status()); | 625 EXPECT_EQ(base::File::FILE_OK, status()); |
622 EXPECT_TRUE(FileExists("new")); | 626 EXPECT_TRUE(FileExists("new")); |
623 EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count()); | 627 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); |
624 | 628 |
625 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 629 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
626 EXPECT_TRUE(change_observer()->HasNoChange()); | 630 EXPECT_TRUE(change_observer()->HasNoChange()); |
627 } | 631 } |
628 | 632 |
629 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { | 633 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { |
630 FileSystemURL src_dir(CreateDirectory("src")); | 634 FileSystemURL src_dir(CreateDirectory("src")); |
631 FileSystemURL dest_dir(CreateDirectory("dest")); | 635 FileSystemURL dest_dir(CreateDirectory("dest")); |
632 | 636 |
633 operation_runner()->Copy(src_dir, dest_dir, | 637 operation_runner()->Copy(src_dir, dest_dir, |
634 FileSystemOperation::OPTION_NONE, | 638 FileSystemOperation::OPTION_NONE, |
635 FileSystemOperationRunner::CopyProgressCallback(), | 639 FileSystemOperationRunner::CopyProgressCallback(), |
636 RecordStatusCallback()); | 640 RecordStatusCallback()); |
637 base::RunLoop().RunUntilIdle(); | 641 base::RunLoop().RunUntilIdle(); |
638 EXPECT_EQ(base::File::FILE_OK, status()); | 642 EXPECT_EQ(base::File::FILE_OK, status()); |
639 | 643 |
640 // Make sure we've overwritten but not copied the source under the |dest_dir|. | 644 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
641 EXPECT_TRUE(DirectoryExists("dest")); | 645 EXPECT_TRUE(DirectoryExists("dest")); |
642 EXPECT_FALSE(DirectoryExists("dest/src")); | 646 EXPECT_FALSE(DirectoryExists("dest/src")); |
643 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); | 647 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); |
644 | 648 |
| 649 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
645 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 650 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
646 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | |
647 EXPECT_TRUE(change_observer()->HasNoChange()); | 651 EXPECT_TRUE(change_observer()->HasNoChange()); |
648 } | 652 } |
649 | 653 |
650 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { | 654 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { |
651 FileSystemURL src_dir(CreateDirectory("src")); | 655 FileSystemURL src_dir(CreateDirectory("src")); |
652 FileSystemURL dest_dir_new(URLForPath("dest")); | 656 FileSystemURL dest_dir_new(URLForPath("dest")); |
653 | 657 |
654 operation_runner()->Copy(src_dir, dest_dir_new, | 658 operation_runner()->Copy(src_dir, dest_dir_new, |
655 FileSystemOperation::OPTION_NONE, | 659 FileSystemOperation::OPTION_NONE, |
656 FileSystemOperationRunner::CopyProgressCallback(), | 660 FileSystemOperationRunner::CopyProgressCallback(), |
(...skipping 20 matching lines...) Expand all Loading... |
677 RecordStatusCallback()); | 681 RecordStatusCallback()); |
678 base::RunLoop().RunUntilIdle(); | 682 base::RunLoop().RunUntilIdle(); |
679 | 683 |
680 EXPECT_EQ(base::File::FILE_OK, status()); | 684 EXPECT_EQ(base::File::FILE_OK, status()); |
681 EXPECT_TRUE(DirectoryExists("dest/dir")); | 685 EXPECT_TRUE(DirectoryExists("dest/dir")); |
682 EXPECT_TRUE(FileExists("dest/dir/sub")); | 686 EXPECT_TRUE(FileExists("dest/dir/sub")); |
683 | 687 |
684 // For recursive copy we may record multiple read access. | 688 // For recursive copy we may record multiple read access. |
685 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); | 689 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); |
686 | 690 |
| 691 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
687 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 692 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
688 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 693 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
689 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | |
690 EXPECT_TRUE(change_observer()->HasNoChange()); | 694 EXPECT_TRUE(change_observer()->HasNoChange()); |
691 } | 695 } |
692 | 696 |
693 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { | 697 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { |
694 FileSystemURL src_dir(CreateDirectory("src")); | 698 FileSystemURL src_dir(CreateDirectory("src")); |
695 CreateDirectory("src/dir"); | 699 CreateDirectory("src/dir"); |
696 CreateFile("src/dir/sub"); | 700 CreateFile("src/dir/sub"); |
697 | 701 |
698 operation_runner()->Copy(src_dir, src_dir, | 702 operation_runner()->Copy(src_dir, src_dir, |
699 FileSystemOperation::OPTION_NONE, | 703 FileSystemOperation::OPTION_NONE, |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 base::RunLoop().RunUntilIdle(); | 1285 base::RunLoop().RunUntilIdle(); |
1282 | 1286 |
1283 expected_usage += grandchild_file_size + grandchild_path_cost; | 1287 expected_usage += grandchild_file_size + grandchild_path_cost; |
1284 usage = GetUsage(); | 1288 usage = GetUsage(); |
1285 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, | 1289 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, |
1286 GetDataSizeOnDisk()); | 1290 GetDataSizeOnDisk()); |
1287 EXPECT_EQ(expected_usage, usage); | 1291 EXPECT_EQ(expected_usage, usage); |
1288 } | 1292 } |
1289 | 1293 |
1290 } // namespace content | 1294 } // namespace content |
OLD | NEW |