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

Unified Diff: net/base/network_quality_estimator_unittest.cc

Issue 1376473003: Notify NQE of TCP RTT values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed rsleevi comments Created 4 years, 10 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
Index: net/base/network_quality_estimator_unittest.cc
diff --git a/net/base/network_quality_estimator_unittest.cc b/net/base/network_quality_estimator_unittest.cc
index 25e386db44db573184f628053115c75be6ea87e5..092d1070ec97966e1ccb332e6aa0c4333abe070b 100644
--- a/net/base/network_quality_estimator_unittest.cc
+++ b/net/base/network_quality_estimator_unittest.cc
@@ -5,8 +5,11 @@
#include "net/base/network_quality_estimator.h"
#include <stdint.h>
+#include <netinet/tcp.h>
+
#include <limits>
#include <map>
+#include <string>
#include <utility>
#include <vector>
@@ -23,10 +26,12 @@
#include "net/base/external_estimate_provider.h"
#include "net/base/load_flags.h"
#include "net/base/network_change_notifier.h"
+#include "net/http/http_network_session.h"
#include "net/http/http_status_code.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
+#include "net/url_request/url_request.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
@@ -42,7 +47,8 @@ class TestNetworkQualityEstimator : public net::NetworkQualityEstimator {
: NetworkQualityEstimator(std::move(external_estimate_provider),
variation_params,
true,
- true) {
+ true),
+ watcher_reset_notification_received_count_(0) {
// Set up embedded test server.
embedded_test_server_.ServeFilesFromDirectory(
base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
@@ -84,6 +90,14 @@ class TestNetworkQualityEstimator : public net::NetworkQualityEstimator {
return embedded_test_server_.GetURL("/echo.html");
}
+ void OnWatcherReset() override {
+ watcher_reset_notification_received_count_++;
+ }
+
+ size_t watcher_reset_notification_received_count() const {
+ return watcher_reset_notification_received_count_;
+ }
+
using NetworkQualityEstimator::ReadCachedNetworkQualityEstimate;
using NetworkQualityEstimator::OnConnectionTypeChanged;
@@ -101,6 +115,8 @@ class TestNetworkQualityEstimator : public net::NetworkQualityEstimator {
// Embedded server used for testing.
net::EmbeddedTestServer embedded_test_server_;
+ size_t watcher_reset_notification_received_count_;
+
DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator);
};
@@ -1061,12 +1077,12 @@ TEST(NetworkQualityEstimatorTest, TestObservers) {
EXPECT_EQ(2U, rtt_observer.observations().size());
EXPECT_EQ(2U, throughput_observer.observations().size());
- for (auto observation : rtt_observer.observations()) {
+ for (const auto& observation : rtt_observer.observations()) {
EXPECT_LE(0, observation.rtt_ms);
EXPECT_LE(0, (observation.timestamp - then).InMilliseconds());
EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source);
}
- for (auto observation : throughput_observer.observations()) {
+ for (const auto& observation : throughput_observer.observations()) {
EXPECT_LE(0, observation.throughput_kbps);
EXPECT_LE(0, (observation.timestamp - then).InMilliseconds());
EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source);
@@ -1093,4 +1109,66 @@ TEST(NetworkQualityEstimatorTest, TestObservers) {
rtt_observer.observations().at(3).rtt_ms);
}
+// TestTCPSocketRTT requires kernel support for tcp_info struct, and so it is
+// enabled only on the POSIX platforms.
+#if defined(TCP_INFO)
+#define MAYBE_TestTCPSocketRTT TestTCPSocketRTT
+#else
+#define MAYBE_TestTCPSocketRTT DISABLED_TestTCPSocketRTT
+#endif
+// Tests that the TCP socket notifies the Network Quality Estimator of TCP RTTs,
+// which in turn notifies registered RTT observers.
+TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) {
+ base::HistogramTester histogram_tester;
+ TestRTTObserver rtt_observer;
+ std::map<std::string, std::string> variation_params;
+ TestNetworkQualityEstimator estimator(variation_params);
+ estimator.AddRTTObserver(&rtt_observer);
+
+ TestDelegate test_delegate;
+ TestURLRequestContext context(true);
+ context.set_network_quality_estimator(&estimator);
+
+ scoped_ptr<HttpNetworkSession::Params> params(new HttpNetworkSession::Params);
+ // |estimator| should be notified of TCP RTT observations.
+ params->socket_performance_watcher_factory = &estimator;
+ context.set_http_network_session_params(std::move(params));
+ context.Init();
+
+ EXPECT_EQ(0U, rtt_observer.observations().size());
+ EXPECT_EQ(0U, estimator.watcher_reset_notification_received_count());
+
+ const size_t kNumRequests = 2;
+
+ // Send two requests. Verify that the completion of each request generates at
+ // least one TCP RTT observation.
+ for (size_t i = 0; i < kNumRequests; ++i) {
+ size_t before_count_tcp_rtt_observations = 0;
+ for (const auto& observation : rtt_observer.observations()) {
+ if (observation.source == NetworkQualityEstimator::TCP)
+ ++before_count_tcp_rtt_observations;
+ }
+
+ scoped_ptr<URLRequest> request(context.CreateRequest(
+ estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
+ request->Start();
+ base::RunLoop().Run();
+
+ size_t after_count_tcp_rtt_observations = 0;
+ for (const auto& observation : rtt_observer.observations()) {
+ if (observation.source == NetworkQualityEstimator::TCP)
+ ++after_count_tcp_rtt_observations;
+ }
+ // Exactly one notification should be received per socket performance
+ // watcher because the delay between notifications is currently set to a
+ // high value.
+ EXPECT_EQ(1u, after_count_tcp_rtt_observations -
+ before_count_tcp_rtt_observations)
+ << i;
+ }
+ // At least one reset should be received for each request.
+ EXPECT_LE(kNumRequests,
+ estimator.watcher_reset_notification_received_count());
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698