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( | 53 void AssertFileErrorEqWithClosure(const tracked_objects::Location& from_here, |
54 const tracked_objects::Location& from_here, | 54 base::File::Error expected, |
55 base::File::Error expected, | 55 base::Closure closure, |
56 base::Closure closure, | 56 base::File::Error actual) { |
57 base::File::Error actual) { | |
58 ASSERT_EQ(expected, actual) << from_here.ToString(); | 57 ASSERT_EQ(expected, actual) << from_here.ToString(); |
59 closure.Run(); | 58 closure.Run(); |
60 } | 59 } |
61 | 60 |
62 } // namespace | 61 } // namespace |
63 | 62 |
64 // Test class for FileSystemOperationImpl. | 63 // Test class for FileSystemOperationImpl. |
65 class FileSystemOperationImplTest | 64 class FileSystemOperationImplTest |
66 : public testing::Test { | 65 : public testing::Test { |
67 public: | 66 public: |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 278 |
280 void AddQuota(int64 quota_delta) { | 279 void AddQuota(int64 quota_delta) { |
281 int64 quota; | 280 int64 quota; |
282 GetUsageAndQuota(NULL, "a); | 281 GetUsageAndQuota(NULL, "a); |
283 quota_manager()->SetQuota(sandbox_file_system_.origin(), | 282 quota_manager()->SetQuota(sandbox_file_system_.origin(), |
284 sandbox_file_system_.storage_type(), | 283 sandbox_file_system_.storage_type(), |
285 quota + quota_delta); | 284 quota + quota_delta); |
286 } | 285 } |
287 | 286 |
288 private: | 287 private: |
289 base::MessageLoop message_loop_; | 288 base::MessageLoopForIO message_loop_; |
290 scoped_refptr<QuotaManager> quota_manager_; | 289 scoped_refptr<QuotaManager> quota_manager_; |
291 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | 290 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; |
292 | 291 |
293 // Common temp base for nondestructive uses. | 292 // Common temp base for nondestructive uses. |
294 base::ScopedTempDir base_; | 293 base::ScopedTempDir base_; |
295 | 294 |
296 SandboxFileSystemTestHelper sandbox_file_system_; | 295 SandboxFileSystemTestHelper sandbox_file_system_; |
297 | 296 |
298 // For post-operation status. | 297 // For post-operation status. |
299 int status_; | 298 int status_; |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 FileSystemURL dest_file(CreateFile("dest")); | 606 FileSystemURL dest_file(CreateFile("dest")); |
608 | 607 |
609 operation_runner()->Copy(src_file, dest_file, | 608 operation_runner()->Copy(src_file, dest_file, |
610 FileSystemOperation::OPTION_NONE, | 609 FileSystemOperation::OPTION_NONE, |
611 FileSystemOperationRunner::CopyProgressCallback(), | 610 FileSystemOperationRunner::CopyProgressCallback(), |
612 RecordStatusCallback()); | 611 RecordStatusCallback()); |
613 base::RunLoop().RunUntilIdle(); | 612 base::RunLoop().RunUntilIdle(); |
614 EXPECT_EQ(base::File::FILE_OK, status()); | 613 EXPECT_EQ(base::File::FILE_OK, status()); |
615 EXPECT_TRUE(FileExists("dest")); | 614 EXPECT_TRUE(FileExists("dest")); |
616 EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count()); | 615 EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count()); |
| 616 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
617 | 617 |
618 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | |
619 EXPECT_TRUE(change_observer()->HasNoChange()); | 618 EXPECT_TRUE(change_observer()->HasNoChange()); |
620 } | 619 } |
621 | 620 |
622 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { | 621 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { |
623 FileSystemURL src_file(CreateFile("src")); | 622 FileSystemURL src_file(CreateFile("src")); |
624 | 623 |
625 operation_runner()->Copy(src_file, URLForPath("new"), | 624 operation_runner()->Copy(src_file, URLForPath("new"), |
626 FileSystemOperation::OPTION_NONE, | 625 FileSystemOperation::OPTION_NONE, |
627 FileSystemOperationRunner::CopyProgressCallback(), | 626 FileSystemOperationRunner::CopyProgressCallback(), |
628 RecordStatusCallback()); | 627 RecordStatusCallback()); |
(...skipping 15 matching lines...) Expand all Loading... |
644 FileSystemOperationRunner::CopyProgressCallback(), | 643 FileSystemOperationRunner::CopyProgressCallback(), |
645 RecordStatusCallback()); | 644 RecordStatusCallback()); |
646 base::RunLoop().RunUntilIdle(); | 645 base::RunLoop().RunUntilIdle(); |
647 EXPECT_EQ(base::File::FILE_OK, status()); | 646 EXPECT_EQ(base::File::FILE_OK, status()); |
648 | 647 |
649 // Make sure we've overwritten but not copied the source under the |dest_dir|. | 648 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
650 EXPECT_TRUE(DirectoryExists("dest")); | 649 EXPECT_TRUE(DirectoryExists("dest")); |
651 EXPECT_FALSE(DirectoryExists("dest/src")); | 650 EXPECT_FALSE(DirectoryExists("dest/src")); |
652 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); | 651 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); |
653 | 652 |
| 653 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
654 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 654 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
655 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | |
656 EXPECT_TRUE(change_observer()->HasNoChange()); | 655 EXPECT_TRUE(change_observer()->HasNoChange()); |
657 } | 656 } |
658 | 657 |
659 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { | 658 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { |
660 FileSystemURL src_dir(CreateDirectory("src")); | 659 FileSystemURL src_dir(CreateDirectory("src")); |
661 FileSystemURL dest_dir_new(URLForPath("dest")); | 660 FileSystemURL dest_dir_new(URLForPath("dest")); |
662 | 661 |
663 operation_runner()->Copy(src_dir, dest_dir_new, | 662 operation_runner()->Copy(src_dir, dest_dir_new, |
664 FileSystemOperation::OPTION_NONE, | 663 FileSystemOperation::OPTION_NONE, |
665 FileSystemOperationRunner::CopyProgressCallback(), | 664 FileSystemOperationRunner::CopyProgressCallback(), |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 | 1258 |
1260 const int64 child_file_size = 8000 + 700; | 1259 const int64 child_file_size = 8000 + 700; |
1261 const int64 grandchild_file_size = 60 + 5; | 1260 const int64 grandchild_file_size = 60 + 5; |
1262 const int64 all_file_size = child_file_size + grandchild_file_size; | 1261 const int64 all_file_size = child_file_size + grandchild_file_size; |
1263 int64 expected_usage = all_file_size + total_path_cost; | 1262 int64 expected_usage = all_file_size + total_path_cost; |
1264 | 1263 |
1265 usage = GetUsage(); | 1264 usage = GetUsage(); |
1266 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); | 1265 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); |
1267 EXPECT_EQ(expected_usage, usage); | 1266 EXPECT_EQ(expected_usage, usage); |
1268 | 1267 |
1269 // Copy src to dest1. | 1268 { |
1270 operation_runner()->Copy( | 1269 base::RunLoop run_loop; |
1271 src, dest1, FileSystemOperation::OPTION_NONE, | 1270 // Copy src to dest1. |
1272 FileSystemOperationRunner::CopyProgressCallback(), | 1271 operation_runner()->Copy(src, |
1273 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | 1272 dest1, |
1274 base::RunLoop().RunUntilIdle(); | 1273 FileSystemOperation::OPTION_NONE, |
| 1274 FileSystemOperationRunner::CopyProgressCallback(), |
| 1275 base::Bind(&AssertFileErrorEqWithClosure, |
| 1276 FROM_HERE, |
| 1277 base::File::FILE_OK, |
| 1278 run_loop.QuitClosure())); |
| 1279 run_loop.Run(); |
| 1280 } |
1275 | 1281 |
1276 expected_usage += all_file_size + child_path_cost + grandchild_path_cost; | 1282 expected_usage += all_file_size + child_path_cost + grandchild_path_cost; |
1277 EXPECT_TRUE(DirectoryExists("src/dir")); | 1283 EXPECT_TRUE(DirectoryExists("src/dir")); |
1278 EXPECT_TRUE(FileExists("src/dir/file2")); | 1284 EXPECT_TRUE(FileExists("src/dir/file2")); |
1279 EXPECT_TRUE(DirectoryExists("dest1/dir")); | 1285 EXPECT_TRUE(DirectoryExists("dest1/dir")); |
1280 EXPECT_TRUE(FileExists("dest1/dir/file2")); | 1286 EXPECT_TRUE(FileExists("dest1/dir/file2")); |
1281 | 1287 |
1282 EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk()); | 1288 EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk()); |
1283 EXPECT_EQ(expected_usage, GetUsage()); | 1289 EXPECT_EQ(expected_usage, GetUsage()); |
1284 | 1290 |
1285 // Copy src/dir to dest2. | 1291 { |
1286 operation_runner()->Copy( | 1292 base::RunLoop run_loop; |
1287 child_dir, dest2, FileSystemOperation::OPTION_NONE, | 1293 // Copy src/dir to dest2. |
1288 FileSystemOperationRunner::CopyProgressCallback(), | 1294 operation_runner()->Copy(child_dir, |
1289 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); | 1295 dest2, |
1290 base::RunLoop().RunUntilIdle(); | 1296 FileSystemOperation::OPTION_NONE, |
| 1297 FileSystemOperationRunner::CopyProgressCallback(), |
| 1298 base::Bind(&AssertFileErrorEqWithClosure, |
| 1299 FROM_HERE, |
| 1300 base::File::FILE_OK, |
| 1301 run_loop.QuitClosure())); |
| 1302 run_loop.Run(); |
| 1303 } |
1291 | 1304 |
1292 expected_usage += grandchild_file_size + grandchild_path_cost; | 1305 expected_usage += grandchild_file_size + grandchild_path_cost; |
1293 usage = GetUsage(); | 1306 usage = GetUsage(); |
1294 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, | 1307 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, |
1295 GetDataSizeOnDisk()); | 1308 GetDataSizeOnDisk()); |
1296 EXPECT_EQ(expected_usage, usage); | 1309 EXPECT_EQ(expected_usage, usage); |
1297 } | 1310 } |
1298 | 1311 |
1299 TEST_F(FileSystemOperationImplTest, | 1312 TEST_F(FileSystemOperationImplTest, |
1300 TestCopySuccessSrcFileWithDifferentFileSize) { | 1313 TestCopySuccessSrcFileWithDifferentFileSize) { |
(...skipping 19 matching lines...) Expand all Loading... |
1320 base::Bind(&AssertFileErrorEqWithClosure, | 1333 base::Bind(&AssertFileErrorEqWithClosure, |
1321 FROM_HERE, | 1334 FROM_HERE, |
1322 base::File::FILE_OK, | 1335 base::File::FILE_OK, |
1323 run_loop.QuitClosure())); | 1336 run_loop.QuitClosure())); |
1324 run_loop.Run(); | 1337 run_loop.Run(); |
1325 } | 1338 } |
1326 EXPECT_EQ(0, GetFileSize("dest")); | 1339 EXPECT_EQ(0, GetFileSize("dest")); |
1327 } | 1340 } |
1328 | 1341 |
1329 } // namespace content | 1342 } // namespace content |
OLD | NEW |