| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 private: | 159 private: |
| 160 std::vector<Observation> observations_; | 160 std::vector<Observation> observations_; |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 } // namespace | 163 } // namespace |
| 164 | 164 |
| 165 TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) { | 165 TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) { |
| 166 base::HistogramTester histogram_tester; | 166 base::HistogramTester histogram_tester; |
| 167 // Enable requests to local host to be used for network quality estimation. | 167 // Enable requests to local host to be used for network quality estimation. |
| 168 std::map<std::string, std::string> variation_params; | 168 TestNetworkQualityEstimator estimator; |
| 169 TestNetworkQualityEstimator estimator(variation_params); | |
| 170 | 169 |
| 171 estimator.SimulateNetworkChange( | 170 estimator.SimulateNetworkChange( |
| 172 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test"); | 171 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test"); |
| 173 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", | 172 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", |
| 174 false, 1); | 173 false, 1); |
| 175 | 174 |
| 176 base::TimeDelta rtt; | 175 base::TimeDelta rtt; |
| 177 int32_t kbps; | 176 int32_t kbps; |
| 178 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 177 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 179 EXPECT_FALSE( | 178 EXPECT_FALSE( |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false, | 295 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false, |
| 297 3); | 296 3); |
| 298 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true, | 297 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true, |
| 299 1); | 298 1); |
| 300 } | 299 } |
| 301 | 300 |
| 302 // Tests that the network quality estimator writes and reads network quality | 301 // Tests that the network quality estimator writes and reads network quality |
| 303 // from the cache store correctly. | 302 // from the cache store correctly. |
| 304 TEST(NetworkQualityEstimatorTest, Caching) { | 303 TEST(NetworkQualityEstimatorTest, Caching) { |
| 305 base::HistogramTester histogram_tester; | 304 base::HistogramTester histogram_tester; |
| 306 std::map<std::string, std::string> variation_params; | 305 TestNetworkQualityEstimator estimator; |
| 307 TestNetworkQualityEstimator estimator(variation_params); | |
| 308 | 306 |
| 309 estimator.SimulateNetworkChange( | 307 estimator.SimulateNetworkChange( |
| 310 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test"); | 308 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test"); |
| 311 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", | 309 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", |
| 312 false, 1); | 310 false, 1); |
| 313 | 311 |
| 314 base::TimeDelta rtt; | 312 base::TimeDelta rtt; |
| 315 int32_t kbps; | 313 int32_t kbps; |
| 316 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 314 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 317 EXPECT_FALSE( | 315 EXPECT_FALSE( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 // notified. |observer| must be notified once right after it was added, and | 367 // notified. |observer| must be notified once right after it was added, and |
| 370 // once again after the cached network quality was read. | 368 // once again after the cached network quality was read. |
| 371 EXPECT_LE(2U, observer.effective_connection_types().size()); | 369 EXPECT_LE(2U, observer.effective_connection_types().size()); |
| 372 EXPECT_EQ(estimator.GetEffectiveConnectionType(), | 370 EXPECT_EQ(estimator.GetEffectiveConnectionType(), |
| 373 observer.effective_connection_types().back()); | 371 observer.effective_connection_types().back()); |
| 374 EXPECT_EQ(1U, rtt_observer.observations().size()); | 372 EXPECT_EQ(1U, rtt_observer.observations().size()); |
| 375 EXPECT_EQ(1U, throughput_observer.observations().size()); | 373 EXPECT_EQ(1U, throughput_observer.observations().size()); |
| 376 } | 374 } |
| 377 | 375 |
| 378 TEST(NetworkQualityEstimatorTest, StoreObservations) { | 376 TEST(NetworkQualityEstimatorTest, StoreObservations) { |
| 379 std::map<std::string, std::string> variation_params; | 377 TestNetworkQualityEstimator estimator; |
| 380 TestNetworkQualityEstimator estimator(variation_params); | |
| 381 | 378 |
| 382 base::TimeDelta rtt; | 379 base::TimeDelta rtt; |
| 383 int32_t kbps; | 380 int32_t kbps; |
| 384 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 381 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 385 EXPECT_FALSE( | 382 EXPECT_FALSE( |
| 386 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 383 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 387 | 384 |
| 388 TestDelegate test_delegate; | 385 TestDelegate test_delegate; |
| 389 TestURLRequestContext context(true); | 386 TestURLRequestContext context(true); |
| 390 context.set_network_quality_estimator(&estimator); | 387 context.set_network_quality_estimator(&estimator); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 407 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-2"); | 404 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-2"); |
| 408 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 405 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 409 EXPECT_FALSE( | 406 EXPECT_FALSE( |
| 410 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 407 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 411 } | 408 } |
| 412 | 409 |
| 413 // This test notifies NetworkQualityEstimator of received data. Next, | 410 // This test notifies NetworkQualityEstimator of received data. Next, |
| 414 // throughput and RTT percentiles are checked for correctness by doing simple | 411 // throughput and RTT percentiles are checked for correctness by doing simple |
| 415 // verifications. | 412 // verifications. |
| 416 TEST(NetworkQualityEstimatorTest, ComputedPercentiles) { | 413 TEST(NetworkQualityEstimatorTest, ComputedPercentiles) { |
| 417 std::map<std::string, std::string> variation_params; | 414 TestNetworkQualityEstimator estimator; |
| 418 TestNetworkQualityEstimator estimator(variation_params); | |
| 419 | 415 |
| 420 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; | 416 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
| 421 disallowed_observation_sources.push_back( | 417 disallowed_observation_sources.push_back( |
| 422 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); | 418 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); |
| 423 disallowed_observation_sources.push_back( | 419 disallowed_observation_sources.push_back( |
| 424 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); | 420 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); |
| 425 | 421 |
| 426 EXPECT_EQ(nqe::internal::InvalidRTT(), | 422 EXPECT_EQ(nqe::internal::InvalidRTT(), |
| 427 estimator.GetRTTEstimateInternal(disallowed_observation_sources, | 423 estimator.GetRTTEstimateInternal(disallowed_observation_sources, |
| 428 base::TimeTicks(), 100)); | 424 base::TimeTicks(), 100)); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 DCHECK_NE(it_first->second, it_second->second); | 658 DCHECK_NE(it_first->second, it_second->second); |
| 663 } | 659 } |
| 664 } | 660 } |
| 665 } | 661 } |
| 666 } | 662 } |
| 667 } | 663 } |
| 668 | 664 |
| 669 // Tests that |GetEffectiveConnectionType| returns | 665 // Tests that |GetEffectiveConnectionType| returns |
| 670 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. | 666 // EFFECTIVE_CONNECTION_TYPE_OFFLINE when the device is currently offline. |
| 671 TEST(NetworkQualityEstimatorTest, Offline) { | 667 TEST(NetworkQualityEstimatorTest, Offline) { |
| 672 std::map<std::string, std::string> variation_params; | 668 TestNetworkQualityEstimator estimator; |
| 673 TestNetworkQualityEstimator estimator(variation_params); | |
| 674 | 669 |
| 675 const struct { | 670 const struct { |
| 676 NetworkChangeNotifier::ConnectionType connection_type; | 671 NetworkChangeNotifier::ConnectionType connection_type; |
| 677 EffectiveConnectionType expected_connection_type; | 672 EffectiveConnectionType expected_connection_type; |
| 678 } tests[] = { | 673 } tests[] = { |
| 679 {NetworkChangeNotifier::CONNECTION_2G, EFFECTIVE_CONNECTION_TYPE_UNKNOWN}, | 674 {NetworkChangeNotifier::CONNECTION_2G, EFFECTIVE_CONNECTION_TYPE_UNKNOWN}, |
| 680 {NetworkChangeNotifier::CONNECTION_NONE, | 675 {NetworkChangeNotifier::CONNECTION_NONE, |
| 681 EFFECTIVE_CONNECTION_TYPE_OFFLINE}, | 676 EFFECTIVE_CONNECTION_TYPE_OFFLINE}, |
| 682 {NetworkChangeNotifier::CONNECTION_3G, EFFECTIVE_CONNECTION_TYPE_UNKNOWN}, | 677 {NetworkChangeNotifier::CONNECTION_3G, EFFECTIVE_CONNECTION_TYPE_UNKNOWN}, |
| 683 }; | 678 }; |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 const base::TimeDelta external_estimate_provider_rtt = | 1320 const base::TimeDelta external_estimate_provider_rtt = |
| 1326 base::TimeDelta::FromMilliseconds(1); | 1321 base::TimeDelta::FromMilliseconds(1); |
| 1327 const int32_t external_estimate_provider_downstream_throughput = 100; | 1322 const int32_t external_estimate_provider_downstream_throughput = 100; |
| 1328 | 1323 |
| 1329 TestExternalEstimateProvider* test_external_estimate_provider = | 1324 TestExternalEstimateProvider* test_external_estimate_provider = |
| 1330 new TestExternalEstimateProvider( | 1325 new TestExternalEstimateProvider( |
| 1331 external_estimate_provider_rtt, | 1326 external_estimate_provider_rtt, |
| 1332 external_estimate_provider_downstream_throughput); | 1327 external_estimate_provider_downstream_throughput); |
| 1333 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( | 1328 std::unique_ptr<ExternalEstimateProvider> external_estimate_provider( |
| 1334 test_external_estimate_provider); | 1329 test_external_estimate_provider); |
| 1335 std::map<std::string, std::string> variation_params; | 1330 TestNetworkQualityEstimator estimator(std::map<std::string, std::string>(), |
| 1336 TestNetworkQualityEstimator estimator(variation_params, | |
| 1337 std::move(external_estimate_provider)); | 1331 std::move(external_estimate_provider)); |
| 1338 estimator.SimulateNetworkChange(net::NetworkChangeNotifier::CONNECTION_WIFI, | 1332 estimator.SimulateNetworkChange(net::NetworkChangeNotifier::CONNECTION_WIFI, |
| 1339 "test"); | 1333 "test"); |
| 1340 base::TimeDelta rtt; | 1334 base::TimeDelta rtt; |
| 1341 int32_t kbps; | 1335 int32_t kbps; |
| 1342 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 1336 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1343 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 1337 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 1344 EXPECT_TRUE( | 1338 EXPECT_TRUE( |
| 1345 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 1339 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1346 | 1340 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 | 1489 |
| 1496 // Tests that the effective connection type is computed at the specified | 1490 // Tests that the effective connection type is computed at the specified |
| 1497 // interval, and that the observers are notified of any change. | 1491 // interval, and that the observers are notified of any change. |
| 1498 TEST(NetworkQualityEstimatorTest, MAYBE_TestEffectiveConnectionTypeObserver) { | 1492 TEST(NetworkQualityEstimatorTest, MAYBE_TestEffectiveConnectionTypeObserver) { |
| 1499 base::HistogramTester histogram_tester; | 1493 base::HistogramTester histogram_tester; |
| 1500 std::unique_ptr<base::SimpleTestTickClock> tick_clock( | 1494 std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| 1501 new base::SimpleTestTickClock()); | 1495 new base::SimpleTestTickClock()); |
| 1502 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1496 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 1503 | 1497 |
| 1504 TestEffectiveConnectionTypeObserver observer; | 1498 TestEffectiveConnectionTypeObserver observer; |
| 1505 std::map<std::string, std::string> variation_params; | 1499 TestNetworkQualityEstimator estimator; |
| 1506 TestNetworkQualityEstimator estimator(variation_params); | |
| 1507 estimator.AddEffectiveConnectionTypeObserver(&observer); | 1500 estimator.AddEffectiveConnectionTypeObserver(&observer); |
| 1508 estimator.SetTickClockForTesting(std::move(tick_clock)); | 1501 estimator.SetTickClockForTesting(std::move(tick_clock)); |
| 1509 | 1502 |
| 1510 TestDelegate test_delegate; | 1503 TestDelegate test_delegate; |
| 1511 TestURLRequestContext context(true); | 1504 TestURLRequestContext context(true); |
| 1512 context.set_network_quality_estimator(&estimator); | 1505 context.set_network_quality_estimator(&estimator); |
| 1513 context.Init(); | 1506 context.Init(); |
| 1514 | 1507 |
| 1515 EXPECT_EQ(0U, observer.effective_connection_types().size()); | 1508 EXPECT_EQ(0U, observer.effective_connection_types().size()); |
| 1516 | 1509 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 | 1567 |
| 1575 // Tests that the network quality is computed at the specified interval, and | 1568 // Tests that the network quality is computed at the specified interval, and |
| 1576 // that the network quality observers are notified of any change. | 1569 // that the network quality observers are notified of any change. |
| 1577 TEST(NetworkQualityEstimatorTest, TestRTTAndThroughputEstimatesObserver) { | 1570 TEST(NetworkQualityEstimatorTest, TestRTTAndThroughputEstimatesObserver) { |
| 1578 base::HistogramTester histogram_tester; | 1571 base::HistogramTester histogram_tester; |
| 1579 std::unique_ptr<base::SimpleTestTickClock> tick_clock( | 1572 std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| 1580 new base::SimpleTestTickClock()); | 1573 new base::SimpleTestTickClock()); |
| 1581 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1574 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 1582 | 1575 |
| 1583 TestRTTAndThroughputEstimatesObserver observer; | 1576 TestRTTAndThroughputEstimatesObserver observer; |
| 1584 std::map<std::string, std::string> variation_params; | 1577 TestNetworkQualityEstimator estimator; |
| 1585 TestNetworkQualityEstimator estimator(variation_params); | |
| 1586 estimator.AddRTTAndThroughputEstimatesObserver(&observer); | 1578 estimator.AddRTTAndThroughputEstimatesObserver(&observer); |
| 1587 estimator.SetTickClockForTesting(std::move(tick_clock)); | 1579 estimator.SetTickClockForTesting(std::move(tick_clock)); |
| 1588 | 1580 |
| 1589 TestDelegate test_delegate; | 1581 TestDelegate test_delegate; |
| 1590 TestURLRequestContext context(true); | 1582 TestURLRequestContext context(true); |
| 1591 context.set_network_quality_estimator(&estimator); | 1583 context.set_network_quality_estimator(&estimator); |
| 1592 context.Init(); | 1584 context.Init(); |
| 1593 | 1585 |
| 1594 EXPECT_EQ(nqe::internal::InvalidRTT(), observer.http_rtt()); | 1586 EXPECT_EQ(nqe::internal::InvalidRTT(), observer.http_rtt()); |
| 1595 EXPECT_EQ(nqe::internal::InvalidRTT(), observer.transport_rtt()); | 1587 EXPECT_EQ(nqe::internal::InvalidRTT(), observer.transport_rtt()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1673 } | 1665 } |
| 1674 | 1666 |
| 1675 // Tests that the effective connection type is computed on every RTT | 1667 // Tests that the effective connection type is computed on every RTT |
| 1676 // observation if the last computed effective connection type was unknown. | 1668 // observation if the last computed effective connection type was unknown. |
| 1677 TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) { | 1669 TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) { |
| 1678 std::unique_ptr<base::SimpleTestTickClock> tick_clock( | 1670 std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| 1679 new base::SimpleTestTickClock()); | 1671 new base::SimpleTestTickClock()); |
| 1680 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1672 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 1681 | 1673 |
| 1682 TestEffectiveConnectionTypeObserver observer; | 1674 TestEffectiveConnectionTypeObserver observer; |
| 1683 std::map<std::string, std::string> variation_params; | 1675 TestNetworkQualityEstimator estimator; |
| 1684 TestNetworkQualityEstimator estimator(variation_params); | |
| 1685 estimator.SetTickClockForTesting(std::move(tick_clock)); | 1676 estimator.SetTickClockForTesting(std::move(tick_clock)); |
| 1686 estimator.AddEffectiveConnectionTypeObserver(&observer); | 1677 estimator.AddEffectiveConnectionTypeObserver(&observer); |
| 1687 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); | 1678 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
| 1688 | 1679 |
| 1689 size_t expected_effective_connection_type_notifications = 0; | 1680 size_t expected_effective_connection_type_notifications = 0; |
| 1690 estimator.set_recent_effective_connection_type( | 1681 estimator.set_recent_effective_connection_type( |
| 1691 EFFECTIVE_CONNECTION_TYPE_UNKNOWN); | 1682 EFFECTIVE_CONNECTION_TYPE_UNKNOWN); |
| 1692 // Run one main frame request to force recomputation of effective connection | 1683 // Run one main frame request to force recomputation of effective connection |
| 1693 // type. | 1684 // type. |
| 1694 estimator.RunOneRequest(); | 1685 estimator.RunOneRequest(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1720 // Tests that the effective connection type is computed regularly depending | 1711 // Tests that the effective connection type is computed regularly depending |
| 1721 // on the number of RTT and bandwidth samples. | 1712 // on the number of RTT and bandwidth samples. |
| 1722 TEST(NetworkQualityEstimatorTest, | 1713 TEST(NetworkQualityEstimatorTest, |
| 1723 AdaptiveRecomputationEffectiveConnectionType) { | 1714 AdaptiveRecomputationEffectiveConnectionType) { |
| 1724 base::HistogramTester histogram_tester; | 1715 base::HistogramTester histogram_tester; |
| 1725 std::unique_ptr<base::SimpleTestTickClock> tick_clock( | 1716 std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| 1726 new base::SimpleTestTickClock()); | 1717 new base::SimpleTestTickClock()); |
| 1727 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1718 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 1728 | 1719 |
| 1729 TestEffectiveConnectionTypeObserver observer; | 1720 TestEffectiveConnectionTypeObserver observer; |
| 1730 std::map<std::string, std::string> variation_params; | 1721 TestNetworkQualityEstimator estimator; |
| 1731 TestNetworkQualityEstimator estimator(variation_params); | |
| 1732 estimator.SetTickClockForTesting(std::move(tick_clock)); | 1722 estimator.SetTickClockForTesting(std::move(tick_clock)); |
| 1733 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, | 1723 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, |
| 1734 "test"); | 1724 "test"); |
| 1735 estimator.AddEffectiveConnectionTypeObserver(&observer); | 1725 estimator.AddEffectiveConnectionTypeObserver(&observer); |
| 1736 | 1726 |
| 1737 TestDelegate test_delegate; | 1727 TestDelegate test_delegate; |
| 1738 TestURLRequestContext context(true); | 1728 TestURLRequestContext context(true); |
| 1739 context.set_network_quality_estimator(&estimator); | 1729 context.set_network_quality_estimator(&estimator); |
| 1740 context.Init(); | 1730 context.Init(); |
| 1741 | 1731 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1804 } | 1794 } |
| 1805 EXPECT_EQ(expected_effective_connection_type_notifications, | 1795 EXPECT_EQ(expected_effective_connection_type_notifications, |
| 1806 observer.effective_connection_types().size()); | 1796 observer.effective_connection_types().size()); |
| 1807 } | 1797 } |
| 1808 } | 1798 } |
| 1809 } | 1799 } |
| 1810 | 1800 |
| 1811 TEST(NetworkQualityEstimatorTest, TestRttThroughputObservers) { | 1801 TEST(NetworkQualityEstimatorTest, TestRttThroughputObservers) { |
| 1812 TestRTTObserver rtt_observer; | 1802 TestRTTObserver rtt_observer; |
| 1813 TestThroughputObserver throughput_observer; | 1803 TestThroughputObserver throughput_observer; |
| 1814 std::map<std::string, std::string> variation_params; | 1804 TestNetworkQualityEstimator estimator; |
| 1815 TestNetworkQualityEstimator estimator(variation_params); | |
| 1816 estimator.AddRTTObserver(&rtt_observer); | 1805 estimator.AddRTTObserver(&rtt_observer); |
| 1817 estimator.AddThroughputObserver(&throughput_observer); | 1806 estimator.AddThroughputObserver(&throughput_observer); |
| 1818 | 1807 |
| 1819 TestDelegate test_delegate; | 1808 TestDelegate test_delegate; |
| 1820 TestURLRequestContext context(true); | 1809 TestURLRequestContext context(true); |
| 1821 context.set_network_quality_estimator(&estimator); | 1810 context.set_network_quality_estimator(&estimator); |
| 1822 context.Init(); | 1811 context.Init(); |
| 1823 | 1812 |
| 1824 EXPECT_EQ(0U, rtt_observer.observations().size()); | 1813 EXPECT_EQ(0U, rtt_observer.observations().size()); |
| 1825 EXPECT_EQ(0U, throughput_observer.observations().size()); | 1814 EXPECT_EQ(0U, throughput_observer.observations().size()); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1894 #if defined(TCP_INFO) || defined(OS_LINUX) | 1883 #if defined(TCP_INFO) || defined(OS_LINUX) |
| 1895 #define MAYBE_TestTCPSocketRTT TestTCPSocketRTT | 1884 #define MAYBE_TestTCPSocketRTT TestTCPSocketRTT |
| 1896 #else | 1885 #else |
| 1897 #define MAYBE_TestTCPSocketRTT DISABLED_TestTCPSocketRTT | 1886 #define MAYBE_TestTCPSocketRTT DISABLED_TestTCPSocketRTT |
| 1898 #endif | 1887 #endif |
| 1899 // Tests that the TCP socket notifies the Network Quality Estimator of TCP RTTs, | 1888 // Tests that the TCP socket notifies the Network Quality Estimator of TCP RTTs, |
| 1900 // which in turn notifies registered RTT observers. | 1889 // which in turn notifies registered RTT observers. |
| 1901 TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) { | 1890 TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) { |
| 1902 base::HistogramTester histogram_tester; | 1891 base::HistogramTester histogram_tester; |
| 1903 TestRTTObserver rtt_observer; | 1892 TestRTTObserver rtt_observer; |
| 1904 std::map<std::string, std::string> variation_params; | 1893 TestNetworkQualityEstimator estimator; |
| 1905 TestNetworkQualityEstimator estimator(variation_params); | |
| 1906 estimator.AddRTTObserver(&rtt_observer); | 1894 estimator.AddRTTObserver(&rtt_observer); |
| 1907 | 1895 |
| 1908 TestDelegate test_delegate; | 1896 TestDelegate test_delegate; |
| 1909 TestURLRequestContext context(true); | 1897 TestURLRequestContext context(true); |
| 1910 context.set_network_quality_estimator(&estimator); | 1898 context.set_network_quality_estimator(&estimator); |
| 1911 | 1899 |
| 1912 std::unique_ptr<HttpNetworkSession::Params> params( | 1900 std::unique_ptr<HttpNetworkSession::Params> params( |
| 1913 new HttpNetworkSession::Params); | 1901 new HttpNetworkSession::Params); |
| 1914 // |estimator| should be notified of TCP RTT observations. | 1902 // |estimator| should be notified of TCP RTT observations. |
| 1915 params->socket_performance_watcher_factory = | 1903 params->socket_performance_watcher_factory = |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2173 "NQE.ExternalEstimateProvider.RTT.Accuracy.EstimatedObservedDiff." + | 2161 "NQE.ExternalEstimateProvider.RTT.Accuracy.EstimatedObservedDiff." + |
| 2174 rtt_sign_suffix_with_zero_samples + "." + interval_value + | 2162 rtt_sign_suffix_with_zero_samples + "." + interval_value + |
| 2175 ".300_620", | 2163 ".300_620", |
| 2176 0); | 2164 0); |
| 2177 } | 2165 } |
| 2178 } | 2166 } |
| 2179 } | 2167 } |
| 2180 | 2168 |
| 2181 TEST(NetworkQualityEstimatorTest, TestRecordNetworkIDAvailability) { | 2169 TEST(NetworkQualityEstimatorTest, TestRecordNetworkIDAvailability) { |
| 2182 base::HistogramTester histogram_tester; | 2170 base::HistogramTester histogram_tester; |
| 2183 std::map<std::string, std::string> variation_params; | 2171 TestNetworkQualityEstimator estimator; |
| 2184 TestNetworkQualityEstimator estimator(variation_params); | |
| 2185 | 2172 |
| 2186 // The NetworkID is recorded as available on Wi-Fi connection. | 2173 // The NetworkID is recorded as available on Wi-Fi connection. |
| 2187 estimator.SimulateNetworkChange( | 2174 estimator.SimulateNetworkChange( |
| 2188 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); | 2175 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); |
| 2189 histogram_tester.ExpectUniqueSample("NQE.NetworkIdAvailable", 1, 1); | 2176 histogram_tester.ExpectUniqueSample("NQE.NetworkIdAvailable", 1, 1); |
| 2190 | 2177 |
| 2191 // The histogram is not recorded on an unknown connection. | 2178 // The histogram is not recorded on an unknown connection. |
| 2192 estimator.SimulateNetworkChange( | 2179 estimator.SimulateNetworkChange( |
| 2193 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, ""); | 2180 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, ""); |
| 2194 histogram_tester.ExpectTotalCount("NQE.NetworkIdAvailable", 1); | 2181 histogram_tester.ExpectTotalCount("NQE.NetworkIdAvailable", 1); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2393 nqe::internal::NetworkID network_id() const { return network_id_; } | 2380 nqe::internal::NetworkID network_id() const { return network_id_; } |
| 2394 | 2381 |
| 2395 private: | 2382 private: |
| 2396 nqe::internal::NetworkID network_id_; | 2383 nqe::internal::NetworkID network_id_; |
| 2397 size_t notification_received_; | 2384 size_t notification_received_; |
| 2398 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualitiesCacheObserver); | 2385 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualitiesCacheObserver); |
| 2399 }; | 2386 }; |
| 2400 | 2387 |
| 2401 TEST(NetworkQualityEstimatorTest, CacheObserver) { | 2388 TEST(NetworkQualityEstimatorTest, CacheObserver) { |
| 2402 TestNetworkQualitiesCacheObserver observer; | 2389 TestNetworkQualitiesCacheObserver observer; |
| 2403 std::map<std::string, std::string> variation_params; | 2390 TestNetworkQualityEstimator estimator; |
| 2404 TestNetworkQualityEstimator estimator(variation_params); | |
| 2405 | 2391 |
| 2406 // Add |observer| as a persistent caching observer. | 2392 // Add |observer| as a persistent caching observer. |
| 2407 estimator.AddNetworkQualitiesCacheObserver(&observer); | 2393 estimator.AddNetworkQualitiesCacheObserver(&observer); |
| 2408 | 2394 |
| 2409 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); | 2395 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); |
| 2410 estimator.SimulateNetworkChange( | 2396 estimator.SimulateNetworkChange( |
| 2411 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test3g"); | 2397 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test3g"); |
| 2412 estimator.RunOneRequest(); | 2398 estimator.RunOneRequest(); |
| 2413 EXPECT_EQ(1u, observer.get_notification_received_and_reset()); | 2399 EXPECT_EQ(1u, observer.get_notification_received_and_reset()); |
| 2414 EXPECT_EQ("test3g", observer.network_id().id); | 2400 EXPECT_EQ("test3g", observer.network_id().id); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2703 | 2689 |
| 2704 // Cleanup. | 2690 // Cleanup. |
| 2705 estimator.RemoveRTTObserver(&rtt_observer); | 2691 estimator.RemoveRTTObserver(&rtt_observer); |
| 2706 estimator.RemoveThroughputObserver(&throughput_observer); | 2692 estimator.RemoveThroughputObserver(&throughput_observer); |
| 2707 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); | 2693 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); |
| 2708 estimator.RemoveEffectiveConnectionTypeObserver( | 2694 estimator.RemoveEffectiveConnectionTypeObserver( |
| 2709 &effective_connection_type_observer); | 2695 &effective_connection_type_observer); |
| 2710 } | 2696 } |
| 2711 | 2697 |
| 2712 } // namespace net | 2698 } // namespace net |
| OLD | NEW |