Chromium Code Reviews| 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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 | 444 |
| 445 // RTT percentiles are in increasing order. | 445 // RTT percentiles are in increasing order. |
| 446 EXPECT_GE(estimator.GetRTTEstimateInternal(disallowed_observation_sources, | 446 EXPECT_GE(estimator.GetRTTEstimateInternal(disallowed_observation_sources, |
| 447 base::TimeTicks(), i), | 447 base::TimeTicks(), i), |
| 448 estimator.GetRTTEstimateInternal(disallowed_observation_sources, | 448 estimator.GetRTTEstimateInternal(disallowed_observation_sources, |
| 449 base::TimeTicks(), i - 1)); | 449 base::TimeTicks(), i - 1)); |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 } | 452 } |
| 453 | 453 |
| 454 TEST(NetworkQualityEstimatorTest, ObtainOperatingParams) { | 454 // Verifies that the default observations are added to the set of observations. |
| 455 // If default observations are overridden using field trial parameters, verify | |
| 456 // that the overriding values are used. | |
| 457 TEST(NetworkQualityEstimatorTest, DefaultObservationsOverridden) { | |
| 455 std::map<std::string, std::string> variation_params; | 458 std::map<std::string, std::string> variation_params; |
| 456 variation_params["Unknown.DefaultMedianKbps"] = "100"; | 459 variation_params["Unknown.DefaultMedianKbps"] = "100"; |
| 457 variation_params["WiFi.DefaultMedianKbps"] = "200"; | 460 variation_params["WiFi.DefaultMedianKbps"] = "200"; |
| 458 variation_params["2G.DefaultMedianKbps"] = "300"; | 461 variation_params["2G.DefaultMedianKbps"] = "300"; |
| 459 | 462 |
| 460 variation_params["Unknown.DefaultMedianRTTMsec"] = "1000"; | 463 variation_params["Unknown.DefaultMedianRTTMsec"] = "1000"; |
| 461 variation_params["WiFi.DefaultMedianRTTMsec"] = "2000"; | 464 variation_params["WiFi.DefaultMedianRTTMsec"] = "2000"; |
| 462 // Negative variation value should not be used. | 465 // Negative variation value should not be used. |
| 463 variation_params["2G.DefaultMedianRTTMsec"] = "-5"; | 466 variation_params["2G.DefaultMedianRTTMsec"] = "-5"; |
| 464 | 467 |
| 465 TestNetworkQualityEstimator estimator(variation_params); | 468 variation_params["Unknown.DefaultMedianTransportRTTMsec"] = "500"; |
| 469 variation_params["WiFi.DefaultMedianTransportRTTMsec"] = "1000"; | |
| 470 // Negative variation value should not be used. | |
| 471 variation_params["2G.DefaultMedianTransportRTTMsec"] = "-5"; | |
| 472 | |
| 473 TestNetworkQualityEstimator estimator(nullptr, variation_params, false, false, | |
| 474 true /* use_default_platform_values */); | |
| 466 | 475 |
| 467 base::TimeDelta rtt; | 476 base::TimeDelta rtt; |
| 477 int32_t kbps; | |
| 478 | |
| 468 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 479 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 469 int32_t kbps; | 480 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); |
| 481 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | |
| 482 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500), rtt); | |
| 470 EXPECT_TRUE( | 483 EXPECT_TRUE( |
| 471 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 484 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 472 | |
| 473 EXPECT_EQ(100, kbps); | 485 EXPECT_EQ(100, kbps); |
| 474 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); | |
| 475 | |
| 476 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | |
| 477 | 486 |
| 478 // Simulate network change to Wi-Fi. | 487 // Simulate network change to Wi-Fi. |
| 479 estimator.SimulateNetworkChange( | 488 estimator.SimulateNetworkChange( |
| 480 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 489 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
| 481 | |
| 482 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 490 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 491 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); | |
| 492 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | |
| 493 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); | |
| 483 EXPECT_TRUE( | 494 EXPECT_TRUE( |
| 484 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 495 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 485 EXPECT_EQ(200, kbps); | 496 EXPECT_EQ(200, kbps); |
| 486 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), rtt); | |
| 487 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | |
| 488 | 497 |
| 489 // Peak network quality should not be affected by the network quality | 498 // Peak network quality should not be affected by the network quality |
| 490 // estimator field trial. | 499 // estimator field trial. |
| 491 EXPECT_EQ(nqe::internal::InvalidRTT(), | 500 EXPECT_EQ(nqe::internal::InvalidRTT(), |
| 492 estimator.peak_network_quality_.http_rtt()); | 501 estimator.peak_network_quality_.http_rtt()); |
| 493 EXPECT_EQ(nqe::internal::kInvalidThroughput, | 502 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
| 494 estimator.peak_network_quality_.downstream_throughput_kbps()); | 503 estimator.peak_network_quality_.downstream_throughput_kbps()); |
| 495 | 504 |
| 496 // Simulate network change to 2G. Only the Kbps default estimate should be | 505 // Simulate network change to 2G. Only the Kbps default estimate should be |
| 497 // available. | 506 // available. |
| 498 estimator.SimulateNetworkChange( | 507 estimator.SimulateNetworkChange( |
| 499 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); | 508 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test-2"); |
| 500 | 509 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 501 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 510 // Taken from network_quality_estimator_params.cc. |
| 511 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1726), rtt); | |
| 512 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | |
| 513 // Taken from network_quality_estimator_params.cc. | |
| 514 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1531), rtt); | |
| 502 EXPECT_TRUE( | 515 EXPECT_TRUE( |
| 503 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 516 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 504 EXPECT_EQ(300, kbps); | 517 EXPECT_EQ(300, kbps); |
| 505 | 518 |
| 506 // Simulate network change to 3G. Default estimates should be unavailable. | 519 // Simulate network change to 3G. Default estimates should be available. |
| 507 estimator.SimulateNetworkChange( | 520 estimator.SimulateNetworkChange( |
| 508 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); | 521 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); |
| 522 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | |
| 523 // Taken from network_quality_estimator_params.cc. | |
| 524 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), rtt); | |
| 525 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | |
| 526 // Taken from network_quality_estimator_params.cc. | |
| 527 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), rtt); | |
| 528 EXPECT_TRUE( | |
| 529 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | |
| 530 // Taken from network_quality_estimator_params.cc. | |
| 531 EXPECT_EQ(749, kbps); | |
| 532 } | |
| 509 | 533 |
| 510 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 534 // Verify that the observers receive the notifications when default estimates |
| 511 EXPECT_FALSE( | 535 // are added to the observations. |
| 536 TEST(NetworkQualityEstimatorTest, DefaultObservations) { | |
|
RyanSturm
2016/11/28 21:10:03
nit: Can you switch the order of these tests? It m
tbansal1
2016/11/28 22:50:57
Done.
| |
| 537 TestEffectiveConnectionTypeObserver effective_connection_type_observer; | |
| 538 TestRTTAndThroughputEstimatesObserver rtt_throughput_estimates_observer; | |
| 539 TestRTTObserver rtt_observer; | |
| 540 TestThroughputObserver throughput_observer; | |
| 541 std::map<std::string, std::string> variation_params; | |
| 542 TestNetworkQualityEstimator estimator(nullptr, variation_params, false, false, | |
| 543 true /* use_default_platform_values */); | |
| 544 base::TimeDelta rtt; | |
| 545 int32_t kbps; | |
| 546 | |
| 547 // Default estimates should be available. | |
| 548 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | |
| 549 EXPECT_EQ(base::TimeDelta::FromMilliseconds(115), rtt); | |
| 550 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | |
| 551 EXPECT_EQ(base::TimeDelta::FromMilliseconds(55), rtt); | |
| 552 EXPECT_TRUE( | |
| 512 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 553 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 554 EXPECT_EQ(1961, kbps); | |
| 555 | |
| 556 estimator.AddEffectiveConnectionTypeObserver( | |
| 557 &effective_connection_type_observer); | |
| 558 estimator.AddRTTAndThroughputEstimatesObserver( | |
| 559 &rtt_throughput_estimates_observer); | |
| 560 estimator.AddRTTObserver(&rtt_observer); | |
| 561 estimator.AddThroughputObserver(&throughput_observer); | |
| 562 | |
| 563 // Simulate network change to 3G. Default estimates should be available. | |
| 564 estimator.SimulateNetworkChange( | |
| 565 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); | |
| 566 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | |
| 567 // Taken from network_quality_estimator_params.cc. | |
| 568 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), rtt); | |
| 569 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | |
| 570 // Taken from network_quality_estimator_params.cc. | |
| 571 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), rtt); | |
| 572 EXPECT_TRUE( | |
| 573 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | |
| 574 // Taken from network_quality_estimator_params.cc. | |
| 575 EXPECT_EQ(749, kbps); | |
| 576 | |
| 577 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | |
| 578 estimator.GetEffectiveConnectionType()); | |
| 579 EXPECT_EQ( | |
| 580 1U, | |
| 581 effective_connection_type_observer.effective_connection_types().size()); | |
| 582 EXPECT_NE( | |
| 583 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | |
| 584 effective_connection_type_observer.effective_connection_types().front()); | |
| 585 | |
| 586 EXPECT_EQ(3, rtt_throughput_estimates_observer.notifications_received()); | |
| 587 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), | |
| 588 rtt_throughput_estimates_observer.http_rtt()); | |
| 589 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), | |
| 590 rtt_throughput_estimates_observer.transport_rtt()); | |
| 591 EXPECT_EQ(749, | |
| 592 rtt_throughput_estimates_observer.downstream_throughput_kbps()); | |
| 593 | |
| 594 EXPECT_EQ(2U, rtt_observer.observations().size()); | |
| 595 EXPECT_EQ(272, rtt_observer.observations().at(0).rtt_ms); | |
| 596 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM, | |
| 597 rtt_observer.observations().at(0).source); | |
| 598 EXPECT_EQ(209, rtt_observer.observations().at(1).rtt_ms); | |
| 599 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM, | |
| 600 rtt_observer.observations().at(1).source); | |
| 601 | |
| 602 EXPECT_EQ(1U, throughput_observer.observations().size()); | |
| 603 EXPECT_EQ(749, throughput_observer.observations().at(0).throughput_kbps); | |
| 604 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM, | |
| 605 throughput_observer.observations().at(0).source); | |
| 513 } | 606 } |
| 514 | 607 |
| 515 TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) { | 608 TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) { |
| 516 const struct { | 609 const struct { |
| 517 bool set_variation_param; | 610 bool set_variation_param; |
| 518 std::string algorithm; | 611 std::string algorithm; |
| 519 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm | 612 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm |
| 520 expected_algorithm; | 613 expected_algorithm; |
| 521 } tests[] = { | 614 } tests[] = { |
| 522 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: | 615 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1332 }, | 1425 }, |
| 1333 { | 1426 { |
| 1334 true, | 1427 true, |
| 1335 }, | 1428 }, |
| 1336 }; | 1429 }; |
| 1337 | 1430 |
| 1338 for (const auto& test : tests) { | 1431 for (const auto& test : tests) { |
| 1339 TestNetworkQualityEstimator estimator( | 1432 TestNetworkQualityEstimator estimator( |
| 1340 std::unique_ptr<net::ExternalEstimateProvider>(), variation_params, | 1433 std::unique_ptr<net::ExternalEstimateProvider>(), variation_params, |
| 1341 test.allow_small_localhost_requests, | 1434 test.allow_small_localhost_requests, |
| 1342 test.allow_small_localhost_requests); | 1435 test.allow_small_localhost_requests, false); |
| 1343 | 1436 |
| 1344 base::TimeDelta rtt; | 1437 base::TimeDelta rtt; |
| 1345 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 1438 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1346 int32_t kbps; | 1439 int32_t kbps; |
| 1347 EXPECT_FALSE( | 1440 EXPECT_FALSE( |
| 1348 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 1441 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1349 | 1442 |
| 1350 TestDelegate test_delegate; | 1443 TestDelegate test_delegate; |
| 1351 TestURLRequestContext context(true); | 1444 TestURLRequestContext context(true); |
| 1352 context.set_network_quality_estimator(&estimator); | 1445 context.set_network_quality_estimator(&estimator); |
| (...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2466 request->Start(); | 2559 request->Start(); |
| 2467 base::RunLoop().Run(); | 2560 base::RunLoop().Run(); |
| 2468 | 2561 |
| 2469 EXPECT_EQ(effective_connection_type, | 2562 EXPECT_EQ(effective_connection_type, |
| 2470 estimator.GetEffectiveConnectionType()); | 2563 estimator.GetEffectiveConnectionType()); |
| 2471 } | 2564 } |
| 2472 } | 2565 } |
| 2473 } | 2566 } |
| 2474 | 2567 |
| 2475 } // namespace net | 2568 } // namespace net |
| OLD | NEW |