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

Side by Side Diff: content/common/common_param_traits_unittest.cc

Issue 2838893002: Remove base::ListValue::Set(size_t, base::Value*) (Closed)
Patch Set: Fix Compilation Error Created 3 years, 7 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/public/common/common_param_traits.h" 5 #include "content/public/common/common_param_traits.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 memset(bogus_pixels.get(), 'B', bogus_pixels_size); 81 memset(bogus_pixels.get(), 'B', bogus_pixels_size);
82 bad_msg.WriteData(bogus_pixels.get(), bogus_pixels_size); 82 bad_msg.WriteData(bogus_pixels.get(), bogus_pixels_size);
83 // Make sure we don't read out the bitmap! 83 // Make sure we don't read out the bitmap!
84 SkBitmap bad_output; 84 SkBitmap bad_output;
85 iter = base::PickleIterator(bad_msg); 85 iter = base::PickleIterator(bad_msg);
86 EXPECT_FALSE(IPC::ParamTraits<SkBitmap>::Read(&bad_msg, &iter, &bad_output)); 86 EXPECT_FALSE(IPC::ParamTraits<SkBitmap>::Read(&bad_msg, &iter, &bad_output));
87 } 87 }
88 88
89 TEST(IPCMessageTest, ListValue) { 89 TEST(IPCMessageTest, ListValue) {
90 base::ListValue input; 90 base::ListValue input;
91 input.Set(0, new base::Value(42.42)); 91 input.AppendDouble(42.42);
92 input.Set(1, new base::Value("forty")); 92 input.AppendString("forty");
93 input.Set(2, base::MakeUnique<base::Value>()); 93 input.Append(base::MakeUnique<base::Value>());
94 94
95 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); 95 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
96 IPC::WriteParam(&msg, input); 96 IPC::WriteParam(&msg, input);
97 97
98 base::ListValue output; 98 base::ListValue output;
99 base::PickleIterator iter(msg); 99 base::PickleIterator iter(msg);
100 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); 100 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output));
101 101
102 EXPECT_TRUE(input.Equals(&output)); 102 EXPECT_TRUE(input.Equals(&output));
103 103
104 // Also test the corrupt case. 104 // Also test the corrupt case.
105 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); 105 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
106 bad_msg.WriteInt(99); 106 bad_msg.WriteInt(99);
107 iter = base::PickleIterator(bad_msg); 107 iter = base::PickleIterator(bad_msg);
108 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); 108 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output));
109 } 109 }
110 110
111 TEST(IPCMessageTest, DictionaryValue) { 111 TEST(IPCMessageTest, DictionaryValue) {
112 base::DictionaryValue input; 112 base::DictionaryValue input;
113 input.Set("null", base::MakeUnique<base::Value>()); 113 input.Set("null", base::MakeUnique<base::Value>());
114 input.Set("bool", new base::Value(true)); 114 input.SetBoolean("bool", true);
115 input.Set("int", new base::Value(42)); 115 input.SetInteger("int", 42);
116 116
117 std::unique_ptr<base::DictionaryValue> subdict(new base::DictionaryValue()); 117 auto subdict = base::MakeUnique<base::DictionaryValue>();
118 subdict->Set("str", new base::Value("forty two")); 118 subdict->SetString("str", "forty two");
119 subdict->Set("bool", new base::Value(false)); 119 subdict->SetBoolean("bool", false);
120 120
121 std::unique_ptr<base::ListValue> sublist(new base::ListValue()); 121 auto sublist = base::MakeUnique<base::ListValue>();
122 sublist->Set(0, new base::Value(42.42)); 122 sublist->AppendDouble(42.42);
123 sublist->Set(1, new base::Value("forty")); 123 sublist->AppendString("forty");
124 sublist->Set(2, new base::Value("two")); 124 sublist->AppendString("two");
125 subdict->Set("list", sublist.release()); 125 subdict->Set("list", std::move(sublist));
126 126
127 input.Set("dict", subdict.release()); 127 input.Set("dict", std::move(subdict));
128 128
129 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); 129 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
130 IPC::WriteParam(&msg, input); 130 IPC::WriteParam(&msg, input);
131 131
132 base::DictionaryValue output; 132 base::DictionaryValue output;
133 base::PickleIterator iter(msg); 133 base::PickleIterator iter(msg);
134 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); 134 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output));
135 135
136 EXPECT_TRUE(input.Equals(&output)); 136 EXPECT_TRUE(input.Equals(&output));
137 137
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 out.signed_certificate_timestamps[0].sct->origin); 248 out.signed_certificate_timestamps[0].sct->origin);
249 ASSERT_EQ(in.signed_certificate_timestamps[0].sct->log_description, 249 ASSERT_EQ(in.signed_certificate_timestamps[0].sct->log_description,
250 out.signed_certificate_timestamps[0].sct->log_description); 250 out.signed_certificate_timestamps[0].sct->log_description);
251 251
252 ASSERT_EQ(in.ct_compliance_details_available, 252 ASSERT_EQ(in.ct_compliance_details_available,
253 out.ct_compliance_details_available); 253 out.ct_compliance_details_available);
254 ASSERT_EQ(in.ct_ev_policy_compliance, out.ct_ev_policy_compliance); 254 ASSERT_EQ(in.ct_ev_policy_compliance, out.ct_ev_policy_compliance);
255 ASSERT_EQ(in.ct_cert_policy_compliance, out.ct_cert_policy_compliance); 255 ASSERT_EQ(in.ct_cert_policy_compliance, out.ct_cert_policy_compliance);
256 ASSERT_EQ(in.ocsp_result, out.ocsp_result); 256 ASSERT_EQ(in.ocsp_result, out.ocsp_result);
257 } 257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698