Home | History | Annotate | Download | only in sync_file_system
      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 <string>
      9 
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/observer_list.h"
     12 #include "base/values.h"
     13 #include "chrome/browser/sync_file_system/file_status_observer.h"
     14 #include "chrome/browser/sync_file_system/mock_local_change_processor.h"
     15 #include "chrome/browser/sync_file_system/remote_change_processor.h"
     16 #include "chrome/browser/sync_file_system/remote_file_sync_service.h"
     17 #include "chrome/browser/sync_file_system/sync_callbacks.h"
     18 #include "chrome/browser/sync_file_system/sync_direction.h"
     19 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
     20 #include "testing/gmock/include/gmock/gmock.h"
     21 #include "url/gurl.h"
     22 
     23 namespace sync_file_system {
     24 
     25 class MockRemoteFileSyncService : public RemoteFileSyncService {
     26  public:
     27   MockRemoteFileSyncService();
     28   virtual ~MockRemoteFileSyncService();
     29 
     30   // RemoteFileSyncService overrides.
     31   MOCK_METHOD1(AddServiceObserver,
     32                void(RemoteFileSyncService::Observer* observer));
     33   MOCK_METHOD1(AddFileStatusObserver,
     34                void(FileStatusObserver* observer));
     35   MOCK_METHOD2(RegisterOrigin,
     36                void(const GURL& origin, const SyncStatusCallback& callback));
     37   MOCK_METHOD2(EnableOrigin,
     38                void(const GURL& origin, const SyncStatusCallback& callback));
     39   MOCK_METHOD2(DisableOrigin,
     40                void(const GURL& origin, const SyncStatusCallback& callback));
     41   MOCK_METHOD3(UninstallOrigin,
     42                void(const GURL& origin,
     43                     UninstallFlag flag,
     44                     const SyncStatusCallback& callback));
     45   MOCK_METHOD1(ProcessRemoteChange,
     46                void(const SyncFileCallback& callback));
     47   MOCK_METHOD1(SetRemoteChangeProcessor,
     48                void(RemoteChangeProcessor* processor));
     49   MOCK_METHOD0(GetLocalChangeProcessor, LocalChangeProcessor*());
     50   MOCK_CONST_METHOD0(GetCurrentState,
     51                      RemoteServiceState());
     52   MOCK_METHOD1(GetOriginStatusMap,
     53                void(const StatusMapCallback& callback));
     54   MOCK_METHOD1(SetSyncEnabled, void(bool enabled));
     55   MOCK_METHOD1(PromoteDemotedChanges, void(const base::Closure& callback));
     56 
     57   virtual void DumpFiles(const GURL& origin,
     58                          const ListCallback& callback) OVERRIDE;
     59   virtual void DumpDatabase(const ListCallback& callback) OVERRIDE;
     60 
     61   void SetServiceState(RemoteServiceState state);
     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(const storage::FileSystemURL& url,
     70                                SyncFileStatus sync_status,
     71                                SyncAction action_taken,
     72                                SyncDirection direction);
     73 
     74  private:
     75   void AddServiceObserverStub(Observer* observer);
     76   void AddFileStatusObserverStub(FileStatusObserver* observer);
     77   void RegisterOriginStub(
     78       const GURL& origin, const SyncStatusCallback& callback);
     79   void DeleteOriginDirectoryStub(
     80       const GURL& origin, UninstallFlag flag,
     81       const SyncStatusCallback& callback);
     82   void ProcessRemoteChangeStub(const SyncFileCallback& callback);
     83   RemoteServiceState GetCurrentStateStub() const;
     84 
     85   // For default implementation.
     86   ::testing::NiceMock<MockLocalChangeProcessor> mock_local_change_processor_;
     87 
     88   ObserverList<Observer> service_observers_;
     89   ObserverList<FileStatusObserver> file_status_observers_;
     90 
     91   ConflictResolutionPolicy conflict_resolution_policy_;
     92 
     93   RemoteServiceState state_;
     94 
     95   DISALLOW_COPY_AND_ASSIGN(MockRemoteFileSyncService);
     96 };
     97 
     98 }  // namespace sync_file_system
     99 
    100 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_MOCK_REMOTE_FILE_SYNC_SERVICE_H_
    101