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/prefs/json_pref_store.h" | 7 #include "base/prefs/json_pref_store.h" |
8 #include "base/prefs/mock_pref_change_callback.h" | 8 #include "base/prefs/mock_pref_change_callback.h" |
9 #include "base/prefs/pref_change_registrar.h" | 9 #include "base/prefs/pref_change_registrar.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 const char pref_name[] = "homepage"; | 26 const char pref_name[] = "homepage"; |
27 prefs.registry()->RegisterStringPref(pref_name, std::string()); | 27 prefs.registry()->RegisterStringPref(pref_name, std::string()); |
28 | 28 |
29 const char new_pref_value[] = "http://www.google.com/"; | 29 const char new_pref_value[] = "http://www.google.com/"; |
30 MockPrefChangeCallback obs(&prefs); | 30 MockPrefChangeCallback obs(&prefs); |
31 PrefChangeRegistrar registrar; | 31 PrefChangeRegistrar registrar; |
32 registrar.Init(&prefs); | 32 registrar.Init(&prefs); |
33 registrar.Add(pref_name, obs.GetCallback()); | 33 registrar.Add(pref_name, obs.GetCallback()); |
34 | 34 |
35 // This should fire the checks in MockPrefChangeCallback::OnPreferenceChanged. | 35 // This should fire the checks in MockPrefChangeCallback::OnPreferenceChanged. |
36 const StringValue expected_value(new_pref_value); | 36 const base::StringValue expected_value(new_pref_value); |
37 obs.Expect(pref_name, &expected_value); | 37 obs.Expect(pref_name, &expected_value); |
38 prefs.SetString(pref_name, new_pref_value); | 38 prefs.SetString(pref_name, new_pref_value); |
39 Mock::VerifyAndClearExpectations(&obs); | 39 Mock::VerifyAndClearExpectations(&obs); |
40 | 40 |
41 // Setting the pref to the same value should not set the pref value a second | 41 // Setting the pref to the same value should not set the pref value a second |
42 // time. | 42 // time. |
43 EXPECT_CALL(obs, OnPreferenceChanged(_)).Times(0); | 43 EXPECT_CALL(obs, OnPreferenceChanged(_)).Times(0); |
44 prefs.SetString(pref_name, new_pref_value); | 44 prefs.SetString(pref_name, new_pref_value); |
45 Mock::VerifyAndClearExpectations(&obs); | 45 Mock::VerifyAndClearExpectations(&obs); |
46 | 46 |
47 // Clearing the pref should cause the pref to fire. | 47 // Clearing the pref should cause the pref to fire. |
48 const StringValue expected_default_value((std::string())); | 48 const base::StringValue expected_default_value((std::string())); |
49 obs.Expect(pref_name, &expected_default_value); | 49 obs.Expect(pref_name, &expected_default_value); |
50 prefs.ClearPref(pref_name); | 50 prefs.ClearPref(pref_name); |
51 Mock::VerifyAndClearExpectations(&obs); | 51 Mock::VerifyAndClearExpectations(&obs); |
52 | 52 |
53 // Clearing the pref again should not cause the pref to fire. | 53 // Clearing the pref again should not cause the pref to fire. |
54 EXPECT_CALL(obs, OnPreferenceChanged(_)).Times(0); | 54 EXPECT_CALL(obs, OnPreferenceChanged(_)).Times(0); |
55 prefs.ClearPref(pref_name); | 55 prefs.ClearPref(pref_name); |
56 Mock::VerifyAndClearExpectations(&obs); | 56 Mock::VerifyAndClearExpectations(&obs); |
57 } | 57 } |
58 | 58 |
(...skipping 12 matching lines...) Expand all Loading... |
71 | 71 |
72 // Set a value and make sure we have a path. | 72 // Set a value and make sure we have a path. |
73 prefs.SetString(path, "blah"); | 73 prefs.SetString(path, "blah"); |
74 EXPECT_TRUE(prefs.HasPrefPath(path)); | 74 EXPECT_TRUE(prefs.HasPrefPath(path)); |
75 } | 75 } |
76 | 76 |
77 TEST(PrefServiceTest, Observers) { | 77 TEST(PrefServiceTest, Observers) { |
78 const char pref_name[] = "homepage"; | 78 const char pref_name[] = "homepage"; |
79 | 79 |
80 TestingPrefServiceSimple prefs; | 80 TestingPrefServiceSimple prefs; |
81 prefs.SetUserPref(pref_name, Value::CreateStringValue("http://www.cnn.com")); | 81 prefs.SetUserPref(pref_name, |
| 82 base::Value::CreateStringValue("http://www.cnn.com")); |
82 prefs.registry()->RegisterStringPref(pref_name, std::string()); | 83 prefs.registry()->RegisterStringPref(pref_name, std::string()); |
83 | 84 |
84 const char new_pref_value[] = "http://www.google.com/"; | 85 const char new_pref_value[] = "http://www.google.com/"; |
85 const StringValue expected_new_pref_value(new_pref_value); | 86 const base::StringValue expected_new_pref_value(new_pref_value); |
86 MockPrefChangeCallback obs(&prefs); | 87 MockPrefChangeCallback obs(&prefs); |
87 PrefChangeRegistrar registrar; | 88 PrefChangeRegistrar registrar; |
88 registrar.Init(&prefs); | 89 registrar.Init(&prefs); |
89 registrar.Add(pref_name, obs.GetCallback()); | 90 registrar.Add(pref_name, obs.GetCallback()); |
90 | 91 |
91 PrefChangeRegistrar registrar_two; | 92 PrefChangeRegistrar registrar_two; |
92 registrar_two.Init(&prefs); | 93 registrar_two.Init(&prefs); |
93 | 94 |
94 // This should fire the checks in MockPrefChangeCallback::OnPreferenceChanged. | 95 // This should fire the checks in MockPrefChangeCallback::OnPreferenceChanged. |
95 obs.Expect(pref_name, &expected_new_pref_value); | 96 obs.Expect(pref_name, &expected_new_pref_value); |
96 prefs.SetString(pref_name, new_pref_value); | 97 prefs.SetString(pref_name, new_pref_value); |
97 Mock::VerifyAndClearExpectations(&obs); | 98 Mock::VerifyAndClearExpectations(&obs); |
98 | 99 |
99 // Now try adding a second pref observer. | 100 // Now try adding a second pref observer. |
100 const char new_pref_value2[] = "http://www.youtube.com/"; | 101 const char new_pref_value2[] = "http://www.youtube.com/"; |
101 const StringValue expected_new_pref_value2(new_pref_value2); | 102 const base::StringValue expected_new_pref_value2(new_pref_value2); |
102 MockPrefChangeCallback obs2(&prefs); | 103 MockPrefChangeCallback obs2(&prefs); |
103 obs.Expect(pref_name, &expected_new_pref_value2); | 104 obs.Expect(pref_name, &expected_new_pref_value2); |
104 obs2.Expect(pref_name, &expected_new_pref_value2); | 105 obs2.Expect(pref_name, &expected_new_pref_value2); |
105 registrar_two.Add(pref_name, obs2.GetCallback()); | 106 registrar_two.Add(pref_name, obs2.GetCallback()); |
106 // This should fire the checks in obs and obs2. | 107 // This should fire the checks in obs and obs2. |
107 prefs.SetString(pref_name, new_pref_value2); | 108 prefs.SetString(pref_name, new_pref_value2); |
108 Mock::VerifyAndClearExpectations(&obs); | 109 Mock::VerifyAndClearExpectations(&obs); |
109 Mock::VerifyAndClearExpectations(&obs2); | 110 Mock::VerifyAndClearExpectations(&obs2); |
110 | 111 |
111 // Set a recommended value. | 112 // Set a recommended value. |
112 const StringValue recommended_pref_value("http://www.gmail.com/"); | 113 const base::StringValue recommended_pref_value("http://www.gmail.com/"); |
113 obs.Expect(pref_name, &expected_new_pref_value2); | 114 obs.Expect(pref_name, &expected_new_pref_value2); |
114 obs2.Expect(pref_name, &expected_new_pref_value2); | 115 obs2.Expect(pref_name, &expected_new_pref_value2); |
115 // This should fire the checks in obs and obs2 but with an unchanged value | 116 // This should fire the checks in obs and obs2 but with an unchanged value |
116 // as the recommended value is being overridden by the user-set value. | 117 // as the recommended value is being overridden by the user-set value. |
117 prefs.SetRecommendedPref(pref_name, recommended_pref_value.DeepCopy()); | 118 prefs.SetRecommendedPref(pref_name, recommended_pref_value.DeepCopy()); |
118 Mock::VerifyAndClearExpectations(&obs); | 119 Mock::VerifyAndClearExpectations(&obs); |
119 Mock::VerifyAndClearExpectations(&obs2); | 120 Mock::VerifyAndClearExpectations(&obs2); |
120 | 121 |
121 // Make sure obs2 still works after removing obs. | 122 // Make sure obs2 still works after removing obs. |
122 registrar.Remove(pref_name); | 123 registrar.Remove(pref_name); |
123 EXPECT_CALL(obs, OnPreferenceChanged(_)).Times(0); | 124 EXPECT_CALL(obs, OnPreferenceChanged(_)).Times(0); |
124 obs2.Expect(pref_name, &expected_new_pref_value); | 125 obs2.Expect(pref_name, &expected_new_pref_value); |
125 // This should only fire the observer in obs2. | 126 // This should only fire the observer in obs2. |
126 prefs.SetString(pref_name, new_pref_value); | 127 prefs.SetString(pref_name, new_pref_value); |
127 Mock::VerifyAndClearExpectations(&obs); | 128 Mock::VerifyAndClearExpectations(&obs); |
128 Mock::VerifyAndClearExpectations(&obs2); | 129 Mock::VerifyAndClearExpectations(&obs2); |
129 } | 130 } |
130 | 131 |
131 // Make sure that if a preference changes type, so the wrong type is stored in | 132 // Make sure that if a preference changes type, so the wrong type is stored in |
132 // the user pref file, it uses the correct fallback value instead. | 133 // the user pref file, it uses the correct fallback value instead. |
133 TEST(PrefServiceTest, GetValueChangedType) { | 134 TEST(PrefServiceTest, GetValueChangedType) { |
134 const int kTestValue = 10; | 135 const int kTestValue = 10; |
135 TestingPrefServiceSimple prefs; | 136 TestingPrefServiceSimple prefs; |
136 prefs.registry()->RegisterIntegerPref(kPrefName, kTestValue); | 137 prefs.registry()->RegisterIntegerPref(kPrefName, kTestValue); |
137 | 138 |
138 // Check falling back to a recommended value. | 139 // Check falling back to a recommended value. |
139 prefs.SetUserPref(kPrefName, Value::CreateStringValue("not an integer")); | 140 prefs.SetUserPref(kPrefName, |
| 141 base::Value::CreateStringValue("not an integer")); |
140 const PrefService::Preference* pref = prefs.FindPreference(kPrefName); | 142 const PrefService::Preference* pref = prefs.FindPreference(kPrefName); |
141 ASSERT_TRUE(pref); | 143 ASSERT_TRUE(pref); |
142 const Value* value = pref->GetValue(); | 144 const base::Value* value = pref->GetValue(); |
143 ASSERT_TRUE(value); | 145 ASSERT_TRUE(value); |
144 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | 146 EXPECT_EQ(base::Value::TYPE_INTEGER, value->GetType()); |
145 int actual_int_value = -1; | 147 int actual_int_value = -1; |
146 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | 148 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
147 EXPECT_EQ(kTestValue, actual_int_value); | 149 EXPECT_EQ(kTestValue, actual_int_value); |
148 } | 150 } |
149 | 151 |
150 TEST(PrefServiceTest, GetValueAndGetRecommendedValue) { | 152 TEST(PrefServiceTest, GetValueAndGetRecommendedValue) { |
151 const int kDefaultValue = 5; | 153 const int kDefaultValue = 5; |
152 const int kUserValue = 10; | 154 const int kUserValue = 10; |
153 const int kRecommendedValue = 15; | 155 const int kRecommendedValue = 15; |
154 TestingPrefServiceSimple prefs; | 156 TestingPrefServiceSimple prefs; |
155 prefs.registry()->RegisterIntegerPref(kPrefName, kDefaultValue); | 157 prefs.registry()->RegisterIntegerPref(kPrefName, kDefaultValue); |
156 | 158 |
157 // Create pref with a default value only. | 159 // Create pref with a default value only. |
158 const PrefService::Preference* pref = prefs.FindPreference(kPrefName); | 160 const PrefService::Preference* pref = prefs.FindPreference(kPrefName); |
159 ASSERT_TRUE(pref); | 161 ASSERT_TRUE(pref); |
160 | 162 |
161 // Check that GetValue() returns the default value. | 163 // Check that GetValue() returns the default value. |
162 const Value* value = pref->GetValue(); | 164 const base::Value* value = pref->GetValue(); |
163 ASSERT_TRUE(value); | 165 ASSERT_TRUE(value); |
164 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | 166 EXPECT_EQ(base::Value::TYPE_INTEGER, value->GetType()); |
165 int actual_int_value = -1; | 167 int actual_int_value = -1; |
166 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | 168 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
167 EXPECT_EQ(kDefaultValue, actual_int_value); | 169 EXPECT_EQ(kDefaultValue, actual_int_value); |
168 | 170 |
169 // Check that GetRecommendedValue() returns no value. | 171 // Check that GetRecommendedValue() returns no value. |
170 value = pref->GetRecommendedValue(); | 172 value = pref->GetRecommendedValue(); |
171 ASSERT_FALSE(value); | 173 ASSERT_FALSE(value); |
172 | 174 |
173 // Set a user-set value. | 175 // Set a user-set value. |
174 prefs.SetUserPref(kPrefName, Value::CreateIntegerValue(kUserValue)); | 176 prefs.SetUserPref(kPrefName, base::Value::CreateIntegerValue(kUserValue)); |
175 | 177 |
176 // Check that GetValue() returns the user-set value. | 178 // Check that GetValue() returns the user-set value. |
177 value = pref->GetValue(); | 179 value = pref->GetValue(); |
178 ASSERT_TRUE(value); | 180 ASSERT_TRUE(value); |
179 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | 181 EXPECT_EQ(base::Value::TYPE_INTEGER, value->GetType()); |
180 actual_int_value = -1; | 182 actual_int_value = -1; |
181 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | 183 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
182 EXPECT_EQ(kUserValue, actual_int_value); | 184 EXPECT_EQ(kUserValue, actual_int_value); |
183 | 185 |
184 // Check that GetRecommendedValue() returns no value. | 186 // Check that GetRecommendedValue() returns no value. |
185 value = pref->GetRecommendedValue(); | 187 value = pref->GetRecommendedValue(); |
186 ASSERT_FALSE(value); | 188 ASSERT_FALSE(value); |
187 | 189 |
188 // Set a recommended value. | 190 // Set a recommended value. |
189 prefs.SetRecommendedPref(kPrefName, | 191 prefs.SetRecommendedPref(kPrefName, |
190 Value::CreateIntegerValue(kRecommendedValue)); | 192 base::Value::CreateIntegerValue(kRecommendedValue)); |
191 | 193 |
192 // Check that GetValue() returns the user-set value. | 194 // Check that GetValue() returns the user-set value. |
193 value = pref->GetValue(); | 195 value = pref->GetValue(); |
194 ASSERT_TRUE(value); | 196 ASSERT_TRUE(value); |
195 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | 197 EXPECT_EQ(base::Value::TYPE_INTEGER, value->GetType()); |
196 actual_int_value = -1; | 198 actual_int_value = -1; |
197 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | 199 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
198 EXPECT_EQ(kUserValue, actual_int_value); | 200 EXPECT_EQ(kUserValue, actual_int_value); |
199 | 201 |
200 // Check that GetRecommendedValue() returns the recommended value. | 202 // Check that GetRecommendedValue() returns the recommended value. |
201 value = pref->GetRecommendedValue(); | 203 value = pref->GetRecommendedValue(); |
202 ASSERT_TRUE(value); | 204 ASSERT_TRUE(value); |
203 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | 205 EXPECT_EQ(base::Value::TYPE_INTEGER, value->GetType()); |
204 actual_int_value = -1; | 206 actual_int_value = -1; |
205 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | 207 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
206 EXPECT_EQ(kRecommendedValue, actual_int_value); | 208 EXPECT_EQ(kRecommendedValue, actual_int_value); |
207 | 209 |
208 // Remove the user-set value. | 210 // Remove the user-set value. |
209 prefs.RemoveUserPref(kPrefName); | 211 prefs.RemoveUserPref(kPrefName); |
210 | 212 |
211 // Check that GetValue() returns the recommended value. | 213 // Check that GetValue() returns the recommended value. |
212 value = pref->GetValue(); | 214 value = pref->GetValue(); |
213 ASSERT_TRUE(value); | 215 ASSERT_TRUE(value); |
214 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | 216 EXPECT_EQ(base::Value::TYPE_INTEGER, value->GetType()); |
215 actual_int_value = -1; | 217 actual_int_value = -1; |
216 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | 218 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
217 EXPECT_EQ(kRecommendedValue, actual_int_value); | 219 EXPECT_EQ(kRecommendedValue, actual_int_value); |
218 | 220 |
219 // Check that GetRecommendedValue() returns the recommended value. | 221 // Check that GetRecommendedValue() returns the recommended value. |
220 value = pref->GetRecommendedValue(); | 222 value = pref->GetRecommendedValue(); |
221 ASSERT_TRUE(value); | 223 ASSERT_TRUE(value); |
222 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | 224 EXPECT_EQ(base::Value::TYPE_INTEGER, value->GetType()); |
223 actual_int_value = -1; | 225 actual_int_value = -1; |
224 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | 226 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
225 EXPECT_EQ(kRecommendedValue, actual_int_value); | 227 EXPECT_EQ(kRecommendedValue, actual_int_value); |
226 } | 228 } |
227 | 229 |
228 class PrefServiceSetValueTest : public testing::Test { | 230 class PrefServiceSetValueTest : public testing::Test { |
229 protected: | 231 protected: |
230 static const char kName[]; | 232 static const char kName[]; |
231 static const char kValue[]; | 233 static const char kValue[]; |
232 | 234 |
233 PrefServiceSetValueTest() : observer_(&prefs_) {} | 235 PrefServiceSetValueTest() : observer_(&prefs_) {} |
234 | 236 |
235 TestingPrefServiceSimple prefs_; | 237 TestingPrefServiceSimple prefs_; |
236 MockPrefChangeCallback observer_; | 238 MockPrefChangeCallback observer_; |
237 }; | 239 }; |
238 | 240 |
239 const char PrefServiceSetValueTest::kName[] = "name"; | 241 const char PrefServiceSetValueTest::kName[] = "name"; |
240 const char PrefServiceSetValueTest::kValue[] = "value"; | 242 const char PrefServiceSetValueTest::kValue[] = "value"; |
241 | 243 |
242 TEST_F(PrefServiceSetValueTest, SetStringValue) { | 244 TEST_F(PrefServiceSetValueTest, SetStringValue) { |
243 const char default_string[] = "default"; | 245 const char default_string[] = "default"; |
244 const StringValue default_value(default_string); | 246 const base::StringValue default_value(default_string); |
245 prefs_.registry()->RegisterStringPref(kName, default_string); | 247 prefs_.registry()->RegisterStringPref(kName, default_string); |
246 | 248 |
247 PrefChangeRegistrar registrar; | 249 PrefChangeRegistrar registrar; |
248 registrar.Init(&prefs_); | 250 registrar.Init(&prefs_); |
249 registrar.Add(kName, observer_.GetCallback()); | 251 registrar.Add(kName, observer_.GetCallback()); |
250 | 252 |
251 // Changing the controlling store from default to user triggers notification. | 253 // Changing the controlling store from default to user triggers notification. |
252 observer_.Expect(kName, &default_value); | 254 observer_.Expect(kName, &default_value); |
253 prefs_.Set(kName, default_value); | 255 prefs_.Set(kName, default_value); |
254 Mock::VerifyAndClearExpectations(&observer_); | 256 Mock::VerifyAndClearExpectations(&observer_); |
255 | 257 |
256 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); | 258 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); |
257 prefs_.Set(kName, default_value); | 259 prefs_.Set(kName, default_value); |
258 Mock::VerifyAndClearExpectations(&observer_); | 260 Mock::VerifyAndClearExpectations(&observer_); |
259 | 261 |
260 StringValue new_value(kValue); | 262 base::StringValue new_value(kValue); |
261 observer_.Expect(kName, &new_value); | 263 observer_.Expect(kName, &new_value); |
262 prefs_.Set(kName, new_value); | 264 prefs_.Set(kName, new_value); |
263 Mock::VerifyAndClearExpectations(&observer_); | 265 Mock::VerifyAndClearExpectations(&observer_); |
264 } | 266 } |
265 | 267 |
266 TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { | 268 TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { |
267 prefs_.registry()->RegisterDictionaryPref(kName); | 269 prefs_.registry()->RegisterDictionaryPref(kName); |
268 PrefChangeRegistrar registrar; | 270 PrefChangeRegistrar registrar; |
269 registrar.Init(&prefs_); | 271 registrar.Init(&prefs_); |
270 registrar.Add(kName, observer_.GetCallback()); | 272 registrar.Add(kName, observer_.GetCallback()); |
271 | 273 |
272 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); | 274 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); |
273 prefs_.RemoveUserPref(kName); | 275 prefs_.RemoveUserPref(kName); |
274 Mock::VerifyAndClearExpectations(&observer_); | 276 Mock::VerifyAndClearExpectations(&observer_); |
275 | 277 |
276 DictionaryValue new_value; | 278 base::DictionaryValue new_value; |
277 new_value.SetString(kName, kValue); | 279 new_value.SetString(kName, kValue); |
278 observer_.Expect(kName, &new_value); | 280 observer_.Expect(kName, &new_value); |
279 prefs_.Set(kName, new_value); | 281 prefs_.Set(kName, new_value); |
280 Mock::VerifyAndClearExpectations(&observer_); | 282 Mock::VerifyAndClearExpectations(&observer_); |
281 | 283 |
282 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); | 284 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); |
283 prefs_.Set(kName, new_value); | 285 prefs_.Set(kName, new_value); |
284 Mock::VerifyAndClearExpectations(&observer_); | 286 Mock::VerifyAndClearExpectations(&observer_); |
285 | 287 |
286 DictionaryValue empty; | 288 base::DictionaryValue empty; |
287 observer_.Expect(kName, &empty); | 289 observer_.Expect(kName, &empty); |
288 prefs_.Set(kName, empty); | 290 prefs_.Set(kName, empty); |
289 Mock::VerifyAndClearExpectations(&observer_); | 291 Mock::VerifyAndClearExpectations(&observer_); |
290 } | 292 } |
291 | 293 |
292 TEST_F(PrefServiceSetValueTest, SetListValue) { | 294 TEST_F(PrefServiceSetValueTest, SetListValue) { |
293 prefs_.registry()->RegisterListPref(kName); | 295 prefs_.registry()->RegisterListPref(kName); |
294 PrefChangeRegistrar registrar; | 296 PrefChangeRegistrar registrar; |
295 registrar.Init(&prefs_); | 297 registrar.Init(&prefs_); |
296 registrar.Add(kName, observer_.GetCallback()); | 298 registrar.Add(kName, observer_.GetCallback()); |
297 | 299 |
298 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); | 300 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); |
299 prefs_.RemoveUserPref(kName); | 301 prefs_.RemoveUserPref(kName); |
300 Mock::VerifyAndClearExpectations(&observer_); | 302 Mock::VerifyAndClearExpectations(&observer_); |
301 | 303 |
302 ListValue new_value; | 304 base::ListValue new_value; |
303 new_value.Append(Value::CreateStringValue(kValue)); | 305 new_value.Append(base::Value::CreateStringValue(kValue)); |
304 observer_.Expect(kName, &new_value); | 306 observer_.Expect(kName, &new_value); |
305 prefs_.Set(kName, new_value); | 307 prefs_.Set(kName, new_value); |
306 Mock::VerifyAndClearExpectations(&observer_); | 308 Mock::VerifyAndClearExpectations(&observer_); |
307 | 309 |
308 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); | 310 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); |
309 prefs_.Set(kName, new_value); | 311 prefs_.Set(kName, new_value); |
310 Mock::VerifyAndClearExpectations(&observer_); | 312 Mock::VerifyAndClearExpectations(&observer_); |
311 | 313 |
312 ListValue empty; | 314 base::ListValue empty; |
313 observer_.Expect(kName, &empty); | 315 observer_.Expect(kName, &empty); |
314 prefs_.Set(kName, empty); | 316 prefs_.Set(kName, empty); |
315 Mock::VerifyAndClearExpectations(&observer_); | 317 Mock::VerifyAndClearExpectations(&observer_); |
316 } | 318 } |
OLD | NEW |