| OLD | NEW |
| 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/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/optional.h" | 15 #include "base/optional.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "net/base/network_change_notifier.h" | 17 #include "net/base/network_change_notifier.h" |
| 17 #include "net/nqe/effective_connection_type.h" | 18 #include "net/nqe/effective_connection_type.h" |
| 18 #include "net/nqe/network_quality_estimator.h" | 19 #include "net/nqe/network_quality_estimator.h" |
| 19 #include "net/test/embedded_test_server/embedded_test_server.h" | 20 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 50 | 51 |
| 51 // Runs one URL request to completion. | 52 // Runs one URL request to completion. |
| 52 void RunOneRequest(); | 53 void RunOneRequest(); |
| 53 | 54 |
| 54 // Overrides the current network type and id. | 55 // Overrides the current network type and id. |
| 55 // Notifies network quality estimator of a change in connection. | 56 // Notifies network quality estimator of a change in connection. |
| 56 void SimulateNetworkChange( | 57 void SimulateNetworkChange( |
| 57 NetworkChangeNotifier::ConnectionType new_connection_type, | 58 NetworkChangeNotifier::ConnectionType new_connection_type, |
| 58 const std::string& network_id); | 59 const std::string& network_id); |
| 59 | 60 |
| 60 // Called by the embedded server when an HTTP request is received. | |
| 61 std::unique_ptr<test_server::HttpResponse> HandleRequest( | |
| 62 const test_server::HttpRequest& request); | |
| 63 | |
| 64 // Returns a GURL hosted at the embedded test server. | 61 // Returns a GURL hosted at the embedded test server. |
| 65 const GURL GetEchoURL() const; | 62 const GURL GetEchoURL() const; |
| 66 | 63 |
| 64 // Returns a GURL hosted at the embedded test server which contains redirect |
| 65 // to another HTTPS URL. |
| 66 const GURL GetRedirectURL() const; |
| 67 |
| 67 void set_effective_connection_type(EffectiveConnectionType type) { | 68 void set_effective_connection_type(EffectiveConnectionType type) { |
| 68 // Callers should not set effective connection type along with the | 69 // Callers should not set effective connection type along with the |
| 69 // lower-layer metrics. | 70 // lower-layer metrics. |
| 70 DCHECK(!start_time_null_http_rtt_ && !recent_http_rtt_ && | 71 DCHECK(!start_time_null_http_rtt_ && !recent_http_rtt_ && |
| 71 !start_time_null_transport_rtt_ && !recent_transport_rtt_ && | 72 !start_time_null_transport_rtt_ && !recent_transport_rtt_ && |
| 72 !start_time_null_downlink_throughput_kbps_ && | 73 !start_time_null_downlink_throughput_kbps_ && |
| 73 !recent_downlink_throughput_kbps_); | 74 !recent_downlink_throughput_kbps_); |
| 74 effective_connection_type_ = type; | 75 effective_connection_type_ = type; |
| 75 } | 76 } |
| 76 | 77 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 const override; | 174 const override; |
| 174 | 175 |
| 175 void set_rand_double(double rand_double) { rand_double_ = rand_double; } | 176 void set_rand_double(double rand_double) { rand_double_ = rand_double; } |
| 176 | 177 |
| 177 double RandDouble() const override; | 178 double RandDouble() const override; |
| 178 | 179 |
| 179 using NetworkQualityEstimator::SetTickClockForTesting; | 180 using NetworkQualityEstimator::SetTickClockForTesting; |
| 180 using NetworkQualityEstimator::OnConnectionTypeChanged; | 181 using NetworkQualityEstimator::OnConnectionTypeChanged; |
| 181 | 182 |
| 182 private: | 183 private: |
| 184 class LocalHttpTestServer : public EmbeddedTestServer { |
| 185 public: |
| 186 explicit LocalHttpTestServer(const base::FilePath& document_root); |
| 187 }; |
| 188 |
| 183 // NetworkQualityEstimator implementation that returns the overridden | 189 // NetworkQualityEstimator implementation that returns the overridden |
| 184 // network | 190 // network |
| 185 // id (instead of invoking platform APIs). | 191 // id (instead of invoking platform APIs). |
| 186 nqe::internal::NetworkID GetCurrentNetworkID() const override; | 192 nqe::internal::NetworkID GetCurrentNetworkID() const override; |
| 187 | 193 |
| 188 // If set, GetEffectiveConnectionType() and GetRecentEffectiveConnectionType() | 194 // If set, GetEffectiveConnectionType() and GetRecentEffectiveConnectionType() |
| 189 // would return the set values, respectively. | 195 // would return the set values, respectively. |
| 190 base::Optional<EffectiveConnectionType> effective_connection_type_; | 196 base::Optional<EffectiveConnectionType> effective_connection_type_; |
| 191 base::Optional<EffectiveConnectionType> recent_effective_connection_type_; | 197 base::Optional<EffectiveConnectionType> recent_effective_connection_type_; |
| 192 | 198 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 210 | 216 |
| 211 // If set, GetRecentDownlinkThroughputKbps() would return one of the set | 217 // If set, GetRecentDownlinkThroughputKbps() would return one of the set |
| 212 // values. |start_time_null_downlink_throughput_kbps_| is returned if the | 218 // values. |start_time_null_downlink_throughput_kbps_| is returned if the |
| 213 // |start_time| is null. Otherwise, |recent_downlink_throughput_kbps_| is | 219 // |start_time| is null. Otherwise, |recent_downlink_throughput_kbps_| is |
| 214 // returned. | 220 // returned. |
| 215 base::Optional<int32_t> start_time_null_downlink_throughput_kbps_; | 221 base::Optional<int32_t> start_time_null_downlink_throughput_kbps_; |
| 216 base::Optional<int32_t> recent_downlink_throughput_kbps_; | 222 base::Optional<int32_t> recent_downlink_throughput_kbps_; |
| 217 | 223 |
| 218 double rand_double_; | 224 double rand_double_; |
| 219 | 225 |
| 220 EmbeddedTestServer embedded_test_server_; | 226 LocalHttpTestServer embedded_test_server_; |
| 221 | 227 |
| 222 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); | 228 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); |
| 223 }; | 229 }; |
| 224 | 230 |
| 225 } // namespace net | 231 } // namespace net |
| 226 | 232 |
| 227 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_TEST_UTIL_H_ | 233 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_TEST_UTIL_H_ |
| OLD | NEW |