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

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

Issue 542029: Retry proxies which were cached as bad before giving up.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 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
« no previous file with comments | « net/proxy/proxy_list.cc ('k') | net/proxy/proxy_service.cc » ('j') | 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) 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_list.h" 5 #include "net/proxy/proxy_list.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace net {
9
10 namespace {
11
8 // Test parsing from a PAC string. 12 // Test parsing from a PAC string.
9 TEST(ProxyListTest, SetFromPacString) { 13 TEST(ProxyListTest, SetFromPacString) {
10 const struct { 14 const struct {
11 const char* pac_input; 15 const char* pac_input;
12 const char* pac_output; 16 const char* pac_output;
13 } tests[] = { 17 } tests[] = {
14 // Valid inputs: 18 // Valid inputs:
15 { "PROXY foopy:10", 19 { "PROXY foopy:10",
16 "PROXY foopy:10", 20 "PROXY foopy:10",
17 }, 21 },
(...skipping 25 matching lines...) Expand all
43 }, 47 },
44 { "PROXY", 48 { "PROXY",
45 "DIRECT", 49 "DIRECT",
46 }, 50 },
47 { "PROXY foopy1 ; JUNK ; JUNK ; SOCKS5 foopy2 ; ;", 51 { "PROXY foopy1 ; JUNK ; JUNK ; SOCKS5 foopy2 ; ;",
48 "PROXY foopy1:80;SOCKS5 foopy2:1080", 52 "PROXY foopy1:80;SOCKS5 foopy2:1080",
49 }, 53 },
50 }; 54 };
51 55
52 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 56 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
53 net::ProxyList list; 57 ProxyList list;
54 list.SetFromPacString(tests[i].pac_input); 58 list.SetFromPacString(tests[i].pac_input);
55 EXPECT_EQ(tests[i].pac_output, list.ToPacString()); 59 EXPECT_EQ(tests[i].pac_output, list.ToPacString());
56 EXPECT_FALSE(list.IsEmpty()); 60 EXPECT_FALSE(list.IsEmpty());
57 } 61 }
58 } 62 }
59 63
60 TEST(ProxyListTest, RemoveProxiesWithoutScheme) { 64 TEST(ProxyListTest, RemoveProxiesWithoutScheme) {
61 const struct { 65 const struct {
62 const char* pac_input; 66 const char* pac_input;
63 int filter; 67 int filter;
64 const char* filtered_pac_output; 68 const char* filtered_pac_output;
65 } tests[] = { 69 } tests[] = {
66 { "PROXY foopy:10 ; SOCKS5 foopy2 ; SOCKS foopy11 ; PROXY foopy3 ; DIRECT", 70 { "PROXY foopy:10 ; SOCKS5 foopy2 ; SOCKS foopy11 ; PROXY foopy3 ; DIRECT",
67 // Remove anything that isn't HTTP or DIRECT. 71 // Remove anything that isn't HTTP or DIRECT.
68 net::ProxyServer::SCHEME_DIRECT | net::ProxyServer::SCHEME_HTTP, 72 ProxyServer::SCHEME_DIRECT | ProxyServer::SCHEME_HTTP,
69 "PROXY foopy:10;PROXY foopy3:80;DIRECT", 73 "PROXY foopy:10;PROXY foopy3:80;DIRECT",
70 }, 74 },
71 { "PROXY foopy:10 ; SOCKS5 foopy2", 75 { "PROXY foopy:10 ; SOCKS5 foopy2",
72 // Remove anything that isn't HTTP or SOCKS5. 76 // Remove anything that isn't HTTP or SOCKS5.
73 net::ProxyServer::SCHEME_DIRECT | net::ProxyServer::SCHEME_SOCKS4, 77 ProxyServer::SCHEME_DIRECT | ProxyServer::SCHEME_SOCKS4,
74 "", 78 "",
75 }, 79 },
76 }; 80 };
77 81
78 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 82 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
79 net::ProxyList list; 83 ProxyList list;
80 list.SetFromPacString(tests[i].pac_input); 84 list.SetFromPacString(tests[i].pac_input);
81 list.RemoveProxiesWithoutScheme(tests[i].filter); 85 list.RemoveProxiesWithoutScheme(tests[i].filter);
82 EXPECT_EQ(tests[i].filtered_pac_output, list.ToPacString()); 86 EXPECT_EQ(tests[i].filtered_pac_output, list.ToPacString());
83 } 87 }
84 } 88 }
89
90 TEST(ProxyListTest, DeprioritizeBadProxies) {
91 // Retry info that marks a proxy as being bad for a *very* long time (to avoid
92 // the test depending on the current time.)
93 ProxyRetryInfo proxy_retry_info;
94 proxy_retry_info.bad_until =
95 base::TimeTicks::Now() + base::TimeDelta::FromDays(1);
96
97 // Call DeprioritizeBadProxies with an empty map -- should have no effect.
98 {
99 ProxyList list;
100 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80");
101
102 ProxyRetryInfoMap retry_info_map;
103 list.DeprioritizeBadProxies(retry_info_map);
104 EXPECT_EQ("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80",
105 list.ToPacString());
106 }
107
108 // Call DeprioritizeBadProxies with 2 of the three proxies marked as bad.
109 // These proxies should be retried last.
110 {
111 ProxyList list;
112 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80");
113
114 ProxyRetryInfoMap retry_info_map;
115 retry_info_map["foopy1:80"] = proxy_retry_info;
116 retry_info_map["foopy3:80"] = proxy_retry_info;
117 retry_info_map["socks5://localhost:1080"] = proxy_retry_info;
118
119 list.DeprioritizeBadProxies(retry_info_map);
120
121 EXPECT_EQ("PROXY foopy2:80;PROXY foopy1:80;PROXY foopy3:80",
122 list.ToPacString());
123 }
124
125 // Call DeprioritizeBadProxies where ALL of the proxies are marked as bad.
126 // This should have no effect on the order.
127 {
128 ProxyList list;
129 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80");
130
131 ProxyRetryInfoMap retry_info_map;
132 retry_info_map["foopy1:80"] = proxy_retry_info;
133 retry_info_map["foopy2:80"] = proxy_retry_info;
134 retry_info_map["foopy3:80"] = proxy_retry_info;
135
136 list.DeprioritizeBadProxies(retry_info_map);
137
138 EXPECT_EQ("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80",
139 list.ToPacString());
140 }
141 }
142
143 } // namesapce
144
145 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_list.cc ('k') | net/proxy/proxy_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698