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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 const StringValue expected_new_pref_value2(new_pref_value2); | 118 const StringValue expected_new_pref_value2(new_pref_value2); |
119 PrefObserverMock obs2; | 119 PrefObserverMock obs2; |
120 obs.Expect(&prefs, pref_name, &expected_new_pref_value2); | 120 obs.Expect(&prefs, pref_name, &expected_new_pref_value2); |
121 obs2.Expect(&prefs, pref_name, &expected_new_pref_value2); | 121 obs2.Expect(&prefs, pref_name, &expected_new_pref_value2); |
122 registrar.Add(pref_name, &obs2); | 122 registrar.Add(pref_name, &obs2); |
123 // This should fire the checks in obs and obs2. | 123 // This should fire the checks in obs and obs2. |
124 prefs.SetString(pref_name, new_pref_value2); | 124 prefs.SetString(pref_name, new_pref_value2); |
125 Mock::VerifyAndClearExpectations(&obs); | 125 Mock::VerifyAndClearExpectations(&obs); |
126 Mock::VerifyAndClearExpectations(&obs2); | 126 Mock::VerifyAndClearExpectations(&obs2); |
127 | 127 |
| 128 // Set a recommended value. |
| 129 const StringValue recommended_pref_value("http://www.gmail.com/"); |
| 130 obs.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 |
| 133 // as the recommended value is being overridden by the user-set value. |
| 134 prefs.SetRecommendedPref(pref_name, recommended_pref_value.DeepCopy()); |
| 135 Mock::VerifyAndClearExpectations(&obs); |
| 136 Mock::VerifyAndClearExpectations(&obs2); |
| 137 |
128 // Make sure obs2 still works after removing obs. | 138 // Make sure obs2 still works after removing obs. |
129 registrar.Remove(pref_name, &obs); | 139 registrar.Remove(pref_name, &obs); |
130 EXPECT_CALL(obs, Observe(_, _, _)).Times(0); | 140 EXPECT_CALL(obs, Observe(_, _, _)).Times(0); |
131 obs2.Expect(&prefs, pref_name, &expected_new_pref_value); | 141 obs2.Expect(&prefs, pref_name, &expected_new_pref_value); |
132 // This should only fire the observer in obs2. | 142 // This should only fire the observer in obs2. |
133 prefs.SetString(pref_name, new_pref_value); | 143 prefs.SetString(pref_name, new_pref_value); |
134 Mock::VerifyAndClearExpectations(&obs); | 144 Mock::VerifyAndClearExpectations(&obs); |
135 Mock::VerifyAndClearExpectations(&obs2); | 145 Mock::VerifyAndClearExpectations(&obs2); |
136 } | 146 } |
137 | 147 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 pref = prefs.FindPreference(prefs::kCloudPrintProxyEnabled); | 190 pref = prefs.FindPreference(prefs::kCloudPrintProxyEnabled); |
181 ASSERT_TRUE(pref); | 191 ASSERT_TRUE(pref); |
182 value = pref->GetValue(); | 192 value = pref->GetValue(); |
183 ASSERT_TRUE(value); | 193 ASSERT_TRUE(value); |
184 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType()); | 194 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType()); |
185 actual_bool_value = false; | 195 actual_bool_value = false; |
186 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value)); | 196 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value)); |
187 EXPECT_TRUE(actual_bool_value); | 197 EXPECT_TRUE(actual_bool_value); |
188 } | 198 } |
189 | 199 |
| 200 TEST(PrefServiceTest, GetValueAndGetRecommendedValue) { |
| 201 const int kDefaultValue = 5; |
| 202 const int kUserValue = 10; |
| 203 const int kRecommendedValue = 15; |
| 204 TestingPrefService prefs; |
| 205 prefs.RegisterIntegerPref(prefs::kStabilityLaunchCount, kDefaultValue); |
| 206 |
| 207 // Create pref with a default value only. |
| 208 const PrefService::Preference* pref = |
| 209 prefs.FindPreference(prefs::kStabilityLaunchCount); |
| 210 ASSERT_TRUE(pref); |
| 211 |
| 212 // Check that GetValue() returns the default value. |
| 213 const Value* value = pref->GetValue(); |
| 214 ASSERT_TRUE(value); |
| 215 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); |
| 216 int actual_int_value = -1; |
| 217 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
| 218 EXPECT_EQ(kDefaultValue, actual_int_value); |
| 219 |
| 220 // Check that GetRecommendedValue() returns no value. |
| 221 value = pref->GetRecommendedValue(); |
| 222 ASSERT_FALSE(value); |
| 223 |
| 224 // Set a user-set value. |
| 225 prefs.SetUserPref(prefs::kStabilityLaunchCount, |
| 226 Value::CreateIntegerValue(kUserValue)); |
| 227 |
| 228 // Check that GetValue() returns the user-set value. |
| 229 value = pref->GetValue(); |
| 230 ASSERT_TRUE(value); |
| 231 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); |
| 232 actual_int_value = -1; |
| 233 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
| 234 EXPECT_EQ(kUserValue, actual_int_value); |
| 235 |
| 236 // Check that GetRecommendedValue() returns no value. |
| 237 value = pref->GetRecommendedValue(); |
| 238 ASSERT_FALSE(value); |
| 239 |
| 240 // Set a recommended value. |
| 241 prefs.SetRecommendedPref(prefs::kStabilityLaunchCount, |
| 242 Value::CreateIntegerValue(kRecommendedValue)); |
| 243 |
| 244 // Check that GetValue() returns the user-set value. |
| 245 value = pref->GetValue(); |
| 246 ASSERT_TRUE(value); |
| 247 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); |
| 248 actual_int_value = -1; |
| 249 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
| 250 EXPECT_EQ(kUserValue, actual_int_value); |
| 251 |
| 252 // Check that GetRecommendedValue() returns the recommended value. |
| 253 value = pref->GetRecommendedValue(); |
| 254 ASSERT_TRUE(value); |
| 255 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); |
| 256 actual_int_value = -1; |
| 257 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
| 258 EXPECT_EQ(kRecommendedValue, actual_int_value); |
| 259 |
| 260 // Remove the user-set value. |
| 261 prefs.RemoveUserPref(prefs::kStabilityLaunchCount); |
| 262 |
| 263 // Check that GetValue() returns the recommended value. |
| 264 value = pref->GetValue(); |
| 265 ASSERT_TRUE(value); |
| 266 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); |
| 267 actual_int_value = -1; |
| 268 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
| 269 EXPECT_EQ(kRecommendedValue, actual_int_value); |
| 270 |
| 271 // Check that GetRecommendedValue() returns the recommended value. |
| 272 value = pref->GetRecommendedValue(); |
| 273 ASSERT_TRUE(value); |
| 274 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); |
| 275 actual_int_value = -1; |
| 276 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
| 277 EXPECT_EQ(kRecommendedValue, actual_int_value); |
| 278 } |
| 279 |
190 class PrefServiceUserFilePrefsTest : public testing::Test { | 280 class PrefServiceUserFilePrefsTest : public testing::Test { |
191 protected: | 281 protected: |
192 virtual void SetUp() { | 282 virtual void SetUp() { |
193 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 283 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
194 | 284 |
195 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); | 285 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); |
196 data_dir_ = data_dir_.AppendASCII("pref_service"); | 286 data_dir_ = data_dir_.AppendASCII("pref_service"); |
197 ASSERT_TRUE(file_util::PathExists(data_dir_)); | 287 ASSERT_TRUE(file_util::PathExists(data_dir_)); |
198 } | 288 } |
199 | 289 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 const char kDefaultFont[] = "Times"; | 491 const char kDefaultFont[] = "Times"; |
402 #elif defined(OS_CHROMEOS) | 492 #elif defined(OS_CHROMEOS) |
403 const char kDefaultFont[] = "Tinos"; | 493 const char kDefaultFont[] = "Tinos"; |
404 #else | 494 #else |
405 const char kDefaultFont[] = "Times New Roman"; | 495 const char kDefaultFont[] = "Times New Roman"; |
406 #endif | 496 #endif |
407 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), | 497 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), |
408 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); | 498 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); |
409 EXPECT_TRUE(webkit_prefs.javascript_enabled); | 499 EXPECT_TRUE(webkit_prefs.javascript_enabled); |
410 } | 500 } |
OLD | NEW |