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_list.h" | 5 #include "net/proxy/proxy_list.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/log/net_log.h" | 10 #include "net/log/net_log.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 { | 174 { |
175 ProxyList list; | 175 ProxyList list; |
176 ProxyRetryInfoMap retry_info_map; | 176 ProxyRetryInfoMap retry_info_map; |
177 BoundNetLog net_log; | 177 BoundNetLog net_log; |
178 ProxyServer proxy_server( | 178 ProxyServer proxy_server( |
179 ProxyServer::FromURI("foopy1:80", ProxyServer::SCHEME_HTTP)); | 179 ProxyServer::FromURI("foopy1:80", ProxyServer::SCHEME_HTTP)); |
180 std::vector<ProxyServer> bad_proxies; | 180 std::vector<ProxyServer> bad_proxies; |
181 bad_proxies.push_back(proxy_server); | 181 bad_proxies.push_back(proxy_server); |
182 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); | 182 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); |
183 list.UpdateRetryInfoOnFallback( | 183 list.UpdateRetryInfoOnFallback( |
184 &retry_info_map, base::TimeDelta::FromSeconds(60), true, bad_proxies, | 184 retry_info_map, base::TimeDelta::FromSeconds(60), true, bad_proxies, |
185 ERR_PROXY_CONNECTION_FAILED, net_log); | 185 ERR_PROXY_CONNECTION_FAILED, net_log); |
186 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); | 186 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); |
187 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, | 187 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, |
188 retry_info_map[proxy_server.ToURI()].net_error); | 188 retry_info_map[proxy_server.ToURI()].net_error); |
189 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); | 189 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); |
190 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); | 190 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); |
191 } | 191 } |
192 // Retrying should put the first proxy on the retry list, even if there | 192 // Retrying should put the first proxy on the retry list, even if there |
193 // was no network error. | 193 // was no network error. |
194 { | 194 { |
195 ProxyList list; | 195 ProxyList list; |
196 ProxyRetryInfoMap retry_info_map; | 196 ProxyRetryInfoMap retry_info_map; |
197 BoundNetLog net_log; | 197 BoundNetLog net_log; |
198 ProxyServer proxy_server( | 198 ProxyServer proxy_server( |
199 ProxyServer::FromURI("foopy1:80", ProxyServer::SCHEME_HTTP)); | 199 ProxyServer::FromURI("foopy1:80", ProxyServer::SCHEME_HTTP)); |
200 std::vector<ProxyServer> bad_proxies; | 200 std::vector<ProxyServer> bad_proxies; |
201 bad_proxies.push_back(proxy_server); | 201 bad_proxies.push_back(proxy_server); |
202 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); | 202 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); |
203 list.UpdateRetryInfoOnFallback(&retry_info_map, | 203 list.UpdateRetryInfoOnFallback(retry_info_map, |
204 base::TimeDelta::FromSeconds(60), true, | 204 base::TimeDelta::FromSeconds(60), true, |
205 bad_proxies, OK, net_log); | 205 bad_proxies, OK, net_log); |
206 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); | 206 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); |
207 EXPECT_EQ(OK, retry_info_map[proxy_server.ToURI()].net_error); | 207 EXPECT_EQ(OK, retry_info_map[proxy_server.ToURI()].net_error); |
208 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); | 208 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); |
209 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); | 209 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); |
210 } | 210 } |
211 // Including another bad proxy should put both the first and the specified | 211 // Including another bad proxy should put both the first and the specified |
212 // proxy on the retry list. | 212 // proxy on the retry list. |
213 { | 213 { |
214 ProxyList list; | 214 ProxyList list; |
215 ProxyRetryInfoMap retry_info_map; | 215 ProxyRetryInfoMap retry_info_map; |
216 BoundNetLog net_log; | 216 BoundNetLog net_log; |
217 ProxyServer proxy_server = ProxyServer::FromURI("foopy3:80", | 217 ProxyServer proxy_server = ProxyServer::FromURI("foopy3:80", |
218 ProxyServer::SCHEME_HTTP); | 218 ProxyServer::SCHEME_HTTP); |
219 std::vector<ProxyServer> bad_proxies; | 219 std::vector<ProxyServer> bad_proxies; |
220 bad_proxies.push_back(proxy_server); | 220 bad_proxies.push_back(proxy_server); |
221 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); | 221 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); |
222 list.UpdateRetryInfoOnFallback( | 222 list.UpdateRetryInfoOnFallback( |
223 &retry_info_map, base::TimeDelta::FromSeconds(60), true, bad_proxies, | 223 retry_info_map, base::TimeDelta::FromSeconds(60), true, bad_proxies, |
224 ERR_NAME_RESOLUTION_FAILED, net_log); | 224 ERR_NAME_RESOLUTION_FAILED, net_log); |
225 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); | 225 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); |
226 EXPECT_EQ(ERR_NAME_RESOLUTION_FAILED, | 226 EXPECT_EQ(ERR_NAME_RESOLUTION_FAILED, |
227 retry_info_map[proxy_server.ToURI()].net_error); | 227 retry_info_map[proxy_server.ToURI()].net_error); |
228 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); | 228 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); |
229 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy3:80")); | 229 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy3:80")); |
230 } | 230 } |
231 // If the first proxy is DIRECT, nothing is added to the retry list, even | 231 // If the first proxy is DIRECT, nothing is added to the retry list, even |
232 // if another bad proxy is specified. | 232 // if another bad proxy is specified. |
233 { | 233 { |
234 ProxyList list; | 234 ProxyList list; |
235 ProxyRetryInfoMap retry_info_map; | 235 ProxyRetryInfoMap retry_info_map; |
236 BoundNetLog net_log; | 236 BoundNetLog net_log; |
237 ProxyServer proxy_server = ProxyServer::FromURI("foopy2:80", | 237 ProxyServer proxy_server = ProxyServer::FromURI("foopy2:80", |
238 ProxyServer::SCHEME_HTTP); | 238 ProxyServer::SCHEME_HTTP); |
239 std::vector<ProxyServer> bad_proxies; | 239 std::vector<ProxyServer> bad_proxies; |
240 bad_proxies.push_back(proxy_server); | 240 bad_proxies.push_back(proxy_server); |
241 list.SetFromPacString("DIRECT;PROXY foopy2:80;PROXY foopy3:80"); | 241 list.SetFromPacString("DIRECT;PROXY foopy2:80;PROXY foopy3:80"); |
242 list.UpdateRetryInfoOnFallback(&retry_info_map, | 242 list.UpdateRetryInfoOnFallback(retry_info_map, |
243 base::TimeDelta::FromSeconds(60), true, | 243 base::TimeDelta::FromSeconds(60), true, |
244 bad_proxies, OK, net_log); | 244 bad_proxies, OK, net_log); |
245 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); | 245 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); |
246 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); | 246 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); |
247 } | 247 } |
248 // If the bad proxy is already on the retry list, and the old retry info would | 248 // If the bad proxy is already on the retry list, and the old retry info would |
249 // cause the proxy to be retried later than the newly specified retry info, | 249 // cause the proxy to be retried later than the newly specified retry info, |
250 // then the old retry info should be kept. | 250 // then the old retry info should be kept. |
251 { | 251 { |
252 ProxyList list; | 252 ProxyList list; |
253 ProxyRetryInfoMap retry_info_map; | 253 ProxyRetryInfoMap retry_info_map; |
254 BoundNetLog net_log; | 254 BoundNetLog net_log; |
255 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); | 255 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); |
256 | 256 |
257 // First, mark the proxy as bad for 60 seconds. | 257 // First, mark the proxy as bad for 60 seconds. |
258 list.UpdateRetryInfoOnFallback( | 258 list.UpdateRetryInfoOnFallback( |
259 &retry_info_map, base::TimeDelta::FromSeconds(60), true, | 259 retry_info_map, base::TimeDelta::FromSeconds(60), true, |
260 std::vector<ProxyServer>(), ERR_PROXY_CONNECTION_FAILED, net_log); | 260 std::vector<ProxyServer>(), ERR_PROXY_CONNECTION_FAILED, net_log); |
261 // Next, mark the same proxy as bad for 1 second. This call should have no | 261 // Next, mark the same proxy as bad for 1 second. This call should have no |
262 // effect, since this would cause the bad proxy to be retried sooner than | 262 // effect, since this would cause the bad proxy to be retried sooner than |
263 // the existing retry info. | 263 // the existing retry info. |
264 list.UpdateRetryInfoOnFallback(&retry_info_map, | 264 list.UpdateRetryInfoOnFallback(retry_info_map, |
265 base::TimeDelta::FromSeconds(1), false, | 265 base::TimeDelta::FromSeconds(1), false, |
266 std::vector<ProxyServer>(), OK, net_log); | 266 std::vector<ProxyServer>(), OK, net_log); |
267 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); | 267 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); |
268 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, | 268 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, |
269 retry_info_map["foopy1:80"].net_error); | 269 retry_info_map["foopy1:80"].net_error); |
270 EXPECT_TRUE(retry_info_map["foopy1:80"].try_while_bad); | 270 EXPECT_TRUE(retry_info_map["foopy1:80"].try_while_bad); |
271 EXPECT_EQ(base::TimeDelta::FromSeconds(60), | 271 EXPECT_EQ(base::TimeDelta::FromSeconds(60), |
272 retry_info_map["foopy1:80"].current_delay); | 272 retry_info_map["foopy1:80"].current_delay); |
273 EXPECT_GT(retry_info_map["foopy1:80"].bad_until, | 273 EXPECT_GT(retry_info_map["foopy1:80"].bad_until, |
274 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(30)); | 274 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(30)); |
275 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); | 275 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); |
276 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); | 276 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); |
277 } | 277 } |
278 // If the bad proxy is already on the retry list, and the newly specified | 278 // If the bad proxy is already on the retry list, and the newly specified |
279 // retry info would cause the proxy to be retried later than the old retry | 279 // retry info would cause the proxy to be retried later than the old retry |
280 // info, then the old retry info should be replaced with the new retry info. | 280 // info, then the old retry info should be replaced with the new retry info. |
281 { | 281 { |
282 ProxyList list; | 282 ProxyList list; |
283 ProxyRetryInfoMap retry_info_map; | 283 ProxyRetryInfoMap retry_info_map; |
284 BoundNetLog net_log; | 284 BoundNetLog net_log; |
285 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); | 285 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80"); |
286 | 286 |
287 // First, mark the proxy as bad for 1 second. | 287 // First, mark the proxy as bad for 1 second. |
288 list.UpdateRetryInfoOnFallback(&retry_info_map, | 288 list.UpdateRetryInfoOnFallback(retry_info_map, |
289 base::TimeDelta::FromSeconds(1), false, | 289 base::TimeDelta::FromSeconds(1), false, |
290 std::vector<ProxyServer>(), OK, net_log); | 290 std::vector<ProxyServer>(), OK, net_log); |
291 // Next, mark the same proxy as bad for 60 seconds. This call should replace | 291 // Next, mark the same proxy as bad for 60 seconds. This call should replace |
292 // the existing retry info with the new 60 second retry info. | 292 // the existing retry info with the new 60 second retry info. |
293 list.UpdateRetryInfoOnFallback( | 293 list.UpdateRetryInfoOnFallback( |
294 &retry_info_map, base::TimeDelta::FromSeconds(60), true, | 294 retry_info_map, base::TimeDelta::FromSeconds(60), true, |
295 std::vector<ProxyServer>(), ERR_PROXY_CONNECTION_FAILED, net_log); | 295 std::vector<ProxyServer>(), ERR_PROXY_CONNECTION_FAILED, net_log); |
296 | 296 |
297 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); | 297 EXPECT_TRUE(retry_info_map.end() != retry_info_map.find("foopy1:80")); |
298 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, | 298 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, |
299 retry_info_map["foopy1:80"].net_error); | 299 retry_info_map["foopy1:80"].net_error); |
300 EXPECT_TRUE(retry_info_map["foopy1:80"].try_while_bad); | 300 EXPECT_TRUE(retry_info_map["foopy1:80"].try_while_bad); |
301 EXPECT_EQ(base::TimeDelta::FromSeconds(60), | 301 EXPECT_EQ(base::TimeDelta::FromSeconds(60), |
302 retry_info_map["foopy1:80"].current_delay); | 302 retry_info_map["foopy1:80"].current_delay); |
303 EXPECT_GT(retry_info_map["foopy1:80"].bad_until, | 303 EXPECT_GT(retry_info_map["foopy1:80"].bad_until, |
304 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(30)); | 304 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(30)); |
305 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); | 305 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy2:80")); |
306 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); | 306 EXPECT_TRUE(retry_info_map.end() == retry_info_map.find("foopy3:80")); |
307 } | 307 } |
308 } | 308 } |
309 | 309 |
310 } // namesapce | 310 } // namesapce |
311 | 311 |
312 } // namespace net | 312 } // namespace net |
OLD | NEW |