Index: base/prefs/json_pref_store_unittest.cc |
diff --git a/base/prefs/json_pref_store_unittest.cc b/base/prefs/json_pref_store_unittest.cc |
index 34e1b8a9ede63dcf76b4b5edeaa242c180f1bc8b..a26afd71375ebe3a7654ec042a67caf763c4f2e0 100644 |
--- a/base/prefs/json_pref_store_unittest.cc |
+++ b/base/prefs/json_pref_store_unittest.cc |
@@ -216,6 +216,33 @@ TEST_F(JsonPrefStoreTest, BasicAsync) { |
pref_store.get(), input_file, data_dir_.AppendASCII("write.golden.json")); |
} |
+TEST_F(JsonPrefStoreTest, PreserveEmptyValues) { |
+ FilePath pref_file = temp_dir_.path().AppendASCII("empty_values.json"); |
+ |
+ scoped_refptr<JsonPrefStore> pref_store = |
+ new JsonPrefStore(pref_file, message_loop_.message_loop_proxy()); |
+ |
+ // Set some keys with empty values. |
+ pref_store->SetValue("list", new base::ListValue); |
+ pref_store->SetValue("dict", new base::DictionaryValue); |
+ |
+ // Write to file. |
+ pref_store->CommitPendingWrite(); |
+ MessageLoop::current()->RunUntilIdle(); |
+ |
+ // Reload. |
+ pref_store = new JsonPrefStore(pref_file, message_loop_.message_loop_proxy()); |
+ ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs()); |
+ ASSERT_FALSE(pref_store->ReadOnly()); |
+ |
+ // Check values. |
+ const Value* result = NULL; |
+ EXPECT_TRUE(pref_store->GetValue("list", &result)); |
+ EXPECT_TRUE(ListValue().Equals(result)); |
+ EXPECT_TRUE(pref_store->GetValue("dict", &result)); |
+ EXPECT_TRUE(DictionaryValue().Equals(result)); |
+} |
+ |
// Tests asynchronous reading of the file when there is no file. |
TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) { |
base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt"); |
@@ -237,51 +264,4 @@ TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) { |
EXPECT_FALSE(pref_store->ReadOnly()); |
} |
-TEST_F(JsonPrefStoreTest, NeedsEmptyValue) { |
- base::FilePath pref_file = temp_dir_.path().AppendASCII("write.json"); |
- |
- ASSERT_TRUE(base::CopyFile( |
- data_dir_.AppendASCII("read.need_empty_value.json"), |
- pref_file)); |
- |
- // Test that the persistent value can be loaded. |
- ASSERT_TRUE(PathExists(pref_file)); |
- scoped_refptr<JsonPrefStore> pref_store = |
- new JsonPrefStore(pref_file, message_loop_.message_loop_proxy().get()); |
- ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs()); |
- ASSERT_FALSE(pref_store->ReadOnly()); |
- |
- // The JSON file looks like this: |
- // { |
- // "list": [ 1 ], |
- // "list_needs_empty_value": [ 2 ], |
- // "dict": { |
- // "dummy": true, |
- // }, |
- // "dict_needs_empty_value": { |
- // "dummy": true, |
- // }, |
- // } |
- |
- // Set flag to preserve empty values for the following keys. |
- pref_store->MarkNeedsEmptyValue("list_needs_empty_value"); |
- pref_store->MarkNeedsEmptyValue("dict_needs_empty_value"); |
- |
- // Set all keys to empty values. |
- pref_store->SetValue("list", new base::ListValue); |
- pref_store->SetValue("list_needs_empty_value", new base::ListValue); |
- pref_store->SetValue("dict", new base::DictionaryValue); |
- pref_store->SetValue("dict_needs_empty_value", new base::DictionaryValue); |
- |
- // Write to file. |
- pref_store->CommitPendingWrite(); |
- RunLoop().RunUntilIdle(); |
- |
- // Compare to expected output. |
- base::FilePath golden_output_file = |
- data_dir_.AppendASCII("write.golden.need_empty_value.json"); |
- ASSERT_TRUE(PathExists(golden_output_file)); |
- EXPECT_TRUE(TextContentsEqual(golden_output_file, pref_file)); |
-} |
- |
} // namespace base |