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

Side by Side Diff: net/nqe/network_quality_estimator_test_util.cc

Issue 2461833002: NQE: Store the current network quality in a single variable (Closed)
Patch Set: Rebased 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/nqe/network_quality_estimator_test_util.h" 5 #include "net/nqe/network_quality_estimator_test_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "net/base/load_flags.h" 9 #include "net/base/load_flags.h"
10 #include "net/test/embedded_test_server/http_response.h" 10 #include "net/test/embedded_test_server/http_response.h"
(...skipping 12 matching lines...) Expand all
23 23
24 TestNetworkQualityEstimator::TestNetworkQualityEstimator( 24 TestNetworkQualityEstimator::TestNetworkQualityEstimator(
25 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider, 25 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider,
26 const std::map<std::string, std::string>& variation_params, 26 const std::map<std::string, std::string>& variation_params,
27 bool allow_local_host_requests_for_tests, 27 bool allow_local_host_requests_for_tests,
28 bool allow_smaller_responses_for_tests) 28 bool allow_smaller_responses_for_tests)
29 : NetworkQualityEstimator(std::move(external_estimate_provider), 29 : NetworkQualityEstimator(std::move(external_estimate_provider),
30 variation_params, 30 variation_params,
31 allow_local_host_requests_for_tests, 31 allow_local_host_requests_for_tests,
32 allow_smaller_responses_for_tests), 32 allow_smaller_responses_for_tests),
33 effective_connection_type_set_(false),
34 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
35 recent_effective_connection_type_set_(false),
36 recent_effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
37 current_network_type_(NetworkChangeNotifier::CONNECTION_UNKNOWN), 33 current_network_type_(NetworkChangeNotifier::CONNECTION_UNKNOWN),
38 accuracy_recording_intervals_set_(false), 34 accuracy_recording_intervals_set_(false),
39 http_rtt_set_(false),
40 recent_http_rtt_set_(false),
41 transport_rtt_set_(false),
42 recent_transport_rtt_set_(false),
43 downlink_throughput_kbps_set_(false),
44 recent_downlink_throughput_kbps_set_(false),
45 rand_double_(0.0) { 35 rand_double_(0.0) {
46 // Set up the embedded test server. 36 // Set up the embedded test server.
47 embedded_test_server_.ServeFilesFromDirectory( 37 embedded_test_server_.ServeFilesFromDirectory(
48 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 38 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
49 embedded_test_server_.RegisterRequestHandler(base::Bind( 39 embedded_test_server_.RegisterRequestHandler(base::Bind(
50 &TestNetworkQualityEstimator::HandleRequest, base::Unretained(this))); 40 &TestNetworkQualityEstimator::HandleRequest, base::Unretained(this)));
51 EXPECT_TRUE(embedded_test_server_.Start()); 41 EXPECT_TRUE(embedded_test_server_.Start());
52 } 42 }
53 43
54 TestNetworkQualityEstimator::TestNetworkQualityEstimator( 44 TestNetworkQualityEstimator::TestNetworkQualityEstimator(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 http_response->set_content_type("text/plain"); 79 http_response->set_content_type("text/plain");
90 return std::move(http_response); 80 return std::move(http_response);
91 } 81 }
92 82
93 const GURL TestNetworkQualityEstimator::GetEchoURL() const { 83 const GURL TestNetworkQualityEstimator::GetEchoURL() const {
94 return embedded_test_server_.GetURL("/echo.html"); 84 return embedded_test_server_.GetURL("/echo.html");
95 } 85 }
96 86
97 EffectiveConnectionType 87 EffectiveConnectionType
98 TestNetworkQualityEstimator::GetEffectiveConnectionType() const { 88 TestNetworkQualityEstimator::GetEffectiveConnectionType() const {
99 if (effective_connection_type_set_) 89 if (effective_connection_type_)
100 return effective_connection_type_; 90 return effective_connection_type_.value();
101 return NetworkQualityEstimator::GetEffectiveConnectionType(); 91 return NetworkQualityEstimator::GetEffectiveConnectionType();
102 } 92 }
103 93
104 EffectiveConnectionType 94 EffectiveConnectionType
105 TestNetworkQualityEstimator::GetRecentEffectiveConnectionType( 95 TestNetworkQualityEstimator::GetRecentEffectiveConnectionType(
106 const base::TimeTicks& start_time) const { 96 const base::TimeTicks& start_time) const {
107 if (recent_effective_connection_type_set_) 97 if (recent_effective_connection_type_)
108 return recent_effective_connection_type_; 98 return recent_effective_connection_type_.value();
109 return NetworkQualityEstimator::GetRecentEffectiveConnectionType(start_time); 99 return NetworkQualityEstimator::GetRecentEffectiveConnectionType(start_time);
110 } 100 }
111 101
112 EffectiveConnectionType 102 EffectiveConnectionType
113 TestNetworkQualityEstimator::GetRecentEffectiveConnectionTypeAndNetworkQuality( 103 TestNetworkQualityEstimator::GetRecentEffectiveConnectionTypeAndNetworkQuality(
114 const base::TimeTicks& start_time, 104 const base::TimeTicks& start_time,
115 base::TimeDelta* http_rtt, 105 base::TimeDelta* http_rtt,
116 base::TimeDelta* transport_rtt, 106 base::TimeDelta* transport_rtt,
117 int32_t* downstream_throughput_kbps) const { 107 int32_t* downstream_throughput_kbps) const {
118 if (recent_effective_connection_type_set_) { 108 if (recent_effective_connection_type_) {
119 *http_rtt = recent_http_rtt_; 109 GetRecentHttpRTT(start_time, http_rtt);
120 *transport_rtt = recent_transport_rtt_; 110 GetRecentTransportRTT(start_time, transport_rtt);
121 *downstream_throughput_kbps = recent_downlink_throughput_kbps_; 111 GetRecentDownlinkThroughputKbps(start_time, downstream_throughput_kbps);
122 return recent_effective_connection_type_; 112 return recent_effective_connection_type_.value();
123 } 113 }
124 return NetworkQualityEstimator:: 114 return NetworkQualityEstimator::
125 GetRecentEffectiveConnectionTypeAndNetworkQuality( 115 GetRecentEffectiveConnectionTypeAndNetworkQuality(
126 start_time, http_rtt, transport_rtt, downstream_throughput_kbps); 116 start_time, http_rtt, transport_rtt, downstream_throughput_kbps);
127 } 117 }
128 118
129 bool TestNetworkQualityEstimator::GetHttpRTT(base::TimeDelta* rtt) const {
130 if (http_rtt_set_) {
131 *rtt = http_rtt_;
132 return true;
133 }
134 return NetworkQualityEstimator::GetHttpRTT(rtt);
135 }
136
137 bool TestNetworkQualityEstimator::GetRecentHttpRTT( 119 bool TestNetworkQualityEstimator::GetRecentHttpRTT(
138 const base::TimeTicks& start_time, 120 const base::TimeTicks& start_time,
139 base::TimeDelta* rtt) const { 121 base::TimeDelta* rtt) const {
140 if (recent_http_rtt_set_) { 122 if (start_time.is_null()) {
141 *rtt = recent_http_rtt_; 123 if (start_time_null_http_rtt_) {
124 *rtt = start_time_null_http_rtt_.value();
125 return true;
126 }
127 return NetworkQualityEstimator::GetRecentHttpRTT(start_time, rtt);
128 }
129 if (recent_http_rtt_) {
130 *rtt = recent_http_rtt_.value();
142 return true; 131 return true;
143 } 132 }
144 return NetworkQualityEstimator::GetRecentHttpRTT(start_time, rtt); 133 return NetworkQualityEstimator::GetRecentHttpRTT(start_time, rtt);
145 } 134 }
146 135
147 bool TestNetworkQualityEstimator::GetTransportRTT(base::TimeDelta* rtt) const {
148 if (transport_rtt_set_) {
149 *rtt = transport_rtt_;
150 return true;
151 }
152 return NetworkQualityEstimator::GetTransportRTT(rtt);
153 }
154
155 bool TestNetworkQualityEstimator::GetRecentTransportRTT( 136 bool TestNetworkQualityEstimator::GetRecentTransportRTT(
156 const base::TimeTicks& start_time, 137 const base::TimeTicks& start_time,
157 base::TimeDelta* rtt) const { 138 base::TimeDelta* rtt) const {
158 if (recent_transport_rtt_set_) { 139 if (start_time.is_null()) {
159 *rtt = recent_transport_rtt_; 140 if (start_time_null_transport_rtt_) {
141 *rtt = start_time_null_transport_rtt_.value();
142 return true;
143 }
144 return NetworkQualityEstimator::GetRecentTransportRTT(start_time, rtt);
145 }
146
147 if (recent_transport_rtt_) {
148 *rtt = recent_transport_rtt_.value();
160 return true; 149 return true;
161 } 150 }
162 return NetworkQualityEstimator::GetRecentTransportRTT(start_time, rtt); 151 return NetworkQualityEstimator::GetRecentTransportRTT(start_time, rtt);
163 } 152 }
164 153
165 bool TestNetworkQualityEstimator::GetDownlinkThroughputKbps(
166 int32_t* kbps) const {
167 if (downlink_throughput_kbps_set_) {
168 *kbps = downlink_throughput_kbps_;
169 return true;
170 }
171 return NetworkQualityEstimator::GetDownlinkThroughputKbps(kbps);
172 }
173
174 bool TestNetworkQualityEstimator::GetRecentDownlinkThroughputKbps( 154 bool TestNetworkQualityEstimator::GetRecentDownlinkThroughputKbps(
175 const base::TimeTicks& start_time, 155 const base::TimeTicks& start_time,
176 int32_t* kbps) const { 156 int32_t* kbps) const {
177 if (recent_downlink_throughput_kbps_set_) { 157 if (start_time.is_null()) {
178 *kbps = recent_downlink_throughput_kbps_; 158 if (start_time_null_downlink_throughput_kbps_) {
159 *kbps = start_time_null_downlink_throughput_kbps_.value();
160 return true;
161 }
162 return NetworkQualityEstimator::GetRecentDownlinkThroughputKbps(start_time,
163 kbps);
164 }
165
166 if (recent_downlink_throughput_kbps_) {
167 *kbps = recent_downlink_throughput_kbps_.value();
179 return true; 168 return true;
180 } 169 }
181 return NetworkQualityEstimator::GetRecentDownlinkThroughputKbps(start_time, 170 return NetworkQualityEstimator::GetRecentDownlinkThroughputKbps(start_time,
182 kbps); 171 kbps);
183 } 172 }
184 173
185 void TestNetworkQualityEstimator::SetAccuracyRecordingIntervals( 174 void TestNetworkQualityEstimator::SetAccuracyRecordingIntervals(
186 const std::vector<base::TimeDelta>& accuracy_recording_intervals) { 175 const std::vector<base::TimeDelta>& accuracy_recording_intervals) {
187 accuracy_recording_intervals_set_ = true; 176 accuracy_recording_intervals_set_ = true;
188 accuracy_recording_intervals_ = accuracy_recording_intervals; 177 accuracy_recording_intervals_ = accuracy_recording_intervals;
(...skipping 10 matching lines...) Expand all
199 double TestNetworkQualityEstimator::RandDouble() const { 188 double TestNetworkQualityEstimator::RandDouble() const {
200 return rand_double_; 189 return rand_double_;
201 } 190 }
202 191
203 nqe::internal::NetworkID TestNetworkQualityEstimator::GetCurrentNetworkID() 192 nqe::internal::NetworkID TestNetworkQualityEstimator::GetCurrentNetworkID()
204 const { 193 const {
205 return nqe::internal::NetworkID(current_network_type_, current_network_id_); 194 return nqe::internal::NetworkID(current_network_type_, current_network_id_);
206 } 195 }
207 196
208 } // namespace net 197 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator_test_util.h ('k') | net/nqe/network_quality_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698