Fix build break
[chromium-blink-merge.git] / chrome / browser / sync_file_system / mock_remote_file_sync_service.cc
blob41dce1e7fc429a6ce5fa6863b351df9a4821a5a8
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"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/location.h"
11 #include "base/message_loop_proxy.h"
12 #include "googleurl/src/gurl.h"
13 #include "webkit/fileapi/file_system_url.h"
15 using ::testing::_;
16 using ::testing::Invoke;
17 using ::testing::Return;
19 namespace sync_file_system {
21 const char MockRemoteFileSyncService::kServiceName[] = "mock_sync_service";
23 MockRemoteFileSyncService::MockRemoteFileSyncService()
24 : conflict_resolution_policy_(CONFLICT_RESOLUTION_MANUAL) {
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, RegisterOriginForTrackingChanges(_, _))
31 .WillByDefault(Invoke(this, &self::RegisterOriginForTrackingChangesStub));
32 ON_CALL(*this, UnregisterOriginForTrackingChanges(_, _))
33 .WillByDefault(
34 Invoke(this, &self::UnregisterOriginForTrackingChangesStub));
35 ON_CALL(*this, UninstallOrigin(_, _))
36 .WillByDefault(
37 Invoke(this, &self::DeleteOriginDirectoryStub));
38 ON_CALL(*this, ProcessRemoteChange(_))
39 .WillByDefault(Invoke(this, &self::ProcessRemoteChangeStub));
40 ON_CALL(*this, GetLocalChangeProcessor())
41 .WillByDefault(Return(&mock_local_change_processor_));
42 ON_CALL(*this, IsConflicting(_))
43 .WillByDefault(Return(false));
44 ON_CALL(*this, GetRemoteFileMetadata(_, _))
45 .WillByDefault(Invoke(this, &self::GetRemoteFileMetadataStub));
46 ON_CALL(*this, GetCurrentState())
47 .WillByDefault(Return(REMOTE_SERVICE_OK));
48 ON_CALL(*this, GetServiceName())
49 .WillByDefault(Return(kServiceName));
50 ON_CALL(*this, SetConflictResolutionPolicy(_))
51 .WillByDefault(Invoke(this, &self::SetConflictResolutionPolicyStub));
52 ON_CALL(*this, GetConflictResolutionPolicy())
53 .WillByDefault(Invoke(this, &self::GetConflictResolutionPolicyStub));
56 MockRemoteFileSyncService::~MockRemoteFileSyncService() {
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::RegisterOriginForTrackingChangesStub(
92 const GURL& origin,
93 const SyncStatusCallback& callback) {
94 base::MessageLoopProxy::current()->PostTask(
95 FROM_HERE,
96 base::Bind(callback, SYNC_STATUS_OK));
99 void MockRemoteFileSyncService::UnregisterOriginForTrackingChangesStub(
100 const GURL& origin,
101 const SyncStatusCallback& callback) {
102 base::MessageLoopProxy::current()->PostTask(
103 FROM_HERE,
104 base::Bind(callback, SYNC_STATUS_OK));
107 void MockRemoteFileSyncService::DeleteOriginDirectoryStub(
108 const GURL& origin,
109 const SyncStatusCallback& callback) {
110 base::MessageLoopProxy::current()->PostTask(
111 FROM_HERE,
112 base::Bind(callback, SYNC_STATUS_OK));
115 void MockRemoteFileSyncService::ProcessRemoteChangeStub(
116 const SyncFileCallback& callback) {
117 base::MessageLoopProxy::current()->PostTask(
118 FROM_HERE,
119 base::Bind(callback, SYNC_STATUS_NO_CHANGE_TO_SYNC,
120 fileapi::FileSystemURL()));
123 void MockRemoteFileSyncService::GetRemoteFileMetadataStub(
124 const fileapi::FileSystemURL& url,
125 const SyncFileMetadataCallback& callback) {
126 FileMetadataMap::iterator iter = conflict_file_metadata_.find(url);
127 if (iter == conflict_file_metadata_.end()) {
128 base::MessageLoopProxy::current()->PostTask(
129 FROM_HERE,
130 base::Bind(callback, SYNC_FILE_ERROR_NOT_FOUND,
131 SyncFileMetadata()));
132 return;
134 base::MessageLoopProxy::current()->PostTask(
135 FROM_HERE, base::Bind(callback, SYNC_STATUS_OK, iter->second));
138 SyncStatusCode MockRemoteFileSyncService::SetConflictResolutionPolicyStub(
139 ConflictResolutionPolicy policy) {
140 conflict_resolution_policy_ = policy;
141 return SYNC_STATUS_OK;
144 ConflictResolutionPolicy
145 MockRemoteFileSyncService::GetConflictResolutionPolicyStub() const {
146 return conflict_resolution_policy_;
149 } // namespace sync_file_system