Chromium Code Reviews| 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 a7777f50d6c158ea2229a9841daed1da7dc390b5..11402547bf746750cd41c993ecbace7a743b9041 100644 |
| --- a/net/nqe/network_quality_estimator_unittest.cc |
| +++ b/net/nqe/network_quality_estimator_unittest.cc |
| @@ -670,36 +670,6 @@ TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) { |
| } |
| } |
| -// Tests that |GetEffectiveConnectionType| returns correct connection type when |
| -// no variation params are specified. |
| -TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) { |
| - std::map<std::string, std::string> variation_params; |
| - |
| - TestNetworkQualityEstimator estimator(variation_params); |
| - |
| - // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| - // does not return Offline if the device is offline. |
| - estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| - "test"); |
| - |
| - const struct { |
| - int32_t rtt_msec; |
| - NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; |
| - } tests[] = { |
| - {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| - {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| - }; |
| - |
| - for (const auto& test : tests) { |
| - estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| - estimator.set_recent_http_rtt( |
| - base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| - estimator.set_downlink_throughput_kbps(INT32_MAX); |
| - estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| - EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| - } |
| -} |
| - |
| // Tests that |GetEffectiveConnectionType| returns |
| // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. |
| TEST(NetworkQualityEstimatorTest, Offline) { |
| @@ -773,6 +743,118 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyRTT) { |
| } |
| } |
| +// Tests that default transport RTT thresholds for different effective |
| +// connection types are correctly set. |
| +TEST(NetworkQualityEstimatorTest, DefaultTransportRTTBasedThresholds) { |
| + const struct { |
| + // When the variation params do not override connection thresholds, default |
| + // values should be used. |
| + bool override_defaults_using_variation_params; |
| + int32_t transport_rtt_msec; |
| + NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; |
| + } tests[] = { |
| + {false, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| + {false, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| + {false, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| + {false, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| + {false, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| + {false, 1000, |
| + NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| + {false, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| + // Override default thresholds using variation params. |
| + {true, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| + {true, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| + {true, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| + {true, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| + {true, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| + {true, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| + {true, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| + }; |
| + |
| + for (const auto& test : tests) { |
| + std::map<std::string, std::string> variation_params; |
| + variation_params["effective_connection_type_algorithm"] = |
| + "TransportRTTOrDownstreamThroughput"; |
| + if (test.override_defaults_using_variation_params) { |
| + variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000"; |
| + variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000"; |
| + variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; |
| + } |
| + // Thresholds are not set using |variation_params|. Default values should be |
| + // used. |
| + |
| + TestNetworkQualityEstimator estimator(variation_params); |
| + |
| + // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| + // does not return Offline if the device is offline. |
| + estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| + "test"); |
| + |
| + estimator.set_transport_rtt( |
| + base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| + estimator.set_recent_transport_rtt( |
| + base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| + estimator.set_downlink_throughput_kbps(INT32_MAX); |
| + estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| + EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| + } |
| +} |
| + |
| +// Tests that default HTTP RTT thresholds for different effective |
| +// connection types are correctly set. |
| +TEST(NetworkQualityEstimatorTest, DefaultHttpRTTBasedThresholds) { |
| + const struct { |
| + // When the variation params do not override connection thresholds, default |
| + // values should be used. |
| + bool override_defaults_using_variation_params; |
| + int32_t http_rtt_msec; |
| + NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; |
| + } tests[] = { |
| + {false, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| + {false, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| + {false, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| + {false, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| + {false, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| + {false, 1000, |
| + NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| + {false, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| + // Override default thresholds using variation params. |
| + {true, 5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| + {true, 4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| + {true, 3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| + {true, 2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| + {true, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| + {true, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| + {true, 20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| + }; |
| + |
| + for (const auto& test : tests) { |
| + std::map<std::string, std::string> variation_params; |
| + if (test.override_defaults_using_variation_params) { |
| + variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; |
| + variation_params["Slow2G.ThresholdMedianHttpRTTMsec"] = "2000"; |
| + variation_params["2G.ThresholdMedianHttpRTTMsec"] = "1000"; |
| + } |
| + // Thresholds are not set using |variation_params|. Default values should be |
|
RyanSturm
2016/07/22 21:45:43
This comment confuses me, and the space below it s
tbansal1
2016/07/22 21:51:23
Done.
|
| + // used. |
| + |
| + TestNetworkQualityEstimator estimator(variation_params); |
| + |
| + // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| + // does not return Offline if the device is offline. |
| + estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| + "test"); |
| + |
| + estimator.set_http_rtt( |
| + base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); |
| + estimator.set_recent_http_rtt( |
| + base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); |
| + estimator.set_downlink_throughput_kbps(INT32_MAX); |
| + estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| + EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| + } |
| +} |
| + |
| // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| // only transport RTT thresholds are specified in the variation params. |
| TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyTransportRTT) { |