1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "dbus/values_util.h"
15 #include "base/json/json_writer.h"
16 #include "base/values.h"
17 #include "dbus/message.h"
18 #include "testing/gtest/include/gtest/gtest.h"
22 TEST(ValuesUtilTest, PopBasicTypes) {
23 std::unique_ptr<Response> response(Response::CreateEmpty());
24 // Append basic type values.
25 MessageWriter writer(response.get());
26 const uint8_t kByteValue = 42;
27 writer.AppendByte(kByteValue);
28 const bool kBoolValue = true;
29 writer.AppendBool(kBoolValue);
30 const int16_t kInt16Value = -43;
31 writer.AppendInt16(kInt16Value);
32 const uint16_t kUint16Value = 44;
33 writer.AppendUint16(kUint16Value);
34 const int32_t kInt32Value = -45;
35 writer.AppendInt32(kInt32Value);
36 const uint32_t kUint32Value = 46;
37 writer.AppendUint32(kUint32Value);
38 const int64_t kInt64Value = -47;
39 writer.AppendInt64(kInt64Value);
40 const uint64_t kUint64Value = 48;
41 writer.AppendUint64(kUint64Value);
42 const double kDoubleValue = 4.9;
43 writer.AppendDouble(kDoubleValue);
44 const std::string kStringValue = "fifty";
45 writer.AppendString(kStringValue);
46 const std::string kEmptyStringValue;
47 writer.AppendString(kEmptyStringValue);
48 const ObjectPath kObjectPathValue("/ObjectPath");
49 writer.AppendObjectPath(kObjectPathValue);
51 MessageReader reader(response.get());
54 value = PopDataAsValue(&reader);
55 ASSERT_FALSE(value.is_none());
56 EXPECT_EQ(value, base::Value(kByteValue));
58 value = PopDataAsValue(&reader);
59 ASSERT_FALSE(value.is_none());
60 EXPECT_EQ(value, base::Value(kBoolValue));
62 value = PopDataAsValue(&reader);
63 ASSERT_FALSE(value.is_none());
64 EXPECT_EQ(value, base::Value(kInt16Value));
66 value = PopDataAsValue(&reader);
67 ASSERT_FALSE(value.is_none());
68 EXPECT_EQ(value, base::Value(kUint16Value));
70 value = PopDataAsValue(&reader);
71 ASSERT_FALSE(value.is_none());
72 EXPECT_EQ(value, base::Value(kInt32Value));
74 value = PopDataAsValue(&reader);
75 ASSERT_FALSE(value.is_none());
76 EXPECT_EQ(value, base::Value(static_cast<double>(kUint32Value)));
78 value = PopDataAsValue(&reader);
79 ASSERT_FALSE(value.is_none());
80 EXPECT_EQ(value, base::Value(static_cast<double>(kInt64Value)));
82 value = PopDataAsValue(&reader);
83 ASSERT_FALSE(value.is_none());
84 EXPECT_EQ(value, base::Value(static_cast<double>(kUint64Value)));
86 value = PopDataAsValue(&reader);
87 ASSERT_FALSE(value.is_none());
88 EXPECT_EQ(value, base::Value(kDoubleValue));
90 value = PopDataAsValue(&reader);
91 ASSERT_FALSE(value.is_none());
92 EXPECT_EQ(value, base::Value(kStringValue));
93 // Pop an empty string.
94 value = PopDataAsValue(&reader);
95 ASSERT_FALSE(value.is_none());
96 EXPECT_EQ(value, base::Value(kEmptyStringValue));
97 // Pop an object path.
98 value = PopDataAsValue(&reader);
99 ASSERT_FALSE(value.is_none());
100 EXPECT_EQ(value, base::Value(kObjectPathValue.value()));
103 TEST(ValuesUtilTest, PopVariant) {
104 std::unique_ptr<Response> response(Response::CreateEmpty());
105 // Append variant values.
106 MessageWriter writer(response.get());
107 const bool kBoolValue = true;
108 writer.AppendVariantOfBool(kBoolValue);
109 const int32_t kInt32Value = -45;
110 writer.AppendVariantOfInt32(kInt32Value);
111 const double kDoubleValue = 4.9;
112 writer.AppendVariantOfDouble(kDoubleValue);
113 const std::string kStringValue = "fifty";
114 writer.AppendVariantOfString(kStringValue);
116 MessageReader reader(response.get());
119 value = PopDataAsValue(&reader);
120 ASSERT_FALSE(value.is_none());
121 EXPECT_EQ(value, base::Value(kBoolValue));
123 value = PopDataAsValue(&reader);
124 ASSERT_FALSE(value.is_none());
125 EXPECT_EQ(value, base::Value(kInt32Value));
127 value = PopDataAsValue(&reader);
128 ASSERT_FALSE(value.is_none());
129 EXPECT_EQ(value, base::Value(kDoubleValue));
131 value = PopDataAsValue(&reader);
132 ASSERT_FALSE(value.is_none());
133 EXPECT_EQ(value, base::Value(kStringValue));
136 // Pop extremely large integers which cannot be precisely represented in
138 TEST(ValuesUtilTest, PopExtremelyLargeIntegers) {
139 std::unique_ptr<Response> response(Response::CreateEmpty());
140 // Append large integers.
141 MessageWriter writer(response.get());
142 const int64_t kInt64Value = -123456789012345689LL;
143 writer.AppendInt64(kInt64Value);
144 const uint64_t kUint64Value = 9876543210987654321ULL;
145 writer.AppendUint64(kUint64Value);
147 MessageReader reader(response.get());
150 value = PopDataAsValue(&reader);
151 ASSERT_FALSE(value.is_none());
152 EXPECT_EQ(value, base::Value(static_cast<double>(kInt64Value)));
153 ASSERT_TRUE(value.is_double());
154 EXPECT_NE(kInt64Value, static_cast<int64_t>(value.GetDouble()));
156 value = PopDataAsValue(&reader);
157 ASSERT_FALSE(value.is_none());
158 EXPECT_EQ(value, base::Value(static_cast<double>(kUint64Value)));
159 ASSERT_TRUE(value.is_double());
160 EXPECT_NE(kUint64Value, static_cast<uint64_t>(value.GetDouble()));
163 TEST(ValuesUtilTest, PopIntArray) {
164 std::unique_ptr<Response> response(Response::CreateEmpty());
165 // Append an int32_t array.
166 MessageWriter writer(response.get());
167 MessageWriter sub_writer(nullptr);
168 std::vector<int32_t> data;
172 writer.OpenArray("i", &sub_writer);
173 for (size_t i = 0; i != data.size(); ++i)
174 sub_writer.AppendInt32(data[i]);
175 writer.CloseContainer(&sub_writer);
177 // Create the expected value.
178 base::Value::List list_value;
179 for (size_t i = 0; i != data.size(); ++i)
180 list_value.Append(data[i]);
182 // Pop an int32_t array.
183 MessageReader reader(response.get());
184 base::Value value(PopDataAsValue(&reader));
185 ASSERT_FALSE(value.is_none());
186 EXPECT_EQ(value, list_value);
189 TEST(ValuesUtilTest, PopStringArray) {
190 std::unique_ptr<Response> response(Response::CreateEmpty());
191 // Append a string array.
192 MessageWriter writer(response.get());
193 MessageWriter sub_writer(nullptr);
194 std::vector<std::string> data;
195 data.push_back("Dreamlifter");
196 data.push_back("Beluga");
197 data.push_back("Mriya");
198 writer.AppendArrayOfStrings(data);
200 // Create the expected value.
201 base::Value::List list_value;
202 for (size_t i = 0; i != data.size(); ++i)
203 list_value.Append(data[i]);
205 // Pop a string array.
206 MessageReader reader(response.get());
207 base::Value value(PopDataAsValue(&reader));
208 ASSERT_FALSE(value.is_none());
209 EXPECT_EQ(value, list_value);
212 TEST(ValuesUtilTest, PopStruct) {
213 std::unique_ptr<Response> response(Response::CreateEmpty());
215 MessageWriter writer(response.get());
216 MessageWriter sub_writer(nullptr);
217 writer.OpenStruct(&sub_writer);
218 const bool kBoolValue = true;
219 sub_writer.AppendBool(kBoolValue);
220 const int32_t kInt32Value = -123;
221 sub_writer.AppendInt32(kInt32Value);
222 const double kDoubleValue = 1.23;
223 sub_writer.AppendDouble(kDoubleValue);
224 const std::string kStringValue = "one two three";
225 sub_writer.AppendString(kStringValue);
226 writer.CloseContainer(&sub_writer);
228 // Create the expected value.
229 base::Value::List list_value;
230 list_value.Append(kBoolValue);
231 list_value.Append(kInt32Value);
232 list_value.Append(kDoubleValue);
233 list_value.Append(kStringValue);
236 MessageReader reader(response.get());
237 base::Value value(PopDataAsValue(&reader));
238 ASSERT_FALSE(value.is_none());
239 EXPECT_EQ(value, list_value);
242 TEST(ValuesUtilTest, PopStringToVariantDictionary) {
243 std::unique_ptr<Response> response(Response::CreateEmpty());
244 // Append a dictionary.
245 MessageWriter writer(response.get());
246 MessageWriter sub_writer(nullptr);
247 MessageWriter entry_writer(nullptr);
248 writer.OpenArray("{sv}", &sub_writer);
249 sub_writer.OpenDictEntry(&entry_writer);
250 const std::string kKey1 = "one";
251 entry_writer.AppendString(kKey1);
252 const bool kBoolValue = true;
253 entry_writer.AppendVariantOfBool(kBoolValue);
254 sub_writer.CloseContainer(&entry_writer);
255 sub_writer.OpenDictEntry(&entry_writer);
256 const std::string kKey2 = "two";
257 entry_writer.AppendString(kKey2);
258 const int32_t kInt32Value = -45;
259 entry_writer.AppendVariantOfInt32(kInt32Value);
260 sub_writer.CloseContainer(&entry_writer);
261 sub_writer.OpenDictEntry(&entry_writer);
262 const std::string kKey3 = "three";
263 entry_writer.AppendString(kKey3);
264 const double kDoubleValue = 4.9;
265 entry_writer.AppendVariantOfDouble(kDoubleValue);
266 sub_writer.CloseContainer(&entry_writer);
267 sub_writer.OpenDictEntry(&entry_writer);
268 const std::string kKey4 = "four";
269 entry_writer.AppendString(kKey4);
270 const std::string kStringValue = "fifty";
271 entry_writer.AppendVariantOfString(kStringValue);
272 sub_writer.CloseContainer(&entry_writer);
273 writer.CloseContainer(&sub_writer);
275 // Create the expected value.
276 base::Value::Dict dictionary_value;
277 dictionary_value.Set(kKey1, kBoolValue);
278 dictionary_value.Set(kKey2, kInt32Value);
279 dictionary_value.Set(kKey3, kDoubleValue);
280 dictionary_value.Set(kKey4, kStringValue);
283 MessageReader reader(response.get());
284 base::Value value(PopDataAsValue(&reader));
285 ASSERT_FALSE(value.is_none());
286 EXPECT_EQ(value, dictionary_value);
289 TEST(ValuesUtilTest, PopDictionaryWithDottedStringKey) {
290 std::unique_ptr<Response> response(Response::CreateEmpty());
291 // Append a dictionary.
292 MessageWriter writer(response.get());
293 MessageWriter sub_writer(nullptr);
294 MessageWriter entry_writer(nullptr);
295 writer.OpenArray("{sv}", &sub_writer);
296 sub_writer.OpenDictEntry(&entry_writer);
297 const std::string kKey1 = "www.example.com"; // String including dots.
298 entry_writer.AppendString(kKey1);
299 const bool kBoolValue = true;
300 entry_writer.AppendVariantOfBool(kBoolValue);
301 sub_writer.CloseContainer(&entry_writer);
302 sub_writer.OpenDictEntry(&entry_writer);
303 const std::string kKey2 = ".example"; // String starting with a dot.
304 entry_writer.AppendString(kKey2);
305 const int32_t kInt32Value = -45;
306 entry_writer.AppendVariantOfInt32(kInt32Value);
307 sub_writer.CloseContainer(&entry_writer);
308 sub_writer.OpenDictEntry(&entry_writer);
309 const std::string kKey3 = "example."; // String ending with a dot.
310 entry_writer.AppendString(kKey3);
311 const double kDoubleValue = 4.9;
312 entry_writer.AppendVariantOfDouble(kDoubleValue);
313 sub_writer.CloseContainer(&entry_writer);
314 writer.CloseContainer(&sub_writer);
316 // Create the expected value.
317 base::Value::Dict dictionary_value;
318 dictionary_value.Set(kKey1, kBoolValue);
319 dictionary_value.Set(kKey2, kInt32Value);
320 dictionary_value.Set(kKey3, kDoubleValue);
323 MessageReader reader(response.get());
324 base::Value value(PopDataAsValue(&reader));
325 ASSERT_FALSE(value.is_none());
326 EXPECT_EQ(value, dictionary_value);
329 TEST(ValuesUtilTest, PopDoubleToIntDictionary) {
331 const int32_t kValues[] = {0, 1, 1, 2, 3, 5, 8, 13, 21};
332 const std::vector<int32_t> values(kValues, kValues + std::size(kValues));
333 std::vector<double> keys(values.size());
334 for (size_t i = 0; i != values.size(); ++i)
335 keys[i] = std::sqrt(values[i]);
337 // Append a dictionary.
338 std::unique_ptr<Response> response(Response::CreateEmpty());
339 MessageWriter writer(response.get());
340 MessageWriter sub_writer(nullptr);
341 writer.OpenArray("{di}", &sub_writer);
342 for (size_t i = 0; i != values.size(); ++i) {
343 MessageWriter entry_writer(nullptr);
344 sub_writer.OpenDictEntry(&entry_writer);
345 entry_writer.AppendDouble(keys[i]);
346 entry_writer.AppendInt32(values[i]);
347 sub_writer.CloseContainer(&entry_writer);
349 writer.CloseContainer(&sub_writer);
351 // Create the expected value.
352 base::Value::Dict dictionary_value;
353 for (size_t i = 0; i != values.size(); ++i) {
354 std::string key_string;
355 base::JSONWriter::Write(base::Value(keys[i]), &key_string);
356 dictionary_value.Set(key_string, values[i]);
360 MessageReader reader(response.get());
361 base::Value value(PopDataAsValue(&reader));
362 ASSERT_FALSE(value.is_none());
363 EXPECT_EQ(value, dictionary_value);
366 TEST(ValuesUtilTest, AppendBasicTypes) {
367 const base::Value kBoolValue(false);
368 const base::Value kIntegerValue(42);
369 const base::Value kDoubleValue(4.2);
370 const base::Value kStringValue("string");
372 std::unique_ptr<Response> response(Response::CreateEmpty());
373 MessageWriter writer(response.get());
374 AppendBasicTypeValueData(&writer, kBoolValue);
375 AppendBasicTypeValueData(&writer, kIntegerValue);
376 AppendBasicTypeValueData(&writer, kDoubleValue);
377 AppendBasicTypeValueData(&writer, kStringValue);
379 MessageReader reader(response.get());
381 value = PopDataAsValue(&reader);
382 ASSERT_FALSE(value.is_none());
383 EXPECT_EQ(value, kBoolValue);
384 value = PopDataAsValue(&reader);
385 ASSERT_FALSE(value.is_none());
386 EXPECT_EQ(value, kIntegerValue);
387 value = PopDataAsValue(&reader);
388 ASSERT_FALSE(value.is_none());
389 EXPECT_EQ(value, kDoubleValue);
390 value = PopDataAsValue(&reader);
391 ASSERT_FALSE(value.is_none());
392 EXPECT_EQ(value, kStringValue);
395 TEST(ValuesUtilTest, AppendBasicTypesAsVariant) {
396 const base::Value kBoolValue(false);
397 const base::Value kIntegerValue(42);
398 const base::Value kDoubleValue(4.2);
399 const base::Value kStringValue("string");
401 std::unique_ptr<Response> response(Response::CreateEmpty());
402 MessageWriter writer(response.get());
403 AppendBasicTypeValueDataAsVariant(&writer, kBoolValue);
404 AppendBasicTypeValueDataAsVariant(&writer, kIntegerValue);
405 AppendBasicTypeValueDataAsVariant(&writer, kDoubleValue);
406 AppendBasicTypeValueDataAsVariant(&writer, kStringValue);
408 MessageReader reader(response.get());
410 value = PopDataAsValue(&reader);
411 ASSERT_FALSE(value.is_none());
412 EXPECT_EQ(value, kBoolValue);
413 value = PopDataAsValue(&reader);
414 ASSERT_FALSE(value.is_none());
415 EXPECT_EQ(value, kIntegerValue);
416 value = PopDataAsValue(&reader);
417 ASSERT_FALSE(value.is_none());
418 EXPECT_EQ(value, kDoubleValue);
419 value = PopDataAsValue(&reader);
420 ASSERT_FALSE(value.is_none());
421 EXPECT_EQ(value, kStringValue);
424 TEST(ValuesUtilTest, AppendValueDataBasicTypes) {
425 const base::Value kBoolValue(false);
426 const base::Value kIntegerValue(42);
427 const base::Value kDoubleValue(4.2);
428 const base::Value kStringValue("string");
430 std::unique_ptr<Response> response(Response::CreateEmpty());
431 MessageWriter writer(response.get());
432 AppendValueData(&writer, kBoolValue);
433 AppendValueData(&writer, kIntegerValue);
434 AppendValueData(&writer, kDoubleValue);
435 AppendValueData(&writer, kStringValue);
437 MessageReader reader(response.get());
439 value = PopDataAsValue(&reader);
440 ASSERT_FALSE(value.is_none());
441 EXPECT_EQ(value, kBoolValue);
442 value = PopDataAsValue(&reader);
443 ASSERT_FALSE(value.is_none());
444 EXPECT_EQ(value, kIntegerValue);
445 value = PopDataAsValue(&reader);
446 ASSERT_FALSE(value.is_none());
447 EXPECT_EQ(value, kDoubleValue);
448 value = PopDataAsValue(&reader);
449 ASSERT_FALSE(value.is_none());
450 EXPECT_EQ(value, kStringValue);
453 TEST(ValuesUtilTest, AppendValueDataAsVariantBasicTypes) {
454 const base::Value kBoolValue(false);
455 const base::Value kIntegerValue(42);
456 const base::Value kDoubleValue(4.2);
457 const base::Value kStringValue("string");
459 std::unique_ptr<Response> response(Response::CreateEmpty());
460 MessageWriter writer(response.get());
461 AppendValueDataAsVariant(&writer, kBoolValue);
462 AppendValueDataAsVariant(&writer, kIntegerValue);
463 AppendValueDataAsVariant(&writer, kDoubleValue);
464 AppendValueDataAsVariant(&writer, kStringValue);
466 MessageReader reader(response.get());
468 value = PopDataAsValue(&reader);
469 ASSERT_FALSE(value.is_none());
470 EXPECT_EQ(value, kBoolValue);
471 value = PopDataAsValue(&reader);
472 ASSERT_FALSE(value.is_none());
473 EXPECT_EQ(value, kIntegerValue);
474 value = PopDataAsValue(&reader);
475 ASSERT_FALSE(value.is_none());
476 EXPECT_EQ(value, kDoubleValue);
477 value = PopDataAsValue(&reader);
478 ASSERT_FALSE(value.is_none());
479 EXPECT_EQ(value, kStringValue);
482 TEST(ValuesUtilTest, AppendDictionary) {
483 // Set up the input dictionary.
484 const std::string kKey1 = "one";
485 const std::string kKey2 = "two";
486 const std::string kKey3 = "three";
487 const std::string kKey4 = "four";
488 const std::string kKey5 = "five";
489 const std::string kKey6 = "six";
491 const bool kBoolValue = true;
492 const int32_t kInt32Value = -45;
493 const double kDoubleValue = 4.9;
494 const std::string kStringValue = "fifty";
496 base::Value::List list_value;
497 list_value.Append(kBoolValue);
498 list_value.Append(kInt32Value);
500 base::Value::Dict dictionary_value;
501 dictionary_value.Set(kKey1, kBoolValue);
502 dictionary_value.Set(kKey2, kDoubleValue);
504 base::Value::Dict test_dictionary;
505 test_dictionary.Set(kKey1, kBoolValue);
506 test_dictionary.Set(kKey2, kInt32Value);
507 test_dictionary.Set(kKey3, kDoubleValue);
508 test_dictionary.Set(kKey4, kStringValue);
509 test_dictionary.Set(kKey5, std::move(list_value));
510 test_dictionary.Set(kKey6, std::move(dictionary_value));
512 std::unique_ptr<Response> response(Response::CreateEmpty());
513 MessageWriter writer(response.get());
514 AppendValueData(&writer, test_dictionary);
515 base::Value int_value(kInt32Value);
516 AppendValueData(&writer, int_value);
519 MessageReader reader(response.get());
521 value = PopDataAsValue(&reader);
522 ASSERT_FALSE(value.is_none());
523 EXPECT_EQ(value, test_dictionary);
524 value = PopDataAsValue(&reader);
525 ASSERT_FALSE(value.is_none());
526 EXPECT_EQ(value, int_value);
529 TEST(ValuesUtilTest, AppendDictionaryAsVariant) {
530 // Set up the input dictionary.
531 const std::string kKey1 = "one";
532 const std::string kKey2 = "two";
533 const std::string kKey3 = "three";
534 const std::string kKey4 = "four";
535 const std::string kKey5 = "five";
536 const std::string kKey6 = "six";
538 const bool kBoolValue = true;
539 const int32_t kInt32Value = -45;
540 const double kDoubleValue = 4.9;
541 const std::string kStringValue = "fifty";
543 base::Value::List list_value;
544 list_value.Append(kBoolValue);
545 list_value.Append(kInt32Value);
547 base::Value::Dict dictionary_value;
548 dictionary_value.Set(kKey1, kBoolValue);
549 dictionary_value.Set(kKey2, kDoubleValue);
551 base::Value::Dict test_dictionary;
552 test_dictionary.Set(kKey1, kBoolValue);
553 test_dictionary.Set(kKey2, kInt32Value);
554 test_dictionary.Set(kKey3, kDoubleValue);
555 test_dictionary.Set(kKey4, kStringValue);
556 test_dictionary.Set(kKey5, std::move(list_value));
557 test_dictionary.Set(kKey6, std::move(dictionary_value));
559 std::unique_ptr<Response> response(Response::CreateEmpty());
560 MessageWriter writer(response.get());
561 AppendValueDataAsVariant(&writer, test_dictionary);
562 base::Value int_value(kInt32Value);
563 AppendValueData(&writer, int_value);
566 MessageReader reader(response.get());
568 value = PopDataAsValue(&reader);
569 ASSERT_FALSE(value.is_none());
570 EXPECT_EQ(value, test_dictionary);
571 value = PopDataAsValue(&reader);
572 ASSERT_FALSE(value.is_none());
573 EXPECT_EQ(value, int_value);
576 TEST(ValuesUtilTest, AppendList) {
577 // Set up the input list.
578 const std::string kKey1 = "one";
579 const std::string kKey2 = "two";
581 const bool kBoolValue = true;
582 const int32_t kInt32Value = -45;
583 const double kDoubleValue = 4.9;
584 const std::string kStringValue = "fifty";
586 base::Value::List list_value;
587 list_value.Append(kBoolValue);
588 list_value.Append(kInt32Value);
590 base::Value::Dict dictionary_value;
591 dictionary_value.Set(kKey1, kBoolValue);
592 dictionary_value.Set(kKey2, kDoubleValue);
594 base::Value::List test_list;
595 test_list.Append(kBoolValue);
596 test_list.Append(kInt32Value);
597 test_list.Append(kDoubleValue);
598 test_list.Append(kStringValue);
599 test_list.Append(std::move(list_value));
600 test_list.Append(std::move(dictionary_value));
602 std::unique_ptr<Response> response(Response::CreateEmpty());
603 MessageWriter writer(response.get());
604 AppendValueData(&writer, test_list);
605 base::Value int_value(kInt32Value);
606 AppendValueData(&writer, int_value);
609 MessageReader reader(response.get());
611 value = PopDataAsValue(&reader);
612 ASSERT_FALSE(value.is_none());
613 EXPECT_EQ(value, test_list);
614 value = PopDataAsValue(&reader);
615 ASSERT_FALSE(value.is_none());
616 EXPECT_EQ(value, int_value);
619 TEST(ValuesUtilTest, AppendListAsVariant) {
620 // Set up the input list.
621 const std::string kKey1 = "one";
622 const std::string kKey2 = "two";
624 const bool kBoolValue = true;
625 const int32_t kInt32Value = -45;
626 const double kDoubleValue = 4.9;
627 const std::string kStringValue = "fifty";
629 base::Value::List list_value;
630 list_value.Append(kBoolValue);
631 list_value.Append(kInt32Value);
633 base::Value::Dict dictionary_value;
634 dictionary_value.Set(kKey1, kBoolValue);
635 dictionary_value.Set(kKey2, kDoubleValue);
637 base::Value::List test_list;
638 test_list.Append(kBoolValue);
639 test_list.Append(kInt32Value);
640 test_list.Append(kDoubleValue);
641 test_list.Append(kStringValue);
642 test_list.Append(std::move(list_value));
643 test_list.Append(std::move(dictionary_value));
645 std::unique_ptr<Response> response(Response::CreateEmpty());
646 MessageWriter writer(response.get());
647 AppendValueDataAsVariant(&writer, test_list);
648 base::Value int_value(kInt32Value);
649 AppendValueData(&writer, int_value);
652 MessageReader reader(response.get());
654 value = PopDataAsValue(&reader);
655 ASSERT_FALSE(value.is_none());
656 EXPECT_EQ(value, test_list);
657 value = PopDataAsValue(&reader);
658 ASSERT_FALSE(value.is_none());
659 EXPECT_EQ(value, int_value);