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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 registrar.Add(pref_name, &obs); | 53 registrar.Add(pref_name, &obs); |
54 | 54 |
55 // This should fire the checks in PrefObserverMock::Observe. | 55 // This should fire the checks in PrefObserverMock::Observe. |
56 const StringValue expected_value(new_pref_value); | 56 const StringValue expected_value(new_pref_value); |
57 obs.Expect(&prefs, pref_name, &expected_value); | 57 obs.Expect(&prefs, pref_name, &expected_value); |
58 prefs.SetString(pref_name, new_pref_value); | 58 prefs.SetString(pref_name, new_pref_value); |
59 Mock::VerifyAndClearExpectations(&obs); | 59 Mock::VerifyAndClearExpectations(&obs); |
60 | 60 |
61 // Setting the pref to the same value should not set the pref value a second | 61 // Setting the pref to the same value should not set the pref value a second |
62 // time. | 62 // time. |
63 EXPECT_CALL(obs, Observe(_, _, _)).Times(0); | 63 EXPECT_CALL(obs, OnPreferenceChanged(_, _)).Times(0); |
64 prefs.SetString(pref_name, new_pref_value); | 64 prefs.SetString(pref_name, new_pref_value); |
65 Mock::VerifyAndClearExpectations(&obs); | 65 Mock::VerifyAndClearExpectations(&obs); |
66 | 66 |
67 // Clearing the pref should cause the pref to fire. | 67 // Clearing the pref should cause the pref to fire. |
68 const StringValue expected_default_value(""); | 68 const StringValue expected_default_value(""); |
69 obs.Expect(&prefs, pref_name, &expected_default_value); | 69 obs.Expect(&prefs, pref_name, &expected_default_value); |
70 prefs.ClearPref(pref_name); | 70 prefs.ClearPref(pref_name); |
71 Mock::VerifyAndClearExpectations(&obs); | 71 Mock::VerifyAndClearExpectations(&obs); |
72 | 72 |
73 // Clearing the pref again should not cause the pref to fire. | 73 // Clearing the pref again should not cause the pref to fire. |
74 EXPECT_CALL(obs, Observe(_, _, _)).Times(0); | 74 EXPECT_CALL(obs, OnPreferenceChanged(_, _)).Times(0); |
75 prefs.ClearPref(pref_name); | 75 prefs.ClearPref(pref_name); |
76 Mock::VerifyAndClearExpectations(&obs); | 76 Mock::VerifyAndClearExpectations(&obs); |
77 } | 77 } |
78 | 78 |
79 TEST(PrefServiceTest, HasPrefPath) { | 79 TEST(PrefServiceTest, HasPrefPath) { |
80 TestingPrefService prefs; | 80 TestingPrefService prefs; |
81 | 81 |
82 const char path[] = "fake.path"; | 82 const char path[] = "fake.path"; |
83 | 83 |
84 // Shouldn't initially have a path. | 84 // Shouldn't initially have a path. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 obs.Expect(&prefs, pref_name, &expected_new_pref_value2); | 130 obs.Expect(&prefs, pref_name, &expected_new_pref_value2); |
131 obs2.Expect(&prefs, pref_name, &expected_new_pref_value2); | 131 obs2.Expect(&prefs, pref_name, &expected_new_pref_value2); |
132 // This should fire the checks in obs and obs2 but with an unchanged value | 132 // This should fire the checks in obs and obs2 but with an unchanged value |
133 // as the recommended value is being overridden by the user-set value. | 133 // as the recommended value is being overridden by the user-set value. |
134 prefs.SetRecommendedPref(pref_name, recommended_pref_value.DeepCopy()); | 134 prefs.SetRecommendedPref(pref_name, recommended_pref_value.DeepCopy()); |
135 Mock::VerifyAndClearExpectations(&obs); | 135 Mock::VerifyAndClearExpectations(&obs); |
136 Mock::VerifyAndClearExpectations(&obs2); | 136 Mock::VerifyAndClearExpectations(&obs2); |
137 | 137 |
138 // Make sure obs2 still works after removing obs. | 138 // Make sure obs2 still works after removing obs. |
139 registrar.Remove(pref_name, &obs); | 139 registrar.Remove(pref_name, &obs); |
140 EXPECT_CALL(obs, Observe(_, _, _)).Times(0); | 140 EXPECT_CALL(obs, OnPreferenceChanged(_, _)).Times(0); |
141 obs2.Expect(&prefs, pref_name, &expected_new_pref_value); | 141 obs2.Expect(&prefs, pref_name, &expected_new_pref_value); |
142 // This should only fire the observer in obs2. | 142 // This should only fire the observer in obs2. |
143 prefs.SetString(pref_name, new_pref_value); | 143 prefs.SetString(pref_name, new_pref_value); |
144 Mock::VerifyAndClearExpectations(&obs); | 144 Mock::VerifyAndClearExpectations(&obs); |
145 Mock::VerifyAndClearExpectations(&obs2); | 145 Mock::VerifyAndClearExpectations(&obs2); |
146 } | 146 } |
147 | 147 |
148 // Make sure that if a preference changes type, so the wrong type is stored in | 148 // Make sure that if a preference changes type, so the wrong type is stored in |
149 // the user pref file, it uses the correct fallback value instead. | 149 // the user pref file, it uses the correct fallback value instead. |
150 TEST(PrefServiceTest, GetValueChangedType) { | 150 TEST(PrefServiceTest, GetValueChangedType) { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 372 |
373 PrefChangeRegistrar registrar; | 373 PrefChangeRegistrar registrar; |
374 registrar.Init(&prefs_); | 374 registrar.Init(&prefs_); |
375 registrar.Add(kName, &observer_); | 375 registrar.Add(kName, &observer_); |
376 | 376 |
377 // Changing the controlling store from default to user triggers notification. | 377 // Changing the controlling store from default to user triggers notification. |
378 observer_.Expect(&prefs_, kName, &default_value); | 378 observer_.Expect(&prefs_, kName, &default_value); |
379 prefs_.Set(kName, default_value); | 379 prefs_.Set(kName, default_value); |
380 Mock::VerifyAndClearExpectations(&observer_); | 380 Mock::VerifyAndClearExpectations(&observer_); |
381 | 381 |
382 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); | 382 EXPECT_CALL(observer_, OnPreferenceChanged(_, _)).Times(0); |
383 prefs_.Set(kName, default_value); | 383 prefs_.Set(kName, default_value); |
384 Mock::VerifyAndClearExpectations(&observer_); | 384 Mock::VerifyAndClearExpectations(&observer_); |
385 | 385 |
386 StringValue new_value(kValue); | 386 StringValue new_value(kValue); |
387 observer_.Expect(&prefs_, kName, &new_value); | 387 observer_.Expect(&prefs_, kName, &new_value); |
388 prefs_.Set(kName, new_value); | 388 prefs_.Set(kName, new_value); |
389 Mock::VerifyAndClearExpectations(&observer_); | 389 Mock::VerifyAndClearExpectations(&observer_); |
390 } | 390 } |
391 | 391 |
392 TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { | 392 TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { |
393 prefs_.RegisterDictionaryPref(kName); | 393 prefs_.RegisterDictionaryPref(kName); |
394 PrefChangeRegistrar registrar; | 394 PrefChangeRegistrar registrar; |
395 registrar.Init(&prefs_); | 395 registrar.Init(&prefs_); |
396 registrar.Add(kName, &observer_); | 396 registrar.Add(kName, &observer_); |
397 | 397 |
398 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); | 398 EXPECT_CALL(observer_, OnPreferenceChanged(_, _)).Times(0); |
399 prefs_.RemoveUserPref(kName); | 399 prefs_.RemoveUserPref(kName); |
400 Mock::VerifyAndClearExpectations(&observer_); | 400 Mock::VerifyAndClearExpectations(&observer_); |
401 | 401 |
402 DictionaryValue new_value; | 402 DictionaryValue new_value; |
403 new_value.SetString(kName, kValue); | 403 new_value.SetString(kName, kValue); |
404 observer_.Expect(&prefs_, kName, &new_value); | 404 observer_.Expect(&prefs_, kName, &new_value); |
405 prefs_.Set(kName, new_value); | 405 prefs_.Set(kName, new_value); |
406 Mock::VerifyAndClearExpectations(&observer_); | 406 Mock::VerifyAndClearExpectations(&observer_); |
407 | 407 |
408 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); | 408 EXPECT_CALL(observer_, OnPreferenceChanged(_, _)).Times(0); |
409 prefs_.Set(kName, new_value); | 409 prefs_.Set(kName, new_value); |
410 Mock::VerifyAndClearExpectations(&observer_); | 410 Mock::VerifyAndClearExpectations(&observer_); |
411 | 411 |
412 DictionaryValue empty; | 412 DictionaryValue empty; |
413 observer_.Expect(&prefs_, kName, &empty); | 413 observer_.Expect(&prefs_, kName, &empty); |
414 prefs_.Set(kName, empty); | 414 prefs_.Set(kName, empty); |
415 Mock::VerifyAndClearExpectations(&observer_); | 415 Mock::VerifyAndClearExpectations(&observer_); |
416 } | 416 } |
417 | 417 |
418 TEST_F(PrefServiceSetValueTest, SetListValue) { | 418 TEST_F(PrefServiceSetValueTest, SetListValue) { |
419 prefs_.RegisterListPref(kName); | 419 prefs_.RegisterListPref(kName); |
420 PrefChangeRegistrar registrar; | 420 PrefChangeRegistrar registrar; |
421 registrar.Init(&prefs_); | 421 registrar.Init(&prefs_); |
422 registrar.Add(kName, &observer_); | 422 registrar.Add(kName, &observer_); |
423 | 423 |
424 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); | 424 EXPECT_CALL(observer_, OnPreferenceChanged(_, _)).Times(0); |
425 prefs_.RemoveUserPref(kName); | 425 prefs_.RemoveUserPref(kName); |
426 Mock::VerifyAndClearExpectations(&observer_); | 426 Mock::VerifyAndClearExpectations(&observer_); |
427 | 427 |
428 ListValue new_value; | 428 ListValue new_value; |
429 new_value.Append(Value::CreateStringValue(kValue)); | 429 new_value.Append(Value::CreateStringValue(kValue)); |
430 observer_.Expect(&prefs_, kName, &new_value); | 430 observer_.Expect(&prefs_, kName, &new_value); |
431 prefs_.Set(kName, new_value); | 431 prefs_.Set(kName, new_value); |
432 Mock::VerifyAndClearExpectations(&observer_); | 432 Mock::VerifyAndClearExpectations(&observer_); |
433 | 433 |
434 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); | 434 EXPECT_CALL(observer_, OnPreferenceChanged(_, _)).Times(0); |
435 prefs_.Set(kName, new_value); | 435 prefs_.Set(kName, new_value); |
436 Mock::VerifyAndClearExpectations(&observer_); | 436 Mock::VerifyAndClearExpectations(&observer_); |
437 | 437 |
438 ListValue empty; | 438 ListValue empty; |
439 observer_.Expect(&prefs_, kName, &empty); | 439 observer_.Expect(&prefs_, kName, &empty); |
440 prefs_.Set(kName, empty); | 440 prefs_.Set(kName, empty); |
441 Mock::VerifyAndClearExpectations(&observer_); | 441 Mock::VerifyAndClearExpectations(&observer_); |
442 } | 442 } |
443 | 443 |
444 class PrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness { | 444 class PrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 const char kDefaultFont[] = "Times"; | 491 const char kDefaultFont[] = "Times"; |
492 #elif defined(OS_CHROMEOS) | 492 #elif defined(OS_CHROMEOS) |
493 const char kDefaultFont[] = "Tinos"; | 493 const char kDefaultFont[] = "Tinos"; |
494 #else | 494 #else |
495 const char kDefaultFont[] = "Times New Roman"; | 495 const char kDefaultFont[] = "Times New Roman"; |
496 #endif | 496 #endif |
497 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), | 497 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), |
498 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); | 498 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); |
499 EXPECT_TRUE(webkit_prefs.javascript_enabled); | 499 EXPECT_TRUE(webkit_prefs.javascript_enabled); |
500 } | 500 } |
OLD | NEW |