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

Side by Side 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: Fixed net tests compilation issues, Added tests 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/network_quality_estimator.h" 5 #include "net/base/network_quality_estimator.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
bengr 2016/02/08 18:51:14 Add a blank line.
tbansal1 2016/02/08 21:33:26 Done.
8 #include <limits> 8 #include <limits>
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/metrics/histogram_samples.h" 17 #include "base/metrics/histogram_samples.h"
(...skipping 17 matching lines...) Expand all
35 35
36 // Helps in setting the current network type and id. 36 // Helps in setting the current network type and id.
37 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { 37 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator {
38 public: 38 public:
39 TestNetworkQualityEstimator( 39 TestNetworkQualityEstimator(
40 const std::map<std::string, std::string>& variation_params, 40 const std::map<std::string, std::string>& variation_params,
41 scoped_ptr<net::ExternalEstimateProvider> external_estimate_provider) 41 scoped_ptr<net::ExternalEstimateProvider> external_estimate_provider)
42 : NetworkQualityEstimator(std::move(external_estimate_provider), 42 : NetworkQualityEstimator(std::move(external_estimate_provider),
43 variation_params, 43 variation_params,
44 true, 44 true,
45 true) { 45 true),
46 watcher_reset_notification_received_(false) {
46 // Set up embedded test server. 47 // Set up embedded test server.
47 embedded_test_server_.ServeFilesFromDirectory( 48 embedded_test_server_.ServeFilesFromDirectory(
48 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 49 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
49 EXPECT_TRUE(embedded_test_server_.Start()); 50 EXPECT_TRUE(embedded_test_server_.Start());
50 embedded_test_server_.RegisterRequestHandler(base::Bind( 51 embedded_test_server_.RegisterRequestHandler(base::Bind(
51 &TestNetworkQualityEstimator::HandleRequest, base::Unretained(this))); 52 &TestNetworkQualityEstimator::HandleRequest, base::Unretained(this)));
52 } 53 }
53 54
54 explicit TestNetworkQualityEstimator( 55 explicit TestNetworkQualityEstimator(
55 const std::map<std::string, std::string>& variation_params) 56 const std::map<std::string, std::string>& variation_params)
(...skipping 21 matching lines...) Expand all
77 http_response->set_content("hello"); 78 http_response->set_content("hello");
78 http_response->set_content_type("text/plain"); 79 http_response->set_content_type("text/plain");
79 return std::move(http_response); 80 return std::move(http_response);
80 } 81 }
81 82
82 // Returns a GURL hosted at embedded test server. 83 // Returns a GURL hosted at embedded test server.
83 const GURL GetEchoURL() const { 84 const GURL GetEchoURL() const {
84 return embedded_test_server_.GetURL("/echo.html"); 85 return embedded_test_server_.GetURL("/echo.html");
85 } 86 }
86 87
88 void OnWatcherReset() override {
89 watcher_reset_notification_received_ = true;
90 }
91
92 bool watcher_reset_notification_received() const {
93 return watcher_reset_notification_received_;
94 }
95
87 using NetworkQualityEstimator::ReadCachedNetworkQualityEstimate; 96 using NetworkQualityEstimator::ReadCachedNetworkQualityEstimate;
88 using NetworkQualityEstimator::OnConnectionTypeChanged; 97 using NetworkQualityEstimator::OnConnectionTypeChanged;
89 98
90 private: 99 private:
91 // NetworkQualityEstimator implementation that returns the overridden network 100 // NetworkQualityEstimator implementation that returns the overridden network
92 // id (instead of invoking platform APIs). 101 // id (instead of invoking platform APIs).
93 NetworkQualityEstimator::NetworkID GetCurrentNetworkID() const override { 102 NetworkQualityEstimator::NetworkID GetCurrentNetworkID() const override {
94 return NetworkQualityEstimator::NetworkID(current_network_type_, 103 return NetworkQualityEstimator::NetworkID(current_network_type_,
95 current_network_id_); 104 current_network_id_);
96 } 105 }
97 106
98 net::NetworkChangeNotifier::ConnectionType current_network_type_; 107 net::NetworkChangeNotifier::ConnectionType current_network_type_;
99 std::string current_network_id_; 108 std::string current_network_id_;
100 109
101 // Embedded server used for testing. 110 // Embedded server used for testing.
102 net::EmbeddedTestServer embedded_test_server_; 111 net::EmbeddedTestServer embedded_test_server_;
103 112
113 bool watcher_reset_notification_received_;
114
104 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); 115 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator);
105 }; 116 };
106 117
107 class TestRTTObserver : public net::NetworkQualityEstimator::RTTObserver { 118 class TestRTTObserver : public net::NetworkQualityEstimator::RTTObserver {
108 public: 119 public:
109 struct Observation { 120 struct Observation {
110 Observation(int32_t ms, 121 Observation(int32_t ms,
111 const base::TimeTicks& ts, 122 const base::TimeTicks& ts,
112 net::NetworkQualityEstimator::ObservationSource src) 123 net::NetworkQualityEstimator::ObservationSource src)
113 : rtt_ms(ms), timestamp(ts), source(src) {} 124 : rtt_ms(ms), timestamp(ts), source(src) {}
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 quic_watcher->OnUpdatedRTTAvailable(quic_rtt); 1097 quic_watcher->OnUpdatedRTTAvailable(quic_rtt);
1087 1098
1088 EXPECT_EQ(4U, rtt_observer.observations().size()); 1099 EXPECT_EQ(4U, rtt_observer.observations().size());
1089 EXPECT_EQ(2U, throughput_observer.observations().size()); 1100 EXPECT_EQ(2U, throughput_observer.observations().size());
1090 1101
1091 EXPECT_EQ(tcp_rtt.InMilliseconds(), rtt_observer.observations().at(2).rtt_ms); 1102 EXPECT_EQ(tcp_rtt.InMilliseconds(), rtt_observer.observations().at(2).rtt_ms);
1092 EXPECT_EQ(quic_rtt.InMilliseconds(), 1103 EXPECT_EQ(quic_rtt.InMilliseconds(),
1093 rtt_observer.observations().at(3).rtt_ms); 1104 rtt_observer.observations().at(3).rtt_ms);
1094 } 1105 }
1095 1106
1107 // TestTCPSocketRTT requires kernel support for tcp_info struct, and so it is
1108 // enabled only on the Linux platform.
1109 #if defined(OS_LINUX)
1110 #define MAYBE_TestTCPSocketRTT TestTCPSocketRTT
1111 #else
1112 #define MAYBE_TestTCPSocketRTT DISABLED_TestTCPSocketRTT
1113 #endif
1114 // 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.
1115 // estimator, which in turn notifies to the registered RTT observers.
1116 TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) {
1117 TestRTTObserver rtt_observer;
1118 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.
1119 TestNetworkQualityEstimator estimator(variation_params);
1120 estimator.AddRTTObserver(&rtt_observer);
1121
1122 TestDelegate test_delegate;
1123 TestURLRequestContext context(true);
1124 context.set_network_quality_estimator(&estimator);
1125
1126 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.
1127 // |estimator| should be notified of TCP RTT observations.
1128 params->socket_performance_watcher_factory = &estimator;
1129 context.set_http_network_session_params(std::move(params));
1130 context.Init();
1131
1132 EXPECT_EQ(0U, rtt_observer.observations().size());
1133 EXPECT_FALSE(estimator.watcher_reset_notification_received());
1134
1135 // Send two requests. Verify that the completion of each request generates at
1136 // least one TCP RTT observation.
1137 for (size_t i = 0; i < 2; ++i) {
1138 size_t before_count_tcp_rtt_observations = 0;
1139 for (auto observation : rtt_observer.observations()) {
1140 if (observation.source == NetworkQualityEstimator::TCP)
1141 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.
1142 }
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.
1143
1144 scoped_ptr<URLRequest> request(context.CreateRequest(
1145 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
1146 request->Start();
bengr 2016/02/08 18:51:14 #include "net/url_request/url_request.h"
tbansal1 2016/02/08 21:33:26 Done.
1147 base::RunLoop().Run();
1148
1149 size_t after_count_tcp_rtt_observations = 0;
1150 for (auto observation : rtt_observer.observations()) {
1151 if (observation.source == NetworkQualityEstimator::TCP)
1152 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.
1153 }
1154 EXPECT_LT(before_count_tcp_rtt_observations,
1155 after_count_tcp_rtt_observations)
1156 << i;
1157 }
1158
1159 EXPECT_TRUE(estimator.watcher_reset_notification_received());
1160 }
1161
1096 } // namespace net 1162 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698