| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/path_service.h" |
| 11 #include "base/scoped_temp_dir.h" |
| 9 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" | 13 #include "base/values.h" |
| 11 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 14 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 12 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 15 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 13 #include "chrome/browser/prefs/browser_prefs.h" | 16 #include "chrome/browser/prefs/browser_prefs.h" |
| 14 #include "chrome/browser/prefs/command_line_pref_store.h" | 17 #include "chrome/browser/prefs/command_line_pref_store.h" |
| 15 #include "chrome/browser/prefs/pref_change_registrar.h" | 18 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 16 #include "chrome/browser/prefs/pref_observer_mock.h" | 19 #include "chrome/browser/prefs/pref_observer_mock.h" |
| 17 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 20 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
| 18 #include "chrome/browser/prefs/pref_value_store.h" | 21 #include "chrome/browser/prefs/pref_value_store.h" |
| 22 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 19 #include "chrome/browser/prefs/testing_pref_store.h" | 23 #include "chrome/browser/prefs/testing_pref_store.h" |
| 20 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 21 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/json_pref_store.h" |
| 22 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 28 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 24 #include "chrome/test/base/testing_pref_service.h" | 29 #include "chrome/test/base/testing_pref_service.h" |
| 25 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
| 26 #include "content/test/test_browser_thread.h" | 31 #include "content/test/test_browser_thread.h" |
| 27 #include "content/test/web_contents_tester.h" | 32 #include "content/test/web_contents_tester.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "ui/base/test/data/resource.h" | 35 #include "ui/base/test/data/resource.h" |
| 31 #include "webkit/glue/webpreferences.h" | 36 #include "webkit/glue/webpreferences.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 pref = prefs.FindPreference(prefs::kCloudPrintProxyEnabled); | 180 pref = prefs.FindPreference(prefs::kCloudPrintProxyEnabled); |
| 176 ASSERT_TRUE(pref); | 181 ASSERT_TRUE(pref); |
| 177 value = pref->GetValue(); | 182 value = pref->GetValue(); |
| 178 ASSERT_TRUE(value); | 183 ASSERT_TRUE(value); |
| 179 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType()); | 184 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType()); |
| 180 actual_bool_value = false; | 185 actual_bool_value = false; |
| 181 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value)); | 186 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value)); |
| 182 EXPECT_TRUE(actual_bool_value); | 187 EXPECT_TRUE(actual_bool_value); |
| 183 } | 188 } |
| 184 | 189 |
| 190 class 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. |
| 220 TEST_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 |
| 185 class PrefServiceSetValueTest : public testing::Test { | 266 class PrefServiceSetValueTest : public testing::Test { |
| 186 protected: | 267 protected: |
| 187 static const char kName[]; | 268 static const char kName[]; |
| 188 static const char kValue[]; | 269 static const char kValue[]; |
| 189 | 270 |
| 190 TestingPrefService prefs_; | 271 TestingPrefService prefs_; |
| 191 PrefObserverMock observer_; | 272 PrefObserverMock observer_; |
| 192 }; | 273 }; |
| 193 | 274 |
| 194 const char PrefServiceSetValueTest::kName[] = "name"; | 275 const char PrefServiceSetValueTest::kName[] = "name"; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 #if defined(OS_MACOSX) | 400 #if defined(OS_MACOSX) |
| 320 const char kDefaultFont[] = "Times"; | 401 const char kDefaultFont[] = "Times"; |
| 321 #elif defined(OS_CHROMEOS) | 402 #elif defined(OS_CHROMEOS) |
| 322 const char kDefaultFont[] = "Tinos"; | 403 const char kDefaultFont[] = "Tinos"; |
| 323 #else | 404 #else |
| 324 const char kDefaultFont[] = "Times New Roman"; | 405 const char kDefaultFont[] = "Times New Roman"; |
| 325 #endif | 406 #endif |
| 326 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), webkit_prefs.standard_font_family); | 407 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), webkit_prefs.standard_font_family); |
| 327 EXPECT_TRUE(webkit_prefs.javascript_enabled); | 408 EXPECT_TRUE(webkit_prefs.javascript_enabled); |
| 328 } | 409 } |
| OLD | NEW |