Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: net/nqe/network_quality_estimator_unittest.cc

Issue 2266663002: NQE: Change GetEffectiveConnectionType to return last ECT (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Ryan's comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 std::unique_ptr<test_server::HttpResponse> HandleRequest( 109 std::unique_ptr<test_server::HttpResponse> HandleRequest(
110 const test_server::HttpRequest& request) { 110 const test_server::HttpRequest& request) {
111 std::unique_ptr<test_server::BasicHttpResponse> http_response( 111 std::unique_ptr<test_server::BasicHttpResponse> http_response(
112 new test_server::BasicHttpResponse()); 112 new test_server::BasicHttpResponse());
113 http_response->set_code(HTTP_OK); 113 http_response->set_code(HTTP_OK);
114 http_response->set_content("hello"); 114 http_response->set_content("hello");
115 http_response->set_content_type("text/plain"); 115 http_response->set_content_type("text/plain");
116 return std::move(http_response); 116 return std::move(http_response);
117 } 117 }
118 118
119 // Runs one URL request to completion.
120 void RunOneRequest() {
121 TestDelegate test_delegate;
122 TestURLRequestContext context(true);
123 context.set_network_quality_estimator(this);
124 context.Init();
125 std::unique_ptr<URLRequest> request(
126 context.CreateRequest(GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
127 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME);
128 request->Start();
129 base::RunLoop().Run();
130 }
131
119 // Returns a GURL hosted at embedded test server. 132 // Returns a GURL hosted at embedded test server.
120 const GURL GetEchoURL() const { 133 const GURL GetEchoURL() const {
121 return embedded_test_server_.GetURL("/echo.html"); 134 return embedded_test_server_.GetURL("/echo.html");
122 } 135 }
123 136
124 void set_effective_connection_type(EffectiveConnectionType type) { 137 void set_effective_connection_type(EffectiveConnectionType type) {
125 effective_connection_type_set_ = true; 138 effective_connection_type_set_ = true;
126 effective_connection_type_ = type; 139 effective_connection_type_ = type;
127 } 140 }
128 141
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 {100, EFFECTIVE_CONNECTION_TYPE_4G}, 824 {100, EFFECTIVE_CONNECTION_TYPE_4G},
812 {20, EFFECTIVE_CONNECTION_TYPE_4G}, 825 {20, EFFECTIVE_CONNECTION_TYPE_4G},
813 }; 826 };
814 827
815 for (const auto& test : tests) { 828 for (const auto& test : tests) {
816 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); 829 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec));
817 estimator.set_recent_http_rtt( 830 estimator.set_recent_http_rtt(
818 base::TimeDelta::FromMilliseconds(test.rtt_msec)); 831 base::TimeDelta::FromMilliseconds(test.rtt_msec));
819 estimator.set_downlink_throughput_kbps(INT32_MAX); 832 estimator.set_downlink_throughput_kbps(INT32_MAX);
820 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); 833 estimator.set_recent_downlink_throughput_kbps(INT32_MAX);
834 // Run one main frame request to force recomputation of effective connection
835 // type.
836 estimator.RunOneRequest();
821 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); 837 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType());
822 } 838 }
823 } 839 }
824 840
825 // Tests that default transport RTT thresholds for different effective 841 // Tests that default transport RTT thresholds for different effective
826 // connection types are correctly set. 842 // connection types are correctly set.
827 TEST(NetworkQualityEstimatorTest, DefaultTransportRTTBasedThresholds) { 843 TEST(NetworkQualityEstimatorTest, DefaultTransportRTTBasedThresholds) {
828 const struct { 844 const struct {
829 bool override_defaults_using_variation_params; 845 bool override_defaults_using_variation_params;
830 int32_t transport_rtt_msec; 846 int32_t transport_rtt_msec;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 // does not return Offline if the device is offline. 881 // does not return Offline if the device is offline.
866 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, 882 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI,
867 "test"); 883 "test");
868 884
869 estimator.set_transport_rtt( 885 estimator.set_transport_rtt(
870 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); 886 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec));
871 estimator.set_recent_transport_rtt( 887 estimator.set_recent_transport_rtt(
872 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); 888 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec));
873 estimator.set_downlink_throughput_kbps(INT32_MAX); 889 estimator.set_downlink_throughput_kbps(INT32_MAX);
874 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); 890 estimator.set_recent_downlink_throughput_kbps(INT32_MAX);
891 // Run one main frame request to force recomputation of effective connection
892 // type.
893 estimator.RunOneRequest();
875 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); 894 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType());
876 } 895 }
877 } 896 }
878 897
879 // Tests that default HTTP RTT thresholds for different effective 898 // Tests that default HTTP RTT thresholds for different effective
880 // connection types are correctly set. 899 // connection types are correctly set.
881 TEST(NetworkQualityEstimatorTest, DefaultHttpRTTBasedThresholds) { 900 TEST(NetworkQualityEstimatorTest, DefaultHttpRTTBasedThresholds) {
882 const struct { 901 const struct {
883 bool override_defaults_using_variation_params; 902 bool override_defaults_using_variation_params;
884 int32_t http_rtt_msec; 903 int32_t http_rtt_msec;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 // does not return Offline if the device is offline. 936 // does not return Offline if the device is offline.
918 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, 937 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI,
919 "test"); 938 "test");
920 939
921 estimator.set_http_rtt( 940 estimator.set_http_rtt(
922 base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); 941 base::TimeDelta::FromMilliseconds(test.http_rtt_msec));
923 estimator.set_recent_http_rtt( 942 estimator.set_recent_http_rtt(
924 base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); 943 base::TimeDelta::FromMilliseconds(test.http_rtt_msec));
925 estimator.set_downlink_throughput_kbps(INT32_MAX); 944 estimator.set_downlink_throughput_kbps(INT32_MAX);
926 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); 945 estimator.set_recent_downlink_throughput_kbps(INT32_MAX);
946 // Run one main frame request to force recomputation of effective connection
947 // type.
948 estimator.RunOneRequest();
927 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); 949 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType());
928 } 950 }
929 } 951 }
930 952
931 // Tests that |GetEffectiveConnectionType| returns correct connection type when 953 // Tests that |GetEffectiveConnectionType| returns correct connection type when
932 // only transport RTT thresholds are specified in the variation params. 954 // only transport RTT thresholds are specified in the variation params.
933 TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyTransportRTT) { 955 TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyTransportRTT) {
934 std::map<std::string, std::string> variation_params; 956 std::map<std::string, std::string> variation_params;
935 variation_params["effective_connection_type_algorithm"] = 957 variation_params["effective_connection_type_algorithm"] =
936 "TransportRTTOrDownstreamThroughput"; 958 "TransportRTTOrDownstreamThroughput";
(...skipping 30 matching lines...) Expand all
967 {20, EFFECTIVE_CONNECTION_TYPE_4G}, 989 {20, EFFECTIVE_CONNECTION_TYPE_4G},
968 }; 990 };
969 991
970 for (const auto& test : tests) { 992 for (const auto& test : tests) {
971 estimator.set_transport_rtt( 993 estimator.set_transport_rtt(
972 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); 994 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec));
973 estimator.set_recent_transport_rtt( 995 estimator.set_recent_transport_rtt(
974 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); 996 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec));
975 estimator.set_downlink_throughput_kbps(INT32_MAX); 997 estimator.set_downlink_throughput_kbps(INT32_MAX);
976 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); 998 estimator.set_recent_downlink_throughput_kbps(INT32_MAX);
999 // Run one main frame request to force recomputation of effective connection
1000 // type.
1001 estimator.RunOneRequest();
977 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); 1002 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType());
978 } 1003 }
979 } 1004 }
980 1005
981 // Tests that |GetEffectiveConnectionType| returns correct connection type when 1006 // Tests that |GetEffectiveConnectionType| returns correct connection type when
982 // both HTTP RTT and throughput thresholds are specified in the variation 1007 // both HTTP RTT and throughput thresholds are specified in the variation
983 // params. 1008 // params.
984 TEST(NetworkQualityEstimatorTest, ObtainThresholdsHttpRTTandThroughput) { 1009 TEST(NetworkQualityEstimatorTest, ObtainThresholdsHttpRTTandThroughput) {
985 std::map<std::string, std::string> variation_params; 1010 std::map<std::string, std::string> variation_params;
986 1011
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 {700, 25000, EFFECTIVE_CONNECTION_TYPE_3G}, 1052 {700, 25000, EFFECTIVE_CONNECTION_TYPE_3G},
1028 }; 1053 };
1029 1054
1030 for (const auto& test : tests) { 1055 for (const auto& test : tests) {
1031 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); 1056 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec));
1032 estimator.set_recent_http_rtt( 1057 estimator.set_recent_http_rtt(
1033 base::TimeDelta::FromMilliseconds(test.rtt_msec)); 1058 base::TimeDelta::FromMilliseconds(test.rtt_msec));
1034 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); 1059 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps);
1035 estimator.set_recent_downlink_throughput_kbps( 1060 estimator.set_recent_downlink_throughput_kbps(
1036 test.downlink_throughput_kbps); 1061 test.downlink_throughput_kbps);
1062 // Run one main frame request to force recomputation of effective connection
1063 // type.
1064 estimator.RunOneRequest();
1037 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); 1065 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType());
1038 } 1066 }
1039 } 1067 }
1040 1068
1041 // Tests that |GetEffectiveConnectionType| returns correct connection type when 1069 // Tests that |GetEffectiveConnectionType| returns correct connection type when
1042 // both transport RTT and throughput thresholds are specified in the variation 1070 // both transport RTT and throughput thresholds are specified in the variation
1043 // params. 1071 // params.
1044 TEST(NetworkQualityEstimatorTest, ObtainThresholdsTransportRTTandThroughput) { 1072 TEST(NetworkQualityEstimatorTest, ObtainThresholdsTransportRTTandThroughput) {
1045 std::map<std::string, std::string> variation_params; 1073 std::map<std::string, std::string> variation_params;
1046 variation_params["effective_connection_type_algorithm"] = 1074 variation_params["effective_connection_type_algorithm"] =
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 }; 1118 };
1091 1119
1092 for (const auto& test : tests) { 1120 for (const auto& test : tests) {
1093 estimator.set_transport_rtt( 1121 estimator.set_transport_rtt(
1094 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); 1122 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec));
1095 estimator.set_recent_transport_rtt( 1123 estimator.set_recent_transport_rtt(
1096 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); 1124 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec));
1097 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); 1125 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps);
1098 estimator.set_recent_downlink_throughput_kbps( 1126 estimator.set_recent_downlink_throughput_kbps(
1099 test.downlink_throughput_kbps); 1127 test.downlink_throughput_kbps);
1128 // Run one main frame request to force recomputation of effective connection
1129 // type.
1130 estimator.RunOneRequest();
1100 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); 1131 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType());
1101 } 1132 }
1102 } 1133 }
1103 1134
1104 // Tests if |weight_multiplier_per_second_| is set to correct value for various 1135 // Tests if |weight_multiplier_per_second_| is set to correct value for various
1105 // values of half life parameter. 1136 // values of half life parameter.
1106 TEST(NetworkQualityEstimatorTest, HalfLifeParam) { 1137 TEST(NetworkQualityEstimatorTest, HalfLifeParam) {
1107 std::map<std::string, std::string> variation_params; 1138 std::map<std::string, std::string> variation_params;
1108 1139
1109 const struct { 1140 const struct {
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 estimator.AddEffectiveConnectionTypeObserver(&observer); 1582 estimator.AddEffectiveConnectionTypeObserver(&observer);
1552 estimator.SetTickClockForTesting(std::move(tick_clock)); 1583 estimator.SetTickClockForTesting(std::move(tick_clock));
1553 1584
1554 TestDelegate test_delegate; 1585 TestDelegate test_delegate;
1555 TestURLRequestContext context(true); 1586 TestURLRequestContext context(true);
1556 context.set_network_quality_estimator(&estimator); 1587 context.set_network_quality_estimator(&estimator);
1557 context.Init(); 1588 context.Init();
1558 1589
1559 EXPECT_EQ(0U, observer.effective_connection_types().size()); 1590 EXPECT_EQ(0U, observer.effective_connection_types().size());
1560 1591
1561 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); 1592 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G);
1562 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); 1593 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60));
1563 1594
1564 std::unique_ptr<URLRequest> request(context.CreateRequest( 1595 std::unique_ptr<URLRequest> request(context.CreateRequest(
1565 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 1596 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
1566 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); 1597 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME);
1567 request->Start(); 1598 request->Start();
1568 base::RunLoop().Run(); 1599 base::RunLoop().Run();
1569 EXPECT_EQ(1U, observer.effective_connection_types().size()); 1600 EXPECT_EQ(1U, observer.effective_connection_types().size());
1570 histogram_tester.ExpectUniqueSample( 1601 histogram_tester.ExpectUniqueSample(
1571 "NQE.MainFrame.EffectiveConnectionType.Unknown", 1602 "NQE.MainFrame.EffectiveConnectionType.Unknown",
1572 EFFECTIVE_CONNECTION_TYPE_2G, 1); 1603 EFFECTIVE_CONNECTION_TYPE_2G, 1);
1573 1604
1574 // Next request should not trigger recomputation of effective connection type 1605 // Next request should not trigger recomputation of effective connection type
1575 // since there has been no change in the clock. 1606 // since there has been no change in the clock.
1576 std::unique_ptr<URLRequest> request2(context.CreateRequest( 1607 std::unique_ptr<URLRequest> request2(context.CreateRequest(
1577 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 1608 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
1578 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); 1609 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME);
1579 request2->Start(); 1610 request2->Start();
1580 base::RunLoop().Run(); 1611 base::RunLoop().Run();
1581 EXPECT_EQ(1U, observer.effective_connection_types().size()); 1612 EXPECT_EQ(1U, observer.effective_connection_types().size());
1582 1613
1583 // Change in connection type should send out notification to the observers. 1614 // Change in connection type should send out notification to the observers.
1584 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); 1615 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G);
1585 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, 1616 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI,
1586 "test"); 1617 "test");
1587 EXPECT_EQ(2U, observer.effective_connection_types().size()); 1618 EXPECT_EQ(2U, observer.effective_connection_types().size());
1588 1619
1589 // A change in effective connection type does not trigger notification to the 1620 // A change in effective connection type does not trigger notification to the
1590 // observers, since it is not accompanied by any new observation or a network 1621 // observers, since it is not accompanied by any new observation or a network
1591 // change event. 1622 // change event.
1592 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); 1623 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G);
1593 EXPECT_EQ(2U, observer.effective_connection_types().size()); 1624 EXPECT_EQ(2U, observer.effective_connection_types().size());
1594 } 1625 }
1595 1626
1596 // Tests that the effective connection type is computed on every RTT 1627 // Tests that the effective connection type is computed on every RTT
1597 // observation if the last computed effective connection type was unknown. 1628 // observation if the last computed effective connection type was unknown.
1598 TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) { 1629 TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) {
1599 std::unique_ptr<base::SimpleTestTickClock> tick_clock( 1630 std::unique_ptr<base::SimpleTestTickClock> tick_clock(
1600 new base::SimpleTestTickClock()); 1631 new base::SimpleTestTickClock());
1601 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); 1632 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get();
1602 1633
1603 TestEffectiveConnectionTypeObserver observer; 1634 TestEffectiveConnectionTypeObserver observer;
1604 std::map<std::string, std::string> variation_params; 1635 std::map<std::string, std::string> variation_params;
1605 TestNetworkQualityEstimator estimator(variation_params); 1636 TestNetworkQualityEstimator estimator(variation_params);
1606 estimator.SetTickClockForTesting(std::move(tick_clock)); 1637 estimator.SetTickClockForTesting(std::move(tick_clock));
1607 estimator.AddEffectiveConnectionTypeObserver(&observer); 1638 estimator.AddEffectiveConnectionTypeObserver(&observer);
1608 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); 1639 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60));
1609 1640
1610 size_t expected_effective_connection_type_notifications = 0; 1641 size_t expected_effective_connection_type_notifications = 0;
1611 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_UNKNOWN); 1642 estimator.set_recent_effective_connection_type(
1643 EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
1644 // Run one main frame request to force recomputation of effective connection
1645 // type.
1646 estimator.RunOneRequest();
1612 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, 1647 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI,
1613 "test"); 1648 "test");
1614 1649
1615 NetworkQualityEstimator::RttObservation rtt_observation( 1650 NetworkQualityEstimator::RttObservation rtt_observation(
1616 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), 1651 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(),
1617 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); 1652 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST);
1618 1653
1619 for (size_t i = 0; i < 10; ++i) { 1654 for (size_t i = 0; i < 10; ++i) {
1620 estimator.NotifyObserversOfRTT(rtt_observation); 1655 estimator.NotifyObserversOfRTT(rtt_observation);
1621 EXPECT_EQ(expected_effective_connection_type_notifications, 1656 EXPECT_EQ(expected_effective_connection_type_notifications,
1622 observer.effective_connection_types().size()); 1657 observer.effective_connection_types().size());
1623 } 1658 }
1624 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_SLOW_2G); 1659 estimator.set_recent_effective_connection_type(
1660 EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1625 // Even though there are 10 RTT samples already available, the addition of one 1661 // Even though there are 10 RTT samples already available, the addition of one
1626 // more RTT sample should trigger recomputation of the effective connection 1662 // more RTT sample should trigger recomputation of the effective connection
1627 // type since the last computed effective connection type was unknown. 1663 // type since the last computed effective connection type was unknown.
1628 estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation( 1664 estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation(
1629 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), 1665 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(),
1630 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 1666 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST));
1631 ++expected_effective_connection_type_notifications; 1667 ++expected_effective_connection_type_notifications;
1632 EXPECT_EQ(expected_effective_connection_type_notifications, 1668 EXPECT_EQ(expected_effective_connection_type_notifications,
1633 observer.effective_connection_types().size()); 1669 observer.effective_connection_types().size());
1634 } 1670 }
(...skipping 15 matching lines...) Expand all
1650 "test"); 1686 "test");
1651 estimator.AddEffectiveConnectionTypeObserver(&observer); 1687 estimator.AddEffectiveConnectionTypeObserver(&observer);
1652 1688
1653 TestDelegate test_delegate; 1689 TestDelegate test_delegate;
1654 TestURLRequestContext context(true); 1690 TestURLRequestContext context(true);
1655 context.set_network_quality_estimator(&estimator); 1691 context.set_network_quality_estimator(&estimator);
1656 context.Init(); 1692 context.Init();
1657 1693
1658 EXPECT_EQ(0U, observer.effective_connection_types().size()); 1694 EXPECT_EQ(0U, observer.effective_connection_types().size());
1659 1695
1660 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); 1696 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G);
1661 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); 1697 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60));
1662 1698
1663 std::unique_ptr<URLRequest> request(context.CreateRequest( 1699 std::unique_ptr<URLRequest> request(context.CreateRequest(
1664 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 1700 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
1665 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); 1701 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME);
1666 request->Start(); 1702 request->Start();
1667 base::RunLoop().Run(); 1703 base::RunLoop().Run();
1668 EXPECT_EQ(1U, observer.effective_connection_types().size()); 1704 EXPECT_EQ(1U, observer.effective_connection_types().size());
1669 histogram_tester.ExpectUniqueSample( 1705 histogram_tester.ExpectUniqueSample(
1670 "NQE.MainFrame.EffectiveConnectionType.WiFi", 1706 "NQE.MainFrame.EffectiveConnectionType.WiFi",
1671 EFFECTIVE_CONNECTION_TYPE_2G, 1); 1707 EFFECTIVE_CONNECTION_TYPE_2G, 1);
1672 1708
1673 size_t expected_effective_connection_type_notifications = 1; 1709 size_t expected_effective_connection_type_notifications = 1;
1674 EXPECT_EQ(expected_effective_connection_type_notifications, 1710 EXPECT_EQ(expected_effective_connection_type_notifications,
1675 observer.effective_connection_types().size()); 1711 observer.effective_connection_types().size());
1676 1712
1677 EXPECT_EQ(expected_effective_connection_type_notifications, 1713 EXPECT_EQ(expected_effective_connection_type_notifications,
1678 estimator.rtt_observations_.Size()); 1714 estimator.rtt_observations_.Size());
1679 1715
1680 // Increase the number of RTT observations. Every time the number of RTT 1716 // Increase the number of RTT observations. Every time the number of RTT
1681 // observations is more than doubled, effective connection type must be 1717 // observations is more than doubled, effective connection type must be
1682 // recomputed and notified to observers. 1718 // recomputed and notified to observers.
1683 for (size_t repetition = 0; repetition < 2; ++repetition) { 1719 for (size_t repetition = 0; repetition < 2; ++repetition) {
1684 // Change the effective connection type so that the observers are 1720 // Change the effective connection type so that the observers are
1685 // notified when the effective connection type is recomputed. 1721 // notified when the effective connection type is recomputed.
1686 if (repetition % 2 == 0) { 1722 if (repetition % 2 == 0) {
1687 estimator.set_effective_connection_type( 1723 estimator.set_recent_effective_connection_type(
1688 EFFECTIVE_CONNECTION_TYPE_SLOW_2G); 1724 EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1689 } else { 1725 } else {
1690 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); 1726 estimator.set_recent_effective_connection_type(
1727 EFFECTIVE_CONNECTION_TYPE_3G);
1691 } 1728 }
1692 size_t rtt_observations_count = estimator.rtt_observations_.Size(); 1729 size_t rtt_observations_count = estimator.rtt_observations_.Size() * 0.5;
1693 // Increase the number of RTT observations to more than twice the number 1730 // Increase the number of RTT observations to more than twice the number
1694 // of current observations. This should trigger recomputation of 1731 // of current observations. This should trigger recomputation of
1695 // effective connection type. 1732 // effective connection type.
1696 for (size_t i = 0; i < rtt_observations_count + 1; ++i) { 1733 for (size_t i = 0; i < rtt_observations_count + 1; ++i) {
1697 estimator.rtt_observations_.AddObservation( 1734 estimator.rtt_observations_.AddObservation(
1698 NetworkQualityEstimator::RttObservation( 1735 NetworkQualityEstimator::RttObservation(
1699 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), 1736 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(),
1700 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 1737 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST));
1701 1738
1702 estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation( 1739 estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation(
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
2211 2248
2212 // Get the bits at index 18-24 which contain the resource fetch time. 2249 // Get the bits at index 18-24 which contain the resource fetch time.
2213 EXPECT_LE(0, (buckets.at(0).min >> kBitsPerMetric) % 128); 2250 EXPECT_LE(0, (buckets.at(0).min >> kBitsPerMetric) % 128);
2214 2251
2215 // Get the bits at index 25-31 which contain the resource load size. 2252 // Get the bits at index 25-31 which contain the resource load size.
2216 EXPECT_LE(0, (buckets.at(0).min) % 128); 2253 EXPECT_LE(0, (buckets.at(0).min) % 128);
2217 } 2254 }
2218 } 2255 }
2219 2256
2220 } // namespace net 2257 } // namespace net
OLDNEW
« net/nqe/network_quality_estimator.cc ('K') | « net/nqe/network_quality_estimator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698