Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 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 "shill/metrics.h" |
| 6 | |
| 7 | #include <chromeos/dbus/service_constants.h> |
| 8 | #include <metrics/metrics_library_mock.h> |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 9 | #include <metrics/timer_mock.h> |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 10 | |
| 11 | #include "shill/mock_service.h" |
| 12 | #include "shill/mock_wifi_service.h" |
| 13 | #include "shill/property_store_unittest.h" |
| 14 | |
| 15 | using testing::_; |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 16 | using testing::DoAll; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 17 | using testing::Ge; |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 18 | using testing::Mock; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 19 | using testing::Return; |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 20 | using testing::SetArgumentPointee; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 21 | using testing::Test; |
| 22 | |
| 23 | namespace shill { |
| 24 | |
| 25 | class MetricsTest : public PropertyStoreTest { |
| 26 | public: |
| 27 | MetricsTest() |
| 28 | : service_(new MockService(control_interface(), |
| 29 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 30 | &metrics_, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 31 | manager())), |
| 32 | wifi_(new WiFi(control_interface(), |
| 33 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 34 | &metrics_, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 35 | manager(), |
| 36 | "wlan0", |
| 37 | "000102030405", |
| 38 | 0)), |
| 39 | wifi_service_(new MockWiFiService(control_interface(), |
| 40 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 41 | &metrics_, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 42 | manager(), |
| 43 | wifi_, |
| 44 | ssid_, |
| 45 | flimflam::kModeManaged, |
| 46 | flimflam::kSecurityNone, |
| 47 | false)) { |
| 48 | } |
| 49 | |
| 50 | virtual ~MetricsTest() {} |
| 51 | |
| 52 | virtual void SetUp() { |
| 53 | metrics_.set_library(&library_); |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 54 | metrics_.collect_bootstats_ = false; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | protected: |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 58 | void ExpectCommonPostReady(Metrics::WiFiChannel channel, |
| 59 | Metrics::WiFiNetworkPhyMode mode, |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 60 | Metrics::WiFiSecurity security, |
| 61 | int signal_strength) { |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 62 | EXPECT_CALL(library_, SendEnumToUMA("Network.Shill.Wifi.Channel", |
| 63 | channel, |
| 64 | Metrics::kMetricNetworkChannelMax)); |
| 65 | EXPECT_CALL(library_, SendEnumToUMA("Network.Shill.Wifi.PhyMode", |
| 66 | mode, |
| 67 | Metrics::kWiFiNetworkPhyModeMax)); |
| 68 | EXPECT_CALL(library_, SendEnumToUMA("Network.Shill.Wifi.Security", |
| 69 | security, |
| 70 | Metrics::kWiFiSecurityMax)); |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 71 | EXPECT_CALL(library_, |
| 72 | SendToUMA("Network.Shill.Wifi.SignalStrength", |
| 73 | signal_strength, |
| 74 | Metrics::kMetricNetworkSignalStrengthMin, |
| 75 | Metrics::kMetricNetworkSignalStrengthMax, |
| 76 | Metrics::kMetricNetworkSignalStrengthNumBuckets)); |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 79 | Metrics metrics_; // This must be destroyed after service_ and wifi_service_ |
| 80 | MetricsLibraryMock library_; |
| 81 | scoped_refptr<MockService> service_; |
| 82 | WiFiRefPtr wifi_; |
| 83 | const std::vector<uint8_t> ssid_; |
| 84 | scoped_refptr<MockWiFiService> wifi_service_; |
| 85 | }; |
| 86 | |
| 87 | TEST_F(MetricsTest, TimeToConfig) { |
| 88 | EXPECT_CALL(library_, SendToUMA("Network.Shill.Unknown.TimeToConfig", |
| 89 | Ge(0), |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 90 | Metrics::kTimerHistogramMillisecondsMin, |
| 91 | Metrics::kTimerHistogramMillisecondsMax, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 92 | Metrics::kTimerHistogramNumBuckets)); |
| 93 | metrics_.RegisterService(service_); |
| 94 | metrics_.NotifyServiceStateChanged(service_, Service::kStateConfiguring); |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 95 | metrics_.NotifyServiceStateChanged(service_, Service::kStateConnected); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | TEST_F(MetricsTest, TimeToPortal) { |
| 99 | EXPECT_CALL(library_, SendToUMA("Network.Shill.Unknown.TimeToPortal", |
| 100 | Ge(0), |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 101 | Metrics::kTimerHistogramMillisecondsMin, |
| 102 | Metrics::kTimerHistogramMillisecondsMax, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 103 | Metrics::kTimerHistogramNumBuckets)); |
| 104 | metrics_.RegisterService(service_); |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 105 | metrics_.NotifyServiceStateChanged(service_, Service::kStateConnected); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 106 | metrics_.NotifyServiceStateChanged(service_, Service::kStatePortal); |
| 107 | } |
| 108 | |
| 109 | TEST_F(MetricsTest, TimeToOnline) { |
| 110 | EXPECT_CALL(library_, SendToUMA("Network.Shill.Unknown.TimeToOnline", |
| 111 | Ge(0), |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 112 | Metrics::kTimerHistogramMillisecondsMin, |
| 113 | Metrics::kTimerHistogramMillisecondsMax, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 114 | Metrics::kTimerHistogramNumBuckets)); |
| 115 | metrics_.RegisterService(service_); |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 116 | metrics_.NotifyServiceStateChanged(service_, Service::kStateConnected); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 117 | metrics_.NotifyServiceStateChanged(service_, Service::kStateOnline); |
| 118 | } |
| 119 | |
| 120 | TEST_F(MetricsTest, ServiceFailure) { |
| 121 | EXPECT_CALL(*service_.get(), failure()) |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 122 | .WillRepeatedly(Return(Service::kFailureBadPassphrase)); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 123 | EXPECT_CALL(library_, SendEnumToUMA(Metrics::kMetricNetworkServiceErrors, |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 124 | Service::kFailureBadPassphrase, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 125 | Metrics::kMetricNetworkServiceErrorsMax)); |
| 126 | metrics_.RegisterService(service_); |
| 127 | metrics_.NotifyServiceStateChanged(service_, Service::kStateFailure); |
| 128 | } |
| 129 | |
| 130 | TEST_F(MetricsTest, WiFiServiceTimeToJoin) { |
| 131 | EXPECT_CALL(library_, SendToUMA("Network.Shill.Wifi.TimeToJoin", |
| 132 | Ge(0), |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 133 | Metrics::kTimerHistogramMillisecondsMin, |
| 134 | Metrics::kTimerHistogramMillisecondsMax, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 135 | Metrics::kTimerHistogramNumBuckets)); |
| 136 | metrics_.RegisterService(wifi_service_); |
| 137 | metrics_.NotifyServiceStateChanged(wifi_service_, Service::kStateAssociating); |
| 138 | metrics_.NotifyServiceStateChanged(wifi_service_, Service::kStateConfiguring); |
| 139 | } |
| 140 | |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 141 | TEST_F(MetricsTest, WiFiServicePostReady) { |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 142 | base::TimeDelta non_zero_time_delta = base::TimeDelta::FromMilliseconds(1); |
| 143 | chromeos_metrics::TimerMock *mock_time_resume_to_ready_timer = |
| 144 | new chromeos_metrics::TimerMock; |
| 145 | metrics_.set_time_resume_to_ready_timer(mock_time_resume_to_ready_timer); |
| 146 | |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 147 | const int kStrength = -42; |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 148 | ExpectCommonPostReady(Metrics::kWiFiChannel2412, |
| 149 | Metrics::kWiFiNetworkPhyMode11a, |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 150 | Metrics::kWiFiSecurityWep, |
| 151 | -kStrength); |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 152 | EXPECT_CALL(library_, SendToUMA("Network.Shill.Wifi.TimeResumeToReady", |
| 153 | _, _, _, _)).Times(0); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 154 | wifi_service_->frequency_ = 2412; |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 155 | wifi_service_->physical_mode_ = Metrics::kWiFiNetworkPhyMode11a; |
| 156 | wifi_service_->security_ = flimflam::kSecurityWep; |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 157 | wifi_service_->raw_signal_strength_ = kStrength; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 158 | metrics_.RegisterService(wifi_service_); |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 159 | metrics_.NotifyServiceStateChanged(wifi_service_, Service::kStateConnected); |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 160 | Mock::VerifyAndClearExpectations(&library_); |
| 161 | |
| 162 | // Simulate a system suspend, resume and an AP reconnect. |
| 163 | ExpectCommonPostReady(Metrics::kWiFiChannel2412, |
| 164 | Metrics::kWiFiNetworkPhyMode11a, |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 165 | Metrics::kWiFiSecurityWep, |
| 166 | -kStrength); |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 167 | EXPECT_CALL(library_, SendToUMA("Network.Shill.Wifi.TimeResumeToReady", |
| 168 | Ge(0), |
| 169 | Metrics::kTimerHistogramMillisecondsMin, |
| 170 | Metrics::kTimerHistogramMillisecondsMax, |
| 171 | Metrics::kTimerHistogramNumBuckets)); |
| 172 | EXPECT_CALL(*mock_time_resume_to_ready_timer, GetElapsedTime(_)). |
| 173 | WillOnce(DoAll(SetArgumentPointee<0>(non_zero_time_delta), Return(true))); |
| 174 | metrics_.NotifyPowerStateChange(PowerManagerProxyDelegate::kMem); |
| 175 | metrics_.NotifyPowerStateChange(PowerManagerProxyDelegate::kOn); |
| 176 | metrics_.NotifyServiceStateChanged(wifi_service_, Service::kStateConnected); |
| 177 | Mock::VerifyAndClearExpectations(&library_); |
| 178 | Mock::VerifyAndClearExpectations(mock_time_resume_to_ready_timer); |
| 179 | |
| 180 | // Make sure subsequent connects do not count towards TimeResumeToReady. |
| 181 | ExpectCommonPostReady(Metrics::kWiFiChannel2412, |
| 182 | Metrics::kWiFiNetworkPhyMode11a, |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 183 | Metrics::kWiFiSecurityWep, |
| 184 | -kStrength); |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 185 | EXPECT_CALL(library_, SendToUMA("Network.Shill.Wifi.TimeResumeToReady", |
| 186 | _, _, _, _)).Times(0); |
| 187 | metrics_.NotifyServiceStateChanged(wifi_service_, Service::kStateConnected); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | TEST_F(MetricsTest, FrequencyToChannel) { |
| 191 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(2411)); |
| 192 | EXPECT_EQ(Metrics::kWiFiChannel2412, metrics_.WiFiFrequencyToChannel(2412)); |
| 193 | EXPECT_EQ(Metrics::kWiFiChannel2472, metrics_.WiFiFrequencyToChannel(2472)); |
| 194 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(2473)); |
| 195 | EXPECT_EQ(Metrics::kWiFiChannel2484, metrics_.WiFiFrequencyToChannel(2484)); |
| 196 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(5169)); |
| 197 | EXPECT_EQ(Metrics::kWiFiChannel5170, metrics_.WiFiFrequencyToChannel(5170)); |
| 198 | EXPECT_EQ(Metrics::kWiFiChannel5190, metrics_.WiFiFrequencyToChannel(5190)); |
| 199 | EXPECT_EQ(Metrics::kWiFiChannel5180, metrics_.WiFiFrequencyToChannel(5180)); |
| 200 | EXPECT_EQ(Metrics::kWiFiChannel5200, metrics_.WiFiFrequencyToChannel(5200)); |
| 201 | EXPECT_EQ(Metrics::kWiFiChannel5230, metrics_.WiFiFrequencyToChannel(5230)); |
| 202 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(5231)); |
| 203 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(5239)); |
| 204 | EXPECT_EQ(Metrics::kWiFiChannel5240, metrics_.WiFiFrequencyToChannel(5240)); |
| 205 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(5241)); |
| 206 | EXPECT_EQ(Metrics::kWiFiChannel5320, metrics_.WiFiFrequencyToChannel(5320)); |
| 207 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(5321)); |
| 208 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(5499)); |
| 209 | EXPECT_EQ(Metrics::kWiFiChannel5500, metrics_.WiFiFrequencyToChannel(5500)); |
| 210 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(5501)); |
| 211 | EXPECT_EQ(Metrics::kWiFiChannel5700, metrics_.WiFiFrequencyToChannel(5700)); |
| 212 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(5701)); |
| 213 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(5744)); |
| 214 | EXPECT_EQ(Metrics::kWiFiChannel5745, metrics_.WiFiFrequencyToChannel(5745)); |
| 215 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(5746)); |
| 216 | EXPECT_EQ(Metrics::kWiFiChannel5825, metrics_.WiFiFrequencyToChannel(5825)); |
| 217 | EXPECT_EQ(Metrics::kWiFiChannelUndef, metrics_.WiFiFrequencyToChannel(5826)); |
| 218 | } |
| 219 | |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 220 | TEST_F(MetricsTest, TimeOnlineTimeToDrop) { |
| 221 | chromeos_metrics::TimerMock *mock_time_online_timer = |
| 222 | new chromeos_metrics::TimerMock; |
| 223 | metrics_.set_time_online_timer(mock_time_online_timer); |
| 224 | chromeos_metrics::TimerMock *mock_time_to_drop_timer = |
| 225 | new chromeos_metrics::TimerMock; |
| 226 | metrics_.set_time_to_drop_timer(mock_time_to_drop_timer); |
| 227 | EXPECT_CALL(*service_.get(), technology()). |
| 228 | WillOnce(Return(Technology::kEthernet)); |
| 229 | EXPECT_CALL(library_, SendToUMA("Network.Shill.Ethernet.TimeOnline", |
| 230 | Ge(0), |
| 231 | Metrics::kMetricTimeOnlineSecondsMin, |
| 232 | Metrics::kMetricTimeOnlineSecondsMax, |
| 233 | Metrics::kTimerHistogramNumBuckets)); |
| 234 | EXPECT_CALL(library_, SendToUMA(Metrics::kMetricTimeToDropSeconds, |
| 235 | Ge(0), |
| 236 | Metrics::kMetricTimeToDropSecondsMin, |
| 237 | Metrics::kMetricTimeToDropSecondsMax, |
| 238 | Metrics::kTimerHistogramNumBuckets)).Times(0); |
| 239 | EXPECT_CALL(*mock_time_online_timer, Start()).Times(2); |
| 240 | EXPECT_CALL(*mock_time_to_drop_timer, Start()); |
| 241 | metrics_.NotifyDefaultServiceChanged(service_); |
| 242 | metrics_.NotifyDefaultServiceChanged(wifi_service_); |
| 243 | |
| 244 | EXPECT_CALL(*mock_time_online_timer, Start()); |
| 245 | EXPECT_CALL(*mock_time_to_drop_timer, Start()).Times(0); |
| 246 | EXPECT_CALL(library_, SendToUMA("Network.Shill.Wifi.TimeOnline", |
| 247 | Ge(0), |
| 248 | Metrics::kMetricTimeOnlineSecondsMin, |
| 249 | Metrics::kMetricTimeOnlineSecondsMax, |
| 250 | Metrics::kTimerHistogramNumBuckets)); |
| 251 | EXPECT_CALL(library_, SendToUMA(Metrics::kMetricTimeToDropSeconds, |
| 252 | Ge(0), |
| 253 | Metrics::kMetricTimeToDropSecondsMin, |
| 254 | Metrics::kMetricTimeToDropSecondsMax, |
| 255 | Metrics::kTimerHistogramNumBuckets)); |
| 256 | metrics_.NotifyDefaultServiceChanged(NULL); |
| 257 | } |
| 258 | |
Thieu Le | 67370f6 | 2012-02-14 23:01:42 +0000 | [diff] [blame] | 259 | TEST_F(MetricsTest, Disconnect) { |
| 260 | EXPECT_CALL(*service_.get(), technology()). |
| 261 | WillRepeatedly(Return(Technology::kWifi)); |
| 262 | EXPECT_CALL(*service_.get(), explicitly_disconnected()). |
| 263 | WillOnce(Return(false)); |
| 264 | EXPECT_CALL(library_, SendToUMA("Network.Shill.Wifi.Disconnect", |
| 265 | false, |
| 266 | Metrics::kMetricDisconnectMin, |
| 267 | Metrics::kMetricDisconnectMax, |
| 268 | Metrics::kMetricDisconnectNumBuckets)); |
| 269 | metrics_.NotifyServiceDisconnect(service_); |
| 270 | |
| 271 | EXPECT_CALL(*service_.get(), explicitly_disconnected()). |
| 272 | WillOnce(Return(true)); |
| 273 | EXPECT_CALL(library_, SendToUMA("Network.Shill.Wifi.Disconnect", |
| 274 | true, |
| 275 | Metrics::kMetricDisconnectMin, |
| 276 | Metrics::kMetricDisconnectMax, |
| 277 | Metrics::kMetricDisconnectNumBuckets)); |
| 278 | metrics_.NotifyServiceDisconnect(service_); |
| 279 | } |
| 280 | |
Thieu Le | 85e050b | 2012-03-13 15:04:38 -0700 | [diff] [blame] | 281 | TEST_F(MetricsTest, PortalDetectionResultToEnum) { |
| 282 | PortalDetector::Result result(PortalDetector::kPhaseDNS, |
| 283 | PortalDetector::kStatusFailure, 0, true); |
| 284 | EXPECT_EQ(Metrics::kPortalResultDNSFailure, |
| 285 | Metrics::PortalDetectionResultToEnum(result)); |
| 286 | |
| 287 | result.phase = PortalDetector::kPhaseDNS; |
| 288 | result.status = PortalDetector::kStatusTimeout; |
| 289 | EXPECT_EQ(Metrics::kPortalResultDNSTimeout, |
| 290 | Metrics::PortalDetectionResultToEnum(result)); |
| 291 | |
| 292 | result.phase = PortalDetector::kPhaseConnection; |
| 293 | result.status = PortalDetector::kStatusFailure; |
| 294 | EXPECT_EQ(Metrics::kPortalResultConnectionFailure, |
| 295 | Metrics::PortalDetectionResultToEnum(result)); |
| 296 | |
| 297 | result.phase = PortalDetector::kPhaseConnection; |
| 298 | result.status = PortalDetector::kStatusTimeout; |
| 299 | EXPECT_EQ(Metrics::kPortalResultConnectionTimeout, |
| 300 | Metrics::PortalDetectionResultToEnum(result)); |
| 301 | |
| 302 | result.phase = PortalDetector::kPhaseHTTP; |
| 303 | result.status = PortalDetector::kStatusFailure; |
| 304 | EXPECT_EQ(Metrics::kPortalResultHTTPFailure, |
| 305 | Metrics::PortalDetectionResultToEnum(result)); |
| 306 | |
| 307 | result.phase = PortalDetector::kPhaseHTTP; |
| 308 | result.status = PortalDetector::kStatusTimeout; |
| 309 | EXPECT_EQ(Metrics::kPortalResultHTTPTimeout, |
| 310 | Metrics::PortalDetectionResultToEnum(result)); |
| 311 | |
| 312 | result.phase = PortalDetector::kPhaseContent; |
| 313 | result.status = PortalDetector::kStatusSuccess; |
| 314 | EXPECT_EQ(Metrics::kPortalResultSuccess, |
| 315 | Metrics::PortalDetectionResultToEnum(result)); |
| 316 | |
| 317 | result.phase = PortalDetector::kPhaseContent; |
| 318 | result.status = PortalDetector::kStatusFailure; |
| 319 | EXPECT_EQ(Metrics::kPortalResultContentFailure, |
| 320 | Metrics::PortalDetectionResultToEnum(result)); |
| 321 | |
| 322 | result.phase = PortalDetector::kPhaseContent; |
| 323 | result.status = PortalDetector::kStatusTimeout; |
| 324 | EXPECT_EQ(Metrics::kPortalResultContentTimeout, |
| 325 | Metrics::PortalDetectionResultToEnum(result)); |
| 326 | |
| 327 | result.phase = PortalDetector::kPhaseUnknown; |
| 328 | result.status = PortalDetector::kStatusFailure; |
| 329 | EXPECT_EQ(Metrics::kPortalResultUnknown, |
| 330 | Metrics::PortalDetectionResultToEnum(result)); |
| 331 | } |
| 332 | |
| 333 | #ifndef NDEBUG |
| 334 | |
| 335 | typedef MetricsTest MetricsDeathTest; |
| 336 | |
| 337 | TEST_F(MetricsDeathTest, PortalDetectionResultToEnumDNSSuccess) { |
| 338 | PortalDetector::Result result(PortalDetector::kPhaseDNS, |
| 339 | PortalDetector::kStatusSuccess, 0, true); |
| 340 | EXPECT_DEATH(Metrics::PortalDetectionResultToEnum(result), |
| 341 | "Final result status 1 is not allowed in the DNS phase"); |
| 342 | } |
| 343 | |
| 344 | TEST_F(MetricsDeathTest, PortalDetectionResultToEnumConnectionSuccess) { |
| 345 | PortalDetector::Result result(PortalDetector::kPhaseConnection, |
| 346 | PortalDetector::kStatusSuccess, 0, true); |
| 347 | EXPECT_DEATH(Metrics::PortalDetectionResultToEnum(result), |
| 348 | "Final result status 1 is not allowed in the Connection phase"); |
| 349 | } |
| 350 | |
| 351 | TEST_F(MetricsDeathTest, PortalDetectionResultToEnumHTTPSuccess) { |
| 352 | PortalDetector::Result result(PortalDetector::kPhaseHTTP, |
| 353 | PortalDetector::kStatusSuccess, 0, true); |
| 354 | EXPECT_DEATH(Metrics::PortalDetectionResultToEnum(result), |
| 355 | "Final result status 1 is not allowed in the HTTP phase"); |
| 356 | } |
| 357 | |
| 358 | #endif // NDEBUG |
| 359 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 360 | } // namespace shill |