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..420bde5b3f93a80b69aebebb9cc85a662f55ecc3 100644 |
--- a/net/base/network_quality_estimator_unittest.cc |
+++ b/net/base/network_quality_estimator_unittest.cc |
@@ -42,7 +42,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 +85,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 +110,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 +1104,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(OS_LINUX) |
+#define MAYBE_TestTCPSocketRTT TestTCPSocketRTT |
+#else |
+#define MAYBE_TestTCPSocketRTT DISABLED_TestTCPSocketRTT |
+#endif |
+// Tests that TCP RTTs are notified by the TCP socket to the Network quality |
bengr
2016/02/08 18:51:14
Capitalize "Quality Estimator."
tbansal1
2016/02/08 21:33:26
Done.
|
+// estimator, which in turn notifies to the registered RTT observers. |
+TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) { |
+ TestRTTObserver rtt_observer; |
+ std::map<std::string, std::string> variation_params; |
bengr
2016/02/08 18:51:14
#include <string>
tbansal1
2016/02/08 21:33:26
Done.
|
+ 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); |
bengr
2016/02/08 18:51:14
#include "net/http/http_network_session.h"
tbansal1
2016/02/08 21:33:26
Done.
|
+ // |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++; |
bengr
2016/02/08 18:51:14
++before_count_tcp_rtt_observations;
tbansal1
2016/02/08 21:33:26
Done.
|
+ } |
bengr
2016/02/08 18:51:14
Can you expect also that at some point, rtt_observ
tbansal1
2016/02/08 21:33:26
I do not think it is possible to write a test with
bengr
2016/02/08 23:42:06
Acknowledged.
|
+ |
+ scoped_ptr<URLRequest> request(context.CreateRequest( |
+ estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
+ request->Start(); |
bengr
2016/02/08 18:51:14
#include "net/url_request/url_request.h"
tbansal1
2016/02/08 21:33:26
Done.
|
+ 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++; |
bengr
2016/02/08 18:51:14
++after_count_tcp_rtt_observations;
tbansal1
2016/02/08 21:33:26
Done.
|
+ } |
+ EXPECT_LT(before_count_tcp_rtt_observations, |
+ after_count_tcp_rtt_observations) |
+ << i; |
+ } |
+ |
+ EXPECT_TRUE(estimator.watcher_reset_notification_received()); |
+} |
+ |
} // namespace net |