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
MockRemoteFileSyncService()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, GetCurrentState())
39 .WillByDefault(Invoke(this, &self::GetCurrentStateStub));
40 }
41
~MockRemoteFileSyncService()42 MockRemoteFileSyncService::~MockRemoteFileSyncService() {
43 }
44
DumpFiles(const GURL & origin,const ListCallback & callback)45 void MockRemoteFileSyncService::DumpFiles(const GURL& origin,
46 const ListCallback& callback) {
47 callback.Run(scoped_ptr<base::ListValue>());
48 }
49
DumpDatabase(const ListCallback & callback)50 void MockRemoteFileSyncService::DumpDatabase(const ListCallback& callback) {
51 callback.Run(scoped_ptr<base::ListValue>());
52 }
53
SetServiceState(RemoteServiceState state)54 void MockRemoteFileSyncService::SetServiceState(RemoteServiceState state) {
55 state_ = state;
56 }
57
NotifyRemoteChangeQueueUpdated(int64 pending_changes)58 void MockRemoteFileSyncService::NotifyRemoteChangeQueueUpdated(
59 int64 pending_changes) {
60 FOR_EACH_OBSERVER(Observer, service_observers_,
61 OnRemoteChangeQueueUpdated(pending_changes));
62 }
63
NotifyRemoteServiceStateUpdated(RemoteServiceState state,const std::string & description)64 void MockRemoteFileSyncService::NotifyRemoteServiceStateUpdated(
65 RemoteServiceState state,
66 const std::string& description) {
67 FOR_EACH_OBSERVER(Observer, service_observers_,
68 OnRemoteServiceStateUpdated(state, description));
69 }
70
NotifyFileStatusChanged(const fileapi::FileSystemURL & url,SyncFileStatus sync_status,SyncAction action_taken,SyncDirection direction)71 void MockRemoteFileSyncService::NotifyFileStatusChanged(
72 const fileapi::FileSystemURL& url,
73 SyncFileStatus sync_status,
74 SyncAction action_taken,
75 SyncDirection direction) {
76 FOR_EACH_OBSERVER(FileStatusObserver, file_status_observers_,
77 OnFileStatusChanged(url, sync_status,
78 action_taken, direction));
79 }
80
AddServiceObserverStub(Observer * observer)81 void MockRemoteFileSyncService::AddServiceObserverStub(Observer* observer) {
82 service_observers_.AddObserver(observer);
83 }
84
AddFileStatusObserverStub(FileStatusObserver * observer)85 void MockRemoteFileSyncService::AddFileStatusObserverStub(
86 FileStatusObserver* observer) {
87 file_status_observers_.AddObserver(observer);
88 }
89
RegisterOriginStub(const GURL & origin,const SyncStatusCallback & callback)90 void MockRemoteFileSyncService::RegisterOriginStub(
91 const GURL& origin,
92 const SyncStatusCallback& callback) {
93 base::MessageLoopProxy::current()->PostTask(
94 FROM_HERE,
95 base::Bind(callback, SYNC_STATUS_OK));
96 }
97
DeleteOriginDirectoryStub(const GURL & origin,UninstallFlag flag,const SyncStatusCallback & callback)98 void MockRemoteFileSyncService::DeleteOriginDirectoryStub(
99 const GURL& origin,
100 UninstallFlag flag,
101 const SyncStatusCallback& callback) {
102 base::MessageLoopProxy::current()->PostTask(
103 FROM_HERE,
104 base::Bind(callback, SYNC_STATUS_OK));
105 }
106
ProcessRemoteChangeStub(const SyncFileCallback & callback)107 void MockRemoteFileSyncService::ProcessRemoteChangeStub(
108 const SyncFileCallback& callback) {
109 base::MessageLoopProxy::current()->PostTask(
110 FROM_HERE,
111 base::Bind(callback, SYNC_STATUS_NO_CHANGE_TO_SYNC,
112 fileapi::FileSystemURL()));
113 }
114
GetCurrentStateStub() const115 RemoteServiceState MockRemoteFileSyncService::GetCurrentStateStub() const {
116 return state_;
117 }
118
119 } // namespace sync_file_system
120