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

Side by Side Diff: components/metrics/net/network_metrics_provider_unittest.cc

Issue 2605553002: Add EffectiveConnectionType enum to the system profile proto (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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/metrics/net/network_metrics_provider.h"
6
7 #include "base/callback.h"
8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h"
11 #include "base/threading/thread_task_runner_handle.h"
12 #include "components/metrics/proto/system_profile.pb.h"
13 #include "net/base/network_change_notifier.h"
14 #include "net/nqe/network_quality_estimator_test_util.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 #if defined(OS_CHROMEOS)
18 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/network/network_handler.h"
20 #endif // OS_CHROMEOS
21
22 namespace metrics {
23
24 namespace {
25
26 class TestNetworkQualityEstimatorProvider
27 : public NetworkMetricsProvider::NetworkQualityEstimatorProvider {
28 public:
29 explicit TestNetworkQualityEstimatorProvider(
30 net::TestNetworkQualityEstimator* estimator)
31 : estimator_(estimator) {}
32 ~TestNetworkQualityEstimatorProvider() override {}
33
34 private:
35 // NetworkMetricsProvider::NetworkQualityEstimatorProvider:
36 scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() override {
37 return base::ThreadTaskRunnerHandle::Get();
38 }
39
40 net::NetworkQualityEstimator* GetNetworkQualityEstimator() override {
41 return estimator_;
42 }
43
44 net::TestNetworkQualityEstimator* estimator_;
45 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimatorProvider);
46 };
47
48 } // namespace
49
50 // Verifies that the effective connection type is correctly set.
51 TEST(NetworkMetricsProviderTest, EffectiveConnectionType) {
52 base::MessageLoop loop(base::MessageLoop::TYPE_IO);
53
54 #if defined(OS_CHROMEOS)
55 chromeos::DBusThreadManager::Initialize();
56 chromeos::NetworkHandler::Initialize();
57 #endif // OS_CHROMEOS
58
59 net::TestNetworkQualityEstimator estimator;
60 std::unique_ptr<NetworkMetricsProvider::NetworkQualityEstimatorProvider>
61 estimator_provider(base::WrapUnique(
62 new TestNetworkQualityEstimatorProvider(&estimator)));
63 SystemProfileProto system_profile;
64 NetworkMetricsProvider network_metrics_provider(
65 std::move(estimator_provider), base::ThreadTaskRunnerHandle::Get().get());
66
67 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
68 network_metrics_provider.effective_connection_type_);
69 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile);
70 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
71 system_profile.network().effective_connection_type());
72
73 // Set RTT so that the effective connection type is computed as 2G.
74 estimator.set_recent_http_rtt(base::TimeDelta::FromMilliseconds(1500));
75 estimator.set_start_time_null_http_rtt(
76 base::TimeDelta::FromMilliseconds(1500));
77
78 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
79 network_metrics_provider.effective_connection_type_);
80 // Running a request would cause the effective connection type to be computed
81 // as 2G, and observers to be notified.
82 estimator.RunOneRequest();
83 base::RunLoop().RunUntilIdle();
84 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_2G,
85 network_metrics_provider.effective_connection_type_);
86 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile);
87 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_2G,
88 system_profile.network().effective_connection_type());
89
90 // Set RTT so that the effective connection type is computed as SLOW_2G.
91 estimator.set_recent_http_rtt(base::TimeDelta::FromMilliseconds(3000));
92 estimator.set_start_time_null_http_rtt(
93 base::TimeDelta::FromMilliseconds(3000));
94 // Running a request would cause the effective connection type to be computed
95 // as SLOW_2G, and observers to be notified.
96 estimator.RunOneRequest();
97 base::RunLoop().RunUntilIdle();
98 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
99 network_metrics_provider.effective_connection_type_);
100 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile);
101 // Effective connection type is set to ambiguous since the effective
102 // connection type changed from 2G to SLOW_2G during the lifetime of the log.
103 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_AMBIGUOUS,
104 system_profile.network().effective_connection_type());
105
106 // Getting the system profile again should return the actual effective
107 // connection type since the effective connection type did not change during
108 // the lifetime of the log.
109 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile);
110 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
111 system_profile.network().effective_connection_type());
112 }
113
114 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/net/network_metrics_provider.cc ('k') | components/metrics/proto/system_profile.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698