OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 6 |
7 #include "chrome/common/ipc_message.h" | 7 #include "chrome/common/ipc_message.h" |
8 #include "chrome/common/ipc_message_utils.h" | 8 #include "chrome/common/ipc_message_utils.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 // Tests that serialize/deserialize correctly understand each other | 12 // Tests that serialize/deserialize correctly understand each other |
13 TEST(IPCMessageTest, Serialize) { | 13 TEST(IPCMessageTest, Serialize) { |
14 const char* serialize_cases[] = { | 14 const char* serialize_cases[] = { |
15 "http://www.google.com/", | 15 "http://www.google.com/", |
16 "http://user:pass@host.com:888/foo;bar?baz#nop", | 16 "http://user:pass@host.com:888/foo;bar?baz#nop", |
17 "#inva://idurl/", | 17 "#inva://idurl/", |
18 }; | 18 }; |
19 | 19 |
20 for (size_t i = 0; i < arraysize(serialize_cases); i++) { | 20 for (size_t i = 0; i < arraysize(serialize_cases); i++) { |
21 GURL input(serialize_cases[i]); | 21 GURL input(serialize_cases[i]); |
22 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 22 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
23 IPC::ParamTraits<GURL>::Write(&msg, input); | 23 ParamTraits<GURL>::Write(&msg, input); |
24 | 24 |
25 GURL output; | 25 GURL output; |
26 void* iter = NULL; | 26 void* iter = NULL; |
27 EXPECT_TRUE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); | 27 EXPECT_TRUE(ParamTraits<GURL>::Read(&msg, &iter, &output)); |
28 | 28 |
29 // We want to test each component individually to make sure its range was | 29 // We want to test each component individually to make sure its range was |
30 // correctly serialized and deserialized, not just the spec. | 30 // correctly serialized and deserialized, not just the spec. |
31 EXPECT_EQ(input.possibly_invalid_spec(), output.possibly_invalid_spec()); | 31 EXPECT_EQ(input.possibly_invalid_spec(), output.possibly_invalid_spec()); |
32 EXPECT_EQ(input.is_valid(), output.is_valid()); | 32 EXPECT_EQ(input.is_valid(), output.is_valid()); |
33 EXPECT_EQ(input.scheme(), output.scheme()); | 33 EXPECT_EQ(input.scheme(), output.scheme()); |
34 EXPECT_EQ(input.username(), output.username()); | 34 EXPECT_EQ(input.username(), output.username()); |
35 EXPECT_EQ(input.password(), output.password()); | 35 EXPECT_EQ(input.password(), output.password()); |
36 EXPECT_EQ(input.host(), output.host()); | 36 EXPECT_EQ(input.host(), output.host()); |
37 EXPECT_EQ(input.port(), output.port()); | 37 EXPECT_EQ(input.port(), output.port()); |
38 EXPECT_EQ(input.path(), output.path()); | 38 EXPECT_EQ(input.path(), output.path()); |
39 EXPECT_EQ(input.query(), output.query()); | 39 EXPECT_EQ(input.query(), output.query()); |
40 EXPECT_EQ(input.ref(), output.ref()); | 40 EXPECT_EQ(input.ref(), output.ref()); |
41 } | 41 } |
42 | 42 |
43 // Also test the corrupt case. | 43 // Also test the corrupt case. |
44 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 44 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
45 msg.WriteInt(99); | 45 msg.WriteInt(99); |
46 GURL output; | 46 GURL output; |
47 void* iter = NULL; | 47 void* iter = NULL; |
48 EXPECT_FALSE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); | 48 EXPECT_FALSE(ParamTraits<GURL>::Read(&msg, &iter, &output)); |
49 } | 49 } |
50 | 50 |
OLD | NEW |