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 "chrome/browser/sync_file_system/local/local_file_sync_context.h" | 5 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 // Opens the file_system, perform some operation and see if the change tracker | 403 // Opens the file_system, perform some operation and see if the change tracker |
404 // correctly captures the change. | 404 // correctly captures the change. |
405 EXPECT_EQ(base::File::FILE_OK, file_system.OpenFileSystem()); | 405 EXPECT_EQ(base::File::FILE_OK, file_system.OpenFileSystem()); |
406 | 406 |
407 const FileSystemURL kURL(file_system.URL("foo")); | 407 const FileSystemURL kURL(file_system.URL("foo")); |
408 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kURL)); | 408 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kURL)); |
409 | 409 |
410 FileSystemURLSet urls; | 410 FileSystemURLSet urls; |
411 file_system.GetChangedURLsInTracker(&urls); | 411 file_system.GetChangedURLsInTracker(&urls); |
412 ASSERT_EQ(1U, urls.size()); | 412 ASSERT_EQ(1U, urls.size()); |
413 EXPECT_TRUE(ContainsKey(urls, kURL)); | 413 EXPECT_TRUE(base::ContainsKey(urls, kURL)); |
414 | 414 |
415 // Finishing the test. | 415 // Finishing the test. |
416 sync_context_->ShutdownOnUIThread(); | 416 sync_context_->ShutdownOnUIThread(); |
417 file_system.TearDown(); | 417 file_system.TearDown(); |
418 } | 418 } |
419 | 419 |
420 TEST_F(LocalFileSyncContextTest, MultipleFileSystemContexts) { | 420 TEST_F(LocalFileSyncContextTest, MultipleFileSystemContexts) { |
421 CannedSyncableFileSystem file_system1(GURL(kOrigin1), | 421 CannedSyncableFileSystem file_system1(GURL(kOrigin1), |
422 in_memory_env_.get(), | 422 in_memory_env_.get(), |
423 io_task_runner_.get(), | 423 io_task_runner_.get(), |
(...skipping 21 matching lines...) Expand all Loading... |
445 const FileSystemURL kURL1(file_system1.URL("foo")); | 445 const FileSystemURL kURL1(file_system1.URL("foo")); |
446 const FileSystemURL kURL2(file_system2.URL("bar")); | 446 const FileSystemURL kURL2(file_system2.URL("bar")); |
447 | 447 |
448 // Creates a file in file_system1. | 448 // Creates a file in file_system1. |
449 EXPECT_EQ(base::File::FILE_OK, file_system1.CreateFile(kURL1)); | 449 EXPECT_EQ(base::File::FILE_OK, file_system1.CreateFile(kURL1)); |
450 | 450 |
451 // file_system1's tracker must have recorded the change. | 451 // file_system1's tracker must have recorded the change. |
452 FileSystemURLSet urls; | 452 FileSystemURLSet urls; |
453 file_system1.GetChangedURLsInTracker(&urls); | 453 file_system1.GetChangedURLsInTracker(&urls); |
454 ASSERT_EQ(1U, urls.size()); | 454 ASSERT_EQ(1U, urls.size()); |
455 EXPECT_TRUE(ContainsKey(urls, kURL1)); | 455 EXPECT_TRUE(base::ContainsKey(urls, kURL1)); |
456 | 456 |
457 // file_system1's tracker must have no change. | 457 // file_system1's tracker must have no change. |
458 urls.clear(); | 458 urls.clear(); |
459 file_system2.GetChangedURLsInTracker(&urls); | 459 file_system2.GetChangedURLsInTracker(&urls); |
460 ASSERT_TRUE(urls.empty()); | 460 ASSERT_TRUE(urls.empty()); |
461 | 461 |
462 // Creates a directory in file_system2. | 462 // Creates a directory in file_system2. |
463 EXPECT_EQ(base::File::FILE_OK, file_system2.CreateDirectory(kURL2)); | 463 EXPECT_EQ(base::File::FILE_OK, file_system2.CreateDirectory(kURL2)); |
464 | 464 |
465 // file_system1's tracker must have the change for kURL1 as before. | 465 // file_system1's tracker must have the change for kURL1 as before. |
466 urls.clear(); | 466 urls.clear(); |
467 file_system1.GetChangedURLsInTracker(&urls); | 467 file_system1.GetChangedURLsInTracker(&urls); |
468 ASSERT_EQ(1U, urls.size()); | 468 ASSERT_EQ(1U, urls.size()); |
469 EXPECT_TRUE(ContainsKey(urls, kURL1)); | 469 EXPECT_TRUE(base::ContainsKey(urls, kURL1)); |
470 | 470 |
471 // file_system2's tracker now must have the change for kURL2. | 471 // file_system2's tracker now must have the change for kURL2. |
472 urls.clear(); | 472 urls.clear(); |
473 file_system2.GetChangedURLsInTracker(&urls); | 473 file_system2.GetChangedURLsInTracker(&urls); |
474 ASSERT_EQ(1U, urls.size()); | 474 ASSERT_EQ(1U, urls.size()); |
475 EXPECT_TRUE(ContainsKey(urls, kURL2)); | 475 EXPECT_TRUE(base::ContainsKey(urls, kURL2)); |
476 | 476 |
477 SyncFileMetadata metadata; | 477 SyncFileMetadata metadata; |
478 FileChangeList changes; | 478 FileChangeList changes; |
479 EXPECT_EQ(SYNC_STATUS_OK, | 479 EXPECT_EQ(SYNC_STATUS_OK, |
480 PrepareForSync(file_system1.file_system_context(), kURL1, | 480 PrepareForSync(file_system1.file_system_context(), kURL1, |
481 LocalFileSyncContext::SYNC_EXCLUSIVE, | 481 LocalFileSyncContext::SYNC_EXCLUSIVE, |
482 &metadata, &changes, nullptr)); | 482 &metadata, &changes, nullptr)); |
483 EXPECT_EQ(1U, changes.size()); | 483 EXPECT_EQ(1U, changes.size()); |
484 EXPECT_TRUE(changes.list().back().IsFile()); | 484 EXPECT_TRUE(changes.list().back().IsFile()); |
485 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); | 485 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 const FileSystemURL kChild(file_system.URL("dir/child")); | 625 const FileSystemURL kChild(file_system.URL("dir/child")); |
626 | 626 |
627 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile)); | 627 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile)); |
628 EXPECT_EQ(base::File::FILE_OK, file_system.CreateDirectory(kDir)); | 628 EXPECT_EQ(base::File::FILE_OK, file_system.CreateDirectory(kDir)); |
629 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kChild)); | 629 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kChild)); |
630 | 630 |
631 // file_system's change tracker must have recorded the creation. | 631 // file_system's change tracker must have recorded the creation. |
632 FileSystemURLSet urls; | 632 FileSystemURLSet urls; |
633 file_system.GetChangedURLsInTracker(&urls); | 633 file_system.GetChangedURLsInTracker(&urls); |
634 ASSERT_EQ(3U, urls.size()); | 634 ASSERT_EQ(3U, urls.size()); |
635 ASSERT_TRUE(ContainsKey(urls, kFile)); | 635 ASSERT_TRUE(base::ContainsKey(urls, kFile)); |
636 ASSERT_TRUE(ContainsKey(urls, kDir)); | 636 ASSERT_TRUE(base::ContainsKey(urls, kDir)); |
637 ASSERT_TRUE(ContainsKey(urls, kChild)); | 637 ASSERT_TRUE(base::ContainsKey(urls, kChild)); |
638 for (FileSystemURLSet::iterator iter = urls.begin(); | 638 for (FileSystemURLSet::iterator iter = urls.begin(); |
639 iter != urls.end(); ++iter) { | 639 iter != urls.end(); ++iter) { |
640 file_system.ClearChangeForURLInTracker(*iter); | 640 file_system.ClearChangeForURLInTracker(*iter); |
641 } | 641 } |
642 | 642 |
643 // At this point the usage must be greater than the initial usage. | 643 // At this point the usage must be greater than the initial usage. |
644 int64_t new_usage = -1; | 644 int64_t new_usage = -1; |
645 EXPECT_EQ(storage::kQuotaStatusOk, | 645 EXPECT_EQ(storage::kQuotaStatusOk, |
646 file_system.GetUsageAndQuota(&new_usage, "a)); | 646 file_system.GetUsageAndQuota(&new_usage, "a)); |
647 EXPECT_GT(new_usage, initial_usage); | 647 EXPECT_GT(new_usage, initial_usage); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 // kFile2 and kDir are not there yet. | 787 // kFile2 and kDir are not there yet. |
788 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, | 788 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
789 file_system.FileExists(kFile2)); | 789 file_system.FileExists(kFile2)); |
790 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, | 790 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
791 file_system.DirectoryExists(kDir)); | 791 file_system.DirectoryExists(kDir)); |
792 | 792 |
793 // file_system's change tracker must have recorded the creation. | 793 // file_system's change tracker must have recorded the creation. |
794 FileSystemURLSet urls; | 794 FileSystemURLSet urls; |
795 file_system.GetChangedURLsInTracker(&urls); | 795 file_system.GetChangedURLsInTracker(&urls); |
796 ASSERT_EQ(1U, urls.size()); | 796 ASSERT_EQ(1U, urls.size()); |
797 EXPECT_TRUE(ContainsKey(urls, kFile1)); | 797 EXPECT_TRUE(base::ContainsKey(urls, kFile1)); |
798 file_system.ClearChangeForURLInTracker(*urls.begin()); | 798 file_system.ClearChangeForURLInTracker(*urls.begin()); |
799 | 799 |
800 // Prepare temporary files which represent the remote file data. | 800 // Prepare temporary files which represent the remote file data. |
801 const base::FilePath kFilePath1(temp_dir.path().Append(FPL("file1"))); | 801 const base::FilePath kFilePath1(temp_dir.path().Append(FPL("file1"))); |
802 const base::FilePath kFilePath2(temp_dir.path().Append(FPL("file2"))); | 802 const base::FilePath kFilePath2(temp_dir.path().Append(FPL("file2"))); |
803 | 803 |
804 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData1) - 1), | 804 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData1) - 1), |
805 base::WriteFile(kFilePath1, kTestFileData1, | 805 base::WriteFile(kFilePath1, kTestFileData1, |
806 arraysize(kTestFileData1) - 1)); | 806 arraysize(kTestFileData1) - 1)); |
807 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData2) - 1), | 807 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData2) - 1), |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 | 954 |
955 // Make sure kDir and kFile are created by ApplyRemoteChange. | 955 // Make sure kDir and kFile are created by ApplyRemoteChange. |
956 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile)); | 956 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile)); |
957 EXPECT_EQ(base::File::FILE_OK, file_system.DirectoryExists(kDir)); | 957 EXPECT_EQ(base::File::FILE_OK, file_system.DirectoryExists(kDir)); |
958 | 958 |
959 sync_context_->ShutdownOnUIThread(); | 959 sync_context_->ShutdownOnUIThread(); |
960 file_system.TearDown(); | 960 file_system.TearDown(); |
961 } | 961 } |
962 | 962 |
963 } // namespace sync_file_system | 963 } // namespace sync_file_system |
OLD | NEW |