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

Unified Diff: net/nqe/network_quality_estimator_unittest.cc

Issue 2487883002: NQE: Use cached estimates (Closed)
Patch Set: ps Created 4 years 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
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 36d12bb32a398a8a41e2fd2c6a2d2dd8161adc60..7af79f185187ac01ad91f654d5b6ca25164350c6 100644
--- a/net/nqe/network_quality_estimator_unittest.cc
+++ b/net/nqe/network_quality_estimator_unittest.cc
@@ -118,6 +118,17 @@ class TestRTTObserver : public NetworkQualityEstimator::RTTObserver {
observations_.push_back(Observation(rtt_ms, timestamp, source));
}
+ // Returns the last received RTT observation that has source set to |source|.
+ base::TimeDelta last_rtt(NetworkQualityObservationSource source) {
+ for (std::vector<Observation>::reverse_iterator i = observations_.rbegin();
+ i != observations_.rend(); ++i) {
+ Observation observation = *i;
+ if (observation.source == source)
+ return base::TimeDelta::FromMilliseconds(observation.rtt_ms);
+ }
+ return nqe::internal::InvalidRTT();
+ }
+
private:
std::vector<Observation> observations_;
};
@@ -343,6 +354,10 @@ TEST(NetworkQualityEstimatorTest, Caching) {
TestThroughputObserver throughput_observer;
estimator.AddThroughputObserver(&throughput_observer);
+ // |observer| should be notified as soon as it is added.
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1U, observer.effective_connection_types().size());
+
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test");
histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true,
@@ -353,7 +368,9 @@ TEST(NetworkQualityEstimatorTest, Caching) {
// Verify that the cached network quality was read, and observers were
// notified. |observer| must be notified once right after it was added, and
// once again after the cached network quality was read.
- EXPECT_EQ(2U, observer.effective_connection_types().size());
+ EXPECT_LE(2U, observer.effective_connection_types().size());
+ EXPECT_EQ(estimator.GetEffectiveConnectionType(),
+ observer.effective_connection_types().back());
EXPECT_EQ(1U, rtt_observer.observations().size());
EXPECT_EQ(1U, throughput_observer.observations().size());
}
@@ -2570,4 +2587,114 @@ TEST(NetworkQualityEstimatorTest, TypicalNetworkQualities) {
}
}
+// Verify that the cached network qualities from the prefs are correctly used.
+TEST(NetworkQualityEstimatorTest, OnPrefsRead) {
+ base::HistogramTester histogram_tester;
+
+ // Construct the read prefs.
+ std::map<nqe::internal::NetworkID, nqe::internal::CachedNetworkQuality>
+ read_prefs;
+ read_prefs[nqe::internal::NetworkID(NetworkChangeNotifier::CONNECTION_WIFI,
+ "test_ect_2g")] =
+ nqe::internal::CachedNetworkQuality(EFFECTIVE_CONNECTION_TYPE_2G);
+ read_prefs[nqe::internal::NetworkID(NetworkChangeNotifier::CONNECTION_WIFI,
+ "test_ect_slow_2g")] =
+ nqe::internal::CachedNetworkQuality(EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
+ read_prefs[nqe::internal::NetworkID(NetworkChangeNotifier::CONNECTION_4G,
+ "test_ect_4g")] =
+ nqe::internal::CachedNetworkQuality(EFFECTIVE_CONNECTION_TYPE_4G);
+
+ std::map<std::string, std::string> variation_params;
+ variation_params["effective_connection_type_algorithm"] =
+ "TransportRTTOrDownstreamThroughput";
+ // Disable default platform values so that the effect of cached estimates
+ // at the time of startup can be studied in isolation.
+ TestNetworkQualityEstimator estimator(
+ std::unique_ptr<net::ExternalEstimateProvider>(), variation_params, true,
+ true, false /* use_default_platform_values */);
+
+ // Add observers.
+ TestRTTObserver rtt_observer;
+ TestThroughputObserver throughput_observer;
+ TestRTTAndThroughputEstimatesObserver rtt_throughput_observer;
+ TestEffectiveConnectionTypeObserver effective_connection_type_observer;
+ estimator.AddRTTObserver(&rtt_observer);
+ estimator.AddThroughputObserver(&throughput_observer);
+ estimator.AddRTTAndThroughputEstimatesObserver(&rtt_throughput_observer);
+ estimator.AddEffectiveConnectionTypeObserver(
+ &effective_connection_type_observer);
+
+ std::string network_name("test_ect_2g");
+
+ estimator.SimulateNetworkChange(
+ NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, network_name);
+ EXPECT_EQ(0u, rtt_observer.observations().size());
+ EXPECT_EQ(0u, throughput_observer.observations().size());
+ EXPECT_LE(0, rtt_throughput_observer.notifications_received());
+
+ // Simulate reading of prefs.
+ estimator.OnPrefsRead(read_prefs);
+ histogram_tester.ExpectUniqueSample("NQE.Prefs.ReadSize", read_prefs.size(),
+ 1);
+
+ // Taken from network_quality_estimator_params.cc.
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(1800),
+ rtt_observer.last_rtt(
+ NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE));
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(1500),
+ rtt_observer.last_rtt(
+ NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE));
+ EXPECT_EQ(0u, throughput_observer.observations().size());
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(1800),
+ rtt_throughput_observer.http_rtt());
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(1500),
+ rtt_throughput_observer.transport_rtt());
+ EXPECT_EQ(nqe::internal::kInvalidThroughput,
+ rtt_throughput_observer.downstream_throughput_kbps());
+ EXPECT_LE(
+ 1u,
+ effective_connection_type_observer.effective_connection_types().size());
+ // Compare the ECT stored in prefs with the observer's last entry.
+ EXPECT_EQ(
+ read_prefs[nqe::internal::NetworkID(
+ NetworkChangeNotifier::CONNECTION_WIFI, network_name)]
+ .effective_connection_type(),
+ effective_connection_type_observer.effective_connection_types().back());
+
+ // Change to a different connection type.
+ network_name = "test_ect_slow_2g";
+ estimator.SimulateNetworkChange(
+ NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, network_name);
+
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(3600),
+ rtt_observer.last_rtt(
+ NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE));
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(3000),
+ rtt_observer.last_rtt(
+ NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE));
+ EXPECT_EQ(0u, throughput_observer.observations().size());
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(3600),
+ rtt_throughput_observer.http_rtt());
+ EXPECT_EQ(base::TimeDelta::FromMilliseconds(3000),
+ rtt_throughput_observer.transport_rtt());
+ EXPECT_EQ(nqe::internal::kInvalidThroughput,
+ rtt_throughput_observer.downstream_throughput_kbps());
+ EXPECT_LE(
+ 2u,
+ effective_connection_type_observer.effective_connection_types().size());
+ // Compare with the last entry.
+ EXPECT_EQ(
+ read_prefs[nqe::internal::NetworkID(
+ NetworkChangeNotifier::CONNECTION_WIFI, network_name)]
+ .effective_connection_type(),
+ effective_connection_type_observer.effective_connection_types().back());
+
+ // Cleanup.
+ estimator.RemoveRTTObserver(&rtt_observer);
+ estimator.RemoveThroughputObserver(&throughput_observer);
+ estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer);
+ estimator.RemoveEffectiveConnectionTypeObserver(
+ &effective_connection_type_observer);
+}
+
} // namespace net
« 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