OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "net/proxy/proxy_server.h" | 6 #include "net/proxy/proxy_server.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 // Test the creation of ProxyServer using ProxyServer::FromURI, which parses | 9 // Test the creation of ProxyServer using ProxyServer::FromURI, which parses |
10 // inputs of the form [<scheme>"://"]<host>[":"<port>]. Verify that each part | 10 // inputs of the form [<scheme>"://"]<host>[":"<port>]. Verify that each part |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 }, | 138 }, |
139 { | 139 { |
140 "socks://foopy:10", | 140 "socks://foopy:10", |
141 "socks4://foopy:10", | 141 "socks4://foopy:10", |
142 net::ProxyServer::SCHEME_SOCKS4, | 142 net::ProxyServer::SCHEME_SOCKS4, |
143 "foopy", | 143 "foopy", |
144 10, | 144 10, |
145 "foopy:10", | 145 "foopy:10", |
146 "SOCKS foopy:10" | 146 "SOCKS foopy:10" |
147 }, | 147 }, |
| 148 |
| 149 // HTTPS proxy URIs: |
| 150 { |
| 151 "https://foopy", // No port |
| 152 "https://foopy:443", |
| 153 net::ProxyServer::SCHEME_HTTPS, |
| 154 "foopy", |
| 155 443, |
| 156 "foopy:443", |
| 157 "HTTPS foopy:443" |
| 158 }, |
| 159 { |
| 160 "https://foopy:10", // Non-standard port |
| 161 "https://foopy:10", |
| 162 net::ProxyServer::SCHEME_HTTPS, |
| 163 "foopy", |
| 164 10, |
| 165 "foopy:10", |
| 166 "HTTPS foopy:10" |
| 167 }, |
| 168 { |
| 169 "https://1.2.3.4:10", // IP Address |
| 170 "https://1.2.3.4:10", |
| 171 net::ProxyServer::SCHEME_HTTPS, |
| 172 "1.2.3.4", |
| 173 10, |
| 174 "1.2.3.4:10", |
| 175 "HTTPS 1.2.3.4:10" |
| 176 }, |
148 }; | 177 }; |
149 | 178 |
150 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 179 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
151 net::ProxyServer uri = | 180 net::ProxyServer uri = |
152 net::ProxyServer::FromURI(tests[i].input_uri, | 181 net::ProxyServer::FromURI(tests[i].input_uri, |
153 net::ProxyServer::SCHEME_HTTP); | 182 net::ProxyServer::SCHEME_HTTP); |
154 EXPECT_TRUE(uri.is_valid()); | 183 EXPECT_TRUE(uri.is_valid()); |
155 EXPECT_FALSE(uri.is_direct()); | 184 EXPECT_FALSE(uri.is_direct()); |
156 EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); | 185 EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); |
157 EXPECT_EQ(tests[i].expected_scheme, uri.scheme()); | 186 EXPECT_EQ(tests[i].expected_scheme, uri.scheme()); |
(...skipping 24 matching lines...) Expand all Loading... |
182 TEST(ProxyServerTest, Invalid) { | 211 TEST(ProxyServerTest, Invalid) { |
183 const char* tests[] = { | 212 const char* tests[] = { |
184 "", | 213 "", |
185 " ", | 214 " ", |
186 "dddf:", // not a valid port | 215 "dddf:", // not a valid port |
187 "dddd:d", // not a valid port | 216 "dddd:d", // not a valid port |
188 "http://", // not a valid host/port. | 217 "http://", // not a valid host/port. |
189 "direct://xyz", // direct is not allowed a host/port. | 218 "direct://xyz", // direct is not allowed a host/port. |
190 "http:/", // ambiguous, but will fail because of bad port. | 219 "http:/", // ambiguous, but will fail because of bad port. |
191 "http:", // ambiguous, but will fail because of bad port. | 220 "http:", // ambiguous, but will fail because of bad port. |
192 "https://blah", // "https" is not a valid proxy scheme. | |
193 }; | 221 }; |
194 | 222 |
195 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 223 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
196 net::ProxyServer uri = | 224 net::ProxyServer uri = |
197 net::ProxyServer::FromURI(tests[i], net::ProxyServer::SCHEME_HTTP); | 225 net::ProxyServer::FromURI(tests[i], net::ProxyServer::SCHEME_HTTP); |
198 EXPECT_FALSE(uri.is_valid()); | 226 EXPECT_FALSE(uri.is_valid()); |
199 EXPECT_FALSE(uri.is_direct()); | 227 EXPECT_FALSE(uri.is_direct()); |
200 EXPECT_FALSE(uri.is_http()); | 228 EXPECT_FALSE(uri.is_http()); |
201 EXPECT_FALSE(uri.is_socks()); | 229 EXPECT_FALSE(uri.is_socks()); |
202 } | 230 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 "socks5://foopy:1080", | 280 "socks5://foopy:1080", |
253 }, | 281 }, |
254 { | 282 { |
255 "socks5 foopy:11", | 283 "socks5 foopy:11", |
256 "socks5://foopy:11", | 284 "socks5://foopy:11", |
257 }, | 285 }, |
258 { | 286 { |
259 " direct ", | 287 " direct ", |
260 "direct://", | 288 "direct://", |
261 }, | 289 }, |
| 290 { |
| 291 "https foopy", |
| 292 "https://foopy:443", |
| 293 }, |
| 294 { |
| 295 "https foopy:10", |
| 296 "https://foopy:10", |
| 297 }, |
262 }; | 298 }; |
263 | 299 |
264 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 300 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
265 net::ProxyServer uri = net::ProxyServer::FromPacString(tests[i].input_pac); | 301 net::ProxyServer uri = net::ProxyServer::FromPacString(tests[i].input_pac); |
266 EXPECT_TRUE(uri.is_valid()); | 302 EXPECT_TRUE(uri.is_valid()); |
267 EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); | 303 EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); |
268 } | 304 } |
269 } | 305 } |
270 | 306 |
271 // Test parsing a ProxyServer from an invalid PAC representation. | 307 // Test parsing a ProxyServer from an invalid PAC representation. |
272 TEST(ProxyServerTest, FromPACStringInvalid) { | 308 TEST(ProxyServerTest, FromPACStringInvalid) { |
273 const char* tests[] = { | 309 const char* tests[] = { |
274 "PROXY", // missing host/port. | 310 "PROXY", // missing host/port. |
| 311 "HTTPS", // missing host/port. |
275 "SOCKS", // missing host/port. | 312 "SOCKS", // missing host/port. |
276 "DIRECT foopy:10", // direct cannot have host/port. | 313 "DIRECT foopy:10", // direct cannot have host/port. |
277 }; | 314 }; |
278 | 315 |
279 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 316 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
280 net::ProxyServer uri = net::ProxyServer::FromPacString(tests[i]); | 317 net::ProxyServer uri = net::ProxyServer::FromPacString(tests[i]); |
281 EXPECT_FALSE(uri.is_valid()); | 318 EXPECT_FALSE(uri.is_valid()); |
282 } | 319 } |
283 } | 320 } |
OLD | NEW |