Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc

Issue 2575323002: Store data reduction proxy server in a separate class (Closed)
Patch Set: ryansturm comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc
index bb979db5db6ef52389a12a6dca00709d3fb45733..97a837532429e38a914a838732590165603eaa07 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc
@@ -22,10 +22,12 @@
#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.h"
#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/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"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_server.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
#include "components/data_reduction_proxy/proto/client_config.pb.h"
#include "net/base/network_change_notifier.h"
@@ -81,9 +83,11 @@ ClientConfig CreateConfig(const std::string& session_key,
ProxyServer_ProxyScheme primary_scheme,
const std::string& primary_host,
int primary_port,
+ const ProxyServer_ProxyType& primary_proxy_type,
ProxyServer_ProxyScheme secondary_scheme,
const std::string& secondary_host,
int secondary_port,
+ const ProxyServer_ProxyType& secondary_proxy_type,
float reporting_fraction) {
ClientConfig config;
@@ -102,11 +106,14 @@ ClientConfig CreateConfig(const std::string& session_key,
primary_proxy->set_scheme(primary_scheme);
primary_proxy->set_host(primary_host);
primary_proxy->set_port(primary_port);
+ primary_proxy->set_type(primary_proxy_type);
+
ProxyServer* secondary_proxy =
config.mutable_proxy_config()->add_http_proxy_servers();
secondary_proxy->set_scheme(secondary_scheme);
secondary_proxy->set_host(secondary_host);
secondary_proxy->set_port(secondary_port);
+ secondary_proxy->set_type(secondary_proxy_type);
return config;
}
@@ -162,33 +169,38 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
ClientConfig config =
CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "origin.net", 443,
- ProxyServer_ProxyScheme_HTTP, "fallback.net", 80, 0.5f);
+ ProxyServer::CORE, ProxyServer_ProxyScheme_HTTP,
+ "fallback.net", 80, ProxyServer::UNSPECIFIED_TYPE, 0.5f);
config.SerializeToString(&config_);
encoded_config_ = EncodeConfig(config);
ClientConfig previous_config = CreateConfig(
kOldSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
- ProxyServer_ProxyScheme_HTTPS, "old.origin.net", 443,
- ProxyServer_ProxyScheme_HTTP, "old.fallback.net", 80, 0.0f);
+ ProxyServer_ProxyScheme_HTTPS, "old.origin.net", 443, ProxyServer::CORE,
+ ProxyServer_ProxyScheme_HTTP, "old.fallback.net", 80,
+ ProxyServer::UNSPECIFIED_TYPE, 0.0f);
previous_config.SerializeToString(&previous_config_);
ClientConfig persisted =
CreateConfig(kPersistedSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "persisted.net", 443,
- ProxyServer_ProxyScheme_HTTP, "persisted.net", 80, 0.0f);
+ ProxyServer::CORE, ProxyServer_ProxyScheme_HTTP,
+ "persisted.net", 80, ProxyServer::UNSPECIFIED_TYPE, 0.0f);
loaded_config_ = EncodeConfig(persisted);
ClientConfig zero_reporting_fraction_config =
CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "origin.net", 443,
- ProxyServer_ProxyScheme_HTTP, "origin.net", 0, 0.0f);
+ ProxyServer::CORE, ProxyServer_ProxyScheme_HTTP,
+ "origin.net", 0, ProxyServer::UNSPECIFIED_TYPE, 0.0f);
zero_reporting_fraction_encoded_config_ =
EncodeConfig(zero_reporting_fraction_config);
ClientConfig one_reporting_fraction_config =
CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
- ProxyServer_ProxyScheme_HTTPS, "", 443,
- ProxyServer_ProxyScheme_HTTP, "", 0, 1.0f);
+ ProxyServer_ProxyScheme_HTTPS, "", 443, ProxyServer::CORE,
+ ProxyServer_ProxyScheme_HTTP, "", 0,
+ ProxyServer::UNSPECIFIED_TYPE, 1.0f);
one_reporting_fraction_encoded_config_ =
EncodeConfig(one_reporting_fraction_config);
@@ -198,14 +210,16 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
ClientConfig empty_reporting_fraction_config =
CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "origin.net", 443,
- ProxyServer_ProxyScheme_HTTP, "origin.net", 0, -1.0f);
+ ProxyServer::CORE, ProxyServer_ProxyScheme_HTTP,
+ "origin.net", 0, ProxyServer::UNSPECIFIED_TYPE, -1.0f);
empty_reporting_fraction_encoded_config_ =
EncodeConfig(empty_reporting_fraction_config);
ClientConfig half_reporting_fraction_config =
CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
ProxyServer_ProxyScheme_HTTPS, "origin.net", 443,
- ProxyServer_ProxyScheme_HTTP, "origin.net", 0, 0.5f);
+ ProxyServer::CORE, ProxyServer_ProxyScheme_HTTP,
+ "origin.net", 0, ProxyServer::UNSPECIFIED_TYPE, 0.5f);
half_reporting_fraction_encoded_config_ =
EncodeConfig(half_reporting_fraction_config);
@@ -233,44 +247,112 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
}
void VerifyRemoteSuccess(bool expect_secure_proxies) {
- std::vector<net::ProxyServer> expected_http_proxies;
+ std::vector<DataReductionProxyServer> expected_http_proxies;
if (expect_secure_proxies) {
- expected_http_proxies.push_back(net::ProxyServer::FromURI(
- kSuccessOrigin, net::ProxyServer::SCHEME_HTTP));
+ expected_http_proxies.push_back(DataReductionProxyServer(
+ net::ProxyServer::FromURI(kSuccessOrigin,
+ net::ProxyServer::SCHEME_HTTP),
+ ProxyServer::CORE));
}
- expected_http_proxies.push_back(net::ProxyServer::FromURI(
- kSuccessFallback, net::ProxyServer::SCHEME_HTTP));
+ expected_http_proxies.push_back(DataReductionProxyServer(
+ net::ProxyServer::FromURI(kSuccessFallback,
+ net::ProxyServer::SCHEME_HTTP),
+ ProxyServer::UNSPECIFIED_TYPE));
+
EXPECT_EQ(base::TimeDelta::FromSeconds(kConfigRefreshDurationSeconds),
config_client()->GetDelay());
- EXPECT_EQ(expected_http_proxies, GetConfiguredProxiesForHttp());
+ EXPECT_EQ(DataReductionProxyServer::ConvertToNetProxyServers(
+ expected_http_proxies),
+ GetConfiguredProxiesForHttp());
EXPECT_EQ(kSuccessSessionKey, request_options()->GetSecureSession());
// The config should be persisted on the pref.
EXPECT_EQ(encoded_config(), persisted_config());
EXPECT_EQ(0.5f, pingback_reporting_fraction());
+
+ // Verify that the data reduction proxy servers are correctly set.
+ // The first proxy must have type CORE. The second proxy must have type
+ // UNSPECIFIED_TYPE since these are the types specified in the encoded
+ // configs.
+ ASSERT_EQ(
+ 2U, test_context_->mutable_config_values()->proxies_for_http().size());
+ EXPECT_EQ(ProxyServer::CORE, test_context_->mutable_config_values()
+ ->proxies_for_http()
+ .at(0)
+ .GetProxyTypeForTesting());
+ EXPECT_EQ(ProxyServer::UNSPECIFIED_TYPE,
+ test_context_->mutable_config_values()
+ ->proxies_for_http()
+ .at(1)
+ .GetProxyTypeForTesting());
}
void VerifyRemoteSuccessWithOldConfig() {
- std::vector<net::ProxyServer> expected_http_proxies;
- expected_http_proxies.push_back(net::ProxyServer::FromURI(
- kOldSuccessOrigin, net::ProxyServer::SCHEME_HTTP));
- expected_http_proxies.push_back(net::ProxyServer::FromURI(
- kOldSuccessFallback, net::ProxyServer::SCHEME_HTTP));
+ std::vector<DataReductionProxyServer> expected_http_proxies;
+ expected_http_proxies.push_back(DataReductionProxyServer(
+ net::ProxyServer::FromURI(kOldSuccessOrigin,
+ net::ProxyServer::SCHEME_HTTP),
+ ProxyServer::CORE));
+ expected_http_proxies.push_back(DataReductionProxyServer(
+ net::ProxyServer::FromURI(kOldSuccessFallback,
+ net::ProxyServer::SCHEME_HTTP),
+ ProxyServer::UNSPECIFIED_TYPE));
+
EXPECT_EQ(base::TimeDelta::FromSeconds(kConfigRefreshDurationSeconds),
config_client()->GetDelay());
- EXPECT_EQ(expected_http_proxies, GetConfiguredProxiesForHttp());
+ EXPECT_EQ(DataReductionProxyServer::ConvertToNetProxyServers(
+ expected_http_proxies),
+ GetConfiguredProxiesForHttp());
EXPECT_EQ(kOldSuccessSessionKey, request_options()->GetSecureSession());
+
+ // Verify that the data reduction proxy servers are correctly set.
+ // The first proxy must have type CORE. The second proxy must have type
+ // UNSPECIFIED_TYPE since these are the types specified in the encoded
+ // configs.
+ ASSERT_EQ(
+ 2U, test_context_->mutable_config_values()->proxies_for_http().size());
+ EXPECT_EQ(ProxyServer::CORE, test_context_->mutable_config_values()
+ ->proxies_for_http()
+ .at(0)
+ .GetProxyTypeForTesting());
+ EXPECT_EQ(ProxyServer::UNSPECIFIED_TYPE,
+ test_context_->mutable_config_values()
+ ->proxies_for_http()
+ .at(1)
+ .GetProxyTypeForTesting());
}
void VerifySuccessWithLoadedConfig(bool expect_secure_proxies) {
- std::vector<net::ProxyServer> expected_http_proxies;
+ std::vector<DataReductionProxyServer> expected_http_proxies;
if (expect_secure_proxies) {
- expected_http_proxies.push_back(net::ProxyServer::FromURI(
- kPersistedOrigin, net::ProxyServer::SCHEME_HTTP));
+ expected_http_proxies.push_back(DataReductionProxyServer(
+ net::ProxyServer::FromURI(kPersistedOrigin,
+ net::ProxyServer::SCHEME_HTTP),
+ ProxyServer::CORE));
}
- expected_http_proxies.push_back(net::ProxyServer::FromURI(
- kPersistedFallback, net::ProxyServer::SCHEME_HTTP));
- EXPECT_EQ(expected_http_proxies, GetConfiguredProxiesForHttp());
+ expected_http_proxies.push_back(DataReductionProxyServer(
+ net::ProxyServer::FromURI(kPersistedFallback,
+ net::ProxyServer::SCHEME_HTTP),
+ ProxyServer::UNSPECIFIED_TYPE));
+ EXPECT_EQ(DataReductionProxyServer::ConvertToNetProxyServers(
+ expected_http_proxies),
+ GetConfiguredProxiesForHttp());
EXPECT_EQ(kPersistedSessionKey, request_options()->GetSecureSession());
+
+ // Verify that the data reduction proxy servers are correctly set.
+ // The first proxy must have type CORE. The second proxy must have type
+ // UNSPECIFIED_TYPE since these are the types specified in the encoded
+ // configs.
+ ASSERT_EQ(
+ 2U, test_context_->mutable_config_values()->proxies_for_http().size());
+ EXPECT_EQ(ProxyServer::CORE, test_context_->mutable_config_values()
+ ->proxies_for_http()
+ .at(0)
+ .GetProxyTypeForTesting());
+ EXPECT_EQ(ProxyServer::UNSPECIFIED_TYPE,
+ test_context_->mutable_config_values()
+ ->proxies_for_http()
+ .at(1)
+ .GetProxyTypeForTesting());
}
TestDataReductionProxyConfigServiceClient* config_client() {

Powered by Google App Engine
This is Rietveld 408576698