| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 }, | 118 }, |
| 119 { | 119 { |
| 120 "socks5://foopy:10", | 120 "socks5://foopy:10", |
| 121 "socks5://foopy:10", | 121 "socks5://foopy:10", |
| 122 net::ProxyServer::SCHEME_SOCKS5, | 122 net::ProxyServer::SCHEME_SOCKS5, |
| 123 "foopy", | 123 "foopy", |
| 124 10, | 124 10, |
| 125 "foopy:10", | 125 "foopy:10", |
| 126 "SOCKS5 foopy:10" | 126 "SOCKS5 foopy:10" |
| 127 }, | 127 }, |
| 128 |
| 129 // SOCKS proxy URIs (should default to SOCKS4) |
| 130 { |
| 131 "socks://foopy", // No port. |
| 132 "socks4://foopy:1080", |
| 133 net::ProxyServer::SCHEME_SOCKS4, |
| 134 "foopy", |
| 135 1080, |
| 136 "foopy:1080", |
| 137 "SOCKS foopy:1080" |
| 138 }, |
| 139 { |
| 140 "socks://foopy:10", |
| 141 "socks4://foopy:10", |
| 142 net::ProxyServer::SCHEME_SOCKS4, |
| 143 "foopy", |
| 144 10, |
| 145 "foopy:10", |
| 146 "SOCKS foopy:10" |
| 147 }, |
| 128 }; | 148 }; |
| 129 | 149 |
| 130 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 150 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 131 net::ProxyServer uri = net::ProxyServer::FromURI(tests[i].input_uri); | 151 net::ProxyServer uri = net::ProxyServer::FromURI(tests[i].input_uri); |
| 132 EXPECT_TRUE(uri.is_valid()); | 152 EXPECT_TRUE(uri.is_valid()); |
| 133 EXPECT_FALSE(uri.is_direct()); | 153 EXPECT_FALSE(uri.is_direct()); |
| 134 EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); | 154 EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); |
| 135 EXPECT_EQ(tests[i].expected_scheme, uri.scheme()); | 155 EXPECT_EQ(tests[i].expected_scheme, uri.scheme()); |
| 136 EXPECT_EQ(tests[i].expected_host, uri.HostNoBrackets()); | 156 EXPECT_EQ(tests[i].expected_host, uri.HostNoBrackets()); |
| 137 EXPECT_EQ(tests[i].expected_port, uri.port()); | 157 EXPECT_EQ(tests[i].expected_port, uri.port()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 155 EXPECT_EQ("DIRECT", uri.ToPacString()); | 175 EXPECT_EQ("DIRECT", uri.ToPacString()); |
| 156 } | 176 } |
| 157 | 177 |
| 158 // Test parsing some invalid inputs. | 178 // Test parsing some invalid inputs. |
| 159 TEST(ProxyServerTest, Invalid) { | 179 TEST(ProxyServerTest, Invalid) { |
| 160 const char* tests[] = { | 180 const char* tests[] = { |
| 161 "", | 181 "", |
| 162 " ", | 182 " ", |
| 163 "dddf:", // not a valid port | 183 "dddf:", // not a valid port |
| 164 "dddd:d", // not a valid port | 184 "dddd:d", // not a valid port |
| 165 "socks://foopy", // not a valid scheme (needs to be socks4 or sock5). | |
| 166 "http://", // not a valid host/port. | 185 "http://", // not a valid host/port. |
| 167 "direct://xyz", // direct is not allowed a host/port. | 186 "direct://xyz", // direct is not allowed a host/port. |
| 168 "http:/", // ambiguous, but will fail because of bad port. | 187 "http:/", // ambiguous, but will fail because of bad port. |
| 169 "http:", // ambiguous, but will fail because of bad port. | 188 "http:", // ambiguous, but will fail because of bad port. |
| 170 "https://blah", // "https" is not a valid proxy scheme. | 189 "https://blah", // "https" is not a valid proxy scheme. |
| 171 }; | 190 }; |
| 172 | 191 |
| 173 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 192 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 174 net::ProxyServer uri = net::ProxyServer::FromURI(tests[i]); | 193 net::ProxyServer uri = net::ProxyServer::FromURI(tests[i]); |
| 175 EXPECT_FALSE(uri.is_valid()); | 194 EXPECT_FALSE(uri.is_valid()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 "PROXY", // missing host/port. | 269 "PROXY", // missing host/port. |
| 251 "SOCKS", // missing host/port. | 270 "SOCKS", // missing host/port. |
| 252 "DIRECT foopy:10", // direct cannot have host/port. | 271 "DIRECT foopy:10", // direct cannot have host/port. |
| 253 }; | 272 }; |
| 254 | 273 |
| 255 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 274 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 256 net::ProxyServer uri = net::ProxyServer::FromPacString(tests[i]); | 275 net::ProxyServer uri = net::ProxyServer::FromPacString(tests[i]); |
| 257 EXPECT_FALSE(uri.is_valid()); | 276 EXPECT_FALSE(uri.is_valid()); |
| 258 } | 277 } |
| 259 } | 278 } |
| OLD | NEW |