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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 | 271 |
272 void AddQuota(int64 quota_delta) { | 272 void AddQuota(int64 quota_delta) { |
273 int64 quota; | 273 int64 quota; |
274 GetUsageAndQuota(NULL, "a); | 274 GetUsageAndQuota(NULL, "a); |
275 quota_manager()->SetQuota(sandbox_file_system_.origin(), | 275 quota_manager()->SetQuota(sandbox_file_system_.origin(), |
276 sandbox_file_system_.storage_type(), | 276 sandbox_file_system_.storage_type(), |
277 quota + quota_delta); | 277 quota + quota_delta); |
278 } | 278 } |
279 | 279 |
280 private: | 280 private: |
281 base::MessageLoop message_loop_; | 281 base::MessageLoop message_loop_; |
tzik
2014/08/25 07:59:20
This should be MessageLoopForIO now. That causes t
iseki
2014/08/25 10:28:23
Done.
| |
282 scoped_refptr<QuotaManager> quota_manager_; | 282 scoped_refptr<QuotaManager> quota_manager_; |
283 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | 283 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; |
284 | 284 |
285 // Common temp base for nondestructive uses. | 285 // Common temp base for nondestructive uses. |
286 base::ScopedTempDir base_; | 286 base::ScopedTempDir base_; |
287 | 287 |
288 SandboxFileSystemTestHelper sandbox_file_system_; | 288 SandboxFileSystemTestHelper sandbox_file_system_; |
289 | 289 |
290 // For post-operation status. | 290 // For post-operation status. |
291 int status_; | 291 int status_; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { | 547 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { |
548 // Src exists and is a file. Dest is a directory. | 548 // Src exists and is a file. Dest is a directory. |
549 FileSystemURL src_file(CreateFile("src")); | 549 FileSystemURL src_file(CreateFile("src")); |
550 FileSystemURL dest_dir(CreateDirectory("dest")); | 550 FileSystemURL dest_dir(CreateDirectory("dest")); |
551 | 551 |
552 operation_runner()->Copy(src_file, dest_dir, | 552 operation_runner()->Copy(src_file, dest_dir, |
553 FileSystemOperation::OPTION_NONE, | 553 FileSystemOperation::OPTION_NONE, |
554 FileSystemOperationRunner::CopyProgressCallback(), | 554 FileSystemOperationRunner::CopyProgressCallback(), |
555 RecordStatusCallback()); | 555 RecordStatusCallback()); |
556 base::RunLoop().RunUntilIdle(); | 556 base::RunLoop().RunUntilIdle(); |
557 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()); | |
558 EXPECT_TRUE(change_observer()->HasNoChange()); | 562 EXPECT_TRUE(change_observer()->HasNoChange()); |
559 } | 563 } |
560 | 564 |
561 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { | 565 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { |
562 // Dest. parent path does not exist. | 566 // Dest. parent path does not exist. |
563 FileSystemURL src_dir(CreateDirectory("src")); | 567 FileSystemURL src_dir(CreateDirectory("src")); |
564 | 568 |
565 operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), | 569 operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), |
566 FileSystemOperation::OPTION_NONE, | 570 FileSystemOperation::OPTION_NONE, |
567 FileSystemOperationRunner::CopyProgressCallback(), | 571 FileSystemOperationRunner::CopyProgressCallback(), |
(...skipping 30 matching lines...) Expand all Loading... | |
598 FileSystemURL src_file(CreateFile("src")); | 602 FileSystemURL src_file(CreateFile("src")); |
599 FileSystemURL dest_file(CreateFile("dest")); | 603 FileSystemURL dest_file(CreateFile("dest")); |
600 | 604 |
601 operation_runner()->Copy(src_file, dest_file, | 605 operation_runner()->Copy(src_file, dest_file, |
602 FileSystemOperation::OPTION_NONE, | 606 FileSystemOperation::OPTION_NONE, |
603 FileSystemOperationRunner::CopyProgressCallback(), | 607 FileSystemOperationRunner::CopyProgressCallback(), |
604 RecordStatusCallback()); | 608 RecordStatusCallback()); |
605 base::RunLoop().RunUntilIdle(); | 609 base::RunLoop().RunUntilIdle(); |
606 EXPECT_EQ(base::File::FILE_OK, status()); | 610 EXPECT_EQ(base::File::FILE_OK, status()); |
607 EXPECT_TRUE(FileExists("dest")); | 611 EXPECT_TRUE(FileExists("dest")); |
608 EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count()); | 612 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); |
609 | 613 |
610 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | |
611 EXPECT_TRUE(change_observer()->HasNoChange()); | 614 EXPECT_TRUE(change_observer()->HasNoChange()); |
612 } | 615 } |
613 | 616 |
614 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { | 617 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { |
615 FileSystemURL src_file(CreateFile("src")); | 618 FileSystemURL src_file(CreateFile("src")); |
616 | 619 |
617 operation_runner()->Copy(src_file, URLForPath("new"), | 620 operation_runner()->Copy(src_file, URLForPath("new"), |
618 FileSystemOperation::OPTION_NONE, | 621 FileSystemOperation::OPTION_NONE, |
619 FileSystemOperationRunner::CopyProgressCallback(), | 622 FileSystemOperationRunner::CopyProgressCallback(), |
620 RecordStatusCallback()); | 623 RecordStatusCallback()); |
621 base::RunLoop().RunUntilIdle(); | 624 base::RunLoop().RunUntilIdle(); |
622 EXPECT_EQ(base::File::FILE_OK, status()); | 625 EXPECT_EQ(base::File::FILE_OK, status()); |
623 EXPECT_TRUE(FileExists("new")); | 626 EXPECT_TRUE(FileExists("new")); |
624 EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count()); | 627 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); |
625 | 628 |
626 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 629 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
627 EXPECT_TRUE(change_observer()->HasNoChange()); | 630 EXPECT_TRUE(change_observer()->HasNoChange()); |
628 } | 631 } |
629 | 632 |
630 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { | 633 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { |
631 FileSystemURL src_dir(CreateDirectory("src")); | 634 FileSystemURL src_dir(CreateDirectory("src")); |
632 FileSystemURL dest_dir(CreateDirectory("dest")); | 635 FileSystemURL dest_dir(CreateDirectory("dest")); |
633 | 636 |
634 operation_runner()->Copy(src_dir, dest_dir, | 637 operation_runner()->Copy(src_dir, dest_dir, |
635 FileSystemOperation::OPTION_NONE, | 638 FileSystemOperation::OPTION_NONE, |
636 FileSystemOperationRunner::CopyProgressCallback(), | 639 FileSystemOperationRunner::CopyProgressCallback(), |
637 RecordStatusCallback()); | 640 RecordStatusCallback()); |
638 base::RunLoop().RunUntilIdle(); | 641 base::RunLoop().RunUntilIdle(); |
639 EXPECT_EQ(base::File::FILE_OK, status()); | 642 EXPECT_EQ(base::File::FILE_OK, status()); |
640 | 643 |
641 // 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|. |
642 EXPECT_TRUE(DirectoryExists("dest")); | 645 EXPECT_TRUE(DirectoryExists("dest")); |
643 EXPECT_FALSE(DirectoryExists("dest/src")); | 646 EXPECT_FALSE(DirectoryExists("dest/src")); |
644 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); | 647 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); |
645 | 648 |
649 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | |
646 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 650 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
647 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | |
648 EXPECT_TRUE(change_observer()->HasNoChange()); | 651 EXPECT_TRUE(change_observer()->HasNoChange()); |
649 } | 652 } |
650 | 653 |
651 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { | 654 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { |
652 FileSystemURL src_dir(CreateDirectory("src")); | 655 FileSystemURL src_dir(CreateDirectory("src")); |
653 FileSystemURL dest_dir_new(URLForPath("dest")); | 656 FileSystemURL dest_dir_new(URLForPath("dest")); |
654 | 657 |
655 operation_runner()->Copy(src_dir, dest_dir_new, | 658 operation_runner()->Copy(src_dir, dest_dir_new, |
656 FileSystemOperation::OPTION_NONE, | 659 FileSystemOperation::OPTION_NONE, |
657 FileSystemOperationRunner::CopyProgressCallback(), | 660 FileSystemOperationRunner::CopyProgressCallback(), |
(...skipping 20 matching lines...) Expand all Loading... | |
678 RecordStatusCallback()); | 681 RecordStatusCallback()); |
679 base::RunLoop().RunUntilIdle(); | 682 base::RunLoop().RunUntilIdle(); |
680 | 683 |
681 EXPECT_EQ(base::File::FILE_OK, status()); | 684 EXPECT_EQ(base::File::FILE_OK, status()); |
682 EXPECT_TRUE(DirectoryExists("dest/dir")); | 685 EXPECT_TRUE(DirectoryExists("dest/dir")); |
683 EXPECT_TRUE(FileExists("dest/dir/sub")); | 686 EXPECT_TRUE(FileExists("dest/dir/sub")); |
684 | 687 |
685 // For recursive copy we may record multiple read access. | 688 // For recursive copy we may record multiple read access. |
686 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); | 689 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); |
687 | 690 |
691 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | |
688 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 692 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
689 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 693 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
690 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | |
691 EXPECT_TRUE(change_observer()->HasNoChange()); | 694 EXPECT_TRUE(change_observer()->HasNoChange()); |
692 } | 695 } |
693 | 696 |
694 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { | 697 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { |
695 FileSystemURL src_dir(CreateDirectory("src")); | 698 FileSystemURL src_dir(CreateDirectory("src")); |
696 CreateDirectory("src/dir"); | 699 CreateDirectory("src/dir"); |
697 CreateFile("src/dir/sub"); | 700 CreateFile("src/dir/sub"); |
698 | 701 |
699 operation_runner()->Copy(src_dir, src_dir, | 702 operation_runner()->Copy(src_dir, src_dir, |
700 FileSystemOperation::OPTION_NONE, | 703 FileSystemOperation::OPTION_NONE, |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1282 base::RunLoop().RunUntilIdle(); | 1285 base::RunLoop().RunUntilIdle(); |
1283 | 1286 |
1284 expected_usage += grandchild_file_size + grandchild_path_cost; | 1287 expected_usage += grandchild_file_size + grandchild_path_cost; |
1285 usage = GetUsage(); | 1288 usage = GetUsage(); |
1286 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, | 1289 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, |
1287 GetDataSizeOnDisk()); | 1290 GetDataSizeOnDisk()); |
1288 EXPECT_EQ(expected_usage, usage); | 1291 EXPECT_EQ(expected_usage, usage); |
1289 } | 1292 } |
1290 | 1293 |
1291 } // namespace content | 1294 } // namespace content |
OLD | NEW |