OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |
6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ | 6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // |initial_condition_setup_task| can be used to populate nodes before the | 58 // |initial_condition_setup_task| can be used to populate nodes before the |
59 // OnBackendInitialized callback fires. | 59 // OnBackendInitialized callback fires. |
60 // |set_initial_sync_ended_on_init| determines whether we pretend that a full | 60 // |set_initial_sync_ended_on_init| determines whether we pretend that a full |
61 // initial download has occurred and set bits for enabled data types. If | 61 // initial download has occurred and set bits for enabled data types. If |
62 // this is false, configuring data types will require a syncer nudge. | 62 // this is false, configuring data types will require a syncer nudge. |
63 // |synchronous_init| causes initialization to block until the syncapi has | 63 // |synchronous_init| causes initialization to block until the syncapi has |
64 // completed setting itself up and called us back. | 64 // completed setting itself up and called us back. |
65 SyncBackendHostForProfileSyncTest( | 65 SyncBackendHostForProfileSyncTest( |
66 TestProfileSyncService* service, | 66 TestProfileSyncService* service, |
67 Profile* profile, | 67 Profile* profile, |
68 const FilePath& profile_path, | |
69 const DataTypeController::TypeMap& data_type_controllers, | |
70 Task* initial_condition_setup_task, | 68 Task* initial_condition_setup_task, |
71 int num_expected_resumes, | 69 int num_expected_resumes, |
72 int num_expected_pauses, | 70 int num_expected_pauses, |
73 bool set_initial_sync_ended_on_init, | 71 bool set_initial_sync_ended_on_init, |
74 bool synchronous_init); | 72 bool synchronous_init); |
75 | 73 |
76 MOCK_METHOD0(RequestPause, bool()); | 74 MOCK_METHOD0(RequestPause, bool()); |
77 MOCK_METHOD0(RequestResume, bool()); | 75 MOCK_METHOD0(RequestResume, bool()); |
78 MOCK_METHOD0(RequestNudge, void()); | 76 MOCK_METHOD0(RequestNudge, void()); |
79 | 77 |
80 void SetInitialSyncEndedForEnabledTypes() { | 78 void SetInitialSyncEndedForEnabledTypes() { |
81 UserShare* user_share = core_->syncapi()->GetUserShare(); | 79 UserShare* user_share = core_->syncapi()->GetUserShare(); |
82 DirectoryManager* dir_manager = user_share->dir_manager.get(); | 80 DirectoryManager* dir_manager = user_share->dir_manager.get(); |
83 | 81 |
84 ScopedDirLookup dir(dir_manager, user_share->name); | 82 ScopedDirLookup dir(dir_manager, user_share->name); |
85 if (!dir.good()) | 83 if (!dir.good()) |
86 FAIL(); | 84 FAIL(); |
87 | 85 |
88 ModelSafeRoutingInfo enabled_types; | 86 ModelSafeRoutingInfo enabled_types; |
89 GetModelSafeRoutingInfo(&enabled_types); | 87 GetModelSafeRoutingInfo(&enabled_types); |
90 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); | 88 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); |
91 i != enabled_types.end(); ++i) { | 89 i != enabled_types.end(); ++i) { |
92 dir->set_initial_sync_ended_for_type(i->first, true); | 90 dir->set_initial_sync_ended_for_type(i->first, true); |
93 } | 91 } |
94 } | 92 } |
95 | 93 |
96 virtual void ConfigureDataTypes(const syncable::ModelTypeSet& types, | 94 virtual void ConfigureDataTypes( |
| 95 const DataTypeController::TypeMap& data_type_controllers, |
| 96 const syncable::ModelTypeSet& types, |
97 CancelableTask* ready_task) { | 97 CancelableTask* ready_task) { |
98 SetAutofillMigrationState(syncable::MIGRATED); | 98 SetAutofillMigrationState(syncable::MIGRATED); |
99 SyncBackendHost::ConfigureDataTypes(types, ready_task); | 99 SyncBackendHost::ConfigureDataTypes( |
| 100 data_type_controllers, types, ready_task); |
100 } | 101 } |
101 | 102 |
102 // Called when a nudge comes in. | 103 // Called when a nudge comes in. |
103 void SimulateSyncCycleCompletedInitialSyncEnded() { | 104 void SimulateSyncCycleCompletedInitialSyncEnded() { |
104 syncable::ModelTypeBitSet sync_ended; | 105 syncable::ModelTypeBitSet sync_ended; |
105 ModelSafeRoutingInfo enabled_types; | 106 ModelSafeRoutingInfo enabled_types; |
106 GetModelSafeRoutingInfo(&enabled_types); | 107 GetModelSafeRoutingInfo(&enabled_types); |
107 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; | 108 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; |
108 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); | 109 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); |
109 i != enabled_types.end(); ++i) { | 110 i != enabled_types.end(); ++i) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 158 |
158 } // namespace browser_sync | 159 } // namespace browser_sync |
159 | 160 |
160 class TestProfileSyncService : public ProfileSyncService { | 161 class TestProfileSyncService : public ProfileSyncService { |
161 public: | 162 public: |
162 TestProfileSyncService(ProfileSyncFactory* factory, | 163 TestProfileSyncService(ProfileSyncFactory* factory, |
163 Profile* profile, | 164 Profile* profile, |
164 const std::string& test_user, | 165 const std::string& test_user, |
165 bool synchronous_backend_initialization, | 166 bool synchronous_backend_initialization, |
166 Task* initial_condition_setup_task) | 167 Task* initial_condition_setup_task) |
167 : ProfileSyncService(factory, profile, | 168 : ProfileSyncService(factory, profile, test_user), |
168 !test_user.empty() ? | |
169 test_user : ""), | |
170 synchronous_backend_initialization_( | 169 synchronous_backend_initialization_( |
171 synchronous_backend_initialization), | 170 synchronous_backend_initialization), |
172 synchronous_sync_configuration_(false), | 171 synchronous_sync_configuration_(false), |
173 num_expected_resumes_(1), | 172 num_expected_resumes_(1), |
174 num_expected_pauses_(1), | 173 num_expected_pauses_(1), |
175 initial_condition_setup_task_(initial_condition_setup_task), | 174 initial_condition_setup_task_(initial_condition_setup_task), |
176 set_initial_sync_ended_on_init_(true) { | 175 set_initial_sync_ended_on_init_(true) { |
177 RegisterPreferences(); | 176 RegisterPreferences(); |
178 SetSyncSetupCompleted(); | 177 SetSyncSetupCompleted(); |
179 } | 178 } |
180 virtual ~TestProfileSyncService() { } | 179 virtual ~TestProfileSyncService() { } |
181 | 180 |
182 virtual void CreateBackend() { | |
183 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( | |
184 this, profile(), | |
185 profile()->GetPath(), data_type_controllers(), | |
186 initial_condition_setup_task_.release(), | |
187 num_expected_resumes_, num_expected_pauses_, | |
188 set_initial_sync_ended_on_init_, | |
189 synchronous_backend_initialization_)); | |
190 } | |
191 | |
192 virtual void OnBackendInitialized() { | 181 virtual void OnBackendInitialized() { |
193 ProfileSyncService::OnBackendInitialized(); | 182 ProfileSyncService::OnBackendInitialized(); |
194 // TODO(akalin): Figure out a better way to do this. | 183 // TODO(akalin): Figure out a better way to do this. |
195 if (synchronous_backend_initialization_) { | 184 if (synchronous_backend_initialization_) { |
196 MessageLoop::current()->Quit(); | 185 MessageLoop::current()->Quit(); |
197 } | 186 } |
198 } | 187 } |
199 | 188 |
200 virtual void Observe(NotificationType type, | 189 virtual void Observe(NotificationType type, |
201 const NotificationSource& source, | 190 const NotificationSource& source, |
(...skipping 13 matching lines...) Expand all Loading... |
215 } | 204 } |
216 void dont_set_initial_sync_ended_on_init() { | 205 void dont_set_initial_sync_ended_on_init() { |
217 set_initial_sync_ended_on_init_ = false; | 206 set_initial_sync_ended_on_init_ = false; |
218 } | 207 } |
219 void set_synchronous_sync_configuration() { | 208 void set_synchronous_sync_configuration() { |
220 synchronous_sync_configuration_ = true; | 209 synchronous_sync_configuration_ = true; |
221 } | 210 } |
222 | 211 |
223 browser_sync::TestIdFactory* id_factory() { return &id_factory_; } | 212 browser_sync::TestIdFactory* id_factory() { return &id_factory_; } |
224 | 213 |
| 214 protected: |
| 215 virtual void CreateBackend(); |
| 216 |
225 private: | 217 private: |
226 // When testing under ChromiumOS, this method must not return an empty | 218 // When testing under ChromiumOS, this method must not return an empty |
227 // value value in order for the profile sync service to start. | 219 // value value in order for the profile sync service to start. |
228 virtual std::string GetLsidForAuthBootstraping() { | 220 virtual std::string GetLsidForAuthBootstraping() { |
229 return "foo"; | 221 return "foo"; |
230 } | 222 } |
231 | 223 |
232 bool synchronous_backend_initialization_; | 224 bool synchronous_backend_initialization_; |
233 | 225 |
234 // Set to true when a mock data type manager is being used and the configure | 226 // Set to true when a mock data type manager is being used and the configure |
235 // step is performed synchronously. | 227 // step is performed synchronously. |
236 bool synchronous_sync_configuration_; | 228 bool synchronous_sync_configuration_; |
237 bool set_expect_resume_expectations_; | 229 bool set_expect_resume_expectations_; |
238 int num_expected_resumes_; | 230 int num_expected_resumes_; |
239 int num_expected_pauses_; | 231 int num_expected_pauses_; |
240 | 232 |
241 scoped_ptr<Task> initial_condition_setup_task_; | 233 scoped_ptr<Task> initial_condition_setup_task_; |
242 bool set_initial_sync_ended_on_init_; | 234 bool set_initial_sync_ended_on_init_; |
243 browser_sync::TestIdFactory id_factory_; | 235 browser_sync::TestIdFactory id_factory_; |
244 }; | 236 }; |
245 | 237 |
246 | 238 |
247 | 239 |
248 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ | 240 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |
OLD | NEW |