OLD | NEW |
(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/macros.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 "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "net/base/network_change_notifier.h" |
| 13 #include "net/nqe/network_quality_estimator_test_util.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace metrics { |
| 17 |
| 18 // Verifies that the effective connection type is correctly set. |
| 19 TEST(NetworkMetricsProviderTest, EffectiveConnectionType) { |
| 20 content::TestBrowserThreadBundle thread_bundle( |
| 21 content::TestBrowserThreadBundle::IO_MAINLOOP); |
| 22 net::TestNetworkQualityEstimator estimator; |
| 23 SystemProfileProto system_profile; |
| 24 |
| 25 NetworkMetricsProvider network_metrics_provider( |
| 26 base::ThreadTaskRunnerHandle::Get().get()); |
| 27 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 28 network_metrics_provider.effective_connection_type_); |
| 29 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile); |
| 30 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 31 system_profile.network().effective_connection_type()); |
| 32 |
| 33 // Set RTT so that the effective connection type is computed as 2G. |
| 34 estimator.set_recent_http_rtt(base::TimeDelta::FromMilliseconds(1500)); |
| 35 estimator.set_start_time_null_http_rtt( |
| 36 base::TimeDelta::FromMilliseconds(1500)); |
| 37 |
| 38 network_metrics_provider.ProvideNetworkQualityEstimator( |
| 39 &estimator, base::ThreadTaskRunnerHandle::Get()); |
| 40 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 41 network_metrics_provider.effective_connection_type_); |
| 42 // Running a request would cause the effective connection type to be computed |
| 43 // as 2G, and observers to be notified. |
| 44 estimator.RunOneRequest(); |
| 45 base::RunLoop().RunUntilIdle(); |
| 46 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_2G, |
| 47 network_metrics_provider.effective_connection_type_); |
| 48 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile); |
| 49 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_2G, |
| 50 system_profile.network().effective_connection_type()); |
| 51 |
| 52 // Set RTT so that the effective connection type is computed as SLOW_2G. |
| 53 estimator.set_recent_http_rtt(base::TimeDelta::FromMilliseconds(3000)); |
| 54 estimator.set_start_time_null_http_rtt( |
| 55 base::TimeDelta::FromMilliseconds(3000)); |
| 56 // Running a request would cause the effective connection type to be computed |
| 57 // as SLOW_2G, and observers to be notified. |
| 58 estimator.RunOneRequest(); |
| 59 base::RunLoop().RunUntilIdle(); |
| 60 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
| 61 network_metrics_provider.effective_connection_type_); |
| 62 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile); |
| 63 // Effective connection type is set to ambiguous since the effective |
| 64 // connection type changed from 2G to SLOW_2G during the lifetime of the log. |
| 65 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_AMBIGUOUS, |
| 66 system_profile.network().effective_connection_type()); |
| 67 |
| 68 // Getting the system profile again should return the actual effective |
| 69 // connection type since the effective connection type did not change during |
| 70 // the lifetime of the log. |
| 71 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile); |
| 72 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
| 73 system_profile.network().effective_connection_type()); |
| 74 } |
| 75 |
| 76 } // namespace metrics |
OLD | NEW |