| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.h" | 5 #include "net/nqe/network_quality_estimator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 const std::map<std::string, std::string>& variation_params) | 68 const std::map<std::string, std::string>& variation_params) |
| 69 : TestNetworkQualityEstimator( | 69 : TestNetworkQualityEstimator( |
| 70 variation_params, | 70 variation_params, |
| 71 std::unique_ptr<ExternalEstimateProvider>()) {} | 71 std::unique_ptr<ExternalEstimateProvider>()) {} |
| 72 | 72 |
| 73 ~TestNetworkQualityEstimator() override {} | 73 ~TestNetworkQualityEstimator() override {} |
| 74 | 74 |
| 75 // Overrides the current network type and id. | 75 // Overrides the current network type and id. |
| 76 // Notifies network quality estimator of change in connection. | 76 // Notifies network quality estimator of change in connection. |
| 77 void SimulateNetworkChangeTo(NetworkChangeNotifier::ConnectionType type, | 77 void SimulateNetworkChangeTo(NetworkChangeNotifier::ConnectionType type, |
| 78 const std::string& network_id) { | 78 std::string network_id) { |
| 79 current_network_type_ = type; | 79 current_network_type_ = type; |
| 80 current_network_id_ = network_id; | 80 current_network_id_ = network_id; |
| 81 OnConnectionTypeChanged(type); | 81 OnConnectionTypeChanged(type); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Called by embedded server when a HTTP request is received. | 84 // Called by embedded server when a HTTP request is received. |
| 85 std::unique_ptr<test_server::HttpResponse> HandleRequest( | 85 std::unique_ptr<test_server::HttpResponse> HandleRequest( |
| 86 const test_server::HttpRequest& request) { | 86 const test_server::HttpRequest& request) { |
| 87 std::unique_ptr<test_server::BasicHttpResponse> http_response( | 87 std::unique_ptr<test_server::BasicHttpResponse> http_response( |
| 88 new test_server::BasicHttpResponse()); | 88 new test_server::BasicHttpResponse()); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 424 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 425 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 425 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 426 }; | 426 }; |
| 427 | 427 |
| 428 for (const auto& test : tests) { | 428 for (const auto& test : tests) { |
| 429 estimator.set_url_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 429 estimator.set_url_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 430 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 430 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 | 433 |
| 434 // Tests that |GetEffectiveConnectionType| returns | |
| 435 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. | |
| 436 TEST(NetworkQualityEstimatorTest, Offline) { | |
| 437 std::map<std::string, std::string> variation_params; | |
| 438 | |
| 439 TestNetworkQualityEstimator estimator(variation_params); | |
| 440 | |
| 441 const struct { | |
| 442 NetworkChangeNotifier::ConnectionType connection_type; | |
| 443 NetworkQualityEstimator::EffectiveConnectionType expected_connection_type; | |
| 444 } tests[] = { | |
| 445 {NetworkChangeNotifier::CONNECTION_2G, | |
| 446 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN}, | |
| 447 {NetworkChangeNotifier::CONNECTION_NONE, | |
| 448 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | |
| 449 {NetworkChangeNotifier::CONNECTION_3G, | |
| 450 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN}, | |
| 451 }; | |
| 452 | |
| 453 for (const auto& test : tests) { | |
| 454 estimator.SimulateNetworkChangeTo(test.connection_type, "test"); | |
| 455 EXPECT_EQ(test.expected_connection_type, | |
| 456 estimator.GetEffectiveConnectionType()); | |
| 457 } | |
| 458 } | |
| 459 | |
| 460 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 434 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 461 // only RTT thresholds are specified in the variation params. | 435 // only RTT thresholds are specified in the variation params. |
| 462 TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyRTT) { | 436 TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyRTT) { |
| 463 std::map<std::string, std::string> variation_params; | 437 std::map<std::string, std::string> variation_params; |
| 464 | 438 |
| 465 variation_params["Offline.ThresholdMedianURLRTTMsec"] = "4000"; | 439 variation_params["Offline.ThresholdMedianURLRTTMsec"] = "4000"; |
| 466 variation_params["Slow2G.ThresholdMedianURLRTTMsec"] = "2000"; | 440 variation_params["Slow2G.ThresholdMedianURLRTTMsec"] = "2000"; |
| 467 variation_params["2G.ThresholdMedianURLRTTMsec"] = "1000"; | 441 variation_params["2G.ThresholdMedianURLRTTMsec"] = "1000"; |
| 468 variation_params["3G.ThresholdMedianURLRTTMsec"] = "500"; | 442 variation_params["3G.ThresholdMedianURLRTTMsec"] = "500"; |
| 469 variation_params["4G.ThresholdMedianURLRTTMsec"] = "300"; | 443 variation_params["4G.ThresholdMedianURLRTTMsec"] = "300"; |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 // At least one notification should be received per socket performance | 1200 // At least one notification should be received per socket performance |
| 1227 // watcher. | 1201 // watcher. |
| 1228 EXPECT_LE(1U, after_count_tcp_rtt_observations - | 1202 EXPECT_LE(1U, after_count_tcp_rtt_observations - |
| 1229 before_count_tcp_rtt_observations) | 1203 before_count_tcp_rtt_observations) |
| 1230 << i; | 1204 << i; |
| 1231 } | 1205 } |
| 1232 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); | 1206 EXPECT_TRUE(estimator.GetURLRequestRTTEstimate(&rtt)); |
| 1233 } | 1207 } |
| 1234 | 1208 |
| 1235 } // namespace net | 1209 } // namespace net |
| OLD | NEW |