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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 namespace { | 43 namespace { |
44 | 44 |
45 const int kFileOperationStatusNotSet = 1; | 45 const int kFileOperationStatusNotSet = 1; |
46 | 46 |
47 void AssertFileErrorEq(const tracked_objects::Location& from_here, | 47 void AssertFileErrorEq(const tracked_objects::Location& from_here, |
48 base::File::Error expected, | 48 base::File::Error expected, |
49 base::File::Error actual) { | 49 base::File::Error actual) { |
50 ASSERT_EQ(expected, actual) << from_here.ToString(); | 50 ASSERT_EQ(expected, actual) << from_here.ToString(); |
51 } | 51 } |
52 | 52 |
53 void AssertFileErrorEqWithClosure(const tracked_objects::Location& from_here, | |
54 base::File::Error expected, | |
55 base::Closure closure, | |
56 base::File::Error actual) { | |
57 ASSERT_EQ(expected, actual) << from_here.ToString(); | |
58 closure.Run(); | |
59 } | |
60 | |
53 } // namespace | 61 } // namespace |
54 | 62 |
55 // Test class for FileSystemOperationImpl. | 63 // Test class for FileSystemOperationImpl. |
56 class FileSystemOperationImplTest | 64 class FileSystemOperationImplTest |
57 : public testing::Test { | 65 : public testing::Test { |
58 public: | 66 public: |
59 FileSystemOperationImplTest() | 67 FileSystemOperationImplTest() |
60 : status_(kFileOperationStatusNotSet), | 68 : status_(kFileOperationStatusNotSet), |
61 weak_factory_(this) {} | 69 weak_factory_(this) {} |
62 | 70 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 | 278 |
271 void AddQuota(int64 quota_delta) { | 279 void AddQuota(int64 quota_delta) { |
272 int64 quota; | 280 int64 quota; |
273 GetUsageAndQuota(NULL, "a); | 281 GetUsageAndQuota(NULL, "a); |
274 quota_manager()->SetQuota(sandbox_file_system_.origin(), | 282 quota_manager()->SetQuota(sandbox_file_system_.origin(), |
275 sandbox_file_system_.storage_type(), | 283 sandbox_file_system_.storage_type(), |
276 quota + quota_delta); | 284 quota + quota_delta); |
277 } | 285 } |
278 | 286 |
279 private: | 287 private: |
280 base::MessageLoop message_loop_; | 288 base::MessageLoopForIO message_loop_; |
281 scoped_refptr<QuotaManager> quota_manager_; | 289 scoped_refptr<QuotaManager> quota_manager_; |
282 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | 290 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; |
283 | 291 |
284 // Common temp base for nondestructive uses. | 292 // Common temp base for nondestructive uses. |
285 base::ScopedTempDir base_; | 293 base::ScopedTempDir base_; |
286 | 294 |
287 SandboxFileSystemTestHelper sandbox_file_system_; | 295 SandboxFileSystemTestHelper sandbox_file_system_; |
288 | 296 |
289 // For post-operation status. | 297 // For post-operation status. |
290 int status_; | 298 int status_; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { | 554 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { |
547 // Src exists and is a file. Dest is a directory. | 555 // Src exists and is a file. Dest is a directory. |
548 FileSystemURL src_file(CreateFile("src")); | 556 FileSystemURL src_file(CreateFile("src")); |
549 FileSystemURL dest_dir(CreateDirectory("dest")); | 557 FileSystemURL dest_dir(CreateDirectory("dest")); |
550 | 558 |
551 operation_runner()->Copy(src_file, dest_dir, | 559 operation_runner()->Copy(src_file, dest_dir, |
552 FileSystemOperation::OPTION_NONE, | 560 FileSystemOperation::OPTION_NONE, |
553 FileSystemOperationRunner::CopyProgressCallback(), | 561 FileSystemOperationRunner::CopyProgressCallback(), |
554 RecordStatusCallback()); | 562 RecordStatusCallback()); |
555 base::RunLoop().RunUntilIdle(); | 563 base::RunLoop().RunUntilIdle(); |
556 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status()); | 564 EXPECT_EQ(3, quota_manager_proxy()->notify_storage_accessed_count()); |
565 | |
566 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | |
567 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | |
tzik
2014/09/02 03:25:11
This looks strange to me. Why was a directory crea
iseki
2014/09/03 09:34:16
Done.
| |
568 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status()); | |
557 EXPECT_TRUE(change_observer()->HasNoChange()); | 569 EXPECT_TRUE(change_observer()->HasNoChange()); |
558 } | 570 } |
559 | 571 |
560 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { | 572 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { |
561 // Dest. parent path does not exist. | 573 // Dest. parent path does not exist. |
562 FileSystemURL src_dir(CreateDirectory("src")); | 574 FileSystemURL src_dir(CreateDirectory("src")); |
563 | 575 |
564 operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), | 576 operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), |
565 FileSystemOperation::OPTION_NONE, | 577 FileSystemOperation::OPTION_NONE, |
566 FileSystemOperationRunner::CopyProgressCallback(), | 578 FileSystemOperationRunner::CopyProgressCallback(), |
(...skipping 30 matching lines...) Expand all Loading... | |
597 FileSystemURL src_file(CreateFile("src")); | 609 FileSystemURL src_file(CreateFile("src")); |
598 FileSystemURL dest_file(CreateFile("dest")); | 610 FileSystemURL dest_file(CreateFile("dest")); |
599 | 611 |
600 operation_runner()->Copy(src_file, dest_file, | 612 operation_runner()->Copy(src_file, dest_file, |
601 FileSystemOperation::OPTION_NONE, | 613 FileSystemOperation::OPTION_NONE, |
602 FileSystemOperationRunner::CopyProgressCallback(), | 614 FileSystemOperationRunner::CopyProgressCallback(), |
603 RecordStatusCallback()); | 615 RecordStatusCallback()); |
604 base::RunLoop().RunUntilIdle(); | 616 base::RunLoop().RunUntilIdle(); |
605 EXPECT_EQ(base::File::FILE_OK, status()); | 617 EXPECT_EQ(base::File::FILE_OK, status()); |
606 EXPECT_TRUE(FileExists("dest")); | 618 EXPECT_TRUE(FileExists("dest")); |
607 EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count()); | 619 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); |
608 | 620 |
609 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | |
tzik
2014/09/02 03:25:10
We should get notified for the file modification.
iseki
2014/09/03 09:34:16
Done.
| |
610 EXPECT_TRUE(change_observer()->HasNoChange()); | 621 EXPECT_TRUE(change_observer()->HasNoChange()); |
611 } | 622 } |
612 | 623 |
613 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { | 624 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { |
614 FileSystemURL src_file(CreateFile("src")); | 625 FileSystemURL src_file(CreateFile("src")); |
615 | 626 |
616 operation_runner()->Copy(src_file, URLForPath("new"), | 627 operation_runner()->Copy(src_file, URLForPath("new"), |
617 FileSystemOperation::OPTION_NONE, | 628 FileSystemOperation::OPTION_NONE, |
618 FileSystemOperationRunner::CopyProgressCallback(), | 629 FileSystemOperationRunner::CopyProgressCallback(), |
619 RecordStatusCallback()); | 630 RecordStatusCallback()); |
620 base::RunLoop().RunUntilIdle(); | 631 base::RunLoop().RunUntilIdle(); |
621 EXPECT_EQ(base::File::FILE_OK, status()); | 632 EXPECT_EQ(base::File::FILE_OK, status()); |
622 EXPECT_TRUE(FileExists("new")); | 633 EXPECT_TRUE(FileExists("new")); |
623 EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count()); | 634 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); |
624 | 635 |
625 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 636 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
626 EXPECT_TRUE(change_observer()->HasNoChange()); | 637 EXPECT_TRUE(change_observer()->HasNoChange()); |
627 } | 638 } |
628 | 639 |
629 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { | 640 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { |
630 FileSystemURL src_dir(CreateDirectory("src")); | 641 FileSystemURL src_dir(CreateDirectory("src")); |
631 FileSystemURL dest_dir(CreateDirectory("dest")); | 642 FileSystemURL dest_dir(CreateDirectory("dest")); |
632 | 643 |
633 operation_runner()->Copy(src_dir, dest_dir, | 644 operation_runner()->Copy(src_dir, dest_dir, |
634 FileSystemOperation::OPTION_NONE, | 645 FileSystemOperation::OPTION_NONE, |
635 FileSystemOperationRunner::CopyProgressCallback(), | 646 FileSystemOperationRunner::CopyProgressCallback(), |
636 RecordStatusCallback()); | 647 RecordStatusCallback()); |
637 base::RunLoop().RunUntilIdle(); | 648 base::RunLoop().RunUntilIdle(); |
638 EXPECT_EQ(base::File::FILE_OK, status()); | 649 EXPECT_EQ(base::File::FILE_OK, status()); |
639 | 650 |
640 // Make sure we've overwritten but not copied the source under the |dest_dir|. | 651 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
641 EXPECT_TRUE(DirectoryExists("dest")); | 652 EXPECT_TRUE(DirectoryExists("dest")); |
642 EXPECT_FALSE(DirectoryExists("dest/src")); | 653 EXPECT_FALSE(DirectoryExists("dest/src")); |
643 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); | 654 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); |
644 | 655 |
656 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | |
645 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 657 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()); | 658 EXPECT_TRUE(change_observer()->HasNoChange()); |
648 } | 659 } |
649 | 660 |
650 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { | 661 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { |
651 FileSystemURL src_dir(CreateDirectory("src")); | 662 FileSystemURL src_dir(CreateDirectory("src")); |
652 FileSystemURL dest_dir_new(URLForPath("dest")); | 663 FileSystemURL dest_dir_new(URLForPath("dest")); |
653 | 664 |
654 operation_runner()->Copy(src_dir, dest_dir_new, | 665 operation_runner()->Copy(src_dir, dest_dir_new, |
655 FileSystemOperation::OPTION_NONE, | 666 FileSystemOperation::OPTION_NONE, |
656 FileSystemOperationRunner::CopyProgressCallback(), | 667 FileSystemOperationRunner::CopyProgressCallback(), |
(...skipping 20 matching lines...) Expand all Loading... | |
677 RecordStatusCallback()); | 688 RecordStatusCallback()); |
678 base::RunLoop().RunUntilIdle(); | 689 base::RunLoop().RunUntilIdle(); |
679 | 690 |
680 EXPECT_EQ(base::File::FILE_OK, status()); | 691 EXPECT_EQ(base::File::FILE_OK, status()); |
681 EXPECT_TRUE(DirectoryExists("dest/dir")); | 692 EXPECT_TRUE(DirectoryExists("dest/dir")); |
682 EXPECT_TRUE(FileExists("dest/dir/sub")); | 693 EXPECT_TRUE(FileExists("dest/dir/sub")); |
683 | 694 |
684 // For recursive copy we may record multiple read access. | 695 // For recursive copy we may record multiple read access. |
685 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); | 696 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); |
686 | 697 |
698 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | |
687 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 699 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
688 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 700 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()); | 701 EXPECT_TRUE(change_observer()->HasNoChange()); |
691 } | 702 } |
692 | 703 |
693 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { | 704 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { |
694 FileSystemURL src_dir(CreateDirectory("src")); | 705 FileSystemURL src_dir(CreateDirectory("src")); |
695 CreateDirectory("src/dir"); | 706 CreateDirectory("src/dir"); |
696 CreateFile("src/dir/sub"); | 707 CreateFile("src/dir/sub"); |
697 | 708 |
698 operation_runner()->Copy(src_dir, src_dir, | 709 operation_runner()->Copy(src_dir, src_dir, |
699 FileSystemOperation::OPTION_NONE, | 710 FileSystemOperation::OPTION_NONE, |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1250 | 1261 |
1251 const int64 child_file_size = 8000 + 700; | 1262 const int64 child_file_size = 8000 + 700; |
1252 const int64 grandchild_file_size = 60 + 5; | 1263 const int64 grandchild_file_size = 60 + 5; |
1253 const int64 all_file_size = child_file_size + grandchild_file_size; | 1264 const int64 all_file_size = child_file_size + grandchild_file_size; |
1254 int64 expected_usage = all_file_size + total_path_cost; | 1265 int64 expected_usage = all_file_size + total_path_cost; |
1255 | 1266 |
1256 usage = GetUsage(); | 1267 usage = GetUsage(); |
1257 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); | 1268 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); |
1258 EXPECT_EQ(expected_usage, usage); | 1269 EXPECT_EQ(expected_usage, usage); |
1259 | 1270 |
1271 base::RunLoop run_loop_for_dest1; | |
1260 // Copy src to dest1. | 1272 // Copy src to dest1. |
1261 operation_runner()->Copy( | 1273 operation_runner()->Copy( |
1262 src, dest1, FileSystemOperation::OPTION_NONE, | 1274 src, dest1, FileSystemOperation::OPTION_NONE, |
1263 FileSystemOperationRunner::CopyProgressCallback(), | 1275 FileSystemOperationRunner::CopyProgressCallback(), |
1264 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | 1276 base::Bind(&AssertFileErrorEqWithClosure, |
1265 base::RunLoop().RunUntilIdle(); | 1277 FROM_HERE, |
1278 base::File::FILE_OK, | |
1279 run_loop_for_dest1.QuitClosure())); | |
1280 run_loop_for_dest1.Run(); | |
1266 | 1281 |
1267 expected_usage += all_file_size + child_path_cost + grandchild_path_cost; | 1282 expected_usage += all_file_size + child_path_cost + grandchild_path_cost; |
1268 EXPECT_TRUE(DirectoryExists("src/dir")); | 1283 EXPECT_TRUE(DirectoryExists("src/dir")); |
1269 EXPECT_TRUE(FileExists("src/dir/file2")); | 1284 EXPECT_TRUE(FileExists("src/dir/file2")); |
1270 EXPECT_TRUE(DirectoryExists("dest1/dir")); | 1285 EXPECT_TRUE(DirectoryExists("dest1/dir")); |
1271 EXPECT_TRUE(FileExists("dest1/dir/file2")); | 1286 EXPECT_TRUE(FileExists("dest1/dir/file2")); |
1272 | 1287 |
1273 EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk()); | 1288 EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk()); |
1274 EXPECT_EQ(expected_usage, GetUsage()); | 1289 EXPECT_EQ(expected_usage, GetUsage()); |
1275 | 1290 |
1291 base::RunLoop run_loop_for_dest2; | |
tzik
2014/09/02 03:25:10
How about making a block scope for these RunLoops?
iseki
2014/09/03 09:34:16
Done.
| |
1276 // Copy src/dir to dest2. | 1292 // Copy src/dir to dest2. |
1277 operation_runner()->Copy( | 1293 operation_runner()->Copy( |
1278 child_dir, dest2, FileSystemOperation::OPTION_NONE, | 1294 child_dir, dest2, FileSystemOperation::OPTION_NONE, |
1279 FileSystemOperationRunner::CopyProgressCallback(), | 1295 FileSystemOperationRunner::CopyProgressCallback(), |
1280 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | 1296 base::Bind(&AssertFileErrorEqWithClosure, |
1281 base::RunLoop().RunUntilIdle(); | 1297 FROM_HERE, |
1298 base::File::FILE_OK, | |
1299 run_loop_for_dest2.QuitClosure())); | |
1300 run_loop_for_dest2.Run(); | |
1282 | 1301 |
1283 expected_usage += grandchild_file_size + grandchild_path_cost; | 1302 expected_usage += grandchild_file_size + grandchild_path_cost; |
1284 usage = GetUsage(); | 1303 usage = GetUsage(); |
1285 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, | 1304 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, |
1286 GetDataSizeOnDisk()); | 1305 GetDataSizeOnDisk()); |
1287 EXPECT_EQ(expected_usage, usage); | 1306 EXPECT_EQ(expected_usage, usage); |
1288 } | 1307 } |
1289 | 1308 |
1290 } // namespace content | 1309 } // namespace content |
OLD | NEW |