| 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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 EXPECT_EQ(300, kbps); | 484 EXPECT_EQ(300, kbps); |
| 485 | 485 |
| 486 // Simulate network change to 3G. Default estimates should be unavailable. | 486 // Simulate network change to 3G. Default estimates should be unavailable. |
| 487 estimator.SimulateNetworkChangeTo( | 487 estimator.SimulateNetworkChangeTo( |
| 488 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); | 488 NetworkChangeNotifier::ConnectionType::CONNECTION_3G, "test-3"); |
| 489 | 489 |
| 490 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); | 490 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); |
| 491 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 491 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 492 } | 492 } |
| 493 | 493 |
| 494 TEST(NetworkQualityEstimatorTest, ObtainAlgorithmToUseFromParams) { |
| 495 const struct { |
| 496 std::string algorithm; |
| 497 int32_t expected_algorithm; |
| 498 } tests[] = { |
| 499 {"", 0}, {"0", 0}, {"1", 1}, {"2", 2}, {"100", 100}, |
| 500 }; |
| 501 |
| 502 for (const auto& test : tests) { |
| 503 std::map<std::string, std::string> variation_params; |
| 504 variation_params["algorithm"] = test.algorithm; |
| 505 |
| 506 TestNetworkQualityEstimator estimator(variation_params); |
| 507 EXPECT_EQ(test.expected_algorithm, estimator.algorithm_) << test.algorithm; |
| 508 } |
| 509 } |
| 510 |
| 494 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 511 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 495 // no variation params are specified. | 512 // no variation params are specified. |
| 496 TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) { | 513 TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) { |
| 497 std::map<std::string, std::string> variation_params; | 514 std::map<std::string, std::string> variation_params; |
| 498 | 515 |
| 499 TestNetworkQualityEstimator estimator(variation_params); | 516 TestNetworkQualityEstimator estimator(variation_params); |
| 500 | 517 |
| 501 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | 518 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 502 // does not return Offline if the device is offline. | 519 // does not return Offline if the device is offline. |
| 503 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, | 520 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| 504 "test"); | 521 "test"); |
| 505 | 522 |
| 506 const struct { | 523 const struct { |
| 507 int32_t rtt_msec; | 524 int32_t rtt_msec; |
| 508 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | 525 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; |
| 509 } tests[] = { | 526 } tests[] = { |
| 510 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 527 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 511 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 528 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 512 }; | 529 }; |
| 513 | 530 |
| 514 for (const auto& test : tests) { | 531 for (const auto& test : tests) { |
| 515 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 532 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 533 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 516 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 534 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 517 } | 535 } |
| 518 } | 536 } |
| 519 | 537 |
| 520 // Tests that |GetEffectiveConnectionType| returns | 538 // Tests that |GetEffectiveConnectionType| returns |
| 521 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. | 539 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. |
| 522 TEST(NetworkQualityEstimatorTest, Offline) { | 540 TEST(NetworkQualityEstimatorTest, Offline) { |
| 523 std::map<std::string, std::string> variation_params; | 541 std::map<std::string, std::string> variation_params; |
| 524 TestNetworkQualityEstimator estimator(variation_params); | 542 TestNetworkQualityEstimator estimator(variation_params); |
| 525 | 543 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 {500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 593 {500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 576 {400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 594 {400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 577 {300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 595 {300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 578 {200, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 596 {200, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 579 {100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 597 {100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 580 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 598 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 581 }; | 599 }; |
| 582 | 600 |
| 583 for (const auto& test : tests) { | 601 for (const auto& test : tests) { |
| 584 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 602 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 603 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 585 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 604 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 586 } | 605 } |
| 587 } | 606 } |
| 588 | 607 |
| 589 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 608 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 590 // both RTT and throughput thresholds are specified in the variation params. | 609 // both RTT and throughput thresholds are specified in the variation params. |
| 591 TEST(NetworkQualityEstimatorTest, ObtainThresholdsRTTandThroughput) { | 610 TEST(NetworkQualityEstimatorTest, ObtainThresholdsRTTandThroughput) { |
| 592 std::map<std::string, std::string> variation_params; | 611 std::map<std::string, std::string> variation_params; |
| 593 | 612 |
| 594 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; | 613 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 {1, 300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, | 646 {1, 300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 628 {1, 400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 647 {1, 400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 629 {1, 500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 648 {1, 500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 630 {1, 700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 649 {1, 700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 631 {1, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 650 {1, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 632 {1, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 651 {1, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 633 {1, 2500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 652 {1, 2500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 634 // Set both RTT and throughput. RTT is the bottleneck. | 653 // Set both RTT and throughput. RTT is the bottleneck. |
| 635 {3000, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 654 {3000, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 636 {700, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 655 {700, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 637 // Set throughput to an invalid value. | |
| 638 {3000, 0, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | |
| 639 {700, 0, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | |
| 640 }; | 656 }; |
| 641 | 657 |
| 642 for (const auto& test : tests) { | 658 for (const auto& test : tests) { |
| 643 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 659 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 644 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); | 660 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); |
| 645 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 661 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 646 } | 662 } |
| 647 } | 663 } |
| 648 | 664 |
| 649 // Tests if |weight_multiplier_per_second_| is set to correct value for various | 665 // Tests if |weight_multiplier_per_second_| is set to correct value for various |
| (...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1454 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); | 1470 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); |
| 1455 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", | 1471 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", |
| 1456 1); | 1472 1); |
| 1457 | 1473 |
| 1458 // Verify that metrics are logged correctly on main-frame requests. | 1474 // Verify that metrics are logged correctly on main-frame requests. |
| 1459 histogram_tester.ExpectTotalCount( | 1475 histogram_tester.ExpectTotalCount( |
| 1460 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", num_requests); | 1476 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", num_requests); |
| 1461 } | 1477 } |
| 1462 | 1478 |
| 1463 } // namespace net | 1479 } // namespace net |
| OLD | NEW |