1 // Copyright 2011 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.
5 #ifndef COMPONENTS_PREFS_MOCK_PREF_CHANGE_CALLBACK_H_
6 #define COMPONENTS_PREFS_MOCK_PREF_CHANGE_CALLBACK_H_
10 #include "base/memory/raw_ptr.h"
11 #include "base/memory/values_equivalent.h"
12 #include "components/prefs/pref_change_registrar.h"
13 #include "components/prefs/pref_service.h"
14 #include "testing/gmock/include/gmock/gmock.h"
16 using testing::Pointee;
17 using testing::Property;
20 // Matcher that checks whether the current value of the preference named
21 // |pref_name| in |prefs| matches |value|. If |value| is NULL, the matcher
22 // checks that the value is not set.
23 MATCHER_P3(PrefValueMatches, prefs, pref_name, value, "") {
24 const PrefService::Preference* pref = prefs->FindPreference(pref_name);
28 return base::ValuesEquivalent(value, pref->GetValue());
31 // A mock for testing preference notifications and easy setup of expectations.
32 class MockPrefChangeCallback {
34 explicit MockPrefChangeCallback(PrefService* prefs);
35 virtual ~MockPrefChangeCallback();
37 PrefChangeRegistrar::NamedChangeCallback GetCallback();
39 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&));
41 void Expect(const std::string& pref_name,
42 const base::Value* value);
45 raw_ptr<PrefService> prefs_;
48 #endif // COMPONENTS_PREFS_MOCK_PREF_CHANGE_CALLBACK_H_