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

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

Issue 2593243003: Add network quality change events to net log (Closed)
Patch Set: rebased Created 3 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/io_thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/test/histogram_tester.h" 11 #include "base/test/histogram_tester.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "net/log/test_net_log.h"
14 #include "net/nqe/network_quality_estimator.h" 15 #include "net/nqe/network_quality_estimator.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace { 18 namespace {
18 19
19 // Tests if the |ExternalEstimateProviderAndroid| APIs return false without the 20 // Tests if the |ExternalEstimateProviderAndroid| APIs return false without the
20 // downstream implementation. 21 // downstream implementation.
21 TEST(ExternalEstimateProviderAndroidTest, BasicsTest) { 22 TEST(ExternalEstimateProviderAndroidTest, BasicsTest) {
22 base::ShadowingAtExitManager at_exit_manager; 23 base::ShadowingAtExitManager at_exit_manager;
23 chrome::android::ExternalEstimateProviderAndroid external_estimate_provider; 24 chrome::android::ExternalEstimateProviderAndroid external_estimate_provider;
24 25
25 base::TimeDelta rtt; 26 base::TimeDelta rtt;
26 EXPECT_FALSE(external_estimate_provider.GetRTT(&rtt)); 27 EXPECT_FALSE(external_estimate_provider.GetRTT(&rtt));
27 28
28 int32_t kbps; 29 int32_t kbps;
29 EXPECT_FALSE(external_estimate_provider.GetDownstreamThroughputKbps(&kbps)); 30 EXPECT_FALSE(external_estimate_provider.GetDownstreamThroughputKbps(&kbps));
30 EXPECT_FALSE(external_estimate_provider.GetUpstreamThroughputKbps(&kbps)); 31 EXPECT_FALSE(external_estimate_provider.GetUpstreamThroughputKbps(&kbps));
31 32
32 base::TimeDelta time_since_last_update; 33 base::TimeDelta time_since_last_update;
33 EXPECT_FALSE(external_estimate_provider.GetTimeSinceLastUpdate( 34 EXPECT_FALSE(external_estimate_provider.GetTimeSinceLastUpdate(
34 &time_since_last_update)); 35 &time_since_last_update));
35 } 36 }
36 37
37 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { 38 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator {
38 public: 39 public:
39 TestNetworkQualityEstimator( 40 TestNetworkQualityEstimator(
40 std::unique_ptr<chrome::android::ExternalEstimateProviderAndroid> 41 std::unique_ptr<chrome::android::ExternalEstimateProviderAndroid>
41 external_estimate_provider, 42 external_estimate_provider,
42 const std::map<std::string, std::string>& variation_params) 43 const std::map<std::string, std::string>& variation_params,
44 net::NetLog* net_log)
43 : NetworkQualityEstimator(std::move(external_estimate_provider), 45 : NetworkQualityEstimator(std::move(external_estimate_provider),
44 variation_params), 46 variation_params,
47 net_log),
45 notified_(false) {} 48 notified_(false) {}
46 49
47 ~TestNetworkQualityEstimator() override {} 50 ~TestNetworkQualityEstimator() override {}
48 51
49 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt, 52 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt,
50 int32_t downstream_throughput_kbps, 53 int32_t downstream_throughput_kbps,
51 int32_t upstream_throughput_kbps) override { 54 int32_t upstream_throughput_kbps) override {
52 EXPECT_EQ(base::TimeDelta(), rtt); 55 EXPECT_EQ(base::TimeDelta(), rtt);
53 EXPECT_EQ(-1, downstream_throughput_kbps); 56 EXPECT_EQ(-1, downstream_throughput_kbps);
54 EXPECT_EQ(-1, upstream_throughput_kbps); 57 EXPECT_EQ(-1, upstream_throughput_kbps);
(...skipping 29 matching lines...) Expand all
84 content::TestBrowserThreadBundle thread_bundle( 87 content::TestBrowserThreadBundle thread_bundle(
85 content::TestBrowserThreadBundle::IO_MAINLOOP); 88 content::TestBrowserThreadBundle::IO_MAINLOOP);
86 89
87 base::ShadowingAtExitManager at_exit_manager; 90 base::ShadowingAtExitManager at_exit_manager;
88 base::HistogramTester histogram_tester; 91 base::HistogramTester histogram_tester;
89 std::unique_ptr<TestExternalEstimateProviderAndroid> 92 std::unique_ptr<TestExternalEstimateProviderAndroid>
90 external_estimate_provider; 93 external_estimate_provider;
91 external_estimate_provider.reset(new TestExternalEstimateProviderAndroid()); 94 external_estimate_provider.reset(new TestExternalEstimateProviderAndroid());
92 95
93 TestExternalEstimateProviderAndroid* ptr = external_estimate_provider.get(); 96 TestExternalEstimateProviderAndroid* ptr = external_estimate_provider.get();
97 net::TestNetLog net_log;
94 std::map<std::string, std::string> variation_params; 98 std::map<std::string, std::string> variation_params;
95 TestNetworkQualityEstimator network_quality_estimator( 99 TestNetworkQualityEstimator network_quality_estimator(
96 std::move(external_estimate_provider), variation_params); 100 std::move(external_estimate_provider), variation_params, &net_log);
97 ptr->NotifyUpdatedEstimateAvailable(); 101 ptr->NotifyUpdatedEstimateAvailable();
98 EXPECT_TRUE(network_quality_estimator.notified()); 102 EXPECT_TRUE(network_quality_estimator.notified());
99 103
100 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 2); 104 histogram_tester.ExpectTotalCount("NQE.ExternalEstimateProviderStatus", 2);
101 105
102 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE 106 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE
103 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 1, 107 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 1,
104 1); 108 1);
105 109
106 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK 110 // EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK
107 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 4, 111 histogram_tester.ExpectBucketCount("NQE.ExternalEstimateProviderStatus", 4,
108 1); 112 1);
109 } 113 }
110 114
111 } // namespace 115 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/io_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698