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 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 test.expected_effective_connection_type, | 914 test.expected_effective_connection_type, |
915 estimator.GetRecentEffectiveConnectionType(test.start_timestamp)); | 915 estimator.GetRecentEffectiveConnectionType(test.start_timestamp)); |
916 } | 916 } |
917 } | 917 } |
918 } | 918 } |
919 | 919 |
920 // An external estimate provider that does not have a valid RTT or throughput | 920 // An external estimate provider that does not have a valid RTT or throughput |
921 // estimate. | 921 // estimate. |
922 class InvalidExternalEstimateProvider : public ExternalEstimateProvider { | 922 class InvalidExternalEstimateProvider : public ExternalEstimateProvider { |
923 public: | 923 public: |
924 InvalidExternalEstimateProvider() | 924 InvalidExternalEstimateProvider() : update_count_(0) {} |
925 : get_rtt_count_(0), get_downstream_throughput_count_(0) {} | |
926 ~InvalidExternalEstimateProvider() override {} | 925 ~InvalidExternalEstimateProvider() override {} |
927 | 926 |
928 // ExternalEstimateProvider implementation: | |
929 bool GetRTT(base::TimeDelta* rtt) const override { | 927 bool GetRTT(base::TimeDelta* rtt) const override { |
930 DCHECK(rtt); | 928 DCHECK(rtt); |
931 get_rtt_count_++; | |
932 return false; | 929 return false; |
933 } | 930 } |
934 | 931 |
935 // ExternalEstimateProvider implementation: | |
936 bool GetDownstreamThroughputKbps( | 932 bool GetDownstreamThroughputKbps( |
937 int32_t* downstream_throughput_kbps) const override { | 933 int32_t* downstream_throughput_kbps) const override { |
938 DCHECK(downstream_throughput_kbps); | 934 DCHECK(downstream_throughput_kbps); |
939 get_downstream_throughput_count_++; | |
940 return false; | 935 return false; |
941 } | 936 } |
942 | 937 |
943 // ExternalEstimateProvider implementation: | |
944 bool GetUpstreamThroughputKbps( | 938 bool GetUpstreamThroughputKbps( |
945 int32_t* upstream_throughput_kbps) const override { | 939 int32_t* upstream_throughput_kbps) const override { |
946 // NetworkQualityEstimator does not support upstream throughput. | 940 // NetworkQualityEstimator does not support upstream throughput. |
947 ADD_FAILURE(); | 941 ADD_FAILURE(); |
948 return false; | 942 return false; |
949 } | 943 } |
950 | 944 |
951 // ExternalEstimateProvider implementation: | |
952 bool GetTimeSinceLastUpdate( | 945 bool GetTimeSinceLastUpdate( |
953 base::TimeDelta* time_since_last_update) const override { | 946 base::TimeDelta* time_since_last_update) const override { |
954 *time_since_last_update = base::TimeDelta::FromMilliseconds(1); | 947 NOTREACHED(); |
955 return true; | 948 return false; |
956 } | 949 } |
957 | 950 |
958 // ExternalEstimateProvider implementation: | |
959 void SetUpdatedEstimateDelegate(UpdatedEstimateDelegate* delegate) override {} | 951 void SetUpdatedEstimateDelegate(UpdatedEstimateDelegate* delegate) override {} |
960 | 952 |
961 // ExternalEstimateProvider implementation: | 953 void Update() const override { update_count_++; } |
962 void Update() const override {} | |
963 | 954 |
964 size_t get_rtt_count() const { return get_rtt_count_; } | 955 size_t update_count() const { return update_count_; } |
965 | |
966 size_t get_downstream_throughput_count() const { | |
967 return get_downstream_throughput_count_; | |
968 } | |
969 | 956 |
970 private: | 957 private: |
971 // Keeps track of number of times different functions were called. | 958 mutable size_t update_count_; |
972 mutable size_t get_rtt_count_; | |
973 mutable size_t get_downstream_throughput_count_; | |
974 | 959 |
975 DISALLOW_COPY_AND_ASSIGN(InvalidExternalEstimateProvider); | 960 DISALLOW_COPY_AND_ASSIGN(InvalidExternalEstimateProvider); |
976 }; | 961 }; |
977 | 962 |
978 // Tests if the RTT value from external estimate provider is discarded if the | 963 // Tests if the RTT value from external estimate provider is discarded if the |
979 // external estimate provider is invalid. | 964 // external estimate provider is invalid. |
980 TEST(NetworkQualityEstimatorTest, InvalidExternalEstimateProvider) { | 965 TEST(NetworkQualityEstimatorTest, InvalidExternalEstimateProvider) { |
981 base::HistogramTester histogram_tester; | 966 base::HistogramTester histogram_tester; |
982 InvalidExternalEstimateProvider* invalid_external_estimate_provider = | 967 InvalidExternalEstimateProvider* invalid_external_estimate_provider = |
983 new InvalidExternalEstimateProvider(); | 968 new InvalidExternalEstimateProvider(); |
984 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( | 969 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( |
985 invalid_external_estimate_provider); | 970 invalid_external_estimate_provider); |
986 | 971 |
987 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), | 972 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), |
988 std::move(external_estimate_provider)); | 973 std::move(external_estimate_provider)); |
| 974 estimator.SimulateNetworkChangeTo(net::NetworkChangeNotifier::CONNECTION_WIFI, |
| 975 "test"); |
989 | 976 |
990 base::TimeDelta rtt; | 977 base::TimeDelta rtt; |
991 int32_t kbps; | 978 int32_t kbps; |
992 EXPECT_EQ(1U, invalid_external_estimate_provider->get_rtt_count()); | 979 EXPECT_EQ(1U, invalid_external_estimate_provider->update_count()); |
993 EXPECT_EQ( | |
994 1U, | |
995 invalid_external_estimate_provider->get_downstream_throughput_count()); | |
996 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); | 980 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); |
997 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 981 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
998 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 3); | 982 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 2); |
999 | 983 |
1000 histogram_tester.ExpectBucketCount( | 984 histogram_tester.ExpectBucketCount( |
1001 "NQE.ExternalEstimateProviderStatus", | 985 "NQE.ExternalEstimateProviderStatus", |
1002 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); | 986 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); |
1003 histogram_tester.ExpectBucketCount( | 987 histogram_tester.ExpectBucketCount( |
1004 "NQE.ExternalEstimateProviderStatus", | 988 "NQE.ExternalEstimateProviderStatus", |
1005 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); | 989 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); |
1006 histogram_tester.ExpectBucketCount( | |
1007 "NQE.ExternalEstimateProviderStatus", | |
1008 3 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL */, 1); | |
1009 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProvider.RTT", 0); | 990 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProvider.RTT", 0); |
1010 histogram_tester.ExpectTotalCount( | 991 histogram_tester.ExpectTotalCount( |
1011 "NQE.ExternalEstimateProvider.DownlinkBandwidth", 0); | 992 "NQE.ExternalEstimateProvider.DownlinkBandwidth", 0); |
1012 } | 993 } |
1013 | 994 |
1014 class TestExternalEstimateProvider : public ExternalEstimateProvider { | 995 class TestExternalEstimateProvider : public ExternalEstimateProvider { |
1015 public: | 996 public: |
1016 TestExternalEstimateProvider(base::TimeDelta rtt, | 997 TestExternalEstimateProvider(base::TimeDelta rtt, |
1017 int32_t downstream_throughput_kbps) | 998 int32_t downstream_throughput_kbps) |
1018 : rtt_(rtt), | 999 : delegate_(nullptr), |
| 1000 should_notify_delegate_(true), |
| 1001 rtt_(rtt), |
1019 downstream_throughput_kbps_(downstream_throughput_kbps), | 1002 downstream_throughput_kbps_(downstream_throughput_kbps), |
1020 time_since_last_update_(base::TimeDelta::FromSeconds(1)), | |
1021 get_time_since_last_update_count_(0), | |
1022 get_rtt_count_(0), | |
1023 get_downstream_throughput_kbps_count_(0), | |
1024 update_count_(0) {} | 1003 update_count_(0) {} |
1025 ~TestExternalEstimateProvider() override {} | 1004 ~TestExternalEstimateProvider() override {} |
1026 | 1005 |
1027 // ExternalEstimateProvider implementation: | |
1028 bool GetRTT(base::TimeDelta* rtt) const override { | 1006 bool GetRTT(base::TimeDelta* rtt) const override { |
1029 *rtt = rtt_; | 1007 NOTREACHED(); |
1030 get_rtt_count_++; | |
1031 return true; | 1008 return true; |
1032 } | 1009 } |
1033 | 1010 |
1034 // ExternalEstimateProvider implementation: | |
1035 bool GetDownstreamThroughputKbps( | 1011 bool GetDownstreamThroughputKbps( |
1036 int32_t* downstream_throughput_kbps) const override { | 1012 int32_t* downstream_throughput_kbps) const override { |
1037 *downstream_throughput_kbps = downstream_throughput_kbps_; | 1013 NOTREACHED(); |
1038 get_downstream_throughput_kbps_count_++; | |
1039 return true; | 1014 return true; |
1040 } | 1015 } |
1041 | 1016 |
1042 // ExternalEstimateProvider implementation: | |
1043 bool GetUpstreamThroughputKbps( | 1017 bool GetUpstreamThroughputKbps( |
1044 int32_t* upstream_throughput_kbps) const override { | 1018 int32_t* upstream_throughput_kbps) const override { |
1045 // NetworkQualityEstimator does not support upstream throughput. | 1019 NOTREACHED(); |
1046 ADD_FAILURE(); | |
1047 return false; | 1020 return false; |
1048 } | 1021 } |
1049 | 1022 |
1050 // ExternalEstimateProvider implementation: | |
1051 bool GetTimeSinceLastUpdate( | 1023 bool GetTimeSinceLastUpdate( |
1052 base::TimeDelta* time_since_last_update) const override { | 1024 base::TimeDelta* time_since_last_update) const override { |
1053 *time_since_last_update = time_since_last_update_; | 1025 NOTREACHED(); |
1054 get_time_since_last_update_count_++; | |
1055 return true; | 1026 return true; |
1056 } | 1027 } |
1057 | 1028 |
1058 // ExternalEstimateProvider implementation: | 1029 void SetUpdatedEstimateDelegate(UpdatedEstimateDelegate* delegate) override { |
1059 void SetUpdatedEstimateDelegate(UpdatedEstimateDelegate* delegate) override {} | 1030 delegate_ = delegate; |
1060 | |
1061 // ExternalEstimateProvider implementation: | |
1062 void Update() const override { update_count_++; } | |
1063 | |
1064 void set_time_since_last_update(base::TimeDelta time_since_last_update) { | |
1065 time_since_last_update_ = time_since_last_update; | |
1066 } | 1031 } |
1067 | 1032 |
1068 size_t get_time_since_last_update_count() const { | 1033 void set_should_notify_delegate(bool should_notify_delegate) { |
1069 return get_time_since_last_update_count_; | 1034 should_notify_delegate_ = should_notify_delegate; |
1070 } | 1035 } |
1071 size_t get_rtt_count() const { return get_rtt_count_; } | 1036 |
1072 size_t get_downstream_throughput_kbps_count() const { | 1037 void Update() const override { |
1073 return get_downstream_throughput_kbps_count_; | 1038 update_count_++; |
| 1039 if (!should_notify_delegate_) |
| 1040 return; |
| 1041 delegate_->OnUpdatedEstimateAvailable(rtt_, downstream_throughput_kbps_, |
| 1042 -1); |
1074 } | 1043 } |
| 1044 |
1075 size_t update_count() const { return update_count_; } | 1045 size_t update_count() const { return update_count_; } |
1076 | 1046 |
1077 private: | 1047 private: |
| 1048 UpdatedEstimateDelegate* delegate_; |
| 1049 |
| 1050 bool should_notify_delegate_; |
| 1051 |
1078 // RTT and downstream throughput estimates. | 1052 // RTT and downstream throughput estimates. |
1079 const base::TimeDelta rtt_; | 1053 const base::TimeDelta rtt_; |
1080 const int32_t downstream_throughput_kbps_; | 1054 const int32_t downstream_throughput_kbps_; |
1081 | 1055 |
1082 base::TimeDelta time_since_last_update_; | |
1083 | |
1084 // Keeps track of number of times different functions were called. | |
1085 mutable size_t get_time_since_last_update_count_; | |
1086 mutable size_t get_rtt_count_; | |
1087 mutable size_t get_downstream_throughput_kbps_count_; | |
1088 mutable size_t update_count_; | 1056 mutable size_t update_count_; |
1089 | 1057 |
1090 DISALLOW_COPY_AND_ASSIGN(TestExternalEstimateProvider); | 1058 DISALLOW_COPY_AND_ASSIGN(TestExternalEstimateProvider); |
1091 }; | 1059 }; |
1092 | 1060 |
1093 // Tests if the external estimate provider is called in the constructor and | 1061 // Tests if the external estimate provider is called in the constructor and |
1094 // on network change notification. | 1062 // on network change notification. |
1095 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProvider) { | 1063 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProvider) { |
1096 base::HistogramTester histogram_tester; | 1064 base::HistogramTester histogram_tester; |
| 1065 const base::TimeDelta external_estimate_provider_rtt = |
| 1066 base::TimeDelta::FromMilliseconds(1); |
| 1067 const int32_t external_estimate_provider_downstream_throughput = 100; |
| 1068 |
1097 TestExternalEstimateProvider* test_external_estimate_provider = | 1069 TestExternalEstimateProvider* test_external_estimate_provider = |
1098 new TestExternalEstimateProvider(base::TimeDelta::FromMilliseconds(1), | 1070 new TestExternalEstimateProvider( |
1099 100); | 1071 external_estimate_provider_rtt, |
| 1072 external_estimate_provider_downstream_throughput); |
1100 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( | 1073 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( |
1101 test_external_estimate_provider); | 1074 test_external_estimate_provider); |
1102 std::map<std::string, std::string> variation_params; | 1075 std::map<std::string, std::string> variation_params; |
1103 TestNetworkQualityEstimator estimator(variation_params, | 1076 TestNetworkQualityEstimator estimator(variation_params, |
1104 std::move(external_estimate_provider)); | 1077 std::move(external_estimate_provider)); |
1105 | 1078 estimator.SimulateNetworkChangeTo(net::NetworkChangeNotifier::CONNECTION_WIFI, |
| 1079 "test"); |
1106 base::TimeDelta rtt; | 1080 base::TimeDelta rtt; |
1107 int32_t kbps; | 1081 int32_t kbps; |
1108 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); | 1082 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); |
1109 EXPECT_FALSE(estimator.GetTransportRTTEstimate(&rtt)); | 1083 EXPECT_FALSE(estimator.GetTransportRTTEstimate(&rtt)); |
1110 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 1084 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
1111 | 1085 |
1112 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 5); | 1086 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 5); |
1113 | 1087 |
1114 histogram_tester.ExpectBucketCount( | 1088 histogram_tester.ExpectBucketCount( |
1115 "NQE.ExternalEstimateProviderStatus", | 1089 "NQE.ExternalEstimateProviderStatus", |
1116 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); | 1090 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); |
1117 histogram_tester.ExpectBucketCount( | 1091 histogram_tester.ExpectBucketCount( |
1118 "NQE.ExternalEstimateProviderStatus", | 1092 "NQE.ExternalEstimateProviderStatus", |
1119 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); | 1093 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); |
1120 histogram_tester.ExpectBucketCount( | 1094 histogram_tester.ExpectBucketCount( |
1121 "NQE.ExternalEstimateProviderStatus", | 1095 "NQE.ExternalEstimateProviderStatus", |
1122 3 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL */, 1); | 1096 4 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK */, 1); |
1123 histogram_tester.ExpectBucketCount( | 1097 histogram_tester.ExpectBucketCount( |
1124 "NQE.ExternalEstimateProviderStatus", | 1098 "NQE.ExternalEstimateProviderStatus", |
1125 5 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE */, 1); | 1099 5 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE */, 1); |
1126 histogram_tester.ExpectBucketCount( | 1100 histogram_tester.ExpectBucketCount( |
1127 "NQE.ExternalEstimateProviderStatus", | 1101 "NQE.ExternalEstimateProviderStatus", |
1128 6 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE */, | 1102 6 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE */, |
1129 1); | 1103 1); |
1130 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProvider.RTT", 1); | 1104 histogram_tester.ExpectUniqueSample("NQE.ExternalEstimateProvider.RTT", 1, 1); |
1131 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProvider.RTT", 1, 1); | 1105 histogram_tester.ExpectUniqueSample( |
1132 | |
1133 histogram_tester.ExpectTotalCount( | |
1134 "NQE.ExternalEstimateProvider.DownlinkBandwidth", 1); | |
1135 histogram_tester.ExpectBucketCount( | |
1136 "NQE.ExternalEstimateProvider.DownlinkBandwidth", 100, 1); | 1106 "NQE.ExternalEstimateProvider.DownlinkBandwidth", 100, 1); |
1137 | 1107 |
1138 EXPECT_EQ( | 1108 EXPECT_EQ(1U, test_external_estimate_provider->update_count()); |
1139 1U, test_external_estimate_provider->get_time_since_last_update_count()); | |
1140 EXPECT_EQ(1U, test_external_estimate_provider->get_rtt_count()); | |
1141 EXPECT_EQ( | |
1142 1U, | |
1143 test_external_estimate_provider->get_downstream_throughput_kbps_count()); | |
1144 | 1109 |
1145 // Change network type to WiFi. Number of queries to External estimate | 1110 // Change network type to WiFi. Number of queries to External estimate |
1146 // provider must increment. | 1111 // provider must increment. |
1147 estimator.SimulateNetworkChangeTo( | 1112 estimator.SimulateNetworkChangeTo( |
1148 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 1113 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
1149 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); | 1114 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); |
1150 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 1115 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
1151 EXPECT_EQ( | 1116 EXPECT_EQ(2U, test_external_estimate_provider->update_count()); |
1152 2U, test_external_estimate_provider->get_time_since_last_update_count()); | |
1153 EXPECT_EQ(2U, test_external_estimate_provider->get_rtt_count()); | |
1154 EXPECT_EQ( | |
1155 2U, | |
1156 test_external_estimate_provider->get_downstream_throughput_kbps_count()); | |
1157 | 1117 |
1158 // Change network type to 2G. Number of queries to External estimate provider | 1118 test_external_estimate_provider->set_should_notify_delegate(false); |
1159 // must increment. | |
1160 estimator.SimulateNetworkChangeTo( | |
1161 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); | |
1162 EXPECT_EQ( | |
1163 3U, test_external_estimate_provider->get_time_since_last_update_count()); | |
1164 EXPECT_EQ(3U, test_external_estimate_provider->get_rtt_count()); | |
1165 EXPECT_EQ( | |
1166 3U, | |
1167 test_external_estimate_provider->get_downstream_throughput_kbps_count()); | |
1168 | |
1169 // Set the external estimate as old. Network Quality estimator should request | |
1170 // an update on connection type change. | |
1171 EXPECT_EQ(0U, test_external_estimate_provider->update_count()); | |
1172 test_external_estimate_provider->set_time_since_last_update( | |
1173 base::TimeDelta::Max()); | |
1174 | |
1175 estimator.SimulateNetworkChangeTo( | 1119 estimator.SimulateNetworkChangeTo( |
1176 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); | 1120 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); |
1177 EXPECT_EQ( | 1121 EXPECT_EQ(3U, test_external_estimate_provider->update_count()); |
1178 4U, test_external_estimate_provider->get_time_since_last_update_count()); | |
1179 EXPECT_EQ(3U, test_external_estimate_provider->get_rtt_count()); | |
1180 EXPECT_EQ( | |
1181 3U, | |
1182 test_external_estimate_provider->get_downstream_throughput_kbps_count()); | |
1183 EXPECT_EQ(1U, test_external_estimate_provider->update_count()); | |
1184 | |
1185 // Estimates are unavailable because external estimate provider never | 1122 // Estimates are unavailable because external estimate provider never |
1186 // notifies network quality estimator of the updated estimates. | 1123 // notifies network quality estimator of the updated estimates. |
1187 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); | 1124 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); |
1188 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 1125 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
1189 } | 1126 } |
1190 | 1127 |
1191 // Tests if the estimate from the external estimate provider is merged with the | 1128 // Tests if the estimate from the external estimate provider is merged with the |
1192 // observations collected from the HTTP requests. | 1129 // observations collected from the HTTP requests. |
1193 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProviderMergeEstimates) { | 1130 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProviderMergeEstimates) { |
1194 const base::TimeDelta external_estimate_provider_rtt = | 1131 const base::TimeDelta external_estimate_provider_rtt = |
1195 base::TimeDelta::FromMilliseconds(10 * 1000); | 1132 base::TimeDelta::FromMilliseconds(10 * 1000); |
1196 const int32_t external_estimate_provider_downstream_throughput = 100 * 1000; | 1133 const int32_t external_estimate_provider_downstream_throughput = 100 * 1000; |
1197 TestExternalEstimateProvider* test_external_estimate_provider = | 1134 TestExternalEstimateProvider* test_external_estimate_provider = |
1198 new TestExternalEstimateProvider( | 1135 new TestExternalEstimateProvider( |
1199 external_estimate_provider_rtt, | 1136 external_estimate_provider_rtt, |
1200 external_estimate_provider_downstream_throughput); | 1137 external_estimate_provider_downstream_throughput); |
1201 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( | 1138 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( |
1202 test_external_estimate_provider); | 1139 test_external_estimate_provider); |
1203 | 1140 |
1204 std::map<std::string, std::string> variation_params; | 1141 std::map<std::string, std::string> variation_params; |
1205 TestNetworkQualityEstimator estimator(variation_params, | 1142 TestNetworkQualityEstimator estimator(variation_params, |
1206 std::move(external_estimate_provider)); | 1143 std::move(external_estimate_provider)); |
| 1144 estimator.SimulateNetworkChangeTo(net::NetworkChangeNotifier::CONNECTION_WIFI, |
| 1145 "test"); |
1207 | 1146 |
1208 base::TimeDelta rtt; | 1147 base::TimeDelta rtt; |
1209 // Estimate provided by network quality estimator should match the estimate | 1148 // Estimate provided by network quality estimator should match the estimate |
1210 // provided by external estimate provider. | 1149 // provided by external estimate provider. |
1211 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); | 1150 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); |
1212 EXPECT_EQ(external_estimate_provider_rtt, rtt); | 1151 EXPECT_EQ(external_estimate_provider_rtt, rtt); |
1213 | 1152 |
1214 int32_t kbps; | 1153 int32_t kbps; |
1215 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 1154 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
1216 EXPECT_EQ(external_estimate_provider_downstream_throughput, kbps); | 1155 EXPECT_EQ(external_estimate_provider_downstream_throughput, kbps); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1433 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); | 1372 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); |
1434 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", | 1373 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", |
1435 1); | 1374 1); |
1436 | 1375 |
1437 // Verify that metrics are logged correctly on main-frame requests. | 1376 // Verify that metrics are logged correctly on main-frame requests. |
1438 histogram_tester.ExpectTotalCount( | 1377 histogram_tester.ExpectTotalCount( |
1439 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", num_requests); | 1378 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", num_requests); |
1440 } | 1379 } |
1441 | 1380 |
1442 } // namespace net | 1381 } // namespace net |
OLD | NEW |