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" | 23 #include "url/gurl.h" |
24 | 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 } | |
85 | |
86 // Tests std::pair serialization | 25 // Tests std::pair serialization |
87 TEST(IPCMessageTest, Pair) { | 26 TEST(IPCMessageTest, Pair) { |
88 typedef std::pair<std::string, std::string> TestPair; | 27 typedef std::pair<std::string, std::string> TestPair; |
89 | 28 |
90 TestPair input("foo", "bar"); | 29 TestPair input("foo", "bar"); |
91 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 30 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
92 IPC::ParamTraits<TestPair>::Write(&msg, input); | 31 IPC::ParamTraits<TestPair>::Write(&msg, input); |
93 | 32 |
94 TestPair output; | 33 TestPair output; |
95 base::PickleIterator iter(msg); | 34 base::PickleIterator iter(msg); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 140 |
202 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 141 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
203 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); | 142 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); |
204 | 143 |
205 net::HostPortPair output; | 144 net::HostPortPair output; |
206 base::PickleIterator iter(msg); | 145 base::PickleIterator iter(msg); |
207 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); | 146 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); |
208 EXPECT_EQ(input.host(), output.host()); | 147 EXPECT_EQ(input.host(), output.host()); |
209 EXPECT_EQ(input.port(), output.port()); | 148 EXPECT_EQ(input.port(), output.port()); |
210 } | 149 } |
OLD | NEW |