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