Chromium Code Reviews| Index: components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc |
| diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc |
| index cb8f7af56907903112629df0f6729643bd8d6a50..2523d6951108cbf2f554315a7673b428280d8ade 100644 |
| --- a/components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc |
| +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc |
| @@ -4,10 +4,14 @@ |
| #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
| +#include <map> |
| + |
| #include "base/command_line.h" |
| #include "base/logging.h" |
| #include "components/data_reduction_proxy/browser/data_reduction_proxy_params_test_utils.h" |
| #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h" |
| +#include "net/proxy/proxy_retry_info.h" |
| +#include "net/proxy/proxy_server.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace data_reduction_proxy { |
| @@ -558,4 +562,355 @@ TEST_F(DataReductionProxyParamsTest, IsDataReductionProxy) { |
| net::HostPortPair::FromURL(proxy_servers.second))); |
| } |
| } |
| + |
| +std::string GetRetryMapKeyFromOrigin(std::string origin) { |
| + // The retry map has the scheme prefix for https but not for http |
| + return net::ProxyServer(GURL(origin).SchemeIs(url::kHttpsScheme) ? |
| + net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, |
| + net::HostPortPair::FromURL(GURL(origin))).ToURI(); |
| +} |
| + |
| +TEST_F(DataReductionProxyParamsTest, AreProxiesBypassed) { |
| + const struct { |
| + // proxy rules |
| + bool allowed; |
| + bool fallback_allowed; |
| + bool alt_allowed; |
| + bool ssl; |
| + // proxies in retry map |
| + bool origin; |
| + bool fallback_origin; |
| + bool alt_origin; |
| + bool alt_fallback_origin; |
| + bool ssl_origin; |
| + |
| + bool expected_result; |
| + } tests[] = { |
|
bengr
2014/07/22 16:59:44
Indentation should be only two, and you should pro
megjablon
2014/07/22 18:40:45
I think the comment makes more sense in the curren
|
| + { // proxy rules |
| + false, |
| + false, |
| + false, |
| + false, |
| + // proxies in retry map |
| + false, |
| + false, |
| + false, |
| + false, |
| + false, |
| + // expected result |
| + false, |
| + }, |
| + { // proxy rules |
| + true, |
| + false, |
| + false, |
| + false, |
| + // proxies in retry map |
| + false, |
| + false, |
| + false, |
| + false, |
| + false, |
| + // expected result |
| + false, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + false, |
| + false, |
| + // proxies in retry map |
| + false, |
| + false, |
| + false, |
| + false, |
| + false, |
| + // expected result |
| + false, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + true, |
| + false, |
| + // proxies in retry map |
| + false, |
| + false, |
| + false, |
| + false, |
| + false, |
| + // expected result |
| + false, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + true, |
| + true, |
| + // proxies in retry map |
| + false, |
| + false, |
| + false, |
| + false, |
| + false, |
| + // expected result |
| + false, |
| + }, |
| + { // proxy rules |
| + false, |
| + false, |
| + false, |
| + true, |
| + // proxies in retry map |
| + false, |
| + false, |
| + false, |
| + false, |
| + true, |
| + // expected result |
| + false, |
| + }, |
| + { // proxy rules |
| + false, |
| + false, |
| + true, |
| + true, |
| + // proxies in retry map |
| + false, |
| + false, |
| + false, |
| + false, |
| + true, |
| + // expected result |
| + true, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + true, |
| + true, |
| + // proxies in retry map |
| + false, |
| + false, |
| + false, |
| + false, |
| + true, |
| + // expected result |
| + true, |
| + }, |
| + { // proxy rules |
| + true, |
| + false, |
| + false, |
| + false, |
| + // proxies in retry map |
| + true, |
| + false, |
| + false, |
| + false, |
| + false, |
| + // expected result |
| + true, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + false, |
| + false, |
| + // proxies in retry map |
| + true, |
| + false, |
| + false, |
| + false, |
| + false, |
| + // expected result |
| + false, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + false, |
| + false, |
| + // proxies in retry map |
| + true, |
| + true, |
| + false, |
| + false, |
| + false, |
| + // expected result |
| + true, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + true, |
| + false, |
| + // proxies in retry map |
| + true, |
| + true, |
| + false, |
| + false, |
| + false, |
| + // expected result |
| + true, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + true, |
| + false, |
| + // proxies in retry map |
| + true, |
| + false, |
| + true, |
| + false, |
| + false, |
| + // expected result |
| + false, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + true, |
| + false, |
| + // proxies in retry map |
| + false, |
| + false, |
| + true, |
| + true, |
| + false, |
| + // expected result |
| + true, |
| + }, |
| + { // proxy rules |
| + false, |
| + true, |
| + true, |
| + false, |
| + // proxies in retry map |
| + false, |
| + false, |
| + true, |
| + true, |
| + false, |
| + // expected result |
| + true, |
| + }, |
| + { // proxy rules |
| + false, |
| + true, |
| + false, |
| + false, |
| + // proxies in retry map |
| + false, |
| + false, |
| + true, |
| + false, |
| + false, |
| + // expected result |
| + false, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + true, |
| + false, |
| + // proxies in retry map |
| + true, |
| + false, |
| + true, |
| + true, |
| + false, |
| + // expected result |
| + true, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + true, |
| + false, |
| + // proxies in retry map |
| + true, |
| + true, |
| + true, |
| + true, |
| + true, |
| + // expected result |
| + true, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + true, |
| + true, |
| + // proxies in retry map |
| + true, |
| + true, |
| + true, |
| + true, |
| + true, |
| + // expected result |
| + true, |
| + }, |
| + { // proxy rules |
| + true, |
| + true, |
| + true, |
| + true, |
| + // proxies in retry map |
| + true, |
| + true, |
| + true, |
| + true, |
| + false, |
| + // expected result |
| + false, |
| + }, |
| + }; |
| + |
| + // The retry map has the scheme prefix for https but not for http. |
| + std::string origin = GetRetryMapKeyFromOrigin( |
| + TestDataReductionProxyParams::DefaultOrigin()); |
| + std::string fallback_origin =GetRetryMapKeyFromOrigin( |
| + TestDataReductionProxyParams::DefaultFallbackOrigin()); |
| + std::string alt_origin = GetRetryMapKeyFromOrigin( |
| + TestDataReductionProxyParams::DefaultAltOrigin()); |
| + std::string alt_fallback_origin = GetRetryMapKeyFromOrigin( |
| + TestDataReductionProxyParams::DefaultAltFallbackOrigin()); |
| + std::string ssl_origin = GetRetryMapKeyFromOrigin( |
| + TestDataReductionProxyParams::DefaultSSLOrigin()); |
| + |
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| + int flags = 0; |
| + if (tests[i].allowed) |
| + flags |= DataReductionProxyParams::kAllowed; |
| + if(tests[i].alt_allowed) |
| + flags |= DataReductionProxyParams::kAlternativeAllowed; |
| + if (tests[i].fallback_allowed) |
| + flags |= DataReductionProxyParams::kFallbackAllowed; |
| + TestDataReductionProxyParams params( |
| + flags, TestDataReductionProxyParams::HAS_EVERYTHING & |
| + ~TestDataReductionProxyParams::HAS_DEV_ORIGIN); |
| + |
| + net::ProxyRetryInfoMap retry_map; |
| + net::ProxyRetryInfo retry_info; |
| + |
| + if (tests[i].origin) |
| + retry_map[origin] = retry_info; |
| + if (tests[i].fallback_origin) |
| + retry_map[fallback_origin] = retry_info; |
| + if (tests[i].alt_origin) |
| + retry_map[alt_origin] = retry_info; |
| + if (tests[i].alt_fallback_origin) |
| + retry_map[alt_fallback_origin] = retry_info; |
| + if (tests[i].ssl_origin) |
| + retry_map[ssl_origin] = retry_info; |
| + |
| + bool was_bypassed = params.AreProxiesBypassed(retry_map, |
| + tests[i].ssl, |
| + NULL); |
| + |
| + EXPECT_EQ(tests[i].expected_result, was_bypassed); |
| + } |
| +} |
| } // namespace data_reduction_proxy |