Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: chrome/browser/sync_file_system/local/local_file_sync_context_unittest.cc

Issue 492873002: Collapse fileapi, webkit_blob, webkit_database, quota, and webkit_common namespaces into single sto… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos build Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 14 matching lines...) Expand all
25 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" 25 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h"
26 #include "third_party/leveldatabase/src/include/leveldb/env.h" 26 #include "third_party/leveldatabase/src/include/leveldb/env.h"
27 #include "webkit/browser/fileapi/file_system_context.h" 27 #include "webkit/browser/fileapi/file_system_context.h"
28 #include "webkit/browser/fileapi/file_system_operation_runner.h" 28 #include "webkit/browser/fileapi/file_system_operation_runner.h"
29 #include "webkit/browser/fileapi/isolated_context.h" 29 #include "webkit/browser/fileapi/isolated_context.h"
30 #include "webkit/common/blob/scoped_file.h" 30 #include "webkit/common/blob/scoped_file.h"
31 31
32 #define FPL FILE_PATH_LITERAL 32 #define FPL FILE_PATH_LITERAL
33 33
34 using content::BrowserThread; 34 using content::BrowserThread;
35 using fileapi::FileSystemContext; 35 using storage::FileSystemContext;
36 using fileapi::FileSystemURL; 36 using storage::FileSystemURL;
37 using fileapi::FileSystemURLSet; 37 using storage::FileSystemURLSet;
38 38
39 // This tests LocalFileSyncContext behavior in multi-thread / 39 // This tests LocalFileSyncContext behavior in multi-thread /
40 // multi-file-system-context environment. 40 // multi-file-system-context environment.
41 // Basic combined tests (single-thread / single-file-system-context) 41 // Basic combined tests (single-thread / single-file-system-context)
42 // that involve LocalFileSyncContext are also in 42 // that involve LocalFileSyncContext are also in
43 // syncable_file_system_unittests.cc. 43 // syncable_file_system_unittests.cc.
44 44
45 namespace sync_file_system { 45 namespace sync_file_system {
46 46
47 namespace { 47 namespace {
(...skipping 26 matching lines...) Expand all
74 74
75 virtual void TearDown() OVERRIDE { 75 virtual void TearDown() OVERRIDE {
76 RevokeSyncableFileSystem(); 76 RevokeSyncableFileSystem();
77 } 77 }
78 78
79 void StartPrepareForSync(FileSystemContext* file_system_context, 79 void StartPrepareForSync(FileSystemContext* file_system_context,
80 const FileSystemURL& url, 80 const FileSystemURL& url,
81 LocalFileSyncContext::SyncMode sync_mode, 81 LocalFileSyncContext::SyncMode sync_mode,
82 SyncFileMetadata* metadata, 82 SyncFileMetadata* metadata,
83 FileChangeList* changes, 83 FileChangeList* changes,
84 webkit_blob::ScopedFile* snapshot) { 84 storage::ScopedFile* snapshot) {
85 ASSERT_TRUE(changes != NULL); 85 ASSERT_TRUE(changes != NULL);
86 ASSERT_FALSE(has_inflight_prepare_for_sync_); 86 ASSERT_FALSE(has_inflight_prepare_for_sync_);
87 status_ = SYNC_STATUS_UNKNOWN; 87 status_ = SYNC_STATUS_UNKNOWN;
88 has_inflight_prepare_for_sync_ = true; 88 has_inflight_prepare_for_sync_ = true;
89 sync_context_->PrepareForSync( 89 sync_context_->PrepareForSync(
90 file_system_context, 90 file_system_context,
91 url, 91 url,
92 sync_mode, 92 sync_mode,
93 base::Bind(&LocalFileSyncContextTest::DidPrepareForSync, 93 base::Bind(&LocalFileSyncContextTest::DidPrepareForSync,
94 base::Unretained(this), metadata, changes, snapshot)); 94 base::Unretained(this), metadata, changes, snapshot));
95 } 95 }
96 96
97 SyncStatusCode PrepareForSync(FileSystemContext* file_system_context, 97 SyncStatusCode PrepareForSync(FileSystemContext* file_system_context,
98 const FileSystemURL& url, 98 const FileSystemURL& url,
99 LocalFileSyncContext::SyncMode sync_mode, 99 LocalFileSyncContext::SyncMode sync_mode,
100 SyncFileMetadata* metadata, 100 SyncFileMetadata* metadata,
101 FileChangeList* changes, 101 FileChangeList* changes,
102 webkit_blob::ScopedFile* snapshot) { 102 storage::ScopedFile* snapshot) {
103 StartPrepareForSync(file_system_context, url, sync_mode, 103 StartPrepareForSync(file_system_context, url, sync_mode,
104 metadata, changes, snapshot); 104 metadata, changes, snapshot);
105 base::MessageLoop::current()->Run(); 105 base::MessageLoop::current()->Run();
106 return status_; 106 return status_;
107 } 107 }
108 108
109 base::Closure GetPrepareForSyncClosure( 109 base::Closure GetPrepareForSyncClosure(
110 FileSystemContext* file_system_context, 110 FileSystemContext* file_system_context,
111 const FileSystemURL& url, 111 const FileSystemURL& url,
112 LocalFileSyncContext::SyncMode sync_mode, 112 LocalFileSyncContext::SyncMode sync_mode,
113 SyncFileMetadata* metadata, 113 SyncFileMetadata* metadata,
114 FileChangeList* changes, 114 FileChangeList* changes,
115 webkit_blob::ScopedFile* snapshot) { 115 storage::ScopedFile* snapshot) {
116 return base::Bind(&LocalFileSyncContextTest::StartPrepareForSync, 116 return base::Bind(&LocalFileSyncContextTest::StartPrepareForSync,
117 base::Unretained(this), 117 base::Unretained(this),
118 base::Unretained(file_system_context), 118 base::Unretained(file_system_context),
119 url, sync_mode, metadata, changes, snapshot); 119 url, sync_mode, metadata, changes, snapshot);
120 } 120 }
121 121
122 void DidPrepareForSync(SyncFileMetadata* metadata_out, 122 void DidPrepareForSync(SyncFileMetadata* metadata_out,
123 FileChangeList* changes_out, 123 FileChangeList* changes_out,
124 webkit_blob::ScopedFile* snapshot_out, 124 storage::ScopedFile* snapshot_out,
125 SyncStatusCode status, 125 SyncStatusCode status,
126 const LocalFileSyncInfo& sync_file_info, 126 const LocalFileSyncInfo& sync_file_info,
127 webkit_blob::ScopedFile snapshot) { 127 storage::ScopedFile snapshot) {
128 ASSERT_TRUE(ui_task_runner_->RunsTasksOnCurrentThread()); 128 ASSERT_TRUE(ui_task_runner_->RunsTasksOnCurrentThread());
129 has_inflight_prepare_for_sync_ = false; 129 has_inflight_prepare_for_sync_ = false;
130 status_ = status; 130 status_ = status;
131 *metadata_out = sync_file_info.metadata; 131 *metadata_out = sync_file_info.metadata;
132 *changes_out = sync_file_info.changes; 132 *changes_out = sync_file_info.changes;
133 if (snapshot_out) 133 if (snapshot_out)
134 *snapshot_out = snapshot.Pass(); 134 *snapshot_out = snapshot.Pass();
135 base::MessageLoop::current()->Quit(); 135 base::MessageLoop::current()->Quit();
136 } 136 }
137 137
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 ASSERT_EQ(SYNC_STATUS_OK, 292 ASSERT_EQ(SYNC_STATUS_OK,
293 file_system.MaybeInitializeFileSystemContext( 293 file_system.MaybeInitializeFileSystemContext(
294 sync_context_.get())); 294 sync_context_.get()));
295 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem()); 295 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem());
296 296
297 const FileSystemURL kFile(file_system.URL("file")); 297 const FileSystemURL kFile(file_system.URL("file"));
298 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile)); 298 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile));
299 299
300 SyncFileMetadata metadata; 300 SyncFileMetadata metadata;
301 FileChangeList changes; 301 FileChangeList changes;
302 webkit_blob::ScopedFile snapshot; 302 storage::ScopedFile snapshot;
303 EXPECT_EQ(SYNC_STATUS_OK, 303 EXPECT_EQ(SYNC_STATUS_OK,
304 PrepareForSync(file_system.file_system_context(), kFile, 304 PrepareForSync(file_system.file_system_context(), kFile,
305 sync_mode, &metadata, &changes, &snapshot)); 305 sync_mode, &metadata, &changes, &snapshot));
306 EXPECT_EQ(1U, changes.size()); 306 EXPECT_EQ(1U, changes.size());
307 EXPECT_TRUE(changes.list().back().IsFile()); 307 EXPECT_TRUE(changes.list().back().IsFile());
308 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); 308 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
309 309
310 EXPECT_EQ(sync_mode == LocalFileSyncContext::SYNC_SNAPSHOT, 310 EXPECT_EQ(sync_mode == LocalFileSyncContext::SYNC_SNAPSHOT,
311 !snapshot.path().empty()); 311 !snapshot.path().empty());
312 312
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 sync_context_ = new LocalFileSyncContext( 605 sync_context_ = new LocalFileSyncContext(
606 dir_.path(), in_memory_env_.get(), 606 dir_.path(), in_memory_env_.get(),
607 ui_task_runner_.get(), io_task_runner_.get()); 607 ui_task_runner_.get(), io_task_runner_.get());
608 ASSERT_EQ(SYNC_STATUS_OK, 608 ASSERT_EQ(SYNC_STATUS_OK,
609 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 609 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
610 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem()); 610 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem());
611 611
612 // Record the initial usage (likely 0). 612 // Record the initial usage (likely 0).
613 int64 initial_usage = -1; 613 int64 initial_usage = -1;
614 int64 quota = -1; 614 int64 quota = -1;
615 EXPECT_EQ(quota::kQuotaStatusOk, 615 EXPECT_EQ(storage::kQuotaStatusOk,
616 file_system.GetUsageAndQuota(&initial_usage, &quota)); 616 file_system.GetUsageAndQuota(&initial_usage, &quota));
617 617
618 // Create a file and directory in the file_system. 618 // Create a file and directory in the file_system.
619 const FileSystemURL kFile(file_system.URL("file")); 619 const FileSystemURL kFile(file_system.URL("file"));
620 const FileSystemURL kDir(file_system.URL("dir")); 620 const FileSystemURL kDir(file_system.URL("dir"));
621 const FileSystemURL kChild(file_system.URL("dir/child")); 621 const FileSystemURL kChild(file_system.URL("dir/child"));
622 622
623 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile)); 623 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile));
624 EXPECT_EQ(base::File::FILE_OK, file_system.CreateDirectory(kDir)); 624 EXPECT_EQ(base::File::FILE_OK, file_system.CreateDirectory(kDir));
625 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kChild)); 625 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kChild));
626 626
627 // file_system's change tracker must have recorded the creation. 627 // file_system's change tracker must have recorded the creation.
628 FileSystemURLSet urls; 628 FileSystemURLSet urls;
629 file_system.GetChangedURLsInTracker(&urls); 629 file_system.GetChangedURLsInTracker(&urls);
630 ASSERT_EQ(3U, urls.size()); 630 ASSERT_EQ(3U, urls.size());
631 ASSERT_TRUE(ContainsKey(urls, kFile)); 631 ASSERT_TRUE(ContainsKey(urls, kFile));
632 ASSERT_TRUE(ContainsKey(urls, kDir)); 632 ASSERT_TRUE(ContainsKey(urls, kDir));
633 ASSERT_TRUE(ContainsKey(urls, kChild)); 633 ASSERT_TRUE(ContainsKey(urls, kChild));
634 for (FileSystemURLSet::iterator iter = urls.begin(); 634 for (FileSystemURLSet::iterator iter = urls.begin();
635 iter != urls.end(); ++iter) { 635 iter != urls.end(); ++iter) {
636 file_system.ClearChangeForURLInTracker(*iter); 636 file_system.ClearChangeForURLInTracker(*iter);
637 } 637 }
638 638
639 // At this point the usage must be greater than the initial usage. 639 // At this point the usage must be greater than the initial usage.
640 int64 new_usage = -1; 640 int64 new_usage = -1;
641 EXPECT_EQ(quota::kQuotaStatusOk, 641 EXPECT_EQ(storage::kQuotaStatusOk,
642 file_system.GetUsageAndQuota(&new_usage, &quota)); 642 file_system.GetUsageAndQuota(&new_usage, &quota));
643 EXPECT_GT(new_usage, initial_usage); 643 EXPECT_GT(new_usage, initial_usage);
644 644
645 // Now let's apply remote deletion changes. 645 // Now let's apply remote deletion changes.
646 FileChange change(FileChange::FILE_CHANGE_DELETE, 646 FileChange change(FileChange::FILE_CHANGE_DELETE,
647 SYNC_FILE_TYPE_FILE); 647 SYNC_FILE_TYPE_FILE);
648 EXPECT_EQ(SYNC_STATUS_OK, 648 EXPECT_EQ(SYNC_STATUS_OK,
649 ApplyRemoteChange(file_system.file_system_context(), 649 ApplyRemoteChange(file_system.file_system_context(),
650 change, base::FilePath(), kFile, 650 change, base::FilePath(), kFile,
651 SYNC_FILE_TYPE_FILE)); 651 SYNC_FILE_TYPE_FILE));
(...skipping 15 matching lines...) Expand all
667 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, 667 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
668 file_system.FileExists(kChild)); 668 file_system.FileExists(kChild));
669 669
670 // The changes applied by ApplyRemoteChange should not be recorded in 670 // The changes applied by ApplyRemoteChange should not be recorded in
671 // the change tracker. 671 // the change tracker.
672 urls.clear(); 672 urls.clear();
673 file_system.GetChangedURLsInTracker(&urls); 673 file_system.GetChangedURLsInTracker(&urls);
674 EXPECT_TRUE(urls.empty()); 674 EXPECT_TRUE(urls.empty());
675 675
676 // The quota usage data must have reflected the deletion. 676 // The quota usage data must have reflected the deletion.
677 EXPECT_EQ(quota::kQuotaStatusOk, 677 EXPECT_EQ(storage::kQuotaStatusOk,
678 file_system.GetUsageAndQuota(&new_usage, &quota)); 678 file_system.GetUsageAndQuota(&new_usage, &quota));
679 EXPECT_EQ(new_usage, initial_usage); 679 EXPECT_EQ(new_usage, initial_usage);
680 680
681 sync_context_->ShutdownOnUIThread(); 681 sync_context_->ShutdownOnUIThread();
682 sync_context_ = NULL; 682 sync_context_ = NULL;
683 file_system.TearDown(); 683 file_system.TearDown();
684 } 684 }
685 685
686 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForDeletion_ForRoot) { 686 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForDeletion_ForRoot) {
687 CannedSyncableFileSystem file_system(GURL(kOrigin1), 687 CannedSyncableFileSystem file_system(GURL(kOrigin1),
688 in_memory_env_.get(), 688 in_memory_env_.get(),
689 io_task_runner_.get(), 689 io_task_runner_.get(),
690 file_task_runner_.get()); 690 file_task_runner_.get());
691 file_system.SetUp(CannedSyncableFileSystem::QUOTA_ENABLED); 691 file_system.SetUp(CannedSyncableFileSystem::QUOTA_ENABLED);
692 692
693 sync_context_ = new LocalFileSyncContext( 693 sync_context_ = new LocalFileSyncContext(
694 dir_.path(), in_memory_env_.get(), 694 dir_.path(), in_memory_env_.get(),
695 ui_task_runner_.get(), io_task_runner_.get()); 695 ui_task_runner_.get(), io_task_runner_.get());
696 ASSERT_EQ(SYNC_STATUS_OK, 696 ASSERT_EQ(SYNC_STATUS_OK,
697 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 697 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
698 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem()); 698 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem());
699 699
700 // Record the initial usage (likely 0). 700 // Record the initial usage (likely 0).
701 int64 initial_usage = -1; 701 int64 initial_usage = -1;
702 int64 quota = -1; 702 int64 quota = -1;
703 EXPECT_EQ(quota::kQuotaStatusOk, 703 EXPECT_EQ(storage::kQuotaStatusOk,
704 file_system.GetUsageAndQuota(&initial_usage, &quota)); 704 file_system.GetUsageAndQuota(&initial_usage, &quota));
705 705
706 // Create a file and directory in the file_system. 706 // Create a file and directory in the file_system.
707 const FileSystemURL kFile(file_system.URL("file")); 707 const FileSystemURL kFile(file_system.URL("file"));
708 const FileSystemURL kDir(file_system.URL("dir")); 708 const FileSystemURL kDir(file_system.URL("dir"));
709 const FileSystemURL kChild(file_system.URL("dir/child")); 709 const FileSystemURL kChild(file_system.URL("dir/child"));
710 710
711 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile)); 711 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile));
712 EXPECT_EQ(base::File::FILE_OK, file_system.CreateDirectory(kDir)); 712 EXPECT_EQ(base::File::FILE_OK, file_system.CreateDirectory(kDir));
713 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kChild)); 713 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kChild));
714 714
715 // At this point the usage must be greater than the initial usage. 715 // At this point the usage must be greater than the initial usage.
716 int64 new_usage = -1; 716 int64 new_usage = -1;
717 EXPECT_EQ(quota::kQuotaStatusOk, 717 EXPECT_EQ(storage::kQuotaStatusOk,
718 file_system.GetUsageAndQuota(&new_usage, &quota)); 718 file_system.GetUsageAndQuota(&new_usage, &quota));
719 EXPECT_GT(new_usage, initial_usage); 719 EXPECT_GT(new_usage, initial_usage);
720 720
721 const FileSystemURL kRoot(file_system.URL("")); 721 const FileSystemURL kRoot(file_system.URL(""));
722 722
723 // Now let's apply remote deletion changes for the root. 723 // Now let's apply remote deletion changes for the root.
724 FileChange change(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_DIRECTORY); 724 FileChange change(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_DIRECTORY);
725 EXPECT_EQ(SYNC_STATUS_OK, 725 EXPECT_EQ(SYNC_STATUS_OK,
726 ApplyRemoteChange(file_system.file_system_context(), 726 ApplyRemoteChange(file_system.file_system_context(),
727 change, base::FilePath(), kRoot, 727 change, base::FilePath(), kRoot,
728 SYNC_FILE_TYPE_DIRECTORY)); 728 SYNC_FILE_TYPE_DIRECTORY));
729 729
730 // Check the directory/files are deleted successfully. 730 // Check the directory/files are deleted successfully.
731 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, 731 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
732 file_system.FileExists(kFile)); 732 file_system.FileExists(kFile));
733 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, 733 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
734 file_system.DirectoryExists(kDir)); 734 file_system.DirectoryExists(kDir));
735 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, 735 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
736 file_system.FileExists(kChild)); 736 file_system.FileExists(kChild));
737 737
738 // All changes made for the previous creation must have been also reset. 738 // All changes made for the previous creation must have been also reset.
739 FileSystemURLSet urls; 739 FileSystemURLSet urls;
740 file_system.GetChangedURLsInTracker(&urls); 740 file_system.GetChangedURLsInTracker(&urls);
741 EXPECT_TRUE(urls.empty()); 741 EXPECT_TRUE(urls.empty());
742 742
743 // The quota usage data must have reflected the deletion. 743 // The quota usage data must have reflected the deletion.
744 EXPECT_EQ(quota::kQuotaStatusOk, 744 EXPECT_EQ(storage::kQuotaStatusOk,
745 file_system.GetUsageAndQuota(&new_usage, &quota)); 745 file_system.GetUsageAndQuota(&new_usage, &quota));
746 EXPECT_EQ(new_usage, initial_usage); 746 EXPECT_EQ(new_usage, initial_usage);
747 747
748 sync_context_->ShutdownOnUIThread(); 748 sync_context_->ShutdownOnUIThread();
749 sync_context_ = NULL; 749 sync_context_ = NULL;
750 file_system.TearDown(); 750 file_system.TearDown();
751 } 751 }
752 752
753 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForAddOrUpdate) { 753 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForAddOrUpdate) {
754 base::ScopedTempDir temp_dir; 754 base::ScopedTempDir temp_dir;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData1) - 1), 800 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData1) - 1),
801 base::WriteFile(kFilePath1, kTestFileData1, 801 base::WriteFile(kFilePath1, kTestFileData1,
802 arraysize(kTestFileData1) - 1)); 802 arraysize(kTestFileData1) - 1));
803 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData2) - 1), 803 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData2) - 1),
804 base::WriteFile(kFilePath2, kTestFileData2, 804 base::WriteFile(kFilePath2, kTestFileData2,
805 arraysize(kTestFileData2) - 1)); 805 arraysize(kTestFileData2) - 1));
806 806
807 // Record the usage. 807 // Record the usage.
808 int64 usage = -1, new_usage = -1; 808 int64 usage = -1, new_usage = -1;
809 int64 quota = -1; 809 int64 quota = -1;
810 EXPECT_EQ(quota::kQuotaStatusOk, 810 EXPECT_EQ(storage::kQuotaStatusOk,
811 file_system.GetUsageAndQuota(&usage, &quota)); 811 file_system.GetUsageAndQuota(&usage, &quota));
812 812
813 // Here in the local filesystem we have: 813 // Here in the local filesystem we have:
814 // * kFile1 with kTestFileData0 814 // * kFile1 with kTestFileData0
815 // 815 //
816 // In the remote side let's assume we have: 816 // In the remote side let's assume we have:
817 // * kFile1 with kTestFileData1 817 // * kFile1 with kTestFileData1
818 // * kFile2 with kTestFileData2 818 // * kFile2 with kTestFileData2
819 // * kDir 819 // * kDir
820 // 820 //
821 // By calling ApplyChange's: 821 // By calling ApplyChange's:
822 // * kFile1 will be updated to have kTestFileData1 822 // * kFile1 will be updated to have kTestFileData1
823 // * kFile2 will be created 823 // * kFile2 will be created
824 // * kDir will be created 824 // * kDir will be created
825 825
826 // Apply the remote change to kFile1 (which will update the file). 826 // Apply the remote change to kFile1 (which will update the file).
827 FileChange change(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 827 FileChange change(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
828 SYNC_FILE_TYPE_FILE); 828 SYNC_FILE_TYPE_FILE);
829 EXPECT_EQ(SYNC_STATUS_OK, 829 EXPECT_EQ(SYNC_STATUS_OK,
830 ApplyRemoteChange(file_system.file_system_context(), 830 ApplyRemoteChange(file_system.file_system_context(),
831 change, kFilePath1, kFile1, 831 change, kFilePath1, kFile1,
832 SYNC_FILE_TYPE_FILE)); 832 SYNC_FILE_TYPE_FILE));
833 833
834 // Check if the usage has been increased by (kTestFileData1 - kTestFileData0). 834 // Check if the usage has been increased by (kTestFileData1 - kTestFileData0).
835 const int updated_size = 835 const int updated_size =
836 arraysize(kTestFileData1) - arraysize(kTestFileData0); 836 arraysize(kTestFileData1) - arraysize(kTestFileData0);
837 EXPECT_EQ(quota::kQuotaStatusOk, 837 EXPECT_EQ(storage::kQuotaStatusOk,
838 file_system.GetUsageAndQuota(&new_usage, &quota)); 838 file_system.GetUsageAndQuota(&new_usage, &quota));
839 EXPECT_EQ(updated_size, new_usage - usage); 839 EXPECT_EQ(updated_size, new_usage - usage);
840 840
841 // Apply remote changes to kFile2 and kDir (should create a file and 841 // Apply remote changes to kFile2 and kDir (should create a file and
842 // directory respectively). 842 // directory respectively).
843 // They are non-existent yet so their expected file type (the last 843 // They are non-existent yet so their expected file type (the last
844 // parameter of ApplyRemoteChange) are 844 // parameter of ApplyRemoteChange) are
845 // SYNC_FILE_TYPE_UNKNOWN. 845 // SYNC_FILE_TYPE_UNKNOWN.
846 change = FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 846 change = FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
847 SYNC_FILE_TYPE_FILE); 847 SYNC_FILE_TYPE_FILE);
(...skipping 26 matching lines...) Expand all
874 EXPECT_EQ(SYNC_STATUS_OK, 874 EXPECT_EQ(SYNC_STATUS_OK,
875 ApplyRemoteChange(file_system.file_system_context(), 875 ApplyRemoteChange(file_system.file_system_context(),
876 change, 876 change,
877 kFilePath1, 877 kFilePath1,
878 kDir, 878 kDir,
879 SYNC_FILE_TYPE_FILE)); 879 SYNC_FILE_TYPE_FILE));
880 880
881 // Creating a file/directory must have increased the usage more than 881 // Creating a file/directory must have increased the usage more than
882 // the size of kTestFileData2. 882 // the size of kTestFileData2.
883 new_usage = usage; 883 new_usage = usage;
884 EXPECT_EQ(quota::kQuotaStatusOk, 884 EXPECT_EQ(storage::kQuotaStatusOk,
885 file_system.GetUsageAndQuota(&new_usage, &quota)); 885 file_system.GetUsageAndQuota(&new_usage, &quota));
886 EXPECT_GT(new_usage, 886 EXPECT_GT(new_usage,
887 static_cast<int64>(usage + arraysize(kTestFileData2) - 1)); 887 static_cast<int64>(usage + arraysize(kTestFileData2) - 1));
888 888
889 // The changes applied by ApplyRemoteChange should not be recorded in 889 // The changes applied by ApplyRemoteChange should not be recorded in
890 // the change tracker. 890 // the change tracker.
891 urls.clear(); 891 urls.clear();
892 file_system.GetChangedURLsInTracker(&urls); 892 file_system.GetChangedURLsInTracker(&urls);
893 EXPECT_TRUE(urls.empty()); 893 EXPECT_TRUE(urls.empty());
894 894
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 950
951 // Make sure kDir and kFile are created by ApplyRemoteChange. 951 // Make sure kDir and kFile are created by ApplyRemoteChange.
952 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile)); 952 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile));
953 EXPECT_EQ(base::File::FILE_OK, file_system.DirectoryExists(kDir)); 953 EXPECT_EQ(base::File::FILE_OK, file_system.DirectoryExists(kDir));
954 954
955 sync_context_->ShutdownOnUIThread(); 955 sync_context_->ShutdownOnUIThread();
956 file_system.TearDown(); 956 file_system.TearDown();
957 } 957 }
958 958
959 } // namespace sync_file_system 959 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698