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

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: Fix chrome\browser\policy\configuration_policy_handler_chromeos.cc 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
« no previous file with comments | « base/json/json_writer.cc ('k') | chrome/browser/browser_about_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::WriteWithOptions(root, false,
100 JSONWriter::OPTIONS_OMIT_BINARY_VALUES,
101 &output_js);
102 ASSERT_TRUE(output_js.empty());
103 delete root;
104
105 ListValue binary_list;
106 binary_list.Append(Value::CreateIntegerValue(5));
107 binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4));
108 binary_list.Append(Value::CreateIntegerValue(2));
109 JSONWriter::WriteWithOptions(&binary_list, false,
110 JSONWriter::OPTIONS_OMIT_BINARY_VALUES,
111 &output_js);
112 ASSERT_EQ("[5,2]", output_js);
113
114 DictionaryValue binary_dict;
115 binary_dict.Set("a", Value::CreateIntegerValue(5));
116 binary_dict.Set("b", BinaryValue::CreateWithCopiedBuffer("asdf", 4));
117 binary_dict.Set("c", Value::CreateIntegerValue(2));
118 JSONWriter::WriteWithOptions(&binary_dict, false,
119 JSONWriter::OPTIONS_OMIT_BINARY_VALUES,
120 &output_js);
121 ASSERT_EQ("{\"a\":5,\"c\":2}", output_js);
96 } 122 }
97 123
98 } // namespace base 124 } // namespace base
OLDNEW
« no previous file with comments | « base/json/json_writer.cc ('k') | chrome/browser/browser_about_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698