Chromium Code Reviews| Index: net/nqe/network_quality_estimator_unittest.cc |
| diff --git a/net/nqe/network_quality_estimator_unittest.cc b/net/nqe/network_quality_estimator_unittest.cc |
| index 87de5f174485ae3b7c27a8ca8be57e374dd8a9de..06e45e7a9d59b2c66408ed88c82e271e1e7cfe06 100644 |
| --- a/net/nqe/network_quality_estimator_unittest.cc |
| +++ b/net/nqe/network_quality_estimator_unittest.cc |
| @@ -1728,4 +1728,101 @@ TEST(NetworkQualityEstimatorTest, NameConnectionTypeConversion) { |
| } |
| } |
| +// Tests that the correlation histogram is recorded correctly based on |
| +// correlation logging probability set in the variation params. |
| +TEST(NetworkQualityEstimatorTest, CorrelationHistogram) { |
| + // Match the values set in network_quality_estimator.cc. |
| + static const int32_t kTrimBits = 5; |
| + static const int32_t kBitsPerMetric = 7; |
| + |
| + const struct { |
| + double correlation_logging_probability; |
| + base::TimeDelta transport_rtt; |
| + int32_t expected_transport_rtt_milliseconds; |
| + base::TimeDelta http_rtt; |
| + int32_t expected_http_rtt_milliseconds; |
| + int32_t downstream_throughput_kbps; |
| + int32_t expected_downstream_throughput_kbps; |
| + |
| + } tests[] = { |
| + { |
| + // Verify that the metric is not recorded if the logging probability |
| + // is set to 0.0. |
| + 0.0, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, |
| + base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, |
| + 3000 >> kTrimBits, |
| + }, |
| + { |
| + 1.0, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, |
| + base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, |
| + 3000 >> kTrimBits, |
| + }, |
| + { |
| + // Verify that if the metric is larger 2^(kBitsPerMetric + kTrimBits), |
|
bengr
2016/07/08 16:49:52
larger -> larger than
tbansal1
2016/07/08 17:45:51
Done.
|
| + // it is rounded down to |
| + // (2^(kBitsPerMetric + kTrimBits) - 1) >> kTrimBits. |
| + 1.0, base::TimeDelta::FromSeconds(10), 4095 >> kTrimBits, |
|
bengr
2016/07/08 16:49:52
I guess there's no way to test a probability great
tbansal1
2016/07/08 17:45:51
Done. Moved random number to a different function,
|
| + base::TimeDelta::FromSeconds(20), 4095 >> kTrimBits, 30000, |
| + 4095 >> kTrimBits, |
| + }, |
| + }; |
| + |
| + for (const auto& test : tests) { |
| + base::HistogramTester histogram_tester; |
| + |
| + std::map<std::string, std::string> variation_params; |
| + variation_params["correlation_logging_probability"] = |
| + base::DoubleToString(test.correlation_logging_probability); |
| + TestNetworkQualityEstimator estimator(variation_params); |
| + |
| + estimator.set_transport_rtt(test.transport_rtt); |
| + estimator.set_recent_transport_rtt(test.transport_rtt); |
| + estimator.set_http_rtt(test.http_rtt); |
| + estimator.set_recent_http_rtt(test.http_rtt); |
| + estimator.set_downlink_throughput_kbps(test.downstream_throughput_kbps); |
| + |
| + TestDelegate test_delegate; |
| + TestURLRequestContext context(true); |
| + context.set_network_quality_estimator(&estimator); |
| + context.Init(); |
| + |
| + // Start a main-frame request which should cause network quality estimator |
|
bengr
2016/07/08 16:49:52
which -> that
tbansal1
2016/07/08 17:45:51
Done.
|
| + // to record the network quality at the last main frame request. |
| + std::unique_ptr<URLRequest> request_1(context.CreateRequest( |
| + estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| + request_1->SetLoadFlags(request_1->load_flags() | LOAD_MAIN_FRAME); |
| + request_1->Start(); |
| + base::RunLoop().Run(); |
| + histogram_tester.ExpectTotalCount("NQE.Correlation.ResourceLoadTime", 0); |
| + |
| + // Start another main-frame request which should cause network quality |
| + // estimator to record the correlation UMA. |
| + std::unique_ptr<URLRequest> request_2(context.CreateRequest( |
| + estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| + request_2->Start(); |
| + base::RunLoop().Run(); |
| + |
| + if (test.correlation_logging_probability == 0.0) { |
| + histogram_tester.ExpectTotalCount("NQE.Correlation.ResourceLoadTime", 0); |
| + continue; |
| + } |
| + histogram_tester.ExpectTotalCount("NQE.Correlation.ResourceLoadTime", 1); |
| + std::vector<base::Bucket> buckets = |
| + histogram_tester.GetAllSamples("NQE.Correlation.ResourceLoadTime"); |
| + // Get the bits at index 0-10 which contain the transport RTT. |
| + // 128 is 2^kBitsPerMetric. |
| + EXPECT_EQ(test.expected_transport_rtt_milliseconds, |
| + buckets.at(0).min >> kBitsPerMetric >> kBitsPerMetric >> |
| + kBitsPerMetric); |
| + // Get the bits at index 11-17 which contain the HTTP RTT. |
| + EXPECT_EQ(test.expected_http_rtt_milliseconds, |
| + (buckets.at(0).min >> kBitsPerMetric >> kBitsPerMetric) % 128); |
| + // Get the bits at index 18-24 which contain the downstream throughput. |
| + EXPECT_EQ(test.expected_downstream_throughput_kbps, |
| + (buckets.at(0).min >> kBitsPerMetric) % 128); |
| + // Get the bits at index 25-31 which contain the resource fetch time. |
| + EXPECT_LE(0, buckets.at(0).min % 128); |
| + } |
| +} |
| + |
| } // namespace net |