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