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