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..af4a81a878ada014e13b9ea9fb0e9631f3fc8a72 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,13 @@ |
#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 "testing/gtest/include/gtest/gtest.h" |
namespace data_reduction_proxy { |
@@ -558,4 +561,387 @@ TEST_F(DataReductionProxyParamsTest, IsDataReductionProxy) { |
net::HostPortPair::FromURL(proxy_servers.second))); |
} |
} |
+ |
+TEST_F(DataReductionProxyParamsTest, WereProxiesBypassed) { |
+ 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; |
+ //expected result |
bengr
2014/07/19 00:13:01
no need for this comment.
megjablon
2014/07/21 19:44:45
Done.
|
+ bool expected_result; |
+ } tests[] = { |
+ { |
+ //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 |
bengr
2014/07/19 00:13:01
Always add a space after //
megjablon
2014/07/21 19:44:45
Done.
|
+ 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, |
+ }, |
+ { |
+ 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 list has the scheme prefix for https but not for http. |
+ std::string origin = TestDataReductionProxyParams::DefaultOrigin(); |
+ if (origin.find("https")==std::string::npos) { |
bengr
2014/07/19 00:13:01
eek. this is busted for http://https.com
megjablon
2014/07/21 19:44:45
Done.
|
+ origin = origin.substr(7); |
+ } |
+ std::string fallback_origin = |
+ TestDataReductionProxyParams::DefaultFallbackOrigin(); |
+ if (fallback_origin.find("https")==std::string::npos) { |
+ fallback_origin = fallback_origin.substr(7); |
+ } |
+ std::string alt_origin = |
+ TestDataReductionProxyParams::DefaultAltOrigin(); |
+ if (alt_origin.find("https")==std::string::npos) { |
+ alt_origin = alt_origin.substr(7); |
+ } |
+ std::string alt_fallback_origin = |
+ TestDataReductionProxyParams::DefaultAltFallbackOrigin(); |
+ if (alt_fallback_origin.find("https")==std::string::npos) { |
+ alt_fallback_origin = alt_fallback_origin.substr(7); |
+ } |
+ std::string ssl_origin = |
+ TestDataReductionProxyParams::DefaultSSLOrigin(); |
+ if (ssl_origin.find("https")==std::string::npos) { |
+ ssl_origin = ssl_origin.substr(7); |
+ } |
+ |
+ 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; |
+ |
+ // The retry list has the scheme prefix for https but not for http. |
+ if (tests[i].origin) { |
bengr
2014/07/19 00:13:01
Here and below can lose the curly braces.
megjablon
2014/07/21 19:44:45
Done.
|
+ 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.WereProxiesBypassed(retry_map, |
+ tests[i].ssl, |
+ NULL); |
+ |
+ EXPECT_EQ(tests[i].expected_result, was_bypassed); |
+ } |
+} |
} // namespace data_reduction_proxy |