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

Side by Side Diff: net/proxy/proxy_config_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_config_service_win_unittest.cc ('k') | net/proxy/proxy_list.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 "net/proxy/proxy_config.h" 5 #include "net/proxy/proxy_config.h"
6 #include "net/proxy/proxy_config_service_common_unittest.h" 6 #include "net/proxy/proxy_config_service_common_unittest.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace { 9 namespace {
10 static void ExpectProxyServerEquals(const char* expectation, 10 static void ExpectProxyServerEquals(const char* expectation,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 EXPECT_FALSE(config2.Equals(config1)); 42 EXPECT_FALSE(config2.Equals(config1));
43 43
44 config1.pac_url = GURL("http://wpad/wpad.dat"); 44 config1.pac_url = GURL("http://wpad/wpad.dat");
45 45
46 EXPECT_TRUE(config1.Equals(config2)); 46 EXPECT_TRUE(config1.Equals(config2));
47 EXPECT_TRUE(config2.Equals(config1)); 47 EXPECT_TRUE(config2.Equals(config1));
48 48
49 // Test |ProxyConfig::proxy_rules|. 49 // Test |ProxyConfig::proxy_rules|.
50 50
51 config2.proxy_rules.type = net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; 51 config2.proxy_rules.type = net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
52 config2.proxy_rules.single_proxy = net::ProxyServer::FromURI("myproxy:80"); 52 config2.proxy_rules.single_proxy =
53 net::ProxyServer::FromURI("myproxy:80", net::ProxyServer::SCHEME_HTTP);
53 54
54 EXPECT_FALSE(config1.Equals(config2)); 55 EXPECT_FALSE(config1.Equals(config2));
55 EXPECT_FALSE(config2.Equals(config1)); 56 EXPECT_FALSE(config2.Equals(config1));
56 57
57 config1.proxy_rules.type = net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; 58 config1.proxy_rules.type = net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
58 config1.proxy_rules.single_proxy = net::ProxyServer::FromURI("myproxy:100"); 59 config1.proxy_rules.single_proxy =
60 net::ProxyServer::FromURI("myproxy:100", net::ProxyServer::SCHEME_HTTP);
59 61
60 EXPECT_FALSE(config1.Equals(config2)); 62 EXPECT_FALSE(config1.Equals(config2));
61 EXPECT_FALSE(config2.Equals(config1)); 63 EXPECT_FALSE(config2.Equals(config1));
62 64
63 config1.proxy_rules.single_proxy = net::ProxyServer::FromURI("myproxy"); 65 config1.proxy_rules.single_proxy =
66 net::ProxyServer::FromURI("myproxy", net::ProxyServer::SCHEME_HTTP);
64 67
65 EXPECT_TRUE(config1.Equals(config2)); 68 EXPECT_TRUE(config1.Equals(config2));
66 EXPECT_TRUE(config2.Equals(config1)); 69 EXPECT_TRUE(config2.Equals(config1));
67 70
68 // Test |ProxyConfig::proxy_bypass|. 71 // Test |ProxyConfig::proxy_bypass|.
69 72
70 config2.proxy_bypass.push_back("*.google.com"); 73 config2.proxy_bypass.push_back("*.google.com");
71 74
72 EXPECT_FALSE(config1.Equals(config2)); 75 EXPECT_FALSE(config1.Equals(config2));
73 EXPECT_FALSE(config2.Equals(config1)); 76 EXPECT_FALSE(config2.Equals(config1));
(...skipping 18 matching lines...) Expand all
92 95
93 TEST(ProxyConfigTest, ParseProxyRules) { 96 TEST(ProxyConfigTest, ParseProxyRules) {
94 const struct { 97 const struct {
95 const char* proxy_rules; 98 const char* proxy_rules;
96 99
97 net::ProxyConfig::ProxyRules::Type type; 100 net::ProxyConfig::ProxyRules::Type type;
98 const char* single_proxy; 101 const char* single_proxy;
99 const char* proxy_for_http; 102 const char* proxy_for_http;
100 const char* proxy_for_https; 103 const char* proxy_for_https;
101 const char* proxy_for_ftp; 104 const char* proxy_for_ftp;
105 const char* socks_proxy;
102 } tests[] = { 106 } tests[] = {
103 // One HTTP proxy for all schemes. 107 // One HTTP proxy for all schemes.
104 { 108 {
105 "myproxy:80", 109 "myproxy:80",
106 110
107 net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, 111 net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
108 "myproxy:80", 112 "myproxy:80",
109 NULL, 113 NULL,
110 NULL, 114 NULL,
111 NULL, 115 NULL,
116 NULL,
112 }, 117 },
113 118
114 // Only specify a proxy server for "http://" urls. 119 // Only specify a proxy server for "http://" urls.
115 { 120 {
116 "http=myproxy:80", 121 "http=myproxy:80",
117 122
118 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 123 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
119 NULL, 124 NULL,
120 "myproxy:80", 125 "myproxy:80",
121 NULL, 126 NULL,
122 NULL, 127 NULL,
128 NULL,
123 }, 129 },
124 130
125 // Specify an HTTP proxy for "ftp://" and a SOCKS proxy for "https://" urls. 131 // Specify an HTTP proxy for "ftp://" and a SOCKS proxy for "https://" urls.
126 { 132 {
127 "ftp=ftp-proxy ; https=socks4://foopy", 133 "ftp=ftp-proxy ; https=socks4://foopy",
128 134
129 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 135 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
130 NULL, 136 NULL,
131 NULL, 137 NULL,
132 "socks4://foopy:1080", 138 "socks4://foopy:1080",
133 "ftp-proxy:80", 139 "ftp-proxy:80",
140 NULL,
134 }, 141 },
135 142
136 // Give a scheme-specific proxy as well as a non-scheme specific. 143 // Give a scheme-specific proxy as well as a non-scheme specific.
137 // The first entry "foopy" takes precedance marking this list as 144 // The first entry "foopy" takes precedance marking this list as
138 // TYPE_SINGLE_PROXY. 145 // TYPE_SINGLE_PROXY.
139 { 146 {
140 "foopy ; ftp=ftp-proxy", 147 "foopy ; ftp=ftp-proxy",
141 148
142 net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, 149 net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
143 "foopy:80", 150 "foopy:80",
144 NULL, 151 NULL,
145 NULL, 152 NULL,
146 NULL, 153 NULL,
154 NULL,
147 }, 155 },
148 156
149 // Give a scheme-specific proxy as well as a non-scheme specific. 157 // Give a scheme-specific proxy as well as a non-scheme specific.
150 // The first entry "ftp=ftp-proxy" takes precedance marking this list as 158 // The first entry "ftp=ftp-proxy" takes precedance marking this list as
151 // TYPE_PROXY_PER_SCHEME. 159 // TYPE_PROXY_PER_SCHEME.
152 { 160 {
153 "ftp=ftp-proxy ; foopy", 161 "ftp=ftp-proxy ; foopy",
154 162
155 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 163 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
156 NULL, 164 NULL,
157 NULL, 165 NULL,
158 NULL, 166 NULL,
159 "ftp-proxy:80", 167 "ftp-proxy:80",
168 NULL,
160 }, 169 },
161 170
162 // Include duplicate entries -- last one wins. 171 // Include duplicate entries -- last one wins.
163 { 172 {
164 "ftp=ftp1 ; ftp=ftp2 ; ftp=ftp3", 173 "ftp=ftp1 ; ftp=ftp2 ; ftp=ftp3",
165 174
166 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 175 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
167 NULL, 176 NULL,
168 NULL, 177 NULL,
169 NULL, 178 NULL,
170 "ftp3:80", 179 "ftp3:80",
180 NULL,
171 }, 181 },
172 182
173 // Only socks proxy present, others being blank. 183 // Only SOCKS proxy present, others being blank.
174 { // NOLINT 184 {
175 "socks=foopy", 185 "socks=foopy",
176 186
177 net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, 187 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
178 "socks4://foopy:1080",
179 NULL, 188 NULL,
180 NULL, 189 NULL,
181 NULL, 190 NULL,
191 NULL,
192 "socks4://foopy:1080",
193 },
194
195 // SOCKS proxy present along with other proxies too
196 {
197 "http=httpproxy ; https=httpsproxy ; ftp=ftpproxy ; socks=foopy ",
198
199 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
200 NULL,
201 "httpproxy:80",
202 "httpsproxy:80",
203 "ftpproxy:80",
204 "socks4://foopy:1080",
182 }, 205 },
183 206
207 // SOCKS proxy (with modifier) present along with some proxies
208 // (FTP being blank)
209 {
210 "http=httpproxy ; https=httpsproxy ; socks=socks5://foopy ",
211
212 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
213 NULL,
214 "httpproxy:80",
215 "httpsproxy:80",
216 NULL,
217 "socks5://foopy:1080",
218 },
219
184 // Include unsupported schemes -- they are discarded. 220 // Include unsupported schemes -- they are discarded.
185 { 221 {
186 "crazy=foopy ; foo=bar ; https=myhttpsproxy", 222 "crazy=foopy ; foo=bar ; https=myhttpsproxy",
187 223
188 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 224 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
189 NULL, 225 NULL,
190 NULL, 226 NULL,
191 "myhttpsproxy:80", 227 "myhttpsproxy:80",
192 NULL, 228 NULL,
229 NULL,
193 }, 230 },
194 }; 231 };
195 232
196 net::ProxyConfig config; 233 net::ProxyConfig config;
197 234
198 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 235 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
199 config.proxy_rules.ParseFromString(tests[i].proxy_rules); 236 config.proxy_rules.ParseFromString(tests[i].proxy_rules);
200 237
201 EXPECT_EQ(tests[i].type, config.proxy_rules.type); 238 EXPECT_EQ(tests[i].type, config.proxy_rules.type);
202 ExpectProxyServerEquals(tests[i].single_proxy, 239 ExpectProxyServerEquals(tests[i].single_proxy,
203 config.proxy_rules.single_proxy); 240 config.proxy_rules.single_proxy);
204 ExpectProxyServerEquals(tests[i].proxy_for_http, 241 ExpectProxyServerEquals(tests[i].proxy_for_http,
205 config.proxy_rules.proxy_for_http); 242 config.proxy_rules.proxy_for_http);
206 ExpectProxyServerEquals(tests[i].proxy_for_https, 243 ExpectProxyServerEquals(tests[i].proxy_for_https,
207 config.proxy_rules.proxy_for_https); 244 config.proxy_rules.proxy_for_https);
208 ExpectProxyServerEquals(tests[i].proxy_for_ftp, 245 ExpectProxyServerEquals(tests[i].proxy_for_ftp,
209 config.proxy_rules.proxy_for_ftp); 246 config.proxy_rules.proxy_for_ftp);
247 ExpectProxyServerEquals(tests[i].socks_proxy,
248 config.proxy_rules.socks_proxy);
210 } 249 }
211 } 250 }
212 251
213 TEST(ProxyConfigTest, ParseProxyBypassList) { 252 TEST(ProxyConfigTest, ParseProxyBypassList) {
214 struct bypass_test { 253 struct bypass_test {
215 const char* proxy_bypass_input; 254 const char* proxy_bypass_input;
216 const char* flattened_output; 255 const char* flattened_output;
217 }; 256 };
218 257
219 const struct { 258 const struct {
(...skipping 15 matching lines...) Expand all
235 }; 274 };
236 275
237 net::ProxyConfig config; 276 net::ProxyConfig config;
238 277
239 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 278 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
240 config.ParseNoProxyList(tests[i].proxy_bypass_input); 279 config.ParseNoProxyList(tests[i].proxy_bypass_input);
241 EXPECT_EQ(tests[i].flattened_output, 280 EXPECT_EQ(tests[i].flattened_output,
242 net::FlattenProxyBypass(config.proxy_bypass)); 281 net::FlattenProxyBypass(config.proxy_bypass));
243 } 282 }
244 } 283 }
OLDNEW
« no previous file with comments | « net/proxy/proxy_config_service_win_unittest.cc ('k') | net/proxy/proxy_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698