Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
| 17 | #include "update_engine/metrics_utils.h" |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
Alex Deymo | a259179 | 2015-11-17 00:39:40 -0300 | [diff] [blame] | 21 | #include "update_engine/common/fake_prefs.h" |
Alex Deymo | a259179 | 2015-11-17 00:39:40 -0300 | [diff] [blame] | 22 | |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 23 | namespace chromeos_update_engine { |
| 24 | namespace metrics_utils { |
| 25 | |
| 26 | class MetricsUtilsTest : public ::testing::Test {}; |
| 27 | |
| 28 | TEST(MetricsUtilsTest, GetConnectionType) { |
| 29 | // Check that expected combinations map to the right value. |
| 30 | EXPECT_EQ(metrics::ConnectionType::kUnknown, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 31 | GetConnectionType(ConnectionType::kUnknown, |
| 32 | ConnectionTethering::kUnknown)); |
Colin Howes | c9e98d6 | 2018-09-18 10:35:20 -0700 | [diff] [blame] | 33 | EXPECT_EQ(metrics::ConnectionType::kDisconnected, |
| 34 | GetConnectionType(ConnectionType::kDisconnected, |
| 35 | ConnectionTethering::kUnknown)); |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 36 | EXPECT_EQ(metrics::ConnectionType::kEthernet, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 37 | GetConnectionType(ConnectionType::kEthernet, |
| 38 | ConnectionTethering::kUnknown)); |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 39 | EXPECT_EQ( |
| 40 | metrics::ConnectionType::kWifi, |
| 41 | GetConnectionType(ConnectionType::kWifi, ConnectionTethering::kUnknown)); |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 42 | EXPECT_EQ(metrics::ConnectionType::kCellular, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 43 | GetConnectionType(ConnectionType::kCellular, |
| 44 | ConnectionTethering::kUnknown)); |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 45 | EXPECT_EQ(metrics::ConnectionType::kTetheredEthernet, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 46 | GetConnectionType(ConnectionType::kEthernet, |
| 47 | ConnectionTethering::kConfirmed)); |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 48 | EXPECT_EQ(metrics::ConnectionType::kTetheredWifi, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 49 | GetConnectionType(ConnectionType::kWifi, |
| 50 | ConnectionTethering::kConfirmed)); |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 51 | |
| 52 | // Ensure that we don't report tethered ethernet unless it's confirmed. |
| 53 | EXPECT_EQ(metrics::ConnectionType::kEthernet, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 54 | GetConnectionType(ConnectionType::kEthernet, |
| 55 | ConnectionTethering::kNotDetected)); |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 56 | EXPECT_EQ(metrics::ConnectionType::kEthernet, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 57 | GetConnectionType(ConnectionType::kEthernet, |
| 58 | ConnectionTethering::kSuspected)); |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 59 | EXPECT_EQ(metrics::ConnectionType::kEthernet, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 60 | GetConnectionType(ConnectionType::kEthernet, |
| 61 | ConnectionTethering::kUnknown)); |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 62 | |
| 63 | // Ditto for tethered wifi. |
| 64 | EXPECT_EQ(metrics::ConnectionType::kWifi, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 65 | GetConnectionType(ConnectionType::kWifi, |
| 66 | ConnectionTethering::kNotDetected)); |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 67 | EXPECT_EQ(metrics::ConnectionType::kWifi, |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 68 | GetConnectionType(ConnectionType::kWifi, |
| 69 | ConnectionTethering::kSuspected)); |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 70 | EXPECT_EQ( |
| 71 | metrics::ConnectionType::kWifi, |
| 72 | GetConnectionType(ConnectionType::kWifi, ConnectionTethering::kUnknown)); |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 75 | } // namespace metrics_utils |
| 76 | } // namespace chromeos_update_engine |