| 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" |
| 32 #include "net/nqe/observation_buffer.h" |
| 30 #include "net/socket/socket_performance_watcher.h" | 33 #include "net/socket/socket_performance_watcher.h" |
| 31 #include "net/socket/socket_performance_watcher_factory.h" | 34 #include "net/socket/socket_performance_watcher_factory.h" |
| 32 #include "net/test/embedded_test_server/embedded_test_server.h" | 35 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 33 #include "net/test/embedded_test_server/http_request.h" | 36 #include "net/test/embedded_test_server/http_request.h" |
| 34 #include "net/test/embedded_test_server/http_response.h" | 37 #include "net/test/embedded_test_server/http_response.h" |
| 35 #include "net/url_request/url_request.h" | 38 #include "net/url_request/url_request.h" |
| 36 #include "net/url_request/url_request_test_util.h" | 39 #include "net/url_request/url_request_test_util.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
| 38 #include "url/gurl.h" | 41 #include "url/gurl.h" |
| 39 | 42 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 EmbeddedTestServer embedded_test_server_; | 147 EmbeddedTestServer embedded_test_server_; |
| 145 | 148 |
| 146 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); | 149 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); |
| 147 }; | 150 }; |
| 148 | 151 |
| 149 class TestRTTObserver : public NetworkQualityEstimator::RTTObserver { | 152 class TestRTTObserver : public NetworkQualityEstimator::RTTObserver { |
| 150 public: | 153 public: |
| 151 struct Observation { | 154 struct Observation { |
| 152 Observation(int32_t ms, | 155 Observation(int32_t ms, |
| 153 const base::TimeTicks& ts, | 156 const base::TimeTicks& ts, |
| 154 NetworkQualityEstimator::ObservationSource src) | 157 NetworkQualityObservationSource src) |
| 155 : rtt_ms(ms), timestamp(ts), source(src) {} | 158 : rtt_ms(ms), timestamp(ts), source(src) {} |
| 156 int32_t rtt_ms; | 159 int32_t rtt_ms; |
| 157 base::TimeTicks timestamp; | 160 base::TimeTicks timestamp; |
| 158 NetworkQualityEstimator::ObservationSource source; | 161 NetworkQualityObservationSource source; |
| 159 }; | 162 }; |
| 160 | 163 |
| 161 std::vector<Observation>& observations() { return observations_; } | 164 std::vector<Observation>& observations() { return observations_; } |
| 162 | 165 |
| 163 // RttObserver implementation: | 166 // RttObserver implementation: |
| 164 void OnRTTObservation( | 167 void OnRTTObservation(int32_t rtt_ms, |
| 165 int32_t rtt_ms, | 168 const base::TimeTicks& timestamp, |
| 166 const base::TimeTicks& timestamp, | 169 NetworkQualityObservationSource source) override { |
| 167 NetworkQualityEstimator::ObservationSource source) override { | |
| 168 observations_.push_back(Observation(rtt_ms, timestamp, source)); | 170 observations_.push_back(Observation(rtt_ms, timestamp, source)); |
| 169 } | 171 } |
| 170 | 172 |
| 171 private: | 173 private: |
| 172 std::vector<Observation> observations_; | 174 std::vector<Observation> observations_; |
| 173 }; | 175 }; |
| 174 | 176 |
| 175 class TestThroughputObserver | 177 class TestThroughputObserver |
| 176 : public NetworkQualityEstimator::ThroughputObserver { | 178 : public NetworkQualityEstimator::ThroughputObserver { |
| 177 public: | 179 public: |
| 178 struct Observation { | 180 struct Observation { |
| 179 Observation(int32_t kbps, | 181 Observation(int32_t kbps, |
| 180 const base::TimeTicks& ts, | 182 const base::TimeTicks& ts, |
| 181 NetworkQualityEstimator::ObservationSource src) | 183 NetworkQualityObservationSource src) |
| 182 : throughput_kbps(kbps), timestamp(ts), source(src) {} | 184 : throughput_kbps(kbps), timestamp(ts), source(src) {} |
| 183 int32_t throughput_kbps; | 185 int32_t throughput_kbps; |
| 184 base::TimeTicks timestamp; | 186 base::TimeTicks timestamp; |
| 185 NetworkQualityEstimator::ObservationSource source; | 187 NetworkQualityObservationSource source; |
| 186 }; | 188 }; |
| 187 | 189 |
| 188 std::vector<Observation>& observations() { return observations_; } | 190 std::vector<Observation>& observations() { return observations_; } |
| 189 | 191 |
| 190 // ThroughputObserver implementation: | 192 // ThroughputObserver implementation: |
| 191 void OnThroughputObservation( | 193 void OnThroughputObservation( |
| 192 int32_t throughput_kbps, | 194 int32_t throughput_kbps, |
| 193 const base::TimeTicks& timestamp, | 195 const base::TimeTicks& timestamp, |
| 194 NetworkQualityEstimator::ObservationSource source) override { | 196 NetworkQualityObservationSource source) override { |
| 195 observations_.push_back(Observation(throughput_kbps, timestamp, source)); | 197 observations_.push_back(Observation(throughput_kbps, timestamp, source)); |
| 196 } | 198 } |
| 197 | 199 |
| 198 private: | 200 private: |
| 199 std::vector<Observation> observations_; | 201 std::vector<Observation> observations_; |
| 200 }; | 202 }; |
| 201 | 203 |
| 202 } // namespace | 204 } // namespace |
| 203 | 205 |
| 204 TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) { | 206 TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 220 std::unique_ptr<URLRequest> request(context.CreateRequest( | 222 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 221 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 223 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 222 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); | 224 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); |
| 223 request->Start(); | 225 request->Start(); |
| 224 base::RunLoop().Run(); | 226 base::RunLoop().Run(); |
| 225 | 227 |
| 226 // Both RTT and downstream throughput should be updated. | 228 // Both RTT and downstream throughput should be updated. |
| 227 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | 229 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 228 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 230 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 229 | 231 |
| 230 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | |
| 231 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | |
| 232 | |
| 233 // Check UMA histograms. | 232 // Check UMA histograms. |
| 234 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); | 233 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); |
| 235 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); | 234 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); |
| 236 | 235 |
| 237 histogram_tester.ExpectTotalCount("NQE.RatioEstimatedToActualRTT.Unknown", 0); | 236 histogram_tester.ExpectTotalCount("NQE.RatioEstimatedToActualRTT.Unknown", 0); |
| 238 | 237 |
| 239 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 238 std::unique_ptr<URLRequest> request2(context.CreateRequest( |
| 240 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 239 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 241 request2->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); | 240 request2->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); |
| 242 request2->Start(); | 241 request2->Start(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 base::TimeDelta rtt; | 274 base::TimeDelta rtt; |
| 276 int32_t kbps; | 275 int32_t kbps; |
| 277 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); | 276 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 278 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 277 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 279 | 278 |
| 280 TestDelegate test_delegate; | 279 TestDelegate test_delegate; |
| 281 TestURLRequestContext context(true); | 280 TestURLRequestContext context(true); |
| 282 context.set_network_quality_estimator(&estimator); | 281 context.set_network_quality_estimator(&estimator); |
| 283 context.Init(); | 282 context.Init(); |
| 284 | 283 |
| 285 // Push 10 more observations than the maximum buffer size. | 284 // Push more observations than the maximum buffer size. |
| 286 for (size_t i = 0; i < estimator.kMaximumObservationsBufferSize + 10U; ++i) { | 285 const size_t kMaxObservations = 1000; |
| 286 for (size_t i = 0; i < kMaxObservations; ++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 // Verify that the stored observations are cleared on network change. | 295 // Verify that the stored observations are cleared on network change. |
| 296 estimator.SimulateNetworkChangeTo( | 296 estimator.SimulateNetworkChangeTo( |
| 297 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-2"); | 297 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-2"); |
| 298 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); | 298 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 299 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 299 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 300 } | 300 } |
| 301 | 301 |
| 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, | 302 // This test notifies NetworkQualityEstimator of received data. Next, |
| 446 // throughput and RTT percentiles are checked for correctness by doing simple | 303 // throughput and RTT percentiles are checked for correctness by doing simple |
| 447 // verifications. | 304 // verifications. |
| 448 TEST(NetworkQualityEstimatorTest, ComputedPercentiles) { | 305 TEST(NetworkQualityEstimatorTest, ComputedPercentiles) { |
| 449 std::map<std::string, std::string> variation_params; | 306 std::map<std::string, std::string> variation_params; |
| 450 TestNetworkQualityEstimator estimator(variation_params); | 307 TestNetworkQualityEstimator estimator(variation_params); |
| 451 | 308 |
| 452 std::vector<NetworkQualityEstimator::ObservationSource> | 309 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
| 453 disallowed_observation_sources; | 310 disallowed_observation_sources.push_back( |
| 454 disallowed_observation_sources.push_back(NetworkQualityEstimator::TCP); | 311 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); |
| 455 disallowed_observation_sources.push_back(NetworkQualityEstimator::QUIC); | 312 disallowed_observation_sources.push_back( |
| 313 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); |
| 456 | 314 |
| 457 EXPECT_EQ(NetworkQualityEstimator::InvalidRTT(), | 315 EXPECT_EQ(nqe::internal::InvalidRTT(), |
| 458 estimator.GetRTTEstimateInternal(disallowed_observation_sources, | 316 estimator.GetRTTEstimateInternal(disallowed_observation_sources, |
| 459 base::TimeTicks(), 100)); | 317 base::TimeTicks(), 100)); |
| 460 EXPECT_EQ(NetworkQualityEstimator::kInvalidThroughput, | 318 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
| 461 estimator.GetDownlinkThroughputKbpsEstimateInternal( | 319 estimator.GetDownlinkThroughputKbpsEstimateInternal( |
| 462 base::TimeTicks(), 100)); | 320 base::TimeTicks(), 100)); |
| 463 | 321 |
| 464 TestDelegate test_delegate; | 322 TestDelegate test_delegate; |
| 465 TestURLRequestContext context(true); | 323 TestURLRequestContext context(true); |
| 466 context.set_network_quality_estimator(&estimator); | 324 context.set_network_quality_estimator(&estimator); |
| 467 context.Init(); | 325 context.Init(); |
| 468 | 326 |
| 469 // Number of observations are more than the maximum buffer size. | 327 // Number of observations are more than the maximum buffer size. |
| 470 for (size_t i = 0; i < estimator.kMaximumObservationsBufferSize + 100U; ++i) { | 328 for (size_t i = 0; i < 1000U; ++i) { |
| 471 std::unique_ptr<URLRequest> request(context.CreateRequest( | 329 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 472 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 330 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 473 request->Start(); | 331 request->Start(); |
| 474 base::RunLoop().Run(); | 332 base::RunLoop().Run(); |
| 475 } | 333 } |
| 476 | 334 |
| 477 // Verify the percentiles through simple tests. | 335 // Verify the percentiles through simple tests. |
| 478 for (int i = 0; i <= 100; ++i) { | 336 for (int i = 0; i <= 100; ++i) { |
| 479 EXPECT_GT(estimator.GetDownlinkThroughputKbpsEstimateInternal( | 337 EXPECT_GT(estimator.GetDownlinkThroughputKbpsEstimateInternal( |
| 480 base::TimeTicks(), i), | 338 base::TimeTicks(), i), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 estimator.SimulateNetworkChangeTo( | 382 estimator.SimulateNetworkChangeTo( |
| 525 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 383 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
| 526 | 384 |
| 527 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | 385 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 528 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 386 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 529 EXPECT_EQ(200, kbps); | 387 EXPECT_EQ(200, kbps); |
| 530 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); | 388 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); |
| 531 | 389 |
| 532 // Peak network quality should not be affected by the network quality | 390 // Peak network quality should not be affected by the network quality |
| 533 // estimator field trial. | 391 // estimator field trial. |
| 534 EXPECT_EQ(NetworkQualityEstimator::InvalidRTT(), | 392 EXPECT_EQ(nqe::internal::InvalidRTT(), estimator.peak_network_quality_.rtt()); |
| 535 estimator.peak_network_quality_.rtt()); | 393 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
| 536 EXPECT_EQ(NetworkQualityEstimator::kInvalidThroughput, | |
| 537 estimator.peak_network_quality_.downstream_throughput_kbps()); | 394 estimator.peak_network_quality_.downstream_throughput_kbps()); |
| 538 | 395 |
| 539 // Simulate network change to 2G. Only the Kbps default estimate should be | 396 // Simulate network change to 2G. Only the Kbps default estimate should be |
| 540 // available. | 397 // available. |
| 541 estimator.SimulateNetworkChangeTo( | 398 estimator.SimulateNetworkChangeTo( |
| 542 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); | 399 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); |
| 543 | 400 |
| 544 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); | 401 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 545 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 402 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 546 EXPECT_EQ(300, kbps); | 403 EXPECT_EQ(300, kbps); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 // is invoked. | 557 // is invoked. |
| 701 TEST(NetworkQualityEstimatorTest, TestCaching) { | 558 TEST(NetworkQualityEstimatorTest, TestCaching) { |
| 702 std::map<std::string, std::string> variation_params; | 559 std::map<std::string, std::string> variation_params; |
| 703 TestNetworkQualityEstimator estimator(variation_params); | 560 TestNetworkQualityEstimator estimator(variation_params); |
| 704 size_t expected_cache_size = 0; | 561 size_t expected_cache_size = 0; |
| 705 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | 562 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); |
| 706 | 563 |
| 707 // Cache entry will not be added for (NONE, ""). | 564 // Cache entry will not be added for (NONE, ""). |
| 708 estimator.downstream_throughput_kbps_observations_.AddObservation( | 565 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 709 NetworkQualityEstimator::ThroughputObservation( | 566 NetworkQualityEstimator::ThroughputObservation( |
| 710 1, base::TimeTicks::Now(), NetworkQualityEstimator::URL_REQUEST)); | 567 1, base::TimeTicks::Now(), |
| 568 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 711 estimator.rtt_observations_.AddObservation( | 569 estimator.rtt_observations_.AddObservation( |
| 712 NetworkQualityEstimator::RttObservation( | 570 NetworkQualityEstimator::RttObservation( |
| 713 base::TimeDelta::FromMilliseconds(1000), base::TimeTicks::Now(), | 571 base::TimeDelta::FromMilliseconds(1000), base::TimeTicks::Now(), |
| 714 NetworkQualityEstimator::URL_REQUEST)); | 572 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 715 estimator.SimulateNetworkChangeTo( | 573 estimator.SimulateNetworkChangeTo( |
| 716 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); | 574 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); |
| 717 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | 575 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); |
| 718 | 576 |
| 719 // Entry will be added for (2G, "test1"). | 577 // Entry will be added for (2G, "test1"). |
| 720 // Also, set the network quality for (2G, "test1") so that it is stored in | 578 // Also, set the network quality for (2G, "test1") so that it is stored in |
| 721 // the cache. | 579 // the cache. |
| 722 estimator.downstream_throughput_kbps_observations_.AddObservation( | 580 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 723 NetworkQualityEstimator::ThroughputObservation( | 581 NetworkQualityEstimator::ThroughputObservation( |
| 724 1, base::TimeTicks::Now(), NetworkQualityEstimator::URL_REQUEST)); | 582 1, base::TimeTicks::Now(), |
| 583 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 725 estimator.rtt_observations_.AddObservation( | 584 estimator.rtt_observations_.AddObservation( |
| 726 NetworkQualityEstimator::RttObservation( | 585 NetworkQualityEstimator::RttObservation( |
| 727 base::TimeDelta::FromMilliseconds(1000), base::TimeTicks::Now(), | 586 base::TimeDelta::FromMilliseconds(1000), base::TimeTicks::Now(), |
| 728 NetworkQualityEstimator::URL_REQUEST)); | 587 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 729 | 588 |
| 730 estimator.SimulateNetworkChangeTo( | 589 estimator.SimulateNetworkChangeTo( |
| 731 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-1"); | 590 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-1"); |
| 732 ++expected_cache_size; | 591 ++expected_cache_size; |
| 733 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | 592 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); |
| 734 | 593 |
| 735 // Entry will be added for (3G, "test1"). | 594 // Entry will be added for (3G, "test1"). |
| 736 // Also, set the network quality for (3G, "test1") so that it is stored in | 595 // Also, set the network quality for (3G, "test1") so that it is stored in |
| 737 // the cache. | 596 // the cache. |
| 738 estimator.downstream_throughput_kbps_observations_.AddObservation( | 597 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 739 NetworkQualityEstimator::ThroughputObservation( | 598 NetworkQualityEstimator::ThroughputObservation( |
| 740 2, base::TimeTicks::Now(), NetworkQualityEstimator::URL_REQUEST)); | 599 2, base::TimeTicks::Now(), |
| 600 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 741 estimator.rtt_observations_.AddObservation( | 601 estimator.rtt_observations_.AddObservation( |
| 742 NetworkQualityEstimator::RttObservation( | 602 NetworkQualityEstimator::RttObservation( |
| 743 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), | 603 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), |
| 744 NetworkQualityEstimator::URL_REQUEST)); | 604 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 745 estimator.SimulateNetworkChangeTo( | 605 estimator.SimulateNetworkChangeTo( |
| 746 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-2"); | 606 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-2"); |
| 747 ++expected_cache_size; | 607 ++expected_cache_size; |
| 748 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | 608 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); |
| 749 | 609 |
| 750 // Entry will not be added for (3G, "test2"). | 610 // Entry will not be added for (3G, "test2"). |
| 751 estimator.SimulateNetworkChangeTo( | 611 estimator.SimulateNetworkChangeTo( |
| 752 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); | 612 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); |
| 753 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | 613 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); |
| 754 | 614 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 EXPECT_EQ(0U, estimator.cached_network_qualities_.size()); | 658 EXPECT_EQ(0U, estimator.cached_network_qualities_.size()); |
| 799 | 659 |
| 800 // Add 100 more networks than the maximum size of the cache. | 660 // Add 100 more networks than the maximum size of the cache. |
| 801 size_t network_count = | 661 size_t network_count = |
| 802 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize + 100; | 662 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize + 100; |
| 803 | 663 |
| 804 base::TimeTicks update_time_of_network_100; | 664 base::TimeTicks update_time_of_network_100; |
| 805 for (size_t i = 0; i < network_count; ++i) { | 665 for (size_t i = 0; i < network_count; ++i) { |
| 806 estimator.downstream_throughput_kbps_observations_.AddObservation( | 666 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 807 NetworkQualityEstimator::ThroughputObservation( | 667 NetworkQualityEstimator::ThroughputObservation( |
| 808 2, base::TimeTicks::Now(), NetworkQualityEstimator::URL_REQUEST)); | 668 2, base::TimeTicks::Now(), |
| 669 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 809 estimator.rtt_observations_.AddObservation( | 670 estimator.rtt_observations_.AddObservation( |
| 810 NetworkQualityEstimator::RttObservation( | 671 NetworkQualityEstimator::RttObservation( |
| 811 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), | 672 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), |
| 812 NetworkQualityEstimator::URL_REQUEST)); | 673 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 813 | 674 |
| 814 if (i == 100) | 675 if (i == 100) |
| 815 update_time_of_network_100 = base::TimeTicks::Now(); | 676 update_time_of_network_100 = base::TimeTicks::Now(); |
| 816 | 677 |
| 817 estimator.SimulateNetworkChangeTo( | 678 estimator.SimulateNetworkChangeTo( |
| 818 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, | 679 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, |
| 819 base::SizeTToString(i)); | 680 base::SizeTToString(i)); |
| 820 if (i < NetworkQualityEstimator::kMaximumNetworkQualityCacheSize) | 681 if (i < NetworkQualityEstimator::kMaximumNetworkQualityCacheSize) |
| 821 EXPECT_EQ(i, estimator.cached_network_qualities_.size()); | 682 EXPECT_EQ(i, estimator.cached_network_qualities_.size()); |
| 822 EXPECT_LE(estimator.cached_network_qualities_.size(), | 683 EXPECT_LE(estimator.cached_network_qualities_.size(), |
| 823 static_cast<size_t>( | 684 static_cast<size_t>( |
| 824 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize)); | 685 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize)); |
| 825 } | 686 } |
| 826 // One more call so that the last network is also written to cache. | 687 // One more call so that the last network is also written to cache. |
| 827 estimator.downstream_throughput_kbps_observations_.AddObservation( | 688 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 828 NetworkQualityEstimator::ThroughputObservation( | 689 NetworkQualityEstimator::ThroughputObservation( |
| 829 2, base::TimeTicks::Now(), NetworkQualityEstimator::URL_REQUEST)); | 690 2, base::TimeTicks::Now(), |
| 691 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 830 estimator.rtt_observations_.AddObservation( | 692 estimator.rtt_observations_.AddObservation( |
| 831 NetworkQualityEstimator::RttObservation( | 693 NetworkQualityEstimator::RttObservation( |
| 832 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), | 694 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), |
| 833 NetworkQualityEstimator::URL_REQUEST)); | 695 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 834 estimator.SimulateNetworkChangeTo( | 696 estimator.SimulateNetworkChangeTo( |
| 835 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, | 697 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, |
| 836 base::SizeTToString(network_count - 1)); | 698 base::SizeTToString(network_count - 1)); |
| 837 EXPECT_EQ(static_cast<size_t>( | 699 EXPECT_EQ(static_cast<size_t>( |
| 838 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize), | 700 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize), |
| 839 estimator.cached_network_qualities_.size()); | 701 estimator.cached_network_qualities_.size()); |
| 840 | 702 |
| 841 // Test that the cache is LRU by examining its contents. Networks in cache | 703 // Test that the cache is LRU by examining its contents. Networks in cache |
| 842 // must all be newer than the 100th network. | 704 // must all be newer than the 100th network. |
| 843 for (NetworkQualityEstimator::CachedNetworkQualities::iterator it = | 705 for (NetworkQualityEstimator::CachedNetworkQualities::iterator it = |
| 844 estimator.cached_network_qualities_.begin(); | 706 estimator.cached_network_qualities_.begin(); |
| 845 it != estimator.cached_network_qualities_.end(); ++it) { | 707 it != estimator.cached_network_qualities_.end(); ++it) { |
| 846 EXPECT_GE((it->second).last_update_time_, update_time_of_network_100); | 708 EXPECT_GE((it->second).last_update_time_, update_time_of_network_100); |
| 847 } | 709 } |
| 848 } | 710 } |
| 849 | 711 |
| 850 TEST(NetworkQualityEstimatorTest, TestGetMedianRTTSince) { | 712 TEST(NetworkQualityEstimatorTest, TestGetMedianRTTSince) { |
| 851 std::map<std::string, std::string> variation_params; | 713 std::map<std::string, std::string> variation_params; |
| 852 TestNetworkQualityEstimator estimator(variation_params); | 714 TestNetworkQualityEstimator estimator(variation_params); |
| 853 base::TimeTicks now = base::TimeTicks::Now(); | 715 base::TimeTicks now = base::TimeTicks::Now(); |
| 854 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1); | 716 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1); |
| 855 ASSERT_NE(old, now); | 717 ASSERT_NE(old, now); |
| 856 | 718 |
| 857 // First sample has very old timestamp. | 719 // First sample has very old timestamp. |
| 858 estimator.downstream_throughput_kbps_observations_.AddObservation( | 720 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 859 NetworkQualityEstimator::ThroughputObservation( | 721 NetworkQualityEstimator::ThroughputObservation( |
| 860 1, old, NetworkQualityEstimator::URL_REQUEST)); | 722 1, old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 861 estimator.rtt_observations_.AddObservation( | 723 estimator.rtt_observations_.AddObservation( |
| 862 NetworkQualityEstimator::RttObservation( | 724 NetworkQualityEstimator::RttObservation( |
| 863 base::TimeDelta::FromMilliseconds(1), old, | 725 base::TimeDelta::FromMilliseconds(1), old, |
| 864 NetworkQualityEstimator::URL_REQUEST)); | 726 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 865 | 727 |
| 866 estimator.downstream_throughput_kbps_observations_.AddObservation( | 728 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 867 NetworkQualityEstimator::ThroughputObservation( | 729 NetworkQualityEstimator::ThroughputObservation( |
| 868 100, now, NetworkQualityEstimator::URL_REQUEST)); | 730 100, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 869 estimator.rtt_observations_.AddObservation( | 731 estimator.rtt_observations_.AddObservation( |
| 870 NetworkQualityEstimator::RttObservation( | 732 NetworkQualityEstimator::RttObservation( |
| 871 base::TimeDelta::FromMilliseconds(100), now, | 733 base::TimeDelta::FromMilliseconds(100), now, |
| 872 NetworkQualityEstimator::URL_REQUEST)); | 734 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 873 | 735 |
| 874 const struct { | 736 const struct { |
| 875 base::TimeTicks start_timestamp; | 737 base::TimeTicks start_timestamp; |
| 876 bool expect_network_quality_available; | 738 bool expect_network_quality_available; |
| 877 base::TimeDelta expected_url_request_rtt; | 739 base::TimeDelta expected_url_request_rtt; |
| 878 int32_t expected_downstream_throughput; | 740 int32_t expected_downstream_throughput; |
| 879 } tests[] = { | 741 } tests[] = { |
| 880 {now + base::TimeDelta::FromSeconds(10), false, | 742 {now + base::TimeDelta::FromSeconds(10), false, |
| 881 base::TimeDelta::FromMilliseconds(0), 0}, | 743 base::TimeDelta::FromMilliseconds(0), 0}, |
| 882 {now, true, base::TimeDelta::FromMilliseconds(100), 100}, | 744 {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)); | 1103 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 1242 | 1104 |
| 1243 int32_t throughput; | 1105 int32_t throughput; |
| 1244 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&throughput)); | 1106 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&throughput)); |
| 1245 | 1107 |
| 1246 EXPECT_EQ(2U, rtt_observer.observations().size()); | 1108 EXPECT_EQ(2U, rtt_observer.observations().size()); |
| 1247 EXPECT_EQ(2U, throughput_observer.observations().size()); | 1109 EXPECT_EQ(2U, throughput_observer.observations().size()); |
| 1248 for (const auto& observation : rtt_observer.observations()) { | 1110 for (const auto& observation : rtt_observer.observations()) { |
| 1249 EXPECT_LE(0, observation.rtt_ms); | 1111 EXPECT_LE(0, observation.rtt_ms); |
| 1250 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); | 1112 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); |
| 1251 EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source); | 1113 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST, |
| 1114 observation.source); |
| 1252 } | 1115 } |
| 1253 for (const auto& observation : throughput_observer.observations()) { | 1116 for (const auto& observation : throughput_observer.observations()) { |
| 1254 EXPECT_LE(0, observation.throughput_kbps); | 1117 EXPECT_LE(0, observation.throughput_kbps); |
| 1255 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); | 1118 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); |
| 1256 EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source); | 1119 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST, |
| 1120 observation.source); |
| 1257 } | 1121 } |
| 1258 | 1122 |
| 1259 // Verify that observations from TCP and QUIC are passed on to the observers. | 1123 // Verify that observations from TCP and QUIC are passed on to the observers. |
| 1260 base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1)); | 1124 base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1)); |
| 1261 base::TimeDelta quic_rtt(base::TimeDelta::FromMilliseconds(2)); | 1125 base::TimeDelta quic_rtt(base::TimeDelta::FromMilliseconds(2)); |
| 1262 | 1126 |
| 1263 std::unique_ptr<SocketPerformanceWatcher> tcp_watcher = | 1127 std::unique_ptr<SocketPerformanceWatcher> tcp_watcher = |
| 1264 estimator.GetSocketPerformanceWatcherFactory() | 1128 estimator.GetSocketPerformanceWatcherFactory() |
| 1265 ->CreateSocketPerformanceWatcher( | 1129 ->CreateSocketPerformanceWatcher( |
| 1266 SocketPerformanceWatcherFactory::PROTOCOL_TCP); | 1130 SocketPerformanceWatcherFactory::PROTOCOL_TCP); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 | 1176 |
| 1313 EXPECT_EQ(0U, rtt_observer.observations().size()); | 1177 EXPECT_EQ(0U, rtt_observer.observations().size()); |
| 1314 base::TimeDelta rtt; | 1178 base::TimeDelta rtt; |
| 1315 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); | 1179 EXPECT_FALSE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 1316 | 1180 |
| 1317 // Send two requests. Verify that the completion of each request generates at | 1181 // Send two requests. Verify that the completion of each request generates at |
| 1318 // least one TCP RTT observation. | 1182 // least one TCP RTT observation. |
| 1319 for (size_t i = 0; i < 2; ++i) { | 1183 for (size_t i = 0; i < 2; ++i) { |
| 1320 size_t before_count_tcp_rtt_observations = 0; | 1184 size_t before_count_tcp_rtt_observations = 0; |
| 1321 for (const auto& observation : rtt_observer.observations()) { | 1185 for (const auto& observation : rtt_observer.observations()) { |
| 1322 if (observation.source == NetworkQualityEstimator::TCP) | 1186 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) |
| 1323 ++before_count_tcp_rtt_observations; | 1187 ++before_count_tcp_rtt_observations; |
| 1324 } | 1188 } |
| 1325 | 1189 |
| 1326 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1190 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1327 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1191 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1328 request->Start(); | 1192 request->Start(); |
| 1329 base::RunLoop().Run(); | 1193 base::RunLoop().Run(); |
| 1330 | 1194 |
| 1331 size_t after_count_tcp_rtt_observations = 0; | 1195 size_t after_count_tcp_rtt_observations = 0; |
| 1332 for (const auto& observation : rtt_observer.observations()) { | 1196 for (const auto& observation : rtt_observer.observations()) { |
| 1333 if (observation.source == NetworkQualityEstimator::TCP) | 1197 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) |
| 1334 ++after_count_tcp_rtt_observations; | 1198 ++after_count_tcp_rtt_observations; |
| 1335 } | 1199 } |
| 1336 // At least one notification should be received per socket performance | 1200 // At least one notification should be received per socket performance |
| 1337 // watcher. | 1201 // watcher. |
| 1338 EXPECT_LE(1U, after_count_tcp_rtt_observations - | 1202 EXPECT_LE(1U, after_count_tcp_rtt_observations - |
| 1339 before_count_tcp_rtt_observations) | 1203 before_count_tcp_rtt_observations) |
| 1340 << i; | 1204 << i; |
| 1341 } | 1205 } |
| 1342 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | 1206 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 1343 } | 1207 } |
| 1344 | 1208 |
| 1345 } // namespace net | 1209 } // namespace net |
| OLD | NEW |