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

Side by Side Diff: chrome/browser/pref_member_unittest.cc

Issue 2823037: Add an ExtensionPrefStore, layered between the user prefs nad the managed pre... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/file_path.h" 5 #include "base/file_path.h"
6 #include "chrome/browser/dummy_pref_store.h" 6 #include "chrome/browser/dummy_pref_store.h"
7 #include "chrome/browser/pref_member.h" 7 #include "chrome/browser/pref_member.h"
8 #include "chrome/browser/pref_service.h" 8 #include "chrome/browser/pref_service.h"
9 #include "chrome/browser/pref_value_store.h" 9 #include "chrome/browser/pref_value_store.h"
10 #include "chrome/common/notification_service.h" 10 #include "chrome/common/notification_service.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 StringPrefMember str_; 46 StringPrefMember str_;
47 int observe_cnt_; 47 int observe_cnt_;
48 48
49 private: 49 private:
50 PrefService* prefs_; 50 PrefService* prefs_;
51 }; 51 };
52 52
53 } // anonymous namespace 53 } // anonymous namespace
54 54
55 TEST(PrefMemberTest, BasicGetAndSet) { 55 TEST(PrefMemberTest, BasicGetAndSet) {
56 PrefService prefs(new PrefValueStore(NULL, new DummyPrefStore(), NULL)); 56 PrefService prefs(new PrefValueStore(NULL, NULL, new DummyPrefStore(),
57 NULL));
57 RegisterTestPrefs(&prefs); 58 RegisterTestPrefs(&prefs);
58 59
59 // Test bool 60 // Test bool
60 BooleanPrefMember boolean; 61 BooleanPrefMember boolean;
61 boolean.Init(kBoolPref, &prefs, NULL); 62 boolean.Init(kBoolPref, &prefs, NULL);
62 63
63 // Check the defaults 64 // Check the defaults
64 EXPECT_FALSE(prefs.GetBoolean(kBoolPref)); 65 EXPECT_FALSE(prefs.GetBoolean(kBoolPref));
65 EXPECT_FALSE(boolean.GetValue()); 66 EXPECT_FALSE(boolean.GetValue());
66 EXPECT_FALSE(*boolean); 67 EXPECT_FALSE(*boolean);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 137
137 // Try changing back through the pref. 138 // Try changing back through the pref.
138 prefs.SetString(kStringPref, "bar"); 139 prefs.SetString(kStringPref, "bar");
139 EXPECT_EQ("bar", prefs.GetString(kStringPref)); 140 EXPECT_EQ("bar", prefs.GetString(kStringPref));
140 EXPECT_EQ("bar", string.GetValue()); 141 EXPECT_EQ("bar", string.GetValue());
141 EXPECT_EQ("bar", *string); 142 EXPECT_EQ("bar", *string);
142 } 143 }
143 144
144 TEST(PrefMemberTest, TwoPrefs) { 145 TEST(PrefMemberTest, TwoPrefs) {
145 // Make sure two RealPrefMembers stay in sync. 146 // Make sure two RealPrefMembers stay in sync.
146 PrefService prefs(new PrefValueStore(NULL, new DummyPrefStore(), NULL)); 147 PrefService prefs(new PrefValueStore(NULL, NULL, new DummyPrefStore(),
148 NULL));
147 RegisterTestPrefs(&prefs); 149 RegisterTestPrefs(&prefs);
148 150
149 RealPrefMember pref1; 151 RealPrefMember pref1;
150 pref1.Init(kRealPref, &prefs, NULL); 152 pref1.Init(kRealPref, &prefs, NULL);
151 RealPrefMember pref2; 153 RealPrefMember pref2;
152 pref2.Init(kRealPref, &prefs, NULL); 154 pref2.Init(kRealPref, &prefs, NULL);
153 155
154 pref1.SetValue(2.3); 156 pref1.SetValue(2.3);
155 EXPECT_EQ(2.3, *pref2); 157 EXPECT_EQ(2.3, *pref2);
156 158
157 pref2.SetValue(3.5); 159 pref2.SetValue(3.5);
158 EXPECT_EQ(3.5, *pref1); 160 EXPECT_EQ(3.5, *pref1);
159 161
160 prefs.SetReal(kRealPref, 4.2); 162 prefs.SetReal(kRealPref, 4.2);
161 EXPECT_EQ(4.2, *pref1); 163 EXPECT_EQ(4.2, *pref1);
162 EXPECT_EQ(4.2, *pref2); 164 EXPECT_EQ(4.2, *pref2);
163 } 165 }
164 166
165 TEST(PrefMemberTest, Observer) { 167 TEST(PrefMemberTest, Observer) {
166 PrefService prefs(new PrefValueStore(NULL, new DummyPrefStore(), NULL)); 168 PrefService prefs(new PrefValueStore(NULL, NULL, new DummyPrefStore(),
169 NULL));
167 RegisterTestPrefs(&prefs); 170 RegisterTestPrefs(&prefs);
168 171
169 PrefMemberTestClass test_obj(&prefs); 172 PrefMemberTestClass test_obj(&prefs);
170 EXPECT_EQ("default", *test_obj.str_); 173 EXPECT_EQ("default", *test_obj.str_);
171 174
172 // Calling SetValue should not fire the observer. 175 // Calling SetValue should not fire the observer.
173 test_obj.str_.SetValue("hello"); 176 test_obj.str_.SetValue("hello");
174 EXPECT_EQ(0, test_obj.observe_cnt_); 177 EXPECT_EQ(0, test_obj.observe_cnt_);
175 EXPECT_EQ("hello", prefs.GetString(kStringPref)); 178 EXPECT_EQ("hello", prefs.GetString(kStringPref));
176 179
177 // Changing the pref does fire the observer. 180 // Changing the pref does fire the observer.
178 prefs.SetString(kStringPref, "world"); 181 prefs.SetString(kStringPref, "world");
179 EXPECT_EQ(1, test_obj.observe_cnt_); 182 EXPECT_EQ(1, test_obj.observe_cnt_);
180 EXPECT_EQ("world", *(test_obj.str_)); 183 EXPECT_EQ("world", *(test_obj.str_));
181 184
182 // Not changing the value should not fire the observer. 185 // Not changing the value should not fire the observer.
183 prefs.SetString(kStringPref, "world"); 186 prefs.SetString(kStringPref, "world");
184 EXPECT_EQ(1, test_obj.observe_cnt_); 187 EXPECT_EQ(1, test_obj.observe_cnt_);
185 EXPECT_EQ("world", *(test_obj.str_)); 188 EXPECT_EQ("world", *(test_obj.str_));
186 189
187 prefs.SetString(kStringPref, "hello"); 190 prefs.SetString(kStringPref, "hello");
188 EXPECT_EQ(2, test_obj.observe_cnt_); 191 EXPECT_EQ(2, test_obj.observe_cnt_);
189 EXPECT_EQ("hello", prefs.GetString(kStringPref)); 192 EXPECT_EQ("hello", prefs.GetString(kStringPref));
190 } 193 }
191 194
192 TEST(PrefMemberTest, NoInit) { 195 TEST(PrefMemberTest, NoInit) {
193 // Make sure not calling Init on a PrefMember doesn't cause problems. 196 // Make sure not calling Init on a PrefMember doesn't cause problems.
194 IntegerPrefMember pref; 197 IntegerPrefMember pref;
195 } 198 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_url_request_context_unittest.cc ('k') | chrome/browser/pref_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698