Chromium Code Reviews| 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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 estimator.algorithm_name_to_enum_.begin(); | 663 estimator.algorithm_name_to_enum_.begin(); |
| 664 it_second != estimator.algorithm_name_to_enum_.end(); ++it_second) { | 664 it_second != estimator.algorithm_name_to_enum_.end(); ++it_second) { |
| 665 if (it_first != it_second) { | 665 if (it_first != it_second) { |
| 666 DCHECK_NE(it_first->second, it_second->second); | 666 DCHECK_NE(it_first->second, it_second->second); |
| 667 } | 667 } |
| 668 } | 668 } |
| 669 } | 669 } |
| 670 } | 670 } |
| 671 } | 671 } |
| 672 | 672 |
| 673 // Tests that |GetEffectiveConnectionType| returns correct connection type when | |
| 674 // no variation params are specified. | |
| 675 TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) { | |
| 676 std::map<std::string, std::string> variation_params; | |
| 677 | |
| 678 TestNetworkQualityEstimator estimator(variation_params); | |
| 679 | |
| 680 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | |
| 681 // does not return Offline if the device is offline. | |
| 682 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, | |
| 683 "test"); | |
| 684 | |
| 685 const struct { | |
| 686 int32_t rtt_msec; | |
| 687 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | |
| 688 } tests[] = { | |
| 689 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 690 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 691 }; | |
| 692 | |
| 693 for (const auto& test : tests) { | |
| 694 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | |
| 695 estimator.set_recent_http_rtt( | |
| 696 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | |
| 697 estimator.set_downlink_throughput_kbps(INT32_MAX); | |
| 698 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | |
| 699 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | |
| 700 } | |
| 701 } | |
| 702 | |
| 703 // Tests that |GetEffectiveConnectionType| returns | 673 // Tests that |GetEffectiveConnectionType| returns |
| 704 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. | 674 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. |
| 705 TEST(NetworkQualityEstimatorTest, Offline) { | 675 TEST(NetworkQualityEstimatorTest, Offline) { |
| 706 std::map<std::string, std::string> variation_params; | 676 std::map<std::string, std::string> variation_params; |
| 707 TestNetworkQualityEstimator estimator(variation_params); | 677 TestNetworkQualityEstimator estimator(variation_params); |
| 708 | 678 |
| 709 const struct { | 679 const struct { |
| 710 NetworkChangeNotifier::ConnectionType connection_type; | 680 NetworkChangeNotifier::ConnectionType connection_type; |
| 711 NetworkQualityEstimator::EffectiveConnectionType expected_connection_type; | 681 NetworkQualityEstimator::EffectiveConnectionType expected_connection_type; |
| 712 } tests[] = { | 682 } tests[] = { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 for (const auto& test : tests) { | 736 for (const auto& test : tests) { |
| 767 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 737 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 768 estimator.set_recent_http_rtt( | 738 estimator.set_recent_http_rtt( |
| 769 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 739 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 770 estimator.set_downlink_throughput_kbps(INT32_MAX); | 740 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 771 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | 741 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| 772 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 742 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 773 } | 743 } |
| 774 } | 744 } |
| 775 | 745 |
| 746 // Tests that default transport RTT thresholds for different effective | |
| 747 // connection types are correctly set. | |
| 748 TEST(NetworkQualityEstimatorTest, DefaultTransportRTTBasedThresholds) { | |
| 749 const struct { | |
| 750 // When the variation params do not override connection thresholds, default | |
| 751 // values should be used. | |
| 752 bool override_defaults_using_variation_params; | |
| 753 int32_t transport_rtt_msec; | |
| 754 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | |
| 755 } tests[] = { | |
| 756 {false, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 757 {false, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 758 {false, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 759 {false, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 760 {false, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | |
| 761 {false, 1000, | |
| 762 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 763 {false, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 764 // Override default thresholds using variation params. | |
| 765 {true, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | |
| 766 {true, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | |
| 767 {true, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 768 {true, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 769 {true, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | |
| 770 {true, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | |
| 771 {true, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 772 }; | |
| 773 | |
| 774 for (const auto& test : tests) { | |
| 775 std::map<std::string, std::string> variation_params; | |
| 776 variation_params["effective_connection_type_algorithm"] = | |
| 777 "TransportRTTOrDownstreamThroughput"; | |
| 778 if (test.override_defaults_using_variation_params) { | |
| 779 variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000"; | |
| 780 variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000"; | |
| 781 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; | |
| 782 } | |
| 783 // Thresholds are not set using |variation_params|. Default values should be | |
| 784 // used. | |
| 785 | |
| 786 TestNetworkQualityEstimator estimator(variation_params); | |
| 787 | |
| 788 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | |
| 789 // does not return Offline if the device is offline. | |
| 790 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, | |
| 791 "test"); | |
| 792 | |
| 793 estimator.set_transport_rtt( | |
| 794 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); | |
| 795 estimator.set_recent_transport_rtt( | |
| 796 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); | |
| 797 estimator.set_downlink_throughput_kbps(INT32_MAX); | |
| 798 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | |
| 799 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | |
| 800 } | |
| 801 } | |
| 802 | |
| 803 // Tests that default HTTP RTT thresholds for different effective | |
| 804 // connection types are correctly set. | |
| 805 TEST(NetworkQualityEstimatorTest, DefaultHttpRTTBasedThresholds) { | |
| 806 const struct { | |
| 807 // When the variation params do not override connection thresholds, default | |
| 808 // values should be used. | |
| 809 bool override_defaults_using_variation_params; | |
| 810 int32_t http_rtt_msec; | |
| 811 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | |
| 812 } tests[] = { | |
| 813 {false, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 814 {false, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 815 {false, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 816 {false, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 817 {false, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | |
| 818 {false, 1000, | |
| 819 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 820 {false, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 821 // Override default thresholds using variation params. | |
| 822 {true, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | |
| 823 {true, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | |
| 824 {true, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 825 {true, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 826 {true, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | |
| 827 {true, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | |
| 828 {true, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 829 }; | |
| 830 | |
| 831 for (const auto& test : tests) { | |
| 832 std::map<std::string, std::string> variation_params; | |
| 833 if (test.override_defaults_using_variation_params) { | |
| 834 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; | |
| 835 variation_params["Slow2G.ThresholdMedianHttpRTTMsec"] = "2000"; | |
| 836 variation_params["2G.ThresholdMedianHttpRTTMsec"] = "1000"; | |
| 837 } | |
| 838 // Thresholds are not set using |variation_params|. Default values should be | |
|
RyanSturm
2016/07/22 21:45:43
This comment confuses me, and the space below it s
tbansal1
2016/07/22 21:51:23
Done.
| |
| 839 // used. | |
| 840 | |
| 841 TestNetworkQualityEstimator estimator(variation_params); | |
| 842 | |
| 843 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | |
| 844 // does not return Offline if the device is offline. | |
| 845 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, | |
| 846 "test"); | |
| 847 | |
| 848 estimator.set_http_rtt( | |
| 849 base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); | |
| 850 estimator.set_recent_http_rtt( | |
| 851 base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); | |
| 852 estimator.set_downlink_throughput_kbps(INT32_MAX); | |
| 853 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | |
| 854 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | |
| 855 } | |
| 856 } | |
| 857 | |
| 776 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 858 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 777 // only transport RTT thresholds are specified in the variation params. | 859 // only transport RTT thresholds are specified in the variation params. |
| 778 TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyTransportRTT) { | 860 TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyTransportRTT) { |
| 779 std::map<std::string, std::string> variation_params; | 861 std::map<std::string, std::string> variation_params; |
| 780 variation_params["effective_connection_type_algorithm"] = | 862 variation_params["effective_connection_type_algorithm"] = |
| 781 "TransportRTTOrDownstreamThroughput"; | 863 "TransportRTTOrDownstreamThroughput"; |
| 782 | 864 |
| 783 variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000"; | 865 variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000"; |
| 784 variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000"; | 866 variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000"; |
| 785 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; | 867 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; |
| (...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1978 histogram_tester.ExpectTotalCount("NQE.NetworkIdAvailable", 3); | 2060 histogram_tester.ExpectTotalCount("NQE.NetworkIdAvailable", 3); |
| 1979 | 2061 |
| 1980 // The NetworkID is recorded as being available on a cellular connection. | 2062 // The NetworkID is recorded as being available on a cellular connection. |
| 1981 estimator.SimulateNetworkChangeTo( | 2063 estimator.SimulateNetworkChangeTo( |
| 1982 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); | 2064 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); |
| 1983 histogram_tester.ExpectBucketCount("NQE.NetworkIdAvailable", 1, 3); | 2065 histogram_tester.ExpectBucketCount("NQE.NetworkIdAvailable", 1, 3); |
| 1984 histogram_tester.ExpectTotalCount("NQE.NetworkIdAvailable", 4); | 2066 histogram_tester.ExpectTotalCount("NQE.NetworkIdAvailable", 4); |
| 1985 } | 2067 } |
| 1986 | 2068 |
| 1987 } // namespace net | 2069 } // namespace net |
| OLD | NEW |