Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: chrome/browser/android/net/external_estimate_provider_android_unittest.cc

Issue 1316863006: Populate EEP estimate in NQE (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed asvitkine comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 8
9 #include "base/test/histogram_tester.h"
9 #include "base/time/time.h" 10 #include "base/time/time.h"
10 #include "net/base/network_quality_estimator.h" 11 #include "net/base/network_quality_estimator.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace { 14 namespace {
14 15
15 // Tests if the |ExternalEstimateProviderAndroid| APIs return false without the 16 // Tests if the |ExternalEstimateProviderAndroid| APIs return false without the
16 // downstream implementation. 17 // downstream implementation.
17 TEST(ExternalEstimateProviderAndroidTest, BasicsTest) { 18 TEST(ExternalEstimateProviderAndroidTest, BasicsTest) {
18 chrome::android::ExternalEstimateProviderAndroid external_estimate_provider; 19 chrome::android::ExternalEstimateProviderAndroid external_estimate_provider;
(...skipping 15 matching lines...) Expand all
34 TestNetworkQualityEstimator( 35 TestNetworkQualityEstimator(
35 scoped_ptr<chrome::android::ExternalEstimateProviderAndroid> 36 scoped_ptr<chrome::android::ExternalEstimateProviderAndroid>
36 external_estimate_provider, 37 external_estimate_provider,
37 const std::map<std::string, std::string>& variation_params) 38 const std::map<std::string, std::string>& variation_params)
38 : NetworkQualityEstimator(external_estimate_provider.Pass(), 39 : NetworkQualityEstimator(external_estimate_provider.Pass(),
39 variation_params), 40 variation_params),
40 notified_(false) {} 41 notified_(false) {}
41 42
42 ~TestNetworkQualityEstimator() override {} 43 ~TestNetworkQualityEstimator() override {}
43 44
44 void OnUpdatedEstimateAvailable() override { notified_ = true; } 45 void OnUpdatedEstimateAvailable() override {
46 notified_ = true;
47 net::NetworkQualityEstimator::OnUpdatedEstimateAvailable();
48 }
45 49
46 bool IsNotified() const { return notified_; } 50 bool IsNotified() const { return notified_; }
47 51
48 private: 52 private:
49 bool notified_; 53 bool notified_;
50 }; 54 };
51 55
52 class TestExternalEstimateProviderAndroid 56 class TestExternalEstimateProviderAndroid
53 : public chrome::android::ExternalEstimateProviderAndroid { 57 : public chrome::android::ExternalEstimateProviderAndroid {
54 public: 58 public:
55 TestExternalEstimateProviderAndroid() 59 TestExternalEstimateProviderAndroid()
56 : chrome::android::ExternalEstimateProviderAndroid() {} 60 : chrome::android::ExternalEstimateProviderAndroid() {}
57 ~TestExternalEstimateProviderAndroid() override {} 61 ~TestExternalEstimateProviderAndroid() override {}
58 using ExternalEstimateProviderAndroid::NotifyUpdatedEstimateAvailable; 62 using ExternalEstimateProviderAndroid::NotifyUpdatedEstimateAvailable;
63
64 bool GetTimeSinceLastUpdate(
65 base::TimeDelta* time_since_last_update) const override {
66 *time_since_last_update = base::TimeDelta::FromMilliseconds(1);
67 return true;
68 }
59 }; 69 };
60 70
61 // Tests if the |ExternalEstimateProviderAndroid| notifies 71 // Tests if the |ExternalEstimateProviderAndroid| notifies
62 // |NetworkQualityEstimator|. 72 // |NetworkQualityEstimator|.
63 TEST(ExternalEstimateProviderAndroidTest, DelegateTest) { 73 TEST(ExternalEstimateProviderAndroidTest, DelegateTest) {
74 base::HistogramTester histogram_tester;
64 scoped_ptr<TestExternalEstimateProviderAndroid> external_estimate_provider; 75 scoped_ptr<TestExternalEstimateProviderAndroid> external_estimate_provider;
65 external_estimate_provider.reset(new TestExternalEstimateProviderAndroid()); 76 external_estimate_provider.reset(new TestExternalEstimateProviderAndroid());
66 77
67 TestExternalEstimateProviderAndroid* ptr = external_estimate_provider.get(); 78 TestExternalEstimateProviderAndroid* ptr = external_estimate_provider.get();
68 std::map<std::string, std::string> variation_params; 79 std::map<std::string, std::string> variation_params;
69 TestNetworkQualityEstimator network_quality_estimator( 80 TestNetworkQualityEstimator network_quality_estimator(
70 external_estimate_provider.Pass(), variation_params); 81 external_estimate_provider.Pass(), variation_params);
71 ptr->NotifyUpdatedEstimateAvailable(); 82 ptr->NotifyUpdatedEstimateAvailable();
72 DCHECK(network_quality_estimator.IsNotified()); 83 DCHECK(network_quality_estimator.IsNotified());
84
85 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE
86 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 0,
87 0);
88
89 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE
90 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 1,
91 1);
92
93 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED
94 // Updated once during NetworkQualityEstimator constructor and again,
95 // when |OnUpdatedEstimateAvailable| is called.
96 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 2,
97 2);
98
99 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL
100 // Updated once during NetworkQualityEstimator constructor and again,
101 // when |OnUpdatedEstimateAvailable| is called.
102 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 3,
103 2);
104
105 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK
106 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 4,
107 1);
108
109 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 6);
73 } 110 }
74 111
75 } // namespace 112 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698