| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 257 |
| 258 const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals() | 258 const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals() |
| 259 const override { | 259 const override { |
| 260 if (accuracy_recording_intervals_set_) | 260 if (accuracy_recording_intervals_set_) |
| 261 return accuracy_recording_intervals_; | 261 return accuracy_recording_intervals_; |
| 262 | 262 |
| 263 return NetworkQualityEstimator::GetAccuracyRecordingIntervals(); | 263 return NetworkQualityEstimator::GetAccuracyRecordingIntervals(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 using NetworkQualityEstimator::SetTickClockForTesting; | 266 using NetworkQualityEstimator::SetTickClockForTesting; |
| 267 using NetworkQualityEstimator::ReadCachedNetworkQualityEstimate; | |
| 268 using NetworkQualityEstimator::OnConnectionTypeChanged; | 267 using NetworkQualityEstimator::OnConnectionTypeChanged; |
| 269 | 268 |
| 270 private: | 269 private: |
| 271 // NetworkQualityEstimator implementation that returns the overridden | 270 // NetworkQualityEstimator implementation that returns the overridden |
| 272 // network | 271 // network |
| 273 // id (instead of invoking platform APIs). | 272 // id (instead of invoking platform APIs). |
| 274 NetworkQualityEstimator::NetworkID GetCurrentNetworkID() const override { | 273 nqe::internal::NetworkID GetCurrentNetworkID() const override { |
| 275 return NetworkQualityEstimator::NetworkID(current_network_type_, | 274 return nqe::internal::NetworkID(current_network_type_, current_network_id_); |
| 276 current_network_id_); | |
| 277 } | 275 } |
| 278 | 276 |
| 279 bool effective_connection_type_set_; | 277 bool effective_connection_type_set_; |
| 280 EffectiveConnectionType effective_connection_type_; | 278 EffectiveConnectionType effective_connection_type_; |
| 281 | 279 |
| 282 bool recent_effective_connection_type_set_; | 280 bool recent_effective_connection_type_set_; |
| 283 EffectiveConnectionType recent_effective_connection_type_; | 281 EffectiveConnectionType recent_effective_connection_type_; |
| 284 | 282 |
| 285 NetworkChangeNotifier::ConnectionType current_network_type_; | 283 NetworkChangeNotifier::ConnectionType current_network_type_; |
| 286 std::string current_network_id_; | 284 std::string current_network_id_; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 }; | 382 }; |
| 385 | 383 |
| 386 } // namespace | 384 } // namespace |
| 387 | 385 |
| 388 TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) { | 386 TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) { |
| 389 base::HistogramTester histogram_tester; | 387 base::HistogramTester histogram_tester; |
| 390 // Enable requests to local host to be used for network quality estimation. | 388 // Enable requests to local host to be used for network quality estimation. |
| 391 std::map<std::string, std::string> variation_params; | 389 std::map<std::string, std::string> variation_params; |
| 392 TestNetworkQualityEstimator estimator(variation_params); | 390 TestNetworkQualityEstimator estimator(variation_params); |
| 393 | 391 |
| 392 estimator.SimulateNetworkChangeTo( |
| 393 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test"); |
| 394 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", |
| 395 false, 1); |
| 396 |
| 394 base::TimeDelta rtt; | 397 base::TimeDelta rtt; |
| 395 int32_t kbps; | 398 int32_t kbps; |
| 396 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); | 399 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); |
| 397 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 400 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 398 | 401 |
| 399 TestDelegate test_delegate; | 402 TestDelegate test_delegate; |
| 400 TestURLRequestContext context(true); | 403 TestURLRequestContext context(true); |
| 401 context.set_network_quality_estimator(&estimator); | 404 context.set_network_quality_estimator(&estimator); |
| 402 context.Init(); | 405 context.Init(); |
| 403 | 406 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 424 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 427 std::unique_ptr<URLRequest> request2(context.CreateRequest( |
| 425 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 428 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 426 request2->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); | 429 request2->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); |
| 427 request2->Start(); | 430 request2->Start(); |
| 428 base::RunLoop().Run(); | 431 base::RunLoop().Run(); |
| 429 histogram_tester.ExpectTotalCount( | 432 histogram_tester.ExpectTotalCount( |
| 430 "NQE.MainFrame.EffectiveConnectionType.Unknown", 2); | 433 "NQE.MainFrame.EffectiveConnectionType.Unknown", 2); |
| 431 | 434 |
| 432 estimator.SimulateNetworkChangeTo( | 435 estimator.SimulateNetworkChangeTo( |
| 433 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 436 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
| 437 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", |
| 438 false, 2); |
| 434 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); | 439 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); |
| 435 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); | 440 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); |
| 436 | 441 |
| 437 histogram_tester.ExpectTotalCount("NQE.RatioMedianRTT.WiFi", 0); | 442 histogram_tester.ExpectTotalCount("NQE.RatioMedianRTT.WiFi", 0); |
| 438 | 443 |
| 439 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile0.Unknown", 1); | 444 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile0.Unknown", 1); |
| 440 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile10.Unknown", 1); | 445 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile10.Unknown", 1); |
| 441 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile50.Unknown", 1); | 446 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile50.Unknown", 1); |
| 442 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile90.Unknown", 1); | 447 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile90.Unknown", 1); |
| 443 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile100.Unknown", 1); | 448 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile100.Unknown", 1); |
| 444 | 449 |
| 445 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 0); | 450 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 0); |
| 446 | 451 |
| 447 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); | 452 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); |
| 448 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 453 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 449 | 454 |
| 450 // Verify that metrics are logged correctly on main-frame requests. | 455 // Verify that metrics are logged correctly on main-frame requests. |
| 451 histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50.Unknown", | 456 histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50.Unknown", |
| 452 1); | 457 1); |
| 453 histogram_tester.ExpectTotalCount( | 458 histogram_tester.ExpectTotalCount( |
| 454 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", 0); | 459 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", 0); |
| 455 histogram_tester.ExpectTotalCount("NQE.MainFrame.Kbps.Percentile50.Unknown", | 460 histogram_tester.ExpectTotalCount("NQE.MainFrame.Kbps.Percentile50.Unknown", |
| 456 1); | 461 1); |
| 457 | 462 |
| 458 estimator.SimulateNetworkChangeTo( | 463 estimator.SimulateNetworkChangeTo( |
| 459 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, std::string()); | 464 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, std::string()); |
| 465 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", |
| 466 false, 3); |
| 460 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); | 467 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); |
| 461 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); | 468 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); |
| 462 | 469 |
| 463 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); | 470 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); |
| 464 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 471 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 465 | 472 |
| 466 std::unique_ptr<URLRequest> request3(context.CreateRequest( | 473 std::unique_ptr<URLRequest> request3(context.CreateRequest( |
| 467 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 474 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 468 request3->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); | 475 request3->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); |
| 469 request3->Start(); | 476 request3->Start(); |
| 470 base::RunLoop().Run(); | 477 base::RunLoop().Run(); |
| 471 histogram_tester.ExpectUniqueSample( | 478 histogram_tester.ExpectUniqueSample( |
| 472 "NQE.MainFrame.EffectiveConnectionType.WiFi", | 479 "NQE.MainFrame.EffectiveConnectionType.WiFi", |
| 473 NetworkQualityEstimator::EffectiveConnectionType:: | 480 NetworkQualityEstimator::EffectiveConnectionType:: |
| 474 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | 481 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 475 1); | 482 1); |
| 483 |
| 484 estimator.SimulateNetworkChangeTo( |
| 485 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test"); |
| 486 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false, |
| 487 3); |
| 488 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true, |
| 489 1); |
| 476 } | 490 } |
| 477 | 491 |
| 478 TEST(NetworkQualityEstimatorTest, StoreObservations) { | 492 TEST(NetworkQualityEstimatorTest, StoreObservations) { |
| 479 std::map<std::string, std::string> variation_params; | 493 std::map<std::string, std::string> variation_params; |
| 480 TestNetworkQualityEstimator estimator(variation_params); | 494 TestNetworkQualityEstimator estimator(variation_params); |
| 481 | 495 |
| 482 base::TimeDelta rtt; | 496 base::TimeDelta rtt; |
| 483 int32_t kbps; | 497 int32_t kbps; |
| 484 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); | 498 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); |
| 485 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 499 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 | 986 |
| 973 for (const auto& test : tests) { | 987 for (const auto& test : tests) { |
| 974 variation_params["HalfLifeSeconds"] = test.variation_params_value; | 988 variation_params["HalfLifeSeconds"] = test.variation_params_value; |
| 975 TestNetworkQualityEstimator estimator(variation_params); | 989 TestNetworkQualityEstimator estimator(variation_params); |
| 976 EXPECT_NEAR(test.expected_weight_multiplier, | 990 EXPECT_NEAR(test.expected_weight_multiplier, |
| 977 estimator.weight_multiplier_per_second_, 0.001) | 991 estimator.weight_multiplier_per_second_, 0.001) |
| 978 << test.description; | 992 << test.description; |
| 979 } | 993 } |
| 980 } | 994 } |
| 981 | 995 |
| 982 // Test if the network estimates are cached when network change notification | |
| 983 // is invoked. | |
| 984 TEST(NetworkQualityEstimatorTest, TestCaching) { | |
| 985 std::map<std::string, std::string> variation_params; | |
| 986 TestNetworkQualityEstimator estimator(variation_params); | |
| 987 size_t expected_cache_size = 0; | |
| 988 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | |
| 989 | |
| 990 // Cache entry will not be added for (NONE, ""). | |
| 991 estimator.downstream_throughput_kbps_observations_.AddObservation( | |
| 992 NetworkQualityEstimator::ThroughputObservation( | |
| 993 1, base::TimeTicks::Now(), | |
| 994 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 995 estimator.rtt_observations_.AddObservation( | |
| 996 NetworkQualityEstimator::RttObservation( | |
| 997 base::TimeDelta::FromMilliseconds(1000), base::TimeTicks::Now(), | |
| 998 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 999 estimator.SimulateNetworkChangeTo( | |
| 1000 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); | |
| 1001 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | |
| 1002 | |
| 1003 // Entry will be added for (2G, "test1"). | |
| 1004 // Also, set the network quality for (2G, "test1") so that it is stored in | |
| 1005 // the cache. | |
| 1006 estimator.downstream_throughput_kbps_observations_.AddObservation( | |
| 1007 NetworkQualityEstimator::ThroughputObservation( | |
| 1008 1, base::TimeTicks::Now(), | |
| 1009 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 1010 estimator.rtt_observations_.AddObservation( | |
| 1011 NetworkQualityEstimator::RttObservation( | |
| 1012 base::TimeDelta::FromMilliseconds(1000), base::TimeTicks::Now(), | |
| 1013 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 1014 | |
| 1015 estimator.SimulateNetworkChangeTo( | |
| 1016 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-1"); | |
| 1017 ++expected_cache_size; | |
| 1018 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | |
| 1019 | |
| 1020 // Entry will be added for (3G, "test1"). | |
| 1021 // Also, set the network quality for (3G, "test1") so that it is stored in | |
| 1022 // the cache. | |
| 1023 estimator.downstream_throughput_kbps_observations_.AddObservation( | |
| 1024 NetworkQualityEstimator::ThroughputObservation( | |
| 1025 2, base::TimeTicks::Now(), | |
| 1026 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 1027 estimator.rtt_observations_.AddObservation( | |
| 1028 NetworkQualityEstimator::RttObservation( | |
| 1029 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), | |
| 1030 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 1031 estimator.SimulateNetworkChangeTo( | |
| 1032 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-2"); | |
| 1033 ++expected_cache_size; | |
| 1034 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | |
| 1035 | |
| 1036 // Entry will not be added for (3G, "test2"). | |
| 1037 estimator.SimulateNetworkChangeTo( | |
| 1038 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-1"); | |
| 1039 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | |
| 1040 | |
| 1041 // Read the network quality for (2G, "test-1"). | |
| 1042 EXPECT_TRUE(estimator.ReadCachedNetworkQualityEstimate()); | |
| 1043 | |
| 1044 base::TimeDelta rtt; | |
| 1045 int32_t kbps; | |
| 1046 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); | |
| 1047 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | |
| 1048 EXPECT_EQ(1, kbps); | |
| 1049 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); | |
| 1050 EXPECT_FALSE(estimator.GetTransportRTTEstimate(&rtt)); | |
| 1051 | |
| 1052 // No new entry should be added for (2G, "test-1") since it already exists | |
| 1053 // in the cache. | |
| 1054 estimator.SimulateNetworkChangeTo( | |
| 1055 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-1"); | |
| 1056 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | |
| 1057 | |
| 1058 // Read the network quality for (3G, "test-1"). | |
| 1059 EXPECT_TRUE(estimator.ReadCachedNetworkQualityEstimate()); | |
| 1060 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); | |
| 1061 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | |
| 1062 EXPECT_EQ(2, kbps); | |
| 1063 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500), rtt); | |
| 1064 // No new entry should be added for (3G, "test1") since it already exists | |
| 1065 // in the cache. | |
| 1066 estimator.SimulateNetworkChangeTo( | |
| 1067 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-2"); | |
| 1068 EXPECT_EQ(expected_cache_size, estimator.cached_network_qualities_.size()); | |
| 1069 | |
| 1070 // Reading quality of (3G, "test-2") should return false. | |
| 1071 EXPECT_FALSE(estimator.ReadCachedNetworkQualityEstimate()); | |
| 1072 | |
| 1073 // Reading quality of (2G, "test-3") should return false. | |
| 1074 estimator.SimulateNetworkChangeTo( | |
| 1075 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-3"); | |
| 1076 EXPECT_FALSE(estimator.ReadCachedNetworkQualityEstimate()); | |
| 1077 } | |
| 1078 | |
| 1079 // Tests if the cache size remains bounded. Also, ensure that the cache is | |
| 1080 // LRU. | |
| 1081 TEST(NetworkQualityEstimatorTest, TestLRUCacheMaximumSize) { | |
| 1082 std::map<std::string, std::string> variation_params; | |
| 1083 TestNetworkQualityEstimator estimator(variation_params); | |
| 1084 estimator.SimulateNetworkChangeTo( | |
| 1085 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, std::string()); | |
| 1086 EXPECT_EQ(0U, estimator.cached_network_qualities_.size()); | |
| 1087 | |
| 1088 // Add 100 more networks than the maximum size of the cache. | |
| 1089 size_t network_count = | |
| 1090 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize + 100; | |
| 1091 | |
| 1092 base::TimeTicks update_time_of_network_100; | |
| 1093 for (size_t i = 0; i < network_count; ++i) { | |
| 1094 estimator.downstream_throughput_kbps_observations_.AddObservation( | |
| 1095 NetworkQualityEstimator::ThroughputObservation( | |
| 1096 2, base::TimeTicks::Now(), | |
| 1097 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 1098 estimator.rtt_observations_.AddObservation( | |
| 1099 NetworkQualityEstimator::RttObservation( | |
| 1100 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), | |
| 1101 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 1102 | |
| 1103 if (i == 100) | |
| 1104 update_time_of_network_100 = base::TimeTicks::Now(); | |
| 1105 | |
| 1106 estimator.SimulateNetworkChangeTo( | |
| 1107 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, | |
| 1108 base::SizeTToString(i)); | |
| 1109 if (i < NetworkQualityEstimator::kMaximumNetworkQualityCacheSize) | |
| 1110 EXPECT_EQ(i, estimator.cached_network_qualities_.size()); | |
| 1111 EXPECT_LE(estimator.cached_network_qualities_.size(), | |
| 1112 static_cast<size_t>( | |
| 1113 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize)); | |
| 1114 } | |
| 1115 // One more call so that the last network is also written to cache. | |
| 1116 estimator.downstream_throughput_kbps_observations_.AddObservation( | |
| 1117 NetworkQualityEstimator::ThroughputObservation( | |
| 1118 2, base::TimeTicks::Now(), | |
| 1119 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 1120 estimator.rtt_observations_.AddObservation( | |
| 1121 NetworkQualityEstimator::RttObservation( | |
| 1122 base::TimeDelta::FromMilliseconds(500), base::TimeTicks::Now(), | |
| 1123 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 1124 estimator.SimulateNetworkChangeTo( | |
| 1125 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, | |
| 1126 base::SizeTToString(network_count - 1)); | |
| 1127 EXPECT_EQ(static_cast<size_t>( | |
| 1128 NetworkQualityEstimator::kMaximumNetworkQualityCacheSize), | |
| 1129 estimator.cached_network_qualities_.size()); | |
| 1130 | |
| 1131 // Test that the cache is LRU by examining its contents. Networks in cache | |
| 1132 // must all be newer than the 100th network. | |
| 1133 for (NetworkQualityEstimator::CachedNetworkQualities::iterator it = | |
| 1134 estimator.cached_network_qualities_.begin(); | |
| 1135 it != estimator.cached_network_qualities_.end(); ++it) { | |
| 1136 EXPECT_GE((it->second).last_update_time_, update_time_of_network_100); | |
| 1137 } | |
| 1138 } | |
| 1139 | |
| 1140 TEST(NetworkQualityEstimatorTest, TestGetMetricsSince) { | 996 TEST(NetworkQualityEstimatorTest, TestGetMetricsSince) { |
| 1141 std::map<std::string, std::string> variation_params; | 997 std::map<std::string, std::string> variation_params; |
| 1142 | 998 |
| 1143 const base::TimeDelta rtt_threshold_4g = | 999 const base::TimeDelta rtt_threshold_4g = |
| 1144 base::TimeDelta::FromMilliseconds(30); | 1000 base::TimeDelta::FromMilliseconds(30); |
| 1145 const base::TimeDelta rtt_threshold_broadband = | 1001 const base::TimeDelta rtt_threshold_broadband = |
| 1146 base::TimeDelta::FromMilliseconds(1); | 1002 base::TimeDelta::FromMilliseconds(1); |
| 1147 | 1003 |
| 1148 variation_params["4G.ThresholdMedianHttpRTTMsec"] = | 1004 variation_params["4G.ThresholdMedianHttpRTTMsec"] = |
| 1149 base::IntToString(rtt_threshold_4g.InMilliseconds()); | 1005 base::IntToString(rtt_threshold_4g.InMilliseconds()); |
| (...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1943 std::string(NetworkQualityEstimator::GetNameForEffectiveConnectionType( | 1799 std::string(NetworkQualityEstimator::GetNameForEffectiveConnectionType( |
| 1944 effective_connection_type)); | 1800 effective_connection_type)); |
| 1945 EXPECT_FALSE(connection_type_name.empty()); | 1801 EXPECT_FALSE(connection_type_name.empty()); |
| 1946 EXPECT_EQ(effective_connection_type, | 1802 EXPECT_EQ(effective_connection_type, |
| 1947 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( | 1803 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( |
| 1948 connection_type_name)); | 1804 connection_type_name)); |
| 1949 } | 1805 } |
| 1950 } | 1806 } |
| 1951 | 1807 |
| 1952 } // namespace net | 1808 } // namespace net |
| OLD | NEW |