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 ProfileSyncComponentsFactoryMock
;
25 ACTION(ReturnNewDataTypeManager
) {
26 return new sync_driver::DataTypeManagerImpl(base::Closure(),
34 namespace browser_sync
{
36 class SyncBackendHostForProfileSyncTest
: public SyncBackendHostImpl
{
38 SyncBackendHostForProfileSyncTest(
40 const scoped_refptr
<base::SingleThreadTaskRunner
>& ui_thread
,
41 invalidation::InvalidationService
* invalidator
,
42 const base::WeakPtr
<sync_driver::SyncPrefs
>& sync_prefs
,
43 base::Closure callback
);
44 ~SyncBackendHostForProfileSyncTest() override
;
46 void RequestConfigureSyncer(
47 syncer::ConfigureReason reason
,
48 syncer::ModelTypeSet to_download
,
49 syncer::ModelTypeSet to_purge
,
50 syncer::ModelTypeSet to_journal
,
51 syncer::ModelTypeSet to_unapply
,
52 syncer::ModelTypeSet to_ignore
,
53 const syncer::ModelSafeRoutingInfo
& routing_info
,
54 const base::Callback
<void(syncer::ModelTypeSet
, syncer::ModelTypeSet
)>&
56 const base::Closure
& retry_callback
) override
;
59 void InitCore(scoped_ptr
<DoInitializeOptions
> options
) override
;
62 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop.
63 // Allows extra initialization work to be performed before the backend comes
65 base::Closure callback_
;
68 } // namespace browser_sync
70 class TestProfileSyncService
: public ProfileSyncService
{
72 // TODO(tim): Add ability to inject TokenService alongside SigninManager.
73 // TODO(rogerta): what does above comment mean?
74 TestProfileSyncService(
75 scoped_ptr
<sync_driver::SyncApiComponentFactory
> factory
,
77 SigninManagerBase
* signin
,
78 ProfileOAuth2TokenService
* oauth2_token_service
,
79 browser_sync::ProfileSyncServiceStartBehavior behavior
);
81 ~TestProfileSyncService() override
;
84 const sync_driver::DataTypeManager::ConfigureResult
& result
) override
;
86 // We implement our own version to avoid some DCHECKs.
87 syncer::UserShare
* GetUserShare() const override
;
89 static TestProfileSyncService
* BuildAutoStartAsyncInit(
90 Profile
* profile
, base::Closure callback
);
92 ProfileSyncComponentsFactoryMock
* components_factory_mock();
94 syncer::TestIdFactory
* id_factory();
96 // Raise visibility to ease testing.
97 using ProfileSyncService::NotifyObservers
;
100 static scoped_ptr
<KeyedService
> TestFactoryFunction(
101 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 syncer::WeakHandle
<syncer::JsEventHandler
> GetJsEventHandler() override
;
108 bool NeedBackup() const override
;
111 syncer::TestIdFactory id_factory_
;
114 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_