OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1569 EXPECT_EQ(OK, rv); | 1569 EXPECT_EQ(OK, rv); |
1570 EXPECT_TRUE(info[0].is_direct()); | 1570 EXPECT_TRUE(info[0].is_direct()); |
1571 | 1571 |
1572 // Request for a .com domain hits the proxy. | 1572 // Request for a .com domain hits the proxy. |
1573 rv = service.ResolveProxy(url2, LOAD_NORMAL, &info[1], callback[1].callback(), | 1573 rv = service.ResolveProxy(url2, LOAD_NORMAL, &info[1], callback[1].callback(), |
1574 NULL, NULL, BoundNetLog()); | 1574 NULL, NULL, BoundNetLog()); |
1575 EXPECT_EQ(OK, rv); | 1575 EXPECT_EQ(OK, rv); |
1576 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); | 1576 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); |
1577 } | 1577 } |
1578 | 1578 |
| 1579 TEST_F(ProxyServiceTest, MarkProxiesAsBadTests) { |
| 1580 ProxyConfig config; |
| 1581 config.proxy_rules().ParseFromString( |
| 1582 "http=foopy1:8080;http=foopy2:8080;http=foopy3.8080;http=foopy4:8080"); |
| 1583 config.set_auto_detect(false); |
| 1584 |
| 1585 ProxyList proxy_list; |
| 1586 std::vector<ProxyServer> additional_bad_proxies; |
| 1587 for (const ProxyServer& proxy_server : |
| 1588 config.proxy_rules().proxies_for_http.GetAll()) { |
| 1589 proxy_list.AddProxyServer(proxy_server); |
| 1590 if (proxy_server == config.proxy_rules().proxies_for_http.Get()) |
| 1591 continue; |
| 1592 |
| 1593 additional_bad_proxies.push_back(proxy_server); |
| 1594 } |
| 1595 |
| 1596 EXPECT_EQ(3u, additional_bad_proxies.size()); |
| 1597 |
| 1598 ProxyService service(new MockProxyConfigService(config), nullptr, NULL); |
| 1599 ProxyInfo proxy_info; |
| 1600 proxy_info.UseProxyList(proxy_list); |
| 1601 const ProxyRetryInfoMap& retry_info = service.proxy_retry_info(); |
| 1602 service.MarkProxiesAsBadUntil(proxy_info, base::TimeDelta::FromSeconds(1), |
| 1603 additional_bad_proxies, BoundNetLog()); |
| 1604 ASSERT_EQ(4u, retry_info.size()); |
| 1605 for (const ProxyServer& proxy_server : |
| 1606 config.proxy_rules().proxies_for_http.GetAll()) { |
| 1607 ProxyRetryInfoMap::const_iterator i = |
| 1608 retry_info.find(proxy_server.host_port_pair().ToString()); |
| 1609 ASSERT_TRUE(i != retry_info.end()); |
| 1610 } |
| 1611 } |
1579 | 1612 |
1580 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { | 1613 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { |
1581 ProxyConfig config; | 1614 ProxyConfig config; |
1582 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); | 1615 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); |
1583 config.set_auto_detect(false); | 1616 config.set_auto_detect(false); |
1584 { | 1617 { |
1585 ProxyService service(new MockProxyConfigService(config), nullptr, NULL); | 1618 ProxyService service(new MockProxyConfigService(config), nullptr, NULL); |
1586 GURL test_url("http://www.msn.com"); | 1619 GURL test_url("http://www.msn.com"); |
1587 ProxyInfo info; | 1620 ProxyInfo info; |
1588 TestCompletionCallback callback; | 1621 TestCompletionCallback callback; |
(...skipping 1651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3240 url, LOAD_NORMAL, &info, NULL, log.bound()); | 3273 url, LOAD_NORMAL, &info, NULL, log.bound()); |
3241 EXPECT_TRUE(synchronous_success); | 3274 EXPECT_TRUE(synchronous_success); |
3242 EXPECT_FALSE(info.is_direct()); | 3275 EXPECT_FALSE(info.is_direct()); |
3243 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); | 3276 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); |
3244 | 3277 |
3245 // No request should have been queued. | 3278 // No request should have been queued. |
3246 EXPECT_EQ(0u, factory->pending_requests().size()); | 3279 EXPECT_EQ(0u, factory->pending_requests().size()); |
3247 } | 3280 } |
3248 | 3281 |
3249 } // namespace net | 3282 } // namespace net |
OLD | NEW |