| 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 | 9 |
| 9 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| 10 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
| 11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 12 #include "net/base/network_quality_estimator.h" | 13 #include "net/base/network_quality_estimator.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 // Tests if the |ExternalEstimateProviderAndroid| APIs return false without the | 18 // Tests if the |ExternalEstimateProviderAndroid| APIs return false without the |
| (...skipping 13 matching lines...) Expand all Loading... |
| 31 EXPECT_FALSE(external_estimate_provider.GetTimeSinceLastUpdate( | 32 EXPECT_FALSE(external_estimate_provider.GetTimeSinceLastUpdate( |
| 32 &time_since_last_update)); | 33 &time_since_last_update)); |
| 33 } | 34 } |
| 34 | 35 |
| 35 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { | 36 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { |
| 36 public: | 37 public: |
| 37 TestNetworkQualityEstimator( | 38 TestNetworkQualityEstimator( |
| 38 scoped_ptr<chrome::android::ExternalEstimateProviderAndroid> | 39 scoped_ptr<chrome::android::ExternalEstimateProviderAndroid> |
| 39 external_estimate_provider, | 40 external_estimate_provider, |
| 40 const std::map<std::string, std::string>& variation_params) | 41 const std::map<std::string, std::string>& variation_params) |
| 41 : NetworkQualityEstimator(external_estimate_provider.Pass(), | 42 : NetworkQualityEstimator(std::move(external_estimate_provider), |
| 42 variation_params), | 43 variation_params), |
| 43 notified_(false) {} | 44 notified_(false) {} |
| 44 | 45 |
| 45 ~TestNetworkQualityEstimator() override {} | 46 ~TestNetworkQualityEstimator() override {} |
| 46 | 47 |
| 47 void OnUpdatedEstimateAvailable() override { | 48 void OnUpdatedEstimateAvailable() override { |
| 48 notified_ = true; | 49 notified_ = true; |
| 49 net::NetworkQualityEstimator::OnUpdatedEstimateAvailable(); | 50 net::NetworkQualityEstimator::OnUpdatedEstimateAvailable(); |
| 50 } | 51 } |
| 51 | 52 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 74 // |NetworkQualityEstimator|. | 75 // |NetworkQualityEstimator|. |
| 75 TEST(ExternalEstimateProviderAndroidTest, DelegateTest) { | 76 TEST(ExternalEstimateProviderAndroidTest, DelegateTest) { |
| 76 base::ShadowingAtExitManager at_exit_manager; | 77 base::ShadowingAtExitManager at_exit_manager; |
| 77 base::HistogramTester histogram_tester; | 78 base::HistogramTester histogram_tester; |
| 78 scoped_ptr<TestExternalEstimateProviderAndroid> external_estimate_provider; | 79 scoped_ptr<TestExternalEstimateProviderAndroid> external_estimate_provider; |
| 79 external_estimate_provider.reset(new TestExternalEstimateProviderAndroid()); | 80 external_estimate_provider.reset(new TestExternalEstimateProviderAndroid()); |
| 80 | 81 |
| 81 TestExternalEstimateProviderAndroid* ptr = external_estimate_provider.get(); | 82 TestExternalEstimateProviderAndroid* ptr = external_estimate_provider.get(); |
| 82 std::map<std::string, std::string> variation_params; | 83 std::map<std::string, std::string> variation_params; |
| 83 TestNetworkQualityEstimator network_quality_estimator( | 84 TestNetworkQualityEstimator network_quality_estimator( |
| 84 external_estimate_provider.Pass(), variation_params); | 85 std::move(external_estimate_provider), variation_params); |
| 85 ptr->NotifyUpdatedEstimateAvailable(); | 86 ptr->NotifyUpdatedEstimateAvailable(); |
| 86 DCHECK(network_quality_estimator.IsNotified()); | 87 DCHECK(network_quality_estimator.IsNotified()); |
| 87 | 88 |
| 88 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE | 89 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE |
| 89 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 0, | 90 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 0, |
| 90 0); | 91 0); |
| 91 | 92 |
| 92 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE | 93 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE |
| 93 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 1, | 94 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 1, |
| 94 1); | 95 1); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 106 2); | 107 2); |
| 107 | 108 |
| 108 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK | 109 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK |
| 109 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 4, | 110 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 4, |
| 110 1); | 111 1); |
| 111 | 112 |
| 112 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 6); | 113 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 6); |
| 113 } | 114 } |
| 114 | 115 |
| 115 } // namespace | 116 } // namespace |
| OLD | NEW |