OLD | NEW |
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 "components/prefs/pref_value_store.h" | 5 #include "components/prefs/pref_value_store.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 TEST_F(PrefValueStoreTest, GetValue) { | 264 TEST_F(PrefValueStoreTest, GetValue) { |
265 const base::Value* value; | 265 const base::Value* value; |
266 | 266 |
267 // The following tests read a value from the PrefService. The preferences are | 267 // The following tests read a value from the PrefService. The preferences are |
268 // set in a way such that all lower-priority stores have a value and we can | 268 // set in a way such that all lower-priority stores have a value and we can |
269 // test whether overrides work correctly. | 269 // test whether overrides work correctly. |
270 | 270 |
271 // Test getting a managed value. | 271 // Test getting a managed value. |
272 value = NULL; | 272 value = NULL; |
273 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kManagedPref, | 273 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kManagedPref, |
274 base::Value::TYPE_STRING, &value)); | 274 base::Value::Type::STRING, &value)); |
275 std::string actual_str_value; | 275 std::string actual_str_value; |
276 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 276 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
277 EXPECT_EQ(managed_pref::kManagedValue, actual_str_value); | 277 EXPECT_EQ(managed_pref::kManagedValue, actual_str_value); |
278 | 278 |
279 // Test getting a supervised user value. | 279 // Test getting a supervised user value. |
280 value = NULL; | 280 value = NULL; |
281 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kSupervisedUserPref, | 281 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kSupervisedUserPref, |
282 base::Value::TYPE_STRING, &value)); | 282 base::Value::Type::STRING, &value)); |
283 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 283 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
284 EXPECT_EQ(supervised_user_pref::kSupervisedUserValue, actual_str_value); | 284 EXPECT_EQ(supervised_user_pref::kSupervisedUserValue, actual_str_value); |
285 | 285 |
286 // Test getting an extension value. | 286 // Test getting an extension value. |
287 value = NULL; | 287 value = NULL; |
288 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kExtensionPref, | 288 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kExtensionPref, |
289 base::Value::TYPE_STRING, &value)); | 289 base::Value::Type::STRING, &value)); |
290 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 290 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
291 EXPECT_EQ(extension_pref::kExtensionValue, actual_str_value); | 291 EXPECT_EQ(extension_pref::kExtensionValue, actual_str_value); |
292 | 292 |
293 // Test getting a command-line value. | 293 // Test getting a command-line value. |
294 value = NULL; | 294 value = NULL; |
295 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kCommandLinePref, | 295 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kCommandLinePref, |
296 base::Value::TYPE_STRING, &value)); | 296 base::Value::Type::STRING, &value)); |
297 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 297 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
298 EXPECT_EQ(command_line_pref::kCommandLineValue, actual_str_value); | 298 EXPECT_EQ(command_line_pref::kCommandLineValue, actual_str_value); |
299 | 299 |
300 // Test getting a user-set value. | 300 // Test getting a user-set value. |
301 value = NULL; | 301 value = NULL; |
302 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kUserPref, | 302 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kUserPref, |
303 base::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(user_pref::kUserValue, actual_str_value); | 305 EXPECT_EQ(user_pref::kUserValue, actual_str_value); |
306 | 306 |
307 // Test getting a user set value overwriting a recommended value. | 307 // Test getting a user set value overwriting a recommended value. |
308 value = NULL; | 308 value = NULL; |
309 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedPref, | 309 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedPref, |
310 base::Value::TYPE_STRING, &value)); | 310 base::Value::Type::STRING, &value)); |
311 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 311 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
312 EXPECT_EQ(recommended_pref::kRecommendedValue, | 312 EXPECT_EQ(recommended_pref::kRecommendedValue, |
313 actual_str_value); | 313 actual_str_value); |
314 | 314 |
315 // Test getting a default value. | 315 // Test getting a default value. |
316 value = NULL; | 316 value = NULL; |
317 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultPref, | 317 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultPref, |
318 base::Value::TYPE_STRING, &value)); | 318 base::Value::Type::STRING, &value)); |
319 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 319 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
320 EXPECT_EQ(default_pref::kDefaultValue, actual_str_value); | 320 EXPECT_EQ(default_pref::kDefaultValue, actual_str_value); |
321 | 321 |
322 // Test getting a preference value that the |PrefValueStore| | 322 // Test getting a preference value that the |PrefValueStore| |
323 // does not contain. | 323 // does not contain. |
324 base::FundamentalValue tmp_dummy_value(true); | 324 base::FundamentalValue tmp_dummy_value(true); |
325 value = &tmp_dummy_value; | 325 value = &tmp_dummy_value; |
326 ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref, | 326 ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref, |
327 base::Value::TYPE_STRING, &value)); | 327 base::Value::Type::STRING, &value)); |
328 ASSERT_FALSE(value); | 328 ASSERT_FALSE(value); |
329 } | 329 } |
330 | 330 |
331 TEST_F(PrefValueStoreTest, GetRecommendedValue) { | 331 TEST_F(PrefValueStoreTest, GetRecommendedValue) { |
332 const base::Value* value; | 332 const base::Value* value; |
333 | 333 |
334 // The following tests read a value from the PrefService. The preferences are | 334 // The following tests read a value from the PrefService. The preferences are |
335 // set in a way such that all lower-priority stores have a value and we can | 335 // set in a way such that all lower-priority stores have a value and we can |
336 // test whether overrides do not clutter the recommended value. | 336 // test whether overrides do not clutter the recommended value. |
337 | 337 |
338 // Test getting recommended value when a managed value is present. | 338 // Test getting recommended value when a managed value is present. |
339 value = NULL; | 339 value = NULL; |
340 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( | 340 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( |
341 prefs::kManagedPref, | 341 prefs::kManagedPref, |
342 base::Value::TYPE_STRING, &value)); | 342 base::Value::Type::STRING, &value)); |
343 std::string actual_str_value; | 343 std::string actual_str_value; |
344 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 344 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
345 EXPECT_EQ(recommended_pref::kManagedValue, actual_str_value); | 345 EXPECT_EQ(recommended_pref::kManagedValue, actual_str_value); |
346 | 346 |
347 // Test getting recommended value when a supervised user value is present. | 347 // Test getting recommended value when a supervised user value is present. |
348 value = NULL; | 348 value = NULL; |
349 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( | 349 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( |
350 prefs::kSupervisedUserPref, | 350 prefs::kSupervisedUserPref, |
351 base::Value::TYPE_STRING, &value)); | 351 base::Value::Type::STRING, &value)); |
352 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 352 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
353 EXPECT_EQ(recommended_pref::kSupervisedUserValue, actual_str_value); | 353 EXPECT_EQ(recommended_pref::kSupervisedUserValue, actual_str_value); |
354 | 354 |
355 // Test getting recommended value when an extension value is present. | 355 // Test getting recommended value when an extension value is present. |
356 value = NULL; | 356 value = NULL; |
357 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( | 357 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( |
358 prefs::kExtensionPref, | 358 prefs::kExtensionPref, |
359 base::Value::TYPE_STRING, &value)); | 359 base::Value::Type::STRING, &value)); |
360 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 360 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
361 EXPECT_EQ(recommended_pref::kExtensionValue, actual_str_value); | 361 EXPECT_EQ(recommended_pref::kExtensionValue, actual_str_value); |
362 | 362 |
363 // Test getting recommended value when a command-line value is present. | 363 // Test getting recommended value when a command-line value is present. |
364 value = NULL; | 364 value = NULL; |
365 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( | 365 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( |
366 prefs::kCommandLinePref, | 366 prefs::kCommandLinePref, |
367 base::Value::TYPE_STRING, &value)); | 367 base::Value::Type::STRING, &value)); |
368 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 368 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
369 EXPECT_EQ(recommended_pref::kCommandLineValue, actual_str_value); | 369 EXPECT_EQ(recommended_pref::kCommandLineValue, actual_str_value); |
370 | 370 |
371 // Test getting recommended value when a user-set value is present. | 371 // Test getting recommended value when a user-set value is present. |
372 value = NULL; | 372 value = NULL; |
373 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( | 373 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( |
374 prefs::kUserPref, | 374 prefs::kUserPref, |
375 base::Value::TYPE_STRING, &value)); | 375 base::Value::Type::STRING, &value)); |
376 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 376 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
377 EXPECT_EQ(recommended_pref::kUserValue, actual_str_value); | 377 EXPECT_EQ(recommended_pref::kUserValue, actual_str_value); |
378 | 378 |
379 // Test getting recommended value when no higher-priority value is present. | 379 // Test getting recommended value when no higher-priority value is present. |
380 value = NULL; | 380 value = NULL; |
381 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( | 381 ASSERT_TRUE(pref_value_store_->GetRecommendedValue( |
382 prefs::kRecommendedPref, | 382 prefs::kRecommendedPref, |
383 base::Value::TYPE_STRING, &value)); | 383 base::Value::Type::STRING, &value)); |
384 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 384 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
385 EXPECT_EQ(recommended_pref::kRecommendedValue, | 385 EXPECT_EQ(recommended_pref::kRecommendedValue, |
386 actual_str_value); | 386 actual_str_value); |
387 | 387 |
388 // Test getting recommended value when no recommended value is present. | 388 // Test getting recommended value when no recommended value is present. |
389 base::FundamentalValue tmp_dummy_value(true); | 389 base::FundamentalValue tmp_dummy_value(true); |
390 value = &tmp_dummy_value; | 390 value = &tmp_dummy_value; |
391 ASSERT_FALSE(pref_value_store_->GetRecommendedValue( | 391 ASSERT_FALSE(pref_value_store_->GetRecommendedValue( |
392 prefs::kDefaultPref, | 392 prefs::kDefaultPref, |
393 base::Value::TYPE_STRING, &value)); | 393 base::Value::Type::STRING, &value)); |
394 ASSERT_FALSE(value); | 394 ASSERT_FALSE(value); |
395 | 395 |
396 // Test getting a preference value that the |PrefValueStore| | 396 // Test getting a preference value that the |PrefValueStore| |
397 // does not contain. | 397 // does not contain. |
398 value = &tmp_dummy_value; | 398 value = &tmp_dummy_value; |
399 ASSERT_FALSE(pref_value_store_->GetRecommendedValue( | 399 ASSERT_FALSE(pref_value_store_->GetRecommendedValue( |
400 prefs::kMissingPref, | 400 prefs::kMissingPref, |
401 base::Value::TYPE_STRING, &value)); | 401 base::Value::Type::STRING, &value)); |
402 ASSERT_FALSE(value); | 402 ASSERT_FALSE(value); |
403 } | 403 } |
404 | 404 |
405 TEST_F(PrefValueStoreTest, PrefChanges) { | 405 TEST_F(PrefValueStoreTest, PrefChanges) { |
406 // Check pref controlled by highest-priority store. | 406 // Check pref controlled by highest-priority store. |
407 ExpectValueChangeNotifications(prefs::kManagedPref); | 407 ExpectValueChangeNotifications(prefs::kManagedPref); |
408 managed_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref); | 408 managed_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref); |
409 CheckAndClearValueChangeNotifications(); | 409 CheckAndClearValueChangeNotifications(); |
410 | 410 |
411 ExpectValueChangeNotifications(prefs::kManagedPref); | 411 ExpectValueChangeNotifications(prefs::kManagedPref); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 prefs::kCommandLinePref)); | 662 prefs::kCommandLinePref)); |
663 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( | 663 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( |
664 prefs::kUserPref)); | 664 prefs::kUserPref)); |
665 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( | 665 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( |
666 prefs::kRecommendedPref)); | 666 prefs::kRecommendedPref)); |
667 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( | 667 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( |
668 prefs::kDefaultPref)); | 668 prefs::kDefaultPref)); |
669 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( | 669 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( |
670 prefs::kMissingPref)); | 670 prefs::kMissingPref)); |
671 } | 671 } |
OLD | NEW |