blob: 0005b2e021be1b7207576ed6dbb3b4453028936f [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
Alex Vakulenkod2779df2014-06-16 13:19:00 -070019#include <set>
20#include <string>
21
Jay Srinivasan43488792012-06-19 00:25:31 -070022#include <base/logging.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070023#include <brillo/any.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070024#include <brillo/message_loops/fake_message_loop.h>
25#include <brillo/variant_dictionary.h>
Alex Deymo5665d0c2014-05-28 17:45:43 -070026#include <gmock/gmock.h>
Jay Srinivasan43488792012-06-19 00:25:31 -070027#include <gtest/gtest.h>
Alex Deymod6deb1d2015-08-28 15:54:37 -070028#include <shill/dbus-constants.h>
29#include <shill/dbus-proxies.h>
30#include <shill/dbus-proxy-mocks.h>
Jay Srinivasan43488792012-06-19 00:25:31 -070031
Alex Deymo39910dc2015-11-09 17:04:30 -080032#include "update_engine/common/test_utils.h"
Alex Deymo30534502015-07-20 15:06:33 -070033#include "update_engine/fake_shill_proxy.h"
Gilad Arnold5bb4c902014-04-10 12:32:13 -070034#include "update_engine/fake_system_state.h"
Jay Srinivasan43488792012-06-19 00:25:31 -070035
Sen Jiang255e22b2016-05-20 16:15:29 -070036using chromeos_update_engine::connection_utils::StringForConnectionType;
Alex Deymo30534502015-07-20 15:06:33 -070037using org::chromium::flimflam::ManagerProxyMock;
38using org::chromium::flimflam::ServiceProxyMock;
Jay Srinivasan43488792012-06-19 00:25:31 -070039using std::set;
40using std::string;
Jay Srinivasan43488792012-06-19 00:25:31 -070041using testing::Return;
Alex Deymo30534502015-07-20 15:06:33 -070042using testing::SetArgPointee;
Alex Deymof329b932014-10-30 01:37:48 -070043using testing::_;
Jay Srinivasan43488792012-06-19 00:25:31 -070044
45namespace chromeos_update_engine {
46
47class ConnectionManagerTest : public ::testing::Test {
48 public:
Sen Jiangf5bebae2016-06-03 15:36:54 -070049 ConnectionManagerTest() : fake_shill_proxy_(new FakeShillProxy()) {}
50
Alex Deymo30534502015-07-20 15:06:33 -070051 void SetUp() override {
52 loop_.SetAsCurrent();
Gilad Arnold5bb4c902014-04-10 12:32:13 -070053 fake_system_state_.set_connection_manager(&cmut_);
Jay Srinivasan43488792012-06-19 00:25:31 -070054 }
55
Alex Deymo30534502015-07-20 15:06:33 -070056 void TearDown() override { EXPECT_FALSE(loop_.PendingTasks()); }
Alex Deymo1c4e6382013-07-15 12:09:51 -070057
Alex Deymo30534502015-07-20 15:06:33 -070058 protected:
59 // Sets the default_service object path in the response from the
60 // ManagerProxyMock instance.
61 void SetManagerReply(const char* default_service, bool reply_succeeds);
62
63 // Sets the |service_type|, |physical_technology| and |service_tethering|
64 // properties in the mocked service |service_path|. If any of the three
65 // const char* is a nullptr, the corresponding property will not be included
66 // in the response.
67 void SetServiceReply(const string& service_path,
68 const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -070069 const char* physical_technology,
70 const char* service_tethering);
Alex Deymo30534502015-07-20 15:06:33 -070071
Jay Srinivasan43488792012-06-19 00:25:31 -070072 void TestWithServiceType(
Alex Deymo1c4e6382013-07-15 12:09:51 -070073 const char* service_type,
74 const char* physical_technology,
Sen Jiang255e22b2016-05-20 16:15:29 -070075 ConnectionType expected_type);
Alex Deymo6ae91202014-03-10 19:21:25 -070076 void TestWithServiceTethering(
77 const char* service_tethering,
Sen Jiang255e22b2016-05-20 16:15:29 -070078 ConnectionTethering expected_tethering);
Jay Srinivasan43488792012-06-19 00:25:31 -070079
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070080 brillo::FakeMessageLoop loop_{nullptr};
Gilad Arnold5bb4c902014-04-10 12:32:13 -070081 FakeSystemState fake_system_state_;
Sen Jiangf5bebae2016-06-03 15:36:54 -070082 FakeShillProxy* fake_shill_proxy_;
Alex Deymo30534502015-07-20 15:06:33 -070083
84 // ConnectionManager under test.
Sen Jiangf5bebae2016-06-03 15:36:54 -070085 ConnectionManager cmut_{fake_shill_proxy_, &fake_system_state_};
Jay Srinivasan43488792012-06-19 00:25:31 -070086};
87
Alex Deymo30534502015-07-20 15:06:33 -070088void ConnectionManagerTest::SetManagerReply(const char* default_service,
89 bool reply_succeeds) {
Sen Jiangf5bebae2016-06-03 15:36:54 -070090 ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_->GetManagerProxy();
Alex Deymo30534502015-07-20 15:06:33 -070091 if (!reply_succeeds) {
92 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
93 .WillOnce(Return(false));
94 return;
95 }
Jay Srinivasan43488792012-06-19 00:25:31 -070096
Alex Deymo30534502015-07-20 15:06:33 -070097 // Create a dictionary of properties and optionally include the default
98 // service.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070099 brillo::VariantDictionary reply_dict;
Alex Deymo30534502015-07-20 15:06:33 -0700100 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
Jay Srinivasan43488792012-06-19 00:25:31 -0700101
Alex Deymo30534502015-07-20 15:06:33 -0700102 if (default_service) {
103 reply_dict[shill::kDefaultServiceProperty] =
104 dbus::ObjectPath(default_service);
105 }
106 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
107 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700108}
109
Alex Deymo30534502015-07-20 15:06:33 -0700110void ConnectionManagerTest::SetServiceReply(const string& service_path,
111 const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -0700112 const char* physical_technology,
113 const char* service_tethering) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700114 brillo::VariantDictionary reply_dict;
Alex Deymo30534502015-07-20 15:06:33 -0700115 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
116
117 if (service_type)
118 reply_dict[shill::kTypeProperty] = string(service_type);
Jay Srinivasan43488792012-06-19 00:25:31 -0700119
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700120 if (physical_technology) {
Alex Deymo30534502015-07-20 15:06:33 -0700121 reply_dict[shill::kPhysicalTechnologyProperty] =
122 string(physical_technology);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700123 }
124
Alex Deymo30534502015-07-20 15:06:33 -0700125 if (service_tethering)
126 reply_dict[shill::kTetheringProperty] = string(service_tethering);
127
128 std::unique_ptr<ServiceProxyMock> service_proxy_mock(new ServiceProxyMock());
Alex Deymo6ae91202014-03-10 19:21:25 -0700129
Jay Srinivasan43488792012-06-19 00:25:31 -0700130 // Plumb return value into mock object.
Alex Deymo30534502015-07-20 15:06:33 -0700131 EXPECT_CALL(*service_proxy_mock.get(), GetProperties(_, _, _))
132 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700133
Sen Jiangf5bebae2016-06-03 15:36:54 -0700134 fake_shill_proxy_->SetServiceForPath(dbus::ObjectPath(service_path),
135 std::move(service_proxy_mock));
Jay Srinivasan43488792012-06-19 00:25:31 -0700136}
137
138void ConnectionManagerTest::TestWithServiceType(
139 const char* service_type,
Alex Deymo1c4e6382013-07-15 12:09:51 -0700140 const char* physical_technology,
Sen Jiang255e22b2016-05-20 16:15:29 -0700141 ConnectionType expected_type) {
Alex Deymo758dd532015-09-09 15:21:22 -0700142 SetManagerReply("/service/guest/network", true);
143 SetServiceReply("/service/guest/network",
Alex Deymo30534502015-07-20 15:06:33 -0700144 service_type,
145 physical_technology,
Alex Deymo6ae91202014-03-10 19:21:25 -0700146 shill::kTetheringNotDetectedState);
Jay Srinivasan43488792012-06-19 00:25:31 -0700147
Sen Jiang255e22b2016-05-20 16:15:29 -0700148 ConnectionType type;
149 ConnectionTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700150 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700151 EXPECT_EQ(expected_type, type);
Alex Deymo30534502015-07-20 15:06:33 -0700152 testing::Mock::VerifyAndClearExpectations(
Sen Jiangf5bebae2016-06-03 15:36:54 -0700153 fake_shill_proxy_->GetManagerProxy());
Jay Srinivasan43488792012-06-19 00:25:31 -0700154}
155
Alex Deymo6ae91202014-03-10 19:21:25 -0700156void ConnectionManagerTest::TestWithServiceTethering(
157 const char* service_tethering,
Sen Jiang255e22b2016-05-20 16:15:29 -0700158 ConnectionTethering expected_tethering) {
Alex Deymo758dd532015-09-09 15:21:22 -0700159 SetManagerReply("/service/guest/network", true);
Alex Deymo30534502015-07-20 15:06:33 -0700160 SetServiceReply(
Alex Deymo758dd532015-09-09 15:21:22 -0700161 "/service/guest/network", shill::kTypeWifi, nullptr, service_tethering);
Alex Deymo6ae91202014-03-10 19:21:25 -0700162
Sen Jiang255e22b2016-05-20 16:15:29 -0700163 ConnectionType type;
164 ConnectionTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700165 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Alex Deymo6ae91202014-03-10 19:21:25 -0700166 EXPECT_EQ(expected_tethering, tethering);
Alex Deymo30534502015-07-20 15:06:33 -0700167 testing::Mock::VerifyAndClearExpectations(
Sen Jiangf5bebae2016-06-03 15:36:54 -0700168 fake_shill_proxy_->GetManagerProxy());
Alex Deymo6ae91202014-03-10 19:21:25 -0700169}
170
Jay Srinivasan43488792012-06-19 00:25:31 -0700171TEST_F(ConnectionManagerTest, SimpleTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700172 TestWithServiceType(shill::kTypeEthernet, nullptr, ConnectionType::kEthernet);
173 TestWithServiceType(shill::kTypeWifi, nullptr, ConnectionType::kWifi);
174 TestWithServiceType(shill::kTypeWimax, nullptr, ConnectionType::kWimax);
175 TestWithServiceType(
176 shill::kTypeBluetooth, nullptr, ConnectionType::kBluetooth);
177 TestWithServiceType(shill::kTypeCellular, nullptr, ConnectionType::kCellular);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700178}
179
180TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700181 TestWithServiceType(shill::kTypeVPN, nullptr, ConnectionType::kUnknown);
182 TestWithServiceType(
183 shill::kTypeVPN, shill::kTypeVPN, ConnectionType::kUnknown);
184 TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi, ConnectionType::kWifi);
185 TestWithServiceType(
186 shill::kTypeVPN, shill::kTypeWimax, ConnectionType::kWimax);
Jay Srinivasan43488792012-06-19 00:25:31 -0700187}
188
Alex Deymo6ae91202014-03-10 19:21:25 -0700189TEST_F(ConnectionManagerTest, TetheringTest) {
190 TestWithServiceTethering(shill::kTetheringConfirmedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700191 ConnectionTethering::kConfirmed);
Alex Deymo6ae91202014-03-10 19:21:25 -0700192 TestWithServiceTethering(shill::kTetheringNotDetectedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700193 ConnectionTethering::kNotDetected);
Alex Deymo6ae91202014-03-10 19:21:25 -0700194 TestWithServiceTethering(shill::kTetheringSuspectedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700195 ConnectionTethering::kSuspected);
Alex Deymo6ae91202014-03-10 19:21:25 -0700196 TestWithServiceTethering("I'm not a valid property value =)",
Sen Jiang255e22b2016-05-20 16:15:29 -0700197 ConnectionTethering::kUnknown);
Alex Deymo6ae91202014-03-10 19:21:25 -0700198}
199
Jay Srinivasan43488792012-06-19 00:25:31 -0700200TEST_F(ConnectionManagerTest, UnknownTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700201 TestWithServiceType("foo", nullptr, ConnectionType::kUnknown);
Jay Srinivasan43488792012-06-19 00:25:31 -0700202}
203
204TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) {
Jay Srinivasan43488792012-06-19 00:25:31 -0700205 // Updates over Ethernet are allowed even if there's no policy.
Sen Jiang255e22b2016-05-20 16:15:29 -0700206 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
207 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700208}
209
210TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700211 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
212 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700213}
214
215TEST_F(ConnectionManagerTest, AllowUpdatesOverWimaxTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700216 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWimax,
217 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700218}
219
220TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700221 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kBluetooth,
222 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700223}
224
225TEST_F(ConnectionManagerTest, AllowUpdatesOnlyOver3GPerPolicyTest) {
226 policy::MockDevicePolicy allow_3g_policy;
227
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700228 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700229
Alex Deymof4867c42013-06-28 14:41:39 -0700230 // This test tests cellular (3G) being the only connection type being allowed.
Jay Srinivasan43488792012-06-19 00:25:31 -0700231 set<string> allowed_set;
Sen Jiang255e22b2016-05-20 16:15:29 -0700232 allowed_set.insert(StringForConnectionType(ConnectionType::kCellular));
Jay Srinivasan43488792012-06-19 00:25:31 -0700233
234 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
235 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700236 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700237
Sen Jiang255e22b2016-05-20 16:15:29 -0700238 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
239 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700240}
241
242TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) {
243 policy::MockDevicePolicy allow_3g_policy;
244
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700245 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700246
247 // This test tests multiple connection types being allowed, with
Alex Deymof4867c42013-06-28 14:41:39 -0700248 // 3G one among them. Only Cellular is currently enforced by the policy
249 // setting, the others are ignored (see Bluetooth for example).
Jay Srinivasan43488792012-06-19 00:25:31 -0700250 set<string> allowed_set;
Sen Jiang255e22b2016-05-20 16:15:29 -0700251 allowed_set.insert(StringForConnectionType(ConnectionType::kCellular));
252 allowed_set.insert(StringForConnectionType(ConnectionType::kBluetooth));
Jay Srinivasan43488792012-06-19 00:25:31 -0700253
254 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymo6ae91202014-03-10 19:21:25 -0700255 .Times(3)
Alex Deymo30534502015-07-20 15:06:33 -0700256 .WillRepeatedly(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700257
Sen Jiang255e22b2016-05-20 16:15:29 -0700258 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
259 ConnectionTethering::kUnknown));
260 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
261 ConnectionTethering::kNotDetected));
262 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
263 ConnectionTethering::kUnknown));
264 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
265 ConnectionTethering::kUnknown));
266 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWimax,
267 ConnectionTethering::kUnknown));
268 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kBluetooth,
269 ConnectionTethering::kUnknown));
Alex Deymo6ae91202014-03-10 19:21:25 -0700270
271 // Tethered networks are treated in the same way as Cellular networks and
272 // thus allowed.
Sen Jiang255e22b2016-05-20 16:15:29 -0700273 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
274 ConnectionTethering::kConfirmed));
275 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
276 ConnectionTethering::kConfirmed));
Jay Srinivasan43488792012-06-19 00:25:31 -0700277}
278
Weidong Guo4b0d6032017-04-17 10:08:38 -0700279TEST_F(ConnectionManagerTest, AllowUpdatesOverCellularByDefaultTest) {
280 policy::MockDevicePolicy device_policy;
281 // Set an empty device policy.
282 fake_system_state_.set_device_policy(&device_policy);
283
284 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
285 ConnectionTethering::kUnknown));
Alex Deymo6ae91202014-03-10 19:21:25 -0700286}
287
Weidong Guo4b0d6032017-04-17 10:08:38 -0700288TEST_F(ConnectionManagerTest, AllowUpdatesOverTetheredNetworkByDefaultTest) {
289 policy::MockDevicePolicy device_policy;
290 // Set an empty device policy.
291 fake_system_state_.set_device_policy(&device_policy);
292
293 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
294 ConnectionTethering::kConfirmed));
295 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
296 ConnectionTethering::kConfirmed));
Sen Jiang255e22b2016-05-20 16:15:29 -0700297 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
298 ConnectionTethering::kSuspected));
Jay Srinivasan43488792012-06-19 00:25:31 -0700299}
300
301TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) {
302 policy::MockDevicePolicy block_3g_policy;
303
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700304 fake_system_state_.set_device_policy(&block_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700305
306 // Test that updates for 3G are blocked while updates are allowed
307 // over several other types.
308 set<string> allowed_set;
Sen Jiang255e22b2016-05-20 16:15:29 -0700309 allowed_set.insert(StringForConnectionType(ConnectionType::kEthernet));
310 allowed_set.insert(StringForConnectionType(ConnectionType::kWifi));
311 allowed_set.insert(StringForConnectionType(ConnectionType::kWimax));
Jay Srinivasan43488792012-06-19 00:25:31 -0700312
313 EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_))
314 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700315 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700316
Sen Jiang255e22b2016-05-20 16:15:29 -0700317 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
318 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700319}
320
Weidong Guo4b0d6032017-04-17 10:08:38 -0700321TEST_F(ConnectionManagerTest, AllowUpdatesOver3GIfPolicyIsNotSet) {
322 policy::MockDevicePolicy device_policy;
Jay Srinivasan43488792012-06-19 00:25:31 -0700323
Weidong Guo4b0d6032017-04-17 10:08:38 -0700324 fake_system_state_.set_device_policy(&device_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700325
326 // Return false for GetAllowedConnectionTypesForUpdate and see
Weidong Guo4b0d6032017-04-17 10:08:38 -0700327 // that updates are allowed as device policy is not set. Further
328 // check is left to |OmahaRequestAction|.
329 EXPECT_CALL(device_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymof4867c42013-06-28 14:41:39 -0700330 .Times(1)
331 .WillOnce(Return(false));
Alex Deymof4867c42013-06-28 14:41:39 -0700332
Sen Jiang255e22b2016-05-20 16:15:29 -0700333 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
334 ConnectionTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700335}
336
Weidong Guo840703a2018-01-04 19:41:56 -0800337TEST_F(ConnectionManagerTest,
338 AllowUpdatesOverCellularIfPolicyFailsToBeLoaded) {
339 fake_system_state_.set_device_policy(nullptr);
340
341 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
342 ConnectionTethering::kUnknown));
343}
344
Jay Srinivasan43488792012-06-19 00:25:31 -0700345TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700346 EXPECT_STREQ(shill::kTypeEthernet,
Sen Jiang255e22b2016-05-20 16:15:29 -0700347 StringForConnectionType(ConnectionType::kEthernet));
Ben Chanc6007e42013-09-19 23:49:22 -0700348 EXPECT_STREQ(shill::kTypeWifi,
Sen Jiang255e22b2016-05-20 16:15:29 -0700349 StringForConnectionType(ConnectionType::kWifi));
Ben Chanc6007e42013-09-19 23:49:22 -0700350 EXPECT_STREQ(shill::kTypeWimax,
Sen Jiang255e22b2016-05-20 16:15:29 -0700351 StringForConnectionType(ConnectionType::kWimax));
Ben Chanc6007e42013-09-19 23:49:22 -0700352 EXPECT_STREQ(shill::kTypeBluetooth,
Sen Jiang255e22b2016-05-20 16:15:29 -0700353 StringForConnectionType(ConnectionType::kBluetooth));
Ben Chanc6007e42013-09-19 23:49:22 -0700354 EXPECT_STREQ(shill::kTypeCellular,
Sen Jiang255e22b2016-05-20 16:15:29 -0700355 StringForConnectionType(ConnectionType::kCellular));
356 EXPECT_STREQ("Unknown", StringForConnectionType(ConnectionType::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700357 EXPECT_STREQ("Unknown",
Sen Jiang255e22b2016-05-20 16:15:29 -0700358 StringForConnectionType(static_cast<ConnectionType>(999999)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700359}
360
361TEST_F(ConnectionManagerTest, MalformedServiceList) {
Alex Deymo758dd532015-09-09 15:21:22 -0700362 SetManagerReply("/service/guest/network", false);
Jay Srinivasan43488792012-06-19 00:25:31 -0700363
Sen Jiang255e22b2016-05-20 16:15:29 -0700364 ConnectionType type;
365 ConnectionTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700366 EXPECT_FALSE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700367}
368
369} // namespace chromeos_update_engine