| 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 <cstdarg> | 7 #include <cstdarg> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "net/base/load_flags.h" | |
| 19 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 20 #include "net/base/proxy_delegate.h" | 19 #include "net/base/proxy_delegate.h" |
| 21 #include "net/base/test_completion_callback.h" | 20 #include "net/base/test_completion_callback.h" |
| 22 #include "net/log/net_log.h" | 21 #include "net/log/net_log.h" |
| 23 #include "net/log/test_net_log.h" | 22 #include "net/log/test_net_log.h" |
| 24 #include "net/log/test_net_log_entry.h" | 23 #include "net/log/test_net_log_entry.h" |
| 25 #include "net/log/test_net_log_util.h" | 24 #include "net/log/test_net_log_util.h" |
| 26 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 25 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
| 27 #include "net/proxy/mock_proxy_resolver.h" | 26 #include "net/proxy/mock_proxy_resolver.h" |
| 28 #include "net/proxy/mock_proxy_script_fetcher.h" | 27 #include "net/proxy/mock_proxy_script_fetcher.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 class TestResolveProxyDelegate : public ProxyDelegate { | 172 class TestResolveProxyDelegate : public ProxyDelegate { |
| 174 public: | 173 public: |
| 175 TestResolveProxyDelegate() | 174 TestResolveProxyDelegate() |
| 176 : on_resolve_proxy_called_(false), | 175 : on_resolve_proxy_called_(false), |
| 177 add_proxy_(false), | 176 add_proxy_(false), |
| 178 remove_proxy_(false), | 177 remove_proxy_(false), |
| 179 proxy_service_(nullptr) {} | 178 proxy_service_(nullptr) {} |
| 180 | 179 |
| 181 void OnResolveProxy(const GURL& url, | 180 void OnResolveProxy(const GURL& url, |
| 182 const std::string& method, | 181 const std::string& method, |
| 183 int load_flags, | |
| 184 const ProxyService& proxy_service, | 182 const ProxyService& proxy_service, |
| 185 ProxyInfo* result) override { | 183 ProxyInfo* result) override { |
| 186 method_ = method; | 184 method_ = method; |
| 187 on_resolve_proxy_called_ = true; | 185 on_resolve_proxy_called_ = true; |
| 188 proxy_service_ = &proxy_service; | 186 proxy_service_ = &proxy_service; |
| 189 DCHECK(!add_proxy_ || !remove_proxy_); | 187 DCHECK(!add_proxy_ || !remove_proxy_); |
| 190 if (add_proxy_) { | 188 if (add_proxy_) { |
| 191 result->UseNamedProxy("delegate_proxy.com"); | 189 result->UseNamedProxy("delegate_proxy.com"); |
| 192 } else if (remove_proxy_) { | 190 } else if (remove_proxy_) { |
| 193 result->UseDirect(); | 191 result->UseDirect(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 234 |
| 237 // A test network delegate that exercises the OnProxyFallback callback. | 235 // A test network delegate that exercises the OnProxyFallback callback. |
| 238 class TestProxyFallbackProxyDelegate : public ProxyDelegate { | 236 class TestProxyFallbackProxyDelegate : public ProxyDelegate { |
| 239 public: | 237 public: |
| 240 TestProxyFallbackProxyDelegate() | 238 TestProxyFallbackProxyDelegate() |
| 241 : on_proxy_fallback_called_(false), proxy_fallback_net_error_(OK) {} | 239 : on_proxy_fallback_called_(false), proxy_fallback_net_error_(OK) {} |
| 242 | 240 |
| 243 // ProxyDelegate implementation: | 241 // ProxyDelegate implementation: |
| 244 void OnResolveProxy(const GURL& url, | 242 void OnResolveProxy(const GURL& url, |
| 245 const std::string& method, | 243 const std::string& method, |
| 246 int load_flags, | |
| 247 const ProxyService& proxy_service, | 244 const ProxyService& proxy_service, |
| 248 ProxyInfo* result) override {} | 245 ProxyInfo* result) override {} |
| 249 void OnTunnelConnectCompleted(const HostPortPair& endpoint, | 246 void OnTunnelConnectCompleted(const HostPortPair& endpoint, |
| 250 const HostPortPair& proxy_server, | 247 const HostPortPair& proxy_server, |
| 251 int net_error) override {} | 248 int net_error) override {} |
| 252 void OnFallback(const ProxyServer& bad_proxy, int net_error) override { | 249 void OnFallback(const ProxyServer& bad_proxy, int net_error) override { |
| 253 proxy_server_ = bad_proxy; | 250 proxy_server_ = bad_proxy; |
| 254 proxy_fallback_net_error_ = net_error; | 251 proxy_fallback_net_error_ = net_error; |
| 255 on_proxy_fallback_called_ = true; | 252 on_proxy_fallback_called_ = true; |
| 256 } | 253 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 new MockAsyncProxyResolverFactory(false); | 352 new MockAsyncProxyResolverFactory(false); |
| 356 ProxyService service( | 353 ProxyService service( |
| 357 base::WrapUnique(new MockProxyConfigService(ProxyConfig::CreateDirect())), | 354 base::WrapUnique(new MockProxyConfigService(ProxyConfig::CreateDirect())), |
| 358 base::WrapUnique(factory), nullptr); | 355 base::WrapUnique(factory), nullptr); |
| 359 | 356 |
| 360 GURL url("http://www.google.com/"); | 357 GURL url("http://www.google.com/"); |
| 361 | 358 |
| 362 ProxyInfo info; | 359 ProxyInfo info; |
| 363 TestCompletionCallback callback; | 360 TestCompletionCallback callback; |
| 364 BoundTestNetLog log; | 361 BoundTestNetLog log; |
| 365 int rv = | 362 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
| 366 service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 363 nullptr, nullptr, log.bound()); |
| 367 callback.callback(), nullptr, nullptr, log.bound()); | |
| 368 EXPECT_THAT(rv, IsOk()); | 364 EXPECT_THAT(rv, IsOk()); |
| 369 EXPECT_TRUE(factory->pending_requests().empty()); | 365 EXPECT_TRUE(factory->pending_requests().empty()); |
| 370 | 366 |
| 371 EXPECT_TRUE(info.is_direct()); | 367 EXPECT_TRUE(info.is_direct()); |
| 372 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); | 368 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); |
| 373 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); | 369 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); |
| 374 | 370 |
| 375 // Check the NetLog was filled correctly. | 371 // Check the NetLog was filled correctly. |
| 376 TestNetLogEntry::List entries; | 372 TestNetLogEntry::List entries; |
| 377 log.GetEntries(&entries); | 373 log.GetEntries(&entries); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 396 nullptr, nullptr); | 392 nullptr, nullptr); |
| 397 | 393 |
| 398 GURL url("http://www.google.com/"); | 394 GURL url("http://www.google.com/"); |
| 399 GURL bypass_url("http://internet.org"); | 395 GURL bypass_url("http://internet.org"); |
| 400 | 396 |
| 401 ProxyInfo info; | 397 ProxyInfo info; |
| 402 TestCompletionCallback callback; | 398 TestCompletionCallback callback; |
| 403 BoundTestNetLog log; | 399 BoundTestNetLog log; |
| 404 | 400 |
| 405 // First, warm up the ProxyService. | 401 // First, warm up the ProxyService. |
| 406 int rv = | 402 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
| 407 service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 403 nullptr, nullptr, log.bound()); |
| 408 callback.callback(), nullptr, nullptr, log.bound()); | |
| 409 EXPECT_THAT(rv, IsOk()); | 404 EXPECT_THAT(rv, IsOk()); |
| 410 | 405 |
| 411 // Verify that network delegate is invoked. | 406 // Verify that network delegate is invoked. |
| 412 TestResolveProxyDelegate delegate; | 407 TestResolveProxyDelegate delegate; |
| 413 rv = service.ResolveProxy(url, "GET", LOAD_NORMAL, &info, callback.callback(), | 408 rv = service.ResolveProxy(url, "GET", &info, callback.callback(), nullptr, |
| 414 nullptr, &delegate, log.bound()); | 409 &delegate, log.bound()); |
| 415 EXPECT_TRUE(delegate.on_resolve_proxy_called()); | 410 EXPECT_TRUE(delegate.on_resolve_proxy_called()); |
| 416 EXPECT_EQ(&service, delegate.proxy_service()); | 411 EXPECT_EQ(&service, delegate.proxy_service()); |
| 417 EXPECT_EQ(delegate.method(), "GET"); | 412 EXPECT_EQ(delegate.method(), "GET"); |
| 418 | 413 |
| 419 // Verify that the ProxyDelegate's behavior is stateless across | 414 // Verify that the ProxyDelegate's behavior is stateless across |
| 420 // invocations of ResolveProxy. Start by having the callback add a proxy | 415 // invocations of ResolveProxy. Start by having the callback add a proxy |
| 421 // and checking that subsequent requests are not affected. | 416 // and checking that subsequent requests are not affected. |
| 422 delegate.set_add_proxy(true); | 417 delegate.set_add_proxy(true); |
| 423 | 418 |
| 424 // Callback should interpose: | 419 // Callback should interpose: |
| 425 rv = service.ResolveProxy(url, "GET", LOAD_NORMAL, &info, callback.callback(), | 420 rv = service.ResolveProxy(url, "GET", &info, callback.callback(), nullptr, |
| 426 nullptr, &delegate, log.bound()); | 421 &delegate, log.bound()); |
| 427 EXPECT_FALSE(info.is_direct()); | 422 EXPECT_FALSE(info.is_direct()); |
| 428 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "delegate_proxy.com"); | 423 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "delegate_proxy.com"); |
| 429 delegate.set_add_proxy(false); | 424 delegate.set_add_proxy(false); |
| 430 | 425 |
| 431 // Check non-bypassed URL: | 426 // Check non-bypassed URL: |
| 432 rv = service.ResolveProxy(url, "GET", LOAD_NORMAL, &info, callback.callback(), | 427 rv = service.ResolveProxy(url, "GET", &info, callback.callback(), nullptr, |
| 433 nullptr, &delegate, log.bound()); | 428 &delegate, log.bound()); |
| 434 EXPECT_FALSE(info.is_direct()); | 429 EXPECT_FALSE(info.is_direct()); |
| 435 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "foopy1"); | 430 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "foopy1"); |
| 436 | 431 |
| 437 // Check bypassed URL: | 432 // Check bypassed URL: |
| 438 rv = service.ResolveProxy(bypass_url, "GET", LOAD_NORMAL, &info, | 433 rv = service.ResolveProxy(bypass_url, "GET", &info, callback.callback(), |
| 439 callback.callback(), nullptr, &delegate, | 434 nullptr, &delegate, log.bound()); |
| 440 log.bound()); | |
| 441 EXPECT_TRUE(info.is_direct()); | 435 EXPECT_TRUE(info.is_direct()); |
| 442 } | 436 } |
| 443 | 437 |
| 444 TEST_F(ProxyServiceTest, OnResolveProxyCallbackRemoveProxy) { | 438 TEST_F(ProxyServiceTest, OnResolveProxyCallbackRemoveProxy) { |
| 445 // Same as OnResolveProxyCallbackAddProxy, but verify that the | 439 // Same as OnResolveProxyCallbackAddProxy, but verify that the |
| 446 // ProxyDelegate's behavior is stateless across invocations after it | 440 // ProxyDelegate's behavior is stateless across invocations after it |
| 447 // *removes* a proxy. | 441 // *removes* a proxy. |
| 448 ProxyConfig config; | 442 ProxyConfig config; |
| 449 config.proxy_rules().ParseFromString("foopy1:8080"); | 443 config.proxy_rules().ParseFromString("foopy1:8080"); |
| 450 config.set_auto_detect(false); | 444 config.set_auto_detect(false); |
| 451 config.proxy_rules().bypass_rules.ParseFromString("*.org"); | 445 config.proxy_rules().bypass_rules.ParseFromString("*.org"); |
| 452 | 446 |
| 453 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 447 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 454 nullptr, nullptr); | 448 nullptr, nullptr); |
| 455 | 449 |
| 456 GURL url("http://www.google.com/"); | 450 GURL url("http://www.google.com/"); |
| 457 GURL bypass_url("http://internet.org"); | 451 GURL bypass_url("http://internet.org"); |
| 458 | 452 |
| 459 ProxyInfo info; | 453 ProxyInfo info; |
| 460 TestCompletionCallback callback; | 454 TestCompletionCallback callback; |
| 461 BoundTestNetLog log; | 455 BoundTestNetLog log; |
| 462 | 456 |
| 463 // First, warm up the ProxyService. | 457 // First, warm up the ProxyService. |
| 464 int rv = | 458 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
| 465 service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 459 nullptr, nullptr, log.bound()); |
| 466 callback.callback(), nullptr, nullptr, log.bound()); | |
| 467 EXPECT_THAT(rv, IsOk()); | 460 EXPECT_THAT(rv, IsOk()); |
| 468 | 461 |
| 469 TestResolveProxyDelegate delegate; | 462 TestResolveProxyDelegate delegate; |
| 470 delegate.set_remove_proxy(true); | 463 delegate.set_remove_proxy(true); |
| 471 | 464 |
| 472 // Callback should interpose: | 465 // Callback should interpose: |
| 473 rv = service.ResolveProxy(url, "GET", LOAD_NORMAL, &info, callback.callback(), | 466 rv = service.ResolveProxy(url, "GET", &info, callback.callback(), nullptr, |
| 474 nullptr, &delegate, log.bound()); | 467 &delegate, log.bound()); |
| 475 EXPECT_TRUE(info.is_direct()); | 468 EXPECT_TRUE(info.is_direct()); |
| 476 delegate.set_remove_proxy(false); | 469 delegate.set_remove_proxy(false); |
| 477 | 470 |
| 478 // Check non-bypassed URL: | 471 // Check non-bypassed URL: |
| 479 rv = service.ResolveProxy(url, "GET", LOAD_NORMAL, &info, callback.callback(), | 472 rv = service.ResolveProxy(url, "GET", &info, callback.callback(), nullptr, |
| 480 nullptr, &delegate, log.bound()); | 473 &delegate, log.bound()); |
| 481 EXPECT_FALSE(info.is_direct()); | 474 EXPECT_FALSE(info.is_direct()); |
| 482 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "foopy1"); | 475 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "foopy1"); |
| 483 | 476 |
| 484 // Check bypassed URL: | 477 // Check bypassed URL: |
| 485 rv = service.ResolveProxy(bypass_url, "GET", LOAD_NORMAL, &info, | 478 rv = service.ResolveProxy(bypass_url, "GET", &info, callback.callback(), |
| 486 callback.callback(), nullptr, &delegate, | 479 nullptr, &delegate, log.bound()); |
| 487 log.bound()); | |
| 488 EXPECT_TRUE(info.is_direct()); | 480 EXPECT_TRUE(info.is_direct()); |
| 489 } | 481 } |
| 490 | 482 |
| 491 TEST_F(ProxyServiceTest, PAC) { | 483 TEST_F(ProxyServiceTest, PAC) { |
| 492 MockProxyConfigService* config_service = | 484 MockProxyConfigService* config_service = |
| 493 new MockProxyConfigService("http://foopy/proxy.pac"); | 485 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 494 | 486 |
| 495 MockAsyncProxyResolver resolver; | 487 MockAsyncProxyResolver resolver; |
| 496 MockAsyncProxyResolverFactory* factory = | 488 MockAsyncProxyResolverFactory* factory = |
| 497 new MockAsyncProxyResolverFactory(false); | 489 new MockAsyncProxyResolverFactory(false); |
| 498 | 490 |
| 499 ProxyService service(base::WrapUnique(config_service), | 491 ProxyService service(base::WrapUnique(config_service), |
| 500 base::WrapUnique(factory), nullptr); | 492 base::WrapUnique(factory), nullptr); |
| 501 | 493 |
| 502 GURL url("http://www.google.com/"); | 494 GURL url("http://www.google.com/"); |
| 503 | 495 |
| 504 ProxyInfo info; | 496 ProxyInfo info; |
| 505 TestCompletionCallback callback; | 497 TestCompletionCallback callback; |
| 506 ProxyService::PacRequest* request; | 498 ProxyService::PacRequest* request; |
| 507 BoundTestNetLog log; | 499 BoundTestNetLog log; |
| 508 | 500 |
| 509 int rv = | 501 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
| 510 service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 502 &request, nullptr, log.bound()); |
| 511 callback.callback(), &request, nullptr, log.bound()); | |
| 512 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 503 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 513 | 504 |
| 514 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); | 505 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); |
| 515 | 506 |
| 516 ASSERT_EQ(1u, factory->pending_requests().size()); | 507 ASSERT_EQ(1u, factory->pending_requests().size()); |
| 517 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 508 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 518 factory->pending_requests()[0]->script_data()->url()); | 509 factory->pending_requests()[0]->script_data()->url()); |
| 519 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 510 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 520 | 511 |
| 521 ASSERT_EQ(1u, resolver.pending_requests().size()); | 512 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 MockAsyncProxyResolverFactory* factory = | 550 MockAsyncProxyResolverFactory* factory = |
| 560 new MockAsyncProxyResolverFactory(false); | 551 new MockAsyncProxyResolverFactory(false); |
| 561 | 552 |
| 562 ProxyService service(base::WrapUnique(config_service), | 553 ProxyService service(base::WrapUnique(config_service), |
| 563 base::WrapUnique(factory), nullptr); | 554 base::WrapUnique(factory), nullptr); |
| 564 | 555 |
| 565 GURL url("http://username:password@www.google.com/?ref#hash#hash"); | 556 GURL url("http://username:password@www.google.com/?ref#hash#hash"); |
| 566 | 557 |
| 567 ProxyInfo info; | 558 ProxyInfo info; |
| 568 TestCompletionCallback callback; | 559 TestCompletionCallback callback; |
| 569 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 560 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
| 570 callback.callback(), nullptr, nullptr, | 561 nullptr, nullptr, BoundNetLog()); |
| 571 BoundNetLog()); | |
| 572 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 562 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 573 | 563 |
| 574 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 564 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 575 factory->pending_requests()[0]->script_data()->url()); | 565 factory->pending_requests()[0]->script_data()->url()); |
| 576 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 566 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 577 | 567 |
| 578 ASSERT_EQ(1u, resolver.pending_requests().size()); | 568 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 579 // The URL should have been simplified, stripping the username/password/hash. | 569 // The URL should have been simplified, stripping the username/password/hash. |
| 580 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 570 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
| 581 resolver.pending_requests()[0]->url()); | 571 resolver.pending_requests()[0]->url()); |
| 582 | 572 |
| 583 // We end here without ever completing the request -- destruction of | 573 // We end here without ever completing the request -- destruction of |
| 584 // ProxyService will cancel the outstanding request. | 574 // ProxyService will cancel the outstanding request. |
| 585 } | 575 } |
| 586 | 576 |
| 587 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { | 577 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { |
| 588 MockProxyConfigService* config_service = | 578 MockProxyConfigService* config_service = |
| 589 new MockProxyConfigService("http://foopy/proxy.pac"); | 579 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 590 MockAsyncProxyResolver resolver; | 580 MockAsyncProxyResolver resolver; |
| 591 MockAsyncProxyResolverFactory* factory = | 581 MockAsyncProxyResolverFactory* factory = |
| 592 new MockAsyncProxyResolverFactory(false); | 582 new MockAsyncProxyResolverFactory(false); |
| 593 | 583 |
| 594 ProxyService service(base::WrapUnique(config_service), | 584 ProxyService service(base::WrapUnique(config_service), |
| 595 base::WrapUnique(factory), nullptr); | 585 base::WrapUnique(factory), nullptr); |
| 596 | 586 |
| 597 GURL url("http://www.google.com/"); | 587 GURL url("http://www.google.com/"); |
| 598 | 588 |
| 599 ProxyInfo info; | 589 ProxyInfo info; |
| 600 TestCompletionCallback callback1; | 590 TestCompletionCallback callback1; |
| 601 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 591 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
| 602 callback1.callback(), nullptr, nullptr, | 592 nullptr, nullptr, BoundNetLog()); |
| 603 BoundNetLog()); | |
| 604 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 593 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 605 | 594 |
| 606 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 595 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 607 factory->pending_requests()[0]->script_data()->url()); | 596 factory->pending_requests()[0]->script_data()->url()); |
| 608 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 597 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 609 | 598 |
| 610 ASSERT_EQ(1u, resolver.pending_requests().size()); | 599 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 611 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 600 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 612 | 601 |
| 613 // Set the result in proxy resolver. | 602 // Set the result in proxy resolver. |
| 614 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); | 603 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); |
| 615 resolver.pending_requests()[0]->CompleteNow(OK); | 604 resolver.pending_requests()[0]->CompleteNow(OK); |
| 616 | 605 |
| 617 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 606 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 618 EXPECT_FALSE(info.is_direct()); | 607 EXPECT_FALSE(info.is_direct()); |
| 619 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); | 608 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); |
| 620 EXPECT_TRUE(info.did_use_pac_script()); | 609 EXPECT_TRUE(info.did_use_pac_script()); |
| 621 | 610 |
| 622 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 611 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
| 623 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 612 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
| 624 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 613 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
| 625 | 614 |
| 626 // Now, imagine that connecting to foopy:8080 fails: there is nothing | 615 // Now, imagine that connecting to foopy:8080 fails: there is nothing |
| 627 // left to fallback to, since our proxy list was NOT terminated by | 616 // left to fallback to, since our proxy list was NOT terminated by |
| 628 // DIRECT. | 617 // DIRECT. |
| 629 TestResolveProxyDelegate proxy_delegate; | 618 TestResolveProxyDelegate proxy_delegate; |
| 630 TestCompletionCallback callback2; | 619 TestCompletionCallback callback2; |
| 631 ProxyServer expected_proxy_server = info.proxy_server(); | 620 ProxyServer expected_proxy_server = info.proxy_server(); |
| 632 rv = service.ReconsiderProxyAfterError( | 621 rv = service.ReconsiderProxyAfterError( |
| 633 url, "GET", LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 622 url, "GET", ERR_PROXY_CONNECTION_FAILED, &info, callback2.callback(), |
| 634 callback2.callback(), nullptr, &proxy_delegate, BoundNetLog()); | 623 nullptr, &proxy_delegate, BoundNetLog()); |
| 635 // ReconsiderProxyAfterError returns error indicating nothing left. | 624 // ReconsiderProxyAfterError returns error indicating nothing left. |
| 636 EXPECT_THAT(rv, IsError(ERR_FAILED)); | 625 EXPECT_THAT(rv, IsError(ERR_FAILED)); |
| 637 EXPECT_TRUE(info.is_empty()); | 626 EXPECT_TRUE(info.is_empty()); |
| 638 } | 627 } |
| 639 | 628 |
| 640 // Test that if the execution of the PAC script fails (i.e. javascript runtime | 629 // Test that if the execution of the PAC script fails (i.e. javascript runtime |
| 641 // error), and the PAC settings are non-mandatory, that we fall-back to direct. | 630 // error), and the PAC settings are non-mandatory, that we fall-back to direct. |
| 642 TEST_F(ProxyServiceTest, PAC_RuntimeError) { | 631 TEST_F(ProxyServiceTest, PAC_RuntimeError) { |
| 643 MockProxyConfigService* config_service = | 632 MockProxyConfigService* config_service = |
| 644 new MockProxyConfigService("http://foopy/proxy.pac"); | 633 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 645 MockAsyncProxyResolver resolver; | 634 MockAsyncProxyResolver resolver; |
| 646 MockAsyncProxyResolverFactory* factory = | 635 MockAsyncProxyResolverFactory* factory = |
| 647 new MockAsyncProxyResolverFactory(false); | 636 new MockAsyncProxyResolverFactory(false); |
| 648 | 637 |
| 649 ProxyService service(base::WrapUnique(config_service), | 638 ProxyService service(base::WrapUnique(config_service), |
| 650 base::WrapUnique(factory), nullptr); | 639 base::WrapUnique(factory), nullptr); |
| 651 | 640 |
| 652 GURL url("http://this-causes-js-error/"); | 641 GURL url("http://this-causes-js-error/"); |
| 653 | 642 |
| 654 ProxyInfo info; | 643 ProxyInfo info; |
| 655 TestCompletionCallback callback1; | 644 TestCompletionCallback callback1; |
| 656 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 645 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
| 657 callback1.callback(), nullptr, nullptr, | 646 nullptr, nullptr, BoundNetLog()); |
| 658 BoundNetLog()); | |
| 659 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 647 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 660 | 648 |
| 661 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 649 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 662 factory->pending_requests()[0]->script_data()->url()); | 650 factory->pending_requests()[0]->script_data()->url()); |
| 663 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 651 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 664 | 652 |
| 665 ASSERT_EQ(1u, resolver.pending_requests().size()); | 653 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 666 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 654 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 667 | 655 |
| 668 // Simulate a failure in the PAC executor. | 656 // Simulate a failure in the PAC executor. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 MockAsyncProxyResolverFactory* factory = | 693 MockAsyncProxyResolverFactory* factory = |
| 706 new MockAsyncProxyResolverFactory(false); | 694 new MockAsyncProxyResolverFactory(false); |
| 707 | 695 |
| 708 ProxyService service(base::WrapUnique(config_service), | 696 ProxyService service(base::WrapUnique(config_service), |
| 709 base::WrapUnique(factory), nullptr); | 697 base::WrapUnique(factory), nullptr); |
| 710 | 698 |
| 711 GURL url("http://www.google.com/"); | 699 GURL url("http://www.google.com/"); |
| 712 | 700 |
| 713 ProxyInfo info; | 701 ProxyInfo info; |
| 714 TestCompletionCallback callback1; | 702 TestCompletionCallback callback1; |
| 715 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 703 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
| 716 callback1.callback(), nullptr, nullptr, | 704 nullptr, nullptr, BoundNetLog()); |
| 717 BoundNetLog()); | |
| 718 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 705 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 719 | 706 |
| 720 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 707 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 721 factory->pending_requests()[0]->script_data()->url()); | 708 factory->pending_requests()[0]->script_data()->url()); |
| 722 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 709 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 723 | 710 |
| 724 ASSERT_EQ(1u, resolver.pending_requests().size()); | 711 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 725 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 712 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 726 | 713 |
| 727 // Set the result in proxy resolver. | 714 // Set the result in proxy resolver. |
| 728 resolver.pending_requests()[0]->results()->UsePacString( | 715 resolver.pending_requests()[0]->results()->UsePacString( |
| 729 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); | 716 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); |
| 730 resolver.pending_requests()[0]->CompleteNow(OK); | 717 resolver.pending_requests()[0]->CompleteNow(OK); |
| 731 | 718 |
| 732 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 719 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 733 EXPECT_TRUE(info.is_direct()); | 720 EXPECT_TRUE(info.is_direct()); |
| 734 | 721 |
| 735 // Fallback 1. | 722 // Fallback 1. |
| 736 TestCompletionCallback callback2; | 723 TestCompletionCallback callback2; |
| 737 rv = service.ReconsiderProxyAfterError( | 724 rv = service.ReconsiderProxyAfterError( |
| 738 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 725 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 739 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 726 callback2.callback(), nullptr, nullptr, BoundNetLog()); |
| 740 EXPECT_THAT(rv, IsOk()); | 727 EXPECT_THAT(rv, IsOk()); |
| 741 EXPECT_FALSE(info.is_direct()); | 728 EXPECT_FALSE(info.is_direct()); |
| 742 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); | 729 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); |
| 743 | 730 |
| 744 // Fallback 2. | 731 // Fallback 2. |
| 745 TestResolveProxyDelegate proxy_delegate; | 732 TestResolveProxyDelegate proxy_delegate; |
| 746 ProxyServer expected_proxy_server3 = info.proxy_server(); | 733 ProxyServer expected_proxy_server3 = info.proxy_server(); |
| 747 TestCompletionCallback callback3; | 734 TestCompletionCallback callback3; |
| 748 rv = service.ReconsiderProxyAfterError( | 735 rv = service.ReconsiderProxyAfterError( |
| 749 url, "GET", LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 736 url, "GET", ERR_PROXY_CONNECTION_FAILED, &info, callback3.callback(), |
| 750 callback3.callback(), nullptr, &proxy_delegate, BoundNetLog()); | 737 nullptr, &proxy_delegate, BoundNetLog()); |
| 751 EXPECT_THAT(rv, IsOk()); | 738 EXPECT_THAT(rv, IsOk()); |
| 752 EXPECT_TRUE(info.is_direct()); | 739 EXPECT_TRUE(info.is_direct()); |
| 753 | 740 |
| 754 // Fallback 3. | 741 // Fallback 3. |
| 755 ProxyServer expected_proxy_server4 = info.proxy_server(); | 742 ProxyServer expected_proxy_server4 = info.proxy_server(); |
| 756 TestCompletionCallback callback4; | 743 TestCompletionCallback callback4; |
| 757 rv = service.ReconsiderProxyAfterError( | 744 rv = service.ReconsiderProxyAfterError( |
| 758 url, "GET", LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 745 url, "GET", ERR_PROXY_CONNECTION_FAILED, &info, callback4.callback(), |
| 759 callback4.callback(), nullptr, &proxy_delegate, BoundNetLog()); | 746 nullptr, &proxy_delegate, BoundNetLog()); |
| 760 EXPECT_THAT(rv, IsOk()); | 747 EXPECT_THAT(rv, IsOk()); |
| 761 EXPECT_FALSE(info.is_direct()); | 748 EXPECT_FALSE(info.is_direct()); |
| 762 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); | 749 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); |
| 763 | 750 |
| 764 // Fallback 4 -- Nothing to fall back to! | 751 // Fallback 4 -- Nothing to fall back to! |
| 765 ProxyServer expected_proxy_server5 = info.proxy_server(); | 752 ProxyServer expected_proxy_server5 = info.proxy_server(); |
| 766 TestCompletionCallback callback5; | 753 TestCompletionCallback callback5; |
| 767 rv = service.ReconsiderProxyAfterError( | 754 rv = service.ReconsiderProxyAfterError( |
| 768 url, "GET", LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 755 url, "GET", ERR_PROXY_CONNECTION_FAILED, &info, callback5.callback(), |
| 769 callback5.callback(), nullptr, &proxy_delegate, BoundNetLog()); | 756 nullptr, &proxy_delegate, BoundNetLog()); |
| 770 EXPECT_THAT(rv, IsError(ERR_FAILED)); | 757 EXPECT_THAT(rv, IsError(ERR_FAILED)); |
| 771 EXPECT_TRUE(info.is_empty()); | 758 EXPECT_TRUE(info.is_empty()); |
| 772 } | 759 } |
| 773 | 760 |
| 774 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { | 761 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { |
| 775 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied | 762 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied |
| 776 // to ProxyInfo after the proxy is resolved via a PAC script. | 763 // to ProxyInfo after the proxy is resolved via a PAC script. |
| 777 ProxyConfig config = | 764 ProxyConfig config = |
| 778 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); | 765 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); |
| 779 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 766 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
| 780 | 767 |
| 781 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 768 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 782 MockAsyncProxyResolver resolver; | 769 MockAsyncProxyResolver resolver; |
| 783 MockAsyncProxyResolverFactory* factory = | 770 MockAsyncProxyResolverFactory* factory = |
| 784 new MockAsyncProxyResolverFactory(false); | 771 new MockAsyncProxyResolverFactory(false); |
| 785 ProxyService service(base::WrapUnique(config_service), | 772 ProxyService service(base::WrapUnique(config_service), |
| 786 base::WrapUnique(factory), nullptr); | 773 base::WrapUnique(factory), nullptr); |
| 787 | 774 |
| 788 // Resolve something. | 775 // Resolve something. |
| 789 GURL url("http://www.google.com/"); | 776 GURL url("http://www.google.com/"); |
| 790 ProxyInfo info; | 777 ProxyInfo info; |
| 791 TestCompletionCallback callback; | 778 TestCompletionCallback callback; |
| 792 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 779 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
| 793 callback.callback(), nullptr, nullptr, | 780 nullptr, nullptr, BoundNetLog()); |
| 794 BoundNetLog()); | |
| 795 ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); | 781 ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 796 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 782 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 797 ASSERT_EQ(1u, resolver.pending_requests().size()); | 783 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 798 | 784 |
| 799 // Set the result in proxy resolver. | 785 // Set the result in proxy resolver. |
| 800 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); | 786 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); |
| 801 resolver.pending_requests()[0]->CompleteNow(OK); | 787 resolver.pending_requests()[0]->CompleteNow(OK); |
| 802 | 788 |
| 803 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 789 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 804 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 790 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 821 MockAsyncProxyResolverFactory* factory = | 807 MockAsyncProxyResolverFactory* factory = |
| 822 new MockAsyncProxyResolverFactory(false); | 808 new MockAsyncProxyResolverFactory(false); |
| 823 | 809 |
| 824 ProxyService service(base::WrapUnique(config_service), | 810 ProxyService service(base::WrapUnique(config_service), |
| 825 base::WrapUnique(factory), nullptr); | 811 base::WrapUnique(factory), nullptr); |
| 826 | 812 |
| 827 // Start first resolve request. | 813 // Start first resolve request. |
| 828 GURL url("http://www.google.com/"); | 814 GURL url("http://www.google.com/"); |
| 829 ProxyInfo info; | 815 ProxyInfo info; |
| 830 TestCompletionCallback callback1; | 816 TestCompletionCallback callback1; |
| 831 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 817 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
| 832 callback1.callback(), nullptr, nullptr, | 818 nullptr, nullptr, BoundNetLog()); |
| 833 BoundNetLog()); | |
| 834 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 819 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 835 | 820 |
| 836 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 821 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 837 factory->pending_requests()[0]->script_data()->url()); | 822 factory->pending_requests()[0]->script_data()->url()); |
| 838 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 823 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 839 | 824 |
| 840 ASSERT_EQ(1u, resolver.pending_requests().size()); | 825 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 841 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 826 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 842 | 827 |
| 843 // Fail the first resolve request in MockAsyncProxyResolver. | 828 // Fail the first resolve request in MockAsyncProxyResolver. |
| 844 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 829 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
| 845 | 830 |
| 846 // Although the proxy resolver failed the request, ProxyService implicitly | 831 // Although the proxy resolver failed the request, ProxyService implicitly |
| 847 // falls-back to DIRECT. | 832 // falls-back to DIRECT. |
| 848 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 833 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 849 EXPECT_TRUE(info.is_direct()); | 834 EXPECT_TRUE(info.is_direct()); |
| 850 | 835 |
| 851 // Failed PAC executions still have proxy resolution times. | 836 // Failed PAC executions still have proxy resolution times. |
| 852 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 837 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
| 853 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 838 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
| 854 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 839 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
| 855 | 840 |
| 856 // The second resolve request will try to run through the proxy resolver, | 841 // The second resolve request will try to run through the proxy resolver, |
| 857 // regardless of whether the first request failed in it. | 842 // regardless of whether the first request failed in it. |
| 858 TestCompletionCallback callback2; | 843 TestCompletionCallback callback2; |
| 859 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 844 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), |
| 860 callback2.callback(), nullptr, nullptr, | 845 nullptr, nullptr, BoundNetLog()); |
| 861 BoundNetLog()); | |
| 862 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 846 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 863 | 847 |
| 864 ASSERT_EQ(1u, resolver.pending_requests().size()); | 848 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 865 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 849 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 866 | 850 |
| 867 // This time we will have the resolver succeed (perhaps the PAC script has | 851 // This time we will have the resolver succeed (perhaps the PAC script has |
| 868 // a dependency on the current time). | 852 // a dependency on the current time). |
| 869 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 853 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
| 870 resolver.pending_requests()[0]->CompleteNow(OK); | 854 resolver.pending_requests()[0]->CompleteNow(OK); |
| 871 | 855 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 885 MockAsyncProxyResolverFactory* factory = | 869 MockAsyncProxyResolverFactory* factory = |
| 886 new MockAsyncProxyResolverFactory(false); | 870 new MockAsyncProxyResolverFactory(false); |
| 887 | 871 |
| 888 ProxyService service(base::WrapUnique(config_service), | 872 ProxyService service(base::WrapUnique(config_service), |
| 889 base::WrapUnique(factory), nullptr); | 873 base::WrapUnique(factory), nullptr); |
| 890 | 874 |
| 891 // Start first resolve request. | 875 // Start first resolve request. |
| 892 GURL url("http://www.google.com/"); | 876 GURL url("http://www.google.com/"); |
| 893 ProxyInfo info; | 877 ProxyInfo info; |
| 894 TestCompletionCallback callback1; | 878 TestCompletionCallback callback1; |
| 895 int rv = service.ResolveProxy(url, std::string(), net::LOAD_NORMAL, &info, | 879 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
| 896 callback1.callback(), nullptr, nullptr, | 880 nullptr, nullptr, BoundNetLog()); |
| 897 BoundNetLog()); | |
| 898 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 881 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 899 | 882 |
| 900 ASSERT_EQ(1u, factory->pending_requests().size()); | 883 ASSERT_EQ(1u, factory->pending_requests().size()); |
| 901 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 884 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 902 factory->pending_requests()[0]->script_data()->url()); | 885 factory->pending_requests()[0]->script_data()->url()); |
| 903 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 886 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 904 | 887 |
| 905 ASSERT_EQ(1u, resolver.pending_requests().size()); | 888 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 906 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 889 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 907 | 890 |
| 908 // Fail the first resolve request in MockAsyncProxyResolver. | 891 // Fail the first resolve request in MockAsyncProxyResolver. |
| 909 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); | 892 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); |
| 910 | 893 |
| 911 // Although the proxy resolver failed the request, ProxyService implicitly | 894 // Although the proxy resolver failed the request, ProxyService implicitly |
| 912 // falls-back to DIRECT. | 895 // falls-back to DIRECT. |
| 913 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 896 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 914 EXPECT_TRUE(info.is_direct()); | 897 EXPECT_TRUE(info.is_direct()); |
| 915 | 898 |
| 916 // Failed PAC executions still have proxy resolution times. | 899 // Failed PAC executions still have proxy resolution times. |
| 917 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 900 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
| 918 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 901 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
| 919 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 902 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
| 920 | 903 |
| 921 // With no other requests, the ProxyService waits for a new request before | 904 // With no other requests, the ProxyService waits for a new request before |
| 922 // initializing a new ProxyResolver. | 905 // initializing a new ProxyResolver. |
| 923 EXPECT_TRUE(factory->pending_requests().empty()); | 906 EXPECT_TRUE(factory->pending_requests().empty()); |
| 924 | 907 |
| 925 TestCompletionCallback callback2; | 908 TestCompletionCallback callback2; |
| 926 rv = service.ResolveProxy(url, std::string(), net::LOAD_NORMAL, &info, | 909 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), |
| 927 callback2.callback(), nullptr, nullptr, | 910 nullptr, nullptr, BoundNetLog()); |
| 928 BoundNetLog()); | |
| 929 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 911 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 930 | 912 |
| 931 ASSERT_EQ(1u, factory->pending_requests().size()); | 913 ASSERT_EQ(1u, factory->pending_requests().size()); |
| 932 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 914 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 933 factory->pending_requests()[0]->script_data()->url()); | 915 factory->pending_requests()[0]->script_data()->url()); |
| 934 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 916 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 935 | 917 |
| 936 ASSERT_EQ(1u, resolver.pending_requests().size()); | 918 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 937 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 919 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 938 | 920 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 958 new MockAsyncProxyResolverFactory(false); | 940 new MockAsyncProxyResolverFactory(false); |
| 959 | 941 |
| 960 ProxyService service(base::WrapUnique(config_service), | 942 ProxyService service(base::WrapUnique(config_service), |
| 961 base::WrapUnique(factory), nullptr); | 943 base::WrapUnique(factory), nullptr); |
| 962 | 944 |
| 963 // Start two resolve requests. | 945 // Start two resolve requests. |
| 964 GURL url1("http://www.google.com/"); | 946 GURL url1("http://www.google.com/"); |
| 965 GURL url2("https://www.google.com/"); | 947 GURL url2("https://www.google.com/"); |
| 966 ProxyInfo info; | 948 ProxyInfo info; |
| 967 TestCompletionCallback callback1; | 949 TestCompletionCallback callback1; |
| 968 int rv = service.ResolveProxy(url1, std::string(), net::LOAD_NORMAL, &info, | 950 int rv = |
| 969 callback1.callback(), nullptr, nullptr, | 951 service.ResolveProxy(url1, std::string(), &info, callback1.callback(), |
| 970 BoundNetLog()); | 952 nullptr, nullptr, BoundNetLog()); |
| 971 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 953 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 972 TestCompletionCallback callback2; | 954 TestCompletionCallback callback2; |
| 973 rv = service.ResolveProxy(url2, std::string(), net::LOAD_NORMAL, &info, | 955 rv = service.ResolveProxy(url2, std::string(), &info, callback2.callback(), |
| 974 callback2.callback(), nullptr, nullptr, | 956 nullptr, nullptr, BoundNetLog()); |
| 975 BoundNetLog()); | |
| 976 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 957 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 977 | 958 |
| 978 ASSERT_EQ(1u, factory->pending_requests().size()); | 959 ASSERT_EQ(1u, factory->pending_requests().size()); |
| 979 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 960 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 980 factory->pending_requests()[0]->script_data()->url()); | 961 factory->pending_requests()[0]->script_data()->url()); |
| 981 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 962 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 982 | 963 |
| 983 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); | 964 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); |
| 984 | 965 |
| 985 // Fail the first resolve request in MockAsyncProxyResolver. | 966 // Fail the first resolve request in MockAsyncProxyResolver. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 MockAsyncProxyResolverFactory* factory = | 1010 MockAsyncProxyResolverFactory* factory = |
| 1030 new MockAsyncProxyResolverFactory(false); | 1011 new MockAsyncProxyResolverFactory(false); |
| 1031 | 1012 |
| 1032 ProxyService service(base::WrapUnique(config_service), | 1013 ProxyService service(base::WrapUnique(config_service), |
| 1033 base::WrapUnique(factory), nullptr); | 1014 base::WrapUnique(factory), nullptr); |
| 1034 | 1015 |
| 1035 // Start first resolve request. | 1016 // Start first resolve request. |
| 1036 GURL url("http://www.google.com/"); | 1017 GURL url("http://www.google.com/"); |
| 1037 ProxyInfo info; | 1018 ProxyInfo info; |
| 1038 TestCompletionCallback callback1; | 1019 TestCompletionCallback callback1; |
| 1039 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1020 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
| 1040 callback1.callback(), nullptr, nullptr, | 1021 nullptr, nullptr, BoundNetLog()); |
| 1041 BoundNetLog()); | |
| 1042 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1022 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1043 | 1023 |
| 1044 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1024 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1045 factory->pending_requests()[0]->script_data()->url()); | 1025 factory->pending_requests()[0]->script_data()->url()); |
| 1046 factory->pending_requests()[0]->CompleteNow(ERR_FAILED, nullptr); | 1026 factory->pending_requests()[0]->CompleteNow(ERR_FAILED, nullptr); |
| 1047 | 1027 |
| 1048 ASSERT_EQ(0u, factory->pending_requests().size()); | 1028 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 1049 // As the proxy resolver factory failed the request and is configured for a | 1029 // As the proxy resolver factory failed the request and is configured for a |
| 1050 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1030 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. |
| 1051 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1031 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
| 1052 callback1.WaitForResult()); | 1032 callback1.WaitForResult()); |
| 1053 EXPECT_FALSE(info.is_direct()); | 1033 EXPECT_FALSE(info.is_direct()); |
| 1054 | 1034 |
| 1055 // As the proxy resolver factory failed the request and is configured for a | 1035 // As the proxy resolver factory failed the request and is configured for a |
| 1056 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1036 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. |
| 1057 TestCompletionCallback callback2; | 1037 TestCompletionCallback callback2; |
| 1058 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1038 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), |
| 1059 callback2.callback(), nullptr, nullptr, | 1039 nullptr, nullptr, BoundNetLog()); |
| 1060 BoundNetLog()); | |
| 1061 EXPECT_THAT(rv, IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); | 1040 EXPECT_THAT(rv, IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 1062 EXPECT_FALSE(info.is_direct()); | 1041 EXPECT_FALSE(info.is_direct()); |
| 1063 } | 1042 } |
| 1064 | 1043 |
| 1065 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { | 1044 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { |
| 1066 // Test what happens when the ProxyResolver fails that is configured to use a | 1045 // Test what happens when the ProxyResolver fails that is configured to use a |
| 1067 // mandatory PAC script. The download of the PAC script has already | 1046 // mandatory PAC script. The download of the PAC script has already |
| 1068 // succeeded but the PAC script contains no valid javascript. | 1047 // succeeded but the PAC script contains no valid javascript. |
| 1069 | 1048 |
| 1070 ProxyConfig config( | 1049 ProxyConfig config( |
| 1071 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 1050 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
| 1072 config.set_pac_mandatory(true); | 1051 config.set_pac_mandatory(true); |
| 1073 | 1052 |
| 1074 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1053 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1075 | 1054 |
| 1076 MockAsyncProxyResolverFactory* factory = | 1055 MockAsyncProxyResolverFactory* factory = |
| 1077 new MockAsyncProxyResolverFactory(true); | 1056 new MockAsyncProxyResolverFactory(true); |
| 1078 | 1057 |
| 1079 ProxyService service(base::WrapUnique(config_service), | 1058 ProxyService service(base::WrapUnique(config_service), |
| 1080 base::WrapUnique(factory), nullptr); | 1059 base::WrapUnique(factory), nullptr); |
| 1081 | 1060 |
| 1082 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1061 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1083 service.SetProxyScriptFetchers( | 1062 service.SetProxyScriptFetchers( |
| 1084 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 1063 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 1085 | 1064 |
| 1086 // Start resolve request. | 1065 // Start resolve request. |
| 1087 GURL url("http://www.google.com/"); | 1066 GURL url("http://www.google.com/"); |
| 1088 ProxyInfo info; | 1067 ProxyInfo info; |
| 1089 TestCompletionCallback callback; | 1068 TestCompletionCallback callback; |
| 1090 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1069 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
| 1091 callback.callback(), nullptr, nullptr, | 1070 nullptr, nullptr, BoundNetLog()); |
| 1092 BoundNetLog()); | |
| 1093 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1071 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1094 | 1072 |
| 1095 // Check that nothing has been sent to the proxy resolver factory yet. | 1073 // Check that nothing has been sent to the proxy resolver factory yet. |
| 1096 ASSERT_EQ(0u, factory->pending_requests().size()); | 1074 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 1097 | 1075 |
| 1098 // Downloading the PAC script succeeds. | 1076 // Downloading the PAC script succeeds. |
| 1099 EXPECT_TRUE(fetcher->has_pending_request()); | 1077 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1100 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1078 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 1101 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 1079 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
| 1102 | 1080 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1127 MockAsyncProxyResolverFactory* factory = | 1105 MockAsyncProxyResolverFactory* factory = |
| 1128 new MockAsyncProxyResolverFactory(false); | 1106 new MockAsyncProxyResolverFactory(false); |
| 1129 | 1107 |
| 1130 ProxyService service(base::WrapUnique(config_service), | 1108 ProxyService service(base::WrapUnique(config_service), |
| 1131 base::WrapUnique(factory), nullptr); | 1109 base::WrapUnique(factory), nullptr); |
| 1132 | 1110 |
| 1133 // Start first resolve request. | 1111 // Start first resolve request. |
| 1134 GURL url("http://www.google.com/"); | 1112 GURL url("http://www.google.com/"); |
| 1135 ProxyInfo info; | 1113 ProxyInfo info; |
| 1136 TestCompletionCallback callback1; | 1114 TestCompletionCallback callback1; |
| 1137 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1115 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
| 1138 callback1.callback(), nullptr, nullptr, | 1116 nullptr, nullptr, BoundNetLog()); |
| 1139 BoundNetLog()); | |
| 1140 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1117 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1141 | 1118 |
| 1142 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1119 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1143 factory->pending_requests()[0]->script_data()->url()); | 1120 factory->pending_requests()[0]->script_data()->url()); |
| 1144 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1121 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1145 | 1122 |
| 1146 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1123 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1147 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1124 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1148 | 1125 |
| 1149 // Fail the first resolve request in MockAsyncProxyResolver. | 1126 // Fail the first resolve request in MockAsyncProxyResolver. |
| 1150 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1127 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
| 1151 | 1128 |
| 1152 // As the proxy resolver failed the request and is configured for a mandatory | 1129 // As the proxy resolver failed the request and is configured for a mandatory |
| 1153 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1130 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
| 1154 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1131 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
| 1155 callback1.WaitForResult()); | 1132 callback1.WaitForResult()); |
| 1156 EXPECT_FALSE(info.is_direct()); | 1133 EXPECT_FALSE(info.is_direct()); |
| 1157 | 1134 |
| 1158 // The second resolve request will try to run through the proxy resolver, | 1135 // The second resolve request will try to run through the proxy resolver, |
| 1159 // regardless of whether the first request failed in it. | 1136 // regardless of whether the first request failed in it. |
| 1160 TestCompletionCallback callback2; | 1137 TestCompletionCallback callback2; |
| 1161 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1138 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), |
| 1162 callback2.callback(), nullptr, nullptr, | 1139 nullptr, nullptr, BoundNetLog()); |
| 1163 BoundNetLog()); | |
| 1164 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1140 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1165 | 1141 |
| 1166 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1142 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1167 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1143 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1168 | 1144 |
| 1169 // This time we will have the resolver succeed (perhaps the PAC script has | 1145 // This time we will have the resolver succeed (perhaps the PAC script has |
| 1170 // a dependency on the current time). | 1146 // a dependency on the current time). |
| 1171 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 1147 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
| 1172 resolver.pending_requests()[0]->CompleteNow(OK); | 1148 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1173 | 1149 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1188 new MockAsyncProxyResolverFactory(false); | 1164 new MockAsyncProxyResolverFactory(false); |
| 1189 | 1165 |
| 1190 ProxyService service(base::WrapUnique(config_service), | 1166 ProxyService service(base::WrapUnique(config_service), |
| 1191 base::WrapUnique(factory), nullptr); | 1167 base::WrapUnique(factory), nullptr); |
| 1192 | 1168 |
| 1193 GURL url("http://www.google.com/"); | 1169 GURL url("http://www.google.com/"); |
| 1194 | 1170 |
| 1195 // Get the proxy information. | 1171 // Get the proxy information. |
| 1196 ProxyInfo info; | 1172 ProxyInfo info; |
| 1197 TestCompletionCallback callback1; | 1173 TestCompletionCallback callback1; |
| 1198 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1174 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
| 1199 callback1.callback(), nullptr, nullptr, | 1175 nullptr, nullptr, BoundNetLog()); |
| 1200 BoundNetLog()); | |
| 1201 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1176 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1202 | 1177 |
| 1203 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1178 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1204 factory->pending_requests()[0]->script_data()->url()); | 1179 factory->pending_requests()[0]->script_data()->url()); |
| 1205 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1180 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1206 | 1181 |
| 1207 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1182 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1208 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1183 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1209 | 1184 |
| 1210 // Set the result in proxy resolver. | 1185 // Set the result in proxy resolver. |
| 1211 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1186 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1212 "foopy1:8080;foopy2:9090"); | 1187 "foopy1:8080;foopy2:9090"); |
| 1213 resolver.pending_requests()[0]->CompleteNow(OK); | 1188 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1214 | 1189 |
| 1215 // The first item is valid. | 1190 // The first item is valid. |
| 1216 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1191 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 1217 EXPECT_FALSE(info.is_direct()); | 1192 EXPECT_FALSE(info.is_direct()); |
| 1218 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1193 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1219 | 1194 |
| 1220 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1195 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
| 1221 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1196 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
| 1222 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1197 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
| 1223 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); | 1198 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); |
| 1224 base::TimeTicks proxy_resolve_end_time = info.proxy_resolve_end_time(); | 1199 base::TimeTicks proxy_resolve_end_time = info.proxy_resolve_end_time(); |
| 1225 | 1200 |
| 1226 // Fake an error on the proxy. | 1201 // Fake an error on the proxy. |
| 1227 TestCompletionCallback callback2; | 1202 TestCompletionCallback callback2; |
| 1228 rv = service.ReconsiderProxyAfterError( | 1203 rv = service.ReconsiderProxyAfterError( |
| 1229 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1204 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 1230 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1205 callback2.callback(), nullptr, nullptr, BoundNetLog()); |
| 1231 EXPECT_THAT(rv, IsOk()); | 1206 EXPECT_THAT(rv, IsOk()); |
| 1232 | 1207 |
| 1233 // Proxy times should not have been modified by fallback. | 1208 // Proxy times should not have been modified by fallback. |
| 1234 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 1209 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
| 1235 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 1210 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
| 1236 | 1211 |
| 1237 // The second proxy should be specified. | 1212 // The second proxy should be specified. |
| 1238 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1213 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
| 1239 // Report back that the second proxy worked. This will globally mark the | 1214 // Report back that the second proxy worked. This will globally mark the |
| 1240 // first proxy as bad. | 1215 // first proxy as bad. |
| 1241 TestProxyFallbackProxyDelegate test_delegate; | 1216 TestProxyFallbackProxyDelegate test_delegate; |
| 1242 service.ReportSuccess(info, &test_delegate); | 1217 service.ReportSuccess(info, &test_delegate); |
| 1243 EXPECT_EQ("foopy1:8080", test_delegate.proxy_server().ToURI()); | 1218 EXPECT_EQ("foopy1:8080", test_delegate.proxy_server().ToURI()); |
| 1244 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, | 1219 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, |
| 1245 test_delegate.proxy_fallback_net_error()); | 1220 test_delegate.proxy_fallback_net_error()); |
| 1246 | 1221 |
| 1247 TestCompletionCallback callback3; | 1222 TestCompletionCallback callback3; |
| 1248 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1223 rv = service.ResolveProxy(url, std::string(), &info, callback3.callback(), |
| 1249 callback3.callback(), nullptr, nullptr, | 1224 nullptr, nullptr, BoundNetLog()); |
| 1250 BoundNetLog()); | |
| 1251 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1225 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1252 | 1226 |
| 1253 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1227 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1254 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1228 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1255 | 1229 |
| 1256 // Set the result in proxy resolver -- the second result is already known | 1230 // Set the result in proxy resolver -- the second result is already known |
| 1257 // to be bad, so we will not try to use it initially. | 1231 // to be bad, so we will not try to use it initially. |
| 1258 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1232 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1259 "foopy3:7070;foopy1:8080;foopy2:9090"); | 1233 "foopy3:7070;foopy1:8080;foopy2:9090"); |
| 1260 resolver.pending_requests()[0]->CompleteNow(OK); | 1234 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1261 | 1235 |
| 1262 EXPECT_THAT(callback3.WaitForResult(), IsOk()); | 1236 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
| 1263 EXPECT_FALSE(info.is_direct()); | 1237 EXPECT_FALSE(info.is_direct()); |
| 1264 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 1238 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
| 1265 | 1239 |
| 1266 // Proxy times should have been updated, so get them again. | 1240 // Proxy times should have been updated, so get them again. |
| 1267 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); | 1241 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); |
| 1268 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1242 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
| 1269 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1243 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
| 1270 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1244 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
| 1271 proxy_resolve_start_time = info.proxy_resolve_start_time(); | 1245 proxy_resolve_start_time = info.proxy_resolve_start_time(); |
| 1272 proxy_resolve_end_time = info.proxy_resolve_end_time(); | 1246 proxy_resolve_end_time = info.proxy_resolve_end_time(); |
| 1273 | 1247 |
| 1274 // We fake another error. It should now try the third one. | 1248 // We fake another error. It should now try the third one. |
| 1275 TestCompletionCallback callback4; | 1249 TestCompletionCallback callback4; |
| 1276 rv = service.ReconsiderProxyAfterError( | 1250 rv = service.ReconsiderProxyAfterError( |
| 1277 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1251 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 1278 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1252 callback4.callback(), nullptr, nullptr, BoundNetLog()); |
| 1279 EXPECT_THAT(rv, IsOk()); | 1253 EXPECT_THAT(rv, IsOk()); |
| 1280 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1254 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
| 1281 | 1255 |
| 1282 // We fake another error. At this point we have tried all of the | 1256 // We fake another error. At this point we have tried all of the |
| 1283 // proxy servers we thought were valid; next we try the proxy server | 1257 // proxy servers we thought were valid; next we try the proxy server |
| 1284 // that was in our bad proxies map (foopy1:8080). | 1258 // that was in our bad proxies map (foopy1:8080). |
| 1285 TestCompletionCallback callback5; | 1259 TestCompletionCallback callback5; |
| 1286 rv = service.ReconsiderProxyAfterError( | 1260 rv = service.ReconsiderProxyAfterError( |
| 1287 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1261 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 1288 callback5.callback(), nullptr, nullptr, BoundNetLog()); | 1262 callback5.callback(), nullptr, nullptr, BoundNetLog()); |
| 1289 EXPECT_THAT(rv, IsOk()); | 1263 EXPECT_THAT(rv, IsOk()); |
| 1290 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1264 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1291 | 1265 |
| 1292 // Fake another error, the last proxy is gone, the list should now be empty, | 1266 // Fake another error, the last proxy is gone, the list should now be empty, |
| 1293 // so there is nothing left to try. | 1267 // so there is nothing left to try. |
| 1294 TestCompletionCallback callback6; | 1268 TestCompletionCallback callback6; |
| 1295 rv = service.ReconsiderProxyAfterError( | 1269 rv = service.ReconsiderProxyAfterError( |
| 1296 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1270 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 1297 callback6.callback(), nullptr, nullptr, BoundNetLog()); | 1271 callback6.callback(), nullptr, nullptr, BoundNetLog()); |
| 1298 EXPECT_THAT(rv, IsError(ERR_FAILED)); | 1272 EXPECT_THAT(rv, IsError(ERR_FAILED)); |
| 1299 EXPECT_FALSE(info.is_direct()); | 1273 EXPECT_FALSE(info.is_direct()); |
| 1300 EXPECT_TRUE(info.is_empty()); | 1274 EXPECT_TRUE(info.is_empty()); |
| 1301 | 1275 |
| 1302 // Proxy times should not have been modified by fallback. | 1276 // Proxy times should not have been modified by fallback. |
| 1303 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 1277 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
| 1304 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 1278 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
| 1305 | 1279 |
| 1306 // Look up proxies again | 1280 // Look up proxies again |
| 1307 TestCompletionCallback callback7; | 1281 TestCompletionCallback callback7; |
| 1308 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1282 rv = service.ResolveProxy(url, std::string(), &info, callback7.callback(), |
| 1309 callback7.callback(), nullptr, nullptr, | 1283 nullptr, nullptr, BoundNetLog()); |
| 1310 BoundNetLog()); | |
| 1311 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1284 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1312 | 1285 |
| 1313 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1286 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1314 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1287 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1315 | 1288 |
| 1316 // This time, the first 3 results have been found to be bad, but only the | 1289 // This time, the first 3 results have been found to be bad, but only the |
| 1317 // first proxy has been confirmed ... | 1290 // first proxy has been confirmed ... |
| 1318 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1291 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1319 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); | 1292 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); |
| 1320 resolver.pending_requests()[0]->CompleteNow(OK); | 1293 resolver.pending_requests()[0]->CompleteNow(OK); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1341 new MockAsyncProxyResolverFactory(false); | 1314 new MockAsyncProxyResolverFactory(false); |
| 1342 | 1315 |
| 1343 ProxyService service(base::WrapUnique(config_service), | 1316 ProxyService service(base::WrapUnique(config_service), |
| 1344 base::WrapUnique(factory), nullptr); | 1317 base::WrapUnique(factory), nullptr); |
| 1345 | 1318 |
| 1346 GURL url("http://www.google.com/"); | 1319 GURL url("http://www.google.com/"); |
| 1347 | 1320 |
| 1348 // Get the proxy information. | 1321 // Get the proxy information. |
| 1349 ProxyInfo info; | 1322 ProxyInfo info; |
| 1350 TestCompletionCallback callback1; | 1323 TestCompletionCallback callback1; |
| 1351 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1324 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
| 1352 callback1.callback(), nullptr, nullptr, | 1325 nullptr, nullptr, BoundNetLog()); |
| 1353 BoundNetLog()); | |
| 1354 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1326 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1355 | 1327 |
| 1356 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1328 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1357 factory->pending_requests()[0]->script_data()->url()); | 1329 factory->pending_requests()[0]->script_data()->url()); |
| 1358 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1330 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1359 | 1331 |
| 1360 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1332 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1361 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1333 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1362 | 1334 |
| 1363 // Set the result in proxy resolver. | 1335 // Set the result in proxy resolver. |
| 1364 resolver.pending_requests()[0]->results()->UsePacString( | 1336 resolver.pending_requests()[0]->results()->UsePacString( |
| 1365 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); | 1337 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); |
| 1366 resolver.pending_requests()[0]->CompleteNow(OK); | 1338 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1367 | 1339 |
| 1368 // Get the first result. | 1340 // Get the first result. |
| 1369 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1341 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 1370 EXPECT_FALSE(info.is_direct()); | 1342 EXPECT_FALSE(info.is_direct()); |
| 1371 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1343 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1372 | 1344 |
| 1373 // Fake an error on the proxy. | 1345 // Fake an error on the proxy. |
| 1374 TestCompletionCallback callback2; | 1346 TestCompletionCallback callback2; |
| 1375 rv = service.ReconsiderProxyAfterError( | 1347 rv = service.ReconsiderProxyAfterError( |
| 1376 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1348 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 1377 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1349 callback2.callback(), nullptr, nullptr, BoundNetLog()); |
| 1378 EXPECT_THAT(rv, IsOk()); | 1350 EXPECT_THAT(rv, IsOk()); |
| 1379 | 1351 |
| 1380 // Now we get back the second proxy. | 1352 // Now we get back the second proxy. |
| 1381 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1353 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
| 1382 | 1354 |
| 1383 // Fake an error on this proxy as well. | 1355 // Fake an error on this proxy as well. |
| 1384 TestCompletionCallback callback3; | 1356 TestCompletionCallback callback3; |
| 1385 rv = service.ReconsiderProxyAfterError( | 1357 rv = service.ReconsiderProxyAfterError( |
| 1386 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1358 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 1387 callback3.callback(), nullptr, nullptr, BoundNetLog()); | 1359 callback3.callback(), nullptr, nullptr, BoundNetLog()); |
| 1388 EXPECT_THAT(rv, IsOk()); | 1360 EXPECT_THAT(rv, IsOk()); |
| 1389 | 1361 |
| 1390 // Finally, we get back DIRECT. | 1362 // Finally, we get back DIRECT. |
| 1391 EXPECT_TRUE(info.is_direct()); | 1363 EXPECT_TRUE(info.is_direct()); |
| 1392 | 1364 |
| 1393 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1365 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
| 1394 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1366 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
| 1395 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1367 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
| 1396 | 1368 |
| 1397 // Now we tell the proxy service that even DIRECT failed. | 1369 // Now we tell the proxy service that even DIRECT failed. |
| 1398 TestCompletionCallback callback4; | 1370 TestCompletionCallback callback4; |
| 1399 rv = service.ReconsiderProxyAfterError( | 1371 rv = service.ReconsiderProxyAfterError( |
| 1400 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1372 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 1401 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1373 callback4.callback(), nullptr, nullptr, BoundNetLog()); |
| 1402 // There was nothing left to try after DIRECT, so we are out of | 1374 // There was nothing left to try after DIRECT, so we are out of |
| 1403 // choices. | 1375 // choices. |
| 1404 EXPECT_THAT(rv, IsError(ERR_FAILED)); | 1376 EXPECT_THAT(rv, IsError(ERR_FAILED)); |
| 1405 } | 1377 } |
| 1406 | 1378 |
| 1407 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { | 1379 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { |
| 1408 // Test proxy failover when new settings are available. | 1380 // Test proxy failover when new settings are available. |
| 1409 | 1381 |
| 1410 MockProxyConfigService* config_service = | 1382 MockProxyConfigService* config_service = |
| 1411 new MockProxyConfigService("http://foopy/proxy.pac"); | 1383 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1412 | 1384 |
| 1413 MockAsyncProxyResolver resolver; | 1385 MockAsyncProxyResolver resolver; |
| 1414 MockAsyncProxyResolverFactory* factory = | 1386 MockAsyncProxyResolverFactory* factory = |
| 1415 new MockAsyncProxyResolverFactory(false); | 1387 new MockAsyncProxyResolverFactory(false); |
| 1416 | 1388 |
| 1417 ProxyService service(base::WrapUnique(config_service), | 1389 ProxyService service(base::WrapUnique(config_service), |
| 1418 base::WrapUnique(factory), nullptr); | 1390 base::WrapUnique(factory), nullptr); |
| 1419 | 1391 |
| 1420 GURL url("http://www.google.com/"); | 1392 GURL url("http://www.google.com/"); |
| 1421 | 1393 |
| 1422 // Get the proxy information. | 1394 // Get the proxy information. |
| 1423 ProxyInfo info; | 1395 ProxyInfo info; |
| 1424 TestCompletionCallback callback1; | 1396 TestCompletionCallback callback1; |
| 1425 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1397 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
| 1426 callback1.callback(), nullptr, nullptr, | 1398 nullptr, nullptr, BoundNetLog()); |
| 1427 BoundNetLog()); | |
| 1428 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1399 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1429 | 1400 |
| 1430 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1401 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1431 factory->pending_requests()[0]->script_data()->url()); | 1402 factory->pending_requests()[0]->script_data()->url()); |
| 1432 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1403 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1433 | 1404 |
| 1434 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1405 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1435 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1406 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1436 | 1407 |
| 1437 // Set the result in proxy resolver. | 1408 // Set the result in proxy resolver. |
| 1438 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1409 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1439 "foopy1:8080;foopy2:9090"); | 1410 "foopy1:8080;foopy2:9090"); |
| 1440 resolver.pending_requests()[0]->CompleteNow(OK); | 1411 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1441 | 1412 |
| 1442 // The first item is valid. | 1413 // The first item is valid. |
| 1443 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1414 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 1444 EXPECT_FALSE(info.is_direct()); | 1415 EXPECT_FALSE(info.is_direct()); |
| 1445 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1416 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1446 | 1417 |
| 1447 // Fake an error on the proxy, and also a new configuration on the proxy. | 1418 // Fake an error on the proxy, and also a new configuration on the proxy. |
| 1448 config_service->SetConfig( | 1419 config_service->SetConfig( |
| 1449 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); | 1420 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); |
| 1450 | 1421 |
| 1451 TestCompletionCallback callback2; | 1422 TestCompletionCallback callback2; |
| 1452 rv = service.ReconsiderProxyAfterError( | 1423 rv = service.ReconsiderProxyAfterError( |
| 1453 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1424 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 1454 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1425 callback2.callback(), nullptr, nullptr, BoundNetLog()); |
| 1455 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1426 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1456 | 1427 |
| 1457 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), | 1428 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), |
| 1458 factory->pending_requests()[0]->script_data()->url()); | 1429 factory->pending_requests()[0]->script_data()->url()); |
| 1459 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1430 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1460 | 1431 |
| 1461 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1432 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1462 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1433 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1463 | 1434 |
| 1464 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1435 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1465 "foopy1:8080;foopy2:9090"); | 1436 "foopy1:8080;foopy2:9090"); |
| 1466 resolver.pending_requests()[0]->CompleteNow(OK); | 1437 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1467 | 1438 |
| 1468 // The first proxy is still there since the configuration changed. | 1439 // The first proxy is still there since the configuration changed. |
| 1469 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 1440 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 1470 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1441 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1471 | 1442 |
| 1472 // We fake another error. It should now ignore the first one. | 1443 // We fake another error. It should now ignore the first one. |
| 1473 TestCompletionCallback callback3; | 1444 TestCompletionCallback callback3; |
| 1474 rv = service.ReconsiderProxyAfterError( | 1445 rv = service.ReconsiderProxyAfterError( |
| 1475 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1446 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 1476 callback3.callback(), nullptr, nullptr, BoundNetLog()); | 1447 callback3.callback(), nullptr, nullptr, BoundNetLog()); |
| 1477 EXPECT_THAT(rv, IsOk()); | 1448 EXPECT_THAT(rv, IsOk()); |
| 1478 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1449 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
| 1479 | 1450 |
| 1480 // We simulate a new configuration. | 1451 // We simulate a new configuration. |
| 1481 config_service->SetConfig( | 1452 config_service->SetConfig( |
| 1482 ProxyConfig::CreateFromCustomPacURL( | 1453 ProxyConfig::CreateFromCustomPacURL( |
| 1483 GURL("http://foopy-new2/proxy.pac"))); | 1454 GURL("http://foopy-new2/proxy.pac"))); |
| 1484 | 1455 |
| 1485 // We fake another error. It should go back to the first proxy. | 1456 // We fake another error. It should go back to the first proxy. |
| 1486 TestCompletionCallback callback4; | 1457 TestCompletionCallback callback4; |
| 1487 rv = service.ReconsiderProxyAfterError( | 1458 rv = service.ReconsiderProxyAfterError( |
| 1488 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1459 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 1489 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1460 callback4.callback(), nullptr, nullptr, BoundNetLog()); |
| 1490 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1461 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1491 | 1462 |
| 1492 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), | 1463 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), |
| 1493 factory->pending_requests()[0]->script_data()->url()); | 1464 factory->pending_requests()[0]->script_data()->url()); |
| 1494 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1465 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1495 | 1466 |
| 1496 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1467 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1497 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1468 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1498 | 1469 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1519 new MockAsyncProxyResolverFactory(false); | 1490 new MockAsyncProxyResolverFactory(false); |
| 1520 | 1491 |
| 1521 ProxyService service(base::WrapUnique(config_service), | 1492 ProxyService service(base::WrapUnique(config_service), |
| 1522 base::WrapUnique(factory), nullptr); | 1493 base::WrapUnique(factory), nullptr); |
| 1523 | 1494 |
| 1524 GURL url("http://www.google.com/"); | 1495 GURL url("http://www.google.com/"); |
| 1525 | 1496 |
| 1526 // Get the proxy information. | 1497 // Get the proxy information. |
| 1527 ProxyInfo info; | 1498 ProxyInfo info; |
| 1528 TestCompletionCallback callback1; | 1499 TestCompletionCallback callback1; |
| 1529 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1500 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
| 1530 callback1.callback(), nullptr, nullptr, | 1501 nullptr, nullptr, BoundNetLog()); |
| 1531 BoundNetLog()); | |
| 1532 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1502 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1533 | 1503 |
| 1534 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1504 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1535 factory->pending_requests()[0]->script_data()->url()); | 1505 factory->pending_requests()[0]->script_data()->url()); |
| 1536 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1506 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1537 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1507 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1538 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1508 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1539 | 1509 |
| 1540 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1510 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1541 "foopy1:8080;foopy2:9090"); | 1511 "foopy1:8080;foopy2:9090"); |
| 1542 resolver.pending_requests()[0]->CompleteNow(OK); | 1512 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1543 | 1513 |
| 1544 // The first item is valid. | 1514 // The first item is valid. |
| 1545 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1515 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 1546 EXPECT_FALSE(info.is_direct()); | 1516 EXPECT_FALSE(info.is_direct()); |
| 1547 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1517 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1548 | 1518 |
| 1549 // Fake a proxy error. | 1519 // Fake a proxy error. |
| 1550 TestCompletionCallback callback2; | 1520 TestCompletionCallback callback2; |
| 1551 rv = service.ReconsiderProxyAfterError( | 1521 rv = service.ReconsiderProxyAfterError( |
| 1552 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1522 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 1553 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1523 callback2.callback(), nullptr, nullptr, BoundNetLog()); |
| 1554 EXPECT_THAT(rv, IsOk()); | 1524 EXPECT_THAT(rv, IsOk()); |
| 1555 | 1525 |
| 1556 // The first proxy is ignored, and the second one is selected. | 1526 // The first proxy is ignored, and the second one is selected. |
| 1557 EXPECT_FALSE(info.is_direct()); | 1527 EXPECT_FALSE(info.is_direct()); |
| 1558 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1528 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
| 1559 | 1529 |
| 1560 // Fake a PAC failure. | 1530 // Fake a PAC failure. |
| 1561 ProxyInfo info2; | 1531 ProxyInfo info2; |
| 1562 TestCompletionCallback callback3; | 1532 TestCompletionCallback callback3; |
| 1563 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info2, | 1533 rv = service.ResolveProxy(url, std::string(), &info2, callback3.callback(), |
| 1564 callback3.callback(), nullptr, nullptr, | 1534 nullptr, nullptr, BoundNetLog()); |
| 1565 BoundNetLog()); | |
| 1566 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1535 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1567 | 1536 |
| 1568 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1537 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1569 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1538 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1570 | 1539 |
| 1571 // This simulates a javascript runtime error in the PAC script. | 1540 // This simulates a javascript runtime error in the PAC script. |
| 1572 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1541 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
| 1573 | 1542 |
| 1574 // Although the resolver failed, the ProxyService will implicitly fall-back | 1543 // Although the resolver failed, the ProxyService will implicitly fall-back |
| 1575 // to a DIRECT connection. | 1544 // to a DIRECT connection. |
| 1576 EXPECT_THAT(callback3.WaitForResult(), IsOk()); | 1545 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
| 1577 EXPECT_TRUE(info2.is_direct()); | 1546 EXPECT_TRUE(info2.is_direct()); |
| 1578 EXPECT_FALSE(info2.is_empty()); | 1547 EXPECT_FALSE(info2.is_empty()); |
| 1579 | 1548 |
| 1580 // The PAC script will work properly next time and successfully return a | 1549 // The PAC script will work properly next time and successfully return a |
| 1581 // proxy list. Since we have not marked the configuration as bad, it should | 1550 // proxy list. Since we have not marked the configuration as bad, it should |
| 1582 // "just work" the next time we call it. | 1551 // "just work" the next time we call it. |
| 1583 ProxyInfo info3; | 1552 ProxyInfo info3; |
| 1584 TestCompletionCallback callback4; | 1553 TestCompletionCallback callback4; |
| 1585 rv = service.ReconsiderProxyAfterError( | 1554 rv = service.ReconsiderProxyAfterError( |
| 1586 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, | 1555 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info3, |
| 1587 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1556 callback4.callback(), nullptr, nullptr, BoundNetLog()); |
| 1588 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1557 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1589 | 1558 |
| 1590 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1559 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1591 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1560 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1592 | 1561 |
| 1593 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1562 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1594 "foopy1:8080;foopy2:9090"); | 1563 "foopy1:8080;foopy2:9090"); |
| 1595 resolver.pending_requests()[0]->CompleteNow(OK); | 1564 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1596 | 1565 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1619 new MockAsyncProxyResolverFactory(false); | 1588 new MockAsyncProxyResolverFactory(false); |
| 1620 | 1589 |
| 1621 ProxyService service(base::WrapUnique(config_service), | 1590 ProxyService service(base::WrapUnique(config_service), |
| 1622 base::WrapUnique(factory), nullptr); | 1591 base::WrapUnique(factory), nullptr); |
| 1623 | 1592 |
| 1624 GURL url("http://www.google.com/"); | 1593 GURL url("http://www.google.com/"); |
| 1625 | 1594 |
| 1626 // Get the proxy information. | 1595 // Get the proxy information. |
| 1627 ProxyInfo info; | 1596 ProxyInfo info; |
| 1628 TestCompletionCallback callback1; | 1597 TestCompletionCallback callback1; |
| 1629 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1598 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
| 1630 callback1.callback(), nullptr, nullptr, | 1599 nullptr, nullptr, BoundNetLog()); |
| 1631 BoundNetLog()); | |
| 1632 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1600 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1633 | 1601 |
| 1634 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1602 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1635 factory->pending_requests()[0]->script_data()->url()); | 1603 factory->pending_requests()[0]->script_data()->url()); |
| 1636 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1604 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1637 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1605 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1638 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1606 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1639 | 1607 |
| 1640 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1608 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1641 "foopy1:8080;foopy2:9090"); | 1609 "foopy1:8080;foopy2:9090"); |
| 1642 resolver.pending_requests()[0]->CompleteNow(OK); | 1610 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1643 | 1611 |
| 1644 // The first item is valid. | 1612 // The first item is valid. |
| 1645 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1613 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 1646 EXPECT_FALSE(info.is_direct()); | 1614 EXPECT_FALSE(info.is_direct()); |
| 1647 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1615 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1648 | 1616 |
| 1649 // Fake a proxy error. | 1617 // Fake a proxy error. |
| 1650 TestCompletionCallback callback2; | 1618 TestCompletionCallback callback2; |
| 1651 rv = service.ReconsiderProxyAfterError( | 1619 rv = service.ReconsiderProxyAfterError( |
| 1652 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1620 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
| 1653 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1621 callback2.callback(), nullptr, nullptr, BoundNetLog()); |
| 1654 EXPECT_THAT(rv, IsOk()); | 1622 EXPECT_THAT(rv, IsOk()); |
| 1655 | 1623 |
| 1656 // The first proxy is ignored, and the second one is selected. | 1624 // The first proxy is ignored, and the second one is selected. |
| 1657 EXPECT_FALSE(info.is_direct()); | 1625 EXPECT_FALSE(info.is_direct()); |
| 1658 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1626 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
| 1659 | 1627 |
| 1660 // Fake a PAC failure. | 1628 // Fake a PAC failure. |
| 1661 ProxyInfo info2; | 1629 ProxyInfo info2; |
| 1662 TestCompletionCallback callback3; | 1630 TestCompletionCallback callback3; |
| 1663 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info2, | 1631 rv = service.ResolveProxy(url, std::string(), &info2, callback3.callback(), |
| 1664 callback3.callback(), nullptr, nullptr, | 1632 nullptr, nullptr, BoundNetLog()); |
| 1665 BoundNetLog()); | |
| 1666 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1633 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1667 | 1634 |
| 1668 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1635 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1669 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1636 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1670 | 1637 |
| 1671 // This simulates a javascript runtime error in the PAC script. | 1638 // This simulates a javascript runtime error in the PAC script. |
| 1672 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1639 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
| 1673 | 1640 |
| 1674 // Although the resolver failed, the ProxyService will NOT fall-back | 1641 // Although the resolver failed, the ProxyService will NOT fall-back |
| 1675 // to a DIRECT connection as it is configured as mandatory. | 1642 // to a DIRECT connection as it is configured as mandatory. |
| 1676 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1643 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
| 1677 callback3.WaitForResult()); | 1644 callback3.WaitForResult()); |
| 1678 EXPECT_FALSE(info2.is_direct()); | 1645 EXPECT_FALSE(info2.is_direct()); |
| 1679 EXPECT_TRUE(info2.is_empty()); | 1646 EXPECT_TRUE(info2.is_empty()); |
| 1680 | 1647 |
| 1681 // The PAC script will work properly next time and successfully return a | 1648 // The PAC script will work properly next time and successfully return a |
| 1682 // proxy list. Since we have not marked the configuration as bad, it should | 1649 // proxy list. Since we have not marked the configuration as bad, it should |
| 1683 // "just work" the next time we call it. | 1650 // "just work" the next time we call it. |
| 1684 ProxyInfo info3; | 1651 ProxyInfo info3; |
| 1685 TestCompletionCallback callback4; | 1652 TestCompletionCallback callback4; |
| 1686 rv = service.ReconsiderProxyAfterError( | 1653 rv = service.ReconsiderProxyAfterError( |
| 1687 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, | 1654 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info3, |
| 1688 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1655 callback4.callback(), nullptr, nullptr, BoundNetLog()); |
| 1689 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1656 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1690 | 1657 |
| 1691 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1658 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1692 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1659 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1693 | 1660 |
| 1694 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1661 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1695 "foopy1:8080;foopy2:9090"); | 1662 "foopy1:8080;foopy2:9090"); |
| 1696 resolver.pending_requests()[0]->CompleteNow(OK); | 1663 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1697 | 1664 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1713 config.proxy_rules().bypass_rules.ParseFromString("*.org"); | 1680 config.proxy_rules().bypass_rules.ParseFromString("*.org"); |
| 1714 | 1681 |
| 1715 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1682 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 1716 nullptr, nullptr); | 1683 nullptr, nullptr); |
| 1717 | 1684 |
| 1718 int rv; | 1685 int rv; |
| 1719 GURL url1("http://www.webkit.org"); | 1686 GURL url1("http://www.webkit.org"); |
| 1720 GURL url2("http://www.webkit.com"); | 1687 GURL url2("http://www.webkit.com"); |
| 1721 | 1688 |
| 1722 // Request for a .org domain should bypass proxy. | 1689 // Request for a .org domain should bypass proxy. |
| 1723 rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info[0], | 1690 rv = service.ResolveProxy(url1, std::string(), &info[0], |
| 1724 callback[0].callback(), nullptr, nullptr, | 1691 callback[0].callback(), nullptr, nullptr, |
| 1725 BoundNetLog()); | 1692 BoundNetLog()); |
| 1726 EXPECT_THAT(rv, IsOk()); | 1693 EXPECT_THAT(rv, IsOk()); |
| 1727 EXPECT_TRUE(info[0].is_direct()); | 1694 EXPECT_TRUE(info[0].is_direct()); |
| 1728 | 1695 |
| 1729 // Request for a .com domain hits the proxy. | 1696 // Request for a .com domain hits the proxy. |
| 1730 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info[1], | 1697 rv = service.ResolveProxy(url2, std::string(), &info[1], |
| 1731 callback[1].callback(), nullptr, nullptr, | 1698 callback[1].callback(), nullptr, nullptr, |
| 1732 BoundNetLog()); | 1699 BoundNetLog()); |
| 1733 EXPECT_THAT(rv, IsOk()); | 1700 EXPECT_THAT(rv, IsOk()); |
| 1734 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); | 1701 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); |
| 1735 } | 1702 } |
| 1736 | 1703 |
| 1737 TEST_F(ProxyServiceTest, MarkProxiesAsBadTests) { | 1704 TEST_F(ProxyServiceTest, MarkProxiesAsBadTests) { |
| 1738 ProxyConfig config; | 1705 ProxyConfig config; |
| 1739 config.proxy_rules().ParseFromString( | 1706 config.proxy_rules().ParseFromString( |
| 1740 "http=foopy1:8080;http=foopy2:8080;http=foopy3.8080;http=foopy4:8080"); | 1707 "http=foopy1:8080;http=foopy2:8080;http=foopy3.8080;http=foopy4:8080"); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { | 1739 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { |
| 1773 ProxyConfig config; | 1740 ProxyConfig config; |
| 1774 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); | 1741 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); |
| 1775 config.set_auto_detect(false); | 1742 config.set_auto_detect(false); |
| 1776 { | 1743 { |
| 1777 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1744 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 1778 nullptr, nullptr); | 1745 nullptr, nullptr); |
| 1779 GURL test_url("http://www.msn.com"); | 1746 GURL test_url("http://www.msn.com"); |
| 1780 ProxyInfo info; | 1747 ProxyInfo info; |
| 1781 TestCompletionCallback callback; | 1748 TestCompletionCallback callback; |
| 1782 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1749 int rv = service.ResolveProxy(test_url, std::string(), &info, |
| 1783 callback.callback(), nullptr, nullptr, | 1750 callback.callback(), nullptr, nullptr, |
| 1784 BoundNetLog()); | 1751 BoundNetLog()); |
| 1785 EXPECT_THAT(rv, IsOk()); | 1752 EXPECT_THAT(rv, IsOk()); |
| 1786 EXPECT_FALSE(info.is_direct()); | 1753 EXPECT_FALSE(info.is_direct()); |
| 1787 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1754 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1788 } | 1755 } |
| 1789 { | 1756 { |
| 1790 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1757 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 1791 nullptr, nullptr); | 1758 nullptr, nullptr); |
| 1792 GURL test_url("ftp://ftp.google.com"); | 1759 GURL test_url("ftp://ftp.google.com"); |
| 1793 ProxyInfo info; | 1760 ProxyInfo info; |
| 1794 TestCompletionCallback callback; | 1761 TestCompletionCallback callback; |
| 1795 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1762 int rv = service.ResolveProxy(test_url, std::string(), &info, |
| 1796 callback.callback(), nullptr, nullptr, | 1763 callback.callback(), nullptr, nullptr, |
| 1797 BoundNetLog()); | 1764 BoundNetLog()); |
| 1798 EXPECT_THAT(rv, IsOk()); | 1765 EXPECT_THAT(rv, IsOk()); |
| 1799 EXPECT_TRUE(info.is_direct()); | 1766 EXPECT_TRUE(info.is_direct()); |
| 1800 EXPECT_EQ("direct://", info.proxy_server().ToURI()); | 1767 EXPECT_EQ("direct://", info.proxy_server().ToURI()); |
| 1801 } | 1768 } |
| 1802 { | 1769 { |
| 1803 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1770 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 1804 nullptr, nullptr); | 1771 nullptr, nullptr); |
| 1805 GURL test_url("https://webbranch.techcu.com"); | 1772 GURL test_url("https://webbranch.techcu.com"); |
| 1806 ProxyInfo info; | 1773 ProxyInfo info; |
| 1807 TestCompletionCallback callback; | 1774 TestCompletionCallback callback; |
| 1808 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1775 int rv = service.ResolveProxy(test_url, std::string(), &info, |
| 1809 callback.callback(), nullptr, nullptr, | 1776 callback.callback(), nullptr, nullptr, |
| 1810 BoundNetLog()); | 1777 BoundNetLog()); |
| 1811 EXPECT_THAT(rv, IsOk()); | 1778 EXPECT_THAT(rv, IsOk()); |
| 1812 EXPECT_FALSE(info.is_direct()); | 1779 EXPECT_FALSE(info.is_direct()); |
| 1813 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 1780 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
| 1814 } | 1781 } |
| 1815 { | 1782 { |
| 1816 config.proxy_rules().ParseFromString("foopy1:8080"); | 1783 config.proxy_rules().ParseFromString("foopy1:8080"); |
| 1817 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1784 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 1818 nullptr, nullptr); | 1785 nullptr, nullptr); |
| 1819 GURL test_url("http://www.microsoft.com"); | 1786 GURL test_url("http://www.microsoft.com"); |
| 1820 ProxyInfo info; | 1787 ProxyInfo info; |
| 1821 TestCompletionCallback callback; | 1788 TestCompletionCallback callback; |
| 1822 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1789 int rv = service.ResolveProxy(test_url, std::string(), &info, |
| 1823 callback.callback(), nullptr, nullptr, | 1790 callback.callback(), nullptr, nullptr, |
| 1824 BoundNetLog()); | 1791 BoundNetLog()); |
| 1825 EXPECT_THAT(rv, IsOk()); | 1792 EXPECT_THAT(rv, IsOk()); |
| 1826 EXPECT_FALSE(info.is_direct()); | 1793 EXPECT_FALSE(info.is_direct()); |
| 1827 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1794 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1828 } | 1795 } |
| 1829 } | 1796 } |
| 1830 | 1797 |
| 1831 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { | 1798 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { |
| 1832 // Test that the proxy config source is set correctly when resolving proxies | 1799 // Test that the proxy config source is set correctly when resolving proxies |
| 1833 // using manual proxy rules. Namely, the config source should only be set if | 1800 // using manual proxy rules. Namely, the config source should only be set if |
| 1834 // any of the rules were applied. | 1801 // any of the rules were applied. |
| 1835 { | 1802 { |
| 1836 ProxyConfig config; | 1803 ProxyConfig config; |
| 1837 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1804 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
| 1838 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1805 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
| 1839 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1806 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 1840 nullptr, nullptr); | 1807 nullptr, nullptr); |
| 1841 GURL test_url("http://www.google.com"); | 1808 GURL test_url("http://www.google.com"); |
| 1842 ProxyInfo info; | 1809 ProxyInfo info; |
| 1843 TestCompletionCallback callback; | 1810 TestCompletionCallback callback; |
| 1844 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1811 int rv = service.ResolveProxy(test_url, std::string(), &info, |
| 1845 callback.callback(), nullptr, nullptr, | 1812 callback.callback(), nullptr, nullptr, |
| 1846 BoundNetLog()); | 1813 BoundNetLog()); |
| 1847 ASSERT_THAT(rv, IsOk()); | 1814 ASSERT_THAT(rv, IsOk()); |
| 1848 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. | 1815 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. |
| 1849 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1816 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
| 1850 } | 1817 } |
| 1851 { | 1818 { |
| 1852 ProxyConfig config; | 1819 ProxyConfig config; |
| 1853 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1820 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
| 1854 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1821 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
| 1855 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1822 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 1856 nullptr, nullptr); | 1823 nullptr, nullptr); |
| 1857 GURL test_url("https://www.google.com"); | 1824 GURL test_url("https://www.google.com"); |
| 1858 ProxyInfo info; | 1825 ProxyInfo info; |
| 1859 TestCompletionCallback callback; | 1826 TestCompletionCallback callback; |
| 1860 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1827 int rv = service.ResolveProxy(test_url, std::string(), &info, |
| 1861 callback.callback(), nullptr, nullptr, | 1828 callback.callback(), nullptr, nullptr, |
| 1862 BoundNetLog()); | 1829 BoundNetLog()); |
| 1863 ASSERT_THAT(rv, IsOk()); | 1830 ASSERT_THAT(rv, IsOk()); |
| 1864 // Used the HTTPS proxy. So source should be TEST. | 1831 // Used the HTTPS proxy. So source should be TEST. |
| 1865 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1832 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
| 1866 } | 1833 } |
| 1867 { | 1834 { |
| 1868 ProxyConfig config; | 1835 ProxyConfig config; |
| 1869 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1836 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
| 1870 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1837 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 1871 nullptr, nullptr); | 1838 nullptr, nullptr); |
| 1872 GURL test_url("http://www.google.com"); | 1839 GURL test_url("http://www.google.com"); |
| 1873 ProxyInfo info; | 1840 ProxyInfo info; |
| 1874 TestCompletionCallback callback; | 1841 TestCompletionCallback callback; |
| 1875 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1842 int rv = service.ResolveProxy(test_url, std::string(), &info, |
| 1876 callback.callback(), nullptr, nullptr, | 1843 callback.callback(), nullptr, nullptr, |
| 1877 BoundNetLog()); | 1844 BoundNetLog()); |
| 1878 ASSERT_THAT(rv, IsOk()); | 1845 ASSERT_THAT(rv, IsOk()); |
| 1879 // ProxyConfig is empty. Source should still be TEST. | 1846 // ProxyConfig is empty. Source should still be TEST. |
| 1880 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1847 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
| 1881 } | 1848 } |
| 1882 } | 1849 } |
| 1883 | 1850 |
| 1884 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries | 1851 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries |
| 1885 // fall back to the SOCKS proxy. | 1852 // fall back to the SOCKS proxy. |
| 1886 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { | 1853 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { |
| 1887 ProxyConfig config; | 1854 ProxyConfig config; |
| 1888 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); | 1855 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); |
| 1889 config.set_auto_detect(false); | 1856 config.set_auto_detect(false); |
| 1890 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 1857 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
| 1891 config.proxy_rules().type); | 1858 config.proxy_rules().type); |
| 1892 | 1859 |
| 1893 { | 1860 { |
| 1894 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1861 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 1895 nullptr, nullptr); | 1862 nullptr, nullptr); |
| 1896 GURL test_url("http://www.msn.com"); | 1863 GURL test_url("http://www.msn.com"); |
| 1897 ProxyInfo info; | 1864 ProxyInfo info; |
| 1898 TestCompletionCallback callback; | 1865 TestCompletionCallback callback; |
| 1899 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1866 int rv = service.ResolveProxy(test_url, std::string(), &info, |
| 1900 callback.callback(), nullptr, nullptr, | 1867 callback.callback(), nullptr, nullptr, |
| 1901 BoundNetLog()); | 1868 BoundNetLog()); |
| 1902 EXPECT_THAT(rv, IsOk()); | 1869 EXPECT_THAT(rv, IsOk()); |
| 1903 EXPECT_FALSE(info.is_direct()); | 1870 EXPECT_FALSE(info.is_direct()); |
| 1904 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1871 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1905 } | 1872 } |
| 1906 { | 1873 { |
| 1907 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1874 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 1908 nullptr, nullptr); | 1875 nullptr, nullptr); |
| 1909 GURL test_url("ftp://ftp.google.com"); | 1876 GURL test_url("ftp://ftp.google.com"); |
| 1910 ProxyInfo info; | 1877 ProxyInfo info; |
| 1911 TestCompletionCallback callback; | 1878 TestCompletionCallback callback; |
| 1912 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1879 int rv = service.ResolveProxy(test_url, std::string(), &info, |
| 1913 callback.callback(), nullptr, nullptr, | 1880 callback.callback(), nullptr, nullptr, |
| 1914 BoundNetLog()); | 1881 BoundNetLog()); |
| 1915 EXPECT_THAT(rv, IsOk()); | 1882 EXPECT_THAT(rv, IsOk()); |
| 1916 EXPECT_FALSE(info.is_direct()); | 1883 EXPECT_FALSE(info.is_direct()); |
| 1917 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1884 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
| 1918 } | 1885 } |
| 1919 { | 1886 { |
| 1920 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1887 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 1921 nullptr, nullptr); | 1888 nullptr, nullptr); |
| 1922 GURL test_url("https://webbranch.techcu.com"); | 1889 GURL test_url("https://webbranch.techcu.com"); |
| 1923 ProxyInfo info; | 1890 ProxyInfo info; |
| 1924 TestCompletionCallback callback; | 1891 TestCompletionCallback callback; |
| 1925 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1892 int rv = service.ResolveProxy(test_url, std::string(), &info, |
| 1926 callback.callback(), nullptr, nullptr, | 1893 callback.callback(), nullptr, nullptr, |
| 1927 BoundNetLog()); | 1894 BoundNetLog()); |
| 1928 EXPECT_THAT(rv, IsOk()); | 1895 EXPECT_THAT(rv, IsOk()); |
| 1929 EXPECT_FALSE(info.is_direct()); | 1896 EXPECT_FALSE(info.is_direct()); |
| 1930 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1897 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
| 1931 } | 1898 } |
| 1932 { | 1899 { |
| 1933 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1900 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 1934 nullptr, nullptr); | 1901 nullptr, nullptr); |
| 1935 GURL test_url("unknown://www.microsoft.com"); | 1902 GURL test_url("unknown://www.microsoft.com"); |
| 1936 ProxyInfo info; | 1903 ProxyInfo info; |
| 1937 TestCompletionCallback callback; | 1904 TestCompletionCallback callback; |
| 1938 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1905 int rv = service.ResolveProxy(test_url, std::string(), &info, |
| 1939 callback.callback(), nullptr, nullptr, | 1906 callback.callback(), nullptr, nullptr, |
| 1940 BoundNetLog()); | 1907 BoundNetLog()); |
| 1941 EXPECT_THAT(rv, IsOk()); | 1908 EXPECT_THAT(rv, IsOk()); |
| 1942 EXPECT_FALSE(info.is_direct()); | 1909 EXPECT_FALSE(info.is_direct()); |
| 1943 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1910 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
| 1944 } | 1911 } |
| 1945 } | 1912 } |
| 1946 | 1913 |
| 1947 // Test cancellation of an in-progress request. | 1914 // Test cancellation of an in-progress request. |
| 1948 TEST_F(ProxyServiceTest, CancelInProgressRequest) { | 1915 TEST_F(ProxyServiceTest, CancelInProgressRequest) { |
| 1949 const GURL url1("http://request1"); | 1916 const GURL url1("http://request1"); |
| 1950 const GURL url2("http://request2"); | 1917 const GURL url2("http://request2"); |
| 1951 const GURL url3("http://request3"); | 1918 const GURL url3("http://request3"); |
| 1952 MockProxyConfigService* config_service = | 1919 MockProxyConfigService* config_service = |
| 1953 new MockProxyConfigService("http://foopy/proxy.pac"); | 1920 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1954 | 1921 |
| 1955 MockAsyncProxyResolver resolver; | 1922 MockAsyncProxyResolver resolver; |
| 1956 MockAsyncProxyResolverFactory* factory = | 1923 MockAsyncProxyResolverFactory* factory = |
| 1957 new MockAsyncProxyResolverFactory(false); | 1924 new MockAsyncProxyResolverFactory(false); |
| 1958 | 1925 |
| 1959 ProxyService service(base::WrapUnique(config_service), | 1926 ProxyService service(base::WrapUnique(config_service), |
| 1960 base::WrapUnique(factory), nullptr); | 1927 base::WrapUnique(factory), nullptr); |
| 1961 | 1928 |
| 1962 // Start 3 requests. | 1929 // Start 3 requests. |
| 1963 | 1930 |
| 1964 ProxyInfo info1; | 1931 ProxyInfo info1; |
| 1965 TestCompletionCallback callback1; | 1932 TestCompletionCallback callback1; |
| 1966 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, | 1933 int rv = |
| 1967 callback1.callback(), nullptr, nullptr, | 1934 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), |
| 1968 BoundNetLog()); | 1935 nullptr, nullptr, BoundNetLog()); |
| 1969 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1936 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1970 | 1937 |
| 1971 // Successfully initialize the PAC script. | 1938 // Successfully initialize the PAC script. |
| 1972 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1939 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1973 factory->pending_requests()[0]->script_data()->url()); | 1940 factory->pending_requests()[0]->script_data()->url()); |
| 1974 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1941 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1975 | 1942 |
| 1976 GetPendingRequestsForURLs(resolver, url1); | 1943 GetPendingRequestsForURLs(resolver, url1); |
| 1977 | 1944 |
| 1978 ProxyInfo info2; | 1945 ProxyInfo info2; |
| 1979 TestCompletionCallback callback2; | 1946 TestCompletionCallback callback2; |
| 1980 ProxyService::PacRequest* request2; | 1947 ProxyService::PacRequest* request2; |
| 1981 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, | 1948 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), |
| 1982 callback2.callback(), &request2, nullptr, | 1949 &request2, nullptr, BoundNetLog()); |
| 1983 BoundNetLog()); | |
| 1984 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1950 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1985 | 1951 |
| 1986 GetPendingRequestsForURLs(resolver, url1, url2); | 1952 GetPendingRequestsForURLs(resolver, url1, url2); |
| 1987 | 1953 |
| 1988 ProxyInfo info3; | 1954 ProxyInfo info3; |
| 1989 TestCompletionCallback callback3; | 1955 TestCompletionCallback callback3; |
| 1990 rv = service.ResolveProxy(url3, std::string(), LOAD_NORMAL, &info3, | 1956 rv = service.ResolveProxy(url3, std::string(), &info3, callback3.callback(), |
| 1991 callback3.callback(), nullptr, nullptr, | 1957 nullptr, nullptr, BoundNetLog()); |
| 1992 BoundNetLog()); | |
| 1993 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1958 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1994 GetPendingRequestsForURLs(resolver, url1, url2, url3); | 1959 GetPendingRequestsForURLs(resolver, url1, url2, url3); |
| 1995 | 1960 |
| 1996 // Cancel the second request | 1961 // Cancel the second request |
| 1997 service.CancelPacRequest(request2); | 1962 service.CancelPacRequest(request2); |
| 1998 | 1963 |
| 1999 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url3); | 1964 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url3); |
| 2000 | 1965 |
| 2001 // Complete the two un-cancelled requests. | 1966 // Complete the two un-cancelled requests. |
| 2002 // We complete the last one first, just to mix it up a bit. | 1967 // We complete the last one first, just to mix it up a bit. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2034 | 1999 |
| 2035 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2000 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2036 service.SetProxyScriptFetchers( | 2001 service.SetProxyScriptFetchers( |
| 2037 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2002 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 2038 | 2003 |
| 2039 // Start 3 requests. | 2004 // Start 3 requests. |
| 2040 | 2005 |
| 2041 ProxyInfo info1; | 2006 ProxyInfo info1; |
| 2042 TestCompletionCallback callback1; | 2007 TestCompletionCallback callback1; |
| 2043 ProxyService::PacRequest* request1; | 2008 ProxyService::PacRequest* request1; |
| 2044 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, | 2009 int rv = |
| 2045 callback1.callback(), &request1, nullptr, | 2010 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), |
| 2046 BoundNetLog()); | 2011 &request1, nullptr, BoundNetLog()); |
| 2047 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2012 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2048 | 2013 |
| 2049 // The first request should have triggered download of PAC script. | 2014 // The first request should have triggered download of PAC script. |
| 2050 EXPECT_TRUE(fetcher->has_pending_request()); | 2015 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2051 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2016 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2052 | 2017 |
| 2053 ProxyInfo info2; | 2018 ProxyInfo info2; |
| 2054 TestCompletionCallback callback2; | 2019 TestCompletionCallback callback2; |
| 2055 ProxyService::PacRequest* request2; | 2020 ProxyService::PacRequest* request2; |
| 2056 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, | 2021 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), |
| 2057 callback2.callback(), &request2, nullptr, | 2022 &request2, nullptr, BoundNetLog()); |
| 2058 BoundNetLog()); | |
| 2059 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2023 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2060 | 2024 |
| 2061 ProxyInfo info3; | 2025 ProxyInfo info3; |
| 2062 TestCompletionCallback callback3; | 2026 TestCompletionCallback callback3; |
| 2063 ProxyService::PacRequest* request3; | 2027 ProxyService::PacRequest* request3; |
| 2064 rv = service.ResolveProxy(url3, std::string(), LOAD_NORMAL, &info3, | 2028 rv = service.ResolveProxy(url3, std::string(), &info3, callback3.callback(), |
| 2065 callback3.callback(), &request3, nullptr, | 2029 &request3, nullptr, BoundNetLog()); |
| 2066 BoundNetLog()); | |
| 2067 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2030 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2068 | 2031 |
| 2069 // Nothing has been sent to the factory yet. | 2032 // Nothing has been sent to the factory yet. |
| 2070 EXPECT_TRUE(factory->pending_requests().empty()); | 2033 EXPECT_TRUE(factory->pending_requests().empty()); |
| 2071 | 2034 |
| 2072 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 2035 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
| 2073 service.GetLoadState(request1)); | 2036 service.GetLoadState(request1)); |
| 2074 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 2037 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
| 2075 service.GetLoadState(request2)); | 2038 service.GetLoadState(request2)); |
| 2076 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 2039 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2139 base::WrapUnique(factory), nullptr); | 2102 base::WrapUnique(factory), nullptr); |
| 2140 | 2103 |
| 2141 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2104 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2142 service.SetProxyScriptFetchers( | 2105 service.SetProxyScriptFetchers( |
| 2143 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2106 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 2144 | 2107 |
| 2145 // Start 2 requests. | 2108 // Start 2 requests. |
| 2146 | 2109 |
| 2147 ProxyInfo info1; | 2110 ProxyInfo info1; |
| 2148 TestCompletionCallback callback1; | 2111 TestCompletionCallback callback1; |
| 2149 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, | 2112 int rv = |
| 2150 callback1.callback(), nullptr, nullptr, | 2113 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), |
| 2151 BoundNetLog()); | 2114 nullptr, nullptr, BoundNetLog()); |
| 2152 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2115 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2153 | 2116 |
| 2154 // The first request should have triggered download of PAC script. | 2117 // The first request should have triggered download of PAC script. |
| 2155 EXPECT_TRUE(fetcher->has_pending_request()); | 2118 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2156 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2119 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2157 | 2120 |
| 2158 ProxyInfo info2; | 2121 ProxyInfo info2; |
| 2159 TestCompletionCallback callback2; | 2122 TestCompletionCallback callback2; |
| 2160 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, | 2123 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), |
| 2161 callback2.callback(), nullptr, nullptr, | 2124 nullptr, nullptr, BoundNetLog()); |
| 2162 BoundNetLog()); | |
| 2163 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2125 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2164 | 2126 |
| 2165 // At this point the ProxyService should be waiting for the | 2127 // At this point the ProxyService should be waiting for the |
| 2166 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2128 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 2167 // PAC script download completion. | 2129 // PAC script download completion. |
| 2168 | 2130 |
| 2169 // We now change out the ProxyService's script fetcher. We should restart | 2131 // We now change out the ProxyService's script fetcher. We should restart |
| 2170 // the initialization with the new fetcher. | 2132 // the initialization with the new fetcher. |
| 2171 | 2133 |
| 2172 fetcher = new MockProxyScriptFetcher; | 2134 fetcher = new MockProxyScriptFetcher; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2201 | 2163 |
| 2202 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2164 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2203 service.SetProxyScriptFetchers( | 2165 service.SetProxyScriptFetchers( |
| 2204 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2166 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 2205 | 2167 |
| 2206 // Start 3 requests. | 2168 // Start 3 requests. |
| 2207 ProxyInfo info1; | 2169 ProxyInfo info1; |
| 2208 TestCompletionCallback callback1; | 2170 TestCompletionCallback callback1; |
| 2209 ProxyService::PacRequest* request1; | 2171 ProxyService::PacRequest* request1; |
| 2210 BoundTestNetLog log1; | 2172 BoundTestNetLog log1; |
| 2211 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 2173 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
| 2212 LOAD_NORMAL, &info1, callback1.callback(), | 2174 callback1.callback(), &request1, nullptr, |
| 2213 &request1, nullptr, log1.bound()); | 2175 log1.bound()); |
| 2214 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2176 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2215 | 2177 |
| 2216 // The first request should have triggered download of PAC script. | 2178 // The first request should have triggered download of PAC script. |
| 2217 EXPECT_TRUE(fetcher->has_pending_request()); | 2179 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2218 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2180 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2219 | 2181 |
| 2220 ProxyInfo info2; | 2182 ProxyInfo info2; |
| 2221 TestCompletionCallback callback2; | 2183 TestCompletionCallback callback2; |
| 2222 ProxyService::PacRequest* request2; | 2184 ProxyService::PacRequest* request2; |
| 2223 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 2185 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
| 2224 &info2, callback2.callback(), &request2, nullptr, | 2186 callback2.callback(), &request2, nullptr, |
| 2225 BoundNetLog()); | 2187 BoundNetLog()); |
| 2226 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2188 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2227 | 2189 |
| 2228 ProxyInfo info3; | 2190 ProxyInfo info3; |
| 2229 TestCompletionCallback callback3; | 2191 TestCompletionCallback callback3; |
| 2230 rv = service.ResolveProxy(GURL("http://request3"), std::string(), LOAD_NORMAL, | 2192 rv = service.ResolveProxy(GURL("http://request3"), std::string(), &info3, |
| 2231 &info3, callback3.callback(), nullptr, nullptr, | 2193 callback3.callback(), nullptr, nullptr, |
| 2232 BoundNetLog()); | 2194 BoundNetLog()); |
| 2233 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2195 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2234 | 2196 |
| 2235 // Nothing has been sent to the factory yet. | 2197 // Nothing has been sent to the factory yet. |
| 2236 EXPECT_TRUE(factory->pending_requests().empty()); | 2198 EXPECT_TRUE(factory->pending_requests().empty()); |
| 2237 | 2199 |
| 2238 // Cancel the first 2 requests. | 2200 // Cancel the first 2 requests. |
| 2239 service.CancelPacRequest(request1); | 2201 service.CancelPacRequest(request1); |
| 2240 service.CancelPacRequest(request2); | 2202 service.CancelPacRequest(request2); |
| 2241 | 2203 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2299 base::WrapUnique(factory), nullptr); | 2261 base::WrapUnique(factory), nullptr); |
| 2300 | 2262 |
| 2301 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2263 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2302 service.SetProxyScriptFetchers( | 2264 service.SetProxyScriptFetchers( |
| 2303 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2265 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 2304 | 2266 |
| 2305 // Start 2 requests. | 2267 // Start 2 requests. |
| 2306 | 2268 |
| 2307 ProxyInfo info1; | 2269 ProxyInfo info1; |
| 2308 TestCompletionCallback callback1; | 2270 TestCompletionCallback callback1; |
| 2309 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, | 2271 int rv = |
| 2310 callback1.callback(), nullptr, nullptr, | 2272 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), |
| 2311 BoundNetLog()); | 2273 nullptr, nullptr, BoundNetLog()); |
| 2312 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2274 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2313 | 2275 |
| 2314 ProxyInfo info2; | 2276 ProxyInfo info2; |
| 2315 TestCompletionCallback callback2; | 2277 TestCompletionCallback callback2; |
| 2316 ProxyService::PacRequest* request2; | 2278 ProxyService::PacRequest* request2; |
| 2317 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, | 2279 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), |
| 2318 callback2.callback(), &request2, nullptr, | 2280 &request2, nullptr, BoundNetLog()); |
| 2319 BoundNetLog()); | |
| 2320 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2281 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2321 | 2282 |
| 2322 // Check that nothing has been sent to the proxy resolver factory yet. | 2283 // Check that nothing has been sent to the proxy resolver factory yet. |
| 2323 ASSERT_EQ(0u, factory->pending_requests().size()); | 2284 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 2324 | 2285 |
| 2325 // It should be trying to auto-detect first -- FAIL the autodetect during | 2286 // It should be trying to auto-detect first -- FAIL the autodetect during |
| 2326 // the script download. | 2287 // the script download. |
| 2327 EXPECT_TRUE(fetcher->has_pending_request()); | 2288 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2328 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2289 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 2329 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2290 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2380 base::WrapUnique(factory), nullptr); | 2341 base::WrapUnique(factory), nullptr); |
| 2381 | 2342 |
| 2382 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2343 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2383 service.SetProxyScriptFetchers( | 2344 service.SetProxyScriptFetchers( |
| 2384 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2345 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 2385 | 2346 |
| 2386 // Start 2 requests. | 2347 // Start 2 requests. |
| 2387 | 2348 |
| 2388 ProxyInfo info1; | 2349 ProxyInfo info1; |
| 2389 TestCompletionCallback callback1; | 2350 TestCompletionCallback callback1; |
| 2390 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, | 2351 int rv = |
| 2391 callback1.callback(), nullptr, nullptr, | 2352 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), |
| 2392 BoundNetLog()); | 2353 nullptr, nullptr, BoundNetLog()); |
| 2393 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2354 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2394 | 2355 |
| 2395 ProxyInfo info2; | 2356 ProxyInfo info2; |
| 2396 TestCompletionCallback callback2; | 2357 TestCompletionCallback callback2; |
| 2397 ProxyService::PacRequest* request2; | 2358 ProxyService::PacRequest* request2; |
| 2398 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, | 2359 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), |
| 2399 callback2.callback(), &request2, nullptr, | 2360 &request2, nullptr, BoundNetLog()); |
| 2400 BoundNetLog()); | |
| 2401 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2361 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2402 | 2362 |
| 2403 // Check that nothing has been sent to the proxy resolver factory yet. | 2363 // Check that nothing has been sent to the proxy resolver factory yet. |
| 2404 ASSERT_EQ(0u, factory->pending_requests().size()); | 2364 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 2405 | 2365 |
| 2406 // It should be trying to auto-detect first -- succeed the download. | 2366 // It should be trying to auto-detect first -- succeed the download. |
| 2407 EXPECT_TRUE(fetcher->has_pending_request()); | 2367 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2408 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2368 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 2409 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 2369 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
| 2410 | 2370 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2454 base::WrapUnique(factory), nullptr); | 2414 base::WrapUnique(factory), nullptr); |
| 2455 | 2415 |
| 2456 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2416 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2457 service.SetProxyScriptFetchers( | 2417 service.SetProxyScriptFetchers( |
| 2458 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2418 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 2459 | 2419 |
| 2460 // Start 2 requests. | 2420 // Start 2 requests. |
| 2461 | 2421 |
| 2462 ProxyInfo info1; | 2422 ProxyInfo info1; |
| 2463 TestCompletionCallback callback1; | 2423 TestCompletionCallback callback1; |
| 2464 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 2424 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
| 2465 LOAD_NORMAL, &info1, callback1.callback(), | 2425 callback1.callback(), nullptr, nullptr, |
| 2466 nullptr, nullptr, BoundNetLog()); | 2426 BoundNetLog()); |
| 2467 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2427 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2468 | 2428 |
| 2469 ProxyInfo info2; | 2429 ProxyInfo info2; |
| 2470 TestCompletionCallback callback2; | 2430 TestCompletionCallback callback2; |
| 2471 ProxyService::PacRequest* request2; | 2431 ProxyService::PacRequest* request2; |
| 2472 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 2432 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
| 2473 &info2, callback2.callback(), &request2, nullptr, | 2433 callback2.callback(), &request2, nullptr, |
| 2474 BoundNetLog()); | 2434 BoundNetLog()); |
| 2475 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2435 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2476 | 2436 |
| 2477 // Check that nothing has been sent to the proxy resolver factory yet. | 2437 // Check that nothing has been sent to the proxy resolver factory yet. |
| 2478 ASSERT_EQ(0u, factory->pending_requests().size()); | 2438 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 2479 | 2439 |
| 2480 // It should be trying to auto-detect first -- fail the download. | 2440 // It should be trying to auto-detect first -- fail the download. |
| 2481 EXPECT_TRUE(fetcher->has_pending_request()); | 2441 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2482 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2442 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 2483 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2443 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2517 | 2477 |
| 2518 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2478 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2519 service.SetProxyScriptFetchers( | 2479 service.SetProxyScriptFetchers( |
| 2520 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2480 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 2521 | 2481 |
| 2522 // Start 1 requests. | 2482 // Start 1 requests. |
| 2523 | 2483 |
| 2524 ProxyInfo info1; | 2484 ProxyInfo info1; |
| 2525 TestCompletionCallback callback1; | 2485 TestCompletionCallback callback1; |
| 2526 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2486 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
| 2527 LOAD_NORMAL, &info1, callback1.callback(), | 2487 &info1, callback1.callback(), nullptr, nullptr, |
| 2528 nullptr, nullptr, BoundNetLog()); | 2488 BoundNetLog()); |
| 2529 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2489 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2530 | 2490 |
| 2531 // Check that nothing has been sent to the proxy resolver factory yet. | 2491 // Check that nothing has been sent to the proxy resolver factory yet. |
| 2532 ASSERT_EQ(0u, factory->pending_requests().size()); | 2492 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 2533 | 2493 |
| 2534 // It should be trying to auto-detect first -- succeed the download. | 2494 // It should be trying to auto-detect first -- succeed the download. |
| 2535 EXPECT_TRUE(fetcher->has_pending_request()); | 2495 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2536 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2496 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 2537 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2497 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 2538 | 2498 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2549 resolver.pending_requests()[0]->CompleteNow(OK); | 2509 resolver.pending_requests()[0]->CompleteNow(OK); |
| 2550 | 2510 |
| 2551 // Verify that request ran as expected. | 2511 // Verify that request ran as expected. |
| 2552 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 2512 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 2553 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2513 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 2554 | 2514 |
| 2555 // Start another request, it should pickup the bypass item. | 2515 // Start another request, it should pickup the bypass item. |
| 2556 ProxyInfo info2; | 2516 ProxyInfo info2; |
| 2557 TestCompletionCallback callback2; | 2517 TestCompletionCallback callback2; |
| 2558 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2518 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
| 2559 LOAD_NORMAL, &info2, callback2.callback(), nullptr, | 2519 &info2, callback2.callback(), nullptr, nullptr, |
| 2560 nullptr, BoundNetLog()); | 2520 BoundNetLog()); |
| 2561 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2521 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2562 | 2522 |
| 2563 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2523 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 2564 EXPECT_EQ(GURL("http://www.google.com"), | 2524 EXPECT_EQ(GURL("http://www.google.com"), |
| 2565 resolver.pending_requests()[0]->url()); | 2525 resolver.pending_requests()[0]->url()); |
| 2566 | 2526 |
| 2567 // Complete the pending request. | 2527 // Complete the pending request. |
| 2568 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2528 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
| 2569 resolver.pending_requests()[0]->CompleteNow(OK); | 2529 resolver.pending_requests()[0]->CompleteNow(OK); |
| 2570 | 2530 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2588 | 2548 |
| 2589 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2549 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2590 service.SetProxyScriptFetchers( | 2550 service.SetProxyScriptFetchers( |
| 2591 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2551 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 2592 | 2552 |
| 2593 // Start 1 request. | 2553 // Start 1 request. |
| 2594 | 2554 |
| 2595 ProxyInfo info1; | 2555 ProxyInfo info1; |
| 2596 TestCompletionCallback callback1; | 2556 TestCompletionCallback callback1; |
| 2597 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2557 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
| 2598 LOAD_NORMAL, &info1, callback1.callback(), | 2558 &info1, callback1.callback(), nullptr, nullptr, |
| 2599 nullptr, nullptr, BoundNetLog()); | 2559 BoundNetLog()); |
| 2600 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2560 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2601 | 2561 |
| 2602 // Check that nothing has been sent to the proxy resolver factory yet. | 2562 // Check that nothing has been sent to the proxy resolver factory yet. |
| 2603 ASSERT_EQ(0u, factory->pending_requests().size()); | 2563 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 2604 | 2564 |
| 2605 // InitProxyResolver should have issued a request to the ProxyScriptFetcher | 2565 // InitProxyResolver should have issued a request to the ProxyScriptFetcher |
| 2606 // and be waiting on that to complete. | 2566 // and be waiting on that to complete. |
| 2607 EXPECT_TRUE(fetcher->has_pending_request()); | 2567 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2608 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2568 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2609 } | 2569 } |
| 2610 | 2570 |
| 2611 // Delete the ProxyService while InitProxyResolver has an outstanding | 2571 // Delete the ProxyService while InitProxyResolver has an outstanding |
| 2612 // request to the proxy resolver. When run under valgrind, should not | 2572 // request to the proxy resolver. When run under valgrind, should not |
| 2613 // have any memory errors (used to be that the ProxyResolver was | 2573 // have any memory errors (used to be that the ProxyResolver was |
| 2614 // being deleted prior to the InitProxyResolver). | 2574 // being deleted prior to the InitProxyResolver). |
| 2615 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { | 2575 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { |
| 2616 MockProxyConfigService* config_service = | 2576 MockProxyConfigService* config_service = |
| 2617 new MockProxyConfigService("http://foopy/proxy.pac"); | 2577 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 2618 | 2578 |
| 2619 MockAsyncProxyResolverFactory* factory = | 2579 MockAsyncProxyResolverFactory* factory = |
| 2620 new MockAsyncProxyResolverFactory(false); | 2580 new MockAsyncProxyResolverFactory(false); |
| 2621 | 2581 |
| 2622 ProxyService service(base::WrapUnique(config_service), | 2582 ProxyService service(base::WrapUnique(config_service), |
| 2623 base::WrapUnique(factory), nullptr); | 2583 base::WrapUnique(factory), nullptr); |
| 2624 | 2584 |
| 2625 GURL url("http://www.google.com/"); | 2585 GURL url("http://www.google.com/"); |
| 2626 | 2586 |
| 2627 ProxyInfo info; | 2587 ProxyInfo info; |
| 2628 TestCompletionCallback callback; | 2588 TestCompletionCallback callback; |
| 2629 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 2589 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
| 2630 callback.callback(), nullptr, nullptr, | 2590 nullptr, nullptr, BoundNetLog()); |
| 2631 BoundNetLog()); | |
| 2632 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2591 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2633 | 2592 |
| 2634 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 2593 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 2635 factory->pending_requests()[0]->script_data()->url()); | 2594 factory->pending_requests()[0]->script_data()->url()); |
| 2636 } | 2595 } |
| 2637 | 2596 |
| 2638 TEST_F(ProxyServiceTest, ResetProxyConfigService) { | 2597 TEST_F(ProxyServiceTest, ResetProxyConfigService) { |
| 2639 ProxyConfig config1; | 2598 ProxyConfig config1; |
| 2640 config1.proxy_rules().ParseFromString("foopy1:8080"); | 2599 config1.proxy_rules().ParseFromString("foopy1:8080"); |
| 2641 config1.set_auto_detect(false); | 2600 config1.set_auto_detect(false); |
| 2642 ProxyService service(base::WrapUnique(new MockProxyConfigService(config1)), | 2601 ProxyService service(base::WrapUnique(new MockProxyConfigService(config1)), |
| 2643 nullptr, nullptr); | 2602 nullptr, nullptr); |
| 2644 | 2603 |
| 2645 ProxyInfo info; | 2604 ProxyInfo info; |
| 2646 TestCompletionCallback callback1; | 2605 TestCompletionCallback callback1; |
| 2647 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 2606 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info, |
| 2648 LOAD_NORMAL, &info, callback1.callback(), | 2607 callback1.callback(), nullptr, nullptr, |
| 2649 nullptr, nullptr, BoundNetLog()); | 2608 BoundNetLog()); |
| 2650 EXPECT_THAT(rv, IsOk()); | 2609 EXPECT_THAT(rv, IsOk()); |
| 2651 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 2610 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 2652 | 2611 |
| 2653 ProxyConfig config2; | 2612 ProxyConfig config2; |
| 2654 config2.proxy_rules().ParseFromString("foopy2:8080"); | 2613 config2.proxy_rules().ParseFromString("foopy2:8080"); |
| 2655 config2.set_auto_detect(false); | 2614 config2.set_auto_detect(false); |
| 2656 service.ResetConfigService( | 2615 service.ResetConfigService( |
| 2657 base::WrapUnique(new MockProxyConfigService(config2))); | 2616 base::WrapUnique(new MockProxyConfigService(config2))); |
| 2658 TestCompletionCallback callback2; | 2617 TestCompletionCallback callback2; |
| 2659 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 2618 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info, |
| 2660 &info, callback2.callback(), nullptr, nullptr, | 2619 callback2.callback(), nullptr, nullptr, |
| 2661 BoundNetLog()); | 2620 BoundNetLog()); |
| 2662 EXPECT_THAT(rv, IsOk()); | 2621 EXPECT_THAT(rv, IsOk()); |
| 2663 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 2622 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
| 2664 } | 2623 } |
| 2665 | 2624 |
| 2666 // Test that when going from a configuration that required PAC to one | 2625 // Test that when going from a configuration that required PAC to one |
| 2667 // that does NOT, we unset the variable |should_use_proxy_resolver_|. | 2626 // that does NOT, we unset the variable |should_use_proxy_resolver_|. |
| 2668 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { | 2627 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { |
| 2669 ProxyConfig config = ProxyConfig::CreateAutoDetect(); | 2628 ProxyConfig config = ProxyConfig::CreateAutoDetect(); |
| 2670 | 2629 |
| 2671 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2630 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 2672 MockAsyncProxyResolver resolver; | 2631 MockAsyncProxyResolver resolver; |
| 2673 MockAsyncProxyResolverFactory* factory = | 2632 MockAsyncProxyResolverFactory* factory = |
| 2674 new MockAsyncProxyResolverFactory(false); | 2633 new MockAsyncProxyResolverFactory(false); |
| 2675 ProxyService service(base::WrapUnique(config_service), | 2634 ProxyService service(base::WrapUnique(config_service), |
| 2676 base::WrapUnique(factory), nullptr); | 2635 base::WrapUnique(factory), nullptr); |
| 2677 | 2636 |
| 2678 // Start 1 request. | 2637 // Start 1 request. |
| 2679 | 2638 |
| 2680 ProxyInfo info1; | 2639 ProxyInfo info1; |
| 2681 TestCompletionCallback callback1; | 2640 TestCompletionCallback callback1; |
| 2682 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2641 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
| 2683 LOAD_NORMAL, &info1, callback1.callback(), | 2642 &info1, callback1.callback(), nullptr, nullptr, |
| 2684 nullptr, nullptr, BoundNetLog()); | 2643 BoundNetLog()); |
| 2685 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2644 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2686 | 2645 |
| 2687 // Successfully set the autodetect script. | 2646 // Successfully set the autodetect script. |
| 2688 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, | 2647 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, |
| 2689 factory->pending_requests()[0]->script_data()->type()); | 2648 factory->pending_requests()[0]->script_data()->type()); |
| 2690 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2649 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2691 | 2650 |
| 2692 // Complete the pending request. | 2651 // Complete the pending request. |
| 2693 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2652 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 2694 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2653 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 2695 resolver.pending_requests()[0]->CompleteNow(OK); | 2654 resolver.pending_requests()[0]->CompleteNow(OK); |
| 2696 | 2655 |
| 2697 // Verify that request ran as expected. | 2656 // Verify that request ran as expected. |
| 2698 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 2657 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 2699 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2658 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 2700 | 2659 |
| 2701 // Force the ProxyService to pull down a new proxy configuration. | 2660 // Force the ProxyService to pull down a new proxy configuration. |
| 2702 // (Even though the configuration isn't old/bad). | 2661 // (Even though the configuration isn't old/bad). |
| 2703 // | 2662 // |
| 2704 // This new configuration no longer has auto_detect set, so | 2663 // This new configuration no longer has auto_detect set, so |
| 2705 // requests should complete synchronously now as direct-connect. | 2664 // requests should complete synchronously now as direct-connect. |
| 2706 config_service->SetConfig(ProxyConfig::CreateDirect()); | 2665 config_service->SetConfig(ProxyConfig::CreateDirect()); |
| 2707 | 2666 |
| 2708 // Start another request -- the effective configuration has changed. | 2667 // Start another request -- the effective configuration has changed. |
| 2709 ProxyInfo info2; | 2668 ProxyInfo info2; |
| 2710 TestCompletionCallback callback2; | 2669 TestCompletionCallback callback2; |
| 2711 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2670 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
| 2712 LOAD_NORMAL, &info2, callback2.callback(), nullptr, | 2671 &info2, callback2.callback(), nullptr, nullptr, |
| 2713 nullptr, BoundNetLog()); | 2672 BoundNetLog()); |
| 2714 EXPECT_THAT(rv, IsOk()); | 2673 EXPECT_THAT(rv, IsOk()); |
| 2715 | 2674 |
| 2716 EXPECT_TRUE(info2.is_direct()); | 2675 EXPECT_TRUE(info2.is_direct()); |
| 2717 } | 2676 } |
| 2718 | 2677 |
| 2719 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { | 2678 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { |
| 2720 MockProxyConfigService* config_service = | 2679 MockProxyConfigService* config_service = |
| 2721 new MockProxyConfigService("http://foopy/proxy.pac"); | 2680 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 2722 | 2681 |
| 2723 MockAsyncProxyResolver resolver; | 2682 MockAsyncProxyResolver resolver; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2734 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2693 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 2735 | 2694 |
| 2736 // Disable the "wait after IP address changes" hack, so this unit-test can | 2695 // Disable the "wait after IP address changes" hack, so this unit-test can |
| 2737 // complete quickly. | 2696 // complete quickly. |
| 2738 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); | 2697 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); |
| 2739 | 2698 |
| 2740 // Start 1 request. | 2699 // Start 1 request. |
| 2741 | 2700 |
| 2742 ProxyInfo info1; | 2701 ProxyInfo info1; |
| 2743 TestCompletionCallback callback1; | 2702 TestCompletionCallback callback1; |
| 2744 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 2703 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
| 2745 LOAD_NORMAL, &info1, callback1.callback(), | 2704 callback1.callback(), nullptr, nullptr, |
| 2746 nullptr, nullptr, BoundNetLog()); | 2705 BoundNetLog()); |
| 2747 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2706 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2748 | 2707 |
| 2749 // The first request should have triggered initial download of PAC script. | 2708 // The first request should have triggered initial download of PAC script. |
| 2750 EXPECT_TRUE(fetcher->has_pending_request()); | 2709 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2751 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2710 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2752 | 2711 |
| 2753 // Nothing has been sent to the factory yet. | 2712 // Nothing has been sent to the factory yet. |
| 2754 EXPECT_TRUE(factory->pending_requests().empty()); | 2713 EXPECT_TRUE(factory->pending_requests().empty()); |
| 2755 | 2714 |
| 2756 // At this point the ProxyService should be waiting for the | 2715 // At this point the ProxyService should be waiting for the |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2777 | 2736 |
| 2778 // Now simluate a change in the network. The ProxyConfigService is still | 2737 // Now simluate a change in the network. The ProxyConfigService is still |
| 2779 // going to return the same PAC URL as before, but this URL needs to be | 2738 // going to return the same PAC URL as before, but this URL needs to be |
| 2780 // refetched on the new network. | 2739 // refetched on the new network. |
| 2781 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 2740 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 2782 base::RunLoop().RunUntilIdle(); // Notification happens async. | 2741 base::RunLoop().RunUntilIdle(); // Notification happens async. |
| 2783 | 2742 |
| 2784 // Start a second request. | 2743 // Start a second request. |
| 2785 ProxyInfo info2; | 2744 ProxyInfo info2; |
| 2786 TestCompletionCallback callback2; | 2745 TestCompletionCallback callback2; |
| 2787 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 2746 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
| 2788 &info2, callback2.callback(), nullptr, nullptr, | 2747 callback2.callback(), nullptr, nullptr, |
| 2789 BoundNetLog()); | 2748 BoundNetLog()); |
| 2790 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2749 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2791 | 2750 |
| 2792 // This second request should have triggered the re-download of the PAC | 2751 // This second request should have triggered the re-download of the PAC |
| 2793 // script (since we marked the network as having changed). | 2752 // script (since we marked the network as having changed). |
| 2794 EXPECT_TRUE(fetcher->has_pending_request()); | 2753 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2795 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2754 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2796 | 2755 |
| 2797 // Nothing has been sent to the factory yet. | 2756 // Nothing has been sent to the factory yet. |
| 2798 EXPECT_TRUE(factory->pending_requests().empty()); | 2757 EXPECT_TRUE(factory->pending_requests().empty()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2852 base::WrapUnique(factory), nullptr); | 2811 base::WrapUnique(factory), nullptr); |
| 2853 | 2812 |
| 2854 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2813 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2855 service.SetProxyScriptFetchers( | 2814 service.SetProxyScriptFetchers( |
| 2856 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2815 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 2857 | 2816 |
| 2858 // Start 1 request. | 2817 // Start 1 request. |
| 2859 | 2818 |
| 2860 ProxyInfo info1; | 2819 ProxyInfo info1; |
| 2861 TestCompletionCallback callback1; | 2820 TestCompletionCallback callback1; |
| 2862 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 2821 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
| 2863 LOAD_NORMAL, &info1, callback1.callback(), | 2822 callback1.callback(), nullptr, nullptr, |
| 2864 nullptr, nullptr, BoundNetLog()); | 2823 BoundNetLog()); |
| 2865 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2824 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2866 | 2825 |
| 2867 // The first request should have triggered initial download of PAC script. | 2826 // The first request should have triggered initial download of PAC script. |
| 2868 EXPECT_TRUE(fetcher->has_pending_request()); | 2827 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2869 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2828 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2870 | 2829 |
| 2871 // Nothing has been sent to the factory yet. | 2830 // Nothing has been sent to the factory yet. |
| 2872 EXPECT_TRUE(factory->pending_requests().empty()); | 2831 EXPECT_TRUE(factory->pending_requests().empty()); |
| 2873 | 2832 |
| 2874 // At this point the ProxyService should be waiting for the | 2833 // At this point the ProxyService should be waiting for the |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2913 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2872 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2914 | 2873 |
| 2915 // At this point the ProxyService should have re-configured itself to use the | 2874 // At this point the ProxyService should have re-configured itself to use the |
| 2916 // PAC script (thereby recovering from the initial fetch failure). We will | 2875 // PAC script (thereby recovering from the initial fetch failure). We will |
| 2917 // verify that the next Resolve request uses the resolver rather than | 2876 // verify that the next Resolve request uses the resolver rather than |
| 2918 // DIRECT. | 2877 // DIRECT. |
| 2919 | 2878 |
| 2920 // Start a second request. | 2879 // Start a second request. |
| 2921 ProxyInfo info2; | 2880 ProxyInfo info2; |
| 2922 TestCompletionCallback callback2; | 2881 TestCompletionCallback callback2; |
| 2923 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 2882 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
| 2924 &info2, callback2.callback(), nullptr, nullptr, | 2883 callback2.callback(), nullptr, nullptr, |
| 2925 BoundNetLog()); | 2884 BoundNetLog()); |
| 2926 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2885 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2927 | 2886 |
| 2928 // Check that it was sent to the resolver. | 2887 // Check that it was sent to the resolver. |
| 2929 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2888 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 2930 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 2889 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
| 2931 | 2890 |
| 2932 // Complete the pending second request. | 2891 // Complete the pending second request. |
| 2933 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2892 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
| 2934 resolver.pending_requests()[0]->CompleteNow(OK); | 2893 resolver.pending_requests()[0]->CompleteNow(OK); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2959 base::WrapUnique(factory), nullptr); | 2918 base::WrapUnique(factory), nullptr); |
| 2960 | 2919 |
| 2961 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2920 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2962 service.SetProxyScriptFetchers( | 2921 service.SetProxyScriptFetchers( |
| 2963 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2922 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 2964 | 2923 |
| 2965 // Start 1 request. | 2924 // Start 1 request. |
| 2966 | 2925 |
| 2967 ProxyInfo info1; | 2926 ProxyInfo info1; |
| 2968 TestCompletionCallback callback1; | 2927 TestCompletionCallback callback1; |
| 2969 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 2928 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
| 2970 LOAD_NORMAL, &info1, callback1.callback(), | 2929 callback1.callback(), nullptr, nullptr, |
| 2971 nullptr, nullptr, BoundNetLog()); | 2930 BoundNetLog()); |
| 2972 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2931 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2973 | 2932 |
| 2974 // The first request should have triggered initial download of PAC script. | 2933 // The first request should have triggered initial download of PAC script. |
| 2975 EXPECT_TRUE(fetcher->has_pending_request()); | 2934 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2976 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2935 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2977 | 2936 |
| 2978 // Nothing has been sent to the factory yet. | 2937 // Nothing has been sent to the factory yet. |
| 2979 EXPECT_TRUE(factory->pending_requests().empty()); | 2938 EXPECT_TRUE(factory->pending_requests().empty()); |
| 2980 | 2939 |
| 2981 // At this point the ProxyService should be waiting for the | 2940 // At this point the ProxyService should be waiting for the |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3026 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), | 2985 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), |
| 3027 factory->pending_requests()[0]->script_data()->utf16()); | 2986 factory->pending_requests()[0]->script_data()->utf16()); |
| 3028 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2987 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 3029 | 2988 |
| 3030 // At this point the ProxyService should have re-configured itself to use the | 2989 // At this point the ProxyService should have re-configured itself to use the |
| 3031 // new PAC script. | 2990 // new PAC script. |
| 3032 | 2991 |
| 3033 // Start a second request. | 2992 // Start a second request. |
| 3034 ProxyInfo info2; | 2993 ProxyInfo info2; |
| 3035 TestCompletionCallback callback2; | 2994 TestCompletionCallback callback2; |
| 3036 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 2995 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
| 3037 &info2, callback2.callback(), nullptr, nullptr, | 2996 callback2.callback(), nullptr, nullptr, |
| 3038 BoundNetLog()); | 2997 BoundNetLog()); |
| 3039 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2998 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 3040 | 2999 |
| 3041 // Check that it was sent to the resolver. | 3000 // Check that it was sent to the resolver. |
| 3042 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3001 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 3043 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3002 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
| 3044 | 3003 |
| 3045 // Complete the pending second request. | 3004 // Complete the pending second request. |
| 3046 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3005 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
| 3047 resolver.pending_requests()[0]->CompleteNow(OK); | 3006 resolver.pending_requests()[0]->CompleteNow(OK); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3072 base::WrapUnique(factory), nullptr); | 3031 base::WrapUnique(factory), nullptr); |
| 3073 | 3032 |
| 3074 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 3033 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 3075 service.SetProxyScriptFetchers( | 3034 service.SetProxyScriptFetchers( |
| 3076 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 3035 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 3077 | 3036 |
| 3078 // Start 1 request. | 3037 // Start 1 request. |
| 3079 | 3038 |
| 3080 ProxyInfo info1; | 3039 ProxyInfo info1; |
| 3081 TestCompletionCallback callback1; | 3040 TestCompletionCallback callback1; |
| 3082 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 3041 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
| 3083 LOAD_NORMAL, &info1, callback1.callback(), | 3042 callback1.callback(), nullptr, nullptr, |
| 3084 nullptr, nullptr, BoundNetLog()); | 3043 BoundNetLog()); |
| 3085 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3044 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 3086 | 3045 |
| 3087 // The first request should have triggered initial download of PAC script. | 3046 // The first request should have triggered initial download of PAC script. |
| 3088 EXPECT_TRUE(fetcher->has_pending_request()); | 3047 EXPECT_TRUE(fetcher->has_pending_request()); |
| 3089 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3048 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 3090 | 3049 |
| 3091 // Nothing has been sent to the factory yet. | 3050 // Nothing has been sent to the factory yet. |
| 3092 EXPECT_TRUE(factory->pending_requests().empty()); | 3051 EXPECT_TRUE(factory->pending_requests().empty()); |
| 3093 | 3052 |
| 3094 // At this point the ProxyService should be waiting for the | 3053 // At this point the ProxyService should be waiting for the |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3136 | 3095 |
| 3137 ASSERT_TRUE(factory->pending_requests().empty()); | 3096 ASSERT_TRUE(factory->pending_requests().empty()); |
| 3138 ASSERT_TRUE(resolver.pending_requests().empty()); | 3097 ASSERT_TRUE(resolver.pending_requests().empty()); |
| 3139 | 3098 |
| 3140 // At this point the ProxyService is still running the same PAC script as | 3099 // At this point the ProxyService is still running the same PAC script as |
| 3141 // before. | 3100 // before. |
| 3142 | 3101 |
| 3143 // Start a second request. | 3102 // Start a second request. |
| 3144 ProxyInfo info2; | 3103 ProxyInfo info2; |
| 3145 TestCompletionCallback callback2; | 3104 TestCompletionCallback callback2; |
| 3146 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 3105 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
| 3147 &info2, callback2.callback(), nullptr, nullptr, | 3106 callback2.callback(), nullptr, nullptr, |
| 3148 BoundNetLog()); | 3107 BoundNetLog()); |
| 3149 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3108 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 3150 | 3109 |
| 3151 // Check that it was sent to the resolver. | 3110 // Check that it was sent to the resolver. |
| 3152 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3111 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 3153 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3112 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
| 3154 | 3113 |
| 3155 // Complete the pending second request. | 3114 // Complete the pending second request. |
| 3156 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3115 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
| 3157 resolver.pending_requests()[0]->CompleteNow(OK); | 3116 resolver.pending_requests()[0]->CompleteNow(OK); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3182 base::WrapUnique(factory), nullptr); | 3141 base::WrapUnique(factory), nullptr); |
| 3183 | 3142 |
| 3184 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 3143 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 3185 service.SetProxyScriptFetchers( | 3144 service.SetProxyScriptFetchers( |
| 3186 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 3145 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 3187 | 3146 |
| 3188 // Start 1 request. | 3147 // Start 1 request. |
| 3189 | 3148 |
| 3190 ProxyInfo info1; | 3149 ProxyInfo info1; |
| 3191 TestCompletionCallback callback1; | 3150 TestCompletionCallback callback1; |
| 3192 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 3151 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
| 3193 LOAD_NORMAL, &info1, callback1.callback(), | 3152 callback1.callback(), nullptr, nullptr, |
| 3194 nullptr, nullptr, BoundNetLog()); | 3153 BoundNetLog()); |
| 3195 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3154 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 3196 | 3155 |
| 3197 // The first request should have triggered initial download of PAC script. | 3156 // The first request should have triggered initial download of PAC script. |
| 3198 EXPECT_TRUE(fetcher->has_pending_request()); | 3157 EXPECT_TRUE(fetcher->has_pending_request()); |
| 3199 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3158 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 3200 | 3159 |
| 3201 // Nothing has been sent to the factory yet. | 3160 // Nothing has been sent to the factory yet. |
| 3202 EXPECT_TRUE(factory->pending_requests().empty()); | 3161 EXPECT_TRUE(factory->pending_requests().empty()); |
| 3203 | 3162 |
| 3204 // At this point the ProxyService should be waiting for the | 3163 // At this point the ProxyService should be waiting for the |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3243 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 3202 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
| 3244 | 3203 |
| 3245 base::RunLoop().RunUntilIdle(); | 3204 base::RunLoop().RunUntilIdle(); |
| 3246 | 3205 |
| 3247 // At this point the ProxyService should have re-configured itself to use | 3206 // At this point the ProxyService should have re-configured itself to use |
| 3248 // DIRECT connections rather than the given proxy resolver. | 3207 // DIRECT connections rather than the given proxy resolver. |
| 3249 | 3208 |
| 3250 // Start a second request. | 3209 // Start a second request. |
| 3251 ProxyInfo info2; | 3210 ProxyInfo info2; |
| 3252 TestCompletionCallback callback2; | 3211 TestCompletionCallback callback2; |
| 3253 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 3212 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
| 3254 &info2, callback2.callback(), nullptr, nullptr, | 3213 callback2.callback(), nullptr, nullptr, |
| 3255 BoundNetLog()); | 3214 BoundNetLog()); |
| 3256 EXPECT_THAT(rv, IsOk()); | 3215 EXPECT_THAT(rv, IsOk()); |
| 3257 EXPECT_TRUE(info2.is_direct()); | 3216 EXPECT_TRUE(info2.is_direct()); |
| 3258 } | 3217 } |
| 3259 | 3218 |
| 3260 // Tests that the code which decides at what times to poll the PAC | 3219 // Tests that the code which decides at what times to poll the PAC |
| 3261 // script follows the expected policy. | 3220 // script follows the expected policy. |
| 3262 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { | 3221 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { |
| 3263 // Retrieve the internal polling policy implementation used by ProxyService. | 3222 // Retrieve the internal polling policy implementation used by ProxyService. |
| 3264 std::unique_ptr<ProxyService::PacPollPolicy> policy = | 3223 std::unique_ptr<ProxyService::PacPollPolicy> policy = |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3337 base::WrapUnique(factory), nullptr); | 3296 base::WrapUnique(factory), nullptr); |
| 3338 | 3297 |
| 3339 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 3298 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 3340 service.SetProxyScriptFetchers( | 3299 service.SetProxyScriptFetchers( |
| 3341 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 3300 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
| 3342 | 3301 |
| 3343 // Start 1 request. | 3302 // Start 1 request. |
| 3344 | 3303 |
| 3345 ProxyInfo info1; | 3304 ProxyInfo info1; |
| 3346 TestCompletionCallback callback1; | 3305 TestCompletionCallback callback1; |
| 3347 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 3306 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
| 3348 LOAD_NORMAL, &info1, callback1.callback(), | 3307 callback1.callback(), nullptr, nullptr, |
| 3349 nullptr, nullptr, BoundNetLog()); | 3308 BoundNetLog()); |
| 3350 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3309 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 3351 | 3310 |
| 3352 // The first request should have triggered initial download of PAC script. | 3311 // The first request should have triggered initial download of PAC script. |
| 3353 EXPECT_TRUE(fetcher->has_pending_request()); | 3312 EXPECT_TRUE(fetcher->has_pending_request()); |
| 3354 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3313 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 3355 | 3314 |
| 3356 // Nothing has been sent to the factory yet. | 3315 // Nothing has been sent to the factory yet. |
| 3357 EXPECT_TRUE(factory->pending_requests().empty()); | 3316 EXPECT_TRUE(factory->pending_requests().empty()); |
| 3358 | 3317 |
| 3359 // At this point the ProxyService should be waiting for the | 3318 // At this point the ProxyService should be waiting for the |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3382 // Our PAC poller is set to update ONLY in response to network activity, | 3341 // Our PAC poller is set to update ONLY in response to network activity, |
| 3383 // (i.e. another call to ResolveProxy()). | 3342 // (i.e. another call to ResolveProxy()). |
| 3384 | 3343 |
| 3385 ASSERT_FALSE(fetcher->has_pending_request()); | 3344 ASSERT_FALSE(fetcher->has_pending_request()); |
| 3386 ASSERT_TRUE(factory->pending_requests().empty()); | 3345 ASSERT_TRUE(factory->pending_requests().empty()); |
| 3387 ASSERT_TRUE(resolver.pending_requests().empty()); | 3346 ASSERT_TRUE(resolver.pending_requests().empty()); |
| 3388 | 3347 |
| 3389 // Start a second request. | 3348 // Start a second request. |
| 3390 ProxyInfo info2; | 3349 ProxyInfo info2; |
| 3391 TestCompletionCallback callback2; | 3350 TestCompletionCallback callback2; |
| 3392 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 3351 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
| 3393 &info2, callback2.callback(), nullptr, nullptr, | 3352 callback2.callback(), nullptr, nullptr, |
| 3394 BoundNetLog()); | 3353 BoundNetLog()); |
| 3395 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3354 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 3396 | 3355 |
| 3397 // This request should have sent work to the resolver; complete it. | 3356 // This request should have sent work to the resolver; complete it. |
| 3398 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3357 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 3399 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3358 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
| 3400 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3359 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
| 3401 resolver.pending_requests()[0]->CompleteNow(OK); | 3360 resolver.pending_requests()[0]->CompleteNow(OK); |
| 3402 | 3361 |
| 3403 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 3362 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 3404 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3363 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 3405 | 3364 |
| 3406 // In response to getting that resolve request, the poller should have | 3365 // In response to getting that resolve request, the poller should have |
| 3407 // started the next poll, and made it as far as to request the download. | 3366 // started the next poll, and made it as far as to request the download. |
| 3408 | 3367 |
| 3409 EXPECT_TRUE(fetcher->has_pending_request()); | 3368 EXPECT_TRUE(fetcher->has_pending_request()); |
| 3410 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3369 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 3411 | 3370 |
| 3412 // This time we will fail the download, to simulate a PAC script change. | 3371 // This time we will fail the download, to simulate a PAC script change. |
| 3413 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 3372 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
| 3414 | 3373 |
| 3415 // Drain the message loop, so ProxyService is notified of the change | 3374 // Drain the message loop, so ProxyService is notified of the change |
| 3416 // and has a chance to re-configure itself. | 3375 // and has a chance to re-configure itself. |
| 3417 base::RunLoop().RunUntilIdle(); | 3376 base::RunLoop().RunUntilIdle(); |
| 3418 | 3377 |
| 3419 // Start a third request -- this time we expect to get a direct connection | 3378 // Start a third request -- this time we expect to get a direct connection |
| 3420 // since the PAC script poller experienced a failure. | 3379 // since the PAC script poller experienced a failure. |
| 3421 ProxyInfo info3; | 3380 ProxyInfo info3; |
| 3422 TestCompletionCallback callback3; | 3381 TestCompletionCallback callback3; |
| 3423 rv = service.ResolveProxy(GURL("http://request3"), std::string(), LOAD_NORMAL, | 3382 rv = service.ResolveProxy(GURL("http://request3"), std::string(), &info3, |
| 3424 &info3, callback3.callback(), nullptr, nullptr, | 3383 callback3.callback(), nullptr, nullptr, |
| 3425 BoundNetLog()); | 3384 BoundNetLog()); |
| 3426 EXPECT_THAT(rv, IsOk()); | 3385 EXPECT_THAT(rv, IsOk()); |
| 3427 EXPECT_TRUE(info3.is_direct()); | 3386 EXPECT_TRUE(info3.is_direct()); |
| 3428 } | 3387 } |
| 3429 | 3388 |
| 3430 // Test that the synchronous resolution fails when a PAC script is active. | 3389 // Test that the synchronous resolution fails when a PAC script is active. |
| 3431 TEST_F(ProxyServiceTest, SynchronousWithPAC) { | 3390 TEST_F(ProxyServiceTest, SynchronousWithPAC) { |
| 3432 MockProxyConfigService* config_service = | 3391 MockProxyConfigService* config_service = |
| 3433 new MockProxyConfigService("http://foopy/proxy.pac"); | 3392 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 3434 | 3393 |
| 3435 MockAsyncProxyResolverFactory* factory = | 3394 MockAsyncProxyResolverFactory* factory = |
| 3436 new MockAsyncProxyResolverFactory(false); | 3395 new MockAsyncProxyResolverFactory(false); |
| 3437 | 3396 |
| 3438 ProxyService service(base::WrapUnique(config_service), | 3397 ProxyService service(base::WrapUnique(config_service), |
| 3439 base::WrapUnique(factory), nullptr); | 3398 base::WrapUnique(factory), nullptr); |
| 3440 | 3399 |
| 3441 GURL url("http://www.google.com/"); | 3400 GURL url("http://www.google.com/"); |
| 3442 | 3401 |
| 3443 ProxyInfo info; | 3402 ProxyInfo info; |
| 3444 info.UseDirect(); | 3403 info.UseDirect(); |
| 3445 BoundTestNetLog log; | 3404 BoundTestNetLog log; |
| 3446 | 3405 |
| 3447 bool synchronous_success = service.TryResolveProxySynchronously( | 3406 bool synchronous_success = service.TryResolveProxySynchronously( |
| 3448 url, std::string(), LOAD_NORMAL, &info, nullptr, log.bound()); | 3407 url, std::string(), &info, nullptr, log.bound()); |
| 3449 EXPECT_FALSE(synchronous_success); | 3408 EXPECT_FALSE(synchronous_success); |
| 3450 | 3409 |
| 3451 // |info| should not have been modified. | 3410 // |info| should not have been modified. |
| 3452 EXPECT_TRUE(info.is_direct()); | 3411 EXPECT_TRUE(info.is_direct()); |
| 3453 } | 3412 } |
| 3454 | 3413 |
| 3455 // Test that synchronous results are returned correctly if a fixed proxy | 3414 // Test that synchronous results are returned correctly if a fixed proxy |
| 3456 // configuration is active. | 3415 // configuration is active. |
| 3457 TEST_F(ProxyServiceTest, SynchronousWithFixedConfiguration) { | 3416 TEST_F(ProxyServiceTest, SynchronousWithFixedConfiguration) { |
| 3458 ProxyConfig config; | 3417 ProxyConfig config; |
| 3459 config.proxy_rules().ParseFromString("foopy1:8080"); | 3418 config.proxy_rules().ParseFromString("foopy1:8080"); |
| 3460 config.set_auto_detect(false); | 3419 config.set_auto_detect(false); |
| 3461 | 3420 |
| 3462 MockAsyncProxyResolverFactory* factory = | 3421 MockAsyncProxyResolverFactory* factory = |
| 3463 new MockAsyncProxyResolverFactory(false); | 3422 new MockAsyncProxyResolverFactory(false); |
| 3464 | 3423 |
| 3465 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 3424 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
| 3466 base::WrapUnique(factory), nullptr); | 3425 base::WrapUnique(factory), nullptr); |
| 3467 | 3426 |
| 3468 GURL url("http://www.google.com/"); | 3427 GURL url("http://www.google.com/"); |
| 3469 | 3428 |
| 3470 ProxyInfo info; | 3429 ProxyInfo info; |
| 3471 BoundTestNetLog log; | 3430 BoundTestNetLog log; |
| 3472 | 3431 |
| 3473 bool synchronous_success = service.TryResolveProxySynchronously( | 3432 bool synchronous_success = service.TryResolveProxySynchronously( |
| 3474 url, std::string(), LOAD_NORMAL, &info, nullptr, log.bound()); | 3433 url, std::string(), &info, nullptr, log.bound()); |
| 3475 EXPECT_TRUE(synchronous_success); | 3434 EXPECT_TRUE(synchronous_success); |
| 3476 EXPECT_FALSE(info.is_direct()); | 3435 EXPECT_FALSE(info.is_direct()); |
| 3477 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); | 3436 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); |
| 3478 | 3437 |
| 3479 // No request should have been queued. | 3438 // No request should have been queued. |
| 3480 EXPECT_EQ(0u, factory->pending_requests().size()); | 3439 EXPECT_EQ(0u, factory->pending_requests().size()); |
| 3481 } | 3440 } |
| 3482 | 3441 |
| 3483 // Helper class to exercise URL sanitization using the different policies. This | 3442 // Helper class to exercise URL sanitization using the different policies. This |
| 3484 // works by submitted URLs to the ProxyService. In turn the ProxyService | 3443 // works by submitted URLs to the ProxyService. In turn the ProxyService |
| 3485 // sanitizes the URL and then passes it along to the ProxyResolver. This helper | 3444 // sanitizes the URL and then passes it along to the ProxyResolver. This helper |
| 3486 // returns the URL seen by the ProxyResolver. | 3445 // returns the URL seen by the ProxyResolver. |
| 3487 class SanitizeUrlHelper { | 3446 class SanitizeUrlHelper { |
| 3488 public: | 3447 public: |
| 3489 SanitizeUrlHelper() { | 3448 SanitizeUrlHelper() { |
| 3490 std::unique_ptr<MockProxyConfigService> config_service( | 3449 std::unique_ptr<MockProxyConfigService> config_service( |
| 3491 new MockProxyConfigService("http://foopy/proxy.pac")); | 3450 new MockProxyConfigService("http://foopy/proxy.pac")); |
| 3492 | 3451 |
| 3493 factory = new MockAsyncProxyResolverFactory(false); | 3452 factory = new MockAsyncProxyResolverFactory(false); |
| 3494 | 3453 |
| 3495 service_.reset(new ProxyService(std::move(config_service), | 3454 service_.reset(new ProxyService(std::move(config_service), |
| 3496 base::WrapUnique(factory), nullptr)); | 3455 base::WrapUnique(factory), nullptr)); |
| 3497 | 3456 |
| 3498 // Do an initial request to initialize the service (configure the PAC | 3457 // Do an initial request to initialize the service (configure the PAC |
| 3499 // script). | 3458 // script). |
| 3500 GURL url("http://example.com"); | 3459 GURL url("http://example.com"); |
| 3501 | 3460 |
| 3502 ProxyInfo info; | 3461 ProxyInfo info; |
| 3503 TestCompletionCallback callback; | 3462 TestCompletionCallback callback; |
| 3504 int rv = service_->ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 3463 int rv = |
| 3505 callback.callback(), nullptr, nullptr, | 3464 service_->ResolveProxy(url, std::string(), &info, callback.callback(), |
| 3506 BoundNetLog()); | 3465 nullptr, nullptr, BoundNetLog()); |
| 3507 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3466 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 3508 | 3467 |
| 3509 // First step is to download the PAC script. | 3468 // First step is to download the PAC script. |
| 3510 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 3469 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 3511 factory->pending_requests()[0]->script_data()->url()); | 3470 factory->pending_requests()[0]->script_data()->url()); |
| 3512 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3471 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 3513 | 3472 |
| 3514 EXPECT_EQ(1u, resolver.pending_requests().size()); | 3473 EXPECT_EQ(1u, resolver.pending_requests().size()); |
| 3515 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 3474 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 3516 | 3475 |
| 3517 // Complete the request. | 3476 // Complete the request. |
| 3518 resolver.pending_requests()[0]->results()->UsePacString("DIRECT"); | 3477 resolver.pending_requests()[0]->results()->UsePacString("DIRECT"); |
| 3519 resolver.pending_requests()[0]->CompleteNow(OK); | 3478 resolver.pending_requests()[0]->CompleteNow(OK); |
| 3520 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 3479 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 3521 EXPECT_TRUE(info.is_direct()); | 3480 EXPECT_TRUE(info.is_direct()); |
| 3522 } | 3481 } |
| 3523 | 3482 |
| 3524 // Changes the URL sanitization policy for the underlying ProxyService. This | 3483 // Changes the URL sanitization policy for the underlying ProxyService. This |
| 3525 // will affect subsequent calls to SanitizeUrl. | 3484 // will affect subsequent calls to SanitizeUrl. |
| 3526 void SetSanitizeUrlPolicy(ProxyService::SanitizeUrlPolicy policy) { | 3485 void SetSanitizeUrlPolicy(ProxyService::SanitizeUrlPolicy policy) { |
| 3527 service_->set_sanitize_url_policy(policy); | 3486 service_->set_sanitize_url_policy(policy); |
| 3528 } | 3487 } |
| 3529 | 3488 |
| 3530 // Makes a proxy resolution request through the ProxyService, and returns the | 3489 // Makes a proxy resolution request through the ProxyService, and returns the |
| 3531 // URL that was submitted to the Proxy Resolver. | 3490 // URL that was submitted to the Proxy Resolver. |
| 3532 GURL SanitizeUrl(const GURL& raw_url) { | 3491 GURL SanitizeUrl(const GURL& raw_url) { |
| 3533 // Issue a request and see what URL is sent to the proxy resolver. | 3492 // Issue a request and see what URL is sent to the proxy resolver. |
| 3534 ProxyInfo info; | 3493 ProxyInfo info; |
| 3535 TestCompletionCallback callback; | 3494 TestCompletionCallback callback; |
| 3536 int rv = service_->ResolveProxy(raw_url, std::string(), LOAD_NORMAL, &info, | 3495 int rv = service_->ResolveProxy(raw_url, std::string(), &info, |
| 3537 callback.callback(), nullptr, nullptr, | 3496 callback.callback(), nullptr, nullptr, |
| 3538 BoundNetLog()); | 3497 BoundNetLog()); |
| 3539 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3498 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 3540 | 3499 |
| 3541 EXPECT_EQ(1u, resolver.pending_requests().size()); | 3500 EXPECT_EQ(1u, resolver.pending_requests().size()); |
| 3542 | 3501 |
| 3543 GURL sanitized_url = resolver.pending_requests()[0]->url(); | 3502 GURL sanitized_url = resolver.pending_requests()[0]->url(); |
| 3544 | 3503 |
| 3545 // Complete the request. | 3504 // Complete the request. |
| 3546 resolver.pending_requests()[0]->results()->UsePacString("DIRECT"); | 3505 resolver.pending_requests()[0]->results()->UsePacString("DIRECT"); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3694 GURL(test.sanitized_url_unstripped), | 3653 GURL(test.sanitized_url_unstripped), |
| 3695 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); | 3654 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); |
| 3696 | 3655 |
| 3697 EXPECT_EQ( | 3656 EXPECT_EQ( |
| 3698 GURL(test.sanitized_url), | 3657 GURL(test.sanitized_url), |
| 3699 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); | 3658 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); |
| 3700 } | 3659 } |
| 3701 } | 3660 } |
| 3702 | 3661 |
| 3703 } // namespace net | 3662 } // namespace net |
| OLD | NEW |