Index: net/nqe/network_quality_estimator_unittest.cc |
diff --git a/net/nqe/network_quality_estimator_unittest.cc b/net/nqe/network_quality_estimator_unittest.cc |
index d8bbbe7f7836185d4eaac4e608d34a67d99c77ab..dc16325c02610918399130cb01d2eb64a03cedce 100644 |
--- a/net/nqe/network_quality_estimator_unittest.cc |
+++ b/net/nqe/network_quality_estimator_unittest.cc |
@@ -116,6 +116,19 @@ class TestNetworkQualityEstimator : public NetworkQualityEstimator { |
return std::move(http_response); |
} |
+ // Runs one URL request to completion. |
+ void RunOneRequest() { |
+ TestDelegate test_delegate; |
+ TestURLRequestContext context(true); |
+ context.set_network_quality_estimator(this); |
+ context.Init(); |
+ std::unique_ptr<URLRequest> request( |
+ context.CreateRequest(GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
+ request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); |
+ request->Start(); |
+ base::RunLoop().Run(); |
+ } |
+ |
// Returns a GURL hosted at embedded test server. |
const GURL GetEchoURL() const { |
return embedded_test_server_.GetURL("/echo.html"); |
@@ -818,6 +831,9 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyRTT) { |
base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
estimator.set_downlink_throughput_kbps(INT32_MAX); |
estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
+ // Run one main frame request to force recomputation of effective connection |
+ // type. |
+ estimator.RunOneRequest(); |
EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
} |
} |
@@ -872,6 +888,9 @@ TEST(NetworkQualityEstimatorTest, DefaultTransportRTTBasedThresholds) { |
base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
estimator.set_downlink_throughput_kbps(INT32_MAX); |
estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
+ // Run one main frame request to force recomputation of effective connection |
+ // type. |
+ estimator.RunOneRequest(); |
EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
} |
} |
@@ -924,6 +943,9 @@ TEST(NetworkQualityEstimatorTest, DefaultHttpRTTBasedThresholds) { |
base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); |
estimator.set_downlink_throughput_kbps(INT32_MAX); |
estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
+ // Run one main frame request to force recomputation of effective connection |
+ // type. |
+ estimator.RunOneRequest(); |
EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
} |
} |
@@ -974,6 +996,9 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyTransportRTT) { |
base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
estimator.set_downlink_throughput_kbps(INT32_MAX); |
estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
+ // Run one main frame request to force recomputation of effective connection |
+ // type. |
+ estimator.RunOneRequest(); |
EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
} |
} |
@@ -1034,6 +1059,9 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsHttpRTTandThroughput) { |
estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); |
estimator.set_recent_downlink_throughput_kbps( |
test.downlink_throughput_kbps); |
+ // Run one main frame request to force recomputation of effective connection |
+ // type. |
+ estimator.RunOneRequest(); |
EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
} |
} |
@@ -1097,6 +1125,9 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsTransportRTTandThroughput) { |
estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); |
estimator.set_recent_downlink_throughput_kbps( |
test.downlink_throughput_kbps); |
+ // Run one main frame request to force recomputation of effective connection |
+ // type. |
+ estimator.RunOneRequest(); |
EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
} |
} |
@@ -1558,7 +1589,7 @@ TEST(NetworkQualityEstimatorTest, TestEffectiveConnectionTypeObserver) { |
EXPECT_EQ(0U, observer.effective_connection_types().size()); |
- estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); |
+ estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); |
tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
std::unique_ptr<URLRequest> request(context.CreateRequest( |
@@ -1581,7 +1612,7 @@ TEST(NetworkQualityEstimatorTest, TestEffectiveConnectionTypeObserver) { |
EXPECT_EQ(1U, observer.effective_connection_types().size()); |
// Change in connection type should send out notification to the observers. |
- estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); |
+ estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); |
estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
"test"); |
EXPECT_EQ(2U, observer.effective_connection_types().size()); |
@@ -1589,7 +1620,7 @@ TEST(NetworkQualityEstimatorTest, TestEffectiveConnectionTypeObserver) { |
// A change in effective connection type does not trigger notification to the |
// observers, since it is not accompanied by any new observation or a network |
// change event. |
- estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); |
+ estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); |
EXPECT_EQ(2U, observer.effective_connection_types().size()); |
} |
@@ -1608,7 +1639,11 @@ TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) { |
tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
size_t expected_effective_connection_type_notifications = 0; |
- estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_UNKNOWN); |
+ estimator.set_recent_effective_connection_type( |
+ EFFECTIVE_CONNECTION_TYPE_UNKNOWN); |
+ // Run one main frame request to force recomputation of effective connection |
+ // type. |
+ estimator.RunOneRequest(); |
estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
"test"); |
@@ -1621,7 +1656,8 @@ TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) { |
EXPECT_EQ(expected_effective_connection_type_notifications, |
observer.effective_connection_types().size()); |
} |
- estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
+ estimator.set_recent_effective_connection_type( |
+ EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
// Even though there are 10 RTT samples already available, the addition of one |
// more RTT sample should trigger recomputation of the effective connection |
// type since the last computed effective connection type was unknown. |
@@ -1657,7 +1693,7 @@ TEST(NetworkQualityEstimatorTest, |
EXPECT_EQ(0U, observer.effective_connection_types().size()); |
- estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); |
+ estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); |
tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
std::unique_ptr<URLRequest> request(context.CreateRequest( |
@@ -1684,12 +1720,13 @@ TEST(NetworkQualityEstimatorTest, |
// Change the effective connection type so that the observers are |
// notified when the effective connection type is recomputed. |
if (repetition % 2 == 0) { |
- estimator.set_effective_connection_type( |
+ estimator.set_recent_effective_connection_type( |
EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
} else { |
- estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); |
+ estimator.set_recent_effective_connection_type( |
+ EFFECTIVE_CONNECTION_TYPE_3G); |
} |
- size_t rtt_observations_count = estimator.rtt_observations_.Size(); |
+ size_t rtt_observations_count = estimator.rtt_observations_.Size() * 0.5; |
// Increase the number of RTT observations to more than twice the number |
// of current observations. This should trigger recomputation of |
// effective connection type. |