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

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

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
« no previous file with comments | « net/nqe/network_quality_estimator.cc ('k') | net/nqe/network_quality_estimator_test_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef NET_NQE_NETWORK_QUALITY_ESTIMATOR_TEST_UTIL_H_ 5 #ifndef NET_NQE_NETWORK_QUALITY_ESTIMATOR_TEST_UTIL_H_
6 #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_TEST_UTIL_H_ 6 #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_TEST_UTIL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/optional.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "net/base/network_change_notifier.h" 16 #include "net/base/network_change_notifier.h"
16 #include "net/nqe/effective_connection_type.h" 17 #include "net/nqe/effective_connection_type.h"
17 #include "net/nqe/network_quality_estimator.h" 18 #include "net/nqe/network_quality_estimator.h"
18 #include "net/test/embedded_test_server/embedded_test_server.h" 19 #include "net/test/embedded_test_server/embedded_test_server.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 namespace net { 23 namespace net {
23 24
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 const std::string& network_id); 58 const std::string& network_id);
58 59
59 // Called by the embedded server when an HTTP request is received. 60 // Called by the embedded server when an HTTP request is received.
60 std::unique_ptr<test_server::HttpResponse> HandleRequest( 61 std::unique_ptr<test_server::HttpResponse> HandleRequest(
61 const test_server::HttpRequest& request); 62 const test_server::HttpRequest& request);
62 63
63 // Returns a GURL hosted at the embedded test server. 64 // Returns a GURL hosted at the embedded test server.
64 const GURL GetEchoURL() const; 65 const GURL GetEchoURL() const;
65 66
66 void set_effective_connection_type(EffectiveConnectionType type) { 67 void set_effective_connection_type(EffectiveConnectionType type) {
67 effective_connection_type_set_ = true; 68 // Callers should not set effective connection type along with the
69 // lower-layer metrics.
70 DCHECK(!start_time_null_http_rtt_ && !recent_http_rtt_ &&
71 !start_time_null_transport_rtt_ && !recent_transport_rtt_ &&
72 !start_time_null_downlink_throughput_kbps_ &&
73 !recent_downlink_throughput_kbps_);
68 effective_connection_type_ = type; 74 effective_connection_type_ = type;
69 } 75 }
70 76
71 // Returns the effective connection type that was set using 77 // Returns the effective connection type that was set using
72 // |set_effective_connection_type|. If the connection type has not been set, 78 // |set_effective_connection_type|. If the connection type has not been set,
73 // then the base implementation is called. 79 // then the base implementation is called.
74 EffectiveConnectionType GetEffectiveConnectionType() const override; 80 EffectiveConnectionType GetEffectiveConnectionType() const override;
75 81
76 void set_recent_effective_connection_type(EffectiveConnectionType type) { 82 void set_recent_effective_connection_type(EffectiveConnectionType type) {
77 recent_effective_connection_type_set_ = true; 83 // Callers should not set effective connection type along with the
84 // lower-layer metrics.
85 DCHECK(!start_time_null_http_rtt_ && !recent_http_rtt_ &&
86 !start_time_null_transport_rtt_ && !recent_transport_rtt_ &&
87 !start_time_null_downlink_throughput_kbps_ &&
88 !recent_downlink_throughput_kbps_);
78 recent_effective_connection_type_ = type; 89 recent_effective_connection_type_ = type;
79 } 90 }
80 91
81 // Returns the effective connection type that was set using 92 // Returns the effective connection type that was set using
82 // |set_effective_connection_type|. If the connection type has not been set, 93 // |set_effective_connection_type|. If the connection type has not been set,
83 // then the base implementation is called. 94 // then the base implementation is called.
84 EffectiveConnectionType GetRecentEffectiveConnectionType( 95 EffectiveConnectionType GetRecentEffectiveConnectionType(
85 const base::TimeTicks& start_time) const override; 96 const base::TimeTicks& start_time) const override;
86 97
87 // Returns the effective connection type that was set using 98 // Returns the effective connection type that was set using
88 // |set_effective_connection_type|. If the connection type has not been set, 99 // |set_effective_connection_type|. If the connection type has not been set,
89 // then the base implementation is called. |http_rtt|, |transport_rtt| and 100 // then the base implementation is called. |http_rtt|, |transport_rtt| and
90 // |downstream_throughput_kbps| are set to the values that were previously 101 // |downstream_throughput_kbps| are set to the values that were previously
91 // set by calling set_recent_http_rtt(), set_recent_transport_rtt() 102 // set by calling set_recent_http_rtt(), set_recent_transport_rtt()
92 // and set_recent_transport_rtt() methods, respectively. 103 // and set_recent_transport_rtt() methods, respectively.
93 EffectiveConnectionType GetRecentEffectiveConnectionTypeAndNetworkQuality( 104 EffectiveConnectionType GetRecentEffectiveConnectionTypeAndNetworkQuality(
94 const base::TimeTicks& start_time, 105 const base::TimeTicks& start_time,
95 base::TimeDelta* http_rtt, 106 base::TimeDelta* http_rtt,
96 base::TimeDelta* transport_rtt, 107 base::TimeDelta* transport_rtt,
97 int32_t* downstream_throughput_kbps) const override; 108 int32_t* downstream_throughput_kbps) const override;
98 109
99 void set_http_rtt(const base::TimeDelta& http_rtt) { 110 void set_start_time_null_http_rtt(const base::TimeDelta& http_rtt) {
100 http_rtt_set_ = true; 111 // Callers should not set effective connection type along with the
101 http_rtt_ = http_rtt; 112 // lower-layer metrics.
113 DCHECK(!effective_connection_type_ && !recent_effective_connection_type_);
114 start_time_null_http_rtt_ = http_rtt;
102 } 115 }
103 // Returns the HTTP RTT that was set using |set_http_rtt|. If the HTTP RTT has
104 // not been set, then the base implementation is called.
105 bool GetHttpRTT(base::TimeDelta* rtt) const override;
106 116
107 void set_recent_http_rtt(const base::TimeDelta& recent_http_rtt) { 117 void set_recent_http_rtt(const base::TimeDelta& recent_http_rtt) {
108 recent_http_rtt_set_ = true; 118 // Callers should not set effective connection type along with the
119 // lower-layer metrics.
120 DCHECK(!effective_connection_type_ && !recent_effective_connection_type_);
109 recent_http_rtt_ = recent_http_rtt; 121 recent_http_rtt_ = recent_http_rtt;
110 } 122 }
111 // Returns the recent HTTP RTT that was set using |set_recent_http_rtt|. If 123 // Returns the recent HTTP RTT that was set using |set_recent_http_rtt|. If
112 // the recent HTTP RTT has not been set, then the base implementation is 124 // the recent HTTP RTT has not been set, then the base implementation is
113 // called. 125 // called.
114 bool GetRecentHttpRTT(const base::TimeTicks& start_time, 126 bool GetRecentHttpRTT(const base::TimeTicks& start_time,
115 base::TimeDelta* rtt) const override; 127 base::TimeDelta* rtt) const override;
116 128
117 void set_transport_rtt(const base::TimeDelta& transport_rtt) { 129 void set_start_time_null_transport_rtt(const base::TimeDelta& transport_rtt) {
118 transport_rtt_set_ = true; 130 // Callers should not set effective connection type along with the
119 transport_rtt_ = transport_rtt; 131 // lower-layer metrics.
132 DCHECK(!effective_connection_type_ && !recent_effective_connection_type_);
133 start_time_null_transport_rtt_ = transport_rtt;
120 } 134 }
121 // Returns the transport RTT that was set using |set_transport_rtt|. If the
122 // transport RTT has not been set, then the base implementation is called.
123 bool GetTransportRTT(base::TimeDelta* rtt) const override;
124 135
125 void set_recent_transport_rtt(const base::TimeDelta& recent_transport_rtt) { 136 void set_recent_transport_rtt(const base::TimeDelta& recent_transport_rtt) {
126 recent_transport_rtt_set_ = true; 137 // Callers should not set effective connection type along with the
138 // lower-layer metrics.
139 DCHECK(!effective_connection_type_ && !recent_effective_connection_type_);
127 recent_transport_rtt_ = recent_transport_rtt; 140 recent_transport_rtt_ = recent_transport_rtt;
128 } 141 }
129 // Returns the recent transport RTT that was set using 142 // Returns the recent transport RTT that was set using
130 // |set_recent_transport_rtt|. If the recent transport RTT has not been set, 143 // |set_recent_transport_rtt|. If the recent transport RTT has not been set,
131 // then the base implementation is called. 144 // then the base implementation is called.
132 bool GetRecentTransportRTT(const base::TimeTicks& start_time, 145 bool GetRecentTransportRTT(const base::TimeTicks& start_time,
133 base::TimeDelta* rtt) const override; 146 base::TimeDelta* rtt) const override;
134 147
135 void set_downlink_throughput_kbps(int32_t downlink_throughput_kbps) { 148 void set_start_time_null_downlink_throughput_kbps(
136 downlink_throughput_kbps_set_ = true; 149 int32_t downlink_throughput_kbps) {
137 downlink_throughput_kbps_ = downlink_throughput_kbps; 150 // Callers should not set effective connection type along with the
151 // lower-layer metrics.
152 DCHECK(!effective_connection_type_ && !recent_effective_connection_type_);
153 start_time_null_downlink_throughput_kbps_ = downlink_throughput_kbps;
138 } 154 }
139 // Returns the downlink throughput that was set using
140 // |set_downlink_throughput_kbps|. If the downlink throughput has not been
141 // set, then the base implementation is called.
142 bool GetDownlinkThroughputKbps(int32_t* kbps) const override;
143 155
144 void set_recent_downlink_throughput_kbps( 156 void set_recent_downlink_throughput_kbps(
145 int32_t recent_downlink_throughput_kbps) { 157 int32_t recent_downlink_throughput_kbps) {
146 recent_downlink_throughput_kbps_set_ = true; 158 // Callers should not set effective connection type along with the
159 // lower-layer metrics.
160 DCHECK(!effective_connection_type_ && !recent_effective_connection_type_);
147 recent_downlink_throughput_kbps_ = recent_downlink_throughput_kbps; 161 recent_downlink_throughput_kbps_ = recent_downlink_throughput_kbps;
148 } 162 }
149 // Returns the downlink throughput that was set using 163 // Returns the downlink throughput that was set using
150 // |set_recent_downlink_throughput_kbps|. If the downlink throughput has not 164 // |set_recent_downlink_throughput_kbps|. If the downlink throughput has not
151 // been set, then the base implementation is called. 165 // been set, then the base implementation is called.
152 bool GetRecentDownlinkThroughputKbps(const base::TimeTicks& start_time, 166 bool GetRecentDownlinkThroughputKbps(const base::TimeTicks& start_time,
153 int32_t* kbps) const override; 167 int32_t* kbps) const override;
154 168
155 void SetAccuracyRecordingIntervals( 169 void SetAccuracyRecordingIntervals(
156 const std::vector<base::TimeDelta>& accuracy_recording_intervals); 170 const std::vector<base::TimeDelta>& accuracy_recording_intervals);
157 171
158 const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals() 172 const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals()
159 const override; 173 const override;
160 174
161 void set_rand_double(double rand_double) { rand_double_ = rand_double; } 175 void set_rand_double(double rand_double) { rand_double_ = rand_double; }
162 176
163 double RandDouble() const override; 177 double RandDouble() const override;
164 178
165 using NetworkQualityEstimator::SetTickClockForTesting; 179 using NetworkQualityEstimator::SetTickClockForTesting;
166 using NetworkQualityEstimator::OnConnectionTypeChanged; 180 using NetworkQualityEstimator::OnConnectionTypeChanged;
167 181
168 private: 182 private:
169 // NetworkQualityEstimator implementation that returns the overridden 183 // NetworkQualityEstimator implementation that returns the overridden
170 // network 184 // network
171 // id (instead of invoking platform APIs). 185 // id (instead of invoking platform APIs).
172 nqe::internal::NetworkID GetCurrentNetworkID() const override; 186 nqe::internal::NetworkID GetCurrentNetworkID() const override;
173 187
174 bool effective_connection_type_set_; 188 // If set, GetEffectiveConnectionType() and GetRecentEffectiveConnectionType()
175 EffectiveConnectionType effective_connection_type_; 189 // would return the set values, respectively.
176 190 base::Optional<EffectiveConnectionType> effective_connection_type_;
177 bool recent_effective_connection_type_set_; 191 base::Optional<EffectiveConnectionType> recent_effective_connection_type_;
178 EffectiveConnectionType recent_effective_connection_type_;
179 192
180 NetworkChangeNotifier::ConnectionType current_network_type_; 193 NetworkChangeNotifier::ConnectionType current_network_type_;
181 std::string current_network_id_; 194 std::string current_network_id_;
182 195
183 bool accuracy_recording_intervals_set_; 196 bool accuracy_recording_intervals_set_;
184 std::vector<base::TimeDelta> accuracy_recording_intervals_; 197 std::vector<base::TimeDelta> accuracy_recording_intervals_;
185 198
186 bool http_rtt_set_; 199 // If set, GetRecentHttpRTT() would return one of the set values.
187 base::TimeDelta http_rtt_; 200 // |start_time_null_http_rtt_| is returned if the |start_time| is null.
201 // Otherwise, |recent_http_rtt_| is returned.
202 base::Optional<base::TimeDelta> start_time_null_http_rtt_;
203 base::Optional<base::TimeDelta> recent_http_rtt_;
188 204
189 bool recent_http_rtt_set_; 205 // If set, GetRecentTransportRTT() would return one of the set values.
190 base::TimeDelta recent_http_rtt_; 206 // |start_time_null_transport_rtt_| is returned if the |start_time| is null.
207 // Otherwise, |recent_transport_rtt_| is returned.
208 base::Optional<base::TimeDelta> start_time_null_transport_rtt_;
209 base::Optional<base::TimeDelta> recent_transport_rtt_;
191 210
192 bool transport_rtt_set_; 211 // If set, GetRecentDownlinkThroughputKbps() would return one of the set
193 base::TimeDelta transport_rtt_; 212 // values. |start_time_null_downlink_throughput_kbps_| is returned if the
194 213 // |start_time| is null. Otherwise, |recent_downlink_throughput_kbps_| is
195 bool recent_transport_rtt_set_; 214 // returned.
196 base::TimeDelta recent_transport_rtt_; 215 base::Optional<int32_t> start_time_null_downlink_throughput_kbps_;
197 216 base::Optional<int32_t> recent_downlink_throughput_kbps_;
198 bool downlink_throughput_kbps_set_;
199 int32_t downlink_throughput_kbps_;
200
201 bool recent_downlink_throughput_kbps_set_;
202 int32_t recent_downlink_throughput_kbps_;
203 217
204 double rand_double_; 218 double rand_double_;
205 219
206 EmbeddedTestServer embedded_test_server_; 220 EmbeddedTestServer embedded_test_server_;
207 221
208 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); 222 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator);
209 }; 223 };
210 224
211 } // namespace net 225 } // namespace net
212 226
213 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_TEST_UTIL_H_ 227 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.cc ('k') | net/nqe/network_quality_estimator_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698