Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1310)

Unified Diff: base/prefs/json_pref_store_unittest.cc

Issue 81183005: Remove JsonPrefStore pruning of empty values on write. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove else Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/prefs/json_pref_store.cc ('k') | base/prefs/overlay_user_pref_store.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « base/prefs/json_pref_store.cc ('k') | base/prefs/overlay_user_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698