| 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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 EXPECT_EQ(300, kbps); | 565 EXPECT_EQ(300, kbps); |
| 566 | 566 |
| 567 // Simulate network change to 3G. Default estimates should be unavailable. | 567 // Simulate network change to 3G. Default estimates should be unavailable. |
| 568 estimator.SimulateNetworkChangeTo( | 568 estimator.SimulateNetworkChangeTo( |
| 569 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); | 569 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); |
| 570 | 570 |
| 571 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); | 571 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); |
| 572 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 572 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 573 } | 573 } |
| 574 | 574 |
| 575 TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) { |
| 576 const struct { |
| 577 bool set_variation_param; |
| 578 std::string algorithm; |
| 579 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm |
| 580 expected_algorithm; |
| 581 } tests[] = { |
| 582 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: |
| 583 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, |
| 584 {true, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: |
| 585 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, |
| 586 {true, "HttpRTTAndDownstreamThroughput", |
| 587 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: |
| 588 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, |
| 589 }; |
| 590 |
| 591 for (const auto& test : tests) { |
| 592 std::map<std::string, std::string> variation_params; |
| 593 if (test.set_variation_param) |
| 594 variation_params["effective_connection_type_algorithm"] = test.algorithm; |
| 595 |
| 596 TestNetworkQualityEstimator estimator(variation_params); |
| 597 EXPECT_EQ(test.expected_algorithm, |
| 598 estimator.effective_connection_type_algorithm_) |
| 599 << test.algorithm; |
| 600 } |
| 601 } |
| 602 |
| 575 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 603 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 576 // no variation params are specified. | 604 // no variation params are specified. |
| 577 TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) { | 605 TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) { |
| 578 std::map<std::string, std::string> variation_params; | 606 std::map<std::string, std::string> variation_params; |
| 579 | 607 |
| 580 TestNetworkQualityEstimator estimator(variation_params); | 608 TestNetworkQualityEstimator estimator(variation_params); |
| 581 | 609 |
| 582 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | 610 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 583 // does not return Offline if the device is offline. | 611 // does not return Offline if the device is offline. |
| 584 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, | 612 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| 585 "test"); | 613 "test"); |
| 586 | 614 |
| 587 const struct { | 615 const struct { |
| 588 int32_t rtt_msec; | 616 int32_t rtt_msec; |
| 589 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | 617 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; |
| 590 } tests[] = { | 618 } tests[] = { |
| 591 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 619 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 592 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 620 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 593 }; | 621 }; |
| 594 | 622 |
| 595 for (const auto& test : tests) { | 623 for (const auto& test : tests) { |
| 596 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 624 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 597 estimator.set_recent_http_rtt( | 625 estimator.set_recent_http_rtt( |
| 598 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 626 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 627 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 599 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 628 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 600 } | 629 } |
| 601 } | 630 } |
| 602 | 631 |
| 603 // Tests that |GetEffectiveConnectionType| returns | 632 // Tests that |GetEffectiveConnectionType| returns |
| 604 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. | 633 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. |
| 605 TEST(NetworkQualityEstimatorTest, Offline) { | 634 TEST(NetworkQualityEstimatorTest, Offline) { |
| 606 std::map<std::string, std::string> variation_params; | 635 std::map<std::string, std::string> variation_params; |
| 607 TestNetworkQualityEstimator estimator(variation_params); | 636 TestNetworkQualityEstimator estimator(variation_params); |
| 608 | 637 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 {300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 689 {300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 661 {200, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 690 {200, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 662 {100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 691 {100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 663 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 692 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 664 }; | 693 }; |
| 665 | 694 |
| 666 for (const auto& test : tests) { | 695 for (const auto& test : tests) { |
| 667 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 696 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 668 estimator.set_recent_http_rtt( | 697 estimator.set_recent_http_rtt( |
| 669 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 698 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 699 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 670 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 700 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 671 } | 701 } |
| 672 } | 702 } |
| 673 | 703 |
| 674 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 704 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 675 // both RTT and throughput thresholds are specified in the variation params. | 705 // both RTT and throughput thresholds are specified in the variation params. |
| 676 TEST(NetworkQualityEstimatorTest, ObtainThresholdsRTTandThroughput) { | 706 TEST(NetworkQualityEstimatorTest, ObtainThresholdsRTTandThroughput) { |
| 677 std::map<std::string, std::string> variation_params; | 707 std::map<std::string, std::string> variation_params; |
| 678 | 708 |
| 679 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; | 709 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 {1, 300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 742 {1, 300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 713 {1, 400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 743 {1, 400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 714 {1, 500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 744 {1, 500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 715 {1, 700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 745 {1, 700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 716 {1, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 746 {1, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 717 {1, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 747 {1, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 718 {1, 2500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 748 {1, 2500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 719 // Set both RTT and throughput. RTT is the bottleneck. | 749 // Set both RTT and throughput. RTT is the bottleneck. |
| 720 {3000, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 750 {3000, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 721 {700, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 751 {700, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 722 // Set throughput to an invalid value. | |
| 723 {3000, 0, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 724 {700, 0, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | |
| 725 }; | 752 }; |
| 726 | 753 |
| 727 for (const auto& test : tests) { | 754 for (const auto& test : tests) { |
| 728 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 755 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 729 estimator.set_recent_http_rtt( | 756 estimator.set_recent_http_rtt( |
| 730 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 757 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 731 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); | 758 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); |
| 732 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 759 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 733 } | 760 } |
| 734 } | 761 } |
| (...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1645 diff, 1); | 1672 diff, 1); |
| 1646 histogram_tester.ExpectTotalCount( | 1673 histogram_tester.ExpectTotalCount( |
| 1647 "NQE.Accuracy.TransportRTT.EstimatedObservedDiff." + | 1674 "NQE.Accuracy.TransportRTT.EstimatedObservedDiff." + |
| 1648 sign_suffix_with_zero_samples + "." + interval_value + ".60_140", | 1675 sign_suffix_with_zero_samples + "." + interval_value + ".60_140", |
| 1649 0); | 1676 0); |
| 1650 } | 1677 } |
| 1651 } | 1678 } |
| 1652 } | 1679 } |
| 1653 | 1680 |
| 1654 } // namespace net | 1681 } // namespace net |
| OLD | NEW |