OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "app/test/data/resource.h" | 7 #include "app/test/data/resource.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 11 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 // Make sure obs2 still works after removing obs. | 141 // Make sure obs2 still works after removing obs. |
142 registrar.Remove(pref_name, &obs); | 142 registrar.Remove(pref_name, &obs); |
143 EXPECT_CALL(obs, Observe(_, _, _)).Times(0); | 143 EXPECT_CALL(obs, Observe(_, _, _)).Times(0); |
144 obs2.Expect(&prefs, pref_name, &expected_new_pref_value); | 144 obs2.Expect(&prefs, pref_name, &expected_new_pref_value); |
145 // This should only fire the observer in obs2. | 145 // This should only fire the observer in obs2. |
146 prefs.SetString(pref_name, new_pref_value); | 146 prefs.SetString(pref_name, new_pref_value); |
147 Mock::VerifyAndClearExpectations(&obs); | 147 Mock::VerifyAndClearExpectations(&obs); |
148 Mock::VerifyAndClearExpectations(&obs2); | 148 Mock::VerifyAndClearExpectations(&obs2); |
149 } | 149 } |
150 | 150 |
151 // Make sure that if a preference changes type, so the wrong type is stored in | |
152 // the user pref file, it uses the correct fallback value instead. | |
153 TEST(PrefServiceTest, GetValueChangedType) { | |
154 const int kTestValue = 10; | |
155 TestingPrefService prefs; | |
156 prefs.RegisterIntegerPref(prefs::kStabilityLaunchCount, kTestValue); | |
157 | |
158 // Check falling back to a recommended value. | |
159 prefs.SetUserPref(prefs::kStabilityLaunchCount, | |
160 Value::CreateStringValue("not an integer")); | |
danno
2011/01/14 13:05:09
nit: indent
battre
2011/01/20 17:59:29
Done.
| |
161 const PrefService::Preference* pref = | |
162 prefs.FindPreference(prefs::kStabilityLaunchCount); | |
163 ASSERT_TRUE(pref); | |
164 const Value* value = pref->GetValue(); | |
165 ASSERT_TRUE(value); | |
166 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | |
167 int actual_int_value = -1; | |
168 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | |
169 EXPECT_EQ(kTestValue, actual_int_value); | |
170 } | |
171 | |
151 TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineOptions) { | 172 TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineOptions) { |
152 CommandLine command_line(CommandLine::NO_PROGRAM); | 173 CommandLine command_line(CommandLine::NO_PROGRAM); |
153 command_line.AppendSwitchASCII(switches::kProxyBypassList, "123"); | 174 command_line.AppendSwitchASCII(switches::kProxyBypassList, "123"); |
154 command_line.AppendSwitchASCII(switches::kProxyServer, "789"); | 175 command_line.AppendSwitchASCII(switches::kProxyServer, "789"); |
155 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( | 176 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( |
156 new policy::MockConfigurationPolicyProvider()); | 177 new policy::MockConfigurationPolicyProvider()); |
157 Value* mode_value = Value::CreateIntegerValue( | 178 Value* mode_value = Value::CreateIntegerValue( |
158 policy::kPolicyManuallyConfiguredProxyMode); | 179 policy::kPolicyManuallyConfiguredProxyMode); |
159 provider->AddPolicy(policy::kPolicyProxyMode, mode_value); | 180 provider->AddPolicy(policy::kPolicyProxyMode, mode_value); |
160 provider->AddPolicy(policy::kPolicyProxyBypassList, | 181 provider->AddPolicy(policy::kPolicyProxyBypassList, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyServer)); | 310 EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyServer)); |
290 EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyPacUrl)); | 311 EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyPacUrl)); |
291 EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyBypassList)); | 312 EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyBypassList)); |
292 } | 313 } |
293 | 314 |
294 class PrefServiceSetValueTest : public testing::Test { | 315 class PrefServiceSetValueTest : public testing::Test { |
295 protected: | 316 protected: |
296 static const char kName[]; | 317 static const char kName[]; |
297 static const char kValue[]; | 318 static const char kValue[]; |
298 | 319 |
299 PrefServiceSetValueTest() | |
300 : null_value_(Value::CreateNullValue()) {} | |
301 | |
302 TestingPrefService prefs_; | 320 TestingPrefService prefs_; |
303 scoped_ptr<Value> null_value_; | |
304 PrefObserverMock observer_; | 321 PrefObserverMock observer_; |
305 }; | 322 }; |
306 | 323 |
307 const char PrefServiceSetValueTest::kName[] = "name"; | 324 const char PrefServiceSetValueTest::kName[] = "name"; |
308 const char PrefServiceSetValueTest::kValue[] = "value"; | 325 const char PrefServiceSetValueTest::kValue[] = "value"; |
309 | 326 |
310 TEST_F(PrefServiceSetValueTest, SetStringValue) { | 327 TEST_F(PrefServiceSetValueTest, SetStringValue) { |
311 const char default_string[] = "default"; | 328 const char default_string[] = "default"; |
312 const StringValue default_value(default_string); | 329 const StringValue default_value(default_string); |
313 prefs_.RegisterStringPref(kName, default_string); | 330 prefs_.RegisterStringPref(kName, default_string); |
(...skipping 16 matching lines...) Expand all Loading... | |
330 prefs_.Set(kName, new_value); | 347 prefs_.Set(kName, new_value); |
331 Mock::VerifyAndClearExpectations(&observer_); | 348 Mock::VerifyAndClearExpectations(&observer_); |
332 } | 349 } |
333 | 350 |
334 TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { | 351 TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { |
335 prefs_.RegisterDictionaryPref(kName); | 352 prefs_.RegisterDictionaryPref(kName); |
336 PrefChangeRegistrar registrar; | 353 PrefChangeRegistrar registrar; |
337 registrar.Init(&prefs_); | 354 registrar.Init(&prefs_); |
338 registrar.Add(kName, &observer_); | 355 registrar.Add(kName, &observer_); |
339 | 356 |
340 // Dictionary values are special: setting one to NULL is the same as clearing | |
341 // the user value, allowing the NULL default to take (or keep) control. | |
342 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); | 357 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); |
343 prefs_.Set(kName, *null_value_); | 358 prefs_.RemoveUserPref(kName); |
344 Mock::VerifyAndClearExpectations(&observer_); | 359 Mock::VerifyAndClearExpectations(&observer_); |
345 | 360 |
346 DictionaryValue new_value; | 361 DictionaryValue new_value; |
347 new_value.SetString(kName, kValue); | 362 new_value.SetString(kName, kValue); |
348 observer_.Expect(&prefs_, kName, &new_value); | 363 observer_.Expect(&prefs_, kName, &new_value); |
349 prefs_.Set(kName, new_value); | 364 prefs_.Set(kName, new_value); |
350 Mock::VerifyAndClearExpectations(&observer_); | 365 Mock::VerifyAndClearExpectations(&observer_); |
351 | 366 |
352 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); | 367 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); |
353 prefs_.Set(kName, new_value); | 368 prefs_.Set(kName, new_value); |
354 Mock::VerifyAndClearExpectations(&observer_); | 369 Mock::VerifyAndClearExpectations(&observer_); |
355 | 370 |
356 observer_.Expect(&prefs_, kName, null_value_.get()); | 371 DictionaryValue empty; |
357 prefs_.Set(kName, *null_value_); | 372 observer_.Expect(&prefs_, kName, &empty); |
373 prefs_.Set(kName, empty); | |
358 Mock::VerifyAndClearExpectations(&observer_); | 374 Mock::VerifyAndClearExpectations(&observer_); |
359 } | 375 } |
360 | 376 |
361 TEST_F(PrefServiceSetValueTest, SetListValue) { | 377 TEST_F(PrefServiceSetValueTest, SetListValue) { |
362 prefs_.RegisterListPref(kName); | 378 prefs_.RegisterListPref(kName); |
363 PrefChangeRegistrar registrar; | 379 PrefChangeRegistrar registrar; |
364 registrar.Init(&prefs_); | 380 registrar.Init(&prefs_); |
365 registrar.Add(kName, &observer_); | 381 registrar.Add(kName, &observer_); |
366 | 382 |
367 // List values are special: setting one to NULL is the same as clearing the | |
368 // user value, allowing the NULL default to take (or keep) control. | |
369 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); | 383 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); |
370 prefs_.Set(kName, *null_value_); | 384 prefs_.RemoveUserPref(kName); |
371 Mock::VerifyAndClearExpectations(&observer_); | 385 Mock::VerifyAndClearExpectations(&observer_); |
372 | 386 |
373 ListValue new_value; | 387 ListValue new_value; |
374 new_value.Append(Value::CreateStringValue(kValue)); | 388 new_value.Append(Value::CreateStringValue(kValue)); |
375 observer_.Expect(&prefs_, kName, &new_value); | 389 observer_.Expect(&prefs_, kName, &new_value); |
376 prefs_.Set(kName, new_value); | 390 prefs_.Set(kName, new_value); |
377 Mock::VerifyAndClearExpectations(&observer_); | 391 Mock::VerifyAndClearExpectations(&observer_); |
378 | 392 |
379 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); | 393 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); |
380 prefs_.Set(kName, new_value); | 394 prefs_.Set(kName, new_value); |
381 Mock::VerifyAndClearExpectations(&observer_); | 395 Mock::VerifyAndClearExpectations(&observer_); |
382 | 396 |
383 observer_.Expect(&prefs_, kName, null_value_.get()); | 397 ListValue empty; |
384 prefs_.Set(kName, *null_value_); | 398 observer_.Expect(&prefs_, kName, &empty); |
399 prefs_.Set(kName, empty); | |
385 Mock::VerifyAndClearExpectations(&observer_); | 400 Mock::VerifyAndClearExpectations(&observer_); |
386 } | 401 } |
OLD | NEW |