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 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 EXPECT_EQ(test.expected_downstream_throughput, | 849 EXPECT_EQ(test.expected_downstream_throughput, |
850 downstream_throughput_kbps); | 850 downstream_throughput_kbps); |
851 } | 851 } |
852 } | 852 } |
853 } | 853 } |
854 | 854 |
855 // An external estimate provider that does not have a valid RTT or throughput | 855 // An external estimate provider that does not have a valid RTT or throughput |
856 // estimate. | 856 // estimate. |
857 class InvalidExternalEstimateProvider : public ExternalEstimateProvider { | 857 class InvalidExternalEstimateProvider : public ExternalEstimateProvider { |
858 public: | 858 public: |
859 InvalidExternalEstimateProvider() | 859 InvalidExternalEstimateProvider() : update_count_(0) {} |
860 : get_rtt_count_(0), get_downstream_throughput_count_(0) {} | |
861 ~InvalidExternalEstimateProvider() override {} | 860 ~InvalidExternalEstimateProvider() override {} |
862 | 861 |
863 // ExternalEstimateProvider implementation: | |
864 bool GetRTT(base::TimeDelta* rtt) const override { | 862 bool GetRTT(base::TimeDelta* rtt) const override { |
865 DCHECK(rtt); | 863 DCHECK(rtt); |
866 get_rtt_count_++; | |
867 return false; | 864 return false; |
868 } | 865 } |
869 | 866 |
870 // ExternalEstimateProvider implementation: | |
871 bool GetDownstreamThroughputKbps( | 867 bool GetDownstreamThroughputKbps( |
872 int32_t* downstream_throughput_kbps) const override { | 868 int32_t* downstream_throughput_kbps) const override { |
873 DCHECK(downstream_throughput_kbps); | 869 DCHECK(downstream_throughput_kbps); |
874 get_downstream_throughput_count_++; | |
875 return false; | 870 return false; |
876 } | 871 } |
877 | 872 |
878 // ExternalEstimateProvider implementation: | |
879 bool GetUpstreamThroughputKbps( | 873 bool GetUpstreamThroughputKbps( |
880 int32_t* upstream_throughput_kbps) const override { | 874 int32_t* upstream_throughput_kbps) const override { |
881 // NetworkQualityEstimator does not support upstream throughput. | 875 // NetworkQualityEstimator does not support upstream throughput. |
882 ADD_FAILURE(); | 876 ADD_FAILURE(); |
883 return false; | 877 return false; |
884 } | 878 } |
885 | 879 |
886 // ExternalEstimateProvider implementation: | |
887 bool GetTimeSinceLastUpdate( | 880 bool GetTimeSinceLastUpdate( |
888 base::TimeDelta* time_since_last_update) const override { | 881 base::TimeDelta* time_since_last_update) const override { |
889 *time_since_last_update = base::TimeDelta::FromMilliseconds(1); | 882 NOTREACHED(); |
890 return true; | 883 return false; |
891 } | 884 } |
892 | 885 |
893 // ExternalEstimateProvider implementation: | |
894 void SetUpdatedEstimateDelegate(UpdatedEstimateDelegate* delegate) override {} | 886 void SetUpdatedEstimateDelegate(UpdatedEstimateDelegate* delegate) override {} |
895 | 887 |
896 // ExternalEstimateProvider implementation: | 888 void Update() const override { update_count_++; } |
897 void Update() const override {} | |
898 | 889 |
899 size_t get_rtt_count() const { return get_rtt_count_; } | 890 size_t update_count() const { return update_count_; } |
900 | |
901 size_t get_downstream_throughput_count() const { | |
902 return get_downstream_throughput_count_; | |
903 } | |
904 | 891 |
905 private: | 892 private: |
906 // Keeps track of number of times different functions were called. | 893 mutable size_t update_count_; |
907 mutable size_t get_rtt_count_; | |
908 mutable size_t get_downstream_throughput_count_; | |
909 | 894 |
910 DISALLOW_COPY_AND_ASSIGN(InvalidExternalEstimateProvider); | 895 DISALLOW_COPY_AND_ASSIGN(InvalidExternalEstimateProvider); |
911 }; | 896 }; |
912 | 897 |
913 // Tests if the RTT value from external estimate provider is discarded if the | 898 // Tests if the RTT value from external estimate provider is discarded if the |
914 // external estimate provider is invalid. | 899 // external estimate provider is invalid. |
915 TEST(NetworkQualityEstimatorTest, InvalidExternalEstimateProvider) { | 900 TEST(NetworkQualityEstimatorTest, InvalidExternalEstimateProvider) { |
916 base::HistogramTester histogram_tester; | 901 base::HistogramTester histogram_tester; |
917 InvalidExternalEstimateProvider* invalid_external_estimate_provider = | 902 InvalidExternalEstimateProvider* invalid_external_estimate_provider = |
918 new InvalidExternalEstimateProvider(); | 903 new InvalidExternalEstimateProvider(); |
919 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( | 904 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( |
920 invalid_external_estimate_provider); | 905 invalid_external_estimate_provider); |
921 | 906 |
922 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), | 907 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), |
923 std::move(external_estimate_provider)); | 908 std::move(external_estimate_provider)); |
| 909 estimator.SimulateNetworkChangeTo(net::NetworkChangeNotifier::CONNECTION_WIFI, |
| 910 "test"); |
924 | 911 |
925 base::TimeDelta rtt; | 912 base::TimeDelta rtt; |
926 int32_t kbps; | 913 int32_t kbps; |
927 EXPECT_EQ(1U, invalid_external_estimate_provider->get_rtt_count()); | 914 EXPECT_EQ(1U, invalid_external_estimate_provider->update_count()); |
928 EXPECT_EQ( | |
929 1U, | |
930 invalid_external_estimate_provider->get_downstream_throughput_count()); | |
931 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); | 915 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); |
932 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 916 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
933 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 3); | 917 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 2); |
934 | 918 |
935 histogram_tester.ExpectBucketCount( | 919 histogram_tester.ExpectBucketCount( |
936 "NQE.ExternalEstimateProviderStatus", | 920 "NQE.ExternalEstimateProviderStatus", |
937 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); | 921 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); |
938 histogram_tester.ExpectBucketCount( | 922 histogram_tester.ExpectBucketCount( |
939 "NQE.ExternalEstimateProviderStatus", | 923 "NQE.ExternalEstimateProviderStatus", |
940 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); | 924 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); |
941 histogram_tester.ExpectBucketCount( | |
942 "NQE.ExternalEstimateProviderStatus", | |
943 3 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL */, 1); | |
944 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProvider.RTT", 0); | 925 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProvider.RTT", 0); |
945 histogram_tester.ExpectTotalCount( | 926 histogram_tester.ExpectTotalCount( |
946 "NQE.ExternalEstimateProvider.DownlinkBandwidth", 0); | 927 "NQE.ExternalEstimateProvider.DownlinkBandwidth", 0); |
947 } | 928 } |
948 | 929 |
949 class TestExternalEstimateProvider : public ExternalEstimateProvider { | 930 class TestExternalEstimateProvider : public ExternalEstimateProvider { |
950 public: | 931 public: |
951 TestExternalEstimateProvider(base::TimeDelta rtt, | 932 TestExternalEstimateProvider(base::TimeDelta rtt, |
952 int32_t downstream_throughput_kbps) | 933 int32_t downstream_throughput_kbps) |
953 : rtt_(rtt), | 934 : delegate_(nullptr), |
| 935 should_notify_delegate_(true), |
| 936 rtt_(rtt), |
954 downstream_throughput_kbps_(downstream_throughput_kbps), | 937 downstream_throughput_kbps_(downstream_throughput_kbps), |
955 time_since_last_update_(base::TimeDelta::FromSeconds(1)), | |
956 get_time_since_last_update_count_(0), | |
957 get_rtt_count_(0), | |
958 get_downstream_throughput_kbps_count_(0), | |
959 update_count_(0) {} | 938 update_count_(0) {} |
960 ~TestExternalEstimateProvider() override {} | 939 ~TestExternalEstimateProvider() override {} |
961 | 940 |
962 // ExternalEstimateProvider implementation: | |
963 bool GetRTT(base::TimeDelta* rtt) const override { | 941 bool GetRTT(base::TimeDelta* rtt) const override { |
964 *rtt = rtt_; | 942 NOTREACHED(); |
965 get_rtt_count_++; | |
966 return true; | 943 return true; |
967 } | 944 } |
968 | 945 |
969 // ExternalEstimateProvider implementation: | |
970 bool GetDownstreamThroughputKbps( | 946 bool GetDownstreamThroughputKbps( |
971 int32_t* downstream_throughput_kbps) const override { | 947 int32_t* downstream_throughput_kbps) const override { |
972 *downstream_throughput_kbps = downstream_throughput_kbps_; | 948 NOTREACHED(); |
973 get_downstream_throughput_kbps_count_++; | |
974 return true; | 949 return true; |
975 } | 950 } |
976 | 951 |
977 // ExternalEstimateProvider implementation: | |
978 bool GetUpstreamThroughputKbps( | 952 bool GetUpstreamThroughputKbps( |
979 int32_t* upstream_throughput_kbps) const override { | 953 int32_t* upstream_throughput_kbps) const override { |
980 // NetworkQualityEstimator does not support upstream throughput. | 954 NOTREACHED(); |
981 ADD_FAILURE(); | |
982 return false; | 955 return false; |
983 } | 956 } |
984 | 957 |
985 // ExternalEstimateProvider implementation: | |
986 bool GetTimeSinceLastUpdate( | 958 bool GetTimeSinceLastUpdate( |
987 base::TimeDelta* time_since_last_update) const override { | 959 base::TimeDelta* time_since_last_update) const override { |
988 *time_since_last_update = time_since_last_update_; | 960 NOTREACHED(); |
989 get_time_since_last_update_count_++; | |
990 return true; | 961 return true; |
991 } | 962 } |
992 | 963 |
993 // ExternalEstimateProvider implementation: | 964 void SetUpdatedEstimateDelegate(UpdatedEstimateDelegate* delegate) override { |
994 void SetUpdatedEstimateDelegate(UpdatedEstimateDelegate* delegate) override {} | 965 delegate_ = delegate; |
995 | |
996 // ExternalEstimateProvider implementation: | |
997 void Update() const override { update_count_++; } | |
998 | |
999 void set_time_since_last_update(base::TimeDelta time_since_last_update) { | |
1000 time_since_last_update_ = time_since_last_update; | |
1001 } | 966 } |
1002 | 967 |
1003 size_t get_time_since_last_update_count() const { | 968 void set_should_notify_delegate(bool should_notify_delegate) { |
1004 return get_time_since_last_update_count_; | 969 should_notify_delegate_ = should_notify_delegate; |
1005 } | 970 } |
1006 size_t get_rtt_count() const { return get_rtt_count_; } | 971 |
1007 size_t get_downstream_throughput_kbps_count() const { | 972 void Update() const override { |
1008 return get_downstream_throughput_kbps_count_; | 973 update_count_++; |
| 974 if (!should_notify_delegate_) |
| 975 return; |
| 976 delegate_->OnUpdatedEstimateAvailable(rtt_, downstream_throughput_kbps_, |
| 977 -1); |
1009 } | 978 } |
| 979 |
1010 size_t update_count() const { return update_count_; } | 980 size_t update_count() const { return update_count_; } |
1011 | 981 |
1012 private: | 982 private: |
| 983 UpdatedEstimateDelegate* delegate_; |
| 984 |
| 985 bool should_notify_delegate_; |
| 986 |
1013 // RTT and downstream throughput estimates. | 987 // RTT and downstream throughput estimates. |
1014 const base::TimeDelta rtt_; | 988 const base::TimeDelta rtt_; |
1015 const int32_t downstream_throughput_kbps_; | 989 const int32_t downstream_throughput_kbps_; |
1016 | 990 |
1017 base::TimeDelta time_since_last_update_; | |
1018 | |
1019 // Keeps track of number of times different functions were called. | |
1020 mutable size_t get_time_since_last_update_count_; | |
1021 mutable size_t get_rtt_count_; | |
1022 mutable size_t get_downstream_throughput_kbps_count_; | |
1023 mutable size_t update_count_; | 991 mutable size_t update_count_; |
1024 | 992 |
1025 DISALLOW_COPY_AND_ASSIGN(TestExternalEstimateProvider); | 993 DISALLOW_COPY_AND_ASSIGN(TestExternalEstimateProvider); |
1026 }; | 994 }; |
1027 | 995 |
1028 // Tests if the external estimate provider is called in the constructor and | 996 // Tests if the external estimate provider is called in the constructor and |
1029 // on network change notification. | 997 // on network change notification. |
1030 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProvider) { | 998 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProvider) { |
1031 base::HistogramTester histogram_tester; | 999 base::HistogramTester histogram_tester; |
| 1000 const base::TimeDelta external_estimate_provider_rtt = |
| 1001 base::TimeDelta::FromMilliseconds(1); |
| 1002 const int32_t external_estimate_provider_downstream_throughput = 100; |
| 1003 |
1032 TestExternalEstimateProvider* test_external_estimate_provider = | 1004 TestExternalEstimateProvider* test_external_estimate_provider = |
1033 new TestExternalEstimateProvider(base::TimeDelta::FromMilliseconds(1), | 1005 new TestExternalEstimateProvider( |
1034 100); | 1006 external_estimate_provider_rtt, |
| 1007 external_estimate_provider_downstream_throughput); |
1035 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( | 1008 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( |
1036 test_external_estimate_provider); | 1009 test_external_estimate_provider); |
1037 std::map<std::string, std::string> variation_params; | 1010 std::map<std::string, std::string> variation_params; |
1038 TestNetworkQualityEstimator estimator(variation_params, | 1011 TestNetworkQualityEstimator estimator(variation_params, |
1039 std::move(external_estimate_provider)); | 1012 std::move(external_estimate_provider)); |
1040 | 1013 estimator.SimulateNetworkChangeTo(net::NetworkChangeNotifier::CONNECTION_WIFI, |
| 1014 "test"); |
1041 base::TimeDelta rtt; | 1015 base::TimeDelta rtt; |
1042 int32_t kbps; | 1016 int32_t kbps; |
1043 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); | 1017 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); |
1044 EXPECT_FALSE(estimator.GetTransportRTTEstimate(&rtt)); | 1018 EXPECT_FALSE(estimator.GetTransportRTTEstimate(&rtt)); |
1045 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 1019 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
1046 | 1020 |
1047 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 5); | 1021 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 5); |
1048 | 1022 |
1049 histogram_tester.ExpectBucketCount( | 1023 histogram_tester.ExpectBucketCount( |
1050 "NQE.ExternalEstimateProviderStatus", | 1024 "NQE.ExternalEstimateProviderStatus", |
1051 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); | 1025 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); |
1052 histogram_tester.ExpectBucketCount( | 1026 histogram_tester.ExpectBucketCount( |
1053 "NQE.ExternalEstimateProviderStatus", | 1027 "NQE.ExternalEstimateProviderStatus", |
1054 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); | 1028 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); |
1055 histogram_tester.ExpectBucketCount( | 1029 histogram_tester.ExpectBucketCount( |
1056 "NQE.ExternalEstimateProviderStatus", | 1030 "NQE.ExternalEstimateProviderStatus", |
1057 3 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL */, 1); | 1031 4 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK */, 1); |
1058 histogram_tester.ExpectBucketCount( | 1032 histogram_tester.ExpectBucketCount( |
1059 "NQE.ExternalEstimateProviderStatus", | 1033 "NQE.ExternalEstimateProviderStatus", |
1060 5 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE */, 1); | 1034 5 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE */, 1); |
1061 histogram_tester.ExpectBucketCount( | 1035 histogram_tester.ExpectBucketCount( |
1062 "NQE.ExternalEstimateProviderStatus", | 1036 "NQE.ExternalEstimateProviderStatus", |
1063 6 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE */, | 1037 6 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE */, |
1064 1); | 1038 1); |
1065 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProvider.RTT", 1); | 1039 histogram_tester.ExpectUniqueSample("NQE.ExternalEstimateProvider.RTT", 1, 1); |
1066 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProvider.RTT", 1, 1); | 1040 histogram_tester.ExpectUniqueSample( |
1067 | |
1068 histogram_tester.ExpectTotalCount( | |
1069 "NQE.ExternalEstimateProvider.DownlinkBandwidth", 1); | |
1070 histogram_tester.ExpectBucketCount( | |
1071 "NQE.ExternalEstimateProvider.DownlinkBandwidth", 100, 1); | 1041 "NQE.ExternalEstimateProvider.DownlinkBandwidth", 100, 1); |
1072 | 1042 |
1073 EXPECT_EQ( | 1043 EXPECT_EQ(1U, test_external_estimate_provider->update_count()); |
1074 1U, test_external_estimate_provider->get_time_since_last_update_count()); | |
1075 EXPECT_EQ(1U, test_external_estimate_provider->get_rtt_count()); | |
1076 EXPECT_EQ( | |
1077 1U, | |
1078 test_external_estimate_provider->get_downstream_throughput_kbps_count()); | |
1079 | 1044 |
1080 // Change network type to WiFi. Number of queries to External estimate | 1045 // Change network type to WiFi. Number of queries to External estimate |
1081 // provider must increment. | 1046 // provider must increment. |
1082 estimator.SimulateNetworkChangeTo( | 1047 estimator.SimulateNetworkChangeTo( |
1083 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 1048 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
1084 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); | 1049 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); |
1085 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 1050 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
1086 EXPECT_EQ( | 1051 EXPECT_EQ(2U, test_external_estimate_provider->update_count()); |
1087 2U, test_external_estimate_provider->get_time_since_last_update_count()); | |
1088 EXPECT_EQ(2U, test_external_estimate_provider->get_rtt_count()); | |
1089 EXPECT_EQ( | |
1090 2U, | |
1091 test_external_estimate_provider->get_downstream_throughput_kbps_count()); | |
1092 | 1052 |
1093 // Change network type to 2G. Number of queries to External estimate provider | 1053 test_external_estimate_provider->set_should_notify_delegate(false); |
1094 // must increment. | |
1095 estimator.SimulateNetworkChangeTo( | |
1096 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); | |
1097 EXPECT_EQ( | |
1098 3U, test_external_estimate_provider->get_time_since_last_update_count()); | |
1099 EXPECT_EQ(3U, test_external_estimate_provider->get_rtt_count()); | |
1100 EXPECT_EQ( | |
1101 3U, | |
1102 test_external_estimate_provider->get_downstream_throughput_kbps_count()); | |
1103 | |
1104 // Set the external estimate as old. Network Quality estimator should request | |
1105 // an update on connection type change. | |
1106 EXPECT_EQ(0U, test_external_estimate_provider->update_count()); | |
1107 test_external_estimate_provider->set_time_since_last_update( | |
1108 base::TimeDelta::Max()); | |
1109 | |
1110 estimator.SimulateNetworkChangeTo( | 1054 estimator.SimulateNetworkChangeTo( |
1111 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); | 1055 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); |
1112 EXPECT_EQ( | 1056 EXPECT_EQ(3U, test_external_estimate_provider->update_count()); |
1113 4U, test_external_estimate_provider->get_time_since_last_update_count()); | |
1114 EXPECT_EQ(3U, test_external_estimate_provider->get_rtt_count()); | |
1115 EXPECT_EQ( | |
1116 3U, | |
1117 test_external_estimate_provider->get_downstream_throughput_kbps_count()); | |
1118 EXPECT_EQ(1U, test_external_estimate_provider->update_count()); | |
1119 | |
1120 // Estimates are unavailable because external estimate provider never | 1057 // Estimates are unavailable because external estimate provider never |
1121 // notifies network quality estimator of the updated estimates. | 1058 // notifies network quality estimator of the updated estimates. |
1122 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); | 1059 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); |
1123 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 1060 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
1124 } | 1061 } |
1125 | 1062 |
1126 // Tests if the estimate from the external estimate provider is merged with the | 1063 // Tests if the estimate from the external estimate provider is merged with the |
1127 // observations collected from the HTTP requests. | 1064 // observations collected from the HTTP requests. |
1128 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProviderMergeEstimates) { | 1065 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProviderMergeEstimates) { |
1129 const base::TimeDelta external_estimate_provider_rtt = | 1066 const base::TimeDelta external_estimate_provider_rtt = |
1130 base::TimeDelta::FromMilliseconds(10 * 1000); | 1067 base::TimeDelta::FromMilliseconds(10 * 1000); |
1131 const int32_t external_estimate_provider_downstream_throughput = 100 * 1000; | 1068 const int32_t external_estimate_provider_downstream_throughput = 100 * 1000; |
1132 TestExternalEstimateProvider* test_external_estimate_provider = | 1069 TestExternalEstimateProvider* test_external_estimate_provider = |
1133 new TestExternalEstimateProvider( | 1070 new TestExternalEstimateProvider( |
1134 external_estimate_provider_rtt, | 1071 external_estimate_provider_rtt, |
1135 external_estimate_provider_downstream_throughput); | 1072 external_estimate_provider_downstream_throughput); |
1136 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( | 1073 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( |
1137 test_external_estimate_provider); | 1074 test_external_estimate_provider); |
1138 | 1075 |
1139 std::map<std::string, std::string> variation_params; | 1076 std::map<std::string, std::string> variation_params; |
1140 TestNetworkQualityEstimator estimator(variation_params, | 1077 TestNetworkQualityEstimator estimator(variation_params, |
1141 std::move(external_estimate_provider)); | 1078 std::move(external_estimate_provider)); |
| 1079 estimator.SimulateNetworkChangeTo(net::NetworkChangeNotifier::CONNECTION_WIFI, |
| 1080 "test"); |
1142 | 1081 |
1143 base::TimeDelta rtt; | 1082 base::TimeDelta rtt; |
1144 // Estimate provided by network quality estimator should match the estimate | 1083 // Estimate provided by network quality estimator should match the estimate |
1145 // provided by external estimate provider. | 1084 // provided by external estimate provider. |
1146 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); | 1085 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); |
1147 EXPECT_EQ(external_estimate_provider_rtt, rtt); | 1086 EXPECT_EQ(external_estimate_provider_rtt, rtt); |
1148 | 1087 |
1149 int32_t kbps; | 1088 int32_t kbps; |
1150 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 1089 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
1151 EXPECT_EQ(external_estimate_provider_downstream_throughput, kbps); | 1090 EXPECT_EQ(external_estimate_provider_downstream_throughput, kbps); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 histogram_tester.ExpectBucketCount("NQE.TransportRTT.Percentile50.Unknown", | 1301 histogram_tester.ExpectBucketCount("NQE.TransportRTT.Percentile50.Unknown", |
1363 rtt.InMilliseconds(), 1); | 1302 rtt.InMilliseconds(), 1); |
1364 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile10.Unknown", 1); | 1303 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile10.Unknown", 1); |
1365 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 1); | 1304 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 1); |
1366 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); | 1305 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); |
1367 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", | 1306 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", |
1368 1); | 1307 1); |
1369 } | 1308 } |
1370 | 1309 |
1371 } // namespace net | 1310 } // namespace net |
OLD | NEW |