| 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..7c41a90a7cfa683a99bcb9b18e2f79fc3c124a75 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_(false) {
|
| // 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_ = true;
|
| + }
|
| +
|
| + bool watcher_reset_notification_received() const {
|
| + return watcher_reset_notification_received_;
|
| + }
|
| +
|
| 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_;
|
|
|
| + bool watcher_reset_notification_received_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator);
|
| };
|
|
|
| @@ -1093,4 +1109,59 @@ 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 Linux platform.
|
| +#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) {
|
| + 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_FALSE(estimator.watcher_reset_notification_received());
|
| +
|
| + // Send two requests. Verify that the completion of each request generates at
|
| + // least one TCP RTT observation.
|
| + for (size_t i = 0; i < 2; ++i) {
|
| + size_t before_count_tcp_rtt_observations = 0;
|
| + for (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 (auto observation : rtt_observer.observations()) {
|
| + if (observation.source == NetworkQualityEstimator::TCP)
|
| + ++after_count_tcp_rtt_observations;
|
| + }
|
| + EXPECT_LT(before_count_tcp_rtt_observations,
|
| + after_count_tcp_rtt_observations)
|
| + << i;
|
| + }
|
| +
|
| + EXPECT_TRUE(estimator.watcher_reset_notification_received());
|
| +}
|
| +
|
| } // namespace net
|
|
|