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.
5 #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h"
10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
14 #include "webkit/browser/fileapi/file_system_url.h"
17 using ::testing::Invoke;
18 using ::testing::Return;
20 namespace sync_file_system {
22 MockRemoteFileSyncService::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(_, _, _))
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));
43 MockRemoteFileSyncService::~MockRemoteFileSyncService() {
46 void MockRemoteFileSyncService::DumpFiles(const GURL& origin,
47 const ListCallback& callback) {
48 callback.Run(scoped_ptr<base::ListValue>());
51 void MockRemoteFileSyncService::DumpDatabase(const ListCallback& callback) {
52 callback.Run(scoped_ptr<base::ListValue>());
55 void MockRemoteFileSyncService::SetServiceState(RemoteServiceState state) {
59 void MockRemoteFileSyncService::NotifyRemoteChangeQueueUpdated(
60 int64 pending_changes) {
61 FOR_EACH_OBSERVER(Observer, service_observers_,
62 OnRemoteChangeQueueUpdated(pending_changes));
65 void MockRemoteFileSyncService::NotifyRemoteServiceStateUpdated(
66 RemoteServiceState state,
67 const std::string& description) {
68 FOR_EACH_OBSERVER(Observer, service_observers_,
69 OnRemoteServiceStateUpdated(state, description));
72 void MockRemoteFileSyncService::NotifyFileStatusChanged(
73 const fileapi::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));
82 void MockRemoteFileSyncService::AddServiceObserverStub(Observer* observer) {
83 service_observers_.AddObserver(observer);
86 void MockRemoteFileSyncService::AddFileStatusObserverStub(
87 FileStatusObserver* observer) {
88 file_status_observers_.AddObserver(observer);
91 void MockRemoteFileSyncService::RegisterOriginStub(
93 const SyncStatusCallback& callback) {
94 base::ThreadTaskRunnerHandle::Get()->PostTask(
96 base::Bind(callback, SYNC_STATUS_OK));
99 void MockRemoteFileSyncService::DeleteOriginDirectoryStub(
102 const SyncStatusCallback& callback) {
103 base::ThreadTaskRunnerHandle::Get()->PostTask(
105 base::Bind(callback, SYNC_STATUS_OK));
108 void MockRemoteFileSyncService::ProcessRemoteChangeStub(
109 const SyncFileCallback& callback) {
110 base::ThreadTaskRunnerHandle::Get()->PostTask(
112 base::Bind(callback, SYNC_STATUS_NO_CHANGE_TO_SYNC,
113 fileapi::FileSystemURL()));
116 RemoteServiceState MockRemoteFileSyncService::GetCurrentStateStub() const {
120 } // namespace sync_file_system