| 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 |  | 
|  | 21 | namespace chromeos_update_engine { | 
|  | 22 | namespace metrics_utils { | 
|  | 23 |  | 
|  | 24 | class MetricsUtilsTest : public ::testing::Test {}; | 
|  | 25 |  | 
|  | 26 | TEST(MetricsUtilsTest, GetConnectionType) { | 
|  | 27 | // Check that expected combinations map to the right value. | 
|  | 28 | EXPECT_EQ(metrics::ConnectionType::kUnknown, | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 29 | GetConnectionType(ConnectionType::kUnknown, | 
|  | 30 | ConnectionTethering::kUnknown)); | 
| Colin Howes | c9e98d6 | 2018-09-18 10:35:20 -0700 | [diff] [blame] | 31 | EXPECT_EQ(metrics::ConnectionType::kDisconnected, | 
|  | 32 | GetConnectionType(ConnectionType::kDisconnected, | 
|  | 33 | ConnectionTethering::kUnknown)); | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 34 | EXPECT_EQ(metrics::ConnectionType::kEthernet, | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 35 | GetConnectionType(ConnectionType::kEthernet, | 
|  | 36 | ConnectionTethering::kUnknown)); | 
| Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 37 | EXPECT_EQ( | 
|  | 38 | metrics::ConnectionType::kWifi, | 
|  | 39 | GetConnectionType(ConnectionType::kWifi, ConnectionTethering::kUnknown)); | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 40 | EXPECT_EQ(metrics::ConnectionType::kCellular, | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 41 | GetConnectionType(ConnectionType::kCellular, | 
|  | 42 | ConnectionTethering::kUnknown)); | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 43 | EXPECT_EQ(metrics::ConnectionType::kTetheredEthernet, | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 44 | GetConnectionType(ConnectionType::kEthernet, | 
|  | 45 | ConnectionTethering::kConfirmed)); | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 46 | EXPECT_EQ(metrics::ConnectionType::kTetheredWifi, | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 47 | GetConnectionType(ConnectionType::kWifi, | 
|  | 48 | ConnectionTethering::kConfirmed)); | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 49 |  | 
|  | 50 | // Ensure that we don't report tethered ethernet unless it's confirmed. | 
|  | 51 | EXPECT_EQ(metrics::ConnectionType::kEthernet, | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 52 | GetConnectionType(ConnectionType::kEthernet, | 
|  | 53 | ConnectionTethering::kNotDetected)); | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 54 | EXPECT_EQ(metrics::ConnectionType::kEthernet, | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 55 | GetConnectionType(ConnectionType::kEthernet, | 
|  | 56 | ConnectionTethering::kSuspected)); | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 57 | EXPECT_EQ(metrics::ConnectionType::kEthernet, | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 58 | GetConnectionType(ConnectionType::kEthernet, | 
|  | 59 | ConnectionTethering::kUnknown)); | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 60 |  | 
|  | 61 | // Ditto for tethered wifi. | 
|  | 62 | EXPECT_EQ(metrics::ConnectionType::kWifi, | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 63 | GetConnectionType(ConnectionType::kWifi, | 
|  | 64 | ConnectionTethering::kNotDetected)); | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 65 | EXPECT_EQ(metrics::ConnectionType::kWifi, | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 66 | GetConnectionType(ConnectionType::kWifi, | 
|  | 67 | ConnectionTethering::kSuspected)); | 
| Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 68 | EXPECT_EQ( | 
|  | 69 | metrics::ConnectionType::kWifi, | 
|  | 70 | GetConnectionType(ConnectionType::kWifi, ConnectionTethering::kUnknown)); | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 71 | } | 
|  | 72 |  | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 73 | }  // namespace metrics_utils | 
|  | 74 | }  // namespace chromeos_update_engine |