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

Unified Diff: net/nqe/network_quality_estimator_unittest.cc

Issue 2480203002: ui: Cleanup class/struct forward declarations (Closed)
Patch Set: Sync CL to position 430550 Created 4 years, 1 month 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_test_util.cc ('k') | net/nqe/network_quality_observation_source.h » ('j') | 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 81ae4622d86c426f1302a1adda9cba1241d109e7..a568bc91cea417fafe3c8d95240a1d2692ea2912 100644
--- a/net/nqe/network_quality_estimator_unittest.cc
+++ b/net/nqe/network_quality_estimator_unittest.cc
@@ -162,8 +162,9 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) {
base::TimeDelta rtt;
int32_t kbps;
- EXPECT_FALSE(estimator.GetHttpRTT(&rtt));
- EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_FALSE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
TestDelegate test_delegate;
TestURLRequestContext context(true);
@@ -177,9 +178,10 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) {
base::RunLoop().Run();
// Both RTT and downstream throughput should be updated.
- EXPECT_TRUE(estimator.GetHttpRTT(&rtt));
- EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps));
- EXPECT_FALSE(estimator.GetTransportRTT(&rtt));
+ EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_TRUE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
+ EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
// Check UMA histograms.
histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0);
@@ -190,6 +192,12 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) {
histogram_tester.ExpectUniqueSample(
"NQE.MainFrame.EffectiveConnectionType.Unknown",
EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1);
+ histogram_tester.ExpectUniqueSample("NQE.EstimateAvailable.MainFrame.RTT", 0,
+ 1);
+ histogram_tester.ExpectUniqueSample(
+ "NQE.EstimateAvailable.MainFrame.TransportRTT", 0, 1);
+ histogram_tester.ExpectUniqueSample("NQE.EstimateAvailable.MainFrame.Kbps", 0,
+ 1);
std::unique_ptr<URLRequest> request2(context.CreateRequest(
estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
@@ -199,6 +207,12 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) {
histogram_tester.ExpectTotalCount("NQE.MainFrame.EffectiveConnectionType", 2);
histogram_tester.ExpectTotalCount(
"NQE.MainFrame.EffectiveConnectionType.Unknown", 2);
+ histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 1,
+ 1);
+ histogram_tester.ExpectUniqueSample(
+ "NQE.EstimateAvailable.MainFrame.TransportRTT", 0, 2);
+ histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.Kbps", 1,
+ 1);
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1");
@@ -217,8 +231,9 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) {
histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 0);
- EXPECT_FALSE(estimator.GetHttpRTT(&rtt));
- EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_FALSE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
// Verify that metrics are logged correctly on main-frame requests.
histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50", 1);
@@ -239,8 +254,9 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) {
histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1);
histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1);
- EXPECT_FALSE(estimator.GetHttpRTT(&rtt));
- EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_FALSE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
std::unique_ptr<URLRequest> request3(context.CreateRequest(
estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
@@ -251,6 +267,16 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) {
"NQE.MainFrame.EffectiveConnectionType.WiFi",
EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1);
histogram_tester.ExpectTotalCount("NQE.MainFrame.EffectiveConnectionType", 3);
+ histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 0,
+ 2);
+ histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 1,
+ 1);
+ histogram_tester.ExpectUniqueSample(
+ "NQE.EstimateAvailable.MainFrame.TransportRTT", 0, 3);
+ histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.Kbps", 0,
+ 2);
+ histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.Kbps", 1,
+ 1);
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test");
@@ -274,8 +300,9 @@ TEST(NetworkQualityEstimatorTest, Caching) {
base::TimeDelta rtt;
int32_t kbps;
- EXPECT_FALSE(estimator.GetHttpRTT(&rtt));
- EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_FALSE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
TestDelegate test_delegate;
TestURLRequestContext context(true);
@@ -296,11 +323,12 @@ TEST(NetworkQualityEstimatorTest, Caching) {
base::RunLoop().RunUntilIdle();
// Both RTT and downstream throughput should be updated.
- EXPECT_TRUE(estimator.GetHttpRTT(&rtt));
- EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_TRUE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
estimator.GetEffectiveConnectionType());
- EXPECT_FALSE(estimator.GetTransportRTT(&rtt));
+ EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false,
1);
@@ -333,8 +361,9 @@ TEST(NetworkQualityEstimatorTest, StoreObservations) {
base::TimeDelta rtt;
int32_t kbps;
- EXPECT_FALSE(estimator.GetHttpRTT(&rtt));
- EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_FALSE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
TestDelegate test_delegate;
TestURLRequestContext context(true);
@@ -348,15 +377,17 @@ TEST(NetworkQualityEstimatorTest, StoreObservations) {
estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
request->Start();
base::RunLoop().Run();
- EXPECT_TRUE(estimator.GetHttpRTT(&rtt));
- EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_TRUE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
}
// Verify that the stored observations are cleared on network change.
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-2");
- EXPECT_FALSE(estimator.GetHttpRTT(&rtt));
- EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_FALSE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
}
// This test notifies NetworkQualityEstimator of received data. Next,
@@ -431,24 +462,26 @@ TEST(NetworkQualityEstimatorTest, ObtainOperatingParams) {
TestNetworkQualityEstimator estimator(variation_params);
base::TimeDelta rtt;
- EXPECT_TRUE(estimator.GetHttpRTT(&rtt));
+ EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
int32_t kbps;
- EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_TRUE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
EXPECT_EQ(100, kbps);
EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt);
- EXPECT_FALSE(estimator.GetTransportRTT(&rtt));
+ EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
// Simulate network change to Wi-Fi.
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1");
- EXPECT_TRUE(estimator.GetHttpRTT(&rtt));
- EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_TRUE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
EXPECT_EQ(200, kbps);
EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt);
- EXPECT_FALSE(estimator.GetTransportRTT(&rtt));
+ EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
// Peak network quality should not be affected by the network quality
// estimator field trial.
@@ -462,16 +495,18 @@ TEST(NetworkQualityEstimatorTest, ObtainOperatingParams) {
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2");
- EXPECT_FALSE(estimator.GetHttpRTT(&rtt));
- EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_TRUE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
EXPECT_EQ(300, kbps);
// Simulate network change to 3G. Default estimates should be unavailable.
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3");
- EXPECT_FALSE(estimator.GetHttpRTT(&rtt));
- EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_FALSE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
}
TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) {
@@ -583,10 +618,11 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyRTT) {
};
for (const auto& test : tests) {
- estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec));
+ estimator.set_start_time_null_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_start_time_null_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.
@@ -640,11 +676,11 @@ TEST(NetworkQualityEstimatorTest, DefaultTransportRTTBasedThresholds) {
estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI,
"test");
- estimator.set_transport_rtt(
+ estimator.set_start_time_null_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_start_time_null_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.
@@ -696,11 +732,11 @@ TEST(NetworkQualityEstimatorTest, DefaultHttpRTTBasedThresholds) {
estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI,
"test");
- estimator.set_http_rtt(
+ estimator.set_start_time_null_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_start_time_null_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.
@@ -749,11 +785,11 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyTransportRTT) {
};
for (const auto& test : tests) {
- estimator.set_transport_rtt(
+ estimator.set_start_time_null_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_start_time_null_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.
@@ -812,10 +848,12 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsHttpRTTandThroughput) {
};
for (const auto& test : tests) {
- estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec));
+ estimator.set_start_time_null_http_rtt(
+ base::TimeDelta::FromMilliseconds(test.rtt_msec));
estimator.set_recent_http_rtt(
base::TimeDelta::FromMilliseconds(test.rtt_msec));
- estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps);
+ estimator.set_start_time_null_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
@@ -877,11 +915,12 @@ TEST(NetworkQualityEstimatorTest, ObtainThresholdsTransportRTTandThroughput) {
};
for (const auto& test : tests) {
- estimator.set_transport_rtt(
+ estimator.set_start_time_null_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(test.downlink_throughput_kbps);
+ estimator.set_start_time_null_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
@@ -951,11 +990,10 @@ TEST(NetworkQualityEstimatorTest, TestGetMetricsSince) {
for (size_t i = 0; i < 2; ++i) {
estimator.downstream_throughput_kbps_observations_.AddObservation(
NetworkQualityEstimator::ThroughputObservation(
- old_downlink_kbps, old,
- NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST));
+ old_downlink_kbps, old, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
estimator.rtt_observations_.AddObservation(
NetworkQualityEstimator::RttObservation(
- old_url_rtt, old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST));
+ old_url_rtt, old, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
estimator.rtt_observations_.AddObservation(
NetworkQualityEstimator::RttObservation(
old_tcp_rtt, old, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP));
@@ -975,11 +1013,10 @@ TEST(NetworkQualityEstimatorTest, TestGetMetricsSince) {
estimator.downstream_throughput_kbps_observations_.AddObservation(
NetworkQualityEstimator::ThroughputObservation(
- new_downlink_kbps, now,
- NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST));
+ new_downlink_kbps, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
estimator.rtt_observations_.AddObservation(
NetworkQualityEstimator::RttObservation(
- new_url_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST));
+ new_url_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
estimator.rtt_observations_.AddObservation(
NetworkQualityEstimator::RttObservation(
new_tcp_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP));
@@ -1086,8 +1123,9 @@ TEST(NetworkQualityEstimatorTest, InvalidExternalEstimateProvider) {
base::TimeDelta rtt;
int32_t kbps;
EXPECT_EQ(1U, invalid_external_estimate_provider->update_count());
- EXPECT_FALSE(estimator.GetHttpRTT(&rtt));
- EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_FALSE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 2);
histogram_tester.ExpectBucketCount(
@@ -1188,9 +1226,10 @@ TEST(NetworkQualityEstimatorTest, TestExternalEstimateProvider) {
"test");
base::TimeDelta rtt;
int32_t kbps;
- EXPECT_TRUE(estimator.GetHttpRTT(&rtt));
- EXPECT_FALSE(estimator.GetTransportRTT(&rtt));
- EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
+ EXPECT_TRUE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 5);
@@ -1220,8 +1259,9 @@ TEST(NetworkQualityEstimatorTest, TestExternalEstimateProvider) {
// provider must increment.
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1");
- EXPECT_TRUE(estimator.GetHttpRTT(&rtt));
- EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_TRUE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
EXPECT_EQ(2U, test_external_estimate_provider->update_count());
test_external_estimate_provider->set_should_notify_delegate(false);
@@ -1230,8 +1270,9 @@ TEST(NetworkQualityEstimatorTest, TestExternalEstimateProvider) {
EXPECT_EQ(3U, test_external_estimate_provider->update_count());
// Estimates are unavailable because external estimate provider never
// notifies network quality estimator of the updated estimates.
- EXPECT_FALSE(estimator.GetHttpRTT(&rtt));
- EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_FALSE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
}
// Tests if the estimate from the external estimate provider is merged with the
@@ -1256,11 +1297,12 @@ TEST(NetworkQualityEstimatorTest, TestExternalEstimateProviderMergeEstimates) {
base::TimeDelta rtt;
// Estimate provided by network quality estimator should match the estimate
// provided by external estimate provider.
- EXPECT_TRUE(estimator.GetHttpRTT(&rtt));
+ EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
EXPECT_EQ(external_estimate_provider_rtt, rtt);
int32_t kbps;
- EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_TRUE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
EXPECT_EQ(external_estimate_provider_downstream_throughput, kbps);
TestDelegate test_delegate;
@@ -1273,10 +1315,11 @@ TEST(NetworkQualityEstimatorTest, TestExternalEstimateProviderMergeEstimates) {
request->Start();
base::RunLoop().Run();
- EXPECT_TRUE(estimator.GetHttpRTT(&rtt));
+ EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
EXPECT_NE(external_estimate_provider_rtt, rtt);
- EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_TRUE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
EXPECT_NE(external_estimate_provider_downstream_throughput, kbps);
}
@@ -1304,9 +1347,10 @@ TEST(NetworkQualityEstimatorTest, TestThroughputNoRequestOverlap) {
test.allow_small_localhost_requests);
base::TimeDelta rtt;
- EXPECT_FALSE(estimator.GetHttpRTT(&rtt));
+ EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
int32_t kbps;
- EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps));
+ EXPECT_FALSE(
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
TestDelegate test_delegate;
TestURLRequestContext context(true);
@@ -1319,9 +1363,11 @@ TEST(NetworkQualityEstimatorTest, TestThroughputNoRequestOverlap) {
request->Start();
base::RunLoop().Run();
- EXPECT_EQ(test.allow_small_localhost_requests, estimator.GetHttpRTT(&rtt));
EXPECT_EQ(test.allow_small_localhost_requests,
- estimator.GetDownlinkThroughputKbps(&kbps));
+ estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_EQ(
+ test.allow_small_localhost_requests,
+ estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
}
}
@@ -1346,7 +1392,10 @@ TEST(NetworkQualityEstimatorTest, TestEffectiveConnectionTypeObserver) {
EXPECT_EQ(0U, observer.effective_connection_types().size());
- estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G);
+ estimator.set_start_time_null_http_rtt(
+ base::TimeDelta::FromMilliseconds(1500));
+ estimator.set_start_time_null_downlink_throughput_kbps(100000);
+
tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60));
std::unique_ptr<URLRequest> request(context.CreateRequest(
@@ -1371,7 +1420,8 @@ 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_start_time_null_http_rtt(
+ base::TimeDelta::FromMilliseconds(500));
estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI,
"test");
EXPECT_EQ(2U, observer.effective_connection_types().size());
@@ -1379,7 +1429,8 @@ 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_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G);
+ estimator.set_start_time_null_http_rtt(
+ base::TimeDelta::FromMilliseconds(100));
EXPECT_EQ(2U, observer.effective_connection_types().size());
}
@@ -1412,10 +1463,10 @@ TEST(NetworkQualityEstimatorTest, TestRTTAndThroughputEstimatesObserver) {
base::TimeDelta http_rtt(base::TimeDelta::FromMilliseconds(100));
base::TimeDelta transport_rtt(base::TimeDelta::FromMilliseconds(200));
int32_t downstream_throughput_kbps(300);
- estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G);
- estimator.set_recent_http_rtt(http_rtt);
- estimator.set_recent_transport_rtt(transport_rtt);
- estimator.set_recent_downlink_throughput_kbps(downstream_throughput_kbps);
+ estimator.set_start_time_null_http_rtt(http_rtt);
+ estimator.set_start_time_null_transport_rtt(transport_rtt);
+ estimator.set_start_time_null_downlink_throughput_kbps(
+ downstream_throughput_kbps);
tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60));
std::unique_ptr<URLRequest> request(context.CreateRequest(
@@ -1439,16 +1490,20 @@ TEST(NetworkQualityEstimatorTest, TestRTTAndThroughputEstimatesObserver) {
// A change in the connection type should send out notification to the
// observers.
- estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G);
estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI,
"test");
+ EXPECT_EQ(http_rtt, observer.http_rtt());
+ EXPECT_EQ(transport_rtt, observer.transport_rtt());
+ EXPECT_EQ(downstream_throughput_kbps, observer.downstream_throughput_kbps());
EXPECT_LE(1, observer.notifications_received() - notifications_received);
notifications_received = observer.notifications_received();
// 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_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G);
+ estimator.set_start_time_null_http_rtt(
+ base::TimeDelta::FromMilliseconds(10000));
+ estimator.set_start_time_null_http_rtt(base::TimeDelta::FromMilliseconds(1));
EXPECT_EQ(0, observer.notifications_received() - notifications_received);
}
@@ -1477,7 +1532,7 @@ TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) {
NetworkQualityEstimator::RttObservation rtt_observation(
base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(),
- NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST);
+ NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP);
for (size_t i = 0; i < 10; ++i) {
estimator.NotifyObserversOfRTT(rtt_observation);
@@ -1491,7 +1546,7 @@ TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) {
// type since the last computed effective connection type was unknown.
estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation(
base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(),
- NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST));
+ NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
++expected_effective_connection_type_notifications;
EXPECT_EQ(expected_effective_connection_type_notifications,
observer.effective_connection_types().size());
@@ -1535,6 +1590,12 @@ TEST(NetworkQualityEstimatorTest,
histogram_tester.ExpectUniqueSample(
"NQE.MainFrame.EffectiveConnectionType.WiFi",
EFFECTIVE_CONNECTION_TYPE_2G, 1);
+ histogram_tester.ExpectUniqueSample("NQE.EstimateAvailable.MainFrame.RTT", 0,
+ 1);
+ histogram_tester.ExpectUniqueSample(
+ "NQE.EstimateAvailable.MainFrame.TransportRTT", 0, 1);
+ histogram_tester.ExpectUniqueSample("NQE.EstimateAvailable.MainFrame.Kbps", 0,
+ 1);
size_t expected_effective_connection_type_notifications = 1;
EXPECT_EQ(expected_effective_connection_type_notifications,
@@ -1564,11 +1625,11 @@ TEST(NetworkQualityEstimatorTest,
estimator.rtt_observations_.AddObservation(
NetworkQualityEstimator::RttObservation(
base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(),
- NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST));
+ NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation(
base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(),
- NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST));
+ NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
if (i == rtt_observations_count) {
// Effective connection type must be recomputed since the number of RTT
@@ -1613,27 +1674,26 @@ TEST(NetworkQualityEstimatorTest, TestRttThroughputObservers) {
// Both RTT and downstream throughput should be updated.
base::TimeDelta rtt;
- EXPECT_TRUE(estimator.GetHttpRTT(&rtt));
+ EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
int32_t throughput;
- EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&throughput));
+ EXPECT_TRUE(estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(),
+ &throughput));
EXPECT_EQ(2U, rtt_observer.observations().size());
EXPECT_EQ(2U, throughput_observer.observations().size());
for (const auto& observation : rtt_observer.observations()) {
EXPECT_LE(0, observation.rtt_ms);
EXPECT_LE(0, (observation.timestamp - then).InMilliseconds());
- EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST,
- observation.source);
+ EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, observation.source);
}
for (const auto& observation : throughput_observer.observations()) {
EXPECT_LE(0, observation.throughput_kbps);
EXPECT_LE(0, (observation.timestamp - then).InMilliseconds());
- EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST,
- observation.source);
+ EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, observation.source);
}
- EXPECT_FALSE(estimator.GetTransportRTT(&rtt));
+ EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
// Verify that observations from TCP and QUIC are passed on to the observers.
base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1));
@@ -1661,7 +1721,7 @@ TEST(NetworkQualityEstimatorTest, TestRttThroughputObservers) {
EXPECT_EQ(quic_rtt.InMilliseconds(),
rtt_observer.observations().at(3).rtt_ms);
- EXPECT_TRUE(estimator.GetTransportRTT(&rtt));
+ EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
}
// TestTCPSocketRTT requires kernel support for tcp_info struct, and so it is
@@ -1694,8 +1754,8 @@ TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) {
EXPECT_EQ(0U, rtt_observer.observations().size());
base::TimeDelta rtt;
- EXPECT_FALSE(estimator.GetHttpRTT(&rtt));
- EXPECT_FALSE(estimator.GetTransportRTT(&rtt));
+ EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
// Send two requests. Verify that the completion of each request generates at
// least one TCP RTT observation.
@@ -1724,8 +1784,8 @@ TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) {
before_count_tcp_rtt_observations)
<< i;
}
- EXPECT_TRUE(estimator.GetHttpRTT(&rtt));
- EXPECT_TRUE(estimator.GetTransportRTT(&rtt));
+ EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
+ EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1");
@@ -1741,6 +1801,17 @@ TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) {
// Verify that metrics are logged correctly on main-frame requests.
histogram_tester.ExpectTotalCount("NQE.MainFrame.TransportRTT.Percentile50",
num_requests);
+ histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 0,
+ 1);
+ histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 1,
+ num_requests - 1);
+ histogram_tester.ExpectUniqueSample(
+ "NQE.EstimateAvailable.MainFrame.TransportRTT", 1, num_requests);
+ histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.Kbps", 0,
+ 1);
+ histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.Kbps", 1,
+ num_requests - 1);
+
histogram_tester.ExpectTotalCount(
"NQE.MainFrame.TransportRTT.Percentile50.Unknown", num_requests);
histogram_tester.ExpectTotalCount("NQE.MainFrame.EffectiveConnectionType",
@@ -1760,8 +1831,8 @@ TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) {
#endif
// Tests if the NQE accuracy metrics are recorded properly.
TEST(NetworkQualityEstimatorTest, MAYBE_RecordAccuracy) {
- const int expected_rtt_msec = 100;
- const int expected_downstream_throughput_kbps = 200;
+ const int expected_rtt_msec = 500;
+ const int expected_downstream_throughput_kbps = 2000;
const base::TimeDelta accuracy_recording_delays[] = {
base::TimeDelta::FromSeconds(0), base::TimeDelta::FromSeconds(1),
@@ -1778,21 +1849,20 @@ TEST(NetworkQualityEstimatorTest, MAYBE_RecordAccuracy) {
{base::TimeDelta::FromMilliseconds(expected_rtt_msec),
base::TimeDelta::FromMilliseconds(expected_rtt_msec),
expected_downstream_throughput_kbps, expected_downstream_throughput_kbps,
- EFFECTIVE_CONNECTION_TYPE_2G, EFFECTIVE_CONNECTION_TYPE_2G},
-
+ EFFECTIVE_CONNECTION_TYPE_3G, EFFECTIVE_CONNECTION_TYPE_3G},
{
- base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1),
+ base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1000),
base::TimeDelta::FromMilliseconds(expected_rtt_msec),
- expected_downstream_throughput_kbps + 1,
- expected_downstream_throughput_kbps, EFFECTIVE_CONNECTION_TYPE_3G,
- EFFECTIVE_CONNECTION_TYPE_2G,
+ expected_downstream_throughput_kbps - 1,
+ expected_downstream_throughput_kbps, EFFECTIVE_CONNECTION_TYPE_2G,
+ EFFECTIVE_CONNECTION_TYPE_3G,
},
{
- base::TimeDelta::FromMilliseconds(expected_rtt_msec - 1),
+ base::TimeDelta::FromMilliseconds(expected_rtt_msec - 400),
base::TimeDelta::FromMilliseconds(expected_rtt_msec),
- expected_downstream_throughput_kbps - 1,
- expected_downstream_throughput_kbps,
- EFFECTIVE_CONNECTION_TYPE_SLOW_2G, EFFECTIVE_CONNECTION_TYPE_2G,
+ expected_downstream_throughput_kbps + 1,
+ expected_downstream_throughput_kbps, EFFECTIVE_CONNECTION_TYPE_4G,
+ EFFECTIVE_CONNECTION_TYPE_3G,
},
};
@@ -1821,16 +1891,14 @@ TEST(NetworkQualityEstimatorTest, MAYBE_RecordAccuracy) {
// RTT is higher than threshold. Network is slow.
// Network was predicted to be slow and actually was slow.
- estimator.set_http_rtt(test.rtt);
+ estimator.set_start_time_null_http_rtt(test.rtt);
estimator.set_recent_http_rtt(test.recent_rtt);
- estimator.set_transport_rtt(test.rtt);
+ estimator.set_start_time_null_transport_rtt(test.rtt);
estimator.set_recent_transport_rtt(test.recent_rtt);
- estimator.set_downlink_throughput_kbps(test.downstream_throughput_kbps);
+ estimator.set_start_time_null_downlink_throughput_kbps(
+ test.downstream_throughput_kbps);
estimator.set_recent_downlink_throughput_kbps(
test.recent_downstream_throughput_kbps);
- estimator.set_effective_connection_type(test.effective_connection_type);
- estimator.set_recent_effective_connection_type(
- test.recent_effective_connection_type);
base::HistogramTester histogram_tester;
@@ -1855,61 +1923,91 @@ TEST(NetworkQualityEstimatorTest, MAYBE_RecordAccuracy) {
base::RunLoop().RunUntilIdle();
}
- const int diff = std::abs(test.rtt.InMilliseconds() -
- test.recent_rtt.InMilliseconds());
- const std::string sign_suffix_with_one_sample =
- test.rtt.InMilliseconds() - test.recent_rtt.InMilliseconds() >= 0
- ? "Positive"
- : "Negative";
- const std::string sign_suffix_with_zero_samples =
+ const int rtt_diff = std::abs(test.rtt.InMilliseconds() -
+ test.recent_rtt.InMilliseconds());
+ const int kbps_diff = std::abs(test.downstream_throughput_kbps -
+ test.recent_downstream_throughput_kbps);
+ const int ect_diff = std::abs(test.effective_connection_type -
+ test.recent_effective_connection_type);
+
+ const std::string rtt_sign_suffix_with_zero_samples =
test.rtt.InMilliseconds() - test.recent_rtt.InMilliseconds() >= 0
? "Negative"
: "Positive";
+ const std::string kbps_sign_suffix_with_zero_samples =
+ test.downstream_throughput_kbps -
+ test.recent_downstream_throughput_kbps >=
+ 0
+ ? "Negative"
+ : "Positive";
+
+ const std::string rtt_sign_suffix_with_one_sample =
+ rtt_sign_suffix_with_zero_samples == "Positive" ? "Negative"
+ : "Positive";
+ const std::string ect_sign_suffix_with_zero_samples =
+ test.rtt.InMilliseconds() - test.recent_rtt.InMilliseconds() > 0
+ ? "Positive"
+ : "Negative";
+
+ const std::string kbps_sign_suffix_with_one_sample =
+ kbps_sign_suffix_with_zero_samples == "Positive" ? "Negative"
+ : "Positive";
+ const std::string ect_sign_suffix_with_one_sample =
+ ect_sign_suffix_with_zero_samples == "Positive" ? "Negative"
+ : "Positive";
const std::string interval_value =
base::IntToString(accuracy_recording_delay.InSeconds());
histogram_tester.ExpectUniqueSample(
"NQE.Accuracy.DownstreamThroughputKbps.EstimatedObservedDiff." +
- sign_suffix_with_one_sample + "." + interval_value + ".140_300",
- diff, 1);
+ kbps_sign_suffix_with_one_sample + "." + interval_value +
+ ".1260_2540",
+ kbps_diff, 1);
histogram_tester.ExpectTotalCount(
"NQE.Accuracy.DownstreamThroughputKbps.EstimatedObservedDiff." +
- sign_suffix_with_zero_samples + "." + interval_value + ".140_300",
+ kbps_sign_suffix_with_zero_samples + "." + interval_value +
+ ".1260_2540",
0);
histogram_tester.ExpectUniqueSample(
"NQE.Accuracy.EffectiveConnectionType.EstimatedObservedDiff." +
- sign_suffix_with_one_sample + "." + interval_value + ".2G",
- diff, 1);
+ ect_sign_suffix_with_one_sample + "." + interval_value + ".3G",
+ ect_diff, 1);
histogram_tester.ExpectTotalCount(
"NQE.Accuracy.EffectiveConnectionType.EstimatedObservedDiff." +
- sign_suffix_with_zero_samples + "." + interval_value + ".2G",
+ ect_sign_suffix_with_zero_samples + "." + interval_value + ".3G",
0);
histogram_tester.ExpectUniqueSample(
"NQE.Accuracy.HttpRTT.EstimatedObservedDiff." +
- sign_suffix_with_one_sample + "." + interval_value + ".60_140",
- diff, 1);
+ rtt_sign_suffix_with_one_sample + "." + interval_value +
+ ".300_620",
+ rtt_diff, 1);
histogram_tester.ExpectTotalCount(
"NQE.Accuracy.HttpRTT.EstimatedObservedDiff." +
- sign_suffix_with_zero_samples + "." + interval_value + ".60_140",
+ rtt_sign_suffix_with_zero_samples + "." + interval_value +
+ ".300_620",
0);
histogram_tester.ExpectUniqueSample(
"NQE.Accuracy.TransportRTT.EstimatedObservedDiff." +
- sign_suffix_with_one_sample + "." + interval_value + ".60_140",
- diff, 1);
+ rtt_sign_suffix_with_one_sample + "." + interval_value +
+ ".300_620",
+ rtt_diff, 1);
histogram_tester.ExpectTotalCount(
"NQE.Accuracy.TransportRTT.EstimatedObservedDiff." +
- sign_suffix_with_zero_samples + "." + interval_value + ".60_140",
+ rtt_sign_suffix_with_zero_samples + "." + interval_value +
+ ".300_620",
0);
histogram_tester.ExpectUniqueSample(
"NQE.ExternalEstimateProvider.RTT.Accuracy.EstimatedObservedDiff." +
- sign_suffix_with_one_sample + "." + interval_value + ".60_140",
- diff, 1);
+ rtt_sign_suffix_with_one_sample + "." + interval_value +
+ ".300_620",
+ rtt_diff, 1);
histogram_tester.ExpectTotalCount(
"NQE.ExternalEstimateProvider.RTT.Accuracy.EstimatedObservedDiff." +
- sign_suffix_with_zero_samples + "." + interval_value + ".60_140",
+ rtt_sign_suffix_with_zero_samples + "." + interval_value +
+ ".300_620",
0);
}
}
@@ -2026,11 +2124,12 @@ TEST(NetworkQualityEstimatorTest, CorrelationHistogram) {
}
TestNetworkQualityEstimator estimator(variation_params);
- estimator.set_transport_rtt(test.transport_rtt);
+ estimator.set_start_time_null_transport_rtt(test.transport_rtt);
estimator.set_recent_transport_rtt(test.transport_rtt);
- estimator.set_http_rtt(test.http_rtt);
+ estimator.set_start_time_null_http_rtt(test.http_rtt);
estimator.set_recent_http_rtt(test.http_rtt);
- estimator.set_downlink_throughput_kbps(test.downstream_throughput_kbps);
+ estimator.set_start_time_null_downlink_throughput_kbps(
+ test.downstream_throughput_kbps);
estimator.set_rand_double(test.rand_double);
TestDelegate test_delegate;
« no previous file with comments | « net/nqe/network_quality_estimator_test_util.cc ('k') | net/nqe/network_quality_observation_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698