| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 { | 152 { |
| 153 "https://1.2.3.4:10", // IP Address | 153 "https://1.2.3.4:10", // IP Address |
| 154 "https://1.2.3.4:10", | 154 "https://1.2.3.4:10", |
| 155 net::ProxyServer::SCHEME_HTTPS, | 155 net::ProxyServer::SCHEME_HTTPS, |
| 156 "1.2.3.4", | 156 "1.2.3.4", |
| 157 10, | 157 10, |
| 158 "HTTPS 1.2.3.4:10" | 158 "HTTPS 1.2.3.4:10" |
| 159 }, | 159 }, |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 162 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 163 net::ProxyServer uri = | 163 net::ProxyServer uri = |
| 164 net::ProxyServer::FromURI(tests[i].input_uri, | 164 net::ProxyServer::FromURI(tests[i].input_uri, |
| 165 net::ProxyServer::SCHEME_HTTP); | 165 net::ProxyServer::SCHEME_HTTP); |
| 166 EXPECT_TRUE(uri.is_valid()); | 166 EXPECT_TRUE(uri.is_valid()); |
| 167 EXPECT_FALSE(uri.is_direct()); | 167 EXPECT_FALSE(uri.is_direct()); |
| 168 EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); | 168 EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); |
| 169 EXPECT_EQ(tests[i].expected_scheme, uri.scheme()); | 169 EXPECT_EQ(tests[i].expected_scheme, uri.scheme()); |
| 170 EXPECT_EQ(tests[i].expected_host, uri.host_port_pair().host()); | 170 EXPECT_EQ(tests[i].expected_host, uri.host_port_pair().host()); |
| 171 EXPECT_EQ(tests[i].expected_port, uri.host_port_pair().port()); | 171 EXPECT_EQ(tests[i].expected_port, uri.host_port_pair().port()); |
| 172 EXPECT_EQ(tests[i].expected_pac_string, uri.ToPacString()); | 172 EXPECT_EQ(tests[i].expected_pac_string, uri.ToPacString()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 195 "", | 195 "", |
| 196 " ", | 196 " ", |
| 197 "dddf:", // not a valid port | 197 "dddf:", // not a valid port |
| 198 "dddd:d", // not a valid port | 198 "dddd:d", // not a valid port |
| 199 "http://", // not a valid host/port. | 199 "http://", // not a valid host/port. |
| 200 "direct://xyz", // direct is not allowed a host/port. | 200 "direct://xyz", // direct is not allowed a host/port. |
| 201 "http:/", // ambiguous, but will fail because of bad port. | 201 "http:/", // ambiguous, but will fail because of bad port. |
| 202 "http:", // ambiguous, but will fail because of bad port. | 202 "http:", // ambiguous, but will fail because of bad port. |
| 203 }; | 203 }; |
| 204 | 204 |
| 205 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 205 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 206 net::ProxyServer uri = | 206 net::ProxyServer uri = |
| 207 net::ProxyServer::FromURI(tests[i], net::ProxyServer::SCHEME_HTTP); | 207 net::ProxyServer::FromURI(tests[i], net::ProxyServer::SCHEME_HTTP); |
| 208 EXPECT_FALSE(uri.is_valid()); | 208 EXPECT_FALSE(uri.is_valid()); |
| 209 EXPECT_FALSE(uri.is_direct()); | 209 EXPECT_FALSE(uri.is_direct()); |
| 210 EXPECT_FALSE(uri.is_http()); | 210 EXPECT_FALSE(uri.is_http()); |
| 211 EXPECT_FALSE(uri.is_socks()); | 211 EXPECT_FALSE(uri.is_socks()); |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 // Test that LWS (SP | HT) is disregarded from the ends. | 215 // Test that LWS (SP | HT) is disregarded from the ends. |
| 216 TEST(ProxyServerTest, Whitespace) { | 216 TEST(ProxyServerTest, Whitespace) { |
| 217 const char* tests[] = { | 217 const char* tests[] = { |
| 218 " foopy:80", | 218 " foopy:80", |
| 219 "foopy:80 \t", | 219 "foopy:80 \t", |
| 220 " \tfoopy:80 ", | 220 " \tfoopy:80 ", |
| 221 }; | 221 }; |
| 222 | 222 |
| 223 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 223 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 224 net::ProxyServer uri = | 224 net::ProxyServer uri = |
| 225 net::ProxyServer::FromURI(tests[i], net::ProxyServer::SCHEME_HTTP); | 225 net::ProxyServer::FromURI(tests[i], net::ProxyServer::SCHEME_HTTP); |
| 226 EXPECT_EQ("foopy:80", uri.ToURI()); | 226 EXPECT_EQ("foopy:80", uri.ToURI()); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Test parsing a ProxyServer from a PAC representation. | 230 // Test parsing a ProxyServer from a PAC representation. |
| 231 TEST(ProxyServerTest, FromPACString) { | 231 TEST(ProxyServerTest, FromPACString) { |
| 232 const struct { | 232 const struct { |
| 233 const char* input_pac; | 233 const char* input_pac; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 { | 272 { |
| 273 "https foopy", | 273 "https foopy", |
| 274 "https://foopy:443", | 274 "https://foopy:443", |
| 275 }, | 275 }, |
| 276 { | 276 { |
| 277 "https foopy:10", | 277 "https foopy:10", |
| 278 "https://foopy:10", | 278 "https://foopy:10", |
| 279 }, | 279 }, |
| 280 }; | 280 }; |
| 281 | 281 |
| 282 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 282 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 283 net::ProxyServer uri = net::ProxyServer::FromPacString(tests[i].input_pac); | 283 net::ProxyServer uri = net::ProxyServer::FromPacString(tests[i].input_pac); |
| 284 EXPECT_TRUE(uri.is_valid()); | 284 EXPECT_TRUE(uri.is_valid()); |
| 285 EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); | 285 EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 | 288 |
| 289 // Test parsing a ProxyServer from an invalid PAC representation. | 289 // Test parsing a ProxyServer from an invalid PAC representation. |
| 290 TEST(ProxyServerTest, FromPACStringInvalid) { | 290 TEST(ProxyServerTest, FromPACStringInvalid) { |
| 291 const char* tests[] = { | 291 const char* tests[] = { |
| 292 "PROXY", // missing host/port. | 292 "PROXY", // missing host/port. |
| 293 "HTTPS", // missing host/port. | 293 "HTTPS", // missing host/port. |
| 294 "SOCKS", // missing host/port. | 294 "SOCKS", // missing host/port. |
| 295 "DIRECT foopy:10", // direct cannot have host/port. | 295 "DIRECT foopy:10", // direct cannot have host/port. |
| 296 }; | 296 }; |
| 297 | 297 |
| 298 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 298 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 299 net::ProxyServer uri = net::ProxyServer::FromPacString(tests[i]); | 299 net::ProxyServer uri = net::ProxyServer::FromPacString(tests[i]); |
| 300 EXPECT_FALSE(uri.is_valid()); | 300 EXPECT_FALSE(uri.is_valid()); |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 TEST(ProxyServerTest, ComparatorAndEquality) { | 304 TEST(ProxyServerTest, ComparatorAndEquality) { |
| 305 struct { | 305 struct { |
| 306 // Inputs. | 306 // Inputs. |
| 307 const char* server1; | 307 const char* server1; |
| 308 const char* server2; | 308 const char* server2; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 328 "bar:33", | 328 "bar:33", |
| 329 1 | 329 1 |
| 330 }, | 330 }, |
| 331 { // Scheme is different. | 331 { // Scheme is different. |
| 332 "socks4://foo:33", | 332 "socks4://foo:33", |
| 333 "http://foo:33", | 333 "http://foo:33", |
| 334 1 | 334 1 |
| 335 }, | 335 }, |
| 336 }; | 336 }; |
| 337 | 337 |
| 338 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 338 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 339 // Parse the expected inputs to ProxyServer instances. | 339 // Parse the expected inputs to ProxyServer instances. |
| 340 const net::ProxyServer server1 = | 340 const net::ProxyServer server1 = |
| 341 net::ProxyServer::FromURI( | 341 net::ProxyServer::FromURI( |
| 342 tests[i].server1, net::ProxyServer::SCHEME_HTTP); | 342 tests[i].server1, net::ProxyServer::SCHEME_HTTP); |
| 343 | 343 |
| 344 const net::ProxyServer server2 = | 344 const net::ProxyServer server2 = |
| 345 net::ProxyServer::FromURI( | 345 net::ProxyServer::FromURI( |
| 346 tests[i].server2, net::ProxyServer::SCHEME_HTTP); | 346 tests[i].server2, net::ProxyServer::SCHEME_HTTP); |
| 347 | 347 |
| 348 switch (tests[i].expected_comparison) { | 348 switch (tests[i].expected_comparison) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 359 case 1: | 359 case 1: |
| 360 EXPECT_FALSE(server1 < server2); | 360 EXPECT_FALSE(server1 < server2); |
| 361 EXPECT_TRUE(server2 < server1); | 361 EXPECT_TRUE(server2 < server1); |
| 362 EXPECT_FALSE(server2 == server1); | 362 EXPECT_FALSE(server2 == server1); |
| 363 break; | 363 break; |
| 364 default: | 364 default: |
| 365 FAIL() << "Invalid expectation. Can be only -1, 0, 1"; | 365 FAIL() << "Invalid expectation. Can be only -1, 0, 1"; |
| 366 } | 366 } |
| 367 } | 367 } |
| 368 } | 368 } |
| OLD | NEW |