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 <stdint.h> | 8 #include <stdint.h> |
8 | 9 |
9 #include <limits> | 10 #include <limits> |
10 #include <map> | 11 #include <map> |
11 #include <string> | 12 #include <string> |
12 #include <utility> | 13 #include <utility> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 base::RunLoop().RunUntilIdle(); | 1116 base::RunLoop().RunUntilIdle(); |
1116 | 1117 |
1117 EXPECT_EQ(4U, rtt_observer.observations().size()); | 1118 EXPECT_EQ(4U, rtt_observer.observations().size()); |
1118 EXPECT_EQ(2U, throughput_observer.observations().size()); | 1119 EXPECT_EQ(2U, throughput_observer.observations().size()); |
1119 | 1120 |
1120 EXPECT_EQ(tcp_rtt.InMilliseconds(), rtt_observer.observations().at(2).rtt_ms); | 1121 EXPECT_EQ(tcp_rtt.InMilliseconds(), rtt_observer.observations().at(2).rtt_ms); |
1121 EXPECT_EQ(quic_rtt.InMilliseconds(), | 1122 EXPECT_EQ(quic_rtt.InMilliseconds(), |
1122 rtt_observer.observations().at(3).rtt_ms); | 1123 rtt_observer.observations().at(3).rtt_ms); |
1123 } | 1124 } |
1124 | 1125 |
| 1126 // TestTCPSocketRTT requires kernel support for tcp_info struct, and so it is |
| 1127 // enabled only on certain platforms. |
| 1128 #if defined(TCP_INFO) || defined(OS_LINUX) |
| 1129 #define MAYBE_TestTCPSocketRTT TestTCPSocketRTT |
| 1130 #else |
| 1131 #define MAYBE_TestTCPSocketRTT DISABLED_TestTCPSocketRTT |
| 1132 #endif |
| 1133 // Tests that the TCP socket notifies the Network Quality Estimator of TCP RTTs, |
| 1134 // which in turn notifies registered RTT observers. |
| 1135 TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) { |
| 1136 TestRTTObserver rtt_observer; |
| 1137 std::map<std::string, std::string> variation_params; |
| 1138 TestNetworkQualityEstimator estimator(variation_params); |
| 1139 estimator.AddRTTObserver(&rtt_observer); |
| 1140 |
| 1141 TestDelegate test_delegate; |
| 1142 TestURLRequestContext context(true); |
| 1143 context.set_network_quality_estimator(&estimator); |
| 1144 |
| 1145 scoped_ptr<HttpNetworkSession::Params> params(new HttpNetworkSession::Params); |
| 1146 // |estimator| should be notified of TCP RTT observations. |
| 1147 params->socket_performance_watcher_factory = |
| 1148 estimator.GetSocketPerformanceWatcherFactory(); |
| 1149 context.set_http_network_session_params(std::move(params)); |
| 1150 context.Init(); |
| 1151 |
| 1152 EXPECT_EQ(0U, rtt_observer.observations().size()); |
| 1153 |
| 1154 // Send two requests. Verify that the completion of each request generates at |
| 1155 // least one TCP RTT observation. |
| 1156 for (size_t i = 0; i < 2; ++i) { |
| 1157 size_t before_count_tcp_rtt_observations = 0; |
| 1158 for (const auto& observation : rtt_observer.observations()) { |
| 1159 if (observation.source == NetworkQualityEstimator::TCP) |
| 1160 ++before_count_tcp_rtt_observations; |
| 1161 } |
| 1162 |
| 1163 scoped_ptr<URLRequest> request(context.CreateRequest( |
| 1164 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1165 request->Start(); |
| 1166 base::RunLoop().Run(); |
| 1167 |
| 1168 size_t after_count_tcp_rtt_observations = 0; |
| 1169 for (const auto& observation : rtt_observer.observations()) { |
| 1170 if (observation.source == NetworkQualityEstimator::TCP) |
| 1171 ++after_count_tcp_rtt_observations; |
| 1172 } |
| 1173 // At least one notification should be received per socket performance |
| 1174 // watcher. |
| 1175 EXPECT_LE(1U, after_count_tcp_rtt_observations - |
| 1176 before_count_tcp_rtt_observations) |
| 1177 << i; |
| 1178 } |
| 1179 } |
| 1180 |
1125 } // namespace net | 1181 } // namespace net |
OLD | NEW |