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/signin/profile_oauth2_token_service.h"
14 #include "chrome/browser/sync/glue/data_type_manager_impl.h"
15 #include "chrome/browser/sync/glue/sync_backend_host_impl.h"
16 #include "chrome/browser/sync/profile_sync_service.h"
17 #include "chrome/browser/sync/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 browser_sync::DataTypeManagerImpl(arg0
,
35 namespace browser_sync
{
37 class SyncBackendHostForProfileSyncTest
: public SyncBackendHostImpl
{
39 SyncBackendHostForProfileSyncTest(
41 const base::WeakPtr
<SyncPrefs
>& sync_prefs
,
42 base::Closure
& callback
);
43 virtual ~SyncBackendHostForProfileSyncTest();
45 virtual void RequestConfigureSyncer(
46 syncer::ConfigureReason reason
,
47 syncer::ModelTypeSet to_download
,
48 syncer::ModelTypeSet to_purge
,
49 syncer::ModelTypeSet to_journal
,
50 syncer::ModelTypeSet to_unapply
,
51 syncer::ModelTypeSet to_ignore
,
52 const syncer::ModelSafeRoutingInfo
& routing_info
,
53 const base::Callback
<void(syncer::ModelTypeSet
,
54 syncer::ModelTypeSet
)>& ready_task
,
55 const base::Closure
& retry_callback
) OVERRIDE
;
58 virtual void InitCore(scoped_ptr
<DoInitializeOptions
> options
) OVERRIDE
;
61 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop.
62 // Allows extra initialization work to be performed before the backend comes
64 base::Closure
& callback_
;
67 } // namespace browser_sync
69 class TestProfileSyncService
: public ProfileSyncService
{
71 // TODO(tim): Add ability to inject TokenService alongside SigninManager.
72 // TODO(rogerta): what does above comment mean?
73 TestProfileSyncService(
74 ProfileSyncComponentsFactory
* factory
,
76 SigninManagerBase
* signin
,
77 ProfileOAuth2TokenService
* oauth2_token_service
,
78 ProfileSyncService::StartBehavior behavior
);
80 virtual ~TestProfileSyncService();
82 virtual void OnConfigureDone(
83 const browser_sync::DataTypeManager::ConfigureResult
& result
) OVERRIDE
;
85 // We implement our own version to avoid some DCHECKs.
86 virtual syncer::UserShare
* GetUserShare() const OVERRIDE
;
88 static BrowserContextKeyedService
* BuildAutoStartAsyncInit(
89 content::BrowserContext
* profile
);
91 ProfileSyncComponentsFactoryMock
* components_factory_mock();
93 // |callback| can be used to populate nodes before the OnBackendInitialized
95 void set_backend_init_callback(const base::Closure
& callback
) {
99 syncer::TestIdFactory
* id_factory();
102 virtual void CreateBackend() OVERRIDE
;
104 // Return NULL handle to use in backend initialization to avoid receiving
105 // js messages on UI loop when it's being destroyed, which are not deleted
106 // and cause memory leak in test.
107 virtual syncer::WeakHandle
<syncer::JsEventHandler
> GetJsEventHandler()
111 syncer::TestIdFactory id_factory_
;
113 base::Closure callback_
;
116 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_