pref_test_utils.cc 900 B

123456789101112131415161718192021222324252627
  1. // Copyright (c) 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/prefs/pref_test_utils.h"
  5. #include "base/run_loop.h"
  6. #include "base/test/bind.h"
  7. #include "base/values.h"
  8. #include "components/prefs/pref_change_registrar.h"
  9. #include "components/prefs/pref_service.h"
  10. void WaitForPrefValue(PrefService* pref_service,
  11. const std::string& path,
  12. const base::Value& value) {
  13. if (value == *(pref_service->Get(path)))
  14. return;
  15. base::RunLoop run_loop;
  16. PrefChangeRegistrar pref_changes;
  17. pref_changes.Init(pref_service);
  18. pref_changes.Add(path, base::BindLambdaForTesting([&]() {
  19. if (value == pref_service->GetValue(path))
  20. run_loop.Quit();
  21. }));
  22. run_loop.Run();
  23. }