| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
|
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
|
| index bd5a10db625155aa76b32d840a33a7e0c8d956dd..082e0f09a7858b37f7f9c457e2643d12f94f57d5 100644
|
| --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
|
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
|
| @@ -5,6 +5,7 @@
|
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
|
|
|
| #include "base/command_line.h"
|
| +#include "base/strings/string_util.h"
|
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
|
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h"
|
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
|
| @@ -156,6 +157,15 @@ class DataReductionProxyConfigTest : public testing::Test {
|
| test_context_->RunUntilIdle();
|
| }
|
|
|
| + scoped_ptr<DataReductionProxyConfig> BuildConfig(
|
| + scoped_ptr<DataReductionProxyParams> params) {
|
| + params->EnableQuic(false);
|
| + return make_scoped_ptr(new DataReductionProxyConfig(
|
| + test_context_->task_runner(), test_context_->task_runner(),
|
| + test_context_->net_log(), params.Pass(), test_context_->configurator(),
|
| + test_context_->event_store()));
|
| + }
|
| +
|
| MockDataReductionProxyConfig* config() {
|
| return test_context_->mock_config();
|
| }
|
| @@ -164,40 +174,15 @@ class DataReductionProxyConfigTest : public testing::Test {
|
| return test_context_->test_configurator();
|
| }
|
|
|
| - TestDataReductionProxyParams* params() { return expected_params_.get(); }
|
| + TestDataReductionProxyParams* params() const {
|
| + return expected_params_.get();
|
| + }
|
|
|
| private:
|
| scoped_ptr<DataReductionProxyTestContext> test_context_;
|
| scoped_ptr<TestDataReductionProxyParams> expected_params_;
|
| };
|
|
|
| -TEST_F(DataReductionProxyConfigTest, TestGetDataReductionProxyOrigin) {
|
| - EXPECT_EQ(params()->DefaultOrigin(), config()->Origin().ToURI());
|
| -}
|
| -
|
| -TEST_F(DataReductionProxyConfigTest, TestGetDataReductionProxyDevOrigin) {
|
| - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| - switches::kDataReductionProxyDev, params()->DefaultDevOrigin());
|
| - ResetSettings(true, true, false, true, false);
|
| - EXPECT_EQ(params()->DefaultDevOrigin(), config()->Origin().ToURI());
|
| -}
|
| -
|
| -TEST_F(DataReductionProxyConfigTest, TestGetDataReductionProxies) {
|
| - DataReductionProxyParams::DataReductionProxyList proxies =
|
| - params()->GetAllowedProxies();
|
| -
|
| - unsigned int expected_proxy_size = 2u;
|
| - EXPECT_EQ(expected_proxy_size, proxies.size());
|
| -
|
| - EXPECT_EQ(net::ProxyServer::FromURI(params()->DefaultOrigin(),
|
| - net::ProxyServer::SCHEME_HTTP),
|
| - proxies[0]);
|
| -
|
| - EXPECT_EQ(net::ProxyServer::FromURI(params()->DefaultFallbackOrigin(),
|
| - net::ProxyServer::SCHEME_HTTP),
|
| - proxies[1]);
|
| -}
|
| -
|
| TEST_F(DataReductionProxyConfigTest, TestUpdateConfigurator) {
|
| base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| switches::kDataReductionProxyAlt, params()->DefaultAltOrigin());
|
| @@ -309,4 +294,474 @@ TEST_F(DataReductionProxyConfigTest, TestOnIPAddressChanged) {
|
| kSecureProxyCheckWithOKResponse, "OK", true, false, false);
|
| }
|
|
|
| +std::string GetRetryMapKeyFromOrigin(std::string origin) {
|
| + // The retry map has the scheme prefix for https but not for http.
|
| + return origin;
|
| +}
|
| +
|
| +TEST_F(DataReductionProxyConfigTest, 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,
|
| + 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
|
| + false,
|
| + true,
|
| + false,
|
| + false,
|
| + false,
|
| + // expected result
|
| + false,
|
| + },
|
| + { // proxy flags
|
| + false,
|
| + true,
|
| + true,
|
| + // is https request
|
| + false,
|
| + // proxies in retry map
|
| + false,
|
| + false,
|
| + false,
|
| + true,
|
| + false,
|
| + // expected result
|
| + false,
|
| + },
|
| + { // 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
|
| + false,
|
| + },
|
| + { // 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
|
| + false,
|
| + },
|
| + { // 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
|
| + false,
|
| + },
|
| + { // 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(tests); ++i) {
|
| + net::ProxyConfig::ProxyRules rules;
|
| + std::vector<std::string> proxies;
|
| +
|
| + if (tests[i].allowed)
|
| + proxies.push_back(origin);
|
| + if (tests[i].alt_allowed)
|
| + proxies.push_back(alt_origin);
|
| + if (tests[i].allowed && tests[i].fallback_allowed)
|
| + proxies.push_back(fallback_origin);
|
| + if (tests[i].alt_allowed && tests[i].fallback_allowed)
|
| + proxies.push_back(alt_fallback_origin);
|
| +
|
| + std::string proxy_rules = "http=" + JoinString(proxies, ",") + ",direct://;"
|
| + + (tests[i].alt_allowed ? ("https=" + ssl_origin + ",direct://;") : "");
|
| +
|
| + rules.ParseFromString(proxy_rules);
|
| +
|
| + 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::HAS_DEV_FALLBACK_ORIGIN;
|
| + scoped_ptr<TestDataReductionProxyParams> params(
|
| + new TestDataReductionProxyParams(flags, has_definitions));
|
| + scoped_ptr<DataReductionProxyConfig> config = BuildConfig(params.Pass());
|
| +
|
| + net::ProxyRetryInfoMap retry_map;
|
| + net::ProxyRetryInfo retry_info;
|
| + retry_info.bad_until = base::TimeTicks() + base::TimeDelta::Max();
|
| +
|
| + 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 = config->AreProxiesBypassed(retry_map,
|
| + rules,
|
| + tests[i].is_https,
|
| + NULL);
|
| +
|
| + EXPECT_EQ(tests[i].expected_result, was_bypassed);
|
| + }
|
| +}
|
| +
|
| +TEST_F(DataReductionProxyConfigTest, AreProxiesBypassedRetryDelay) {
|
| + std::string origin = GetRetryMapKeyFromOrigin(
|
| + TestDataReductionProxyParams::DefaultOrigin());
|
| + std::string fallback_origin = GetRetryMapKeyFromOrigin(
|
| + TestDataReductionProxyParams::DefaultFallbackOrigin());
|
| +
|
| + net::ProxyConfig::ProxyRules rules;
|
| + std::vector<std::string> proxies;
|
| +
|
| + proxies.push_back(origin);
|
| + proxies.push_back(fallback_origin);
|
| +
|
| + std::string proxy_rules = "http=" + JoinString(proxies, ",") + ",direct://;";
|
| +
|
| + rules.ParseFromString(proxy_rules);
|
| +
|
| + int flags = 0;
|
| + flags |= DataReductionProxyParams::kAllowed;
|
| + flags |= DataReductionProxyParams::kFallbackAllowed;
|
| + unsigned int has_definitions =
|
| + TestDataReductionProxyParams::HAS_EVERYTHING &
|
| + ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
|
| + ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN;
|
| + scoped_ptr<TestDataReductionProxyParams> params(
|
| + new TestDataReductionProxyParams(flags, has_definitions));
|
| + scoped_ptr<DataReductionProxyConfig> config = BuildConfig(params.Pass());
|
| +
|
| + net::ProxyRetryInfoMap retry_map;
|
| + net::ProxyRetryInfo retry_info;
|
| +
|
| + retry_info.bad_until = base::TimeTicks() + base::TimeDelta::Max();
|
| + retry_map[origin] = retry_info;
|
| +
|
| + retry_info.bad_until = base::TimeTicks();
|
| + retry_map[fallback_origin] = retry_info;
|
| +
|
| + bool was_bypassed = config->AreProxiesBypassed(retry_map,
|
| + rules,
|
| + false,
|
| + NULL);
|
| +
|
| + EXPECT_FALSE(was_bypassed);
|
| +
|
| + base::TimeDelta delay = base::TimeDelta::FromHours(2);
|
| + retry_info.bad_until = base::TimeTicks::Now() + delay;
|
| + retry_info.current_delay = delay;
|
| + retry_map[origin] = retry_info;
|
| +
|
| + delay = base::TimeDelta::FromHours(1);
|
| + retry_info.bad_until = base::TimeTicks::Now() + delay;
|
| + retry_info.current_delay = delay;
|
| + retry_map[fallback_origin] = retry_info;
|
| +
|
| + base::TimeDelta min_retry_delay;
|
| + was_bypassed = config->AreProxiesBypassed(retry_map,
|
| + rules,
|
| + false,
|
| + &min_retry_delay);
|
| + EXPECT_TRUE(was_bypassed);
|
| + EXPECT_EQ(delay, min_retry_delay);
|
| +}
|
| +
|
| } // namespace data_reduction_proxy
|
|
|