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

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

Issue 2379433002: [Sync] Refactoring of sync integration test checkers to remove boilerplate await methods. (Closed)
Patch Set: Rebase 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"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 std::set<Observer*> observers_; 85 std::set<Observer*> observers_;
86 }; 86 };
87 87
88 // A StatusChangeChecker for checking the status of keys in a 88 // A StatusChangeChecker for checking the status of keys in a
89 // TestModelTypeService::Store. 89 // TestModelTypeService::Store.
90 class KeyChecker : public StatusChangeChecker, 90 class KeyChecker : public StatusChangeChecker,
91 public TestModelTypeService::Observer { 91 public TestModelTypeService::Observer {
92 public: 92 public:
93 KeyChecker(TestModelTypeService* service, const std::string& key) 93 KeyChecker(TestModelTypeService* service, const std::string& key)
94 : service_(service), key_(key) {} 94 : service_(service), key_(key) {
95 service_->AddObserver(this);
96 }
97
98 ~KeyChecker() override { service_->RemoveObserver(this); }
95 99
96 void OnApplySyncChanges() override { CheckExitCondition(); } 100 void OnApplySyncChanges() override { CheckExitCondition(); }
97 101
98 bool Wait() {
99 if (IsExitConditionSatisfied()) {
100 DVLOG(1) << "Wait() -> Exit before waiting: " << GetDebugMessage();
101 return true;
102 }
103
104 service_->AddObserver(this);
105 StartBlockingWait();
106 service_->RemoveObserver(this);
107 return !TimedOut();
108 }
109
110 protected: 102 protected:
111 TestModelTypeService* const service_; 103 TestModelTypeService* const service_;
112 const std::string key_; 104 const std::string key_;
113 }; 105 };
114 106
115 // Wait for data for a key to have a certain value. 107 // Wait for data for a key to have a certain value.
116 class DataChecker : public KeyChecker { 108 class DataChecker : public KeyChecker {
117 public: 109 public:
118 DataChecker(TestModelTypeService* service, 110 DataChecker(TestModelTypeService* service,
119 const std::string& key, 111 const std::string& key,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 return "Waiting for metadata for key '" + key_ + "' to be absent."; 169 return "Waiting for metadata for key '" + key_ + "' to be absent.";
178 } 170 }
179 }; 171 };
180 172
181 // Wait for PREFERENCES to no longer be running. 173 // Wait for PREFERENCES to no longer be running.
182 class PrefsNotRunningChecker : public SingleClientStatusChangeChecker { 174 class PrefsNotRunningChecker : public SingleClientStatusChangeChecker {
183 public: 175 public:
184 explicit PrefsNotRunningChecker(browser_sync::ProfileSyncService* service) 176 explicit PrefsNotRunningChecker(browser_sync::ProfileSyncService* service)
185 : SingleClientStatusChangeChecker(service) {} 177 : SingleClientStatusChangeChecker(service) {}
186 178
187 bool Wait() {
188 SingleClientStatusChangeChecker::Wait();
189 return !TimedOut();
190 }
191
192 bool IsExitConditionSatisfied() override { 179 bool IsExitConditionSatisfied() override {
193 return !service()->IsDataTypeControllerRunning(syncer::PREFERENCES); 180 return !service()->IsDataTypeControllerRunning(syncer::PREFERENCES);
194 } 181 }
195 182
196 std::string GetDebugMessage() const override { 183 std::string GetDebugMessage() const override {
197 return "Waiting for prefs to be not running."; 184 return "Waiting for prefs to be not running.";
198 } 185 }
199 }; 186 };
200 187
201 class TwoClientUssSyncTest : public SyncTest { 188 class TwoClientUssSyncTest : public SyncTest {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 model2->SetServiceError(syncer::SyncError::DATATYPE_ERROR); 319 model2->SetServiceError(syncer::SyncError::DATATYPE_ERROR);
333 // Write an item on model 1 to trigger a GetUpdates in model 2. 320 // Write an item on model 1 to trigger a GetUpdates in model 2.
334 model1->WriteItem(kKey1, kValue2); 321 model1->WriteItem(kKey1, kValue2);
335 322
336 // The type should stop syncing but keep tracking metadata. 323 // The type should stop syncing but keep tracking metadata.
337 ASSERT_TRUE(PrefsNotRunningChecker(GetSyncService(1)).Wait()); 324 ASSERT_TRUE(PrefsNotRunningChecker(GetSyncService(1)).Wait());
338 ASSERT_EQ(1U, model2->db().metadata_count()); 325 ASSERT_EQ(1U, model2->db().metadata_count());
339 model2->WriteItem(kKey2, kValue2); 326 model2->WriteItem(kKey2, kValue2);
340 ASSERT_EQ(2U, model2->db().metadata_count()); 327 ASSERT_EQ(2U, model2->db().metadata_count());
341 } 328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698