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