| 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 "chrome/browser/android/net/external_estimate_provider_android.h" | 5 #include "chrome/browser/android/net/external_estimate_provider_android.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/test/histogram_tester.h" | 12 #include "base/test/histogram_tester.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
| 14 #include "net/log/test_net_log.h" | 15 #include "net/log/test_net_log.h" |
| 15 #include "net/nqe/network_quality_estimator.h" | 16 #include "net/nqe/network_quality_estimator.h" |
| 17 #include "net/nqe/network_quality_estimator_params.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 // Tests if the |ExternalEstimateProviderAndroid| APIs return false without the | 22 // Tests if the |ExternalEstimateProviderAndroid| APIs return false without the |
| 21 // downstream implementation. | 23 // downstream implementation. |
| 22 TEST(ExternalEstimateProviderAndroidTest, BasicsTest) { | 24 TEST(ExternalEstimateProviderAndroidTest, BasicsTest) { |
| 23 base::ShadowingAtExitManager at_exit_manager; | 25 base::ShadowingAtExitManager at_exit_manager; |
| 24 chrome::android::ExternalEstimateProviderAndroid external_estimate_provider; | 26 chrome::android::ExternalEstimateProviderAndroid external_estimate_provider; |
| 25 | 27 |
| 26 base::TimeDelta rtt; | 28 base::TimeDelta rtt; |
| 27 EXPECT_FALSE(external_estimate_provider.GetRTT(&rtt)); | 29 EXPECT_FALSE(external_estimate_provider.GetRTT(&rtt)); |
| 28 | 30 |
| 29 int32_t kbps; | 31 int32_t kbps; |
| 30 EXPECT_FALSE(external_estimate_provider.GetDownstreamThroughputKbps(&kbps)); | 32 EXPECT_FALSE(external_estimate_provider.GetDownstreamThroughputKbps(&kbps)); |
| 31 EXPECT_FALSE(external_estimate_provider.GetUpstreamThroughputKbps(&kbps)); | 33 EXPECT_FALSE(external_estimate_provider.GetUpstreamThroughputKbps(&kbps)); |
| 32 | 34 |
| 33 base::TimeDelta time_since_last_update; | 35 base::TimeDelta time_since_last_update; |
| 34 EXPECT_FALSE(external_estimate_provider.GetTimeSinceLastUpdate( | 36 EXPECT_FALSE(external_estimate_provider.GetTimeSinceLastUpdate( |
| 35 &time_since_last_update)); | 37 &time_since_last_update)); |
| 36 } | 38 } |
| 37 | 39 |
| 38 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { | 40 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { |
| 39 public: | 41 public: |
| 40 TestNetworkQualityEstimator( | 42 TestNetworkQualityEstimator( |
| 41 std::unique_ptr<chrome::android::ExternalEstimateProviderAndroid> | 43 std::unique_ptr<chrome::android::ExternalEstimateProviderAndroid> |
| 42 external_estimate_provider, | 44 external_estimate_provider, |
| 43 const std::map<std::string, std::string>& variation_params, | 45 const std::map<std::string, std::string>& variation_params, |
| 44 net::NetLog* net_log) | 46 net::NetLog* net_log) |
| 45 : NetworkQualityEstimator(std::move(external_estimate_provider), | 47 : NetworkQualityEstimator( |
| 46 variation_params, | 48 std::move(external_estimate_provider), |
| 47 net_log), | 49 base::MakeUnique<net::NetworkQualityEstimatorParams>( |
| 50 variation_params), |
| 51 net_log), |
| 48 notified_(false) {} | 52 notified_(false) {} |
| 49 | 53 |
| 50 ~TestNetworkQualityEstimator() override {} | 54 ~TestNetworkQualityEstimator() override {} |
| 51 | 55 |
| 52 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt, | 56 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt, |
| 53 int32_t downstream_throughput_kbps, | 57 int32_t downstream_throughput_kbps, |
| 54 int32_t upstream_throughput_kbps) override { | 58 int32_t upstream_throughput_kbps) override { |
| 55 EXPECT_EQ(base::TimeDelta(), rtt); | 59 EXPECT_EQ(base::TimeDelta(), rtt); |
| 56 EXPECT_EQ(-1, downstream_throughput_kbps); | 60 EXPECT_EQ(-1, downstream_throughput_kbps); |
| 57 EXPECT_EQ(-1, upstream_throughput_kbps); | 61 EXPECT_EQ(-1, upstream_throughput_kbps); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE | 110 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE |
| 107 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 1, | 111 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 1, |
| 108 1); | 112 1); |
| 109 | 113 |
| 110 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK | 114 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK |
| 111 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 4, | 115 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 4, |
| 112 1); | 116 1); |
| 113 } | 117 } |
| 114 | 118 |
| 115 } // namespace | 119 } // namespace |
| OLD | NEW |