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