Commit 191c0cae authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Add the state of non-core data saver proxies to the network properties manager

State of the core data saver proxies are now independent from
the state of the non-core data saver proxies.

Bug: 779219
Change-Id: Id765548736f96ec85db9720a1eb73af95b525b32
Reviewed-on: https://chromium-review.googlesource.com/770146
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarDoug Arnett <dougarnett@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521528}
parent 41145444
......@@ -186,10 +186,8 @@ void DataReductionProxyConfig::ReloadConfig() {
if (enabled_by_user_ && !params::IsIncludedInHoldbackFieldTrial() &&
!config_values_->proxies_for_http().empty()) {
configurator_->Enable(
!network_properties_manager_->IsSecureProxyAllowed(),
!network_properties_manager_->IsInsecureProxyAllowed(),
config_values_->proxies_for_http());
configurator_->Enable(*network_properties_manager_,
config_values_->proxies_for_http());
} else {
configurator_->Disable();
}
......@@ -403,7 +401,11 @@ void DataReductionProxyConfig::UpdateConfigForTesting(
network_properties_manager_->SetIsSecureProxyDisallowedByCarrier(
!secure_proxies_allowed);
network_properties_manager_->SetHasWarmupURLProbeFailed(
false, !insecure_proxies_allowed);
false /* secure_proxy */, false /* is_core_proxy */,
!insecure_proxies_allowed);
network_properties_manager_->SetHasWarmupURLProbeFailed(
false /* secure_proxy */, true /* is_core_proxy */,
!insecure_proxies_allowed);
}
void DataReductionProxyConfig::SetNetworkPropertiesManagerForTesting(
......@@ -626,34 +628,26 @@ base::TimeTicks DataReductionProxyConfig::GetTicksNow() const {
}
void DataReductionProxyConfig::OnInsecureProxyWarmupURLProbeStatusChange(
bool insecure_proxies_allowed) {
bool insecure_proxies_allowed,
bool is_core_proxy) {
DCHECK(thread_checker_.CalledOnValidThread());
bool old_status = network_properties_manager_->IsInsecureProxyAllowed();
bool old_status =
network_properties_manager_->IsInsecureProxyAllowed(is_core_proxy);
network_properties_manager_->SetHasWarmupURLProbeFailed(
false, !insecure_proxies_allowed);
false, is_core_proxy, !insecure_proxies_allowed);
if (old_status == network_properties_manager_->IsInsecureProxyAllowed())
if (old_status ==
network_properties_manager_->IsInsecureProxyAllowed(is_core_proxy)) {
return;
}
ReloadConfig();
}
net::ProxyConfig DataReductionProxyConfig::ProxyConfigIgnoringHoldback() const {
if (!enabled_by_user_ || config_values_->proxies_for_http().empty())
return net::ProxyConfig::CreateDirect();
return configurator_->CreateProxyConfig(
!network_properties_manager_->IsSecureProxyAllowed(),
!network_properties_manager_->IsInsecureProxyAllowed(),
config_values_->proxies_for_http());
}
bool DataReductionProxyConfig::secure_proxy_allowed() const {
DCHECK(thread_checker_.CalledOnValidThread());
return network_properties_manager_->IsSecureProxyAllowed();
}
bool DataReductionProxyConfig::insecure_proxies_allowed() const {
DCHECK(thread_checker_.CalledOnValidThread());
return network_properties_manager_->IsInsecureProxyAllowed();
return configurator_->CreateProxyConfig(*network_properties_manager_,
config_values_->proxies_for_http());
}
std::vector<DataReductionProxyServer>
......@@ -714,4 +708,10 @@ std::string DataReductionProxyConfig::GetCurrentNetworkID() const {
NOTREACHED();
}
const NetworkPropertiesManager&
DataReductionProxyConfig::GetNetworkPropertiesManager() const {
DCHECK(thread_checker_.CalledOnValidThread());
return *network_properties_manager_;
}
} // namespace data_reduction_proxy
......@@ -190,12 +190,6 @@ class DataReductionProxyConfig
// This should only be used for logging purposes.
net::ProxyConfig ProxyConfigIgnoringHoldback() const;
// Returns true if secure data saver proxies are allowed.
bool secure_proxy_allowed() const;
// Returns true if insecure data saver proxies are allowed.
bool insecure_proxies_allowed() const;
std::vector<DataReductionProxyServer> GetProxiesForHttp() const;
// Called when a new client config has been fetched.
......@@ -203,10 +197,17 @@ class DataReductionProxyConfig
void SetNetworkPropertiesManagerForTesting(NetworkPropertiesManager* manager);
// Returns the network properties manager which manages whether a given data
// saver proxy is currently allowed or not.
const NetworkPropertiesManager& GetNetworkPropertiesManager() const;
protected:
// Should be called when there is a change in the status of the availability
// of the insecure data saver proxies triggered due to warmup URL.
void OnInsecureProxyWarmupURLProbeStatusChange(bool insecure_proxies_allowed);
// of the insecure data saver proxies triggered due to fetching of the warmup
// URL. |is_core_proxy| indicates if the warmup URL was fetched over a core
// data saver proxy or not.
void OnInsecureProxyWarmupURLProbeStatusChange(bool insecure_proxies_allowed,
bool is_core_proxy);
virtual base::TimeTicks GetTicksNow() const;
......
......@@ -25,6 +25,7 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
#include "components/data_reduction_proxy/core/browser/network_properties_manager.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
......@@ -595,8 +596,12 @@ TEST_F(DataReductionProxyConfigServiceClientTest,
ProxyServer::CORE));
// Secure check failed.
configurator()->Enable(true /* secure_transport_restricted */, false,
http_proxies);
TestingPrefServiceSimple test_prefs;
test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
NetworkPropertiesManager manager(&test_prefs,
base::ThreadTaskRunnerHandle::Get());
manager.SetIsSecureProxyDisallowedByCarrier(true);
configurator()->Enable(manager, http_proxies);
VerifyRemoteSuccess(false);
}
......@@ -730,8 +735,12 @@ TEST_F(DataReductionProxyConfigServiceClientTest,
ProxyServer::CORE));
// Secure check failed.
configurator()->Enable(true /* secure_transport_restricted */, false,
http_proxies);
TestingPrefServiceSimple test_prefs;
test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
NetworkPropertiesManager manager(&test_prefs,
base::ThreadTaskRunnerHandle::Get());
manager.SetIsSecureProxyDisallowedByCarrier(true);
configurator()->Enable(manager, http_proxies);
VerifyRemoteSuccess(false);
}
......
......@@ -306,17 +306,18 @@ TEST_F(DataReductionProxyConfigTest,
GetConfiguredProxiesForHttp());
// Calling OnInsecureProxyWarmupURLProbeStatusChange should reload the config.
test_config()->OnInsecureProxyWarmupURLProbeStatusChange(false);
test_config()->OnInsecureProxyWarmupURLProbeStatusChange(
false /* insecure_proxies_allowed */, false /* is_core_proxy */);
EXPECT_EQ(std::vector<net::ProxyServer>({kHttpsProxy}),
GetConfiguredProxiesForHttp());
// Calling OnInsecureProxyWarmupURLProbeStatusChange again with the same
// status has no effect.
test_config()->OnInsecureProxyWarmupURLProbeStatusChange(false);
test_config()->OnInsecureProxyWarmupURLProbeStatusChange(false, false);
EXPECT_EQ(std::vector<net::ProxyServer>({kHttpsProxy}),
GetConfiguredProxiesForHttp());
test_config()->OnInsecureProxyWarmupURLProbeStatusChange(true);
test_config()->OnInsecureProxyWarmupURLProbeStatusChange(true, false);
EXPECT_EQ(std::vector<net::ProxyServer>({kHttpsProxy, kHttpProxy}),
GetConfiguredProxiesForHttp());
}
......
......@@ -11,6 +11,7 @@
#include "base/strings/string_util.h"
#include "base/values.h"
#include "components/data_reduction_proxy/core/browser/network_properties_manager.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_util.h"
#include "net/proxy/proxy_config.h"
......@@ -31,22 +32,19 @@ DataReductionProxyConfigurator::~DataReductionProxyConfigurator() {
}
void DataReductionProxyConfigurator::Enable(
bool secure_transport_restricted,
bool insecure_proxies_restricted,
const NetworkPropertiesManager& network_properties_manager,
const std::vector<DataReductionProxyServer>& proxies_for_http) {
DCHECK(thread_checker_.CalledOnValidThread());
net::ProxyConfig config =
CreateProxyConfig(secure_transport_restricted,
insecure_proxies_restricted, proxies_for_http);
CreateProxyConfig(network_properties_manager, proxies_for_http);
data_reduction_proxy_event_creator_->AddProxyEnabledEvent(
net_log_, secure_transport_restricted,
net_log_, network_properties_manager.IsSecureProxyDisallowedByCarrier(),
DataReductionProxyServer::ConvertToNetProxyServers(proxies_for_http));
config_ = config;
}
net::ProxyConfig DataReductionProxyConfigurator::CreateProxyConfig(
bool secure_transport_restricted,
bool insecure_proxies_restricted,
const NetworkPropertiesManager& network_properties_manager,
const std::vector<DataReductionProxyServer>& proxies_for_http) const {
DCHECK(thread_checker_.CalledOnValidThread());
......@@ -56,14 +54,29 @@ net::ProxyConfig DataReductionProxyConfigurator::CreateProxyConfig(
net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
for (const auto& http_proxy : proxies_for_http) {
if (secure_transport_restricted &&
if (!network_properties_manager.IsSecureProxyAllowed(true) &&
(http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_HTTPS ||
http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_QUIC)) {
http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_QUIC) &&
http_proxy.GetProxyTypeForTesting() == ProxyServer_ProxyType_CORE) {
continue;
}
if (insecure_proxies_restricted &&
http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_HTTP) {
if (!network_properties_manager.IsInsecureProxyAllowed(true) &&
http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_HTTP &&
http_proxy.GetProxyTypeForTesting() == ProxyServer_ProxyType_CORE) {
continue;
}
if (!network_properties_manager.IsSecureProxyAllowed(false) &&
(http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_HTTPS ||
http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_QUIC) &&
http_proxy.GetProxyTypeForTesting() != ProxyServer_ProxyType_CORE) {
continue;
}
if (!network_properties_manager.IsInsecureProxyAllowed(false) &&
http_proxy.proxy_server().scheme() == net::ProxyServer::SCHEME_HTTP &&
http_proxy.GetProxyTypeForTesting() != ProxyServer_ProxyType_CORE) {
continue;
}
......
......@@ -22,6 +22,7 @@ class ProxyServer;
namespace data_reduction_proxy {
class DataReductionProxyEventCreator;
class NetworkPropertiesManager;
class DataReductionProxyConfigurator {
public:
......@@ -34,14 +35,10 @@ class DataReductionProxyConfigurator {
virtual ~DataReductionProxyConfigurator();
// Enables data reduction using the proxy servers in |proxies_for_http|.
// |secure_transport_restricted| indicates that proxies going over secure
// transports can not be used. |insecure_proxies_restricted| indicates that
// insecure proxies can not be used.
// TODO: crbug.com/675764: Pass a vector of DataReductionProxyServer
// instead of net::ProxyServer.
virtual void Enable(
bool secure_transport_restricted,
bool insecure_proxies_restricted,
const NetworkPropertiesManager& network_properties_manager,
const std::vector<DataReductionProxyServer>& proxies_for_http);
// Constructs a proxy configuration suitable for disabling the Data Reduction
......@@ -60,12 +57,9 @@ class DataReductionProxyConfigurator {
const net::ProxyConfig& GetProxyConfig() const;
// Constructs a proxy configuration suitable for enabling the Data Reduction
// proxy. If true, |secure_transport_restricted| indicates that proxies going
// over secure transports (HTTPS, QUIC) should/can not be used. If true,
// |insecure_proxies_restricted| indicates that HTTP proxies cannot be used.
// proxy.
net::ProxyConfig CreateProxyConfig(
bool secure_transport_restricted,
bool insecure_proxies_restricted,
const NetworkPropertiesManager& network_properties_manager,
const std::vector<DataReductionProxyServer>& proxies_for_http) const;
private:
......
......@@ -11,7 +11,12 @@
#include "base/test/scoped_task_environment.h"
#include "base/values.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
#include "components/data_reduction_proxy/core/browser/network_properties_manager.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_server.h"
#include "components/data_reduction_proxy/proto/client_config.pb.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "net/proxy/proxy_server.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -21,26 +26,42 @@ namespace data_reduction_proxy {
class DataReductionProxyConfiguratorTest : public testing::Test {
public:
void SetUp() override {
test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
manager_.reset(new NetworkPropertiesManager(
&test_prefs, base::ThreadTaskRunnerHandle::Get()));
test_context_ = DataReductionProxyTestContext::Builder().Build();
config_.reset(new DataReductionProxyConfigurator(
test_context_->net_log(), test_context_->event_creator()));
}
void TearDown() override {
// Reset the state of |manager_|.
manager_->SetIsSecureProxyDisallowedByCarrier(false);
manager_->SetIsCaptivePortal(false);
manager_->SetHasWarmupURLProbeFailed(false, false, false);
manager_->SetHasWarmupURLProbeFailed(false, true, false);
manager_->SetHasWarmupURLProbeFailed(true, false, false);
manager_->SetHasWarmupURLProbeFailed(true, true, false);
}
std::vector<DataReductionProxyServer> BuildProxyList(
const std::string& first,
const std::string& second) {
enum ProxyServer_ProxyType first_proxy_type,
const std::string& second,
enum ProxyServer_ProxyType second_proxy_type) {
std::vector<DataReductionProxyServer> proxies;
if (!first.empty()) {
net::ProxyServer proxy =
net::ProxyServer::FromURI(first, net::ProxyServer::SCHEME_HTTP);
EXPECT_TRUE(proxy.is_valid()) << first;
proxies.push_back(DataReductionProxyServer(proxy, ProxyServer::CORE));
proxies.push_back(DataReductionProxyServer(proxy, first_proxy_type));
}
if (!second.empty()) {
net::ProxyServer proxy =
net::ProxyServer::FromURI(second, net::ProxyServer::SCHEME_HTTP);
EXPECT_TRUE(proxy.is_valid()) << second;
proxies.push_back(DataReductionProxyServer(proxy, ProxyServer::CORE));
proxies.push_back(DataReductionProxyServer(proxy, second_proxy_type));
}
return proxies;
}
......@@ -61,24 +82,26 @@ class DataReductionProxyConfiguratorTest : public testing::Test {
}
}
TestingPrefServiceSimple test_prefs;
base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<DataReductionProxyTestContext> test_context_;
std::unique_ptr<DataReductionProxyConfigurator> config_;
std::unique_ptr<NetworkPropertiesManager> manager_;
};
TEST_F(DataReductionProxyConfiguratorTest, TestUnrestricted) {
config_->Enable(
false, false,
BuildProxyList("https://www.foo.com:443", "http://www.bar.com:80"));
config_->Enable(*manager_,
BuildProxyList("https://www.foo.com:443", ProxyServer::CORE,
"http://www.bar.com:80", ProxyServer::CORE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
"HTTPS www.foo.com:443;PROXY www.bar.com:80;DIRECT",
std::string());
}
TEST_F(DataReductionProxyConfiguratorTest, TestUnrestrictedQuic) {
config_->Enable(
false, false,
BuildProxyList("quic://www.foo.com:443", "http://www.bar.com:80"));
config_->Enable(*manager_,
BuildProxyList("quic://www.foo.com:443", ProxyServer::CORE,
"http://www.bar.com:80", ProxyServer::CORE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
"QUIC www.foo.com:443;PROXY www.bar.com:80;DIRECT",
std::string());
......@@ -86,9 +109,9 @@ TEST_F(DataReductionProxyConfiguratorTest, TestUnrestrictedQuic) {
TEST_F(DataReductionProxyConfiguratorTest, TestUnrestrictedWithBypassRule) {
config_->SetBypassRules("<local>, *.goo.com");
config_->Enable(
false, false,
BuildProxyList("https://www.foo.com:443", "http://www.bar.com:80"));
config_->Enable(*manager_,
BuildProxyList("https://www.foo.com:443", ProxyServer::CORE,
"http://www.bar.com:80", ProxyServer::CORE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
"HTTPS www.foo.com:443;PROXY www.bar.com:80;DIRECT",
"<local>;*.goo.com;");
......@@ -96,65 +119,104 @@ TEST_F(DataReductionProxyConfiguratorTest, TestUnrestrictedWithBypassRule) {
TEST_F(DataReductionProxyConfiguratorTest, TestUnrestrictedWithBypassRuleQuic) {
config_->SetBypassRules("<local>, *.goo.com");
config_->Enable(
false, false,
BuildProxyList("quic://www.foo.com:443", "http://www.bar.com:80"));
config_->Enable(*manager_,
BuildProxyList("quic://www.foo.com:443", ProxyServer::CORE,
"http://www.bar.com:80", ProxyServer::CORE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
"QUIC www.foo.com:443;PROXY www.bar.com:80;DIRECT",
"<local>;*.goo.com;");
}
TEST_F(DataReductionProxyConfiguratorTest, TestUnrestrictedWithoutFallback) {
config_->Enable(false, false,
BuildProxyList("https://www.foo.com:443", std::string()));
config_->Enable(*manager_,
BuildProxyList("https://www.foo.com:443", ProxyServer::CORE,
std::string(), ProxyServer::CORE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
"HTTPS www.foo.com:443;DIRECT", std::string());
}
TEST_F(DataReductionProxyConfiguratorTest,
TestUnrestrictedWithoutFallbackQuic) {
config_->Enable(false, false,
BuildProxyList("quic://www.foo.com:443", std::string()));
config_->Enable(*manager_,
BuildProxyList("quic://www.foo.com:443", ProxyServer::CORE,
std::string(), ProxyServer::CORE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
"QUIC www.foo.com:443;DIRECT", std::string());
}
TEST_F(DataReductionProxyConfiguratorTest, TestSecureRestricted) {
config_->Enable(
true, false,
BuildProxyList("https://www.foo.com:443", "http://www.bar.com:80"));
TEST_F(DataReductionProxyConfiguratorTest, TestSecureRestrictedProxiesAreCore) {
manager_->SetHasWarmupURLProbeFailed(true, true, true);
config_->Enable(*manager_,
BuildProxyList("https://www.foo.com:443", ProxyServer::CORE,
"http://www.bar.com:80", ProxyServer::CORE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
"PROXY www.bar.com:80;DIRECT", std::string());
}
TEST_F(DataReductionProxyConfiguratorTest, TestInsecureRestricted) {
TEST_F(DataReductionProxyConfiguratorTest, TestSecureNonCoreRestricted) {
manager_->SetHasWarmupURLProbeFailed(true, false, true);
config_->Enable(*manager_,
BuildProxyList("https://www.foo.com:443", ProxyServer::CORE,
"http://www.bar.com:80", ProxyServer::CORE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
"HTTPS www.foo.com:443;PROXY www.bar.com:80;DIRECT",
std::string());
}
TEST_F(DataReductionProxyConfiguratorTest,
TestSecureRestrictedProxiesAreNonCore) {
manager_->SetHasWarmupURLProbeFailed(true, true, true);
config_->Enable(
false, true,
BuildProxyList("https://www.foo.com:443", "http://www.bar.com:80"));
*manager_,
BuildProxyList("https://www.foo.com:443", ProxyServer::UNSPECIFIED_TYPE,
"http://www.bar.com:80", ProxyServer::UNSPECIFIED_TYPE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
"HTTPS www.foo.com:443;PROXY www.bar.com:80;DIRECT",
std::string());
}
TEST_F(DataReductionProxyConfiguratorTest, TestInsecureCoreRestricted) {
manager_->SetHasWarmupURLProbeFailed(false, true, true);
config_->Enable(*manager_,
BuildProxyList("https://www.foo.com:443", ProxyServer::CORE,
"http://www.bar.com:80", ProxyServer::CORE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
"HTTPS www.foo.com:443;DIRECT", std::string());
}
TEST_F(DataReductionProxyConfiguratorTest, TestSecureInsecureRestricted) {
config_->Enable(
true, true,
BuildProxyList("https://www.foo.com:443", "http://www.bar.com:80"));
TEST_F(DataReductionProxyConfiguratorTest, TestInsecureNonCoreRestricted) {
manager_->SetHasWarmupURLProbeFailed(false, false, true);
config_->Enable(*manager_,
BuildProxyList("https://www.foo.com:443", ProxyServer::CORE,
"http://www.bar.com:80", ProxyServer::CORE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
"HTTPS www.foo.com:443;PROXY www.bar.com:80;DIRECT",
std::string());
}
TEST_F(DataReductionProxyConfiguratorTest, TestSecureInsecureCoreRestricted) {
manager_->SetHasWarmupURLProbeFailed(true, true, true);
manager_->SetHasWarmupURLProbeFailed(false, true, true);
config_->Enable(*manager_,
BuildProxyList("https://www.foo.com:443", ProxyServer::CORE,
"http://www.bar.com:80", ProxyServer::CORE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, "",
std::string());
}
TEST_F(DataReductionProxyConfiguratorTest, TestRestrictedQuic) {
config_->Enable(
true, false,
BuildProxyList("quic://www.foo.com:443", "http://www.bar.com:80"));
manager_->SetHasWarmupURLProbeFailed(true, true, true);
config_->Enable(*manager_,
BuildProxyList("quic://www.foo.com:443", ProxyServer::CORE,
"http://www.bar.com:80", ProxyServer::CORE));
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
"PROXY www.bar.com:80;DIRECT", std::string());
}
TEST_F(DataReductionProxyConfiguratorTest, TestDisable) {
config_->Enable(
false, false,
BuildProxyList("https://www.foo.com:443", "http://www.bar.com:80"));
config_->Enable(*manager_,
BuildProxyList("https://www.foo.com:443", ProxyServer::CORE,
"http://www.bar.com:80", ProxyServer::CORE));
config_->Disable();
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_NO_RULES, std::string(),
std::string());
......
......@@ -98,8 +98,7 @@ void DataReductionProxyDelegate::OnResolveProxy(
proxies_for_http.end());
net::ProxyConfig proxy_config = configurator_->CreateProxyConfig(
!config_->secure_proxy_allowed(), !config_->insecure_proxies_allowed(),
proxies_for_http);
config_->GetNetworkPropertiesManager(), proxies_for_http);
OnResolveProxyHandler(url, method, proxy_config, proxy_retry_info, *config_,
io_data_, result);
......
......@@ -225,18 +225,17 @@ NetworkPropertiesManager::ConvertDictionaryValueToParsedPrefs(
return read_prefs;
}
bool NetworkPropertiesManager::IsSecureProxyAllowed() const {
bool NetworkPropertiesManager::IsSecureProxyAllowed(bool is_core_proxy) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return !network_properties_.secure_proxy_disallowed_by_carrier() &&
!network_properties_.has_captive_portal() &&
!network_properties_.secure_proxy_flags()
.disallowed_due_to_warmup_probe_failure();
!HasWarmupURLProbeFailed(true, is_core_proxy);
}
bool NetworkPropertiesManager::IsInsecureProxyAllowed() const {
bool NetworkPropertiesManager::IsInsecureProxyAllowed(
bool is_core_proxy) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return !network_properties_.insecure_proxy_flags()
.disallowed_due_to_warmup_probe_failure();
return !HasWarmupURLProbeFailed(false, is_core_proxy);
}
bool NetworkPropertiesManager::IsSecureProxyDisallowedByCarrier() const {
......@@ -264,24 +263,45 @@ void NetworkPropertiesManager::SetIsCaptivePortal(bool is_captive_portal) {
}
bool NetworkPropertiesManager::HasWarmupURLProbeFailed(
bool secure_proxy) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return secure_proxy ? network_properties_.secure_proxy_flags()
.disallowed_due_to_warmup_probe_failure()
: network_properties_.insecure_proxy_flags()
.disallowed_due_to_warmup_probe_failure();
bool secure_proxy,
bool is_core_proxy) const {
if (secure_proxy && is_core_proxy) {
return network_properties_.secure_proxy_flags()
.disallowed_due_to_warmup_probe_failure();
}
if (secure_proxy && !is_core_proxy) {
return network_properties_.secure_non_core_proxy_flags()
.disallowed_due_to_warmup_probe_failure();
}
if (!secure_proxy && is_core_proxy) {
return network_properties_.insecure_proxy_flags()
.disallowed_due_to_warmup_probe_failure();
}
if (!secure_proxy && !is_core_proxy) {
return network_properties_.insecure_non_core_proxy_flags()
.disallowed_due_to_warmup_probe_failure();
}
NOTREACHED();
return false;
}
void NetworkPropertiesManager::SetHasWarmupURLProbeFailed(
bool secure_proxy,
bool is_core_proxy,
bool warmup_url_probe_failed) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (secure_proxy) {
if (secure_proxy && is_core_proxy) {
network_properties_.mutable_secure_proxy_flags()
->set_disallowed_due_to_warmup_probe_failure(warmup_url_probe_failed);
} else {
} else if (secure_proxy && !is_core_proxy) {
network_properties_.mutable_secure_non_core_proxy_flags()
->set_disallowed_due_to_warmup_probe_failure(warmup_url_probe_failed);
} else if (!secure_proxy && is_core_proxy) {
network_properties_.mutable_insecure_proxy_flags()
->set_disallowed_due_to_warmup_probe_failure(warmup_url_probe_failed);
} else {
network_properties_.mutable_insecure_non_core_proxy_flags()
->set_disallowed_due_to_warmup_probe_failure(warmup_url_probe_failed);
}
OnChangeInNetworkPropertyOnIOThread();
}
......
......@@ -41,11 +41,13 @@ class NetworkPropertiesManager {
void OnChangeInNetworkID(const std::string& network_id);
// Returns true if usage of secure proxies are allowed on the current network.
bool IsSecureProxyAllowed() const;
// Returns the status of core secure proxies if |is_core_proxy| is true.
bool IsSecureProxyAllowed(bool is_core_proxy) const;
// Returns true if usage of insecure proxies are allowed on the current
// network.
bool IsInsecureProxyAllowed() const;
// network. Returns the status of core non-secure proxies if |is_core_proxy|
// is true.
bool IsInsecureProxyAllowed(bool is_core_proxy) const;
// Returns true if usage of secure proxies has been disallowed by the carrier
// on the current network.
......@@ -63,15 +65,16 @@ class NetworkPropertiesManager {
// disallowed.
void SetIsCaptivePortal(bool is_captive_portal);
// If secure_proxy is true, returns true if the warmup URL probe has failed
// on secure proxies on the current network. Otherwise, returns true if the
// warmup URL probe has failed on insecure proxies.
bool HasWarmupURLProbeFailed(bool secure_proxy) const;
// Returns true if the warmup URL probe has failed
// on secure (or insecure), core (or non-core) data saver proxies on the
// current network.
bool HasWarmupURLProbeFailed(bool secure_proxy, bool is_core_proxy) const;
// Sets the status of whether the fetching of warmup URL failed on the current
// network. Sets the status for secure proxies if |secure_proxy| is true.
// Otherwise, sets the status for the insecure proxies.
// network. Sets the status for secure (or insecure), core (or non-core) data
// saver proxies.
void SetHasWarmupURLProbeFailed(bool secure_proxy,
bool is_core_proxy,
bool warmup_url_probe_failed);
private:
......
......@@ -38,16 +38,20 @@ TEST(NetworkPropertyTest, TestSetterGetterCaptivePortal) {
std::string network_id("test");
network_properties_manager.OnChangeInNetworkID(network_id);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(true));
network_properties_manager.SetIsCaptivePortal(true);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_FALSE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(false));
EXPECT_FALSE(network_properties_manager.IsSecureProxyAllowed(false));
EXPECT_FALSE(network_properties_manager.IsSecureProxyAllowed(true));
EXPECT_FALSE(network_properties_manager.IsSecureProxyDisallowedByCarrier());
EXPECT_TRUE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true));
EXPECT_FALSE(
network_properties_manager.HasWarmupURLProbeFailed(false, false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true, false));
base::RunLoop().RunUntilIdle();
// Verify the prefs.
......@@ -64,12 +68,14 @@ TEST(NetworkPropertyTest, TestSetterGetterCaptivePortal) {
}
network_properties_manager.SetIsCaptivePortal(false);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(true));
EXPECT_FALSE(network_properties_manager.IsSecureProxyDisallowedByCarrier());
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true));
EXPECT_FALSE(
network_properties_manager.HasWarmupURLProbeFailed(false, false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true, false));
base::RunLoop().RunUntilIdle();
{
......@@ -94,78 +100,108 @@ TEST(NetworkPropertyTest, TestSetterGetterDisallowedByCarrier) {
TestNetworkPropertiesManager network_properties_manager(
&test_prefs, base::ThreadTaskRunnerHandle::Get());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(false));
network_properties_manager.SetIsSecureProxyDisallowedByCarrier(true);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_FALSE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(false));
EXPECT_FALSE(network_properties_manager.IsSecureProxyAllowed(false));
EXPECT_FALSE(network_properties_manager.IsSecureProxyAllowed(true));
EXPECT_TRUE(network_properties_manager.IsSecureProxyDisallowedByCarrier());
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true));
EXPECT_FALSE(
network_properties_manager.HasWarmupURLProbeFailed(false, false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true, false));
network_properties_manager.SetIsSecureProxyDisallowedByCarrier(false);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(false));
EXPECT_FALSE(network_properties_manager.IsSecureProxyDisallowedByCarrier());
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true));
EXPECT_FALSE(
network_properties_manager.HasWarmupURLProbeFailed(false, false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true, false));
}
TEST(NetworkPropertyTest, TestWarmupURLFailedOnSecureProxy) {
TEST(NetworkPropertyTest, TestWarmupURLFailedOnSecureCoreProxy) {
TestingPrefServiceSimple test_prefs;
test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
base::MessageLoopForIO loop;
TestNetworkPropertiesManager network_properties_manager(
&test_prefs, base::ThreadTaskRunnerHandle::Get());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(false));
network_properties_manager.SetHasWarmupURLProbeFailed(true, true);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_FALSE(network_properties_manager.IsSecureProxyAllowed());
network_properties_manager.SetHasWarmupURLProbeFailed(
true /* secure_proxy */, true /* is_core_proxy */,
true /* warmup_url_probe_failed */);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(false));
EXPECT_FALSE(network_properties_manager.IsSecureProxyAllowed(true));
EXPECT_FALSE(network_properties_manager.IsSecureProxyDisallowedByCarrier());
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false));
EXPECT_TRUE(network_properties_manager.HasWarmupURLProbeFailed(true));
network_properties_manager.SetHasWarmupURLProbeFailed(true, false);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(
false /* secure_proxy */, false /* is_core_proxy */));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true, false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false, true));
EXPECT_TRUE(network_properties_manager.HasWarmupURLProbeFailed(true, true));
network_properties_manager.SetHasWarmupURLProbeFailed(true, true, false);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(true));
EXPECT_FALSE(network_properties_manager.IsSecureProxyDisallowedByCarrier());
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true));
EXPECT_FALSE(
network_properties_manager.HasWarmupURLProbeFailed(false, false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false, true));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true, false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true, true));
}
TEST(NetworkPropertyTest, TestWarmupURLFailedOnInSecureProxy) {
TEST(NetworkPropertyTest, TestWarmupURLFailedOnInSecureCoreProxy) {
TestingPrefServiceSimple test_prefs;
test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
base::MessageLoopForIO loop;
TestNetworkPropertiesManager network_properties_manager(
&test_prefs, base::ThreadTaskRunnerHandle::Get());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed());
network_properties_manager.SetHasWarmupURLProbeFailed(false, true);
EXPECT_FALSE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(true));
network_properties_manager.SetHasWarmupURLProbeFailed(
false /* secure_proxy */, true /* is_core_proxy */,
true /* warmup_url_probe_failed */);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(false));
EXPECT_FALSE(network_properties_manager.IsInsecureProxyAllowed(true));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(true));
EXPECT_FALSE(network_properties_manager.IsSecureProxyDisallowedByCarrier());
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_TRUE(network_properties_manager.HasWarmupURLProbeFailed(false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true));
network_properties_manager.SetHasWarmupURLProbeFailed(false, false);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(
false /* secure_proxy */, false /* is_core_proxy */));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true, false));
EXPECT_TRUE(network_properties_manager.HasWarmupURLProbeFailed(false, true));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true, true));
network_properties_manager.SetHasWarmupURLProbeFailed(false, true, false);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(false));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(true));
EXPECT_FALSE(network_properties_manager.IsSecureProxyDisallowedByCarrier());
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true));
EXPECT_FALSE(
network_properties_manager.HasWarmupURLProbeFailed(false, false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false, true));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true, false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true, true));
}
TEST(NetworkPropertyTest, TestLimitPrefSize) {
......@@ -182,16 +218,18 @@ TEST(NetworkPropertyTest, TestLimitPrefSize) {
network_properties_manager.OnChangeInNetworkID(network_id);
// State should be reset when there is a change in the network ID.
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(true));
network_properties_manager.SetIsCaptivePortal(true);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_FALSE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
EXPECT_FALSE(network_properties_manager.IsSecureProxyAllowed(true));
EXPECT_FALSE(network_properties_manager.IsSecureProxyDisallowedByCarrier());
EXPECT_TRUE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true));
EXPECT_FALSE(
network_properties_manager.HasWarmupURLProbeFailed(false, true));
EXPECT_FALSE(
network_properties_manager.HasWarmupURLProbeFailed(true, true));
base::RunLoop().RunUntilIdle();
}
......@@ -219,8 +257,10 @@ TEST(NetworkPropertyTest, TestLimitPrefSize) {
network_properties_manager_2.IsCaptivePortal());
EXPECT_FALSE(
network_properties_manager_2.IsSecureProxyDisallowedByCarrier());
EXPECT_FALSE(network_properties_manager_2.HasWarmupURLProbeFailed(false));
EXPECT_FALSE(network_properties_manager_2.HasWarmupURLProbeFailed(true));
EXPECT_FALSE(
network_properties_manager_2.HasWarmupURLProbeFailed(false, true));
EXPECT_FALSE(
network_properties_manager_2.HasWarmupURLProbeFailed(true, true));
}
}
}
......@@ -237,10 +277,10 @@ TEST(NetworkPropertyTest, TestChangeNetworkIDBackAndForth) {
network_properties_manager.OnChangeInNetworkID(first_network_id);
// State should be reset when there is a change in the network ID.
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
network_properties_manager.SetIsCaptivePortal(true);
EXPECT_TRUE(network_properties_manager.IsCaptivePortal());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
base::RunLoop().RunUntilIdle();
// Warmup probe failed on the insecure proxy for the second network ID.
......@@ -248,21 +288,21 @@ TEST(NetworkPropertyTest, TestChangeNetworkIDBackAndForth) {
network_properties_manager.OnChangeInNetworkID(second_network_id);
// State should be reset when there is a change in the network ID.
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
network_properties_manager.SetHasWarmupURLProbeFailed(false, true);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
network_properties_manager.SetHasWarmupURLProbeFailed(false, true, true);
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_FALSE(network_properties_manager.IsInsecureProxyAllowed(true));
base::RunLoop().RunUntilIdle();
// Change back to |first_network_id|.
network_properties_manager.OnChangeInNetworkID(first_network_id);
EXPECT_TRUE(network_properties_manager.IsCaptivePortal());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
// Change back to |second_network_id|.
network_properties_manager.OnChangeInNetworkID(second_network_id);
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_FALSE(network_properties_manager.IsInsecureProxyAllowed(true));
// Verify the prefs.
EXPECT_EQ(2u, test_prefs.GetDictionary(prefs::kNetworkProperties)->size());
......@@ -286,10 +326,10 @@ TEST(NetworkPropertyTest, TestNetworkQualitiesOverwrite) {
network_properties_manager.OnChangeInNetworkID(first_network_id);
// State should be reset when there is a change in the network ID.
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
network_properties_manager.SetIsCaptivePortal(true);
EXPECT_TRUE(network_properties_manager.IsCaptivePortal());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
base::RunLoop().RunUntilIdle();
// Warmup probe failed on the insecure proxy for the second network ID.
......@@ -297,22 +337,22 @@ TEST(NetworkPropertyTest, TestNetworkQualitiesOverwrite) {
network_properties_manager.OnChangeInNetworkID(second_network_id);
// State should be reset when there is a change in the network ID.
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
network_properties_manager.SetHasWarmupURLProbeFailed(false, true);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
network_properties_manager.SetHasWarmupURLProbeFailed(false, true, true);
EXPECT_FALSE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_FALSE(network_properties_manager.IsInsecureProxyAllowed(true));
base::RunLoop().RunUntilIdle();
// Change back to |first_network_id|.
network_properties_manager.OnChangeInNetworkID(first_network_id);
EXPECT_TRUE(network_properties_manager.IsCaptivePortal());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
network_properties_manager.SetHasWarmupURLProbeFailed(false, true);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
network_properties_manager.SetHasWarmupURLProbeFailed(false, true, true);
// Change to |first_network_id|.
network_properties_manager.OnChangeInNetworkID(first_network_id);
EXPECT_TRUE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_FALSE(network_properties_manager.IsInsecureProxyAllowed(true));
// Verify the prefs.
EXPECT_EQ(2u, test_prefs.GetDictionary(prefs::kNetworkProperties)->size());
......@@ -337,16 +377,16 @@ TEST(NetworkPropertyTest, TestDeleteHistory) {
histogram_tester.ExpectUniqueSample(
"DataReductionProxy.NetworkProperties.CacheHit", false, 1);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
EXPECT_TRUE(network_properties_manager.IsSecureProxyAllowed(true));
network_properties_manager.SetIsCaptivePortal(true);
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed());
EXPECT_FALSE(network_properties_manager.IsSecureProxyAllowed());
EXPECT_TRUE(network_properties_manager.IsInsecureProxyAllowed(true));
EXPECT_FALSE(network_properties_manager.IsSecureProxyAllowed(true));
EXPECT_FALSE(network_properties_manager.IsSecureProxyDisallowedByCarrier());
EXPECT_TRUE(network_properties_manager.IsCaptivePortal());
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(false, true));
EXPECT_FALSE(network_properties_manager.HasWarmupURLProbeFailed(true, true));
base::RunLoop().RunUntilIdle();
// Verify the prefs.
......
......@@ -79,6 +79,8 @@ static_library("test_support") {
]
deps = [
"//base",
"//components/prefs",
"//components/prefs:test_support",
"//net",
"//net:test_support",
"//testing/gmock",
......@@ -100,6 +102,8 @@ source_set("unit_tests") {
":test_support",
"//base",
"//base/test:test_support",
"//components/prefs",
"//components/prefs:test_support",
# TODO this dependency seems wrong, but
# data_reduction_proxy_event_store_unittest.cc includes a file from it.
......
......@@ -13,13 +13,18 @@
#include "base/bind.h"
#include "base/json/json_writer.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/core/browser/network_properties_manager.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_server.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "net/base/host_port_pair.h"
#include "net/base/net_errors.h"
#include "net/http/http_status_code.h"
......@@ -217,6 +222,11 @@ TEST_F(DataReductionProxyEventStoreTest, TestEndSecureProxyCheckFailed) {
}
TEST_F(DataReductionProxyEventStoreTest, TestFeedbackMethods) {
base::MessageLoopForIO loop;
TestingPrefServiceSimple test_prefs;
test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
NetworkPropertiesManager manager(&test_prefs,
base::ThreadTaskRunnerHandle::Get());
DataReductionProxyConfigurator configurator(net_log(), event_creator());
EXPECT_EQ(std::string(), event_store()->GetHttpProxyList());
EXPECT_EQ(std::string(), event_store()->SanitizedLastBypassEvent());
......@@ -230,7 +240,7 @@ TEST_F(DataReductionProxyEventStoreTest, TestFeedbackMethods) {
net::ProxyServer(net::ProxyServer::SCHEME_HTTPS,
net::HostPortPair("bar.com", 443)),
ProxyServer::CORE));
configurator.Enable(false, false, http_proxies);
configurator.Enable(manager, http_proxies);
EXPECT_EQ("foo.com:80;https://bar.com:443",
event_store()->GetHttpProxyList());
......@@ -239,9 +249,14 @@ TEST_F(DataReductionProxyEventStoreTest, TestFeedbackMethods) {
}
TEST_F(DataReductionProxyEventStoreTest, TestFeedbackLastBypassEventFullURL) {
base::MessageLoopForIO loop;
TestingPrefServiceSimple test_prefs;
test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
NetworkPropertiesManager manager(&test_prefs,
base::ThreadTaskRunnerHandle::Get());
DataReductionProxyConfigurator configurator(net_log(), event_creator());
std::vector<DataReductionProxyServer> http_proxies;
configurator.Enable(false, false, http_proxies);
configurator.Enable(manager, http_proxies);
std::unique_ptr<base::DictionaryValue> bypass_event(
new base::DictionaryValue());
......@@ -272,9 +287,14 @@ TEST_F(DataReductionProxyEventStoreTest, TestFeedbackLastBypassEventFullURL) {
}
TEST_F(DataReductionProxyEventStoreTest, TestFeedbackLastBypassEventHostOnly) {
base::MessageLoopForIO loop;
TestingPrefServiceSimple test_prefs;
test_prefs.registry()->RegisterDictionaryPref(prefs::kNetworkProperties);
NetworkPropertiesManager manager(&test_prefs,
base::ThreadTaskRunnerHandle::Get());
DataReductionProxyConfigurator configurator(net_log(), event_creator());
std::vector<DataReductionProxyServer> http_proxies;
configurator.Enable(false, false, http_proxies);
configurator.Enable(manager, http_proxies);
std::unique_ptr<base::DictionaryValue> bypass_event(
new base::DictionaryValue());
......
......@@ -15,9 +15,18 @@ message ProxyFlags {
// State of different proxy schemes on a given network.
message NetworkProperties {
// True if the usage of secure proxy has been disallowed by the carrier.
optional bool secure_proxy_disallowed_by_carrier = 1;
// True if the network has a captive portal.
optional bool has_captive_portal = 2;
// State of the secure core data saver proxies.
optional ProxyFlags secure_proxy_flags = 3;
// State of the insecure core data saver proxies.
optional ProxyFlags insecure_proxy_flags = 4;
// Time when this network property was last modified.
optional int64 last_modified = 5;
// State of the secure non-core data saver proxies.
optional ProxyFlags secure_non_core_proxy_flags = 6;
// State of the insecure non-core data saver proxies.
optional ProxyFlags insecure_non_core_proxy_flags = 7;
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment