| OLD | NEW |
| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 memset(bogus_pixels.get(), 'B', bogus_pixels_size); | 75 memset(bogus_pixels.get(), 'B', bogus_pixels_size); |
| 76 bad_msg.WriteData(bogus_pixels.get(), bogus_pixels_size); | 76 bad_msg.WriteData(bogus_pixels.get(), bogus_pixels_size); |
| 77 // Make sure we don't read out the bitmap! | 77 // Make sure we don't read out the bitmap! |
| 78 SkBitmap bad_output; | 78 SkBitmap bad_output; |
| 79 iter = base::PickleIterator(bad_msg); | 79 iter = base::PickleIterator(bad_msg); |
| 80 EXPECT_FALSE(IPC::ParamTraits<SkBitmap>::Read(&bad_msg, &iter, &bad_output)); | 80 EXPECT_FALSE(IPC::ParamTraits<SkBitmap>::Read(&bad_msg, &iter, &bad_output)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TEST(IPCMessageTest, ListValue) { | 83 TEST(IPCMessageTest, ListValue) { |
| 84 base::ListValue input; | 84 base::ListValue input; |
| 85 input.Set(0, new base::FundamentalValue(42.42)); | 85 input.Set(0, new base::Value(42.42)); |
| 86 input.Set(1, new base::StringValue("forty")); | 86 input.Set(1, new base::StringValue("forty")); |
| 87 input.Set(2, base::Value::CreateNullValue()); | 87 input.Set(2, base::Value::CreateNullValue()); |
| 88 | 88 |
| 89 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 89 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 90 IPC::WriteParam(&msg, input); | 90 IPC::WriteParam(&msg, input); |
| 91 | 91 |
| 92 base::ListValue output; | 92 base::ListValue output; |
| 93 base::PickleIterator iter(msg); | 93 base::PickleIterator iter(msg); |
| 94 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 94 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
| 95 | 95 |
| 96 EXPECT_TRUE(input.Equals(&output)); | 96 EXPECT_TRUE(input.Equals(&output)); |
| 97 | 97 |
| 98 // Also test the corrupt case. | 98 // Also test the corrupt case. |
| 99 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 99 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 100 bad_msg.WriteInt(99); | 100 bad_msg.WriteInt(99); |
| 101 iter = base::PickleIterator(bad_msg); | 101 iter = base::PickleIterator(bad_msg); |
| 102 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); | 102 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 TEST(IPCMessageTest, DictionaryValue) { | 105 TEST(IPCMessageTest, DictionaryValue) { |
| 106 base::DictionaryValue input; | 106 base::DictionaryValue input; |
| 107 input.Set("null", base::Value::CreateNullValue()); | 107 input.Set("null", base::Value::CreateNullValue()); |
| 108 input.Set("bool", new base::FundamentalValue(true)); | 108 input.Set("bool", new base::Value(true)); |
| 109 input.Set("int", new base::FundamentalValue(42)); | 109 input.Set("int", new base::Value(42)); |
| 110 | 110 |
| 111 std::unique_ptr<base::DictionaryValue> subdict(new base::DictionaryValue()); | 111 std::unique_ptr<base::DictionaryValue> subdict(new base::DictionaryValue()); |
| 112 subdict->Set("str", new base::StringValue("forty two")); | 112 subdict->Set("str", new base::StringValue("forty two")); |
| 113 subdict->Set("bool", new base::FundamentalValue(false)); | 113 subdict->Set("bool", new base::Value(false)); |
| 114 | 114 |
| 115 std::unique_ptr<base::ListValue> sublist(new base::ListValue()); | 115 std::unique_ptr<base::ListValue> sublist(new base::ListValue()); |
| 116 sublist->Set(0, new base::FundamentalValue(42.42)); | 116 sublist->Set(0, new base::Value(42.42)); |
| 117 sublist->Set(1, new base::StringValue("forty")); | 117 sublist->Set(1, new base::StringValue("forty")); |
| 118 sublist->Set(2, new base::StringValue("two")); | 118 sublist->Set(2, new base::StringValue("two")); |
| 119 subdict->Set("list", sublist.release()); | 119 subdict->Set("list", sublist.release()); |
| 120 | 120 |
| 121 input.Set("dict", subdict.release()); | 121 input.Set("dict", subdict.release()); |
| 122 | 122 |
| 123 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 123 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 124 IPC::WriteParam(&msg, input); | 124 IPC::WriteParam(&msg, input); |
| 125 | 125 |
| 126 base::DictionaryValue output; | 126 base::DictionaryValue output; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 142 | 142 |
| 143 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 143 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 144 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); | 144 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); |
| 145 | 145 |
| 146 net::HostPortPair output; | 146 net::HostPortPair output; |
| 147 base::PickleIterator iter(msg); | 147 base::PickleIterator iter(msg); |
| 148 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); | 148 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); |
| 149 EXPECT_EQ(input.host(), output.host()); | 149 EXPECT_EQ(input.host(), output.host()); |
| 150 EXPECT_EQ(input.port(), output.port()); | 150 EXPECT_EQ(input.port(), output.port()); |
| 151 } | 151 } |
| OLD | NEW |