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