Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: components/browser_sync/browser/profile_sync_test_util.h

Issue 2345843003: [Sync] Merge //components/browser_sync into one directory. (Closed)
Patch Set: Address comment + rebase. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 COMPONENTS_BROWSER_SYNC_BROWSER_PROFILE_SYNC_TEST_UTIL_H_
6 #define COMPONENTS_BROWSER_SYNC_BROWSER_PROFILE_SYNC_TEST_UTIL_H_
7
8 #include <memory>
9
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/test/sequenced_worker_pool_owner.h"
15 #include "base/time/time.h"
16 #include "components/browser_sync/browser/profile_sync_service.h"
17 #include "components/invalidation/impl/fake_invalidation_service.h"
18 #include "components/signin/core/browser/account_tracker_service.h"
19 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
20 #include "components/signin/core/browser/fake_signin_manager.h"
21 #include "components/signin/core/browser/test_signin_client.h"
22 #include "components/sync/driver/fake_sync_client.h"
23 #include "components/sync/driver/sync_api_component_factory_mock.h"
24 #include "components/sync_sessions/fake_sync_sessions_client.h"
25 #include "components/syncable_prefs/testing_pref_service_syncable.h"
26
27 namespace base {
28 class Time;
29 class TimeDelta;
30 }
31
32 namespace history {
33 class HistoryService;
34 }
35
36 namespace net {
37 class URLRequestContextGetter;
38 }
39
40 namespace user_prefs {
41 class PrefRegistrySyncable;
42 }
43
44 namespace browser_sync {
45
46 // An empty syncer::NetworkTimeUpdateCallback. Used in various tests to
47 // instantiate ProfileSyncService.
48 void EmptyNetworkTimeUpdate(const base::Time&,
49 const base::TimeDelta&,
50 const base::TimeDelta&);
51
52 // Call this to register preferences needed for ProfileSyncService creation.
53 void RegisterPrefsForProfileSyncService(
54 user_prefs::PrefRegistrySyncable* registry);
55
56 // Aggregate this class to get all necessary support for creating a
57 // ProfileSyncService in tests. The test still needs to have its own
58 // MessageLoop, though.
59 class ProfileSyncServiceBundle {
60 public:
61 #if defined(OS_CHROMEOS)
62 typedef FakeSigninManagerBase FakeSigninManagerType;
63 #else
64 typedef FakeSigninManager FakeSigninManagerType;
65 #endif
66
67 ProfileSyncServiceBundle();
68
69 ~ProfileSyncServiceBundle();
70
71 // Builders
72
73 // Builds a child of FakeSyncClient which overrides some of the client's
74 // accessors to return objects from the bundle.
75 class SyncClientBuilder {
76 public:
77 // Construct the builder and associate with the |bundle| to source objects
78 // from.
79 explicit SyncClientBuilder(ProfileSyncServiceBundle* bundle);
80
81 ~SyncClientBuilder();
82
83 void SetPersonalDataManager(
84 autofill::PersonalDataManager* personal_data_manager);
85
86 // The client will call this callback to produce the SyncableService
87 // specific to |type|.
88 void SetSyncableServiceCallback(
89 const base::Callback<base::WeakPtr<syncer::SyncableService>(
90 syncer::ModelType type)>& get_syncable_service_callback);
91
92 // The client will call this callback to produce the SyncService for the
93 // current Profile.
94 void SetSyncServiceCallback(const base::Callback<sync_driver::SyncService*(
95 void)>& get_sync_service_callback);
96
97 void SetHistoryService(history::HistoryService* history_service);
98
99 void SetBookmarkModelCallback(
100 const base::Callback<bookmarks::BookmarkModel*(void)>&
101 get_bookmark_model_callback);
102
103 void set_activate_model_creation() { activate_model_creation_ = true; }
104
105 std::unique_ptr<sync_driver::FakeSyncClient> Build();
106
107 private:
108 // Associated bundle to source objects from.
109 ProfileSyncServiceBundle* const bundle_;
110
111 autofill::PersonalDataManager* personal_data_manager_;
112 base::Callback<base::WeakPtr<syncer::SyncableService>(
113 syncer::ModelType type)>
114 get_syncable_service_callback_;
115 base::Callback<sync_driver::SyncService*(void)> get_sync_service_callback_;
116 history::HistoryService* history_service_ = nullptr;
117 base::Callback<bookmarks::BookmarkModel*(void)>
118 get_bookmark_model_callback_;
119 // If set, the built client will be able to build some ModelSafeWorker
120 // instances.
121 bool activate_model_creation_ = false;
122
123 DISALLOW_COPY_AND_ASSIGN(SyncClientBuilder);
124 };
125
126 // Creates an InitParams instance with the specified |start_behavior| and
127 // |sync_client|, and fills the rest with dummy values and objects owned by
128 // the bundle.
129 ProfileSyncService::InitParams CreateBasicInitParams(
130 ProfileSyncService::StartBehavior start_behavior,
131 std::unique_ptr<sync_driver::SyncClient> sync_client);
132
133 // Accessors
134
135 net::URLRequestContextGetter* url_request_context() {
136 return url_request_context_.get();
137 }
138
139 syncable_prefs::TestingPrefServiceSyncable* pref_service() {
140 return &pref_service_;
141 }
142
143 FakeProfileOAuth2TokenService* auth_service() { return &auth_service_; }
144
145 FakeSigninManagerType* signin_manager() { return &signin_manager_; }
146
147 AccountTrackerService* account_tracker() { return &account_tracker_; }
148
149 SyncApiComponentFactoryMock* component_factory() {
150 return &component_factory_;
151 }
152
153 sync_sessions::FakeSyncSessionsClient* sync_sessions_client() {
154 return &sync_sessions_client_;
155 }
156
157 invalidation::FakeInvalidationService* fake_invalidation_service() {
158 return &fake_invalidation_service_;
159 }
160
161 base::SingleThreadTaskRunner* db_thread() { return db_thread_.get(); }
162
163 void set_db_thread(
164 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread) {
165 db_thread_ = db_thread;
166 }
167
168 private:
169 scoped_refptr<base::SingleThreadTaskRunner> db_thread_;
170 base::SequencedWorkerPoolOwner worker_pool_owner_;
171 syncable_prefs::TestingPrefServiceSyncable pref_service_;
172 TestSigninClient signin_client_;
173 AccountTrackerService account_tracker_;
174 FakeSigninManagerType signin_manager_;
175 FakeProfileOAuth2TokenService auth_service_;
176 SyncApiComponentFactoryMock component_factory_;
177 sync_sessions::FakeSyncSessionsClient sync_sessions_client_;
178 invalidation::FakeInvalidationService fake_invalidation_service_;
179 scoped_refptr<net::URLRequestContextGetter> url_request_context_;
180
181 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceBundle);
182 };
183
184 } // namespace browser_sync
185
186 #endif // COMPONENTS_BROWSER_SYNC_BROWSER_PROFILE_SYNC_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698