OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 159 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
160 ProxyService service(new MockProxyConfigService( | 160 ProxyService service(new MockProxyConfigService( |
161 ProxyConfig::CreateDirect()), resolver, NULL); | 161 ProxyConfig::CreateDirect()), resolver, NULL); |
162 | 162 |
163 GURL url("http://www.google.com/"); | 163 GURL url("http://www.google.com/"); |
164 | 164 |
165 ProxyInfo info; | 165 ProxyInfo info; |
166 TestCompletionCallback callback; | 166 TestCompletionCallback callback; |
167 CapturingBoundNetLog log; | 167 CapturingBoundNetLog log; |
168 int rv = service.ResolveProxy( | 168 int rv = service.ResolveProxy( |
169 url, &info, callback.callback(), NULL, log.bound()); | 169 url, 0, &info, callback.callback(), NULL, log.bound()); |
170 EXPECT_EQ(OK, rv); | 170 EXPECT_EQ(OK, rv); |
171 EXPECT_TRUE(resolver->pending_requests().empty()); | 171 EXPECT_TRUE(resolver->pending_requests().empty()); |
172 | 172 |
173 EXPECT_TRUE(info.is_direct()); | 173 EXPECT_TRUE(info.is_direct()); |
174 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); | 174 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); |
175 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); | 175 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); |
176 | 176 |
177 // Check the NetLog was filled correctly. | 177 // Check the NetLog was filled correctly. |
178 CapturingNetLog::CapturedEntryList entries; | 178 CapturingNetLog::CapturedEntryList entries; |
179 log.GetEntries(&entries); | 179 log.GetEntries(&entries); |
(...skipping 17 matching lines...) Expand all Loading... |
197 ProxyService service(config_service, resolver, NULL); | 197 ProxyService service(config_service, resolver, NULL); |
198 | 198 |
199 GURL url("http://www.google.com/"); | 199 GURL url("http://www.google.com/"); |
200 | 200 |
201 ProxyInfo info; | 201 ProxyInfo info; |
202 TestCompletionCallback callback; | 202 TestCompletionCallback callback; |
203 ProxyService::PacRequest* request; | 203 ProxyService::PacRequest* request; |
204 CapturingBoundNetLog log; | 204 CapturingBoundNetLog log; |
205 | 205 |
206 int rv = service.ResolveProxy( | 206 int rv = service.ResolveProxy( |
207 url, &info, callback.callback(), &request, log.bound()); | 207 url, 0, &info, callback.callback(), &request, log.bound()); |
208 EXPECT_EQ(ERR_IO_PENDING, rv); | 208 EXPECT_EQ(ERR_IO_PENDING, rv); |
209 | 209 |
210 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); | 210 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); |
211 | 211 |
212 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 212 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
213 resolver->pending_set_pac_script_request()->script_data()->url()); | 213 resolver->pending_set_pac_script_request()->script_data()->url()); |
214 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 214 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
215 | 215 |
216 ASSERT_EQ(1u, resolver->pending_requests().size()); | 216 ASSERT_EQ(1u, resolver->pending_requests().size()); |
217 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 217 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 252 |
253 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 253 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
254 | 254 |
255 ProxyService service(config_service, resolver, NULL); | 255 ProxyService service(config_service, resolver, NULL); |
256 | 256 |
257 GURL url("http://username:password@www.google.com/?ref#hash#hash"); | 257 GURL url("http://username:password@www.google.com/?ref#hash#hash"); |
258 | 258 |
259 ProxyInfo info; | 259 ProxyInfo info; |
260 TestCompletionCallback callback; | 260 TestCompletionCallback callback; |
261 int rv = service.ResolveProxy( | 261 int rv = service.ResolveProxy( |
262 url, &info, callback.callback(), NULL, BoundNetLog()); | 262 url, 0, &info, callback.callback(), NULL, BoundNetLog()); |
263 EXPECT_EQ(ERR_IO_PENDING, rv); | 263 EXPECT_EQ(ERR_IO_PENDING, rv); |
264 | 264 |
265 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 265 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
266 resolver->pending_set_pac_script_request()->script_data()->url()); | 266 resolver->pending_set_pac_script_request()->script_data()->url()); |
267 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 267 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
268 | 268 |
269 ASSERT_EQ(1u, resolver->pending_requests().size()); | 269 ASSERT_EQ(1u, resolver->pending_requests().size()); |
270 // The URL should have been simplified, stripping the username/password/hash. | 270 // The URL should have been simplified, stripping the username/password/hash. |
271 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 271 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
272 resolver->pending_requests()[0]->url()); | 272 resolver->pending_requests()[0]->url()); |
273 | 273 |
274 // We end here without ever completing the request -- destruction of | 274 // We end here without ever completing the request -- destruction of |
275 // ProxyService will cancel the outstanding request. | 275 // ProxyService will cancel the outstanding request. |
276 } | 276 } |
277 | 277 |
278 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { | 278 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { |
279 MockProxyConfigService* config_service = | 279 MockProxyConfigService* config_service = |
280 new MockProxyConfigService("http://foopy/proxy.pac"); | 280 new MockProxyConfigService("http://foopy/proxy.pac"); |
281 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 281 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
282 | 282 |
283 ProxyService service(config_service, resolver, NULL); | 283 ProxyService service(config_service, resolver, NULL); |
284 | 284 |
285 GURL url("http://www.google.com/"); | 285 GURL url("http://www.google.com/"); |
286 | 286 |
287 ProxyInfo info; | 287 ProxyInfo info; |
288 TestCompletionCallback callback1; | 288 TestCompletionCallback callback1; |
289 int rv = service.ResolveProxy( | 289 int rv = service.ResolveProxy( |
290 url, &info, callback1.callback(), NULL, BoundNetLog()); | 290 url, 0, &info, callback1.callback(), NULL, BoundNetLog()); |
291 EXPECT_EQ(ERR_IO_PENDING, rv); | 291 EXPECT_EQ(ERR_IO_PENDING, rv); |
292 | 292 |
293 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 293 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
294 resolver->pending_set_pac_script_request()->script_data()->url()); | 294 resolver->pending_set_pac_script_request()->script_data()->url()); |
295 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 295 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
296 | 296 |
297 ASSERT_EQ(1u, resolver->pending_requests().size()); | 297 ASSERT_EQ(1u, resolver->pending_requests().size()); |
298 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 298 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
299 | 299 |
300 // Set the result in proxy resolver. | 300 // Set the result in proxy resolver. |
(...skipping 28 matching lines...) Expand all Loading... |
329 new MockProxyConfigService("http://foopy/proxy.pac"); | 329 new MockProxyConfigService("http://foopy/proxy.pac"); |
330 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 330 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
331 | 331 |
332 ProxyService service(config_service, resolver, NULL); | 332 ProxyService service(config_service, resolver, NULL); |
333 | 333 |
334 GURL url("http://this-causes-js-error/"); | 334 GURL url("http://this-causes-js-error/"); |
335 | 335 |
336 ProxyInfo info; | 336 ProxyInfo info; |
337 TestCompletionCallback callback1; | 337 TestCompletionCallback callback1; |
338 int rv = service.ResolveProxy( | 338 int rv = service.ResolveProxy( |
339 url, &info, callback1.callback(), NULL, BoundNetLog()); | 339 url, 0, &info, callback1.callback(), NULL, BoundNetLog()); |
340 EXPECT_EQ(ERR_IO_PENDING, rv); | 340 EXPECT_EQ(ERR_IO_PENDING, rv); |
341 | 341 |
342 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 342 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
343 resolver->pending_set_pac_script_request()->script_data()->url()); | 343 resolver->pending_set_pac_script_request()->script_data()->url()); |
344 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 344 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
345 | 345 |
346 ASSERT_EQ(1u, resolver->pending_requests().size()); | 346 ASSERT_EQ(1u, resolver->pending_requests().size()); |
347 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 347 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
348 | 348 |
349 // Simulate a failure in the PAC executor. | 349 // Simulate a failure in the PAC executor. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 new MockProxyConfigService("http://foopy/proxy.pac"); | 384 new MockProxyConfigService("http://foopy/proxy.pac"); |
385 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 385 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
386 | 386 |
387 ProxyService service(config_service, resolver, NULL); | 387 ProxyService service(config_service, resolver, NULL); |
388 | 388 |
389 GURL url("http://www.google.com/"); | 389 GURL url("http://www.google.com/"); |
390 | 390 |
391 ProxyInfo info; | 391 ProxyInfo info; |
392 TestCompletionCallback callback1; | 392 TestCompletionCallback callback1; |
393 int rv = service.ResolveProxy( | 393 int rv = service.ResolveProxy( |
394 url, &info, callback1.callback(), NULL, BoundNetLog()); | 394 url, 0, &info, callback1.callback(), NULL, BoundNetLog()); |
395 EXPECT_EQ(ERR_IO_PENDING, rv); | 395 EXPECT_EQ(ERR_IO_PENDING, rv); |
396 | 396 |
397 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 397 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
398 resolver->pending_set_pac_script_request()->script_data()->url()); | 398 resolver->pending_set_pac_script_request()->script_data()->url()); |
399 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 399 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
400 | 400 |
401 ASSERT_EQ(1u, resolver->pending_requests().size()); | 401 ASSERT_EQ(1u, resolver->pending_requests().size()); |
402 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 402 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
403 | 403 |
404 // Set the result in proxy resolver. | 404 // Set the result in proxy resolver. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 453 |
454 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 454 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
455 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 455 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
456 ProxyService service(config_service, resolver, NULL); | 456 ProxyService service(config_service, resolver, NULL); |
457 | 457 |
458 // Resolve something. | 458 // Resolve something. |
459 GURL url("http://www.google.com/"); | 459 GURL url("http://www.google.com/"); |
460 ProxyInfo info; | 460 ProxyInfo info; |
461 TestCompletionCallback callback; | 461 TestCompletionCallback callback; |
462 int rv = service.ResolveProxy( | 462 int rv = service.ResolveProxy( |
463 url, &info, callback.callback(), NULL, BoundNetLog()); | 463 url, 0, &info, callback.callback(), NULL, BoundNetLog()); |
464 ASSERT_EQ(ERR_IO_PENDING, rv); | 464 ASSERT_EQ(ERR_IO_PENDING, rv); |
465 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 465 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
466 ASSERT_EQ(1u, resolver->pending_requests().size()); | 466 ASSERT_EQ(1u, resolver->pending_requests().size()); |
467 | 467 |
468 // Set the result in proxy resolver. | 468 // Set the result in proxy resolver. |
469 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); | 469 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); |
470 resolver->pending_requests()[0]->CompleteNow(OK); | 470 resolver->pending_requests()[0]->CompleteNow(OK); |
471 | 471 |
472 EXPECT_EQ(OK, callback.WaitForResult()); | 472 EXPECT_EQ(OK, callback.WaitForResult()); |
473 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 473 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
(...skipping 14 matching lines...) Expand all Loading... |
488 | 488 |
489 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 489 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
490 | 490 |
491 ProxyService service(config_service, resolver, NULL); | 491 ProxyService service(config_service, resolver, NULL); |
492 | 492 |
493 // Start first resolve request. | 493 // Start first resolve request. |
494 GURL url("http://www.google.com/"); | 494 GURL url("http://www.google.com/"); |
495 ProxyInfo info; | 495 ProxyInfo info; |
496 TestCompletionCallback callback1; | 496 TestCompletionCallback callback1; |
497 int rv = service.ResolveProxy( | 497 int rv = service.ResolveProxy( |
498 url, &info, callback1.callback(), NULL, BoundNetLog()); | 498 url, 0, &info, callback1.callback(), NULL, BoundNetLog()); |
499 EXPECT_EQ(ERR_IO_PENDING, rv); | 499 EXPECT_EQ(ERR_IO_PENDING, rv); |
500 | 500 |
501 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 501 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
502 resolver->pending_set_pac_script_request()->script_data()->url()); | 502 resolver->pending_set_pac_script_request()->script_data()->url()); |
503 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 503 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
504 | 504 |
505 ASSERT_EQ(1u, resolver->pending_requests().size()); | 505 ASSERT_EQ(1u, resolver->pending_requests().size()); |
506 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 506 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
507 | 507 |
508 // Fail the first resolve request in MockAsyncProxyResolver. | 508 // Fail the first resolve request in MockAsyncProxyResolver. |
509 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 509 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
510 | 510 |
511 // Although the proxy resolver failed the request, ProxyService implicitly | 511 // Although the proxy resolver failed the request, ProxyService implicitly |
512 // falls-back to DIRECT. | 512 // falls-back to DIRECT. |
513 EXPECT_EQ(OK, callback1.WaitForResult()); | 513 EXPECT_EQ(OK, callback1.WaitForResult()); |
514 EXPECT_TRUE(info.is_direct()); | 514 EXPECT_TRUE(info.is_direct()); |
515 | 515 |
516 // Failed PAC executions still have proxy resolution times. | 516 // Failed PAC executions still have proxy resolution times. |
517 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 517 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
518 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 518 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
519 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 519 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
520 | 520 |
521 // The second resolve request will try to run through the proxy resolver, | 521 // The second resolve request will try to run through the proxy resolver, |
522 // regardless of whether the first request failed in it. | 522 // regardless of whether the first request failed in it. |
523 TestCompletionCallback callback2; | 523 TestCompletionCallback callback2; |
524 rv = service.ResolveProxy( | 524 rv = service.ResolveProxy( |
525 url, &info, callback2.callback(), NULL, BoundNetLog()); | 525 url, 0, &info, callback2.callback(), NULL, BoundNetLog()); |
526 EXPECT_EQ(ERR_IO_PENDING, rv); | 526 EXPECT_EQ(ERR_IO_PENDING, rv); |
527 | 527 |
528 ASSERT_EQ(1u, resolver->pending_requests().size()); | 528 ASSERT_EQ(1u, resolver->pending_requests().size()); |
529 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 529 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
530 | 530 |
531 // This time we will have the resolver succeed (perhaps the PAC script has | 531 // This time we will have the resolver succeed (perhaps the PAC script has |
532 // a dependency on the current time). | 532 // a dependency on the current time). |
533 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 533 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
534 resolver->pending_requests()[0]->CompleteNow(OK); | 534 resolver->pending_requests()[0]->CompleteNow(OK); |
535 | 535 |
(...skipping 14 matching lines...) Expand all Loading... |
550 | 550 |
551 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 551 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
552 | 552 |
553 ProxyService service(config_service, resolver, NULL); | 553 ProxyService service(config_service, resolver, NULL); |
554 | 554 |
555 // Start first resolve request. | 555 // Start first resolve request. |
556 GURL url("http://www.google.com/"); | 556 GURL url("http://www.google.com/"); |
557 ProxyInfo info; | 557 ProxyInfo info; |
558 TestCompletionCallback callback1; | 558 TestCompletionCallback callback1; |
559 int rv = service.ResolveProxy( | 559 int rv = service.ResolveProxy( |
560 url, &info, callback1.callback(), NULL, BoundNetLog()); | 560 url, 0, &info, callback1.callback(), NULL, BoundNetLog()); |
561 EXPECT_EQ(ERR_IO_PENDING, rv); | 561 EXPECT_EQ(ERR_IO_PENDING, rv); |
562 | 562 |
563 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 563 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
564 resolver->pending_set_pac_script_request()->script_data()->url()); | 564 resolver->pending_set_pac_script_request()->script_data()->url()); |
565 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); | 565 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); |
566 | 566 |
567 ASSERT_EQ(0u, resolver->pending_requests().size()); | 567 ASSERT_EQ(0u, resolver->pending_requests().size()); |
568 | 568 |
569 // As the proxy resolver failed the request and is configured for a mandatory | 569 // As the proxy resolver failed the request and is configured for a mandatory |
570 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 570 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
571 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 571 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
572 callback1.WaitForResult()); | 572 callback1.WaitForResult()); |
573 EXPECT_FALSE(info.is_direct()); | 573 EXPECT_FALSE(info.is_direct()); |
574 | 574 |
575 // As the proxy resolver failed the request and is configured for a mandatory | 575 // As the proxy resolver failed the request and is configured for a mandatory |
576 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 576 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
577 TestCompletionCallback callback2; | 577 TestCompletionCallback callback2; |
578 rv = service.ResolveProxy( | 578 rv = service.ResolveProxy( |
579 url, &info, callback2.callback(), NULL, BoundNetLog()); | 579 url, 0, &info, callback2.callback(), NULL, BoundNetLog()); |
580 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); | 580 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); |
581 EXPECT_FALSE(info.is_direct()); | 581 EXPECT_FALSE(info.is_direct()); |
582 } | 582 } |
583 | 583 |
584 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { | 584 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { |
585 // Test what happens when the ProxyResolver fails that is configured to use a | 585 // Test what happens when the ProxyResolver fails that is configured to use a |
586 // mandatory PAC script. The download of the PAC script has already | 586 // mandatory PAC script. The download of the PAC script has already |
587 // succeeded but the PAC script contains no valid javascript. | 587 // succeeded but the PAC script contains no valid javascript. |
588 | 588 |
589 ProxyConfig config( | 589 ProxyConfig config( |
590 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 590 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
591 config.set_pac_mandatory(true); | 591 config.set_pac_mandatory(true); |
592 | 592 |
593 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 593 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
594 | 594 |
595 MockAsyncProxyResolverExpectsBytes* resolver = | 595 MockAsyncProxyResolverExpectsBytes* resolver = |
596 new MockAsyncProxyResolverExpectsBytes; | 596 new MockAsyncProxyResolverExpectsBytes; |
597 | 597 |
598 ProxyService service(config_service, resolver, NULL); | 598 ProxyService service(config_service, resolver, NULL); |
599 | 599 |
600 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 600 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
601 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher(); | 601 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher(); |
602 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher); | 602 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher); |
603 | 603 |
604 // Start resolve request. | 604 // Start resolve request. |
605 GURL url("http://www.google.com/"); | 605 GURL url("http://www.google.com/"); |
606 ProxyInfo info; | 606 ProxyInfo info; |
607 TestCompletionCallback callback; | 607 TestCompletionCallback callback; |
608 int rv = service.ResolveProxy( | 608 int rv = service.ResolveProxy( |
609 url, &info, callback.callback(), NULL, BoundNetLog()); | 609 url, 0, &info, callback.callback(), NULL, BoundNetLog()); |
610 EXPECT_EQ(ERR_IO_PENDING, rv); | 610 EXPECT_EQ(ERR_IO_PENDING, rv); |
611 | 611 |
612 // Check that nothing has been sent to the proxy resolver yet. | 612 // Check that nothing has been sent to the proxy resolver yet. |
613 ASSERT_EQ(0u, resolver->pending_requests().size()); | 613 ASSERT_EQ(0u, resolver->pending_requests().size()); |
614 | 614 |
615 // Downloading the PAC script succeeds. | 615 // Downloading the PAC script succeeds. |
616 EXPECT_TRUE(fetcher->has_pending_request()); | 616 EXPECT_TRUE(fetcher->has_pending_request()); |
617 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 617 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
618 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 618 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
619 | 619 |
(...skipping 22 matching lines...) Expand all Loading... |
642 | 642 |
643 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 643 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
644 | 644 |
645 ProxyService service(config_service, resolver, NULL); | 645 ProxyService service(config_service, resolver, NULL); |
646 | 646 |
647 // Start first resolve request. | 647 // Start first resolve request. |
648 GURL url("http://www.google.com/"); | 648 GURL url("http://www.google.com/"); |
649 ProxyInfo info; | 649 ProxyInfo info; |
650 TestCompletionCallback callback1; | 650 TestCompletionCallback callback1; |
651 int rv = service.ResolveProxy( | 651 int rv = service.ResolveProxy( |
652 url, &info, callback1.callback(), NULL, BoundNetLog()); | 652 url, 0, &info, callback1.callback(), NULL, BoundNetLog()); |
653 EXPECT_EQ(ERR_IO_PENDING, rv); | 653 EXPECT_EQ(ERR_IO_PENDING, rv); |
654 | 654 |
655 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 655 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
656 resolver->pending_set_pac_script_request()->script_data()->url()); | 656 resolver->pending_set_pac_script_request()->script_data()->url()); |
657 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 657 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
658 | 658 |
659 ASSERT_EQ(1u, resolver->pending_requests().size()); | 659 ASSERT_EQ(1u, resolver->pending_requests().size()); |
660 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 660 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
661 | 661 |
662 // Fail the first resolve request in MockAsyncProxyResolver. | 662 // Fail the first resolve request in MockAsyncProxyResolver. |
663 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 663 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
664 | 664 |
665 // As the proxy resolver failed the request and is configured for a mandatory | 665 // As the proxy resolver failed the request and is configured for a mandatory |
666 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 666 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
667 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 667 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
668 callback1.WaitForResult()); | 668 callback1.WaitForResult()); |
669 EXPECT_FALSE(info.is_direct()); | 669 EXPECT_FALSE(info.is_direct()); |
670 | 670 |
671 // The second resolve request will try to run through the proxy resolver, | 671 // The second resolve request will try to run through the proxy resolver, |
672 // regardless of whether the first request failed in it. | 672 // regardless of whether the first request failed in it. |
673 TestCompletionCallback callback2; | 673 TestCompletionCallback callback2; |
674 rv = service.ResolveProxy( | 674 rv = service.ResolveProxy( |
675 url, &info, callback2.callback(), NULL, BoundNetLog()); | 675 url, 0, &info, callback2.callback(), NULL, BoundNetLog()); |
676 EXPECT_EQ(ERR_IO_PENDING, rv); | 676 EXPECT_EQ(ERR_IO_PENDING, rv); |
677 | 677 |
678 ASSERT_EQ(1u, resolver->pending_requests().size()); | 678 ASSERT_EQ(1u, resolver->pending_requests().size()); |
679 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 679 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
680 | 680 |
681 // This time we will have the resolver succeed (perhaps the PAC script has | 681 // This time we will have the resolver succeed (perhaps the PAC script has |
682 // a dependency on the current time). | 682 // a dependency on the current time). |
683 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 683 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
684 resolver->pending_requests()[0]->CompleteNow(OK); | 684 resolver->pending_requests()[0]->CompleteNow(OK); |
685 | 685 |
(...skipping 12 matching lines...) Expand all Loading... |
698 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 698 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
699 | 699 |
700 ProxyService service(config_service, resolver, NULL); | 700 ProxyService service(config_service, resolver, NULL); |
701 | 701 |
702 GURL url("http://www.google.com/"); | 702 GURL url("http://www.google.com/"); |
703 | 703 |
704 // Get the proxy information. | 704 // Get the proxy information. |
705 ProxyInfo info; | 705 ProxyInfo info; |
706 TestCompletionCallback callback1; | 706 TestCompletionCallback callback1; |
707 int rv = service.ResolveProxy( | 707 int rv = service.ResolveProxy( |
708 url, &info, callback1.callback(), NULL, BoundNetLog()); | 708 url, 0, &info, callback1.callback(), NULL, BoundNetLog()); |
709 EXPECT_EQ(ERR_IO_PENDING, rv); | 709 EXPECT_EQ(ERR_IO_PENDING, rv); |
710 | 710 |
711 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 711 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
712 resolver->pending_set_pac_script_request()->script_data()->url()); | 712 resolver->pending_set_pac_script_request()->script_data()->url()); |
713 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 713 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
714 | 714 |
715 ASSERT_EQ(1u, resolver->pending_requests().size()); | 715 ASSERT_EQ(1u, resolver->pending_requests().size()); |
716 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 716 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
717 | 717 |
718 // Set the result in proxy resolver. | 718 // Set the result in proxy resolver. |
(...skipping 24 matching lines...) Expand all Loading... |
743 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 743 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
744 | 744 |
745 // The second proxy should be specified. | 745 // The second proxy should be specified. |
746 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 746 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
747 // Report back that the second proxy worked. This will globally mark the | 747 // Report back that the second proxy worked. This will globally mark the |
748 // first proxy as bad. | 748 // first proxy as bad. |
749 service.ReportSuccess(info); | 749 service.ReportSuccess(info); |
750 | 750 |
751 TestCompletionCallback callback3; | 751 TestCompletionCallback callback3; |
752 rv = service.ResolveProxy( | 752 rv = service.ResolveProxy( |
753 url, &info, callback3.callback(), NULL, BoundNetLog()); | 753 url, 0, &info, callback3.callback(), NULL, BoundNetLog()); |
754 EXPECT_EQ(ERR_IO_PENDING, rv); | 754 EXPECT_EQ(ERR_IO_PENDING, rv); |
755 | 755 |
756 ASSERT_EQ(1u, resolver->pending_requests().size()); | 756 ASSERT_EQ(1u, resolver->pending_requests().size()); |
757 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 757 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
758 | 758 |
759 // Set the result in proxy resolver -- the second result is already known | 759 // Set the result in proxy resolver -- the second result is already known |
760 // to be bad, so we will not try to use it initially. | 760 // to be bad, so we will not try to use it initially. |
761 resolver->pending_requests()[0]->results()->UseNamedProxy( | 761 resolver->pending_requests()[0]->results()->UseNamedProxy( |
762 "foopy3:7070;foopy1:8080;foopy2:9090"); | 762 "foopy3:7070;foopy1:8080;foopy2:9090"); |
763 resolver->pending_requests()[0]->CompleteNow(OK); | 763 resolver->pending_requests()[0]->CompleteNow(OK); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 EXPECT_EQ(ERR_FAILED, rv); | 801 EXPECT_EQ(ERR_FAILED, rv); |
802 EXPECT_FALSE(info.is_direct()); | 802 EXPECT_FALSE(info.is_direct()); |
803 EXPECT_TRUE(info.is_empty()); | 803 EXPECT_TRUE(info.is_empty()); |
804 | 804 |
805 // Proxy times should not have been modified by fallback. | 805 // Proxy times should not have been modified by fallback. |
806 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 806 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
807 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 807 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
808 | 808 |
809 // Look up proxies again | 809 // Look up proxies again |
810 TestCompletionCallback callback7; | 810 TestCompletionCallback callback7; |
811 rv = service.ResolveProxy(url, &info, callback7.callback(), NULL, | 811 rv = service.ResolveProxy(url, 0, &info, callback7.callback(), NULL, |
812 BoundNetLog()); | 812 BoundNetLog()); |
813 EXPECT_EQ(ERR_IO_PENDING, rv); | 813 EXPECT_EQ(ERR_IO_PENDING, rv); |
814 | 814 |
815 ASSERT_EQ(1u, resolver->pending_requests().size()); | 815 ASSERT_EQ(1u, resolver->pending_requests().size()); |
816 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 816 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
817 | 817 |
818 // This time, the first 3 results have been found to be bad, but only the | 818 // This time, the first 3 results have been found to be bad, but only the |
819 // first proxy has been confirmed ... | 819 // first proxy has been confirmed ... |
820 resolver->pending_requests()[0]->results()->UseNamedProxy( | 820 resolver->pending_requests()[0]->results()->UseNamedProxy( |
821 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); | 821 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); |
(...skipping 19 matching lines...) Expand all Loading... |
841 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 841 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
842 | 842 |
843 ProxyService service(config_service, resolver, NULL); | 843 ProxyService service(config_service, resolver, NULL); |
844 | 844 |
845 GURL url("http://www.google.com/"); | 845 GURL url("http://www.google.com/"); |
846 | 846 |
847 // Get the proxy information. | 847 // Get the proxy information. |
848 ProxyInfo info; | 848 ProxyInfo info; |
849 TestCompletionCallback callback1; | 849 TestCompletionCallback callback1; |
850 int rv = service.ResolveProxy( | 850 int rv = service.ResolveProxy( |
851 url, &info, callback1.callback(), NULL, BoundNetLog()); | 851 url, 0, &info, callback1.callback(), NULL, BoundNetLog()); |
852 EXPECT_EQ(ERR_IO_PENDING, rv); | 852 EXPECT_EQ(ERR_IO_PENDING, rv); |
853 | 853 |
854 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 854 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
855 resolver->pending_set_pac_script_request()->script_data()->url()); | 855 resolver->pending_set_pac_script_request()->script_data()->url()); |
856 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 856 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
857 | 857 |
858 ASSERT_EQ(1u, resolver->pending_requests().size()); | 858 ASSERT_EQ(1u, resolver->pending_requests().size()); |
859 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 859 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
860 | 860 |
861 // Set the result in proxy resolver. | 861 // Set the result in proxy resolver. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 911 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
912 | 912 |
913 ProxyService service(config_service, resolver, NULL); | 913 ProxyService service(config_service, resolver, NULL); |
914 | 914 |
915 GURL url("http://www.google.com/"); | 915 GURL url("http://www.google.com/"); |
916 | 916 |
917 // Get the proxy information. | 917 // Get the proxy information. |
918 ProxyInfo info; | 918 ProxyInfo info; |
919 TestCompletionCallback callback1; | 919 TestCompletionCallback callback1; |
920 int rv = service.ResolveProxy( | 920 int rv = service.ResolveProxy( |
921 url, &info, callback1.callback(), NULL, BoundNetLog()); | 921 url, 0, &info, callback1.callback(), NULL, BoundNetLog()); |
922 EXPECT_EQ(ERR_IO_PENDING, rv); | 922 EXPECT_EQ(ERR_IO_PENDING, rv); |
923 | 923 |
924 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 924 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
925 resolver->pending_set_pac_script_request()->script_data()->url()); | 925 resolver->pending_set_pac_script_request()->script_data()->url()); |
926 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 926 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
927 | 927 |
928 ASSERT_EQ(1u, resolver->pending_requests().size()); | 928 ASSERT_EQ(1u, resolver->pending_requests().size()); |
929 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 929 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
930 | 930 |
931 // Set the result in proxy resolver. | 931 // Set the result in proxy resolver. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1011 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1012 | 1012 |
1013 ProxyService service(config_service, resolver, NULL); | 1013 ProxyService service(config_service, resolver, NULL); |
1014 | 1014 |
1015 GURL url("http://www.google.com/"); | 1015 GURL url("http://www.google.com/"); |
1016 | 1016 |
1017 // Get the proxy information. | 1017 // Get the proxy information. |
1018 ProxyInfo info; | 1018 ProxyInfo info; |
1019 TestCompletionCallback callback1; | 1019 TestCompletionCallback callback1; |
1020 int rv = service.ResolveProxy( | 1020 int rv = service.ResolveProxy( |
1021 url, &info, callback1.callback(), NULL, BoundNetLog()); | 1021 url, 0, &info, callback1.callback(), NULL, BoundNetLog()); |
1022 EXPECT_EQ(ERR_IO_PENDING, rv); | 1022 EXPECT_EQ(ERR_IO_PENDING, rv); |
1023 | 1023 |
1024 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1024 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1025 resolver->pending_set_pac_script_request()->script_data()->url()); | 1025 resolver->pending_set_pac_script_request()->script_data()->url()); |
1026 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1026 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1027 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1027 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1028 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1028 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1029 | 1029 |
1030 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1030 resolver->pending_requests()[0]->results()->UseNamedProxy( |
1031 "foopy1:8080;foopy2:9090"); | 1031 "foopy1:8080;foopy2:9090"); |
(...skipping 12 matching lines...) Expand all Loading... |
1044 EXPECT_EQ(OK, rv); | 1044 EXPECT_EQ(OK, rv); |
1045 | 1045 |
1046 // The first proxy is ignored, and the second one is selected. | 1046 // The first proxy is ignored, and the second one is selected. |
1047 EXPECT_FALSE(info.is_direct()); | 1047 EXPECT_FALSE(info.is_direct()); |
1048 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1048 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1049 | 1049 |
1050 // Fake a PAC failure. | 1050 // Fake a PAC failure. |
1051 ProxyInfo info2; | 1051 ProxyInfo info2; |
1052 TestCompletionCallback callback3; | 1052 TestCompletionCallback callback3; |
1053 rv = service.ResolveProxy( | 1053 rv = service.ResolveProxy( |
1054 url, &info2, callback3.callback(), NULL, BoundNetLog()); | 1054 url, 0, &info2, callback3.callback(), NULL, BoundNetLog()); |
1055 EXPECT_EQ(ERR_IO_PENDING, rv); | 1055 EXPECT_EQ(ERR_IO_PENDING, rv); |
1056 | 1056 |
1057 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1057 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1058 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1058 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1059 | 1059 |
1060 // This simulates a javascript runtime error in the PAC script. | 1060 // This simulates a javascript runtime error in the PAC script. |
1061 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 1061 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
1062 | 1062 |
1063 // Although the resolver failed, the ProxyService will implicitly fall-back | 1063 // Although the resolver failed, the ProxyService will implicitly fall-back |
1064 // to a DIRECT connection. | 1064 // to a DIRECT connection. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1106 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1107 | 1107 |
1108 ProxyService service(config_service, resolver, NULL); | 1108 ProxyService service(config_service, resolver, NULL); |
1109 | 1109 |
1110 GURL url("http://www.google.com/"); | 1110 GURL url("http://www.google.com/"); |
1111 | 1111 |
1112 // Get the proxy information. | 1112 // Get the proxy information. |
1113 ProxyInfo info; | 1113 ProxyInfo info; |
1114 TestCompletionCallback callback1; | 1114 TestCompletionCallback callback1; |
1115 int rv = service.ResolveProxy( | 1115 int rv = service.ResolveProxy( |
1116 url, &info, callback1.callback(), NULL, BoundNetLog()); | 1116 url, 0, &info, callback1.callback(), NULL, BoundNetLog()); |
1117 EXPECT_EQ(ERR_IO_PENDING, rv); | 1117 EXPECT_EQ(ERR_IO_PENDING, rv); |
1118 | 1118 |
1119 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1119 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1120 resolver->pending_set_pac_script_request()->script_data()->url()); | 1120 resolver->pending_set_pac_script_request()->script_data()->url()); |
1121 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1121 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1122 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1122 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1123 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1123 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1124 | 1124 |
1125 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1125 resolver->pending_requests()[0]->results()->UseNamedProxy( |
1126 "foopy1:8080;foopy2:9090"); | 1126 "foopy1:8080;foopy2:9090"); |
(...skipping 12 matching lines...) Expand all Loading... |
1139 EXPECT_EQ(OK, rv); | 1139 EXPECT_EQ(OK, rv); |
1140 | 1140 |
1141 // The first proxy is ignored, and the second one is selected. | 1141 // The first proxy is ignored, and the second one is selected. |
1142 EXPECT_FALSE(info.is_direct()); | 1142 EXPECT_FALSE(info.is_direct()); |
1143 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1143 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1144 | 1144 |
1145 // Fake a PAC failure. | 1145 // Fake a PAC failure. |
1146 ProxyInfo info2; | 1146 ProxyInfo info2; |
1147 TestCompletionCallback callback3; | 1147 TestCompletionCallback callback3; |
1148 rv = service.ResolveProxy( | 1148 rv = service.ResolveProxy( |
1149 url, &info2, callback3.callback(), NULL, BoundNetLog()); | 1149 url, 0, &info2, callback3.callback(), NULL, BoundNetLog()); |
1150 EXPECT_EQ(ERR_IO_PENDING, rv); | 1150 EXPECT_EQ(ERR_IO_PENDING, rv); |
1151 | 1151 |
1152 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1152 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1153 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1153 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1154 | 1154 |
1155 // This simulates a javascript runtime error in the PAC script. | 1155 // This simulates a javascript runtime error in the PAC script. |
1156 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 1156 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
1157 | 1157 |
1158 // Although the resolver failed, the ProxyService will NOT fall-back | 1158 // Although the resolver failed, the ProxyService will NOT fall-back |
1159 // to a DIRECT connection as it is configured as mandatory. | 1159 // to a DIRECT connection as it is configured as mandatory. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 | 1198 |
1199 ProxyService service( | 1199 ProxyService service( |
1200 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1200 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1201 | 1201 |
1202 int rv; | 1202 int rv; |
1203 GURL url1("http://www.webkit.org"); | 1203 GURL url1("http://www.webkit.org"); |
1204 GURL url2("http://www.webkit.com"); | 1204 GURL url2("http://www.webkit.com"); |
1205 | 1205 |
1206 // Request for a .org domain should bypass proxy. | 1206 // Request for a .org domain should bypass proxy. |
1207 rv = service.ResolveProxy( | 1207 rv = service.ResolveProxy( |
1208 url1, &info[0], callback[0].callback(), NULL, BoundNetLog()); | 1208 url1, 0, &info[0], callback[0].callback(), NULL, BoundNetLog()); |
1209 EXPECT_EQ(OK, rv); | 1209 EXPECT_EQ(OK, rv); |
1210 EXPECT_TRUE(info[0].is_direct()); | 1210 EXPECT_TRUE(info[0].is_direct()); |
1211 | 1211 |
1212 // Request for a .com domain hits the proxy. | 1212 // Request for a .com domain hits the proxy. |
1213 rv = service.ResolveProxy( | 1213 rv = service.ResolveProxy( |
1214 url2, &info[1], callback[1].callback(), NULL, BoundNetLog()); | 1214 url2, 0, &info[1], callback[1].callback(), NULL, BoundNetLog()); |
1215 EXPECT_EQ(OK, rv); | 1215 EXPECT_EQ(OK, rv); |
1216 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); | 1216 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); |
1217 } | 1217 } |
1218 | 1218 |
1219 | 1219 |
1220 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { | 1220 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { |
1221 ProxyConfig config; | 1221 ProxyConfig config; |
1222 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); | 1222 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); |
1223 config.set_auto_detect(false); | 1223 config.set_auto_detect(false); |
1224 { | 1224 { |
1225 ProxyService service( | 1225 ProxyService service( |
1226 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1226 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1227 GURL test_url("http://www.msn.com"); | 1227 GURL test_url("http://www.msn.com"); |
1228 ProxyInfo info; | 1228 ProxyInfo info; |
1229 TestCompletionCallback callback; | 1229 TestCompletionCallback callback; |
1230 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1230 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1231 BoundNetLog()); | 1231 BoundNetLog()); |
1232 EXPECT_EQ(OK, rv); | 1232 EXPECT_EQ(OK, rv); |
1233 EXPECT_FALSE(info.is_direct()); | 1233 EXPECT_FALSE(info.is_direct()); |
1234 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1234 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1235 } | 1235 } |
1236 { | 1236 { |
1237 ProxyService service( | 1237 ProxyService service( |
1238 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1238 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1239 GURL test_url("ftp://ftp.google.com"); | 1239 GURL test_url("ftp://ftp.google.com"); |
1240 ProxyInfo info; | 1240 ProxyInfo info; |
1241 TestCompletionCallback callback; | 1241 TestCompletionCallback callback; |
1242 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1242 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1243 BoundNetLog()); | 1243 BoundNetLog()); |
1244 EXPECT_EQ(OK, rv); | 1244 EXPECT_EQ(OK, rv); |
1245 EXPECT_TRUE(info.is_direct()); | 1245 EXPECT_TRUE(info.is_direct()); |
1246 EXPECT_EQ("direct://", info.proxy_server().ToURI()); | 1246 EXPECT_EQ("direct://", info.proxy_server().ToURI()); |
1247 } | 1247 } |
1248 { | 1248 { |
1249 ProxyService service( | 1249 ProxyService service( |
1250 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1250 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1251 GURL test_url("https://webbranch.techcu.com"); | 1251 GURL test_url("https://webbranch.techcu.com"); |
1252 ProxyInfo info; | 1252 ProxyInfo info; |
1253 TestCompletionCallback callback; | 1253 TestCompletionCallback callback; |
1254 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1254 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1255 BoundNetLog()); | 1255 BoundNetLog()); |
1256 EXPECT_EQ(OK, rv); | 1256 EXPECT_EQ(OK, rv); |
1257 EXPECT_FALSE(info.is_direct()); | 1257 EXPECT_FALSE(info.is_direct()); |
1258 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 1258 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
1259 } | 1259 } |
1260 { | 1260 { |
1261 config.proxy_rules().ParseFromString("foopy1:8080"); | 1261 config.proxy_rules().ParseFromString("foopy1:8080"); |
1262 ProxyService service( | 1262 ProxyService service( |
1263 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1263 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1264 GURL test_url("http://www.microsoft.com"); | 1264 GURL test_url("http://www.microsoft.com"); |
1265 ProxyInfo info; | 1265 ProxyInfo info; |
1266 TestCompletionCallback callback; | 1266 TestCompletionCallback callback; |
1267 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1267 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1268 BoundNetLog()); | 1268 BoundNetLog()); |
1269 EXPECT_EQ(OK, rv); | 1269 EXPECT_EQ(OK, rv); |
1270 EXPECT_FALSE(info.is_direct()); | 1270 EXPECT_FALSE(info.is_direct()); |
1271 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1271 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1272 } | 1272 } |
1273 } | 1273 } |
1274 | 1274 |
1275 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { | 1275 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { |
1276 // Test that the proxy config source is set correctly when resolving proxies | 1276 // Test that the proxy config source is set correctly when resolving proxies |
1277 // using manual proxy rules. Namely, the config source should only be set if | 1277 // using manual proxy rules. Namely, the config source should only be set if |
1278 // any of the rules were applied. | 1278 // any of the rules were applied. |
1279 { | 1279 { |
1280 ProxyConfig config; | 1280 ProxyConfig config; |
1281 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1281 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1282 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1282 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
1283 ProxyService service( | 1283 ProxyService service( |
1284 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1284 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1285 GURL test_url("http://www.google.com"); | 1285 GURL test_url("http://www.google.com"); |
1286 ProxyInfo info; | 1286 ProxyInfo info; |
1287 TestCompletionCallback callback; | 1287 TestCompletionCallback callback; |
1288 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1288 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1289 BoundNetLog()); | 1289 BoundNetLog()); |
1290 ASSERT_EQ(OK, rv); | 1290 ASSERT_EQ(OK, rv); |
1291 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. | 1291 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. |
1292 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1292 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1293 } | 1293 } |
1294 { | 1294 { |
1295 ProxyConfig config; | 1295 ProxyConfig config; |
1296 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1296 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1297 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1297 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
1298 ProxyService service( | 1298 ProxyService service( |
1299 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1299 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1300 GURL test_url("https://www.google.com"); | 1300 GURL test_url("https://www.google.com"); |
1301 ProxyInfo info; | 1301 ProxyInfo info; |
1302 TestCompletionCallback callback; | 1302 TestCompletionCallback callback; |
1303 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1303 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1304 BoundNetLog()); | 1304 BoundNetLog()); |
1305 ASSERT_EQ(OK, rv); | 1305 ASSERT_EQ(OK, rv); |
1306 // Used the HTTPS proxy. So source should be TEST. | 1306 // Used the HTTPS proxy. So source should be TEST. |
1307 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1307 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1308 } | 1308 } |
1309 { | 1309 { |
1310 ProxyConfig config; | 1310 ProxyConfig config; |
1311 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1311 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1312 ProxyService service( | 1312 ProxyService service( |
1313 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1313 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1314 GURL test_url("http://www.google.com"); | 1314 GURL test_url("http://www.google.com"); |
1315 ProxyInfo info; | 1315 ProxyInfo info; |
1316 TestCompletionCallback callback; | 1316 TestCompletionCallback callback; |
1317 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1317 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1318 BoundNetLog()); | 1318 BoundNetLog()); |
1319 ASSERT_EQ(OK, rv); | 1319 ASSERT_EQ(OK, rv); |
1320 // ProxyConfig is empty. Source should still be TEST. | 1320 // ProxyConfig is empty. Source should still be TEST. |
1321 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1321 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1322 } | 1322 } |
1323 } | 1323 } |
1324 | 1324 |
1325 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries | 1325 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries |
1326 // fall back to the SOCKS proxy. | 1326 // fall back to the SOCKS proxy. |
1327 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { | 1327 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { |
1328 ProxyConfig config; | 1328 ProxyConfig config; |
1329 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); | 1329 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); |
1330 config.set_auto_detect(false); | 1330 config.set_auto_detect(false); |
1331 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 1331 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
1332 config.proxy_rules().type); | 1332 config.proxy_rules().type); |
1333 | 1333 |
1334 { | 1334 { |
1335 ProxyService service( | 1335 ProxyService service( |
1336 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1336 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1337 GURL test_url("http://www.msn.com"); | 1337 GURL test_url("http://www.msn.com"); |
1338 ProxyInfo info; | 1338 ProxyInfo info; |
1339 TestCompletionCallback callback; | 1339 TestCompletionCallback callback; |
1340 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1340 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1341 BoundNetLog()); | 1341 BoundNetLog()); |
1342 EXPECT_EQ(OK, rv); | 1342 EXPECT_EQ(OK, rv); |
1343 EXPECT_FALSE(info.is_direct()); | 1343 EXPECT_FALSE(info.is_direct()); |
1344 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1344 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1345 } | 1345 } |
1346 { | 1346 { |
1347 ProxyService service( | 1347 ProxyService service( |
1348 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1348 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1349 GURL test_url("ftp://ftp.google.com"); | 1349 GURL test_url("ftp://ftp.google.com"); |
1350 ProxyInfo info; | 1350 ProxyInfo info; |
1351 TestCompletionCallback callback; | 1351 TestCompletionCallback callback; |
1352 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1352 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1353 BoundNetLog()); | 1353 BoundNetLog()); |
1354 EXPECT_EQ(OK, rv); | 1354 EXPECT_EQ(OK, rv); |
1355 EXPECT_FALSE(info.is_direct()); | 1355 EXPECT_FALSE(info.is_direct()); |
1356 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1356 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1357 } | 1357 } |
1358 { | 1358 { |
1359 ProxyService service( | 1359 ProxyService service( |
1360 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1360 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1361 GURL test_url("https://webbranch.techcu.com"); | 1361 GURL test_url("https://webbranch.techcu.com"); |
1362 ProxyInfo info; | 1362 ProxyInfo info; |
1363 TestCompletionCallback callback; | 1363 TestCompletionCallback callback; |
1364 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1364 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1365 BoundNetLog()); | 1365 BoundNetLog()); |
1366 EXPECT_EQ(OK, rv); | 1366 EXPECT_EQ(OK, rv); |
1367 EXPECT_FALSE(info.is_direct()); | 1367 EXPECT_FALSE(info.is_direct()); |
1368 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1368 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1369 } | 1369 } |
1370 { | 1370 { |
1371 ProxyService service( | 1371 ProxyService service( |
1372 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1372 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1373 GURL test_url("unknown://www.microsoft.com"); | 1373 GURL test_url("unknown://www.microsoft.com"); |
1374 ProxyInfo info; | 1374 ProxyInfo info; |
1375 TestCompletionCallback callback; | 1375 TestCompletionCallback callback; |
1376 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1376 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1377 BoundNetLog()); | 1377 BoundNetLog()); |
1378 EXPECT_EQ(OK, rv); | 1378 EXPECT_EQ(OK, rv); |
1379 EXPECT_FALSE(info.is_direct()); | 1379 EXPECT_FALSE(info.is_direct()); |
1380 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1380 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1381 } | 1381 } |
1382 } | 1382 } |
1383 | 1383 |
1384 // Test cancellation of an in-progress request. | 1384 // Test cancellation of an in-progress request. |
1385 TEST_F(ProxyServiceTest, CancelInProgressRequest) { | 1385 TEST_F(ProxyServiceTest, CancelInProgressRequest) { |
1386 MockProxyConfigService* config_service = | 1386 MockProxyConfigService* config_service = |
1387 new MockProxyConfigService("http://foopy/proxy.pac"); | 1387 new MockProxyConfigService("http://foopy/proxy.pac"); |
1388 | 1388 |
1389 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1389 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1390 | 1390 |
1391 ProxyService service(config_service, resolver, NULL); | 1391 ProxyService service(config_service, resolver, NULL); |
1392 | 1392 |
1393 // Start 3 requests. | 1393 // Start 3 requests. |
1394 | 1394 |
1395 ProxyInfo info1; | 1395 ProxyInfo info1; |
1396 TestCompletionCallback callback1; | 1396 TestCompletionCallback callback1; |
1397 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1397 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1398 callback1.callback(), NULL, BoundNetLog()); | 1398 callback1.callback(), NULL, BoundNetLog()); |
1399 EXPECT_EQ(ERR_IO_PENDING, rv); | 1399 EXPECT_EQ(ERR_IO_PENDING, rv); |
1400 | 1400 |
1401 // Nothing has been sent to the proxy resolver yet, since the proxy | 1401 // Nothing has been sent to the proxy resolver yet, since the proxy |
1402 // resolver has not been configured yet. | 1402 // resolver has not been configured yet. |
1403 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1403 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1404 | 1404 |
1405 // Successfully initialize the PAC script. | 1405 // Successfully initialize the PAC script. |
1406 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1406 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1407 resolver->pending_set_pac_script_request()->script_data()->url()); | 1407 resolver->pending_set_pac_script_request()->script_data()->url()); |
1408 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1408 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1409 | 1409 |
1410 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1410 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1411 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1411 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
1412 | 1412 |
1413 ProxyInfo info2; | 1413 ProxyInfo info2; |
1414 TestCompletionCallback callback2; | 1414 TestCompletionCallback callback2; |
1415 ProxyService::PacRequest* request2; | 1415 ProxyService::PacRequest* request2; |
1416 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1416 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1417 callback2.callback(), &request2, BoundNetLog()); | 1417 callback2.callback(), &request2, BoundNetLog()); |
1418 EXPECT_EQ(ERR_IO_PENDING, rv); | 1418 EXPECT_EQ(ERR_IO_PENDING, rv); |
1419 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1419 ASSERT_EQ(2u, resolver->pending_requests().size()); |
1420 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1420 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
1421 | 1421 |
1422 ProxyInfo info3; | 1422 ProxyInfo info3; |
1423 TestCompletionCallback callback3; | 1423 TestCompletionCallback callback3; |
1424 rv = service.ResolveProxy(GURL("http://request3"), &info3, | 1424 rv = service.ResolveProxy(GURL("http://request3"), 0, &info3, |
1425 callback3.callback(), NULL, BoundNetLog()); | 1425 callback3.callback(), NULL, BoundNetLog()); |
1426 EXPECT_EQ(ERR_IO_PENDING, rv); | 1426 EXPECT_EQ(ERR_IO_PENDING, rv); |
1427 ASSERT_EQ(3u, resolver->pending_requests().size()); | 1427 ASSERT_EQ(3u, resolver->pending_requests().size()); |
1428 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); | 1428 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); |
1429 | 1429 |
1430 // Cancel the second request | 1430 // Cancel the second request |
1431 service.CancelPacRequest(request2); | 1431 service.CancelPacRequest(request2); |
1432 | 1432 |
1433 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1433 ASSERT_EQ(2u, resolver->pending_requests().size()); |
1434 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1434 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1466 | 1466 |
1467 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1467 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1468 service.SetProxyScriptFetchers(fetcher, | 1468 service.SetProxyScriptFetchers(fetcher, |
1469 new DoNothingDhcpProxyScriptFetcher()); | 1469 new DoNothingDhcpProxyScriptFetcher()); |
1470 | 1470 |
1471 // Start 3 requests. | 1471 // Start 3 requests. |
1472 | 1472 |
1473 ProxyInfo info1; | 1473 ProxyInfo info1; |
1474 TestCompletionCallback callback1; | 1474 TestCompletionCallback callback1; |
1475 ProxyService::PacRequest* request1; | 1475 ProxyService::PacRequest* request1; |
1476 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1476 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1477 callback1.callback(), &request1, BoundNetLog()); | 1477 callback1.callback(), &request1, BoundNetLog()); |
1478 EXPECT_EQ(ERR_IO_PENDING, rv); | 1478 EXPECT_EQ(ERR_IO_PENDING, rv); |
1479 | 1479 |
1480 // The first request should have triggered download of PAC script. | 1480 // The first request should have triggered download of PAC script. |
1481 EXPECT_TRUE(fetcher->has_pending_request()); | 1481 EXPECT_TRUE(fetcher->has_pending_request()); |
1482 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1482 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1483 | 1483 |
1484 ProxyInfo info2; | 1484 ProxyInfo info2; |
1485 TestCompletionCallback callback2; | 1485 TestCompletionCallback callback2; |
1486 ProxyService::PacRequest* request2; | 1486 ProxyService::PacRequest* request2; |
1487 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1487 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1488 callback2.callback(), &request2, BoundNetLog()); | 1488 callback2.callback(), &request2, BoundNetLog()); |
1489 EXPECT_EQ(ERR_IO_PENDING, rv); | 1489 EXPECT_EQ(ERR_IO_PENDING, rv); |
1490 | 1490 |
1491 ProxyInfo info3; | 1491 ProxyInfo info3; |
1492 TestCompletionCallback callback3; | 1492 TestCompletionCallback callback3; |
1493 ProxyService::PacRequest* request3; | 1493 ProxyService::PacRequest* request3; |
1494 rv = service.ResolveProxy(GURL("http://request3"), &info3, | 1494 rv = service.ResolveProxy(GURL("http://request3"), 0, &info3, |
1495 callback3.callback(), &request3, BoundNetLog()); | 1495 callback3.callback(), &request3, BoundNetLog()); |
1496 EXPECT_EQ(ERR_IO_PENDING, rv); | 1496 EXPECT_EQ(ERR_IO_PENDING, rv); |
1497 | 1497 |
1498 // Nothing has been sent to the resolver yet. | 1498 // Nothing has been sent to the resolver yet. |
1499 EXPECT_TRUE(resolver->pending_requests().empty()); | 1499 EXPECT_TRUE(resolver->pending_requests().empty()); |
1500 | 1500 |
1501 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1501 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
1502 service.GetLoadState(request1)); | 1502 service.GetLoadState(request1)); |
1503 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1503 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
1504 service.GetLoadState(request2)); | 1504 service.GetLoadState(request2)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 ProxyService service(config_service, resolver, NULL); | 1568 ProxyService service(config_service, resolver, NULL); |
1569 | 1569 |
1570 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1570 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1571 service.SetProxyScriptFetchers(fetcher, | 1571 service.SetProxyScriptFetchers(fetcher, |
1572 new DoNothingDhcpProxyScriptFetcher()); | 1572 new DoNothingDhcpProxyScriptFetcher()); |
1573 | 1573 |
1574 // Start 2 requests. | 1574 // Start 2 requests. |
1575 | 1575 |
1576 ProxyInfo info1; | 1576 ProxyInfo info1; |
1577 TestCompletionCallback callback1; | 1577 TestCompletionCallback callback1; |
1578 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1578 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1579 callback1.callback(), NULL, BoundNetLog()); | 1579 callback1.callback(), NULL, BoundNetLog()); |
1580 EXPECT_EQ(ERR_IO_PENDING, rv); | 1580 EXPECT_EQ(ERR_IO_PENDING, rv); |
1581 | 1581 |
1582 // The first request should have triggered download of PAC script. | 1582 // The first request should have triggered download of PAC script. |
1583 EXPECT_TRUE(fetcher->has_pending_request()); | 1583 EXPECT_TRUE(fetcher->has_pending_request()); |
1584 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1584 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1585 | 1585 |
1586 ProxyInfo info2; | 1586 ProxyInfo info2; |
1587 TestCompletionCallback callback2; | 1587 TestCompletionCallback callback2; |
1588 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1588 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1589 callback2.callback(), NULL, BoundNetLog()); | 1589 callback2.callback(), NULL, BoundNetLog()); |
1590 EXPECT_EQ(ERR_IO_PENDING, rv); | 1590 EXPECT_EQ(ERR_IO_PENDING, rv); |
1591 | 1591 |
1592 // At this point the ProxyService should be waiting for the | 1592 // At this point the ProxyService should be waiting for the |
1593 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1593 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
1594 // PAC script download completion. | 1594 // PAC script download completion. |
1595 | 1595 |
1596 // We now change out the ProxyService's script fetcher. We should restart | 1596 // We now change out the ProxyService's script fetcher. We should restart |
1597 // the initialization with the new fetcher. | 1597 // the initialization with the new fetcher. |
1598 | 1598 |
(...skipping 29 matching lines...) Expand all Loading... |
1628 | 1628 |
1629 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1629 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1630 service.SetProxyScriptFetchers(fetcher, | 1630 service.SetProxyScriptFetchers(fetcher, |
1631 new DoNothingDhcpProxyScriptFetcher()); | 1631 new DoNothingDhcpProxyScriptFetcher()); |
1632 | 1632 |
1633 // Start 3 requests. | 1633 // Start 3 requests. |
1634 ProxyInfo info1; | 1634 ProxyInfo info1; |
1635 TestCompletionCallback callback1; | 1635 TestCompletionCallback callback1; |
1636 ProxyService::PacRequest* request1; | 1636 ProxyService::PacRequest* request1; |
1637 CapturingBoundNetLog log1; | 1637 CapturingBoundNetLog log1; |
1638 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1638 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1639 callback1.callback(), &request1, log1.bound()); | 1639 callback1.callback(), &request1, log1.bound()); |
1640 EXPECT_EQ(ERR_IO_PENDING, rv); | 1640 EXPECT_EQ(ERR_IO_PENDING, rv); |
1641 | 1641 |
1642 // The first request should have triggered download of PAC script. | 1642 // The first request should have triggered download of PAC script. |
1643 EXPECT_TRUE(fetcher->has_pending_request()); | 1643 EXPECT_TRUE(fetcher->has_pending_request()); |
1644 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1644 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1645 | 1645 |
1646 ProxyInfo info2; | 1646 ProxyInfo info2; |
1647 TestCompletionCallback callback2; | 1647 TestCompletionCallback callback2; |
1648 ProxyService::PacRequest* request2; | 1648 ProxyService::PacRequest* request2; |
1649 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1649 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1650 callback2.callback(), &request2, BoundNetLog()); | 1650 callback2.callback(), &request2, BoundNetLog()); |
1651 EXPECT_EQ(ERR_IO_PENDING, rv); | 1651 EXPECT_EQ(ERR_IO_PENDING, rv); |
1652 | 1652 |
1653 ProxyInfo info3; | 1653 ProxyInfo info3; |
1654 TestCompletionCallback callback3; | 1654 TestCompletionCallback callback3; |
1655 rv = service.ResolveProxy(GURL("http://request3"), &info3, | 1655 rv = service.ResolveProxy(GURL("http://request3"), 0, &info3, |
1656 callback3.callback(), NULL, BoundNetLog()); | 1656 callback3.callback(), NULL, BoundNetLog()); |
1657 EXPECT_EQ(ERR_IO_PENDING, rv); | 1657 EXPECT_EQ(ERR_IO_PENDING, rv); |
1658 | 1658 |
1659 // Nothing has been sent to the resolver yet. | 1659 // Nothing has been sent to the resolver yet. |
1660 EXPECT_TRUE(resolver->pending_requests().empty()); | 1660 EXPECT_TRUE(resolver->pending_requests().empty()); |
1661 | 1661 |
1662 // Cancel the first 2 requests. | 1662 // Cancel the first 2 requests. |
1663 service.CancelPacRequest(request1); | 1663 service.CancelPacRequest(request1); |
1664 service.CancelPacRequest(request2); | 1664 service.CancelPacRequest(request2); |
1665 | 1665 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1719 ProxyService service(config_service, resolver, NULL); | 1719 ProxyService service(config_service, resolver, NULL); |
1720 | 1720 |
1721 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1721 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1722 service.SetProxyScriptFetchers(fetcher, | 1722 service.SetProxyScriptFetchers(fetcher, |
1723 new DoNothingDhcpProxyScriptFetcher()); | 1723 new DoNothingDhcpProxyScriptFetcher()); |
1724 | 1724 |
1725 // Start 2 requests. | 1725 // Start 2 requests. |
1726 | 1726 |
1727 ProxyInfo info1; | 1727 ProxyInfo info1; |
1728 TestCompletionCallback callback1; | 1728 TestCompletionCallback callback1; |
1729 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1729 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1730 callback1.callback(), NULL, BoundNetLog()); | 1730 callback1.callback(), NULL, BoundNetLog()); |
1731 EXPECT_EQ(ERR_IO_PENDING, rv); | 1731 EXPECT_EQ(ERR_IO_PENDING, rv); |
1732 | 1732 |
1733 ProxyInfo info2; | 1733 ProxyInfo info2; |
1734 TestCompletionCallback callback2; | 1734 TestCompletionCallback callback2; |
1735 ProxyService::PacRequest* request2; | 1735 ProxyService::PacRequest* request2; |
1736 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1736 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1737 callback2.callback(), &request2, BoundNetLog()); | 1737 callback2.callback(), &request2, BoundNetLog()); |
1738 EXPECT_EQ(ERR_IO_PENDING, rv); | 1738 EXPECT_EQ(ERR_IO_PENDING, rv); |
1739 | 1739 |
1740 // Check that nothing has been sent to the proxy resolver yet. | 1740 // Check that nothing has been sent to the proxy resolver yet. |
1741 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1741 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1742 | 1742 |
1743 // It should be trying to auto-detect first -- FAIL the autodetect during | 1743 // It should be trying to auto-detect first -- FAIL the autodetect during |
1744 // the script download. | 1744 // the script download. |
1745 EXPECT_TRUE(fetcher->has_pending_request()); | 1745 EXPECT_TRUE(fetcher->has_pending_request()); |
1746 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1746 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 ProxyService service(config_service, resolver, NULL); | 1796 ProxyService service(config_service, resolver, NULL); |
1797 | 1797 |
1798 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1798 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1799 service.SetProxyScriptFetchers(fetcher, | 1799 service.SetProxyScriptFetchers(fetcher, |
1800 new DoNothingDhcpProxyScriptFetcher()); | 1800 new DoNothingDhcpProxyScriptFetcher()); |
1801 | 1801 |
1802 // Start 2 requests. | 1802 // Start 2 requests. |
1803 | 1803 |
1804 ProxyInfo info1; | 1804 ProxyInfo info1; |
1805 TestCompletionCallback callback1; | 1805 TestCompletionCallback callback1; |
1806 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1806 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1807 callback1.callback(), NULL, BoundNetLog()); | 1807 callback1.callback(), NULL, BoundNetLog()); |
1808 EXPECT_EQ(ERR_IO_PENDING, rv); | 1808 EXPECT_EQ(ERR_IO_PENDING, rv); |
1809 | 1809 |
1810 ProxyInfo info2; | 1810 ProxyInfo info2; |
1811 TestCompletionCallback callback2; | 1811 TestCompletionCallback callback2; |
1812 ProxyService::PacRequest* request2; | 1812 ProxyService::PacRequest* request2; |
1813 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1813 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1814 callback2.callback(), &request2, BoundNetLog()); | 1814 callback2.callback(), &request2, BoundNetLog()); |
1815 EXPECT_EQ(ERR_IO_PENDING, rv); | 1815 EXPECT_EQ(ERR_IO_PENDING, rv); |
1816 | 1816 |
1817 // Check that nothing has been sent to the proxy resolver yet. | 1817 // Check that nothing has been sent to the proxy resolver yet. |
1818 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1818 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1819 | 1819 |
1820 // It should be trying to auto-detect first -- succeed the download. | 1820 // It should be trying to auto-detect first -- succeed the download. |
1821 EXPECT_TRUE(fetcher->has_pending_request()); | 1821 EXPECT_TRUE(fetcher->has_pending_request()); |
1822 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1822 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1823 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 1823 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1869 ProxyService service(config_service, resolver, NULL); | 1869 ProxyService service(config_service, resolver, NULL); |
1870 | 1870 |
1871 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1871 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1872 service.SetProxyScriptFetchers(fetcher, | 1872 service.SetProxyScriptFetchers(fetcher, |
1873 new DoNothingDhcpProxyScriptFetcher()); | 1873 new DoNothingDhcpProxyScriptFetcher()); |
1874 | 1874 |
1875 // Start 2 requests. | 1875 // Start 2 requests. |
1876 | 1876 |
1877 ProxyInfo info1; | 1877 ProxyInfo info1; |
1878 TestCompletionCallback callback1; | 1878 TestCompletionCallback callback1; |
1879 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1879 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1880 callback1.callback(), NULL, BoundNetLog()); | 1880 callback1.callback(), NULL, BoundNetLog()); |
1881 EXPECT_EQ(ERR_IO_PENDING, rv); | 1881 EXPECT_EQ(ERR_IO_PENDING, rv); |
1882 | 1882 |
1883 ProxyInfo info2; | 1883 ProxyInfo info2; |
1884 TestCompletionCallback callback2; | 1884 TestCompletionCallback callback2; |
1885 ProxyService::PacRequest* request2; | 1885 ProxyService::PacRequest* request2; |
1886 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1886 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1887 callback2.callback(), &request2, BoundNetLog()); | 1887 callback2.callback(), &request2, BoundNetLog()); |
1888 EXPECT_EQ(ERR_IO_PENDING, rv); | 1888 EXPECT_EQ(ERR_IO_PENDING, rv); |
1889 | 1889 |
1890 // Check that nothing has been sent to the proxy resolver yet. | 1890 // Check that nothing has been sent to the proxy resolver yet. |
1891 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1891 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1892 | 1892 |
1893 // It should be trying to auto-detect first -- fail the download. | 1893 // It should be trying to auto-detect first -- fail the download. |
1894 EXPECT_TRUE(fetcher->has_pending_request()); | 1894 EXPECT_TRUE(fetcher->has_pending_request()); |
1895 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1895 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1896 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 1896 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1928 | 1928 |
1929 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1929 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1930 service.SetProxyScriptFetchers(fetcher, | 1930 service.SetProxyScriptFetchers(fetcher, |
1931 new DoNothingDhcpProxyScriptFetcher()); | 1931 new DoNothingDhcpProxyScriptFetcher()); |
1932 | 1932 |
1933 // Start 1 requests. | 1933 // Start 1 requests. |
1934 | 1934 |
1935 ProxyInfo info1; | 1935 ProxyInfo info1; |
1936 TestCompletionCallback callback1; | 1936 TestCompletionCallback callback1; |
1937 int rv = service.ResolveProxy( | 1937 int rv = service.ResolveProxy( |
1938 GURL("http://www.google.com"), &info1, callback1.callback(), NULL, | 1938 GURL("http://www.google.com"), 0, &info1, callback1.callback(), NULL, |
1939 BoundNetLog()); | 1939 BoundNetLog()); |
1940 EXPECT_EQ(ERR_IO_PENDING, rv); | 1940 EXPECT_EQ(ERR_IO_PENDING, rv); |
1941 | 1941 |
1942 // Check that nothing has been sent to the proxy resolver yet. | 1942 // Check that nothing has been sent to the proxy resolver yet. |
1943 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1943 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1944 | 1944 |
1945 // It should be trying to auto-detect first -- succeed the download. | 1945 // It should be trying to auto-detect first -- succeed the download. |
1946 EXPECT_TRUE(fetcher->has_pending_request()); | 1946 EXPECT_TRUE(fetcher->has_pending_request()); |
1947 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1947 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1948 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 1948 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
(...skipping 10 matching lines...) Expand all Loading... |
1959 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 1959 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
1960 resolver->pending_requests()[0]->CompleteNow(OK); | 1960 resolver->pending_requests()[0]->CompleteNow(OK); |
1961 | 1961 |
1962 // Verify that request ran as expected. | 1962 // Verify that request ran as expected. |
1963 EXPECT_EQ(OK, callback1.WaitForResult()); | 1963 EXPECT_EQ(OK, callback1.WaitForResult()); |
1964 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1964 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
1965 | 1965 |
1966 // Start another request, it should pickup the bypass item. | 1966 // Start another request, it should pickup the bypass item. |
1967 ProxyInfo info2; | 1967 ProxyInfo info2; |
1968 TestCompletionCallback callback2; | 1968 TestCompletionCallback callback2; |
1969 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, | 1969 rv = service.ResolveProxy(GURL("http://www.google.com"), 0, &info2, |
1970 callback2.callback(), NULL, BoundNetLog()); | 1970 callback2.callback(), NULL, BoundNetLog()); |
1971 EXPECT_EQ(ERR_IO_PENDING, rv); | 1971 EXPECT_EQ(ERR_IO_PENDING, rv); |
1972 | 1972 |
1973 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1973 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1974 EXPECT_EQ(GURL("http://www.google.com"), | 1974 EXPECT_EQ(GURL("http://www.google.com"), |
1975 resolver->pending_requests()[0]->url()); | 1975 resolver->pending_requests()[0]->url()); |
1976 | 1976 |
1977 // Complete the pending request. | 1977 // Complete the pending request. |
1978 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 1978 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
1979 resolver->pending_requests()[0]->CompleteNow(OK); | 1979 resolver->pending_requests()[0]->CompleteNow(OK); |
(...skipping 16 matching lines...) Expand all Loading... |
1996 ProxyService service(config_service, resolver, NULL); | 1996 ProxyService service(config_service, resolver, NULL); |
1997 | 1997 |
1998 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1998 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1999 service.SetProxyScriptFetchers(fetcher, | 1999 service.SetProxyScriptFetchers(fetcher, |
2000 new DoNothingDhcpProxyScriptFetcher()); | 2000 new DoNothingDhcpProxyScriptFetcher()); |
2001 | 2001 |
2002 // Start 1 request. | 2002 // Start 1 request. |
2003 | 2003 |
2004 ProxyInfo info1; | 2004 ProxyInfo info1; |
2005 TestCompletionCallback callback1; | 2005 TestCompletionCallback callback1; |
2006 int rv = service.ResolveProxy(GURL("http://www.google.com"), &info1, | 2006 int rv = service.ResolveProxy(GURL("http://www.google.com"), 0, &info1, |
2007 callback1.callback(), NULL, BoundNetLog()); | 2007 callback1.callback(), NULL, BoundNetLog()); |
2008 EXPECT_EQ(ERR_IO_PENDING, rv); | 2008 EXPECT_EQ(ERR_IO_PENDING, rv); |
2009 | 2009 |
2010 // Check that nothing has been sent to the proxy resolver yet. | 2010 // Check that nothing has been sent to the proxy resolver yet. |
2011 ASSERT_EQ(0u, resolver->pending_requests().size()); | 2011 ASSERT_EQ(0u, resolver->pending_requests().size()); |
2012 | 2012 |
2013 // InitProxyResolver should have issued a request to the ProxyScriptFetcher | 2013 // InitProxyResolver should have issued a request to the ProxyScriptFetcher |
2014 // and be waiting on that to complete. | 2014 // and be waiting on that to complete. |
2015 EXPECT_TRUE(fetcher->has_pending_request()); | 2015 EXPECT_TRUE(fetcher->has_pending_request()); |
2016 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2016 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2017 } | 2017 } |
2018 | 2018 |
2019 // Delete the ProxyService while InitProxyResolver has an outstanding | 2019 // Delete the ProxyService while InitProxyResolver has an outstanding |
2020 // request to the proxy resolver. When run under valgrind, should not | 2020 // request to the proxy resolver. When run under valgrind, should not |
2021 // have any memory errors (used to be that the ProxyResolver was | 2021 // have any memory errors (used to be that the ProxyResolver was |
2022 // being deleted prior to the InitProxyResolver). | 2022 // being deleted prior to the InitProxyResolver). |
2023 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { | 2023 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { |
2024 MockProxyConfigService* config_service = | 2024 MockProxyConfigService* config_service = |
2025 new MockProxyConfigService("http://foopy/proxy.pac"); | 2025 new MockProxyConfigService("http://foopy/proxy.pac"); |
2026 | 2026 |
2027 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 2027 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
2028 | 2028 |
2029 ProxyService service(config_service, resolver, NULL); | 2029 ProxyService service(config_service, resolver, NULL); |
2030 | 2030 |
2031 GURL url("http://www.google.com/"); | 2031 GURL url("http://www.google.com/"); |
2032 | 2032 |
2033 ProxyInfo info; | 2033 ProxyInfo info; |
2034 TestCompletionCallback callback; | 2034 TestCompletionCallback callback; |
2035 int rv = service.ResolveProxy( | 2035 int rv = service.ResolveProxy( |
2036 url, &info, callback.callback(), NULL, BoundNetLog()); | 2036 url, 0, &info, callback.callback(), NULL, BoundNetLog()); |
2037 EXPECT_EQ(ERR_IO_PENDING, rv); | 2037 EXPECT_EQ(ERR_IO_PENDING, rv); |
2038 | 2038 |
2039 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 2039 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
2040 resolver->pending_set_pac_script_request()->script_data()->url()); | 2040 resolver->pending_set_pac_script_request()->script_data()->url()); |
2041 } | 2041 } |
2042 | 2042 |
2043 TEST_F(ProxyServiceTest, ResetProxyConfigService) { | 2043 TEST_F(ProxyServiceTest, ResetProxyConfigService) { |
2044 ProxyConfig config1; | 2044 ProxyConfig config1; |
2045 config1.proxy_rules().ParseFromString("foopy1:8080"); | 2045 config1.proxy_rules().ParseFromString("foopy1:8080"); |
2046 config1.set_auto_detect(false); | 2046 config1.set_auto_detect(false); |
2047 ProxyService service( | 2047 ProxyService service( |
2048 new MockProxyConfigService(config1), | 2048 new MockProxyConfigService(config1), |
2049 new MockAsyncProxyResolverExpectsBytes, NULL); | 2049 new MockAsyncProxyResolverExpectsBytes, NULL); |
2050 | 2050 |
2051 ProxyInfo info; | 2051 ProxyInfo info; |
2052 TestCompletionCallback callback1; | 2052 TestCompletionCallback callback1; |
2053 int rv = service.ResolveProxy(GURL("http://request1"), &info, | 2053 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info, |
2054 callback1.callback(), NULL, BoundNetLog()); | 2054 callback1.callback(), NULL, BoundNetLog()); |
2055 EXPECT_EQ(OK, rv); | 2055 EXPECT_EQ(OK, rv); |
2056 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 2056 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
2057 | 2057 |
2058 ProxyConfig config2; | 2058 ProxyConfig config2; |
2059 config2.proxy_rules().ParseFromString("foopy2:8080"); | 2059 config2.proxy_rules().ParseFromString("foopy2:8080"); |
2060 config2.set_auto_detect(false); | 2060 config2.set_auto_detect(false); |
2061 service.ResetConfigService(new MockProxyConfigService(config2)); | 2061 service.ResetConfigService(new MockProxyConfigService(config2)); |
2062 TestCompletionCallback callback2; | 2062 TestCompletionCallback callback2; |
2063 rv = service.ResolveProxy(GURL("http://request2"), &info, | 2063 rv = service.ResolveProxy(GURL("http://request2"), 0, &info, |
2064 callback2.callback(), NULL, BoundNetLog()); | 2064 callback2.callback(), NULL, BoundNetLog()); |
2065 EXPECT_EQ(OK, rv); | 2065 EXPECT_EQ(OK, rv); |
2066 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 2066 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
2067 } | 2067 } |
2068 | 2068 |
2069 // Test that when going from a configuration that required PAC to one | 2069 // Test that when going from a configuration that required PAC to one |
2070 // that does NOT, we unset the variable |should_use_proxy_resolver_|. | 2070 // that does NOT, we unset the variable |should_use_proxy_resolver_|. |
2071 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { | 2071 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { |
2072 ProxyConfig config = ProxyConfig::CreateAutoDetect(); | 2072 ProxyConfig config = ProxyConfig::CreateAutoDetect(); |
2073 | 2073 |
2074 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2074 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
2075 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 2075 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
2076 ProxyService service(config_service, resolver, NULL); | 2076 ProxyService service(config_service, resolver, NULL); |
2077 | 2077 |
2078 // Start 1 request. | 2078 // Start 1 request. |
2079 | 2079 |
2080 ProxyInfo info1; | 2080 ProxyInfo info1; |
2081 TestCompletionCallback callback1; | 2081 TestCompletionCallback callback1; |
2082 int rv = service.ResolveProxy(GURL("http://www.google.com"), &info1, | 2082 int rv = service.ResolveProxy(GURL("http://www.google.com"), 0, &info1, |
2083 callback1.callback(), NULL, BoundNetLog()); | 2083 callback1.callback(), NULL, BoundNetLog()); |
2084 EXPECT_EQ(ERR_IO_PENDING, rv); | 2084 EXPECT_EQ(ERR_IO_PENDING, rv); |
2085 | 2085 |
2086 // Check that nothing has been sent to the proxy resolver yet. | 2086 // Check that nothing has been sent to the proxy resolver yet. |
2087 ASSERT_EQ(0u, resolver->pending_requests().size()); | 2087 ASSERT_EQ(0u, resolver->pending_requests().size()); |
2088 | 2088 |
2089 // Successfully set the autodetect script. | 2089 // Successfully set the autodetect script. |
2090 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, | 2090 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, |
2091 resolver->pending_set_pac_script_request()->script_data()->type()); | 2091 resolver->pending_set_pac_script_request()->script_data()->type()); |
2092 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 2092 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
(...skipping 10 matching lines...) Expand all Loading... |
2103 // Force the ProxyService to pull down a new proxy configuration. | 2103 // Force the ProxyService to pull down a new proxy configuration. |
2104 // (Even though the configuration isn't old/bad). | 2104 // (Even though the configuration isn't old/bad). |
2105 // | 2105 // |
2106 // This new configuration no longer has auto_detect set, so | 2106 // This new configuration no longer has auto_detect set, so |
2107 // requests should complete synchronously now as direct-connect. | 2107 // requests should complete synchronously now as direct-connect. |
2108 config_service->SetConfig(ProxyConfig::CreateDirect()); | 2108 config_service->SetConfig(ProxyConfig::CreateDirect()); |
2109 | 2109 |
2110 // Start another request -- the effective configuration has changed. | 2110 // Start another request -- the effective configuration has changed. |
2111 ProxyInfo info2; | 2111 ProxyInfo info2; |
2112 TestCompletionCallback callback2; | 2112 TestCompletionCallback callback2; |
2113 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, | 2113 rv = service.ResolveProxy(GURL("http://www.google.com"), 0, &info2, |
2114 callback2.callback(), NULL, BoundNetLog()); | 2114 callback2.callback(), NULL, BoundNetLog()); |
2115 EXPECT_EQ(OK, rv); | 2115 EXPECT_EQ(OK, rv); |
2116 | 2116 |
2117 EXPECT_TRUE(info2.is_direct()); | 2117 EXPECT_TRUE(info2.is_direct()); |
2118 } | 2118 } |
2119 | 2119 |
2120 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { | 2120 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { |
2121 MockProxyConfigService* config_service = | 2121 MockProxyConfigService* config_service = |
2122 new MockProxyConfigService("http://foopy/proxy.pac"); | 2122 new MockProxyConfigService("http://foopy/proxy.pac"); |
2123 | 2123 |
2124 MockAsyncProxyResolverExpectsBytes* resolver = | 2124 MockAsyncProxyResolverExpectsBytes* resolver = |
2125 new MockAsyncProxyResolverExpectsBytes; | 2125 new MockAsyncProxyResolverExpectsBytes; |
2126 | 2126 |
2127 CapturingNetLog log; | 2127 CapturingNetLog log; |
2128 | 2128 |
2129 ProxyService service(config_service, resolver, &log); | 2129 ProxyService service(config_service, resolver, &log); |
2130 | 2130 |
2131 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2131 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2132 service.SetProxyScriptFetchers(fetcher, | 2132 service.SetProxyScriptFetchers(fetcher, |
2133 new DoNothingDhcpProxyScriptFetcher()); | 2133 new DoNothingDhcpProxyScriptFetcher()); |
2134 | 2134 |
2135 // Disable the "wait after IP address changes" hack, so this unit-test can | 2135 // Disable the "wait after IP address changes" hack, so this unit-test can |
2136 // complete quickly. | 2136 // complete quickly. |
2137 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); | 2137 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); |
2138 | 2138 |
2139 // Start 1 request. | 2139 // Start 1 request. |
2140 | 2140 |
2141 ProxyInfo info1; | 2141 ProxyInfo info1; |
2142 TestCompletionCallback callback1; | 2142 TestCompletionCallback callback1; |
2143 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 2143 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
2144 callback1.callback(), NULL, BoundNetLog()); | 2144 callback1.callback(), NULL, BoundNetLog()); |
2145 EXPECT_EQ(ERR_IO_PENDING, rv); | 2145 EXPECT_EQ(ERR_IO_PENDING, rv); |
2146 | 2146 |
2147 // The first request should have triggered initial download of PAC script. | 2147 // The first request should have triggered initial download of PAC script. |
2148 EXPECT_TRUE(fetcher->has_pending_request()); | 2148 EXPECT_TRUE(fetcher->has_pending_request()); |
2149 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2149 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2150 | 2150 |
2151 // Nothing has been sent to the resolver yet. | 2151 // Nothing has been sent to the resolver yet. |
2152 EXPECT_TRUE(resolver->pending_requests().empty()); | 2152 EXPECT_TRUE(resolver->pending_requests().empty()); |
2153 | 2153 |
(...skipping 21 matching lines...) Expand all Loading... |
2175 | 2175 |
2176 // Now simluate a change in the network. The ProxyConfigService is still | 2176 // Now simluate a change in the network. The ProxyConfigService is still |
2177 // going to return the same PAC URL as before, but this URL needs to be | 2177 // going to return the same PAC URL as before, but this URL needs to be |
2178 // refetched on the new network. | 2178 // refetched on the new network. |
2179 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 2179 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
2180 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 2180 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. |
2181 | 2181 |
2182 // Start a second request. | 2182 // Start a second request. |
2183 ProxyInfo info2; | 2183 ProxyInfo info2; |
2184 TestCompletionCallback callback2; | 2184 TestCompletionCallback callback2; |
2185 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 2185 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
2186 callback2.callback(), NULL, BoundNetLog()); | 2186 callback2.callback(), NULL, BoundNetLog()); |
2187 EXPECT_EQ(ERR_IO_PENDING, rv); | 2187 EXPECT_EQ(ERR_IO_PENDING, rv); |
2188 | 2188 |
2189 // This second request should have triggered the re-download of the PAC | 2189 // This second request should have triggered the re-download of the PAC |
2190 // script (since we marked the network as having changed). | 2190 // script (since we marked the network as having changed). |
2191 EXPECT_TRUE(fetcher->has_pending_request()); | 2191 EXPECT_TRUE(fetcher->has_pending_request()); |
2192 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2192 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2193 | 2193 |
2194 // Nothing has been sent to the resolver yet. | 2194 // Nothing has been sent to the resolver yet. |
2195 EXPECT_TRUE(resolver->pending_requests().empty()); | 2195 EXPECT_TRUE(resolver->pending_requests().empty()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2248 | 2248 |
2249 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2249 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2250 service.SetProxyScriptFetchers(fetcher, | 2250 service.SetProxyScriptFetchers(fetcher, |
2251 new DoNothingDhcpProxyScriptFetcher()); | 2251 new DoNothingDhcpProxyScriptFetcher()); |
2252 | 2252 |
2253 // Start 1 request. | 2253 // Start 1 request. |
2254 | 2254 |
2255 ProxyInfo info1; | 2255 ProxyInfo info1; |
2256 TestCompletionCallback callback1; | 2256 TestCompletionCallback callback1; |
2257 int rv = service.ResolveProxy( | 2257 int rv = service.ResolveProxy( |
2258 GURL("http://request1"), &info1, callback1.callback(), | 2258 GURL("http://request1"), 0, &info1, callback1.callback(), |
2259 NULL, BoundNetLog()); | 2259 NULL, BoundNetLog()); |
2260 EXPECT_EQ(ERR_IO_PENDING, rv); | 2260 EXPECT_EQ(ERR_IO_PENDING, rv); |
2261 | 2261 |
2262 // The first request should have triggered initial download of PAC script. | 2262 // The first request should have triggered initial download of PAC script. |
2263 EXPECT_TRUE(fetcher->has_pending_request()); | 2263 EXPECT_TRUE(fetcher->has_pending_request()); |
2264 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2264 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2265 | 2265 |
2266 // Nothing has been sent to the resolver yet. | 2266 // Nothing has been sent to the resolver yet. |
2267 EXPECT_TRUE(resolver->pending_requests().empty()); | 2267 EXPECT_TRUE(resolver->pending_requests().empty()); |
2268 | 2268 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2309 | 2309 |
2310 // At this point the ProxyService should have re-configured itself to use the | 2310 // At this point the ProxyService should have re-configured itself to use the |
2311 // PAC script (thereby recovering from the initial fetch failure). We will | 2311 // PAC script (thereby recovering from the initial fetch failure). We will |
2312 // verify that the next Resolve request uses the resolver rather than | 2312 // verify that the next Resolve request uses the resolver rather than |
2313 // DIRECT. | 2313 // DIRECT. |
2314 | 2314 |
2315 // Start a second request. | 2315 // Start a second request. |
2316 ProxyInfo info2; | 2316 ProxyInfo info2; |
2317 TestCompletionCallback callback2; | 2317 TestCompletionCallback callback2; |
2318 rv = service.ResolveProxy( | 2318 rv = service.ResolveProxy( |
2319 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2319 GURL("http://request2"), 0, &info2, callback2.callback(), NULL, |
2320 BoundNetLog()); | 2320 BoundNetLog()); |
2321 EXPECT_EQ(ERR_IO_PENDING, rv); | 2321 EXPECT_EQ(ERR_IO_PENDING, rv); |
2322 | 2322 |
2323 // Check that it was sent to the resolver. | 2323 // Check that it was sent to the resolver. |
2324 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2324 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2325 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2325 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2326 | 2326 |
2327 // Complete the pending second request. | 2327 // Complete the pending second request. |
2328 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2328 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2329 resolver->pending_requests()[0]->CompleteNow(OK); | 2329 resolver->pending_requests()[0]->CompleteNow(OK); |
(...skipping 23 matching lines...) Expand all Loading... |
2353 | 2353 |
2354 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2354 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2355 service.SetProxyScriptFetchers(fetcher, | 2355 service.SetProxyScriptFetchers(fetcher, |
2356 new DoNothingDhcpProxyScriptFetcher()); | 2356 new DoNothingDhcpProxyScriptFetcher()); |
2357 | 2357 |
2358 // Start 1 request. | 2358 // Start 1 request. |
2359 | 2359 |
2360 ProxyInfo info1; | 2360 ProxyInfo info1; |
2361 TestCompletionCallback callback1; | 2361 TestCompletionCallback callback1; |
2362 int rv = service.ResolveProxy( | 2362 int rv = service.ResolveProxy( |
2363 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2363 GURL("http://request1"), 0, &info1, callback1.callback(), NULL, |
2364 BoundNetLog()); | 2364 BoundNetLog()); |
2365 EXPECT_EQ(ERR_IO_PENDING, rv); | 2365 EXPECT_EQ(ERR_IO_PENDING, rv); |
2366 | 2366 |
2367 // The first request should have triggered initial download of PAC script. | 2367 // The first request should have triggered initial download of PAC script. |
2368 EXPECT_TRUE(fetcher->has_pending_request()); | 2368 EXPECT_TRUE(fetcher->has_pending_request()); |
2369 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2369 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2370 | 2370 |
2371 // Nothing has been sent to the resolver yet. | 2371 // Nothing has been sent to the resolver yet. |
2372 EXPECT_TRUE(resolver->pending_requests().empty()); | 2372 EXPECT_TRUE(resolver->pending_requests().empty()); |
2373 | 2373 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2419 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 2419 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
2420 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 2420 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
2421 | 2421 |
2422 // At this point the ProxyService should have re-configured itself to use the | 2422 // At this point the ProxyService should have re-configured itself to use the |
2423 // new PAC script. | 2423 // new PAC script. |
2424 | 2424 |
2425 // Start a second request. | 2425 // Start a second request. |
2426 ProxyInfo info2; | 2426 ProxyInfo info2; |
2427 TestCompletionCallback callback2; | 2427 TestCompletionCallback callback2; |
2428 rv = service.ResolveProxy( | 2428 rv = service.ResolveProxy( |
2429 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2429 GURL("http://request2"), 0, &info2, callback2.callback(), NULL, |
2430 BoundNetLog()); | 2430 BoundNetLog()); |
2431 EXPECT_EQ(ERR_IO_PENDING, rv); | 2431 EXPECT_EQ(ERR_IO_PENDING, rv); |
2432 | 2432 |
2433 // Check that it was sent to the resolver. | 2433 // Check that it was sent to the resolver. |
2434 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2434 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2435 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2435 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2436 | 2436 |
2437 // Complete the pending second request. | 2437 // Complete the pending second request. |
2438 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2438 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2439 resolver->pending_requests()[0]->CompleteNow(OK); | 2439 resolver->pending_requests()[0]->CompleteNow(OK); |
(...skipping 23 matching lines...) Expand all Loading... |
2463 | 2463 |
2464 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2464 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2465 service.SetProxyScriptFetchers(fetcher, | 2465 service.SetProxyScriptFetchers(fetcher, |
2466 new DoNothingDhcpProxyScriptFetcher()); | 2466 new DoNothingDhcpProxyScriptFetcher()); |
2467 | 2467 |
2468 // Start 1 request. | 2468 // Start 1 request. |
2469 | 2469 |
2470 ProxyInfo info1; | 2470 ProxyInfo info1; |
2471 TestCompletionCallback callback1; | 2471 TestCompletionCallback callback1; |
2472 int rv = service.ResolveProxy( | 2472 int rv = service.ResolveProxy( |
2473 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2473 GURL("http://request1"), 0, &info1, callback1.callback(), NULL, |
2474 BoundNetLog()); | 2474 BoundNetLog()); |
2475 EXPECT_EQ(ERR_IO_PENDING, rv); | 2475 EXPECT_EQ(ERR_IO_PENDING, rv); |
2476 | 2476 |
2477 // The first request should have triggered initial download of PAC script. | 2477 // The first request should have triggered initial download of PAC script. |
2478 EXPECT_TRUE(fetcher->has_pending_request()); | 2478 EXPECT_TRUE(fetcher->has_pending_request()); |
2479 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2479 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2480 | 2480 |
2481 // Nothing has been sent to the resolver yet. | 2481 // Nothing has been sent to the resolver yet. |
2482 EXPECT_TRUE(resolver->pending_requests().empty()); | 2482 EXPECT_TRUE(resolver->pending_requests().empty()); |
2483 | 2483 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2525 | 2525 |
2526 ASSERT_FALSE(resolver->has_pending_set_pac_script_request()); | 2526 ASSERT_FALSE(resolver->has_pending_set_pac_script_request()); |
2527 | 2527 |
2528 // At this point the ProxyService is still running the same PAC script as | 2528 // At this point the ProxyService is still running the same PAC script as |
2529 // before. | 2529 // before. |
2530 | 2530 |
2531 // Start a second request. | 2531 // Start a second request. |
2532 ProxyInfo info2; | 2532 ProxyInfo info2; |
2533 TestCompletionCallback callback2; | 2533 TestCompletionCallback callback2; |
2534 rv = service.ResolveProxy( | 2534 rv = service.ResolveProxy( |
2535 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2535 GURL("http://request2"), 0, &info2, callback2.callback(), NULL, |
2536 BoundNetLog()); | 2536 BoundNetLog()); |
2537 EXPECT_EQ(ERR_IO_PENDING, rv); | 2537 EXPECT_EQ(ERR_IO_PENDING, rv); |
2538 | 2538 |
2539 // Check that it was sent to the resolver. | 2539 // Check that it was sent to the resolver. |
2540 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2540 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2541 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2541 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2542 | 2542 |
2543 // Complete the pending second request. | 2543 // Complete the pending second request. |
2544 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2544 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2545 resolver->pending_requests()[0]->CompleteNow(OK); | 2545 resolver->pending_requests()[0]->CompleteNow(OK); |
(...skipping 23 matching lines...) Expand all Loading... |
2569 | 2569 |
2570 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2570 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2571 service.SetProxyScriptFetchers(fetcher, | 2571 service.SetProxyScriptFetchers(fetcher, |
2572 new DoNothingDhcpProxyScriptFetcher()); | 2572 new DoNothingDhcpProxyScriptFetcher()); |
2573 | 2573 |
2574 // Start 1 request. | 2574 // Start 1 request. |
2575 | 2575 |
2576 ProxyInfo info1; | 2576 ProxyInfo info1; |
2577 TestCompletionCallback callback1; | 2577 TestCompletionCallback callback1; |
2578 int rv = service.ResolveProxy( | 2578 int rv = service.ResolveProxy( |
2579 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2579 GURL("http://request1"), 0, &info1, callback1.callback(), NULL, |
2580 BoundNetLog()); | 2580 BoundNetLog()); |
2581 EXPECT_EQ(ERR_IO_PENDING, rv); | 2581 EXPECT_EQ(ERR_IO_PENDING, rv); |
2582 | 2582 |
2583 // The first request should have triggered initial download of PAC script. | 2583 // The first request should have triggered initial download of PAC script. |
2584 EXPECT_TRUE(fetcher->has_pending_request()); | 2584 EXPECT_TRUE(fetcher->has_pending_request()); |
2585 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2585 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2586 | 2586 |
2587 // Nothing has been sent to the resolver yet. | 2587 // Nothing has been sent to the resolver yet. |
2588 EXPECT_TRUE(resolver->pending_requests().empty()); | 2588 EXPECT_TRUE(resolver->pending_requests().empty()); |
2589 | 2589 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2629 | 2629 |
2630 base::MessageLoop::current()->RunUntilIdle(); | 2630 base::MessageLoop::current()->RunUntilIdle(); |
2631 | 2631 |
2632 // At this point the ProxyService should have re-configured itself to use | 2632 // At this point the ProxyService should have re-configured itself to use |
2633 // DIRECT connections rather than the given proxy resolver. | 2633 // DIRECT connections rather than the given proxy resolver. |
2634 | 2634 |
2635 // Start a second request. | 2635 // Start a second request. |
2636 ProxyInfo info2; | 2636 ProxyInfo info2; |
2637 TestCompletionCallback callback2; | 2637 TestCompletionCallback callback2; |
2638 rv = service.ResolveProxy( | 2638 rv = service.ResolveProxy( |
2639 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2639 GURL("http://request2"), 0, &info2, callback2.callback(), NULL, |
2640 BoundNetLog()); | 2640 BoundNetLog()); |
2641 EXPECT_EQ(OK, rv); | 2641 EXPECT_EQ(OK, rv); |
2642 EXPECT_TRUE(info2.is_direct()); | 2642 EXPECT_TRUE(info2.is_direct()); |
2643 } | 2643 } |
2644 | 2644 |
2645 // Tests that the code which decides at what times to poll the PAC | 2645 // Tests that the code which decides at what times to poll the PAC |
2646 // script follows the expected policy. | 2646 // script follows the expected policy. |
2647 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { | 2647 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { |
2648 // Retrieve the internal polling policy implementation used by ProxyService. | 2648 // Retrieve the internal polling policy implementation used by ProxyService. |
2649 scoped_ptr<ProxyService::PacPollPolicy> policy = | 2649 scoped_ptr<ProxyService::PacPollPolicy> policy = |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2721 | 2721 |
2722 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2722 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2723 service.SetProxyScriptFetchers(fetcher, | 2723 service.SetProxyScriptFetchers(fetcher, |
2724 new DoNothingDhcpProxyScriptFetcher()); | 2724 new DoNothingDhcpProxyScriptFetcher()); |
2725 | 2725 |
2726 // Start 1 request. | 2726 // Start 1 request. |
2727 | 2727 |
2728 ProxyInfo info1; | 2728 ProxyInfo info1; |
2729 TestCompletionCallback callback1; | 2729 TestCompletionCallback callback1; |
2730 int rv = service.ResolveProxy( | 2730 int rv = service.ResolveProxy( |
2731 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2731 GURL("http://request1"), 0, &info1, callback1.callback(), NULL, |
2732 BoundNetLog()); | 2732 BoundNetLog()); |
2733 EXPECT_EQ(ERR_IO_PENDING, rv); | 2733 EXPECT_EQ(ERR_IO_PENDING, rv); |
2734 | 2734 |
2735 // The first request should have triggered initial download of PAC script. | 2735 // The first request should have triggered initial download of PAC script. |
2736 EXPECT_TRUE(fetcher->has_pending_request()); | 2736 EXPECT_TRUE(fetcher->has_pending_request()); |
2737 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2737 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2738 | 2738 |
2739 // Nothing has been sent to the resolver yet. | 2739 // Nothing has been sent to the resolver yet. |
2740 EXPECT_TRUE(resolver->pending_requests().empty()); | 2740 EXPECT_TRUE(resolver->pending_requests().empty()); |
2741 | 2741 |
(...skipping 23 matching lines...) Expand all Loading... |
2765 // Our PAC poller is set to update ONLY in response to network activity, | 2765 // Our PAC poller is set to update ONLY in response to network activity, |
2766 // (i.e. another call to ResolveProxy()). | 2766 // (i.e. another call to ResolveProxy()). |
2767 | 2767 |
2768 ASSERT_FALSE(fetcher->has_pending_request()); | 2768 ASSERT_FALSE(fetcher->has_pending_request()); |
2769 ASSERT_TRUE(resolver->pending_requests().empty()); | 2769 ASSERT_TRUE(resolver->pending_requests().empty()); |
2770 | 2770 |
2771 // Start a second request. | 2771 // Start a second request. |
2772 ProxyInfo info2; | 2772 ProxyInfo info2; |
2773 TestCompletionCallback callback2; | 2773 TestCompletionCallback callback2; |
2774 rv = service.ResolveProxy( | 2774 rv = service.ResolveProxy( |
2775 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2775 GURL("http://request2"), 0, &info2, callback2.callback(), NULL, |
2776 BoundNetLog()); | 2776 BoundNetLog()); |
2777 EXPECT_EQ(ERR_IO_PENDING, rv); | 2777 EXPECT_EQ(ERR_IO_PENDING, rv); |
2778 | 2778 |
2779 // This request should have sent work to the resolver; complete it. | 2779 // This request should have sent work to the resolver; complete it. |
2780 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2780 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2781 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2781 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2782 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2782 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2783 resolver->pending_requests()[0]->CompleteNow(OK); | 2783 resolver->pending_requests()[0]->CompleteNow(OK); |
2784 | 2784 |
2785 EXPECT_EQ(OK, callback2.WaitForResult()); | 2785 EXPECT_EQ(OK, callback2.WaitForResult()); |
(...skipping 10 matching lines...) Expand all Loading... |
2796 | 2796 |
2797 // Drain the message loop, so ProxyService is notified of the change | 2797 // Drain the message loop, so ProxyService is notified of the change |
2798 // and has a chance to re-configure itself. | 2798 // and has a chance to re-configure itself. |
2799 base::MessageLoop::current()->RunUntilIdle(); | 2799 base::MessageLoop::current()->RunUntilIdle(); |
2800 | 2800 |
2801 // Start a third request -- this time we expect to get a direct connection | 2801 // Start a third request -- this time we expect to get a direct connection |
2802 // since the PAC script poller experienced a failure. | 2802 // since the PAC script poller experienced a failure. |
2803 ProxyInfo info3; | 2803 ProxyInfo info3; |
2804 TestCompletionCallback callback3; | 2804 TestCompletionCallback callback3; |
2805 rv = service.ResolveProxy( | 2805 rv = service.ResolveProxy( |
2806 GURL("http://request3"), &info3, callback3.callback(), NULL, | 2806 GURL("http://request3"), 0, &info3, callback3.callback(), NULL, |
2807 BoundNetLog()); | 2807 BoundNetLog()); |
2808 EXPECT_EQ(OK, rv); | 2808 EXPECT_EQ(OK, rv); |
2809 EXPECT_TRUE(info3.is_direct()); | 2809 EXPECT_TRUE(info3.is_direct()); |
2810 } | 2810 } |
2811 | 2811 |
2812 } // namespace net | 2812 } // namespace net |
OLD | NEW |