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 <stdint.h> | 7 #include <stdint.h> |
8 | |
9 #include <limits> | 8 #include <limits> |
10 #include <map> | 9 #include <map> |
| 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/metrics/histogram_samples.h" | 17 #include "base/metrics/histogram_samples.h" |
18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/test/histogram_tester.h" | 20 #include "base/test/histogram_tester.h" |
(...skipping 11 matching lines...) Expand all Loading... |
32 #include "url/gurl.h" | 32 #include "url/gurl.h" |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 // Helps in setting the current network type and id. | 36 // Helps in setting the current network type and id. |
37 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { | 37 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { |
38 public: | 38 public: |
39 TestNetworkQualityEstimator( | 39 TestNetworkQualityEstimator( |
40 const std::map<std::string, std::string>& variation_params, | 40 const std::map<std::string, std::string>& variation_params, |
41 scoped_ptr<net::ExternalEstimateProvider> external_estimate_provider) | 41 scoped_ptr<net::ExternalEstimateProvider> external_estimate_provider) |
42 : NetworkQualityEstimator(external_estimate_provider.Pass(), | 42 : NetworkQualityEstimator(std::move(external_estimate_provider), |
43 variation_params, | 43 variation_params, |
44 true, | 44 true, |
45 true) { | 45 true) { |
46 // Set up embedded test server. | 46 // Set up embedded test server. |
47 embedded_test_server_.ServeFilesFromDirectory( | 47 embedded_test_server_.ServeFilesFromDirectory( |
48 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 48 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
49 EXPECT_TRUE(embedded_test_server_.Start()); | 49 EXPECT_TRUE(embedded_test_server_.Start()); |
50 embedded_test_server_.RegisterRequestHandler(base::Bind( | 50 embedded_test_server_.RegisterRequestHandler(base::Bind( |
51 &TestNetworkQualityEstimator::HandleRequest, base::Unretained(this))); | 51 &TestNetworkQualityEstimator::HandleRequest, base::Unretained(this))); |
52 } | 52 } |
(...skipping 16 matching lines...) Expand all Loading... |
69 } | 69 } |
70 | 70 |
71 // Called by embedded server when a HTTP request is received. | 71 // Called by embedded server when a HTTP request is received. |
72 scoped_ptr<net::test_server::HttpResponse> HandleRequest( | 72 scoped_ptr<net::test_server::HttpResponse> HandleRequest( |
73 const net::test_server::HttpRequest& request) { | 73 const net::test_server::HttpRequest& request) { |
74 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 74 scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
75 new net::test_server::BasicHttpResponse()); | 75 new net::test_server::BasicHttpResponse()); |
76 http_response->set_code(net::HTTP_OK); | 76 http_response->set_code(net::HTTP_OK); |
77 http_response->set_content("hello"); | 77 http_response->set_content("hello"); |
78 http_response->set_content_type("text/plain"); | 78 http_response->set_content_type("text/plain"); |
79 return http_response.Pass(); | 79 return std::move(http_response); |
80 } | 80 } |
81 | 81 |
82 // Returns a GURL hosted at embedded test server. | 82 // Returns a GURL hosted at embedded test server. |
83 const GURL GetEchoURL() const { | 83 const GURL GetEchoURL() const { |
84 return embedded_test_server_.GetURL("/echo.html"); | 84 return embedded_test_server_.GetURL("/echo.html"); |
85 } | 85 } |
86 | 86 |
87 using NetworkQualityEstimator::ReadCachedNetworkQualityEstimate; | 87 using NetworkQualityEstimator::ReadCachedNetworkQualityEstimate; |
88 using NetworkQualityEstimator::OnConnectionTypeChanged; | 88 using NetworkQualityEstimator::OnConnectionTypeChanged; |
89 | 89 |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 | 801 |
802 // Tests if the RTT value from external estimate provider is discarded if the | 802 // Tests if the RTT value from external estimate provider is discarded if the |
803 // external estimate provider is invalid. | 803 // external estimate provider is invalid. |
804 TEST(NetworkQualityEstimatorTest, InvalidExternalEstimateProvider) { | 804 TEST(NetworkQualityEstimatorTest, InvalidExternalEstimateProvider) { |
805 InvalidExternalEstimateProvider* invalid_external_estimate_provider = | 805 InvalidExternalEstimateProvider* invalid_external_estimate_provider = |
806 new InvalidExternalEstimateProvider(); | 806 new InvalidExternalEstimateProvider(); |
807 scoped_ptr<ExternalEstimateProvider> external_estimate_provider( | 807 scoped_ptr<ExternalEstimateProvider> external_estimate_provider( |
808 invalid_external_estimate_provider); | 808 invalid_external_estimate_provider); |
809 | 809 |
810 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), | 810 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), |
811 external_estimate_provider.Pass()); | 811 std::move(external_estimate_provider)); |
812 | 812 |
813 base::TimeDelta rtt; | 813 base::TimeDelta rtt; |
814 int32_t kbps; | 814 int32_t kbps; |
815 EXPECT_EQ(1U, invalid_external_estimate_provider->get_rtt_count()); | 815 EXPECT_EQ(1U, invalid_external_estimate_provider->get_rtt_count()); |
816 EXPECT_FALSE(estimator.GetRTTEstimate(&rtt)); | 816 EXPECT_FALSE(estimator.GetRTTEstimate(&rtt)); |
817 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 817 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
818 } | 818 } |
819 | 819 |
820 class TestExternalEstimateProvider : public ExternalEstimateProvider { | 820 class TestExternalEstimateProvider : public ExternalEstimateProvider { |
821 public: | 821 public: |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 // Tests if the external estimate provider is called in the constructor and | 899 // Tests if the external estimate provider is called in the constructor and |
900 // on network change notification. | 900 // on network change notification. |
901 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProvider) { | 901 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProvider) { |
902 TestExternalEstimateProvider* test_external_estimate_provider = | 902 TestExternalEstimateProvider* test_external_estimate_provider = |
903 new TestExternalEstimateProvider(base::TimeDelta::FromMilliseconds(1), | 903 new TestExternalEstimateProvider(base::TimeDelta::FromMilliseconds(1), |
904 100); | 904 100); |
905 scoped_ptr<ExternalEstimateProvider> external_estimate_provider( | 905 scoped_ptr<ExternalEstimateProvider> external_estimate_provider( |
906 test_external_estimate_provider); | 906 test_external_estimate_provider); |
907 std::map<std::string, std::string> variation_params; | 907 std::map<std::string, std::string> variation_params; |
908 TestNetworkQualityEstimator estimator(variation_params, | 908 TestNetworkQualityEstimator estimator(variation_params, |
909 external_estimate_provider.Pass()); | 909 std::move(external_estimate_provider)); |
910 | 910 |
911 base::TimeDelta rtt; | 911 base::TimeDelta rtt; |
912 int32_t kbps; | 912 int32_t kbps; |
913 EXPECT_TRUE(estimator.GetRTTEstimate(&rtt)); | 913 EXPECT_TRUE(estimator.GetRTTEstimate(&rtt)); |
914 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 914 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
915 | 915 |
916 EXPECT_EQ( | 916 EXPECT_EQ( |
917 1U, test_external_estimate_provider->get_time_since_last_update_count()); | 917 1U, test_external_estimate_provider->get_time_since_last_update_count()); |
918 EXPECT_EQ(1U, test_external_estimate_provider->get_rtt_count()); | 918 EXPECT_EQ(1U, test_external_estimate_provider->get_rtt_count()); |
919 EXPECT_EQ( | 919 EXPECT_EQ( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 const int32_t external_estimate_provider_downstream_throughput = 100; | 974 const int32_t external_estimate_provider_downstream_throughput = 100; |
975 TestExternalEstimateProvider* test_external_estimate_provider = | 975 TestExternalEstimateProvider* test_external_estimate_provider = |
976 new TestExternalEstimateProvider( | 976 new TestExternalEstimateProvider( |
977 external_estimate_provider_rtt, | 977 external_estimate_provider_rtt, |
978 external_estimate_provider_downstream_throughput); | 978 external_estimate_provider_downstream_throughput); |
979 scoped_ptr<ExternalEstimateProvider> external_estimate_provider( | 979 scoped_ptr<ExternalEstimateProvider> external_estimate_provider( |
980 test_external_estimate_provider); | 980 test_external_estimate_provider); |
981 | 981 |
982 std::map<std::string, std::string> variation_params; | 982 std::map<std::string, std::string> variation_params; |
983 TestNetworkQualityEstimator estimator(variation_params, | 983 TestNetworkQualityEstimator estimator(variation_params, |
984 external_estimate_provider.Pass()); | 984 std::move(external_estimate_provider)); |
985 | 985 |
986 base::TimeDelta rtt; | 986 base::TimeDelta rtt; |
987 // Estimate provided by network quality estimator should match the estimate | 987 // Estimate provided by network quality estimator should match the estimate |
988 // provided by external estimate provider. | 988 // provided by external estimate provider. |
989 EXPECT_TRUE(estimator.GetRTTEstimate(&rtt)); | 989 EXPECT_TRUE(estimator.GetRTTEstimate(&rtt)); |
990 EXPECT_EQ(external_estimate_provider_rtt, rtt); | 990 EXPECT_EQ(external_estimate_provider_rtt, rtt); |
991 | 991 |
992 int32_t kbps; | 992 int32_t kbps; |
993 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 993 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
994 EXPECT_EQ(external_estimate_provider_downstream_throughput, kbps); | 994 EXPECT_EQ(external_estimate_provider_downstream_throughput, kbps); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 | 1074 |
1075 EXPECT_EQ(4U, rtt_observer.observations().size()); | 1075 EXPECT_EQ(4U, rtt_observer.observations().size()); |
1076 EXPECT_EQ(2U, throughput_observer.observations().size()); | 1076 EXPECT_EQ(2U, throughput_observer.observations().size()); |
1077 | 1077 |
1078 EXPECT_EQ(tcp_rtt.InMilliseconds(), rtt_observer.observations().at(2).rtt_ms); | 1078 EXPECT_EQ(tcp_rtt.InMilliseconds(), rtt_observer.observations().at(2).rtt_ms); |
1079 EXPECT_EQ(quic_rtt.InMilliseconds(), | 1079 EXPECT_EQ(quic_rtt.InMilliseconds(), |
1080 rtt_observer.observations().at(3).rtt_ms); | 1080 rtt_observer.observations().at(3).rtt_ms); |
1081 } | 1081 } |
1082 | 1082 |
1083 } // namespace net | 1083 } // namespace net |
OLD | NEW |