| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 TestNetworkQualityEstimator( | 58 TestNetworkQualityEstimator( |
| 59 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider, | 59 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider, |
| 60 const std::map<std::string, std::string>& variation_params, | 60 const std::map<std::string, std::string>& variation_params, |
| 61 bool allow_local_host_requests_for_tests, | 61 bool allow_local_host_requests_for_tests, |
| 62 bool allow_smaller_responses_for_tests) | 62 bool allow_smaller_responses_for_tests) |
| 63 : NetworkQualityEstimator(std::move(external_estimate_provider), | 63 : NetworkQualityEstimator(std::move(external_estimate_provider), |
| 64 variation_params, | 64 variation_params, |
| 65 allow_local_host_requests_for_tests, | 65 allow_local_host_requests_for_tests, |
| 66 allow_smaller_responses_for_tests), | 66 allow_smaller_responses_for_tests), |
| 67 current_network_simulated_(false), | 67 current_network_simulated_(false), |
| 68 url_rtt_set_(false), | 68 http_rtt_set_(false), |
| 69 downlink_throughput_kbps_set_(false) { | 69 downlink_throughput_kbps_set_(false) { |
| 70 // Set up embedded test server. | 70 // Set up embedded test server. |
| 71 embedded_test_server_.ServeFilesFromDirectory( | 71 embedded_test_server_.ServeFilesFromDirectory( |
| 72 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 72 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 73 EXPECT_TRUE(embedded_test_server_.Start()); | 73 EXPECT_TRUE(embedded_test_server_.Start()); |
| 74 embedded_test_server_.RegisterRequestHandler(base::Bind( | 74 embedded_test_server_.RegisterRequestHandler(base::Bind( |
| 75 &TestNetworkQualityEstimator::HandleRequest, base::Unretained(this))); | 75 &TestNetworkQualityEstimator::HandleRequest, base::Unretained(this))); |
| 76 } | 76 } |
| 77 | 77 |
| 78 explicit TestNetworkQualityEstimator( | 78 explicit TestNetworkQualityEstimator( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 102 http_response->set_content("hello"); | 102 http_response->set_content("hello"); |
| 103 http_response->set_content_type("text/plain"); | 103 http_response->set_content_type("text/plain"); |
| 104 return std::move(http_response); | 104 return std::move(http_response); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Returns a GURL hosted at embedded test server. | 107 // Returns a GURL hosted at embedded test server. |
| 108 const GURL GetEchoURL() const { | 108 const GURL GetEchoURL() const { |
| 109 return embedded_test_server_.GetURL("/echo.html"); | 109 return embedded_test_server_.GetURL("/echo.html"); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void set_url_rtt(const base::TimeDelta& url_rtt) { | 112 void set_http_rtt(const base::TimeDelta& http_rtt) { |
| 113 url_rtt_set_ = true; | 113 http_rtt_set_ = true; |
| 114 url_rtt_ = url_rtt; | 114 http_rtt_ = http_rtt; |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool GetHttpRTTEstimate(base::TimeDelta* rtt) const override { | 117 bool GetHttpRTTEstimate(base::TimeDelta* rtt) const override { |
| 118 if (url_rtt_set_) { | 118 if (http_rtt_set_) { |
| 119 *rtt = url_rtt_; | 119 *rtt = http_rtt_; |
| 120 return true; | 120 return true; |
| 121 } | 121 } |
| 122 return NetworkQualityEstimator::GetHttpRTTEstimate(rtt); | 122 return NetworkQualityEstimator::GetHttpRTTEstimate(rtt); |
| 123 } | 123 } |
| 124 | 124 |
| 125 bool GetRecentHttpRTTMedian(const base::TimeTicks& start_time, |
| 126 base::TimeDelta* rtt) const override { |
| 127 if (http_rtt_set_) { |
| 128 *rtt = http_rtt_; |
| 129 return true; |
| 130 } |
| 131 return NetworkQualityEstimator::GetRecentHttpRTTMedian(start_time, rtt); |
| 132 } |
| 133 |
| 125 void set_downlink_throughput_kbps(int32_t downlink_throughput_kbps) { | 134 void set_downlink_throughput_kbps(int32_t downlink_throughput_kbps) { |
| 126 downlink_throughput_kbps_set_ = true; | 135 downlink_throughput_kbps_set_ = true; |
| 127 downlink_throughput_kbps_ = downlink_throughput_kbps; | 136 downlink_throughput_kbps_ = downlink_throughput_kbps; |
| 128 } | 137 } |
| 129 | 138 |
| 130 bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const override { | 139 bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const override { |
| 131 if (downlink_throughput_kbps_set_) { | 140 if (downlink_throughput_kbps_set_) { |
| 132 *kbps = downlink_throughput_kbps_; | 141 *kbps = downlink_throughput_kbps_; |
| 133 return true; | 142 return true; |
| 134 } | 143 } |
| 135 return NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimate(kbps); | 144 return NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimate(kbps); |
| 136 } | 145 } |
| 137 | 146 |
| 147 bool GetRecentMedianDownlinkThroughputKbps(const base::TimeTicks& start_time, |
| 148 int32_t* kbps) const override { |
| 149 if (downlink_throughput_kbps_set_) { |
| 150 *kbps = downlink_throughput_kbps_; |
| 151 return true; |
| 152 } |
| 153 return NetworkQualityEstimator::GetRecentMedianDownlinkThroughputKbps( |
| 154 start_time, kbps); |
| 155 } |
| 156 |
| 138 using NetworkQualityEstimator::ReadCachedNetworkQualityEstimate; | 157 using NetworkQualityEstimator::ReadCachedNetworkQualityEstimate; |
| 139 using NetworkQualityEstimator::OnConnectionTypeChanged; | 158 using NetworkQualityEstimator::OnConnectionTypeChanged; |
| 140 | 159 |
| 141 private: | 160 private: |
| 142 // True if the network type and network id are currently simulated. This | 161 // True if the network type and network id are currently simulated. This |
| 143 // ensures that the correctness of the test does not depend on the | 162 // ensures that the correctness of the test does not depend on the |
| 144 // actual network type of the device on which the test is running. | 163 // actual network type of the device on which the test is running. |
| 145 bool current_network_simulated_; | 164 bool current_network_simulated_; |
| 146 | 165 |
| 147 // NetworkQualityEstimator implementation that returns the overridden network | 166 // NetworkQualityEstimator implementation that returns the overridden network |
| 148 // id (instead of invoking platform APIs). | 167 // id (instead of invoking platform APIs). |
| 149 NetworkQualityEstimator::NetworkID GetCurrentNetworkID() const override { | 168 NetworkQualityEstimator::NetworkID GetCurrentNetworkID() const override { |
| 150 // GetCurrentNetworkID should be called only if the network type is | 169 // GetCurrentNetworkID should be called only if the network type is |
| 151 // currently simulated. | 170 // currently simulated. |
| 152 EXPECT_TRUE(current_network_simulated_); | 171 EXPECT_TRUE(current_network_simulated_); |
| 153 | 172 |
| 154 return NetworkQualityEstimator::NetworkID(current_network_type_, | 173 return NetworkQualityEstimator::NetworkID(current_network_type_, |
| 155 current_network_id_); | 174 current_network_id_); |
| 156 } | 175 } |
| 157 | 176 |
| 158 NetworkChangeNotifier::ConnectionType current_network_type_; | 177 NetworkChangeNotifier::ConnectionType current_network_type_; |
| 159 std::string current_network_id_; | 178 std::string current_network_id_; |
| 160 | 179 |
| 161 bool url_rtt_set_; | 180 bool http_rtt_set_; |
| 162 base::TimeDelta url_rtt_; | 181 base::TimeDelta http_rtt_; |
| 163 | 182 |
| 164 bool downlink_throughput_kbps_set_; | 183 bool downlink_throughput_kbps_set_; |
| 165 int32_t downlink_throughput_kbps_; | 184 int32_t downlink_throughput_kbps_; |
| 166 | 185 |
| 167 // Embedded server used for testing. | 186 // Embedded server used for testing. |
| 168 EmbeddedTestServer embedded_test_server_; | 187 EmbeddedTestServer embedded_test_server_; |
| 169 | 188 |
| 170 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); | 189 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); |
| 171 }; | 190 }; |
| 172 | 191 |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 471 |
| 453 const struct { | 472 const struct { |
| 454 int32_t rtt_msec; | 473 int32_t rtt_msec; |
| 455 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | 474 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; |
| 456 } tests[] = { | 475 } tests[] = { |
| 457 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 476 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 458 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 477 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 459 }; | 478 }; |
| 460 | 479 |
| 461 for (const auto& test : tests) { | 480 for (const auto& test : tests) { |
| 462 estimator.set_url_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 481 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 463 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 482 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 464 } | 483 } |
| 465 } | 484 } |
| 466 | 485 |
| 467 // Tests that |GetEffectiveConnectionType| returns | 486 // Tests that |GetEffectiveConnectionType| returns |
| 468 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. | 487 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. |
| 469 TEST(NetworkQualityEstimatorTest, Offline) { | 488 TEST(NetworkQualityEstimatorTest, Offline) { |
| 470 std::map<std::string, std::string> variation_params; | 489 std::map<std::string, std::string> variation_params; |
| 471 TestNetworkQualityEstimator estimator(variation_params); | 490 TestNetworkQualityEstimator estimator(variation_params); |
| 472 | 491 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 {700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 540 {700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 522 {500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 541 {500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 523 {400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 542 {400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 524 {300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 543 {300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 525 {200, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 544 {200, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 526 {100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 545 {100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 527 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 546 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 528 }; | 547 }; |
| 529 | 548 |
| 530 for (const auto& test : tests) { | 549 for (const auto& test : tests) { |
| 531 estimator.set_url_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 550 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 532 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 551 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 533 } | 552 } |
| 534 } | 553 } |
| 535 | 554 |
| 536 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 555 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 537 // both RTT and throughput thresholds are specified in the variation params. | 556 // both RTT and throughput thresholds are specified in the variation params. |
| 538 TEST(NetworkQualityEstimatorTest, ObtainThresholdsRTTandThroughput) { | 557 TEST(NetworkQualityEstimatorTest, ObtainThresholdsRTTandThroughput) { |
| 539 std::map<std::string, std::string> variation_params; | 558 std::map<std::string, std::string> variation_params; |
| 540 | 559 |
| 541 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; | 560 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 {1, 2500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 599 {1, 2500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 581 // Set both RTT and throughput. RTT is the bottleneck. | 600 // Set both RTT and throughput. RTT is the bottleneck. |
| 582 {3000, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 601 {3000, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 583 {700, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 602 {700, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 584 // Set throughput to an invalid value. | 603 // Set throughput to an invalid value. |
| 585 {3000, 0, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 604 {3000, 0, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 586 {700, 0, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 605 {700, 0, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 587 }; | 606 }; |
| 588 | 607 |
| 589 for (const auto& test : tests) { | 608 for (const auto& test : tests) { |
| 590 estimator.set_url_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 609 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 591 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); | 610 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); |
| 592 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 611 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 593 } | 612 } |
| 594 } | 613 } |
| 595 | 614 |
| 596 // Tests if |weight_multiplier_per_second_| is set to correct value for various | 615 // Tests if |weight_multiplier_per_second_| is set to correct value for various |
| 597 // values of half life parameter. | 616 // values of half life parameter. |
| 598 TEST(NetworkQualityEstimatorTest, HalfLifeParam) { | 617 TEST(NetworkQualityEstimatorTest, HalfLifeParam) { |
| 599 std::map<std::string, std::string> variation_params; | 618 std::map<std::string, std::string> variation_params; |
| 600 | 619 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 | 791 |
| 773 // Test that the cache is LRU by examining its contents. Networks in cache | 792 // Test that the cache is LRU by examining its contents. Networks in cache |
| 774 // must all be newer than the 100th network. | 793 // must all be newer than the 100th network. |
| 775 for (NetworkQualityEstimator::CachedNetworkQualities::iterator it = | 794 for (NetworkQualityEstimator::CachedNetworkQualities::iterator it = |
| 776 estimator.cached_network_qualities_.begin(); | 795 estimator.cached_network_qualities_.begin(); |
| 777 it != estimator.cached_network_qualities_.end(); ++it) { | 796 it != estimator.cached_network_qualities_.end(); ++it) { |
| 778 EXPECT_GE((it->second).last_update_time_, update_time_of_network_100); | 797 EXPECT_GE((it->second).last_update_time_, update_time_of_network_100); |
| 779 } | 798 } |
| 780 } | 799 } |
| 781 | 800 |
| 782 TEST(NetworkQualityEstimatorTest, TestGetMedianRTTSince) { | 801 TEST(NetworkQualityEstimatorTest, TestGetMetricsSince) { |
| 783 std::map<std::string, std::string> variation_params; | 802 std::map<std::string, std::string> variation_params; |
| 803 |
| 804 const base::TimeDelta rtt_threshold_4g = |
| 805 base::TimeDelta::FromMilliseconds(30); |
| 806 const base::TimeDelta rtt_threshold_broadband = |
| 807 base::TimeDelta::FromMilliseconds(1); |
| 808 |
| 809 variation_params["4G.ThresholdMedianHttpRTTMsec"] = |
| 810 base::IntToString(rtt_threshold_4g.InMilliseconds()); |
| 811 variation_params["Broadband.ThresholdMedianHttpRTTMsec"] = |
| 812 base::IntToString(rtt_threshold_broadband.InMilliseconds()); |
| 813 variation_params["HalfLifeSeconds"] = "300000"; |
| 814 |
| 784 TestNetworkQualityEstimator estimator(variation_params); | 815 TestNetworkQualityEstimator estimator(variation_params); |
| 785 base::TimeTicks now = base::TimeTicks::Now(); | 816 base::TimeTicks now = base::TimeTicks::Now(); |
| 786 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1); | 817 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1); |
| 787 ASSERT_NE(old, now); | 818 ASSERT_NE(old, now); |
| 788 | 819 |
| 820 estimator.SimulateNetworkChangeTo( |
| 821 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test"); |
| 822 |
| 823 const int32_t old_downlink_kbps = 1; |
| 824 const base::TimeDelta old_url_rtt = base::TimeDelta::FromMilliseconds(1); |
| 825 const base::TimeDelta old_tcp_rtt = base::TimeDelta::FromMilliseconds(10); |
| 826 |
| 827 DCHECK_LT(old_url_rtt, rtt_threshold_4g); |
| 828 DCHECK_LT(old_tcp_rtt, rtt_threshold_4g); |
| 829 |
| 789 // First sample has very old timestamp. | 830 // First sample has very old timestamp. |
| 831 for (size_t i = 0; i < 2; ++i) { |
| 832 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 833 NetworkQualityEstimator::ThroughputObservation( |
| 834 old_downlink_kbps, old, |
| 835 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 836 estimator.rtt_observations_.AddObservation( |
| 837 NetworkQualityEstimator::RttObservation( |
| 838 old_url_rtt, old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 839 estimator.rtt_observations_.AddObservation( |
| 840 NetworkQualityEstimator::RttObservation( |
| 841 old_tcp_rtt, old, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); |
| 842 } |
| 843 |
| 844 const int32_t new_downlink_kbps = 100; |
| 845 const base::TimeDelta new_url_rtt = base::TimeDelta::FromMilliseconds(100); |
| 846 const base::TimeDelta new_tcp_rtt = base::TimeDelta::FromMilliseconds(1000); |
| 847 |
| 848 DCHECK_NE(old_downlink_kbps, new_downlink_kbps); |
| 849 DCHECK_NE(old_url_rtt, new_url_rtt); |
| 850 DCHECK_NE(old_tcp_rtt, new_tcp_rtt); |
| 851 DCHECK_GT(new_url_rtt, rtt_threshold_4g); |
| 852 DCHECK_GT(new_tcp_rtt, rtt_threshold_4g); |
| 853 DCHECK_GT(new_url_rtt, rtt_threshold_broadband); |
| 854 DCHECK_GT(new_tcp_rtt, rtt_threshold_broadband); |
| 855 |
| 790 estimator.downstream_throughput_kbps_observations_.AddObservation( | 856 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 791 NetworkQualityEstimator::ThroughputObservation( | 857 NetworkQualityEstimator::ThroughputObservation( |
| 792 1, old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 858 new_downlink_kbps, now, |
| 793 estimator.rtt_observations_.AddObservation( | |
| 794 NetworkQualityEstimator::RttObservation( | |
| 795 base::TimeDelta::FromMilliseconds(1), old, | |
| 796 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 859 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 797 estimator.rtt_observations_.AddObservation( | 860 estimator.rtt_observations_.AddObservation( |
| 798 NetworkQualityEstimator::RttObservation( | 861 NetworkQualityEstimator::RttObservation( |
| 799 base::TimeDelta::FromMilliseconds(10), old, | 862 new_url_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| 800 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); | |
| 801 | |
| 802 estimator.downstream_throughput_kbps_observations_.AddObservation( | |
| 803 NetworkQualityEstimator::ThroughputObservation( | |
| 804 100, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 805 estimator.rtt_observations_.AddObservation( | 863 estimator.rtt_observations_.AddObservation( |
| 806 NetworkQualityEstimator::RttObservation( | 864 NetworkQualityEstimator::RttObservation( |
| 807 base::TimeDelta::FromMilliseconds(100), now, | 865 new_tcp_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); |
| 808 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 809 estimator.rtt_observations_.AddObservation( | |
| 810 NetworkQualityEstimator::RttObservation( | |
| 811 base::TimeDelta::FromMilliseconds(1000), now, | |
| 812 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); | |
| 813 | 866 |
| 814 const struct { | 867 const struct { |
| 815 base::TimeTicks start_timestamp; | 868 base::TimeTicks start_timestamp; |
| 816 bool expect_network_quality_available; | 869 bool expect_network_quality_available; |
| 817 base::TimeDelta expected_http_rtt; | 870 base::TimeDelta expected_http_rtt; |
| 818 base::TimeDelta expected_transport_rtt; | 871 base::TimeDelta expected_transport_rtt; |
| 819 int32_t expected_downstream_throughput; | 872 int32_t expected_downstream_throughput; |
| 873 NetworkQualityEstimator::EffectiveConnectionType |
| 874 expected_effective_connection_type; |
| 820 } tests[] = { | 875 } tests[] = { |
| 821 {now + base::TimeDelta::FromSeconds(10), false, | 876 {now + base::TimeDelta::FromSeconds(10), false, |
| 822 base::TimeDelta::FromMilliseconds(0), | 877 base::TimeDelta::FromMilliseconds(0), |
| 823 base::TimeDelta::FromMilliseconds(0), 0}, | 878 base::TimeDelta::FromMilliseconds(0), 0, |
| 824 {now, true, base::TimeDelta::FromMilliseconds(100), | 879 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 825 base::TimeDelta::FromMilliseconds(1000), 100}, | 880 {now, true, new_url_rtt, new_tcp_rtt, new_downlink_kbps, |
| 826 {now - base::TimeDelta::FromMicroseconds(500), true, | 881 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 827 base::TimeDelta::FromMilliseconds(100), | 882 {old - base::TimeDelta::FromMicroseconds(500), true, old_url_rtt, |
| 828 base::TimeDelta::FromMilliseconds(1000), 100}, | 883 old_tcp_rtt, old_downlink_kbps, |
| 884 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 829 | 885 |
| 830 }; | 886 }; |
| 831 | |
| 832 for (const auto& test : tests) { | 887 for (const auto& test : tests) { |
| 833 base::TimeDelta http_rtt; | 888 base::TimeDelta http_rtt; |
| 834 base::TimeDelta transport_rtt; | 889 base::TimeDelta transport_rtt; |
| 835 int32_t downstream_throughput_kbps; | 890 int32_t downstream_throughput_kbps; |
| 836 EXPECT_EQ( | 891 EXPECT_EQ( |
| 837 test.expect_network_quality_available, | 892 test.expect_network_quality_available, |
| 838 estimator.GetRecentHttpRTTMedian(test.start_timestamp, &http_rtt)); | 893 estimator.GetRecentHttpRTTMedian(test.start_timestamp, &http_rtt)); |
| 839 EXPECT_EQ(test.expect_network_quality_available, | 894 EXPECT_EQ(test.expect_network_quality_available, |
| 840 estimator.GetRecentTransportRTTMedian(test.start_timestamp, | 895 estimator.GetRecentTransportRTTMedian(test.start_timestamp, |
| 841 &transport_rtt)); | 896 &transport_rtt)); |
| 842 EXPECT_EQ(test.expect_network_quality_available, | 897 EXPECT_EQ(test.expect_network_quality_available, |
| 843 estimator.GetRecentMedianDownlinkThroughputKbps( | 898 estimator.GetRecentMedianDownlinkThroughputKbps( |
| 844 test.start_timestamp, &downstream_throughput_kbps)); | 899 test.start_timestamp, &downstream_throughput_kbps)); |
| 845 | 900 |
| 846 if (test.expect_network_quality_available) { | 901 if (test.expect_network_quality_available) { |
| 847 EXPECT_EQ(test.expected_http_rtt, http_rtt); | 902 EXPECT_EQ(test.expected_http_rtt, http_rtt); |
| 848 EXPECT_EQ(test.expected_transport_rtt, transport_rtt); | 903 EXPECT_EQ(test.expected_transport_rtt, transport_rtt); |
| 849 EXPECT_EQ(test.expected_downstream_throughput, | 904 EXPECT_EQ(test.expected_downstream_throughput, |
| 850 downstream_throughput_kbps); | 905 downstream_throughput_kbps); |
| 906 EXPECT_EQ( |
| 907 test.expected_effective_connection_type, |
| 908 estimator.GetRecentEffectiveConnectionType(test.start_timestamp)); |
| 851 } | 909 } |
| 852 } | 910 } |
| 853 } | 911 } |
| 854 | 912 |
| 855 // An external estimate provider that does not have a valid RTT or throughput | 913 // An external estimate provider that does not have a valid RTT or throughput |
| 856 // estimate. | 914 // estimate. |
| 857 class InvalidExternalEstimateProvider : public ExternalEstimateProvider { | 915 class InvalidExternalEstimateProvider : public ExternalEstimateProvider { |
| 858 public: | 916 public: |
| 859 InvalidExternalEstimateProvider() | 917 InvalidExternalEstimateProvider() |
| 860 : get_rtt_count_(0), get_downstream_throughput_count_(0) {} | 918 : get_rtt_count_(0), get_downstream_throughput_count_(0) {} |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 histogram_tester.ExpectBucketCount("NQE.TransportRTT.Percentile50.Unknown", | 1420 histogram_tester.ExpectBucketCount("NQE.TransportRTT.Percentile50.Unknown", |
| 1363 rtt.InMilliseconds(), 1); | 1421 rtt.InMilliseconds(), 1); |
| 1364 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile10.Unknown", 1); | 1422 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile10.Unknown", 1); |
| 1365 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 1); | 1423 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 1); |
| 1366 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); | 1424 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); |
| 1367 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", | 1425 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", |
| 1368 1); | 1426 1); |
| 1369 } | 1427 } |
| 1370 | 1428 |
| 1371 } // namespace net | 1429 } // namespace net |
| OLD | NEW |