OLD | NEW |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 "net/quic/platform/api/quic_url.h" | 5 #include "net/quic/platform/api/quic_url.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "net/quic/platform/api/quic_test.h" |
8 | 8 |
9 using std::string; | 9 using std::string; |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 namespace test { | 12 namespace test { |
13 namespace { | 13 namespace { |
14 | 14 |
15 TEST(QuicUrlTest, Basic) { | 15 class QuicUrlTest : public QuicTest {}; |
| 16 |
| 17 TEST_F(QuicUrlTest, Basic) { |
16 // No scheme specified. | 18 // No scheme specified. |
17 string url_str = "www.example.com"; | 19 string url_str = "www.example.com"; |
18 QuicUrl url(url_str); | 20 QuicUrl url(url_str); |
19 EXPECT_FALSE(url.IsValid()); | 21 EXPECT_FALSE(url.IsValid()); |
20 | 22 |
21 // scheme is HTTP. | 23 // scheme is HTTP. |
22 url_str = "http://www.example.com"; | 24 url_str = "http://www.example.com"; |
23 url = QuicUrl(url_str); | 25 url = QuicUrl(url_str); |
24 EXPECT_TRUE(url.IsValid()); | 26 EXPECT_TRUE(url.IsValid()); |
25 EXPECT_EQ("http://www.example.com/", url.ToString()); | 27 EXPECT_EQ("http://www.example.com/", url.ToString()); |
(...skipping 17 matching lines...) Expand all Loading... |
43 url_str = "ftp://www.example.com"; | 45 url_str = "ftp://www.example.com"; |
44 url = QuicUrl(url_str); | 46 url = QuicUrl(url_str); |
45 EXPECT_TRUE(url.IsValid()); | 47 EXPECT_TRUE(url.IsValid()); |
46 EXPECT_EQ("ftp://www.example.com/", url.ToString()); | 48 EXPECT_EQ("ftp://www.example.com/", url.ToString()); |
47 EXPECT_EQ("ftp", url.scheme()); | 49 EXPECT_EQ("ftp", url.scheme()); |
48 EXPECT_EQ("www.example.com", url.HostPort()); | 50 EXPECT_EQ("www.example.com", url.HostPort()); |
49 EXPECT_EQ("/", url.PathParamsQuery()); | 51 EXPECT_EQ("/", url.PathParamsQuery()); |
50 EXPECT_EQ(21u, url.port()); | 52 EXPECT_EQ(21u, url.port()); |
51 } | 53 } |
52 | 54 |
53 TEST(QuicUrlTest, DefaultScheme) { | 55 TEST_F(QuicUrlTest, DefaultScheme) { |
54 // Default scheme to HTTP. | 56 // Default scheme to HTTP. |
55 string url_str = "www.example.com"; | 57 string url_str = "www.example.com"; |
56 QuicUrl url(url_str, "http"); | 58 QuicUrl url(url_str, "http"); |
57 EXPECT_EQ("http://www.example.com/", url.ToString()); | 59 EXPECT_EQ("http://www.example.com/", url.ToString()); |
58 EXPECT_EQ("http", url.scheme()); | 60 EXPECT_EQ("http", url.scheme()); |
59 | 61 |
60 // URL already has a scheme specified. | 62 // URL already has a scheme specified. |
61 url_str = "http://www.example.com"; | 63 url_str = "http://www.example.com"; |
62 url = QuicUrl(url_str, "https"); | 64 url = QuicUrl(url_str, "https"); |
63 EXPECT_EQ("http://www.example.com/", url.ToString()); | 65 EXPECT_EQ("http://www.example.com/", url.ToString()); |
64 EXPECT_EQ("http", url.scheme()); | 66 EXPECT_EQ("http", url.scheme()); |
65 | 67 |
66 // Default scheme to FTP. | 68 // Default scheme to FTP. |
67 url_str = "www.example.com"; | 69 url_str = "www.example.com"; |
68 url = QuicUrl(url_str, "ftp"); | 70 url = QuicUrl(url_str, "ftp"); |
69 EXPECT_EQ("ftp://www.example.com/", url.ToString()); | 71 EXPECT_EQ("ftp://www.example.com/", url.ToString()); |
70 EXPECT_EQ("ftp", url.scheme()); | 72 EXPECT_EQ("ftp", url.scheme()); |
71 } | 73 } |
72 | 74 |
73 TEST(QuicUrlTest, IsValid) { | 75 TEST_F(QuicUrlTest, IsValid) { |
74 string url_str = | 76 string url_str = |
75 "ftp://www.example.com:12345/path/to/resource?a=1&campaign=2"; | 77 "ftp://www.example.com:12345/path/to/resource?a=1&campaign=2"; |
76 EXPECT_TRUE(QuicUrl(url_str).IsValid()); | 78 EXPECT_TRUE(QuicUrl(url_str).IsValid()); |
77 | 79 |
78 // Invalid characters in host name. | 80 // Invalid characters in host name. |
79 url_str = "https://www%.example.com:12345/path/to/resource?a=1&campaign=2"; | 81 url_str = "https://www%.example.com:12345/path/to/resource?a=1&campaign=2"; |
80 EXPECT_FALSE(QuicUrl(url_str).IsValid()); | 82 EXPECT_FALSE(QuicUrl(url_str).IsValid()); |
81 | 83 |
82 // Invalid characters in scheme. | 84 // Invalid characters in scheme. |
83 url_str = "%http://www.example.com:12345/path/to/resource?a=1&campaign=2"; | 85 url_str = "%http://www.example.com:12345/path/to/resource?a=1&campaign=2"; |
84 EXPECT_FALSE(QuicUrl(url_str).IsValid()); | 86 EXPECT_FALSE(QuicUrl(url_str).IsValid()); |
85 | 87 |
86 // Host name too long. | 88 // Host name too long. |
87 string host(1024, 'a'); | 89 string host(1024, 'a'); |
88 url_str = "https://" + host; | 90 url_str = "https://" + host; |
89 EXPECT_FALSE(QuicUrl(url_str).IsValid()); | 91 EXPECT_FALSE(QuicUrl(url_str).IsValid()); |
90 | 92 |
91 // Invalid port number. | 93 // Invalid port number. |
92 url_str = "https://www..example.com:123456/path/to/resource?a=1&campaign=2"; | 94 url_str = "https://www..example.com:123456/path/to/resource?a=1&campaign=2"; |
93 EXPECT_FALSE(QuicUrl(url_str).IsValid()); | 95 EXPECT_FALSE(QuicUrl(url_str).IsValid()); |
94 } | 96 } |
95 | 97 |
96 TEST(QuicUrlTest, HostPort) { | 98 TEST_F(QuicUrlTest, HostPort) { |
97 string url_str = "http://www.example.com/"; | 99 string url_str = "http://www.example.com/"; |
98 QuicUrl url(url_str); | 100 QuicUrl url(url_str); |
99 EXPECT_EQ("www.example.com", url.HostPort()); | 101 EXPECT_EQ("www.example.com", url.HostPort()); |
100 EXPECT_EQ("www.example.com", url.host()); | 102 EXPECT_EQ("www.example.com", url.host()); |
101 EXPECT_EQ(80u, url.port()); | 103 EXPECT_EQ(80u, url.port()); |
102 | 104 |
103 url_str = "http://www.example.com:80/"; | 105 url_str = "http://www.example.com:80/"; |
104 url = QuicUrl(url_str); | 106 url = QuicUrl(url_str); |
105 EXPECT_EQ("www.example.com", url.HostPort()); | 107 EXPECT_EQ("www.example.com", url.HostPort()); |
106 EXPECT_EQ("www.example.com", url.host()); | 108 EXPECT_EQ("www.example.com", url.host()); |
(...skipping 17 matching lines...) Expand all Loading... |
124 EXPECT_EQ("2001::1", url.host()); | 126 EXPECT_EQ("2001::1", url.host()); |
125 EXPECT_EQ(80u, url.port()); | 127 EXPECT_EQ(80u, url.port()); |
126 | 128 |
127 url_str = "http://[2001::1]:81/"; | 129 url_str = "http://[2001::1]:81/"; |
128 url = QuicUrl(url_str); | 130 url = QuicUrl(url_str); |
129 EXPECT_EQ("[2001::1]:81", url.HostPort()); | 131 EXPECT_EQ("[2001::1]:81", url.HostPort()); |
130 EXPECT_EQ("2001::1", url.host()); | 132 EXPECT_EQ("2001::1", url.host()); |
131 EXPECT_EQ(81u, url.port()); | 133 EXPECT_EQ(81u, url.port()); |
132 } | 134 } |
133 | 135 |
134 TEST(QuicUrlTest, PathParamsQuery) { | 136 TEST_F(QuicUrlTest, PathParamsQuery) { |
135 string url_str = | 137 string url_str = |
136 "https://www.example.com:12345/path/to/resource?a=1&campaign=2"; | 138 "https://www.example.com:12345/path/to/resource?a=1&campaign=2"; |
137 QuicUrl url(url_str); | 139 QuicUrl url(url_str); |
138 EXPECT_EQ("/path/to/resource?a=1&campaign=2", url.PathParamsQuery()); | 140 EXPECT_EQ("/path/to/resource?a=1&campaign=2", url.PathParamsQuery()); |
139 EXPECT_EQ("/path/to/resource", url.path()); | 141 EXPECT_EQ("/path/to/resource", url.path()); |
140 | 142 |
141 url_str = "https://www.example.com/?"; | 143 url_str = "https://www.example.com/?"; |
142 url = QuicUrl(url_str); | 144 url = QuicUrl(url_str); |
143 EXPECT_EQ("/?", url.PathParamsQuery()); | 145 EXPECT_EQ("/?", url.PathParamsQuery()); |
144 EXPECT_EQ("/", url.path()); | 146 EXPECT_EQ("/", url.path()); |
145 | 147 |
146 url_str = "https://www.example.com/"; | 148 url_str = "https://www.example.com/"; |
147 url = QuicUrl(url_str); | 149 url = QuicUrl(url_str); |
148 EXPECT_EQ("/", url.PathParamsQuery()); | 150 EXPECT_EQ("/", url.PathParamsQuery()); |
149 EXPECT_EQ("/", url.path()); | 151 EXPECT_EQ("/", url.path()); |
150 } | 152 } |
151 | 153 |
152 } // namespace | 154 } // namespace |
153 } // namespace test | 155 } // namespace test |
154 } // namespace net | 156 } // namespace net |
OLD | NEW |