blob: 3cdaf4cda1768109e9e1b57e6c2e22d66c8f4cb4 [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);
187 TestWithServiceType(shill::kTypeWimax, nullptr, ConnectionType::kWimax);
188 TestWithServiceType(
189 shill::kTypeBluetooth, nullptr, ConnectionType::kBluetooth);
190 TestWithServiceType(shill::kTypeCellular, nullptr, ConnectionType::kCellular);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700191}
192
193TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700194 TestWithServiceType(shill::kTypeVPN, nullptr, ConnectionType::kUnknown);
195 TestWithServiceType(
196 shill::kTypeVPN, shill::kTypeVPN, ConnectionType::kUnknown);
197 TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi, ConnectionType::kWifi);
198 TestWithServiceType(
199 shill::kTypeVPN, shill::kTypeWimax, ConnectionType::kWimax);
Jay Srinivasan43488792012-06-19 00:25:31 -0700200}
201
Alex Deymo6ae91202014-03-10 19:21:25 -0700202TEST_F(ConnectionManagerTest, TetheringTest) {
203 TestWithServiceTethering(shill::kTetheringConfirmedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700204 ConnectionTethering::kConfirmed);
Alex Deymo6ae91202014-03-10 19:21:25 -0700205 TestWithServiceTethering(shill::kTetheringNotDetectedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700206 ConnectionTethering::kNotDetected);
Alex Deymo6ae91202014-03-10 19:21:25 -0700207 TestWithServiceTethering(shill::kTetheringSuspectedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700208 ConnectionTethering::kSuspected);
Alex Deymo6ae91202014-03-10 19:21:25 -0700209 TestWithServiceTethering("I'm not a valid property value =)",
Sen Jiang255e22b2016-05-20 16:15:29 -0700210 ConnectionTethering::kUnknown);
Alex Deymo6ae91202014-03-10 19:21:25 -0700211}
212
Jay Srinivasan43488792012-06-19 00:25:31 -0700213TEST_F(ConnectionManagerTest, UnknownTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700214 TestWithServiceType("foo", nullptr, ConnectionType::kUnknown);
Jay Srinivasan43488792012-06-19 00:25:31 -0700215}
216
Colin Howesc9e98d62018-09-18 10:35:20 -0700217TEST_F(ConnectionManagerTest, DisconnectTest) {
218 TestWithServiceDisconnected(ConnectionType::kDisconnected);
219}
220
Jay Srinivasan43488792012-06-19 00:25:31 -0700221TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) {
Jay Srinivasan43488792012-06-19 00:25:31 -0700222 // Updates over Ethernet are allowed even if there's no policy.
Sen Jiang255e22b2016-05-20 16:15:29 -0700223 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
224 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700225}
226
227TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700228 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
229 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700230}
231
232TEST_F(ConnectionManagerTest, AllowUpdatesOverWimaxTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700233 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWimax,
234 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700235}
236
237TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700238 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kBluetooth,
239 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700240}
241
242TEST_F(ConnectionManagerTest, AllowUpdatesOnlyOver3GPerPolicyTest) {
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
Alex Deymof4867c42013-06-28 14:41:39 -0700247 // This test tests cellular (3G) being the only connection type being allowed.
Jay Srinivasan43488792012-06-19 00:25:31 -0700248 set<string> allowed_set;
Sen Jiang255e22b2016-05-20 16:15:29 -0700249 allowed_set.insert(StringForConnectionType(ConnectionType::kCellular));
Jay Srinivasan43488792012-06-19 00:25:31 -0700250
251 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
252 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700253 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700254
Sen Jiang255e22b2016-05-20 16:15:29 -0700255 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
256 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700257}
258
259TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) {
260 policy::MockDevicePolicy allow_3g_policy;
261
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700262 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700263
264 // This test tests multiple connection types being allowed, with
Alex Deymof4867c42013-06-28 14:41:39 -0700265 // 3G one among them. Only Cellular is currently enforced by the policy
266 // setting, the others are ignored (see Bluetooth for example).
Jay Srinivasan43488792012-06-19 00:25:31 -0700267 set<string> allowed_set;
Sen Jiang255e22b2016-05-20 16:15:29 -0700268 allowed_set.insert(StringForConnectionType(ConnectionType::kCellular));
269 allowed_set.insert(StringForConnectionType(ConnectionType::kBluetooth));
Jay Srinivasan43488792012-06-19 00:25:31 -0700270
271 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymo6ae91202014-03-10 19:21:25 -0700272 .Times(3)
Alex Deymo30534502015-07-20 15:06:33 -0700273 .WillRepeatedly(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700274
Sen Jiang255e22b2016-05-20 16:15:29 -0700275 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
276 ConnectionTethering::kUnknown));
277 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
278 ConnectionTethering::kNotDetected));
279 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
280 ConnectionTethering::kUnknown));
281 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
282 ConnectionTethering::kUnknown));
283 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWimax,
284 ConnectionTethering::kUnknown));
285 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kBluetooth,
286 ConnectionTethering::kUnknown));
Alex Deymo6ae91202014-03-10 19:21:25 -0700287
288 // Tethered networks are treated in the same way as Cellular networks and
289 // thus allowed.
Sen Jiang255e22b2016-05-20 16:15:29 -0700290 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
291 ConnectionTethering::kConfirmed));
292 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
293 ConnectionTethering::kConfirmed));
Jay Srinivasan43488792012-06-19 00:25:31 -0700294}
295
Weidong Guo421ff332017-04-17 10:08:38 -0700296TEST_F(ConnectionManagerTest, AllowUpdatesOverCellularByDefaultTest) {
297 policy::MockDevicePolicy device_policy;
298 // Set an empty device policy.
299 fake_system_state_.set_device_policy(&device_policy);
300
301 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
302 ConnectionTethering::kUnknown));
Alex Deymo6ae91202014-03-10 19:21:25 -0700303}
304
Weidong Guo421ff332017-04-17 10:08:38 -0700305TEST_F(ConnectionManagerTest, AllowUpdatesOverTetheredNetworkByDefaultTest) {
306 policy::MockDevicePolicy device_policy;
307 // Set an empty device policy.
308 fake_system_state_.set_device_policy(&device_policy);
309
310 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
311 ConnectionTethering::kConfirmed));
312 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
313 ConnectionTethering::kConfirmed));
Sen Jiang255e22b2016-05-20 16:15:29 -0700314 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
315 ConnectionTethering::kSuspected));
Jay Srinivasan43488792012-06-19 00:25:31 -0700316}
317
318TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) {
319 policy::MockDevicePolicy block_3g_policy;
320
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700321 fake_system_state_.set_device_policy(&block_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700322
323 // Test that updates for 3G are blocked while updates are allowed
324 // over several other types.
325 set<string> allowed_set;
Sen Jiang255e22b2016-05-20 16:15:29 -0700326 allowed_set.insert(StringForConnectionType(ConnectionType::kEthernet));
327 allowed_set.insert(StringForConnectionType(ConnectionType::kWifi));
328 allowed_set.insert(StringForConnectionType(ConnectionType::kWimax));
Jay Srinivasan43488792012-06-19 00:25:31 -0700329
330 EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_))
331 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700332 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700333
Sen Jiang255e22b2016-05-20 16:15:29 -0700334 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
335 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700336}
337
Weidong Guo421ff332017-04-17 10:08:38 -0700338TEST_F(ConnectionManagerTest, AllowUpdatesOver3GIfPolicyIsNotSet) {
339 policy::MockDevicePolicy device_policy;
Jay Srinivasan43488792012-06-19 00:25:31 -0700340
Weidong Guo421ff332017-04-17 10:08:38 -0700341 fake_system_state_.set_device_policy(&device_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700342
343 // Return false for GetAllowedConnectionTypesForUpdate and see
Weidong Guo421ff332017-04-17 10:08:38 -0700344 // that updates are allowed as device policy is not set. Further
345 // check is left to |OmahaRequestAction|.
346 EXPECT_CALL(device_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymof4867c42013-06-28 14:41:39 -0700347 .Times(1)
348 .WillOnce(Return(false));
Alex Deymof4867c42013-06-28 14:41:39 -0700349
Sen Jiang255e22b2016-05-20 16:15:29 -0700350 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
351 ConnectionTethering::kUnknown));
Weidong Guo421ff332017-04-17 10:08:38 -0700352}
Tao Bao5688d162017-06-06 13:09:06 -0700353
Weidong Guo421ff332017-04-17 10:08:38 -0700354TEST_F(ConnectionManagerTest, AllowUpdatesOverCellularIfPolicyFailsToBeLoaded) {
355 fake_system_state_.set_device_policy(nullptr);
356
357 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
358 ConnectionTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700359}
360
Jay Srinivasan43488792012-06-19 00:25:31 -0700361TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700362 EXPECT_STREQ(shill::kTypeEthernet,
Sen Jiang255e22b2016-05-20 16:15:29 -0700363 StringForConnectionType(ConnectionType::kEthernet));
Ben Chanc6007e42013-09-19 23:49:22 -0700364 EXPECT_STREQ(shill::kTypeWifi,
Sen Jiang255e22b2016-05-20 16:15:29 -0700365 StringForConnectionType(ConnectionType::kWifi));
Ben Chanc6007e42013-09-19 23:49:22 -0700366 EXPECT_STREQ(shill::kTypeWimax,
Sen Jiang255e22b2016-05-20 16:15:29 -0700367 StringForConnectionType(ConnectionType::kWimax));
Ben Chanc6007e42013-09-19 23:49:22 -0700368 EXPECT_STREQ(shill::kTypeBluetooth,
Sen Jiang255e22b2016-05-20 16:15:29 -0700369 StringForConnectionType(ConnectionType::kBluetooth));
Ben Chanc6007e42013-09-19 23:49:22 -0700370 EXPECT_STREQ(shill::kTypeCellular,
Sen Jiang255e22b2016-05-20 16:15:29 -0700371 StringForConnectionType(ConnectionType::kCellular));
372 EXPECT_STREQ("Unknown", StringForConnectionType(ConnectionType::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700373 EXPECT_STREQ("Unknown",
Sen Jiang255e22b2016-05-20 16:15:29 -0700374 StringForConnectionType(static_cast<ConnectionType>(999999)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700375}
376
377TEST_F(ConnectionManagerTest, MalformedServiceList) {
Alex Deymo758dd532015-09-09 15:21:22 -0700378 SetManagerReply("/service/guest/network", false);
Jay Srinivasan43488792012-06-19 00:25:31 -0700379
Sen Jiang255e22b2016-05-20 16:15:29 -0700380 ConnectionType type;
381 ConnectionTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700382 EXPECT_FALSE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700383}
384
385} // namespace chromeos_update_engine