Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/test/integration/preferences_helper.h" | 5 #include "chrome/browser/sync/test/integration/preferences_helper.h" |
| 6 | 6 |
| 7 #include <utility> | |
| 8 | |
| 7 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke r.h" | |
| 10 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 11 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| 11 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 12 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 12 #include "chrome/browser/sync/test/integration/sync_test.h" | 13 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 13 #include "components/prefs/pref_change_registrar.h" | 14 #include "components/prefs/pref_change_registrar.h" |
| 14 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
| 15 #include "components/prefs/scoped_user_pref_update.h" | 16 #include "components/prefs/scoped_user_pref_update.h" |
| 16 | 17 |
| 17 using sync_datatype_helper::test; | 18 using sync_datatype_helper::test; |
| 18 | 19 |
| 19 namespace preferences_helper { | 20 namespace preferences_helper { |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 for (int i = 0; i < test()->num_clients(); ++i) { | 204 for (int i = 0; i < test()->num_clients(); ++i) { |
| 204 if (!reference_value->Equals(GetPrefs(i)->GetList(pref_name))) { | 205 if (!reference_value->Equals(GetPrefs(i)->GetList(pref_name))) { |
| 205 DVLOG(1) << "List preference " << pref_name << " mismatched in" | 206 DVLOG(1) << "List preference " << pref_name << " mismatched in" |
| 206 << " profile " << i << "."; | 207 << " profile " << i << "."; |
| 207 return false; | 208 return false; |
| 208 } | 209 } |
| 209 } | 210 } |
| 210 return true; | 211 return true; |
| 211 } | 212 } |
| 212 | 213 |
| 213 | 214 } // namespace preferences_helper |
| 214 namespace { | |
| 215 | |
| 216 class PrefMatchChecker : public StatusChangeChecker { | |
| 217 public: | |
| 218 explicit PrefMatchChecker(const char* path); | |
| 219 ~PrefMatchChecker() override; | |
| 220 | |
| 221 // StatusChangeChecker implementation. | |
| 222 bool IsExitConditionSatisfied() override = 0; | |
| 223 std::string GetDebugMessage() const override; | |
| 224 | |
| 225 // Wait for condition to become true. | |
| 226 void Wait(); | |
| 227 | |
| 228 protected: | |
| 229 const char* GetPath() const; | |
| 230 | |
| 231 private: | |
| 232 void RegisterPrefListener(PrefService* pref_service); | |
| 233 | |
| 234 ScopedVector<PrefChangeRegistrar> pref_change_registrars_; | |
| 235 const char* path_; | |
| 236 }; | |
| 237 | 215 |
| 238 PrefMatchChecker::PrefMatchChecker(const char* path) : path_(path) { | 216 PrefMatchChecker::PrefMatchChecker(const char* path) : path_(path) { |
| 217 if (test()->use_verifier()) { | |
| 218 RegisterPrefListener(preferences_helper::GetVerifierPrefs()); | |
| 219 } | |
| 220 for (int i = 0; i < test()->num_clients(); ++i) { | |
| 221 RegisterPrefListener(preferences_helper::GetPrefs(i)); | |
| 222 } | |
| 239 } | 223 } |
| 240 | 224 |
| 241 PrefMatchChecker::~PrefMatchChecker() { | 225 PrefMatchChecker::~PrefMatchChecker() {} |
| 242 } | |
| 243 | 226 |
| 244 std::string PrefMatchChecker::GetDebugMessage() const { | 227 std::string PrefMatchChecker::GetDebugMessage() const { |
| 245 return base::StringPrintf("Waiting for pref '%s' to match", GetPath()); | 228 return base::StringPrintf("Waiting for pref '%s' to match", GetPath()); |
| 246 } | 229 } |
| 247 | 230 |
| 248 void PrefMatchChecker::Wait() { | |
| 249 if (test()->use_verifier()) { | |
| 250 RegisterPrefListener(GetVerifierPrefs()); | |
| 251 } | |
| 252 | |
| 253 for (int i = 0; i < test()->num_clients(); ++i) { | |
| 254 RegisterPrefListener(GetPrefs(i)); | |
| 255 } | |
| 256 | |
| 257 if (IsExitConditionSatisfied()) { | |
| 258 return; | |
| 259 } | |
| 260 | |
| 261 StartBlockingWait(); | |
| 262 } | |
| 263 | |
| 264 const char* PrefMatchChecker::GetPath() const { | 231 const char* PrefMatchChecker::GetPath() const { |
| 265 return path_; | 232 return path_; |
| 266 } | 233 } |
| 267 | 234 |
| 268 void PrefMatchChecker::RegisterPrefListener(PrefService* pref_service) { | 235 void PrefMatchChecker::RegisterPrefListener(PrefService* pref_service) { |
| 269 std::unique_ptr<PrefChangeRegistrar> registrar(new PrefChangeRegistrar()); | 236 std::unique_ptr<PrefChangeRegistrar> registrar(new PrefChangeRegistrar()); |
| 270 registrar->Init(pref_service); | 237 registrar->Init(pref_service); |
| 271 registrar->Add(path_, | 238 registrar->Add(path_, |
| 272 base::Bind(&PrefMatchChecker::CheckExitCondition, | 239 base::Bind(&PrefMatchChecker::CheckExitCondition, |
| 273 base::Unretained(this))); | 240 base::Unretained(this))); |
| 274 pref_change_registrars_.push_back(registrar.release()); | 241 pref_change_registrars_.push_back(std::move(registrar)); |
| 275 } | 242 } |
| 276 | 243 |
| 277 // Helper class used in the implementation of AwaitListPrefMatches. | 244 ListPrefMatchChecker::ListPrefMatchChecker(const char* path) |
| 278 class ListPrefMatchChecker : public PrefMatchChecker { | 245 : PrefMatchChecker(path) {} |
| 279 public: | |
| 280 explicit ListPrefMatchChecker(const char* path); | |
| 281 ~ListPrefMatchChecker() override; | |
| 282 | 246 |
| 283 // Implementation of PrefMatchChecker. | 247 bool ListPrefMatchChecker::IsExitConditionSatisfied() { |
| 284 bool IsExitConditionSatisfied() override; | 248 return preferences_helper::ListPrefMatches(GetPath()); |
| 285 }; | |
| 286 | |
| 287 ListPrefMatchChecker::ListPrefMatchChecker(const char* path) | |
| 288 : PrefMatchChecker(path) { | |
| 289 } | 249 } |
| 290 | 250 |
| 291 ListPrefMatchChecker::~ListPrefMatchChecker() { | 251 BooleanPrefMatchChecker::BooleanPrefMatchChecker(const char* path) |
| 252 : PrefMatchChecker(path) {} | |
| 253 | |
| 254 bool BooleanPrefMatchChecker::IsExitConditionSatisfied() { | |
| 255 return preferences_helper::BooleanPrefMatches(GetPath()); | |
| 292 } | 256 } |
| 293 | 257 |
| 294 bool ListPrefMatchChecker::IsExitConditionSatisfied() { | 258 IntegerPrefMatchChecker::IntegerPrefMatchChecker(const char* path) |
| 295 return ListPrefMatches(GetPath()); | 259 : PrefMatchChecker(path) {} |
| 260 | |
| 261 bool IntegerPrefMatchChecker::IsExitConditionSatisfied() { | |
| 262 return preferences_helper::IntegerPrefMatches(GetPath()); | |
| 296 } | 263 } |
| 297 | 264 |
| 298 // Helper class used in the implementation of AwaitBooleanPrefMatches. | |
| 299 class BooleanPrefMatchChecker : public PrefMatchChecker { | |
| 300 public: | |
| 301 explicit BooleanPrefMatchChecker(const char* path); | |
| 302 ~BooleanPrefMatchChecker() override; | |
| 303 | |
| 304 // Implementation of PrefMatchChecker. | |
| 305 bool IsExitConditionSatisfied() override; | |
| 306 }; | |
| 307 | |
| 308 BooleanPrefMatchChecker::BooleanPrefMatchChecker(const char* path) | |
| 309 : PrefMatchChecker(path) { | |
| 310 } | |
| 311 | |
| 312 BooleanPrefMatchChecker::~BooleanPrefMatchChecker() { | |
| 313 } | |
| 314 | |
| 315 bool BooleanPrefMatchChecker::IsExitConditionSatisfied() { | |
| 316 return BooleanPrefMatches(GetPath()); | |
| 317 } | |
| 318 | |
| 319 // Helper class used in the implementation of AwaitIntegerPrefMatches. | |
| 320 class IntegerPrefMatchChecker : public PrefMatchChecker { | |
| 321 public: | |
| 322 explicit IntegerPrefMatchChecker(const char* path); | |
| 323 ~IntegerPrefMatchChecker() override; | |
| 324 | |
| 325 // Implementation of PrefMatchChecker. | |
| 326 bool IsExitConditionSatisfied() override; | |
| 327 }; | |
| 328 | |
| 329 IntegerPrefMatchChecker::IntegerPrefMatchChecker(const char* path) | |
| 330 : PrefMatchChecker(path) { | |
| 331 } | |
| 332 | |
| 333 IntegerPrefMatchChecker::~IntegerPrefMatchChecker() { | |
| 334 } | |
| 335 | |
| 336 bool IntegerPrefMatchChecker::IsExitConditionSatisfied() { | |
| 337 return IntegerPrefMatches(GetPath()); | |
| 338 } | |
| 339 | |
| 340 // Helper class used in the implementation of AwaitStringPrefMatches. | |
| 341 class StringPrefMatchChecker : public PrefMatchChecker { | |
| 342 public: | |
| 343 explicit StringPrefMatchChecker(const char* path); | |
| 344 ~StringPrefMatchChecker() override; | |
| 345 | |
| 346 // Implementation of PrefMatchChecker. | |
| 347 bool IsExitConditionSatisfied() override; | |
| 348 }; | |
| 349 | |
| 350 StringPrefMatchChecker::StringPrefMatchChecker(const char* path) | 265 StringPrefMatchChecker::StringPrefMatchChecker(const char* path) |
| 351 : PrefMatchChecker(path) { | 266 : PrefMatchChecker(path) {} |
| 352 } | |
| 353 | |
| 354 StringPrefMatchChecker::~StringPrefMatchChecker() { | |
| 355 } | |
| 356 | 267 |
| 357 bool StringPrefMatchChecker::IsExitConditionSatisfied() { | 268 bool StringPrefMatchChecker::IsExitConditionSatisfied() { |
| 358 return StringPrefMatches(GetPath()); | 269 return preferences_helper::StringPrefMatches(GetPath()); |
| 359 } | 270 } |
| 360 | |
| 361 } // namespace | |
| 362 | |
| 363 bool AwaitListPrefMatches(const char* pref_name) { | |
|
maxbogue
2016/09/30 16:27:55
I'm not even halfway through this CL and I can't b
skym
2016/09/30 17:43:21
Right!?
| |
| 364 ListPrefMatchChecker checker(pref_name); | |
| 365 checker.Wait(); | |
| 366 return !checker.TimedOut(); | |
| 367 } | |
| 368 | |
| 369 bool AwaitBooleanPrefMatches(const char* pref_name) { | |
| 370 BooleanPrefMatchChecker checker(pref_name); | |
| 371 checker.Wait(); | |
| 372 return !checker.TimedOut(); | |
| 373 } | |
| 374 | |
| 375 bool AwaitIntegerPrefMatches(const char* pref_name) { | |
| 376 IntegerPrefMatchChecker checker(pref_name); | |
| 377 checker.Wait(); | |
| 378 return !checker.TimedOut(); | |
| 379 } | |
| 380 | |
| 381 bool AwaitStringPrefMatches(const char* pref_name) { | |
| 382 StringPrefMatchChecker checker(pref_name); | |
| 383 checker.Wait(); | |
| 384 return !checker.TimedOut(); | |
| 385 } | |
| 386 | |
| 387 } // namespace preferences_helper | |
| OLD | NEW |