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

Side by Side Diff: chrome/browser/sync/test/integration/two_client_uss_sync_test.cc

Issue 2369063003: [Sync] Add an error integration test for USS. (Closed)
Patch Set: Fix a DCHECK in DTMI. Created 4 years, 2 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
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/status_change_checker.h" 12 #include "chrome/browser/sync/test/integration/status_change_checker.h"
12 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" 13 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
13 #include "chrome/browser/sync/test/integration/sync_test.h" 14 #include "chrome/browser/sync/test/integration/sync_test.h"
14 #include "components/browser_sync/profile_sync_components_factory_impl.h" 15 #include "components/browser_sync/profile_sync_components_factory_impl.h"
15 #include "components/browser_sync/profile_sync_service.h" 16 #include "components/browser_sync/profile_sync_service.h"
16 #include "components/sync/api/fake_model_type_service.h" 17 #include "components/sync/api/fake_model_type_service.h"
17 18
18 using browser_sync::ChromeSyncClient; 19 using browser_sync::ChromeSyncClient;
19 using browser_sync::ProfileSyncComponentsFactoryImpl; 20 using browser_sync::ProfileSyncComponentsFactoryImpl;
20 using syncer_v2::ConflictResolution; 21 using syncer_v2::ConflictResolution;
21 using syncer_v2::FakeModelTypeService; 22 using syncer_v2::FakeModelTypeService;
22 using syncer_v2::ModelTypeService; 23 using syncer_v2::ModelTypeService;
23 using syncer_v2::SharedModelTypeProcessor; 24 using syncer_v2::SharedModelTypeProcessor;
24 25
25 const char kKey1[] = "key1"; 26 const char kKey1[] = "key1";
27 const char kKey2[] = "key2";
26 const char kValue1[] = "value1"; 28 const char kValue1[] = "value1";
27 const char kValue2[] = "value2"; 29 const char kValue2[] = "value2";
28 const char kValue3[] = "value3"; 30 const char kValue3[] = "value3";
29 31
30 // A ChromeSyncClient that provides a ModelTypeService for PREFERENCES. 32 // A ChromeSyncClient that provides a ModelTypeService for PREFERENCES.
31 class TestSyncClient : public ChromeSyncClient { 33 class TestSyncClient : public ChromeSyncClient {
32 public: 34 public:
33 TestSyncClient(Profile* profile, ModelTypeService* service) 35 TestSyncClient(Profile* profile, ModelTypeService* service)
34 : ChromeSyncClient(profile), service_(service) {} 36 : ChromeSyncClient(profile), service_(service) {}
35 37
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 176
175 bool IsExitConditionSatisfied() override { 177 bool IsExitConditionSatisfied() override {
176 return !service_->db().HasMetadata(key_); 178 return !service_->db().HasMetadata(key_);
177 } 179 }
178 180
179 std::string GetDebugMessage() const override { 181 std::string GetDebugMessage() const override {
180 return "Waiting for metadata for key '" + key_ + "' to be absent."; 182 return "Waiting for metadata for key '" + key_ + "' to be absent.";
181 } 183 }
182 }; 184 };
183 185
186 // Wait for PREFERENCES to no longer be running.
187 class PrefsNotRunningChecker : public SingleClientStatusChangeChecker {
188 public:
189 explicit PrefsNotRunningChecker(browser_sync::ProfileSyncService* service)
190 : SingleClientStatusChangeChecker(service) {}
191 ~PrefsNotRunningChecker() override {}
skym 2016/09/27 20:24:45 I don't think you need this. I'm going through the
maxbogue 2016/09/28 20:17:08 Removed them all.
192
193 bool Wait() {
194 SingleClientStatusChangeChecker::Wait();
skym 2016/09/27 20:24:44 This awkwardness should be fixed by my CL.
maxbogue 2016/09/28 20:17:09 Acknowledged.
195 return !TimedOut();
196 }
197
198 bool IsExitConditionSatisfied() override {
199 return !service()->IsDataTypeControllerRunning(syncer::PREFERENCES);
200 }
201
202 std::string GetDebugMessage() const override {
203 return "Waiting for prefs to be not running.";
204 }
205 };
206
184 class TwoClientUssSyncTest : public SyncTest { 207 class TwoClientUssSyncTest : public SyncTest {
185 public: 208 public:
186 TwoClientUssSyncTest() : SyncTest(TWO_CLIENT) { 209 TwoClientUssSyncTest() : SyncTest(TWO_CLIENT) {
187 DisableVerifier(); 210 DisableVerifier();
188 sync_client_factory_ = base::Bind(&TwoClientUssSyncTest::CreateSyncClient, 211 sync_client_factory_ = base::Bind(&TwoClientUssSyncTest::CreateSyncClient,
189 base::Unretained(this)); 212 base::Unretained(this));
190 ProfileSyncServiceFactory::SetSyncClientFactoryForTest( 213 ProfileSyncServiceFactory::SetSyncClientFactoryForTest(
191 &sync_client_factory_); 214 &sync_client_factory_);
192 ProfileSyncComponentsFactoryImpl::OverridePrefsForUssTest(true); 215 ProfileSyncComponentsFactoryImpl::OverridePrefsForUssTest(true);
193 } 216 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 317
295 // Write conflicting entities. 318 // Write conflicting entities.
296 model1->WriteItem(kKey1, kValue1); 319 model1->WriteItem(kKey1, kValue1);
297 model2->WriteItem(kKey1, kValue2); 320 model2->WriteItem(kKey1, kValue2);
298 321
299 // Wait for them to be resolved to kResolutionValue by the custom conflict 322 // Wait for them to be resolved to kResolutionValue by the custom conflict
300 // resolution logic in TestModelTypeService. 323 // resolution logic in TestModelTypeService.
301 ASSERT_TRUE(DataChecker(model1, kKey1, kValue3).Wait()); 324 ASSERT_TRUE(DataChecker(model1, kKey1, kValue3).Wait());
302 ASSERT_TRUE(DataChecker(model2, kKey1, kValue3).Wait()); 325 ASSERT_TRUE(DataChecker(model2, kKey1, kValue3).Wait());
303 } 326 }
327
328 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Error) {
329 ASSERT_TRUE(SetupSync());
330 TestModelTypeService* model1 = GetModelTypeService(0);
331 TestModelTypeService* model2 = GetModelTypeService(1);
332
333 // Add an entity.
334 model1->WriteItem(kKey1, kValue1);
335 ASSERT_TRUE(DataChecker(model2, kKey1, kValue1).Wait());
336
337 // Queue an error in model 2 and trigger a GetUpdates.
338 model2->SetServiceError(syncer::SyncError::DATATYPE_ERROR);
339 model1->WriteItem(kKey1, kValue2);
skym 2016/09/27 20:24:45 What's the point of this? You don't verify that mo
maxbogue 2016/09/28 20:17:09 To trigger an ApplySyncChanges (GU) in model2.
340
341 // The type should stop syncing but keep tracking metadata.
342 ASSERT_TRUE(PrefsNotRunningChecker(GetSyncService(1)).Wait());
skym 2016/09/27 20:24:44 Seems odd that you error(2) -> write(1) -> block f
maxbogue 2016/09/28 20:17:09 SetServiceError stores the error that is returned
343 ASSERT_EQ(1U, model2->db().metadata_count());
344 model2->WriteItem(kKey2, kValue2);
345 ASSERT_EQ(2U, model2->db().metadata_count());
346 }
OLDNEW
« no previous file with comments | « no previous file | components/sync/driver/data_type_manager_impl.cc » ('j') | components/sync/driver/data_type_manager_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698