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

Side by Side Diff: base/prefs/public/pref_change_registrar_unittest.cc

Issue 11570009: Split PrefService into PrefService, PrefServiceSimple and PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head again, previous had unrelated broken win_rel test. 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
« no previous file with comments | « no previous file | base/prefs/public/pref_member_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/prefs/pref_observer.h" 7 #include "base/prefs/pref_observer.h"
8 #include "base/prefs/public/pref_change_registrar.h" 8 #include "base/prefs/public/pref_change_registrar.h"
9 #include "chrome/test/base/testing_pref_service.h" 9 #include "chrome/test/base/testing_pref_service.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 using testing::Mock; 13 using testing::Mock;
14 using testing::Eq; 14 using testing::Eq;
15 15
16 namespace base { 16 namespace base {
17 namespace { 17 namespace {
18 18
19 const char kHomePage[] = "homepage"; 19 const char kHomePage[] = "homepage";
20 const char kHomePageIsNewTabPage[] = "homepage_is_newtabpage"; 20 const char kHomePageIsNewTabPage[] = "homepage_is_newtabpage";
21 const char kApplicationLocale[] = "intl.app_locale"; 21 const char kApplicationLocale[] = "intl.app_locale";
22 22
23 // A mock provider that allows us to capture pref observer changes. 23 // A mock provider that allows us to capture pref observer changes.
24 class MockPrefService : public TestingPrefService { 24 class MockPrefService : public TestingPrefServiceSimple {
25 public: 25 public:
26 MockPrefService() {} 26 MockPrefService() {}
27 virtual ~MockPrefService() {} 27 virtual ~MockPrefService() {}
28 28
29 MOCK_METHOD2(AddPrefObserver, 29 MOCK_METHOD2(AddPrefObserver,
30 void(const char*, PrefObserver*)); 30 void(const char*, PrefObserver*));
31 MOCK_METHOD2(RemovePrefObserver, 31 MOCK_METHOD2(RemovePrefObserver,
32 void(const char*, PrefObserver*)); 32 void(const char*, PrefObserver*));
33 }; 33 };
34 34
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 EXPECT_TRUE(registrar.IsEmpty()); 120 EXPECT_TRUE(registrar.IsEmpty());
121 121
122 // Explicitly check the expectations now to make sure that the RemoveAll 122 // Explicitly check the expectations now to make sure that the RemoveAll
123 // worked (rather than the registrar destructor doing the work). 123 // worked (rather than the registrar destructor doing the work).
124 Mock::VerifyAndClearExpectations(service()); 124 Mock::VerifyAndClearExpectations(service());
125 } 125 }
126 126
127 class ObserveSetOfPreferencesTest : public testing::Test { 127 class ObserveSetOfPreferencesTest : public testing::Test {
128 public: 128 public:
129 virtual void SetUp() { 129 virtual void SetUp() {
130 pref_service_.reset(new TestingPrefService); 130 pref_service_.reset(new TestingPrefServiceSimple);
131 pref_service_->RegisterStringPref(kHomePage, 131 pref_service_->RegisterStringPref(kHomePage, "http://google.com");
132 "http://google.com", 132 pref_service_->RegisterBooleanPref(kHomePageIsNewTabPage, false);
133 PrefService::UNSYNCABLE_PREF); 133 pref_service_->RegisterStringPref(kApplicationLocale, "");
134 pref_service_->RegisterBooleanPref(kHomePageIsNewTabPage,
135 false,
136 PrefService::UNSYNCABLE_PREF);
137 pref_service_->RegisterStringPref(kApplicationLocale,
138 "",
139 PrefService::UNSYNCABLE_PREF);
140 } 134 }
141 135
142 PrefChangeRegistrar* CreatePrefChangeRegistrar() { 136 PrefChangeRegistrar* CreatePrefChangeRegistrar() {
143 PrefChangeRegistrar* pref_set = new PrefChangeRegistrar(); 137 PrefChangeRegistrar* pref_set = new PrefChangeRegistrar();
144 base::Closure callback = base::Bind(&base::DoNothing); 138 base::Closure callback = base::Bind(&base::DoNothing);
145 pref_set->Init(pref_service_.get()); 139 pref_set->Init(pref_service_.get());
146 pref_set->Add(kHomePage, callback); 140 pref_set->Add(kHomePage, callback);
147 pref_set->Add(kHomePageIsNewTabPage, callback); 141 pref_set->Add(kHomePageIsNewTabPage, callback);
148 return pref_set; 142 return pref_set;
149 } 143 }
150 144
151 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&)); 145 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&));
152 146
153 scoped_ptr<TestingPrefService> pref_service_; 147 scoped_ptr<TestingPrefServiceSimple> pref_service_;
154 }; 148 };
155 149
156 TEST_F(ObserveSetOfPreferencesTest, IsObserved) { 150 TEST_F(ObserveSetOfPreferencesTest, IsObserved) {
157 scoped_ptr<PrefChangeRegistrar> pref_set(CreatePrefChangeRegistrar()); 151 scoped_ptr<PrefChangeRegistrar> pref_set(CreatePrefChangeRegistrar());
158 EXPECT_TRUE(pref_set->IsObserved(kHomePage)); 152 EXPECT_TRUE(pref_set->IsObserved(kHomePage));
159 EXPECT_TRUE(pref_set->IsObserved(kHomePageIsNewTabPage)); 153 EXPECT_TRUE(pref_set->IsObserved(kHomePageIsNewTabPage));
160 EXPECT_FALSE(pref_set->IsObserved(kApplicationLocale)); 154 EXPECT_FALSE(pref_set->IsObserved(kApplicationLocale));
161 } 155 }
162 156
163 TEST_F(ObserveSetOfPreferencesTest, IsManaged) { 157 TEST_F(ObserveSetOfPreferencesTest, IsManaged) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 pref_service_->SetUserPref(kHomePageIsNewTabPage, 189 pref_service_->SetUserPref(kHomePageIsNewTabPage,
196 new FundamentalValue(true)); 190 new FundamentalValue(true));
197 Mock::VerifyAndClearExpectations(this); 191 Mock::VerifyAndClearExpectations(this);
198 192
199 EXPECT_CALL(*this, OnPreferenceChanged(_)).Times(0); 193 EXPECT_CALL(*this, OnPreferenceChanged(_)).Times(0);
200 pref_service_->SetUserPref(kApplicationLocale, new StringValue("en_US.utf8")); 194 pref_service_->SetUserPref(kApplicationLocale, new StringValue("en_US.utf8"));
201 Mock::VerifyAndClearExpectations(this); 195 Mock::VerifyAndClearExpectations(this);
202 } 196 }
203 197
204 } // namespace base 198 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/prefs/public/pref_member_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698