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..4ab9e2d2bfba2fd782480180e88079496da74115 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,377 @@ 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 flags |
+ bool allowed; |
+ bool fallback_allowed; |
+ bool alt_allowed; |
+ // is https request |
+ bool is_https; |
+ // proxies in retry map |
+ bool origin; |
+ bool fallback_origin; |
+ bool alt_origin; |
+ bool alt_fallback_origin; |
+ bool ssl_origin; |
+ |
+ bool expected_result; |
+ } tests[] = { |
+ { // proxy flags |
+ false, |
+ false, |
+ false, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ false, |
+ false, |
+ false, |
+ false, |
+ false, |
+ // expected result |
+ false, |
+ }, |
+ { // proxy flags |
+ true, |
+ false, |
+ false, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ false, |
+ false, |
+ false, |
+ false, |
+ false, |
+ // expected result |
+ false, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ false, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ false, |
+ false, |
+ false, |
+ false, |
+ false, |
+ // expected result |
+ false, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ true, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ false, |
+ false, |
+ false, |
+ false, |
+ false, |
+ // expected result |
+ false, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ true, |
+ // is https request |
+ true, |
+ // proxies in retry map |
+ false, |
+ false, |
+ false, |
+ false, |
+ false, |
+ // expected result |
+ false, |
+ }, |
+ { // proxy flags |
+ false, |
+ false, |
+ false, |
+ // is https request |
+ true, |
+ // proxies in retry map |
+ false, |
+ false, |
+ false, |
+ false, |
+ true, |
+ // expected result |
+ false, |
+ }, |
+ { // proxy flags |
+ false, |
+ false, |
+ true, |
+ // is https request |
+ true, |
+ // proxies in retry map |
+ false, |
+ false, |
+ false, |
+ false, |
+ true, |
+ // expected result |
+ true, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ true, |
+ // is https request |
+ true, |
+ // proxies in retry map |
+ false, |
+ false, |
+ false, |
+ false, |
+ true, |
+ // expected result |
+ true, |
+ }, |
+ { // proxy flags |
+ true, |
+ false, |
+ false, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ true, |
+ false, |
+ false, |
+ false, |
+ false, |
+ // expected result |
+ true, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ false, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ true, |
+ false, |
+ false, |
+ false, |
+ false, |
+ // expected result |
+ false, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ false, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ true, |
+ true, |
+ false, |
+ false, |
+ false, |
+ // expected result |
+ true, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ true, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ true, |
+ true, |
+ false, |
+ false, |
+ false, |
+ // expected result |
+ true, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ true, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ true, |
+ false, |
+ true, |
+ false, |
+ false, |
+ // expected result |
+ false, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ true, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ false, |
+ false, |
+ true, |
+ true, |
+ false, |
+ // expected result |
+ true, |
+ }, |
+ { // proxy flags |
+ false, |
+ true, |
+ true, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ false, |
+ false, |
+ true, |
+ true, |
+ false, |
+ // expected result |
+ true, |
+ }, |
+ { // proxy flags |
+ false, |
+ true, |
+ false, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ false, |
+ false, |
+ true, |
+ false, |
+ false, |
+ // expected result |
+ false, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ true, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ true, |
+ false, |
+ true, |
+ true, |
+ false, |
+ // expected result |
+ true, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ true, |
+ // is https request |
+ false, |
+ // proxies in retry map |
+ true, |
+ true, |
+ true, |
+ true, |
+ true, |
+ // expected result |
+ true, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ true, |
+ // is https request |
+ true, |
+ // proxies in retry map |
+ true, |
+ true, |
+ true, |
+ true, |
+ true, |
+ // expected result |
+ true, |
+ }, |
+ { // proxy flags |
+ true, |
+ true, |
+ true, |
+ // is https request |
+ 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; |
+ unsigned int has_definitions = |
+ TestDataReductionProxyParams::HAS_EVERYTHING & |
+ ~TestDataReductionProxyParams::HAS_DEV_ORIGIN; |
+ TestDataReductionProxyParams params(flags, has_definitions); |
+ |
+ 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].is_https, |
+ NULL); |
+ |
+ EXPECT_EQ(tests[i].expected_result, was_bypassed); |
+ } |
+} |
} // namespace data_reduction_proxy |