| 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 2624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2635 histogram_tester.ExpectUniqueSample("NQE.Prefs.ReadSize", read_prefs.size(), | 2635 histogram_tester.ExpectUniqueSample("NQE.Prefs.ReadSize", read_prefs.size(), |
| 2636 1); | 2636 1); |
| 2637 | 2637 |
| 2638 // Taken from network_quality_estimator_params.cc. | 2638 // Taken from network_quality_estimator_params.cc. |
| 2639 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1800), | 2639 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1800), |
| 2640 rtt_observer.last_rtt( | 2640 rtt_observer.last_rtt( |
| 2641 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE)); | 2641 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE)); |
| 2642 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1500), | 2642 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1500), |
| 2643 rtt_observer.last_rtt( | 2643 rtt_observer.last_rtt( |
| 2644 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE)); | 2644 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE)); |
| 2645 EXPECT_EQ(0u, throughput_observer.observations().size()); | 2645 EXPECT_EQ(1u, throughput_observer.observations().size()); |
| 2646 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1800), | 2646 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1800), |
| 2647 rtt_throughput_observer.http_rtt()); | 2647 rtt_throughput_observer.http_rtt()); |
| 2648 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1500), | 2648 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1500), |
| 2649 rtt_throughput_observer.transport_rtt()); | 2649 rtt_throughput_observer.transport_rtt()); |
| 2650 EXPECT_EQ(nqe::internal::kInvalidThroughput, | 2650 EXPECT_EQ(75, rtt_throughput_observer.downstream_throughput_kbps()); |
| 2651 rtt_throughput_observer.downstream_throughput_kbps()); | |
| 2652 EXPECT_LE( | 2651 EXPECT_LE( |
| 2653 1u, | 2652 1u, |
| 2654 effective_connection_type_observer.effective_connection_types().size()); | 2653 effective_connection_type_observer.effective_connection_types().size()); |
| 2655 // Compare the ECT stored in prefs with the observer's last entry. | 2654 // Compare the ECT stored in prefs with the observer's last entry. |
| 2656 EXPECT_EQ( | 2655 EXPECT_EQ( |
| 2657 read_prefs[nqe::internal::NetworkID( | 2656 read_prefs[nqe::internal::NetworkID( |
| 2658 NetworkChangeNotifier::CONNECTION_WIFI, network_name)] | 2657 NetworkChangeNotifier::CONNECTION_WIFI, network_name)] |
| 2659 .effective_connection_type(), | 2658 .effective_connection_type(), |
| 2660 effective_connection_type_observer.effective_connection_types().back()); | 2659 effective_connection_type_observer.effective_connection_types().back()); |
| 2661 | 2660 |
| 2662 // Change to a different connection type. | 2661 // Change to a different connection type. |
| 2663 network_name = "test_ect_slow_2g"; | 2662 network_name = "test_ect_slow_2g"; |
| 2664 estimator.SimulateNetworkChange( | 2663 estimator.SimulateNetworkChange( |
| 2665 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, network_name); | 2664 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, network_name); |
| 2666 | 2665 |
| 2667 EXPECT_EQ(base::TimeDelta::FromMilliseconds(3600), | 2666 EXPECT_EQ(base::TimeDelta::FromMilliseconds(3600), |
| 2668 rtt_observer.last_rtt( | 2667 rtt_observer.last_rtt( |
| 2669 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE)); | 2668 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE)); |
| 2670 EXPECT_EQ(base::TimeDelta::FromMilliseconds(3000), | 2669 EXPECT_EQ(base::TimeDelta::FromMilliseconds(3000), |
| 2671 rtt_observer.last_rtt( | 2670 rtt_observer.last_rtt( |
| 2672 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE)); | 2671 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE)); |
| 2673 EXPECT_EQ(0u, throughput_observer.observations().size()); | 2672 EXPECT_EQ(2U, throughput_observer.observations().size()); |
| 2674 EXPECT_EQ(base::TimeDelta::FromMilliseconds(3600), | 2673 EXPECT_EQ(base::TimeDelta::FromMilliseconds(3600), |
| 2675 rtt_throughput_observer.http_rtt()); | 2674 rtt_throughput_observer.http_rtt()); |
| 2676 EXPECT_EQ(base::TimeDelta::FromMilliseconds(3000), | 2675 EXPECT_EQ(base::TimeDelta::FromMilliseconds(3000), |
| 2677 rtt_throughput_observer.transport_rtt()); | 2676 rtt_throughput_observer.transport_rtt()); |
| 2678 EXPECT_EQ(nqe::internal::kInvalidThroughput, | 2677 EXPECT_EQ(40, rtt_throughput_observer.downstream_throughput_kbps()); |
| 2679 rtt_throughput_observer.downstream_throughput_kbps()); | |
| 2680 EXPECT_LE( | 2678 EXPECT_LE( |
| 2681 2u, | 2679 2u, |
| 2682 effective_connection_type_observer.effective_connection_types().size()); | 2680 effective_connection_type_observer.effective_connection_types().size()); |
| 2683 // Compare with the last entry. | 2681 // Compare with the last entry. |
| 2684 EXPECT_EQ( | 2682 EXPECT_EQ( |
| 2685 read_prefs[nqe::internal::NetworkID( | 2683 read_prefs[nqe::internal::NetworkID( |
| 2686 NetworkChangeNotifier::CONNECTION_WIFI, network_name)] | 2684 NetworkChangeNotifier::CONNECTION_WIFI, network_name)] |
| 2687 .effective_connection_type(), | 2685 .effective_connection_type(), |
| 2688 effective_connection_type_observer.effective_connection_types().back()); | 2686 effective_connection_type_observer.effective_connection_types().back()); |
| 2689 | 2687 |
| 2690 // Cleanup. | 2688 // Cleanup. |
| 2691 estimator.RemoveRTTObserver(&rtt_observer); | 2689 estimator.RemoveRTTObserver(&rtt_observer); |
| 2692 estimator.RemoveThroughputObserver(&throughput_observer); | 2690 estimator.RemoveThroughputObserver(&throughput_observer); |
| 2693 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); | 2691 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); |
| 2694 estimator.RemoveEffectiveConnectionTypeObserver( | 2692 estimator.RemoveEffectiveConnectionTypeObserver( |
| 2695 &effective_connection_type_observer); | 2693 &effective_connection_type_observer); |
| 2696 } | 2694 } |
| 2697 | 2695 |
| 2698 } // namespace net | 2696 } // namespace net |
| OLD | NEW |