| 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 #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" |
| 11 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
| 12 #include "net/url_request/url_request_test_util.h" | 12 #include "net/url_request/url_request_test_util.h" |
| 13 | 13 |
| 14 namespace { |
| 15 |
| 16 const base::FilePath::CharType kTestFilePath[] = |
| 17 FILE_PATH_LITERAL("net/data/url_request_unittest"); |
| 18 |
| 19 } // namespace |
| 20 |
| 14 namespace net { | 21 namespace net { |
| 15 | 22 |
| 16 TestNetworkQualityEstimator::TestNetworkQualityEstimator( | 23 TestNetworkQualityEstimator::TestNetworkQualityEstimator( |
| 17 const std::map<std::string, std::string>& variation_params, | 24 const std::map<std::string, std::string>& variation_params, |
| 18 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider) | 25 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider) |
| 19 : TestNetworkQualityEstimator(std::move(external_estimate_provider), | 26 : TestNetworkQualityEstimator(std::move(external_estimate_provider), |
| 20 variation_params, | 27 variation_params, |
| 21 true, | 28 true, |
| 22 true) {} | 29 true) {} |
| 23 | 30 |
| 24 TestNetworkQualityEstimator::TestNetworkQualityEstimator( | 31 TestNetworkQualityEstimator::TestNetworkQualityEstimator( |
| 25 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider, | 32 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider, |
| 26 const std::map<std::string, std::string>& variation_params, | 33 const std::map<std::string, std::string>& variation_params, |
| 27 bool allow_local_host_requests_for_tests, | 34 bool allow_local_host_requests_for_tests, |
| 28 bool allow_smaller_responses_for_tests) | 35 bool allow_smaller_responses_for_tests) |
| 29 : NetworkQualityEstimator(std::move(external_estimate_provider), | 36 : NetworkQualityEstimator(std::move(external_estimate_provider), |
| 30 variation_params, | 37 variation_params, |
| 31 allow_local_host_requests_for_tests, | 38 allow_local_host_requests_for_tests, |
| 32 allow_smaller_responses_for_tests), | 39 allow_smaller_responses_for_tests), |
| 33 current_network_type_(NetworkChangeNotifier::CONNECTION_UNKNOWN), | 40 current_network_type_(NetworkChangeNotifier::CONNECTION_UNKNOWN), |
| 34 accuracy_recording_intervals_set_(false), | 41 accuracy_recording_intervals_set_(false), |
| 35 rand_double_(0.0) { | 42 rand_double_(0.0), |
| 43 embedded_test_server_(base::FilePath(kTestFilePath)) { |
| 36 // Set up the embedded test server. | 44 // Set up the embedded test server. |
| 37 embedded_test_server_.ServeFilesFromDirectory( | |
| 38 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | |
| 39 embedded_test_server_.RegisterRequestHandler(base::Bind( | |
| 40 &TestNetworkQualityEstimator::HandleRequest, base::Unretained(this))); | |
| 41 EXPECT_TRUE(embedded_test_server_.Start()); | 45 EXPECT_TRUE(embedded_test_server_.Start()); |
| 42 } | 46 } |
| 43 | 47 |
| 44 TestNetworkQualityEstimator::TestNetworkQualityEstimator( | 48 TestNetworkQualityEstimator::TestNetworkQualityEstimator( |
| 45 const std::map<std::string, std::string>& variation_params) | 49 const std::map<std::string, std::string>& variation_params) |
| 46 : TestNetworkQualityEstimator(variation_params, | 50 : TestNetworkQualityEstimator(variation_params, |
| 47 std::unique_ptr<ExternalEstimateProvider>()) { | 51 std::unique_ptr<ExternalEstimateProvider>()) { |
| 48 } | 52 } |
| 49 | 53 |
| 50 TestNetworkQualityEstimator::~TestNetworkQualityEstimator() {} | 54 TestNetworkQualityEstimator::~TestNetworkQualityEstimator() {} |
| (...skipping 11 matching lines...) Expand all Loading... |
| 62 } | 66 } |
| 63 | 67 |
| 64 void TestNetworkQualityEstimator::SimulateNetworkChange( | 68 void TestNetworkQualityEstimator::SimulateNetworkChange( |
| 65 NetworkChangeNotifier::ConnectionType new_connection_type, | 69 NetworkChangeNotifier::ConnectionType new_connection_type, |
| 66 const std::string& network_id) { | 70 const std::string& network_id) { |
| 67 current_network_type_ = new_connection_type; | 71 current_network_type_ = new_connection_type; |
| 68 current_network_id_ = network_id; | 72 current_network_id_ = network_id; |
| 69 OnConnectionTypeChanged(new_connection_type); | 73 OnConnectionTypeChanged(new_connection_type); |
| 70 } | 74 } |
| 71 | 75 |
| 72 std::unique_ptr<test_server::HttpResponse> | 76 const GURL TestNetworkQualityEstimator::GetEchoURL() const { |
| 73 TestNetworkQualityEstimator::HandleRequest( | 77 return embedded_test_server_.GetURL("/simple.html"); |
| 74 const test_server::HttpRequest& request) { | |
| 75 std::unique_ptr<test_server::BasicHttpResponse> http_response( | |
| 76 new test_server::BasicHttpResponse()); | |
| 77 http_response->set_code(HTTP_OK); | |
| 78 http_response->set_content("hello"); | |
| 79 http_response->set_content_type("text/plain"); | |
| 80 return std::move(http_response); | |
| 81 } | 78 } |
| 82 | 79 |
| 83 const GURL TestNetworkQualityEstimator::GetEchoURL() const { | 80 const GURL TestNetworkQualityEstimator::GetRedirectURL() const { |
| 84 return embedded_test_server_.GetURL("/echo.html"); | 81 return embedded_test_server_.GetURL("/redirect302-to-https"); |
| 85 } | 82 } |
| 86 | 83 |
| 87 EffectiveConnectionType | 84 EffectiveConnectionType |
| 88 TestNetworkQualityEstimator::GetEffectiveConnectionType() const { | 85 TestNetworkQualityEstimator::GetEffectiveConnectionType() const { |
| 89 if (effective_connection_type_) | 86 if (effective_connection_type_) |
| 90 return effective_connection_type_.value(); | 87 return effective_connection_type_.value(); |
| 91 return NetworkQualityEstimator::GetEffectiveConnectionType(); | 88 return NetworkQualityEstimator::GetEffectiveConnectionType(); |
| 92 } | 89 } |
| 93 | 90 |
| 94 EffectiveConnectionType | 91 EffectiveConnectionType |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 184 |
| 188 double TestNetworkQualityEstimator::RandDouble() const { | 185 double TestNetworkQualityEstimator::RandDouble() const { |
| 189 return rand_double_; | 186 return rand_double_; |
| 190 } | 187 } |
| 191 | 188 |
| 192 nqe::internal::NetworkID TestNetworkQualityEstimator::GetCurrentNetworkID() | 189 nqe::internal::NetworkID TestNetworkQualityEstimator::GetCurrentNetworkID() |
| 193 const { | 190 const { |
| 194 return nqe::internal::NetworkID(current_network_type_, current_network_id_); | 191 return nqe::internal::NetworkID(current_network_type_, current_network_id_); |
| 195 } | 192 } |
| 196 | 193 |
| 194 TestNetworkQualityEstimator::LocalHttpTestServer::LocalHttpTestServer( |
| 195 const base::FilePath& document_root) { |
| 196 AddDefaultHandlers(document_root); |
| 197 } |
| 198 |
| 197 } // namespace net | 199 } // namespace net |
| OLD | NEW |