blob: 97436c9c222cb3c7ae09bb4c88d16cd5eff227d6 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2012 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//
Jay Srinivasan43488792012-06-19 00:25:31 -070016
Alex Deymo8427b4a2014-11-05 14:00:32 -080017#include "update_engine/connection_manager.h"
18
Weidong Guo421ff332017-04-17 10:08:38 -070019#include <memory>
Alex Vakulenkod2779df2014-06-16 13:19:00 -070020#include <set>
21#include <string>
Weidong Guo421ff332017-04-17 10:08:38 -070022#include <utility>
Alex Vakulenkod2779df2014-06-16 13:19:00 -070023
Jay Srinivasan43488792012-06-19 00:25:31 -070024#include <base/logging.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070025#include <brillo/any.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070026#include <brillo/message_loops/fake_message_loop.h>
27#include <brillo/variant_dictionary.h>
Alex Deymo5665d0c2014-05-28 17:45:43 -070028#include <gmock/gmock.h>
Jay Srinivasan43488792012-06-19 00:25:31 -070029#include <gtest/gtest.h>
Alex Deymod6deb1d2015-08-28 15:54:37 -070030#include <shill/dbus-constants.h>
31#include <shill/dbus-proxies.h>
32#include <shill/dbus-proxy-mocks.h>
Jay Srinivasan43488792012-06-19 00:25:31 -070033
Alex Deymo39910dc2015-11-09 17:04:30 -080034#include "update_engine/common/test_utils.h"
Alex Deymo30534502015-07-20 15:06:33 -070035#include "update_engine/fake_shill_proxy.h"
Gilad Arnold5bb4c902014-04-10 12:32:13 -070036#include "update_engine/fake_system_state.h"
Jay Srinivasan43488792012-06-19 00:25:31 -070037
Sen Jiang255e22b2016-05-20 16:15:29 -070038using chromeos_update_engine::connection_utils::StringForConnectionType;
Alex Deymo30534502015-07-20 15:06:33 -070039using org::chromium::flimflam::ManagerProxyMock;
40using org::chromium::flimflam::ServiceProxyMock;
Jay Srinivasan43488792012-06-19 00:25:31 -070041using std::set;
42using std::string;
Amin Hassani7cc8bb02019-01-14 16:29:47 -080043using testing::_;
Jay Srinivasan43488792012-06-19 00:25:31 -070044using testing::Return;
Alex Deymo30534502015-07-20 15:06:33 -070045using testing::SetArgPointee;
Jay Srinivasan43488792012-06-19 00:25:31 -070046
47namespace chromeos_update_engine {
48
49class ConnectionManagerTest : public ::testing::Test {
50 public:
Sen Jiangf5bebae2016-06-03 15:36:54 -070051 ConnectionManagerTest() : fake_shill_proxy_(new FakeShillProxy()) {}
52
Alex Deymo30534502015-07-20 15:06:33 -070053 void SetUp() override {
54 loop_.SetAsCurrent();
Gilad Arnold5bb4c902014-04-10 12:32:13 -070055 fake_system_state_.set_connection_manager(&cmut_);
Jay Srinivasan43488792012-06-19 00:25:31 -070056 }
57
Alex Deymo30534502015-07-20 15:06:33 -070058 void TearDown() override { EXPECT_FALSE(loop_.PendingTasks()); }
Alex Deymo1c4e6382013-07-15 12:09:51 -070059
Alex Deymo30534502015-07-20 15:06:33 -070060 protected:
61 // Sets the default_service object path in the response from the
62 // ManagerProxyMock instance.
63 void SetManagerReply(const char* default_service, bool reply_succeeds);
64
65 // Sets the |service_type|, |physical_technology| and |service_tethering|
66 // properties in the mocked service |service_path|. If any of the three
67 // const char* is a nullptr, the corresponding property will not be included
68 // in the response.
69 void SetServiceReply(const string& service_path,
70 const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -070071 const char* physical_technology,
72 const char* service_tethering);
Alex Deymo30534502015-07-20 15:06:33 -070073
Amin Hassani7cc8bb02019-01-14 16:29:47 -080074 void TestWithServiceType(const char* service_type,
75 const char* physical_technology,
76 ConnectionType expected_type);
Colin Howesc9e98d62018-09-18 10:35:20 -070077
78 void TestWithServiceDisconnected(ConnectionType expected_type);
79
Amin Hassani7cc8bb02019-01-14 16:29:47 -080080 void TestWithServiceTethering(const char* service_tethering,
81 ConnectionTethering expected_tethering);
Jay Srinivasan43488792012-06-19 00:25:31 -070082
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070083 brillo::FakeMessageLoop loop_{nullptr};
Gilad Arnold5bb4c902014-04-10 12:32:13 -070084 FakeSystemState fake_system_state_;
Sen Jiangf5bebae2016-06-03 15:36:54 -070085 FakeShillProxy* fake_shill_proxy_;
Alex Deymo30534502015-07-20 15:06:33 -070086
87 // ConnectionManager under test.
Sen Jiangf5bebae2016-06-03 15:36:54 -070088 ConnectionManager cmut_{fake_shill_proxy_, &fake_system_state_};
Jay Srinivasan43488792012-06-19 00:25:31 -070089};
90
Alex Deymo30534502015-07-20 15:06:33 -070091void ConnectionManagerTest::SetManagerReply(const char* default_service,
92 bool reply_succeeds) {
Sen Jiangf5bebae2016-06-03 15:36:54 -070093 ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_->GetManagerProxy();
Alex Deymo30534502015-07-20 15:06:33 -070094 if (!reply_succeeds) {
95 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
96 .WillOnce(Return(false));
97 return;
98 }
Jay Srinivasan43488792012-06-19 00:25:31 -070099
Alex Deymo30534502015-07-20 15:06:33 -0700100 // Create a dictionary of properties and optionally include the default
101 // service.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700102 brillo::VariantDictionary reply_dict;
Alex Deymo30534502015-07-20 15:06:33 -0700103 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
Jay Srinivasan43488792012-06-19 00:25:31 -0700104
Alex Deymo30534502015-07-20 15:06:33 -0700105 if (default_service) {
106 reply_dict[shill::kDefaultServiceProperty] =
107 dbus::ObjectPath(default_service);
108 }
109 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
110 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700111}
112
Alex Deymo30534502015-07-20 15:06:33 -0700113void ConnectionManagerTest::SetServiceReply(const string& service_path,
114 const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -0700115 const char* physical_technology,
116 const char* service_tethering) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700117 brillo::VariantDictionary reply_dict;
Alex Deymo30534502015-07-20 15:06:33 -0700118 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
119
120 if (service_type)
121 reply_dict[shill::kTypeProperty] = string(service_type);
Jay Srinivasan43488792012-06-19 00:25:31 -0700122
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700123 if (physical_technology) {
Alex Deymo30534502015-07-20 15:06:33 -0700124 reply_dict[shill::kPhysicalTechnologyProperty] =
125 string(physical_technology);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700126 }
127
Alex Deymo30534502015-07-20 15:06:33 -0700128 if (service_tethering)
129 reply_dict[shill::kTetheringProperty] = string(service_tethering);
130
131 std::unique_ptr<ServiceProxyMock> service_proxy_mock(new ServiceProxyMock());
Alex Deymo6ae91202014-03-10 19:21:25 -0700132
Jay Srinivasan43488792012-06-19 00:25:31 -0700133 // Plumb return value into mock object.
Alex Deymo30534502015-07-20 15:06:33 -0700134 EXPECT_CALL(*service_proxy_mock.get(), GetProperties(_, _, _))
135 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700136
Sen Jiangf5bebae2016-06-03 15:36:54 -0700137 fake_shill_proxy_->SetServiceForPath(dbus::ObjectPath(service_path),
138 std::move(service_proxy_mock));
Jay Srinivasan43488792012-06-19 00:25:31 -0700139}
140
Amin Hassani7cc8bb02019-01-14 16:29:47 -0800141void ConnectionManagerTest::TestWithServiceType(const char* service_type,
142 const char* physical_technology,
143 ConnectionType expected_type) {
Alex Deymo758dd532015-09-09 15:21:22 -0700144 SetManagerReply("/service/guest/network", true);
145 SetServiceReply("/service/guest/network",
Alex Deymo30534502015-07-20 15:06:33 -0700146 service_type,
147 physical_technology,
Alex Deymo6ae91202014-03-10 19:21:25 -0700148 shill::kTetheringNotDetectedState);
Jay Srinivasan43488792012-06-19 00:25:31 -0700149
Sen Jiang255e22b2016-05-20 16:15:29 -0700150 ConnectionType type;
151 ConnectionTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700152 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700153 EXPECT_EQ(expected_type, type);
Alex Deymo30534502015-07-20 15:06:33 -0700154 testing::Mock::VerifyAndClearExpectations(
Sen Jiangf5bebae2016-06-03 15:36:54 -0700155 fake_shill_proxy_->GetManagerProxy());
Jay Srinivasan43488792012-06-19 00:25:31 -0700156}
157
Alex Deymo6ae91202014-03-10 19:21:25 -0700158void ConnectionManagerTest::TestWithServiceTethering(
Amin Hassani7cc8bb02019-01-14 16:29:47 -0800159 const char* service_tethering, ConnectionTethering expected_tethering) {
Alex Deymo758dd532015-09-09 15:21:22 -0700160 SetManagerReply("/service/guest/network", true);
Alex Deymo30534502015-07-20 15:06:33 -0700161 SetServiceReply(
Alex Deymo758dd532015-09-09 15:21:22 -0700162 "/service/guest/network", shill::kTypeWifi, nullptr, service_tethering);
Alex Deymo6ae91202014-03-10 19:21:25 -0700163
Sen Jiang255e22b2016-05-20 16:15:29 -0700164 ConnectionType type;
165 ConnectionTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700166 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Alex Deymo6ae91202014-03-10 19:21:25 -0700167 EXPECT_EQ(expected_tethering, tethering);
Alex Deymo30534502015-07-20 15:06:33 -0700168 testing::Mock::VerifyAndClearExpectations(
Sen Jiangf5bebae2016-06-03 15:36:54 -0700169 fake_shill_proxy_->GetManagerProxy());
Alex Deymo6ae91202014-03-10 19:21:25 -0700170}
171
Colin Howesc9e98d62018-09-18 10:35:20 -0700172void ConnectionManagerTest::TestWithServiceDisconnected(
173 ConnectionType expected_type) {
174 SetManagerReply("/", true);
175
176 ConnectionType type;
177 ConnectionTethering tethering;
178 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
179 EXPECT_EQ(expected_type, type);
180 testing::Mock::VerifyAndClearExpectations(
181 fake_shill_proxy_->GetManagerProxy());
182}
183
Jay Srinivasan43488792012-06-19 00:25:31 -0700184TEST_F(ConnectionManagerTest, SimpleTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700185 TestWithServiceType(shill::kTypeEthernet, nullptr, ConnectionType::kEthernet);
186 TestWithServiceType(shill::kTypeWifi, nullptr, ConnectionType::kWifi);
Sen Jiang255e22b2016-05-20 16:15:29 -0700187 TestWithServiceType(shill::kTypeCellular, nullptr, ConnectionType::kCellular);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700188}
189
190TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700191 TestWithServiceType(shill::kTypeVPN, nullptr, ConnectionType::kUnknown);
192 TestWithServiceType(
193 shill::kTypeVPN, shill::kTypeVPN, ConnectionType::kUnknown);
194 TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi, ConnectionType::kWifi);
Jay Srinivasan43488792012-06-19 00:25:31 -0700195}
196
Alex Deymo6ae91202014-03-10 19:21:25 -0700197TEST_F(ConnectionManagerTest, TetheringTest) {
198 TestWithServiceTethering(shill::kTetheringConfirmedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700199 ConnectionTethering::kConfirmed);
Alex Deymo6ae91202014-03-10 19:21:25 -0700200 TestWithServiceTethering(shill::kTetheringNotDetectedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700201 ConnectionTethering::kNotDetected);
Alex Deymo6ae91202014-03-10 19:21:25 -0700202 TestWithServiceTethering(shill::kTetheringSuspectedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700203 ConnectionTethering::kSuspected);
Alex Deymo6ae91202014-03-10 19:21:25 -0700204 TestWithServiceTethering("I'm not a valid property value =)",
Sen Jiang255e22b2016-05-20 16:15:29 -0700205 ConnectionTethering::kUnknown);
Alex Deymo6ae91202014-03-10 19:21:25 -0700206}
207
Jay Srinivasan43488792012-06-19 00:25:31 -0700208TEST_F(ConnectionManagerTest, UnknownTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700209 TestWithServiceType("foo", nullptr, ConnectionType::kUnknown);
Jay Srinivasan43488792012-06-19 00:25:31 -0700210}
211
Colin Howesc9e98d62018-09-18 10:35:20 -0700212TEST_F(ConnectionManagerTest, DisconnectTest) {
213 TestWithServiceDisconnected(ConnectionType::kDisconnected);
214}
215
Jay Srinivasan43488792012-06-19 00:25:31 -0700216TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) {
Jay Srinivasan43488792012-06-19 00:25:31 -0700217 // Updates over Ethernet are allowed even if there's no policy.
Sen Jiang255e22b2016-05-20 16:15:29 -0700218 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
219 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700220}
221
222TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700223 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
224 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700225}
226
Jay Srinivasan43488792012-06-19 00:25:31 -0700227TEST_F(ConnectionManagerTest, AllowUpdatesOnlyOver3GPerPolicyTest) {
228 policy::MockDevicePolicy allow_3g_policy;
229
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700230 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700231
Alex Deymof4867c42013-06-28 14:41:39 -0700232 // This test tests cellular (3G) being the only connection type being allowed.
Jay Srinivasan43488792012-06-19 00:25:31 -0700233 set<string> allowed_set;
Sen Jiang255e22b2016-05-20 16:15:29 -0700234 allowed_set.insert(StringForConnectionType(ConnectionType::kCellular));
Jay Srinivasan43488792012-06-19 00:25:31 -0700235
236 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
237 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700238 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700239
Sen Jiang255e22b2016-05-20 16:15:29 -0700240 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
241 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700242}
243
244TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) {
245 policy::MockDevicePolicy allow_3g_policy;
246
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700247 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700248
249 // This test tests multiple connection types being allowed, with
Alex Deymof4867c42013-06-28 14:41:39 -0700250 // 3G one among them. Only Cellular is currently enforced by the policy
Alex Khouderchahbfa82262019-08-13 15:00:34 -0700251 // setting.
Jay Srinivasan43488792012-06-19 00:25:31 -0700252 set<string> allowed_set;
Sen Jiang255e22b2016-05-20 16:15:29 -0700253 allowed_set.insert(StringForConnectionType(ConnectionType::kCellular));
Jay Srinivasan43488792012-06-19 00:25:31 -0700254
255 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymo6ae91202014-03-10 19:21:25 -0700256 .Times(3)
Alex Deymo30534502015-07-20 15:06:33 -0700257 .WillRepeatedly(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700258
Sen Jiang255e22b2016-05-20 16:15:29 -0700259 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
260 ConnectionTethering::kUnknown));
261 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
262 ConnectionTethering::kNotDetected));
263 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
264 ConnectionTethering::kUnknown));
265 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
266 ConnectionTethering::kUnknown));
Alex Deymo6ae91202014-03-10 19:21:25 -0700267
268 // Tethered networks are treated in the same way as Cellular networks and
269 // thus allowed.
Sen Jiang255e22b2016-05-20 16:15:29 -0700270 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
271 ConnectionTethering::kConfirmed));
272 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
273 ConnectionTethering::kConfirmed));
Jay Srinivasan43488792012-06-19 00:25:31 -0700274}
275
Weidong Guo421ff332017-04-17 10:08:38 -0700276TEST_F(ConnectionManagerTest, AllowUpdatesOverCellularByDefaultTest) {
277 policy::MockDevicePolicy device_policy;
278 // Set an empty device policy.
279 fake_system_state_.set_device_policy(&device_policy);
280
281 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
282 ConnectionTethering::kUnknown));
Alex Deymo6ae91202014-03-10 19:21:25 -0700283}
284
Weidong Guo421ff332017-04-17 10:08:38 -0700285TEST_F(ConnectionManagerTest, AllowUpdatesOverTetheredNetworkByDefaultTest) {
286 policy::MockDevicePolicy device_policy;
287 // Set an empty device policy.
288 fake_system_state_.set_device_policy(&device_policy);
289
290 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
291 ConnectionTethering::kConfirmed));
292 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
293 ConnectionTethering::kConfirmed));
Sen Jiang255e22b2016-05-20 16:15:29 -0700294 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
295 ConnectionTethering::kSuspected));
Jay Srinivasan43488792012-06-19 00:25:31 -0700296}
297
298TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) {
299 policy::MockDevicePolicy block_3g_policy;
300
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700301 fake_system_state_.set_device_policy(&block_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700302
303 // Test that updates for 3G are blocked while updates are allowed
304 // over several other types.
305 set<string> allowed_set;
Sen Jiang255e22b2016-05-20 16:15:29 -0700306 allowed_set.insert(StringForConnectionType(ConnectionType::kEthernet));
307 allowed_set.insert(StringForConnectionType(ConnectionType::kWifi));
Jay Srinivasan43488792012-06-19 00:25:31 -0700308
309 EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_))
310 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700311 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700312
Sen Jiang255e22b2016-05-20 16:15:29 -0700313 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
314 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700315}
316
Weidong Guo421ff332017-04-17 10:08:38 -0700317TEST_F(ConnectionManagerTest, AllowUpdatesOver3GIfPolicyIsNotSet) {
318 policy::MockDevicePolicy device_policy;
Jay Srinivasan43488792012-06-19 00:25:31 -0700319
Weidong Guo421ff332017-04-17 10:08:38 -0700320 fake_system_state_.set_device_policy(&device_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700321
322 // Return false for GetAllowedConnectionTypesForUpdate and see
Weidong Guo421ff332017-04-17 10:08:38 -0700323 // that updates are allowed as device policy is not set. Further
324 // check is left to |OmahaRequestAction|.
325 EXPECT_CALL(device_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymof4867c42013-06-28 14:41:39 -0700326 .Times(1)
327 .WillOnce(Return(false));
Alex Deymof4867c42013-06-28 14:41:39 -0700328
Sen Jiang255e22b2016-05-20 16:15:29 -0700329 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
330 ConnectionTethering::kUnknown));
Weidong Guo421ff332017-04-17 10:08:38 -0700331}
Tao Bao5688d162017-06-06 13:09:06 -0700332
Weidong Guo421ff332017-04-17 10:08:38 -0700333TEST_F(ConnectionManagerTest, AllowUpdatesOverCellularIfPolicyFailsToBeLoaded) {
334 fake_system_state_.set_device_policy(nullptr);
335
336 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
337 ConnectionTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700338}
339
Jay Srinivasan43488792012-06-19 00:25:31 -0700340TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700341 EXPECT_STREQ(shill::kTypeEthernet,
Sen Jiang255e22b2016-05-20 16:15:29 -0700342 StringForConnectionType(ConnectionType::kEthernet));
Ben Chanc6007e42013-09-19 23:49:22 -0700343 EXPECT_STREQ(shill::kTypeWifi,
Sen Jiang255e22b2016-05-20 16:15:29 -0700344 StringForConnectionType(ConnectionType::kWifi));
Ben Chanc6007e42013-09-19 23:49:22 -0700345 EXPECT_STREQ(shill::kTypeCellular,
Sen Jiang255e22b2016-05-20 16:15:29 -0700346 StringForConnectionType(ConnectionType::kCellular));
347 EXPECT_STREQ("Unknown", StringForConnectionType(ConnectionType::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700348 EXPECT_STREQ("Unknown",
Sen Jiang255e22b2016-05-20 16:15:29 -0700349 StringForConnectionType(static_cast<ConnectionType>(999999)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700350}
351
352TEST_F(ConnectionManagerTest, MalformedServiceList) {
Alex Deymo758dd532015-09-09 15:21:22 -0700353 SetManagerReply("/service/guest/network", false);
Jay Srinivasan43488792012-06-19 00:25:31 -0700354
Sen Jiang255e22b2016-05-20 16:15:29 -0700355 ConnectionType type;
356 ConnectionTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700357 EXPECT_FALSE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700358}
359
360} // namespace chromeos_update_engine