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

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: 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
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..a933ca7e8d69184b037fd0469a0b8857472ebd82 100644
--- a/base/prefs/json_pref_store_unittest.cc
+++ b/base/prefs/json_pref_store_unittest.cc
@@ -216,6 +216,25 @@ 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");
+
+ // Test that the persistent value can be loaded.
Mattias Nissler (ping if slow) 2013/11/22 08:03:38 I think this comment is stale.
gab 2013/11/22 23:24:21 Removed.
+ scoped_refptr<JsonPrefStore> pref_store =
+ new JsonPrefStore(pref_file, message_loop_.message_loop_proxy());
Mattias Nissler (ping if slow) 2013/11/22 08:03:38 Looks like there's a merge problem here, the origi
gab 2013/11/22 23:24:21 Oops, merge problem indeed, fixed to be as in http
+ // 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));
+ ListValue().Equals(result);
+ EXPECT_TRUE(pref_store->GetValue("dict", &result));
+ 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 +256,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

Powered by Google App Engine
This is Rietveld 408576698