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

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, ryansturm comments, fix failing chromeos test 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 2016 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/message_loop/message_loop.h"
8 #include "base/run_loop.h"
9 #include "base/threading/thread_task_runner_handle.h"
10 #include "components/metrics/proto/system_profile.pb.h"
11 #include "net/base/network_change_notifier.h"
12 #include "net/nqe/network_quality_estimator_test_util.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 #if defined(OS_CHROMEOS)
16 #include "chromeos/dbus/dbus_thread_manager.h"
17 #include "chromeos/network/network_handler.h"
18 #endif // OS_CHROMEOS
19
20 namespace metrics {
21
22 // Verifies that the effective connection type is correctly set.
23 TEST(NetworkMetricsProviderTest, EffectiveConnectionType) {
24 base::MessageLoop loop(base::MessageLoop::TYPE_IO);
25
26 #if defined(OS_CHROMEOS)
27 chromeos::DBusThreadManager::Initialize();
28 chromeos::NetworkHandler::Initialize();
29 #endif // OS_CHROMEOS
30
31 net::TestNetworkQualityEstimator estimator;
32 SystemProfileProto system_profile;
33 NetworkMetricsProvider network_metrics_provider(
34 base::ThreadTaskRunnerHandle::Get().get());
35
36 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
37 network_metrics_provider.effective_connection_type_);
38 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile);
39 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
40 system_profile.network().effective_connection_type());
41
42 // Set RTT so that the effective connection type is computed as 2G.
43 estimator.set_recent_http_rtt(base::TimeDelta::FromMilliseconds(1500));
44 estimator.set_start_time_null_http_rtt(
45 base::TimeDelta::FromMilliseconds(1500));
46
47 network_metrics_provider.ProvideNetworkQualityEstimator(
48 &estimator, base::ThreadTaskRunnerHandle::Get());
49 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
50 network_metrics_provider.effective_connection_type_);
51 // Running a request would cause the effective connection type to be computed
52 // as 2G, and observers to be notified.
53 estimator.RunOneRequest();
54 base::RunLoop().RunUntilIdle();
55 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_2G,
56 network_metrics_provider.effective_connection_type_);
57 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile);
58 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_2G,
59 system_profile.network().effective_connection_type());
60
61 // Set RTT so that the effective connection type is computed as SLOW_2G.
62 estimator.set_recent_http_rtt(base::TimeDelta::FromMilliseconds(3000));
63 estimator.set_start_time_null_http_rtt(
64 base::TimeDelta::FromMilliseconds(3000));
65 // Running a request would cause the effective connection type to be computed
66 // as SLOW_2G, and observers to be notified.
67 estimator.RunOneRequest();
68 base::RunLoop().RunUntilIdle();
69 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
70 network_metrics_provider.effective_connection_type_);
71 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile);
72 // Effective connection type is set to ambiguous since the effective
73 // connection type changed from 2G to SLOW_2G during the lifetime of the log.
74 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_AMBIGUOUS,
75 system_profile.network().effective_connection_type());
76
77 // Getting the system profile again should return the actual effective
78 // connection type since the effective connection type did not change during
79 // the lifetime of the log.
80 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile);
81 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
82 system_profile.network().effective_connection_type());
83 }
84
85 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698