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 : 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(_
, _
, _
))
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
));
42 MockRemoteFileSyncService::~MockRemoteFileSyncService() {
45 void MockRemoteFileSyncService::DumpFiles(const GURL
& origin
,
46 const ListCallback
& callback
) {
47 callback
.Run(nullptr);
50 void MockRemoteFileSyncService::DumpDatabase(const ListCallback
& callback
) {
51 callback
.Run(nullptr);
54 void MockRemoteFileSyncService::SetServiceState(RemoteServiceState state
) {
58 void MockRemoteFileSyncService::NotifyRemoteChangeQueueUpdated(
59 int64 pending_changes
) {
60 FOR_EACH_OBSERVER(Observer
, service_observers_
,
61 OnRemoteChangeQueueUpdated(pending_changes
));
64 void MockRemoteFileSyncService::NotifyRemoteServiceStateUpdated(
65 RemoteServiceState state
,
66 const std::string
& description
) {
67 FOR_EACH_OBSERVER(Observer
, service_observers_
,
68 OnRemoteServiceStateUpdated(state
, description
));
71 void MockRemoteFileSyncService::NotifyFileStatusChanged(
72 const storage::FileSystemURL
& url
,
73 SyncFileType file_type
,
74 SyncFileStatus sync_status
,
75 SyncAction action_taken
,
76 SyncDirection direction
) {
77 FOR_EACH_OBSERVER(FileStatusObserver
, file_status_observers_
,
78 OnFileStatusChanged(url
, file_type
, 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(
113 callback
, SYNC_STATUS_NO_CHANGE_TO_SYNC
, storage::FileSystemURL()));
116 RemoteServiceState
MockRemoteFileSyncService::GetCurrentStateStub() const {
120 } // namespace sync_file_system