diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-12 22:10:25 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-12 22:10:25 +0000 |
commit | 02cf5a4cb28d86669bcc4c3934f51437795b05ac (patch) | |
tree | ebf581c062a8f469bd0dbaa18df1e37b2ad8e0b1 /net/proxy/proxy_list_unittest.cc | |
parent | d6fc4854834e9764dadeaf9fa826c06776d9a96e (diff) | |
download | chromium_src-02cf5a4cb28d86669bcc4c3934f51437795b05ac.zip chromium_src-02cf5a4cb28d86669bcc4c3934f51437795b05ac.tar.gz chromium_src-02cf5a4cb28d86669bcc4c3934f51437795b05ac.tar.bz2 |
Retry proxies which were cached as bad before giving up.
This morphs ProxyList::RemoveBadProxies() into ProxyList::DeprioritizeBadProxies(), such that "bad proxies" are moved to the end of the fallback list rather than removed alltogether.
BUG=31983
TEST=ProxyListTest.DeprioritizeBadProxies
Review URL: http://codereview.chromium.org/542029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36054 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_list_unittest.cc')
-rw-r--r-- | net/proxy/proxy_list_unittest.cc | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/net/proxy/proxy_list_unittest.cc b/net/proxy/proxy_list_unittest.cc index 401461f..397bb7c 100644 --- a/net/proxy/proxy_list_unittest.cc +++ b/net/proxy/proxy_list_unittest.cc @@ -5,6 +5,10 @@ #include "net/proxy/proxy_list.h" #include "testing/gtest/include/gtest/gtest.h" +namespace net { + +namespace { + // Test parsing from a PAC string. TEST(ProxyListTest, SetFromPacString) { const struct { @@ -50,7 +54,7 @@ TEST(ProxyListTest, SetFromPacString) { }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { - net::ProxyList list; + ProxyList list; list.SetFromPacString(tests[i].pac_input); EXPECT_EQ(tests[i].pac_output, list.ToPacString()); EXPECT_FALSE(list.IsEmpty()); @@ -65,20 +69,77 @@ TEST(ProxyListTest, RemoveProxiesWithoutScheme) { } tests[] = { { "PROXY foopy:10 ; SOCKS5 foopy2 ; SOCKS foopy11 ; PROXY foopy3 ; DIRECT", // Remove anything that isn't HTTP or DIRECT. - net::ProxyServer::SCHEME_DIRECT | net::ProxyServer::SCHEME_HTTP, + ProxyServer::SCHEME_DIRECT | ProxyServer::SCHEME_HTTP, "PROXY foopy:10;PROXY foopy3:80;DIRECT", }, { "PROXY foopy:10 ; SOCKS5 foopy2", // Remove anything that isn't HTTP or SOCKS5. - net::ProxyServer::SCHEME_DIRECT | net::ProxyServer::SCHEME_SOCKS4, + ProxyServer::SCHEME_DIRECT | ProxyServer::SCHEME_SOCKS4, "", }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { - net::ProxyList list; + ProxyList list; list.SetFromPacString(tests[i].pac_input); list.RemoveProxiesWithoutScheme(tests[i].filter); EXPECT_EQ(tests[i].filtered_pac_output, list.ToPacString()); } } + +TEST(ProxyListTest, DeprioritizeBadProxies) { + // Retry info that marks a proxy as being bad for a *very* long time (to avoid + // the test depending on the current time.) + ProxyRetryInfo proxy_retry_info; + proxy_retry_info.bad_until = + base::TimeTicks::Now() + base::TimeDelta::FromDays(1); + + // Call DeprioritizeBadProxies with an empty map -- should have no effect. + { + ProxyList list; + list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); + + ProxyRetryInfoMap retry_info_map; + list.DeprioritizeBadProxies(retry_info_map); + EXPECT_EQ("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80", + list.ToPacString()); + } + + // Call DeprioritizeBadProxies with 2 of the three proxies marked as bad. + // These proxies should be retried last. + { + ProxyList list; + list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); + + ProxyRetryInfoMap retry_info_map; + retry_info_map["foopy1:80"] = proxy_retry_info; + retry_info_map["foopy3:80"] = proxy_retry_info; + retry_info_map["socks5://localhost:1080"] = proxy_retry_info; + + list.DeprioritizeBadProxies(retry_info_map); + + EXPECT_EQ("PROXY foopy2:80;PROXY foopy1:80;PROXY foopy3:80", + list.ToPacString()); + } + + // Call DeprioritizeBadProxies where ALL of the proxies are marked as bad. + // This should have no effect on the order. + { + ProxyList list; + list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); + + ProxyRetryInfoMap retry_info_map; + retry_info_map["foopy1:80"] = proxy_retry_info; + retry_info_map["foopy2:80"] = proxy_retry_info; + retry_info_map["foopy3:80"] = proxy_retry_info; + + list.DeprioritizeBadProxies(retry_info_map); + + EXPECT_EQ("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80", + list.ToPacString()); + } +} + +} // namesapce + +} // namespace net |