| 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 f3a4962e11ee14296925ad4e49a70e241c76d075..0544418bb61ea4fddfdc79f4d0034ebf14e30986 100644
|
| --- a/net/nqe/network_quality_estimator_unittest.cc
|
| +++ b/net/nqe/network_quality_estimator_unittest.cc
|
| @@ -54,6 +54,7 @@ class TestNetworkQualityEstimator : public NetworkQualityEstimator {
|
| variation_params,
|
| true,
|
| true),
|
| + current_network_simulated_(false),
|
| url_rtt_set_(false),
|
| downlink_throughput_kbps_set_(false) {
|
| // Set up embedded test server.
|
| @@ -75,7 +76,8 @@ class TestNetworkQualityEstimator : public NetworkQualityEstimator {
|
| // Overrides the current network type and id.
|
| // Notifies network quality estimator of change in connection.
|
| void SimulateNetworkChangeTo(NetworkChangeNotifier::ConnectionType type,
|
| - std::string network_id) {
|
| + const std::string& network_id) {
|
| + current_network_simulated_ = true;
|
| current_network_type_ = type;
|
| current_network_id_ = network_id;
|
| OnConnectionTypeChanged(type);
|
| @@ -127,9 +129,18 @@ class TestNetworkQualityEstimator : public NetworkQualityEstimator {
|
| using NetworkQualityEstimator::OnConnectionTypeChanged;
|
|
|
| private:
|
| + // True if the network type and network id are currently simulated. This
|
| + // ensures that the correctness of the test does not depend on the
|
| + // actual network type of the device on which the test is running.
|
| + bool current_network_simulated_;
|
| +
|
| // NetworkQualityEstimator implementation that returns the overridden network
|
| // id (instead of invoking platform APIs).
|
| NetworkQualityEstimator::NetworkID GetCurrentNetworkID() const override {
|
| + // GetCurrentNetworkID should be called only if the network type is
|
| + // currently simulated.
|
| + EXPECT_TRUE(current_network_simulated_);
|
| +
|
| return NetworkQualityEstimator::NetworkID(current_network_type_,
|
| current_network_id_);
|
| }
|
| @@ -417,6 +428,11 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) {
|
|
|
| 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;
|
| @@ -431,6 +447,32 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) {
|
| }
|
| }
|
|
|
| +// Tests that |GetEffectiveConnectionType| returns
|
| +// EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline.
|
| +TEST(NetworkQualityEstimatorTest, Offline) {
|
| + std::map<std::string, std::string> variation_params;
|
| +
|
| + TestNetworkQualityEstimator estimator(variation_params);
|
| +
|
| + const struct {
|
| + NetworkChangeNotifier::ConnectionType connection_type;
|
| + NetworkQualityEstimator::EffectiveConnectionType expected_connection_type;
|
| + } tests[] = {
|
| + {NetworkChangeNotifier::CONNECTION_2G,
|
| + NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN},
|
| + {NetworkChangeNotifier::CONNECTION_NONE,
|
| + NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE},
|
| + {NetworkChangeNotifier::CONNECTION_3G,
|
| + NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN},
|
| + };
|
| +
|
| + for (const auto& test : tests) {
|
| + estimator.SimulateNetworkChangeTo(test.connection_type, "test");
|
| + EXPECT_EQ(test.expected_connection_type,
|
| + estimator.GetEffectiveConnectionType());
|
| + }
|
| +}
|
| +
|
| // Tests that |GetEffectiveConnectionType| returns correct connection type when
|
| // only RTT thresholds are specified in the variation params.
|
| TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyRTT) {
|
| @@ -445,6 +487,11 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyRTT) {
|
|
|
| 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;
|
| @@ -491,6 +538,11 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsRTTandThroughput) {
|
|
|
| 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;
|
| int32_t downlink_throughput_kbps;
|
|
|