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

Unified Diff: net/nqe/network_quality_estimator_unittest.cc

Issue 1998683003: Return E_C_T_OFFLINE when the device is offline (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/nqe/network_quality_estimator.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 365cbb47f78d08c3b03bd4e04b933e2d7f71a9a2..5e24a55213f56c5fda5efbc022f0528efef28493 100644
--- a/net/nqe/network_quality_estimator_unittest.cc
+++ b/net/nqe/network_quality_estimator_unittest.cc
@@ -64,6 +64,7 @@ class TestNetworkQualityEstimator : public NetworkQualityEstimator {
variation_params,
allow_local_host_requests_for_tests,
allow_smaller_responses_for_tests),
+ current_network_simulated_(false),
url_rtt_set_(false),
downlink_throughput_kbps_set_(false) {
// Set up embedded test server.
@@ -85,7 +86,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);
@@ -137,9 +139,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_);
}
@@ -433,6 +444,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;
@@ -447,6 +463,31 @@ 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) {
@@ -461,6 +502,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;
@@ -507,6 +553,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;
« no previous file with comments | « net/nqe/network_quality_estimator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698