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_TEST_PROFILE_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/sync/glue/sync_backend_host_impl.h"
14 #include "chrome/browser/sync/profile_sync_service.h"
15 #include "components/signin/core/browser/profile_oauth2_token_service.h"
16 #include "components/sync_driver/data_type_manager_impl.h"
17 #include "components/sync_driver/sync_prefs.h"
18 #include "sync/test/engine/test_id_factory.h"
19 #include "testing/gmock/include/gmock/gmock.h"
22 class ProfileOAuth2TokenService;
23 class ProfileSyncComponentsFactory;
24 class ProfileSyncComponentsFactoryMock;
26 ACTION(ReturnNewDataTypeManager) {
27 return new sync_driver::DataTypeManagerImpl(base::Closure(),
36 namespace browser_sync {
38 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl {
40 SyncBackendHostForProfileSyncTest(
42 invalidation::InvalidationService* invalidator,
43 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs,
44 base::Closure callback);
45 virtual ~SyncBackendHostForProfileSyncTest();
47 virtual void RequestConfigureSyncer(
48 syncer::ConfigureReason reason,
49 syncer::ModelTypeSet to_download,
50 syncer::ModelTypeSet to_purge,
51 syncer::ModelTypeSet to_journal,
52 syncer::ModelTypeSet to_unapply,
53 syncer::ModelTypeSet to_ignore,
54 const syncer::ModelSafeRoutingInfo& routing_info,
55 const base::Callback<void(syncer::ModelTypeSet,
56 syncer::ModelTypeSet)>& ready_task,
57 const base::Closure& retry_callback) OVERRIDE;
60 virtual void InitCore(scoped_ptr<DoInitializeOptions> options) OVERRIDE;
63 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop.
64 // Allows extra initialization work to be performed before the backend comes
66 base::Closure callback_;
69 } // namespace browser_sync
71 class TestProfileSyncService : public ProfileSyncService {
73 // TODO(tim): Add ability to inject TokenService alongside SigninManager.
74 // TODO(rogerta): what does above comment mean?
75 TestProfileSyncService(
76 scoped_ptr<ProfileSyncComponentsFactory> factory,
78 SigninManagerBase* signin,
79 ProfileOAuth2TokenService* oauth2_token_service,
80 browser_sync::ProfileSyncServiceStartBehavior behavior);
82 virtual ~TestProfileSyncService();
84 virtual void OnConfigureDone(
85 const sync_driver::DataTypeManager::ConfigureResult& result) OVERRIDE;
87 // We implement our own version to avoid some DCHECKs.
88 virtual syncer::UserShare* GetUserShare() const OVERRIDE;
90 static TestProfileSyncService* BuildAutoStartAsyncInit(
91 Profile* profile, base::Closure callback);
93 ProfileSyncComponentsFactoryMock* components_factory_mock();
95 syncer::TestIdFactory* id_factory();
97 // Raise visibility to ease testing.
98 using ProfileSyncService::NotifyObservers;
101 static KeyedService* TestFactoryFunction(content::BrowserContext* profile);
103 // Return NULL handle to use in backend initialization to avoid receiving
104 // js messages on UI loop when it's being destroyed, which are not deleted
105 // and cause memory leak in test.
106 virtual syncer::WeakHandle<syncer::JsEventHandler> GetJsEventHandler()
109 virtual bool NeedBackup() const OVERRIDE;
112 syncer::TestIdFactory id_factory_;
115 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_