OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/nqe/network_quality_estimator.h" | 5 #include "net/nqe/network_quality_estimator.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1721 std::string connection_type_name = | 1721 std::string connection_type_name = |
1722 std::string(NetworkQualityEstimator::GetNameForEffectiveConnectionType( | 1722 std::string(NetworkQualityEstimator::GetNameForEffectiveConnectionType( |
1723 effective_connection_type)); | 1723 effective_connection_type)); |
1724 EXPECT_FALSE(connection_type_name.empty()); | 1724 EXPECT_FALSE(connection_type_name.empty()); |
1725 EXPECT_EQ(effective_connection_type, | 1725 EXPECT_EQ(effective_connection_type, |
1726 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( | 1726 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( |
1727 connection_type_name)); | 1727 connection_type_name)); |
1728 } | 1728 } |
1729 } | 1729 } |
1730 | 1730 |
1731 // Tests that the correlation histogram is recorded correctly based on | |
1732 // correlation logging probability set in the variation params. | |
1733 TEST(NetworkQualityEstimatorTest, CorrelationHistogram) { | |
1734 // Match the values set in network_quality_estimator.cc. | |
1735 static const int32_t kTrimBits = 5; | |
1736 static const int32_t kBitsPerMetric = 7; | |
1737 | |
1738 const struct { | |
1739 double correlation_logging_probability; | |
1740 base::TimeDelta transport_rtt; | |
1741 int32_t expected_transport_rtt_milliseconds; | |
1742 base::TimeDelta http_rtt; | |
1743 int32_t expected_http_rtt_milliseconds; | |
1744 int32_t downstream_throughput_kbps; | |
1745 int32_t expected_downstream_throughput_kbps; | |
1746 | |
1747 } tests[] = { | |
1748 { | |
1749 // Verify that the metric is not recorded if the logging probability | |
1750 // is set to 0.0. | |
1751 0.0, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, | |
1752 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, | |
1753 3000 >> kTrimBits, | |
1754 }, | |
1755 { | |
1756 1.0, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, | |
1757 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, | |
1758 3000 >> kTrimBits, | |
1759 }, | |
1760 { | |
1761 // 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.
| |
1762 // it is rounded down to | |
1763 // (2^(kBitsPerMetric + kTrimBits) - 1) >> kTrimBits. | |
1764 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,
| |
1765 base::TimeDelta::FromSeconds(20), 4095 >> kTrimBits, 30000, | |
1766 4095 >> kTrimBits, | |
1767 }, | |
1768 }; | |
1769 | |
1770 for (const auto& test : tests) { | |
1771 base::HistogramTester histogram_tester; | |
1772 | |
1773 std::map<std::string, std::string> variation_params; | |
1774 variation_params["correlation_logging_probability"] = | |
1775 base::DoubleToString(test.correlation_logging_probability); | |
1776 TestNetworkQualityEstimator estimator(variation_params); | |
1777 | |
1778 estimator.set_transport_rtt(test.transport_rtt); | |
1779 estimator.set_recent_transport_rtt(test.transport_rtt); | |
1780 estimator.set_http_rtt(test.http_rtt); | |
1781 estimator.set_recent_http_rtt(test.http_rtt); | |
1782 estimator.set_downlink_throughput_kbps(test.downstream_throughput_kbps); | |
1783 | |
1784 TestDelegate test_delegate; | |
1785 TestURLRequestContext context(true); | |
1786 context.set_network_quality_estimator(&estimator); | |
1787 context.Init(); | |
1788 | |
1789 // 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.
| |
1790 // to record the network quality at the last main frame request. | |
1791 std::unique_ptr<URLRequest> request_1(context.CreateRequest( | |
1792 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | |
1793 request_1->SetLoadFlags(request_1->load_flags() | LOAD_MAIN_FRAME); | |
1794 request_1->Start(); | |
1795 base::RunLoop().Run(); | |
1796 histogram_tester.ExpectTotalCount("NQE.Correlation.ResourceLoadTime", 0); | |
1797 | |
1798 // Start another main-frame request which should cause network quality | |
1799 // estimator to record the correlation UMA. | |
1800 std::unique_ptr<URLRequest> request_2(context.CreateRequest( | |
1801 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | |
1802 request_2->Start(); | |
1803 base::RunLoop().Run(); | |
1804 | |
1805 if (test.correlation_logging_probability == 0.0) { | |
1806 histogram_tester.ExpectTotalCount("NQE.Correlation.ResourceLoadTime", 0); | |
1807 continue; | |
1808 } | |
1809 histogram_tester.ExpectTotalCount("NQE.Correlation.ResourceLoadTime", 1); | |
1810 std::vector<base::Bucket> buckets = | |
1811 histogram_tester.GetAllSamples("NQE.Correlation.ResourceLoadTime"); | |
1812 // Get the bits at index 0-10 which contain the transport RTT. | |
1813 // 128 is 2^kBitsPerMetric. | |
1814 EXPECT_EQ(test.expected_transport_rtt_milliseconds, | |
1815 buckets.at(0).min >> kBitsPerMetric >> kBitsPerMetric >> | |
1816 kBitsPerMetric); | |
1817 // Get the bits at index 11-17 which contain the HTTP RTT. | |
1818 EXPECT_EQ(test.expected_http_rtt_milliseconds, | |
1819 (buckets.at(0).min >> kBitsPerMetric >> kBitsPerMetric) % 128); | |
1820 // Get the bits at index 18-24 which contain the downstream throughput. | |
1821 EXPECT_EQ(test.expected_downstream_throughput_kbps, | |
1822 (buckets.at(0).min >> kBitsPerMetric) % 128); | |
1823 // Get the bits at index 25-31 which contain the resource fetch time. | |
1824 EXPECT_LE(0, buckets.at(0).min % 128); | |
1825 } | |
1826 } | |
1827 | |
1731 } // namespace net | 1828 } // namespace net |
OLD | NEW |