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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h" 6 7 #include <string> 8 9 #include "base/bind.h" 10 #include "base/location.h" 11 #include "base/message_loop/message_loop_proxy.h" 12 #include "url/gurl.h" 13 #include "webkit/browser/fileapi/file_system_url.h" 14 15 using ::testing::_; 16 using ::testing::Invoke; 17 using ::testing::Return; 18 19 namespace sync_file_system { 20 21 MockRemoteFileSyncService::MockRemoteFileSyncService() 22 : conflict_resolution_policy_(CONFLICT_RESOLUTION_POLICY_MANUAL), 23 state_(REMOTE_SERVICE_OK) { 24 typedef MockRemoteFileSyncService self; 25 ON_CALL(*this, AddServiceObserver(_)) 26 .WillByDefault(Invoke(this, &self::AddServiceObserverStub)); 27 ON_CALL(*this, AddFileStatusObserver(_)) 28 .WillByDefault(Invoke(this, &self::AddFileStatusObserverStub)); 29 ON_CALL(*this, RegisterOrigin(_, _)) 30 .WillByDefault(Invoke(this, &self::RegisterOriginStub)); 31 ON_CALL(*this, UninstallOrigin(_, _, _)) 32 .WillByDefault( 33 Invoke(this, &self::DeleteOriginDirectoryStub)); 34 ON_CALL(*this, ProcessRemoteChange(_)) 35 .WillByDefault(Invoke(this, &self::ProcessRemoteChangeStub)); 36 ON_CALL(*this, GetLocalChangeProcessor()) 37 .WillByDefault(Return(&mock_local_change_processor_)); 38 ON_CALL(*this, IsConflicting(_)) 39 .WillByDefault(Return(false)); 40 ON_CALL(*this, GetCurrentState()) 41 .WillByDefault(Invoke(this, &self::GetCurrentStateStub)); 42 ON_CALL(*this, SetConflictResolutionPolicy(_)) 43 .WillByDefault(Invoke(this, &self::SetConflictResolutionPolicyStub)); 44 ON_CALL(*this, GetConflictResolutionPolicy()) 45 .WillByDefault(Invoke(this, &self::GetConflictResolutionPolicyStub)); 46 } 47 48 MockRemoteFileSyncService::~MockRemoteFileSyncService() { 49 } 50 51 scoped_ptr<base::ListValue> MockRemoteFileSyncService::DumpFiles( 52 const GURL& origin) { 53 return scoped_ptr<base::ListValue>(); 54 } 55 56 scoped_ptr<base::ListValue> MockRemoteFileSyncService::DumpDatabase() { 57 return scoped_ptr<base::ListValue>(); 58 } 59 60 void MockRemoteFileSyncService::SetServiceState(RemoteServiceState state) { 61 state_ = state; 62 } 63 64 void MockRemoteFileSyncService::NotifyRemoteChangeQueueUpdated( 65 int64 pending_changes) { 66 FOR_EACH_OBSERVER(Observer, service_observers_, 67 OnRemoteChangeQueueUpdated(pending_changes)); 68 } 69 70 void MockRemoteFileSyncService::NotifyRemoteServiceStateUpdated( 71 RemoteServiceState state, 72 const std::string& description) { 73 FOR_EACH_OBSERVER(Observer, service_observers_, 74 OnRemoteServiceStateUpdated(state, description)); 75 } 76 77 void MockRemoteFileSyncService::NotifyFileStatusChanged( 78 const fileapi::FileSystemURL& url, 79 SyncFileStatus sync_status, 80 SyncAction action_taken, 81 SyncDirection direction) { 82 FOR_EACH_OBSERVER(FileStatusObserver, file_status_observers_, 83 OnFileStatusChanged(url, sync_status, 84 action_taken, direction)); 85 } 86 87 void MockRemoteFileSyncService::AddServiceObserverStub(Observer* observer) { 88 service_observers_.AddObserver(observer); 89 } 90 91 void MockRemoteFileSyncService::AddFileStatusObserverStub( 92 FileStatusObserver* observer) { 93 file_status_observers_.AddObserver(observer); 94 } 95 96 void MockRemoteFileSyncService::RegisterOriginStub( 97 const GURL& origin, 98 const SyncStatusCallback& callback) { 99 base::MessageLoopProxy::current()->PostTask( 100 FROM_HERE, 101 base::Bind(callback, SYNC_STATUS_OK)); 102 } 103 104 void MockRemoteFileSyncService::DeleteOriginDirectoryStub( 105 const GURL& origin, 106 UninstallFlag flag, 107 const SyncStatusCallback& callback) { 108 base::MessageLoopProxy::current()->PostTask( 109 FROM_HERE, 110 base::Bind(callback, SYNC_STATUS_OK)); 111 } 112 113 void MockRemoteFileSyncService::ProcessRemoteChangeStub( 114 const SyncFileCallback& callback) { 115 base::MessageLoopProxy::current()->PostTask( 116 FROM_HERE, 117 base::Bind(callback, SYNC_STATUS_NO_CHANGE_TO_SYNC, 118 fileapi::FileSystemURL())); 119 } 120 121 SyncStatusCode MockRemoteFileSyncService::SetConflictResolutionPolicyStub( 122 ConflictResolutionPolicy policy) { 123 conflict_resolution_policy_ = policy; 124 return SYNC_STATUS_OK; 125 } 126 127 ConflictResolutionPolicy 128 MockRemoteFileSyncService::GetConflictResolutionPolicyStub() const { 129 return conflict_resolution_policy_; 130 } 131 132 RemoteServiceState MockRemoteFileSyncService::GetCurrentStateStub() const { 133 return state_; 134 } 135 136 } // namespace sync_file_system 137