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 2739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2750 EXPECT_EQ(0u, observer.get_notification_received_and_reset()); | 2750 EXPECT_EQ(0u, observer.get_notification_received_and_reset()); |
2751 estimator.RunOneRequest(); | 2751 estimator.RunOneRequest(); |
2752 EXPECT_EQ(0u, observer.get_notification_received_and_reset()); | 2752 EXPECT_EQ(0u, observer.get_notification_received_and_reset()); |
2753 } | 2753 } |
2754 | 2754 |
2755 // Tests that the value of the effective connection type can be forced through | 2755 // Tests that the value of the effective connection type can be forced through |
2756 // field trial parameters. | 2756 // field trial parameters. |
2757 TEST(NetworkQualityEstimatorTest, | 2757 TEST(NetworkQualityEstimatorTest, |
2758 ForceEffectiveConnectionTypeThroughFieldTrial) { | 2758 ForceEffectiveConnectionTypeThroughFieldTrial) { |
2759 for (int i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { | 2759 for (int i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { |
| 2760 EffectiveConnectionType ect_type = static_cast<EffectiveConnectionType>(i); |
2760 std::map<std::string, std::string> variation_params; | 2761 std::map<std::string, std::string> variation_params; |
2761 variation_params[kForceEffectiveConnectionType] = | 2762 variation_params[kForceEffectiveConnectionType] = |
2762 GetNameForEffectiveConnectionType( | 2763 GetNameForEffectiveConnectionType( |
2763 static_cast<EffectiveConnectionType>(i)); | 2764 static_cast<EffectiveConnectionType>(i)); |
2764 TestNetworkQualityEstimator estimator(variation_params); | 2765 TestNetworkQualityEstimator estimator(variation_params); |
2765 | 2766 |
2766 TestEffectiveConnectionTypeObserver observer; | 2767 TestEffectiveConnectionTypeObserver ect_observer; |
2767 estimator.AddEffectiveConnectionTypeObserver(&observer); | 2768 estimator.AddEffectiveConnectionTypeObserver(&ect_observer); |
| 2769 TestRTTAndThroughputEstimatesObserver rtt_throughput_observer; |
| 2770 estimator.AddRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); |
2768 // |observer| may be notified as soon as it is added. Run the loop to so | 2771 // |observer| may be notified as soon as it is added. Run the loop to so |
2769 // that the notification to |observer| is finished. | 2772 // that the notification to |observer| is finished. |
2770 base::RunLoop().RunUntilIdle(); | 2773 base::RunLoop().RunUntilIdle(); |
2771 | 2774 |
2772 TestDelegate test_delegate; | 2775 TestDelegate test_delegate; |
2773 TestURLRequestContext context(true); | 2776 TestURLRequestContext context(true); |
2774 context.set_network_quality_estimator(&estimator); | 2777 context.set_network_quality_estimator(&estimator); |
2775 context.Init(); | 2778 context.Init(); |
2776 | 2779 |
2777 EXPECT_EQ(0U, observer.effective_connection_types().size()); | 2780 EXPECT_EQ(0U, ect_observer.effective_connection_types().size()); |
2778 | 2781 |
2779 std::unique_ptr<URLRequest> request( | 2782 std::unique_ptr<URLRequest> request( |
2780 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, | 2783 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
2781 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); | 2784 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
2782 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 2785 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
2783 request->Start(); | 2786 request->Start(); |
2784 base::RunLoop().Run(); | 2787 base::RunLoop().Run(); |
2785 | 2788 |
2786 EXPECT_EQ(i, estimator.GetEffectiveConnectionType()); | 2789 EXPECT_EQ(i, estimator.GetEffectiveConnectionType()); |
2787 | 2790 |
2788 size_t expected_count = static_cast<EffectiveConnectionType>(i) == | 2791 size_t expected_count = |
2789 EFFECTIVE_CONNECTION_TYPE_UNKNOWN | 2792 ect_type == EFFECTIVE_CONNECTION_TYPE_UNKNOWN ? 0 : 1; |
2790 ? 0 | 2793 ASSERT_EQ(expected_count, ect_observer.effective_connection_types().size()); |
2791 : 1; | |
2792 ASSERT_EQ(expected_count, observer.effective_connection_types().size()); | |
2793 if (expected_count == 1) { | 2794 if (expected_count == 1) { |
2794 EffectiveConnectionType last_notified_type = | 2795 EffectiveConnectionType last_notified_type = |
2795 observer.effective_connection_types().at( | 2796 ect_observer.effective_connection_types().at( |
2796 observer.effective_connection_types().size() - 1); | 2797 ect_observer.effective_connection_types().size() - 1); |
2797 EXPECT_EQ(i, last_notified_type); | 2798 EXPECT_EQ(i, last_notified_type); |
| 2799 |
| 2800 if (ect_type == EFFECTIVE_CONNECTION_TYPE_UNKNOWN || |
| 2801 ect_type == EFFECTIVE_CONNECTION_TYPE_OFFLINE) { |
| 2802 EXPECT_EQ(nqe::internal::InvalidRTT(), |
| 2803 rtt_throughput_observer.http_rtt()); |
| 2804 EXPECT_EQ(nqe::internal::InvalidRTT(), |
| 2805 rtt_throughput_observer.transport_rtt()); |
| 2806 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
| 2807 rtt_throughput_observer.downstream_throughput_kbps()); |
| 2808 } else { |
| 2809 EXPECT_EQ(estimator.params_.TypicalNetworkQuality(ect_type).http_rtt(), |
| 2810 rtt_throughput_observer.http_rtt()); |
| 2811 EXPECT_EQ( |
| 2812 estimator.params_.TypicalNetworkQuality(ect_type).transport_rtt(), |
| 2813 rtt_throughput_observer.transport_rtt()); |
| 2814 EXPECT_EQ(estimator.params_.TypicalNetworkQuality(ect_type) |
| 2815 .downstream_throughput_kbps(), |
| 2816 rtt_throughput_observer.downstream_throughput_kbps()); |
| 2817 } |
2798 } | 2818 } |
2799 } | 2819 } |
2800 } | 2820 } |
2801 | 2821 |
2802 // Test that the typical network qualities are set correctly. | 2822 // Test that the typical network qualities are set correctly. |
2803 TEST(NetworkQualityEstimatorTest, TypicalNetworkQualities) { | 2823 TEST(NetworkQualityEstimatorTest, TypicalNetworkQualities) { |
2804 const struct { | 2824 const struct { |
2805 bool use_transport_rtt; | 2825 bool use_transport_rtt; |
2806 } tests[] = { | 2826 } tests[] = { |
2807 { | 2827 { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3059 | 3079 |
3060 // Cleanup. | 3080 // Cleanup. |
3061 estimator.RemoveRTTObserver(&rtt_observer); | 3081 estimator.RemoveRTTObserver(&rtt_observer); |
3062 estimator.RemoveThroughputObserver(&throughput_observer); | 3082 estimator.RemoveThroughputObserver(&throughput_observer); |
3063 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); | 3083 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); |
3064 estimator.RemoveEffectiveConnectionTypeObserver( | 3084 estimator.RemoveEffectiveConnectionTypeObserver( |
3065 &effective_connection_type_observer); | 3085 &effective_connection_type_observer); |
3066 } | 3086 } |
3067 | 3087 |
3068 } // namespace net | 3088 } // namespace net |
OLD | NEW |