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

Side by Side Diff: net/proxy/proxy_service_unittest.cc

Issue 7532011: Only mark a proxy as bad if we have confirmation that another proxy succeeded for the same request. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better names Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« net/proxy/proxy_service.cc ('K') | « net/proxy/proxy_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 534 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
535 535
536 // Fake an error on the proxy. 536 // Fake an error on the proxy.
537 TestCompletionCallback callback2; 537 TestCompletionCallback callback2;
538 rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL, 538 rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL,
539 BoundNetLog()); 539 BoundNetLog());
540 EXPECT_EQ(OK, rv); 540 EXPECT_EQ(OK, rv);
541 541
542 // The second proxy should be specified. 542 // The second proxy should be specified.
543 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); 543 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI());
544 // Report back that the second proxy worked. This will globally mark the
545 // first proxy as bad.
546 service.ReportSuccess(info);
544 547
545 TestCompletionCallback callback3; 548 TestCompletionCallback callback3;
546 rv = service.ResolveProxy(url, &info, &callback3, NULL, BoundNetLog()); 549 rv = service.ResolveProxy(url, &info, &callback3, NULL, BoundNetLog());
547 EXPECT_EQ(ERR_IO_PENDING, rv); 550 EXPECT_EQ(ERR_IO_PENDING, rv);
548 551
549 ASSERT_EQ(1u, resolver->pending_requests().size()); 552 ASSERT_EQ(1u, resolver->pending_requests().size());
550 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 553 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
551 554
552 // Set the result in proxy resolver -- the second result is already known 555 // Set the result in proxy resolver -- the second result is already known
553 // to be bad, so we will not try to use it initially. 556 // to be bad, so we will not try to use it initially.
(...skipping 23 matching lines...) Expand all
577 580
578 // Fake another error, the last proxy is gone, the list should now be empty, 581 // Fake another error, the last proxy is gone, the list should now be empty,
579 // so there is nothing left to try. 582 // so there is nothing left to try.
580 TestCompletionCallback callback6; 583 TestCompletionCallback callback6;
581 rv = service.ReconsiderProxyAfterError(url, &info, &callback6, NULL, 584 rv = service.ReconsiderProxyAfterError(url, &info, &callback6, NULL,
582 BoundNetLog()); 585 BoundNetLog());
583 EXPECT_EQ(ERR_FAILED, rv); 586 EXPECT_EQ(ERR_FAILED, rv);
584 EXPECT_FALSE(info.is_direct()); 587 EXPECT_FALSE(info.is_direct());
585 EXPECT_TRUE(info.is_empty()); 588 EXPECT_TRUE(info.is_empty());
586 589
590 // Look up proxies again
591 TestCompletionCallback callback7;
592 rv = service.ResolveProxy(url, &info, &callback7, NULL, BoundNetLog());
593 EXPECT_EQ(ERR_IO_PENDING, rv);
594
595 ASSERT_EQ(1u, resolver->pending_requests().size());
596 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
597
598 // This time, the first 3 results have been found to be bad, but only the
599 // first proxy has been confirmed ...
600 resolver->pending_requests()[0]->results()->UseNamedProxy(
601 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091");
602 resolver->pending_requests()[0]->CompleteNow(OK);
603
604 // ... therefore, we should see the second proxy first.
605 EXPECT_EQ(OK, callback7.WaitForResult());
606 EXPECT_FALSE(info.is_direct());
607 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI());
608
587 // TODO(nsylvain): Test that the proxy can be retried after the delay. 609 // TODO(nsylvain): Test that the proxy can be retried after the delay.
588 } 610 }
589 611
590 // This test is similar to ProxyFallback, but this time we have an explicit 612 // This test is similar to ProxyFallback, but this time we have an explicit
591 // fallback choice to DIRECT. 613 // fallback choice to DIRECT.
592 TEST(ProxyServiceTest, ProxyFallbackToDirect) { 614 TEST(ProxyServiceTest, ProxyFallbackToDirect) {
593 MockProxyConfigService* config_service = 615 MockProxyConfigService* config_service =
594 new MockProxyConfigService("http://foopy/proxy.pac"); 616 new MockProxyConfigService("http://foopy/proxy.pac");
595 617
596 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 618 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
(...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 log.GetEntries(&entries); 1892 log.GetEntries(&entries);
1871 1893
1872 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, 1894 EXPECT_TRUE(LogContainsEntryWithType(entries, 0,
1873 NetLog::TYPE_PROXY_CONFIG_CHANGED)); 1895 NetLog::TYPE_PROXY_CONFIG_CHANGED));
1874 ASSERT_EQ(13u, entries.size()); 1896 ASSERT_EQ(13u, entries.size());
1875 for (size_t i = 1; i < entries.size(); ++i) 1897 for (size_t i = 1; i < entries.size(); ++i)
1876 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); 1898 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type);
1877 } 1899 }
1878 1900
1879 } // namespace net 1901 } // namespace net
OLDNEW
« net/proxy/proxy_service.cc ('K') | « net/proxy/proxy_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698