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

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

Issue 2010003002: Reduce the number of calls to external estimate provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 6 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
(...skipping 28 matching lines...) Expand all
39 TestNetworkQualityEstimator( 39 TestNetworkQualityEstimator(
40 std::unique_ptr<chrome::android::ExternalEstimateProviderAndroid> 40 std::unique_ptr<chrome::android::ExternalEstimateProviderAndroid>
41 external_estimate_provider, 41 external_estimate_provider,
42 const std::map<std::string, std::string>& variation_params) 42 const std::map<std::string, std::string>& variation_params)
43 : NetworkQualityEstimator(std::move(external_estimate_provider), 43 : NetworkQualityEstimator(std::move(external_estimate_provider),
44 variation_params), 44 variation_params),
45 notified_(false) {} 45 notified_(false) {}
46 46
47 ~TestNetworkQualityEstimator() override {} 47 ~TestNetworkQualityEstimator() override {}
48 48
49 void OnUpdatedEstimateAvailable() override { 49 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt,
50 int32_t downstream_throughput_kbps,
51 int32_t upstream_throughput_kbps) override {
52 EXPECT_EQ(base::TimeDelta(), rtt);
53 EXPECT_EQ(-1, downstream_throughput_kbps);
54 EXPECT_EQ(-1, upstream_throughput_kbps);
50 notified_ = true; 55 notified_ = true;
51 net::NetworkQualityEstimator::OnUpdatedEstimateAvailable(); 56 net::NetworkQualityEstimator::OnUpdatedEstimateAvailable(
57 rtt, downstream_throughput_kbps, upstream_throughput_kbps);
52 } 58 }
53 59
54 bool IsNotified() const { return notified_; } 60 bool notified() const { return notified_; }
55 61
56 private: 62 private:
57 bool notified_; 63 bool notified_;
58 }; 64 };
59 65
60 class TestExternalEstimateProviderAndroid 66 class TestExternalEstimateProviderAndroid
61 : public chrome::android::ExternalEstimateProviderAndroid { 67 : public chrome::android::ExternalEstimateProviderAndroid {
62 public: 68 public:
63 TestExternalEstimateProviderAndroid() 69 TestExternalEstimateProviderAndroid()
64 : chrome::android::ExternalEstimateProviderAndroid() {} 70 : chrome::android::ExternalEstimateProviderAndroid() {}
65 ~TestExternalEstimateProviderAndroid() override {} 71 ~TestExternalEstimateProviderAndroid() override {}
66 using ExternalEstimateProviderAndroid::NotifyUpdatedEstimateAvailable; 72 using ExternalEstimateProviderAndroid::NotifyUpdatedEstimateAvailable;
67 73
68 bool GetTimeSinceLastUpdate( 74 bool GetTimeSinceLastUpdate(
69 base::TimeDelta* time_since_last_update) const override { 75 base::TimeDelta* time_since_last_update) const override {
70 *time_since_last_update = base::TimeDelta::FromMilliseconds(1); 76 *time_since_last_update = base::TimeDelta::FromMilliseconds(0);
71 return true; 77 return true;
72 } 78 }
73 }; 79 };
74 80
75 // Tests if the |ExternalEstimateProviderAndroid| notifies 81 // Tests if the |ExternalEstimateProviderAndroid| notifies
76 // |NetworkQualityEstimator|. 82 // |NetworkQualityEstimator|.
77 TEST(ExternalEstimateProviderAndroidTest, DelegateTest) { 83 TEST(ExternalEstimateProviderAndroidTest, DelegateTest) {
78 content::TestBrowserThreadBundle thread_bundle( 84 content::TestBrowserThreadBundle thread_bundle(
79 content::TestBrowserThreadBundle::IO_MAINLOOP); 85 content::TestBrowserThreadBundle::IO_MAINLOOP);
80 86
81 base::ShadowingAtExitManager at_exit_manager; 87 base::ShadowingAtExitManager at_exit_manager;
82 base::HistogramTester histogram_tester; 88 base::HistogramTester histogram_tester;
83 std::unique_ptr<TestExternalEstimateProviderAndroid> 89 std::unique_ptr<TestExternalEstimateProviderAndroid>
84 external_estimate_provider; 90 external_estimate_provider;
85 external_estimate_provider.reset(new TestExternalEstimateProviderAndroid()); 91 external_estimate_provider.reset(new TestExternalEstimateProviderAndroid());
86 92
87 TestExternalEstimateProviderAndroid* ptr = external_estimate_provider.get(); 93 TestExternalEstimateProviderAndroid* ptr = external_estimate_provider.get();
88 std::map<std::string, std::string> variation_params; 94 std::map<std::string, std::string> variation_params;
89 TestNetworkQualityEstimator network_quality_estimator( 95 TestNetworkQualityEstimator network_quality_estimator(
90 std::move(external_estimate_provider), variation_params); 96 std::move(external_estimate_provider), variation_params);
91 ptr->NotifyUpdatedEstimateAvailable(); 97 ptr->NotifyUpdatedEstimateAvailable();
92 DCHECK(network_quality_estimator.IsNotified()); 98 EXPECT_TRUE(network_quality_estimator.notified());
93 99
94 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE 100 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 2);
95 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 0,
96 0);
97 101
98 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE 102 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE
99 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 1, 103 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 1,
100 1); 104 1);
101 105
102 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED
103 // Updated once during NetworkQualityEstimator constructor and again,
104 // when |OnUpdatedEstimateAvailable| is called.
105 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 2,
106 2);
107
108 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL
109 // Updated once during NetworkQualityEstimator constructor and again,
110 // when |OnUpdatedEstimateAvailable| is called.
111 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 3,
112 2);
113
114 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK 106 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK
115 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 4, 107 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 4,
116 1); 108 1);
117
118 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 6);
119 } 109 }
120 110
121 } // namespace 111 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/android/net/external_estimate_provider_android.cc ('k') | net/nqe/external_estimate_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698