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

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

Issue 3323022: Create a DefaultPrefStore to hold registered application-default preference v... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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) 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 <string> 5 #include <string>
6 6
7 #include "app/test/data/resource.h" 7 #include "app/test/data/resource.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/prefs/dummy_pref_store.h" 10 #include "chrome/browser/prefs/dummy_pref_store.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 }; 205 };
206 206
207 const char PrefServiceSetValueTest::name_[] = "name"; 207 const char PrefServiceSetValueTest::name_[] = "name";
208 const char PrefServiceSetValueTest::value_[] = "value"; 208 const char PrefServiceSetValueTest::value_[] = "value";
209 209
210 TEST_F(PrefServiceSetValueTest, SetStringValue) { 210 TEST_F(PrefServiceSetValueTest, SetStringValue) {
211 const char default_string[] = "default"; 211 const char default_string[] = "default";
212 scoped_ptr<Value> default_value(Value::CreateStringValue(default_string)); 212 scoped_ptr<Value> default_value(Value::CreateStringValue(default_string));
213 prefs_.RegisterStringPref(name_, default_string); 213 prefs_.RegisterStringPref(name_, default_string);
214 prefs_.AddPrefObserver(name_, &observer_); 214 prefs_.AddPrefObserver(name_, &observer_);
215 // Changing the controlling store from default to user triggers notification.
216 SetExpectPrefChanged();
217 prefs_.Set(name_, *default_value);
218 Mock::VerifyAndClearExpectations(&observer_);
219
215 SetExpectNoNotification(); 220 SetExpectNoNotification();
216 prefs_.Set(name_, *default_value); 221 prefs_.Set(name_, *default_value);
217 Mock::VerifyAndClearExpectations(&observer_); 222 Mock::VerifyAndClearExpectations(&observer_);
218 223
219 scoped_ptr<Value> new_value(Value::CreateStringValue(value_)); 224 scoped_ptr<Value> new_value(Value::CreateStringValue(value_));
220 SetExpectPrefChanged(); 225 SetExpectPrefChanged();
221 prefs_.Set(name_, *new_value); 226 prefs_.Set(name_, *new_value);
222 EXPECT_EQ(value_, prefs_.GetString(name_)); 227 EXPECT_EQ(value_, prefs_.GetString(name_));
223 228
224 prefs_.RemovePrefObserver(name_, &observer_); 229 prefs_.RemovePrefObserver(name_, &observer_);
225 } 230 }
226 231
227 TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { 232 TEST_F(PrefServiceSetValueTest, SetDictionaryValue) {
228 prefs_.RegisterDictionaryPref(name_); 233 prefs_.RegisterDictionaryPref(name_);
229 prefs_.AddPrefObserver(name_, &observer_); 234 prefs_.AddPrefObserver(name_, &observer_);
230 235
236 // Dictionary values are special: setting one to NULL is the same as clearing
237 // the user value, allowing the NULL default to take (or keep) control.
231 SetExpectNoNotification(); 238 SetExpectNoNotification();
232 prefs_.Set(name_, *null_value_); 239 prefs_.Set(name_, *null_value_);
233 Mock::VerifyAndClearExpectations(&observer_); 240 Mock::VerifyAndClearExpectations(&observer_);
234 241
235 DictionaryValue new_value; 242 DictionaryValue new_value;
236 new_value.SetString(name_, value_); 243 new_value.SetString(name_, value_);
237 SetExpectPrefChanged(); 244 SetExpectPrefChanged();
238 prefs_.Set(name_, new_value); 245 prefs_.Set(name_, new_value);
239 Mock::VerifyAndClearExpectations(&observer_); 246 Mock::VerifyAndClearExpectations(&observer_);
240 DictionaryValue* dict = prefs_.GetMutableDictionary(name_); 247 DictionaryValue* dict = prefs_.GetMutableDictionary(name_);
(...skipping 12 matching lines...) Expand all
253 dict = prefs_.GetMutableDictionary(name_); 260 dict = prefs_.GetMutableDictionary(name_);
254 EXPECT_EQ(0U, dict->size()); 261 EXPECT_EQ(0U, dict->size());
255 262
256 prefs_.RemovePrefObserver(name_, &observer_); 263 prefs_.RemovePrefObserver(name_, &observer_);
257 } 264 }
258 265
259 TEST_F(PrefServiceSetValueTest, SetListValue) { 266 TEST_F(PrefServiceSetValueTest, SetListValue) {
260 prefs_.RegisterListPref(name_); 267 prefs_.RegisterListPref(name_);
261 prefs_.AddPrefObserver(name_, &observer_); 268 prefs_.AddPrefObserver(name_, &observer_);
262 269
270 // List values are special: setting one to NULL is the same as clearing the
271 // user value, allowing the NULL default to take (or keep) control.
263 SetExpectNoNotification(); 272 SetExpectNoNotification();
264 prefs_.Set(name_, *null_value_); 273 prefs_.Set(name_, *null_value_);
265 Mock::VerifyAndClearExpectations(&observer_); 274 Mock::VerifyAndClearExpectations(&observer_);
266 275
267 ListValue new_value; 276 ListValue new_value;
268 new_value.Append(Value::CreateStringValue(value_)); 277 new_value.Append(Value::CreateStringValue(value_));
269 SetExpectPrefChanged(); 278 SetExpectPrefChanged();
270 prefs_.Set(name_, new_value); 279 prefs_.Set(name_, new_value);
271 Mock::VerifyAndClearExpectations(&observer_); 280 Mock::VerifyAndClearExpectations(&observer_);
272 ListValue* list = prefs_.GetMutableList(name_); 281 ListValue* list = prefs_.GetMutableList(name_);
273 ASSERT_EQ(1U, list->GetSize()); 282 ASSERT_EQ(1U, list->GetSize());
274 std::string out_value; 283 std::string out_value;
275 list->GetString(0, &out_value); 284 list->GetString(0, &out_value);
276 EXPECT_EQ(value_, out_value); 285 EXPECT_EQ(value_, out_value);
277 286
278 SetExpectNoNotification(); 287 SetExpectNoNotification();
279 prefs_.Set(name_, new_value); 288 prefs_.Set(name_, new_value);
280 Mock::VerifyAndClearExpectations(&observer_); 289 Mock::VerifyAndClearExpectations(&observer_);
281 290
282 SetExpectPrefChanged(); 291 SetExpectPrefChanged();
283 prefs_.Set(name_, *null_value_); 292 prefs_.Set(name_, *null_value_);
284 Mock::VerifyAndClearExpectations(&observer_); 293 Mock::VerifyAndClearExpectations(&observer_);
285 list = prefs_.GetMutableList(name_); 294 list = prefs_.GetMutableList(name_);
286 EXPECT_EQ(0U, list->GetSize()); 295 EXPECT_EQ(0U, list->GetSize());
287 296
288 prefs_.RemovePrefObserver(name_, &observer_); 297 prefs_.RemovePrefObserver(name_, &observer_);
289 } 298 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698