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 const size_t kNumRequests = 2; | |
Ryan Sleevi
2016/04/11 22:06:55
Doesn't seem like you need to use a constant here,
tbansal1
2016/04/12 16:14:33
Done.
| |
1155 | |
1156 // Send two requests. Verify that the completion of each request generates at | |
1157 // least one TCP RTT observation. | |
1158 for (size_t i = 0; i < kNumRequests; ++i) { | |
1159 size_t before_count_tcp_rtt_observations = 0; | |
1160 for (const auto& observation : rtt_observer.observations()) { | |
1161 if (observation.source == NetworkQualityEstimator::TCP) | |
1162 ++before_count_tcp_rtt_observations; | |
1163 } | |
1164 | |
1165 scoped_ptr<URLRequest> request(context.CreateRequest( | |
1166 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | |
1167 request->Start(); | |
1168 base::RunLoop().Run(); | |
1169 | |
1170 size_t after_count_tcp_rtt_observations = 0; | |
1171 for (const auto& observation : rtt_observer.observations()) { | |
1172 if (observation.source == NetworkQualityEstimator::TCP) | |
1173 ++after_count_tcp_rtt_observations; | |
1174 } | |
1175 // At least one notification should be received per socket performance | |
1176 // watcher. | |
1177 EXPECT_LE(1U, after_count_tcp_rtt_observations - | |
1178 before_count_tcp_rtt_observations) | |
1179 << i; | |
1180 } | |
1181 } | |
1182 | |
1125 } // namespace net | 1183 } // namespace net |
OLD | NEW |