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 15 matching lines...) Expand all Loading... |
26 #include "base/threading/platform_thread.h" | 26 #include "base/threading/platform_thread.h" |
27 #include "base/time/time.h" | 27 #include "base/time/time.h" |
28 #include "build/build_config.h" | 28 #include "build/build_config.h" |
29 #include "net/base/load_flags.h" | 29 #include "net/base/load_flags.h" |
30 #include "net/base/network_change_notifier.h" | 30 #include "net/base/network_change_notifier.h" |
31 #include "net/http/http_response_headers.h" | 31 #include "net/http/http_response_headers.h" |
32 #include "net/http/http_response_info.h" | 32 #include "net/http/http_response_info.h" |
33 #include "net/http/http_status_code.h" | 33 #include "net/http/http_status_code.h" |
34 #include "net/log/test_net_log.h" | 34 #include "net/log/test_net_log.h" |
35 #include "net/nqe/effective_connection_type.h" | 35 #include "net/nqe/effective_connection_type.h" |
| 36 #include "net/nqe/effective_connection_type_observer.h" |
36 #include "net/nqe/external_estimate_provider.h" | 37 #include "net/nqe/external_estimate_provider.h" |
37 #include "net/nqe/network_quality_estimator_test_util.h" | 38 #include "net/nqe/network_quality_estimator_test_util.h" |
38 #include "net/nqe/network_quality_observation.h" | 39 #include "net/nqe/network_quality_observation.h" |
39 #include "net/nqe/network_quality_observation_source.h" | 40 #include "net/nqe/network_quality_observation_source.h" |
40 #include "net/nqe/observation_buffer.h" | 41 #include "net/nqe/observation_buffer.h" |
| 42 #include "net/nqe/rtt_throughput_estimates_observer.h" |
41 #include "net/socket/socket_performance_watcher.h" | 43 #include "net/socket/socket_performance_watcher.h" |
42 #include "net/socket/socket_performance_watcher_factory.h" | 44 #include "net/socket/socket_performance_watcher_factory.h" |
43 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 45 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
44 #include "net/url_request/url_request.h" | 46 #include "net/url_request/url_request.h" |
45 #include "net/url_request/url_request_test_util.h" | 47 #include "net/url_request/url_request_test_util.h" |
46 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
47 #include "url/gurl.h" | 49 #include "url/gurl.h" |
48 | 50 |
49 namespace { | 51 namespace { |
50 | 52 |
(...skipping 15 matching lines...) Expand all Loading... |
66 << " expected_min_count_samples=" << expected_min_count_samples; | 68 << " expected_min_count_samples=" << expected_min_count_samples; |
67 } | 69 } |
68 | 70 |
69 } // namespace | 71 } // namespace |
70 | 72 |
71 namespace net { | 73 namespace net { |
72 | 74 |
73 namespace { | 75 namespace { |
74 | 76 |
75 class TestEffectiveConnectionTypeObserver | 77 class TestEffectiveConnectionTypeObserver |
76 : public NetworkQualityEstimator::EffectiveConnectionTypeObserver { | 78 : public EffectiveConnectionTypeObserver { |
77 public: | 79 public: |
78 std::vector<EffectiveConnectionType>& effective_connection_types() { | 80 std::vector<EffectiveConnectionType>& effective_connection_types() { |
79 return effective_connection_types_; | 81 return effective_connection_types_; |
80 } | 82 } |
81 | 83 |
82 // EffectiveConnectionTypeObserver implementation: | 84 // EffectiveConnectionTypeObserver implementation: |
83 void OnEffectiveConnectionTypeChanged(EffectiveConnectionType type) override { | 85 void OnEffectiveConnectionTypeChanged(EffectiveConnectionType type) override { |
84 effective_connection_types_.push_back(type); | 86 effective_connection_types_.push_back(type); |
85 } | 87 } |
86 | 88 |
87 private: | 89 private: |
88 std::vector<EffectiveConnectionType> effective_connection_types_; | 90 std::vector<EffectiveConnectionType> effective_connection_types_; |
89 }; | 91 }; |
90 | 92 |
91 class TestRTTAndThroughputEstimatesObserver | 93 class TestRTTAndThroughputEstimatesObserver |
92 : public NetworkQualityEstimator::RTTAndThroughputEstimatesObserver { | 94 : public RTTAndThroughputEstimatesObserver { |
93 public: | 95 public: |
94 TestRTTAndThroughputEstimatesObserver() | 96 TestRTTAndThroughputEstimatesObserver() |
95 : http_rtt_(nqe::internal::InvalidRTT()), | 97 : http_rtt_(nqe::internal::InvalidRTT()), |
96 transport_rtt_(nqe::internal::InvalidRTT()), | 98 transport_rtt_(nqe::internal::InvalidRTT()), |
97 downstream_throughput_kbps_(nqe::internal::kInvalidThroughput), | 99 downstream_throughput_kbps_(nqe::internal::kInvalidThroughput), |
98 notifications_received_(0) {} | 100 notifications_received_(0) {} |
99 | 101 |
100 // RTTAndThroughputEstimatesObserver implementation: | 102 // RTTAndThroughputEstimatesObserver implementation: |
101 void OnRTTOrThroughputEstimatesComputed( | 103 void OnRTTOrThroughputEstimatesComputed( |
102 base::TimeDelta http_rtt, | 104 base::TimeDelta http_rtt, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 std::unique_ptr<URLRequest> request( | 216 std::unique_ptr<URLRequest> request( |
215 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, | 217 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
216 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); | 218 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
217 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 219 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
218 request->Start(); | 220 request->Start(); |
219 base::RunLoop().Run(); | 221 base::RunLoop().Run(); |
220 | 222 |
221 // Both RTT and downstream throughput should be updated. | 223 // Both RTT and downstream throughput should be updated. |
222 base::TimeDelta http_rtt; | 224 base::TimeDelta http_rtt; |
223 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &http_rtt)); | 225 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &http_rtt)); |
| 226 EXPECT_EQ(http_rtt, estimator.GetHttpRTT().value()); |
224 EXPECT_TRUE( | 227 EXPECT_TRUE( |
225 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 228 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 229 EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); |
226 base::TimeDelta transport_rtt; | 230 base::TimeDelta transport_rtt; |
227 EXPECT_FALSE(estimator.GetTransportRTT()); | 231 EXPECT_FALSE(estimator.GetTransportRTT()); |
228 EXPECT_FALSE( | 232 EXPECT_FALSE( |
229 estimator.GetRecentTransportRTT(base::TimeTicks(), &transport_rtt)); | 233 estimator.GetRecentTransportRTT(base::TimeTicks(), &transport_rtt)); |
230 | 234 |
231 // Verify the contents of the net log. | 235 // Verify the contents of the net log. |
232 EXPECT_LE( | 236 EXPECT_LE( |
233 2, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); | 237 2, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); |
234 EXPECT_EQ(http_rtt.InMilliseconds(), | 238 EXPECT_EQ(http_rtt.InMilliseconds(), |
235 estimator.GetNetLogLastIntegerValue( | 239 estimator.GetNetLogLastIntegerValue( |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); | 394 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
391 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 395 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
392 request->Start(); | 396 request->Start(); |
393 base::RunLoop().Run(); | 397 base::RunLoop().Run(); |
394 } | 398 } |
395 | 399 |
396 base::RunLoop().RunUntilIdle(); | 400 base::RunLoop().RunUntilIdle(); |
397 | 401 |
398 // Both RTT and downstream throughput should be updated. | 402 // Both RTT and downstream throughput should be updated. |
399 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 403 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 404 EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); |
400 EXPECT_TRUE( | 405 EXPECT_TRUE( |
401 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 406 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 407 EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); |
402 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | 408 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
403 estimator.GetEffectiveConnectionType()); | 409 estimator.GetEffectiveConnectionType()); |
404 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 410 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
405 EXPECT_FALSE(estimator.GetTransportRTT()); | 411 EXPECT_FALSE(estimator.GetTransportRTT()); |
406 | 412 |
407 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false, | 413 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false, |
408 1); | 414 1); |
409 | 415 |
410 // Add the observers before changing the network type. | 416 // Add the observers before changing the network type. |
411 TestEffectiveConnectionTypeObserver observer; | 417 TestEffectiveConnectionTypeObserver observer; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); | 503 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
498 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 504 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
499 request->Start(); | 505 request->Start(); |
500 base::RunLoop().Run(); | 506 base::RunLoop().Run(); |
501 } | 507 } |
502 | 508 |
503 base::RunLoop().RunUntilIdle(); | 509 base::RunLoop().RunUntilIdle(); |
504 | 510 |
505 // Both RTT and downstream throughput should be updated. | 511 // Both RTT and downstream throughput should be updated. |
506 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 512 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 513 EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); |
507 EXPECT_TRUE( | 514 EXPECT_TRUE( |
508 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 515 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 516 EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); |
509 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | 517 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
510 estimator.GetEffectiveConnectionType()); | 518 estimator.GetEffectiveConnectionType()); |
511 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 519 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
512 EXPECT_FALSE(estimator.GetTransportRTT()); | 520 EXPECT_FALSE(estimator.GetTransportRTT()); |
513 | 521 |
514 histogram_tester.ExpectTotalCount("NQE.CachedNetworkQualityAvailable", 0); | 522 histogram_tester.ExpectTotalCount("NQE.CachedNetworkQualityAvailable", 0); |
515 | 523 |
516 // Add the observers before changing the network type. | 524 // Add the observers before changing the network type. |
517 TestRTTObserver rtt_observer; | 525 TestRTTObserver rtt_observer; |
518 estimator.AddRTTObserver(&rtt_observer); | 526 estimator.AddRTTObserver(&rtt_observer); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM, 1); | 693 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM, 1); |
686 histogram_tester.ExpectTotalCount("NQE.RTT.ObservationSource", 2); | 694 histogram_tester.ExpectTotalCount("NQE.RTT.ObservationSource", 2); |
687 histogram_tester.ExpectTotalCount("NQE.Kbps.ObservationSource", 1); | 695 histogram_tester.ExpectTotalCount("NQE.Kbps.ObservationSource", 1); |
688 | 696 |
689 base::TimeDelta rtt; | 697 base::TimeDelta rtt; |
690 int32_t kbps; | 698 int32_t kbps; |
691 | 699 |
692 // Default estimates should be available. | 700 // Default estimates should be available. |
693 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 701 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
694 EXPECT_EQ(base::TimeDelta::FromMilliseconds(115), rtt); | 702 EXPECT_EQ(base::TimeDelta::FromMilliseconds(115), rtt); |
| 703 EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); |
695 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 704 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
696 EXPECT_EQ(base::TimeDelta::FromMilliseconds(55), rtt); | 705 EXPECT_EQ(base::TimeDelta::FromMilliseconds(55), rtt); |
697 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); | 706 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); |
698 EXPECT_TRUE( | 707 EXPECT_TRUE( |
699 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 708 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
700 EXPECT_EQ(1961, kbps); | 709 EXPECT_EQ(1961, kbps); |
| 710 EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); |
701 | 711 |
702 estimator.AddEffectiveConnectionTypeObserver( | 712 estimator.AddEffectiveConnectionTypeObserver( |
703 &effective_connection_type_observer); | 713 &effective_connection_type_observer); |
704 estimator.AddRTTAndThroughputEstimatesObserver( | 714 estimator.AddRTTAndThroughputEstimatesObserver( |
705 &rtt_throughput_estimates_observer); | 715 &rtt_throughput_estimates_observer); |
706 estimator.AddRTTObserver(&rtt_observer); | 716 estimator.AddRTTObserver(&rtt_observer); |
707 estimator.AddThroughputObserver(&throughput_observer); | 717 estimator.AddThroughputObserver(&throughput_observer); |
708 | 718 |
709 // Simulate network change to 3G. Default estimates should be available. | 719 // Simulate network change to 3G. Default estimates should be available. |
710 estimator.SimulateNetworkChange( | 720 estimator.SimulateNetworkChange( |
711 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); | 721 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); |
712 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 722 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
713 // Taken from network_quality_estimator_params.cc. | 723 // Taken from network_quality_estimator_params.cc. |
714 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), rtt); | 724 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), rtt); |
| 725 EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); |
715 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 726 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
716 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), rtt); | 727 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), rtt); |
717 EXPECT_EQ(rtt, estimator.GetTransportRTT()); | 728 EXPECT_EQ(rtt, estimator.GetTransportRTT()); |
718 EXPECT_TRUE( | 729 EXPECT_TRUE( |
719 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 730 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
720 EXPECT_EQ(749, kbps); | 731 EXPECT_EQ(749, kbps); |
| 732 EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); |
721 | 733 |
722 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | 734 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
723 estimator.GetEffectiveConnectionType()); | 735 estimator.GetEffectiveConnectionType()); |
724 EXPECT_EQ( | 736 EXPECT_EQ( |
725 1U, | 737 1U, |
726 effective_connection_type_observer.effective_connection_types().size()); | 738 effective_connection_type_observer.effective_connection_types().size()); |
727 EXPECT_NE( | 739 EXPECT_NE( |
728 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | 740 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
729 effective_connection_type_observer.effective_connection_types().front()); | 741 effective_connection_type_observer.effective_connection_types().front()); |
730 | 742 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 TestNetworkQualityEstimator estimator( | 793 TestNetworkQualityEstimator estimator( |
782 nullptr, variation_params, false, false, | 794 nullptr, variation_params, false, false, |
783 true /* add_default_platform_observations */, | 795 true /* add_default_platform_observations */, |
784 base::MakeUnique<BoundTestNetLog>()); | 796 base::MakeUnique<BoundTestNetLog>()); |
785 | 797 |
786 base::TimeDelta rtt; | 798 base::TimeDelta rtt; |
787 int32_t kbps; | 799 int32_t kbps; |
788 | 800 |
789 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 801 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
790 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); | 802 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); |
| 803 EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); |
791 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 804 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
792 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500), rtt); | 805 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500), rtt); |
793 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); | 806 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); |
794 EXPECT_TRUE( | 807 EXPECT_TRUE( |
795 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 808 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
796 EXPECT_EQ(100, kbps); | 809 EXPECT_EQ(100, kbps); |
| 810 EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); |
797 | 811 |
798 // Simulate network change to Wi-Fi. | 812 // Simulate network change to Wi-Fi. |
799 estimator.SimulateNetworkChange( | 813 estimator.SimulateNetworkChange( |
800 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 814 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
801 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 815 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
802 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); | 816 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); |
| 817 EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); |
803 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 818 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
804 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); | 819 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); |
805 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); | 820 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); |
806 EXPECT_TRUE( | 821 EXPECT_TRUE( |
807 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 822 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
808 EXPECT_EQ(200, kbps); | 823 EXPECT_EQ(200, kbps); |
| 824 EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); |
809 | 825 |
810 // Peak network quality should not be affected by the network quality | 826 // Peak network quality should not be affected by the network quality |
811 // estimator field trial. | 827 // estimator field trial. |
812 EXPECT_EQ(nqe::internal::InvalidRTT(), | 828 EXPECT_EQ(nqe::internal::InvalidRTT(), |
813 estimator.peak_network_quality_.http_rtt()); | 829 estimator.peak_network_quality_.http_rtt()); |
814 EXPECT_EQ(nqe::internal::kInvalidThroughput, | 830 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
815 estimator.peak_network_quality_.downstream_throughput_kbps()); | 831 estimator.peak_network_quality_.downstream_throughput_kbps()); |
816 | 832 |
817 // Simulate network change to 2G. Only the Kbps default estimate should be | 833 // Simulate network change to 2G. Only the Kbps default estimate should be |
818 // available. | 834 // available. |
819 estimator.SimulateNetworkChange( | 835 estimator.SimulateNetworkChange( |
820 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); | 836 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); |
821 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 837 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
822 // Taken from network_quality_estimator_params.cc. | 838 // Taken from network_quality_estimator_params.cc. |
823 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1726), rtt); | 839 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1726), rtt); |
| 840 EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); |
824 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 841 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
825 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1531), rtt); | 842 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1531), rtt); |
826 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); | 843 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); |
827 EXPECT_TRUE( | 844 EXPECT_TRUE( |
828 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 845 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
829 EXPECT_EQ(300, kbps); | 846 EXPECT_EQ(300, kbps); |
| 847 EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); |
830 | 848 |
831 // Simulate network change to 3G. Default estimates should be available. | 849 // Simulate network change to 3G. Default estimates should be available. |
832 estimator.SimulateNetworkChange( | 850 estimator.SimulateNetworkChange( |
833 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); | 851 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); |
834 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 852 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
835 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), rtt); | 853 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), rtt); |
| 854 EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); |
836 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 855 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
837 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), rtt); | 856 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), rtt); |
838 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); | 857 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); |
839 EXPECT_TRUE( | 858 EXPECT_TRUE( |
840 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 859 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
841 EXPECT_EQ(749, kbps); | 860 EXPECT_EQ(749, kbps); |
| 861 EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); |
842 } | 862 } |
843 | 863 |
844 TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) { | 864 TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) { |
845 const struct { | 865 const struct { |
846 bool set_variation_param; | 866 bool set_variation_param; |
847 std::string algorithm; | 867 std::string algorithm; |
848 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm | 868 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm |
849 expected_algorithm; | 869 expected_algorithm; |
850 } tests[] = { | 870 } tests[] = { |
851 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: | 871 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 external_estimate_provider_downstream_throughput); | 1546 external_estimate_provider_downstream_throughput); |
1527 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( | 1547 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( |
1528 test_external_estimate_provider); | 1548 test_external_estimate_provider); |
1529 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), | 1549 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), |
1530 std::move(external_estimate_provider)); | 1550 std::move(external_estimate_provider)); |
1531 estimator.SimulateNetworkChange(net::NetworkChangeNotifier::CONNECTION_WIFI, | 1551 estimator.SimulateNetworkChange(net::NetworkChangeNotifier::CONNECTION_WIFI, |
1532 "test"); | 1552 "test"); |
1533 base::TimeDelta rtt; | 1553 base::TimeDelta rtt; |
1534 int32_t kbps; | 1554 int32_t kbps; |
1535 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 1555 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1556 EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); |
1536 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 1557 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
1537 EXPECT_FALSE(estimator.GetTransportRTT()); | 1558 EXPECT_FALSE(estimator.GetTransportRTT()); |
1538 EXPECT_TRUE( | 1559 EXPECT_TRUE( |
1539 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 1560 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1561 EXPECT_EQ(kbps, estimator.GetDownstreamThroughputKbps().value()); |
1540 | 1562 |
1541 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 5); | 1563 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 5); |
1542 | 1564 |
1543 histogram_tester.ExpectBucketCount( | 1565 histogram_tester.ExpectBucketCount( |
1544 "NQE.ExternalEstimateProviderStatus", | 1566 "NQE.ExternalEstimateProviderStatus", |
1545 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); | 1567 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); |
1546 histogram_tester.ExpectBucketCount( | 1568 histogram_tester.ExpectBucketCount( |
1547 "NQE.ExternalEstimateProviderStatus", | 1569 "NQE.ExternalEstimateProviderStatus", |
1548 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); | 1570 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); |
1549 histogram_tester.ExpectBucketCount( | 1571 histogram_tester.ExpectBucketCount( |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2161 new HttpNetworkSession::Context); | 2183 new HttpNetworkSession::Context); |
2162 // |estimator| should be notified of TCP RTT observations. | 2184 // |estimator| should be notified of TCP RTT observations. |
2163 session_context->socket_performance_watcher_factory = | 2185 session_context->socket_performance_watcher_factory = |
2164 estimator.GetSocketPerformanceWatcherFactory(); | 2186 estimator.GetSocketPerformanceWatcherFactory(); |
2165 context.set_http_network_session_context(std::move(session_context)); | 2187 context.set_http_network_session_context(std::move(session_context)); |
2166 context.Init(); | 2188 context.Init(); |
2167 | 2189 |
2168 EXPECT_EQ(0U, rtt_observer.observations().size()); | 2190 EXPECT_EQ(0U, rtt_observer.observations().size()); |
2169 base::TimeDelta rtt; | 2191 base::TimeDelta rtt; |
2170 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 2192 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 2193 EXPECT_EQ(rtt, estimator.GetHttpRTT().value()); |
2171 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 2194 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
2172 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); | 2195 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); |
2173 | 2196 |
2174 // Send two requests. Verify that the completion of each request generates at | 2197 // Send two requests. Verify that the completion of each request generates at |
2175 // least one TCP RTT observation. | 2198 // least one TCP RTT observation. |
2176 const size_t num_requests = 2; | 2199 const size_t num_requests = 2; |
2177 for (size_t i = 0; i < num_requests; ++i) { | 2200 for (size_t i = 0; i < num_requests; ++i) { |
2178 size_t before_count_tcp_rtt_observations = 0; | 2201 size_t before_count_tcp_rtt_observations = 0; |
2179 for (const auto& observation : rtt_observer.observations()) { | 2202 for (const auto& observation : rtt_observer.observations()) { |
2180 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) | 2203 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) |
(...skipping 12 matching lines...) Expand all Loading... |
2193 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) | 2216 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) |
2194 ++after_count_tcp_rtt_observations; | 2217 ++after_count_tcp_rtt_observations; |
2195 } | 2218 } |
2196 // At least one notification should be received per socket performance | 2219 // At least one notification should be received per socket performance |
2197 // watcher. | 2220 // watcher. |
2198 EXPECT_LE(1U, after_count_tcp_rtt_observations - | 2221 EXPECT_LE(1U, after_count_tcp_rtt_observations - |
2199 before_count_tcp_rtt_observations) | 2222 before_count_tcp_rtt_observations) |
2200 << i; | 2223 << i; |
2201 } | 2224 } |
2202 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 2225 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 2226 EXPECT_NE(nqe::internal::InvalidRTT(), estimator.GetHttpRTT().value()); |
2203 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 2227 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
2204 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); | 2228 EXPECT_EQ(rtt, estimator.GetTransportRTT().value()); |
2205 | 2229 |
2206 estimator.SimulateNetworkChange( | 2230 estimator.SimulateNetworkChange( |
2207 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 2231 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
2208 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.2G", 1); | 2232 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.2G", 1); |
2209 histogram_tester.ExpectBucketCount("NQE.TransportRTT.Percentile50.2G", | 2233 histogram_tester.ExpectBucketCount("NQE.TransportRTT.Percentile50.2G", |
2210 rtt.InMilliseconds(), 1); | 2234 rtt.InMilliseconds(), 1); |
2211 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile10.2G", 1); | 2235 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile10.2G", 1); |
2212 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.2G", 1); | 2236 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.2G", 1); |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3091 | 3115 |
3092 // Cleanup. | 3116 // Cleanup. |
3093 estimator.RemoveRTTObserver(&rtt_observer); | 3117 estimator.RemoveRTTObserver(&rtt_observer); |
3094 estimator.RemoveThroughputObserver(&throughput_observer); | 3118 estimator.RemoveThroughputObserver(&throughput_observer); |
3095 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); | 3119 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); |
3096 estimator.RemoveEffectiveConnectionTypeObserver( | 3120 estimator.RemoveEffectiveConnectionTypeObserver( |
3097 &effective_connection_type_observer); | 3121 &effective_connection_type_observer); |
3098 } | 3122 } |
3099 | 3123 |
3100 } // namespace net | 3124 } // namespace net |
OLD | NEW |