OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 }; | 85 }; |
86 | 86 |
87 TEST(ProxyServiceTest, Direct) { | 87 TEST(ProxyServiceTest, Direct) { |
88 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 88 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
89 ProxyService service(new MockProxyConfigService, resolver); | 89 ProxyService service(new MockProxyConfigService, resolver); |
90 | 90 |
91 GURL url("http://www.google.com/"); | 91 GURL url("http://www.google.com/"); |
92 | 92 |
93 ProxyInfo info; | 93 ProxyInfo info; |
94 TestCompletionCallback callback; | 94 TestCompletionCallback callback; |
95 int rv = service.ResolveProxy(url, &info, &callback, NULL); | 95 int rv = service.ResolveProxy(NULL, url, &info, &callback, NULL); |
96 EXPECT_EQ(OK, rv); | 96 EXPECT_EQ(OK, rv); |
97 EXPECT_TRUE(resolver->pending_requests().empty()); | 97 EXPECT_TRUE(resolver->pending_requests().empty()); |
98 | 98 |
99 EXPECT_TRUE(info.is_direct()); | 99 EXPECT_TRUE(info.is_direct()); |
100 } | 100 } |
101 | 101 |
102 TEST(ProxyServiceTest, PAC) { | 102 TEST(ProxyServiceTest, PAC) { |
103 MockProxyConfigService* config_service = | 103 MockProxyConfigService* config_service = |
104 new MockProxyConfigService("http://foopy/proxy.pac"); | 104 new MockProxyConfigService("http://foopy/proxy.pac"); |
105 | 105 |
106 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 106 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
107 | 107 |
108 ProxyService service(config_service, resolver); | 108 ProxyService service(config_service, resolver); |
109 | 109 |
110 GURL url("http://www.google.com/"); | 110 GURL url("http://www.google.com/"); |
111 | 111 |
112 ProxyInfo info; | 112 ProxyInfo info; |
113 TestCompletionCallback callback; | 113 TestCompletionCallback callback; |
114 int rv = service.ResolveProxy(url, &info, &callback, NULL); | 114 int rv = service.ResolveProxy(NULL, url, &info, &callback, NULL); |
115 EXPECT_EQ(ERR_IO_PENDING, rv); | 115 EXPECT_EQ(ERR_IO_PENDING, rv); |
116 | 116 |
117 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 117 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
118 resolver->pending_set_pac_script_request()->pac_url()); | 118 resolver->pending_set_pac_script_request()->pac_url()); |
119 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 119 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
120 | 120 |
121 ASSERT_EQ(1u, resolver->pending_requests().size()); | 121 ASSERT_EQ(1u, resolver->pending_requests().size()); |
122 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 122 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
123 | 123 |
124 // Set the result in proxy resolver. | 124 // Set the result in proxy resolver. |
(...skipping 12 matching lines...) Expand all Loading... |
137 new MockProxyConfigService("http://foopy/proxy.pac"); | 137 new MockProxyConfigService("http://foopy/proxy.pac"); |
138 | 138 |
139 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 139 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
140 | 140 |
141 ProxyService service(config_service, resolver); | 141 ProxyService service(config_service, resolver); |
142 | 142 |
143 GURL url("http://username:password@www.google.com/?ref#hash#hash"); | 143 GURL url("http://username:password@www.google.com/?ref#hash#hash"); |
144 | 144 |
145 ProxyInfo info; | 145 ProxyInfo info; |
146 TestCompletionCallback callback; | 146 TestCompletionCallback callback; |
147 int rv = service.ResolveProxy(url, &info, &callback, NULL); | 147 int rv = service.ResolveProxy(NULL, url, &info, &callback, NULL); |
148 EXPECT_EQ(ERR_IO_PENDING, rv); | 148 EXPECT_EQ(ERR_IO_PENDING, rv); |
149 | 149 |
150 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 150 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
151 resolver->pending_set_pac_script_request()->pac_url()); | 151 resolver->pending_set_pac_script_request()->pac_url()); |
152 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 152 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
153 | 153 |
154 ASSERT_EQ(1u, resolver->pending_requests().size()); | 154 ASSERT_EQ(1u, resolver->pending_requests().size()); |
155 // The URL should have been simplified, stripping the username/password/hash. | 155 // The URL should have been simplified, stripping the username/password/hash. |
156 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 156 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
157 resolver->pending_requests()[0]->url()); | 157 resolver->pending_requests()[0]->url()); |
158 | 158 |
159 // We end here without ever completing the request -- destruction of | 159 // We end here without ever completing the request -- destruction of |
160 // ProxyService will cancel the outstanding request. | 160 // ProxyService will cancel the outstanding request. |
161 } | 161 } |
162 | 162 |
163 TEST(ProxyServiceTest, PAC_FailoverToDirect) { | 163 TEST(ProxyServiceTest, PAC_FailoverToDirect) { |
164 MockProxyConfigService* config_service = | 164 MockProxyConfigService* config_service = |
165 new MockProxyConfigService("http://foopy/proxy.pac"); | 165 new MockProxyConfigService("http://foopy/proxy.pac"); |
166 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 166 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
167 | 167 |
168 ProxyService service(config_service, resolver); | 168 ProxyService service(config_service, resolver); |
169 | 169 |
170 GURL url("http://www.google.com/"); | 170 GURL url("http://www.google.com/"); |
171 | 171 |
172 ProxyInfo info; | 172 ProxyInfo info; |
173 TestCompletionCallback callback1; | 173 TestCompletionCallback callback1; |
174 int rv = service.ResolveProxy(url, &info, &callback1, NULL); | 174 int rv = service.ResolveProxy(NULL, url, &info, &callback1, NULL); |
175 EXPECT_EQ(ERR_IO_PENDING, rv); | 175 EXPECT_EQ(ERR_IO_PENDING, rv); |
176 | 176 |
177 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 177 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
178 resolver->pending_set_pac_script_request()->pac_url()); | 178 resolver->pending_set_pac_script_request()->pac_url()); |
179 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 179 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
180 | 180 |
181 ASSERT_EQ(1u, resolver->pending_requests().size()); | 181 ASSERT_EQ(1u, resolver->pending_requests().size()); |
182 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 182 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
183 | 183 |
184 // Set the result in proxy resolver. | 184 // Set the result in proxy resolver. |
185 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); | 185 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); |
186 resolver->pending_requests()[0]->CompleteNow(OK); | 186 resolver->pending_requests()[0]->CompleteNow(OK); |
187 | 187 |
188 EXPECT_EQ(OK, callback1.WaitForResult()); | 188 EXPECT_EQ(OK, callback1.WaitForResult()); |
189 EXPECT_FALSE(info.is_direct()); | 189 EXPECT_FALSE(info.is_direct()); |
190 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); | 190 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); |
191 | 191 |
192 // Now, imagine that connecting to foopy:8080 fails. | 192 // Now, imagine that connecting to foopy:8080 fails. |
193 TestCompletionCallback callback2; | 193 TestCompletionCallback callback2; |
194 rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL); | 194 rv = service.ReconsiderProxyAfterError(NULL, url, &info, &callback2, NULL); |
195 EXPECT_EQ(OK, rv); | 195 EXPECT_EQ(OK, rv); |
196 EXPECT_TRUE(info.is_direct()); | 196 EXPECT_TRUE(info.is_direct()); |
197 } | 197 } |
198 | 198 |
199 TEST(ProxyServiceTest, ProxyResolverFails) { | 199 TEST(ProxyServiceTest, ProxyResolverFails) { |
200 // Test what happens when the ProxyResolver fails (this could represent | 200 // Test what happens when the ProxyResolver fails (this could represent |
201 // a failure to download the PAC script in the case of ProxyResolvers which | 201 // a failure to download the PAC script in the case of ProxyResolvers which |
202 // do the fetch internally.) | 202 // do the fetch internally.) |
203 // TODO(eroman): change this comment. | 203 // TODO(eroman): change this comment. |
204 | 204 |
205 MockProxyConfigService* config_service = | 205 MockProxyConfigService* config_service = |
206 new MockProxyConfigService("http://foopy/proxy.pac"); | 206 new MockProxyConfigService("http://foopy/proxy.pac"); |
207 | 207 |
208 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 208 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
209 | 209 |
210 ProxyService service(config_service, resolver); | 210 ProxyService service(config_service, resolver); |
211 | 211 |
212 // Start first resolve request. | 212 // Start first resolve request. |
213 GURL url("http://www.google.com/"); | 213 GURL url("http://www.google.com/"); |
214 ProxyInfo info; | 214 ProxyInfo info; |
215 TestCompletionCallback callback1; | 215 TestCompletionCallback callback1; |
216 int rv = service.ResolveProxy(url, &info, &callback1, NULL); | 216 int rv = service.ResolveProxy(NULL, url, &info, &callback1, NULL); |
217 EXPECT_EQ(ERR_IO_PENDING, rv); | 217 EXPECT_EQ(ERR_IO_PENDING, rv); |
218 | 218 |
219 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 219 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
220 resolver->pending_set_pac_script_request()->pac_url()); | 220 resolver->pending_set_pac_script_request()->pac_url()); |
221 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 221 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
222 | 222 |
223 ASSERT_EQ(1u, resolver->pending_requests().size()); | 223 ASSERT_EQ(1u, resolver->pending_requests().size()); |
224 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 224 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
225 | 225 |
226 // Fail the first resolve request in MockAsyncProxyResolver. | 226 // Fail the first resolve request in MockAsyncProxyResolver. |
227 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 227 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
228 | 228 |
229 EXPECT_EQ(ERR_FAILED, callback1.WaitForResult()); | 229 EXPECT_EQ(ERR_FAILED, callback1.WaitForResult()); |
230 | 230 |
231 // The second resolve request will automatically select direct connect, | 231 // The second resolve request will automatically select direct connect, |
232 // because it has cached the configuration as being bad. | 232 // because it has cached the configuration as being bad. |
233 TestCompletionCallback callback2; | 233 TestCompletionCallback callback2; |
234 rv = service.ResolveProxy(url, &info, &callback2, NULL); | 234 rv = service.ResolveProxy(NULL, url, &info, &callback2, NULL); |
235 EXPECT_EQ(OK, rv); | 235 EXPECT_EQ(OK, rv); |
236 EXPECT_TRUE(info.is_direct()); | 236 EXPECT_TRUE(info.is_direct()); |
237 EXPECT_TRUE(resolver->pending_requests().empty()); | 237 EXPECT_TRUE(resolver->pending_requests().empty()); |
238 | 238 |
239 // But, if that fails, then we should give the proxy config another shot | 239 // But, if that fails, then we should give the proxy config another shot |
240 // since we have never tried it with this URL before. | 240 // since we have never tried it with this URL before. |
241 TestCompletionCallback callback3; | 241 TestCompletionCallback callback3; |
242 rv = service.ReconsiderProxyAfterError(url, &info, &callback3, NULL); | 242 rv = service.ReconsiderProxyAfterError(NULL, url, &info, &callback3, NULL); |
243 EXPECT_EQ(ERR_IO_PENDING, rv); | 243 EXPECT_EQ(ERR_IO_PENDING, rv); |
244 | 244 |
245 ASSERT_EQ(1u, resolver->pending_requests().size()); | 245 ASSERT_EQ(1u, resolver->pending_requests().size()); |
246 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 246 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
247 | 247 |
248 // Set the result in proxy resolver. | 248 // Set the result in proxy resolver. |
249 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 249 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
250 resolver->pending_requests()[0]->CompleteNow(OK); | 250 resolver->pending_requests()[0]->CompleteNow(OK); |
251 | 251 |
252 EXPECT_EQ(OK, callback3.WaitForResult()); | 252 EXPECT_EQ(OK, callback3.WaitForResult()); |
(...skipping 10 matching lines...) Expand all Loading... |
263 | 263 |
264 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 264 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
265 | 265 |
266 ProxyService service(config_service, resolver); | 266 ProxyService service(config_service, resolver); |
267 | 267 |
268 GURL url("http://www.google.com/"); | 268 GURL url("http://www.google.com/"); |
269 | 269 |
270 // Get the proxy information. | 270 // Get the proxy information. |
271 ProxyInfo info; | 271 ProxyInfo info; |
272 TestCompletionCallback callback1; | 272 TestCompletionCallback callback1; |
273 int rv = service.ResolveProxy(url, &info, &callback1, NULL); | 273 int rv = service.ResolveProxy(NULL, url, &info, &callback1, NULL); |
274 EXPECT_EQ(ERR_IO_PENDING, rv); | 274 EXPECT_EQ(ERR_IO_PENDING, rv); |
275 | 275 |
276 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 276 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
277 resolver->pending_set_pac_script_request()->pac_url()); | 277 resolver->pending_set_pac_script_request()->pac_url()); |
278 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 278 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
279 | 279 |
280 ASSERT_EQ(1u, resolver->pending_requests().size()); | 280 ASSERT_EQ(1u, resolver->pending_requests().size()); |
281 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 281 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
282 | 282 |
283 // Set the result in proxy resolver. | 283 // Set the result in proxy resolver. |
284 resolver->pending_requests()[0]->results()->UseNamedProxy( | 284 resolver->pending_requests()[0]->results()->UseNamedProxy( |
285 "foopy1:8080;foopy2:9090"); | 285 "foopy1:8080;foopy2:9090"); |
286 resolver->pending_requests()[0]->CompleteNow(OK); | 286 resolver->pending_requests()[0]->CompleteNow(OK); |
287 | 287 |
288 // The first item is valid. | 288 // The first item is valid. |
289 EXPECT_EQ(OK, callback1.WaitForResult()); | 289 EXPECT_EQ(OK, callback1.WaitForResult()); |
290 EXPECT_FALSE(info.is_direct()); | 290 EXPECT_FALSE(info.is_direct()); |
291 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 291 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
292 | 292 |
293 // Fake an error on the proxy. | 293 // Fake an error on the proxy. |
294 TestCompletionCallback callback2; | 294 TestCompletionCallback callback2; |
295 rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL); | 295 rv = service.ReconsiderProxyAfterError(NULL, url, &info, &callback2, NULL); |
296 EXPECT_EQ(OK, rv); | 296 EXPECT_EQ(OK, rv); |
297 | 297 |
298 // The second proxy should be specified. | 298 // The second proxy should be specified. |
299 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 299 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
300 | 300 |
301 TestCompletionCallback callback3; | 301 TestCompletionCallback callback3; |
302 rv = service.ResolveProxy(url, &info, &callback3, NULL); | 302 rv = service.ResolveProxy(NULL, url, &info, &callback3, NULL); |
303 EXPECT_EQ(ERR_IO_PENDING, rv); | 303 EXPECT_EQ(ERR_IO_PENDING, rv); |
304 | 304 |
305 ASSERT_EQ(1u, resolver->pending_requests().size()); | 305 ASSERT_EQ(1u, resolver->pending_requests().size()); |
306 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 306 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
307 | 307 |
308 // Set the result in proxy resolver -- the second result is already known | 308 // Set the result in proxy resolver -- the second result is already known |
309 // to be bad. | 309 // to be bad. |
310 resolver->pending_requests()[0]->results()->UseNamedProxy( | 310 resolver->pending_requests()[0]->results()->UseNamedProxy( |
311 "foopy3:7070;foopy1:8080;foopy2:9090"); | 311 "foopy3:7070;foopy1:8080;foopy2:9090"); |
312 resolver->pending_requests()[0]->CompleteNow(OK); | 312 resolver->pending_requests()[0]->CompleteNow(OK); |
313 | 313 |
314 EXPECT_EQ(OK, callback3.WaitForResult()); | 314 EXPECT_EQ(OK, callback3.WaitForResult()); |
315 EXPECT_FALSE(info.is_direct()); | 315 EXPECT_FALSE(info.is_direct()); |
316 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 316 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
317 | 317 |
318 // We fake another error. It should now try the third one. | 318 // We fake another error. It should now try the third one. |
319 TestCompletionCallback callback4; | 319 TestCompletionCallback callback4; |
320 rv = service.ReconsiderProxyAfterError(url, &info, &callback4, NULL); | 320 rv = service.ReconsiderProxyAfterError(NULL, url, &info, &callback4, NULL); |
321 EXPECT_EQ(OK, rv); | 321 EXPECT_EQ(OK, rv); |
322 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 322 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
323 | 323 |
324 // Fake another error, the last proxy is gone, the list should now be empty. | 324 // Fake another error, the last proxy is gone, the list should now be empty. |
325 TestCompletionCallback callback5; | 325 TestCompletionCallback callback5; |
326 rv = service.ReconsiderProxyAfterError(url, &info, &callback5, NULL); | 326 rv = service.ReconsiderProxyAfterError(NULL, url, &info, &callback5, NULL); |
327 EXPECT_EQ(OK, rv); // We try direct. | 327 EXPECT_EQ(OK, rv); // We try direct. |
328 EXPECT_TRUE(info.is_direct()); | 328 EXPECT_TRUE(info.is_direct()); |
329 | 329 |
330 // If it fails again, we don't have anything else to try. | 330 // If it fails again, we don't have anything else to try. |
331 TestCompletionCallback callback6; | 331 TestCompletionCallback callback6; |
332 rv = service.ReconsiderProxyAfterError(url, &info, &callback6, NULL); | 332 rv = service.ReconsiderProxyAfterError(NULL, url, &info, &callback6, NULL); |
333 EXPECT_EQ(ERR_FAILED, rv); | 333 EXPECT_EQ(ERR_FAILED, rv); |
334 | 334 |
335 // TODO(nsylvain): Test that the proxy can be retried after the delay. | 335 // TODO(nsylvain): Test that the proxy can be retried after the delay. |
336 } | 336 } |
337 | 337 |
338 TEST(ProxyServiceTest, ProxyFallback_NewSettings) { | 338 TEST(ProxyServiceTest, ProxyFallback_NewSettings) { |
339 // Test proxy failover when new settings are available. | 339 // Test proxy failover when new settings are available. |
340 | 340 |
341 MockProxyConfigService* config_service = | 341 MockProxyConfigService* config_service = |
342 new MockProxyConfigService("http://foopy/proxy.pac"); | 342 new MockProxyConfigService("http://foopy/proxy.pac"); |
343 | 343 |
344 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 344 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
345 | 345 |
346 ProxyService service(config_service, resolver); | 346 ProxyService service(config_service, resolver); |
347 | 347 |
348 GURL url("http://www.google.com/"); | 348 GURL url("http://www.google.com/"); |
349 | 349 |
350 // Get the proxy information. | 350 // Get the proxy information. |
351 ProxyInfo info; | 351 ProxyInfo info; |
352 TestCompletionCallback callback1; | 352 TestCompletionCallback callback1; |
353 int rv = service.ResolveProxy(url, &info, &callback1, NULL); | 353 int rv = service.ResolveProxy(NULL, url, &info, &callback1, NULL); |
354 EXPECT_EQ(ERR_IO_PENDING, rv); | 354 EXPECT_EQ(ERR_IO_PENDING, rv); |
355 | 355 |
356 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 356 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
357 resolver->pending_set_pac_script_request()->pac_url()); | 357 resolver->pending_set_pac_script_request()->pac_url()); |
358 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 358 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
359 | 359 |
360 ASSERT_EQ(1u, resolver->pending_requests().size()); | 360 ASSERT_EQ(1u, resolver->pending_requests().size()); |
361 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 361 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
362 | 362 |
363 // Set the result in proxy resolver. | 363 // Set the result in proxy resolver. |
364 resolver->pending_requests()[0]->results()->UseNamedProxy( | 364 resolver->pending_requests()[0]->results()->UseNamedProxy( |
365 "foopy1:8080;foopy2:9090"); | 365 "foopy1:8080;foopy2:9090"); |
366 resolver->pending_requests()[0]->CompleteNow(OK); | 366 resolver->pending_requests()[0]->CompleteNow(OK); |
367 | 367 |
368 // The first item is valid. | 368 // The first item is valid. |
369 EXPECT_EQ(OK, callback1.WaitForResult()); | 369 EXPECT_EQ(OK, callback1.WaitForResult()); |
370 EXPECT_FALSE(info.is_direct()); | 370 EXPECT_FALSE(info.is_direct()); |
371 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 371 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
372 | 372 |
373 // Fake an error on the proxy, and also a new configuration on the proxy. | 373 // Fake an error on the proxy, and also a new configuration on the proxy. |
374 config_service->config = ProxyConfig(); | 374 config_service->config = ProxyConfig(); |
375 config_service->config.pac_url = GURL("http://foopy-new/proxy.pac"); | 375 config_service->config.pac_url = GURL("http://foopy-new/proxy.pac"); |
376 | 376 |
377 TestCompletionCallback callback2; | 377 TestCompletionCallback callback2; |
378 rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL); | 378 rv = service.ReconsiderProxyAfterError(NULL, url, &info, &callback2, NULL); |
379 EXPECT_EQ(ERR_IO_PENDING, rv); | 379 EXPECT_EQ(ERR_IO_PENDING, rv); |
380 | 380 |
381 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), | 381 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), |
382 resolver->pending_set_pac_script_request()->pac_url()); | 382 resolver->pending_set_pac_script_request()->pac_url()); |
383 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 383 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
384 | 384 |
385 ASSERT_EQ(1u, resolver->pending_requests().size()); | 385 ASSERT_EQ(1u, resolver->pending_requests().size()); |
386 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 386 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
387 | 387 |
388 resolver->pending_requests()[0]->results()->UseNamedProxy( | 388 resolver->pending_requests()[0]->results()->UseNamedProxy( |
389 "foopy1:8080;foopy2:9090"); | 389 "foopy1:8080;foopy2:9090"); |
390 resolver->pending_requests()[0]->CompleteNow(OK); | 390 resolver->pending_requests()[0]->CompleteNow(OK); |
391 | 391 |
392 // The first proxy is still there since the configuration changed. | 392 // The first proxy is still there since the configuration changed. |
393 EXPECT_EQ(OK, callback2.WaitForResult()); | 393 EXPECT_EQ(OK, callback2.WaitForResult()); |
394 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 394 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
395 | 395 |
396 // We fake another error. It should now ignore the first one. | 396 // We fake another error. It should now ignore the first one. |
397 TestCompletionCallback callback3; | 397 TestCompletionCallback callback3; |
398 rv = service.ReconsiderProxyAfterError(url, &info, &callback3, NULL); | 398 rv = service.ReconsiderProxyAfterError(NULL, url, &info, &callback3, NULL); |
399 EXPECT_EQ(OK, rv); | 399 EXPECT_EQ(OK, rv); |
400 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 400 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
401 | 401 |
402 // We simulate a new configuration. | 402 // We simulate a new configuration. |
403 config_service->config = ProxyConfig(); | 403 config_service->config = ProxyConfig(); |
404 config_service->config.pac_url = GURL("http://foopy-new2/proxy.pac"); | 404 config_service->config.pac_url = GURL("http://foopy-new2/proxy.pac"); |
405 | 405 |
406 // We fake another error. It should go back to the first proxy. | 406 // We fake another error. It should go back to the first proxy. |
407 TestCompletionCallback callback4; | 407 TestCompletionCallback callback4; |
408 rv = service.ReconsiderProxyAfterError(url, &info, &callback4, NULL); | 408 rv = service.ReconsiderProxyAfterError(NULL, url, &info, &callback4, NULL); |
409 EXPECT_EQ(ERR_IO_PENDING, rv); | 409 EXPECT_EQ(ERR_IO_PENDING, rv); |
410 | 410 |
411 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), | 411 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), |
412 resolver->pending_set_pac_script_request()->pac_url()); | 412 resolver->pending_set_pac_script_request()->pac_url()); |
413 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 413 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
414 | 414 |
415 ASSERT_EQ(1u, resolver->pending_requests().size()); | 415 ASSERT_EQ(1u, resolver->pending_requests().size()); |
416 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 416 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
417 | 417 |
418 resolver->pending_requests()[0]->results()->UseNamedProxy( | 418 resolver->pending_requests()[0]->results()->UseNamedProxy( |
(...skipping 12 matching lines...) Expand all Loading... |
431 | 431 |
432 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 432 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
433 | 433 |
434 ProxyService service(config_service, resolver); | 434 ProxyService service(config_service, resolver); |
435 | 435 |
436 GURL url("http://www.google.com/"); | 436 GURL url("http://www.google.com/"); |
437 | 437 |
438 // Get the proxy information. | 438 // Get the proxy information. |
439 ProxyInfo info; | 439 ProxyInfo info; |
440 TestCompletionCallback callback1; | 440 TestCompletionCallback callback1; |
441 int rv = service.ResolveProxy(url, &info, &callback1, NULL); | 441 int rv = service.ResolveProxy(NULL, url, &info, &callback1, NULL); |
442 EXPECT_EQ(ERR_IO_PENDING, rv); | 442 EXPECT_EQ(ERR_IO_PENDING, rv); |
443 | 443 |
444 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 444 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
445 resolver->pending_set_pac_script_request()->pac_url()); | 445 resolver->pending_set_pac_script_request()->pac_url()); |
446 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 446 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
447 ASSERT_EQ(1u, resolver->pending_requests().size()); | 447 ASSERT_EQ(1u, resolver->pending_requests().size()); |
448 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 448 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
449 | 449 |
450 resolver->pending_requests()[0]->results()->UseNamedProxy( | 450 resolver->pending_requests()[0]->results()->UseNamedProxy( |
451 "foopy1:8080;foopy2:9090"); | 451 "foopy1:8080;foopy2:9090"); |
452 resolver->pending_requests()[0]->CompleteNow(OK); | 452 resolver->pending_requests()[0]->CompleteNow(OK); |
453 | 453 |
454 // The first item is valid. | 454 // The first item is valid. |
455 EXPECT_EQ(OK, callback1.WaitForResult()); | 455 EXPECT_EQ(OK, callback1.WaitForResult()); |
456 EXPECT_FALSE(info.is_direct()); | 456 EXPECT_FALSE(info.is_direct()); |
457 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 457 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
458 | 458 |
459 // Fake a proxy error. | 459 // Fake a proxy error. |
460 TestCompletionCallback callback2; | 460 TestCompletionCallback callback2; |
461 rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL); | 461 rv = service.ReconsiderProxyAfterError(NULL, url, &info, &callback2, NULL); |
462 EXPECT_EQ(OK, rv); | 462 EXPECT_EQ(OK, rv); |
463 | 463 |
464 // The first proxy is ignored, and the second one is selected. | 464 // The first proxy is ignored, and the second one is selected. |
465 EXPECT_FALSE(info.is_direct()); | 465 EXPECT_FALSE(info.is_direct()); |
466 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 466 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
467 | 467 |
468 // Fake a PAC failure. | 468 // Fake a PAC failure. |
469 ProxyInfo info2; | 469 ProxyInfo info2; |
470 TestCompletionCallback callback3; | 470 TestCompletionCallback callback3; |
471 rv = service.ResolveProxy(url, &info2, &callback3, NULL); | 471 rv = service.ResolveProxy(NULL, url, &info2, &callback3, NULL); |
472 EXPECT_EQ(ERR_IO_PENDING, rv); | 472 EXPECT_EQ(ERR_IO_PENDING, rv); |
473 | 473 |
474 ASSERT_EQ(1u, resolver->pending_requests().size()); | 474 ASSERT_EQ(1u, resolver->pending_requests().size()); |
475 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 475 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
476 | 476 |
477 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 477 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
478 | 478 |
479 // No proxy servers are returned. It's a direct connection. | 479 // No proxy servers are returned. It's a direct connection. |
480 EXPECT_EQ(ERR_FAILED, callback3.WaitForResult()); | 480 EXPECT_EQ(ERR_FAILED, callback3.WaitForResult()); |
481 EXPECT_TRUE(info2.is_direct()); | 481 EXPECT_TRUE(info2.is_direct()); |
482 | 482 |
483 // The PAC will now be fixed and will return a proxy server. | 483 // The PAC will now be fixed and will return a proxy server. |
484 // It should also clear the list of bad proxies. | 484 // It should also clear the list of bad proxies. |
485 | 485 |
486 // Try to resolve, it will still return "direct" because we have no reason | 486 // Try to resolve, it will still return "direct" because we have no reason |
487 // to check the config since everything works. | 487 // to check the config since everything works. |
488 ProxyInfo info3; | 488 ProxyInfo info3; |
489 TestCompletionCallback callback4; | 489 TestCompletionCallback callback4; |
490 rv = service.ResolveProxy(url, &info3, &callback4, NULL); | 490 rv = service.ResolveProxy(NULL, url, &info3, &callback4, NULL); |
491 EXPECT_EQ(OK, rv); | 491 EXPECT_EQ(OK, rv); |
492 EXPECT_TRUE(info3.is_direct()); | 492 EXPECT_TRUE(info3.is_direct()); |
493 | 493 |
494 // But if the direct connection fails, we check if the ProxyInfo tried to | 494 // But if the direct connection fails, we check if the ProxyInfo tried to |
495 // resolve the proxy before, and if not (like in this case), we give the | 495 // resolve the proxy before, and if not (like in this case), we give the |
496 // PAC another try. | 496 // PAC another try. |
497 TestCompletionCallback callback5; | 497 TestCompletionCallback callback5; |
498 rv = service.ReconsiderProxyAfterError(url, &info3, &callback5, NULL); | 498 rv = service.ReconsiderProxyAfterError(NULL, url, &info3, &callback5, NULL); |
499 EXPECT_EQ(ERR_IO_PENDING, rv); | 499 EXPECT_EQ(ERR_IO_PENDING, rv); |
500 | 500 |
501 ASSERT_EQ(1u, resolver->pending_requests().size()); | 501 ASSERT_EQ(1u, resolver->pending_requests().size()); |
502 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 502 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
503 | 503 |
504 resolver->pending_requests()[0]->results()->UseNamedProxy( | 504 resolver->pending_requests()[0]->results()->UseNamedProxy( |
505 "foopy1:8080;foopy2:9090"); | 505 "foopy1:8080;foopy2:9090"); |
506 resolver->pending_requests()[0]->CompleteNow(OK); | 506 resolver->pending_requests()[0]->CompleteNow(OK); |
507 | 507 |
508 // The first proxy is still there since the list of bad proxies got cleared. | 508 // The first proxy is still there since the list of bad proxies got cleared. |
(...skipping 10 matching lines...) Expand all Loading... |
519 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); | 519 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); |
520 config.auto_detect = false; | 520 config.auto_detect = false; |
521 config.proxy_bypass_local_names = true; | 521 config.proxy_bypass_local_names = true; |
522 | 522 |
523 { | 523 { |
524 ProxyService service(new MockProxyConfigService(config), | 524 ProxyService service(new MockProxyConfigService(config), |
525 new MockAsyncProxyResolver()); | 525 new MockAsyncProxyResolver()); |
526 GURL url("http://www.google.com/"); | 526 GURL url("http://www.google.com/"); |
527 // Get the proxy information. | 527 // Get the proxy information. |
528 TestCompletionCallback callback; | 528 TestCompletionCallback callback; |
529 int rv = service.ResolveProxy(url, &info, &callback, NULL); | 529 int rv = service.ResolveProxy(NULL, url, &info, &callback, NULL); |
530 EXPECT_EQ(OK, rv); | 530 EXPECT_EQ(OK, rv); |
531 EXPECT_FALSE(info.is_direct()); | 531 EXPECT_FALSE(info.is_direct()); |
532 } | 532 } |
533 | 533 |
534 { | 534 { |
535 ProxyService service(new MockProxyConfigService(config), | 535 ProxyService service(new MockProxyConfigService(config), |
536 new MockAsyncProxyResolver()); | 536 new MockAsyncProxyResolver()); |
537 GURL test_url("http://local"); | 537 GURL test_url("http://local"); |
538 TestCompletionCallback callback; | 538 TestCompletionCallback callback; |
539 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 539 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
540 EXPECT_EQ(OK, rv); | 540 EXPECT_EQ(OK, rv); |
541 EXPECT_TRUE(info.is_direct()); | 541 EXPECT_TRUE(info.is_direct()); |
542 } | 542 } |
543 | 543 |
544 config.proxy_bypass.clear(); | 544 config.proxy_bypass.clear(); |
545 config.proxy_bypass.push_back("*.org"); | 545 config.proxy_bypass.push_back("*.org"); |
546 config.proxy_bypass_local_names = true; | 546 config.proxy_bypass_local_names = true; |
547 { | 547 { |
548 ProxyService service(new MockProxyConfigService(config), | 548 ProxyService service(new MockProxyConfigService(config), |
549 new MockAsyncProxyResolver); | 549 new MockAsyncProxyResolver); |
550 GURL test_url("http://www.webkit.org"); | 550 GURL test_url("http://www.webkit.org"); |
551 TestCompletionCallback callback; | 551 TestCompletionCallback callback; |
552 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 552 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
553 EXPECT_EQ(OK, rv); | 553 EXPECT_EQ(OK, rv); |
554 EXPECT_TRUE(info.is_direct()); | 554 EXPECT_TRUE(info.is_direct()); |
555 } | 555 } |
556 | 556 |
557 config.proxy_bypass.clear(); | 557 config.proxy_bypass.clear(); |
558 config.proxy_bypass.push_back("*.org"); | 558 config.proxy_bypass.push_back("*.org"); |
559 config.proxy_bypass.push_back("7*"); | 559 config.proxy_bypass.push_back("7*"); |
560 config.proxy_bypass_local_names = true; | 560 config.proxy_bypass_local_names = true; |
561 { | 561 { |
562 ProxyService service(new MockProxyConfigService(config), | 562 ProxyService service(new MockProxyConfigService(config), |
563 new MockAsyncProxyResolver); | 563 new MockAsyncProxyResolver); |
564 GURL test_url("http://74.125.19.147"); | 564 GURL test_url("http://74.125.19.147"); |
565 TestCompletionCallback callback; | 565 TestCompletionCallback callback; |
566 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 566 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
567 EXPECT_EQ(OK, rv); | 567 EXPECT_EQ(OK, rv); |
568 EXPECT_TRUE(info.is_direct()); | 568 EXPECT_TRUE(info.is_direct()); |
569 } | 569 } |
570 | 570 |
571 config.proxy_bypass.clear(); | 571 config.proxy_bypass.clear(); |
572 config.proxy_bypass.push_back("*.org"); | 572 config.proxy_bypass.push_back("*.org"); |
573 config.proxy_bypass_local_names = true; | 573 config.proxy_bypass_local_names = true; |
574 { | 574 { |
575 ProxyService service(new MockProxyConfigService(config), | 575 ProxyService service(new MockProxyConfigService(config), |
576 new MockAsyncProxyResolver); | 576 new MockAsyncProxyResolver); |
577 GURL test_url("http://www.msn.com"); | 577 GURL test_url("http://www.msn.com"); |
578 TestCompletionCallback callback; | 578 TestCompletionCallback callback; |
579 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 579 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
580 EXPECT_EQ(OK, rv); | 580 EXPECT_EQ(OK, rv); |
581 EXPECT_FALSE(info.is_direct()); | 581 EXPECT_FALSE(info.is_direct()); |
582 } | 582 } |
583 | 583 |
584 config.proxy_bypass.clear(); | 584 config.proxy_bypass.clear(); |
585 config.proxy_bypass.push_back("*.MSN.COM"); | 585 config.proxy_bypass.push_back("*.MSN.COM"); |
586 config.proxy_bypass_local_names = true; | 586 config.proxy_bypass_local_names = true; |
587 { | 587 { |
588 ProxyService service(new MockProxyConfigService(config), | 588 ProxyService service(new MockProxyConfigService(config), |
589 new MockAsyncProxyResolver); | 589 new MockAsyncProxyResolver); |
590 GURL test_url("http://www.msnbc.msn.com"); | 590 GURL test_url("http://www.msnbc.msn.com"); |
591 TestCompletionCallback callback; | 591 TestCompletionCallback callback; |
592 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 592 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
593 EXPECT_EQ(OK, rv); | 593 EXPECT_EQ(OK, rv); |
594 EXPECT_TRUE(info.is_direct()); | 594 EXPECT_TRUE(info.is_direct()); |
595 } | 595 } |
596 | 596 |
597 config.proxy_bypass.clear(); | 597 config.proxy_bypass.clear(); |
598 config.proxy_bypass.push_back("*.msn.com"); | 598 config.proxy_bypass.push_back("*.msn.com"); |
599 config.proxy_bypass_local_names = true; | 599 config.proxy_bypass_local_names = true; |
600 { | 600 { |
601 ProxyService service(new MockProxyConfigService(config), | 601 ProxyService service(new MockProxyConfigService(config), |
602 new MockAsyncProxyResolver); | 602 new MockAsyncProxyResolver); |
603 GURL test_url("HTTP://WWW.MSNBC.MSN.COM"); | 603 GURL test_url("HTTP://WWW.MSNBC.MSN.COM"); |
604 TestCompletionCallback callback; | 604 TestCompletionCallback callback; |
605 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 605 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
606 EXPECT_EQ(OK, rv); | 606 EXPECT_EQ(OK, rv); |
607 EXPECT_TRUE(info.is_direct()); | 607 EXPECT_TRUE(info.is_direct()); |
608 } | 608 } |
609 } | 609 } |
610 | 610 |
611 TEST(ProxyServiceTest, ProxyBypassListWithPorts) { | 611 TEST(ProxyServiceTest, ProxyBypassListWithPorts) { |
612 // Test port specification in bypass list entries. | 612 // Test port specification in bypass list entries. |
613 ProxyInfo info; | 613 ProxyInfo info; |
614 ProxyConfig config; | 614 ProxyConfig config; |
615 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); | 615 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); |
616 config.auto_detect = false; | 616 config.auto_detect = false; |
617 config.proxy_bypass_local_names = false; | 617 config.proxy_bypass_local_names = false; |
618 | 618 |
619 config.proxy_bypass.clear(); | 619 config.proxy_bypass.clear(); |
620 config.proxy_bypass.push_back("*.example.com:99"); | 620 config.proxy_bypass.push_back("*.example.com:99"); |
621 { | 621 { |
622 ProxyService service(new MockProxyConfigService(config), | 622 ProxyService service(new MockProxyConfigService(config), |
623 new MockAsyncProxyResolver); | 623 new MockAsyncProxyResolver); |
624 { | 624 { |
625 GURL test_url("http://www.example.com:99"); | 625 GURL test_url("http://www.example.com:99"); |
626 TestCompletionCallback callback; | 626 TestCompletionCallback callback; |
627 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 627 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
628 EXPECT_EQ(OK, rv); | 628 EXPECT_EQ(OK, rv); |
629 EXPECT_TRUE(info.is_direct()); | 629 EXPECT_TRUE(info.is_direct()); |
630 } | 630 } |
631 { | 631 { |
632 GURL test_url("http://www.example.com:100"); | 632 GURL test_url("http://www.example.com:100"); |
633 TestCompletionCallback callback; | 633 TestCompletionCallback callback; |
634 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 634 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
635 EXPECT_EQ(OK, rv); | 635 EXPECT_EQ(OK, rv); |
636 EXPECT_FALSE(info.is_direct()); | 636 EXPECT_FALSE(info.is_direct()); |
637 } | 637 } |
638 { | 638 { |
639 GURL test_url("http://www.example.com"); | 639 GURL test_url("http://www.example.com"); |
640 TestCompletionCallback callback; | 640 TestCompletionCallback callback; |
641 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 641 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
642 EXPECT_EQ(OK, rv); | 642 EXPECT_EQ(OK, rv); |
643 EXPECT_FALSE(info.is_direct()); | 643 EXPECT_FALSE(info.is_direct()); |
644 } | 644 } |
645 } | 645 } |
646 | 646 |
647 config.proxy_bypass.clear(); | 647 config.proxy_bypass.clear(); |
648 config.proxy_bypass.push_back("*.example.com:80"); | 648 config.proxy_bypass.push_back("*.example.com:80"); |
649 { | 649 { |
650 ProxyService service(new MockProxyConfigService(config), | 650 ProxyService service(new MockProxyConfigService(config), |
651 new MockAsyncProxyResolver); | 651 new MockAsyncProxyResolver); |
652 GURL test_url("http://www.example.com"); | 652 GURL test_url("http://www.example.com"); |
653 TestCompletionCallback callback; | 653 TestCompletionCallback callback; |
654 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 654 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
655 EXPECT_EQ(OK, rv); | 655 EXPECT_EQ(OK, rv); |
656 EXPECT_TRUE(info.is_direct()); | 656 EXPECT_TRUE(info.is_direct()); |
657 } | 657 } |
658 | 658 |
659 config.proxy_bypass.clear(); | 659 config.proxy_bypass.clear(); |
660 config.proxy_bypass.push_back("*.example.com"); | 660 config.proxy_bypass.push_back("*.example.com"); |
661 { | 661 { |
662 ProxyService service(new MockProxyConfigService(config), | 662 ProxyService service(new MockProxyConfigService(config), |
663 new MockAsyncProxyResolver); | 663 new MockAsyncProxyResolver); |
664 GURL test_url("http://www.example.com:99"); | 664 GURL test_url("http://www.example.com:99"); |
665 TestCompletionCallback callback; | 665 TestCompletionCallback callback; |
666 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 666 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
667 EXPECT_EQ(OK, rv); | 667 EXPECT_EQ(OK, rv); |
668 EXPECT_TRUE(info.is_direct()); | 668 EXPECT_TRUE(info.is_direct()); |
669 } | 669 } |
670 | 670 |
671 // IPv6 with port. | 671 // IPv6 with port. |
672 config.proxy_bypass.clear(); | 672 config.proxy_bypass.clear(); |
673 config.proxy_bypass.push_back("[3ffe:2a00:100:7031::1]:99"); | 673 config.proxy_bypass.push_back("[3ffe:2a00:100:7031::1]:99"); |
674 { | 674 { |
675 ProxyService service(new MockProxyConfigService(config), | 675 ProxyService service(new MockProxyConfigService(config), |
676 new MockAsyncProxyResolver); | 676 new MockAsyncProxyResolver); |
677 { | 677 { |
678 GURL test_url("http://[3ffe:2a00:100:7031::1]:99/"); | 678 GURL test_url("http://[3ffe:2a00:100:7031::1]:99/"); |
679 TestCompletionCallback callback; | 679 TestCompletionCallback callback; |
680 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 680 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
681 EXPECT_EQ(OK, rv); | 681 EXPECT_EQ(OK, rv); |
682 EXPECT_TRUE(info.is_direct()); | 682 EXPECT_TRUE(info.is_direct()); |
683 } | 683 } |
684 { | 684 { |
685 GURL test_url("http://[3ffe:2a00:100:7031::1]/"); | 685 GURL test_url("http://[3ffe:2a00:100:7031::1]/"); |
686 TestCompletionCallback callback; | 686 TestCompletionCallback callback; |
687 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 687 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
688 EXPECT_EQ(OK, rv); | 688 EXPECT_EQ(OK, rv); |
689 EXPECT_FALSE(info.is_direct()); | 689 EXPECT_FALSE(info.is_direct()); |
690 } | 690 } |
691 } | 691 } |
692 | 692 |
693 // IPv6 without port. The bypass entry ought to work without the | 693 // IPv6 without port. The bypass entry ought to work without the |
694 // brackets, but the bypass matching logic in ProxyService is | 694 // brackets, but the bypass matching logic in ProxyService is |
695 // currently limited. | 695 // currently limited. |
696 config.proxy_bypass.clear(); | 696 config.proxy_bypass.clear(); |
697 config.proxy_bypass.push_back("[3ffe:2a00:100:7031::1]"); | 697 config.proxy_bypass.push_back("[3ffe:2a00:100:7031::1]"); |
698 { | 698 { |
699 ProxyService service(new MockProxyConfigService(config), | 699 ProxyService service(new MockProxyConfigService(config), |
700 new MockAsyncProxyResolver); | 700 new MockAsyncProxyResolver); |
701 { | 701 { |
702 GURL test_url("http://[3ffe:2a00:100:7031::1]:99/"); | 702 GURL test_url("http://[3ffe:2a00:100:7031::1]:99/"); |
703 TestCompletionCallback callback; | 703 TestCompletionCallback callback; |
704 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 704 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
705 EXPECT_EQ(OK, rv); | 705 EXPECT_EQ(OK, rv); |
706 EXPECT_TRUE(info.is_direct()); | 706 EXPECT_TRUE(info.is_direct()); |
707 } | 707 } |
708 { | 708 { |
709 GURL test_url("http://[3ffe:2a00:100:7031::1]/"); | 709 GURL test_url("http://[3ffe:2a00:100:7031::1]/"); |
710 TestCompletionCallback callback; | 710 TestCompletionCallback callback; |
711 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 711 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
712 EXPECT_EQ(OK, rv); | 712 EXPECT_EQ(OK, rv); |
713 EXPECT_TRUE(info.is_direct()); | 713 EXPECT_TRUE(info.is_direct()); |
714 } | 714 } |
715 } | 715 } |
716 } | 716 } |
717 | 717 |
718 TEST(ProxyServiceTest, PerProtocolProxyTests) { | 718 TEST(ProxyServiceTest, PerProtocolProxyTests) { |
719 ProxyConfig config; | 719 ProxyConfig config; |
720 config.proxy_rules.ParseFromString("http=foopy1:8080;https=foopy2:8080"); | 720 config.proxy_rules.ParseFromString("http=foopy1:8080;https=foopy2:8080"); |
721 config.auto_detect = false; | 721 config.auto_detect = false; |
722 { | 722 { |
723 ProxyService service(new MockProxyConfigService(config), | 723 ProxyService service(new MockProxyConfigService(config), |
724 new MockAsyncProxyResolver); | 724 new MockAsyncProxyResolver); |
725 GURL test_url("http://www.msn.com"); | 725 GURL test_url("http://www.msn.com"); |
726 ProxyInfo info; | 726 ProxyInfo info; |
727 TestCompletionCallback callback; | 727 TestCompletionCallback callback; |
728 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 728 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
729 EXPECT_EQ(OK, rv); | 729 EXPECT_EQ(OK, rv); |
730 EXPECT_FALSE(info.is_direct()); | 730 EXPECT_FALSE(info.is_direct()); |
731 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 731 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
732 } | 732 } |
733 { | 733 { |
734 ProxyService service(new MockProxyConfigService(config), | 734 ProxyService service(new MockProxyConfigService(config), |
735 new MockAsyncProxyResolver); | 735 new MockAsyncProxyResolver); |
736 GURL test_url("ftp://ftp.google.com"); | 736 GURL test_url("ftp://ftp.google.com"); |
737 ProxyInfo info; | 737 ProxyInfo info; |
738 TestCompletionCallback callback; | 738 TestCompletionCallback callback; |
739 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 739 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
740 EXPECT_EQ(OK, rv); | 740 EXPECT_EQ(OK, rv); |
741 EXPECT_TRUE(info.is_direct()); | 741 EXPECT_TRUE(info.is_direct()); |
742 EXPECT_EQ("direct://", info.proxy_server().ToURI()); | 742 EXPECT_EQ("direct://", info.proxy_server().ToURI()); |
743 } | 743 } |
744 { | 744 { |
745 ProxyService service(new MockProxyConfigService(config), | 745 ProxyService service(new MockProxyConfigService(config), |
746 new MockAsyncProxyResolver); | 746 new MockAsyncProxyResolver); |
747 GURL test_url("https://webbranch.techcu.com"); | 747 GURL test_url("https://webbranch.techcu.com"); |
748 ProxyInfo info; | 748 ProxyInfo info; |
749 TestCompletionCallback callback; | 749 TestCompletionCallback callback; |
750 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 750 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
751 EXPECT_EQ(OK, rv); | 751 EXPECT_EQ(OK, rv); |
752 EXPECT_FALSE(info.is_direct()); | 752 EXPECT_FALSE(info.is_direct()); |
753 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 753 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
754 } | 754 } |
755 { | 755 { |
756 config.proxy_rules.ParseFromString("foopy1:8080"); | 756 config.proxy_rules.ParseFromString("foopy1:8080"); |
757 ProxyService service(new MockProxyConfigService(config), | 757 ProxyService service(new MockProxyConfigService(config), |
758 new MockAsyncProxyResolver); | 758 new MockAsyncProxyResolver); |
759 GURL test_url("http://www.microsoft.com"); | 759 GURL test_url("http://www.microsoft.com"); |
760 ProxyInfo info; | 760 ProxyInfo info; |
761 TestCompletionCallback callback; | 761 TestCompletionCallback callback; |
762 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 762 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
763 EXPECT_EQ(OK, rv); | 763 EXPECT_EQ(OK, rv); |
764 EXPECT_FALSE(info.is_direct()); | 764 EXPECT_FALSE(info.is_direct()); |
765 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 765 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
766 } | 766 } |
767 } | 767 } |
768 | 768 |
769 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries | 769 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries |
770 // fall back to the SOCKS proxy. | 770 // fall back to the SOCKS proxy. |
771 TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { | 771 TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { |
772 ProxyConfig config; | 772 ProxyConfig config; |
773 config.proxy_rules.ParseFromString("http=foopy1:8080;socks=foopy2:1080"); | 773 config.proxy_rules.ParseFromString("http=foopy1:8080;socks=foopy2:1080"); |
774 config.auto_detect = false; | 774 config.auto_detect = false; |
775 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 775 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
776 config.proxy_rules.type); | 776 config.proxy_rules.type); |
777 | 777 |
778 { | 778 { |
779 ProxyService service(new MockProxyConfigService(config), | 779 ProxyService service(new MockProxyConfigService(config), |
780 new MockAsyncProxyResolver); | 780 new MockAsyncProxyResolver); |
781 GURL test_url("http://www.msn.com"); | 781 GURL test_url("http://www.msn.com"); |
782 ProxyInfo info; | 782 ProxyInfo info; |
783 TestCompletionCallback callback; | 783 TestCompletionCallback callback; |
784 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 784 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
785 EXPECT_EQ(OK, rv); | 785 EXPECT_EQ(OK, rv); |
786 EXPECT_FALSE(info.is_direct()); | 786 EXPECT_FALSE(info.is_direct()); |
787 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 787 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
788 } | 788 } |
789 { | 789 { |
790 ProxyService service(new MockProxyConfigService(config), | 790 ProxyService service(new MockProxyConfigService(config), |
791 new MockAsyncProxyResolver); | 791 new MockAsyncProxyResolver); |
792 GURL test_url("ftp://ftp.google.com"); | 792 GURL test_url("ftp://ftp.google.com"); |
793 ProxyInfo info; | 793 ProxyInfo info; |
794 TestCompletionCallback callback; | 794 TestCompletionCallback callback; |
795 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 795 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
796 EXPECT_EQ(OK, rv); | 796 EXPECT_EQ(OK, rv); |
797 EXPECT_FALSE(info.is_direct()); | 797 EXPECT_FALSE(info.is_direct()); |
798 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 798 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
799 } | 799 } |
800 { | 800 { |
801 ProxyService service(new MockProxyConfigService(config), | 801 ProxyService service(new MockProxyConfigService(config), |
802 new MockAsyncProxyResolver); | 802 new MockAsyncProxyResolver); |
803 GURL test_url("https://webbranch.techcu.com"); | 803 GURL test_url("https://webbranch.techcu.com"); |
804 ProxyInfo info; | 804 ProxyInfo info; |
805 TestCompletionCallback callback; | 805 TestCompletionCallback callback; |
806 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 806 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
807 EXPECT_EQ(OK, rv); | 807 EXPECT_EQ(OK, rv); |
808 EXPECT_FALSE(info.is_direct()); | 808 EXPECT_FALSE(info.is_direct()); |
809 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 809 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
810 } | 810 } |
811 { | 811 { |
812 ProxyService service(new MockProxyConfigService(config), | 812 ProxyService service(new MockProxyConfigService(config), |
813 new MockAsyncProxyResolver); | 813 new MockAsyncProxyResolver); |
814 GURL test_url("unknown://www.microsoft.com"); | 814 GURL test_url("unknown://www.microsoft.com"); |
815 ProxyInfo info; | 815 ProxyInfo info; |
816 TestCompletionCallback callback; | 816 TestCompletionCallback callback; |
817 int rv = service.ResolveProxy(test_url, &info, &callback, NULL); | 817 int rv = service.ResolveProxy(NULL, test_url, &info, &callback, NULL); |
818 EXPECT_EQ(OK, rv); | 818 EXPECT_EQ(OK, rv); |
819 EXPECT_FALSE(info.is_direct()); | 819 EXPECT_FALSE(info.is_direct()); |
820 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 820 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
821 } | 821 } |
822 } | 822 } |
823 | 823 |
824 // Test cancellation of an in-progress request. | 824 // Test cancellation of an in-progress request. |
825 TEST(ProxyServiceTest, CancelInProgressRequest) { | 825 TEST(ProxyServiceTest, CancelInProgressRequest) { |
826 MockProxyConfigService* config_service = | 826 MockProxyConfigService* config_service = |
827 new MockProxyConfigService("http://foopy/proxy.pac"); | 827 new MockProxyConfigService("http://foopy/proxy.pac"); |
828 | 828 |
829 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 829 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
830 | 830 |
831 ProxyService service(config_service, resolver); | 831 ProxyService service(config_service, resolver); |
832 | 832 |
833 // Start 3 requests. | 833 // Start 3 requests. |
834 | 834 |
835 ProxyInfo info1; | 835 ProxyInfo info1; |
836 TestCompletionCallback callback1; | 836 TestCompletionCallback callback1; |
837 int rv = service.ResolveProxy( | 837 int rv = service.ResolveProxy( |
838 GURL("http://request1"), &info1, &callback1, NULL); | 838 NULL, GURL("http://request1"), &info1, &callback1, NULL); |
839 EXPECT_EQ(ERR_IO_PENDING, rv); | 839 EXPECT_EQ(ERR_IO_PENDING, rv); |
840 | 840 |
841 // Nothing has been sent to the proxy resolver yet, since the proxy | 841 // Nothing has been sent to the proxy resolver yet, since the proxy |
842 // resolver has not been configured yet. | 842 // resolver has not been configured yet. |
843 ASSERT_EQ(0u, resolver->pending_requests().size()); | 843 ASSERT_EQ(0u, resolver->pending_requests().size()); |
844 | 844 |
845 // Successfully initialize the PAC script. | 845 // Successfully initialize the PAC script. |
846 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 846 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
847 resolver->pending_set_pac_script_request()->pac_url()); | 847 resolver->pending_set_pac_script_request()->pac_url()); |
848 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 848 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
849 | 849 |
850 ASSERT_EQ(1u, resolver->pending_requests().size()); | 850 ASSERT_EQ(1u, resolver->pending_requests().size()); |
851 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 851 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
852 | 852 |
853 ProxyInfo info2; | 853 ProxyInfo info2; |
854 TestCompletionCallback callback2; | 854 TestCompletionCallback callback2; |
855 ProxyService::PacRequest* request2; | 855 ProxyService::PacRequest* request2; |
856 rv = service.ResolveProxy( | 856 rv = service.ResolveProxy( |
857 GURL("http://request2"), &info2, &callback2, &request2); | 857 NULL, GURL("http://request2"), &info2, &callback2, &request2); |
858 EXPECT_EQ(ERR_IO_PENDING, rv); | 858 EXPECT_EQ(ERR_IO_PENDING, rv); |
859 ASSERT_EQ(2u, resolver->pending_requests().size()); | 859 ASSERT_EQ(2u, resolver->pending_requests().size()); |
860 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 860 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
861 | 861 |
862 ProxyInfo info3; | 862 ProxyInfo info3; |
863 TestCompletionCallback callback3; | 863 TestCompletionCallback callback3; |
864 rv = service.ResolveProxy( | 864 rv = service.ResolveProxy( |
865 GURL("http://request3"), &info3, &callback3, NULL); | 865 NULL, GURL("http://request3"), &info3, &callback3, NULL); |
866 EXPECT_EQ(ERR_IO_PENDING, rv); | 866 EXPECT_EQ(ERR_IO_PENDING, rv); |
867 ASSERT_EQ(3u, resolver->pending_requests().size()); | 867 ASSERT_EQ(3u, resolver->pending_requests().size()); |
868 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); | 868 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); |
869 | 869 |
870 // Cancel the second request | 870 // Cancel the second request |
871 service.CancelPacRequest(request2); | 871 service.CancelPacRequest(request2); |
872 | 872 |
873 ASSERT_EQ(2u, resolver->pending_requests().size()); | 873 ASSERT_EQ(2u, resolver->pending_requests().size()); |
874 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 874 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
875 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); | 875 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); |
(...skipping 29 matching lines...) Expand all Loading... |
905 ProxyService service(config_service, resolver); | 905 ProxyService service(config_service, resolver); |
906 | 906 |
907 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 907 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
908 service.SetProxyScriptFetcher(fetcher); | 908 service.SetProxyScriptFetcher(fetcher); |
909 | 909 |
910 // Start 3 requests. | 910 // Start 3 requests. |
911 | 911 |
912 ProxyInfo info1; | 912 ProxyInfo info1; |
913 TestCompletionCallback callback1; | 913 TestCompletionCallback callback1; |
914 int rv = service.ResolveProxy( | 914 int rv = service.ResolveProxy( |
915 GURL("http://request1"), &info1, &callback1, NULL); | 915 NULL, GURL("http://request1"), &info1, &callback1, NULL); |
916 EXPECT_EQ(ERR_IO_PENDING, rv); | 916 EXPECT_EQ(ERR_IO_PENDING, rv); |
917 | 917 |
918 // The first request should have triggered download of PAC script. | 918 // The first request should have triggered download of PAC script. |
919 EXPECT_TRUE(fetcher->has_pending_request()); | 919 EXPECT_TRUE(fetcher->has_pending_request()); |
920 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 920 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
921 | 921 |
922 ProxyInfo info2; | 922 ProxyInfo info2; |
923 TestCompletionCallback callback2; | 923 TestCompletionCallback callback2; |
924 rv = service.ResolveProxy( | 924 rv = service.ResolveProxy( |
925 GURL("http://request2"), &info2, &callback2, NULL); | 925 NULL, GURL("http://request2"), &info2, &callback2, NULL); |
926 EXPECT_EQ(ERR_IO_PENDING, rv); | 926 EXPECT_EQ(ERR_IO_PENDING, rv); |
927 | 927 |
928 ProxyInfo info3; | 928 ProxyInfo info3; |
929 TestCompletionCallback callback3; | 929 TestCompletionCallback callback3; |
930 rv = service.ResolveProxy( | 930 rv = service.ResolveProxy( |
931 GURL("http://request3"), &info3, &callback3, NULL); | 931 NULL, GURL("http://request3"), &info3, &callback3, NULL); |
932 EXPECT_EQ(ERR_IO_PENDING, rv); | 932 EXPECT_EQ(ERR_IO_PENDING, rv); |
933 | 933 |
934 // Nothing has been sent to the resolver yet. | 934 // Nothing has been sent to the resolver yet. |
935 EXPECT_TRUE(resolver->pending_requests().empty()); | 935 EXPECT_TRUE(resolver->pending_requests().empty()); |
936 | 936 |
937 // At this point the ProxyService should be waiting for the | 937 // At this point the ProxyService should be waiting for the |
938 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 938 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
939 // PAC script download completion. | 939 // PAC script download completion. |
940 fetcher->NotifyFetchCompletion(OK, "pac-v1"); | 940 fetcher->NotifyFetchCompletion(OK, "pac-v1"); |
941 | 941 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 ProxyService service(config_service, resolver); | 983 ProxyService service(config_service, resolver); |
984 | 984 |
985 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 985 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
986 service.SetProxyScriptFetcher(fetcher); | 986 service.SetProxyScriptFetcher(fetcher); |
987 | 987 |
988 // Start 3 requests. | 988 // Start 3 requests. |
989 ProxyInfo info1; | 989 ProxyInfo info1; |
990 TestCompletionCallback callback1; | 990 TestCompletionCallback callback1; |
991 ProxyService::PacRequest* request1; | 991 ProxyService::PacRequest* request1; |
992 int rv = service.ResolveProxy( | 992 int rv = service.ResolveProxy( |
993 GURL("http://request1"), &info1, &callback1, &request1); | 993 NULL, GURL("http://request1"), &info1, &callback1, &request1); |
994 EXPECT_EQ(ERR_IO_PENDING, rv); | 994 EXPECT_EQ(ERR_IO_PENDING, rv); |
995 | 995 |
996 // The first request should have triggered download of PAC script. | 996 // The first request should have triggered download of PAC script. |
997 EXPECT_TRUE(fetcher->has_pending_request()); | 997 EXPECT_TRUE(fetcher->has_pending_request()); |
998 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 998 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
999 | 999 |
1000 ProxyInfo info2; | 1000 ProxyInfo info2; |
1001 TestCompletionCallback callback2; | 1001 TestCompletionCallback callback2; |
1002 ProxyService::PacRequest* request2; | 1002 ProxyService::PacRequest* request2; |
1003 rv = service.ResolveProxy( | 1003 rv = service.ResolveProxy( |
1004 GURL("http://request2"), &info2, &callback2, &request2); | 1004 NULL, GURL("http://request2"), &info2, &callback2, &request2); |
1005 EXPECT_EQ(ERR_IO_PENDING, rv); | 1005 EXPECT_EQ(ERR_IO_PENDING, rv); |
1006 | 1006 |
1007 ProxyInfo info3; | 1007 ProxyInfo info3; |
1008 TestCompletionCallback callback3; | 1008 TestCompletionCallback callback3; |
1009 rv = service.ResolveProxy( | 1009 rv = service.ResolveProxy( |
1010 GURL("http://request3"), &info3, &callback3, NULL); | 1010 NULL, GURL("http://request3"), &info3, &callback3, NULL); |
1011 EXPECT_EQ(ERR_IO_PENDING, rv); | 1011 EXPECT_EQ(ERR_IO_PENDING, rv); |
1012 | 1012 |
1013 // Nothing has been sent to the resolver yet. | 1013 // Nothing has been sent to the resolver yet. |
1014 EXPECT_TRUE(resolver->pending_requests().empty()); | 1014 EXPECT_TRUE(resolver->pending_requests().empty()); |
1015 | 1015 |
1016 // Cancel the first 2 requests. | 1016 // Cancel the first 2 requests. |
1017 service.CancelPacRequest(request1); | 1017 service.CancelPacRequest(request1); |
1018 service.CancelPacRequest(request2); | 1018 service.CancelPacRequest(request2); |
1019 | 1019 |
1020 // At this point the ProxyService should be waiting for the | 1020 // At this point the ProxyService should be waiting for the |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 ProxyService service(config_service, resolver); | 1056 ProxyService service(config_service, resolver); |
1057 | 1057 |
1058 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1058 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1059 service.SetProxyScriptFetcher(fetcher); | 1059 service.SetProxyScriptFetcher(fetcher); |
1060 | 1060 |
1061 // Start 2 requests. | 1061 // Start 2 requests. |
1062 | 1062 |
1063 ProxyInfo info1; | 1063 ProxyInfo info1; |
1064 TestCompletionCallback callback1; | 1064 TestCompletionCallback callback1; |
1065 int rv = service.ResolveProxy( | 1065 int rv = service.ResolveProxy( |
1066 GURL("http://request1"), &info1, &callback1, NULL); | 1066 NULL, GURL("http://request1"), &info1, &callback1, NULL); |
1067 EXPECT_EQ(ERR_IO_PENDING, rv); | 1067 EXPECT_EQ(ERR_IO_PENDING, rv); |
1068 | 1068 |
1069 ProxyInfo info2; | 1069 ProxyInfo info2; |
1070 TestCompletionCallback callback2; | 1070 TestCompletionCallback callback2; |
1071 ProxyService::PacRequest* request2; | 1071 ProxyService::PacRequest* request2; |
1072 rv = service.ResolveProxy( | 1072 rv = service.ResolveProxy( |
1073 GURL("http://request2"), &info2, &callback2, &request2); | 1073 NULL, GURL("http://request2"), &info2, &callback2, &request2); |
1074 EXPECT_EQ(ERR_IO_PENDING, rv); | 1074 EXPECT_EQ(ERR_IO_PENDING, rv); |
1075 | 1075 |
1076 // Check that nothing has been sent to the proxy resolver yet. | 1076 // Check that nothing has been sent to the proxy resolver yet. |
1077 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1077 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1078 | 1078 |
1079 // It should be trying to auto-detect first -- FAIL the autodetect during | 1079 // It should be trying to auto-detect first -- FAIL the autodetect during |
1080 // the script download. | 1080 // the script download. |
1081 EXPECT_TRUE(fetcher->has_pending_request()); | 1081 EXPECT_TRUE(fetcher->has_pending_request()); |
1082 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1082 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1083 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); | 1083 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 ProxyService service(config_service, resolver); | 1126 ProxyService service(config_service, resolver); |
1127 | 1127 |
1128 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1128 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1129 service.SetProxyScriptFetcher(fetcher); | 1129 service.SetProxyScriptFetcher(fetcher); |
1130 | 1130 |
1131 // Start 2 requests. | 1131 // Start 2 requests. |
1132 | 1132 |
1133 ProxyInfo info1; | 1133 ProxyInfo info1; |
1134 TestCompletionCallback callback1; | 1134 TestCompletionCallback callback1; |
1135 int rv = service.ResolveProxy( | 1135 int rv = service.ResolveProxy( |
1136 GURL("http://request1"), &info1, &callback1, NULL); | 1136 NULL, GURL("http://request1"), &info1, &callback1, NULL); |
1137 EXPECT_EQ(ERR_IO_PENDING, rv); | 1137 EXPECT_EQ(ERR_IO_PENDING, rv); |
1138 | 1138 |
1139 ProxyInfo info2; | 1139 ProxyInfo info2; |
1140 TestCompletionCallback callback2; | 1140 TestCompletionCallback callback2; |
1141 ProxyService::PacRequest* request2; | 1141 ProxyService::PacRequest* request2; |
1142 rv = service.ResolveProxy( | 1142 rv = service.ResolveProxy( |
1143 GURL("http://request2"), &info2, &callback2, &request2); | 1143 NULL, GURL("http://request2"), &info2, &callback2, &request2); |
1144 EXPECT_EQ(ERR_IO_PENDING, rv); | 1144 EXPECT_EQ(ERR_IO_PENDING, rv); |
1145 | 1145 |
1146 // Check that nothing has been sent to the proxy resolver yet. | 1146 // Check that nothing has been sent to the proxy resolver yet. |
1147 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1147 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1148 | 1148 |
1149 // It should be trying to auto-detect first -- succeed the download. | 1149 // It should be trying to auto-detect first -- succeed the download. |
1150 EXPECT_TRUE(fetcher->has_pending_request()); | 1150 EXPECT_TRUE(fetcher->has_pending_request()); |
1151 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1151 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1152 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 1152 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
1153 | 1153 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 ProxyService service(config_service, resolver); | 1201 ProxyService service(config_service, resolver); |
1202 | 1202 |
1203 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1203 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1204 service.SetProxyScriptFetcher(fetcher); | 1204 service.SetProxyScriptFetcher(fetcher); |
1205 | 1205 |
1206 // Start 2 requests. | 1206 // Start 2 requests. |
1207 | 1207 |
1208 ProxyInfo info1; | 1208 ProxyInfo info1; |
1209 TestCompletionCallback callback1; | 1209 TestCompletionCallback callback1; |
1210 int rv = service.ResolveProxy( | 1210 int rv = service.ResolveProxy( |
1211 GURL("http://request1"), &info1, &callback1, NULL); | 1211 NULL, GURL("http://request1"), &info1, &callback1, NULL); |
1212 EXPECT_EQ(ERR_IO_PENDING, rv); | 1212 EXPECT_EQ(ERR_IO_PENDING, rv); |
1213 | 1213 |
1214 ProxyInfo info2; | 1214 ProxyInfo info2; |
1215 TestCompletionCallback callback2; | 1215 TestCompletionCallback callback2; |
1216 ProxyService::PacRequest* request2; | 1216 ProxyService::PacRequest* request2; |
1217 rv = service.ResolveProxy( | 1217 rv = service.ResolveProxy( |
1218 GURL("http://request2"), &info2, &callback2, &request2); | 1218 NULL, GURL("http://request2"), &info2, &callback2, &request2); |
1219 EXPECT_EQ(ERR_IO_PENDING, rv); | 1219 EXPECT_EQ(ERR_IO_PENDING, rv); |
1220 | 1220 |
1221 // Check that nothing has been sent to the proxy resolver yet. | 1221 // Check that nothing has been sent to the proxy resolver yet. |
1222 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1222 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1223 | 1223 |
1224 // It should be trying to auto-detect first -- fail the download. | 1224 // It should be trying to auto-detect first -- fail the download. |
1225 EXPECT_TRUE(fetcher->has_pending_request()); | 1225 EXPECT_TRUE(fetcher->has_pending_request()); |
1226 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1226 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1227 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); | 1227 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); |
1228 | 1228 |
(...skipping 29 matching lines...) Expand all Loading... |
1258 ProxyService service(config_service, resolver); | 1258 ProxyService service(config_service, resolver); |
1259 | 1259 |
1260 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1260 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1261 service.SetProxyScriptFetcher(fetcher); | 1261 service.SetProxyScriptFetcher(fetcher); |
1262 | 1262 |
1263 // Start 1 requests. | 1263 // Start 1 requests. |
1264 | 1264 |
1265 ProxyInfo info1; | 1265 ProxyInfo info1; |
1266 TestCompletionCallback callback1; | 1266 TestCompletionCallback callback1; |
1267 int rv = service.ResolveProxy( | 1267 int rv = service.ResolveProxy( |
1268 GURL("http://www.google.com"), &info1, &callback1, NULL); | 1268 NULL, GURL("http://www.google.com"), &info1, &callback1, NULL); |
1269 EXPECT_EQ(ERR_IO_PENDING, rv); | 1269 EXPECT_EQ(ERR_IO_PENDING, rv); |
1270 | 1270 |
1271 // Check that nothing has been sent to the proxy resolver yet. | 1271 // Check that nothing has been sent to the proxy resolver yet. |
1272 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1272 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1273 | 1273 |
1274 // It should be trying to auto-detect first -- succeed the download. | 1274 // It should be trying to auto-detect first -- succeed the download. |
1275 EXPECT_TRUE(fetcher->has_pending_request()); | 1275 EXPECT_TRUE(fetcher->has_pending_request()); |
1276 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1276 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1277 fetcher->NotifyFetchCompletion(OK, "auto-detect"); | 1277 fetcher->NotifyFetchCompletion(OK, "auto-detect"); |
1278 | 1278 |
(...skipping 10 matching lines...) Expand all Loading... |
1289 resolver->pending_requests()[0]->CompleteNow(OK); | 1289 resolver->pending_requests()[0]->CompleteNow(OK); |
1290 | 1290 |
1291 // Verify that request ran as expected. | 1291 // Verify that request ran as expected. |
1292 EXPECT_EQ(OK, callback1.WaitForResult()); | 1292 EXPECT_EQ(OK, callback1.WaitForResult()); |
1293 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1293 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
1294 | 1294 |
1295 // Start another request, it should pickup the bypass item. | 1295 // Start another request, it should pickup the bypass item. |
1296 ProxyInfo info2; | 1296 ProxyInfo info2; |
1297 TestCompletionCallback callback2; | 1297 TestCompletionCallback callback2; |
1298 rv = service.ResolveProxy( | 1298 rv = service.ResolveProxy( |
1299 GURL("http://www.google.com"), &info2, &callback2, NULL); | 1299 NULL, GURL("http://www.google.com"), &info2, &callback2, NULL); |
1300 EXPECT_EQ(ERR_IO_PENDING, rv); | 1300 EXPECT_EQ(ERR_IO_PENDING, rv); |
1301 | 1301 |
1302 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1302 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1303 EXPECT_EQ(GURL("http://www.google.com"), | 1303 EXPECT_EQ(GURL("http://www.google.com"), |
1304 resolver->pending_requests()[0]->url()); | 1304 resolver->pending_requests()[0]->url()); |
1305 | 1305 |
1306 // Complete the pending request. | 1306 // Complete the pending request. |
1307 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 1307 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
1308 resolver->pending_requests()[0]->CompleteNow(OK); | 1308 resolver->pending_requests()[0]->CompleteNow(OK); |
1309 | 1309 |
1310 EXPECT_EQ(OK, callback2.WaitForResult()); | 1310 EXPECT_EQ(OK, callback2.WaitForResult()); |
1311 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 1311 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
1312 } | 1312 } |
1313 | 1313 |
1314 TEST(ProxyServiceTest, ResetProxyConfigService) { | 1314 TEST(ProxyServiceTest, ResetProxyConfigService) { |
1315 ProxyConfig config1; | 1315 ProxyConfig config1; |
1316 config1.proxy_rules.ParseFromString("foopy1:8080"); | 1316 config1.proxy_rules.ParseFromString("foopy1:8080"); |
1317 config1.auto_detect = false; | 1317 config1.auto_detect = false; |
1318 ProxyService service(new MockProxyConfigService(config1), | 1318 ProxyService service(new MockProxyConfigService(config1), |
1319 new MockAsyncProxyResolverExpectsBytes); | 1319 new MockAsyncProxyResolverExpectsBytes); |
1320 | 1320 |
1321 ProxyInfo info; | 1321 ProxyInfo info; |
1322 TestCompletionCallback callback1; | 1322 TestCompletionCallback callback1; |
1323 int rv = service.ResolveProxy( | 1323 int rv = service.ResolveProxy( |
1324 GURL("http://request1"), &info, &callback1, NULL); | 1324 NULL, GURL("http://request1"), &info, &callback1, NULL); |
1325 EXPECT_EQ(OK, rv); | 1325 EXPECT_EQ(OK, rv); |
1326 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1326 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1327 | 1327 |
1328 ProxyConfig config2; | 1328 ProxyConfig config2; |
1329 config2.proxy_rules.ParseFromString("foopy2:8080"); | 1329 config2.proxy_rules.ParseFromString("foopy2:8080"); |
1330 config2.auto_detect = false; | 1330 config2.auto_detect = false; |
1331 service.ResetConfigService(new MockProxyConfigService(config2)); | 1331 service.ResetConfigService(new MockProxyConfigService(config2)); |
1332 TestCompletionCallback callback2; | 1332 TestCompletionCallback callback2; |
1333 rv = service.ResolveProxy(GURL("http://request2"), &info, &callback2, NULL); | 1333 rv = service.ResolveProxy( |
| 1334 NULL, GURL("http://request2"), &info, &callback2, NULL); |
1334 EXPECT_EQ(OK, rv); | 1335 EXPECT_EQ(OK, rv); |
1335 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 1336 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
1336 } | 1337 } |
1337 | 1338 |
1338 TEST(ProxyServiceTest, IsLocalName) { | 1339 TEST(ProxyServiceTest, IsLocalName) { |
1339 const struct { | 1340 const struct { |
1340 const char* url; | 1341 const char* url; |
1341 bool expected_is_local; | 1342 bool expected_is_local; |
1342 } tests[] = { | 1343 } tests[] = { |
1343 // Single-component hostnames are considered local. | 1344 // Single-component hostnames are considered local. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 | 1388 |
1388 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1389 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
1389 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1390 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1390 ProxyService service(config_service, resolver); | 1391 ProxyService service(config_service, resolver); |
1391 | 1392 |
1392 // Start 1 requests. | 1393 // Start 1 requests. |
1393 | 1394 |
1394 ProxyInfo info1; | 1395 ProxyInfo info1; |
1395 TestCompletionCallback callback1; | 1396 TestCompletionCallback callback1; |
1396 int rv = service.ResolveProxy( | 1397 int rv = service.ResolveProxy( |
1397 GURL("http://www.google.com"), &info1, &callback1, NULL); | 1398 NULL, GURL("http://www.google.com"), &info1, &callback1, NULL); |
1398 EXPECT_EQ(ERR_IO_PENDING, rv); | 1399 EXPECT_EQ(ERR_IO_PENDING, rv); |
1399 | 1400 |
1400 // Check that nothing has been sent to the proxy resolver yet. | 1401 // Check that nothing has been sent to the proxy resolver yet. |
1401 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1402 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1402 | 1403 |
1403 // Fail the setting of autodetect script. | 1404 // Fail the setting of autodetect script. |
1404 EXPECT_EQ(GURL(), resolver->pending_set_pac_script_request()->pac_url()); | 1405 EXPECT_EQ(GURL(), resolver->pending_set_pac_script_request()->pac_url()); |
1405 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); | 1406 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); |
1406 | 1407 |
1407 // Verify that request ran as expected -- should have fallen back to direct. | 1408 // Verify that request ran as expected -- should have fallen back to direct. |
1408 EXPECT_EQ(OK, callback1.WaitForResult()); | 1409 EXPECT_EQ(OK, callback1.WaitForResult()); |
1409 EXPECT_TRUE(info1.is_direct()); | 1410 EXPECT_TRUE(info1.is_direct()); |
1410 | 1411 |
1411 // Force the ProxyService to pull down a new proxy configuration. | 1412 // Force the ProxyService to pull down a new proxy configuration. |
1412 // (Even though the configuration isn't old/bad). | 1413 // (Even though the configuration isn't old/bad). |
1413 service.UpdateConfig(); | 1414 service.UpdateConfig(); |
1414 | 1415 |
1415 // Start another request -- the effective configuration has not | 1416 // Start another request -- the effective configuration has not |
1416 // changed, so we shouldn't re-run the autodetect step. | 1417 // changed, so we shouldn't re-run the autodetect step. |
1417 // Rather, it should complete synchronously as direct-connect. | 1418 // Rather, it should complete synchronously as direct-connect. |
1418 ProxyInfo info2; | 1419 ProxyInfo info2; |
1419 TestCompletionCallback callback2; | 1420 TestCompletionCallback callback2; |
1420 rv = service.ResolveProxy( | 1421 rv = service.ResolveProxy( |
1421 GURL("http://www.google.com"), &info2, &callback2, NULL); | 1422 NULL, GURL("http://www.google.com"), &info2, &callback2, NULL); |
1422 EXPECT_EQ(OK, rv); | 1423 EXPECT_EQ(OK, rv); |
1423 | 1424 |
1424 EXPECT_TRUE(info2.is_direct()); | 1425 EXPECT_TRUE(info2.is_direct()); |
1425 } | 1426 } |
1426 | 1427 |
1427 // Test that when going from a configuration that required PAC to one | 1428 // Test that when going from a configuration that required PAC to one |
1428 // that does NOT, we unset the variable |should_use_proxy_resolver_|. | 1429 // that does NOT, we unset the variable |should_use_proxy_resolver_|. |
1429 TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) { | 1430 TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) { |
1430 ProxyConfig config; | 1431 ProxyConfig config; |
1431 config.auto_detect = true; | 1432 config.auto_detect = true; |
1432 | 1433 |
1433 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1434 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
1434 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1435 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1435 ProxyService service(config_service, resolver); | 1436 ProxyService service(config_service, resolver); |
1436 | 1437 |
1437 // Start 1 request. | 1438 // Start 1 request. |
1438 | 1439 |
1439 ProxyInfo info1; | 1440 ProxyInfo info1; |
1440 TestCompletionCallback callback1; | 1441 TestCompletionCallback callback1; |
1441 int rv = service.ResolveProxy( | 1442 int rv = service.ResolveProxy( |
1442 GURL("http://www.google.com"), &info1, &callback1, NULL); | 1443 NULL, GURL("http://www.google.com"), &info1, &callback1, NULL); |
1443 EXPECT_EQ(ERR_IO_PENDING, rv); | 1444 EXPECT_EQ(ERR_IO_PENDING, rv); |
1444 | 1445 |
1445 // Check that nothing has been sent to the proxy resolver yet. | 1446 // Check that nothing has been sent to the proxy resolver yet. |
1446 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1447 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1447 | 1448 |
1448 // Successfully set the autodetect script. | 1449 // Successfully set the autodetect script. |
1449 EXPECT_EQ(GURL(), resolver->pending_set_pac_script_request()->pac_url()); | 1450 EXPECT_EQ(GURL(), resolver->pending_set_pac_script_request()->pac_url()); |
1450 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1451 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1451 | 1452 |
1452 // Complete the pending request. | 1453 // Complete the pending request. |
(...skipping 11 matching lines...) Expand all Loading... |
1464 // This new configuration no longer has auto_detect set, so | 1465 // This new configuration no longer has auto_detect set, so |
1465 // requests should complete synchronously now as direct-connect. | 1466 // requests should complete synchronously now as direct-connect. |
1466 config.auto_detect = false; | 1467 config.auto_detect = false; |
1467 config_service->config = config; | 1468 config_service->config = config; |
1468 service.UpdateConfig(); | 1469 service.UpdateConfig(); |
1469 | 1470 |
1470 // Start another request -- the effective configuration has changed. | 1471 // Start another request -- the effective configuration has changed. |
1471 ProxyInfo info2; | 1472 ProxyInfo info2; |
1472 TestCompletionCallback callback2; | 1473 TestCompletionCallback callback2; |
1473 rv = service.ResolveProxy( | 1474 rv = service.ResolveProxy( |
1474 GURL("http://www.google.com"), &info2, &callback2, NULL); | 1475 NULL, GURL("http://www.google.com"), &info2, &callback2, NULL); |
1475 EXPECT_EQ(OK, rv); | 1476 EXPECT_EQ(OK, rv); |
1476 | 1477 |
1477 EXPECT_TRUE(info2.is_direct()); | 1478 EXPECT_TRUE(info2.is_direct()); |
1478 } | 1479 } |
1479 | 1480 |
1480 } // namespace net | 1481 } // namespace net |
OLD | NEW |