| 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_sync_bridge.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::FakeModelTypeSyncBridge; |
| 25 using syncer::ModelTypeChangeProcessor; | 25 using syncer::ModelTypeChangeProcessor; |
| 26 using syncer::ModelTypeService; | 26 using syncer::ModelTypeSyncBridge; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 const char kKey1[] = "key1"; | 30 const char kKey1[] = "key1"; |
| 31 const char kKey2[] = "key2"; | 31 const char kKey2[] = "key2"; |
| 32 const char kKey3[] = "key3"; | 32 const char kKey3[] = "key3"; |
| 33 const char kKey4[] = "key4"; | 33 const char kKey4[] = "key4"; |
| 34 const char kValue1[] = "value1"; | 34 const char kValue1[] = "value1"; |
| 35 const char kValue2[] = "value2"; | 35 const char kValue2[] = "value2"; |
| 36 const char kValue3[] = "value3"; | 36 const char kValue3[] = "value3"; |
| 37 const char* kPassphrase = "12345"; | 37 const char* kPassphrase = "12345"; |
| 38 | 38 |
| 39 // A ChromeSyncClient that provides a ModelTypeService for PREFERENCES. | 39 // A ChromeSyncClient that provides a ModelTypeSyncBridge for PREFERENCES. |
| 40 class TestSyncClient : public ChromeSyncClient { | 40 class TestSyncClient : public ChromeSyncClient { |
| 41 public: | 41 public: |
| 42 TestSyncClient(Profile* profile, ModelTypeService* service) | 42 TestSyncClient(Profile* profile, ModelTypeSyncBridge* bridge) |
| 43 : ChromeSyncClient(profile), service_(service) {} | 43 : ChromeSyncClient(profile), bridge_(bridge) {} |
| 44 | 44 |
| 45 base::WeakPtr<ModelTypeService> GetModelTypeServiceForType( | 45 base::WeakPtr<ModelTypeSyncBridge> GetSyncBridgeForModelType( |
| 46 syncer::ModelType type) override { | 46 syncer::ModelType type) override { |
| 47 return type == syncer::PREFERENCES | 47 return type == syncer::PREFERENCES |
| 48 ? service_->AsWeakPtr() | 48 ? bridge_->AsWeakPtr() |
| 49 : ChromeSyncClient::GetModelTypeServiceForType(type); | 49 : ChromeSyncClient::GetSyncBridgeForModelType(type); |
| 50 } | 50 } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 ModelTypeService* const service_; | 53 ModelTypeSyncBridge* const bridge_; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // A FakeModelTypeService that supports observing ApplySyncChanges. | 56 // A FakeModelTypeSyncBridge that supports observing ApplySyncChanges. |
| 57 class TestModelTypeService : public FakeModelTypeService { | 57 class TestModelTypeSyncBridge : public FakeModelTypeSyncBridge { |
| 58 public: | 58 public: |
| 59 class Observer { | 59 class Observer { |
| 60 public: | 60 public: |
| 61 virtual void OnApplySyncChanges() = 0; | 61 virtual void OnApplySyncChanges() = 0; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 TestModelTypeService() | 64 TestModelTypeSyncBridge() |
| 65 : FakeModelTypeService(base::Bind(&ModelTypeChangeProcessor::Create)) { | 65 : FakeModelTypeSyncBridge(base::Bind(&ModelTypeChangeProcessor::Create)) { |
| 66 change_processor()->OnMetadataLoaded(syncer::SyncError(), | 66 change_processor()->OnMetadataLoaded(syncer::SyncError(), |
| 67 db().CreateMetadataBatch()); | 67 db().CreateMetadataBatch()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 syncer::SyncError ApplySyncChanges( | 70 syncer::SyncError ApplySyncChanges( |
| 71 std::unique_ptr<syncer::MetadataChangeList> metadata_changes, | 71 std::unique_ptr<syncer::MetadataChangeList> metadata_changes, |
| 72 syncer::EntityChangeList entity_changes) override { | 72 syncer::EntityChangeList entity_changes) override { |
| 73 syncer::SyncError error = FakeModelTypeService::ApplySyncChanges( | 73 syncer::SyncError error = FakeModelTypeSyncBridge::ApplySyncChanges( |
| 74 std::move(metadata_changes), entity_changes); | 74 std::move(metadata_changes), entity_changes); |
| 75 NotifyObservers(); | 75 NotifyObservers(); |
| 76 return error; | 76 return error; |
| 77 } | 77 } |
| 78 | 78 |
| 79 void AddObserver(Observer* observer) { observers_.insert(observer); } | 79 void AddObserver(Observer* observer) { observers_.insert(observer); } |
| 80 void RemoveObserver(Observer* observer) { observers_.erase(observer); } | 80 void RemoveObserver(Observer* observer) { observers_.erase(observer); } |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 void NotifyObservers() { | 83 void NotifyObservers() { |
| 84 for (Observer* observer : observers_) { | 84 for (Observer* observer : observers_) { |
| 85 observer->OnApplySyncChanges(); | 85 observer->OnApplySyncChanges(); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 std::set<Observer*> observers_; | 89 std::set<Observer*> observers_; |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 // A StatusChangeChecker for checking the status of keys in a | 92 // A StatusChangeChecker for checking the status of keys in a |
| 93 // TestModelTypeService::Store. | 93 // TestModelTypeSyncBridge::Store. |
| 94 class KeyChecker : public StatusChangeChecker, | 94 class KeyChecker : public StatusChangeChecker, |
| 95 public TestModelTypeService::Observer { | 95 public TestModelTypeSyncBridge::Observer { |
| 96 public: | 96 public: |
| 97 KeyChecker(TestModelTypeService* service, const std::string& key) | 97 KeyChecker(TestModelTypeSyncBridge* bridge, const std::string& key) |
| 98 : service_(service), key_(key) { | 98 : bridge_(bridge), key_(key) { |
| 99 service_->AddObserver(this); | 99 bridge_->AddObserver(this); |
| 100 } | 100 } |
| 101 | 101 |
| 102 ~KeyChecker() override { service_->RemoveObserver(this); } | 102 ~KeyChecker() override { bridge_->RemoveObserver(this); } |
| 103 | 103 |
| 104 void OnApplySyncChanges() override { CheckExitCondition(); } | 104 void OnApplySyncChanges() override { CheckExitCondition(); } |
| 105 | 105 |
| 106 protected: | 106 protected: |
| 107 TestModelTypeService* const service_; | 107 TestModelTypeSyncBridge* const bridge_; |
| 108 const std::string key_; | 108 const std::string key_; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 // Wait for data for a key to have a certain value. | 111 // Wait for data for a key to have a certain value. |
| 112 class DataChecker : public KeyChecker { | 112 class DataChecker : public KeyChecker { |
| 113 public: | 113 public: |
| 114 DataChecker(TestModelTypeService* service, | 114 DataChecker(TestModelTypeSyncBridge* bridge, |
| 115 const std::string& key, | 115 const std::string& key, |
| 116 const std::string& value) | 116 const std::string& value) |
| 117 : KeyChecker(service, key), value_(value) {} | 117 : KeyChecker(bridge, key), value_(value) {} |
| 118 | 118 |
| 119 bool IsExitConditionSatisfied() override { | 119 bool IsExitConditionSatisfied() override { |
| 120 const auto& db = service_->db(); | 120 const auto& db = bridge_->db(); |
| 121 return db.HasData(key_) && db.GetValue(key_) == value_; | 121 return db.HasData(key_) && db.GetValue(key_) == value_; |
| 122 } | 122 } |
| 123 | 123 |
| 124 std::string GetDebugMessage() const override { | 124 std::string GetDebugMessage() const override { |
| 125 return "Waiting for data for key '" + key_ + "' to be '" + value_ + "'."; | 125 return "Waiting for data for key '" + key_ + "' to be '" + value_ + "'."; |
| 126 } | 126 } |
| 127 | 127 |
| 128 private: | 128 private: |
| 129 const std::string value_; | 129 const std::string value_; |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 // Wait for data for a key to be absent. | 132 // Wait for data for a key to be absent. |
| 133 class DataAbsentChecker : public KeyChecker { | 133 class DataAbsentChecker : public KeyChecker { |
| 134 public: | 134 public: |
| 135 DataAbsentChecker(TestModelTypeService* service, const std::string& key) | 135 DataAbsentChecker(TestModelTypeSyncBridge* bridge, const std::string& key) |
| 136 : KeyChecker(service, key) {} | 136 : KeyChecker(bridge, key) {} |
| 137 | 137 |
| 138 bool IsExitConditionSatisfied() override { | 138 bool IsExitConditionSatisfied() override { |
| 139 return !service_->db().HasData(key_); | 139 return !bridge_->db().HasData(key_); |
| 140 } | 140 } |
| 141 | 141 |
| 142 std::string GetDebugMessage() const override { | 142 std::string GetDebugMessage() const override { |
| 143 return "Waiting for data for key '" + key_ + "' to be absent."; | 143 return "Waiting for data for key '" + key_ + "' to be absent."; |
| 144 } | 144 } |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 // Wait for metadata for a key to be present. | 147 // Wait for metadata for a key to be present. |
| 148 class MetadataPresentChecker : public KeyChecker { | 148 class MetadataPresentChecker : public KeyChecker { |
| 149 public: | 149 public: |
| 150 MetadataPresentChecker(TestModelTypeService* service, const std::string& key) | 150 MetadataPresentChecker(TestModelTypeSyncBridge* bridge, |
| 151 : KeyChecker(service, key) {} | 151 const std::string& key) |
| 152 : KeyChecker(bridge, key) {} |
| 152 | 153 |
| 153 bool IsExitConditionSatisfied() override { | 154 bool IsExitConditionSatisfied() override { |
| 154 return service_->db().HasMetadata(key_); | 155 return bridge_->db().HasMetadata(key_); |
| 155 } | 156 } |
| 156 | 157 |
| 157 std::string GetDebugMessage() const override { | 158 std::string GetDebugMessage() const override { |
| 158 return "Waiting for metadata for key '" + key_ + "' to be present."; | 159 return "Waiting for metadata for key '" + key_ + "' to be present."; |
| 159 } | 160 } |
| 160 }; | 161 }; |
| 161 | 162 |
| 162 // Wait for metadata for a key to be absent. | 163 // Wait for metadata for a key to be absent. |
| 163 class MetadataAbsentChecker : public KeyChecker { | 164 class MetadataAbsentChecker : public KeyChecker { |
| 164 public: | 165 public: |
| 165 MetadataAbsentChecker(TestModelTypeService* service, const std::string& key) | 166 MetadataAbsentChecker(TestModelTypeSyncBridge* bridge, const std::string& key) |
| 166 : KeyChecker(service, key) {} | 167 : KeyChecker(bridge, key) {} |
| 167 | 168 |
| 168 bool IsExitConditionSatisfied() override { | 169 bool IsExitConditionSatisfied() override { |
| 169 return !service_->db().HasMetadata(key_); | 170 return !bridge_->db().HasMetadata(key_); |
| 170 } | 171 } |
| 171 | 172 |
| 172 std::string GetDebugMessage() const override { | 173 std::string GetDebugMessage() const override { |
| 173 return "Waiting for metadata for key '" + key_ + "' to be absent."; | 174 return "Waiting for metadata for key '" + key_ + "' to be absent."; |
| 174 } | 175 } |
| 175 }; | 176 }; |
| 176 | 177 |
| 177 // Wait for PREFERENCES to no longer be running. | 178 // Wait for PREFERENCES to no longer be running. |
| 178 class PrefsNotRunningChecker : public SingleClientStatusChangeChecker { | 179 class PrefsNotRunningChecker : public SingleClientStatusChangeChecker { |
| 179 public: | 180 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 200 ProfileSyncComponentsFactoryImpl::OverridePrefsForUssTest(true); | 201 ProfileSyncComponentsFactoryImpl::OverridePrefsForUssTest(true); |
| 201 } | 202 } |
| 202 | 203 |
| 203 ~TwoClientUssSyncTest() override { | 204 ~TwoClientUssSyncTest() override { |
| 204 ProfileSyncServiceFactory::SetSyncClientFactoryForTest(nullptr); | 205 ProfileSyncServiceFactory::SetSyncClientFactoryForTest(nullptr); |
| 205 ProfileSyncComponentsFactoryImpl::OverridePrefsForUssTest(false); | 206 ProfileSyncComponentsFactoryImpl::OverridePrefsForUssTest(false); |
| 206 } | 207 } |
| 207 | 208 |
| 208 bool TestUsesSelfNotifications() override { return false; } | 209 bool TestUsesSelfNotifications() override { return false; } |
| 209 | 210 |
| 210 TestModelTypeService* GetModelTypeService(int i) { | 211 TestModelTypeSyncBridge* GetModelTypeSyncBridge(int i) { |
| 211 return services_.at(i).get(); | 212 return bridges_.at(i).get(); |
| 212 } | 213 } |
| 213 | 214 |
| 214 protected: | 215 protected: |
| 215 std::unique_ptr<syncer::SyncClient> CreateSyncClient(Profile* profile) { | 216 std::unique_ptr<syncer::SyncClient> CreateSyncClient(Profile* profile) { |
| 216 if (!first_client_ignored_) { | 217 if (!first_client_ignored_) { |
| 217 // The test infra creates a profile before the two made for sync tests. | 218 // The test infra creates a profile before the two made for sync tests. |
| 218 first_client_ignored_ = true; | 219 first_client_ignored_ = true; |
| 219 return base::MakeUnique<ChromeSyncClient>(profile); | 220 return base::MakeUnique<ChromeSyncClient>(profile); |
| 220 } | 221 } |
| 221 auto service = base::MakeUnique<TestModelTypeService>(); | 222 auto bridge = base::MakeUnique<TestModelTypeSyncBridge>(); |
| 222 auto client = base::MakeUnique<TestSyncClient>(profile, service.get()); | 223 auto client = base::MakeUnique<TestSyncClient>(profile, bridge.get()); |
| 223 clients_.push_back(client.get()); | 224 clients_.push_back(client.get()); |
| 224 services_.push_back(std::move(service)); | 225 bridges_.push_back(std::move(bridge)); |
| 225 return std::move(client); | 226 return std::move(client); |
| 226 } | 227 } |
| 227 | 228 |
| 228 ProfileSyncServiceFactory::SyncClientFactory sync_client_factory_; | 229 ProfileSyncServiceFactory::SyncClientFactory sync_client_factory_; |
| 229 std::vector<std::unique_ptr<TestModelTypeService>> services_; | 230 std::vector<std::unique_ptr<TestModelTypeSyncBridge>> bridges_; |
| 230 std::vector<TestSyncClient*> clients_; | 231 std::vector<TestSyncClient*> clients_; |
| 231 bool first_client_ignored_ = false; | 232 bool first_client_ignored_ = false; |
| 232 | 233 |
| 233 private: | 234 private: |
| 234 DISALLOW_COPY_AND_ASSIGN(TwoClientUssSyncTest); | 235 DISALLOW_COPY_AND_ASSIGN(TwoClientUssSyncTest); |
| 235 }; | 236 }; |
| 236 | 237 |
| 237 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Sanity) { | 238 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Sanity) { |
| 238 ASSERT_TRUE(SetupSync()); | 239 ASSERT_TRUE(SetupSync()); |
| 239 ASSERT_EQ(2U, clients_.size()); | 240 ASSERT_EQ(2U, clients_.size()); |
| 240 ASSERT_EQ(2U, services_.size()); | 241 ASSERT_EQ(2U, bridges_.size()); |
| 241 TestModelTypeService* model0 = GetModelTypeService(0); | 242 TestModelTypeSyncBridge* model0 = GetModelTypeSyncBridge(0); |
| 242 TestModelTypeService* model1 = GetModelTypeService(1); | 243 TestModelTypeSyncBridge* model1 = GetModelTypeSyncBridge(1); |
| 243 | 244 |
| 244 // Add an entity. | 245 // Add an entity. |
| 245 model0->WriteItem(kKey1, kValue1); | 246 model0->WriteItem(kKey1, kValue1); |
| 246 ASSERT_TRUE(DataChecker(model1, kKey1, kValue1).Wait()); | 247 ASSERT_TRUE(DataChecker(model1, kKey1, kValue1).Wait()); |
| 247 | 248 |
| 248 // Update an entity. | 249 // Update an entity. |
| 249 model0->WriteItem(kKey1, kValue2); | 250 model0->WriteItem(kKey1, kValue2); |
| 250 ASSERT_TRUE(DataChecker(model1, kKey1, kValue2).Wait()); | 251 ASSERT_TRUE(DataChecker(model1, kKey1, kValue2).Wait()); |
| 251 | 252 |
| 252 // Delete an entity. | 253 // Delete an entity. |
| 253 model0->DeleteItem(kKey1); | 254 model0->DeleteItem(kKey1); |
| 254 ASSERT_TRUE(DataAbsentChecker(model1, kKey1).Wait()); | 255 ASSERT_TRUE(DataAbsentChecker(model1, kKey1).Wait()); |
| 255 } | 256 } |
| 256 | 257 |
| 257 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, DisableEnable) { | 258 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, DisableEnable) { |
| 258 ASSERT_TRUE(SetupSync()); | 259 ASSERT_TRUE(SetupSync()); |
| 259 TestModelTypeService* model0 = GetModelTypeService(0); | 260 TestModelTypeSyncBridge* model0 = GetModelTypeSyncBridge(0); |
| 260 TestModelTypeService* model1 = GetModelTypeService(1); | 261 TestModelTypeSyncBridge* model1 = GetModelTypeSyncBridge(1); |
| 261 | 262 |
| 262 // Add an entity to test with. | 263 // Add an entity to test with. |
| 263 model0->WriteItem(kKey1, kValue1); | 264 model0->WriteItem(kKey1, kValue1); |
| 264 ASSERT_TRUE(DataChecker(model1, kKey1, kValue1).Wait()); | 265 ASSERT_TRUE(DataChecker(model1, kKey1, kValue1).Wait()); |
| 265 ASSERT_EQ(1U, model0->db().data_count()); | 266 ASSERT_EQ(1U, model0->db().data_count()); |
| 266 ASSERT_EQ(1U, model0->db().metadata_count()); | 267 ASSERT_EQ(1U, model0->db().metadata_count()); |
| 267 ASSERT_EQ(1U, model1->db().data_count()); | 268 ASSERT_EQ(1U, model1->db().data_count()); |
| 268 ASSERT_EQ(1U, model1->db().metadata_count()); | 269 ASSERT_EQ(1U, model1->db().metadata_count()); |
| 269 | 270 |
| 270 // Disable PREFERENCES. | 271 // Disable PREFERENCES. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 286 // Wait for metadata to be re-added. | 287 // Wait for metadata to be re-added. |
| 287 ASSERT_TRUE(MetadataPresentChecker(model0, kKey1).Wait()); | 288 ASSERT_TRUE(MetadataPresentChecker(model0, kKey1).Wait()); |
| 288 ASSERT_EQ(1U, model0->db().data_count()); | 289 ASSERT_EQ(1U, model0->db().data_count()); |
| 289 ASSERT_EQ(1U, model0->db().metadata_count()); | 290 ASSERT_EQ(1U, model0->db().metadata_count()); |
| 290 ASSERT_EQ(1U, model1->db().data_count()); | 291 ASSERT_EQ(1U, model1->db().data_count()); |
| 291 ASSERT_EQ(1U, model1->db().metadata_count()); | 292 ASSERT_EQ(1U, model1->db().metadata_count()); |
| 292 } | 293 } |
| 293 | 294 |
| 294 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, ConflictResolution) { | 295 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, ConflictResolution) { |
| 295 ASSERT_TRUE(SetupSync()); | 296 ASSERT_TRUE(SetupSync()); |
| 296 TestModelTypeService* model0 = GetModelTypeService(0); | 297 TestModelTypeSyncBridge* model0 = GetModelTypeSyncBridge(0); |
| 297 TestModelTypeService* model1 = GetModelTypeService(1); | 298 TestModelTypeSyncBridge* model1 = GetModelTypeSyncBridge(1); |
| 298 model0->SetConflictResolution(ConflictResolution::UseNew( | 299 model0->SetConflictResolution(ConflictResolution::UseNew( |
| 299 FakeModelTypeService::GenerateEntityData(kKey1, kValue3))); | 300 FakeModelTypeSyncBridge::GenerateEntityData(kKey1, kValue3))); |
| 300 model1->SetConflictResolution(ConflictResolution::UseNew( | 301 model1->SetConflictResolution(ConflictResolution::UseNew( |
| 301 FakeModelTypeService::GenerateEntityData(kKey1, kValue3))); | 302 FakeModelTypeSyncBridge::GenerateEntityData(kKey1, kValue3))); |
| 302 | 303 |
| 303 // Write conflicting entities. | 304 // Write conflicting entities. |
| 304 model0->WriteItem(kKey1, kValue1); | 305 model0->WriteItem(kKey1, kValue1); |
| 305 model1->WriteItem(kKey1, kValue2); | 306 model1->WriteItem(kKey1, kValue2); |
| 306 | 307 |
| 307 // Wait for them to be resolved to kResolutionValue by the custom conflict | 308 // Wait for them to be resolved to kResolutionValue by the custom conflict |
| 308 // resolution logic in TestModelTypeService. | 309 // resolution logic in TestModelTypeSyncBridge. |
| 309 ASSERT_TRUE(DataChecker(model0, kKey1, kValue3).Wait()); | 310 ASSERT_TRUE(DataChecker(model0, kKey1, kValue3).Wait()); |
| 310 ASSERT_TRUE(DataChecker(model1, kKey1, kValue3).Wait()); | 311 ASSERT_TRUE(DataChecker(model1, kKey1, kValue3).Wait()); |
| 311 } | 312 } |
| 312 | 313 |
| 313 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Error) { | 314 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Error) { |
| 314 ASSERT_TRUE(SetupSync()); | 315 ASSERT_TRUE(SetupSync()); |
| 315 TestModelTypeService* model0 = GetModelTypeService(0); | 316 TestModelTypeSyncBridge* model0 = GetModelTypeSyncBridge(0); |
| 316 TestModelTypeService* model1 = GetModelTypeService(1); | 317 TestModelTypeSyncBridge* model1 = GetModelTypeSyncBridge(1); |
| 317 | 318 |
| 318 // Add an entity. | 319 // Add an entity. |
| 319 model0->WriteItem(kKey1, kValue1); | 320 model0->WriteItem(kKey1, kValue1); |
| 320 ASSERT_TRUE(DataChecker(model1, kKey1, kValue1).Wait()); | 321 ASSERT_TRUE(DataChecker(model1, kKey1, kValue1).Wait()); |
| 321 | 322 |
| 322 // Set an error in model 1 to trigger in the next GetUpdates. | 323 // Set an error in model 1 to trigger in the next GetUpdates. |
| 323 model1->SetServiceError(syncer::SyncError::DATATYPE_ERROR); | 324 model1->ErrorOnNextCall(syncer::SyncError::DATATYPE_ERROR); |
| 324 // Write an item on model 0 to trigger a GetUpdates in model 1. | 325 // Write an item on model 0 to trigger a GetUpdates in model 1. |
| 325 model0->WriteItem(kKey1, kValue2); | 326 model0->WriteItem(kKey1, kValue2); |
| 326 | 327 |
| 327 // The type should stop syncing but keep tracking metadata. | 328 // The type should stop syncing but keep tracking metadata. |
| 328 ASSERT_TRUE(PrefsNotRunningChecker(GetSyncService(1)).Wait()); | 329 ASSERT_TRUE(PrefsNotRunningChecker(GetSyncService(1)).Wait()); |
| 329 ASSERT_EQ(1U, model1->db().metadata_count()); | 330 ASSERT_EQ(1U, model1->db().metadata_count()); |
| 330 model1->WriteItem(kKey2, kValue2); | 331 model1->WriteItem(kKey2, kValue2); |
| 331 ASSERT_EQ(2U, model1->db().metadata_count()); | 332 ASSERT_EQ(2U, model1->db().metadata_count()); |
| 332 } | 333 } |
| 333 | 334 |
| 334 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Encryption) { | 335 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Encryption) { |
| 335 ASSERT_TRUE(SetupSync()); | 336 ASSERT_TRUE(SetupSync()); |
| 336 TestModelTypeService* model0 = GetModelTypeService(0); | 337 TestModelTypeSyncBridge* model0 = GetModelTypeSyncBridge(0); |
| 337 TestModelTypeService* model1 = GetModelTypeService(1); | 338 TestModelTypeSyncBridge* model1 = GetModelTypeSyncBridge(1); |
| 338 | 339 |
| 339 model0->WriteItem(kKey1, kValue1); | 340 model0->WriteItem(kKey1, kValue1); |
| 340 ASSERT_TRUE(DataChecker(model1, kKey1, kValue1).Wait()); | 341 ASSERT_TRUE(DataChecker(model1, kKey1, kValue1).Wait()); |
| 341 | 342 |
| 342 GetSyncService(0)->SetEncryptionPassphrase(kPassphrase, | 343 GetSyncService(0)->SetEncryptionPassphrase(kPassphrase, |
| 343 syncer::SyncService::EXPLICIT); | 344 syncer::SyncService::EXPLICIT); |
| 344 ASSERT_TRUE(PassphraseAcceptedChecker(GetSyncService(0)).Wait()); | 345 ASSERT_TRUE(PassphraseAcceptedChecker(GetSyncService(0)).Wait()); |
| 345 // Wait for client 1 to know that a passphrase is happening to avoid potential | 346 // 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 // race conditions and make the functionality this case tests more consistent. |
| 347 ASSERT_TRUE(PassphraseRequiredChecker(GetSyncService(1)).Wait()); | 348 ASSERT_TRUE(PassphraseRequiredChecker(GetSyncService(1)).Wait()); |
| 348 | 349 |
| 349 model0->WriteItem(kKey1, kValue2); | 350 model0->WriteItem(kKey1, kValue2); |
| 350 model0->WriteItem(kKey2, kValue1); | 351 model0->WriteItem(kKey2, kValue1); |
| 351 model1->WriteItem(kKey3, kValue1); | 352 model1->WriteItem(kKey3, kValue1); |
| 352 | 353 |
| 353 ASSERT_TRUE(GetSyncService(1)->SetDecryptionPassphrase(kPassphrase)); | 354 ASSERT_TRUE(GetSyncService(1)->SetDecryptionPassphrase(kPassphrase)); |
| 354 ASSERT_TRUE(PassphraseAcceptedChecker(GetSyncService(1)).Wait()); | 355 ASSERT_TRUE(PassphraseAcceptedChecker(GetSyncService(1)).Wait()); |
| 355 | 356 |
| 356 model0->WriteItem(kKey4, kValue1); | 357 model0->WriteItem(kKey4, kValue1); |
| 357 | 358 |
| 358 ASSERT_TRUE(DataChecker(model1, kKey1, kValue2).Wait()); | 359 ASSERT_TRUE(DataChecker(model1, kKey1, kValue2).Wait()); |
| 359 ASSERT_TRUE(DataChecker(model1, kKey2, kValue1).Wait()); | 360 ASSERT_TRUE(DataChecker(model1, kKey2, kValue1).Wait()); |
| 360 ASSERT_TRUE(DataChecker(model1, kKey4, kValue1).Wait()); | 361 ASSERT_TRUE(DataChecker(model1, kKey4, kValue1).Wait()); |
| 361 | 362 |
| 362 ASSERT_TRUE(DataChecker(model0, kKey1, kValue2).Wait()); | 363 ASSERT_TRUE(DataChecker(model0, kKey1, kValue2).Wait()); |
| 363 ASSERT_TRUE(DataChecker(model0, kKey3, kValue1).Wait()); | 364 ASSERT_TRUE(DataChecker(model0, kKey3, kValue1).Wait()); |
| 364 } | 365 } |
| 365 | 366 |
| 366 } // namespace | 367 } // namespace |
| OLD | NEW |