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 |
8 #include <limits> | 9 #include <limits> |
9 #include <map> | 10 #include <map> |
| 11 #include <string> |
10 #include <utility> | 12 #include <utility> |
11 #include <vector> | 13 #include <vector> |
12 | 14 |
13 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 16 #include "base/logging.h" |
15 #include "base/macros.h" | 17 #include "base/macros.h" |
16 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
17 #include "base/metrics/histogram_samples.h" | 19 #include "base/metrics/histogram_samples.h" |
18 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
19 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
20 #include "base/test/histogram_tester.h" | 22 #include "base/test/histogram_tester.h" |
21 #include "base/time/time.h" | 23 #include "base/time/time.h" |
22 #include "build/build_config.h" | 24 #include "build/build_config.h" |
23 #include "net/base/external_estimate_provider.h" | 25 #include "net/base/external_estimate_provider.h" |
24 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
25 #include "net/base/network_change_notifier.h" | 27 #include "net/base/network_change_notifier.h" |
| 28 #include "net/base/socket_performance_watcher.h" |
| 29 #include "net/base/socket_performance_watcher_factory.h" |
26 #include "net/http/http_status_code.h" | 30 #include "net/http/http_status_code.h" |
27 #include "net/test/embedded_test_server/embedded_test_server.h" | 31 #include "net/test/embedded_test_server/embedded_test_server.h" |
28 #include "net/test/embedded_test_server/http_request.h" | 32 #include "net/test/embedded_test_server/http_request.h" |
29 #include "net/test/embedded_test_server/http_response.h" | 33 #include "net/test/embedded_test_server/http_response.h" |
| 34 #include "net/url_request/url_request.h" |
30 #include "net/url_request/url_request_test_util.h" | 35 #include "net/url_request/url_request_test_util.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "url/gurl.h" | 37 #include "url/gurl.h" |
33 | 38 |
34 namespace { | 39 namespace { |
35 | 40 |
36 // Helps in setting the current network type and id. | 41 // Helps in setting the current network type and id. |
37 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { | 42 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { |
38 public: | 43 public: |
39 TestNetworkQualityEstimator( | 44 TestNetworkQualityEstimator( |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 request->Start(); | 1069 request->Start(); |
1065 base::RunLoop().Run(); | 1070 base::RunLoop().Run(); |
1066 | 1071 |
1067 scoped_ptr<URLRequest> request2(context.CreateRequest( | 1072 scoped_ptr<URLRequest> request2(context.CreateRequest( |
1068 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1073 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
1069 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); | 1074 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); |
1070 request2->Start(); | 1075 request2->Start(); |
1071 base::RunLoop().Run(); | 1076 base::RunLoop().Run(); |
1072 | 1077 |
1073 // Both RTT and downstream throughput should be updated. | 1078 // Both RTT and downstream throughput should be updated. |
1074 EXPECT_NE(NetworkQualityEstimator::InvalidRTT(), | 1079 base::TimeDelta rtt; |
1075 estimator.GetURLRequestRTTEstimateInternal(base::TimeTicks(), 100)); | 1080 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); |
1076 EXPECT_NE(NetworkQualityEstimator::kInvalidThroughput, | 1081 |
1077 estimator.GetDownlinkThroughputKbpsEstimateInternal( | 1082 int32_t throughput; |
1078 base::TimeTicks(), 100)); | 1083 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&throughput)); |
1079 | 1084 |
1080 EXPECT_EQ(2U, rtt_observer.observations().size()); | 1085 EXPECT_EQ(2U, rtt_observer.observations().size()); |
1081 EXPECT_EQ(2U, throughput_observer.observations().size()); | 1086 EXPECT_EQ(2U, throughput_observer.observations().size()); |
1082 for (auto observation : rtt_observer.observations()) { | 1087 for (auto observation : rtt_observer.observations()) { |
1083 EXPECT_LE(0, observation.rtt_ms); | 1088 EXPECT_LE(0, observation.rtt_ms); |
1084 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); | 1089 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); |
1085 EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source); | 1090 EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source); |
1086 } | 1091 } |
1087 for (auto observation : throughput_observer.observations()) { | 1092 for (auto observation : throughput_observer.observations()) { |
1088 EXPECT_LE(0, observation.throughput_kbps); | 1093 EXPECT_LE(0, observation.throughput_kbps); |
1089 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); | 1094 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); |
1090 EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source); | 1095 EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source); |
1091 } | 1096 } |
1092 | 1097 |
1093 // Verify that observations from TCP and QUIC are passed on to the observers. | 1098 // Verify that observations from TCP and QUIC are passed on to the observers. |
1094 base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1)); | 1099 base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1)); |
1095 base::TimeDelta quic_rtt(base::TimeDelta::FromMilliseconds(2)); | 1100 base::TimeDelta quic_rtt(base::TimeDelta::FromMilliseconds(2)); |
1096 | 1101 |
1097 scoped_ptr<SocketPerformanceWatcher> tcp_watcher = | 1102 scoped_ptr<SocketPerformanceWatcher> tcp_watcher = |
1098 estimator.CreateSocketPerformanceWatcher( | 1103 estimator.GetSocketPerformanceWatcherFactory() |
1099 SocketPerformanceWatcherFactory::PROTOCOL_TCP); | 1104 ->CreateSocketPerformanceWatcher( |
| 1105 SocketPerformanceWatcherFactory::PROTOCOL_TCP); |
| 1106 |
1100 scoped_ptr<SocketPerformanceWatcher> quic_watcher = | 1107 scoped_ptr<SocketPerformanceWatcher> quic_watcher = |
1101 estimator.CreateSocketPerformanceWatcher( | 1108 estimator.GetSocketPerformanceWatcherFactory() |
1102 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); | 1109 ->CreateSocketPerformanceWatcher( |
| 1110 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); |
| 1111 |
1103 tcp_watcher->OnUpdatedRTTAvailable(tcp_rtt); | 1112 tcp_watcher->OnUpdatedRTTAvailable(tcp_rtt); |
1104 quic_watcher->OnUpdatedRTTAvailable(quic_rtt); | 1113 quic_watcher->OnUpdatedRTTAvailable(quic_rtt); |
1105 | 1114 |
| 1115 base::RunLoop().RunUntilIdle(); |
| 1116 |
1106 EXPECT_EQ(4U, rtt_observer.observations().size()); | 1117 EXPECT_EQ(4U, rtt_observer.observations().size()); |
1107 EXPECT_EQ(2U, throughput_observer.observations().size()); | 1118 EXPECT_EQ(2U, throughput_observer.observations().size()); |
1108 | 1119 |
1109 EXPECT_EQ(tcp_rtt.InMilliseconds(), rtt_observer.observations().at(2).rtt_ms); | 1120 EXPECT_EQ(tcp_rtt.InMilliseconds(), rtt_observer.observations().at(2).rtt_ms); |
1110 EXPECT_EQ(quic_rtt.InMilliseconds(), | 1121 EXPECT_EQ(quic_rtt.InMilliseconds(), |
1111 rtt_observer.observations().at(3).rtt_ms); | 1122 rtt_observer.observations().at(3).rtt_ms); |
1112 } | 1123 } |
1113 | 1124 |
1114 } // namespace net | 1125 } // namespace net |
OLD | NEW |