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> |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 | 444 |
445 // RTT percentiles are in increasing order. | 445 // RTT percentiles are in increasing order. |
446 EXPECT_GE(estimator.GetRTTEstimateInternal(disallowed_observation_sources, | 446 EXPECT_GE(estimator.GetRTTEstimateInternal(disallowed_observation_sources, |
447 base::TimeTicks(), i), | 447 base::TimeTicks(), i), |
448 estimator.GetRTTEstimateInternal(disallowed_observation_sources, | 448 estimator.GetRTTEstimateInternal(disallowed_observation_sources, |
449 base::TimeTicks(), i - 1)); | 449 base::TimeTicks(), i - 1)); |
450 } | 450 } |
451 } | 451 } |
452 } | 452 } |
453 | 453 |
454 TEST(NetworkQualityEstimatorTest, ObtainOperatingParams) { | 454 // Verifies that the observers receive the notifications when default estimates |
| 455 // are added to the observations. |
| 456 TEST(NetworkQualityEstimatorTest, DefaultObservations) { |
| 457 TestEffectiveConnectionTypeObserver effective_connection_type_observer; |
| 458 TestRTTAndThroughputEstimatesObserver rtt_throughput_estimates_observer; |
| 459 TestRTTObserver rtt_observer; |
| 460 TestThroughputObserver throughput_observer; |
| 461 std::map<std::string, std::string> variation_params; |
| 462 TestNetworkQualityEstimator estimator( |
| 463 nullptr, variation_params, false, false, |
| 464 true /* add_default_platform_observations */); |
| 465 base::TimeDelta rtt; |
| 466 int32_t kbps; |
| 467 |
| 468 // Default estimates should be available. |
| 469 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 470 EXPECT_EQ(base::TimeDelta::FromMilliseconds(115), rtt); |
| 471 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 472 EXPECT_EQ(base::TimeDelta::FromMilliseconds(55), rtt); |
| 473 EXPECT_TRUE( |
| 474 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 475 EXPECT_EQ(1961, kbps); |
| 476 |
| 477 estimator.AddEffectiveConnectionTypeObserver( |
| 478 &effective_connection_type_observer); |
| 479 estimator.AddRTTAndThroughputEstimatesObserver( |
| 480 &rtt_throughput_estimates_observer); |
| 481 estimator.AddRTTObserver(&rtt_observer); |
| 482 estimator.AddThroughputObserver(&throughput_observer); |
| 483 |
| 484 // Simulate network change to 3G. Default estimates should be available. |
| 485 estimator.SimulateNetworkChange( |
| 486 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); |
| 487 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 488 // Taken from network_quality_estimator_params.cc. |
| 489 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), rtt); |
| 490 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 491 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), rtt); |
| 492 EXPECT_TRUE( |
| 493 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 494 EXPECT_EQ(749, kbps); |
| 495 |
| 496 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 497 estimator.GetEffectiveConnectionType()); |
| 498 EXPECT_EQ( |
| 499 1U, |
| 500 effective_connection_type_observer.effective_connection_types().size()); |
| 501 EXPECT_NE( |
| 502 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 503 effective_connection_type_observer.effective_connection_types().front()); |
| 504 |
| 505 EXPECT_EQ(3, rtt_throughput_estimates_observer.notifications_received()); |
| 506 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), |
| 507 rtt_throughput_estimates_observer.http_rtt()); |
| 508 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), |
| 509 rtt_throughput_estimates_observer.transport_rtt()); |
| 510 EXPECT_EQ(749, |
| 511 rtt_throughput_estimates_observer.downstream_throughput_kbps()); |
| 512 |
| 513 EXPECT_EQ(2U, rtt_observer.observations().size()); |
| 514 EXPECT_EQ(272, rtt_observer.observations().at(0).rtt_ms); |
| 515 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM, |
| 516 rtt_observer.observations().at(0).source); |
| 517 EXPECT_EQ(209, rtt_observer.observations().at(1).rtt_ms); |
| 518 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM, |
| 519 rtt_observer.observations().at(1).source); |
| 520 |
| 521 EXPECT_EQ(1U, throughput_observer.observations().size()); |
| 522 EXPECT_EQ(749, throughput_observer.observations().at(0).throughput_kbps); |
| 523 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM, |
| 524 throughput_observer.observations().at(0).source); |
| 525 } |
| 526 |
| 527 // Verifies that the default observations are added to the set of observations. |
| 528 // If default observations are overridden using field trial parameters, verify |
| 529 // that the overriding values are used. |
| 530 TEST(NetworkQualityEstimatorTest, DefaultObservationsOverridden) { |
455 std::map<std::string, std::string> variation_params; | 531 std::map<std::string, std::string> variation_params; |
456 variation_params["Unknown.DefaultMedianKbps"] = "100"; | 532 variation_params["Unknown.DefaultMedianKbps"] = "100"; |
457 variation_params["WiFi.DefaultMedianKbps"] = "200"; | 533 variation_params["WiFi.DefaultMedianKbps"] = "200"; |
458 variation_params["2G.DefaultMedianKbps"] = "300"; | 534 variation_params["2G.DefaultMedianKbps"] = "300"; |
459 | 535 |
460 variation_params["Unknown.DefaultMedianRTTMsec"] = "1000"; | 536 variation_params["Unknown.DefaultMedianRTTMsec"] = "1000"; |
461 variation_params["WiFi.DefaultMedianRTTMsec"] = "2000"; | 537 variation_params["WiFi.DefaultMedianRTTMsec"] = "2000"; |
462 // Negative variation value should not be used. | 538 // Negative variation value should not be used. |
463 variation_params["2G.DefaultMedianRTTMsec"] = "-5"; | 539 variation_params["2G.DefaultMedianRTTMsec"] = "-5"; |
464 | 540 |
465 TestNetworkQualityEstimator estimator(variation_params); | 541 variation_params["Unknown.DefaultMedianTransportRTTMsec"] = "500"; |
| 542 variation_params["WiFi.DefaultMedianTransportRTTMsec"] = "1000"; |
| 543 // Negative variation value should not be used. |
| 544 variation_params["2G.DefaultMedianTransportRTTMsec"] = "-5"; |
| 545 |
| 546 TestNetworkQualityEstimator estimator( |
| 547 nullptr, variation_params, false, false, |
| 548 true /* add_default_platform_observations */); |
466 | 549 |
467 base::TimeDelta rtt; | 550 base::TimeDelta rtt; |
| 551 int32_t kbps; |
| 552 |
468 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 553 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
469 int32_t kbps; | 554 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); |
| 555 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 556 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500), rtt); |
470 EXPECT_TRUE( | 557 EXPECT_TRUE( |
471 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 558 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
472 | |
473 EXPECT_EQ(100, kbps); | 559 EXPECT_EQ(100, kbps); |
474 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); | |
475 | |
476 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | |
477 | 560 |
478 // Simulate network change to Wi-Fi. | 561 // Simulate network change to Wi-Fi. |
479 estimator.SimulateNetworkChange( | 562 estimator.SimulateNetworkChange( |
480 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 563 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
481 | |
482 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 564 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 565 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); |
| 566 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 567 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); |
483 EXPECT_TRUE( | 568 EXPECT_TRUE( |
484 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 569 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
485 EXPECT_EQ(200, kbps); | 570 EXPECT_EQ(200, kbps); |
486 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); | |
487 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | |
488 | 571 |
489 // Peak network quality should not be affected by the network quality | 572 // Peak network quality should not be affected by the network quality |
490 // estimator field trial. | 573 // estimator field trial. |
491 EXPECT_EQ(nqe::internal::InvalidRTT(), | 574 EXPECT_EQ(nqe::internal::InvalidRTT(), |
492 estimator.peak_network_quality_.http_rtt()); | 575 estimator.peak_network_quality_.http_rtt()); |
493 EXPECT_EQ(nqe::internal::kInvalidThroughput, | 576 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
494 estimator.peak_network_quality_.downstream_throughput_kbps()); | 577 estimator.peak_network_quality_.downstream_throughput_kbps()); |
495 | 578 |
496 // Simulate network change to 2G. Only the Kbps default estimate should be | 579 // Simulate network change to 2G. Only the Kbps default estimate should be |
497 // available. | 580 // available. |
498 estimator.SimulateNetworkChange( | 581 estimator.SimulateNetworkChange( |
499 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); | 582 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); |
500 | 583 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
501 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 584 // Taken from network_quality_estimator_params.cc. |
| 585 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1726), rtt); |
| 586 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 587 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1531), rtt); |
502 EXPECT_TRUE( | 588 EXPECT_TRUE( |
503 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 589 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
504 EXPECT_EQ(300, kbps); | 590 EXPECT_EQ(300, kbps); |
505 | 591 |
506 // Simulate network change to 3G. Default estimates should be unavailable. | 592 // Simulate network change to 3G. Default estimates should be available. |
507 estimator.SimulateNetworkChange( | 593 estimator.SimulateNetworkChange( |
508 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); | 594 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); |
509 | 595 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
510 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 596 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), rtt); |
511 EXPECT_FALSE( | 597 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 598 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), rtt); |
| 599 EXPECT_TRUE( |
512 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 600 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 601 EXPECT_EQ(749, kbps); |
513 } | 602 } |
514 | 603 |
515 TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) { | 604 TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) { |
516 const struct { | 605 const struct { |
517 bool set_variation_param; | 606 bool set_variation_param; |
518 std::string algorithm; | 607 std::string algorithm; |
519 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm | 608 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm |
520 expected_algorithm; | 609 expected_algorithm; |
521 } tests[] = { | 610 } tests[] = { |
522 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: | 611 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 }, | 1421 }, |
1333 { | 1422 { |
1334 true, | 1423 true, |
1335 }, | 1424 }, |
1336 }; | 1425 }; |
1337 | 1426 |
1338 for (const auto& test : tests) { | 1427 for (const auto& test : tests) { |
1339 TestNetworkQualityEstimator estimator( | 1428 TestNetworkQualityEstimator estimator( |
1340 std::unique_ptr<net::ExternalEstimateProvider>(), variation_params, | 1429 std::unique_ptr<net::ExternalEstimateProvider>(), variation_params, |
1341 test.allow_small_localhost_requests, | 1430 test.allow_small_localhost_requests, |
1342 test.allow_small_localhost_requests); | 1431 test.allow_small_localhost_requests, false); |
1343 | 1432 |
1344 base::TimeDelta rtt; | 1433 base::TimeDelta rtt; |
1345 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 1434 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
1346 int32_t kbps; | 1435 int32_t kbps; |
1347 EXPECT_FALSE( | 1436 EXPECT_FALSE( |
1348 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 1437 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
1349 | 1438 |
1350 TestDelegate test_delegate; | 1439 TestDelegate test_delegate; |
1351 TestURLRequestContext context(true); | 1440 TestURLRequestContext context(true); |
1352 context.set_network_quality_estimator(&estimator); | 1441 context.set_network_quality_estimator(&estimator); |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2466 request->Start(); | 2555 request->Start(); |
2467 base::RunLoop().Run(); | 2556 base::RunLoop().Run(); |
2468 | 2557 |
2469 EXPECT_EQ(effective_connection_type, | 2558 EXPECT_EQ(effective_connection_type, |
2470 estimator.GetEffectiveConnectionType()); | 2559 estimator.GetEffectiveConnectionType()); |
2471 } | 2560 } |
2472 } | 2561 } |
2473 } | 2562 } |
2474 | 2563 |
2475 } // namespace net | 2564 } // namespace net |
OLD | NEW |