Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: url/ipc/url_param_traits_unittest.cc

Issue 1722773002: Mustash: Move GURL ParamTraits to url/ipc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698