diff options
author | ericdingle@chromium.org <ericdingle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-15 02:50:48 +0000 |
---|---|---|
committer | ericdingle@chromium.org <ericdingle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-15 02:50:48 +0000 |
commit | 5f4b64f3dbc358de9b561d4874bf37a2f11bf41b (patch) | |
tree | 85eb30d3066c804f63a1267d575bc62a93bbf34e /base/json/json_writer_unittest.cc | |
parent | 16d57d911df1ea8af40c429eaa9c634f9b51c75d (diff) | |
download | chromium_src-5f4b64f3dbc358de9b561d4874bf37a2f11bf41b.zip chromium_src-5f4b64f3dbc358de9b561d4874bf37a2f11bf41b.tar.gz chromium_src-5f4b64f3dbc358de9b561d4874bf37a2f11bf41b.tar.bz2 |
Allow JSONWriter and JSONValueSerializer to ignore binary values when instructed to do so.
Design discussion is available here: http://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/967eb64325c24f9c
BUG=None
TEST=base_unittests
Review URL: http://codereview.chromium.org/8505033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110021 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/json/json_writer_unittest.cc')
-rw-r--r-- | base/json/json_writer_unittest.cc | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/base/json/json_writer_unittest.cc b/base/json/json_writer_unittest.cc index 6d7714b..5d44c02 100644 --- a/base/json/json_writer_unittest.cc +++ b/base/json/json_writer_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -93,6 +93,32 @@ 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::WriteWithOptions(root, false, + JSONWriter::OPTIONS_OMIT_BINARY_VALUES, + &output_js); + ASSERT_TRUE(output_js.empty()); + 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::WriteWithOptions(&binary_list, false, + JSONWriter::OPTIONS_OMIT_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::WriteWithOptions(&binary_dict, false, + JSONWriter::OPTIONS_OMIT_BINARY_VALUES, + &output_js); + ASSERT_EQ("{\"a\":5,\"c\":2}", output_js); } } // namespace base |