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

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

Issue 2863973003: Expose RTT and downlink bandwidth using experimental Javascript API (Closed)
Patch Set: kinuko comments Created 3 years, 7 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 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/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/optional.h" 15 #include "base/optional.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "net/base/network_change_notifier.h" 17 #include "net/base/network_change_notifier.h"
18 #include "net/log/net_log.h" 18 #include "net/log/net_log.h"
19 #include "net/log/test_net_log.h"
19 #include "net/nqe/effective_connection_type.h" 20 #include "net/nqe/effective_connection_type.h"
20 #include "net/nqe/network_quality_estimator.h" 21 #include "net/nqe/network_quality_estimator.h"
21 #include "net/test/embedded_test_server/embedded_test_server.h" 22 #include "net/test/embedded_test_server/embedded_test_server.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 25
25 namespace net { 26 namespace net {
26 27
27 class BoundTestNetLog;
28 class ExternalEstimateProvider; 28 class ExternalEstimateProvider;
29 29
30 // Helps in setting the current network type and id. 30 // Helps in setting the current network type and id.
31 class TestNetworkQualityEstimator : public NetworkQualityEstimator { 31 class TestNetworkQualityEstimator : public NetworkQualityEstimator {
32 public: 32 public:
33 TestNetworkQualityEstimator(); 33 TestNetworkQualityEstimator();
34 34
35 explicit TestNetworkQualityEstimator( 35 explicit TestNetworkQualityEstimator(
36 const std::map<std::string, std::string>& variation_params); 36 const std::map<std::string, std::string>& variation_params);
37 37
38 TestNetworkQualityEstimator( 38 TestNetworkQualityEstimator(
39 const std::map<std::string, std::string>& variation_params, 39 const std::map<std::string, std::string>& variation_params,
40 std::unique_ptr<net::ExternalEstimateProvider> 40 std::unique_ptr<net::ExternalEstimateProvider>
41 external_estimate_provider); 41 external_estimate_provider);
42 42
43 TestNetworkQualityEstimator( 43 TestNetworkQualityEstimator(
44 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider, 44 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider,
45 const std::map<std::string, std::string>& variation_params, 45 const std::map<std::string, std::string>& variation_params,
46 bool allow_local_host_requests_for_tests, 46 bool allow_local_host_requests_for_tests,
47 bool allow_smaller_responses_for_tests, 47 bool allow_smaller_responses_for_tests,
48 bool add_default_platform_observations, 48 bool add_default_platform_observations,
49 std::unique_ptr<BoundTestNetLog> net_log); 49 std::unique_ptr<BoundTestNetLog> net_log);
50 50
51 TestNetworkQualityEstimator(
52 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider,
53 const std::map<std::string, std::string>& variation_params,
54 bool allow_local_host_requests_for_tests,
55 bool allow_smaller_responses_for_tests,
56 bool add_default_platform_observations,
57 bool suppress_notifications_for_testing,
dcheng 2017/05/17 12:27:46 FWIW, this is a lot of bools. I guess it's just ex
tbansal1 2017/05/18 00:10:29 Agreed. I will fix it, but I will prefer to do tha
58 std::unique_ptr<BoundTestNetLog> net_log);
59
51 ~TestNetworkQualityEstimator() override; 60 ~TestNetworkQualityEstimator() override;
52 61
53 // Runs one URL request to completion. 62 // Runs one URL request to completion.
54 void RunOneRequest(); 63 void RunOneRequest();
55 64
56 // Overrides the current network type and id. 65 // Overrides the current network type and id.
57 // Notifies network quality estimator of a change in connection. 66 // Notifies network quality estimator of a change in connection.
58 void SimulateNetworkChange( 67 void SimulateNetworkChange(
59 NetworkChangeNotifier::ConnectionType new_connection_type, 68 NetworkChangeNotifier::ConnectionType new_connection_type,
60 const std::string& network_id); 69 const std::string& network_id);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // then the base implementation is called. |http_rtt|, |transport_rtt| and 111 // then the base implementation is called. |http_rtt|, |transport_rtt| and
103 // |downstream_throughput_kbps| are set to the values that were previously 112 // |downstream_throughput_kbps| are set to the values that were previously
104 // set by calling set_recent_http_rtt(), set_recent_transport_rtt() 113 // set by calling set_recent_http_rtt(), set_recent_transport_rtt()
105 // and set_recent_transport_rtt() methods, respectively. 114 // and set_recent_transport_rtt() methods, respectively.
106 EffectiveConnectionType GetRecentEffectiveConnectionTypeAndNetworkQuality( 115 EffectiveConnectionType GetRecentEffectiveConnectionTypeAndNetworkQuality(
107 const base::TimeTicks& start_time, 116 const base::TimeTicks& start_time,
108 base::TimeDelta* http_rtt, 117 base::TimeDelta* http_rtt,
109 base::TimeDelta* transport_rtt, 118 base::TimeDelta* transport_rtt,
110 int32_t* downstream_throughput_kbps) const override; 119 int32_t* downstream_throughput_kbps) const override;
111 120
121 void NotifyObserversOfRTTOrThroughputComputed() const override;
122
123 void NotifyRTTAndThroughputEstimatesObserverIfPresent(
124 RTTAndThroughputEstimatesObserver* observer) const override;
125
112 void set_start_time_null_http_rtt(const base::TimeDelta& http_rtt) { 126 void set_start_time_null_http_rtt(const base::TimeDelta& http_rtt) {
113 // Callers should not set effective connection type along with the 127 // Callers should not set effective connection type along with the
114 // lower-layer metrics. 128 // lower-layer metrics.
115 DCHECK(!effective_connection_type_ && !recent_effective_connection_type_); 129 DCHECK(!effective_connection_type_ && !recent_effective_connection_type_);
116 start_time_null_http_rtt_ = http_rtt; 130 start_time_null_http_rtt_ = http_rtt;
117 } 131 }
118 132
119 void set_recent_http_rtt(const base::TimeDelta& recent_http_rtt) { 133 void set_recent_http_rtt(const base::TimeDelta& recent_http_rtt) {
120 // Callers should not set effective connection type along with the 134 // Callers should not set effective connection type along with the
121 // lower-layer metrics. 135 // lower-layer metrics.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 base::Optional<int32_t> start_time_null_downlink_throughput_kbps_; 267 base::Optional<int32_t> start_time_null_downlink_throughput_kbps_;
254 base::Optional<int32_t> recent_downlink_throughput_kbps_; 268 base::Optional<int32_t> recent_downlink_throughput_kbps_;
255 269
256 // If set, GetRTTEstimateInternal() would return the set value. 270 // If set, GetRTTEstimateInternal() would return the set value.
257 base::Optional<base::TimeDelta> rtt_estimate_internal_; 271 base::Optional<base::TimeDelta> rtt_estimate_internal_;
258 272
259 double rand_double_; 273 double rand_double_;
260 274
261 LocalHttpTestServer embedded_test_server_; 275 LocalHttpTestServer embedded_test_server_;
262 276
277 // If true, notifications are not sent to any of the observers.
278 const bool suppress_notifications_for_testing_;
279
263 // Net log provided to network quality estimator. 280 // Net log provided to network quality estimator.
264 std::unique_ptr<net::BoundTestNetLog> net_log_; 281 std::unique_ptr<net::BoundTestNetLog> net_log_;
265 282
266 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); 283 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator);
267 }; 284 };
268 285
269 } // namespace net 286 } // namespace net
270 287
271 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_TEST_UTIL_H_ 288 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698