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 <string.h> | 5 #include <string.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "content/public/common/common_param_traits.h" | 10 #include "content/public/common/common_param_traits.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 #include "ipc/ipc_message.h" | 12 #include "ipc/ipc_message.h" |
13 #include "ipc/ipc_message_utils.h" | 13 #include "ipc/ipc_message_utils.h" |
14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
15 #include "printing/backend/print_backend.h" | 15 #include "printing/backend/print_backend.h" |
16 #include "printing/page_range.h" | 16 #include "printing/page_range.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
19 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
20 | 20 |
21 // Tests that serialize/deserialize correctly understand each other | 21 // Tests that serialize/deserialize correctly understand each other |
22 TEST(IPCMessageTest, Serialize) { | 22 TEST(IPCMessageTest, Serialize) { |
23 const char* serialize_cases[] = { | 23 const char* serialize_cases[] = { |
24 "http://www.google.com/", | 24 "http://www.google.com/", |
25 "http://user:pass@host.com:888/foo;bar?baz#nop", | 25 "http://user:pass@host.com:888/foo;bar?baz#nop", |
26 "#inva://idurl/", | |
27 }; | 26 }; |
28 | 27 |
29 for (size_t i = 0; i < arraysize(serialize_cases); i++) { | 28 for (size_t i = 0; i < arraysize(serialize_cases); i++) { |
30 GURL input(serialize_cases[i]); | 29 GURL input(serialize_cases[i]); |
31 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 30 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
32 IPC::ParamTraits<GURL>::Write(&msg, input); | 31 IPC::ParamTraits<GURL>::Write(&msg, input); |
33 | 32 |
34 GURL output; | 33 GURL output; |
35 PickleIterator iter(msg); | 34 PickleIterator iter(msg); |
36 EXPECT_TRUE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); | 35 EXPECT_TRUE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); |
37 | 36 |
38 // We want to test each component individually to make sure its range was | 37 // We want to test each component individually to make sure its range was |
39 // correctly serialized and deserialized, not just the spec. | 38 // correctly serialized and deserialized, not just the spec. |
40 EXPECT_EQ(input.possibly_invalid_spec(), output.possibly_invalid_spec()); | 39 EXPECT_EQ(input.possibly_invalid_spec(), output.possibly_invalid_spec()); |
41 EXPECT_EQ(input.is_valid(), output.is_valid()); | 40 EXPECT_EQ(input.is_valid(), output.is_valid()); |
42 EXPECT_EQ(input.scheme(), output.scheme()); | 41 EXPECT_EQ(input.scheme(), output.scheme()); |
43 EXPECT_EQ(input.username(), output.username()); | 42 EXPECT_EQ(input.username(), output.username()); |
44 EXPECT_EQ(input.password(), output.password()); | 43 EXPECT_EQ(input.password(), output.password()); |
45 EXPECT_EQ(input.host(), output.host()); | 44 EXPECT_EQ(input.host(), output.host()); |
46 EXPECT_EQ(input.port(), output.port()); | 45 EXPECT_EQ(input.port(), output.port()); |
47 EXPECT_EQ(input.path(), output.path()); | 46 EXPECT_EQ(input.path(), output.path()); |
48 EXPECT_EQ(input.query(), output.query()); | 47 EXPECT_EQ(input.query(), output.query()); |
49 EXPECT_EQ(input.ref(), output.ref()); | 48 EXPECT_EQ(input.ref(), output.ref()); |
50 } | 49 } |
51 | 50 |
| 51 // Test an invalid GURL. |
| 52 { |
| 53 IPC::Message msg; |
| 54 msg.WriteString("#inva://idurl/"); |
| 55 GURL output; |
| 56 PickleIterator iter(msg); |
| 57 EXPECT_FALSE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); |
| 58 } |
| 59 |
52 // Also test the corrupt case. | 60 // Also test the corrupt case. |
53 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 61 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
54 msg.WriteInt(99); | 62 msg.WriteInt(99); |
55 GURL output; | 63 GURL output; |
56 PickleIterator iter(msg); | 64 PickleIterator iter(msg); |
57 EXPECT_FALSE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); | 65 EXPECT_FALSE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); |
58 } | 66 } |
59 | 67 |
60 // Tests std::pair serialization | 68 // Tests std::pair serialization |
61 TEST(IPCMessageTest, Pair) { | 69 TEST(IPCMessageTest, Pair) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 185 |
178 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 186 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
179 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); | 187 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); |
180 | 188 |
181 net::HostPortPair output; | 189 net::HostPortPair output; |
182 PickleIterator iter(msg); | 190 PickleIterator iter(msg); |
183 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); | 191 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); |
184 EXPECT_EQ(input.host(), output.host()); | 192 EXPECT_EQ(input.host(), output.host()); |
185 EXPECT_EQ(input.port(), output.port()); | 193 EXPECT_EQ(input.port(), output.port()); |
186 } | 194 } |
OLD | NEW |