| 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/nqe/network_quality_estimator.h" | 5 #include "net/nqe/network_quality_estimator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/metrics/histogram_samples.h" | 20 #include "base/metrics/histogram_samples.h" |
| 21 #include "base/run_loop.h" | 21 #include "base/run_loop.h" |
| 22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/test/histogram_tester.h" | 23 #include "base/test/histogram_tester.h" |
| 24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
| 27 #include "net/base/network_change_notifier.h" | 27 #include "net/base/network_change_notifier.h" |
| 28 #include "net/http/http_status_code.h" | 28 #include "net/http/http_status_code.h" |
| 29 #include "net/nqe/external_estimate_provider.h" | 29 #include "net/nqe/external_estimate_provider.h" |
| 30 #include "net/nqe/network_quality_observation.h" |
| 31 #include "net/nqe/network_quality_observation_source.h" |
| 30 #include "net/socket/socket_performance_watcher.h" | 32 #include "net/socket/socket_performance_watcher.h" |
| 31 #include "net/socket/socket_performance_watcher_factory.h" | 33 #include "net/socket/socket_performance_watcher_factory.h" |
| 32 #include "net/test/embedded_test_server/embedded_test_server.h" | 34 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 33 #include "net/test/embedded_test_server/http_request.h" | 35 #include "net/test/embedded_test_server/http_request.h" |
| 34 #include "net/test/embedded_test_server/http_response.h" | 36 #include "net/test/embedded_test_server/http_response.h" |
| 35 #include "net/url_request/url_request.h" | 37 #include "net/url_request/url_request.h" |
| 36 #include "net/url_request/url_request_test_util.h" | 38 #include "net/url_request/url_request_test_util.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 38 #include "url/gurl.h" | 40 #include "url/gurl.h" |
| 39 | 41 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 EmbeddedTestServer embedded_test_server_; | 146 EmbeddedTestServer embedded_test_server_; |
| 145 | 147 |
| 146 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); | 148 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); |
| 147 }; | 149 }; |
| 148 | 150 |
| 149 class TestRTTObserver : public NetworkQualityEstimator::RTTObserver { | 151 class TestRTTObserver : public NetworkQualityEstimator::RTTObserver { |
| 150 public: | 152 public: |
| 151 struct Observation { | 153 struct Observation { |
| 152 Observation(int32_t ms, | 154 Observation(int32_t ms, |
| 153 const base::TimeTicks& ts, | 155 const base::TimeTicks& ts, |
| 154 NetworkQualityEstimator::ObservationSource src) | 156 NetworkQualityObservationSource src) |
| 155 : rtt_ms(ms), timestamp(ts), source(src) {} | 157 : rtt_ms(ms), timestamp(ts), source(src) {} |
| 156 int32_t rtt_ms; | 158 int32_t rtt_ms; |
| 157 base::TimeTicks timestamp; | 159 base::TimeTicks timestamp; |
| 158 NetworkQualityEstimator::ObservationSource source; | 160 NetworkQualityObservationSource source; |
| 159 }; | 161 }; |
| 160 | 162 |
| 161 std::vector<Observation>& observations() { return observations_; } | 163 std::vector<Observation>& observations() { return observations_; } |
| 162 | 164 |
| 163 // RttObserver implementation: | 165 // RttObserver implementation: |
| 164 void OnRTTObservation( | 166 void OnRTTObservation(int32_t rtt_ms, |
| 165 int32_t rtt_ms, | 167 const base::TimeTicks& timestamp, |
| 166 const base::TimeTicks& timestamp, | 168 NetworkQualityObservationSource source) override { |
| 167 NetworkQualityEstimator::ObservationSource source) override { | |
| 168 observations_.push_back(Observation(rtt_ms, timestamp, source)); | 169 observations_.push_back(Observation(rtt_ms, timestamp, source)); |
| 169 } | 170 } |
| 170 | 171 |
| 171 private: | 172 private: |
| 172 std::vector<Observation> observations_; | 173 std::vector<Observation> observations_; |
| 173 }; | 174 }; |
| 174 | 175 |
| 175 class TestThroughputObserver | 176 class TestThroughputObserver |
| 176 : public NetworkQualityEstimator::ThroughputObserver { | 177 : public NetworkQualityEstimator::ThroughputObserver { |
| 177 public: | 178 public: |
| 178 struct Observation { | 179 struct Observation { |
| 179 Observation(int32_t kbps, | 180 Observation(int32_t kbps, |
| 180 const base::TimeTicks& ts, | 181 const base::TimeTicks& ts, |
| 181 NetworkQualityEstimator::ObservationSource src) | 182 NetworkQualityObservationSource src) |
| 182 : throughput_kbps(kbps), timestamp(ts), source(src) {} | 183 : throughput_kbps(kbps), timestamp(ts), source(src) {} |
| 183 int32_t throughput_kbps; | 184 int32_t throughput_kbps; |
| 184 base::TimeTicks timestamp; | 185 base::TimeTicks timestamp; |
| 185 NetworkQualityEstimator::ObservationSource source; | 186 NetworkQualityObservationSource source; |
| 186 }; | 187 }; |
| 187 | 188 |
| 188 std::vector<Observation>& observations() { return observations_; } | 189 std::vector<Observation>& observations() { return observations_; } |
| 189 | 190 |
| 190 // ThroughputObserver implementation: | 191 // ThroughputObserver implementation: |
| 191 void OnThroughputObservation( | 192 void OnThroughputObservation( |
| 192 int32_t throughput_kbps, | 193 int32_t throughput_kbps, |
| 193 const base::TimeTicks& timestamp, | 194 const base::TimeTicks& timestamp, |
| 194 NetworkQualityEstimator::ObservationSource source) override { | 195 NetworkQualityObservationSource source) override { |
| 195 observations_.push_back(Observation(throughput_kbps, timestamp, source)); | 196 observations_.push_back(Observation(throughput_kbps, timestamp, source)); |
| 196 } | 197 } |
| 197 | 198 |
| 198 private: | 199 private: |
| 199 std::vector<Observation> observations_; | 200 std::vector<Observation> observations_; |
| 200 }; | 201 }; |
| 201 | 202 |
| 202 } // namespace | 203 } // namespace |
| 203 | 204 |
| 204 TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) { | 205 TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 220 std::unique_ptr<URLRequest> request(context.CreateRequest( | 221 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 221 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 222 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 222 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); | 223 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); |
| 223 request->Start(); | 224 request->Start(); |
| 224 base::RunLoop().Run(); | 225 base::RunLoop().Run(); |
| 225 | 226 |
| 226 // Both RTT and downstream throughput should be updated. | 227 // Both RTT and downstream throughput should be updated. |
| 227 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | 228 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 228 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 229 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 229 | 230 |
| 230 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | |
| 231 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | |
| 232 | |
| 233 // Check UMA histograms. | 231 // Check UMA histograms. |
| 234 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); | 232 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); |
| 235 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); | 233 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); |
| 236 | 234 |
| 237 histogram_tester.ExpectTotalCount("NQE.RatioEstimatedToActualRTT.Unknown", 0); | 235 histogram_tester.ExpectTotalCount("NQE.RatioEstimatedToActualRTT.Unknown", 0); |
| 238 | 236 |
| 239 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 237 std::unique_ptr<URLRequest> request2(context.CreateRequest( |
| 240 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 238 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 241 request2->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); | 239 request2->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); |
| 242 request2->Start(); | 240 request2->Start(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 int32_t kbps; | 274 int32_t kbps; |
| 277 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); | 275 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 278 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 276 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 279 | 277 |
| 280 TestDelegate test_delegate; | 278 TestDelegate test_delegate; |
| 281 TestURLRequestContext context(true); | 279 TestURLRequestContext context(true); |
| 282 context.set_network_quality_estimator(&estimator); | 280 context.set_network_quality_estimator(&estimator); |
| 283 context.Init(); | 281 context.Init(); |
| 284 | 282 |
| 285 // Push 10 more observations than the maximum buffer size. | 283 // Push 10 more observations than the maximum buffer size. |
| 286 for (size_t i = 0; i < estimator.kMaximumObservationsBufferSize + 10U; ++i) { | 284 for (size_t i = 0; |
| 285 i < estimator.downstream_throughput_kbps_observations_.Capacity() + 10U; |
| 286 ++i) { |
| 287 std::unique_ptr<URLRequest> request(context.CreateRequest( | 287 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 288 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 288 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 289 request->Start(); | 289 request->Start(); |
| 290 base::RunLoop().Run(); | 290 base::RunLoop().Run(); |
| 291 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | 291 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 292 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 292 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 293 } | 293 } |
| 294 | 294 |
| 295 EXPECT_EQ(estimator.downstream_throughput_kbps_observations_.Capacity(), |
| 296 estimator.downstream_throughput_kbps_observations_.Size()); |
| 297 EXPECT_EQ(estimator.rtt_observations_.Capacity(), |
| 298 estimator.rtt_observations_.Size()); |
| 299 |
| 295 // Verify that the stored observations are cleared on network change. | 300 // Verify that the stored observations are cleared on network change. |
| 296 estimator.SimulateNetworkChangeTo( | 301 estimator.SimulateNetworkChangeTo( |
| 297 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-2"); | 302 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-2"); |
| 298 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); | 303 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 299 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 304 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 300 } | 305 } |
| 301 | 306 |
| 302 // Verifies that the percentiles are correctly computed. All observations have | |
| 303 // the same timestamp. Kbps percentiles must be in decreasing order. RTT | |
| 304 // percentiles must be in increasing order. | |
| 305 TEST(NetworkQualityEstimatorTest, PercentileSameTimestamps) { | |
| 306 std::map<std::string, std::string> variation_params; | |
| 307 TestNetworkQualityEstimator estimator(variation_params); | |
| 308 base::TimeTicks now = base::TimeTicks::Now(); | |
| 309 | |
| 310 // Network quality should be unavailable when no observations are available. | |
| 311 base::TimeDelta rtt; | |
| 312 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); | |
| 313 int32_t kbps; | |
| 314 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | |
| 315 | |
| 316 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even | |
| 317 // samples. This helps in verifying that the order of samples does not matter. | |
| 318 for (int i = 1; i <= 99; i += 2) { | |
| 319 estimator.downstream_throughput_kbps_observations_.AddObservation( | |
| 320 NetworkQualityEstimator::ThroughputObservation( | |
| 321 i, now, NetworkQualityEstimator::URL_REQUEST)); | |
| 322 estimator.rtt_observations_.AddObservation( | |
| 323 NetworkQualityEstimator::RttObservation( | |
| 324 base::TimeDelta::FromMilliseconds(i), now, | |
| 325 NetworkQualityEstimator::URL_REQUEST)); | |
| 326 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | |
| 327 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | |
| 328 } | |
| 329 | |
| 330 for (int i = 1; i <= 99; i += 2) { | |
| 331 // Insert TCP observation which should not be taken into account when | |
| 332 // computing median RTT at HTTP layer. | |
| 333 estimator.rtt_observations_.AddObservation( | |
| 334 NetworkQualityEstimator::RttObservation( | |
| 335 base::TimeDelta::FromMilliseconds(10000), now, | |
| 336 NetworkQualityEstimator::TCP)); | |
| 337 | |
| 338 // Insert QUIC observation which should not be taken into account when | |
| 339 // computing median RTT at HTTP layer. | |
| 340 estimator.rtt_observations_.AddObservation( | |
| 341 NetworkQualityEstimator::RttObservation( | |
| 342 base::TimeDelta::FromMilliseconds(10000), now, | |
| 343 NetworkQualityEstimator::QUIC)); | |
| 344 } | |
| 345 | |
| 346 for (int i = 2; i <= 100; i += 2) { | |
| 347 estimator.downstream_throughput_kbps_observations_.AddObservation( | |
| 348 NetworkQualityEstimator::ThroughputObservation( | |
| 349 i, now, NetworkQualityEstimator::URL_REQUEST)); | |
| 350 estimator.rtt_observations_.AddObservation( | |
| 351 NetworkQualityEstimator::RttObservation( | |
| 352 base::TimeDelta::FromMilliseconds(i), now, | |
| 353 NetworkQualityEstimator::URL_REQUEST)); | |
| 354 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | |
| 355 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | |
| 356 } | |
| 357 | |
| 358 for (int i = 0; i <= 100; ++i) { | |
| 359 // Checks if the difference between the two integers is less than 1. This is | |
| 360 // required because computed percentiles may be slightly different from | |
| 361 // what is expected due to floating point computation errors and integer | |
| 362 // rounding off errors. | |
| 363 EXPECT_NEAR(estimator.GetDownlinkThroughputKbpsEstimateInternal( | |
| 364 base::TimeTicks(), i), | |
| 365 100 - i, 1); | |
| 366 std::vector<NetworkQualityEstimator::ObservationSource> | |
| 367 disallowed_observation_sources; | |
| 368 disallowed_observation_sources.push_back(NetworkQualityEstimator::TCP); | |
| 369 disallowed_observation_sources.push_back(NetworkQualityEstimator::QUIC); | |
| 370 EXPECT_NEAR(estimator | |
| 371 .GetRTTEstimateInternal(disallowed_observation_sources, | |
| 372 base::TimeTicks(), i) | |
| 373 .InMilliseconds(), | |
| 374 i, 1); | |
| 375 } | |
| 376 | |
| 377 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | |
| 378 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | |
| 379 } | |
| 380 | |
| 381 // Verifies that the percentiles are correctly computed. Observations have | |
| 382 // different timestamps with half the observations being very old and the rest | |
| 383 // of them being very recent. Percentiles should factor in recent observations | |
| 384 // much more heavily than older samples. Kbps percentiles must be in decreasing | |
| 385 // order. RTT percentiles must be in increasing order. | |
| 386 TEST(NetworkQualityEstimatorTest, PercentileDifferentTimestamps) { | |
| 387 std::map<std::string, std::string> variation_params; | |
| 388 TestNetworkQualityEstimator estimator(variation_params); | |
| 389 base::TimeTicks now = base::TimeTicks::Now(); | |
| 390 base::TimeTicks very_old = now - base::TimeDelta::FromDays(365); | |
| 391 | |
| 392 // First 50 samples have very old timestamp. | |
| 393 for (int i = 1; i <= 50; ++i) { | |
| 394 estimator.downstream_throughput_kbps_observations_.AddObservation( | |
| 395 NetworkQualityEstimator::ThroughputObservation( | |
| 396 i, very_old, NetworkQualityEstimator::URL_REQUEST)); | |
| 397 estimator.rtt_observations_.AddObservation( | |
| 398 NetworkQualityEstimator::RttObservation( | |
| 399 base::TimeDelta::FromMilliseconds(i), very_old, | |
| 400 NetworkQualityEstimator::URL_REQUEST)); | |
| 401 } | |
| 402 | |
| 403 // Next 50 (i.e., from 51 to 100) have recent timestamp. | |
| 404 for (int i = 51; i <= 100; ++i) { | |
| 405 estimator.downstream_throughput_kbps_observations_.AddObservation( | |
| 406 NetworkQualityEstimator::ThroughputObservation( | |
| 407 i, now, NetworkQualityEstimator::URL_REQUEST)); | |
| 408 | |
| 409 // Insert TCP observation which should not be taken into account when | |
| 410 // computing median RTT at HTTP layer. | |
| 411 estimator.rtt_observations_.AddObservation( | |
| 412 NetworkQualityEstimator::RttObservation( | |
| 413 base::TimeDelta::FromMilliseconds(10000), now, | |
| 414 NetworkQualityEstimator::TCP)); | |
| 415 | |
| 416 estimator.rtt_observations_.AddObservation( | |
| 417 NetworkQualityEstimator::RttObservation( | |
| 418 base::TimeDelta::FromMilliseconds(i), now, | |
| 419 NetworkQualityEstimator::URL_REQUEST)); | |
| 420 } | |
| 421 | |
| 422 std::vector<NetworkQualityEstimator::ObservationSource> | |
| 423 disallowed_observation_sources; | |
| 424 disallowed_observation_sources.push_back(NetworkQualityEstimator::TCP); | |
| 425 disallowed_observation_sources.push_back(NetworkQualityEstimator::QUIC); | |
| 426 | |
| 427 // Older samples have very little weight. So, all percentiles are >= 51 | |
| 428 // (lowest value among recent observations). | |
| 429 for (int i = 1; i < 100; ++i) { | |
| 430 // Checks if the difference between the two integers is less than 1. This is | |
| 431 // required because computed percentiles may be slightly different from | |
| 432 // what is expected due to floating point computation errors and integer | |
| 433 // rounding off errors. | |
| 434 EXPECT_NEAR(estimator.GetDownlinkThroughputKbpsEstimateInternal( | |
| 435 base::TimeTicks(), i), | |
| 436 51 + 0.49 * (100 - i), 1); | |
| 437 EXPECT_NEAR(estimator | |
| 438 .GetRTTEstimateInternal(disallowed_observation_sources, | |
| 439 base::TimeTicks(), i) | |
| 440 .InMilliseconds(), | |
| 441 51 + 0.49 * i, 1); | |
| 442 } | |
| 443 } | |
| 444 | |
| 445 // This test notifies NetworkQualityEstimator of received data. Next, | 307 // This test notifies NetworkQualityEstimator of received data. Next, |
| 446 // throughput and RTT percentiles are checked for correctness by doing simple | 308 // throughput and RTT percentiles are checked for correctness by doing simple |
| 447 // verifications. | 309 // verifications. |
| 448 TEST(NetworkQualityEstimatorTest, ComputedPercentiles) { | 310 TEST(NetworkQualityEstimatorTest, ComputedPercentiles) { |
| 449 std::map<std::string, std::string> variation_params; | 311 std::map<std::string, std::string> variation_params; |
| 450 TestNetworkQualityEstimator estimator(variation_params); | 312 TestNetworkQualityEstimator estimator(variation_params); |
| 451 | 313 |
| 452 std::vector<NetworkQualityEstimator::ObservationSource> | 314 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
| 453 disallowed_observation_sources; | 315 disallowed_observation_sources.push_back( |
| 454 disallowed_observation_sources.push_back(NetworkQualityEstimator::TCP); | 316 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); |
| 455 disallowed_observation_sources.push_back(NetworkQualityEstimator::QUIC); | 317 disallowed_observation_sources.push_back( |
| 318 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); |
| 456 | 319 |
| 457 EXPECT_EQ(NetworkQualityEstimator::InvalidRTT(), | 320 EXPECT_EQ(nqe::internal::InvalidRTT(), |
| 458 estimator.GetRTTEstimateInternal(disallowed_observation_sources, | 321 estimator.GetRTTEstimateInternal(disallowed_observation_sources, |
| 459 base::TimeTicks(), 100)); | 322 base::TimeTicks(), 100)); |
| 460 EXPECT_EQ(NetworkQualityEstimator::kInvalidThroughput, | 323 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
| 461 estimator.GetDownlinkThroughputKbpsEstimateInternal( | 324 estimator.GetDownlinkThroughputKbpsEstimateInternal( |
| 462 base::TimeTicks(), 100)); | 325 base::TimeTicks(), 100)); |
| 463 | 326 |
| 464 TestDelegate test_delegate; | 327 TestDelegate test_delegate; |
| 465 TestURLRequestContext context(true); | 328 TestURLRequestContext context(true); |
| 466 context.set_network_quality_estimator(&estimator); | 329 context.set_network_quality_estimator(&estimator); |
| 467 context.Init(); | 330 context.Init(); |
| 468 | 331 |
| 469 // Number of observations are more than the maximum buffer size. | 332 // Number of observations are more than the maximum buffer size. |
| 470 for (size_t i = 0; i < estimator.kMaximumObservationsBufferSize + 100U; ++i) { | 333 for (size_t i = 0; i < 1000U; ++i) { |
| 471 std::unique_ptr<URLRequest> request(context.CreateRequest( | 334 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 472 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 335 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 473 request->Start(); | 336 request->Start(); |
| 474 base::RunLoop().Run(); | 337 base::RunLoop().Run(); |
| 475 } | 338 } |
| 476 | 339 |
| 477 // Verify the percentiles through simple tests. | 340 // Verify the percentiles through simple tests. |
| 478 for (int i = 0; i <= 100; ++i) { | 341 for (int i = 0; i <= 100; ++i) { |
| 479 EXPECT_GT(estimator.GetDownlinkThroughputKbpsEstimateInternal( | 342 EXPECT_GT(estimator.GetDownlinkThroughputKbpsEstimateInternal( |
| 480 base::TimeTicks(), i), | 343 base::TimeTicks(), i), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 estimator.SimulateNetworkChangeTo( | 387 estimator.SimulateNetworkChangeTo( |
| 525 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 388 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
| 526 | 389 |
| 527 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | 390 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 528 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 391 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 529 EXPECT_EQ(200, kbps); | 392 EXPECT_EQ(200, kbps); |
| 530 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); | 393 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); |
| 531 | 394 |
| 532 // Peak network quality should not be affected by the network quality | 395 // Peak network quality should not be affected by the network quality |
| 533 // estimator field trial. | 396 // estimator field trial. |
| 534 EXPECT_EQ(NetworkQualityEstimator::InvalidRTT(), | 397 EXPECT_EQ(nqe::internal::InvalidRTT(), estimator.peak_network_quality_.rtt()); |
| 535 estimator.peak_network_quality_.rtt()); | 398 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
| 536 EXPECT_EQ(NetworkQualityEstimator::kInvalidThroughput, | |
| 537 estimator.peak_network_quality_.downstream_throughput_kbps()); | 399 estimator.peak_network_quality_.downstream_throughput_kbps()); |
| 538 | 400 |
| 539 // Simulate network change to 2G. Only the Kbps default estimate should be | 401 // Simulate network change to 2G. Only the Kbps default estimate should be |
| 540 // available. | 402 // available. |
| 541 estimator.SimulateNetworkChangeTo( | 403 estimator.SimulateNetworkChangeTo( |
| 542 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); | 404 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); |
| 543 | 405 |
| 544 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); | 406 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 545 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 407 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 546 EXPECT_EQ(300, kbps); | 408 EXPECT_EQ(300, kbps); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 // is invoked. | 562 // is invoked. |
| 701 TEST(NetworkQualityEstimatorTest, TestCaching) { | 563 TEST(NetworkQualityEstimatorTest, TestCaching) { |
| 702 std::map<std::string, std::string> variation_params; | 564 std::map<std::string, std::string> variation_params; |
| 703 TestNetworkQualityEstimator estimator(variation_params); | 565 TestNetworkQualityEstimator estimator(variation_params); |
| 704 size_t expected_cache_size = 0; | 566 size_t expected_cache_size = 0; |
| 705 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | 567 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); |
| 706 | 568 |
| 707 // Cache entry will not be added for (NONE, ""). | 569 // Cache entry will not be added for (NONE, ""). |
| 708 estimator.downstream_throughput_kbps_observations_.AddObservation( | 570 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 709 NetworkQualityEstimator::ThroughputObservation( | 571 NetworkQualityEstimator::ThroughputObservation( |
| 710 1, base::TimeTicks::Now(), NetworkQualityEstimator::URL_REQUEST)); | 572 1, base::TimeTicks::Now(), |
| 573 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 711 estimator.rtt_observations_.AddObservation( | 574 estimator.rtt_observations_.AddObservation( |
| 712 NetworkQualityEstimator::RttObservation( | 575 NetworkQualityEstimator::RttObservation( |
| 713 base::TimeDelta::FromMilliseconds(1000), base::TimeTicks::Now(), | 576 base::TimeDelta::FromMilliseconds(1000), base::TimeTicks::Now(), |
| 714 NetworkQualityEstimator::URL_REQUEST)); | 577 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 715 estimator.SimulateNetworkChangeTo( | 578 estimator.SimulateNetworkChangeTo( |
| 716 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); | 579 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); |
| 717 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | 580 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); |
| 718 | 581 |
| 719 // Entry will be added for (2G, "test1"). | 582 // Entry will be added for (2G, "test1"). |
| 720 // Also, set the network quality for (2G, "test1") so that it is stored in | 583 // Also, set the network quality for (2G, "test1") so that it is stored in |
| 721 // the cache. | 584 // the cache. |
| 722 estimator.downstream_throughput_kbps_observations_.AddObservation( | 585 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 723 NetworkQualityEstimator::ThroughputObservation( | 586 NetworkQualityEstimator::ThroughputObservation( |
| 724 1, base::TimeTicks::Now(), NetworkQualityEstimator::URL_REQUEST)); | 587 1, base::TimeTicks::Now(), |
| 588 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 725 estimator.rtt_observations_.AddObservation( | 589 estimator.rtt_observations_.AddObservation( |
| 726 NetworkQualityEstimator::RttObservation( | 590 NetworkQualityEstimator::RttObservation( |
| 727 base::TimeDelta::FromMilliseconds(1000), base::TimeTicks::Now(), | 591 base::TimeDelta::FromMilliseconds(1000), base::TimeTicks::Now(), |
| 728 NetworkQualityEstimator::URL_REQUEST)); | 592 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 729 | 593 |
| 730 estimator.SimulateNetworkChangeTo( | 594 estimator.SimulateNetworkChangeTo( |
| 731 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-1"); | 595 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-1"); |
| 732 ++expected_cache_size; | 596 ++expected_cache_size; |
| 733 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | 597 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); |
| 734 | 598 |
| 735 // Entry will be added for (3G, "test1"). | 599 // Entry will be added for (3G, "test1"). |
| 736 // Also, set the network quality for (3G, "test1") so that it is stored in | 600 // Also, set the network quality for (3G, "test1") so that it is stored in |
| 737 // the cache. | 601 // the cache. |
| 738 estimator.downstream_throughput_kbps_observations_.AddObservation( | 602 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 739 NetworkQualityEstimator::ThroughputObservation( | 603 NetworkQualityEstimator::ThroughputObservation( |
| 740 2, base::TimeTicks::Now(), NetworkQualityEstimator::URL_REQUEST)); | 604 2, base::TimeTicks::Now(), |
| 605 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 741 estimator.rtt_observations_.AddObservation( | 606 estimator.rtt_observations_.AddObservation( |
| 742 NetworkQualityEstimator::RttObservation( | 607 NetworkQualityEstimator::RttObservation( |
| 743 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), | 608 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), |
| 744 NetworkQualityEstimator::URL_REQUEST)); | 609 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 745 estimator.SimulateNetworkChangeTo( | 610 estimator.SimulateNetworkChangeTo( |
| 746 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-2"); | 611 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-2"); |
| 747 ++expected_cache_size; | 612 ++expected_cache_size; |
| 748 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | 613 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); |
| 749 | 614 |
| 750 // Entry will not be added for (3G, "test2"). | 615 // Entry will not be added for (3G, "test2"). |
| 751 estimator.SimulateNetworkChangeTo( | 616 estimator.SimulateNetworkChangeTo( |
| 752 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); | 617 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); |
| 753 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | 618 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); |
| 754 | 619 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 EXPECT_EQ(0U, estimator.cached_network_qualities_.size()); | 663 EXPECT_EQ(0U, estimator.cached_network_qualities_.size()); |
| 799 | 664 |
| 800 // Add 100 more networks than the maximum size of the cache. | 665 // Add 100 more networks than the maximum size of the cache. |
| 801 size_t network_count = | 666 size_t network_count = |
| 802 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize + 100; | 667 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize + 100; |
| 803 | 668 |
| 804 base::TimeTicks update_time_of_network_100; | 669 base::TimeTicks update_time_of_network_100; |
| 805 for (size_t i = 0; i < network_count; ++i) { | 670 for (size_t i = 0; i < network_count; ++i) { |
| 806 estimator.downstream_throughput_kbps_observations_.AddObservation( | 671 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 807 NetworkQualityEstimator::ThroughputObservation( | 672 NetworkQualityEstimator::ThroughputObservation( |
| 808 2, base::TimeTicks::Now(), NetworkQualityEstimator::URL_REQUEST)); | 673 2, base::TimeTicks::Now(), |
| 674 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 809 estimator.rtt_observations_.AddObservation( | 675 estimator.rtt_observations_.AddObservation( |
| 810 NetworkQualityEstimator::RttObservation( | 676 NetworkQualityEstimator::RttObservation( |
| 811 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), | 677 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), |
| 812 NetworkQualityEstimator::URL_REQUEST)); | 678 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 813 | 679 |
| 814 if (i == 100) | 680 if (i == 100) |
| 815 update_time_of_network_100 = base::TimeTicks::Now(); | 681 update_time_of_network_100 = base::TimeTicks::Now(); |
| 816 | 682 |
| 817 estimator.SimulateNetworkChangeTo( | 683 estimator.SimulateNetworkChangeTo( |
| 818 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, | 684 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, |
| 819 base::SizeTToString(i)); | 685 base::SizeTToString(i)); |
| 820 if (i < NetworkQualityEstimator::kMaximumNetworkQualityCacheSize) | 686 if (i < NetworkQualityEstimator::kMaximumNetworkQualityCacheSize) |
| 821 EXPECT_EQ(i, estimator.cached_network_qualities_.size()); | 687 EXPECT_EQ(i, estimator.cached_network_qualities_.size()); |
| 822 EXPECT_LE(estimator.cached_network_qualities_.size(), | 688 EXPECT_LE(estimator.cached_network_qualities_.size(), |
| 823 static_cast<size_t>( | 689 static_cast<size_t>( |
| 824 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize)); | 690 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize)); |
| 825 } | 691 } |
| 826 // One more call so that the last network is also written to cache. | 692 // One more call so that the last network is also written to cache. |
| 827 estimator.downstream_throughput_kbps_observations_.AddObservation( | 693 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 828 NetworkQualityEstimator::ThroughputObservation( | 694 NetworkQualityEstimator::ThroughputObservation( |
| 829 2, base::TimeTicks::Now(), NetworkQualityEstimator::URL_REQUEST)); | 695 2, base::TimeTicks::Now(), |
| 696 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 830 estimator.rtt_observations_.AddObservation( | 697 estimator.rtt_observations_.AddObservation( |
| 831 NetworkQualityEstimator::RttObservation( | 698 NetworkQualityEstimator::RttObservation( |
| 832 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), | 699 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), |
| 833 NetworkQualityEstimator::URL_REQUEST)); | 700 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 834 estimator.SimulateNetworkChangeTo( | 701 estimator.SimulateNetworkChangeTo( |
| 835 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, | 702 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, |
| 836 base::SizeTToString(network_count - 1)); | 703 base::SizeTToString(network_count - 1)); |
| 837 EXPECT_EQ(static_cast<size_t>( | 704 EXPECT_EQ(static_cast<size_t>( |
| 838 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize), | 705 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize), |
| 839 estimator.cached_network_qualities_.size()); | 706 estimator.cached_network_qualities_.size()); |
| 840 | 707 |
| 841 // Test that the cache is LRU by examining its contents. Networks in cache | 708 // Test that the cache is LRU by examining its contents. Networks in cache |
| 842 // must all be newer than the 100th network. | 709 // must all be newer than the 100th network. |
| 843 for (NetworkQualityEstimator::CachedNetworkQualities::iterator it = | 710 for (NetworkQualityEstimator::CachedNetworkQualities::iterator it = |
| 844 estimator.cached_network_qualities_.begin(); | 711 estimator.cached_network_qualities_.begin(); |
| 845 it != estimator.cached_network_qualities_.end(); ++it) { | 712 it != estimator.cached_network_qualities_.end(); ++it) { |
| 846 EXPECT_GE((it->second).last_update_time_, update_time_of_network_100); | 713 EXPECT_GE((it->second).last_update_time_, update_time_of_network_100); |
| 847 } | 714 } |
| 848 } | 715 } |
| 849 | 716 |
| 850 TEST(NetworkQualityEstimatorTest, TestGetMedianRTTSince) { | 717 TEST(NetworkQualityEstimatorTest, TestGetMedianRTTSince) { |
| 851 std::map<std::string, std::string> variation_params; | 718 std::map<std::string, std::string> variation_params; |
| 852 TestNetworkQualityEstimator estimator(variation_params); | 719 TestNetworkQualityEstimator estimator(variation_params); |
| 853 base::TimeTicks now = base::TimeTicks::Now(); | 720 base::TimeTicks now = base::TimeTicks::Now(); |
| 854 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1); | 721 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1); |
| 855 ASSERT_NE(old, now); | 722 ASSERT_NE(old, now); |
| 856 | 723 |
| 857 // First sample has very old timestamp. | 724 // First sample has very old timestamp. |
| 858 estimator.downstream_throughput_kbps_observations_.AddObservation( | 725 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 859 NetworkQualityEstimator::ThroughputObservation( | 726 NetworkQualityEstimator::ThroughputObservation( |
| 860 1, old, NetworkQualityEstimator::URL_REQUEST)); | 727 1, old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 861 estimator.rtt_observations_.AddObservation( | 728 estimator.rtt_observations_.AddObservation( |
| 862 NetworkQualityEstimator::RttObservation( | 729 NetworkQualityEstimator::RttObservation( |
| 863 base::TimeDelta::FromMilliseconds(1), old, | 730 base::TimeDelta::FromMilliseconds(1), old, |
| 864 NetworkQualityEstimator::URL_REQUEST)); | 731 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 865 | 732 |
| 866 estimator.downstream_throughput_kbps_observations_.AddObservation( | 733 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 867 NetworkQualityEstimator::ThroughputObservation( | 734 NetworkQualityEstimator::ThroughputObservation( |
| 868 100, now, NetworkQualityEstimator::URL_REQUEST)); | 735 100, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 869 estimator.rtt_observations_.AddObservation( | 736 estimator.rtt_observations_.AddObservation( |
| 870 NetworkQualityEstimator::RttObservation( | 737 NetworkQualityEstimator::RttObservation( |
| 871 base::TimeDelta::FromMilliseconds(100), now, | 738 base::TimeDelta::FromMilliseconds(100), now, |
| 872 NetworkQualityEstimator::URL_REQUEST)); | 739 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 873 | 740 |
| 874 const struct { | 741 const struct { |
| 875 base::TimeTicks start_timestamp; | 742 base::TimeTicks start_timestamp; |
| 876 bool expect_network_quality_available; | 743 bool expect_network_quality_available; |
| 877 base::TimeDelta expected_url_request_rtt; | 744 base::TimeDelta expected_url_request_rtt; |
| 878 int32_t expected_downstream_throughput; | 745 int32_t expected_downstream_throughput; |
| 879 } tests[] = { | 746 } tests[] = { |
| 880 {now + base::TimeDelta::FromSeconds(10), false, | 747 {now + base::TimeDelta::FromSeconds(10), false, |
| 881 base::TimeDelta::FromMilliseconds(0), 0}, | 748 base::TimeDelta::FromMilliseconds(0), 0}, |
| 882 {now, true, base::TimeDelta::FromMilliseconds(100), 100}, | 749 {now, true, base::TimeDelta::FromMilliseconds(100), 100}, |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | 1108 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 1242 | 1109 |
| 1243 int32_t throughput; | 1110 int32_t throughput; |
| 1244 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&throughput)); | 1111 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&throughput)); |
| 1245 | 1112 |
| 1246 EXPECT_EQ(2U, rtt_observer.observations().size()); | 1113 EXPECT_EQ(2U, rtt_observer.observations().size()); |
| 1247 EXPECT_EQ(2U, throughput_observer.observations().size()); | 1114 EXPECT_EQ(2U, throughput_observer.observations().size()); |
| 1248 for (const auto& observation : rtt_observer.observations()) { | 1115 for (const auto& observation : rtt_observer.observations()) { |
| 1249 EXPECT_LE(0, observation.rtt_ms); | 1116 EXPECT_LE(0, observation.rtt_ms); |
| 1250 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); | 1117 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); |
| 1251 EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source); | 1118 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST, |
| 1119 observation.source); |
| 1252 } | 1120 } |
| 1253 for (const auto& observation : throughput_observer.observations()) { | 1121 for (const auto& observation : throughput_observer.observations()) { |
| 1254 EXPECT_LE(0, observation.throughput_kbps); | 1122 EXPECT_LE(0, observation.throughput_kbps); |
| 1255 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); | 1123 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); |
| 1256 EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source); | 1124 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST, |
| 1125 observation.source); |
| 1257 } | 1126 } |
| 1258 | 1127 |
| 1259 // Verify that observations from TCP and QUIC are passed on to the observers. | 1128 // Verify that observations from TCP and QUIC are passed on to the observers. |
| 1260 base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1)); | 1129 base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1)); |
| 1261 base::TimeDelta quic_rtt(base::TimeDelta::FromMilliseconds(2)); | 1130 base::TimeDelta quic_rtt(base::TimeDelta::FromMilliseconds(2)); |
| 1262 | 1131 |
| 1263 std::unique_ptr<SocketPerformanceWatcher> tcp_watcher = | 1132 std::unique_ptr<SocketPerformanceWatcher> tcp_watcher = |
| 1264 estimator.GetSocketPerformanceWatcherFactory() | 1133 estimator.GetSocketPerformanceWatcherFactory() |
| 1265 ->CreateSocketPerformanceWatcher( | 1134 ->CreateSocketPerformanceWatcher( |
| 1266 SocketPerformanceWatcherFactory::PROTOCOL_TCP); | 1135 SocketPerformanceWatcherFactory::PROTOCOL_TCP); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 | 1181 |
| 1313 EXPECT_EQ(0U, rtt_observer.observations().size()); | 1182 EXPECT_EQ(0U, rtt_observer.observations().size()); |
| 1314 base::TimeDelta rtt; | 1183 base::TimeDelta rtt; |
| 1315 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); | 1184 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 1316 | 1185 |
| 1317 // Send two requests. Verify that the completion of each request generates at | 1186 // Send two requests. Verify that the completion of each request generates at |
| 1318 // least one TCP RTT observation. | 1187 // least one TCP RTT observation. |
| 1319 for (size_t i = 0; i < 2; ++i) { | 1188 for (size_t i = 0; i < 2; ++i) { |
| 1320 size_t before_count_tcp_rtt_observations = 0; | 1189 size_t before_count_tcp_rtt_observations = 0; |
| 1321 for (const auto& observation : rtt_observer.observations()) { | 1190 for (const auto& observation : rtt_observer.observations()) { |
| 1322 if (observation.source == NetworkQualityEstimator::TCP) | 1191 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) |
| 1323 ++before_count_tcp_rtt_observations; | 1192 ++before_count_tcp_rtt_observations; |
| 1324 } | 1193 } |
| 1325 | 1194 |
| 1326 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1195 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1327 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1196 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1328 request->Start(); | 1197 request->Start(); |
| 1329 base::RunLoop().Run(); | 1198 base::RunLoop().Run(); |
| 1330 | 1199 |
| 1331 size_t after_count_tcp_rtt_observations = 0; | 1200 size_t after_count_tcp_rtt_observations = 0; |
| 1332 for (const auto& observation : rtt_observer.observations()) { | 1201 for (const auto& observation : rtt_observer.observations()) { |
| 1333 if (observation.source == NetworkQualityEstimator::TCP) | 1202 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) |
| 1334 ++after_count_tcp_rtt_observations; | 1203 ++after_count_tcp_rtt_observations; |
| 1335 } | 1204 } |
| 1336 // At least one notification should be received per socket performance | 1205 // At least one notification should be received per socket performance |
| 1337 // watcher. | 1206 // watcher. |
| 1338 EXPECT_LE(1U, after_count_tcp_rtt_observations - | 1207 EXPECT_LE(1U, after_count_tcp_rtt_observations - |
| 1339 before_count_tcp_rtt_observations) | 1208 before_count_tcp_rtt_observations) |
| 1340 << i; | 1209 << i; |
| 1341 } | 1210 } |
| 1342 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | 1211 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 1343 } | 1212 } |
| 1344 | 1213 |
| 1345 } // namespace net | 1214 } // namespace net |
| OLD | NEW |