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 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_MOCK_H_
6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_MOCK_H_
11 #include "base/memory/weak_ptr.h"
12 #include "base/strings/string16.h"
13 #include "chrome/browser/sync/glue/device_info.h"
14 #include "chrome/browser/sync/profile_sync_service.h"
15 #include "chrome/test/base/testing_profile.h"
16 #include "components/sync_driver/change_processor.h"
17 #include "components/sync_driver/data_type_controller.h"
18 #include "google_apis/gaia/google_service_auth_error.h"
19 #include "sync/internal_api/public/base/model_type.h"
20 #include "sync/protocol/sync_protocol_error.h"
21 #include "testing/gmock/include/gmock/gmock.h"
23 using ::testing::Invoke
;
25 class ProfileSyncServiceMock
: public ProfileSyncService
{
27 explicit ProfileSyncServiceMock(Profile
* profile
);
28 virtual ~ProfileSyncServiceMock();
30 // A utility used by sync tests to create a TestingProfile with a Google
31 // Services username stored in a (Testing)PrefService.
32 static TestingProfile
* MakeSignedInTestingProfile();
34 // Helper routine to be used in conjunction with
35 // BrowserContextKeyedServiceFactory::SetTestingFactory().
36 static KeyedService
* BuildMockProfileSyncService(
37 content::BrowserContext
* profile
);
39 MOCK_METHOD0(DisableForUser
, void());
40 MOCK_METHOD3(OnBackendInitialized
,
41 void(const syncer::WeakHandle
<syncer::JsBackend
>&,
42 const syncer::WeakHandle
<syncer::DataTypeDebugInfoListener
>&,
44 MOCK_METHOD0(OnSyncCycleCompleted
, void());
45 MOCK_METHOD0(OnAuthError
, void());
46 MOCK_METHOD4(OnUserSubmittedAuth
,
47 void(const std::string
& username
,
48 const std::string
& password
,
49 const std::string
& captcha
,
50 const std::string
& access_code
));
51 MOCK_METHOD0(OnUserCancelledDialog
, void());
52 MOCK_CONST_METHOD0(GetAuthenticatedUsername
, base::string16());
53 MOCK_METHOD2(OnUserChoseDatatypes
,
54 void(bool sync_everything
,
55 syncer::ModelTypeSet chosen_types
));
57 MOCK_METHOD2(OnUnrecoverableError
,
58 void(const tracked_objects::Location
& location
,
59 const std::string
& message
));
60 MOCK_METHOD3(DisableBrokenDatatype
, void(syncer::ModelType
,
61 const tracked_objects::Location
&,
62 std::string message
));
63 MOCK_CONST_METHOD0(GetUserShare
, syncer::UserShare
*());
64 MOCK_METHOD3(ActivateDataType
,
65 void(syncer::ModelType
, syncer::ModelSafeGroup
,
66 browser_sync::ChangeProcessor
*));
67 MOCK_METHOD1(DeactivateDataType
, void(syncer::ModelType
));
68 MOCK_METHOD0(UnsuppressAndStart
, void());
70 MOCK_METHOD1(AddObserver
, void(ProfileSyncServiceBase::Observer
*));
71 MOCK_METHOD1(RemoveObserver
, void(ProfileSyncServiceBase::Observer
*));
72 MOCK_METHOD0(GetJsController
, base::WeakPtr
<syncer::JsController
>());
73 MOCK_CONST_METHOD0(HasSyncSetupCompleted
, bool());
75 MOCK_CONST_METHOD0(EncryptEverythingEnabled
, bool());
76 MOCK_METHOD0(EnableEncryptEverything
, void());
78 MOCK_METHOD1(ChangePreferredDataTypes
,
79 void(syncer::ModelTypeSet preferred_types
));
80 MOCK_CONST_METHOD0(GetActiveDataTypes
, syncer::ModelTypeSet());
81 MOCK_CONST_METHOD0(GetPreferredDataTypes
, syncer::ModelTypeSet());
82 MOCK_CONST_METHOD0(GetRegisteredDataTypes
, syncer::ModelTypeSet());
83 MOCK_CONST_METHOD0(GetLastSessionSnapshot
,
84 syncer::sessions::SyncSessionSnapshot());
86 MOCK_METHOD1(QueryDetailedSyncStatus
,
87 bool(browser_sync::SyncBackendHost::Status
* result
));
88 MOCK_CONST_METHOD0(GetAuthError
, const GoogleServiceAuthError
&());
89 MOCK_CONST_METHOD0(FirstSetupInProgress
, bool());
90 MOCK_CONST_METHOD0(GetLastSyncedTimeString
, base::string16());
91 MOCK_CONST_METHOD0(HasUnrecoverableError
, bool());
92 MOCK_CONST_METHOD0(sync_initialized
, bool());
93 MOCK_CONST_METHOD0(IsStartSuppressed
, bool());
94 MOCK_CONST_METHOD0(waiting_for_auth
, bool());
95 MOCK_METHOD1(OnActionableError
, void(
96 const syncer::SyncProtocolError
&));
97 MOCK_METHOD1(SetSetupInProgress
, void(bool));
98 MOCK_CONST_METHOD0(IsSessionsDataTypeControllerRunning
, bool());
100 MOCK_CONST_METHOD0(GetAllSignedInDevicesMock
,
101 std::vector
<browser_sync::DeviceInfo
*>* ());
102 // This is to get around the fact that GMOCK does not handle Scoped*.
103 virtual ScopedVector
<browser_sync::DeviceInfo
>
104 GetAllSignedInDevices() const OVERRIDE
;
106 virtual scoped_ptr
<browser_sync::DeviceInfo
> GetLocalDeviceInfo()
108 MOCK_CONST_METHOD0(GetLocalDeviceInfoMock
,
109 browser_sync::DeviceInfo
*());
110 MOCK_CONST_METHOD0(GetLocalSyncCacheGUID
, std::string());
112 // DataTypeManagerObserver mocks.
113 MOCK_METHOD0(OnConfigureBlocked
, void());
114 MOCK_METHOD1(OnConfigureDone
,
115 void(const browser_sync::DataTypeManager::ConfigureResult
&));
116 MOCK_METHOD0(OnConfigureRetry
, void());
117 MOCK_METHOD0(OnConfigureStart
, void());
119 MOCK_METHOD0(IsSyncEnabledAndLoggedIn
, bool());
120 MOCK_CONST_METHOD0(IsManaged
, bool());
121 MOCK_METHOD0(IsOAuthRefreshTokenAvailable
, bool());
123 MOCK_CONST_METHOD0(IsPassphraseRequired
, bool());
124 MOCK_CONST_METHOD0(IsPassphraseRequiredForDecryption
, bool());
125 MOCK_CONST_METHOD0(IsUsingSecondaryPassphrase
, bool());
126 MOCK_CONST_METHOD0(GetPassphraseType
, syncer::PassphraseType());
127 MOCK_CONST_METHOD0(GetPassphraseTime
, base::Time());
128 MOCK_CONST_METHOD0(GetExplicitPassphraseTime
, base::Time());
130 MOCK_METHOD1(SetDecryptionPassphrase
, bool(const std::string
& passphrase
));
131 MOCK_METHOD2(SetEncryptionPassphrase
, void(const std::string
& passphrase
,
132 PassphraseType type
));
135 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_MOCK_H_