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/base/network_quality_estimator.h" | 5 #include "net/base/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 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 private: | 832 private: |
| 833 // Keeps track of number of times different functions were called. | 833 // Keeps track of number of times different functions were called. |
| 834 mutable size_t get_rtt_count_; | 834 mutable size_t get_rtt_count_; |
| 835 | 835 |
| 836 DISALLOW_COPY_AND_ASSIGN(InvalidExternalEstimateProvider); | 836 DISALLOW_COPY_AND_ASSIGN(InvalidExternalEstimateProvider); |
| 837 }; | 837 }; |
| 838 | 838 |
| 839 // Tests if the RTT value from external estimate provider is discarded if the | 839 // Tests if the RTT value from external estimate provider is discarded if the |
| 840 // external estimate provider is invalid. | 840 // external estimate provider is invalid. |
| 841 TEST(NetworkQualityEstimatorTest, InvalidExternalEstimateProvider) { | 841 TEST(NetworkQualityEstimatorTest, InvalidExternalEstimateProvider) { |
| 842 base::HistogramTester histogram_tester; | |
| 842 InvalidExternalEstimateProvider* invalid_external_estimate_provider = | 843 InvalidExternalEstimateProvider* invalid_external_estimate_provider = |
| 843 new InvalidExternalEstimateProvider(); | 844 new InvalidExternalEstimateProvider(); |
| 844 scoped_ptr<ExternalEstimateProvider> external_estimate_provider( | 845 scoped_ptr<ExternalEstimateProvider> external_estimate_provider( |
| 845 invalid_external_estimate_provider); | 846 invalid_external_estimate_provider); |
| 846 | 847 |
| 847 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), | 848 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), |
| 848 std::move(external_estimate_provider)); | 849 std::move(external_estimate_provider)); |
| 849 | 850 |
| 850 base::TimeDelta rtt; | 851 base::TimeDelta rtt; |
| 851 int32_t kbps; | 852 int32_t kbps; |
| 852 EXPECT_EQ(1U, invalid_external_estimate_provider->get_rtt_count()); | 853 EXPECT_EQ(1U, invalid_external_estimate_provider->get_rtt_count()); |
| 853 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); | 854 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 854 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 855 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 856 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 3); | |
| 857 | |
| 858 histogram_tester.ExpectBucketCount( | |
| 859 "NQE.ExternalEstimateProviderStatus", | |
| 860 1 /*EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE*/, 1); | |
|
bengr
2016/04/21 22:58:37
nit: Add spaces: /* EXTERNAL...AVAILABLE */, here
tbansal1
2016/04/26 21:25:28
Done.
| |
| 861 histogram_tester.ExpectBucketCount( | |
| 862 "NQE.ExternalEstimateProviderStatus", | |
| 863 2 /*EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED*/, 1); | |
| 864 histogram_tester.ExpectBucketCount( | |
| 865 "NQE.ExternalEstimateProviderStatus", | |
| 866 3 /*EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL*/, 1); | |
| 855 } | 867 } |
| 856 | 868 |
| 857 class TestExternalEstimateProvider : public ExternalEstimateProvider { | 869 class TestExternalEstimateProvider : public ExternalEstimateProvider { |
| 858 public: | 870 public: |
| 859 TestExternalEstimateProvider(base::TimeDelta rtt, | 871 TestExternalEstimateProvider(base::TimeDelta rtt, |
| 860 int32_t downstream_throughput_kbps) | 872 int32_t downstream_throughput_kbps) |
| 861 : rtt_(rtt), | 873 : rtt_(rtt), |
| 862 downstream_throughput_kbps_(downstream_throughput_kbps), | 874 downstream_throughput_kbps_(downstream_throughput_kbps), |
| 863 time_since_last_update_(base::TimeDelta::FromSeconds(1)), | 875 time_since_last_update_(base::TimeDelta::FromSeconds(1)), |
| 864 get_time_since_last_update_count_(0), | 876 get_time_since_last_update_count_(0), |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 929 mutable size_t get_rtt_count_; | 941 mutable size_t get_rtt_count_; |
| 930 mutable size_t get_downstream_throughput_kbps_count_; | 942 mutable size_t get_downstream_throughput_kbps_count_; |
| 931 mutable size_t update_count_; | 943 mutable size_t update_count_; |
| 932 | 944 |
| 933 DISALLOW_COPY_AND_ASSIGN(TestExternalEstimateProvider); | 945 DISALLOW_COPY_AND_ASSIGN(TestExternalEstimateProvider); |
| 934 }; | 946 }; |
| 935 | 947 |
| 936 // Tests if the external estimate provider is called in the constructor and | 948 // Tests if the external estimate provider is called in the constructor and |
| 937 // on network change notification. | 949 // on network change notification. |
| 938 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProvider) { | 950 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProvider) { |
| 951 base::HistogramTester histogram_tester; | |
| 939 TestExternalEstimateProvider* test_external_estimate_provider = | 952 TestExternalEstimateProvider* test_external_estimate_provider = |
| 940 new TestExternalEstimateProvider(base::TimeDelta::FromMilliseconds(1), | 953 new TestExternalEstimateProvider(base::TimeDelta::FromMilliseconds(1), |
| 941 100); | 954 100); |
| 942 scoped_ptr<ExternalEstimateProvider> external_estimate_provider( | 955 scoped_ptr<ExternalEstimateProvider> external_estimate_provider( |
| 943 test_external_estimate_provider); | 956 test_external_estimate_provider); |
| 944 std::map<std::string, std::string> variation_params; | 957 std::map<std::string, std::string> variation_params; |
| 945 TestNetworkQualityEstimator estimator(variation_params, | 958 TestNetworkQualityEstimator estimator(variation_params, |
| 946 std::move(external_estimate_provider)); | 959 std::move(external_estimate_provider)); |
| 947 | 960 |
| 948 base::TimeDelta rtt; | 961 base::TimeDelta rtt; |
| 949 int32_t kbps; | 962 int32_t kbps; |
| 950 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | 963 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 951 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 964 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 952 | 965 |
| 966 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 5); | |
| 967 | |
| 968 histogram_tester.ExpectBucketCount( | |
| 969 "NQE.ExternalEstimateProviderStatus", | |
| 970 1 /*EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE*/, 1); | |
| 971 histogram_tester.ExpectBucketCount( | |
| 972 "NQE.ExternalEstimateProviderStatus", | |
| 973 2 /*EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED*/, 1); | |
| 974 histogram_tester.ExpectBucketCount( | |
| 975 "NQE.ExternalEstimateProviderStatus", | |
| 976 3 /*EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL*/, 1); | |
| 977 histogram_tester.ExpectBucketCount( | |
| 978 "NQE.ExternalEstimateProviderStatus", | |
| 979 5 /*EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE*/, 1); | |
| 980 histogram_tester.ExpectBucketCount( | |
| 981 "NQE.ExternalEstimateProviderStatus", | |
| 982 6 /*EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE*/, 1); | |
| 983 | |
| 953 EXPECT_EQ( | 984 EXPECT_EQ( |
| 954 1U, test_external_estimate_provider->get_time_since_last_update_count()); | 985 1U, test_external_estimate_provider->get_time_since_last_update_count()); |
| 955 EXPECT_EQ(1U, test_external_estimate_provider->get_rtt_count()); | 986 EXPECT_EQ(1U, test_external_estimate_provider->get_rtt_count()); |
| 956 EXPECT_EQ( | 987 EXPECT_EQ( |
| 957 1U, | 988 1U, |
| 958 test_external_estimate_provider->get_downstream_throughput_kbps_count()); | 989 test_external_estimate_provider->get_downstream_throughput_kbps_count()); |
| 959 | 990 |
| 960 // Change network type to WiFi. Number of queries to External estimate | 991 // Change network type to WiFi. Number of queries to External estimate |
| 961 // provider must increment. | 992 // provider must increment. |
| 962 estimator.SimulateNetworkChangeTo( | 993 estimator.SimulateNetworkChangeTo( |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1172 } | 1203 } |
| 1173 // At least one notification should be received per socket performance | 1204 // At least one notification should be received per socket performance |
| 1174 // watcher. | 1205 // watcher. |
| 1175 EXPECT_LE(1U, after_count_tcp_rtt_observations - | 1206 EXPECT_LE(1U, after_count_tcp_rtt_observations - |
| 1176 before_count_tcp_rtt_observations) | 1207 before_count_tcp_rtt_observations) |
| 1177 << i; | 1208 << i; |
| 1178 } | 1209 } |
| 1179 } | 1210 } |
| 1180 | 1211 |
| 1181 } // namespace net | 1212 } // namespace net |
| OLD | NEW |