| 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 estimator.AddThroughputObserver(&throughput_observer); | 344 estimator.AddThroughputObserver(&throughput_observer); |
| 345 | 345 |
| 346 estimator.SimulateNetworkChange( | 346 estimator.SimulateNetworkChange( |
| 347 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test"); | 347 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test"); |
| 348 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true, | 348 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true, |
| 349 1); | 349 1); |
| 350 histogram_tester.ExpectTotalCount("NQE.CachedNetworkQualityAvailable", 2); | 350 histogram_tester.ExpectTotalCount("NQE.CachedNetworkQualityAvailable", 2); |
| 351 base::RunLoop().RunUntilIdle(); | 351 base::RunLoop().RunUntilIdle(); |
| 352 | 352 |
| 353 // Verify that the cached network quality was read, and observers were | 353 // Verify that the cached network quality was read, and observers were |
| 354 // notified. | 354 // notified. |observer| must be notified once right after it was added, and |
| 355 EXPECT_EQ(1U, observer.effective_connection_types().size()); | 355 // once again after the cached network quality was read. |
| 356 EXPECT_EQ(2U, observer.effective_connection_types().size()); |
| 356 EXPECT_EQ(1U, rtt_observer.observations().size()); | 357 EXPECT_EQ(1U, rtt_observer.observations().size()); |
| 357 EXPECT_EQ(1U, throughput_observer.observations().size()); | 358 EXPECT_EQ(1U, throughput_observer.observations().size()); |
| 358 } | 359 } |
| 359 | 360 |
| 360 TEST(NetworkQualityEstimatorTest, StoreObservations) { | 361 TEST(NetworkQualityEstimatorTest, StoreObservations) { |
| 361 std::map<std::string, std::string> variation_params; | 362 std::map<std::string, std::string> variation_params; |
| 362 TestNetworkQualityEstimator estimator(variation_params); | 363 TestNetworkQualityEstimator estimator(variation_params); |
| 363 | 364 |
| 364 base::TimeDelta rtt; | 365 base::TimeDelta rtt; |
| 365 int32_t kbps; | 366 int32_t kbps; |
| (...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, | 1428 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, |
| 1428 "test"); | 1429 "test"); |
| 1429 EXPECT_EQ(2U, observer.effective_connection_types().size()); | 1430 EXPECT_EQ(2U, observer.effective_connection_types().size()); |
| 1430 | 1431 |
| 1431 // A change in effective connection type does not trigger notification to the | 1432 // A change in effective connection type does not trigger notification to the |
| 1432 // observers, since it is not accompanied by any new observation or a network | 1433 // observers, since it is not accompanied by any new observation or a network |
| 1433 // change event. | 1434 // change event. |
| 1434 estimator.set_start_time_null_http_rtt( | 1435 estimator.set_start_time_null_http_rtt( |
| 1435 base::TimeDelta::FromMilliseconds(100)); | 1436 base::TimeDelta::FromMilliseconds(100)); |
| 1436 EXPECT_EQ(2U, observer.effective_connection_types().size()); | 1437 EXPECT_EQ(2U, observer.effective_connection_types().size()); |
| 1438 |
| 1439 TestEffectiveConnectionTypeObserver observer_2; |
| 1440 estimator.AddEffectiveConnectionTypeObserver(&observer_2); |
| 1441 EXPECT_EQ(0U, observer_2.effective_connection_types().size()); |
| 1442 base::RunLoop().RunUntilIdle(); |
| 1443 // |observer_2| must be notified as soon as it is added. |
| 1444 EXPECT_EQ(1U, observer_2.effective_connection_types().size()); |
| 1437 } | 1445 } |
| 1438 | 1446 |
| 1439 // Tests that the network quality is computed at the specified interval, and | 1447 // Tests that the network quality is computed at the specified interval, and |
| 1440 // that the network quality observers are notified of any change. | 1448 // that the network quality observers are notified of any change. |
| 1441 TEST(NetworkQualityEstimatorTest, TestRTTAndThroughputEstimatesObserver) { | 1449 TEST(NetworkQualityEstimatorTest, TestRTTAndThroughputEstimatesObserver) { |
| 1442 base::HistogramTester histogram_tester; | 1450 base::HistogramTester histogram_tester; |
| 1443 std::unique_ptr<base::SimpleTestTickClock> tick_clock( | 1451 std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| 1444 new base::SimpleTestTickClock()); | 1452 new base::SimpleTestTickClock()); |
| 1445 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1453 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 1446 | 1454 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 EXPECT_LE(1, observer.notifications_received() - notifications_received); | 1508 EXPECT_LE(1, observer.notifications_received() - notifications_received); |
| 1501 notifications_received = observer.notifications_received(); | 1509 notifications_received = observer.notifications_received(); |
| 1502 | 1510 |
| 1503 // A change in effective connection type does not trigger notification to the | 1511 // A change in effective connection type does not trigger notification to the |
| 1504 // observers, since it is not accompanied by any new observation or a network | 1512 // observers, since it is not accompanied by any new observation or a network |
| 1505 // change event. | 1513 // change event. |
| 1506 estimator.set_start_time_null_http_rtt( | 1514 estimator.set_start_time_null_http_rtt( |
| 1507 base::TimeDelta::FromMilliseconds(10000)); | 1515 base::TimeDelta::FromMilliseconds(10000)); |
| 1508 estimator.set_start_time_null_http_rtt(base::TimeDelta::FromMilliseconds(1)); | 1516 estimator.set_start_time_null_http_rtt(base::TimeDelta::FromMilliseconds(1)); |
| 1509 EXPECT_EQ(0, observer.notifications_received() - notifications_received); | 1517 EXPECT_EQ(0, observer.notifications_received() - notifications_received); |
| 1518 |
| 1519 TestRTTAndThroughputEstimatesObserver observer_2; |
| 1520 estimator.AddRTTAndThroughputEstimatesObserver(&observer_2); |
| 1521 EXPECT_EQ(nqe::internal::InvalidRTT(), observer_2.http_rtt()); |
| 1522 EXPECT_EQ(nqe::internal::InvalidRTT(), observer_2.transport_rtt()); |
| 1523 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
| 1524 observer_2.downstream_throughput_kbps()); |
| 1525 base::RunLoop().RunUntilIdle(); |
| 1526 EXPECT_NE(nqe::internal::InvalidRTT(), observer_2.http_rtt()); |
| 1527 EXPECT_NE(nqe::internal::InvalidRTT(), observer_2.transport_rtt()); |
| 1528 EXPECT_NE(nqe::internal::kInvalidThroughput, |
| 1529 observer_2.downstream_throughput_kbps()); |
| 1510 } | 1530 } |
| 1511 | 1531 |
| 1512 // Tests that the effective connection type is computed on every RTT | 1532 // Tests that the effective connection type is computed on every RTT |
| 1513 // observation if the last computed effective connection type was unknown. | 1533 // observation if the last computed effective connection type was unknown. |
| 1514 TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) { | 1534 TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) { |
| 1515 std::unique_ptr<base::SimpleTestTickClock> tick_clock( | 1535 std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| 1516 new base::SimpleTestTickClock()); | 1536 new base::SimpleTestTickClock()); |
| 1517 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1537 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 1518 | 1538 |
| 1519 TestEffectiveConnectionTypeObserver observer; | 1539 TestEffectiveConnectionTypeObserver observer; |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2320 if (expected_count == 1) { | 2340 if (expected_count == 1) { |
| 2321 EffectiveConnectionType last_notified_type = | 2341 EffectiveConnectionType last_notified_type = |
| 2322 observer.effective_connection_types().at( | 2342 observer.effective_connection_types().at( |
| 2323 observer.effective_connection_types().size() - 1); | 2343 observer.effective_connection_types().size() - 1); |
| 2324 EXPECT_EQ(i, last_notified_type); | 2344 EXPECT_EQ(i, last_notified_type); |
| 2325 } | 2345 } |
| 2326 } | 2346 } |
| 2327 } | 2347 } |
| 2328 | 2348 |
| 2329 } // namespace net | 2349 } // namespace net |
| OLD | NEW |