| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 "components/metrics/net/network_metrics_provider.h" | 5 #include "components/metrics/net/network_metrics_provider.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 net::NetworkQualityEstimator* GetNetworkQualityEstimator() override { | 40 net::NetworkQualityEstimator* GetNetworkQualityEstimator() override { |
| 41 return estimator_; | 41 return estimator_; |
| 42 } | 42 } |
| 43 | 43 |
| 44 net::TestNetworkQualityEstimator* estimator_; | 44 net::TestNetworkQualityEstimator* estimator_; |
| 45 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimatorProvider); | 45 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimatorProvider); |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 class NetworkMetricsProviderTest : public testing::Test { |
| 51 protected: |
| 52 NetworkMetricsProviderTest() : loop_(base::MessageLoop::TYPE_IO) { |
| 53 #if defined(OS_CHROMEOS) |
| 54 chromeos::DBusThreadManager::Initialize(); |
| 55 chromeos::NetworkHandler::Initialize(); |
| 56 #endif // OS_CHROMEOS |
| 57 } |
| 58 |
| 59 private: |
| 60 base::MessageLoop loop_; |
| 61 }; |
| 62 |
| 50 // Verifies that the effective connection type is correctly set. | 63 // Verifies that the effective connection type is correctly set. |
| 51 TEST(NetworkMetricsProviderTest, EffectiveConnectionType) { | 64 TEST_F(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; | 65 net::TestNetworkQualityEstimator estimator; |
| 60 std::unique_ptr<NetworkMetricsProvider::NetworkQualityEstimatorProvider> | 66 std::unique_ptr<NetworkMetricsProvider::NetworkQualityEstimatorProvider> |
| 61 estimator_provider(base::WrapUnique( | 67 estimator_provider(base::WrapUnique( |
| 62 new TestNetworkQualityEstimatorProvider(&estimator))); | 68 new TestNetworkQualityEstimatorProvider(&estimator))); |
| 63 SystemProfileProto system_profile; | 69 SystemProfileProto system_profile; |
| 64 NetworkMetricsProvider network_metrics_provider( | 70 NetworkMetricsProvider network_metrics_provider( |
| 65 std::move(estimator_provider), base::ThreadTaskRunnerHandle::Get().get()); | 71 std::move(estimator_provider), base::ThreadTaskRunnerHandle::Get().get()); |
| 66 | 72 |
| 67 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | 73 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 68 network_metrics_provider.effective_connection_type_); | 74 network_metrics_provider.effective_connection_type_); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 system_profile.network().effective_connection_type()); | 110 system_profile.network().effective_connection_type()); |
| 105 | 111 |
| 106 // Getting the system profile again should return the actual effective | 112 // Getting the system profile again should return the actual effective |
| 107 // connection type since the effective connection type did not change during | 113 // connection type since the effective connection type did not change during |
| 108 // the lifetime of the log. | 114 // the lifetime of the log. |
| 109 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile); | 115 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile); |
| 110 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, | 116 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
| 111 system_profile.network().effective_connection_type()); | 117 system_profile.network().effective_connection_type()); |
| 112 } | 118 } |
| 113 | 119 |
| 120 // Verifies that the effective connection type is set to AMBIGUOUS when there is |
| 121 // a change in the connection type. |
| 122 TEST_F(NetworkMetricsProviderTest, ECTAmbiguousOnConnectionTypeChange) { |
| 123 net::TestNetworkQualityEstimator estimator; |
| 124 std::unique_ptr<NetworkMetricsProvider::NetworkQualityEstimatorProvider> |
| 125 estimator_provider(base::WrapUnique( |
| 126 new TestNetworkQualityEstimatorProvider(&estimator))); |
| 127 SystemProfileProto system_profile; |
| 128 NetworkMetricsProvider network_metrics_provider( |
| 129 std::move(estimator_provider), base::ThreadTaskRunnerHandle::Get().get()); |
| 130 |
| 131 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 132 network_metrics_provider.effective_connection_type_); |
| 133 EXPECT_FALSE( |
| 134 network_metrics_provider.effective_connection_type_is_ambiguous_); |
| 135 |
| 136 network_metrics_provider.OnConnectionTypeChanged( |
| 137 net::NetworkChangeNotifier::CONNECTION_2G); |
| 138 EXPECT_TRUE(network_metrics_provider.effective_connection_type_is_ambiguous_); |
| 139 network_metrics_provider.ProvideSystemProfileMetrics(&system_profile); |
| 140 EXPECT_EQ(SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_AMBIGUOUS, |
| 141 system_profile.network().effective_connection_type()); |
| 142 } |
| 143 |
| 114 } // namespace metrics | 144 } // namespace metrics |
| OLD | NEW |