| 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 bool set_variation_param; |
| 497 std::string algorithm; |
| 498 std::string expected_algorithm; |
| 499 } tests[] = { |
| 500 {false, "", "HttpRTTAndDownstreamThroughput"}, |
| 501 {true, "", "HttpRTTAndDownstreamThroughput"}, |
| 502 {true, "HttpRTTAndDownstreamThroughput", |
| 503 "HttpRTTAndDownstreamThroughput"}, |
| 504 }; |
| 505 |
| 506 for (const auto& test : tests) { |
| 507 std::map<std::string, std::string> variation_params; |
| 508 if (test.set_variation_param) |
| 509 variation_params["algorithm"] = test.algorithm; |
| 510 |
| 511 TestNetworkQualityEstimator estimator(variation_params); |
| 512 EXPECT_EQ(test.expected_algorithm, estimator.algorithm_) << test.algorithm; |
| 513 } |
| 514 } |
| 515 |
| 494 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 516 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 495 // no variation params are specified. | 517 // no variation params are specified. |
| 496 TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) { | 518 TEST(NetworkQualityEstimatorTest, ObtainThresholdsNone) { |
| 497 std::map<std::string, std::string> variation_params; | 519 std::map<std::string, std::string> variation_params; |
| 498 | 520 |
| 499 TestNetworkQualityEstimator estimator(variation_params); | 521 TestNetworkQualityEstimator estimator(variation_params); |
| 500 | 522 |
| 501 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType | 523 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType |
| 502 // does not return Offline if the device is offline. | 524 // does not return Offline if the device is offline. |
| 503 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, | 525 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| 504 "test"); | 526 "test"); |
| 505 | 527 |
| 506 const struct { | 528 const struct { |
| 507 int32_t rtt_msec; | 529 int32_t rtt_msec; |
| 508 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; | 530 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type; |
| 509 } tests[] = { | 531 } tests[] = { |
| 510 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 532 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 511 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 533 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 512 }; | 534 }; |
| 513 | 535 |
| 514 for (const auto& test : tests) { | 536 for (const auto& test : tests) { |
| 515 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 537 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 538 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 516 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 539 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 517 } | 540 } |
| 518 } | 541 } |
| 519 | 542 |
| 520 // Tests that |GetEffectiveConnectionType| returns | 543 // Tests that |GetEffectiveConnectionType| returns |
| 521 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. | 544 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. |
| 522 TEST(NetworkQualityEstimatorTest, Offline) { | 545 TEST(NetworkQualityEstimatorTest, Offline) { |
| 523 std::map<std::string, std::string> variation_params; | 546 std::map<std::string, std::string> variation_params; |
| 524 TestNetworkQualityEstimator estimator(variation_params); | 547 TestNetworkQualityEstimator estimator(variation_params); |
| 525 | 548 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 {500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 598 {500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 576 {400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 599 {400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 577 {300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 600 {300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 578 {200, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 601 {200, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 579 {100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 602 {100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 580 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 603 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 581 }; | 604 }; |
| 582 | 605 |
| 583 for (const auto& test : tests) { | 606 for (const auto& test : tests) { |
| 584 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 607 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 608 estimator.set_downlink_throughput_kbps(INT32_MAX); |
| 585 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 609 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 586 } | 610 } |
| 587 } | 611 } |
| 588 | 612 |
| 589 // Tests that |GetEffectiveConnectionType| returns correct connection type when | 613 // Tests that |GetEffectiveConnectionType| returns correct connection type when |
| 590 // both RTT and throughput thresholds are specified in the variation params. | 614 // both RTT and throughput thresholds are specified in the variation params. |
| 591 TEST(NetworkQualityEstimatorTest, ObtainThresholdsRTTandThroughput) { | 615 TEST(NetworkQualityEstimatorTest, ObtainThresholdsRTTandThroughput) { |
| 592 std::map<std::string, std::string> variation_params; | 616 std::map<std::string, std::string> variation_params; |
| 593 | 617 |
| 594 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; | 618 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}, | 651 {1, 300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G}, |
| 628 {1, 400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 652 {1, 400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 629 {1, 500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 653 {1, 500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, |
| 630 {1, 700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 654 {1, 700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 631 {1, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, | 655 {1, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G}, |
| 632 {1, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 656 {1, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 633 {1, 2500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, | 657 {1, 2500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND}, |
| 634 // Set both RTT and throughput. RTT is the bottleneck. | 658 // Set both RTT and throughput. RTT is the bottleneck. |
| 635 {3000, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, | 659 {3000, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G}, |
| 636 {700, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G}, | 660 {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 }; | 661 }; |
| 641 | 662 |
| 642 for (const auto& test : tests) { | 663 for (const auto& test : tests) { |
| 643 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); | 664 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); |
| 644 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); | 665 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); |
| 645 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); | 666 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); |
| 646 } | 667 } |
| 647 } | 668 } |
| 648 | 669 |
| 649 // Tests if |weight_multiplier_per_second_| is set to correct value for various | 670 // 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); | 1475 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); |
| 1455 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", | 1476 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", |
| 1456 1); | 1477 1); |
| 1457 | 1478 |
| 1458 // Verify that metrics are logged correctly on main-frame requests. | 1479 // Verify that metrics are logged correctly on main-frame requests. |
| 1459 histogram_tester.ExpectTotalCount( | 1480 histogram_tester.ExpectTotalCount( |
| 1460 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", num_requests); | 1481 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", num_requests); |
| 1461 } | 1482 } |
| 1462 | 1483 |
| 1463 } // namespace net | 1484 } // namespace net |
| OLD | NEW |