Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync_file_system / mock_remote_file_sync_service.cc
blobb414fa9aba669b9b6391e542878e13e466f43114
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/message_loop_proxy.h"
12 #include "url/gurl.h"
13 #include "webkit/browser/fileapi/file_system_url.h"
15 using ::testing::_;
16 using ::testing::Invoke;
17 using ::testing::Return;
19 namespace sync_file_system {
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, IsConflicting(_))
39 .WillByDefault(Return(false));
40 ON_CALL(*this, GetCurrentState())
41 .WillByDefault(Invoke(this, &self::GetCurrentStateStub));
42 ON_CALL(*this, SetConflictResolutionPolicy(_))
43 .WillByDefault(Invoke(this, &self::SetConflictResolutionPolicyStub));
44 ON_CALL(*this, GetConflictResolutionPolicy())
45 .WillByDefault(Invoke(this, &self::GetConflictResolutionPolicyStub));
48 MockRemoteFileSyncService::~MockRemoteFileSyncService() {
51 scoped_ptr<base::ListValue> MockRemoteFileSyncService::DumpFiles(
52 const GURL& origin) {
53 return scoped_ptr<base::ListValue>();
56 scoped_ptr<base::ListValue> MockRemoteFileSyncService::DumpDatabase() {
57 return scoped_ptr<base::ListValue>();
60 void MockRemoteFileSyncService::SetServiceState(RemoteServiceState state) {
61 state_ = state;
64 void MockRemoteFileSyncService::NotifyRemoteChangeQueueUpdated(
65 int64 pending_changes) {
66 FOR_EACH_OBSERVER(Observer, service_observers_,
67 OnRemoteChangeQueueUpdated(pending_changes));
70 void MockRemoteFileSyncService::NotifyRemoteServiceStateUpdated(
71 RemoteServiceState state,
72 const std::string& description) {
73 FOR_EACH_OBSERVER(Observer, service_observers_,
74 OnRemoteServiceStateUpdated(state, description));
77 void MockRemoteFileSyncService::NotifyFileStatusChanged(
78 const fileapi::FileSystemURL& url,
79 SyncFileStatus sync_status,
80 SyncAction action_taken,
81 SyncDirection direction) {
82 FOR_EACH_OBSERVER(FileStatusObserver, file_status_observers_,
83 OnFileStatusChanged(url, sync_status,
84 action_taken, direction));
87 void MockRemoteFileSyncService::AddServiceObserverStub(Observer* observer) {
88 service_observers_.AddObserver(observer);
91 void MockRemoteFileSyncService::AddFileStatusObserverStub(
92 FileStatusObserver* observer) {
93 file_status_observers_.AddObserver(observer);
96 void MockRemoteFileSyncService::RegisterOriginStub(
97 const GURL& origin,
98 const SyncStatusCallback& callback) {
99 base::MessageLoopProxy::current()->PostTask(
100 FROM_HERE,
101 base::Bind(callback, SYNC_STATUS_OK));
104 void MockRemoteFileSyncService::DeleteOriginDirectoryStub(
105 const GURL& origin,
106 UninstallFlag flag,
107 const SyncStatusCallback& callback) {
108 base::MessageLoopProxy::current()->PostTask(
109 FROM_HERE,
110 base::Bind(callback, SYNC_STATUS_OK));
113 void MockRemoteFileSyncService::ProcessRemoteChangeStub(
114 const SyncFileCallback& callback) {
115 base::MessageLoopProxy::current()->PostTask(
116 FROM_HERE,
117 base::Bind(callback, SYNC_STATUS_NO_CHANGE_TO_SYNC,
118 fileapi::FileSystemURL()));
121 SyncStatusCode MockRemoteFileSyncService::SetConflictResolutionPolicyStub(
122 ConflictResolutionPolicy policy) {
123 conflict_resolution_policy_ = policy;
124 return SYNC_STATUS_OK;
127 ConflictResolutionPolicy
128 MockRemoteFileSyncService::GetConflictResolutionPolicyStub() const {
129 return conflict_resolution_policy_;
132 RemoteServiceState MockRemoteFileSyncService::GetCurrentStateStub() const {
133 return state_;
136 } // namespace sync_file_system