mock_remote_file_sync_service.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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 "googleurl/src/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_MANUAL) { 23 typedef MockRemoteFileSyncService self; 24 ON_CALL(*this, AddServiceObserver(_)) 25 .WillByDefault(Invoke(this, &self::AddServiceObserverStub)); 26 ON_CALL(*this, AddFileStatusObserver(_)) 27 .WillByDefault(Invoke(this, &self::AddFileStatusObserverStub)); 28 ON_CALL(*this, RegisterOriginForTrackingChanges(_, _)) 29 .WillByDefault(Invoke(this, &self::RegisterOriginForTrackingChangesStub)); 30 ON_CALL(*this, UnregisterOriginForTrackingChanges(_, _)) 31 .WillByDefault( 32 Invoke(this, &self::UnregisterOriginForTrackingChangesStub)); 33 ON_CALL(*this, UninstallOrigin(_, _)) 34 .WillByDefault( 35 Invoke(this, &self::DeleteOriginDirectoryStub)); 36 ON_CALL(*this, ProcessRemoteChange(_)) 37 .WillByDefault(Invoke(this, &self::ProcessRemoteChangeStub)); 38 ON_CALL(*this, GetLocalChangeProcessor()) 39 .WillByDefault(Return(&mock_local_change_processor_)); 40 ON_CALL(*this, IsConflicting(_)) 41 .WillByDefault(Return(false)); 42 ON_CALL(*this, GetCurrentState()) 43 .WillByDefault(Return(REMOTE_SERVICE_OK)); 44 ON_CALL(*this, SetConflictResolutionPolicy(_)) 45 .WillByDefault(Invoke(this, &self::SetConflictResolutionPolicyStub)); 46 ON_CALL(*this, GetConflictResolutionPolicy()) 47 .WillByDefault(Invoke(this, &self::GetConflictResolutionPolicyStub)); 48} 49 50MockRemoteFileSyncService::~MockRemoteFileSyncService() { 51} 52 53void MockRemoteFileSyncService::NotifyRemoteChangeQueueUpdated( 54 int64 pending_changes) { 55 FOR_EACH_OBSERVER(Observer, service_observers_, 56 OnRemoteChangeQueueUpdated(pending_changes)); 57} 58 59void MockRemoteFileSyncService::NotifyRemoteServiceStateUpdated( 60 RemoteServiceState state, 61 const std::string& description) { 62 FOR_EACH_OBSERVER(Observer, service_observers_, 63 OnRemoteServiceStateUpdated(state, description)); 64} 65 66void MockRemoteFileSyncService::NotifyFileStatusChanged( 67 const fileapi::FileSystemURL& url, 68 SyncFileStatus sync_status, 69 SyncAction action_taken, 70 SyncDirection direction) { 71 FOR_EACH_OBSERVER(FileStatusObserver, file_status_observers_, 72 OnFileStatusChanged(url, sync_status, 73 action_taken, direction)); 74} 75 76void MockRemoteFileSyncService::AddServiceObserverStub(Observer* observer) { 77 service_observers_.AddObserver(observer); 78} 79 80void MockRemoteFileSyncService::AddFileStatusObserverStub( 81 FileStatusObserver* observer) { 82 file_status_observers_.AddObserver(observer); 83} 84 85void MockRemoteFileSyncService::RegisterOriginForTrackingChangesStub( 86 const GURL& origin, 87 const SyncStatusCallback& callback) { 88 base::MessageLoopProxy::current()->PostTask( 89 FROM_HERE, 90 base::Bind(callback, SYNC_STATUS_OK)); 91} 92 93void MockRemoteFileSyncService::UnregisterOriginForTrackingChangesStub( 94 const GURL& origin, 95 const SyncStatusCallback& callback) { 96 base::MessageLoopProxy::current()->PostTask( 97 FROM_HERE, 98 base::Bind(callback, SYNC_STATUS_OK)); 99} 100 101void MockRemoteFileSyncService::DeleteOriginDirectoryStub( 102 const GURL& origin, 103 const SyncStatusCallback& callback) { 104 base::MessageLoopProxy::current()->PostTask( 105 FROM_HERE, 106 base::Bind(callback, SYNC_STATUS_OK)); 107} 108 109void MockRemoteFileSyncService::ProcessRemoteChangeStub( 110 const SyncFileCallback& callback) { 111 base::MessageLoopProxy::current()->PostTask( 112 FROM_HERE, 113 base::Bind(callback, SYNC_STATUS_NO_CHANGE_TO_SYNC, 114 fileapi::FileSystemURL())); 115} 116 117SyncStatusCode MockRemoteFileSyncService::SetConflictResolutionPolicyStub( 118 ConflictResolutionPolicy policy) { 119 conflict_resolution_policy_ = policy; 120 return SYNC_STATUS_OK; 121} 122 123ConflictResolutionPolicy 124MockRemoteFileSyncService::GetConflictResolutionPolicyStub() const { 125 return conflict_resolution_policy_; 126} 127 128} // namespace sync_file_system 129