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"
13 #include "storage/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(nullptr);
51 void MockRemoteFileSyncService::DumpDatabase(const ListCallback
& callback
) {
52 callback
.Run(nullptr);
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 storage::FileSystemURL
& url
,
74 SyncFileType file_type
,
75 SyncFileStatus sync_status
,
76 SyncAction action_taken
,
77 SyncDirection direction
) {
78 FOR_EACH_OBSERVER(FileStatusObserver
, file_status_observers_
,
79 OnFileStatusChanged(url
, file_type
, sync_status
,
80 action_taken
, direction
));
83 void MockRemoteFileSyncService::AddServiceObserverStub(Observer
* observer
) {
84 service_observers_
.AddObserver(observer
);
87 void MockRemoteFileSyncService::AddFileStatusObserverStub(
88 FileStatusObserver
* observer
) {
89 file_status_observers_
.AddObserver(observer
);
92 void MockRemoteFileSyncService::RegisterOriginStub(
94 const SyncStatusCallback
& callback
) {
95 base::ThreadTaskRunnerHandle::Get()->PostTask(
97 base::Bind(callback
, SYNC_STATUS_OK
));
100 void MockRemoteFileSyncService::DeleteOriginDirectoryStub(
103 const SyncStatusCallback
& callback
) {
104 base::ThreadTaskRunnerHandle::Get()->PostTask(
106 base::Bind(callback
, SYNC_STATUS_OK
));
109 void MockRemoteFileSyncService::ProcessRemoteChangeStub(
110 const SyncFileCallback
& callback
) {
111 base::ThreadTaskRunnerHandle::Get()->PostTask(
114 callback
, SYNC_STATUS_NO_CHANGE_TO_SYNC
, storage::FileSystemURL()));
117 RemoteServiceState
MockRemoteFileSyncService::GetCurrentStateStub() const {
121 } // namespace sync_file_system