OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #include "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
7 #include "base/threading/thread_task_runner_handle.h" | 7 #include "base/threading/thread_task_runner_handle.h" |
8 #include "chrome/browser/sync/chrome_sync_client.h" | 8 #include "chrome/browser/sync/chrome_sync_client.h" |
9 #include "chrome/browser/sync/profile_sync_service_factory.h" | 9 #include "chrome/browser/sync/profile_sync_service_factory.h" |
10 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 10 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
11 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" | 11 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" |
12 #include "chrome/browser/sync/test/integration/status_change_checker.h" | 12 #include "chrome/browser/sync/test/integration/status_change_checker.h" |
13 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" | 13 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" |
14 #include "chrome/browser/sync/test/integration/sync_test.h" | 14 #include "chrome/browser/sync/test/integration/sync_test.h" |
15 #include "components/browser_sync/profile_sync_components_factory_impl.h" | 15 #include "components/browser_sync/profile_sync_components_factory_impl.h" |
16 #include "components/browser_sync/profile_sync_service.h" | 16 #include "components/browser_sync/profile_sync_service.h" |
17 #include "components/sync/model/fake_model_type_service.h" | 17 #include "components/sync/model/fake_model_type_service.h" |
18 #include "components/sync/model/metadata_change_list.h" | 18 #include "components/sync/model/metadata_change_list.h" |
19 #include "components/sync/model/model_type_change_processor.h" | 19 #include "components/sync/model/model_type_change_processor.h" |
20 | 20 |
21 using browser_sync::ChromeSyncClient; | 21 using browser_sync::ChromeSyncClient; |
22 using browser_sync::ProfileSyncComponentsFactoryImpl; | 22 using browser_sync::ProfileSyncComponentsFactoryImpl; |
23 using syncer::ConflictResolution; | 23 using syncer::ConflictResolution; |
24 using syncer::FakeModelTypeService; | 24 using syncer::FakeModelTypeService; |
25 using syncer::ModelTypeChangeProcessor; | 25 using syncer::ModelTypeChangeProcessor; |
26 using syncer::ModelTypeService; | 26 using syncer::ModelTypeService; |
27 | 27 |
| 28 namespace { |
| 29 |
28 const char kKey1[] = "key1"; | 30 const char kKey1[] = "key1"; |
29 const char kKey2[] = "key2"; | 31 const char kKey2[] = "key2"; |
| 32 const char kKey3[] = "key3"; |
| 33 const char kKey4[] = "key4"; |
30 const char kValue1[] = "value1"; | 34 const char kValue1[] = "value1"; |
31 const char kValue2[] = "value2"; | 35 const char kValue2[] = "value2"; |
32 const char kValue3[] = "value3"; | 36 const char kValue3[] = "value3"; |
| 37 const char* kPassphrase = "12345"; |
33 | 38 |
34 // A ChromeSyncClient that provides a ModelTypeService for PREFERENCES. | 39 // A ChromeSyncClient that provides a ModelTypeService for PREFERENCES. |
35 class TestSyncClient : public ChromeSyncClient { | 40 class TestSyncClient : public ChromeSyncClient { |
36 public: | 41 public: |
37 TestSyncClient(Profile* profile, ModelTypeService* service) | 42 TestSyncClient(Profile* profile, ModelTypeService* service) |
38 : ChromeSyncClient(profile), service_(service) {} | 43 : ChromeSyncClient(profile), service_(service) {} |
39 | 44 |
40 base::WeakPtr<ModelTypeService> GetModelTypeServiceForType( | 45 base::WeakPtr<ModelTypeService> GetModelTypeServiceForType( |
41 syncer::ModelType type) override { | 46 syncer::ModelType type) override { |
42 return type == syncer::PREFERENCES | 47 return type == syncer::PREFERENCES |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 bool first_client_ignored_ = false; | 231 bool first_client_ignored_ = false; |
227 | 232 |
228 private: | 233 private: |
229 DISALLOW_COPY_AND_ASSIGN(TwoClientUssSyncTest); | 234 DISALLOW_COPY_AND_ASSIGN(TwoClientUssSyncTest); |
230 }; | 235 }; |
231 | 236 |
232 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Sanity) { | 237 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Sanity) { |
233 ASSERT_TRUE(SetupSync()); | 238 ASSERT_TRUE(SetupSync()); |
234 ASSERT_EQ(2U, clients_.size()); | 239 ASSERT_EQ(2U, clients_.size()); |
235 ASSERT_EQ(2U, services_.size()); | 240 ASSERT_EQ(2U, services_.size()); |
236 TestModelTypeService* model1 = GetModelTypeService(0); | 241 TestModelTypeService* model0 = GetModelTypeService(0); |
237 TestModelTypeService* model2 = GetModelTypeService(1); | 242 TestModelTypeService* model1 = GetModelTypeService(1); |
238 | 243 |
239 // Add an entity. | 244 // Add an entity. |
240 model1->WriteItem(kKey1, kValue1); | 245 model0->WriteItem(kKey1, kValue1); |
241 ASSERT_TRUE(DataChecker(model2, kKey1, kValue1).Wait()); | 246 ASSERT_TRUE(DataChecker(model1, kKey1, kValue1).Wait()); |
242 | 247 |
243 // Update an entity. | 248 // Update an entity. |
244 model1->WriteItem(kKey1, kValue2); | 249 model0->WriteItem(kKey1, kValue2); |
245 ASSERT_TRUE(DataChecker(model2, kKey1, kValue2).Wait()); | 250 ASSERT_TRUE(DataChecker(model1, kKey1, kValue2).Wait()); |
246 | 251 |
247 // Delete an entity. | 252 // Delete an entity. |
248 model1->DeleteItem(kKey1); | 253 model0->DeleteItem(kKey1); |
249 ASSERT_TRUE(DataAbsentChecker(model2, kKey1).Wait()); | 254 ASSERT_TRUE(DataAbsentChecker(model1, kKey1).Wait()); |
250 } | 255 } |
251 | 256 |
252 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, DisableEnable) { | 257 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, DisableEnable) { |
253 ASSERT_TRUE(SetupSync()); | 258 ASSERT_TRUE(SetupSync()); |
254 TestModelTypeService* model1 = GetModelTypeService(0); | 259 TestModelTypeService* model0 = GetModelTypeService(0); |
255 TestModelTypeService* model2 = GetModelTypeService(1); | 260 TestModelTypeService* model1 = GetModelTypeService(1); |
256 | 261 |
257 // Add an entity to test with. | 262 // Add an entity to test with. |
258 model1->WriteItem(kKey1, kValue1); | 263 model0->WriteItem(kKey1, kValue1); |
259 ASSERT_TRUE(DataChecker(model2, kKey1, kValue1).Wait()); | 264 ASSERT_TRUE(DataChecker(model1, kKey1, kValue1).Wait()); |
| 265 ASSERT_EQ(1U, model0->db().data_count()); |
| 266 ASSERT_EQ(1U, model0->db().metadata_count()); |
260 ASSERT_EQ(1U, model1->db().data_count()); | 267 ASSERT_EQ(1U, model1->db().data_count()); |
261 ASSERT_EQ(1U, model1->db().metadata_count()); | 268 ASSERT_EQ(1U, model1->db().metadata_count()); |
262 ASSERT_EQ(1U, model2->db().data_count()); | |
263 ASSERT_EQ(1U, model2->db().metadata_count()); | |
264 | 269 |
265 // Disable PREFERENCES. | 270 // Disable PREFERENCES. |
266 syncer::ModelTypeSet types = syncer::UserSelectableTypes(); | 271 syncer::ModelTypeSet types = syncer::UserSelectableTypes(); |
267 types.Remove(syncer::PREFERENCES); | 272 types.Remove(syncer::PREFERENCES); |
268 GetSyncService(0)->OnUserChoseDatatypes(false, types); | 273 GetSyncService(0)->OnUserChoseDatatypes(false, types); |
269 | 274 |
270 // Wait for it to take effect and remove the metadata. | 275 // Wait for it to take effect and remove the metadata. |
271 ASSERT_TRUE(MetadataAbsentChecker(model1, kKey1).Wait()); | 276 ASSERT_TRUE(MetadataAbsentChecker(model0, kKey1).Wait()); |
| 277 ASSERT_EQ(1U, model0->db().data_count()); |
| 278 ASSERT_EQ(0U, model0->db().metadata_count()); |
| 279 // Model 1 should not be affected. |
272 ASSERT_EQ(1U, model1->db().data_count()); | 280 ASSERT_EQ(1U, model1->db().data_count()); |
273 ASSERT_EQ(0U, model1->db().metadata_count()); | 281 ASSERT_EQ(1U, model1->db().metadata_count()); |
274 // Model 2 should not be affected. | |
275 ASSERT_EQ(1U, model2->db().data_count()); | |
276 ASSERT_EQ(1U, model2->db().metadata_count()); | |
277 | 282 |
278 // Re-enable PREFERENCES. | 283 // Re-enable PREFERENCES. |
279 GetSyncService(0)->OnUserChoseDatatypes(true, syncer::UserSelectableTypes()); | 284 GetSyncService(0)->OnUserChoseDatatypes(true, syncer::UserSelectableTypes()); |
280 | 285 |
281 // Wait for metadata to be re-added. | 286 // Wait for metadata to be re-added. |
282 ASSERT_TRUE(MetadataPresentChecker(model1, kKey1).Wait()); | 287 ASSERT_TRUE(MetadataPresentChecker(model0, kKey1).Wait()); |
| 288 ASSERT_EQ(1U, model0->db().data_count()); |
| 289 ASSERT_EQ(1U, model0->db().metadata_count()); |
283 ASSERT_EQ(1U, model1->db().data_count()); | 290 ASSERT_EQ(1U, model1->db().data_count()); |
284 ASSERT_EQ(1U, model1->db().metadata_count()); | 291 ASSERT_EQ(1U, model1->db().metadata_count()); |
285 ASSERT_EQ(1U, model2->db().data_count()); | |
286 ASSERT_EQ(1U, model2->db().metadata_count()); | |
287 } | 292 } |
288 | 293 |
289 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, ConflictResolution) { | 294 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, ConflictResolution) { |
290 ASSERT_TRUE(SetupSync()); | 295 ASSERT_TRUE(SetupSync()); |
291 TestModelTypeService* model1 = GetModelTypeService(0); | 296 TestModelTypeService* model0 = GetModelTypeService(0); |
292 TestModelTypeService* model2 = GetModelTypeService(1); | 297 TestModelTypeService* model1 = GetModelTypeService(1); |
| 298 model0->SetConflictResolution(ConflictResolution::UseNew( |
| 299 FakeModelTypeService::GenerateEntityData(kKey1, kValue3))); |
293 model1->SetConflictResolution(ConflictResolution::UseNew( | 300 model1->SetConflictResolution(ConflictResolution::UseNew( |
294 FakeModelTypeService::GenerateEntityData(kKey1, kValue3))); | 301 FakeModelTypeService::GenerateEntityData(kKey1, kValue3))); |
295 model2->SetConflictResolution(ConflictResolution::UseNew( | |
296 FakeModelTypeService::GenerateEntityData(kKey1, kValue3))); | |
297 | 302 |
298 // Write conflicting entities. | 303 // Write conflicting entities. |
299 model1->WriteItem(kKey1, kValue1); | 304 model0->WriteItem(kKey1, kValue1); |
300 model2->WriteItem(kKey1, kValue2); | 305 model1->WriteItem(kKey1, kValue2); |
301 | 306 |
302 // Wait for them to be resolved to kResolutionValue by the custom conflict | 307 // Wait for them to be resolved to kResolutionValue by the custom conflict |
303 // resolution logic in TestModelTypeService. | 308 // resolution logic in TestModelTypeService. |
| 309 ASSERT_TRUE(DataChecker(model0, kKey1, kValue3).Wait()); |
304 ASSERT_TRUE(DataChecker(model1, kKey1, kValue3).Wait()); | 310 ASSERT_TRUE(DataChecker(model1, kKey1, kValue3).Wait()); |
305 ASSERT_TRUE(DataChecker(model2, kKey1, kValue3).Wait()); | |
306 } | 311 } |
307 | 312 |
308 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Error) { | 313 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Error) { |
309 ASSERT_TRUE(SetupSync()); | 314 ASSERT_TRUE(SetupSync()); |
310 TestModelTypeService* model1 = GetModelTypeService(0); | 315 TestModelTypeService* model0 = GetModelTypeService(0); |
311 TestModelTypeService* model2 = GetModelTypeService(1); | 316 TestModelTypeService* model1 = GetModelTypeService(1); |
312 | 317 |
313 // Add an entity. | 318 // Add an entity. |
314 model1->WriteItem(kKey1, kValue1); | 319 model0->WriteItem(kKey1, kValue1); |
315 ASSERT_TRUE(DataChecker(model2, kKey1, kValue1).Wait()); | 320 ASSERT_TRUE(DataChecker(model1, kKey1, kValue1).Wait()); |
316 | 321 |
317 // Set an error in model 2 to trigger in the next GetUpdates. | 322 // Set an error in model 1 to trigger in the next GetUpdates. |
318 model2->SetServiceError(syncer::SyncError::DATATYPE_ERROR); | 323 model1->SetServiceError(syncer::SyncError::DATATYPE_ERROR); |
319 // Write an item on model 1 to trigger a GetUpdates in model 2. | 324 // Write an item on model 0 to trigger a GetUpdates in model 1. |
320 model1->WriteItem(kKey1, kValue2); | 325 model0->WriteItem(kKey1, kValue2); |
321 | 326 |
322 // The type should stop syncing but keep tracking metadata. | 327 // The type should stop syncing but keep tracking metadata. |
323 ASSERT_TRUE(PrefsNotRunningChecker(GetSyncService(1)).Wait()); | 328 ASSERT_TRUE(PrefsNotRunningChecker(GetSyncService(1)).Wait()); |
324 ASSERT_EQ(1U, model2->db().metadata_count()); | 329 ASSERT_EQ(1U, model1->db().metadata_count()); |
325 model2->WriteItem(kKey2, kValue2); | 330 model1->WriteItem(kKey2, kValue2); |
326 ASSERT_EQ(2U, model2->db().metadata_count()); | 331 ASSERT_EQ(2U, model1->db().metadata_count()); |
327 } | 332 } |
| 333 |
| 334 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Encryption) { |
| 335 ASSERT_TRUE(SetupSync()); |
| 336 TestModelTypeService* model0 = GetModelTypeService(0); |
| 337 TestModelTypeService* model1 = GetModelTypeService(1); |
| 338 |
| 339 model0->WriteItem(kKey1, kValue1); |
| 340 ASSERT_TRUE(DataChecker(model1, kKey1, kValue1).Wait()); |
| 341 |
| 342 GetSyncService(0)->SetEncryptionPassphrase(kPassphrase, |
| 343 syncer::SyncService::EXPLICIT); |
| 344 ASSERT_TRUE(PassphraseAcceptedChecker(GetSyncService(0)).Wait()); |
| 345 // Wait for client 1 to know that a passphrase is happening to avoid potential |
| 346 // race conditions and make the functionality this case tests more consistent. |
| 347 ASSERT_TRUE(PassphraseRequiredChecker(GetSyncService(1)).Wait()); |
| 348 |
| 349 model0->WriteItem(kKey1, kValue2); |
| 350 model0->WriteItem(kKey2, kValue1); |
| 351 model1->WriteItem(kKey3, kValue1); |
| 352 |
| 353 ASSERT_TRUE(GetSyncService(1)->SetDecryptionPassphrase(kPassphrase)); |
| 354 ASSERT_TRUE(PassphraseAcceptedChecker(GetSyncService(1)).Wait()); |
| 355 |
| 356 model0->WriteItem(kKey4, kValue1); |
| 357 |
| 358 ASSERT_TRUE(DataChecker(model1, kKey1, kValue2).Wait()); |
| 359 ASSERT_TRUE(DataChecker(model1, kKey2, kValue1).Wait()); |
| 360 ASSERT_TRUE(DataChecker(model1, kKey4, kValue1).Wait()); |
| 361 |
| 362 ASSERT_TRUE(DataChecker(model0, kKey1, kValue2).Wait()); |
| 363 ASSERT_TRUE(DataChecker(model0, kKey3, kValue1).Wait()); |
| 364 } |
| 365 |
| 366 } // namespace |
OLD | NEW |