mock_remote_file_sync_service.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_MOCK_REMOTE_FILE_SYNC_SERVICE_H_
6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_MOCK_REMOTE_FILE_SYNC_SERVICE_H_
7
8#include <map>
9
10#include "base/memory/scoped_ptr.h"
11#include "base/observer_list.h"
12#include "chrome/browser/sync_file_system/file_status_observer.h"
13#include "chrome/browser/sync_file_system/mock_local_change_processor.h"
14#include "chrome/browser/sync_file_system/remote_change_processor.h"
15#include "chrome/browser/sync_file_system/remote_file_sync_service.h"
16#include "googleurl/src/gurl.h"
17#include "testing/gmock/include/gmock/gmock.h"
18#include "webkit/browser/fileapi/syncable/sync_callbacks.h"
19#include "webkit/browser/fileapi/syncable/sync_direction.h"
20#include "webkit/browser/fileapi/syncable/sync_file_metadata.h"
21
22namespace sync_file_system {
23
24class MockRemoteFileSyncService : public RemoteFileSyncService {
25 public:
26  MockRemoteFileSyncService();
27  virtual ~MockRemoteFileSyncService();
28
29  // RemoteFileSyncService overrides.
30  MOCK_METHOD1(AddServiceObserver,
31               void(RemoteFileSyncService::Observer* observer));
32  MOCK_METHOD1(AddFileStatusObserver,
33               void(FileStatusObserver* observer));
34  MOCK_METHOD2(RegisterOriginForTrackingChanges,
35               void(const GURL& origin, const SyncStatusCallback& callback));
36  MOCK_METHOD2(UnregisterOriginForTrackingChanges,
37               void(const GURL& origin, const SyncStatusCallback& callback));
38  MOCK_METHOD2(EnableOriginForTrackingChanges,
39               void(const GURL& origin, const SyncStatusCallback& callback));
40  MOCK_METHOD2(DisableOriginForTrackingChanges,
41               void(const GURL& origin, const SyncStatusCallback& callback));
42  MOCK_METHOD2(UninstallOrigin,
43               void(const GURL& origin, const SyncStatusCallback& callback));
44  MOCK_METHOD1(ProcessRemoteChange,
45               void(const SyncFileCallback& callback));
46  MOCK_METHOD1(SetRemoteChangeProcessor,
47               void(RemoteChangeProcessor* processor));
48  MOCK_METHOD0(GetLocalChangeProcessor, LocalChangeProcessor*());
49  MOCK_METHOD1(IsConflicting, bool(const fileapi::FileSystemURL& url));
50  MOCK_CONST_METHOD0(GetCurrentState,
51                     RemoteServiceState());
52  MOCK_METHOD1(GetOriginStatusMap,
53               void(RemoteFileSyncService::OriginStatusMap* status_map));
54  MOCK_METHOD1(
55      GetFileMetadataMap,
56      void(RemoteFileSyncService::OriginFileMetadataMap* metadata_map));
57  MOCK_METHOD1(SetSyncEnabled, void(bool));
58  MOCK_METHOD1(SetConflictResolutionPolicy,
59               SyncStatusCode(ConflictResolutionPolicy));
60  MOCK_CONST_METHOD0(GetConflictResolutionPolicy,
61                     ConflictResolutionPolicy());
62
63  // Send notifications to the observers.
64  // Can be used in the mock implementation.
65  void NotifyRemoteChangeQueueUpdated(int64 pending_changes);
66  void NotifyRemoteServiceStateUpdated(
67      RemoteServiceState state,
68      const std::string& description);
69  void NotifyFileStatusChanged(
70      const fileapi::FileSystemURL& url,
71      SyncFileStatus sync_status,
72      SyncAction action_taken,
73      SyncDirection direction);
74
75 private:
76  void AddServiceObserverStub(Observer* observer);
77  void AddFileStatusObserverStub(FileStatusObserver* observer);
78  void RegisterOriginForTrackingChangesStub(
79      const GURL& origin, const SyncStatusCallback& callback);
80  void UnregisterOriginForTrackingChangesStub(
81      const GURL& origin, const SyncStatusCallback& callback);
82  void DeleteOriginDirectoryStub(
83      const GURL& origin, const SyncStatusCallback& callback);
84  void ProcessRemoteChangeStub(const SyncFileCallback& callback);
85  SyncStatusCode SetConflictResolutionPolicyStub(
86      ConflictResolutionPolicy policy);
87  ConflictResolutionPolicy GetConflictResolutionPolicyStub() const;
88
89  // For default implementation.
90  ::testing::NiceMock<MockLocalChangeProcessor> mock_local_change_processor_;
91
92  ObserverList<Observer> service_observers_;
93  ObserverList<FileStatusObserver> file_status_observers_;
94
95  ConflictResolutionPolicy conflict_resolution_policy_;
96
97  DISALLOW_COPY_AND_ASSIGN(MockRemoteFileSyncService);
98};
99
100}  // namespace sync_file_system
101
102#endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_MOCK_REMOTE_FILE_SYNC_SERVICE_H_
103