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

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_service_unittest.cc

Issue 12304015: Migrated sync_file_status, sync_action and sync_direction from fileapi:: namespace to sync_file_sys… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/drive_file_sync_service.h" 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 const std::string& description)); 193 const std::string& description));
194 }; 194 };
195 195
196 class MockFileStatusObserver: public FileStatusObserver { 196 class MockFileStatusObserver: public FileStatusObserver {
197 public: 197 public:
198 MockFileStatusObserver() {} 198 MockFileStatusObserver() {}
199 virtual ~MockFileStatusObserver() {} 199 virtual ~MockFileStatusObserver() {}
200 200
201 MOCK_METHOD4(OnFileStatusChanged, 201 MOCK_METHOD4(OnFileStatusChanged,
202 void(const fileapi::FileSystemURL& url, 202 void(const fileapi::FileSystemURL& url,
203 fileapi::SyncFileStatus sync_status, 203 SyncFileStatus sync_status,
204 fileapi::SyncAction action_taken, 204 SyncAction action_taken,
205 fileapi::SyncDirection direction)); 205 SyncDirection direction));
206 }; 206 };
207 207
208 class DriveFileSyncServiceTest : public testing::Test { 208 class DriveFileSyncServiceTest : public testing::Test {
209 public: 209 public:
210 DriveFileSyncServiceTest() 210 DriveFileSyncServiceTest()
211 : ui_thread_(content::BrowserThread::UI, &message_loop_), 211 : ui_thread_(content::BrowserThread::UI, &message_loop_),
212 file_thread_(content::BrowserThread::FILE, &message_loop_), 212 file_thread_(content::BrowserThread::FILE, &message_loop_),
213 mock_drive_service_(NULL) { 213 mock_drive_service_(NULL) {
214 } 214 }
215 215
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 383 }
384 384
385 fileapi::FileSystemURL CreateURL(const GURL& origin, 385 fileapi::FileSystemURL CreateURL(const GURL& origin,
386 const base::FilePath::StringType& path) { 386 const base::FilePath::StringType& path) {
387 return fileapi::CreateSyncableFileSystemURL( 387 return fileapi::CreateSyncableFileSystemURL(
388 origin, kServiceName, base::FilePath(path)); 388 origin, kServiceName, base::FilePath(path));
389 } 389 }
390 390
391 void ProcessRemoteChange(fileapi::SyncStatusCode expected_status, 391 void ProcessRemoteChange(fileapi::SyncStatusCode expected_status,
392 const fileapi::FileSystemURL& expected_url, 392 const fileapi::FileSystemURL& expected_url,
393 fileapi::SyncFileStatus expected_sync_file_status, 393 SyncFileStatus expected_sync_file_status,
394 fileapi::SyncAction expected_sync_action, 394 SyncAction expected_sync_action,
395 fileapi::SyncDirection expected_sync_direction) { 395 SyncDirection expected_sync_direction) {
396 fileapi::SyncStatusCode actual_status = fileapi::SYNC_STATUS_UNKNOWN; 396 fileapi::SyncStatusCode actual_status = fileapi::SYNC_STATUS_UNKNOWN;
397 fileapi::FileSystemURL actual_url; 397 fileapi::FileSystemURL actual_url;
398 398
399 if (expected_sync_file_status != fileapi::SYNC_FILE_STATUS_UNKNOWN) { 399 if (expected_sync_file_status != SYNC_FILE_STATUS_UNKNOWN) {
400 EXPECT_CALL(*mock_file_status_observer(), 400 EXPECT_CALL(*mock_file_status_observer(),
401 OnFileStatusChanged(expected_url, 401 OnFileStatusChanged(expected_url,
402 expected_sync_file_status, 402 expected_sync_file_status,
403 expected_sync_action, 403 expected_sync_action,
404 expected_sync_direction)) 404 expected_sync_direction))
405 .Times(1); 405 .Times(1);
406 } 406 }
407 407
408 sync_service_->ProcessRemoteChange( 408 sync_service_->ProcessRemoteChange(
409 mock_remote_processor(), 409 mock_remote_processor(),
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 EXPECT_CALL(*mock_remote_observer(), 840 EXPECT_CALL(*mock_remote_observer(),
841 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) 841 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _))
842 .Times(AnyNumber()); 842 .Times(AnyNumber());
843 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) 843 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
844 .Times(AnyNumber()); 844 .Times(AnyNumber());
845 845
846 SetUpDriveSyncService(true); 846 SetUpDriveSyncService(true);
847 847
848 ProcessRemoteChange(fileapi::SYNC_STATUS_NO_CHANGE_TO_SYNC, 848 ProcessRemoteChange(fileapi::SYNC_STATUS_NO_CHANGE_TO_SYNC,
849 fileapi::FileSystemURL(), 849 fileapi::FileSystemURL(),
850 fileapi::SYNC_FILE_STATUS_UNKNOWN, 850 SYNC_FILE_STATUS_UNKNOWN,
851 fileapi::SYNC_ACTION_NONE, 851 SYNC_ACTION_NONE,
852 fileapi::SYNC_DIRECTION_NONE); 852 SYNC_DIRECTION_NONE);
853 EXPECT_TRUE(metadata_store()->batch_sync_origins().empty()); 853 EXPECT_TRUE(metadata_store()->batch_sync_origins().empty());
854 EXPECT_TRUE(metadata_store()->incremental_sync_origins().empty()); 854 EXPECT_TRUE(metadata_store()->incremental_sync_origins().empty());
855 EXPECT_TRUE(pending_changes().empty()); 855 EXPECT_TRUE(pending_changes().empty());
856 } 856 }
857 857
858 TEST_F(DriveFileSyncServiceTest, RemoteChange_Busy) { 858 TEST_F(DriveFileSyncServiceTest, RemoteChange_Busy) {
859 const GURL kOrigin("chrome-extension://example"); 859 const GURL kOrigin("chrome-extension://example");
860 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 860 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
861 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 861 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
862 const base::FilePath::StringType kFileName(FPL("File 1.mp3")); 862 const base::FilePath::StringType kFileName(FPL("File 1.mp3"));
(...skipping 17 matching lines...) Expand all
880 .WillOnce(InvokeCompletionCallback()); 880 .WillOnce(InvokeCompletionCallback());
881 881
882 SetUpDriveSyncService(true); 882 SetUpDriveSyncService(true);
883 883
884 scoped_ptr<ResourceEntry> entry(ResourceEntry::ExtractAndParse( 884 scoped_ptr<ResourceEntry> entry(ResourceEntry::ExtractAndParse(
885 *LoadJSONFile("gdata/file_entry.json"))); 885 *LoadJSONFile("gdata/file_entry.json")));
886 AppendIncrementalRemoteChangeByEntry(kOrigin, *entry, 12345); 886 AppendIncrementalRemoteChangeByEntry(kOrigin, *entry, 12345);
887 887
888 ProcessRemoteChange(fileapi::SYNC_STATUS_FILE_BUSY, 888 ProcessRemoteChange(fileapi::SYNC_STATUS_FILE_BUSY,
889 CreateURL(kOrigin, kFileName), 889 CreateURL(kOrigin, kFileName),
890 fileapi::SYNC_FILE_STATUS_UNKNOWN, 890 SYNC_FILE_STATUS_UNKNOWN,
891 fileapi::SYNC_ACTION_NONE, 891 SYNC_ACTION_NONE,
892 fileapi::SYNC_DIRECTION_NONE); 892 SYNC_DIRECTION_NONE);
893 } 893 }
894 894
895 TEST_F(DriveFileSyncServiceTest, RemoteChange_NewFile) { 895 TEST_F(DriveFileSyncServiceTest, RemoteChange_NewFile) {
896 const GURL kOrigin = ExtensionNameToGURL(FPL("example1")); 896 const GURL kOrigin = ExtensionNameToGURL(FPL("example1"));
897 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 897 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
898 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 898 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
899 const base::FilePath::StringType kFileName(FPL("File 1.mp3")); 899 const base::FilePath::StringType kFileName(FPL("File 1.mp3"));
900 const std::string kFileResourceId("file:2_file_resource_id"); 900 const std::string kFileResourceId("file:2_file_resource_id");
901 901
902 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 902 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
(...skipping 21 matching lines...) Expand all
924 .WillOnce(InvokeDidApplyRemoteChange()); 924 .WillOnce(InvokeDidApplyRemoteChange());
925 925
926 SetUpDriveSyncService(true); 926 SetUpDriveSyncService(true);
927 927
928 scoped_ptr<ResourceEntry> entry(ResourceEntry::ExtractAndParse( 928 scoped_ptr<ResourceEntry> entry(ResourceEntry::ExtractAndParse(
929 *LoadJSONFile("gdata/file_entry.json"))); 929 *LoadJSONFile("gdata/file_entry.json")));
930 AppendIncrementalRemoteChangeByEntry(kOrigin, *entry, 12345); 930 AppendIncrementalRemoteChangeByEntry(kOrigin, *entry, 12345);
931 931
932 ProcessRemoteChange(fileapi::SYNC_STATUS_OK, 932 ProcessRemoteChange(fileapi::SYNC_STATUS_OK,
933 CreateURL(kOrigin, kFileName), 933 CreateURL(kOrigin, kFileName),
934 fileapi::SYNC_FILE_STATUS_SYNCED, 934 SYNC_FILE_STATUS_SYNCED,
935 fileapi::SYNC_ACTION_ADDED, 935 SYNC_ACTION_ADDED,
936 fileapi::SYNC_DIRECTION_REMOTE_TO_LOCAL); 936 SYNC_DIRECTION_REMOTE_TO_LOCAL);
937 } 937 }
938 938
939 TEST_F(DriveFileSyncServiceTest, RemoteChange_UpdateFile) { 939 TEST_F(DriveFileSyncServiceTest, RemoteChange_UpdateFile) {
940 const GURL kOrigin = ExtensionNameToGURL(FPL("example1")); 940 const GURL kOrigin = ExtensionNameToGURL(FPL("example1"));
941 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 941 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
942 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 942 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
943 const base::FilePath::StringType kFileName(FPL("File 1.mp3")); 943 const base::FilePath::StringType kFileName(FPL("File 1.mp3"));
944 const std::string kFileResourceId("file:2_file_resource_id"); 944 const std::string kFileResourceId("file:2_file_resource_id");
945 945
946 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 946 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
(...skipping 20 matching lines...) Expand all
967 ApplyRemoteChange(_, _, CreateURL(kOrigin, kFileName), _)) 967 ApplyRemoteChange(_, _, CreateURL(kOrigin, kFileName), _))
968 .WillOnce(InvokeDidApplyRemoteChange()); 968 .WillOnce(InvokeDidApplyRemoteChange());
969 969
970 SetUpDriveSyncService(true); 970 SetUpDriveSyncService(true);
971 971
972 scoped_ptr<ResourceEntry> entry(ResourceEntry::ExtractAndParse( 972 scoped_ptr<ResourceEntry> entry(ResourceEntry::ExtractAndParse(
973 *LoadJSONFile("gdata/file_entry.json"))); 973 *LoadJSONFile("gdata/file_entry.json")));
974 AppendIncrementalRemoteChangeByEntry(kOrigin, *entry, 12345); 974 AppendIncrementalRemoteChangeByEntry(kOrigin, *entry, 12345);
975 ProcessRemoteChange(fileapi::SYNC_STATUS_OK, 975 ProcessRemoteChange(fileapi::SYNC_STATUS_OK,
976 CreateURL(kOrigin, kFileName), 976 CreateURL(kOrigin, kFileName),
977 fileapi::SYNC_FILE_STATUS_SYNCED, 977 SYNC_FILE_STATUS_SYNCED,
978 fileapi::SYNC_ACTION_UPDATED, 978 SYNC_ACTION_UPDATED,
979 fileapi::SYNC_DIRECTION_REMOTE_TO_LOCAL); 979 SYNC_DIRECTION_REMOTE_TO_LOCAL);
980 } 980 }
981 981
982 TEST_F(DriveFileSyncServiceTest, RegisterOriginWithSyncDisabled) { 982 TEST_F(DriveFileSyncServiceTest, RegisterOriginWithSyncDisabled) {
983 const GURL kOrigin("chrome-extension://example"); 983 const GURL kOrigin("chrome-extension://example");
984 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 984 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
985 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 985 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
986 986
987 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 987 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
988 988
989 EXPECT_CALL(*mock_remote_observer(), 989 EXPECT_CALL(*mock_remote_observer(),
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 kOrigin, kFilePath, true /* is_deleted */, 1077 kOrigin, kFilePath, true /* is_deleted */,
1078 kFileResourceId2, 7, "deleted_file_md5")); 1078 kFileResourceId2, 7, "deleted_file_md5"));
1079 EXPECT_TRUE(AppendIncrementalRemoteChange( 1079 EXPECT_TRUE(AppendIncrementalRemoteChange(
1080 kOrigin, kFilePath, false /* is_deleted */, 1080 kOrigin, kFilePath, false /* is_deleted */,
1081 kFileResourceId, 8, "updated_file_md5")); 1081 kFileResourceId, 8, "updated_file_md5"));
1082 } 1082 }
1083 1083
1084 #endif // !defined(OS_ANDROID) 1084 #endif // !defined(OS_ANDROID)
1085 1085
1086 } // namespace sync_file_system 1086 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/drive_file_sync_service.cc ('k') | chrome/browser/sync_file_system/file_status_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698