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

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

Issue 1862193002: Enable QUIC for proxies only when QUIC is enabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed sclittle comments Created 4 years, 7 months 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 1ef8b1d56afe2791b306c577c9899c68f6fce44a..e17bb8e3ebfb192f8511bc71a53fbc2d04fbb285 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
@@ -123,7 +123,9 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
mock_socket_factory_.reset(new net::MockClientSocketFactory());
}
- void Init(bool use_mock_client_socket_factory) {
+ void Init(bool use_mock_client_socket_factory,
+ bool enable_quic_in_params,
+ const std::string& quic_field_trial_group) {
if (!use_mock_client_socket_factory)
mock_socket_factory_.reset(nullptr);
test_context_ =
@@ -134,14 +136,26 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
.WithTestConfigurator()
.WithMockRequestOptions()
.WithTestConfigClient()
+ .SkipSettingsInitialization()
.Build();
+ std::unique_ptr<net::HttpNetworkSession::Params> params(
+ new net::HttpNetworkSession::Params());
+ params->enable_quic = enable_quic_in_params;
+ context_->set_http_network_session_params(std::move(params));
context_->set_client_socket_factory(mock_socket_factory_.get());
test_context_->AttachToURLRequestContext(context_storage_.get());
delegate_ = test_context_->io_data()->CreateProxyDelegate();
context_->set_proxy_delegate(delegate_.get());
context_->Init();
+ base::FieldTrialList field_trial_list(nullptr);
+ if (!quic_field_trial_group.empty()) {
+ base::FieldTrialList::CreateFieldTrial(params::GetQuicFieldTrialName(),
+ quic_field_trial_group);
+ }
+
+ test_context_->InitSettings();
ResetBackoffEntryReleaseTime();
test_context_->test_config_client()->SetNow(base::Time::UnixEpoch());
test_context_->test_config_client()->SetEnabled(true);
@@ -292,10 +306,6 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
return previous_config_;
}
- void EnableQuic(bool enable) {
- test_context_->test_params()->EnableQuic(enable);
- }
-
bool IsTrustedSpdyProxy(const net::ProxyServer& proxy_server) const {
return delegate_->IsTrustedSpdyProxy(proxy_server);
}
@@ -306,6 +316,62 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
return context_.get();
}
+ void TestQuicProxy(bool enable_quic_in_params,
+ const std::string& quic_field_trial_group,
+ bool enable_trusted_spdy_proxy_field_trial,
+ const std::string& expected_primary_proxy,
+ const std::string& expected_fallback_proxy,
+ net::ProxyServer::Scheme expected_primary_proxy_scheme) {
+ Init(true, enable_quic_in_params, quic_field_trial_group);
+
+ base::FieldTrialList field_trial_list(new base::MockEntropyProvider());
+ base::FieldTrialList::CreateFieldTrial(
+ params::GetTrustedSpdyProxyFieldTrialName(),
+ enable_trusted_spdy_proxy_field_trial ? "Enabled" : "Control");
+
+ // Use a remote config.
+ AddMockSuccess();
+
+ SetDataReductionProxyEnabled(true);
+
+ config_client()->RetrieveConfig();
+ RunUntilIdle();
+ EXPECT_EQ(base::TimeDelta::FromSeconds(kConfigRefreshDurationSeconds),
+ config_client()->GetDelay());
+
+ // Verify that the proxies were set properly.
+ std::vector<net::ProxyServer> proxies_for_http =
+ configurator()->proxies_for_http();
+
+ EXPECT_EQ(2U, proxies_for_http.size());
+
+ EXPECT_EQ(net::ProxyServer(
+ expected_primary_proxy_scheme,
+ net::ProxyServer::FromURI(expected_primary_proxy,
+ expected_primary_proxy_scheme)
+ .host_port_pair()),
+ proxies_for_http[0]);
+ EXPECT_EQ(net::ProxyServer::FromURI(expected_fallback_proxy,
+ net::ProxyServer::SCHEME_HTTP),
+ proxies_for_http[1]);
+
+ // Test that the trusted SPDY proxy is updated correctly after each config
+ // retrieval. Currently, only the HTTPS proxies are marked as trusted.
+ bool expect_proxy_is_trusted =
+ expected_primary_proxy_scheme == net::ProxyServer::SCHEME_HTTPS &&
+ enable_trusted_spdy_proxy_field_trial;
+
+ // Apply the specified proxy scheme.
+ const net::ProxyServer proxy_server(
+ expected_primary_proxy_scheme,
+ net::ProxyServer::FromURI(expected_primary_proxy,
+ net::ProxyServer::SCHEME_HTTP)
+ .host_port_pair());
+
+ ASSERT_EQ(expected_primary_proxy_scheme, proxy_server.scheme());
+ EXPECT_EQ(expect_proxy_is_trusted, IsTrustedSpdyProxy(proxy_server));
+ }
+
private:
base::MessageLoopForIO message_loop_;
std::unique_ptr<net::TestURLRequestContext> context_;
@@ -341,89 +407,60 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigServiceClientTest);
};
-// Tests the interaction of client config with QUIC field trial.
-TEST_F(DataReductionProxyConfigServiceClientTest, QuicFieldTrial) {
- Init(true);
- const struct {
- bool enable_quic;
- bool enable_trusted_spdy_proxy_field_trial;
- std::string expected_primary_proxy;
- std::string expected_fallback_proxy;
- net::ProxyServer::Scheme expected_primary_proxy_scheme;
- } tests[] = {
- {false, false, kSuccessOrigin, kSuccessFallback,
- net::ProxyServer::SCHEME_HTTPS},
- {false, true, kSuccessOrigin, kSuccessFallback,
- net::ProxyServer::SCHEME_HTTPS},
- {true, true, kSuccessOrigin, kSuccessFallback,
- net::ProxyServer::SCHEME_QUIC},
- };
-
- for (size_t i = 0; i < arraysize(tests); ++i) {
- base::FieldTrialList field_trial_list(new base::MockEntropyProvider());
- base::FieldTrialList::CreateFieldTrial(
- params::GetTrustedSpdyProxyFieldTrialName(),
- tests[i].enable_trusted_spdy_proxy_field_trial ? "Enabled" : "Control");
- if (tests[i].enable_quic) {
- base::FieldTrialList::CreateFieldTrial(params::GetQuicFieldTrialName(),
- "Enabled");
- } else {
- base::FieldTrialList::CreateFieldTrial(params::GetQuicFieldTrialName(),
- "Control");
- }
- EnableQuic(tests[i].enable_quic);
-
- // Use a remote config.
- AddMockSuccess();
-
- SetDataReductionProxyEnabled(true);
+// Tests that QUIC proxy is not used when QUIC is not enabled globally.
+TEST_F(DataReductionProxyConfigServiceClientTest, DisableQuic) {
+ TestQuicProxy(false, "Control", false, kSuccessOrigin, kSuccessFallback,
+ net::ProxyServer::SCHEME_HTTPS);
+}
- config_client()->RetrieveConfig();
- RunUntilIdle();
- EXPECT_EQ(base::TimeDelta::FromSeconds(kConfigRefreshDurationSeconds),
- config_client()->GetDelay())
- << i;
+// Tests that QUIC proxy is not used when the session is not in data reduction
+// proxy's QUIC experiment.
+TEST_F(DataReductionProxyConfigServiceClientTest, EnableQuicOnlyInParams) {
+ TestQuicProxy(true, "", true, kSuccessOrigin, kSuccessFallback,
+ net::ProxyServer::SCHEME_HTTPS);
+}
- // Verify that the proxies were set properly.
- std::vector<net::ProxyServer> proxies_for_http =
- configurator()->proxies_for_http();
+// Tests that QUIC proxy is not used when the session is in the control group of
+// data reduction proxy's QUIC experiment.
+TEST_F(DataReductionProxyConfigServiceClientTest,
+ EnableQuicOnlyInParamsControlGroup) {
+ TestQuicProxy(true, "Control", true, kSuccessOrigin, kSuccessFallback,
+ net::ProxyServer::SCHEME_HTTPS);
+}
- EXPECT_EQ(2U, proxies_for_http.size()) << i;
- EXPECT_EQ(net::ProxyServer(tests[i].expected_primary_proxy_scheme,
- net::ProxyServer::FromURI(
- tests[i].expected_primary_proxy,
- tests[i].expected_primary_proxy_scheme)
- .host_port_pair()),
- proxies_for_http[0])
- << i;
- EXPECT_EQ(net::ProxyServer::FromURI(tests[i].expected_fallback_proxy,
- net::ProxyServer::SCHEME_HTTP),
- proxies_for_http[1])
- << i;
+// Tests that QUIC proxy is not used when QUIC is not enabled globally.
+TEST_F(DataReductionProxyConfigServiceClientTest, EnableQuicOnlyViaFieldTrial) {
+ TestQuicProxy(false, "Enabled", true, kSuccessOrigin, kSuccessFallback,
+ net::ProxyServer::SCHEME_HTTPS);
+}
- // Test that the trusted SPDY proxy is updated correctly after each config
- // retrieval.
- bool expect_proxy_is_trusted =
- tests[i].expected_primary_proxy_scheme ==
- net::ProxyServer::SCHEME_HTTPS &&
- tests[i].enable_trusted_spdy_proxy_field_trial;
+// Tests that QUIC proxy is used when all conditions are satisfied, and Chromium
+// is in the "Enabled" field trial group.
+TEST_F(DataReductionProxyConfigServiceClientTest,
+ EnableQuicButNotTrustedSpdyProxy) {
+ TestQuicProxy(true, "Enabled", false, kSuccessOrigin, kSuccessFallback,
+ net::ProxyServer::SCHEME_QUIC);
+}
- // Apply the specified proxy scheme.
- const net::ProxyServer proxy_server(
- tests[i].expected_primary_proxy_scheme,
- net::ProxyServer::FromURI(tests[i].expected_primary_proxy,
- net::ProxyServer::SCHEME_HTTP)
- .host_port_pair());
+// Tests that QUIC proxy is used when all conditions are satisfied, and Chromium
+// is in the "Enabled_NoControl" field trial group.
+TEST_F(DataReductionProxyConfigServiceClientTest,
+ EnableQuicPrefixMatchingButNotTrustedSpdyProxy) {
+ TestQuicProxy(true, "Enabled_NoControl", false, kSuccessOrigin,
+ kSuccessFallback, net::ProxyServer::SCHEME_QUIC);
+}
- ASSERT_EQ(tests[i].expected_primary_proxy_scheme, proxy_server.scheme())
- << i;
- EXPECT_EQ(expect_proxy_is_trusted, IsTrustedSpdyProxy(proxy_server)) << i;
- }
+// Tests the interaction of the QUIC experiment with the trusted SPDY proxy
+// experiment.
+TEST_F(DataReductionProxyConfigServiceClientTest,
+ EnableQuicAndTrustedSpdyProxy) {
+ TestQuicProxy(true, "Enabled", true, kSuccessOrigin, kSuccessFallback,
+ net::ProxyServer::SCHEME_QUIC);
}
// Tests that backoff values increases with every time config cannot be fetched.
TEST_F(DataReductionProxyConfigServiceClientTest, EnsureBackoff) {
- Init(true);
+ Init(true, false, std::string());
// Use a local/static config.
base::HistogramTester histogram_tester;
AddMockFailure();
@@ -462,7 +499,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest, EnsureBackoff) {
// Tests that the config is read successfully on the first attempt.
TEST_F(DataReductionProxyConfigServiceClientTest, RemoteConfigSuccess) {
- Init(true);
+ Init(true, false, std::string());
AddMockSuccess();
SetDataReductionProxyEnabled(true);
EXPECT_TRUE(configurator()->proxies_for_http().empty());
@@ -477,7 +514,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest, RemoteConfigSuccess) {
// Tests that the config is read successfully on the second attempt.
TEST_F(DataReductionProxyConfigServiceClientTest,
RemoteConfigSuccessAfterFailure) {
- Init(true);
+ Init(true, false, std::string());
base::HistogramTester histogram_tester;
AddMockFailure();
@@ -509,7 +546,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest,
// Verifies that the config is fetched successfully after IP address changes.
TEST_F(DataReductionProxyConfigServiceClientTest, OnIPAddressChange) {
- Init(true);
+ Init(true, false, std::string());
SetDataReductionProxyEnabled(true);
config_client()->RetrieveConfig();
@@ -543,7 +580,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest, OnIPAddressChange) {
// Verifies that fetching the remote config has no effect if the config client
// is disabled.
TEST_F(DataReductionProxyConfigServiceClientTest, OnIPAddressChangeDisabled) {
- Init(true);
+ Init(true, false, std::string());
config_client()->SetEnabled(false);
SetDataReductionProxyEnabled(true);
config_client()->RetrieveConfig();
@@ -570,7 +607,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest, OnIPAddressChangeDisabled) {
// Verifies the correctness of AuthFailure when the session key in the request
// headers matches the currrent session key.
TEST_F(DataReductionProxyConfigServiceClientTest, AuthFailure) {
- Init(true);
+ Init(true, false, std::string());
net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
net::NetworkChangeNotifier::CONNECTION_WIFI);
net::HttpRequestHeaders request_headers;
@@ -656,7 +693,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest, AuthFailure) {
// headers do not match the currrent session key.
TEST_F(DataReductionProxyConfigServiceClientTest,
AuthFailureWithRequestHeaders) {
- Init(true);
+ Init(true, false, std::string());
net::HttpRequestHeaders request_headers;
const char kSessionKeyRequestHeaders[] = "123";
ASSERT_NE(kOldSuccessSessionKey, kSessionKeyRequestHeaders);
@@ -712,7 +749,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest,
// Verifies that requests that were not proxied through data saver proxy due to
// missing config are recorded properly.
TEST_F(DataReductionProxyConfigServiceClientTest, HTTPRequests) {
- Init(false);
+ Init(false, false, std::string());
const struct {
std::string url;
bool enabled_by_user;
@@ -768,7 +805,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest, HTTPRequests) {
// Tests that remote config can be applied after the serialized config has been
// applied.
TEST_F(DataReductionProxyConfigServiceClientTest, ApplySerializedConfig) {
- Init(true);
+ Init(true, false, std::string());
AddMockSuccess();
SetDataReductionProxyEnabled(true);
@@ -786,7 +823,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest, ApplySerializedConfig) {
// retrieved successfully.
TEST_F(DataReductionProxyConfigServiceClientTest,
ApplySerializedConfigAfterReceipt) {
- Init(true);
+ Init(true, false, std::string());
AddMockSuccess();
SetDataReductionProxyEnabled(true);
@@ -807,7 +844,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest,
// Tests that a local serialized config can be applied successfully if remote
// config has not been fetched so far.
TEST_F(DataReductionProxyConfigServiceClientTest, ApplySerializedConfigLocal) {
- Init(true);
+ Init(true, false, std::string());
SetDataReductionProxyEnabled(true);
EXPECT_TRUE(configurator()->proxies_for_http().empty());
EXPECT_TRUE(request_options()->GetSecureSession().empty());
@@ -823,7 +860,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest, ApplySerializedConfigLocal) {
// Verifies the correctness of fetching config when Chromium is in background
// and foreground.
TEST_F(DataReductionProxyConfigServiceClientTest, FetchConfigOnForeground) {
- Init(true);
+ Init(true, false, std::string());
SetDataReductionProxyEnabled(true);
{

Powered by Google App Engine
This is Rietveld 408576698