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 <stddef.h> | 5 #include <stddef.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "content/public/common/common_param_traits.h" | 12 #include "content/public/common/common_param_traits.h" |
13 #include "content/public/common/content_constants.h" | 13 #include "content/public/common/content_constants.h" |
14 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
15 #include "ipc/ipc_message_utils.h" | 15 #include "ipc/ipc_message_utils.h" |
16 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" |
17 #include "printing/backend/print_backend.h" | 17 #include "printing/backend/print_backend.h" |
18 #include "printing/page_range.h" | 18 #include "printing/page_range.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
22 #include "ui/gfx/ipc/gfx_param_traits.h" | 22 #include "ui/gfx/ipc/gfx_param_traits.h" |
| 23 #include "url/gurl.h" |
| 24 |
| 25 // Tests that serialize/deserialize correctly understand each other |
| 26 TEST(IPCMessageTest, Serialize) { |
| 27 const char* serialize_cases[] = { |
| 28 "http://www.google.com/", |
| 29 "http://user:pass@host.com:888/foo;bar?baz#nop", |
| 30 }; |
| 31 |
| 32 for (size_t i = 0; i < arraysize(serialize_cases); i++) { |
| 33 GURL input(serialize_cases[i]); |
| 34 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 35 IPC::ParamTraits<GURL>::Write(&msg, input); |
| 36 |
| 37 GURL output; |
| 38 base::PickleIterator iter(msg); |
| 39 EXPECT_TRUE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); |
| 40 |
| 41 // We want to test each component individually to make sure its range was |
| 42 // correctly serialized and deserialized, not just the spec. |
| 43 EXPECT_EQ(input.possibly_invalid_spec(), output.possibly_invalid_spec()); |
| 44 EXPECT_EQ(input.is_valid(), output.is_valid()); |
| 45 EXPECT_EQ(input.scheme(), output.scheme()); |
| 46 EXPECT_EQ(input.username(), output.username()); |
| 47 EXPECT_EQ(input.password(), output.password()); |
| 48 EXPECT_EQ(input.host(), output.host()); |
| 49 EXPECT_EQ(input.port(), output.port()); |
| 50 EXPECT_EQ(input.path(), output.path()); |
| 51 EXPECT_EQ(input.query(), output.query()); |
| 52 EXPECT_EQ(input.ref(), output.ref()); |
| 53 } |
| 54 |
| 55 // Test an excessively long GURL. |
| 56 { |
| 57 const std::string url = std::string("http://example.org/").append( |
| 58 content::kMaxURLChars + 1, 'a'); |
| 59 GURL input(url.c_str()); |
| 60 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 61 IPC::ParamTraits<GURL>::Write(&msg, input); |
| 62 |
| 63 GURL output; |
| 64 base::PickleIterator iter(msg); |
| 65 EXPECT_TRUE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); |
| 66 EXPECT_TRUE(output.is_empty()); |
| 67 } |
| 68 |
| 69 // Test an invalid GURL. |
| 70 { |
| 71 IPC::Message msg; |
| 72 msg.WriteString("#inva://idurl/"); |
| 73 GURL output; |
| 74 base::PickleIterator iter(msg); |
| 75 EXPECT_FALSE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); |
| 76 } |
| 77 |
| 78 // Also test the corrupt case. |
| 79 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 80 msg.WriteInt(99); |
| 81 GURL output; |
| 82 base::PickleIterator iter(msg); |
| 83 EXPECT_FALSE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); |
| 84 } |
23 | 85 |
24 // Tests std::pair serialization | 86 // Tests std::pair serialization |
25 TEST(IPCMessageTest, Pair) { | 87 TEST(IPCMessageTest, Pair) { |
26 typedef std::pair<std::string, std::string> TestPair; | 88 typedef std::pair<std::string, std::string> TestPair; |
27 | 89 |
28 TestPair input("foo", "bar"); | 90 TestPair input("foo", "bar"); |
29 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 91 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
30 IPC::ParamTraits<TestPair>::Write(&msg, input); | 92 IPC::ParamTraits<TestPair>::Write(&msg, input); |
31 | 93 |
32 TestPair output; | 94 TestPair output; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 201 |
140 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 202 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
141 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); | 203 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); |
142 | 204 |
143 net::HostPortPair output; | 205 net::HostPortPair output; |
144 base::PickleIterator iter(msg); | 206 base::PickleIterator iter(msg); |
145 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); | 207 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); |
146 EXPECT_EQ(input.host(), output.host()); | 208 EXPECT_EQ(input.host(), output.host()); |
147 EXPECT_EQ(input.port(), output.port()); | 209 EXPECT_EQ(input.port(), output.port()); |
148 } | 210 } |
OLD | NEW |