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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm | 629 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm |
630 expected_algorithm; | 630 expected_algorithm; |
631 } tests[] = { | 631 } tests[] = { |
632 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: | 632 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: |
633 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, | 633 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, |
634 {true, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: | 634 {true, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: |
635 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, | 635 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, |
636 {true, "HttpRTTAndDownstreamThroughput", | 636 {true, "HttpRTTAndDownstreamThroughput", |
637 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: | 637 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: |
638 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, | 638 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, |
| 639 {true, "TransportRTTOrDownstreamThroughput", |
| 640 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: |
| 641 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}, |
639 }; | 642 }; |
640 | 643 |
641 for (const auto& test : tests) { | 644 for (const auto& test : tests) { |
642 std::map<std::string, std::string> variation_params; | 645 std::map<std::string, std::string> variation_params; |
643 if (test.set_variation_param) | 646 if (test.set_variation_param) |
644 variation_params["effective_connection_type_algorithm"] = test.algorithm; | 647 variation_params["effective_connection_type_algorithm"] = test.algorithm; |
645 | 648 |
646 TestNetworkQualityEstimator estimator(variation_params); | 649 TestNetworkQualityEstimator estimator(variation_params); |
647 EXPECT_EQ(test.expected_algorithm, | 650 EXPECT_EQ(test.expected_algorithm, |
648 estimator.effective_connection_type_algorithm_) | 651 estimator.effective_connection_type_algorithm_) |
649 << test.algorithm; | 652 << test.algorithm; |
| 653 |
| 654 // Make sure no two values are same in the map. |
| 655 typedef std::map<std::string, |
| 656 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm> |
| 657 Algorithms; |
| 658 |
| 659 for (Algorithms::const_iterator it_first = |
| 660 estimator.algorithm_name_to_enum_.begin(); |
| 661 it_first != estimator.algorithm_name_to_enum_.end(); ++it_first) { |
| 662 for (Algorithms::const_iterator it_second = |
| 663 estimator.algorithm_name_to_enum_.begin(); |
| 664 it_second != estimator.algorithm_name_to_enum_.end(); ++it_second) { |
| 665 if (it_first != it_second) { |
| 666 DCHECK_NE(it_first->second, it_second->second); |
| 667 } |
| 668 } |
| 669 } |
650 } | 670 } |
651 } | 671 } |
652 | 672 |
653 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 673 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
654 // no variation params are specified. | 674 // no variation params are specified. |
655 TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) { | 675 TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) { |
656 std::map<std::string, std::string> variation_params; | 676 std::map<std::string, std::string> variation_params; |
657 | 677 |
658 TestNetworkQualityEstimator estimator(variation_params); | 678 TestNetworkQualityEstimator estimator(variation_params); |
659 | 679 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 767 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
748 estimator.set_recent_http_rtt( | 768 estimator.set_recent_http_rtt( |
749 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 769 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
750 estimator.set_downlink_throughput_kbps(INT32_MAX); | 770 estimator.set_downlink_throughput_kbps(INT32_MAX); |
751 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | 771 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
752 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 772 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
753 } | 773 } |
754 } | 774 } |
755 | 775 |
756 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 776 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
757 // both RTT and throughput thresholds are specified in the variation params. | 777 // only transport RTT thresholds are specified in the variation params. |
758 TEST(NetworkQualityEstimatorTest, ObtainThresholdsRTTandThroughput) { | 778 TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyTransportRTT) { |
| 779 std::map<std::string, std::string> variation_params; |
| 780 variation_params["effective_connection_type_algorithm"] = |
| 781 "TransportRTTOrDownstreamThroughput"; |
| 782 |
| 783 variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000"; |
| 784 variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000"; |
| 785 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; |
| 786 variation_params["3G.ThresholdMedianTransportRTTMsec"] = "500"; |
| 787 variation_params["4G.ThresholdMedianTransportRTTMsec"] = "300"; |
| 788 variation_params["Broadband.ThresholdMedianTransportRTTMsec"] = "100"; |
| 789 |
| 790 TestNetworkQualityEstimator estimator(variation_params); |
| 791 |
| 792 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 793 // does not return Offline if the device is offline. |
| 794 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| 795 "test"); |
| 796 |
| 797 const struct { |
| 798 int32_t transport_rtt_msec; |
| 799 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; |
| 800 } tests[] = { |
| 801 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 802 {4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 803 {3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 804 {2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 805 {1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 806 {1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 807 {700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 808 {500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 809 {400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 810 {300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 811 {200, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 812 {100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 813 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 814 }; |
| 815 |
| 816 for (const auto& test : tests) { |
| 817 estimator.set_transport_rtt( |
| 818 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 819 estimator.set_recent_transport_rtt( |
| 820 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 821 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 822 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| 823 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 824 } |
| 825 } |
| 826 |
| 827 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 828 // both HTTP RTT and throughput thresholds are specified in the variation |
| 829 // params. |
| 830 TEST(NetworkQualityEstimatorTest, ObtainThresholdsHttpRTTandThroughput) { |
759 std::map<std::string, std::string> variation_params; | 831 std::map<std::string, std::string> variation_params; |
760 | 832 |
761 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; | 833 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; |
762 variation_params["Slow2G.ThresholdMedianHttpRTTMsec"] = "2000"; | 834 variation_params["Slow2G.ThresholdMedianHttpRTTMsec"] = "2000"; |
763 variation_params["2G.ThresholdMedianHttpRTTMsec"] = "1000"; | 835 variation_params["2G.ThresholdMedianHttpRTTMsec"] = "1000"; |
764 variation_params["3G.ThresholdMedianHttpRTTMsec"] = "500"; | 836 variation_params["3G.ThresholdMedianHttpRTTMsec"] = "500"; |
765 variation_params["4G.ThresholdMedianHttpRTTMsec"] = "300"; | 837 variation_params["4G.ThresholdMedianHttpRTTMsec"] = "300"; |
766 variation_params["Broadband.ThresholdMedianHttpRTTMsec"] = "100"; | 838 variation_params["Broadband.ThresholdMedianHttpRTTMsec"] = "100"; |
767 | 839 |
768 variation_params["Offline.ThresholdMedianKbps"] = "10"; | 840 variation_params["Offline.ThresholdMedianKbps"] = "10"; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 879 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
808 estimator.set_recent_http_rtt( | 880 estimator.set_recent_http_rtt( |
809 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 881 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
810 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); | 882 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); |
811 estimator.set_recent_downlink_throughput_kbps( | 883 estimator.set_recent_downlink_throughput_kbps( |
812 test.downlink_throughput_kbps); | 884 test.downlink_throughput_kbps); |
813 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 885 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
814 } | 886 } |
815 } | 887 } |
816 | 888 |
| 889 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 890 // both transport RTT and throughput thresholds are specified in the variation |
| 891 // params. |
| 892 TEST(NetworkQualityEstimatorTest, ObtainThresholdsTransportRTTandThroughput) { |
| 893 std::map<std::string, std::string> variation_params; |
| 894 variation_params["effective_connection_type_algorithm"] = |
| 895 "TransportRTTOrDownstreamThroughput"; |
| 896 |
| 897 variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000"; |
| 898 variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000"; |
| 899 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; |
| 900 variation_params["3G.ThresholdMedianTransportRTTMsec"] = "500"; |
| 901 variation_params["4G.ThresholdMedianTransportRTTMsec"] = "300"; |
| 902 variation_params["Broadband.ThresholdMedianTransportRTTMsec"] = "100"; |
| 903 |
| 904 variation_params["Offline.ThresholdMedianKbps"] = "10"; |
| 905 variation_params["Slow2G.ThresholdMedianKbps"] = "100"; |
| 906 variation_params["2G.ThresholdMedianKbps"] = "300"; |
| 907 variation_params["3G.ThresholdMedianKbps"] = "500"; |
| 908 variation_params["4G.ThresholdMedianKbps"] = "1000"; |
| 909 variation_params["Broadband.ThresholdMedianKbps"] = "2000"; |
| 910 |
| 911 TestNetworkQualityEstimator estimator(variation_params); |
| 912 |
| 913 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 914 // does not return Offline if the device is offline. |
| 915 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| 916 "test"); |
| 917 |
| 918 const struct { |
| 919 int32_t transport_rtt_msec; |
| 920 int32_t downlink_throughput_kbps; |
| 921 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; |
| 922 } tests[] = { |
| 923 // Set RTT to a very low value to observe the effect of throughput. |
| 924 // Throughput is the bottleneck. |
| 925 {1, 5, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 926 {1, 10, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 927 {1, 50, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 928 {1, 100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 929 {1, 150, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 930 {1, 300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 931 {1, 400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 932 {1, 500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 933 {1, 700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 934 {1, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 935 {1, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 936 {1, 2500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 937 // Set both RTT and throughput. RTT is the bottleneck. |
| 938 {3000, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 939 {700, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 940 }; |
| 941 |
| 942 for (const auto& test : tests) { |
| 943 estimator.set_transport_rtt( |
| 944 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 945 estimator.set_recent_transport_rtt( |
| 946 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 947 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); |
| 948 estimator.set_recent_downlink_throughput_kbps( |
| 949 test.downlink_throughput_kbps); |
| 950 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 951 } |
| 952 } |
| 953 |
817 // Tests if |weight_multiplier_per_second_| is set to correct value for various | 954 // Tests if |weight_multiplier_per_second_| is set to correct value for various |
818 // values of half life parameter. | 955 // values of half life parameter. |
819 TEST(NetworkQualityEstimatorTest, HalfLifeParam) { | 956 TEST(NetworkQualityEstimatorTest, HalfLifeParam) { |
820 std::map<std::string, std::string> variation_params; | 957 std::map<std::string, std::string> variation_params; |
821 | 958 |
822 const struct { | 959 const struct { |
823 std::string description; | 960 std::string description; |
824 std::string variation_params_value; | 961 std::string variation_params_value; |
825 double expected_weight_multiplier; | 962 double expected_weight_multiplier; |
826 } tests[] = { | 963 } tests[] = { |
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1806 std::string(NetworkQualityEstimator::GetNameForEffectiveConnectionType( | 1943 std::string(NetworkQualityEstimator::GetNameForEffectiveConnectionType( |
1807 effective_connection_type)); | 1944 effective_connection_type)); |
1808 EXPECT_FALSE(connection_type_name.empty()); | 1945 EXPECT_FALSE(connection_type_name.empty()); |
1809 EXPECT_EQ(effective_connection_type, | 1946 EXPECT_EQ(effective_connection_type, |
1810 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( | 1947 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( |
1811 connection_type_name)); | 1948 connection_type_name)); |
1812 } | 1949 } |
1813 } | 1950 } |
1814 | 1951 |
1815 } // namespace net | 1952 } // namespace net |
OLD | NEW |