| 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/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/nqe/effective_connection_type.h" | 19 #include "net/nqe/effective_connection_type.h" |
| 19 #include "net/nqe/network_quality_estimator.h" | 20 #include "net/nqe/network_quality_estimator.h" |
| 20 #include "net/test/embedded_test_server/embedded_test_server.h" | 21 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| 25 | 26 |
| 27 class BoundTestNetLog; |
| 26 class ExternalEstimateProvider; | 28 class ExternalEstimateProvider; |
| 27 | 29 |
| 28 // Helps in setting the current network type and id. | 30 // Helps in setting the current network type and id. |
| 29 class TestNetworkQualityEstimator : public NetworkQualityEstimator { | 31 class TestNetworkQualityEstimator : public NetworkQualityEstimator { |
| 30 public: | 32 public: |
| 31 TestNetworkQualityEstimator(); | 33 TestNetworkQualityEstimator(); |
| 32 | 34 |
| 33 explicit TestNetworkQualityEstimator( | 35 explicit TestNetworkQualityEstimator( |
| 34 const std::map<std::string, std::string>& variation_params); | 36 const std::map<std::string, std::string>& variation_params); |
| 35 | 37 |
| 36 TestNetworkQualityEstimator( | 38 TestNetworkQualityEstimator( |
| 37 const std::map<std::string, std::string>& variation_params, | 39 const std::map<std::string, std::string>& variation_params, |
| 38 std::unique_ptr<net::ExternalEstimateProvider> | 40 std::unique_ptr<net::ExternalEstimateProvider> |
| 39 external_estimate_provider); | 41 external_estimate_provider); |
| 40 | 42 |
| 41 TestNetworkQualityEstimator( | 43 TestNetworkQualityEstimator( |
| 42 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider, | 44 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider, |
| 43 const std::map<std::string, std::string>& variation_params, | 45 const std::map<std::string, std::string>& variation_params, |
| 44 bool allow_local_host_requests_for_tests, | 46 bool allow_local_host_requests_for_tests, |
| 45 bool allow_smaller_responses_for_tests, | 47 bool allow_smaller_responses_for_tests, |
| 46 bool add_default_platform_observations); | 48 bool add_default_platform_observations, |
| 49 std::unique_ptr<BoundTestNetLog> net_log); |
| 47 | 50 |
| 48 ~TestNetworkQualityEstimator() override; | 51 ~TestNetworkQualityEstimator() override; |
| 49 | 52 |
| 50 // Runs one URL request to completion. | 53 // Runs one URL request to completion. |
| 51 void RunOneRequest(); | 54 void RunOneRequest(); |
| 52 | 55 |
| 53 // Overrides the current network type and id. | 56 // Overrides the current network type and id. |
| 54 // Notifies network quality estimator of a change in connection. | 57 // Notifies network quality estimator of a change in connection. |
| 55 void SimulateNetworkChange( | 58 void SimulateNetworkChange( |
| 56 NetworkChangeNotifier::ConnectionType new_connection_type, | 59 NetworkChangeNotifier::ConnectionType new_connection_type, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 void SetAccuracyRecordingIntervals( | 171 void SetAccuracyRecordingIntervals( |
| 169 const std::vector<base::TimeDelta>& accuracy_recording_intervals); | 172 const std::vector<base::TimeDelta>& accuracy_recording_intervals); |
| 170 | 173 |
| 171 const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals() | 174 const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals() |
| 172 const override; | 175 const override; |
| 173 | 176 |
| 174 void set_rand_double(double rand_double) { rand_double_ = rand_double; } | 177 void set_rand_double(double rand_double) { rand_double_ = rand_double; } |
| 175 | 178 |
| 176 double RandDouble() const override; | 179 double RandDouble() const override; |
| 177 | 180 |
| 181 // Returns the number of entries in |net_log_| that have type set to |type|. |
| 182 int GetEntriesCount(NetLogEventType type) const; |
| 183 |
| 178 using NetworkQualityEstimator::SetTickClockForTesting; | 184 using NetworkQualityEstimator::SetTickClockForTesting; |
| 179 using NetworkQualityEstimator::OnConnectionTypeChanged; | 185 using NetworkQualityEstimator::OnConnectionTypeChanged; |
| 180 | 186 |
| 181 private: | 187 private: |
| 182 class LocalHttpTestServer : public EmbeddedTestServer { | 188 class LocalHttpTestServer : public EmbeddedTestServer { |
| 183 public: | 189 public: |
| 184 explicit LocalHttpTestServer(const base::FilePath& document_root); | 190 explicit LocalHttpTestServer(const base::FilePath& document_root); |
| 185 }; | 191 }; |
| 186 | 192 |
| 187 // NetworkQualityEstimator implementation that returns the overridden | 193 // NetworkQualityEstimator implementation that returns the overridden |
| (...skipping 28 matching lines...) Expand all Loading... |
| 216 // values. |start_time_null_downlink_throughput_kbps_| is returned if the | 222 // values. |start_time_null_downlink_throughput_kbps_| is returned if the |
| 217 // |start_time| is null. Otherwise, |recent_downlink_throughput_kbps_| is | 223 // |start_time| is null. Otherwise, |recent_downlink_throughput_kbps_| is |
| 218 // returned. | 224 // returned. |
| 219 base::Optional<int32_t> start_time_null_downlink_throughput_kbps_; | 225 base::Optional<int32_t> start_time_null_downlink_throughput_kbps_; |
| 220 base::Optional<int32_t> recent_downlink_throughput_kbps_; | 226 base::Optional<int32_t> recent_downlink_throughput_kbps_; |
| 221 | 227 |
| 222 double rand_double_; | 228 double rand_double_; |
| 223 | 229 |
| 224 LocalHttpTestServer embedded_test_server_; | 230 LocalHttpTestServer embedded_test_server_; |
| 225 | 231 |
| 232 // Net log provided to network quality estimator. |
| 233 std::unique_ptr<net::BoundTestNetLog> net_log_; |
| 234 |
| 226 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); | 235 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); |
| 227 }; | 236 }; |
| 228 | 237 |
| 229 } // namespace net | 238 } // namespace net |
| 230 | 239 |
| 231 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_TEST_UTIL_H_ | 240 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_TEST_UTIL_H_ |
| OLD | NEW |