OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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> | |
6 | |
7 #include "base/command_line.h" | 5 #include "base/command_line.h" |
8 #include "base/file_util.h" | 6 #include "base/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
10 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
11 #include "base/path_service.h" | 9 #include "base/path_service.h" |
12 #include "base/prefs/json_pref_store.h" | |
13 #include "base/prefs/mock_pref_change_callback.h" | |
14 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
15 #include "base/prefs/pref_value_store.h" | |
16 #include "base/prefs/public/pref_change_registrar.h" | |
17 #include "base/prefs/testing_pref_store.h" | |
18 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
19 #include "base/values.h" | 12 #include "base/values.h" |
20 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 13 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
21 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 14 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
22 #include "chrome/browser/prefs/browser_prefs.h" | 15 #include "chrome/browser/prefs/browser_prefs.h" |
23 #include "chrome/browser/prefs/command_line_pref_store.h" | 16 #include "chrome/browser/prefs/command_line_pref_store.h" |
24 #include "chrome/browser/prefs/pref_registry_syncable.h" | 17 #include "chrome/browser/prefs/pref_registry_syncable.h" |
25 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 18 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
26 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
27 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
30 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
31 #include "chrome/test/base/testing_pref_service_syncable.h" | 24 #include "chrome/test/base/testing_pref_service_syncable.h" |
32 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
33 #include "content/public/test/test_browser_thread.h" | 26 #include "content/public/test/test_browser_thread.h" |
34 #include "content/public/test/web_contents_tester.h" | 27 #include "content/public/test/web_contents_tester.h" |
35 #include "testing/gmock/include/gmock/gmock.h" | |
36 #include "testing/gtest/include/gtest/gtest.h" | |
37 #include "ui/base/test/data/resource.h" | 28 #include "ui/base/test/data/resource.h" |
38 #include "webkit/glue/webpreferences.h" | 29 #include "webkit/glue/webpreferences.h" |
39 | 30 |
40 using content::BrowserThread; | 31 using content::BrowserThread; |
41 using content::WebContentsTester; | 32 using content::WebContentsTester; |
42 using testing::_; | |
43 using testing::Mock; | |
44 | 33 |
45 TEST(PrefServiceTest, NoObserverFire) { | 34 TEST(ChromePrefServiceTest, UpdateCommandLinePrefStore) { |
46 TestingPrefServiceSimple prefs; | |
47 | |
48 const char pref_name[] = "homepage"; | |
49 prefs.registry()->RegisterStringPref(pref_name, std::string()); | |
50 | |
51 const char new_pref_value[] = "http://www.google.com/"; | |
52 MockPrefChangeCallback obs(&prefs); | |
53 PrefChangeRegistrar registrar; | |
54 registrar.Init(&prefs); | |
55 registrar.Add(pref_name, obs.GetCallback()); | |
56 | |
57 // This should fire the checks in MockPrefChangeCallback::OnPreferenceChanged. | |
58 const StringValue expected_value(new_pref_value); | |
59 obs.Expect(pref_name, &expected_value); | |
60 prefs.SetString(pref_name, new_pref_value); | |
61 Mock::VerifyAndClearExpectations(&obs); | |
62 | |
63 // Setting the pref to the same value should not set the pref value a second | |
64 // time. | |
65 EXPECT_CALL(obs, OnPreferenceChanged(_)).Times(0); | |
66 prefs.SetString(pref_name, new_pref_value); | |
67 Mock::VerifyAndClearExpectations(&obs); | |
68 | |
69 // Clearing the pref should cause the pref to fire. | |
70 const StringValue expected_default_value(""); | |
71 obs.Expect(pref_name, &expected_default_value); | |
72 prefs.ClearPref(pref_name); | |
73 Mock::VerifyAndClearExpectations(&obs); | |
74 | |
75 // Clearing the pref again should not cause the pref to fire. | |
76 EXPECT_CALL(obs, OnPreferenceChanged(_)).Times(0); | |
77 prefs.ClearPref(pref_name); | |
78 Mock::VerifyAndClearExpectations(&obs); | |
79 } | |
80 | |
81 TEST(PrefServiceTest, HasPrefPath) { | |
82 TestingPrefServiceSimple prefs; | |
83 | |
84 const char path[] = "fake.path"; | |
85 | |
86 // Shouldn't initially have a path. | |
87 EXPECT_FALSE(prefs.HasPrefPath(path)); | |
88 | |
89 // Register the path. This doesn't set a value, so the path still shouldn't | |
90 // exist. | |
91 prefs.registry()->RegisterStringPref(path, std::string()); | |
92 EXPECT_FALSE(prefs.HasPrefPath(path)); | |
93 | |
94 // Set a value and make sure we have a path. | |
95 prefs.SetString(path, "blah"); | |
96 EXPECT_TRUE(prefs.HasPrefPath(path)); | |
97 } | |
98 | |
99 TEST(PrefServiceTest, Observers) { | |
100 const char pref_name[] = "homepage"; | |
101 | |
102 TestingPrefServiceSimple prefs; | |
103 prefs.SetUserPref(pref_name, Value::CreateStringValue("http://www.cnn.com")); | |
104 prefs.registry()->RegisterStringPref(pref_name, std::string()); | |
105 | |
106 const char new_pref_value[] = "http://www.google.com/"; | |
107 const StringValue expected_new_pref_value(new_pref_value); | |
108 MockPrefChangeCallback obs(&prefs); | |
109 PrefChangeRegistrar registrar; | |
110 registrar.Init(&prefs); | |
111 registrar.Add(pref_name, obs.GetCallback()); | |
112 | |
113 PrefChangeRegistrar registrar_two; | |
114 registrar_two.Init(&prefs); | |
115 | |
116 // This should fire the checks in MockPrefChangeCallback::OnPreferenceChanged. | |
117 obs.Expect(pref_name, &expected_new_pref_value); | |
118 prefs.SetString(pref_name, new_pref_value); | |
119 Mock::VerifyAndClearExpectations(&obs); | |
120 | |
121 // Now try adding a second pref observer. | |
122 const char new_pref_value2[] = "http://www.youtube.com/"; | |
123 const StringValue expected_new_pref_value2(new_pref_value2); | |
124 MockPrefChangeCallback obs2(&prefs); | |
125 obs.Expect(pref_name, &expected_new_pref_value2); | |
126 obs2.Expect(pref_name, &expected_new_pref_value2); | |
127 registrar_two.Add(pref_name, obs2.GetCallback()); | |
128 // This should fire the checks in obs and obs2. | |
129 prefs.SetString(pref_name, new_pref_value2); | |
130 Mock::VerifyAndClearExpectations(&obs); | |
131 Mock::VerifyAndClearExpectations(&obs2); | |
132 | |
133 // Set a recommended value. | |
134 const StringValue recommended_pref_value("http://www.gmail.com/"); | |
135 obs.Expect(pref_name, &expected_new_pref_value2); | |
136 obs2.Expect(pref_name, &expected_new_pref_value2); | |
137 // This should fire the checks in obs and obs2 but with an unchanged value | |
138 // as the recommended value is being overridden by the user-set value. | |
139 prefs.SetRecommendedPref(pref_name, recommended_pref_value.DeepCopy()); | |
140 Mock::VerifyAndClearExpectations(&obs); | |
141 Mock::VerifyAndClearExpectations(&obs2); | |
142 | |
143 // Make sure obs2 still works after removing obs. | |
144 registrar.Remove(pref_name); | |
145 EXPECT_CALL(obs, OnPreferenceChanged(_)).Times(0); | |
146 obs2.Expect(pref_name, &expected_new_pref_value); | |
147 // This should only fire the observer in obs2. | |
148 prefs.SetString(pref_name, new_pref_value); | |
149 Mock::VerifyAndClearExpectations(&obs); | |
150 Mock::VerifyAndClearExpectations(&obs2); | |
151 } | |
152 | |
153 // Make sure that if a preference changes type, so the wrong type is stored in | |
154 // the user pref file, it uses the correct fallback value instead. | |
155 TEST(PrefServiceTest, GetValueChangedType) { | |
156 const int kTestValue = 10; | |
157 TestingPrefServiceSimple prefs; | |
158 prefs.registry()->RegisterIntegerPref( | |
159 prefs::kStabilityLaunchCount, kTestValue); | |
160 | |
161 // Check falling back to a recommended value. | |
162 prefs.SetUserPref(prefs::kStabilityLaunchCount, | |
163 Value::CreateStringValue("not an integer")); | |
164 const PrefService::Preference* pref = | |
165 prefs.FindPreference(prefs::kStabilityLaunchCount); | |
166 ASSERT_TRUE(pref); | |
167 const Value* value = pref->GetValue(); | |
168 ASSERT_TRUE(value); | |
169 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | |
170 int actual_int_value = -1; | |
171 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | |
172 EXPECT_EQ(kTestValue, actual_int_value); | |
173 } | |
174 | |
175 TEST(PrefServiceTest, UpdateCommandLinePrefStore) { | |
176 TestingPrefServiceSimple prefs; | 35 TestingPrefServiceSimple prefs; |
177 prefs.registry()->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, false); | 36 prefs.registry()->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, false); |
178 | 37 |
179 // Check to make sure the value is as expected. | 38 // Check to make sure the value is as expected. |
180 const PrefService::Preference* pref = | 39 const PrefService::Preference* pref = |
181 prefs.FindPreference(prefs::kCloudPrintProxyEnabled); | 40 prefs.FindPreference(prefs::kCloudPrintProxyEnabled); |
182 ASSERT_TRUE(pref); | 41 ASSERT_TRUE(pref); |
183 const Value* value = pref->GetValue(); | 42 const Value* value = pref->GetValue(); |
184 ASSERT_TRUE(value); | 43 ASSERT_TRUE(value); |
185 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType()); | 44 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType()); |
(...skipping 10 matching lines...) Expand all Loading... |
196 pref = prefs.FindPreference(prefs::kCloudPrintProxyEnabled); | 55 pref = prefs.FindPreference(prefs::kCloudPrintProxyEnabled); |
197 ASSERT_TRUE(pref); | 56 ASSERT_TRUE(pref); |
198 value = pref->GetValue(); | 57 value = pref->GetValue(); |
199 ASSERT_TRUE(value); | 58 ASSERT_TRUE(value); |
200 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType()); | 59 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType()); |
201 actual_bool_value = false; | 60 actual_bool_value = false; |
202 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value)); | 61 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value)); |
203 EXPECT_TRUE(actual_bool_value); | 62 EXPECT_TRUE(actual_bool_value); |
204 } | 63 } |
205 | 64 |
206 TEST(PrefServiceTest, GetValueAndGetRecommendedValue) { | 65 class ChromePrefServiceUserFilePrefsTest : public testing::Test { |
207 const int kDefaultValue = 5; | |
208 const int kUserValue = 10; | |
209 const int kRecommendedValue = 15; | |
210 TestingPrefServiceSimple prefs; | |
211 prefs.registry()->RegisterIntegerPref( | |
212 prefs::kStabilityLaunchCount, kDefaultValue); | |
213 | |
214 // Create pref with a default value only. | |
215 const PrefService::Preference* pref = | |
216 prefs.FindPreference(prefs::kStabilityLaunchCount); | |
217 ASSERT_TRUE(pref); | |
218 | |
219 // Check that GetValue() returns the default value. | |
220 const Value* value = pref->GetValue(); | |
221 ASSERT_TRUE(value); | |
222 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | |
223 int actual_int_value = -1; | |
224 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | |
225 EXPECT_EQ(kDefaultValue, actual_int_value); | |
226 | |
227 // Check that GetRecommendedValue() returns no value. | |
228 value = pref->GetRecommendedValue(); | |
229 ASSERT_FALSE(value); | |
230 | |
231 // Set a user-set value. | |
232 prefs.SetUserPref(prefs::kStabilityLaunchCount, | |
233 Value::CreateIntegerValue(kUserValue)); | |
234 | |
235 // Check that GetValue() returns the user-set value. | |
236 value = pref->GetValue(); | |
237 ASSERT_TRUE(value); | |
238 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | |
239 actual_int_value = -1; | |
240 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | |
241 EXPECT_EQ(kUserValue, actual_int_value); | |
242 | |
243 // Check that GetRecommendedValue() returns no value. | |
244 value = pref->GetRecommendedValue(); | |
245 ASSERT_FALSE(value); | |
246 | |
247 // Set a recommended value. | |
248 prefs.SetRecommendedPref(prefs::kStabilityLaunchCount, | |
249 Value::CreateIntegerValue(kRecommendedValue)); | |
250 | |
251 // Check that GetValue() returns the user-set value. | |
252 value = pref->GetValue(); | |
253 ASSERT_TRUE(value); | |
254 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | |
255 actual_int_value = -1; | |
256 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | |
257 EXPECT_EQ(kUserValue, actual_int_value); | |
258 | |
259 // Check that GetRecommendedValue() returns the recommended value. | |
260 value = pref->GetRecommendedValue(); | |
261 ASSERT_TRUE(value); | |
262 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | |
263 actual_int_value = -1; | |
264 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | |
265 EXPECT_EQ(kRecommendedValue, actual_int_value); | |
266 | |
267 // Remove the user-set value. | |
268 prefs.RemoveUserPref(prefs::kStabilityLaunchCount); | |
269 | |
270 // Check that GetValue() returns the recommended value. | |
271 value = pref->GetValue(); | |
272 ASSERT_TRUE(value); | |
273 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | |
274 actual_int_value = -1; | |
275 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | |
276 EXPECT_EQ(kRecommendedValue, actual_int_value); | |
277 | |
278 // Check that GetRecommendedValue() returns the recommended value. | |
279 value = pref->GetRecommendedValue(); | |
280 ASSERT_TRUE(value); | |
281 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); | |
282 actual_int_value = -1; | |
283 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | |
284 EXPECT_EQ(kRecommendedValue, actual_int_value); | |
285 } | |
286 | |
287 class PrefServiceUserFilePrefsTest : public testing::Test { | |
288 protected: | 66 protected: |
289 virtual void SetUp() { | 67 virtual void SetUp() { |
290 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 68 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
291 | 69 |
292 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); | 70 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); |
293 data_dir_ = data_dir_.AppendASCII("pref_service"); | 71 data_dir_ = data_dir_.AppendASCII("pref_service"); |
294 ASSERT_TRUE(file_util::PathExists(data_dir_)); | 72 ASSERT_TRUE(file_util::PathExists(data_dir_)); |
295 } | 73 } |
296 | 74 |
297 void ClearListValue(PrefService* prefs, const char* key) { | 75 void ClearListValue(PrefService* prefs, const char* key) { |
298 ListPrefUpdate updater(prefs, key); | 76 ListPrefUpdate updater(prefs, key); |
299 updater->Clear(); | 77 updater->Clear(); |
300 } | 78 } |
301 | 79 |
302 void ClearDictionaryValue(PrefService* prefs, const char* key) { | 80 void ClearDictionaryValue(PrefService* prefs, const char* key) { |
303 DictionaryPrefUpdate updater(prefs, key); | 81 DictionaryPrefUpdate updater(prefs, key); |
304 updater->Clear(); | 82 updater->Clear(); |
305 } | 83 } |
306 | 84 |
307 // The path to temporary directory used to contain the test operations. | 85 // The path to temporary directory used to contain the test operations. |
308 base::ScopedTempDir temp_dir_; | 86 base::ScopedTempDir temp_dir_; |
309 // The path to the directory where the test data is stored. | 87 // The path to the directory where the test data is stored. |
310 base::FilePath data_dir_; | 88 base::FilePath data_dir_; |
311 // A message loop that we can use as the file thread message loop. | 89 // A message loop that we can use as the file thread message loop. |
312 MessageLoop message_loop_; | 90 MessageLoop message_loop_; |
313 }; | 91 }; |
314 | 92 |
315 // Verifies that ListValue and DictionaryValue pref with non emtpy default | 93 // Verifies that ListValue and DictionaryValue pref with non emtpy default |
316 // preserves its empty value. | 94 // preserves its empty value. |
317 TEST_F(PrefServiceUserFilePrefsTest, PreserveEmptyValue) { | 95 TEST_F(ChromePrefServiceUserFilePrefsTest, PreserveEmptyValue) { |
318 base::FilePath pref_file = temp_dir_.path().AppendASCII("write.json"); | 96 base::FilePath pref_file = temp_dir_.path().AppendASCII("write.json"); |
319 | 97 |
320 ASSERT_TRUE(file_util::CopyFile( | 98 ASSERT_TRUE(file_util::CopyFile( |
321 data_dir_.AppendASCII("read.need_empty_value.json"), | 99 data_dir_.AppendASCII("read.need_empty_value.json"), |
322 pref_file)); | 100 pref_file)); |
323 | 101 |
324 PrefServiceMockBuilder builder; | 102 PrefServiceMockBuilder builder; |
325 builder.WithUserFilePrefs(pref_file, message_loop_.message_loop_proxy()); | 103 builder.WithUserFilePrefs(pref_file, message_loop_.message_loop_proxy()); |
326 scoped_refptr<PrefRegistrySyncable> registry(new PrefRegistrySyncable); | 104 scoped_refptr<PrefRegistrySyncable> registry(new PrefRegistrySyncable); |
327 scoped_ptr<PrefServiceSyncable> prefs(builder.CreateSyncable(registry)); | 105 scoped_ptr<PrefServiceSyncable> prefs(builder.CreateSyncable(registry)); |
(...skipping 26 matching lines...) Expand all Loading... |
354 prefs->CommitPendingWrite(); | 132 prefs->CommitPendingWrite(); |
355 message_loop_.RunUntilIdle(); | 133 message_loop_.RunUntilIdle(); |
356 | 134 |
357 // Compare to expected output. | 135 // Compare to expected output. |
358 base::FilePath golden_output_file = | 136 base::FilePath golden_output_file = |
359 data_dir_.AppendASCII("write.golden.need_empty_value.json"); | 137 data_dir_.AppendASCII("write.golden.need_empty_value.json"); |
360 ASSERT_TRUE(file_util::PathExists(golden_output_file)); | 138 ASSERT_TRUE(file_util::PathExists(golden_output_file)); |
361 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); | 139 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); |
362 } | 140 } |
363 | 141 |
364 class PrefServiceSetValueTest : public testing::Test { | 142 class ChromePrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness { |
365 protected: | 143 protected: |
366 static const char kName[]; | 144 ChromePrefServiceWebKitPrefs() |
367 static const char kValue[]; | 145 : ui_thread_(BrowserThread::UI, &message_loop_) { |
368 | |
369 PrefServiceSetValueTest() : observer_(&prefs_) {} | |
370 | |
371 TestingPrefServiceSimple prefs_; | |
372 MockPrefChangeCallback observer_; | |
373 }; | |
374 | |
375 const char PrefServiceSetValueTest::kName[] = "name"; | |
376 const char PrefServiceSetValueTest::kValue[] = "value"; | |
377 | |
378 TEST_F(PrefServiceSetValueTest, SetStringValue) { | |
379 const char default_string[] = "default"; | |
380 const StringValue default_value(default_string); | |
381 prefs_.registry()->RegisterStringPref(kName, default_string); | |
382 | |
383 PrefChangeRegistrar registrar; | |
384 registrar.Init(&prefs_); | |
385 registrar.Add(kName, observer_.GetCallback()); | |
386 | |
387 // Changing the controlling store from default to user triggers notification. | |
388 observer_.Expect(kName, &default_value); | |
389 prefs_.Set(kName, default_value); | |
390 Mock::VerifyAndClearExpectations(&observer_); | |
391 | |
392 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); | |
393 prefs_.Set(kName, default_value); | |
394 Mock::VerifyAndClearExpectations(&observer_); | |
395 | |
396 StringValue new_value(kValue); | |
397 observer_.Expect(kName, &new_value); | |
398 prefs_.Set(kName, new_value); | |
399 Mock::VerifyAndClearExpectations(&observer_); | |
400 } | |
401 | |
402 TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { | |
403 prefs_.registry()->RegisterDictionaryPref(kName); | |
404 PrefChangeRegistrar registrar; | |
405 registrar.Init(&prefs_); | |
406 registrar.Add(kName, observer_.GetCallback()); | |
407 | |
408 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); | |
409 prefs_.RemoveUserPref(kName); | |
410 Mock::VerifyAndClearExpectations(&observer_); | |
411 | |
412 DictionaryValue new_value; | |
413 new_value.SetString(kName, kValue); | |
414 observer_.Expect(kName, &new_value); | |
415 prefs_.Set(kName, new_value); | |
416 Mock::VerifyAndClearExpectations(&observer_); | |
417 | |
418 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); | |
419 prefs_.Set(kName, new_value); | |
420 Mock::VerifyAndClearExpectations(&observer_); | |
421 | |
422 DictionaryValue empty; | |
423 observer_.Expect(kName, &empty); | |
424 prefs_.Set(kName, empty); | |
425 Mock::VerifyAndClearExpectations(&observer_); | |
426 } | |
427 | |
428 TEST_F(PrefServiceSetValueTest, SetListValue) { | |
429 prefs_.registry()->RegisterListPref(kName); | |
430 PrefChangeRegistrar registrar; | |
431 registrar.Init(&prefs_); | |
432 registrar.Add(kName, observer_.GetCallback()); | |
433 | |
434 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); | |
435 prefs_.RemoveUserPref(kName); | |
436 Mock::VerifyAndClearExpectations(&observer_); | |
437 | |
438 ListValue new_value; | |
439 new_value.Append(Value::CreateStringValue(kValue)); | |
440 observer_.Expect(kName, &new_value); | |
441 prefs_.Set(kName, new_value); | |
442 Mock::VerifyAndClearExpectations(&observer_); | |
443 | |
444 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); | |
445 prefs_.Set(kName, new_value); | |
446 Mock::VerifyAndClearExpectations(&observer_); | |
447 | |
448 ListValue empty; | |
449 observer_.Expect(kName, &empty); | |
450 prefs_.Set(kName, empty); | |
451 Mock::VerifyAndClearExpectations(&observer_); | |
452 } | |
453 | |
454 class PrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness { | |
455 protected: | |
456 PrefServiceWebKitPrefs() : ui_thread_(BrowserThread::UI, &message_loop_) { | |
457 } | 146 } |
458 | 147 |
459 virtual void SetUp() { | 148 virtual void SetUp() { |
460 ChromeRenderViewHostTestHarness::SetUp(); | 149 ChromeRenderViewHostTestHarness::SetUp(); |
461 | 150 |
462 // Supply our own profile so we use the correct profile data. The test | 151 // Supply our own profile so we use the correct profile data. The test |
463 // harness is not supposed to overwrite a profile if it's already created. | 152 // harness is not supposed to overwrite a profile if it's already created. |
464 | 153 |
465 // Set some (WebKit) user preferences. | 154 // Set some (WebKit) user preferences. |
466 TestingPrefServiceSyncable* pref_services = | 155 TestingPrefServiceSyncable* pref_services = |
(...skipping 13 matching lines...) Expand all Loading... |
480 pref_services->SetUserPref("webkit.webprefs.foo", | 169 pref_services->SetUserPref("webkit.webprefs.foo", |
481 Value::CreateStringValue("bar")); | 170 Value::CreateStringValue("bar")); |
482 } | 171 } |
483 | 172 |
484 private: | 173 private: |
485 content::TestBrowserThread ui_thread_; | 174 content::TestBrowserThread ui_thread_; |
486 }; | 175 }; |
487 | 176 |
488 // Tests to see that webkit preferences are properly loaded and copied over | 177 // Tests to see that webkit preferences are properly loaded and copied over |
489 // to a WebPreferences object. | 178 // to a WebPreferences object. |
490 TEST_F(PrefServiceWebKitPrefs, PrefsCopied) { | 179 TEST_F(ChromePrefServiceWebKitPrefs, PrefsCopied) { |
491 webkit_glue::WebPreferences webkit_prefs = | 180 webkit_glue::WebPreferences webkit_prefs = |
492 WebContentsTester::For(web_contents())->TestGetWebkitPrefs(); | 181 WebContentsTester::For(web_contents())->TestGetWebkitPrefs(); |
493 | 182 |
494 // These values have been overridden by the profile preferences. | 183 // These values have been overridden by the profile preferences. |
495 EXPECT_EQ("UTF-8", webkit_prefs.default_encoding); | 184 EXPECT_EQ("UTF-8", webkit_prefs.default_encoding); |
496 EXPECT_EQ(20, webkit_prefs.default_font_size); | 185 EXPECT_EQ(20, webkit_prefs.default_font_size); |
497 EXPECT_FALSE(webkit_prefs.text_areas_are_resizable); | 186 EXPECT_FALSE(webkit_prefs.text_areas_are_resizable); |
498 EXPECT_TRUE(webkit_prefs.uses_universal_detector); | 187 EXPECT_TRUE(webkit_prefs.uses_universal_detector); |
499 | 188 |
500 // These should still be the default values. | 189 // These should still be the default values. |
501 #if defined(OS_MACOSX) | 190 #if defined(OS_MACOSX) |
502 const char kDefaultFont[] = "Times"; | 191 const char kDefaultFont[] = "Times"; |
503 #elif defined(OS_CHROMEOS) | 192 #elif defined(OS_CHROMEOS) |
504 const char kDefaultFont[] = "Tinos"; | 193 const char kDefaultFont[] = "Tinos"; |
505 #else | 194 #else |
506 const char kDefaultFont[] = "Times New Roman"; | 195 const char kDefaultFont[] = "Times New Roman"; |
507 #endif | 196 #endif |
508 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), | 197 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), |
509 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); | 198 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); |
510 EXPECT_TRUE(webkit_prefs.javascript_enabled); | 199 EXPECT_TRUE(webkit_prefs.javascript_enabled); |
511 } | 200 } |
OLD | NEW |