| OLD | NEW |
| 1 // Copyright (c) 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 // The path to temporary directory used to contain the test operations. | 83 // The path to temporary directory used to contain the test operations. |
| 84 base::ScopedTempDir temp_dir_; | 84 base::ScopedTempDir temp_dir_; |
| 85 // The path to the directory where the test data is stored. | 85 // The path to the directory where the test data is stored. |
| 86 base::FilePath data_dir_; | 86 base::FilePath data_dir_; |
| 87 // A message loop that we can use as the file thread message loop. | 87 // A message loop that we can use as the file thread message loop. |
| 88 base::MessageLoop message_loop_; | 88 base::MessageLoop message_loop_; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 // Verifies that ListValue and DictionaryValue pref with non emtpy default | |
| 92 // preserves its empty value. | |
| 93 TEST_F(ChromePrefServiceUserFilePrefsTest, PreserveEmptyValue) { | |
| 94 base::FilePath pref_file = temp_dir_.path().AppendASCII("write.json"); | |
| 95 | |
| 96 ASSERT_TRUE(base::CopyFile( | |
| 97 data_dir_.AppendASCII("read.need_empty_value.json"), | |
| 98 pref_file)); | |
| 99 | |
| 100 PrefServiceMockBuilder builder; | |
| 101 builder.WithUserFilePrefs(pref_file, | |
| 102 message_loop_.message_loop_proxy().get()); | |
| 103 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( | |
| 104 new user_prefs::PrefRegistrySyncable); | |
| 105 scoped_ptr<PrefServiceSyncable> prefs(builder.CreateSyncable(registry.get())); | |
| 106 | |
| 107 // Register testing prefs. | |
| 108 registry->RegisterListPref("list", | |
| 109 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 110 registry->RegisterDictionaryPref( | |
| 111 "dict", | |
| 112 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 113 | |
| 114 base::ListValue* non_empty_list = new base::ListValue; | |
| 115 non_empty_list->Append(base::Value::CreateStringValue("test")); | |
| 116 registry->RegisterListPref("list_needs_empty_value", | |
| 117 non_empty_list, | |
| 118 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 119 | |
| 120 base::DictionaryValue* non_empty_dict = new base::DictionaryValue; | |
| 121 non_empty_dict->SetString("dummy", "whatever"); | |
| 122 registry->RegisterDictionaryPref( | |
| 123 "dict_needs_empty_value", | |
| 124 non_empty_dict, | |
| 125 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 126 | |
| 127 // Set all testing prefs to empty. | |
| 128 ClearListValue(prefs.get(), "list"); | |
| 129 ClearListValue(prefs.get(), "list_needs_empty_value"); | |
| 130 ClearDictionaryValue(prefs.get(), "dict"); | |
| 131 ClearDictionaryValue(prefs.get(), "dict_needs_empty_value"); | |
| 132 | |
| 133 // Write to file. | |
| 134 prefs->CommitPendingWrite(); | |
| 135 message_loop_.RunUntilIdle(); | |
| 136 | |
| 137 // Compare to expected output. | |
| 138 base::FilePath golden_output_file = | |
| 139 data_dir_.AppendASCII("write.golden.need_empty_value.json"); | |
| 140 ASSERT_TRUE(base::PathExists(golden_output_file)); | |
| 141 EXPECT_TRUE(base::TextContentsEqual(golden_output_file, pref_file)); | |
| 142 } | |
| 143 | |
| 144 class ChromePrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness { | 91 class ChromePrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness { |
| 145 protected: | 92 protected: |
| 146 virtual void SetUp() { | 93 virtual void SetUp() { |
| 147 ChromeRenderViewHostTestHarness::SetUp(); | 94 ChromeRenderViewHostTestHarness::SetUp(); |
| 148 | 95 |
| 149 // Supply our own profile so we use the correct profile data. The test | 96 // Supply our own profile so we use the correct profile data. The test |
| 150 // harness is not supposed to overwrite a profile if it's already created. | 97 // harness is not supposed to overwrite a profile if it's already created. |
| 151 | 98 |
| 152 // Set some (WebKit) user preferences. | 99 // Set some (WebKit) user preferences. |
| 153 TestingPrefServiceSyncable* pref_services = | 100 TestingPrefServiceSyncable* pref_services = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 const char kDefaultFont[] = "Times"; | 133 const char kDefaultFont[] = "Times"; |
| 187 #elif defined(OS_CHROMEOS) | 134 #elif defined(OS_CHROMEOS) |
| 188 const char kDefaultFont[] = "Tinos"; | 135 const char kDefaultFont[] = "Tinos"; |
| 189 #else | 136 #else |
| 190 const char kDefaultFont[] = "Times New Roman"; | 137 const char kDefaultFont[] = "Times New Roman"; |
| 191 #endif | 138 #endif |
| 192 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), | 139 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), |
| 193 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); | 140 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); |
| 194 EXPECT_TRUE(webkit_prefs.javascript_enabled); | 141 EXPECT_TRUE(webkit_prefs.javascript_enabled); |
| 195 } | 142 } |
| OLD | NEW |