Chromium Code Reviews| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 prefs.RegisterStringPref(path, std::string()); | 89 prefs.RegisterStringPref(path, std::string()); |
| 90 EXPECT_FALSE(prefs.HasPrefPath(path)); | 90 EXPECT_FALSE(prefs.HasPrefPath(path)); |
| 91 | 91 |
| 92 // Set a value and make sure we have a path. | 92 // Set a value and make sure we have a path. |
| 93 prefs.SetString(path, "blah"); | 93 prefs.SetString(path, "blah"); |
| 94 EXPECT_TRUE(prefs.HasPrefPath(path)); | 94 EXPECT_TRUE(prefs.HasPrefPath(path)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST(PrefServiceTest, Observers) { | 97 TEST(PrefServiceTest, Observers) { |
| 98 const char pref_name[] = "homepage"; | 98 const char pref_name[] = "homepage"; |
| 99 const char pref_name_two[] = "homepage2"; | |
| 99 | 100 |
| 100 TestingPrefService prefs; | 101 TestingPrefService prefs; |
| 101 prefs.SetUserPref(pref_name, Value::CreateStringValue("http://www.cnn.com")); | 102 prefs.SetUserPref(pref_name, Value::CreateStringValue("http://www.cnn.com")); |
| 102 prefs.RegisterStringPref(pref_name, std::string()); | 103 prefs.RegisterStringPref(pref_name, std::string()); |
| 104 prefs.RegisterStringPref(pref_name_two, std::string()); | |
| 103 | 105 |
| 104 const char new_pref_value[] = "http://www.google.com/"; | 106 const char new_pref_value[] = "http://www.google.com/"; |
| 105 const StringValue expected_new_pref_value(new_pref_value); | 107 const StringValue expected_new_pref_value(new_pref_value); |
| 106 PrefObserverMock obs; | 108 PrefObserverMock obs; |
| 107 PrefChangeRegistrar registrar; | 109 PrefChangeRegistrar registrar; |
| 108 registrar.Init(&prefs); | 110 registrar.Init(&prefs); |
| 109 registrar.Add(pref_name, &obs); | 111 registrar.Add(pref_name, &obs); |
| 110 | 112 |
| 111 // This should fire the checks in PrefObserverMock::Observe. | 113 // This should fire the checks in PrefObserverMock::Observe. |
| 112 obs.Expect(&prefs, pref_name, &expected_new_pref_value); | 114 obs.Expect(&prefs, pref_name, &expected_new_pref_value); |
| 113 prefs.SetString(pref_name, new_pref_value); | 115 prefs.SetString(pref_name, new_pref_value); |
| 114 Mock::VerifyAndClearExpectations(&obs); | 116 Mock::VerifyAndClearExpectations(&obs); |
| 115 | 117 |
| 116 // Now try adding a second pref observer. | 118 // Now try adding a second pref observer. |
| 117 const char new_pref_value2[] = "http://www.youtube.com/"; | 119 const char new_pref_value2[] = "http://www.youtube.com/"; |
| 118 const StringValue expected_new_pref_value2(new_pref_value2); | 120 const StringValue expected_new_pref_value2(new_pref_value2); |
| 119 PrefObserverMock obs2; | 121 PrefObserverMock obs2; |
| 120 obs.Expect(&prefs, pref_name, &expected_new_pref_value2); | 122 obs.Expect(&prefs, pref_name, &expected_new_pref_value2); |
| 121 obs2.Expect(&prefs, pref_name, &expected_new_pref_value2); | 123 obs2.Expect(&prefs, pref_name_two, &expected_new_pref_value2); |
| 122 registrar.Add(pref_name, &obs2); | 124 registrar.Add(pref_name_two, &obs2); |
|
Mattias Nissler (ping if slow)
2012/11/07 16:02:24
I think we should just declare a second registrar
Jói
2012/11/08 11:03:14
Done.
| |
| 123 // This should fire the checks in obs and obs2. | 125 // This should fire the checks in obs and obs2. |
| 124 prefs.SetString(pref_name, new_pref_value2); | 126 prefs.SetString(pref_name, new_pref_value2); |
| 127 prefs.SetString(pref_name_two, new_pref_value2); | |
| 125 Mock::VerifyAndClearExpectations(&obs); | 128 Mock::VerifyAndClearExpectations(&obs); |
| 126 Mock::VerifyAndClearExpectations(&obs2); | 129 Mock::VerifyAndClearExpectations(&obs2); |
| 127 | 130 |
| 128 // Set a recommended value. | 131 // Set a recommended value. |
| 129 const StringValue recommended_pref_value("http://www.gmail.com/"); | 132 const StringValue recommended_pref_value("http://www.gmail.com/"); |
| 130 obs.Expect(&prefs, pref_name, &expected_new_pref_value2); | 133 obs.Expect(&prefs, pref_name, &expected_new_pref_value2); |
| 131 obs2.Expect(&prefs, pref_name, &expected_new_pref_value2); | 134 obs2.Expect(&prefs, pref_name_two, &expected_new_pref_value2); |
| 132 // This should fire the checks in obs and obs2 but with an unchanged value | 135 // 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. | 136 // as the recommended value is being overridden by the user-set value. |
| 134 prefs.SetRecommendedPref(pref_name, recommended_pref_value.DeepCopy()); | 137 prefs.SetRecommendedPref(pref_name, recommended_pref_value.DeepCopy()); |
| 138 prefs.SetRecommendedPref(pref_name_two, recommended_pref_value.DeepCopy()); | |
| 135 Mock::VerifyAndClearExpectations(&obs); | 139 Mock::VerifyAndClearExpectations(&obs); |
| 136 Mock::VerifyAndClearExpectations(&obs2); | 140 Mock::VerifyAndClearExpectations(&obs2); |
| 137 | 141 |
| 138 // Make sure obs2 still works after removing obs. | 142 // Make sure obs2 still works after removing obs. |
| 139 registrar.Remove(pref_name, &obs); | 143 registrar.Remove(pref_name); |
| 140 EXPECT_CALL(obs, OnPreferenceChanged(_, _)).Times(0); | 144 EXPECT_CALL(obs, OnPreferenceChanged(_, _)).Times(0); |
| 141 obs2.Expect(&prefs, pref_name, &expected_new_pref_value); | 145 obs2.Expect(&prefs, pref_name_two, &expected_new_pref_value); |
| 142 // This should only fire the observer in obs2. | 146 // This should only fire the observer in obs2. |
| 143 prefs.SetString(pref_name, new_pref_value); | 147 prefs.SetString(pref_name_two, new_pref_value); |
| 144 Mock::VerifyAndClearExpectations(&obs); | 148 Mock::VerifyAndClearExpectations(&obs); |
| 145 Mock::VerifyAndClearExpectations(&obs2); | 149 Mock::VerifyAndClearExpectations(&obs2); |
| 146 } | 150 } |
| 147 | 151 |
| 148 // Make sure that if a preference changes type, so the wrong type is stored in | 152 // 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. | 153 // the user pref file, it uses the correct fallback value instead. |
| 150 TEST(PrefServiceTest, GetValueChangedType) { | 154 TEST(PrefServiceTest, GetValueChangedType) { |
| 151 const int kTestValue = 10; | 155 const int kTestValue = 10; |
| 152 TestingPrefService prefs; | 156 TestingPrefService prefs; |
| 153 prefs.RegisterIntegerPref(prefs::kStabilityLaunchCount, kTestValue); | 157 prefs.RegisterIntegerPref(prefs::kStabilityLaunchCount, kTestValue); |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 const char kDefaultFont[] = "Times"; | 495 const char kDefaultFont[] = "Times"; |
| 492 #elif defined(OS_CHROMEOS) | 496 #elif defined(OS_CHROMEOS) |
| 493 const char kDefaultFont[] = "Tinos"; | 497 const char kDefaultFont[] = "Tinos"; |
| 494 #else | 498 #else |
| 495 const char kDefaultFont[] = "Times New Roman"; | 499 const char kDefaultFont[] = "Times New Roman"; |
| 496 #endif | 500 #endif |
| 497 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), | 501 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), |
| 498 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); | 502 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); |
| 499 EXPECT_TRUE(webkit_prefs.javascript_enabled); | 503 EXPECT_TRUE(webkit_prefs.javascript_enabled); |
| 500 } | 504 } |
| OLD | NEW |