Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / test_profile_sync_service.h
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_TEST_PROFILE_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
7
8 #include <string>
9
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"
20
21 class Profile;
22 class ProfileOAuth2TokenService;
23 class ProfileSyncComponentsFactory;
24 class ProfileSyncComponentsFactoryMock;
25
26 ACTION(ReturnNewDataTypeManager) {
27   return new sync_driver::DataTypeManagerImpl(base::Closure(),
28                                               arg0,
29                                               arg1,
30                                               arg2,
31                                               arg3,
32                                               arg4);
33 }
34
35 namespace browser_sync {
36
37 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl {
38  public:
39   SyncBackendHostForProfileSyncTest(
40       Profile* profile,
41       invalidation::InvalidationService* invalidator,
42       const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs,
43       base::Closure callback);
44   ~SyncBackendHostForProfileSyncTest() override;
45
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)>&
55           ready_task,
56       const base::Closure& retry_callback) override;
57
58  protected:
59   void InitCore(scoped_ptr<DoInitializeOptions> options) override;
60
61  private:
62   // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop.
63   // Allows extra initialization work to be performed before the backend comes
64   // up.
65   base::Closure callback_;
66 };
67
68 }  // namespace browser_sync
69
70 class TestProfileSyncService : public ProfileSyncService {
71  public:
72   // TODO(tim): Add ability to inject TokenService alongside SigninManager.
73   // TODO(rogerta): what does above comment mean?
74   TestProfileSyncService(
75       scoped_ptr<ProfileSyncComponentsFactory> factory,
76       Profile* profile,
77       SigninManagerBase* signin,
78       ProfileOAuth2TokenService* oauth2_token_service,
79       browser_sync::ProfileSyncServiceStartBehavior behavior);
80
81   ~TestProfileSyncService() override;
82
83   void OnConfigureDone(
84       const sync_driver::DataTypeManager::ConfigureResult& result) override;
85
86   // We implement our own version to avoid some DCHECKs.
87   syncer::UserShare* GetUserShare() const override;
88
89   static TestProfileSyncService* BuildAutoStartAsyncInit(
90       Profile* profile, base::Closure callback);
91
92   ProfileSyncComponentsFactoryMock* components_factory_mock();
93
94   syncer::TestIdFactory* id_factory();
95
96   // Raise visibility to ease testing.
97   using ProfileSyncService::NotifyObservers;
98
99  protected:
100   static KeyedService* TestFactoryFunction(content::BrowserContext* profile);
101
102   // Return NULL handle to use in backend initialization to avoid receiving
103   // js messages on UI loop when it's being destroyed, which are not deleted
104   // and cause memory leak in test.
105   syncer::WeakHandle<syncer::JsEventHandler> GetJsEventHandler() override;
106
107   bool NeedBackup() const override;
108
109  private:
110   syncer::TestIdFactory id_factory_;
111 };
112
113 #endif  // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_