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

Side by Side Diff: chrome/browser/prefs/pref_notifier_impl_unittest.cc

Issue 11316163: Remove the last usages of PrefObserver outside of Prefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 years 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 | Annotate | Revision Log
OLDNEW
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/prefs/public/pref_observer.h" 7 #include "base/prefs/public/pref_observer.h"
8 #include "chrome/browser/prefs/mock_pref_change_callback.h"
8 #include "chrome/browser/prefs/pref_notifier_impl.h" 9 #include "chrome/browser/prefs/pref_notifier_impl.h"
9 #include "chrome/browser/prefs/pref_observer_mock.h"
10 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/prefs/pref_value_store.h" 11 #include "chrome/browser/prefs/pref_value_store.h"
12 #include "chrome/common/chrome_notification_types.h" 12 #include "chrome/common/chrome_notification_types.h"
13 #include "chrome/test/base/testing_pref_service.h" 13 #include "chrome/test/base/testing_pref_service.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using testing::_; 17 using testing::_;
18 using testing::Field; 18 using testing::Field;
19 using testing::Invoke; 19 using testing::Invoke;
20 using testing::Mock; 20 using testing::Mock;
21 using testing::Truly; 21 using testing::Truly;
22 22
23 namespace { 23 namespace {
24 24
25 const char kChangedPref[] = "changed_pref"; 25 const char kChangedPref[] = "changed_pref";
26 const char kUnchangedPref[] = "unchanged_pref"; 26 const char kUnchangedPref[] = "unchanged_pref";
27 27
28 class MockPrefInitObserver { 28 class MockPrefInitObserver {
29 public: 29 public:
30 MOCK_METHOD1(OnInitializationCompleted, void(bool)); 30 MOCK_METHOD1(OnInitializationCompleted, void(bool));
31 }; 31 };
32 32
33 // This is an unmodified PrefNotifierImpl, except we make 33 // This is an unmodified PrefNotifierImpl, except we make
34 // OnPreferenceChanged public for tests. 34 // OnPreferenceChanged public for tests.
35 class TestingPrefNotifierImpl : public PrefNotifierImpl { 35 class TestingPrefNotifierImpl : public PrefNotifierImpl {
36 public: 36 public:
37 TestingPrefNotifierImpl(PrefService* service) : PrefNotifierImpl(service) {} 37 explicit TestingPrefNotifierImpl(PrefService* service)
38 : PrefNotifierImpl(service) {
39 }
38 40
39 // Make public for tests. 41 // Make public for tests.
40 using PrefNotifierImpl::OnPreferenceChanged; 42 using PrefNotifierImpl::OnPreferenceChanged;
41 }; 43 };
42 44
43 // Mock PrefNotifier that allows tracking of observers and notifications. 45 // Mock PrefNotifier that allows tracking of observers and notifications.
44 class MockPrefNotifier : public PrefNotifierImpl { 46 class MockPrefNotifier : public PrefNotifierImpl {
45 public: 47 public:
46 explicit MockPrefNotifier(PrefService* pref_service) 48 explicit MockPrefNotifier(PrefService* pref_service)
47 : PrefNotifierImpl(pref_service) {} 49 : PrefNotifierImpl(pref_service) {}
(...skipping 17 matching lines...) Expand all
65 } 67 }
66 68
67 return count; 69 return count;
68 } 70 }
69 71
70 // Make public for tests below. 72 // Make public for tests below.
71 using PrefNotifierImpl::OnPreferenceChanged; 73 using PrefNotifierImpl::OnPreferenceChanged;
72 using PrefNotifierImpl::OnInitializationCompleted; 74 using PrefNotifierImpl::OnInitializationCompleted;
73 }; 75 };
74 76
77 class PrefObserverMock : public PrefObserver {
78 public:
79 PrefObserverMock() {}
80 virtual ~PrefObserverMock() {}
81
82 MOCK_METHOD2(OnPreferenceChanged, void(PrefServiceBase*, const std::string&));
83
84 void Expect(PrefServiceBase* prefs,
85 const std::string& pref_name,
86 const Value* value) {
87 EXPECT_CALL(*this, OnPreferenceChanged(prefs, pref_name))
88 .With(PrefValueMatches(prefs, pref_name, value));
89 }
90 };
91
75 // Test fixture class. 92 // Test fixture class.
76 class PrefNotifierTest : public testing::Test { 93 class PrefNotifierTest : public testing::Test {
77 protected: 94 protected:
78 virtual void SetUp() { 95 virtual void SetUp() {
79 pref_service_.RegisterBooleanPref(kChangedPref, 96 pref_service_.RegisterBooleanPref(kChangedPref,
80 true, 97 true,
81 PrefService::UNSYNCABLE_PREF); 98 PrefService::UNSYNCABLE_PREF);
82 pref_service_.RegisterBooleanPref(kUnchangedPref, 99 pref_service_.RegisterBooleanPref(kUnchangedPref,
83 true, 100 true,
84 PrefService::UNSYNCABLE_PREF); 101 PrefService::UNSYNCABLE_PREF);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 EXPECT_CALL(obs2_, OnPreferenceChanged(&pref_service_, kChangedPref)); 222 EXPECT_CALL(obs2_, OnPreferenceChanged(&pref_service_, kChangedPref));
206 notifier.OnPreferenceChanged(kChangedPref); 223 notifier.OnPreferenceChanged(kChangedPref);
207 Mock::VerifyAndClearExpectations(&obs1_); 224 Mock::VerifyAndClearExpectations(&obs1_);
208 Mock::VerifyAndClearExpectations(&obs2_); 225 Mock::VerifyAndClearExpectations(&obs2_);
209 226
210 notifier.RemovePrefObserver(kChangedPref, &obs2_); 227 notifier.RemovePrefObserver(kChangedPref, &obs2_);
211 notifier.RemovePrefObserver(kUnchangedPref, &obs2_); 228 notifier.RemovePrefObserver(kUnchangedPref, &obs2_);
212 } 229 }
213 230
214 } // namespace 231 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/prefs/mock_pref_change_callback.cc ('k') | chrome/browser/prefs/pref_observer_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698