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

Side by Side Diff: base/prefs/pref_value_store_unittest.cc

Issue 16797003: Make base use the proper Value namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: iwarnings fixed Created 7 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_notifier.h" 10 #include "base/prefs/pref_notifier.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 214
215 scoped_refptr<TestingPrefStore> managed_pref_store_; 215 scoped_refptr<TestingPrefStore> managed_pref_store_;
216 scoped_refptr<TestingPrefStore> extension_pref_store_; 216 scoped_refptr<TestingPrefStore> extension_pref_store_;
217 scoped_refptr<TestingPrefStore> command_line_pref_store_; 217 scoped_refptr<TestingPrefStore> command_line_pref_store_;
218 scoped_refptr<TestingPrefStore> user_pref_store_; 218 scoped_refptr<TestingPrefStore> user_pref_store_;
219 scoped_refptr<TestingPrefStore> recommended_pref_store_; 219 scoped_refptr<TestingPrefStore> recommended_pref_store_;
220 scoped_refptr<TestingPrefStore> default_pref_store_; 220 scoped_refptr<TestingPrefStore> default_pref_store_;
221 }; 221 };
222 222
223 TEST_F(PrefValueStoreTest, GetValue) { 223 TEST_F(PrefValueStoreTest, GetValue) {
224 const Value* value; 224 const base::Value* value;
225 225
226 // The following tests read a value from the PrefService. The preferences are 226 // The following tests read a value from the PrefService. The preferences are
227 // set in a way such that all lower-priority stores have a value and we can 227 // set in a way such that all lower-priority stores have a value and we can
228 // test whether overrides work correctly. 228 // test whether overrides work correctly.
229 229
230 // Test getting a managed value. 230 // Test getting a managed value.
231 value = NULL; 231 value = NULL;
232 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kManagedPref, 232 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kManagedPref,
233 Value::TYPE_STRING, &value)); 233 base::Value::TYPE_STRING, &value));
234 std::string actual_str_value; 234 std::string actual_str_value;
235 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 235 EXPECT_TRUE(value->GetAsString(&actual_str_value));
236 EXPECT_EQ(managed_pref::kManagedValue, actual_str_value); 236 EXPECT_EQ(managed_pref::kManagedValue, actual_str_value);
237 237
238 // Test getting an extension value. 238 // Test getting an extension value.
239 value = NULL; 239 value = NULL;
240 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kExtensionPref, 240 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kExtensionPref,
241 Value::TYPE_STRING, &value)); 241 base::Value::TYPE_STRING, &value));
242 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 242 EXPECT_TRUE(value->GetAsString(&actual_str_value));
243 EXPECT_EQ(extension_pref::kExtensionValue, actual_str_value); 243 EXPECT_EQ(extension_pref::kExtensionValue, actual_str_value);
244 244
245 // Test getting a command-line value. 245 // Test getting a command-line value.
246 value = NULL; 246 value = NULL;
247 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kCommandLinePref, 247 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kCommandLinePref,
248 Value::TYPE_STRING, &value)); 248 base::Value::TYPE_STRING, &value));
249 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 249 EXPECT_TRUE(value->GetAsString(&actual_str_value));
250 EXPECT_EQ(command_line_pref::kCommandLineValue, actual_str_value); 250 EXPECT_EQ(command_line_pref::kCommandLineValue, actual_str_value);
251 251
252 // Test getting a user-set value. 252 // Test getting a user-set value.
253 value = NULL; 253 value = NULL;
254 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kUserPref, 254 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kUserPref,
255 Value::TYPE_STRING, &value)); 255 base::Value::TYPE_STRING, &value));
256 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 256 EXPECT_TRUE(value->GetAsString(&actual_str_value));
257 EXPECT_EQ(user_pref::kUserValue, actual_str_value); 257 EXPECT_EQ(user_pref::kUserValue, actual_str_value);
258 258
259 // Test getting a user set value overwriting a recommended value. 259 // Test getting a user set value overwriting a recommended value.
260 value = NULL; 260 value = NULL;
261 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedPref, 261 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedPref,
262 Value::TYPE_STRING, &value)); 262 base::Value::TYPE_STRING, &value));
263 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 263 EXPECT_TRUE(value->GetAsString(&actual_str_value));
264 EXPECT_EQ(recommended_pref::kRecommendedValue, 264 EXPECT_EQ(recommended_pref::kRecommendedValue,
265 actual_str_value); 265 actual_str_value);
266 266
267 // Test getting a default value. 267 // Test getting a default value.
268 value = NULL; 268 value = NULL;
269 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultPref, 269 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultPref,
270 Value::TYPE_STRING, &value)); 270 base::Value::TYPE_STRING, &value));
271 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 271 EXPECT_TRUE(value->GetAsString(&actual_str_value));
272 EXPECT_EQ(default_pref::kDefaultValue, actual_str_value); 272 EXPECT_EQ(default_pref::kDefaultValue, actual_str_value);
273 273
274 // Test getting a preference value that the |PrefValueStore| 274 // Test getting a preference value that the |PrefValueStore|
275 // does not contain. 275 // does not contain.
276 base::FundamentalValue tmp_dummy_value(true); 276 base::FundamentalValue tmp_dummy_value(true);
277 value = &tmp_dummy_value; 277 value = &tmp_dummy_value;
278 ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref, 278 ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref,
279 Value::TYPE_STRING, &value)); 279 base::Value::TYPE_STRING, &value));
280 ASSERT_FALSE(value); 280 ASSERT_FALSE(value);
281 } 281 }
282 282
283 TEST_F(PrefValueStoreTest, GetRecommendedValue) { 283 TEST_F(PrefValueStoreTest, GetRecommendedValue) {
284 const Value* value; 284 const base::Value* value;
285 285
286 // The following tests read a value from the PrefService. The preferences are 286 // The following tests read a value from the PrefService. The preferences are
287 // set in a way such that all lower-priority stores have a value and we can 287 // set in a way such that all lower-priority stores have a value and we can
288 // test whether overrides do not clutter the recommended value. 288 // test whether overrides do not clutter the recommended value.
289 289
290 // Test getting recommended value when a managed value is present. 290 // Test getting recommended value when a managed value is present.
291 value = NULL; 291 value = NULL;
292 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( 292 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
293 prefs::kManagedPref, 293 prefs::kManagedPref,
294 Value::TYPE_STRING, &value)); 294 base::Value::TYPE_STRING, &value));
295 std::string actual_str_value; 295 std::string actual_str_value;
296 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 296 EXPECT_TRUE(value->GetAsString(&actual_str_value));
297 EXPECT_EQ(recommended_pref::kManagedValue, actual_str_value); 297 EXPECT_EQ(recommended_pref::kManagedValue, actual_str_value);
298 298
299 // Test getting recommended value when an extension value is present. 299 // Test getting recommended value when an extension value is present.
300 value = NULL; 300 value = NULL;
301 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( 301 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
302 prefs::kExtensionPref, 302 prefs::kExtensionPref,
303 Value::TYPE_STRING, &value)); 303 base::Value::TYPE_STRING, &value));
304 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 304 EXPECT_TRUE(value->GetAsString(&actual_str_value));
305 EXPECT_EQ(recommended_pref::kExtensionValue, actual_str_value); 305 EXPECT_EQ(recommended_pref::kExtensionValue, actual_str_value);
306 306
307 // Test getting recommended value when a command-line value is present. 307 // Test getting recommended value when a command-line value is present.
308 value = NULL; 308 value = NULL;
309 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( 309 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
310 prefs::kCommandLinePref, 310 prefs::kCommandLinePref,
311 Value::TYPE_STRING, &value)); 311 base::Value::TYPE_STRING, &value));
312 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 312 EXPECT_TRUE(value->GetAsString(&actual_str_value));
313 EXPECT_EQ(recommended_pref::kCommandLineValue, actual_str_value); 313 EXPECT_EQ(recommended_pref::kCommandLineValue, actual_str_value);
314 314
315 // Test getting recommended value when a user-set value is present. 315 // Test getting recommended value when a user-set value is present.
316 value = NULL; 316 value = NULL;
317 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( 317 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
318 prefs::kUserPref, 318 prefs::kUserPref,
319 Value::TYPE_STRING, &value)); 319 base::Value::TYPE_STRING, &value));
320 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 320 EXPECT_TRUE(value->GetAsString(&actual_str_value));
321 EXPECT_EQ(recommended_pref::kUserValue, actual_str_value); 321 EXPECT_EQ(recommended_pref::kUserValue, actual_str_value);
322 322
323 // Test getting recommended value when no higher-priority value is present. 323 // Test getting recommended value when no higher-priority value is present.
324 value = NULL; 324 value = NULL;
325 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( 325 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
326 prefs::kRecommendedPref, 326 prefs::kRecommendedPref,
327 Value::TYPE_STRING, &value)); 327 base::Value::TYPE_STRING, &value));
328 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 328 EXPECT_TRUE(value->GetAsString(&actual_str_value));
329 EXPECT_EQ(recommended_pref::kRecommendedValue, 329 EXPECT_EQ(recommended_pref::kRecommendedValue,
330 actual_str_value); 330 actual_str_value);
331 331
332 // Test getting recommended value when no recommended value is present. 332 // Test getting recommended value when no recommended value is present.
333 base::FundamentalValue tmp_dummy_value(true); 333 base::FundamentalValue tmp_dummy_value(true);
334 value = &tmp_dummy_value; 334 value = &tmp_dummy_value;
335 ASSERT_FALSE(pref_value_store_->GetRecommendedValue( 335 ASSERT_FALSE(pref_value_store_->GetRecommendedValue(
336 prefs::kDefaultPref, 336 prefs::kDefaultPref,
337 Value::TYPE_STRING, &value)); 337 base::Value::TYPE_STRING, &value));
338 ASSERT_FALSE(value); 338 ASSERT_FALSE(value);
339 339
340 // Test getting a preference value that the |PrefValueStore| 340 // Test getting a preference value that the |PrefValueStore|
341 // does not contain. 341 // does not contain.
342 value = &tmp_dummy_value; 342 value = &tmp_dummy_value;
343 ASSERT_FALSE(pref_value_store_->GetRecommendedValue( 343 ASSERT_FALSE(pref_value_store_->GetRecommendedValue(
344 prefs::kMissingPref, 344 prefs::kMissingPref,
345 Value::TYPE_STRING, &value)); 345 base::Value::TYPE_STRING, &value));
346 ASSERT_FALSE(value); 346 ASSERT_FALSE(value);
347 } 347 }
348 348
349 TEST_F(PrefValueStoreTest, PrefChanges) { 349 TEST_F(PrefValueStoreTest, PrefChanges) {
350 // Check pref controlled by highest-priority store. 350 // Check pref controlled by highest-priority store.
351 ExpectValueChangeNotifications(prefs::kManagedPref); 351 ExpectValueChangeNotifications(prefs::kManagedPref);
352 managed_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref); 352 managed_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
353 CheckAndClearValueChangeNotifications(); 353 CheckAndClearValueChangeNotifications();
354 354
355 ExpectValueChangeNotifications(prefs::kManagedPref); 355 ExpectValueChangeNotifications(prefs::kManagedPref);
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 prefs::kCommandLinePref)); 583 prefs::kCommandLinePref));
584 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( 584 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
585 prefs::kUserPref)); 585 prefs::kUserPref));
586 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( 586 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
587 prefs::kRecommendedPref)); 587 prefs::kRecommendedPref));
588 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( 588 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
589 prefs::kDefaultPref)); 589 prefs::kDefaultPref));
590 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( 590 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
591 prefs::kMissingPref)); 591 prefs::kMissingPref));
592 } 592 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698