| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate_unittest.cc
|
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate_unittest.cc
|
| index 6d99189e360f59a2c832395d52c8b5a6cdaf2827..808943d6e8074a66d718d36a292bdc2139e8da4d 100644
|
| --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate_unittest.cc
|
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate_unittest.cc
|
| @@ -34,6 +34,7 @@
|
| #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_switches.h"
|
| +#include "components/variations/variations_associated_data.h"
|
| #include "net/base/host_port_pair.h"
|
| #include "net/base/net_errors.h"
|
| #include "net/base/proxy_delegate.h"
|
| @@ -124,9 +125,49 @@ class TestDataReductionProxyDelegate : public DataReductionProxyDelegate {
|
| }
|
| }
|
|
|
| + void VerifyGetDefaultAlternativeProxyHistogram(
|
| + const base::HistogramTester& histogram_tester,
|
| + bool is_in_quic_field_trial,
|
| + bool use_proxyzip_proxy_as_first_proxy,
|
| + bool alternative_proxy_broken) {
|
| + static const char kHistogram[] =
|
| + "DataReductionProxy.Quic.DefaultAlternativeProxy";
|
| + if (is_in_quic_field_trial && use_proxyzip_proxy_as_first_proxy &&
|
| + !alternative_proxy_broken) {
|
| + histogram_tester.ExpectUniqueSample(
|
| + kHistogram,
|
| + TestDataReductionProxyDelegate::DefaultAlternativeProxyStatus::
|
| + DEFAULT_ALTERNATIVE_PROXY_STATUS_AVAILABLE,
|
| + 1);
|
| + return;
|
| + }
|
| +
|
| + if (is_in_quic_field_trial && alternative_proxy_broken) {
|
| + histogram_tester.ExpectUniqueSample(
|
| + kHistogram,
|
| + TestDataReductionProxyDelegate::DefaultAlternativeProxyStatus::
|
| + DEFAULT_ALTERNATIVE_PROXY_STATUS_BROKEN,
|
| + 1);
|
| + return;
|
| + }
|
| +
|
| + if (is_in_quic_field_trial && !use_proxyzip_proxy_as_first_proxy) {
|
| + histogram_tester.ExpectUniqueSample(
|
| + kHistogram,
|
| + TestDataReductionProxyDelegate::DefaultAlternativeProxyStatus::
|
| + DEFAULT_ALTERNATIVE_PROXY_STATUS_UNAVAILABLE,
|
| + 1);
|
| + return;
|
| + }
|
| +
|
| + histogram_tester.ExpectTotalCount(kHistogram, 0);
|
| + }
|
| +
|
| using DataReductionProxyDelegate::GetAlternativeProxy;
|
| using DataReductionProxyDelegate::OnAlternativeProxyBroken;
|
| + using DataReductionProxyDelegate::GetDefaultAlternativeProxy;
|
| using DataReductionProxyDelegate::QuicProxyStatus;
|
| + using DataReductionProxyDelegate::DefaultAlternativeProxyStatus;
|
|
|
| private:
|
| const bool proxy_supports_quic_;
|
| @@ -422,6 +463,107 @@ TEST(DataReductionProxyDelegate, AlternativeProxy) {
|
| }
|
| }
|
|
|
| +// Verifies that DataReductionProxyDelegate correctly returns the proxy server
|
| +// that supports 0-RTT.
|
| +TEST(DataReductionProxyDelegate, DefaultAlternativeProxyStatus) {
|
| + base::MessageLoopForIO message_loop_;
|
| + std::unique_ptr<DataReductionProxyTestContext> test_context =
|
| + DataReductionProxyTestContext::Builder()
|
| + .WithConfigClient()
|
| + .WithMockDataReductionProxyService()
|
| + .Build();
|
| +
|
| + const struct {
|
| + bool is_in_quic_field_trial;
|
| + bool zero_rtt_param_set;
|
| + bool use_proxyzip_proxy_as_first_proxy;
|
| + } tests[] = {{false, false, false},
|
| + {false, false, true},
|
| + {true, false, false},
|
| + {true, false, true},
|
| + {true, true, true}};
|
| + for (const auto test : tests) {
|
| + std::vector<net::ProxyServer> proxies_for_http;
|
| + net::ProxyServer first_proxy;
|
| + net::ProxyServer second_proxy =
|
| + GetProxyWithScheme(net::ProxyServer::SCHEME_HTTP);
|
| +
|
| + if (test.use_proxyzip_proxy_as_first_proxy) {
|
| + first_proxy =
|
| + net::ProxyServer(net::ProxyServer::SCHEME_QUIC,
|
| + net::HostPortPair("proxy.googlezip.net", 443));
|
| + } else {
|
| + first_proxy = GetProxyWithScheme(net::ProxyServer::SCHEME_HTTPS);
|
| + }
|
| +
|
| + proxies_for_http.push_back(first_proxy);
|
| + proxies_for_http.push_back(second_proxy);
|
| +
|
| + std::unique_ptr<DataReductionProxyMutableConfigValues> config_values =
|
| + DataReductionProxyMutableConfigValues::CreateFromParams(
|
| + test_context->test_params());
|
| + config_values->UpdateValues(proxies_for_http);
|
| +
|
| + std::unique_ptr<DataReductionProxyConfig> config(
|
| + new DataReductionProxyConfig(
|
| + message_loop_.task_runner(), test_context->net_log(),
|
| + std::move(config_values), test_context->configurator(),
|
| + test_context->event_creator()));
|
| +
|
| + TestDataReductionProxyDelegate delegate(
|
| + config.get(), test_context->io_data()->configurator(),
|
| + test_context->io_data()->event_creator(),
|
| + test_context->io_data()->bypass_stats(), true,
|
| + test_context->io_data()->net_log());
|
| +
|
| + variations::testing::ClearAllVariationParams();
|
| + std::map<std::string, std::string> variation_params;
|
| + if (test.zero_rtt_param_set)
|
| + variation_params["enable_zero_rtt"] = "true";
|
| + ASSERT_TRUE(variations::AssociateVariationParams(
|
| + params::GetQuicFieldTrialName(),
|
| + test.is_in_quic_field_trial ? "Enabled" : "Control", variation_params));
|
| + base::FieldTrialList field_trial_list(nullptr);
|
| + base::FieldTrialList::CreateFieldTrial(
|
| + params::GetQuicFieldTrialName(),
|
| + test.is_in_quic_field_trial ? "Enabled" : "Control");
|
| +
|
| + {
|
| + // Test if the QUIC supporting proxy is correctly set.
|
| + base::HistogramTester histogram_tester;
|
| + if (test.is_in_quic_field_trial && test.zero_rtt_param_set &&
|
| + test.use_proxyzip_proxy_as_first_proxy) {
|
| + EXPECT_EQ(delegate.GetDefaultAlternativeProxy(), first_proxy);
|
| + EXPECT_TRUE(first_proxy.is_quic());
|
| +
|
| + } else {
|
| + EXPECT_FALSE(delegate.GetDefaultAlternativeProxy().is_valid());
|
| + }
|
| +
|
| + delegate.VerifyGetDefaultAlternativeProxyHistogram(
|
| + histogram_tester,
|
| + test.is_in_quic_field_trial && test.zero_rtt_param_set,
|
| + test.use_proxyzip_proxy_as_first_proxy, false);
|
| + }
|
| +
|
| + {
|
| + // Test if the QUIC supporting proxy is correctly set if the proxy is
|
| + // marked as broken.
|
| + base::HistogramTester histogram_tester;
|
| +
|
| + if (test.is_in_quic_field_trial && test.zero_rtt_param_set &&
|
| + test.use_proxyzip_proxy_as_first_proxy) {
|
| + delegate.OnAlternativeProxyBroken(first_proxy);
|
| + EXPECT_FALSE(delegate.GetDefaultAlternativeProxy().is_quic());
|
| + delegate.VerifyGetDefaultAlternativeProxyHistogram(
|
| + histogram_tester,
|
| + test.is_in_quic_field_trial && test.zero_rtt_param_set,
|
| + test.use_proxyzip_proxy_as_first_proxy, true);
|
| + }
|
| + }
|
| + }
|
| +}
|
| +
|
| #if defined(OS_ANDROID)
|
| const Client kClient = Client::CHROME_ANDROID;
|
| #elif defined(OS_IOS)
|
|
|