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

Unified Diff: base/json/json_writer_unittest.cc

Issue 8505033: Allow JSONWriter and JSONValueSerializer to omit binary values when instructed to do so. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address lint warning. Created 9 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/json/json_writer_unittest.cc
diff --git a/base/json/json_writer_unittest.cc b/base/json/json_writer_unittest.cc
index 6d7714b5aad7fd4f964a2b5fa27839fbe18db51f..dcd30d9686f061d2acd779285320430055a4324a 100644
--- a/base/json/json_writer_unittest.cc
+++ b/base/json/json_writer_unittest.cc
@@ -93,6 +93,29 @@ TEST(JSONWriterTest, Writing) {
period_dict3.SetWithoutPathExpansion("a.b", Value::CreateIntegerValue(1));
JSONWriter::Write(&period_dict3, false, &output_js);
ASSERT_EQ("{\"a\":{\"b\":2},\"a.b\":1}", output_js);
+
+ // Test ignoring binary values.
+ root = BinaryValue::CreateWithCopiedBuffer("asdf", 4);
+ JSONWriter::Write(root, false, JSONWriter::OPTIONS_IGNORE_BINARY_VALUES,
+ &output_js);
+ ASSERT_EQ("", output_js);
+ delete root;
+
+ ListValue binary_list;
+ binary_list.Append(Value::CreateIntegerValue(5));
+ binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4));
+ binary_list.Append(Value::CreateIntegerValue(2));
+ JSONWriter::Write(&binary_list, false,
+ JSONWriter::OPTIONS_IGNORE_BINARY_VALUES, &output_js);
+ ASSERT_EQ("[5,2]", output_js);
+
+ DictionaryValue binary_dict;
+ binary_dict.Set("a", Value::CreateIntegerValue(5));
+ binary_dict.Set("b", BinaryValue::CreateWithCopiedBuffer("asdf", 4));
+ binary_dict.Set("c", Value::CreateIntegerValue(2));
+ JSONWriter::Write(&binary_dict, false,
+ JSONWriter::OPTIONS_IGNORE_BINARY_VALUES, &output_js);
+ ASSERT_EQ("{\"a\":5,\"c\":2}", output_js);
}
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698