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

Side by Side Diff: net/proxy/proxy_server_unittest.cc

Issue 149191: Whenever proxy configurations contain socks and http/https/ftp proxies, socks... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_server.cc ('k') | net/proxy/proxy_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }; 148 };
149 149
150 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 150 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
151 net::ProxyServer uri = net::ProxyServer::FromURI(tests[i].input_uri); 151 net::ProxyServer uri =
152 net::ProxyServer::FromURI(tests[i].input_uri,
153 net::ProxyServer::SCHEME_HTTP);
152 EXPECT_TRUE(uri.is_valid()); 154 EXPECT_TRUE(uri.is_valid());
153 EXPECT_FALSE(uri.is_direct()); 155 EXPECT_FALSE(uri.is_direct());
154 EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); 156 EXPECT_EQ(tests[i].expected_uri, uri.ToURI());
155 EXPECT_EQ(tests[i].expected_scheme, uri.scheme()); 157 EXPECT_EQ(tests[i].expected_scheme, uri.scheme());
156 EXPECT_EQ(tests[i].expected_host, uri.HostNoBrackets()); 158 EXPECT_EQ(tests[i].expected_host, uri.HostNoBrackets());
157 EXPECT_EQ(tests[i].expected_port, uri.port()); 159 EXPECT_EQ(tests[i].expected_port, uri.port());
158 EXPECT_EQ(tests[i].expected_host_and_port, uri.host_and_port()); 160 EXPECT_EQ(tests[i].expected_host_and_port, uri.host_and_port());
159 EXPECT_EQ(tests[i].expected_pac_string, uri.ToPacString()); 161 EXPECT_EQ(tests[i].expected_pac_string, uri.ToPacString());
160 } 162 }
161 } 163 }
162 164
163 TEST(ProxyServerTest, DefaultConstructor) { 165 TEST(ProxyServerTest, DefaultConstructor) {
164 net::ProxyServer proxy_server; 166 net::ProxyServer proxy_server;
165 EXPECT_FALSE(proxy_server.is_valid()); 167 EXPECT_FALSE(proxy_server.is_valid());
166 } 168 }
167 169
168 // Test parsing of the special URI form "direct://". Analagous to the "DIRECT" 170 // Test parsing of the special URI form "direct://". Analagous to the "DIRECT"
169 // entry in a PAC result. 171 // entry in a PAC result.
170 TEST(ProxyServerTest, Direct) { 172 TEST(ProxyServerTest, Direct) {
171 net::ProxyServer uri = net::ProxyServer::FromURI("direct://"); 173 net::ProxyServer uri =
174 net::ProxyServer::FromURI("direct://", net::ProxyServer::SCHEME_HTTP);
172 EXPECT_TRUE(uri.is_valid()); 175 EXPECT_TRUE(uri.is_valid());
173 EXPECT_TRUE(uri.is_direct()); 176 EXPECT_TRUE(uri.is_direct());
174 EXPECT_EQ("direct://", uri.ToURI()); 177 EXPECT_EQ("direct://", uri.ToURI());
175 EXPECT_EQ("DIRECT", uri.ToPacString()); 178 EXPECT_EQ("DIRECT", uri.ToPacString());
176 } 179 }
177 180
178 // Test parsing some invalid inputs. 181 // Test parsing some invalid inputs.
179 TEST(ProxyServerTest, Invalid) { 182 TEST(ProxyServerTest, Invalid) {
180 const char* tests[] = { 183 const char* tests[] = {
181 "", 184 "",
182 " ", 185 " ",
183 "dddf:", // not a valid port 186 "dddf:", // not a valid port
184 "dddd:d", // not a valid port 187 "dddd:d", // not a valid port
185 "http://", // not a valid host/port. 188 "http://", // not a valid host/port.
186 "direct://xyz", // direct is not allowed a host/port. 189 "direct://xyz", // direct is not allowed a host/port.
187 "http:/", // ambiguous, but will fail because of bad port. 190 "http:/", // ambiguous, but will fail because of bad port.
188 "http:", // ambiguous, but will fail because of bad port. 191 "http:", // ambiguous, but will fail because of bad port.
189 "https://blah", // "https" is not a valid proxy scheme. 192 "https://blah", // "https" is not a valid proxy scheme.
190 }; 193 };
191 194
192 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 195 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
193 net::ProxyServer uri = net::ProxyServer::FromURI(tests[i]); 196 net::ProxyServer uri =
197 net::ProxyServer::FromURI(tests[i], net::ProxyServer::SCHEME_HTTP);
194 EXPECT_FALSE(uri.is_valid()); 198 EXPECT_FALSE(uri.is_valid());
195 EXPECT_FALSE(uri.is_direct()); 199 EXPECT_FALSE(uri.is_direct());
196 EXPECT_FALSE(uri.is_http()); 200 EXPECT_FALSE(uri.is_http());
197 EXPECT_FALSE(uri.is_socks()); 201 EXPECT_FALSE(uri.is_socks());
198 } 202 }
199 } 203 }
200 204
201 // Test that LWS (SP | HT) is disregarded from the ends. 205 // Test that LWS (SP | HT) is disregarded from the ends.
202 TEST(ProxyServerTest, Whitespace) { 206 TEST(ProxyServerTest, Whitespace) {
203 const char* tests[] = { 207 const char* tests[] = {
204 " foopy:80", 208 " foopy:80",
205 "foopy:80 \t", 209 "foopy:80 \t",
206 " \tfoopy:80 ", 210 " \tfoopy:80 ",
207 }; 211 };
208 212
209 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 213 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
210 net::ProxyServer uri = net::ProxyServer::FromURI(tests[i]); 214 net::ProxyServer uri =
215 net::ProxyServer::FromURI(tests[i], net::ProxyServer::SCHEME_HTTP);
211 EXPECT_EQ("foopy:80", uri.ToURI()); 216 EXPECT_EQ("foopy:80", uri.ToURI());
212 } 217 }
213 } 218 }
214 219
215 // Test parsing a ProxyServer from a PAC representation. 220 // Test parsing a ProxyServer from a PAC representation.
216 TEST(ProxyServerTest, FromPACString) { 221 TEST(ProxyServerTest, FromPACString) {
217 const struct { 222 const struct {
218 const char* input_pac; 223 const char* input_pac;
219 const char* expected_uri; 224 const char* expected_uri;
220 } tests[] = { 225 } tests[] = {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 "PROXY", // missing host/port. 274 "PROXY", // missing host/port.
270 "SOCKS", // missing host/port. 275 "SOCKS", // missing host/port.
271 "DIRECT foopy:10", // direct cannot have host/port. 276 "DIRECT foopy:10", // direct cannot have host/port.
272 }; 277 };
273 278
274 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 279 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
275 net::ProxyServer uri = net::ProxyServer::FromPacString(tests[i]); 280 net::ProxyServer uri = net::ProxyServer::FromPacString(tests[i]);
276 EXPECT_FALSE(uri.is_valid()); 281 EXPECT_FALSE(uri.is_valid());
277 } 282 }
278 } 283 }
OLDNEW
« no previous file with comments | « net/proxy/proxy_server.cc ('k') | net/proxy/proxy_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698