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/status_change_checker.h" | 11 #include "chrome/browser/sync/test/integration/status_change_checker.h" |
12 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" | 12 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" |
13 #include "chrome/browser/sync/test/integration/sync_test.h" | 13 #include "chrome/browser/sync/test/integration/sync_test.h" |
14 #include "components/browser_sync/profile_sync_components_factory_impl.h" | 14 #include "components/browser_sync/profile_sync_components_factory_impl.h" |
15 #include "components/browser_sync/profile_sync_service.h" | 15 #include "components/browser_sync/profile_sync_service.h" |
16 #include "components/sync/api/fake_model_type_service.h" | 16 #include "components/sync/api/fake_model_type_service.h" |
17 | 17 |
18 using browser_sync::ChromeSyncClient; | 18 using browser_sync::ChromeSyncClient; |
19 using browser_sync::ProfileSyncComponentsFactoryImpl; | 19 using browser_sync::ProfileSyncComponentsFactoryImpl; |
| 20 using syncer_v2::ConflictResolution; |
20 using syncer_v2::FakeModelTypeService; | 21 using syncer_v2::FakeModelTypeService; |
21 using syncer_v2::ModelTypeService; | 22 using syncer_v2::ModelTypeService; |
22 using syncer_v2::SharedModelTypeProcessor; | 23 using syncer_v2::SharedModelTypeProcessor; |
23 | 24 |
24 const char kKey1[] = "key1"; | 25 const char kKey1[] = "key1"; |
25 const char kValue1[] = "value1"; | 26 const char kValue1[] = "value1"; |
26 const char kValue2[] = "value2"; | 27 const char kValue2[] = "value2"; |
27 const char kResolutionValue[] = "RESOLVED"; | 28 const char kValue3[] = "value3"; |
28 | 29 |
29 // A ChromeSyncClient that provides a ModelTypeService for PREFERENCES. | 30 // A ChromeSyncClient that provides a ModelTypeService for PREFERENCES. |
30 class TestSyncClient : public ChromeSyncClient { | 31 class TestSyncClient : public ChromeSyncClient { |
31 public: | 32 public: |
32 TestSyncClient(Profile* profile, ModelTypeService* service) | 33 TestSyncClient(Profile* profile, ModelTypeService* service) |
33 : ChromeSyncClient(profile), service_(service) {} | 34 : ChromeSyncClient(profile), service_(service) {} |
34 | 35 |
35 base::WeakPtr<ModelTypeService> GetModelTypeServiceForType( | 36 base::WeakPtr<ModelTypeService> GetModelTypeServiceForType( |
36 syncer::ModelType type) override { | 37 syncer::ModelType type) override { |
37 return type == syncer::PREFERENCES | 38 return type == syncer::PREFERENCES |
(...skipping 24 matching lines...) Expand all Loading... |
62 std::move(metadata_changes), entity_changes); | 63 std::move(metadata_changes), entity_changes); |
63 NotifyObservers(); | 64 NotifyObservers(); |
64 return error; | 65 return error; |
65 } | 66 } |
66 | 67 |
67 void OnChangeProcessorSet() override { | 68 void OnChangeProcessorSet() override { |
68 change_processor()->OnMetadataLoaded(syncer::SyncError(), | 69 change_processor()->OnMetadataLoaded(syncer::SyncError(), |
69 db().CreateMetadataBatch()); | 70 db().CreateMetadataBatch()); |
70 } | 71 } |
71 | 72 |
72 syncer_v2::ConflictResolution ResolveConflict( | |
73 const syncer_v2::EntityData& local_data, | |
74 const syncer_v2::EntityData& remote_data) const override { | |
75 return syncer_v2::ConflictResolution::UseNew( | |
76 GenerateEntityData(local_data.non_unique_name, kResolutionValue)); | |
77 } | |
78 | |
79 void AddObserver(Observer* observer) { observers_.insert(observer); } | 73 void AddObserver(Observer* observer) { observers_.insert(observer); } |
80 void RemoveObserver(Observer* observer) { observers_.erase(observer); } | 74 void RemoveObserver(Observer* observer) { observers_.erase(observer); } |
81 | 75 |
82 private: | 76 private: |
83 void NotifyObservers() { | 77 void NotifyObservers() { |
84 for (Observer* observer : observers_) { | 78 for (Observer* observer : observers_) { |
85 observer->OnApplySyncChanges(); | 79 observer->OnApplySyncChanges(); |
86 } | 80 } |
87 } | 81 } |
88 | 82 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 ASSERT_EQ(1U, model1->db().data_count()); | 280 ASSERT_EQ(1U, model1->db().data_count()); |
287 ASSERT_EQ(1U, model1->db().metadata_count()); | 281 ASSERT_EQ(1U, model1->db().metadata_count()); |
288 ASSERT_EQ(1U, model2->db().data_count()); | 282 ASSERT_EQ(1U, model2->db().data_count()); |
289 ASSERT_EQ(1U, model2->db().metadata_count()); | 283 ASSERT_EQ(1U, model2->db().metadata_count()); |
290 } | 284 } |
291 | 285 |
292 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, ConflictResolution) { | 286 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, ConflictResolution) { |
293 ASSERT_TRUE(SetupSync()); | 287 ASSERT_TRUE(SetupSync()); |
294 TestModelTypeService* model1 = GetModelTypeService(0); | 288 TestModelTypeService* model1 = GetModelTypeService(0); |
295 TestModelTypeService* model2 = GetModelTypeService(1); | 289 TestModelTypeService* model2 = GetModelTypeService(1); |
| 290 model1->SetConflictResolution(ConflictResolution::UseNew( |
| 291 FakeModelTypeService::GenerateEntityData(kKey1, kValue3))); |
| 292 model2->SetConflictResolution(ConflictResolution::UseNew( |
| 293 FakeModelTypeService::GenerateEntityData(kKey1, kValue3))); |
296 | 294 |
297 // Write conflicting entities. | 295 // Write conflicting entities. |
298 model1->WriteItem(kKey1, kValue1); | 296 model1->WriteItem(kKey1, kValue1); |
299 model2->WriteItem(kKey1, kValue2); | 297 model2->WriteItem(kKey1, kValue2); |
300 | 298 |
301 // Wait for them to be resolved to kResolutionValue by the custom conflict | 299 // Wait for them to be resolved to kResolutionValue by the custom conflict |
302 // resolution logic in TestModelTypeService. | 300 // resolution logic in TestModelTypeService. |
303 ASSERT_TRUE(DataChecker(model1, kKey1, kResolutionValue).Wait()); | 301 ASSERT_TRUE(DataChecker(model1, kKey1, kValue3).Wait()); |
304 ASSERT_TRUE(DataChecker(model2, kKey1, kResolutionValue).Wait()); | 302 ASSERT_TRUE(DataChecker(model2, kKey1, kValue3).Wait()); |
305 } | 303 } |
OLD | NEW |