OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 397 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
398 | 398 |
399 TestCompletionCallback callback3; | 399 TestCompletionCallback callback3; |
400 rv = service->ResolveProxy(url, &info, &callback3, NULL, NULL); | 400 rv = service->ResolveProxy(url, &info, &callback3, NULL, NULL); |
401 EXPECT_EQ(ERR_IO_PENDING, rv); | 401 EXPECT_EQ(ERR_IO_PENDING, rv); |
402 | 402 |
403 ASSERT_EQ(1u, resolver->pending_requests().size()); | 403 ASSERT_EQ(1u, resolver->pending_requests().size()); |
404 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 404 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
405 | 405 |
406 // Set the result in proxy resolver -- the second result is already known | 406 // Set the result in proxy resolver -- the second result is already known |
407 // to be bad. | 407 // to be bad, so we will not try to use it initially. |
408 resolver->pending_requests()[0]->results()->UseNamedProxy( | 408 resolver->pending_requests()[0]->results()->UseNamedProxy( |
409 "foopy3:7070;foopy1:8080;foopy2:9090"); | 409 "foopy3:7070;foopy1:8080;foopy2:9090"); |
410 resolver->pending_requests()[0]->CompleteNow(OK); | 410 resolver->pending_requests()[0]->CompleteNow(OK); |
411 | 411 |
412 EXPECT_EQ(OK, callback3.WaitForResult()); | 412 EXPECT_EQ(OK, callback3.WaitForResult()); |
413 EXPECT_FALSE(info.is_direct()); | 413 EXPECT_FALSE(info.is_direct()); |
414 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 414 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
415 | 415 |
416 // We fake another error. It should now try the third one. | 416 // We fake another error. It should now try the third one. |
417 TestCompletionCallback callback4; | 417 TestCompletionCallback callback4; |
418 rv = service->ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL); | 418 rv = service->ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL); |
419 EXPECT_EQ(OK, rv); | 419 EXPECT_EQ(OK, rv); |
420 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 420 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
421 | 421 |
| 422 // We fake another error. At this point we have tried all of the |
| 423 // proxy servers we thought were valid; next we try the proxy server |
| 424 // that was in our bad proxies map (foopy1:8080). |
| 425 TestCompletionCallback callback5; |
| 426 rv = service->ReconsiderProxyAfterError(url, &info, &callback5, NULL, NULL); |
| 427 EXPECT_EQ(OK, rv); |
| 428 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 429 |
422 // Fake another error, the last proxy is gone, the list should now be empty, | 430 // Fake another error, the last proxy is gone, the list should now be empty, |
423 // so there is nothing left to try. | 431 // so there is nothing left to try. |
424 TestCompletionCallback callback5; | 432 TestCompletionCallback callback6; |
425 rv = service->ReconsiderProxyAfterError(url, &info, &callback5, NULL, NULL); | 433 rv = service->ReconsiderProxyAfterError(url, &info, &callback6, NULL, NULL); |
426 EXPECT_EQ(ERR_FAILED, rv); | 434 EXPECT_EQ(ERR_FAILED, rv); |
427 EXPECT_FALSE(info.is_direct()); | 435 EXPECT_FALSE(info.is_direct()); |
428 EXPECT_TRUE(info.is_empty()); | 436 EXPECT_TRUE(info.is_empty()); |
429 | 437 |
430 // TODO(nsylvain): Test that the proxy can be retried after the delay. | 438 // TODO(nsylvain): Test that the proxy can be retried after the delay. |
431 } | 439 } |
432 | 440 |
433 // This test is similar to ProxyFallback, but this time we have an explicit | 441 // This test is similar to ProxyFallback, but this time we have an explicit |
434 // fallback choice to DIRECT. | 442 // fallback choice to DIRECT. |
435 TEST(ProxyServiceTest, ProxyFallbackToDirect) { | 443 TEST(ProxyServiceTest, ProxyFallbackToDirect) { |
(...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 // Complete the pending second request. | 1871 // Complete the pending second request. |
1864 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 1872 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
1865 resolver->pending_requests()[0]->CompleteNow(OK); | 1873 resolver->pending_requests()[0]->CompleteNow(OK); |
1866 | 1874 |
1867 // Wait for completion callback, and verify that the request ran as expected. | 1875 // Wait for completion callback, and verify that the request ran as expected. |
1868 EXPECT_EQ(OK, callback2.WaitForResult()); | 1876 EXPECT_EQ(OK, callback2.WaitForResult()); |
1869 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 1877 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
1870 } | 1878 } |
1871 | 1879 |
1872 } // namespace net | 1880 } // namespace net |
OLD | NEW |