| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
|
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
|
| index 2d067d5a3943d847246090858a386b2f8a54c28d..48b1a0a8ed8fef570341a697cbd07a8e22bd6fdb 100644
|
| --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
|
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
|
| @@ -14,11 +14,14 @@
|
| #include "base/command_line.h"
|
| #include "base/macros.h"
|
| #include "base/memory/ptr_util.h"
|
| +#include "base/memory/ref_counted.h"
|
| #include "base/metrics/field_trial.h"
|
| #include "base/strings/safe_sprintf.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/test/histogram_tester.h"
|
| +#include "base/test/simple_test_tick_clock.h"
|
| +#include "base/threading/platform_thread.h"
|
| #include "base/time/time.h"
|
| #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_test_utils.h"
|
| @@ -30,6 +33,7 @@
|
| #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
|
| #include "components/variations/variations_associated_data.h"
|
| #include "net/base/external_estimate_provider.h"
|
| +#include "net/base/load_flags.h"
|
| #include "net/base/network_quality_estimator.h"
|
| #include "net/http/http_status_code.h"
|
| #include "net/log/test_net_log.h"
|
| @@ -82,6 +86,10 @@ class DataReductionProxyConfigTest : public testing::Test {
|
| config()->ResetParamFlagsForTest(flags);
|
| }
|
|
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner() {
|
| + return message_loop_.task_runner();
|
| + }
|
| +
|
| void ExpectSecureProxyCheckResult(SecureProxyCheckFetchResult result) {
|
| EXPECT_CALL(*config(), RecordSecureProxyCheckFetchResult(result)).Times(1);
|
| }
|
| @@ -129,7 +137,7 @@ class DataReductionProxyConfigTest : public testing::Test {
|
| std::unique_ptr<DataReductionProxyParams> params) {
|
| params->EnableQuic(false);
|
| return base::WrapUnique(new DataReductionProxyConfig(
|
| - test_context_->net_log(), std::move(params),
|
| + task_runner(), test_context_->net_log(), std::move(params),
|
| test_context_->configurator(), test_context_->event_creator()));
|
| }
|
|
|
| @@ -536,8 +544,9 @@ TEST_F(DataReductionProxyConfigTest, IsDataReductionProxyWithParams) {
|
| new TestDataReductionProxyParams(flags, has_definitions));
|
| DataReductionProxyTypeInfo proxy_type_info;
|
| std::unique_ptr<DataReductionProxyConfig> config(
|
| - new DataReductionProxyConfig(net_log(), std::move(params),
|
| - configurator(), event_creator()));
|
| + new DataReductionProxyConfig(task_runner(), net_log(),
|
| + std::move(params), configurator(),
|
| + event_creator()));
|
| EXPECT_EQ(
|
| tests[i].expected_result,
|
| config->IsDataReductionProxy(tests[i].host_port_pair, &proxy_type_info))
|
| @@ -633,7 +642,8 @@ TEST_F(DataReductionProxyConfigTest, IsDataReductionProxyWithMutableConfig) {
|
| DataReductionProxyMutableConfigValues::CreateFromParams(params());
|
| config_values->UpdateValues(proxies_for_http);
|
| std::unique_ptr<DataReductionProxyConfig> config(new DataReductionProxyConfig(
|
| - net_log(), std::move(config_values), configurator(), event_creator()));
|
| + task_runner(), net_log(), std::move(config_values), configurator(),
|
| + event_creator()));
|
| for (size_t i = 0; i < arraysize(tests); ++i) {
|
| DataReductionProxyTypeInfo proxy_type_info;
|
| EXPECT_EQ(tests[i].expected_result,
|
| @@ -761,6 +771,7 @@ TEST_F(DataReductionProxyConfigTest, LoFiOn) {
|
| net::TestDelegate delegate_;
|
| std::unique_ptr<net::URLRequest> request =
|
| context_.CreateRequest(GURL(), net::IDLE, &delegate_);
|
| + request->SetLoadFlags(request->load_flags() | net::LOAD_MAIN_FRAME);
|
| bool should_enable_lofi = config()->ShouldEnableLoFiMode(*request.get());
|
| if (tests[i].expect_bucket_count != 0) {
|
| histogram_tester.ExpectBucketCount(
|
| @@ -829,8 +840,8 @@ class TestNetworkQualityEstimator : public net::NetworkQualityEstimator {
|
| };
|
|
|
| TEST_F(DataReductionProxyConfigTest, AutoLoFiParams) {
|
| - DataReductionProxyConfig config(nullptr, nullptr, configurator(),
|
| - event_creator());
|
| + DataReductionProxyConfig config(task_runner(), nullptr, nullptr,
|
| + configurator(), event_creator());
|
| variations::testing::ClearAllVariationParams();
|
| std::map<std::string, std::string> variation_params;
|
| std::map<std::string, std::string> variation_params_flag;
|
| @@ -934,8 +945,8 @@ TEST_F(DataReductionProxyConfigTest, AutoLoFiParams) {
|
| }
|
|
|
| TEST_F(DataReductionProxyConfigTest, AutoLoFiParamsSlowConnectionsFlag) {
|
| - DataReductionProxyConfig config(nullptr, nullptr, configurator(),
|
| - event_creator());
|
| + DataReductionProxyConfig config(task_runner(), nullptr, nullptr,
|
| + configurator(), event_creator());
|
| variations::testing::ClearAllVariationParams();
|
|
|
| base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| @@ -989,12 +1000,116 @@ TEST_F(DataReductionProxyConfigTest, AutoLoFiParamsSlowConnectionsFlag) {
|
| &test_network_quality_estimator));
|
| }
|
|
|
| -// Tests if metrics for LoFi accuracy are recorded properly.
|
| -TEST_F(DataReductionProxyConfigTest, AutoLoFiAccuracy) {
|
| - base::HistogramTester histogram_tester;
|
| +// Tests if metrics for Lo-Fi accuracy are recorded properly.
|
| +TEST_F(DataReductionProxyConfigTest, LoFiAccuracy) {
|
| + scoped_ptr<base::SimpleTestTickClock> tick_clock(
|
| + new base::SimpleTestTickClock());
|
| +
|
| + std::vector<base::TimeDelta> lofi_accuracy_recording_intervals;
|
| + lofi_accuracy_recording_intervals.push_back(base::TimeDelta::FromSeconds(0));
|
| +
|
| + TestDataReductionProxyConfig config(
|
| + DataReductionProxyParams::kAllowed |
|
| + DataReductionProxyParams::kFallbackAllowed,
|
| + TestDataReductionProxyParams::HAS_EVERYTHING, task_runner(), nullptr,
|
| + configurator(), event_creator());
|
| + config.SetLofiAccuracyRecordingIntervals(lofi_accuracy_recording_intervals);
|
| + config.SetTickClock(tick_clock.get());
|
| +
|
| + variations::testing::ClearAllVariationParams();
|
| + std::map<std::string, std::string> variation_params;
|
| +
|
| + int expected_rtt_msec = 120;
|
| + int expected_hysteresis_sec = 360;
|
| +
|
| + variation_params["rtt_msec"] = base::IntToString(expected_rtt_msec);
|
| + variation_params["hysteresis_period_seconds"] =
|
| + base::IntToString(expected_hysteresis_sec);
|
| +
|
| + const struct {
|
| + std::string description;
|
| + std::string field_trial_group;
|
| + base::TimeDelta rtt;
|
| + base::TimeDelta recent_rtt;
|
| + bool expect_network_quality_slow;
|
| + uint32_t bucket_to_check;
|
| + uint32_t expected_bucket_count;
|
| + } tests[] = {
|
| + {"Predicted slow, actually slow, Enabled group", "Enabled",
|
| + base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1),
|
| + base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1), true, 0, 1},
|
| + {"Predicted slow, actually slow, Enabled_NoControl group",
|
| + "Enabled_NoControl",
|
| + base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1),
|
| + base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1), true, 0, 1},
|
| + {"Predicted slow, actually slow, Control group", "Control",
|
| + base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1),
|
| + base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1), true, 0, 1},
|
| + {"Predicted slow, actually not slow", "Enabled",
|
| + base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1),
|
| + base::TimeDelta::FromMilliseconds(expected_rtt_msec - 1), true, 1, 1},
|
| + {"Predicted not slow, actually slow", "Enabled",
|
| + base::TimeDelta::FromMilliseconds(expected_rtt_msec - 1),
|
| + base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1), false, 2, 1},
|
| + {"Predicted not slow, actually not slow", "Enabled",
|
| + base::TimeDelta::FromMilliseconds(expected_rtt_msec - 1),
|
| + base::TimeDelta::FromMilliseconds(expected_rtt_msec - 1), false, 3, 1},
|
| + };
|
| +
|
| + for (const auto& test : tests) {
|
| + base::FieldTrialList field_trial_list(nullptr);
|
| + variations::testing::ClearAllVariationIDs();
|
| + variations::testing::ClearAllVariationParams();
|
| + ASSERT_TRUE(variations::AssociateVariationParams(
|
| + params::GetLoFiFieldTrialName(), test.field_trial_group,
|
| + variation_params))
|
| + << test.description;
|
| +
|
| + ASSERT_NE(nullptr,
|
| + base::FieldTrialList::CreateFieldTrial(
|
| + params::GetLoFiFieldTrialName(), test.field_trial_group))
|
| + << test.description;
|
| + config.PopulateAutoLoFiParams();
|
| +
|
| + std::map<std::string, std::string> network_quality_estimator_params;
|
| + TestNetworkQualityEstimator test_network_quality_estimator(
|
| + network_quality_estimator_params);
|
| +
|
| + base::HistogramTester histogram_tester;
|
| + // RTT is higher than threshold. Network is slow.
|
| + // Network was predicted to be slow and actually was slow.
|
| + test_network_quality_estimator.SetRTT(test.rtt);
|
| + test_network_quality_estimator.SetMedianRTTSince(test.recent_rtt);
|
| + ASSERT_EQ(test.expect_network_quality_slow,
|
| + config.IsNetworkQualityProhibitivelySlow(
|
| + &test_network_quality_estimator))
|
| + << test.description;
|
| + RunUntilIdle();
|
| + histogram_tester.ExpectTotalCount(
|
| + "DataReductionProxy.LoFi.Accuracy.0.Unknown", 1);
|
| + histogram_tester.ExpectBucketCount(
|
| + "DataReductionProxy.LoFi.Accuracy.0.Unknown", test.bucket_to_check,
|
| + test.expected_bucket_count);
|
| + }
|
| +}
|
| +
|
| +// Tests if metrics for Lo-Fi accuracy are recorded properly at the specified
|
| +// interval.
|
| +TEST_F(DataReductionProxyConfigTest, LoFiAccuracyNonZeroDelay) {
|
| + scoped_ptr<base::SimpleTestTickClock> tick_clock(
|
| + new base::SimpleTestTickClock());
|
| +
|
| + std::vector<base::TimeDelta> lofi_accuracy_recording_intervals;
|
| + lofi_accuracy_recording_intervals.push_back(base::TimeDelta::FromSeconds(1));
|
| +
|
| + TestDataReductionProxyConfig config(
|
| + DataReductionProxyParams::kAllowed |
|
| + DataReductionProxyParams::kFallbackAllowed,
|
| + TestDataReductionProxyParams::HAS_EVERYTHING, task_runner(), nullptr,
|
| + configurator(), event_creator());
|
| + config.SetLofiAccuracyRecordingIntervals(lofi_accuracy_recording_intervals);
|
| + config.SetTickClock(tick_clock.get());
|
|
|
| - DataReductionProxyConfig config(nullptr, nullptr, configurator(),
|
| - event_creator());
|
| variations::testing::ClearAllVariationParams();
|
| std::map<std::string, std::string> variation_params;
|
|
|
| @@ -1017,56 +1132,24 @@ TEST_F(DataReductionProxyConfigTest, AutoLoFiAccuracy) {
|
| TestNetworkQualityEstimator test_network_quality_estimator(
|
| network_quality_estimator_params);
|
|
|
| + base::HistogramTester histogram_tester;
|
| // RTT is higher than threshold. Network is slow.
|
| // Network was predicted to be slow and actually was slow.
|
| test_network_quality_estimator.SetRTT(
|
| base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1));
|
| test_network_quality_estimator.SetMedianRTTSince(
|
| base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1));
|
| - EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow(
|
| - &test_network_quality_estimator));
|
| - config.RecordAutoLoFiAccuracyRate(&test_network_quality_estimator);
|
| - histogram_tester.ExpectBucketCount(
|
| - "DataReductionProxy.AutoLoFiAccuracy.Unknown", 0, 1);
|
| -
|
| - // Network was predicted to be slow but actually was not slow.
|
| - test_network_quality_estimator.SetMedianRTTSince(
|
| - base::TimeDelta::FromMilliseconds(expected_rtt_msec - 1));
|
| - EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow(
|
| - &test_network_quality_estimator));
|
| - config.RecordAutoLoFiAccuracyRate(&test_network_quality_estimator);
|
| - histogram_tester.ExpectBucketCount(
|
| - "DataReductionProxy.AutoLoFiAccuracy.Unknown", 1, 1);
|
| -
|
| - config.network_quality_last_checked_ =
|
| - base::TimeTicks::Now() -
|
| - base::TimeDelta::FromSeconds(expected_hysteresis_sec + 1);
|
| -
|
| - // Network was predicted to be not slow but actually was slow.
|
| - test_network_quality_estimator.SetRTT(
|
| - base::TimeDelta::FromMilliseconds(expected_rtt_msec - 1));
|
| - test_network_quality_estimator.SetMedianRTTSince(
|
| - base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1));
|
| - EXPECT_FALSE(config.IsNetworkQualityProhibitivelySlow(
|
| + ASSERT_TRUE(config.IsNetworkQualityProhibitivelySlow(
|
| &test_network_quality_estimator));
|
| - config.RecordAutoLoFiAccuracyRate(&test_network_quality_estimator);
|
| - histogram_tester.ExpectBucketCount(
|
| - "DataReductionProxy.AutoLoFiAccuracy.Unknown", 2, 1);
|
| + tick_clock->Advance(base::TimeDelta::FromSeconds(1));
|
|
|
| - // Network was predicted to be not slow but actually was not slow.
|
| - test_network_quality_estimator.SetMedianRTTSince(
|
| - base::TimeDelta::FromMilliseconds(expected_rtt_msec - 1));
|
| - EXPECT_FALSE(config.IsNetworkQualityProhibitivelySlow(
|
| - &test_network_quality_estimator));
|
| - config.RecordAutoLoFiAccuracyRate(&test_network_quality_estimator);
|
| + // Sleep to ensure that the delayed task is posted.
|
| + base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
|
| + RunUntilIdle();
|
| + histogram_tester.ExpectTotalCount(
|
| + "DataReductionProxy.LoFi.Accuracy.1.Unknown", 1);
|
| histogram_tester.ExpectBucketCount(
|
| - "DataReductionProxy.AutoLoFiAccuracy.Unknown", 3, 1);
|
| -
|
| - // Make sure that all buckets contain exactly one value.
|
| - for (size_t bucket = 0; bucket < 4; ++bucket) {
|
| - histogram_tester.ExpectBucketCount(
|
| - "DataReductionProxy.AutoLoFiAccuracy.Unknown", bucket, 1);
|
| - }
|
| + "DataReductionProxy.LoFi.Accuracy.1.Unknown", 0, 1);
|
| }
|
|
|
| } // namespace data_reduction_proxy
|
|
|