| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
|
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
|
| index 8519ebbbe767b52cbd63c5bccc37e1769899778c..3bc41a4ff989522e46ce1fdf489f760f0d01e658 100644
|
| --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
|
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
|
| @@ -9,6 +9,7 @@
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/test/test_simple_task_runner.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_settings_test_utils.h"
|
| #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
|
| @@ -20,130 +21,36 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "url/gurl.h"
|
|
|
| -namespace {
|
| -
|
| -const char kProbeURLWithOKResponse[] = "http://ok.org/";
|
| -const char kProbeURLWithBadResponse[] = "http://bad.org/";
|
| -const char kProbeURLWithNoResponse[] = "http://no.org/";
|
| -
|
| -} // namespace
|
| -
|
| namespace data_reduction_proxy {
|
|
|
| class DataReductionProxySettingsTest
|
| : public ConcreteDataReductionProxySettingsTest<
|
| DataReductionProxySettings> {
|
| -};
|
| -
|
| -TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) {
|
| - // SetUp() adds the origin to the command line, which should be returned here.
|
| - std::string result =
|
| - settings_->params()->origin().spec();
|
| - EXPECT_EQ(GURL(expected_params_->DefaultOrigin()), GURL(result));
|
| -}
|
| -
|
| -TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyDevOrigin) {
|
| - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| - switches::kDataReductionProxyDev, expected_params_->DefaultDevOrigin());
|
| - ResetSettings(true, true, false, true, false);
|
| - std::string result =
|
| - settings_->params()->origin().spec();
|
| - EXPECT_EQ(GURL(expected_params_->DefaultDevOrigin()), GURL(result));
|
| -}
|
| -
|
| -
|
| -TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) {
|
| - DataReductionProxyParams::DataReductionProxyList proxies =
|
| - expected_params_->GetAllowedProxies();
|
| -
|
| - unsigned int expected_proxy_size = 2u;
|
| - EXPECT_EQ(expected_proxy_size, proxies.size());
|
| -
|
| - net::HostPortPair expected_origin =
|
| - net::HostPortPair::FromURL(GURL(expected_params_->DefaultOrigin()));
|
| - net::HostPortPair expected_fallback_origin =
|
| - net::HostPortPair::FromURL(
|
| - GURL(expected_params_->DefaultFallbackOrigin()));
|
| - EXPECT_EQ(expected_origin.host(), proxies[0].host());
|
| - EXPECT_EQ(expected_origin.port() ,proxies[0].EffectiveIntPort());
|
| - EXPECT_EQ(expected_fallback_origin.host(), proxies[1].host());
|
| - EXPECT_EQ(expected_fallback_origin.port(), proxies[1].EffectiveIntPort());
|
| -}
|
| -
|
| -TEST_F(DataReductionProxySettingsTest, TestSetProxyConfigs) {
|
| - TestDataReductionProxyParams drp_params(
|
| - DataReductionProxyParams::kAllowed |
|
| - DataReductionProxyParams::kFallbackAllowed |
|
| - DataReductionProxyParams::kPromoAllowed,
|
| - TestDataReductionProxyParams::HAS_EVERYTHING &
|
| - ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
|
| - ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN);
|
| - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| - switches::kDataReductionProxyAlt, drp_params.DefaultAltOrigin());
|
| - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| - switches::kDataReductionProxyAltFallback,
|
| - drp_params.DefaultAltFallbackOrigin());
|
| - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| - switches::kDataReductionSSLProxy, drp_params.DefaultSSLOrigin());
|
| - ResetSettings(true, true, true, true, false);
|
| - TestDataReductionProxyConfigurator* configurator =
|
| - static_cast<TestDataReductionProxyConfigurator*>(
|
| - settings_->configurator());
|
| -
|
| - settings_->SetProxyConfigs(true, true, false, false);
|
| - EXPECT_TRUE(configurator->enabled());
|
| - EXPECT_TRUE(net::HostPortPair::FromString(
|
| - expected_params_->DefaultAltOrigin()).Equals(
|
| - net::HostPortPair::FromString(configurator->origin())));
|
| - EXPECT_TRUE(net::HostPortPair::FromString(
|
| - expected_params_->DefaultAltFallbackOrigin()).Equals(
|
| - net::HostPortPair::FromString(configurator->fallback_origin())));
|
| - EXPECT_TRUE(net::HostPortPair::FromString(
|
| - expected_params_->DefaultSSLOrigin()).Equals(
|
| - net::HostPortPair::FromString(configurator->ssl_origin())));
|
| -
|
| - settings_->SetProxyConfigs(true, false, false, false);
|
| - EXPECT_TRUE(configurator->enabled());
|
| - EXPECT_TRUE(net::HostPortPair::FromString(drp_params.DefaultOrigin()).Equals(
|
| - net::HostPortPair::FromString(configurator->origin())));
|
| - EXPECT_TRUE(net::HostPortPair::FromString(
|
| - drp_params.DefaultFallbackOrigin()).Equals(
|
| - net::HostPortPair::FromString(configurator->fallback_origin())));
|
| - EXPECT_EQ("", configurator->ssl_origin());
|
| -
|
| - settings_->SetProxyConfigs(false, true, false, false);
|
| - EXPECT_FALSE(configurator->enabled());
|
| - EXPECT_EQ("", configurator->origin());
|
| - EXPECT_EQ("", configurator->fallback_origin());
|
| - EXPECT_EQ("", configurator->ssl_origin());
|
| -
|
| - settings_->SetProxyConfigs(false, false, false, false);
|
| - EXPECT_FALSE(configurator->enabled());
|
| - EXPECT_EQ("", configurator->origin());
|
| - EXPECT_EQ("", configurator->fallback_origin());
|
| - EXPECT_EQ("", configurator->ssl_origin());
|
| -}
|
| + public:
|
| + void CheckMaybeActivateDataReductionProxy(
|
| + bool initially_enabled,
|
| + bool request_succeeded,
|
| + bool expected_enabled,
|
| + bool expected_restricted,
|
| + bool expected_fallback_restricted) {
|
| + pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled,
|
| + initially_enabled);
|
| + config_->SetStateForTest(
|
| + initially_enabled, false, !request_succeeded, false);
|
| + ExpectSetProxyPrefs(expected_enabled,
|
| + false,
|
| + false);
|
| + settings_->MaybeActivateDataReductionProxy(false);
|
| + base::MessageLoop::current()->RunUntilIdle();
|
| + }
|
|
|
| -TEST_F(DataReductionProxySettingsTest, TestSetProxyConfigsHoldback) {
|
| - ResetSettings(true, true, true, true, true);
|
| - TestDataReductionProxyConfigurator* configurator =
|
| - static_cast<TestDataReductionProxyConfigurator*>(
|
| - settings_->configurator());
|
| -
|
| - // Holdback.
|
| - settings_->SetProxyConfigs(true, true, false, false);
|
| - EXPECT_FALSE(configurator->enabled());
|
| - EXPECT_EQ("", configurator->origin());
|
| - EXPECT_EQ("", configurator->fallback_origin());
|
| - EXPECT_EQ("", configurator->ssl_origin());
|
| -}
|
| +};
|
|
|
| TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) {
|
| settings_->InitPrefMembers();
|
| base::MessageLoopForUI loop;
|
| // The proxy is disabled initially.
|
| - settings_->enabled_by_user_ = false;
|
| - settings_->SetProxyConfigs(false, false, false, false);
|
| + config_->SetStateForTest(false, false, false, false);
|
|
|
| EXPECT_FALSE(settings_->IsDataReductionProxyEnabled());
|
| EXPECT_FALSE(settings_->IsDataReductionProxyManaged());
|
| @@ -239,118 +146,37 @@ TEST_F(DataReductionProxySettingsTest, TestMaybeActivateDataReductionProxy) {
|
| base::MessageLoopForUI loop;
|
| // The proxy is enabled and unrestructed initially.
|
| // Request succeeded but with bad response, expect proxy to be restricted.
|
| - CheckProbe(true,
|
| - kProbeURLWithBadResponse,
|
| - "Bad",
|
| - true,
|
| - true,
|
| - true,
|
| - false);
|
| + CheckMaybeActivateDataReductionProxy(true,
|
| + true,
|
| + true,
|
| + true,
|
| + false);
|
| // Request succeeded with valid response, expect proxy to be unrestricted.
|
| - CheckProbe(true,
|
| - kProbeURLWithOKResponse,
|
| - "OK",
|
| - true,
|
| - true,
|
| - false,
|
| - false);
|
| + CheckMaybeActivateDataReductionProxy(true,
|
| + true,
|
| + true,
|
| + false,
|
| + false);
|
| // Request failed, expect proxy to be enabled but restricted.
|
| - CheckProbe(true,
|
| - kProbeURLWithNoResponse,
|
| - "",
|
| - false,
|
| - true,
|
| - true,
|
| - false);
|
| + CheckMaybeActivateDataReductionProxy(true,
|
| + false,
|
| + true,
|
| + true,
|
| + false);
|
| // The proxy is disabled initially. Probes should not be emitted to change
|
| // state.
|
| - CheckProbe(false,
|
| - kProbeURLWithOKResponse,
|
| - "OK",
|
| - true,
|
| - false,
|
| - false,
|
| - false);
|
| -}
|
| -
|
| -TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) {
|
| - base::MessageLoopForUI loop;
|
| - // The proxy is enabled initially.
|
| - pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true);
|
| - settings_->spdy_proxy_auth_enabled_.Init(
|
| - prefs::kDataReductionProxyEnabled,
|
| - settings_->GetOriginalProfilePrefs());
|
| - settings_->data_reduction_proxy_alternative_enabled_.Init(
|
| - prefs::kDataReductionProxyAltEnabled,
|
| - settings_->GetOriginalProfilePrefs());
|
| - settings_->enabled_by_user_ = true;
|
| - settings_->restricted_by_carrier_ = false;
|
| - settings_->SetProxyConfigs(true, false, false, true);
|
| - // IP address change triggers a probe that succeeds. Proxy remains
|
| - // unrestricted.
|
| - CheckProbeOnIPChange(kProbeURLWithOKResponse,
|
| - "OK",
|
| - true,
|
| - false,
|
| - false);
|
| - // IP address change triggers a probe that fails. Proxy is restricted.
|
| - CheckProbeOnIPChange(kProbeURLWithBadResponse,
|
| - "Bad",
|
| - true,
|
| - true,
|
| - false);
|
| - // IP address change triggers a probe that fails. Proxy remains restricted.
|
| - CheckProbeOnIPChange(kProbeURLWithBadResponse,
|
| - "Bad",
|
| - true,
|
| - true,
|
| - false);
|
| - // IP address change triggers a probe that succeeds. Proxy is unrestricted.
|
| - CheckProbeOnIPChange(kProbeURLWithOKResponse,
|
| - "OK",
|
| - true,
|
| - false,
|
| - false);
|
| - // Simulate a VPN connection. The proxy should be disabled.
|
| - MockSettings* settings = static_cast<MockSettings*>(settings_.get());
|
| - settings->network_interfaces_.reset(new net::NetworkInterfaceList());
|
| - settings->network_interfaces_->push_back(net::NetworkInterface(
|
| - "tun0", /* network interface name */
|
| - "tun0", /* network interface friendly name */
|
| - 0, /* interface index */
|
| - net::NetworkChangeNotifier::CONNECTION_WIFI,
|
| - net::IPAddressNumber(), /* IP address */
|
| - 0, /* network prefix */
|
| - net::IP_ADDRESS_ATTRIBUTE_NONE /* ip address attribute */
|
| - ));
|
| - settings_->OnIPAddressChanged();
|
| - base::MessageLoop::current()->RunUntilIdle();
|
| - CheckProxyConfigs(false, false, false);
|
| -
|
| - // Check that the proxy is re-enabled if a non-VPN connection is later used.
|
| - settings->network_interfaces_.reset(new net::NetworkInterfaceList());
|
| - settings->network_interfaces_->push_back(net::NetworkInterface(
|
| - "eth0", /* network interface name */
|
| - "eth0", /* network interface friendly name */
|
| - 0, /* interface index */
|
| - net::NetworkChangeNotifier::CONNECTION_WIFI,
|
| - net::IPAddressNumber(),
|
| - 0, /* network prefix */
|
| - net::IP_ADDRESS_ATTRIBUTE_NONE /* ip address attribute */
|
| - ));
|
| - CheckProbeOnIPChange(kProbeURLWithOKResponse,
|
| - "OK",
|
| - true,
|
| - false,
|
| - false);
|
| + CheckMaybeActivateDataReductionProxy(false,
|
| + true,
|
| + false,
|
| + false,
|
| + false);
|
| }
|
|
|
| TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) {
|
| settings_->InitPrefMembers();
|
| base::MessageLoopForUI loop;
|
| // The proxy is enabled initially.
|
| - settings_->enabled_by_user_ = true;
|
| - settings_->SetProxyConfigs(true, false, false, true);
|
| + config_->SetStateForTest(true, false, false, true);
|
| // The pref is disabled, so correspondingly should be the proxy.
|
| CheckOnPrefChange(false, false, false);
|
| // The pref is enabled, so correspondingly should be the proxy.
|
| @@ -407,7 +233,7 @@ TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) {
|
|
|
| ResetSettings(false, false, false, false, false);
|
| MockSettings* settings = static_cast<MockSettings*>(settings_.get());
|
| - EXPECT_FALSE(settings->params()->allowed());
|
| + EXPECT_FALSE(settings->allowed_);
|
| EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE));
|
|
|
| scoped_ptr<DataReductionProxyConfigurator> configurator(
|
| @@ -415,13 +241,11 @@ TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) {
|
| scoped_refptr<base::TestSimpleTaskRunner>(
|
| new base::TestSimpleTaskRunner()),
|
| &net_log_, event_store_.get()));
|
| - settings_->SetProxyConfigurator(configurator.get());
|
| scoped_refptr<net::TestURLRequestContextGetter> request_context =
|
| new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
|
| settings_->InitDataReductionProxySettings(
|
| &pref_service_,
|
| - request_context.get(),
|
| - &net_log_,
|
| + config_.get(),
|
| event_store_.get());
|
| settings_->SetOnDataReductionEnabledCallback(
|
| base::Bind(&DataReductionProxySettingsTestBase::
|
|
|