| 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 10 matching lines...) Expand all Loading... |
| 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/test/simple_test_tick_clock.h" | 24 #include "base/test/simple_test_tick_clock.h" |
| 25 #include "base/threading/platform_thread.h" | 25 #include "base/threading/platform_thread.h" |
| 26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 28 #include "net/base/load_flags.h" | 28 #include "net/base/load_flags.h" |
| 29 #include "net/base/network_change_notifier.h" | 29 #include "net/base/network_change_notifier.h" |
| 30 #include "net/http/http_status_code.h" | 30 #include "net/http/http_status_code.h" |
| 31 #include "net/nqe/effective_connection_type.h" |
| 31 #include "net/nqe/external_estimate_provider.h" | 32 #include "net/nqe/external_estimate_provider.h" |
| 32 #include "net/nqe/network_quality_observation.h" | 33 #include "net/nqe/network_quality_observation.h" |
| 33 #include "net/nqe/network_quality_observation_source.h" | 34 #include "net/nqe/network_quality_observation_source.h" |
| 34 #include "net/nqe/observation_buffer.h" | 35 #include "net/nqe/observation_buffer.h" |
| 35 #include "net/socket/socket_performance_watcher.h" | 36 #include "net/socket/socket_performance_watcher.h" |
| 36 #include "net/socket/socket_performance_watcher_factory.h" | 37 #include "net/socket/socket_performance_watcher_factory.h" |
| 37 #include "net/test/embedded_test_server/embedded_test_server.h" | 38 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 38 #include "net/test/embedded_test_server/http_request.h" | 39 #include "net/test/embedded_test_server/http_request.h" |
| 39 #include "net/test/embedded_test_server/http_response.h" | 40 #include "net/test/embedded_test_server/http_response.h" |
| 40 #include "net/url_request/url_request.h" | 41 #include "net/url_request/url_request.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 314 |
| 314 // Embedded server used for testing. | 315 // Embedded server used for testing. |
| 315 EmbeddedTestServer embedded_test_server_; | 316 EmbeddedTestServer embedded_test_server_; |
| 316 | 317 |
| 317 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); | 318 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); |
| 318 }; | 319 }; |
| 319 | 320 |
| 320 class TestEffectiveConnectionTypeObserver | 321 class TestEffectiveConnectionTypeObserver |
| 321 : public NetworkQualityEstimator::EffectiveConnectionTypeObserver { | 322 : public NetworkQualityEstimator::EffectiveConnectionTypeObserver { |
| 322 public: | 323 public: |
| 323 std::vector<NetworkQualityEstimator::EffectiveConnectionType>& | 324 std::vector<EffectiveConnectionType>& effective_connection_types() { |
| 324 effective_connection_types() { | |
| 325 return effective_connection_types_; | 325 return effective_connection_types_; |
| 326 } | 326 } |
| 327 | 327 |
| 328 // EffectiveConnectionTypeObserver implementation: | 328 // EffectiveConnectionTypeObserver implementation: |
| 329 void OnEffectiveConnectionTypeChanged( | 329 void OnEffectiveConnectionTypeChanged(EffectiveConnectionType type) override { |
| 330 NetworkQualityEstimator::EffectiveConnectionType type) override { | |
| 331 effective_connection_types_.push_back(type); | 330 effective_connection_types_.push_back(type); |
| 332 } | 331 } |
| 333 | 332 |
| 334 private: | 333 private: |
| 335 std::vector<NetworkQualityEstimator::EffectiveConnectionType> | 334 std::vector<EffectiveConnectionType> effective_connection_types_; |
| 336 effective_connection_types_; | |
| 337 }; | 335 }; |
| 338 | 336 |
| 339 class TestRTTObserver : public NetworkQualityEstimator::RTTObserver { | 337 class TestRTTObserver : public NetworkQualityEstimator::RTTObserver { |
| 340 public: | 338 public: |
| 341 struct Observation { | 339 struct Observation { |
| 342 Observation(int32_t ms, | 340 Observation(int32_t ms, |
| 343 const base::TimeTicks& ts, | 341 const base::TimeTicks& ts, |
| 344 NetworkQualityObservationSource src) | 342 NetworkQualityObservationSource src) |
| 345 : rtt_ms(ms), timestamp(ts), source(src) {} | 343 : rtt_ms(ms), timestamp(ts), source(src) {} |
| 346 int32_t rtt_ms; | 344 int32_t rtt_ms; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 // Both RTT and downstream throughput should be updated. | 418 // Both RTT and downstream throughput should be updated. |
| 421 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); | 419 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); |
| 422 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 420 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 423 EXPECT_FALSE(estimator.GetTransportRTTEstimate(&rtt)); | 421 EXPECT_FALSE(estimator.GetTransportRTTEstimate(&rtt)); |
| 424 | 422 |
| 425 // Check UMA histograms. | 423 // Check UMA histograms. |
| 426 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); | 424 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); |
| 427 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); | 425 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); |
| 428 histogram_tester.ExpectUniqueSample( | 426 histogram_tester.ExpectUniqueSample( |
| 429 "NQE.MainFrame.EffectiveConnectionType.Unknown", | 427 "NQE.MainFrame.EffectiveConnectionType.Unknown", |
| 430 NetworkQualityEstimator::EffectiveConnectionType:: | 428 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); |
| 431 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | |
| 432 1); | |
| 433 | 429 |
| 434 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 430 std::unique_ptr<URLRequest> request2(context.CreateRequest( |
| 435 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 431 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 436 request2->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); | 432 request2->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); |
| 437 request2->Start(); | 433 request2->Start(); |
| 438 base::RunLoop().Run(); | 434 base::RunLoop().Run(); |
| 439 histogram_tester.ExpectTotalCount( | 435 histogram_tester.ExpectTotalCount( |
| 440 "NQE.MainFrame.EffectiveConnectionType.Unknown", 2); | 436 "NQE.MainFrame.EffectiveConnectionType.Unknown", 2); |
| 441 | 437 |
| 442 estimator.SimulateNetworkChangeTo( | 438 estimator.SimulateNetworkChangeTo( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); | 473 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); |
| 478 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 474 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 479 | 475 |
| 480 std::unique_ptr<URLRequest> request3(context.CreateRequest( | 476 std::unique_ptr<URLRequest> request3(context.CreateRequest( |
| 481 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 477 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 482 request3->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); | 478 request3->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); |
| 483 request3->Start(); | 479 request3->Start(); |
| 484 base::RunLoop().Run(); | 480 base::RunLoop().Run(); |
| 485 histogram_tester.ExpectUniqueSample( | 481 histogram_tester.ExpectUniqueSample( |
| 486 "NQE.MainFrame.EffectiveConnectionType.WiFi", | 482 "NQE.MainFrame.EffectiveConnectionType.WiFi", |
| 487 NetworkQualityEstimator::EffectiveConnectionType:: | 483 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); |
| 488 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | |
| 489 1); | |
| 490 | 484 |
| 491 estimator.SimulateNetworkChangeTo( | 485 estimator.SimulateNetworkChangeTo( |
| 492 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test"); | 486 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test"); |
| 493 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false, | 487 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false, |
| 494 3); | 488 3); |
| 495 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true, | 489 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true, |
| 496 1); | 490 1); |
| 497 } | 491 } |
| 498 | 492 |
| 499 TEST(NetworkQualityEstimatorTest, StoreObservations) { | 493 TEST(NetworkQualityEstimatorTest, StoreObservations) { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 } | 686 } |
| 693 | 687 |
| 694 // Tests that |GetEffectiveConnectionType| returns | 688 // Tests that |GetEffectiveConnectionType| returns |
| 695 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. | 689 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. |
| 696 TEST(NetworkQualityEstimatorTest, Offline) { | 690 TEST(NetworkQualityEstimatorTest, Offline) { |
| 697 std::map<std::string, std::string> variation_params; | 691 std::map<std::string, std::string> variation_params; |
| 698 TestNetworkQualityEstimator estimator(variation_params); | 692 TestNetworkQualityEstimator estimator(variation_params); |
| 699 | 693 |
| 700 const struct { | 694 const struct { |
| 701 NetworkChangeNotifier::ConnectionType connection_type; | 695 NetworkChangeNotifier::ConnectionType connection_type; |
| 702 NetworkQualityEstimator::EffectiveConnectionType expected_connection_type; | 696 EffectiveConnectionType expected_connection_type; |
| 703 } tests[] = { | 697 } tests[] = { |
| 704 {NetworkChangeNotifier::CONNECTION_2G, | 698 {NetworkChangeNotifier::CONNECTION_2G, EFFECTIVE_CONNECTION_TYPE_UNKNOWN}, |
| 705 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN}, | |
| 706 {NetworkChangeNotifier::CONNECTION_NONE, | 699 {NetworkChangeNotifier::CONNECTION_NONE, |
| 707 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 700 EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 708 {NetworkChangeNotifier::CONNECTION_3G, | 701 {NetworkChangeNotifier::CONNECTION_3G, EFFECTIVE_CONNECTION_TYPE_UNKNOWN}, |
| 709 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN}, | |
| 710 }; | 702 }; |
| 711 | 703 |
| 712 for (const auto& test : tests) { | 704 for (const auto& test : tests) { |
| 713 estimator.SimulateNetworkChangeTo(test.connection_type, "test"); | 705 estimator.SimulateNetworkChangeTo(test.connection_type, "test"); |
| 714 EXPECT_EQ(test.expected_connection_type, | 706 EXPECT_EQ(test.expected_connection_type, |
| 715 estimator.GetEffectiveConnectionType()); | 707 estimator.GetEffectiveConnectionType()); |
| 716 } | 708 } |
| 717 } | 709 } |
| 718 | 710 |
| 719 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 711 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| (...skipping 10 matching lines...) Expand all Loading... |
| 730 | 722 |
| 731 TestNetworkQualityEstimator estimator(variation_params); | 723 TestNetworkQualityEstimator estimator(variation_params); |
| 732 | 724 |
| 733 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | 725 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 734 // does not return Offline if the device is offline. | 726 // does not return Offline if the device is offline. |
| 735 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, | 727 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| 736 "test"); | 728 "test"); |
| 737 | 729 |
| 738 const struct { | 730 const struct { |
| 739 int32_t rtt_msec; | 731 int32_t rtt_msec; |
| 740 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | 732 EffectiveConnectionType expected_conn_type; |
| 741 } tests[] = { | 733 } tests[] = { |
| 742 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 734 {5000, EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 743 {4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 735 {4000, EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 744 {3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 736 {3000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 745 {2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 737 {2000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 746 {1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 738 {1500, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 747 {1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 739 {1000, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 748 {700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 740 {700, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 749 {500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 741 {500, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 750 {400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 742 {400, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 751 {300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 743 {300, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 752 {200, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 744 {200, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 753 {100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 745 {100, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 754 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 746 {20, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 755 }; | 747 }; |
| 756 | 748 |
| 757 for (const auto& test : tests) { | 749 for (const auto& test : tests) { |
| 758 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 750 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 759 estimator.set_recent_http_rtt( | 751 estimator.set_recent_http_rtt( |
| 760 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 752 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 761 estimator.set_downlink_throughput_kbps(INT32_MAX); | 753 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 762 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | 754 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| 763 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 755 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 764 } | 756 } |
| 765 } | 757 } |
| 766 | 758 |
| 767 // Tests that default transport RTT thresholds for different effective | 759 // Tests that default transport RTT thresholds for different effective |
| 768 // connection types are correctly set. | 760 // connection types are correctly set. |
| 769 TEST(NetworkQualityEstimatorTest, DefaultTransportRTTBasedThresholds) { | 761 TEST(NetworkQualityEstimatorTest, DefaultTransportRTTBasedThresholds) { |
| 770 const struct { | 762 const struct { |
| 771 bool override_defaults_using_variation_params; | 763 bool override_defaults_using_variation_params; |
| 772 int32_t transport_rtt_msec; | 764 int32_t transport_rtt_msec; |
| 773 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | 765 EffectiveConnectionType expected_conn_type; |
| 774 } tests[] = { | 766 } tests[] = { |
| 775 // When the variation params do not override connection thresholds, | 767 // When the variation params do not override connection thresholds, |
| 776 // default values should be used. | 768 // default values should be used. |
| 777 {false, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 769 {false, 5000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 778 {false, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 770 {false, 4000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 779 {false, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 771 {false, 3000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 780 {false, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 772 {false, 2000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 781 {false, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 773 {false, 1500, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 782 {false, 1000, | 774 {false, 1000, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 783 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 775 {false, 20, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 784 {false, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 785 // Override default thresholds using variation params. | 776 // Override default thresholds using variation params. |
| 786 {true, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 777 {true, 5000, EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 787 {true, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 778 {true, 4000, EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 788 {true, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 779 {true, 3000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 789 {true, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 780 {true, 2000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 790 {true, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 781 {true, 1500, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 791 {true, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 782 {true, 1000, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 792 {true, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 783 {true, 20, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 793 }; | 784 }; |
| 794 | 785 |
| 795 for (const auto& test : tests) { | 786 for (const auto& test : tests) { |
| 796 std::map<std::string, std::string> variation_params; | 787 std::map<std::string, std::string> variation_params; |
| 797 variation_params["effective_connection_type_algorithm"] = | 788 variation_params["effective_connection_type_algorithm"] = |
| 798 "TransportRTTOrDownstreamThroughput"; | 789 "TransportRTTOrDownstreamThroughput"; |
| 799 if (test.override_defaults_using_variation_params) { | 790 if (test.override_defaults_using_variation_params) { |
| 800 variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000"; | 791 variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000"; |
| 801 variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000"; | 792 variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000"; |
| 802 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; | 793 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 818 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 809 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 819 } | 810 } |
| 820 } | 811 } |
| 821 | 812 |
| 822 // Tests that default HTTP RTT thresholds for different effective | 813 // Tests that default HTTP RTT thresholds for different effective |
| 823 // connection types are correctly set. | 814 // connection types are correctly set. |
| 824 TEST(NetworkQualityEstimatorTest, DefaultHttpRTTBasedThresholds) { | 815 TEST(NetworkQualityEstimatorTest, DefaultHttpRTTBasedThresholds) { |
| 825 const struct { | 816 const struct { |
| 826 bool override_defaults_using_variation_params; | 817 bool override_defaults_using_variation_params; |
| 827 int32_t http_rtt_msec; | 818 int32_t http_rtt_msec; |
| 828 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | 819 EffectiveConnectionType expected_conn_type; |
| 829 } tests[] = { | 820 } tests[] = { |
| 830 // When the variation params do not override connection thresholds, | 821 // When the variation params do not override connection thresholds, |
| 831 // default values should be used. | 822 // default values should be used. |
| 832 {false, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 823 {false, 5000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 833 {false, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 824 {false, 4000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 834 {false, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 825 {false, 3000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 835 {false, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 826 {false, 2000, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 836 {false, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 827 {false, 1500, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 837 {false, 1000, | 828 {false, 1000, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 838 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 829 {false, 20, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 839 {false, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 840 // Override default thresholds using variation params. | 830 // Override default thresholds using variation params. |
| 841 {true, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 831 {true, 5000, EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 842 {true, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 832 {true, 4000, EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 843 {true, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 833 {true, 3000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 844 {true, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 834 {true, 2000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 845 {true, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 835 {true, 1500, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 846 {true, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 836 {true, 1000, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 847 {true, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 837 {true, 20, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 848 }; | 838 }; |
| 849 | 839 |
| 850 for (const auto& test : tests) { | 840 for (const auto& test : tests) { |
| 851 std::map<std::string, std::string> variation_params; | 841 std::map<std::string, std::string> variation_params; |
| 852 if (test.override_defaults_using_variation_params) { | 842 if (test.override_defaults_using_variation_params) { |
| 853 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; | 843 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; |
| 854 variation_params["Slow2G.ThresholdMedianHttpRTTMsec"] = "2000"; | 844 variation_params["Slow2G.ThresholdMedianHttpRTTMsec"] = "2000"; |
| 855 variation_params["2G.ThresholdMedianHttpRTTMsec"] = "1000"; | 845 variation_params["2G.ThresholdMedianHttpRTTMsec"] = "1000"; |
| 856 } | 846 } |
| 857 | 847 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 888 | 878 |
| 889 TestNetworkQualityEstimator estimator(variation_params); | 879 TestNetworkQualityEstimator estimator(variation_params); |
| 890 | 880 |
| 891 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | 881 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 892 // does not return Offline if the device is offline. | 882 // does not return Offline if the device is offline. |
| 893 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, | 883 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| 894 "test"); | 884 "test"); |
| 895 | 885 |
| 896 const struct { | 886 const struct { |
| 897 int32_t transport_rtt_msec; | 887 int32_t transport_rtt_msec; |
| 898 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | 888 EffectiveConnectionType expected_conn_type; |
| 899 } tests[] = { | 889 } tests[] = { |
| 900 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 890 {5000, EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 901 {4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 891 {4000, EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 902 {3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 892 {3000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 903 {2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 893 {2000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 904 {1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 894 {1500, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 905 {1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 895 {1000, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 906 {700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 896 {700, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 907 {500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 897 {500, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 908 {400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 898 {400, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 909 {300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 899 {300, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 910 {200, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 900 {200, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 911 {100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 901 {100, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 912 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 902 {20, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 913 }; | 903 }; |
| 914 | 904 |
| 915 for (const auto& test : tests) { | 905 for (const auto& test : tests) { |
| 916 estimator.set_transport_rtt( | 906 estimator.set_transport_rtt( |
| 917 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); | 907 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 918 estimator.set_recent_transport_rtt( | 908 estimator.set_recent_transport_rtt( |
| 919 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); | 909 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 920 estimator.set_downlink_throughput_kbps(INT32_MAX); | 910 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 921 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | 911 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| 922 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 912 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 946 TestNetworkQualityEstimator estimator(variation_params); | 936 TestNetworkQualityEstimator estimator(variation_params); |
| 947 | 937 |
| 948 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | 938 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 949 // does not return Offline if the device is offline. | 939 // does not return Offline if the device is offline. |
| 950 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, | 940 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| 951 "test"); | 941 "test"); |
| 952 | 942 |
| 953 const struct { | 943 const struct { |
| 954 int32_t rtt_msec; | 944 int32_t rtt_msec; |
| 955 int32_t downlink_throughput_kbps; | 945 int32_t downlink_throughput_kbps; |
| 956 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | 946 EffectiveConnectionType expected_conn_type; |
| 957 } tests[] = { | 947 } tests[] = { |
| 958 // Set RTT to a very low value to observe the effect of throughput. | 948 // Set RTT to a very low value to observe the effect of throughput. |
| 959 // Throughput is the bottleneck. | 949 // Throughput is the bottleneck. |
| 960 {1, 5, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 950 {1, 5, EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 961 {1, 10, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 951 {1, 10, EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 962 {1, 50, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 952 {1, 50, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 963 {1, 100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 953 {1, 100, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 964 {1, 150, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 954 {1, 150, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 965 {1, 300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 955 {1, 300, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 966 {1, 400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 956 {1, 400, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 967 {1, 500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 957 {1, 500, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 968 {1, 700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 958 {1, 700, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 969 {1, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 959 {1, 1000, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 970 {1, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 960 {1, 1500, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 971 {1, 2500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 961 {1, 2500, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 972 // Set both RTT and throughput. RTT is the bottleneck. | 962 // Set both RTT and throughput. RTT is the bottleneck. |
| 973 {3000, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 963 {3000, 25000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 974 {700, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 964 {700, 25000, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 975 }; | 965 }; |
| 976 | 966 |
| 977 for (const auto& test : tests) { | 967 for (const auto& test : tests) { |
| 978 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 968 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 979 estimator.set_recent_http_rtt( | 969 estimator.set_recent_http_rtt( |
| 980 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 970 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 981 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); | 971 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); |
| 982 estimator.set_recent_downlink_throughput_kbps( | 972 estimator.set_recent_downlink_throughput_kbps( |
| 983 test.downlink_throughput_kbps); | 973 test.downlink_throughput_kbps); |
| 984 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 974 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1010 TestNetworkQualityEstimator estimator(variation_params); | 1000 TestNetworkQualityEstimator estimator(variation_params); |
| 1011 | 1001 |
| 1012 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | 1002 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 1013 // does not return Offline if the device is offline. | 1003 // does not return Offline if the device is offline. |
| 1014 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, | 1004 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| 1015 "test"); | 1005 "test"); |
| 1016 | 1006 |
| 1017 const struct { | 1007 const struct { |
| 1018 int32_t transport_rtt_msec; | 1008 int32_t transport_rtt_msec; |
| 1019 int32_t downlink_throughput_kbps; | 1009 int32_t downlink_throughput_kbps; |
| 1020 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | 1010 EffectiveConnectionType expected_conn_type; |
| 1021 } tests[] = { | 1011 } tests[] = { |
| 1022 // Set RTT to a very low value to observe the effect of throughput. | 1012 // Set RTT to a very low value to observe the effect of throughput. |
| 1023 // Throughput is the bottleneck. | 1013 // Throughput is the bottleneck. |
| 1024 {1, 5, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 1014 {1, 5, EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 1025 {1, 10, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 1015 {1, 10, EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 1026 {1, 50, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 1016 {1, 50, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 1027 {1, 100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 1017 {1, 100, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 1028 {1, 150, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 1018 {1, 150, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 1029 {1, 300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 1019 {1, 300, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 1030 {1, 400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 1020 {1, 400, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 1031 {1, 500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 1021 {1, 500, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 1032 {1, 700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 1022 {1, 700, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 1033 {1, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 1023 {1, 1000, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 1034 {1, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 1024 {1, 1500, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 1035 {1, 2500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 1025 {1, 2500, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 1036 // Set both RTT and throughput. RTT is the bottleneck. | 1026 // Set both RTT and throughput. RTT is the bottleneck. |
| 1037 {3000, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 1027 {3000, 25000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 1038 {700, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 1028 {700, 25000, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 1039 }; | 1029 }; |
| 1040 | 1030 |
| 1041 for (const auto& test : tests) { | 1031 for (const auto& test : tests) { |
| 1042 estimator.set_transport_rtt( | 1032 estimator.set_transport_rtt( |
| 1043 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); | 1033 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 1044 estimator.set_recent_transport_rtt( | 1034 estimator.set_recent_transport_rtt( |
| 1045 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); | 1035 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 1046 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); | 1036 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); |
| 1047 estimator.set_recent_downlink_throughput_kbps( | 1037 estimator.set_recent_downlink_throughput_kbps( |
| 1048 test.downlink_throughput_kbps); | 1038 test.downlink_throughput_kbps); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 estimator.rtt_observations_.AddObservation( | 1133 estimator.rtt_observations_.AddObservation( |
| 1144 NetworkQualityEstimator::RttObservation( | 1134 NetworkQualityEstimator::RttObservation( |
| 1145 new_tcp_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); | 1135 new_tcp_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); |
| 1146 | 1136 |
| 1147 const struct { | 1137 const struct { |
| 1148 base::TimeTicks start_timestamp; | 1138 base::TimeTicks start_timestamp; |
| 1149 bool expect_network_quality_available; | 1139 bool expect_network_quality_available; |
| 1150 base::TimeDelta expected_http_rtt; | 1140 base::TimeDelta expected_http_rtt; |
| 1151 base::TimeDelta expected_transport_rtt; | 1141 base::TimeDelta expected_transport_rtt; |
| 1152 int32_t expected_downstream_throughput; | 1142 int32_t expected_downstream_throughput; |
| 1153 NetworkQualityEstimator::EffectiveConnectionType | 1143 EffectiveConnectionType expected_effective_connection_type; |
| 1154 expected_effective_connection_type; | |
| 1155 } tests[] = { | 1144 } tests[] = { |
| 1156 {now + base::TimeDelta::FromSeconds(10), false, | 1145 {now + base::TimeDelta::FromSeconds(10), false, |
| 1157 base::TimeDelta::FromMilliseconds(0), | 1146 base::TimeDelta::FromMilliseconds(0), |
| 1158 base::TimeDelta::FromMilliseconds(0), 0, | 1147 base::TimeDelta::FromMilliseconds(0), 0, |
| 1159 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 1148 EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 1160 {now, true, new_url_rtt, new_tcp_rtt, new_downlink_kbps, | 1149 {now, true, new_url_rtt, new_tcp_rtt, new_downlink_kbps, |
| 1161 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 1150 EFFECTIVE_CONNECTION_TYPE_4G}, |
| 1162 {old - base::TimeDelta::FromMicroseconds(500), true, old_url_rtt, | 1151 {old - base::TimeDelta::FromMicroseconds(500), true, old_url_rtt, |
| 1163 old_tcp_rtt, old_downlink_kbps, | 1152 old_tcp_rtt, old_downlink_kbps, EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 1164 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | |
| 1165 | 1153 |
| 1166 }; | 1154 }; |
| 1167 for (const auto& test : tests) { | 1155 for (const auto& test : tests) { |
| 1168 base::TimeDelta http_rtt; | 1156 base::TimeDelta http_rtt; |
| 1169 base::TimeDelta transport_rtt; | 1157 base::TimeDelta transport_rtt; |
| 1170 int32_t downstream_throughput_kbps; | 1158 int32_t downstream_throughput_kbps; |
| 1171 EXPECT_EQ( | 1159 EXPECT_EQ( |
| 1172 test.expect_network_quality_available, | 1160 test.expect_network_quality_available, |
| 1173 estimator.GetRecentHttpRTTMedian(test.start_timestamp, &http_rtt)); | 1161 estimator.GetRecentHttpRTTMedian(test.start_timestamp, &http_rtt)); |
| 1174 EXPECT_EQ(test.expect_network_quality_available, | 1162 EXPECT_EQ(test.expect_network_quality_available, |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 estimator.AddEffectiveConnectionTypeObserver(&observer); | 1492 estimator.AddEffectiveConnectionTypeObserver(&observer); |
| 1505 estimator.SetTickClockForTesting(std::move(tick_clock)); | 1493 estimator.SetTickClockForTesting(std::move(tick_clock)); |
| 1506 | 1494 |
| 1507 TestDelegate test_delegate; | 1495 TestDelegate test_delegate; |
| 1508 TestURLRequestContext context(true); | 1496 TestURLRequestContext context(true); |
| 1509 context.set_network_quality_estimator(&estimator); | 1497 context.set_network_quality_estimator(&estimator); |
| 1510 context.Init(); | 1498 context.Init(); |
| 1511 | 1499 |
| 1512 EXPECT_EQ(0U, observer.effective_connection_types().size()); | 1500 EXPECT_EQ(0U, observer.effective_connection_types().size()); |
| 1513 | 1501 |
| 1514 estimator.set_effective_connection_type( | 1502 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); |
| 1515 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G); | |
| 1516 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); | 1503 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
| 1517 | 1504 |
| 1518 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1505 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1519 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1506 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1520 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); | 1507 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); |
| 1521 request->Start(); | 1508 request->Start(); |
| 1522 base::RunLoop().Run(); | 1509 base::RunLoop().Run(); |
| 1523 EXPECT_EQ(1U, observer.effective_connection_types().size()); | 1510 EXPECT_EQ(1U, observer.effective_connection_types().size()); |
| 1524 histogram_tester.ExpectUniqueSample( | 1511 histogram_tester.ExpectUniqueSample( |
| 1525 "NQE.MainFrame.EffectiveConnectionType.Unknown", | 1512 "NQE.MainFrame.EffectiveConnectionType.Unknown", |
| 1526 NetworkQualityEstimator::EffectiveConnectionType:: | 1513 EFFECTIVE_CONNECTION_TYPE_2G, 1); |
| 1527 EFFECTIVE_CONNECTION_TYPE_2G, | |
| 1528 1); | |
| 1529 | 1514 |
| 1530 // Next request should not trigger recomputation of effective connection type | 1515 // Next request should not trigger recomputation of effective connection type |
| 1531 // since there has been no change in the clock. | 1516 // since there has been no change in the clock. |
| 1532 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 1517 std::unique_ptr<URLRequest> request2(context.CreateRequest( |
| 1533 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1518 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1534 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); | 1519 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); |
| 1535 request2->Start(); | 1520 request2->Start(); |
| 1536 base::RunLoop().Run(); | 1521 base::RunLoop().Run(); |
| 1537 EXPECT_EQ(1U, observer.effective_connection_types().size()); | 1522 EXPECT_EQ(1U, observer.effective_connection_types().size()); |
| 1538 | 1523 |
| 1539 // Change in connection type should send out notification to the observers. | 1524 // Change in connection type should send out notification to the observers. |
| 1540 estimator.set_effective_connection_type( | 1525 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); |
| 1541 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G); | |
| 1542 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, | 1526 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| 1543 "test"); | 1527 "test"); |
| 1544 EXPECT_EQ(2U, observer.effective_connection_types().size()); | 1528 EXPECT_EQ(2U, observer.effective_connection_types().size()); |
| 1545 | 1529 |
| 1546 // A change in effective connection type does not trigger notification to the | 1530 // A change in effective connection type does not trigger notification to the |
| 1547 // observers, since it is not accompanied by any new observation or a network | 1531 // observers, since it is not accompanied by any new observation or a network |
| 1548 // change event. | 1532 // change event. |
| 1549 estimator.set_effective_connection_type( | 1533 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); |
| 1550 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G); | |
| 1551 EXPECT_EQ(2U, observer.effective_connection_types().size()); | 1534 EXPECT_EQ(2U, observer.effective_connection_types().size()); |
| 1552 } | 1535 } |
| 1553 | 1536 |
| 1554 TEST(NetworkQualityEstimatorTest, TestRttThroughputObservers) { | 1537 TEST(NetworkQualityEstimatorTest, TestRttThroughputObservers) { |
| 1555 TestRTTObserver rtt_observer; | 1538 TestRTTObserver rtt_observer; |
| 1556 TestThroughputObserver throughput_observer; | 1539 TestThroughputObserver throughput_observer; |
| 1557 std::map<std::string, std::string> variation_params; | 1540 std::map<std::string, std::string> variation_params; |
| 1558 TestNetworkQualityEstimator estimator(variation_params); | 1541 TestNetworkQualityEstimator estimator(variation_params); |
| 1559 estimator.AddRTTObserver(&rtt_observer); | 1542 estimator.AddRTTObserver(&rtt_observer); |
| 1560 estimator.AddThroughputObserver(&throughput_observer); | 1543 estimator.AddThroughputObserver(&throughput_observer); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1707 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", | 1690 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", |
| 1708 1); | 1691 1); |
| 1709 | 1692 |
| 1710 // Verify that metrics are logged correctly on main-frame requests. | 1693 // Verify that metrics are logged correctly on main-frame requests. |
| 1711 histogram_tester.ExpectTotalCount( | 1694 histogram_tester.ExpectTotalCount( |
| 1712 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", num_requests); | 1695 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", num_requests); |
| 1713 histogram_tester.ExpectTotalCount( | 1696 histogram_tester.ExpectTotalCount( |
| 1714 "NQE.MainFrame.EffectiveConnectionType.Unknown", num_requests); | 1697 "NQE.MainFrame.EffectiveConnectionType.Unknown", num_requests); |
| 1715 histogram_tester.ExpectBucketCount( | 1698 histogram_tester.ExpectBucketCount( |
| 1716 "NQE.MainFrame.EffectiveConnectionType.Unknown", | 1699 "NQE.MainFrame.EffectiveConnectionType.Unknown", |
| 1717 NetworkQualityEstimator::EffectiveConnectionType:: | 1700 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); |
| 1718 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | |
| 1719 1); | |
| 1720 } | 1701 } |
| 1721 | 1702 |
| 1722 #if defined(OS_IOS) | 1703 #if defined(OS_IOS) |
| 1723 // Flaky on iOS when |accuracy_recording_delay| is non-zero. | 1704 // Flaky on iOS when |accuracy_recording_delay| is non-zero. |
| 1724 #define MAYBE_RecordAccuracy DISABLED_RecordAccuracy | 1705 #define MAYBE_RecordAccuracy DISABLED_RecordAccuracy |
| 1725 #else | 1706 #else |
| 1726 #define MAYBE_RecordAccuracy RecordAccuracy | 1707 #define MAYBE_RecordAccuracy RecordAccuracy |
| 1727 #endif | 1708 #endif |
| 1728 // Tests if the NQE accuracy metrics are recorded properly. | 1709 // Tests if the NQE accuracy metrics are recorded properly. |
| 1729 TEST(NetworkQualityEstimatorTest, MAYBE_RecordAccuracy) { | 1710 TEST(NetworkQualityEstimatorTest, MAYBE_RecordAccuracy) { |
| 1730 const int expected_rtt_msec = 100; | 1711 const int expected_rtt_msec = 100; |
| 1731 const int expected_downstream_throughput_kbps = 200; | 1712 const int expected_downstream_throughput_kbps = 200; |
| 1732 | 1713 |
| 1733 const base::TimeDelta accuracy_recording_delays[] = { | 1714 const base::TimeDelta accuracy_recording_delays[] = { |
| 1734 base::TimeDelta::FromSeconds(0), base::TimeDelta::FromSeconds(1), | 1715 base::TimeDelta::FromSeconds(0), base::TimeDelta::FromSeconds(1), |
| 1735 }; | 1716 }; |
| 1736 | 1717 |
| 1737 const struct { | 1718 const struct { |
| 1738 base::TimeDelta rtt; | 1719 base::TimeDelta rtt; |
| 1739 base::TimeDelta recent_rtt; | 1720 base::TimeDelta recent_rtt; |
| 1740 int32_t downstream_throughput_kbps; | 1721 int32_t downstream_throughput_kbps; |
| 1741 int32_t recent_downstream_throughput_kbps; | 1722 int32_t recent_downstream_throughput_kbps; |
| 1742 NetworkQualityEstimator::EffectiveConnectionType effective_connection_type; | 1723 EffectiveConnectionType effective_connection_type; |
| 1743 NetworkQualityEstimator::EffectiveConnectionType | 1724 EffectiveConnectionType recent_effective_connection_type; |
| 1744 recent_effective_connection_type; | |
| 1745 } tests[] = { | 1725 } tests[] = { |
| 1746 {base::TimeDelta::FromMilliseconds(expected_rtt_msec), | 1726 {base::TimeDelta::FromMilliseconds(expected_rtt_msec), |
| 1747 base::TimeDelta::FromMilliseconds(expected_rtt_msec), | 1727 base::TimeDelta::FromMilliseconds(expected_rtt_msec), |
| 1748 expected_downstream_throughput_kbps, expected_downstream_throughput_kbps, | 1728 expected_downstream_throughput_kbps, expected_downstream_throughput_kbps, |
| 1749 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G, | 1729 EFFECTIVE_CONNECTION_TYPE_2G, EFFECTIVE_CONNECTION_TYPE_2G}, |
| 1750 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | |
| 1751 | 1730 |
| 1752 { | 1731 { |
| 1753 base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1), | 1732 base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1), |
| 1754 base::TimeDelta::FromMilliseconds(expected_rtt_msec), | 1733 base::TimeDelta::FromMilliseconds(expected_rtt_msec), |
| 1755 expected_downstream_throughput_kbps + 1, | 1734 expected_downstream_throughput_kbps + 1, |
| 1756 expected_downstream_throughput_kbps, | 1735 expected_downstream_throughput_kbps, EFFECTIVE_CONNECTION_TYPE_3G, |
| 1757 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G, | 1736 EFFECTIVE_CONNECTION_TYPE_2G, |
| 1758 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G, | |
| 1759 }, | 1737 }, |
| 1760 { | 1738 { |
| 1761 base::TimeDelta::FromMilliseconds(expected_rtt_msec - 1), | 1739 base::TimeDelta::FromMilliseconds(expected_rtt_msec - 1), |
| 1762 base::TimeDelta::FromMilliseconds(expected_rtt_msec), | 1740 base::TimeDelta::FromMilliseconds(expected_rtt_msec), |
| 1763 expected_downstream_throughput_kbps - 1, | 1741 expected_downstream_throughput_kbps - 1, |
| 1764 expected_downstream_throughput_kbps, | 1742 expected_downstream_throughput_kbps, |
| 1765 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, | 1743 EFFECTIVE_CONNECTION_TYPE_SLOW_2G, EFFECTIVE_CONNECTION_TYPE_2G, |
| 1766 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G, | |
| 1767 }, | 1744 }, |
| 1768 }; | 1745 }; |
| 1769 | 1746 |
| 1770 for (const auto& accuracy_recording_delay : accuracy_recording_delays) { | 1747 for (const auto& accuracy_recording_delay : accuracy_recording_delays) { |
| 1771 for (const auto& test : tests) { | 1748 for (const auto& test : tests) { |
| 1772 std::unique_ptr<base::SimpleTestTickClock> tick_clock( | 1749 std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| 1773 new base::SimpleTestTickClock()); | 1750 new base::SimpleTestTickClock()); |
| 1774 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1751 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 1775 tick_clock_ptr->Advance(base::TimeDelta::FromSeconds(1)); | 1752 tick_clock_ptr->Advance(base::TimeDelta::FromSeconds(1)); |
| 1776 | 1753 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1882 "NQE.ExternalEstimateProvider.RTT.Accuracy.EstimatedObservedDiff." + | 1859 "NQE.ExternalEstimateProvider.RTT.Accuracy.EstimatedObservedDiff." + |
| 1883 sign_suffix_with_zero_samples + "." + interval_value + ".60_140", | 1860 sign_suffix_with_zero_samples + "." + interval_value + ".60_140", |
| 1884 0); | 1861 0); |
| 1885 } | 1862 } |
| 1886 } | 1863 } |
| 1887 } | 1864 } |
| 1888 | 1865 |
| 1889 // Tests that the effective connection type is converted correctly to a | 1866 // Tests that the effective connection type is converted correctly to a |
| 1890 // descriptive string name, and vice-versa. | 1867 // descriptive string name, and vice-versa. |
| 1891 TEST(NetworkQualityEstimatorTest, NameConnectionTypeConversion) { | 1868 TEST(NetworkQualityEstimatorTest, NameConnectionTypeConversion) { |
| 1892 for (size_t i = 0; | 1869 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { |
| 1893 i < NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { | 1870 const EffectiveConnectionType effective_connection_type = |
| 1894 const NetworkQualityEstimator::EffectiveConnectionType | 1871 static_cast<EffectiveConnectionType>(i); |
| 1895 effective_connection_type = | |
| 1896 static_cast<NetworkQualityEstimator::EffectiveConnectionType>(i); | |
| 1897 std::string connection_type_name = | 1872 std::string connection_type_name = |
| 1898 std::string(NetworkQualityEstimator::GetNameForEffectiveConnectionType( | 1873 std::string(NetworkQualityEstimator::GetNameForEffectiveConnectionType( |
| 1899 effective_connection_type)); | 1874 effective_connection_type)); |
| 1900 EXPECT_FALSE(connection_type_name.empty()); | 1875 EXPECT_FALSE(connection_type_name.empty()); |
| 1901 EXPECT_EQ(effective_connection_type, | 1876 EXPECT_EQ(effective_connection_type, |
| 1902 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( | 1877 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( |
| 1903 connection_type_name)); | 1878 connection_type_name)); |
| 1904 } | 1879 } |
| 1905 } | 1880 } |
| 1906 | 1881 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2071 | 2046 |
| 2072 // Get the bits at index 18-24 which contain the resource fetch time. | 2047 // Get the bits at index 18-24 which contain the resource fetch time. |
| 2073 EXPECT_LE(0, (buckets.at(0).min >> kBitsPerMetric) % 128); | 2048 EXPECT_LE(0, (buckets.at(0).min >> kBitsPerMetric) % 128); |
| 2074 | 2049 |
| 2075 // Get the bits at index 25-31 which contain the resource load size. | 2050 // Get the bits at index 25-31 which contain the resource load size. |
| 2076 EXPECT_LE(0, (buckets.at(0).min) % 128); | 2051 EXPECT_LE(0, (buckets.at(0).min) % 128); |
| 2077 } | 2052 } |
| 2078 } | 2053 } |
| 2079 | 2054 |
| 2080 } // namespace net | 2055 } // namespace net |
| OLD | NEW |