| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <string> | |
| 6 | |
| 7 #include "ipc/ipc_message.h" | |
| 8 #include "ipc/ipc_message_utils.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "url/gurl.h" | |
| 11 #include "url/ipc/url_param_traits.h" | |
| 12 | |
| 13 // Tests that serialize/deserialize correctly understand each other. | |
| 14 TEST(IPCMessageTest, Serialize) { | |
| 15 const char* serialize_cases[] = { | |
| 16 "http://www.google.com/", | |
| 17 "http://user:pass@host.com:888/foo;bar?baz#nop", | |
| 18 }; | |
| 19 | |
| 20 for (size_t i = 0; i < arraysize(serialize_cases); i++) { | |
| 21 GURL input(serialize_cases[i]); | |
| 22 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | |
| 23 IPC::ParamTraits<GURL>::Write(&msg, input); | |
| 24 | |
| 25 GURL output; | |
| 26 base::PickleIterator iter(msg); | |
| 27 EXPECT_TRUE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); | |
| 28 | |
| 29 // We want to test each component individually to make sure its range was | |
| 30 // correctly serialized and deserialized, not just the spec. | |
| 31 EXPECT_EQ(input.possibly_invalid_spec(), output.possibly_invalid_spec()); | |
| 32 EXPECT_EQ(input.is_valid(), output.is_valid()); | |
| 33 EXPECT_EQ(input.scheme(), output.scheme()); | |
| 34 EXPECT_EQ(input.username(), output.username()); | |
| 35 EXPECT_EQ(input.password(), output.password()); | |
| 36 EXPECT_EQ(input.host(), output.host()); | |
| 37 EXPECT_EQ(input.port(), output.port()); | |
| 38 EXPECT_EQ(input.path(), output.path()); | |
| 39 EXPECT_EQ(input.query(), output.query()); | |
| 40 EXPECT_EQ(input.ref(), output.ref()); | |
| 41 } | |
| 42 | |
| 43 // Test an excessively long GURL. | |
| 44 { | |
| 45 const std::string url = std::string("http://example.org/").append( | |
| 46 url::kMaxURLChars + 1, 'a'); | |
| 47 GURL input(url.c_str()); | |
| 48 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | |
| 49 IPC::ParamTraits<GURL>::Write(&msg, input); | |
| 50 | |
| 51 GURL output; | |
| 52 base::PickleIterator iter(msg); | |
| 53 EXPECT_TRUE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); | |
| 54 EXPECT_TRUE(output.is_empty()); | |
| 55 } | |
| 56 | |
| 57 // Test an invalid GURL. | |
| 58 { | |
| 59 IPC::Message msg; | |
| 60 msg.WriteString("#inva://idurl/"); | |
| 61 GURL output; | |
| 62 base::PickleIterator iter(msg); | |
| 63 EXPECT_FALSE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); | |
| 64 } | |
| 65 | |
| 66 // Also test the corrupt case. | |
| 67 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | |
| 68 msg.WriteInt(99); | |
| 69 GURL output; | |
| 70 base::PickleIterator iter(msg); | |
| 71 EXPECT_FALSE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); | |
| 72 } | |
| OLD | NEW |