blob: 3e810a72bcd49ea50c733fc0ecbd55a1903b3df0 [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>
24#include <brillo/make_unique_ptr.h>
25#include <brillo/message_loops/fake_message_loop.h>
26#include <brillo/variant_dictionary.h>
Alex Deymo5665d0c2014-05-28 17:45:43 -070027#include <gmock/gmock.h>
Jay Srinivasan43488792012-06-19 00:25:31 -070028#include <gtest/gtest.h>
Alex Deymod6deb1d2015-08-28 15:54:37 -070029#include <shill/dbus-constants.h>
30#include <shill/dbus-proxies.h>
31#include <shill/dbus-proxy-mocks.h>
Jay Srinivasan43488792012-06-19 00:25:31 -070032
Alex Deymo39910dc2015-11-09 17:04:30 -080033#include "update_engine/common/test_utils.h"
Alex Deymo30534502015-07-20 15:06:33 -070034#include "update_engine/fake_shill_proxy.h"
Gilad Arnold5bb4c902014-04-10 12:32:13 -070035#include "update_engine/fake_system_state.h"
Jay Srinivasan43488792012-06-19 00:25:31 -070036
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:
Alex Deymo30534502015-07-20 15:06:33 -070049 void SetUp() override {
50 loop_.SetAsCurrent();
Gilad Arnold5bb4c902014-04-10 12:32:13 -070051 fake_system_state_.set_connection_manager(&cmut_);
Jay Srinivasan43488792012-06-19 00:25:31 -070052 }
53
Alex Deymo30534502015-07-20 15:06:33 -070054 void TearDown() override { EXPECT_FALSE(loop_.PendingTasks()); }
Alex Deymo1c4e6382013-07-15 12:09:51 -070055
Alex Deymo30534502015-07-20 15:06:33 -070056 protected:
57 // Sets the default_service object path in the response from the
58 // ManagerProxyMock instance.
59 void SetManagerReply(const char* default_service, bool reply_succeeds);
60
61 // Sets the |service_type|, |physical_technology| and |service_tethering|
62 // properties in the mocked service |service_path|. If any of the three
63 // const char* is a nullptr, the corresponding property will not be included
64 // in the response.
65 void SetServiceReply(const string& service_path,
66 const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -070067 const char* physical_technology,
68 const char* service_tethering);
Alex Deymo30534502015-07-20 15:06:33 -070069
Jay Srinivasan43488792012-06-19 00:25:31 -070070 void TestWithServiceType(
Alex Deymo1c4e6382013-07-15 12:09:51 -070071 const char* service_type,
72 const char* physical_technology,
73 NetworkConnectionType expected_type);
Alex Deymo6ae91202014-03-10 19:21:25 -070074 void TestWithServiceTethering(
75 const char* service_tethering,
76 NetworkTethering expected_tethering);
Jay Srinivasan43488792012-06-19 00:25:31 -070077
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070078 brillo::FakeMessageLoop loop_{nullptr};
Gilad Arnold5bb4c902014-04-10 12:32:13 -070079 FakeSystemState fake_system_state_;
Alex Deymo30534502015-07-20 15:06:33 -070080 FakeShillProxy fake_shill_proxy_;
81
82 // ConnectionManager under test.
83 ConnectionManager cmut_{&fake_shill_proxy_, &fake_system_state_};
Jay Srinivasan43488792012-06-19 00:25:31 -070084};
85
Alex Deymo30534502015-07-20 15:06:33 -070086void ConnectionManagerTest::SetManagerReply(const char* default_service,
87 bool reply_succeeds) {
88 ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_.GetManagerProxy();
89 if (!reply_succeeds) {
90 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
91 .WillOnce(Return(false));
92 return;
93 }
Jay Srinivasan43488792012-06-19 00:25:31 -070094
Alex Deymo30534502015-07-20 15:06:33 -070095 // Create a dictionary of properties and optionally include the default
96 // service.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070097 brillo::VariantDictionary reply_dict;
Alex Deymo30534502015-07-20 15:06:33 -070098 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
Jay Srinivasan43488792012-06-19 00:25:31 -070099
Alex Deymo30534502015-07-20 15:06:33 -0700100 if (default_service) {
101 reply_dict[shill::kDefaultServiceProperty] =
102 dbus::ObjectPath(default_service);
103 }
104 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
105 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700106}
107
Alex Deymo30534502015-07-20 15:06:33 -0700108void ConnectionManagerTest::SetServiceReply(const string& service_path,
109 const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -0700110 const char* physical_technology,
111 const char* service_tethering) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700112 brillo::VariantDictionary reply_dict;
Alex Deymo30534502015-07-20 15:06:33 -0700113 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
114
115 if (service_type)
116 reply_dict[shill::kTypeProperty] = string(service_type);
Jay Srinivasan43488792012-06-19 00:25:31 -0700117
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700118 if (physical_technology) {
Alex Deymo30534502015-07-20 15:06:33 -0700119 reply_dict[shill::kPhysicalTechnologyProperty] =
120 string(physical_technology);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700121 }
122
Alex Deymo30534502015-07-20 15:06:33 -0700123 if (service_tethering)
124 reply_dict[shill::kTetheringProperty] = string(service_tethering);
125
126 std::unique_ptr<ServiceProxyMock> service_proxy_mock(new ServiceProxyMock());
Alex Deymo6ae91202014-03-10 19:21:25 -0700127
Jay Srinivasan43488792012-06-19 00:25:31 -0700128 // Plumb return value into mock object.
Alex Deymo30534502015-07-20 15:06:33 -0700129 EXPECT_CALL(*service_proxy_mock.get(), GetProperties(_, _, _))
130 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700131
Alex Deymo758dd532015-09-09 15:21:22 -0700132 fake_shill_proxy_.SetServiceForPath(dbus::ObjectPath(service_path),
Alex Deymo30534502015-07-20 15:06:33 -0700133 std::move(service_proxy_mock));
Jay Srinivasan43488792012-06-19 00:25:31 -0700134}
135
136void ConnectionManagerTest::TestWithServiceType(
137 const char* service_type,
Alex Deymo1c4e6382013-07-15 12:09:51 -0700138 const char* physical_technology,
Jay Srinivasan43488792012-06-19 00:25:31 -0700139 NetworkConnectionType expected_type) {
Alex Deymo758dd532015-09-09 15:21:22 -0700140 SetManagerReply("/service/guest/network", true);
141 SetServiceReply("/service/guest/network",
Alex Deymo30534502015-07-20 15:06:33 -0700142 service_type,
143 physical_technology,
Alex Deymo6ae91202014-03-10 19:21:25 -0700144 shill::kTetheringNotDetectedState);
Jay Srinivasan43488792012-06-19 00:25:31 -0700145
146 NetworkConnectionType type;
Alex Deymo6ae91202014-03-10 19:21:25 -0700147 NetworkTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700148 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700149 EXPECT_EQ(expected_type, type);
Alex Deymo30534502015-07-20 15:06:33 -0700150 testing::Mock::VerifyAndClearExpectations(
151 fake_shill_proxy_.GetManagerProxy());
Jay Srinivasan43488792012-06-19 00:25:31 -0700152}
153
Alex Deymo6ae91202014-03-10 19:21:25 -0700154void ConnectionManagerTest::TestWithServiceTethering(
155 const char* service_tethering,
156 NetworkTethering expected_tethering) {
Alex Deymo758dd532015-09-09 15:21:22 -0700157 SetManagerReply("/service/guest/network", true);
Alex Deymo30534502015-07-20 15:06:33 -0700158 SetServiceReply(
Alex Deymo758dd532015-09-09 15:21:22 -0700159 "/service/guest/network", shill::kTypeWifi, nullptr, service_tethering);
Alex Deymo6ae91202014-03-10 19:21:25 -0700160
161 NetworkConnectionType type;
162 NetworkTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700163 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Alex Deymo6ae91202014-03-10 19:21:25 -0700164 EXPECT_EQ(expected_tethering, tethering);
Alex Deymo30534502015-07-20 15:06:33 -0700165 testing::Mock::VerifyAndClearExpectations(
166 fake_shill_proxy_.GetManagerProxy());
Alex Deymo6ae91202014-03-10 19:21:25 -0700167}
168
Jay Srinivasan43488792012-06-19 00:25:31 -0700169TEST_F(ConnectionManagerTest, SimpleTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700170 TestWithServiceType(shill::kTypeEthernet, nullptr,
171 NetworkConnectionType::kEthernet);
172 TestWithServiceType(shill::kTypeWifi, nullptr,
173 NetworkConnectionType::kWifi);
174 TestWithServiceType(shill::kTypeWimax, nullptr,
175 NetworkConnectionType::kWimax);
176 TestWithServiceType(shill::kTypeBluetooth, nullptr,
177 NetworkConnectionType::kBluetooth);
178 TestWithServiceType(shill::kTypeCellular, nullptr,
179 NetworkConnectionType::kCellular);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700180}
181
182TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700183 TestWithServiceType(shill::kTypeVPN, nullptr,
184 NetworkConnectionType::kUnknown);
185 TestWithServiceType(shill::kTypeVPN, shill::kTypeVPN,
186 NetworkConnectionType::kUnknown);
187 TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi,
188 NetworkConnectionType::kWifi);
189 TestWithServiceType(shill::kTypeVPN, shill::kTypeWimax,
190 NetworkConnectionType::kWimax);
Jay Srinivasan43488792012-06-19 00:25:31 -0700191}
192
Alex Deymo6ae91202014-03-10 19:21:25 -0700193TEST_F(ConnectionManagerTest, TetheringTest) {
194 TestWithServiceTethering(shill::kTetheringConfirmedState,
195 NetworkTethering::kConfirmed);
196 TestWithServiceTethering(shill::kTetheringNotDetectedState,
197 NetworkTethering::kNotDetected);
198 TestWithServiceTethering(shill::kTetheringSuspectedState,
199 NetworkTethering::kSuspected);
200 TestWithServiceTethering("I'm not a valid property value =)",
201 NetworkTethering::kUnknown);
202}
203
Jay Srinivasan43488792012-06-19 00:25:31 -0700204TEST_F(ConnectionManagerTest, UnknownTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700205 TestWithServiceType("foo", nullptr, NetworkConnectionType::kUnknown);
Jay Srinivasan43488792012-06-19 00:25:31 -0700206}
207
208TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) {
Jay Srinivasan43488792012-06-19 00:25:31 -0700209 // Updates over Ethernet are allowed even if there's no policy.
Alex Deymo75eac7e2015-07-29 13:39:14 -0700210 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700211 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700212}
213
214TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700215 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
216 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700217}
218
219TEST_F(ConnectionManagerTest, AllowUpdatesOverWimaxTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700220 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWimax,
Alex Deymo6ae91202014-03-10 19:21:25 -0700221 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700222}
223
224TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700225 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kBluetooth,
Alex Deymo6ae91202014-03-10 19:21:25 -0700226 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700227}
228
229TEST_F(ConnectionManagerTest, AllowUpdatesOnlyOver3GPerPolicyTest) {
230 policy::MockDevicePolicy allow_3g_policy;
231
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700232 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700233
Alex Deymof4867c42013-06-28 14:41:39 -0700234 // This test tests cellular (3G) being the only connection type being allowed.
Jay Srinivasan43488792012-06-19 00:25:31 -0700235 set<string> allowed_set;
Alex Deymo75eac7e2015-07-29 13:39:14 -0700236 allowed_set.insert(
237 cmut_.StringForConnectionType(NetworkConnectionType::kCellular));
Jay Srinivasan43488792012-06-19 00:25:31 -0700238
239 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
240 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700241 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700242
Alex Deymo75eac7e2015-07-29 13:39:14 -0700243 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700244 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700245}
246
247TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) {
248 policy::MockDevicePolicy allow_3g_policy;
249
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700250 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700251
252 // This test tests multiple connection types being allowed, with
Alex Deymof4867c42013-06-28 14:41:39 -0700253 // 3G one among them. Only Cellular is currently enforced by the policy
254 // setting, the others are ignored (see Bluetooth for example).
Jay Srinivasan43488792012-06-19 00:25:31 -0700255 set<string> allowed_set;
Alex Deymo75eac7e2015-07-29 13:39:14 -0700256 allowed_set.insert(
257 cmut_.StringForConnectionType(NetworkConnectionType::kCellular));
258 allowed_set.insert(
259 cmut_.StringForConnectionType(NetworkConnectionType::kBluetooth));
Jay Srinivasan43488792012-06-19 00:25:31 -0700260
261 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymo6ae91202014-03-10 19:21:25 -0700262 .Times(3)
Alex Deymo30534502015-07-20 15:06:33 -0700263 .WillRepeatedly(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700264
Alex Deymo75eac7e2015-07-29 13:39:14 -0700265 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700266 NetworkTethering::kUnknown));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700267 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700268 NetworkTethering::kNotDetected));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700269 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700270 NetworkTethering::kUnknown));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700271 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
272 NetworkTethering::kUnknown));
273 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWimax,
274 NetworkTethering::kUnknown));
275 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kBluetooth,
Alex Deymo6ae91202014-03-10 19:21:25 -0700276 NetworkTethering::kUnknown));
277
278 // Tethered networks are treated in the same way as Cellular networks and
279 // thus allowed.
Alex Deymo75eac7e2015-07-29 13:39:14 -0700280 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700281 NetworkTethering::kConfirmed));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700282 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
Alex Deymo6ae91202014-03-10 19:21:25 -0700283 NetworkTethering::kConfirmed));
Jay Srinivasan43488792012-06-19 00:25:31 -0700284}
285
Weidong Guo70063d92017-04-17 10:08:38 -0700286TEST_F(ConnectionManagerTest, AllowUpdatesOverCellularByDefaultTest) {
287 policy::MockDevicePolicy device_policy;
288 // Set an empty device policy.
289 fake_system_state_.set_device_policy(&device_policy);
290
291 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700292 NetworkTethering::kUnknown));
293}
294
Weidong Guo70063d92017-04-17 10:08:38 -0700295TEST_F(ConnectionManagerTest, AllowUpdatesOverTetheredNetworkByDefaultTest) {
296 policy::MockDevicePolicy device_policy;
297 // Set an empty device policy.
298 fake_system_state_.set_device_policy(&device_policy);
299
300 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
Alex Deymo6ae91202014-03-10 19:21:25 -0700301 NetworkTethering::kConfirmed));
Weidong Guo70063d92017-04-17 10:08:38 -0700302 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700303 NetworkTethering::kConfirmed));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700304 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
Alex Deymo6ae91202014-03-10 19:21:25 -0700305 NetworkTethering::kSuspected));
Jay Srinivasan43488792012-06-19 00:25:31 -0700306}
307
308TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) {
309 policy::MockDevicePolicy block_3g_policy;
310
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700311 fake_system_state_.set_device_policy(&block_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700312
313 // Test that updates for 3G are blocked while updates are allowed
314 // over several other types.
315 set<string> allowed_set;
Alex Deymo75eac7e2015-07-29 13:39:14 -0700316 allowed_set.insert(
317 cmut_.StringForConnectionType(NetworkConnectionType::kEthernet));
318 allowed_set.insert(
319 cmut_.StringForConnectionType(NetworkConnectionType::kWifi));
320 allowed_set.insert(
321 cmut_.StringForConnectionType(NetworkConnectionType::kWimax));
Jay Srinivasan43488792012-06-19 00:25:31 -0700322
323 EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_))
324 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700325 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700326
Alex Deymo75eac7e2015-07-29 13:39:14 -0700327 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700328 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700329}
330
Weidong Guo70063d92017-04-17 10:08:38 -0700331TEST_F(ConnectionManagerTest, AllowUpdatesOver3GIfPolicyIsNotSet) {
332 policy::MockDevicePolicy device_policy;
Jay Srinivasan43488792012-06-19 00:25:31 -0700333
Weidong Guo70063d92017-04-17 10:08:38 -0700334 fake_system_state_.set_device_policy(&device_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700335
336 // Return false for GetAllowedConnectionTypesForUpdate and see
Weidong Guo70063d92017-04-17 10:08:38 -0700337 // that updates are allowed as device policy is not set. Further
338 // check is left to |OmahaRequestAction|.
339 EXPECT_CALL(device_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymof4867c42013-06-28 14:41:39 -0700340 .Times(1)
341 .WillOnce(Return(false));
Alex Deymof4867c42013-06-28 14:41:39 -0700342
Alex Deymo75eac7e2015-07-29 13:39:14 -0700343 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700344 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700345}
346
Jay Srinivasan43488792012-06-19 00:25:31 -0700347TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700348 EXPECT_STREQ(shill::kTypeEthernet,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700349 cmut_.StringForConnectionType(NetworkConnectionType::kEthernet));
Ben Chanc6007e42013-09-19 23:49:22 -0700350 EXPECT_STREQ(shill::kTypeWifi,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700351 cmut_.StringForConnectionType(NetworkConnectionType::kWifi));
Ben Chanc6007e42013-09-19 23:49:22 -0700352 EXPECT_STREQ(shill::kTypeWimax,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700353 cmut_.StringForConnectionType(NetworkConnectionType::kWimax));
Ben Chanc6007e42013-09-19 23:49:22 -0700354 EXPECT_STREQ(shill::kTypeBluetooth,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700355 cmut_.StringForConnectionType(
356 NetworkConnectionType::kBluetooth));
Ben Chanc6007e42013-09-19 23:49:22 -0700357 EXPECT_STREQ(shill::kTypeCellular,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700358 cmut_.StringForConnectionType(NetworkConnectionType::kCellular));
Jay Srinivasan43488792012-06-19 00:25:31 -0700359 EXPECT_STREQ("Unknown",
Alex Deymo75eac7e2015-07-29 13:39:14 -0700360 cmut_.StringForConnectionType(NetworkConnectionType::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700361 EXPECT_STREQ("Unknown",
362 cmut_.StringForConnectionType(
363 static_cast<NetworkConnectionType>(999999)));
364}
365
366TEST_F(ConnectionManagerTest, MalformedServiceList) {
Alex Deymo758dd532015-09-09 15:21:22 -0700367 SetManagerReply("/service/guest/network", false);
Jay Srinivasan43488792012-06-19 00:25:31 -0700368
369 NetworkConnectionType type;
Alex Deymo6ae91202014-03-10 19:21:25 -0700370 NetworkTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700371 EXPECT_FALSE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700372}
373
374} // namespace chromeos_update_engine