mock_remote_file_sync_service.cc revision 58537e28ecd584eab876aee8be7156509866d23a
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 15using ::testing::_; 16using ::testing::Invoke; 17using ::testing::Return; 18 19namespace sync_file_system { 20 21MockRemoteFileSyncService::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 48MockRemoteFileSyncService::~MockRemoteFileSyncService() { 49} 50 51scoped_ptr<base::ListValue> MockRemoteFileSyncService::DumpFiles( 52 const GURL& origin) { 53 return scoped_ptr<base::ListValue>(); 54} 55 56void MockRemoteFileSyncService::SetServiceState(RemoteServiceState state) { 57 state_ = state; 58} 59 60void MockRemoteFileSyncService::NotifyRemoteChangeQueueUpdated( 61 int64 pending_changes) { 62 FOR_EACH_OBSERVER(Observer, service_observers_, 63 OnRemoteChangeQueueUpdated(pending_changes)); 64} 65 66void MockRemoteFileSyncService::NotifyRemoteServiceStateUpdated( 67 RemoteServiceState state, 68 const std::string& description) { 69 FOR_EACH_OBSERVER(Observer, service_observers_, 70 OnRemoteServiceStateUpdated(state, description)); 71} 72 73void MockRemoteFileSyncService::NotifyFileStatusChanged( 74 const fileapi::FileSystemURL& url, 75 SyncFileStatus sync_status, 76 SyncAction action_taken, 77 SyncDirection direction) { 78 FOR_EACH_OBSERVER(FileStatusObserver, file_status_observers_, 79 OnFileStatusChanged(url, sync_status, 80 action_taken, direction)); 81} 82 83void MockRemoteFileSyncService::AddServiceObserverStub(Observer* observer) { 84 service_observers_.AddObserver(observer); 85} 86 87void MockRemoteFileSyncService::AddFileStatusObserverStub( 88 FileStatusObserver* observer) { 89 file_status_observers_.AddObserver(observer); 90} 91 92void MockRemoteFileSyncService::RegisterOriginStub( 93 const GURL& origin, 94 const SyncStatusCallback& callback) { 95 base::MessageLoopProxy::current()->PostTask( 96 FROM_HERE, 97 base::Bind(callback, SYNC_STATUS_OK)); 98} 99 100void MockRemoteFileSyncService::DeleteOriginDirectoryStub( 101 const GURL& origin, 102 const SyncStatusCallback& callback) { 103 base::MessageLoopProxy::current()->PostTask( 104 FROM_HERE, 105 base::Bind(callback, SYNC_STATUS_OK)); 106} 107 108void MockRemoteFileSyncService::ProcessRemoteChangeStub( 109 const SyncFileCallback& callback) { 110 base::MessageLoopProxy::current()->PostTask( 111 FROM_HERE, 112 base::Bind(callback, SYNC_STATUS_NO_CHANGE_TO_SYNC, 113 fileapi::FileSystemURL())); 114} 115 116SyncStatusCode MockRemoteFileSyncService::SetConflictResolutionPolicyStub( 117 ConflictResolutionPolicy policy) { 118 conflict_resolution_policy_ = policy; 119 return SYNC_STATUS_OK; 120} 121 122ConflictResolutionPolicy 123MockRemoteFileSyncService::GetConflictResolutionPolicyStub() const { 124 return conflict_resolution_policy_; 125} 126 127RemoteServiceState MockRemoteFileSyncService::GetCurrentStateStub() const { 128 return state_; 129} 130 131} // namespace sync_file_system 132