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" |
26 #include "net/http/http_status_code.h" | 28 #include "net/http/http_status_code.h" |
27 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
28 #include "net/test/embedded_test_server/http_request.h" | 30 #include "net/test/embedded_test_server/http_request.h" |
29 #include "net/test/embedded_test_server/http_response.h" | 31 #include "net/test/embedded_test_server/http_response.h" |
32 #include "net/url_request/url_request.h" | |
30 #include "net/url_request/url_request_test_util.h" | 33 #include "net/url_request/url_request_test_util.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "url/gurl.h" | 35 #include "url/gurl.h" |
33 | 36 |
34 namespace { | 37 namespace { |
35 | 38 |
36 // Helps in setting the current network type and id. | 39 // Helps in setting the current network type and id. |
37 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { | 40 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { |
38 public: | 41 public: |
39 TestNetworkQualityEstimator( | 42 TestNetworkQualityEstimator( |
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1072 | 1075 |
1073 // Both RTT and downstream throughput should be updated. | 1076 // Both RTT and downstream throughput should be updated. |
1074 EXPECT_NE(NetworkQualityEstimator::InvalidRTT(), | 1077 EXPECT_NE(NetworkQualityEstimator::InvalidRTT(), |
1075 estimator.GetURLRequestRTTEstimateInternal(base::TimeTicks(), 100)); | 1078 estimator.GetURLRequestRTTEstimateInternal(base::TimeTicks(), 100)); |
1076 EXPECT_NE(NetworkQualityEstimator::kInvalidThroughput, | 1079 EXPECT_NE(NetworkQualityEstimator::kInvalidThroughput, |
1077 estimator.GetDownlinkThroughputKbpsEstimateInternal( | 1080 estimator.GetDownlinkThroughputKbpsEstimateInternal( |
1078 base::TimeTicks(), 100)); | 1081 base::TimeTicks(), 100)); |
1079 | 1082 |
1080 EXPECT_EQ(2U, rtt_observer.observations().size()); | 1083 EXPECT_EQ(2U, rtt_observer.observations().size()); |
1081 EXPECT_EQ(2U, throughput_observer.observations().size()); | 1084 EXPECT_EQ(2U, throughput_observer.observations().size()); |
1082 for (auto observation : rtt_observer.observations()) { | 1085 for (const auto& observation : rtt_observer.observations()) { |
Ryan Sleevi
2016/04/02 00:48:20
Was this your change? If so, please don't make unr
tbansal1
2016/04/04 16:55:44
Reverted.
| |
1083 EXPECT_LE(0, observation.rtt_ms); | 1086 EXPECT_LE(0, observation.rtt_ms); |
1084 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); | 1087 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); |
1085 EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source); | 1088 EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source); |
1086 } | 1089 } |
1087 for (auto observation : throughput_observer.observations()) { | 1090 for (const auto& observation : throughput_observer.observations()) { |
1088 EXPECT_LE(0, observation.throughput_kbps); | 1091 EXPECT_LE(0, observation.throughput_kbps); |
1089 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); | 1092 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); |
1090 EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source); | 1093 EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source); |
1091 } | 1094 } |
1092 | 1095 |
1093 // Verify that observations from TCP and QUIC are passed on to the observers. | 1096 // Verify that observations from TCP and QUIC are passed on to the observers. |
1094 base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1)); | 1097 base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1)); |
1095 base::TimeDelta quic_rtt(base::TimeDelta::FromMilliseconds(2)); | 1098 base::TimeDelta quic_rtt(base::TimeDelta::FromMilliseconds(2)); |
1096 | 1099 |
1097 scoped_ptr<SocketPerformanceWatcher> tcp_watcher = | 1100 scoped_ptr<SocketPerformanceWatcher> tcp_watcher = |
1098 estimator.CreateSocketPerformanceWatcher( | 1101 estimator.GetSocketPerformanceWatcherFactory() |
1099 SocketPerformanceWatcherFactory::PROTOCOL_TCP); | 1102 ->CreateSocketPerformanceWatcher( |
1103 SocketPerformanceWatcherFactory::PROTOCOL_TCP); | |
1100 scoped_ptr<SocketPerformanceWatcher> quic_watcher = | 1104 scoped_ptr<SocketPerformanceWatcher> quic_watcher = |
1101 estimator.CreateSocketPerformanceWatcher( | 1105 estimator.GetSocketPerformanceWatcherFactory() |
1102 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); | 1106 ->CreateSocketPerformanceWatcher( |
1107 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); | |
1103 tcp_watcher->OnUpdatedRTTAvailable(tcp_rtt); | 1108 tcp_watcher->OnUpdatedRTTAvailable(tcp_rtt); |
1104 quic_watcher->OnUpdatedRTTAvailable(quic_rtt); | 1109 quic_watcher->OnUpdatedRTTAvailable(quic_rtt); |
1105 | 1110 |
1111 base::RunLoop().RunUntilIdle(); | |
1112 | |
1106 EXPECT_EQ(4U, rtt_observer.observations().size()); | 1113 EXPECT_EQ(4U, rtt_observer.observations().size()); |
1107 EXPECT_EQ(2U, throughput_observer.observations().size()); | 1114 EXPECT_EQ(2U, throughput_observer.observations().size()); |
1108 | 1115 |
1109 EXPECT_EQ(tcp_rtt.InMilliseconds(), rtt_observer.observations().at(2).rtt_ms); | 1116 EXPECT_EQ(tcp_rtt.InMilliseconds(), rtt_observer.observations().at(2).rtt_ms); |
1110 EXPECT_EQ(quic_rtt.InMilliseconds(), | 1117 EXPECT_EQ(quic_rtt.InMilliseconds(), |
1111 rtt_observer.observations().at(3).rtt_ms); | 1118 rtt_observer.observations().at(3).rtt_ms); |
1112 } | 1119 } |
1113 | 1120 |
1114 } // namespace net | 1121 } // namespace net |
OLD | NEW |