| 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 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 estimator.algorithm_name_to_enum_.begin(); | 684 estimator.algorithm_name_to_enum_.begin(); |
| 685 it_second != estimator.algorithm_name_to_enum_.end(); ++it_second) { | 685 it_second != estimator.algorithm_name_to_enum_.end(); ++it_second) { |
| 686 if (it_first != it_second) { | 686 if (it_first != it_second) { |
| 687 DCHECK_NE(it_first->second, it_second->second); | 687 DCHECK_NE(it_first->second, it_second->second); |
| 688 } | 688 } |
| 689 } | 689 } |
| 690 } | 690 } |
| 691 } | 691 } |
| 692 } | 692 } |
| 693 | 693 |
| 694 // Tests that |GetEffectiveConnectionType| returns correct connection type when | |
| 695 // no variation params are specified. | |
| 696 TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) { | |
| 697 std::map<std::string, std::string> variation_params; | |
| 698 | |
| 699 TestNetworkQualityEstimator estimator(variation_params); | |
| 700 | |
| 701 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | |
| 702 // does not return Offline if the device is offline. | |
| 703 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, | |
| 704 "test"); | |
| 705 | |
| 706 const struct { | |
| 707 int32_t rtt_msec; | |
| 708 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | |
| 709 } tests[] = { | |
| 710 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 711 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 712 }; | |
| 713 | |
| 714 for (const auto& test : tests) { | |
| 715 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | |
| 716 estimator.set_recent_http_rtt( | |
| 717 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | |
| 718 estimator.set_downlink_throughput_kbps(INT32_MAX); | |
| 719 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | |
| 720 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | |
| 721 } | |
| 722 } | |
| 723 | |
| 724 // Tests that |GetEffectiveConnectionType| returns | 694 // Tests that |GetEffectiveConnectionType| returns |
| 725 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. | 695 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. |
| 726 TEST(NetworkQualityEstimatorTest, Offline) { | 696 TEST(NetworkQualityEstimatorTest, Offline) { |
| 727 std::map<std::string, std::string> variation_params; | 697 std::map<std::string, std::string> variation_params; |
| 728 TestNetworkQualityEstimator estimator(variation_params); | 698 TestNetworkQualityEstimator estimator(variation_params); |
| 729 | 699 |
| 730 const struct { | 700 const struct { |
| 731 NetworkChangeNotifier::ConnectionType connection_type; | 701 NetworkChangeNotifier::ConnectionType connection_type; |
| 732 NetworkQualityEstimator::EffectiveConnectionType expected_connection_type; | 702 NetworkQualityEstimator::EffectiveConnectionType expected_connection_type; |
| 733 } tests[] = { | 703 } tests[] = { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 for (const auto& test : tests) { | 757 for (const auto& test : tests) { |
| 788 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 758 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 789 estimator.set_recent_http_rtt( | 759 estimator.set_recent_http_rtt( |
| 790 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 760 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 791 estimator.set_downlink_throughput_kbps(INT32_MAX); | 761 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 792 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | 762 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| 793 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 763 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 794 } | 764 } |
| 795 } | 765 } |
| 796 | 766 |
| 767 // Tests that default transport RTT thresholds for different effective |
| 768 // connection types are correctly set. |
| 769 TEST(NetworkQualityEstimatorTest, DefaultTransportRTTBasedThresholds) { |
| 770 const struct { |
| 771 bool override_defaults_using_variation_params; |
| 772 int32_t transport_rtt_msec; |
| 773 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; |
| 774 } tests[] = { |
| 775 // When the variation params do not override connection thresholds, |
| 776 // default values should be used. |
| 777 {false, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 778 {false, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 779 {false, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 780 {false, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 781 {false, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 782 {false, 1000, |
| 783 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 784 {false, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 785 // Override default thresholds using variation params. |
| 786 {true, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 787 {true, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 788 {true, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 789 {true, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 790 {true, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 791 {true, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 792 {true, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 793 }; |
| 794 |
| 795 for (const auto& test : tests) { |
| 796 std::map<std::string, std::string> variation_params; |
| 797 variation_params["effective_connection_type_algorithm"] = |
| 798 "TransportRTTOrDownstreamThroughput"; |
| 799 if (test.override_defaults_using_variation_params) { |
| 800 variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000"; |
| 801 variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000"; |
| 802 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; |
| 803 } |
| 804 |
| 805 TestNetworkQualityEstimator estimator(variation_params); |
| 806 |
| 807 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 808 // does not return Offline if the device is offline. |
| 809 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| 810 "test"); |
| 811 |
| 812 estimator.set_transport_rtt( |
| 813 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 814 estimator.set_recent_transport_rtt( |
| 815 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 816 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 817 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| 818 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 819 } |
| 820 } |
| 821 |
| 822 // Tests that default HTTP RTT thresholds for different effective |
| 823 // connection types are correctly set. |
| 824 TEST(NetworkQualityEstimatorTest, DefaultHttpRTTBasedThresholds) { |
| 825 const struct { |
| 826 bool override_defaults_using_variation_params; |
| 827 int32_t http_rtt_msec; |
| 828 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; |
| 829 } tests[] = { |
| 830 // When the variation params do not override connection thresholds, |
| 831 // default values should be used. |
| 832 {false, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 833 {false, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 834 {false, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 835 {false, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 836 {false, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 837 {false, 1000, |
| 838 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 839 {false, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 840 // Override default thresholds using variation params. |
| 841 {true, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 842 {true, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 843 {true, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 844 {true, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 845 {true, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 846 {true, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 847 {true, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 848 }; |
| 849 |
| 850 for (const auto& test : tests) { |
| 851 std::map<std::string, std::string> variation_params; |
| 852 if (test.override_defaults_using_variation_params) { |
| 853 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; |
| 854 variation_params["Slow2G.ThresholdMedianHttpRTTMsec"] = "2000"; |
| 855 variation_params["2G.ThresholdMedianHttpRTTMsec"] = "1000"; |
| 856 } |
| 857 |
| 858 TestNetworkQualityEstimator estimator(variation_params); |
| 859 |
| 860 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 861 // does not return Offline if the device is offline. |
| 862 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| 863 "test"); |
| 864 |
| 865 estimator.set_http_rtt( |
| 866 base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); |
| 867 estimator.set_recent_http_rtt( |
| 868 base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); |
| 869 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 870 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| 871 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 872 } |
| 873 } |
| 874 |
| 797 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 875 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 798 // only transport RTT thresholds are specified in the variation params. | 876 // only transport RTT thresholds are specified in the variation params. |
| 799 TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyTransportRTT) { | 877 TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyTransportRTT) { |
| 800 std::map<std::string, std::string> variation_params; | 878 std::map<std::string, std::string> variation_params; |
| 801 variation_params["effective_connection_type_algorithm"] = | 879 variation_params["effective_connection_type_algorithm"] = |
| 802 "TransportRTTOrDownstreamThroughput"; | 880 "TransportRTTOrDownstreamThroughput"; |
| 803 | 881 |
| 804 variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000"; | 882 variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000"; |
| 805 variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000"; | 883 variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000"; |
| 806 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; | 884 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; |
| (...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1993 | 2071 |
| 1994 // Get the bits at index 18-24 which contain the resource fetch time. | 2072 // Get the bits at index 18-24 which contain the resource fetch time. |
| 1995 EXPECT_LE(0, (buckets.at(0).min >> kBitsPerMetric) % 128); | 2073 EXPECT_LE(0, (buckets.at(0).min >> kBitsPerMetric) % 128); |
| 1996 | 2074 |
| 1997 // Get the bits at index 25-31 which contain the resource load size. | 2075 // Get the bits at index 25-31 which contain the resource load size. |
| 1998 EXPECT_LE(0, (buckets.at(0).min) % 128); | 2076 EXPECT_LE(0, (buckets.at(0).min) % 128); |
| 1999 } | 2077 } |
| 2000 } | 2078 } |
| 2001 | 2079 |
| 2002 } // namespace net | 2080 } // namespace net |
| OLD | NEW |