blob: 6c1e0ea5a42dcf24272676dd67e6c4cd00913491 [file] [log] [blame]
[email protected]d3b05ea2012-01-24 22:57:051// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]ecde2742010-04-02 17:36:185#include <string>
6
[email protected]ce1850e92010-10-15 08:40:587#include "base/command_line.h"
[email protected]ea3e4972012-04-12 03:41:378#include "base/file_util.h"
[email protected]3b63f8f42011-03-28 01:54:159#include "base/memory/scoped_ptr.h"
[email protected]ea3e4972012-04-12 03:41:3710#include "base/path_service.h"
11#include "base/scoped_temp_dir.h"
[email protected]1bec2372011-12-07 09:19:0612#include "base/utf_string_conversions.h"
[email protected]ecde2742010-04-02 17:36:1813#include "base/values.h"
[email protected]ce1850e92010-10-15 08:40:5814#include "chrome/browser/policy/configuration_policy_pref_store.h"
15#include "chrome/browser/policy/mock_configuration_policy_provider.h"
16#include "chrome/browser/prefs/browser_prefs.h"
17#include "chrome/browser/prefs/command_line_pref_store.h"
[email protected]2fb7dc982010-09-29 12:24:2818#include "chrome/browser/prefs/pref_change_registrar.h"
[email protected]acd78969c2010-12-08 09:49:1119#include "chrome/browser/prefs/pref_observer_mock.h"
[email protected]f2d1f612010-12-09 15:10:1720#include "chrome/browser/prefs/pref_service_mock_builder.h"
[email protected]37858e52010-08-26 00:22:0221#include "chrome/browser/prefs/pref_value_store.h"
[email protected]ea3e4972012-04-12 03:41:3722#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f2d1f612010-12-09 15:10:1723#include "chrome/browser/prefs/testing_pref_store.h"
initial.commit09911bf2008-07-26 23:55:2924#include "chrome/common/chrome_paths.h"
[email protected]ce1850e92010-10-15 08:40:5825#include "chrome/common/chrome_switches.h"
[email protected]ea3e4972012-04-12 03:41:3726#include "chrome/common/json_pref_store.h"
initial.commit09911bf2008-07-26 23:55:2927#include "chrome/common/pref_names.h"
[email protected]1bec2372011-12-07 09:19:0628#include "chrome/test/base/chrome_render_view_host_test_harness.h"
[email protected]8ad3636e2011-08-01 22:31:4029#include "chrome/test/base/testing_pref_service.h"
[email protected]1bec2372011-12-07 09:19:0630#include "chrome/test/base/testing_profile.h"
[email protected]e97882f2012-06-04 02:23:1731#include "content/public/test/test_browser_thread.h"
[email protected]46a32b92012-03-22 13:04:4832#include "content/test/web_contents_tester.h"
[email protected]ecde2742010-04-02 17:36:1833#include "testing/gmock/include/gmock/gmock.h"
initial.commit09911bf2008-07-26 23:55:2934#include "testing/gtest/include/gtest/gtest.h"
[email protected]41110ca2011-06-27 16:45:4935#include "ui/base/test/data/resource.h"
[email protected]46a32b92012-03-22 13:04:4836#include "webkit/glue/webpreferences.h"
initial.commit09911bf2008-07-26 23:55:2937
[email protected]1bec2372011-12-07 09:19:0638using content::BrowserThread;
[email protected]46a32b92012-03-22 13:04:4839using content::WebContentsTester;
[email protected]ecde2742010-04-02 17:36:1840using testing::_;
41using testing::Mock;
[email protected]12a3c022010-11-03 10:24:1142
[email protected]277404c22010-04-22 13:09:4543TEST(PrefServiceTest, NoObserverFire) {
[email protected]74379bc52010-07-21 13:54:0844 TestingPrefService prefs;
[email protected]7aa0a962010-04-21 17:24:4245
[email protected]57ecc4b2010-08-11 03:02:5146 const char pref_name[] = "homepage";
[email protected]12a3c022010-11-03 10:24:1147 prefs.RegisterStringPref(pref_name, std::string());
[email protected]7aa0a962010-04-21 17:24:4248
[email protected]acd78969c2010-12-08 09:49:1149 const char new_pref_value[] = "http://www.google.com/";
50 PrefObserverMock obs;
[email protected]2fb7dc982010-09-29 12:24:2851 PrefChangeRegistrar registrar;
52 registrar.Init(&prefs);
53 registrar.Add(pref_name, &obs);
[email protected]7aa0a962010-04-21 17:24:4254
[email protected]acd78969c2010-12-08 09:49:1155 // This should fire the checks in PrefObserverMock::Observe.
56 const StringValue expected_value(new_pref_value);
57 obs.Expect(&prefs, pref_name, &expected_value);
58 prefs.SetString(pref_name, new_pref_value);
59 Mock::VerifyAndClearExpectations(&obs);
[email protected]7aa0a962010-04-21 17:24:4260
61 // Setting the pref to the same value should not set the pref value a second
62 // time.
[email protected]acd78969c2010-12-08 09:49:1163 EXPECT_CALL(obs, Observe(_, _, _)).Times(0);
[email protected]7aa0a962010-04-21 17:24:4264 prefs.SetString(pref_name, new_pref_value);
[email protected]acd78969c2010-12-08 09:49:1165 Mock::VerifyAndClearExpectations(&obs);
[email protected]7aa0a962010-04-21 17:24:4266
67 // Clearing the pref should cause the pref to fire.
[email protected]acd78969c2010-12-08 09:49:1168 const StringValue expected_default_value("");
69 obs.Expect(&prefs, pref_name, &expected_default_value);
[email protected]7aa0a962010-04-21 17:24:4270 prefs.ClearPref(pref_name);
[email protected]acd78969c2010-12-08 09:49:1171 Mock::VerifyAndClearExpectations(&obs);
[email protected]7aa0a962010-04-21 17:24:4272
73 // Clearing the pref again should not cause the pref to fire.
[email protected]acd78969c2010-12-08 09:49:1174 EXPECT_CALL(obs, Observe(_, _, _)).Times(0);
[email protected]7aa0a962010-04-21 17:24:4275 prefs.ClearPref(pref_name);
[email protected]acd78969c2010-12-08 09:49:1176 Mock::VerifyAndClearExpectations(&obs);
[email protected]7aa0a962010-04-21 17:24:4277}
78
[email protected]277404c22010-04-22 13:09:4579TEST(PrefServiceTest, HasPrefPath) {
[email protected]74379bc52010-07-21 13:54:0880 TestingPrefService prefs;
[email protected]7aa0a962010-04-21 17:24:4281
[email protected]57ecc4b2010-08-11 03:02:5182 const char path[] = "fake.path";
[email protected]7aa0a962010-04-21 17:24:4283
84 // Shouldn't initially have a path.
85 EXPECT_FALSE(prefs.HasPrefPath(path));
86
87 // Register the path. This doesn't set a value, so the path still shouldn't
88 // exist.
[email protected]20ce516d2010-06-18 02:20:0489 prefs.RegisterStringPref(path, std::string());
[email protected]7aa0a962010-04-21 17:24:4290 EXPECT_FALSE(prefs.HasPrefPath(path));
91
92 // Set a value and make sure we have a path.
[email protected]ddd231e2010-06-29 20:35:1993 prefs.SetString(path, "blah");
[email protected]7aa0a962010-04-21 17:24:4294 EXPECT_TRUE(prefs.HasPrefPath(path));
95}
96
[email protected]277404c22010-04-22 13:09:4597TEST(PrefServiceTest, Observers) {
[email protected]57ecc4b2010-08-11 03:02:5198 const char pref_name[] = "homepage";
[email protected]277404c22010-04-22 13:09:4599
[email protected]74379bc52010-07-21 13:54:08100 TestingPrefService prefs;
[email protected]57ecc4b2010-08-11 03:02:51101 prefs.SetUserPref(pref_name, Value::CreateStringValue("http://www.cnn.com"));
[email protected]12a3c022010-11-03 10:24:11102 prefs.RegisterStringPref(pref_name, std::string());
[email protected]277404c22010-04-22 13:09:45103
[email protected]acd78969c2010-12-08 09:49:11104 const char new_pref_value[] = "http://www.google.com/";
105 const StringValue expected_new_pref_value(new_pref_value);
106 PrefObserverMock obs;
[email protected]2fb7dc982010-09-29 12:24:28107 PrefChangeRegistrar registrar;
108 registrar.Init(&prefs);
109 registrar.Add(pref_name, &obs);
[email protected]277404c22010-04-22 13:09:45110
[email protected]acd78969c2010-12-08 09:49:11111 // This should fire the checks in PrefObserverMock::Observe.
112 obs.Expect(&prefs, pref_name, &expected_new_pref_value);
113 prefs.SetString(pref_name, new_pref_value);
114 Mock::VerifyAndClearExpectations(&obs);
[email protected]277404c22010-04-22 13:09:45115
116 // Now try adding a second pref observer.
[email protected]acd78969c2010-12-08 09:49:11117 const char new_pref_value2[] = "http://www.youtube.com/";
118 const StringValue expected_new_pref_value2(new_pref_value2);
119 PrefObserverMock obs2;
120 obs.Expect(&prefs, pref_name, &expected_new_pref_value2);
121 obs2.Expect(&prefs, pref_name, &expected_new_pref_value2);
[email protected]2fb7dc982010-09-29 12:24:28122 registrar.Add(pref_name, &obs2);
[email protected]277404c22010-04-22 13:09:45123 // This should fire the checks in obs and obs2.
124 prefs.SetString(pref_name, new_pref_value2);
[email protected]acd78969c2010-12-08 09:49:11125 Mock::VerifyAndClearExpectations(&obs);
126 Mock::VerifyAndClearExpectations(&obs2);
[email protected]277404c22010-04-22 13:09:45127
128 // Make sure obs2 still works after removing obs.
[email protected]2fb7dc982010-09-29 12:24:28129 registrar.Remove(pref_name, &obs);
[email protected]acd78969c2010-12-08 09:49:11130 EXPECT_CALL(obs, Observe(_, _, _)).Times(0);
131 obs2.Expect(&prefs, pref_name, &expected_new_pref_value);
[email protected]277404c22010-04-22 13:09:45132 // This should only fire the observer in obs2.
133 prefs.SetString(pref_name, new_pref_value);
[email protected]acd78969c2010-12-08 09:49:11134 Mock::VerifyAndClearExpectations(&obs);
135 Mock::VerifyAndClearExpectations(&obs2);
[email protected]277404c22010-04-22 13:09:45136}
137
[email protected]9a8c4022011-01-25 14:25:33138// Make sure that if a preference changes type, so the wrong type is stored in
139// the user pref file, it uses the correct fallback value instead.
140TEST(PrefServiceTest, GetValueChangedType) {
141 const int kTestValue = 10;
142 TestingPrefService prefs;
143 prefs.RegisterIntegerPref(prefs::kStabilityLaunchCount, kTestValue);
144
145 // Check falling back to a recommended value.
146 prefs.SetUserPref(prefs::kStabilityLaunchCount,
147 Value::CreateStringValue("not an integer"));
148 const PrefService::Preference* pref =
149 prefs.FindPreference(prefs::kStabilityLaunchCount);
150 ASSERT_TRUE(pref);
151 const Value* value = pref->GetValue();
152 ASSERT_TRUE(value);
153 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType());
154 int actual_int_value = -1;
155 EXPECT_TRUE(value->GetAsInteger(&actual_int_value));
156 EXPECT_EQ(kTestValue, actual_int_value);
157}
158
[email protected]d3b05ea2012-01-24 22:57:05159TEST(PrefServiceTest, UpdateCommandLinePrefStore) {
160 TestingPrefService prefs;
161 prefs.RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, false);
162
163 // Check to make sure the value is as expected.
164 const PrefService::Preference* pref =
165 prefs.FindPreference(prefs::kCloudPrintProxyEnabled);
166 ASSERT_TRUE(pref);
167 const Value* value = pref->GetValue();
168 ASSERT_TRUE(value);
169 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType());
170 bool actual_bool_value = true;
171 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value));
[email protected]4eccb81a2012-01-26 12:01:22172 EXPECT_FALSE(actual_bool_value);
[email protected]d3b05ea2012-01-24 22:57:05173
174 // Change the command line.
175 CommandLine cmd_line(CommandLine::NO_PROGRAM);
176 cmd_line.AppendSwitch(switches::kEnableCloudPrintProxy);
177
178 // Call UpdateCommandLinePrefStore and check to see if the value has changed.
179 prefs.UpdateCommandLinePrefStore(&cmd_line);
180 pref = prefs.FindPreference(prefs::kCloudPrintProxyEnabled);
181 ASSERT_TRUE(pref);
182 value = pref->GetValue();
183 ASSERT_TRUE(value);
184 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType());
185 actual_bool_value = false;
186 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value));
[email protected]4eccb81a2012-01-26 12:01:22187 EXPECT_TRUE(actual_bool_value);
[email protected]d3b05ea2012-01-24 22:57:05188}
189
[email protected]ea3e4972012-04-12 03:41:37190class PrefServiceUserFilePrefsTest : public testing::Test {
191 protected:
192 virtual void SetUp() {
193 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
194
195 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_));
196 data_dir_ = data_dir_.AppendASCII("pref_service");
197 ASSERT_TRUE(file_util::PathExists(data_dir_));
198 }
199
200 void ClearListValue(PrefService* prefs, const char* key) {
201 ListPrefUpdate updater(prefs, key);
202 updater->Clear();
203 }
204
205 void ClearDictionaryValue(PrefService* prefs, const char* key) {
206 DictionaryPrefUpdate updater(prefs, key);
207 updater->Clear();
208 }
209
210 // The path to temporary directory used to contain the test operations.
211 ScopedTempDir temp_dir_;
212 // The path to the directory where the test data is stored.
213 FilePath data_dir_;
214 // A message loop that we can use as the file thread message loop.
215 MessageLoop message_loop_;
216};
217
218// Verifies that ListValue and DictionaryValue pref with non emtpy default
219// preserves its empty value.
220TEST_F(PrefServiceUserFilePrefsTest, PreserveEmptyValue) {
221 FilePath pref_file = temp_dir_.path().AppendASCII("write.json");
222
223 ASSERT_TRUE(file_util::CopyFile(
224 data_dir_.AppendASCII("read.need_empty_value.json"),
225 pref_file));
226
227 PrefServiceMockBuilder builder;
228 builder.WithUserFilePrefs(pref_file, base::MessageLoopProxy::current());
229 scoped_ptr<PrefService> prefs(builder.Create());
230
231 // Register testing prefs.
232 prefs->RegisterListPref("list",
233 PrefService::UNSYNCABLE_PREF);
234 prefs->RegisterDictionaryPref("dict",
235 PrefService::UNSYNCABLE_PREF);
236
237 base::ListValue* non_empty_list = new base::ListValue;
238 non_empty_list->Append(base::Value::CreateStringValue("test"));
239 prefs->RegisterListPref("list_needs_empty_value",
240 non_empty_list,
241 PrefService::UNSYNCABLE_PREF);
242
243 base::DictionaryValue* non_empty_dict = new base::DictionaryValue;
244 non_empty_dict->SetString("dummy", "whatever");
245 prefs->RegisterDictionaryPref("dict_needs_empty_value",
246 non_empty_dict,
247 PrefService::UNSYNCABLE_PREF);
248
249 // Set all testing prefs to empty.
250 ClearListValue(prefs.get(), "list");
251 ClearListValue(prefs.get(), "list_needs_empty_value");
252 ClearDictionaryValue(prefs.get(), "dict");
253 ClearDictionaryValue(prefs.get(), "dict_needs_empty_value");
254
255 // Write to file.
256 prefs->CommitPendingWrite();
257 MessageLoop::current()->RunAllPending();
258
259 // Compare to expected output.
260 FilePath golden_output_file =
261 data_dir_.AppendASCII("write.golden.need_empty_value.json");
262 ASSERT_TRUE(file_util::PathExists(golden_output_file));
263 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file));
264}
265
[email protected]ecde2742010-04-02 17:36:18266class PrefServiceSetValueTest : public testing::Test {
267 protected:
[email protected]12a3c022010-11-03 10:24:11268 static const char kName[];
269 static const char kValue[];
[email protected]ecde2742010-04-02 17:36:18270
[email protected]74379bc52010-07-21 13:54:08271 TestingPrefService prefs_;
[email protected]acd78969c2010-12-08 09:49:11272 PrefObserverMock observer_;
[email protected]ecde2742010-04-02 17:36:18273};
[email protected]ddd231e2010-06-29 20:35:19274
[email protected]12a3c022010-11-03 10:24:11275const char PrefServiceSetValueTest::kName[] = "name";
276const char PrefServiceSetValueTest::kValue[] = "value";
[email protected]ecde2742010-04-02 17:36:18277
278TEST_F(PrefServiceSetValueTest, SetStringValue) {
[email protected]20ce516d2010-06-18 02:20:04279 const char default_string[] = "default";
[email protected]acd78969c2010-12-08 09:49:11280 const StringValue default_value(default_string);
[email protected]12a3c022010-11-03 10:24:11281 prefs_.RegisterStringPref(kName, default_string);
[email protected]2fb7dc982010-09-29 12:24:28282
283 PrefChangeRegistrar registrar;
284 registrar.Init(&prefs_);
[email protected]12a3c022010-11-03 10:24:11285 registrar.Add(kName, &observer_);
[email protected]2fb7dc982010-09-29 12:24:28286
[email protected]c3b54f372010-09-14 08:25:07287 // Changing the controlling store from default to user triggers notification.
[email protected]acd78969c2010-12-08 09:49:11288 observer_.Expect(&prefs_, kName, &default_value);
289 prefs_.Set(kName, default_value);
[email protected]c3b54f372010-09-14 08:25:07290 Mock::VerifyAndClearExpectations(&observer_);
291
[email protected]acd78969c2010-12-08 09:49:11292 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0);
293 prefs_.Set(kName, default_value);
[email protected]ecde2742010-04-02 17:36:18294 Mock::VerifyAndClearExpectations(&observer_);
295
[email protected]acd78969c2010-12-08 09:49:11296 StringValue new_value(kValue);
297 observer_.Expect(&prefs_, kName, &new_value);
298 prefs_.Set(kName, new_value);
299 Mock::VerifyAndClearExpectations(&observer_);
[email protected]ecde2742010-04-02 17:36:18300}
301
302TEST_F(PrefServiceSetValueTest, SetDictionaryValue) {
[email protected]12a3c022010-11-03 10:24:11303 prefs_.RegisterDictionaryPref(kName);
[email protected]2fb7dc982010-09-29 12:24:28304 PrefChangeRegistrar registrar;
305 registrar.Init(&prefs_);
[email protected]12a3c022010-11-03 10:24:11306 registrar.Add(kName, &observer_);
[email protected]ecde2742010-04-02 17:36:18307
[email protected]acd78969c2010-12-08 09:49:11308 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0);
[email protected]9a8c4022011-01-25 14:25:33309 prefs_.RemoveUserPref(kName);
[email protected]ecde2742010-04-02 17:36:18310 Mock::VerifyAndClearExpectations(&observer_);
311
312 DictionaryValue new_value;
[email protected]12a3c022010-11-03 10:24:11313 new_value.SetString(kName, kValue);
[email protected]acd78969c2010-12-08 09:49:11314 observer_.Expect(&prefs_, kName, &new_value);
[email protected]12a3c022010-11-03 10:24:11315 prefs_.Set(kName, new_value);
[email protected]ecde2742010-04-02 17:36:18316 Mock::VerifyAndClearExpectations(&observer_);
317
[email protected]acd78969c2010-12-08 09:49:11318 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0);
319 prefs_.Set(kName, new_value);
320 Mock::VerifyAndClearExpectations(&observer_);
321
[email protected]9a8c4022011-01-25 14:25:33322 DictionaryValue empty;
323 observer_.Expect(&prefs_, kName, &empty);
324 prefs_.Set(kName, empty);
[email protected]ecde2742010-04-02 17:36:18325 Mock::VerifyAndClearExpectations(&observer_);
[email protected]ecde2742010-04-02 17:36:18326}
327
328TEST_F(PrefServiceSetValueTest, SetListValue) {
[email protected]12a3c022010-11-03 10:24:11329 prefs_.RegisterListPref(kName);
[email protected]2fb7dc982010-09-29 12:24:28330 PrefChangeRegistrar registrar;
331 registrar.Init(&prefs_);
[email protected]12a3c022010-11-03 10:24:11332 registrar.Add(kName, &observer_);
[email protected]ecde2742010-04-02 17:36:18333
[email protected]acd78969c2010-12-08 09:49:11334 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0);
[email protected]9a8c4022011-01-25 14:25:33335 prefs_.RemoveUserPref(kName);
[email protected]ecde2742010-04-02 17:36:18336 Mock::VerifyAndClearExpectations(&observer_);
337
338 ListValue new_value;
[email protected]12a3c022010-11-03 10:24:11339 new_value.Append(Value::CreateStringValue(kValue));
[email protected]acd78969c2010-12-08 09:49:11340 observer_.Expect(&prefs_, kName, &new_value);
[email protected]12a3c022010-11-03 10:24:11341 prefs_.Set(kName, new_value);
[email protected]ecde2742010-04-02 17:36:18342 Mock::VerifyAndClearExpectations(&observer_);
343
[email protected]acd78969c2010-12-08 09:49:11344 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0);
345 prefs_.Set(kName, new_value);
346 Mock::VerifyAndClearExpectations(&observer_);
347
[email protected]9a8c4022011-01-25 14:25:33348 ListValue empty;
349 observer_.Expect(&prefs_, kName, &empty);
350 prefs_.Set(kName, empty);
[email protected]ecde2742010-04-02 17:36:18351 Mock::VerifyAndClearExpectations(&observer_);
[email protected]ecde2742010-04-02 17:36:18352}
[email protected]1bec2372011-12-07 09:19:06353
354class PrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness {
355 protected:
356 PrefServiceWebKitPrefs() : ui_thread_(BrowserThread::UI, &message_loop_) {
357 }
358
359 virtual void SetUp() {
360 ChromeRenderViewHostTestHarness::SetUp();
361
362 // Supply our own profile so we use the correct profile data. The test
363 // harness is not supposed to overwrite a profile if it's already created.
364
365 // Set some (WebKit) user preferences.
366 TestingPrefService* pref_services = profile()->GetTestingPrefService();
[email protected]a13283cc2012-04-05 00:21:22367#if defined(TOOLKIT_GTK)
[email protected]1bec2372011-12-07 09:19:06368 pref_services->SetUserPref(prefs::kUsesSystemTheme,
369 Value::CreateBooleanValue(false));
370#endif
[email protected]ddf72142012-05-22 04:52:40371 pref_services->SetUserPref(prefs::kDefaultCharset,
[email protected]1bec2372011-12-07 09:19:06372 Value::CreateStringValue("utf8"));
[email protected]ddf72142012-05-22 04:52:40373 pref_services->SetUserPref(prefs::kWebKitDefaultFontSize,
[email protected]1bec2372011-12-07 09:19:06374 Value::CreateIntegerValue(20));
375 pref_services->SetUserPref(prefs::kWebKitTextAreasAreResizable,
376 Value::CreateBooleanValue(false));
377 pref_services->SetUserPref(prefs::kWebKitUsesUniversalDetector,
378 Value::CreateBooleanValue(true));
379 pref_services->SetUserPref("webkit.webprefs.foo",
380 Value::CreateStringValue("bar"));
381 }
382
383 private:
384 content::TestBrowserThread ui_thread_;
385};
386
387// Tests to see that webkit preferences are properly loaded and copied over
388// to a WebPreferences object.
389TEST_F(PrefServiceWebKitPrefs, PrefsCopied) {
[email protected]6717bf272012-05-11 23:31:25390 webkit_glue::WebPreferences webkit_prefs =
[email protected]46a32b92012-03-22 13:04:48391 WebContentsTester::For(contents())->TestGetWebkitPrefs();
[email protected]1bec2372011-12-07 09:19:06392
393 // These values have been overridden by the profile preferences.
394 EXPECT_EQ("UTF-8", webkit_prefs.default_encoding);
395 EXPECT_EQ(20, webkit_prefs.default_font_size);
396 EXPECT_FALSE(webkit_prefs.text_areas_are_resizable);
397 EXPECT_TRUE(webkit_prefs.uses_universal_detector);
398
399 // These should still be the default values.
400#if defined(OS_MACOSX)
401 const char kDefaultFont[] = "Times";
402#elif defined(OS_CHROMEOS)
403 const char kDefaultFont[] = "Tinos";
404#else
405 const char kDefaultFont[] = "Times New Roman";
406#endif
[email protected]966d1e12012-05-18 07:20:32407 EXPECT_EQ(ASCIIToUTF16(kDefaultFont),
408 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]);
[email protected]1bec2372011-12-07 09:19:06409 EXPECT_TRUE(webkit_prefs.javascript_enabled);
410}