| OLD | NEW |
| 1 // Copyright (c) 2011 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 10 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 // Set a value and make sure we have a path. | 104 // Set a value and make sure we have a path. |
| 105 prefs.SetString(path, "blah"); | 105 prefs.SetString(path, "blah"); |
| 106 EXPECT_TRUE(prefs.HasPrefPath(path)); | 106 EXPECT_TRUE(prefs.HasPrefPath(path)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 TEST(PrefServiceTest, Observers) { | 109 TEST(PrefServiceTest, Observers) { |
| 110 const char pref_name[] = "homepage"; | 110 const char pref_name[] = "homepage"; |
| 111 | 111 |
| 112 TestingPrefService prefs; | 112 TestingPrefService prefs; |
| 113 prefs.SetUserPref(pref_name, Value::CreateStringValue("http://www.cnn.com")); | 113 prefs.SetUserPref(pref_name, base::StringValue::New("http://www.cnn.com")); |
| 114 prefs.RegisterStringPref(pref_name, std::string()); | 114 prefs.RegisterStringPref(pref_name, std::string()); |
| 115 | 115 |
| 116 const char new_pref_value[] = "http://www.google.com/"; | 116 const char new_pref_value[] = "http://www.google.com/"; |
| 117 const StringValue expected_new_pref_value(new_pref_value); | 117 const StringValue expected_new_pref_value(new_pref_value); |
| 118 PrefObserverMock obs; | 118 PrefObserverMock obs; |
| 119 PrefChangeRegistrar registrar; | 119 PrefChangeRegistrar registrar; |
| 120 registrar.Init(&prefs); | 120 registrar.Init(&prefs); |
| 121 registrar.Add(pref_name, &obs); | 121 registrar.Add(pref_name, &obs); |
| 122 | 122 |
| 123 // This should fire the checks in PrefObserverMock::Observe. | 123 // This should fire the checks in PrefObserverMock::Observe. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 149 | 149 |
| 150 // Make sure that if a preference changes type, so the wrong type is stored in | 150 // Make sure that if a preference changes type, so the wrong type is stored in |
| 151 // the user pref file, it uses the correct fallback value instead. | 151 // the user pref file, it uses the correct fallback value instead. |
| 152 TEST(PrefServiceTest, GetValueChangedType) { | 152 TEST(PrefServiceTest, GetValueChangedType) { |
| 153 const int kTestValue = 10; | 153 const int kTestValue = 10; |
| 154 TestingPrefService prefs; | 154 TestingPrefService prefs; |
| 155 prefs.RegisterIntegerPref(prefs::kStabilityLaunchCount, kTestValue); | 155 prefs.RegisterIntegerPref(prefs::kStabilityLaunchCount, kTestValue); |
| 156 | 156 |
| 157 // Check falling back to a recommended value. | 157 // Check falling back to a recommended value. |
| 158 prefs.SetUserPref(prefs::kStabilityLaunchCount, | 158 prefs.SetUserPref(prefs::kStabilityLaunchCount, |
| 159 Value::CreateStringValue("not an integer")); | 159 base::StringValue::New("not an integer")); |
| 160 const PrefService::Preference* pref = | 160 const PrefService::Preference* pref = |
| 161 prefs.FindPreference(prefs::kStabilityLaunchCount); | 161 prefs.FindPreference(prefs::kStabilityLaunchCount); |
| 162 ASSERT_TRUE(pref); | 162 ASSERT_TRUE(pref); |
| 163 const Value* value = pref->GetValue(); | 163 const Value* value = pref->GetValue(); |
| 164 ASSERT_TRUE(value); | 164 ASSERT_TRUE(value); |
| 165 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | 165 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); |
| 166 int actual_int_value = -1; | 166 int actual_int_value = -1; |
| 167 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | 167 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
| 168 EXPECT_EQ(kTestValue, actual_int_value); | 168 EXPECT_EQ(kTestValue, actual_int_value); |
| 169 } | 169 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 prefs_.RegisterListPref(kName); | 234 prefs_.RegisterListPref(kName); |
| 235 PrefChangeRegistrar registrar; | 235 PrefChangeRegistrar registrar; |
| 236 registrar.Init(&prefs_); | 236 registrar.Init(&prefs_); |
| 237 registrar.Add(kName, &observer_); | 237 registrar.Add(kName, &observer_); |
| 238 | 238 |
| 239 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); | 239 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); |
| 240 prefs_.RemoveUserPref(kName); | 240 prefs_.RemoveUserPref(kName); |
| 241 Mock::VerifyAndClearExpectations(&observer_); | 241 Mock::VerifyAndClearExpectations(&observer_); |
| 242 | 242 |
| 243 ListValue new_value; | 243 ListValue new_value; |
| 244 new_value.Append(Value::CreateStringValue(kValue)); | 244 new_value.Append(base::StringValue::New(kValue)); |
| 245 observer_.Expect(&prefs_, kName, &new_value); | 245 observer_.Expect(&prefs_, kName, &new_value); |
| 246 prefs_.Set(kName, new_value); | 246 prefs_.Set(kName, new_value); |
| 247 Mock::VerifyAndClearExpectations(&observer_); | 247 Mock::VerifyAndClearExpectations(&observer_); |
| 248 | 248 |
| 249 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); | 249 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); |
| 250 prefs_.Set(kName, new_value); | 250 prefs_.Set(kName, new_value); |
| 251 Mock::VerifyAndClearExpectations(&observer_); | 251 Mock::VerifyAndClearExpectations(&observer_); |
| 252 | 252 |
| 253 ListValue empty; | 253 ListValue empty; |
| 254 observer_.Expect(&prefs_, kName, &empty); | 254 observer_.Expect(&prefs_, kName, &empty); |
| 255 prefs_.Set(kName, empty); | 255 prefs_.Set(kName, empty); |
| 256 Mock::VerifyAndClearExpectations(&observer_); | 256 Mock::VerifyAndClearExpectations(&observer_); |
| 257 } | 257 } |
| OLD | NEW |