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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/json/json_writer.h" 5 #include "base/json/json_writer.h"
6 #include "base/values.h" 6 #include "base/values.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace base { 9 namespace base {
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 Value::CreateIntegerValue(1)); 86 Value::CreateIntegerValue(1));
87 period_dict.SetWithoutPathExpansion("d.e.f", period_dict2); 87 period_dict.SetWithoutPathExpansion("d.e.f", period_dict2);
88 JSONWriter::Write(&period_dict, false, &output_js); 88 JSONWriter::Write(&period_dict, false, &output_js);
89 ASSERT_EQ("{\"a.b\":3,\"c\":2,\"d.e.f\":{\"g.h.i.j\":1}}", output_js); 89 ASSERT_EQ("{\"a.b\":3,\"c\":2,\"d.e.f\":{\"g.h.i.j\":1}}", output_js);
90 90
91 DictionaryValue period_dict3; 91 DictionaryValue period_dict3;
92 period_dict3.Set("a.b", Value::CreateIntegerValue(2)); 92 period_dict3.Set("a.b", Value::CreateIntegerValue(2));
93 period_dict3.SetWithoutPathExpansion("a.b", Value::CreateIntegerValue(1)); 93 period_dict3.SetWithoutPathExpansion("a.b", Value::CreateIntegerValue(1));
94 JSONWriter::Write(&period_dict3, false, &output_js); 94 JSONWriter::Write(&period_dict3, false, &output_js);
95 ASSERT_EQ("{\"a\":{\"b\":2},\"a.b\":1}", output_js); 95 ASSERT_EQ("{\"a\":{\"b\":2},\"a.b\":1}", output_js);
96
97 // Test ignoring binary values.
98 root = BinaryValue::CreateWithCopiedBuffer("asdf", 4);
99 JSONWriter::Write(root, false, JSONWriter::OPTIONS_IGNORE_BINARY_VALUES,
100 &output_js);
101 ASSERT_EQ("", output_js);
102 delete root;
103
104 ListValue binary_list;
105 binary_list.Append(Value::CreateIntegerValue(5));
106 binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4));
107 binary_list.Append(Value::CreateIntegerValue(2));
108 JSONWriter::Write(&binary_list, false,
109 JSONWriter::OPTIONS_IGNORE_BINARY_VALUES, &output_js);
110 ASSERT_EQ("[5,2]", output_js);
111
112 DictionaryValue binary_dict;
113 binary_dict.Set("a", Value::CreateIntegerValue(5));
114 binary_dict.Set("b", BinaryValue::CreateWithCopiedBuffer("asdf", 4));
115 binary_dict.Set("c", Value::CreateIntegerValue(2));
116 JSONWriter::Write(&binary_dict, false,
117 JSONWriter::OPTIONS_IGNORE_BINARY_VALUES, &output_js);
118 ASSERT_EQ("{\"a\":5,\"c\":2}", output_js);
96 } 119 }
97 120
98 } // namespace base 121 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698