| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 std::map<std::string, std::string> variation_params; | 155 std::map<std::string, std::string> variation_params; |
| 156 TestNetworkQualityEstimator estimator(variation_params); | 156 TestNetworkQualityEstimator estimator(variation_params); |
| 157 | 157 |
| 158 estimator.SimulateNetworkChange( | 158 estimator.SimulateNetworkChange( |
| 159 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test"); | 159 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test"); |
| 160 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", | 160 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", |
| 161 false, 1); | 161 false, 1); |
| 162 | 162 |
| 163 base::TimeDelta rtt; | 163 base::TimeDelta rtt; |
| 164 int32_t kbps; | 164 int32_t kbps; |
| 165 EXPECT_FALSE(estimator.GetHttpRTT(&rtt)); | 165 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 166 EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps)); | 166 EXPECT_FALSE( |
| 167 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 167 | 168 |
| 168 TestDelegate test_delegate; | 169 TestDelegate test_delegate; |
| 169 TestURLRequestContext context(true); | 170 TestURLRequestContext context(true); |
| 170 context.set_network_quality_estimator(&estimator); | 171 context.set_network_quality_estimator(&estimator); |
| 171 context.Init(); | 172 context.Init(); |
| 172 | 173 |
| 173 std::unique_ptr<URLRequest> request(context.CreateRequest( | 174 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 174 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 175 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 175 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 176 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 176 request->Start(); | 177 request->Start(); |
| 177 base::RunLoop().Run(); | 178 base::RunLoop().Run(); |
| 178 | 179 |
| 179 // Both RTT and downstream throughput should be updated. | 180 // Both RTT and downstream throughput should be updated. |
| 180 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); | 181 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 181 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps)); | 182 EXPECT_TRUE( |
| 182 EXPECT_FALSE(estimator.GetTransportRTT(&rtt)); | 183 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 184 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 183 | 185 |
| 184 // Check UMA histograms. | 186 // Check UMA histograms. |
| 185 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); | 187 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); |
| 186 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); | 188 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); |
| 187 histogram_tester.ExpectUniqueSample( | 189 histogram_tester.ExpectUniqueSample( |
| 188 "NQE.MainFrame.EffectiveConnectionType", | 190 "NQE.MainFrame.EffectiveConnectionType", |
| 189 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); | 191 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); |
| 190 histogram_tester.ExpectUniqueSample( | 192 histogram_tester.ExpectUniqueSample( |
| 191 "NQE.MainFrame.EffectiveConnectionType.Unknown", | 193 "NQE.MainFrame.EffectiveConnectionType.Unknown", |
| 192 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); | 194 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 210 histogram_tester.ExpectTotalCount("NQE.RatioMedianRTT.WiFi", 0); | 212 histogram_tester.ExpectTotalCount("NQE.RatioMedianRTT.WiFi", 0); |
| 211 | 213 |
| 212 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile0.Unknown", 1); | 214 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile0.Unknown", 1); |
| 213 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile10.Unknown", 1); | 215 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile10.Unknown", 1); |
| 214 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile50.Unknown", 1); | 216 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile50.Unknown", 1); |
| 215 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile90.Unknown", 1); | 217 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile90.Unknown", 1); |
| 216 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile100.Unknown", 1); | 218 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile100.Unknown", 1); |
| 217 | 219 |
| 218 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 0); | 220 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 0); |
| 219 | 221 |
| 220 EXPECT_FALSE(estimator.GetHttpRTT(&rtt)); | 222 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 221 EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps)); | 223 EXPECT_FALSE( |
| 224 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 222 | 225 |
| 223 // Verify that metrics are logged correctly on main-frame requests. | 226 // Verify that metrics are logged correctly on main-frame requests. |
| 224 histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50", 1); | 227 histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50", 1); |
| 225 histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50.Unknown", | 228 histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50.Unknown", |
| 226 1); | 229 1); |
| 227 histogram_tester.ExpectTotalCount("NQE.MainFrame.TransportRTT.Percentile50", | 230 histogram_tester.ExpectTotalCount("NQE.MainFrame.TransportRTT.Percentile50", |
| 228 0); | 231 0); |
| 229 histogram_tester.ExpectTotalCount( | 232 histogram_tester.ExpectTotalCount( |
| 230 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", 0); | 233 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", 0); |
| 231 histogram_tester.ExpectTotalCount("NQE.MainFrame.Kbps.Percentile50", 1); | 234 histogram_tester.ExpectTotalCount("NQE.MainFrame.Kbps.Percentile50", 1); |
| 232 histogram_tester.ExpectTotalCount("NQE.MainFrame.Kbps.Percentile50.Unknown", | 235 histogram_tester.ExpectTotalCount("NQE.MainFrame.Kbps.Percentile50.Unknown", |
| 233 1); | 236 1); |
| 234 | 237 |
| 235 estimator.SimulateNetworkChange( | 238 estimator.SimulateNetworkChange( |
| 236 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, std::string()); | 239 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, std::string()); |
| 237 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", | 240 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", |
| 238 false, 3); | 241 false, 3); |
| 239 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); | 242 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); |
| 240 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); | 243 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); |
| 241 | 244 |
| 242 EXPECT_FALSE(estimator.GetHttpRTT(&rtt)); | 245 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 243 EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps)); | 246 EXPECT_FALSE( |
| 247 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 244 | 248 |
| 245 std::unique_ptr<URLRequest> request3(context.CreateRequest( | 249 std::unique_ptr<URLRequest> request3(context.CreateRequest( |
| 246 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 250 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 247 request3->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 251 request3->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 248 request3->Start(); | 252 request3->Start(); |
| 249 base::RunLoop().Run(); | 253 base::RunLoop().Run(); |
| 250 histogram_tester.ExpectUniqueSample( | 254 histogram_tester.ExpectUniqueSample( |
| 251 "NQE.MainFrame.EffectiveConnectionType.WiFi", | 255 "NQE.MainFrame.EffectiveConnectionType.WiFi", |
| 252 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); | 256 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); |
| 253 histogram_tester.ExpectTotalCount("NQE.MainFrame.EffectiveConnectionType", 3); | 257 histogram_tester.ExpectTotalCount("NQE.MainFrame.EffectiveConnectionType", 3); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 267 std::map<std::string, std::string> variation_params; | 271 std::map<std::string, std::string> variation_params; |
| 268 TestNetworkQualityEstimator estimator(variation_params); | 272 TestNetworkQualityEstimator estimator(variation_params); |
| 269 | 273 |
| 270 estimator.SimulateNetworkChange( | 274 estimator.SimulateNetworkChange( |
| 271 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test"); | 275 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test"); |
| 272 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", | 276 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", |
| 273 false, 1); | 277 false, 1); |
| 274 | 278 |
| 275 base::TimeDelta rtt; | 279 base::TimeDelta rtt; |
| 276 int32_t kbps; | 280 int32_t kbps; |
| 277 EXPECT_FALSE(estimator.GetHttpRTT(&rtt)); | 281 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 278 EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps)); | 282 EXPECT_FALSE( |
| 283 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 279 | 284 |
| 280 TestDelegate test_delegate; | 285 TestDelegate test_delegate; |
| 281 TestURLRequestContext context(true); | 286 TestURLRequestContext context(true); |
| 282 context.set_network_quality_estimator(&estimator); | 287 context.set_network_quality_estimator(&estimator); |
| 283 context.Init(); | 288 context.Init(); |
| 284 | 289 |
| 285 // Start two requests so that the network quality is added to cache store at | 290 // Start two requests so that the network quality is added to cache store at |
| 286 // the beginning of the second request from the network traffic observed from | 291 // the beginning of the second request from the network traffic observed from |
| 287 // the first request. | 292 // the first request. |
| 288 for (size_t i = 0; i < 2; ++i) { | 293 for (size_t i = 0; i < 2; ++i) { |
| 289 std::unique_ptr<URLRequest> request(context.CreateRequest( | 294 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 290 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 295 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 291 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 296 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 292 request->Start(); | 297 request->Start(); |
| 293 base::RunLoop().Run(); | 298 base::RunLoop().Run(); |
| 294 } | 299 } |
| 295 | 300 |
| 296 base::RunLoop().RunUntilIdle(); | 301 base::RunLoop().RunUntilIdle(); |
| 297 | 302 |
| 298 // Both RTT and downstream throughput should be updated. | 303 // Both RTT and downstream throughput should be updated. |
| 299 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); | 304 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 300 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps)); | 305 EXPECT_TRUE( |
| 306 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 301 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | 307 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 302 estimator.GetEffectiveConnectionType()); | 308 estimator.GetEffectiveConnectionType()); |
| 303 EXPECT_FALSE(estimator.GetTransportRTT(&rtt)); | 309 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 304 | 310 |
| 305 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false, | 311 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false, |
| 306 1); | 312 1); |
| 307 | 313 |
| 308 // Add the observers before changing the network type. | 314 // Add the observers before changing the network type. |
| 309 TestEffectiveConnectionTypeObserver observer; | 315 TestEffectiveConnectionTypeObserver observer; |
| 310 estimator.AddEffectiveConnectionTypeObserver(&observer); | 316 estimator.AddEffectiveConnectionTypeObserver(&observer); |
| 311 TestRTTObserver rtt_observer; | 317 TestRTTObserver rtt_observer; |
| 312 estimator.AddRTTObserver(&rtt_observer); | 318 estimator.AddRTTObserver(&rtt_observer); |
| 313 TestThroughputObserver throughput_observer; | 319 TestThroughputObserver throughput_observer; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 326 EXPECT_EQ(1U, rtt_observer.observations().size()); | 332 EXPECT_EQ(1U, rtt_observer.observations().size()); |
| 327 EXPECT_EQ(1U, throughput_observer.observations().size()); | 333 EXPECT_EQ(1U, throughput_observer.observations().size()); |
| 328 } | 334 } |
| 329 | 335 |
| 330 TEST(NetworkQualityEstimatorTest, StoreObservations) { | 336 TEST(NetworkQualityEstimatorTest, StoreObservations) { |
| 331 std::map<std::string, std::string> variation_params; | 337 std::map<std::string, std::string> variation_params; |
| 332 TestNetworkQualityEstimator estimator(variation_params); | 338 TestNetworkQualityEstimator estimator(variation_params); |
| 333 | 339 |
| 334 base::TimeDelta rtt; | 340 base::TimeDelta rtt; |
| 335 int32_t kbps; | 341 int32_t kbps; |
| 336 EXPECT_FALSE(estimator.GetHttpRTT(&rtt)); | 342 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 337 EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps)); | 343 EXPECT_FALSE( |
| 344 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 338 | 345 |
| 339 TestDelegate test_delegate; | 346 TestDelegate test_delegate; |
| 340 TestURLRequestContext context(true); | 347 TestURLRequestContext context(true); |
| 341 context.set_network_quality_estimator(&estimator); | 348 context.set_network_quality_estimator(&estimator); |
| 342 context.Init(); | 349 context.Init(); |
| 343 | 350 |
| 344 // Push more observations than the maximum buffer size. | 351 // Push more observations than the maximum buffer size. |
| 345 const size_t kMaxObservations = 1000; | 352 const size_t kMaxObservations = 1000; |
| 346 for (size_t i = 0; i < kMaxObservations; ++i) { | 353 for (size_t i = 0; i < kMaxObservations; ++i) { |
| 347 std::unique_ptr<URLRequest> request(context.CreateRequest( | 354 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 348 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 355 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 349 request->Start(); | 356 request->Start(); |
| 350 base::RunLoop().Run(); | 357 base::RunLoop().Run(); |
| 351 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); | 358 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 352 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps)); | 359 EXPECT_TRUE( |
| 360 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 353 } | 361 } |
| 354 | 362 |
| 355 // Verify that the stored observations are cleared on network change. | 363 // Verify that the stored observations are cleared on network change. |
| 356 estimator.SimulateNetworkChange( | 364 estimator.SimulateNetworkChange( |
| 357 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-2"); | 365 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-2"); |
| 358 EXPECT_FALSE(estimator.GetHttpRTT(&rtt)); | 366 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 359 EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps)); | 367 EXPECT_FALSE( |
| 368 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 360 } | 369 } |
| 361 | 370 |
| 362 // This test notifies NetworkQualityEstimator of received data. Next, | 371 // This test notifies NetworkQualityEstimator of received data. Next, |
| 363 // throughput and RTT percentiles are checked for correctness by doing simple | 372 // throughput and RTT percentiles are checked for correctness by doing simple |
| 364 // verifications. | 373 // verifications. |
| 365 TEST(NetworkQualityEstimatorTest, ComputedPercentiles) { | 374 TEST(NetworkQualityEstimatorTest, ComputedPercentiles) { |
| 366 std::map<std::string, std::string> variation_params; | 375 std::map<std::string, std::string> variation_params; |
| 367 TestNetworkQualityEstimator estimator(variation_params); | 376 TestNetworkQualityEstimator estimator(variation_params); |
| 368 | 377 |
| 369 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; | 378 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 variation_params["2G.DefaultMedianKbps"] = "300"; | 433 variation_params["2G.DefaultMedianKbps"] = "300"; |
| 425 | 434 |
| 426 variation_params["Unknown.DefaultMedianRTTMsec"] = "1000"; | 435 variation_params["Unknown.DefaultMedianRTTMsec"] = "1000"; |
| 427 variation_params["WiFi.DefaultMedianRTTMsec"] = "2000"; | 436 variation_params["WiFi.DefaultMedianRTTMsec"] = "2000"; |
| 428 // Negative variation value should not be used. | 437 // Negative variation value should not be used. |
| 429 variation_params["2G.DefaultMedianRTTMsec"] = "-5"; | 438 variation_params["2G.DefaultMedianRTTMsec"] = "-5"; |
| 430 | 439 |
| 431 TestNetworkQualityEstimator estimator(variation_params); | 440 TestNetworkQualityEstimator estimator(variation_params); |
| 432 | 441 |
| 433 base::TimeDelta rtt; | 442 base::TimeDelta rtt; |
| 434 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); | 443 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 435 int32_t kbps; | 444 int32_t kbps; |
| 436 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps)); | 445 EXPECT_TRUE( |
| 446 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 437 | 447 |
| 438 EXPECT_EQ(100, kbps); | 448 EXPECT_EQ(100, kbps); |
| 439 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); | 449 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); |
| 440 | 450 |
| 441 EXPECT_FALSE(estimator.GetTransportRTT(&rtt)); | 451 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 442 | 452 |
| 443 // Simulate network change to Wi-Fi. | 453 // Simulate network change to Wi-Fi. |
| 444 estimator.SimulateNetworkChange( | 454 estimator.SimulateNetworkChange( |
| 445 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 455 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
| 446 | 456 |
| 447 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); | 457 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 448 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps)); | 458 EXPECT_TRUE( |
| 459 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 449 EXPECT_EQ(200, kbps); | 460 EXPECT_EQ(200, kbps); |
| 450 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); | 461 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); |
| 451 EXPECT_FALSE(estimator.GetTransportRTT(&rtt)); | 462 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 452 | 463 |
| 453 // Peak network quality should not be affected by the network quality | 464 // Peak network quality should not be affected by the network quality |
| 454 // estimator field trial. | 465 // estimator field trial. |
| 455 EXPECT_EQ(nqe::internal::InvalidRTT(), | 466 EXPECT_EQ(nqe::internal::InvalidRTT(), |
| 456 estimator.peak_network_quality_.http_rtt()); | 467 estimator.peak_network_quality_.http_rtt()); |
| 457 EXPECT_EQ(nqe::internal::kInvalidThroughput, | 468 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
| 458 estimator.peak_network_quality_.downstream_throughput_kbps()); | 469 estimator.peak_network_quality_.downstream_throughput_kbps()); |
| 459 | 470 |
| 460 // Simulate network change to 2G. Only the Kbps default estimate should be | 471 // Simulate network change to 2G. Only the Kbps default estimate should be |
| 461 // available. | 472 // available. |
| 462 estimator.SimulateNetworkChange( | 473 estimator.SimulateNetworkChange( |
| 463 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); | 474 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); |
| 464 | 475 |
| 465 EXPECT_FALSE(estimator.GetHttpRTT(&rtt)); | 476 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 466 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps)); | 477 EXPECT_TRUE( |
| 478 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 467 EXPECT_EQ(300, kbps); | 479 EXPECT_EQ(300, kbps); |
| 468 | 480 |
| 469 // Simulate network change to 3G. Default estimates should be unavailable. | 481 // Simulate network change to 3G. Default estimates should be unavailable. |
| 470 estimator.SimulateNetworkChange( | 482 estimator.SimulateNetworkChange( |
| 471 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); | 483 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); |
| 472 | 484 |
| 473 EXPECT_FALSE(estimator.GetHttpRTT(&rtt)); | 485 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 474 EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps)); | 486 EXPECT_FALSE( |
| 487 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 475 } | 488 } |
| 476 | 489 |
| 477 TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) { | 490 TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) { |
| 478 const struct { | 491 const struct { |
| 479 bool set_variation_param; | 492 bool set_variation_param; |
| 480 std::string algorithm; | 493 std::string algorithm; |
| 481 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm | 494 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm |
| 482 expected_algorithm; | 495 expected_algorithm; |
| 483 } tests[] = { | 496 } tests[] = { |
| 484 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: | 497 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 {700, EFFECTIVE_CONNECTION_TYPE_3G}, | 589 {700, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 577 {500, EFFECTIVE_CONNECTION_TYPE_3G}, | 590 {500, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 578 {400, EFFECTIVE_CONNECTION_TYPE_4G}, | 591 {400, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 579 {300, EFFECTIVE_CONNECTION_TYPE_4G}, | 592 {300, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 580 {200, EFFECTIVE_CONNECTION_TYPE_4G}, | 593 {200, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 581 {100, EFFECTIVE_CONNECTION_TYPE_4G}, | 594 {100, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 582 {20, EFFECTIVE_CONNECTION_TYPE_4G}, | 595 {20, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 583 }; | 596 }; |
| 584 | 597 |
| 585 for (const auto& test : tests) { | 598 for (const auto& test : tests) { |
| 586 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 599 estimator.set_start_time_null_http_rtt( |
| 600 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 587 estimator.set_recent_http_rtt( | 601 estimator.set_recent_http_rtt( |
| 588 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 602 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 589 estimator.set_downlink_throughput_kbps(INT32_MAX); | 603 estimator.set_start_time_null_downlink_throughput_kbps(INT32_MAX); |
| 590 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | 604 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| 591 // Run one main frame request to force recomputation of effective connection | 605 // Run one main frame request to force recomputation of effective connection |
| 592 // type. | 606 // type. |
| 593 estimator.RunOneRequest(); | 607 estimator.RunOneRequest(); |
| 594 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 608 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 595 } | 609 } |
| 596 } | 610 } |
| 597 | 611 |
| 598 // Tests that default transport RTT thresholds for different effective | 612 // Tests that default transport RTT thresholds for different effective |
| 599 // connection types are correctly set. | 613 // connection types are correctly set. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; | 647 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000"; |
| 634 } | 648 } |
| 635 | 649 |
| 636 TestNetworkQualityEstimator estimator(variation_params); | 650 TestNetworkQualityEstimator estimator(variation_params); |
| 637 | 651 |
| 638 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | 652 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 639 // does not return Offline if the device is offline. | 653 // does not return Offline if the device is offline. |
| 640 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, | 654 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, |
| 641 "test"); | 655 "test"); |
| 642 | 656 |
| 643 estimator.set_transport_rtt( | 657 estimator.set_start_time_null_transport_rtt( |
| 644 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); | 658 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 645 estimator.set_recent_transport_rtt( | 659 estimator.set_recent_transport_rtt( |
| 646 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); | 660 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 647 estimator.set_downlink_throughput_kbps(INT32_MAX); | 661 estimator.set_start_time_null_downlink_throughput_kbps(INT32_MAX); |
| 648 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | 662 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| 649 // Run one main frame request to force recomputation of effective connection | 663 // Run one main frame request to force recomputation of effective connection |
| 650 // type. | 664 // type. |
| 651 estimator.RunOneRequest(); | 665 estimator.RunOneRequest(); |
| 652 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 666 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 653 } | 667 } |
| 654 } | 668 } |
| 655 | 669 |
| 656 // Tests that default HTTP RTT thresholds for different effective | 670 // Tests that default HTTP RTT thresholds for different effective |
| 657 // connection types are correctly set. | 671 // connection types are correctly set. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 variation_params["2G.ThresholdMedianHttpRTTMsec"] = "1000"; | 703 variation_params["2G.ThresholdMedianHttpRTTMsec"] = "1000"; |
| 690 } | 704 } |
| 691 | 705 |
| 692 TestNetworkQualityEstimator estimator(variation_params); | 706 TestNetworkQualityEstimator estimator(variation_params); |
| 693 | 707 |
| 694 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | 708 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 695 // does not return Offline if the device is offline. | 709 // does not return Offline if the device is offline. |
| 696 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, | 710 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, |
| 697 "test"); | 711 "test"); |
| 698 | 712 |
| 699 estimator.set_http_rtt( | 713 estimator.set_start_time_null_http_rtt( |
| 700 base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); | 714 base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); |
| 701 estimator.set_recent_http_rtt( | 715 estimator.set_recent_http_rtt( |
| 702 base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); | 716 base::TimeDelta::FromMilliseconds(test.http_rtt_msec)); |
| 703 estimator.set_downlink_throughput_kbps(INT32_MAX); | 717 estimator.set_start_time_null_downlink_throughput_kbps(INT32_MAX); |
| 704 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | 718 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| 705 // Run one main frame request to force recomputation of effective connection | 719 // Run one main frame request to force recomputation of effective connection |
| 706 // type. | 720 // type. |
| 707 estimator.RunOneRequest(); | 721 estimator.RunOneRequest(); |
| 708 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 722 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 709 } | 723 } |
| 710 } | 724 } |
| 711 | 725 |
| 712 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 726 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 713 // only transport RTT thresholds are specified in the variation params. | 727 // only transport RTT thresholds are specified in the variation params. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 742 {700, EFFECTIVE_CONNECTION_TYPE_3G}, | 756 {700, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 743 {500, EFFECTIVE_CONNECTION_TYPE_3G}, | 757 {500, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 744 {400, EFFECTIVE_CONNECTION_TYPE_4G}, | 758 {400, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 745 {300, EFFECTIVE_CONNECTION_TYPE_4G}, | 759 {300, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 746 {200, EFFECTIVE_CONNECTION_TYPE_4G}, | 760 {200, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 747 {100, EFFECTIVE_CONNECTION_TYPE_4G}, | 761 {100, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 748 {20, EFFECTIVE_CONNECTION_TYPE_4G}, | 762 {20, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 749 }; | 763 }; |
| 750 | 764 |
| 751 for (const auto& test : tests) { | 765 for (const auto& test : tests) { |
| 752 estimator.set_transport_rtt( | 766 estimator.set_start_time_null_transport_rtt( |
| 753 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); | 767 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 754 estimator.set_recent_transport_rtt( | 768 estimator.set_recent_transport_rtt( |
| 755 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); | 769 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 756 estimator.set_downlink_throughput_kbps(INT32_MAX); | 770 estimator.set_start_time_null_downlink_throughput_kbps(INT32_MAX); |
| 757 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); | 771 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); |
| 758 // Run one main frame request to force recomputation of effective connection | 772 // Run one main frame request to force recomputation of effective connection |
| 759 // type. | 773 // type. |
| 760 estimator.RunOneRequest(); | 774 estimator.RunOneRequest(); |
| 761 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 775 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 762 } | 776 } |
| 763 } | 777 } |
| 764 | 778 |
| 765 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 779 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 766 // both HTTP RTT and throughput thresholds are specified in the variation | 780 // both HTTP RTT and throughput thresholds are specified in the variation |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 {1, 700, EFFECTIVE_CONNECTION_TYPE_4G}, | 819 {1, 700, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 806 {1, 1000, EFFECTIVE_CONNECTION_TYPE_4G}, | 820 {1, 1000, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 807 {1, 1500, EFFECTIVE_CONNECTION_TYPE_4G}, | 821 {1, 1500, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 808 {1, 2500, EFFECTIVE_CONNECTION_TYPE_4G}, | 822 {1, 2500, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 809 // Set both RTT and throughput. RTT is the bottleneck. | 823 // Set both RTT and throughput. RTT is the bottleneck. |
| 810 {3000, 25000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 824 {3000, 25000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 811 {700, 25000, EFFECTIVE_CONNECTION_TYPE_3G}, | 825 {700, 25000, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 812 }; | 826 }; |
| 813 | 827 |
| 814 for (const auto& test : tests) { | 828 for (const auto& test : tests) { |
| 815 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 829 estimator.set_start_time_null_http_rtt( |
| 830 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 816 estimator.set_recent_http_rtt( | 831 estimator.set_recent_http_rtt( |
| 817 base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 832 base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 818 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); | 833 estimator.set_start_time_null_downlink_throughput_kbps( |
| 834 test.downlink_throughput_kbps); |
| 819 estimator.set_recent_downlink_throughput_kbps( | 835 estimator.set_recent_downlink_throughput_kbps( |
| 820 test.downlink_throughput_kbps); | 836 test.downlink_throughput_kbps); |
| 821 // Run one main frame request to force recomputation of effective connection | 837 // Run one main frame request to force recomputation of effective connection |
| 822 // type. | 838 // type. |
| 823 estimator.RunOneRequest(); | 839 estimator.RunOneRequest(); |
| 824 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 840 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 825 } | 841 } |
| 826 } | 842 } |
| 827 | 843 |
| 828 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 844 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 {1, 700, EFFECTIVE_CONNECTION_TYPE_4G}, | 886 {1, 700, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 871 {1, 1000, EFFECTIVE_CONNECTION_TYPE_4G}, | 887 {1, 1000, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 872 {1, 1500, EFFECTIVE_CONNECTION_TYPE_4G}, | 888 {1, 1500, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 873 {1, 2500, EFFECTIVE_CONNECTION_TYPE_4G}, | 889 {1, 2500, EFFECTIVE_CONNECTION_TYPE_4G}, |
| 874 // Set both RTT and throughput. RTT is the bottleneck. | 890 // Set both RTT and throughput. RTT is the bottleneck. |
| 875 {3000, 25000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 891 {3000, 25000, EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 876 {700, 25000, EFFECTIVE_CONNECTION_TYPE_3G}, | 892 {700, 25000, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 877 }; | 893 }; |
| 878 | 894 |
| 879 for (const auto& test : tests) { | 895 for (const auto& test : tests) { |
| 880 estimator.set_transport_rtt( | 896 estimator.set_start_time_null_transport_rtt( |
| 881 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); | 897 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 882 estimator.set_recent_transport_rtt( | 898 estimator.set_recent_transport_rtt( |
| 883 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); | 899 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec)); |
| 884 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); | 900 estimator.set_start_time_null_downlink_throughput_kbps( |
| 901 test.downlink_throughput_kbps); |
| 885 estimator.set_recent_downlink_throughput_kbps( | 902 estimator.set_recent_downlink_throughput_kbps( |
| 886 test.downlink_throughput_kbps); | 903 test.downlink_throughput_kbps); |
| 887 // Run one main frame request to force recomputation of effective connection | 904 // Run one main frame request to force recomputation of effective connection |
| 888 // type. | 905 // type. |
| 889 estimator.RunOneRequest(); | 906 estimator.RunOneRequest(); |
| 890 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 907 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 891 } | 908 } |
| 892 } | 909 } |
| 893 | 910 |
| 894 // Tests if |weight_multiplier_per_second_| is set to correct value for various | 911 // Tests if |weight_multiplier_per_second_| is set to correct value for various |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 invalid_external_estimate_provider); | 1094 invalid_external_estimate_provider); |
| 1078 | 1095 |
| 1079 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), | 1096 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), |
| 1080 std::move(external_estimate_provider)); | 1097 std::move(external_estimate_provider)); |
| 1081 estimator.SimulateNetworkChange(net::NetworkChangeNotifier::CONNECTION_WIFI, | 1098 estimator.SimulateNetworkChange(net::NetworkChangeNotifier::CONNECTION_WIFI, |
| 1082 "test"); | 1099 "test"); |
| 1083 | 1100 |
| 1084 base::TimeDelta rtt; | 1101 base::TimeDelta rtt; |
| 1085 int32_t kbps; | 1102 int32_t kbps; |
| 1086 EXPECT_EQ(1U, invalid_external_estimate_provider->update_count()); | 1103 EXPECT_EQ(1U, invalid_external_estimate_provider->update_count()); |
| 1087 EXPECT_FALSE(estimator.GetHttpRTT(&rtt)); | 1104 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1088 EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps)); | 1105 EXPECT_FALSE( |
| 1106 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1089 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 2); | 1107 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 2); |
| 1090 | 1108 |
| 1091 histogram_tester.ExpectBucketCount( | 1109 histogram_tester.ExpectBucketCount( |
| 1092 "NQE.ExternalEstimateProviderStatus", | 1110 "NQE.ExternalEstimateProviderStatus", |
| 1093 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); | 1111 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); |
| 1094 histogram_tester.ExpectBucketCount( | 1112 histogram_tester.ExpectBucketCount( |
| 1095 "NQE.ExternalEstimateProviderStatus", | 1113 "NQE.ExternalEstimateProviderStatus", |
| 1096 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); | 1114 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); |
| 1097 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProvider.RTT", 0); | 1115 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProvider.RTT", 0); |
| 1098 histogram_tester.ExpectTotalCount( | 1116 histogram_tester.ExpectTotalCount( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 external_estimate_provider_downstream_throughput); | 1197 external_estimate_provider_downstream_throughput); |
| 1180 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( | 1198 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( |
| 1181 test_external_estimate_provider); | 1199 test_external_estimate_provider); |
| 1182 std::map<std::string, std::string> variation_params; | 1200 std::map<std::string, std::string> variation_params; |
| 1183 TestNetworkQualityEstimator estimator(variation_params, | 1201 TestNetworkQualityEstimator estimator(variation_params, |
| 1184 std::move(external_estimate_provider)); | 1202 std::move(external_estimate_provider)); |
| 1185 estimator.SimulateNetworkChange(net::NetworkChangeNotifier::CONNECTION_WIFI, | 1203 estimator.SimulateNetworkChange(net::NetworkChangeNotifier::CONNECTION_WIFI, |
| 1186 "test"); | 1204 "test"); |
| 1187 base::TimeDelta rtt; | 1205 base::TimeDelta rtt; |
| 1188 int32_t kbps; | 1206 int32_t kbps; |
| 1189 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); | 1207 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1190 EXPECT_FALSE(estimator.GetTransportRTT(&rtt)); | 1208 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 1191 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps)); | 1209 EXPECT_TRUE( |
| 1210 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1192 | 1211 |
| 1193 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 5); | 1212 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 5); |
| 1194 | 1213 |
| 1195 histogram_tester.ExpectBucketCount( | 1214 histogram_tester.ExpectBucketCount( |
| 1196 "NQE.ExternalEstimateProviderStatus", | 1215 "NQE.ExternalEstimateProviderStatus", |
| 1197 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); | 1216 1 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE */, 1); |
| 1198 histogram_tester.ExpectBucketCount( | 1217 histogram_tester.ExpectBucketCount( |
| 1199 "NQE.ExternalEstimateProviderStatus", | 1218 "NQE.ExternalEstimateProviderStatus", |
| 1200 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); | 1219 2 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED */, 1); |
| 1201 histogram_tester.ExpectBucketCount( | 1220 histogram_tester.ExpectBucketCount( |
| 1202 "NQE.ExternalEstimateProviderStatus", | 1221 "NQE.ExternalEstimateProviderStatus", |
| 1203 4 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK */, 1); | 1222 4 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK */, 1); |
| 1204 histogram_tester.ExpectBucketCount( | 1223 histogram_tester.ExpectBucketCount( |
| 1205 "NQE.ExternalEstimateProviderStatus", | 1224 "NQE.ExternalEstimateProviderStatus", |
| 1206 5 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE */, 1); | 1225 5 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE */, 1); |
| 1207 histogram_tester.ExpectBucketCount( | 1226 histogram_tester.ExpectBucketCount( |
| 1208 "NQE.ExternalEstimateProviderStatus", | 1227 "NQE.ExternalEstimateProviderStatus", |
| 1209 6 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE */, | 1228 6 /* EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE */, |
| 1210 1); | 1229 1); |
| 1211 histogram_tester.ExpectUniqueSample("NQE.ExternalEstimateProvider.RTT", 1, 1); | 1230 histogram_tester.ExpectUniqueSample("NQE.ExternalEstimateProvider.RTT", 1, 1); |
| 1212 histogram_tester.ExpectUniqueSample( | 1231 histogram_tester.ExpectUniqueSample( |
| 1213 "NQE.ExternalEstimateProvider.DownlinkBandwidth", 100, 1); | 1232 "NQE.ExternalEstimateProvider.DownlinkBandwidth", 100, 1); |
| 1214 | 1233 |
| 1215 EXPECT_EQ(1U, test_external_estimate_provider->update_count()); | 1234 EXPECT_EQ(1U, test_external_estimate_provider->update_count()); |
| 1216 | 1235 |
| 1217 // Change network type to WiFi. Number of queries to External estimate | 1236 // Change network type to WiFi. Number of queries to External estimate |
| 1218 // provider must increment. | 1237 // provider must increment. |
| 1219 estimator.SimulateNetworkChange( | 1238 estimator.SimulateNetworkChange( |
| 1220 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 1239 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
| 1221 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); | 1240 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1222 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps)); | 1241 EXPECT_TRUE( |
| 1242 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1223 EXPECT_EQ(2U, test_external_estimate_provider->update_count()); | 1243 EXPECT_EQ(2U, test_external_estimate_provider->update_count()); |
| 1224 | 1244 |
| 1225 test_external_estimate_provider->set_should_notify_delegate(false); | 1245 test_external_estimate_provider->set_should_notify_delegate(false); |
| 1226 estimator.SimulateNetworkChange( | 1246 estimator.SimulateNetworkChange( |
| 1227 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); | 1247 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); |
| 1228 EXPECT_EQ(3U, test_external_estimate_provider->update_count()); | 1248 EXPECT_EQ(3U, test_external_estimate_provider->update_count()); |
| 1229 // Estimates are unavailable because external estimate provider never | 1249 // Estimates are unavailable because external estimate provider never |
| 1230 // notifies network quality estimator of the updated estimates. | 1250 // notifies network quality estimator of the updated estimates. |
| 1231 EXPECT_FALSE(estimator.GetHttpRTT(&rtt)); | 1251 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1232 EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps)); | 1252 EXPECT_FALSE( |
| 1253 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1233 } | 1254 } |
| 1234 | 1255 |
| 1235 // Tests if the estimate from the external estimate provider is merged with the | 1256 // Tests if the estimate from the external estimate provider is merged with the |
| 1236 // observations collected from the HTTP requests. | 1257 // observations collected from the HTTP requests. |
| 1237 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProviderMergeEstimates) { | 1258 TEST(NetworkQualityEstimatorTest, TestExternalEstimateProviderMergeEstimates) { |
| 1238 const base::TimeDelta external_estimate_provider_rtt = | 1259 const base::TimeDelta external_estimate_provider_rtt = |
| 1239 base::TimeDelta::FromMilliseconds(10 * 1000); | 1260 base::TimeDelta::FromMilliseconds(10 * 1000); |
| 1240 const int32_t external_estimate_provider_downstream_throughput = 100 * 1000; | 1261 const int32_t external_estimate_provider_downstream_throughput = 100 * 1000; |
| 1241 TestExternalEstimateProvider* test_external_estimate_provider = | 1262 TestExternalEstimateProvider* test_external_estimate_provider = |
| 1242 new TestExternalEstimateProvider( | 1263 new TestExternalEstimateProvider( |
| 1243 external_estimate_provider_rtt, | 1264 external_estimate_provider_rtt, |
| 1244 external_estimate_provider_downstream_throughput); | 1265 external_estimate_provider_downstream_throughput); |
| 1245 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( | 1266 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( |
| 1246 test_external_estimate_provider); | 1267 test_external_estimate_provider); |
| 1247 | 1268 |
| 1248 std::map<std::string, std::string> variation_params; | 1269 std::map<std::string, std::string> variation_params; |
| 1249 TestNetworkQualityEstimator estimator(variation_params, | 1270 TestNetworkQualityEstimator estimator(variation_params, |
| 1250 std::move(external_estimate_provider)); | 1271 std::move(external_estimate_provider)); |
| 1251 estimator.SimulateNetworkChange(net::NetworkChangeNotifier::CONNECTION_WIFI, | 1272 estimator.SimulateNetworkChange(net::NetworkChangeNotifier::CONNECTION_WIFI, |
| 1252 "test"); | 1273 "test"); |
| 1253 | 1274 |
| 1254 base::TimeDelta rtt; | 1275 base::TimeDelta rtt; |
| 1255 // Estimate provided by network quality estimator should match the estimate | 1276 // Estimate provided by network quality estimator should match the estimate |
| 1256 // provided by external estimate provider. | 1277 // provided by external estimate provider. |
| 1257 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); | 1278 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1258 EXPECT_EQ(external_estimate_provider_rtt, rtt); | 1279 EXPECT_EQ(external_estimate_provider_rtt, rtt); |
| 1259 | 1280 |
| 1260 int32_t kbps; | 1281 int32_t kbps; |
| 1261 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps)); | 1282 EXPECT_TRUE( |
| 1283 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1262 EXPECT_EQ(external_estimate_provider_downstream_throughput, kbps); | 1284 EXPECT_EQ(external_estimate_provider_downstream_throughput, kbps); |
| 1263 | 1285 |
| 1264 TestDelegate test_delegate; | 1286 TestDelegate test_delegate; |
| 1265 TestURLRequestContext context(true); | 1287 TestURLRequestContext context(true); |
| 1266 context.set_network_quality_estimator(&estimator); | 1288 context.set_network_quality_estimator(&estimator); |
| 1267 context.Init(); | 1289 context.Init(); |
| 1268 | 1290 |
| 1269 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1291 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1270 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1292 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1271 request->Start(); | 1293 request->Start(); |
| 1272 base::RunLoop().Run(); | 1294 base::RunLoop().Run(); |
| 1273 | 1295 |
| 1274 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); | 1296 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1275 EXPECT_NE(external_estimate_provider_rtt, rtt); | 1297 EXPECT_NE(external_estimate_provider_rtt, rtt); |
| 1276 | 1298 |
| 1277 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&kbps)); | 1299 EXPECT_TRUE( |
| 1300 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1278 EXPECT_NE(external_estimate_provider_downstream_throughput, kbps); | 1301 EXPECT_NE(external_estimate_provider_downstream_throughput, kbps); |
| 1279 } | 1302 } |
| 1280 | 1303 |
| 1281 // Tests if the throughput observation is taken correctly when local and network | 1304 // Tests if the throughput observation is taken correctly when local and network |
| 1282 // requests do not overlap. | 1305 // requests do not overlap. |
| 1283 TEST(NetworkQualityEstimatorTest, TestThroughputNoRequestOverlap) { | 1306 TEST(NetworkQualityEstimatorTest, TestThroughputNoRequestOverlap) { |
| 1284 base::HistogramTester histogram_tester; | 1307 base::HistogramTester histogram_tester; |
| 1285 std::map<std::string, std::string> variation_params; | 1308 std::map<std::string, std::string> variation_params; |
| 1286 | 1309 |
| 1287 static const struct { | 1310 static const struct { |
| 1288 bool allow_small_localhost_requests; | 1311 bool allow_small_localhost_requests; |
| 1289 } tests[] = { | 1312 } tests[] = { |
| 1290 { | 1313 { |
| 1291 false, | 1314 false, |
| 1292 }, | 1315 }, |
| 1293 { | 1316 { |
| 1294 true, | 1317 true, |
| 1295 }, | 1318 }, |
| 1296 }; | 1319 }; |
| 1297 | 1320 |
| 1298 for (const auto& test : tests) { | 1321 for (const auto& test : tests) { |
| 1299 TestNetworkQualityEstimator estimator( | 1322 TestNetworkQualityEstimator estimator( |
| 1300 std::unique_ptr<net::ExternalEstimateProvider>(), variation_params, | 1323 std::unique_ptr<net::ExternalEstimateProvider>(), variation_params, |
| 1301 test.allow_small_localhost_requests, | 1324 test.allow_small_localhost_requests, |
| 1302 test.allow_small_localhost_requests); | 1325 test.allow_small_localhost_requests); |
| 1303 | 1326 |
| 1304 base::TimeDelta rtt; | 1327 base::TimeDelta rtt; |
| 1305 EXPECT_FALSE(estimator.GetHttpRTT(&rtt)); | 1328 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1306 int32_t kbps; | 1329 int32_t kbps; |
| 1307 EXPECT_FALSE(estimator.GetDownlinkThroughputKbps(&kbps)); | 1330 EXPECT_FALSE( |
| 1331 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1308 | 1332 |
| 1309 TestDelegate test_delegate; | 1333 TestDelegate test_delegate; |
| 1310 TestURLRequestContext context(true); | 1334 TestURLRequestContext context(true); |
| 1311 context.set_network_quality_estimator(&estimator); | 1335 context.set_network_quality_estimator(&estimator); |
| 1312 context.Init(); | 1336 context.Init(); |
| 1313 | 1337 |
| 1314 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1338 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1315 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1339 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1316 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1340 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1317 request->Start(); | 1341 request->Start(); |
| 1318 base::RunLoop().Run(); | 1342 base::RunLoop().Run(); |
| 1319 | 1343 |
| 1320 EXPECT_EQ(test.allow_small_localhost_requests, estimator.GetHttpRTT(&rtt)); | |
| 1321 EXPECT_EQ(test.allow_small_localhost_requests, | 1344 EXPECT_EQ(test.allow_small_localhost_requests, |
| 1322 estimator.GetDownlinkThroughputKbps(&kbps)); | 1345 estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1346 EXPECT_EQ( |
| 1347 test.allow_small_localhost_requests, |
| 1348 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1323 } | 1349 } |
| 1324 } | 1350 } |
| 1325 | 1351 |
| 1326 // Tests that the effective connection type is computed at the specified | 1352 // Tests that the effective connection type is computed at the specified |
| 1327 // interval, and that the observers are notified of any change. | 1353 // interval, and that the observers are notified of any change. |
| 1328 TEST(NetworkQualityEstimatorTest, TestEffectiveConnectionTypeObserver) { | 1354 TEST(NetworkQualityEstimatorTest, TestEffectiveConnectionTypeObserver) { |
| 1329 base::HistogramTester histogram_tester; | 1355 base::HistogramTester histogram_tester; |
| 1330 std::unique_ptr<base::SimpleTestTickClock> tick_clock( | 1356 std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| 1331 new base::SimpleTestTickClock()); | 1357 new base::SimpleTestTickClock()); |
| 1332 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1358 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 1333 | 1359 |
| 1334 TestEffectiveConnectionTypeObserver observer; | 1360 TestEffectiveConnectionTypeObserver observer; |
| 1335 std::map<std::string, std::string> variation_params; | 1361 std::map<std::string, std::string> variation_params; |
| 1336 TestNetworkQualityEstimator estimator(variation_params); | 1362 TestNetworkQualityEstimator estimator(variation_params); |
| 1337 estimator.AddEffectiveConnectionTypeObserver(&observer); | 1363 estimator.AddEffectiveConnectionTypeObserver(&observer); |
| 1338 estimator.SetTickClockForTesting(std::move(tick_clock)); | 1364 estimator.SetTickClockForTesting(std::move(tick_clock)); |
| 1339 | 1365 |
| 1340 TestDelegate test_delegate; | 1366 TestDelegate test_delegate; |
| 1341 TestURLRequestContext context(true); | 1367 TestURLRequestContext context(true); |
| 1342 context.set_network_quality_estimator(&estimator); | 1368 context.set_network_quality_estimator(&estimator); |
| 1343 context.Init(); | 1369 context.Init(); |
| 1344 | 1370 |
| 1345 EXPECT_EQ(0U, observer.effective_connection_types().size()); | 1371 EXPECT_EQ(0U, observer.effective_connection_types().size()); |
| 1346 | 1372 |
| 1347 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); | 1373 estimator.set_start_time_null_http_rtt( |
| 1374 base::TimeDelta::FromMilliseconds(1500)); |
| 1375 estimator.set_start_time_null_downlink_throughput_kbps(100000); |
| 1376 |
| 1348 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); | 1377 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
| 1349 | 1378 |
| 1350 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1379 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1351 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1380 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1352 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1381 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1353 request->Start(); | 1382 request->Start(); |
| 1354 base::RunLoop().Run(); | 1383 base::RunLoop().Run(); |
| 1355 EXPECT_EQ(1U, observer.effective_connection_types().size()); | 1384 EXPECT_EQ(1U, observer.effective_connection_types().size()); |
| 1356 histogram_tester.ExpectUniqueSample("NQE.MainFrame.EffectiveConnectionType", | 1385 histogram_tester.ExpectUniqueSample("NQE.MainFrame.EffectiveConnectionType", |
| 1357 EFFECTIVE_CONNECTION_TYPE_2G, 1); | 1386 EFFECTIVE_CONNECTION_TYPE_2G, 1); |
| 1358 histogram_tester.ExpectUniqueSample( | 1387 histogram_tester.ExpectUniqueSample( |
| 1359 "NQE.MainFrame.EffectiveConnectionType.Unknown", | 1388 "NQE.MainFrame.EffectiveConnectionType.Unknown", |
| 1360 EFFECTIVE_CONNECTION_TYPE_2G, 1); | 1389 EFFECTIVE_CONNECTION_TYPE_2G, 1); |
| 1361 | 1390 |
| 1362 // Next request should not trigger recomputation of effective connection type | 1391 // Next request should not trigger recomputation of effective connection type |
| 1363 // since there has been no change in the clock. | 1392 // since there has been no change in the clock. |
| 1364 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 1393 std::unique_ptr<URLRequest> request2(context.CreateRequest( |
| 1365 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1394 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1366 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1395 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1367 request2->Start(); | 1396 request2->Start(); |
| 1368 base::RunLoop().Run(); | 1397 base::RunLoop().Run(); |
| 1369 EXPECT_EQ(1U, observer.effective_connection_types().size()); | 1398 EXPECT_EQ(1U, observer.effective_connection_types().size()); |
| 1370 | 1399 |
| 1371 // Change in connection type should send out notification to the observers. | 1400 // Change in connection type should send out notification to the observers. |
| 1372 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); | 1401 estimator.set_start_time_null_http_rtt( |
| 1402 base::TimeDelta::FromMilliseconds(500)); |
| 1373 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, | 1403 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, |
| 1374 "test"); | 1404 "test"); |
| 1375 EXPECT_EQ(2U, observer.effective_connection_types().size()); | 1405 EXPECT_EQ(2U, observer.effective_connection_types().size()); |
| 1376 | 1406 |
| 1377 // A change in effective connection type does not trigger notification to the | 1407 // A change in effective connection type does not trigger notification to the |
| 1378 // observers, since it is not accompanied by any new observation or a network | 1408 // observers, since it is not accompanied by any new observation or a network |
| 1379 // change event. | 1409 // change event. |
| 1380 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); | 1410 estimator.set_start_time_null_http_rtt( |
| 1411 base::TimeDelta::FromMilliseconds(100)); |
| 1381 EXPECT_EQ(2U, observer.effective_connection_types().size()); | 1412 EXPECT_EQ(2U, observer.effective_connection_types().size()); |
| 1382 } | 1413 } |
| 1383 | 1414 |
| 1384 // Tests that the network quality is computed at the specified interval, and | 1415 // Tests that the network quality is computed at the specified interval, and |
| 1385 // that the network quality observers are notified of any change. | 1416 // that the network quality observers are notified of any change. |
| 1386 TEST(NetworkQualityEstimatorTest, TestRTTAndThroughputEstimatesObserver) { | 1417 TEST(NetworkQualityEstimatorTest, TestRTTAndThroughputEstimatesObserver) { |
| 1387 base::HistogramTester histogram_tester; | 1418 base::HistogramTester histogram_tester; |
| 1388 std::unique_ptr<base::SimpleTestTickClock> tick_clock( | 1419 std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| 1389 new base::SimpleTestTickClock()); | 1420 new base::SimpleTestTickClock()); |
| 1390 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1421 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1403 EXPECT_EQ(nqe::internal::InvalidRTT(), observer.http_rtt()); | 1434 EXPECT_EQ(nqe::internal::InvalidRTT(), observer.http_rtt()); |
| 1404 EXPECT_EQ(nqe::internal::InvalidRTT(), observer.transport_rtt()); | 1435 EXPECT_EQ(nqe::internal::InvalidRTT(), observer.transport_rtt()); |
| 1405 EXPECT_EQ(nqe::internal::kInvalidThroughput, | 1436 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
| 1406 observer.downstream_throughput_kbps()); | 1437 observer.downstream_throughput_kbps()); |
| 1407 int notifications_received = observer.notifications_received(); | 1438 int notifications_received = observer.notifications_received(); |
| 1408 EXPECT_EQ(0, notifications_received); | 1439 EXPECT_EQ(0, notifications_received); |
| 1409 | 1440 |
| 1410 base::TimeDelta http_rtt(base::TimeDelta::FromMilliseconds(100)); | 1441 base::TimeDelta http_rtt(base::TimeDelta::FromMilliseconds(100)); |
| 1411 base::TimeDelta transport_rtt(base::TimeDelta::FromMilliseconds(200)); | 1442 base::TimeDelta transport_rtt(base::TimeDelta::FromMilliseconds(200)); |
| 1412 int32_t downstream_throughput_kbps(300); | 1443 int32_t downstream_throughput_kbps(300); |
| 1413 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); | 1444 estimator.set_start_time_null_http_rtt(http_rtt); |
| 1414 estimator.set_recent_http_rtt(http_rtt); | 1445 estimator.set_start_time_null_transport_rtt(transport_rtt); |
| 1415 estimator.set_recent_transport_rtt(transport_rtt); | 1446 estimator.set_start_time_null_downlink_throughput_kbps( |
| 1416 estimator.set_recent_downlink_throughput_kbps(downstream_throughput_kbps); | 1447 downstream_throughput_kbps); |
| 1417 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); | 1448 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
| 1418 | 1449 |
| 1419 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1450 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1420 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1451 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1421 request->Start(); | 1452 request->Start(); |
| 1422 base::RunLoop().Run(); | 1453 base::RunLoop().Run(); |
| 1423 EXPECT_EQ(http_rtt, observer.http_rtt()); | 1454 EXPECT_EQ(http_rtt, observer.http_rtt()); |
| 1424 EXPECT_EQ(transport_rtt, observer.transport_rtt()); | 1455 EXPECT_EQ(transport_rtt, observer.transport_rtt()); |
| 1425 EXPECT_EQ(downstream_throughput_kbps, observer.downstream_throughput_kbps()); | 1456 EXPECT_EQ(downstream_throughput_kbps, observer.downstream_throughput_kbps()); |
| 1426 EXPECT_LE(1, observer.notifications_received() - notifications_received); | 1457 EXPECT_LE(1, observer.notifications_received() - notifications_received); |
| 1427 notifications_received = observer.notifications_received(); | 1458 notifications_received = observer.notifications_received(); |
| 1428 | 1459 |
| 1429 // The next request should not trigger recomputation of RTT or throughput | 1460 // The next request should not trigger recomputation of RTT or throughput |
| 1430 // since there has been no change in the clock. | 1461 // since there has been no change in the clock. |
| 1431 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 1462 std::unique_ptr<URLRequest> request2(context.CreateRequest( |
| 1432 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1463 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1433 request2->Start(); | 1464 request2->Start(); |
| 1434 base::RunLoop().Run(); | 1465 base::RunLoop().Run(); |
| 1435 EXPECT_LE(1, observer.notifications_received() - notifications_received); | 1466 EXPECT_LE(1, observer.notifications_received() - notifications_received); |
| 1436 notifications_received = observer.notifications_received(); | 1467 notifications_received = observer.notifications_received(); |
| 1437 | 1468 |
| 1438 // A change in the connection type should send out notification to the | 1469 // A change in the connection type should send out notification to the |
| 1439 // observers. | 1470 // observers. |
| 1440 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); | |
| 1441 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, | 1471 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, |
| 1442 "test"); | 1472 "test"); |
| 1473 EXPECT_EQ(http_rtt, observer.http_rtt()); |
| 1474 EXPECT_EQ(transport_rtt, observer.transport_rtt()); |
| 1475 EXPECT_EQ(downstream_throughput_kbps, observer.downstream_throughput_kbps()); |
| 1443 EXPECT_LE(1, observer.notifications_received() - notifications_received); | 1476 EXPECT_LE(1, observer.notifications_received() - notifications_received); |
| 1444 notifications_received = observer.notifications_received(); | 1477 notifications_received = observer.notifications_received(); |
| 1445 | 1478 |
| 1446 // A change in effective connection type does not trigger notification to the | 1479 // A change in effective connection type does not trigger notification to the |
| 1447 // observers, since it is not accompanied by any new observation or a network | 1480 // observers, since it is not accompanied by any new observation or a network |
| 1448 // change event. | 1481 // change event. |
| 1449 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); | 1482 estimator.set_start_time_null_http_rtt( |
| 1483 base::TimeDelta::FromMilliseconds(10000)); |
| 1484 estimator.set_start_time_null_http_rtt(base::TimeDelta::FromMilliseconds(1)); |
| 1450 EXPECT_EQ(0, observer.notifications_received() - notifications_received); | 1485 EXPECT_EQ(0, observer.notifications_received() - notifications_received); |
| 1451 } | 1486 } |
| 1452 | 1487 |
| 1453 // Tests that the effective connection type is computed on every RTT | 1488 // Tests that the effective connection type is computed on every RTT |
| 1454 // observation if the last computed effective connection type was unknown. | 1489 // observation if the last computed effective connection type was unknown. |
| 1455 TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) { | 1490 TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) { |
| 1456 std::unique_ptr<base::SimpleTestTickClock> tick_clock( | 1491 std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| 1457 new base::SimpleTestTickClock()); | 1492 new base::SimpleTestTickClock()); |
| 1458 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1493 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 1459 | 1494 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1604 base::RunLoop().Run(); | 1639 base::RunLoop().Run(); |
| 1605 | 1640 |
| 1606 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 1641 std::unique_ptr<URLRequest> request2(context.CreateRequest( |
| 1607 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1642 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1608 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1643 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1609 request2->Start(); | 1644 request2->Start(); |
| 1610 base::RunLoop().Run(); | 1645 base::RunLoop().Run(); |
| 1611 | 1646 |
| 1612 // Both RTT and downstream throughput should be updated. | 1647 // Both RTT and downstream throughput should be updated. |
| 1613 base::TimeDelta rtt; | 1648 base::TimeDelta rtt; |
| 1614 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); | 1649 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1615 | 1650 |
| 1616 int32_t throughput; | 1651 int32_t throughput; |
| 1617 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&throughput)); | 1652 EXPECT_TRUE(estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), |
| 1653 &throughput)); |
| 1618 | 1654 |
| 1619 EXPECT_EQ(2U, rtt_observer.observations().size()); | 1655 EXPECT_EQ(2U, rtt_observer.observations().size()); |
| 1620 EXPECT_EQ(2U, throughput_observer.observations().size()); | 1656 EXPECT_EQ(2U, throughput_observer.observations().size()); |
| 1621 for (const auto& observation : rtt_observer.observations()) { | 1657 for (const auto& observation : rtt_observer.observations()) { |
| 1622 EXPECT_LE(0, observation.rtt_ms); | 1658 EXPECT_LE(0, observation.rtt_ms); |
| 1623 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); | 1659 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); |
| 1624 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, observation.source); | 1660 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, observation.source); |
| 1625 } | 1661 } |
| 1626 for (const auto& observation : throughput_observer.observations()) { | 1662 for (const auto& observation : throughput_observer.observations()) { |
| 1627 EXPECT_LE(0, observation.throughput_kbps); | 1663 EXPECT_LE(0, observation.throughput_kbps); |
| 1628 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); | 1664 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); |
| 1629 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, observation.source); | 1665 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, observation.source); |
| 1630 } | 1666 } |
| 1631 | 1667 |
| 1632 EXPECT_FALSE(estimator.GetTransportRTT(&rtt)); | 1668 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 1633 | 1669 |
| 1634 // Verify that observations from TCP and QUIC are passed on to the observers. | 1670 // Verify that observations from TCP and QUIC are passed on to the observers. |
| 1635 base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1)); | 1671 base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1)); |
| 1636 base::TimeDelta quic_rtt(base::TimeDelta::FromMilliseconds(2)); | 1672 base::TimeDelta quic_rtt(base::TimeDelta::FromMilliseconds(2)); |
| 1637 | 1673 |
| 1638 std::unique_ptr<SocketPerformanceWatcher> tcp_watcher = | 1674 std::unique_ptr<SocketPerformanceWatcher> tcp_watcher = |
| 1639 estimator.GetSocketPerformanceWatcherFactory() | 1675 estimator.GetSocketPerformanceWatcherFactory() |
| 1640 ->CreateSocketPerformanceWatcher( | 1676 ->CreateSocketPerformanceWatcher( |
| 1641 SocketPerformanceWatcherFactory::PROTOCOL_TCP); | 1677 SocketPerformanceWatcherFactory::PROTOCOL_TCP); |
| 1642 | 1678 |
| 1643 std::unique_ptr<SocketPerformanceWatcher> quic_watcher = | 1679 std::unique_ptr<SocketPerformanceWatcher> quic_watcher = |
| 1644 estimator.GetSocketPerformanceWatcherFactory() | 1680 estimator.GetSocketPerformanceWatcherFactory() |
| 1645 ->CreateSocketPerformanceWatcher( | 1681 ->CreateSocketPerformanceWatcher( |
| 1646 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); | 1682 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); |
| 1647 | 1683 |
| 1648 tcp_watcher->OnUpdatedRTTAvailable(tcp_rtt); | 1684 tcp_watcher->OnUpdatedRTTAvailable(tcp_rtt); |
| 1649 quic_watcher->OnUpdatedRTTAvailable(quic_rtt); | 1685 quic_watcher->OnUpdatedRTTAvailable(quic_rtt); |
| 1650 | 1686 |
| 1651 base::RunLoop().RunUntilIdle(); | 1687 base::RunLoop().RunUntilIdle(); |
| 1652 | 1688 |
| 1653 EXPECT_EQ(4U, rtt_observer.observations().size()); | 1689 EXPECT_EQ(4U, rtt_observer.observations().size()); |
| 1654 EXPECT_EQ(2U, throughput_observer.observations().size()); | 1690 EXPECT_EQ(2U, throughput_observer.observations().size()); |
| 1655 | 1691 |
| 1656 EXPECT_EQ(tcp_rtt.InMilliseconds(), rtt_observer.observations().at(2).rtt_ms); | 1692 EXPECT_EQ(tcp_rtt.InMilliseconds(), rtt_observer.observations().at(2).rtt_ms); |
| 1657 EXPECT_EQ(quic_rtt.InMilliseconds(), | 1693 EXPECT_EQ(quic_rtt.InMilliseconds(), |
| 1658 rtt_observer.observations().at(3).rtt_ms); | 1694 rtt_observer.observations().at(3).rtt_ms); |
| 1659 | 1695 |
| 1660 EXPECT_TRUE(estimator.GetTransportRTT(&rtt)); | 1696 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 1661 } | 1697 } |
| 1662 | 1698 |
| 1663 // TestTCPSocketRTT requires kernel support for tcp_info struct, and so it is | 1699 // TestTCPSocketRTT requires kernel support for tcp_info struct, and so it is |
| 1664 // enabled only on certain platforms. | 1700 // enabled only on certain platforms. |
| 1665 #if defined(TCP_INFO) || defined(OS_LINUX) | 1701 #if defined(TCP_INFO) || defined(OS_LINUX) |
| 1666 #define MAYBE_TestTCPSocketRTT TestTCPSocketRTT | 1702 #define MAYBE_TestTCPSocketRTT TestTCPSocketRTT |
| 1667 #else | 1703 #else |
| 1668 #define MAYBE_TestTCPSocketRTT DISABLED_TestTCPSocketRTT | 1704 #define MAYBE_TestTCPSocketRTT DISABLED_TestTCPSocketRTT |
| 1669 #endif | 1705 #endif |
| 1670 // Tests that the TCP socket notifies the Network Quality Estimator of TCP RTTs, | 1706 // Tests that the TCP socket notifies the Network Quality Estimator of TCP RTTs, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1683 std::unique_ptr<HttpNetworkSession::Params> params( | 1719 std::unique_ptr<HttpNetworkSession::Params> params( |
| 1684 new HttpNetworkSession::Params); | 1720 new HttpNetworkSession::Params); |
| 1685 // |estimator| should be notified of TCP RTT observations. | 1721 // |estimator| should be notified of TCP RTT observations. |
| 1686 params->socket_performance_watcher_factory = | 1722 params->socket_performance_watcher_factory = |
| 1687 estimator.GetSocketPerformanceWatcherFactory(); | 1723 estimator.GetSocketPerformanceWatcherFactory(); |
| 1688 context.set_http_network_session_params(std::move(params)); | 1724 context.set_http_network_session_params(std::move(params)); |
| 1689 context.Init(); | 1725 context.Init(); |
| 1690 | 1726 |
| 1691 EXPECT_EQ(0U, rtt_observer.observations().size()); | 1727 EXPECT_EQ(0U, rtt_observer.observations().size()); |
| 1692 base::TimeDelta rtt; | 1728 base::TimeDelta rtt; |
| 1693 EXPECT_FALSE(estimator.GetHttpRTT(&rtt)); | 1729 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1694 EXPECT_FALSE(estimator.GetTransportRTT(&rtt)); | 1730 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 1695 | 1731 |
| 1696 // Send two requests. Verify that the completion of each request generates at | 1732 // Send two requests. Verify that the completion of each request generates at |
| 1697 // least one TCP RTT observation. | 1733 // least one TCP RTT observation. |
| 1698 const size_t num_requests = 2; | 1734 const size_t num_requests = 2; |
| 1699 for (size_t i = 0; i < num_requests; ++i) { | 1735 for (size_t i = 0; i < num_requests; ++i) { |
| 1700 size_t before_count_tcp_rtt_observations = 0; | 1736 size_t before_count_tcp_rtt_observations = 0; |
| 1701 for (const auto& observation : rtt_observer.observations()) { | 1737 for (const auto& observation : rtt_observer.observations()) { |
| 1702 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) | 1738 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) |
| 1703 ++before_count_tcp_rtt_observations; | 1739 ++before_count_tcp_rtt_observations; |
| 1704 } | 1740 } |
| 1705 | 1741 |
| 1706 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1742 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1707 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1743 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1708 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1744 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1709 request->Start(); | 1745 request->Start(); |
| 1710 base::RunLoop().Run(); | 1746 base::RunLoop().Run(); |
| 1711 | 1747 |
| 1712 size_t after_count_tcp_rtt_observations = 0; | 1748 size_t after_count_tcp_rtt_observations = 0; |
| 1713 for (const auto& observation : rtt_observer.observations()) { | 1749 for (const auto& observation : rtt_observer.observations()) { |
| 1714 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) | 1750 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) |
| 1715 ++after_count_tcp_rtt_observations; | 1751 ++after_count_tcp_rtt_observations; |
| 1716 } | 1752 } |
| 1717 // At least one notification should be received per socket performance | 1753 // At least one notification should be received per socket performance |
| 1718 // watcher. | 1754 // watcher. |
| 1719 EXPECT_LE(1U, after_count_tcp_rtt_observations - | 1755 EXPECT_LE(1U, after_count_tcp_rtt_observations - |
| 1720 before_count_tcp_rtt_observations) | 1756 before_count_tcp_rtt_observations) |
| 1721 << i; | 1757 << i; |
| 1722 } | 1758 } |
| 1723 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); | 1759 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1724 EXPECT_TRUE(estimator.GetTransportRTT(&rtt)); | 1760 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 1725 | 1761 |
| 1726 estimator.SimulateNetworkChange( | 1762 estimator.SimulateNetworkChange( |
| 1727 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 1763 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
| 1728 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 1); | 1764 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 1); |
| 1729 histogram_tester.ExpectBucketCount("NQE.TransportRTT.Percentile50.Unknown", | 1765 histogram_tester.ExpectBucketCount("NQE.TransportRTT.Percentile50.Unknown", |
| 1730 rtt.InMilliseconds(), 1); | 1766 rtt.InMilliseconds(), 1); |
| 1731 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile10.Unknown", 1); | 1767 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile10.Unknown", 1); |
| 1732 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 1); | 1768 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 1); |
| 1733 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); | 1769 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); |
| 1734 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", | 1770 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1749 } | 1785 } |
| 1750 | 1786 |
| 1751 #if defined(OS_IOS) | 1787 #if defined(OS_IOS) |
| 1752 // Flaky on iOS when |accuracy_recording_delay| is non-zero. | 1788 // Flaky on iOS when |accuracy_recording_delay| is non-zero. |
| 1753 #define MAYBE_RecordAccuracy DISABLED_RecordAccuracy | 1789 #define MAYBE_RecordAccuracy DISABLED_RecordAccuracy |
| 1754 #else | 1790 #else |
| 1755 #define MAYBE_RecordAccuracy RecordAccuracy | 1791 #define MAYBE_RecordAccuracy RecordAccuracy |
| 1756 #endif | 1792 #endif |
| 1757 // Tests if the NQE accuracy metrics are recorded properly. | 1793 // Tests if the NQE accuracy metrics are recorded properly. |
| 1758 TEST(NetworkQualityEstimatorTest, MAYBE_RecordAccuracy) { | 1794 TEST(NetworkQualityEstimatorTest, MAYBE_RecordAccuracy) { |
| 1759 const int expected_rtt_msec = 100; | 1795 const int expected_rtt_msec = 500; |
| 1760 const int expected_downstream_throughput_kbps = 200; | 1796 const int expected_downstream_throughput_kbps = 2000; |
| 1761 | 1797 |
| 1762 const base::TimeDelta accuracy_recording_delays[] = { | 1798 const base::TimeDelta accuracy_recording_delays[] = { |
| 1763 base::TimeDelta::FromSeconds(0), base::TimeDelta::FromSeconds(1), | 1799 base::TimeDelta::FromSeconds(0), base::TimeDelta::FromSeconds(1), |
| 1764 }; | 1800 }; |
| 1765 | 1801 |
| 1766 const struct { | 1802 const struct { |
| 1767 base::TimeDelta rtt; | 1803 base::TimeDelta rtt; |
| 1768 base::TimeDelta recent_rtt; | 1804 base::TimeDelta recent_rtt; |
| 1769 int32_t downstream_throughput_kbps; | 1805 int32_t downstream_throughput_kbps; |
| 1770 int32_t recent_downstream_throughput_kbps; | 1806 int32_t recent_downstream_throughput_kbps; |
| 1771 EffectiveConnectionType effective_connection_type; | 1807 EffectiveConnectionType effective_connection_type; |
| 1772 EffectiveConnectionType recent_effective_connection_type; | 1808 EffectiveConnectionType recent_effective_connection_type; |
| 1773 } tests[] = { | 1809 } tests[] = { |
| 1774 {base::TimeDelta::FromMilliseconds(expected_rtt_msec), | 1810 {base::TimeDelta::FromMilliseconds(expected_rtt_msec), |
| 1775 base::TimeDelta::FromMilliseconds(expected_rtt_msec), | 1811 base::TimeDelta::FromMilliseconds(expected_rtt_msec), |
| 1776 expected_downstream_throughput_kbps, expected_downstream_throughput_kbps, | 1812 expected_downstream_throughput_kbps, expected_downstream_throughput_kbps, |
| 1777 EFFECTIVE_CONNECTION_TYPE_2G, EFFECTIVE_CONNECTION_TYPE_2G}, | 1813 EFFECTIVE_CONNECTION_TYPE_3G, EFFECTIVE_CONNECTION_TYPE_3G}, |
| 1778 | |
| 1779 { | 1814 { |
| 1780 base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1), | 1815 base::TimeDelta::FromMilliseconds(expected_rtt_msec + 1000), |
| 1816 base::TimeDelta::FromMilliseconds(expected_rtt_msec), |
| 1817 expected_downstream_throughput_kbps - 1, |
| 1818 expected_downstream_throughput_kbps, EFFECTIVE_CONNECTION_TYPE_2G, |
| 1819 EFFECTIVE_CONNECTION_TYPE_3G, |
| 1820 }, |
| 1821 { |
| 1822 base::TimeDelta::FromMilliseconds(expected_rtt_msec - 400), |
| 1781 base::TimeDelta::FromMilliseconds(expected_rtt_msec), | 1823 base::TimeDelta::FromMilliseconds(expected_rtt_msec), |
| 1782 expected_downstream_throughput_kbps + 1, | 1824 expected_downstream_throughput_kbps + 1, |
| 1783 expected_downstream_throughput_kbps, EFFECTIVE_CONNECTION_TYPE_3G, | 1825 expected_downstream_throughput_kbps, EFFECTIVE_CONNECTION_TYPE_4G, |
| 1784 EFFECTIVE_CONNECTION_TYPE_2G, | 1826 EFFECTIVE_CONNECTION_TYPE_3G, |
| 1785 }, | |
| 1786 { | |
| 1787 base::TimeDelta::FromMilliseconds(expected_rtt_msec - 1), | |
| 1788 base::TimeDelta::FromMilliseconds(expected_rtt_msec), | |
| 1789 expected_downstream_throughput_kbps - 1, | |
| 1790 expected_downstream_throughput_kbps, | |
| 1791 EFFECTIVE_CONNECTION_TYPE_SLOW_2G, EFFECTIVE_CONNECTION_TYPE_2G, | |
| 1792 }, | 1827 }, |
| 1793 }; | 1828 }; |
| 1794 | 1829 |
| 1795 for (const auto& accuracy_recording_delay : accuracy_recording_delays) { | 1830 for (const auto& accuracy_recording_delay : accuracy_recording_delays) { |
| 1796 for (const auto& test : tests) { | 1831 for (const auto& test : tests) { |
| 1797 std::unique_ptr<base::SimpleTestTickClock> tick_clock( | 1832 std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| 1798 new base::SimpleTestTickClock()); | 1833 new base::SimpleTestTickClock()); |
| 1799 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1834 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 1800 tick_clock_ptr->Advance(base::TimeDelta::FromSeconds(1)); | 1835 tick_clock_ptr->Advance(base::TimeDelta::FromSeconds(1)); |
| 1801 | 1836 |
| 1802 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( | 1837 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( |
| 1803 new TestExternalEstimateProvider(test.rtt, 0)); | 1838 new TestExternalEstimateProvider(test.rtt, 0)); |
| 1804 | 1839 |
| 1805 std::map<std::string, std::string> variation_params; | 1840 std::map<std::string, std::string> variation_params; |
| 1806 TestNetworkQualityEstimator estimator( | 1841 TestNetworkQualityEstimator estimator( |
| 1807 variation_params, std::move(external_estimate_provider)); | 1842 variation_params, std::move(external_estimate_provider)); |
| 1808 | 1843 |
| 1809 estimator.SetTickClockForTesting(std::move(tick_clock)); | 1844 estimator.SetTickClockForTesting(std::move(tick_clock)); |
| 1810 estimator.SimulateNetworkChange( | 1845 estimator.SimulateNetworkChange( |
| 1811 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 1846 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
| 1812 tick_clock_ptr->Advance(base::TimeDelta::FromSeconds(1)); | 1847 tick_clock_ptr->Advance(base::TimeDelta::FromSeconds(1)); |
| 1813 | 1848 |
| 1814 std::vector<base::TimeDelta> accuracy_recording_intervals; | 1849 std::vector<base::TimeDelta> accuracy_recording_intervals; |
| 1815 accuracy_recording_intervals.push_back(accuracy_recording_delay); | 1850 accuracy_recording_intervals.push_back(accuracy_recording_delay); |
| 1816 estimator.SetAccuracyRecordingIntervals(accuracy_recording_intervals); | 1851 estimator.SetAccuracyRecordingIntervals(accuracy_recording_intervals); |
| 1817 | 1852 |
| 1818 // RTT is higher than threshold. Network is slow. | 1853 // RTT is higher than threshold. Network is slow. |
| 1819 // Network was predicted to be slow and actually was slow. | 1854 // Network was predicted to be slow and actually was slow. |
| 1820 estimator.set_http_rtt(test.rtt); | 1855 estimator.set_start_time_null_http_rtt(test.rtt); |
| 1821 estimator.set_recent_http_rtt(test.recent_rtt); | 1856 estimator.set_recent_http_rtt(test.recent_rtt); |
| 1822 estimator.set_transport_rtt(test.rtt); | 1857 estimator.set_start_time_null_transport_rtt(test.rtt); |
| 1823 estimator.set_recent_transport_rtt(test.recent_rtt); | 1858 estimator.set_recent_transport_rtt(test.recent_rtt); |
| 1824 estimator.set_downlink_throughput_kbps(test.downstream_throughput_kbps); | 1859 estimator.set_start_time_null_downlink_throughput_kbps( |
| 1860 test.downstream_throughput_kbps); |
| 1825 estimator.set_recent_downlink_throughput_kbps( | 1861 estimator.set_recent_downlink_throughput_kbps( |
| 1826 test.recent_downstream_throughput_kbps); | 1862 test.recent_downstream_throughput_kbps); |
| 1827 estimator.set_effective_connection_type(test.effective_connection_type); | |
| 1828 estimator.set_recent_effective_connection_type( | |
| 1829 test.recent_effective_connection_type); | |
| 1830 | 1863 |
| 1831 base::HistogramTester histogram_tester; | 1864 base::HistogramTester histogram_tester; |
| 1832 | 1865 |
| 1833 TestDelegate test_delegate; | 1866 TestDelegate test_delegate; |
| 1834 TestURLRequestContext context(true); | 1867 TestURLRequestContext context(true); |
| 1835 context.set_network_quality_estimator(&estimator); | 1868 context.set_network_quality_estimator(&estimator); |
| 1836 context.Init(); | 1869 context.Init(); |
| 1837 | 1870 |
| 1838 // Start a main-frame request which should cause network quality estimator | 1871 // Start a main-frame request which should cause network quality estimator |
| 1839 // to record accuracy UMA. | 1872 // to record accuracy UMA. |
| 1840 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1873 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1841 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1874 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1842 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1875 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1843 request->Start(); | 1876 request->Start(); |
| 1844 base::RunLoop().Run(); | 1877 base::RunLoop().Run(); |
| 1845 | 1878 |
| 1846 if (accuracy_recording_delay != base::TimeDelta()) { | 1879 if (accuracy_recording_delay != base::TimeDelta()) { |
| 1847 tick_clock_ptr->Advance(accuracy_recording_delay); | 1880 tick_clock_ptr->Advance(accuracy_recording_delay); |
| 1848 | 1881 |
| 1849 // Sleep for some time to ensure that the delayed task is posted. | 1882 // Sleep for some time to ensure that the delayed task is posted. |
| 1850 base::PlatformThread::Sleep(accuracy_recording_delay * 2); | 1883 base::PlatformThread::Sleep(accuracy_recording_delay * 2); |
| 1851 base::RunLoop().RunUntilIdle(); | 1884 base::RunLoop().RunUntilIdle(); |
| 1852 } | 1885 } |
| 1853 | 1886 |
| 1854 const int diff = std::abs(test.rtt.InMilliseconds() - | 1887 const int rtt_diff = std::abs(test.rtt.InMilliseconds() - |
| 1855 test.recent_rtt.InMilliseconds()); | 1888 test.recent_rtt.InMilliseconds()); |
| 1856 const std::string sign_suffix_with_one_sample = | 1889 const int kbps_diff = std::abs(test.downstream_throughput_kbps - |
| 1857 test.rtt.InMilliseconds() - test.recent_rtt.InMilliseconds() >= 0 | 1890 test.recent_downstream_throughput_kbps); |
| 1858 ? "Positive" | 1891 const int ect_diff = std::abs(test.effective_connection_type - |
| 1859 : "Negative"; | 1892 test.recent_effective_connection_type); |
| 1860 const std::string sign_suffix_with_zero_samples = | 1893 |
| 1894 const std::string rtt_sign_suffix_with_zero_samples = |
| 1861 test.rtt.InMilliseconds() - test.recent_rtt.InMilliseconds() >= 0 | 1895 test.rtt.InMilliseconds() - test.recent_rtt.InMilliseconds() >= 0 |
| 1862 ? "Negative" | 1896 ? "Negative" |
| 1863 : "Positive"; | 1897 : "Positive"; |
| 1898 const std::string kbps_sign_suffix_with_zero_samples = |
| 1899 test.downstream_throughput_kbps - |
| 1900 test.recent_downstream_throughput_kbps >= |
| 1901 0 |
| 1902 ? "Negative" |
| 1903 : "Positive"; |
| 1904 |
| 1905 const std::string rtt_sign_suffix_with_one_sample = |
| 1906 rtt_sign_suffix_with_zero_samples == "Positive" ? "Negative" |
| 1907 : "Positive"; |
| 1908 const std::string ect_sign_suffix_with_zero_samples = |
| 1909 test.rtt.InMilliseconds() - test.recent_rtt.InMilliseconds() > 0 |
| 1910 ? "Positive" |
| 1911 : "Negative"; |
| 1912 |
| 1913 const std::string kbps_sign_suffix_with_one_sample = |
| 1914 kbps_sign_suffix_with_zero_samples == "Positive" ? "Negative" |
| 1915 : "Positive"; |
| 1916 const std::string ect_sign_suffix_with_one_sample = |
| 1917 ect_sign_suffix_with_zero_samples == "Positive" ? "Negative" |
| 1918 : "Positive"; |
| 1864 const std::string interval_value = | 1919 const std::string interval_value = |
| 1865 base::IntToString(accuracy_recording_delay.InSeconds()); | 1920 base::IntToString(accuracy_recording_delay.InSeconds()); |
| 1866 | 1921 |
| 1867 histogram_tester.ExpectUniqueSample( | 1922 histogram_tester.ExpectUniqueSample( |
| 1868 "NQE.Accuracy.DownstreamThroughputKbps.EstimatedObservedDiff." + | 1923 "NQE.Accuracy.DownstreamThroughputKbps.EstimatedObservedDiff." + |
| 1869 sign_suffix_with_one_sample + "." + interval_value + ".140_300", | 1924 kbps_sign_suffix_with_one_sample + "." + interval_value + |
| 1870 diff, 1); | 1925 ".1260_2540", |
| 1926 kbps_diff, 1); |
| 1871 histogram_tester.ExpectTotalCount( | 1927 histogram_tester.ExpectTotalCount( |
| 1872 "NQE.Accuracy.DownstreamThroughputKbps.EstimatedObservedDiff." + | 1928 "NQE.Accuracy.DownstreamThroughputKbps.EstimatedObservedDiff." + |
| 1873 sign_suffix_with_zero_samples + "." + interval_value + ".140_300", | 1929 kbps_sign_suffix_with_zero_samples + "." + interval_value + |
| 1930 ".1260_2540", |
| 1874 0); | 1931 0); |
| 1875 | 1932 |
| 1876 histogram_tester.ExpectUniqueSample( | 1933 histogram_tester.ExpectUniqueSample( |
| 1877 "NQE.Accuracy.EffectiveConnectionType.EstimatedObservedDiff." + | 1934 "NQE.Accuracy.EffectiveConnectionType.EstimatedObservedDiff." + |
| 1878 sign_suffix_with_one_sample + "." + interval_value + ".2G", | 1935 ect_sign_suffix_with_one_sample + "." + interval_value + ".3G", |
| 1879 diff, 1); | 1936 ect_diff, 1); |
| 1880 histogram_tester.ExpectTotalCount( | 1937 histogram_tester.ExpectTotalCount( |
| 1881 "NQE.Accuracy.EffectiveConnectionType.EstimatedObservedDiff." + | 1938 "NQE.Accuracy.EffectiveConnectionType.EstimatedObservedDiff." + |
| 1882 sign_suffix_with_zero_samples + "." + interval_value + ".2G", | 1939 ect_sign_suffix_with_zero_samples + "." + interval_value + ".3G", |
| 1883 0); | 1940 0); |
| 1884 | 1941 |
| 1885 histogram_tester.ExpectUniqueSample( | 1942 histogram_tester.ExpectUniqueSample( |
| 1886 "NQE.Accuracy.HttpRTT.EstimatedObservedDiff." + | 1943 "NQE.Accuracy.HttpRTT.EstimatedObservedDiff." + |
| 1887 sign_suffix_with_one_sample + "." + interval_value + ".60_140", | 1944 rtt_sign_suffix_with_one_sample + "." + interval_value + |
| 1888 diff, 1); | 1945 ".300_620", |
| 1946 rtt_diff, 1); |
| 1889 histogram_tester.ExpectTotalCount( | 1947 histogram_tester.ExpectTotalCount( |
| 1890 "NQE.Accuracy.HttpRTT.EstimatedObservedDiff." + | 1948 "NQE.Accuracy.HttpRTT.EstimatedObservedDiff." + |
| 1891 sign_suffix_with_zero_samples + "." + interval_value + ".60_140", | 1949 rtt_sign_suffix_with_zero_samples + "." + interval_value + |
| 1950 ".300_620", |
| 1892 0); | 1951 0); |
| 1893 histogram_tester.ExpectUniqueSample( | 1952 histogram_tester.ExpectUniqueSample( |
| 1894 "NQE.Accuracy.TransportRTT.EstimatedObservedDiff." + | 1953 "NQE.Accuracy.TransportRTT.EstimatedObservedDiff." + |
| 1895 sign_suffix_with_one_sample + "." + interval_value + ".60_140", | 1954 rtt_sign_suffix_with_one_sample + "." + interval_value + |
| 1896 diff, 1); | 1955 ".300_620", |
| 1956 rtt_diff, 1); |
| 1897 histogram_tester.ExpectTotalCount( | 1957 histogram_tester.ExpectTotalCount( |
| 1898 "NQE.Accuracy.TransportRTT.EstimatedObservedDiff." + | 1958 "NQE.Accuracy.TransportRTT.EstimatedObservedDiff." + |
| 1899 sign_suffix_with_zero_samples + "." + interval_value + ".60_140", | 1959 rtt_sign_suffix_with_zero_samples + "." + interval_value + |
| 1960 ".300_620", |
| 1900 0); | 1961 0); |
| 1901 | 1962 |
| 1902 histogram_tester.ExpectUniqueSample( | 1963 histogram_tester.ExpectUniqueSample( |
| 1903 "NQE.ExternalEstimateProvider.RTT.Accuracy.EstimatedObservedDiff." + | 1964 "NQE.ExternalEstimateProvider.RTT.Accuracy.EstimatedObservedDiff." + |
| 1904 sign_suffix_with_one_sample + "." + interval_value + ".60_140", | 1965 rtt_sign_suffix_with_one_sample + "." + interval_value + |
| 1905 diff, 1); | 1966 ".300_620", |
| 1967 rtt_diff, 1); |
| 1906 histogram_tester.ExpectTotalCount( | 1968 histogram_tester.ExpectTotalCount( |
| 1907 "NQE.ExternalEstimateProvider.RTT.Accuracy.EstimatedObservedDiff." + | 1969 "NQE.ExternalEstimateProvider.RTT.Accuracy.EstimatedObservedDiff." + |
| 1908 sign_suffix_with_zero_samples + "." + interval_value + ".60_140", | 1970 rtt_sign_suffix_with_zero_samples + "." + interval_value + |
| 1971 ".300_620", |
| 1909 0); | 1972 0); |
| 1910 } | 1973 } |
| 1911 } | 1974 } |
| 1912 } | 1975 } |
| 1913 | 1976 |
| 1914 TEST(NetworkQualityEstimatorTest, TestRecordNetworkIDAvailability) { | 1977 TEST(NetworkQualityEstimatorTest, TestRecordNetworkIDAvailability) { |
| 1915 base::HistogramTester histogram_tester; | 1978 base::HistogramTester histogram_tester; |
| 1916 std::map<std::string, std::string> variation_params; | 1979 std::map<std::string, std::string> variation_params; |
| 1917 TestNetworkQualityEstimator estimator(variation_params); | 1980 TestNetworkQualityEstimator estimator(variation_params); |
| 1918 | 1981 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2015 | 2078 |
| 2016 std::map<std::string, std::string> variation_params; | 2079 std::map<std::string, std::string> variation_params; |
| 2017 variation_params["correlation_logging_probability"] = | 2080 variation_params["correlation_logging_probability"] = |
| 2018 base::DoubleToString(test.correlation_logging_probability); | 2081 base::DoubleToString(test.correlation_logging_probability); |
| 2019 if (test.use_transport_rtt) { | 2082 if (test.use_transport_rtt) { |
| 2020 variation_params["effective_connection_type_algorithm"] = | 2083 variation_params["effective_connection_type_algorithm"] = |
| 2021 "TransportRTTOrDownstreamThroughput"; | 2084 "TransportRTTOrDownstreamThroughput"; |
| 2022 } | 2085 } |
| 2023 TestNetworkQualityEstimator estimator(variation_params); | 2086 TestNetworkQualityEstimator estimator(variation_params); |
| 2024 | 2087 |
| 2025 estimator.set_transport_rtt(test.transport_rtt); | 2088 estimator.set_start_time_null_transport_rtt(test.transport_rtt); |
| 2026 estimator.set_recent_transport_rtt(test.transport_rtt); | 2089 estimator.set_recent_transport_rtt(test.transport_rtt); |
| 2027 estimator.set_http_rtt(test.http_rtt); | 2090 estimator.set_start_time_null_http_rtt(test.http_rtt); |
| 2028 estimator.set_recent_http_rtt(test.http_rtt); | 2091 estimator.set_recent_http_rtt(test.http_rtt); |
| 2029 estimator.set_downlink_throughput_kbps(test.downstream_throughput_kbps); | 2092 estimator.set_start_time_null_downlink_throughput_kbps( |
| 2093 test.downstream_throughput_kbps); |
| 2030 estimator.set_rand_double(test.rand_double); | 2094 estimator.set_rand_double(test.rand_double); |
| 2031 | 2095 |
| 2032 TestDelegate test_delegate; | 2096 TestDelegate test_delegate; |
| 2033 TestURLRequestContext context(true); | 2097 TestURLRequestContext context(true); |
| 2034 context.set_network_quality_estimator(&estimator); | 2098 context.set_network_quality_estimator(&estimator); |
| 2035 context.Init(); | 2099 context.Init(); |
| 2036 | 2100 |
| 2037 // Start a main-frame request that should cause network quality estimator to | 2101 // Start a main-frame request that should cause network quality estimator to |
| 2038 // record the network quality at the last main frame request. | 2102 // record the network quality at the last main frame request. |
| 2039 std::unique_ptr<URLRequest> request_1(context.CreateRequest( | 2103 std::unique_ptr<URLRequest> request_1(context.CreateRequest( |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2201 if (expected_count == 1) { | 2265 if (expected_count == 1) { |
| 2202 EffectiveConnectionType last_notified_type = | 2266 EffectiveConnectionType last_notified_type = |
| 2203 observer.effective_connection_types().at( | 2267 observer.effective_connection_types().at( |
| 2204 observer.effective_connection_types().size() - 1); | 2268 observer.effective_connection_types().size() - 1); |
| 2205 EXPECT_EQ(i, last_notified_type); | 2269 EXPECT_EQ(i, last_notified_type); |
| 2206 } | 2270 } |
| 2207 } | 2271 } |
| 2208 } | 2272 } |
| 2209 | 2273 |
| 2210 } // namespace net | 2274 } // namespace net |
| OLD | NEW |