| 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 2f2060046ff9cd618ccb51dc0b0fdd6a2fa8185a..9724e89bf71d65f6752e491107e69e19a4e28ee5 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
|
| @@ -76,26 +76,34 @@ namespace {
|
|
|
| // Creates a new ClientConfig from the given parameters.
|
| ClientConfig CreateConfig(const std::string& session_key,
|
| int64_t expire_duration_seconds,
|
| int64_t expire_duration_nanoseconds,
|
| ProxyServer_ProxyScheme primary_scheme,
|
| const std::string& primary_host,
|
| int primary_port,
|
| ProxyServer_ProxyScheme secondary_scheme,
|
| const std::string& secondary_host,
|
| - int secondary_port) {
|
| + int secondary_port,
|
| + float reporting_fraction) {
|
| ClientConfig config;
|
|
|
| config.set_session_key(session_key);
|
| config.mutable_refresh_duration()->set_seconds(expire_duration_seconds);
|
| config.mutable_refresh_duration()->set_nanos(expire_duration_nanoseconds);
|
| +
|
| + // Leave the pageload_metrics_config empty when |reporting_fraction| is not
|
| + // inclusively between zero and one.
|
| + if (reporting_fraction >= 0.0f && reporting_fraction <= 1.0f) {
|
| + config.mutable_pageload_metrics_config()->set_reporting_fraction(
|
| + reporting_fraction);
|
| + }
|
| ProxyServer* primary_proxy =
|
| config.mutable_proxy_config()->add_http_proxy_servers();
|
| primary_proxy->set_scheme(primary_scheme);
|
| primary_proxy->set_host(primary_host);
|
| primary_proxy->set_port(primary_port);
|
| 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);
|
| @@ -158,36 +166,67 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
|
| test_context_->test_config_client()->SetNow(base::Time::UnixEpoch());
|
| test_context_->test_config_client()->SetEnabled(true);
|
| test_context_->test_config_client()->SetConfigServiceURL(
|
| GURL("http://configservice.com"));
|
|
|
| ASSERT_NE(nullptr, context_->network_delegate());
|
| // Set up the various test ClientConfigs.
|
| ClientConfig config =
|
| CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
|
| ProxyServer_ProxyScheme_HTTPS, "origin.net", 443,
|
| - ProxyServer_ProxyScheme_HTTP, "fallback.net", 80);
|
| + ProxyServer_ProxyScheme_HTTP, "fallback.net", 80, 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);
|
| + ClientConfig previous_config = CreateConfig(
|
| + kOldSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
|
| + ProxyServer_ProxyScheme_HTTPS, "old.origin.net", 443,
|
| + ProxyServer_ProxyScheme_HTTP, "old.fallback.net", 80, 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);
|
| + ProxyServer_ProxyScheme_HTTP, "persisted.net", 80, 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);
|
| + 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);
|
| + one_reporting_fraction_encoded_config_ =
|
| + EncodeConfig(one_reporting_fraction_config);
|
| +
|
| + // Passing in -1.0f as the reporting fraction causes the
|
| + // |empty_reporting_fraction_config| to have no pageload_metrics_config()
|
| + // set.
|
| + ClientConfig empty_reporting_fraction_config =
|
| + CreateConfig(kSuccessSessionKey, kConfigRefreshDurationSeconds, 0,
|
| + ProxyServer_ProxyScheme_HTTPS, "origin.net", 443,
|
| + ProxyServer_ProxyScheme_HTTP, "origin.net", 0, -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);
|
| + half_reporting_fraction_encoded_config_ =
|
| + EncodeConfig(half_reporting_fraction_config);
|
| +
|
| success_reads_[0] = net::MockRead("HTTP/1.1 200 OK\r\n\r\n");
|
| success_reads_[1] =
|
| net::MockRead(net::ASYNC, config_.c_str(), config_.length());
|
| success_reads_[2] = net::MockRead(net::SYNCHRONOUS, net::OK);
|
|
|
| previous_success_reads_[0] = net::MockRead("HTTP/1.1 200 OK\r\n\r\n");
|
| previous_success_reads_[1] = net::MockRead(
|
| net::ASYNC, previous_config_.c_str(), previous_config_.length());
|
| previous_success_reads_[2] = net::MockRead(net::SYNCHRONOUS, net::OK);
|
|
|
| @@ -210,20 +249,21 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
|
| kSuccessOrigin, net::ProxyServer::SCHEME_HTTP));
|
| }
|
| expected_http_proxies.push_back(net::ProxyServer::FromURI(
|
| kSuccessFallback, net::ProxyServer::SCHEME_HTTP));
|
| EXPECT_EQ(base::TimeDelta::FromSeconds(kConfigRefreshDurationSeconds),
|
| config_client()->GetDelay());
|
| EXPECT_EQ(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());
|
| }
|
|
|
| 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));
|
| EXPECT_EQ(base::TimeDelta::FromSeconds(kConfigRefreshDurationSeconds),
|
| config_client()->GetDelay());
|
| @@ -254,20 +294,24 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
|
| TestDataReductionProxyConfig* config() { return test_context_->config(); }
|
|
|
| MockDataReductionProxyRequestOptions* request_options() {
|
| return test_context_->mock_request_options();
|
| }
|
|
|
| std::vector<net::ProxyServer> GetConfiguredProxiesForHttp() const {
|
| return test_context_->GetConfiguredProxiesForHttp();
|
| }
|
|
|
| + float pingback_reporting_fraction() const {
|
| + return test_context_->io_data()->pingback_reporting_fraction();
|
| + }
|
| +
|
| void RunUntilIdle() {
|
| test_context_->RunUntilIdle();
|
| }
|
|
|
| void AddMockSuccess() {
|
| socket_data_providers_.push_back(
|
| (base::WrapUnique(new net::StaticSocketDataProvider(
|
| success_reads_, arraysize(success_reads_), nullptr, 0))));
|
| mock_socket_factory_->AddSocketDataProvider(
|
| socket_data_providers_.back().get());
|
| @@ -295,20 +339,32 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
|
| prefs::kDataReductionProxyConfig);
|
| }
|
|
|
| const std::string& success_response() const { return config_; }
|
|
|
| const std::string& encoded_config() const { return encoded_config_; }
|
|
|
| const std::string& previous_success_response() const {
|
| return previous_config_;
|
| }
|
| + const std::string& empty_reporting_fraction_encoded_config() const {
|
| + return empty_reporting_fraction_encoded_config_;
|
| + }
|
| + const std::string& one_reporting_fraction_encoded_config() const {
|
| + return one_reporting_fraction_encoded_config_;
|
| + }
|
| + const std::string& zero_reporting_fraction_encoded_config() const {
|
| + return zero_reporting_fraction_encoded_config_;
|
| + }
|
| + const std::string& half_reporting_fraction_encoded_config() const {
|
| + return half_reporting_fraction_encoded_config_;
|
| + }
|
|
|
| bool IsTrustedSpdyProxy(const net::ProxyServer& proxy_server) const {
|
| return delegate_->IsTrustedSpdyProxy(proxy_server);
|
| }
|
|
|
| const std::string& loaded_config() const { return loaded_config_; }
|
|
|
| net::TestURLRequestContext* test_url_request_context() const {
|
| return context_.get();
|
| }
|
| @@ -372,20 +428,32 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
|
| // also stored.
|
| std::string config_;
|
| std::string encoded_config_;
|
|
|
| // A configuration from a previous remote request.
|
| std::string previous_config_;
|
|
|
| // An encoded config that represents a previously saved configuration.
|
| std::string loaded_config_;
|
|
|
| + // A configuration where the pingback reporting fraction is not set.
|
| + std::string empty_reporting_fraction_encoded_config_;
|
| +
|
| + // A configuration where the pingback reporting fraction is set to 1.0f.
|
| + std::string one_reporting_fraction_encoded_config_;
|
| +
|
| + // A configuration where the pingback reporting fraction is set to 0.0f.
|
| + std::string zero_reporting_fraction_encoded_config_;
|
| +
|
| + // A configuration where the pingback reporting fraction is set to 0.5f.
|
| + std::string half_reporting_fraction_encoded_config_;
|
| +
|
| // Mock socket data.
|
| std::vector<std::unique_ptr<net::SocketDataProvider>> socket_data_providers_;
|
|
|
| // Mock socket reads.
|
| net::MockRead success_reads_[3];
|
| net::MockRead previous_success_reads_[3];
|
| net::MockRead not_found_reads_[2];
|
|
|
| std::unique_ptr<net::URLRequestContextStorage> context_storage_;
|
|
|
| @@ -964,20 +1032,64 @@ TEST_F(DataReductionProxyConfigServiceClientTest, ApplySerializedConfigLocal) {
|
| EXPECT_EQ(std::vector<net::ProxyServer>(
|
| {net::ProxyServer::FromURI(kSuccessOrigin,
|
| net::ProxyServer::SCHEME_HTTP),
|
| net::ProxyServer::FromURI(kSuccessFallback,
|
| net::ProxyServer::SCHEME_HTTP)}),
|
| GetConfiguredProxiesForHttp());
|
| EXPECT_TRUE(persisted_config().empty());
|
| EXPECT_FALSE(request_options()->GetSecureSession().empty());
|
| }
|
|
|
| +// Verifies that setting a client config sets the pingback reporting fraction
|
| +// correctly to 0.0f.
|
| +TEST_F(DataReductionProxyConfigServiceClientTest,
|
| + ApplySerializedConfigZeroReportingFraction) {
|
| + Init(true, false, std::string());
|
| + // ApplySerializedConfig should apply the encoded config.
|
| + config_client()->ApplySerializedConfig(
|
| + zero_reporting_fraction_encoded_config());
|
| + EXPECT_EQ(0.0f, pingback_reporting_fraction());
|
| +}
|
| +
|
| +// Verifies that setting a client config sets the pingback reporting fraction
|
| +// correctly to 0.0f when the pingback is not set in the protobuf.
|
| +TEST_F(DataReductionProxyConfigServiceClientTest,
|
| + ApplySerializedConfigEmptyReportingFraction) {
|
| + Init(true, false, std::string());
|
| + // ApplySerializedConfig should apply the encoded config.
|
| + config_client()->ApplySerializedConfig(
|
| + empty_reporting_fraction_encoded_config());
|
| + EXPECT_EQ(0.0f, pingback_reporting_fraction());
|
| +}
|
| +
|
| +// Verifies that setting a client config sets the pingback reporting fraction
|
| +// correctly to 1.0f.
|
| +TEST_F(DataReductionProxyConfigServiceClientTest,
|
| + ApplySerializedConfigOneReportingFraction) {
|
| + Init(true, false, std::string());
|
| + // ApplySerializedConfig should apply the encoded config.
|
| + config_client()->ApplySerializedConfig(
|
| + one_reporting_fraction_encoded_config());
|
| + EXPECT_EQ(1.0f, pingback_reporting_fraction());
|
| +}
|
| +
|
| +// Verifies that setting a client config sets the pingback reporting fraction
|
| +// correctly to 0.5f.
|
| +TEST_F(DataReductionProxyConfigServiceClientTest,
|
| + ApplySerializedConfigHalfReportingFraction) {
|
| + Init(true, false, std::string());
|
| + // ApplySerializedConfig should apply the encoded config.
|
| + config_client()->ApplySerializedConfig(
|
| + half_reporting_fraction_encoded_config());
|
| + EXPECT_EQ(0.5f, pingback_reporting_fraction());
|
| +}
|
| +
|
| #if defined(OS_ANDROID)
|
| // Verifies the correctness of fetching config when Chromium is in background
|
| // and foreground.
|
| TEST_F(DataReductionProxyConfigServiceClientTest, FetchConfigOnForeground) {
|
| Init(true, false, std::string());
|
| SetDataReductionProxyEnabled(true, true);
|
|
|
| {
|
| // Tests that successful config fetches while Chromium is in background,
|
| // does not trigger refetches when Chromium comes to foreground.
|
|
|