blob: 85b8c5785ea3ac31c3d06be7872ab00134fb8afd [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;
Jay Srinivasan43488792012-06-19 00:25:31 -070043using testing::Return;
Alex Deymo30534502015-07-20 15:06:33 -070044using testing::SetArgPointee;
Alex Deymof329b932014-10-30 01:37:48 -070045using testing::_;
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
Jay Srinivasan43488792012-06-19 00:25:31 -070074 void TestWithServiceType(
Alex Deymo1c4e6382013-07-15 12:09:51 -070075 const char* service_type,
76 const char* physical_technology,
Sen Jiang255e22b2016-05-20 16:15:29 -070077 ConnectionType expected_type);
Alex Deymo6ae91202014-03-10 19:21:25 -070078 void TestWithServiceTethering(
79 const char* service_tethering,
Sen Jiang255e22b2016-05-20 16:15:29 -070080 ConnectionTethering expected_tethering);
Jay Srinivasan43488792012-06-19 00:25:31 -070081
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070082 brillo::FakeMessageLoop loop_{nullptr};
Gilad Arnold5bb4c902014-04-10 12:32:13 -070083 FakeSystemState fake_system_state_;
Sen Jiangf5bebae2016-06-03 15:36:54 -070084 FakeShillProxy* fake_shill_proxy_;
Alex Deymo30534502015-07-20 15:06:33 -070085
86 // ConnectionManager under test.
Sen Jiangf5bebae2016-06-03 15:36:54 -070087 ConnectionManager cmut_{fake_shill_proxy_, &fake_system_state_};
Jay Srinivasan43488792012-06-19 00:25:31 -070088};
89
Alex Deymo30534502015-07-20 15:06:33 -070090void ConnectionManagerTest::SetManagerReply(const char* default_service,
91 bool reply_succeeds) {
Sen Jiangf5bebae2016-06-03 15:36:54 -070092 ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_->GetManagerProxy();
Alex Deymo30534502015-07-20 15:06:33 -070093 if (!reply_succeeds) {
94 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
95 .WillOnce(Return(false));
96 return;
97 }
Jay Srinivasan43488792012-06-19 00:25:31 -070098
Alex Deymo30534502015-07-20 15:06:33 -070099 // Create a dictionary of properties and optionally include the default
100 // service.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700101 brillo::VariantDictionary reply_dict;
Alex Deymo30534502015-07-20 15:06:33 -0700102 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
Jay Srinivasan43488792012-06-19 00:25:31 -0700103
Alex Deymo30534502015-07-20 15:06:33 -0700104 if (default_service) {
105 reply_dict[shill::kDefaultServiceProperty] =
106 dbus::ObjectPath(default_service);
107 }
108 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
109 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700110}
111
Alex Deymo30534502015-07-20 15:06:33 -0700112void ConnectionManagerTest::SetServiceReply(const string& service_path,
113 const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -0700114 const char* physical_technology,
115 const char* service_tethering) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700116 brillo::VariantDictionary reply_dict;
Alex Deymo30534502015-07-20 15:06:33 -0700117 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
118
119 if (service_type)
120 reply_dict[shill::kTypeProperty] = string(service_type);
Jay Srinivasan43488792012-06-19 00:25:31 -0700121
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700122 if (physical_technology) {
Alex Deymo30534502015-07-20 15:06:33 -0700123 reply_dict[shill::kPhysicalTechnologyProperty] =
124 string(physical_technology);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700125 }
126
Alex Deymo30534502015-07-20 15:06:33 -0700127 if (service_tethering)
128 reply_dict[shill::kTetheringProperty] = string(service_tethering);
129
130 std::unique_ptr<ServiceProxyMock> service_proxy_mock(new ServiceProxyMock());
Alex Deymo6ae91202014-03-10 19:21:25 -0700131
Jay Srinivasan43488792012-06-19 00:25:31 -0700132 // Plumb return value into mock object.
Alex Deymo30534502015-07-20 15:06:33 -0700133 EXPECT_CALL(*service_proxy_mock.get(), GetProperties(_, _, _))
134 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700135
Sen Jiangf5bebae2016-06-03 15:36:54 -0700136 fake_shill_proxy_->SetServiceForPath(dbus::ObjectPath(service_path),
137 std::move(service_proxy_mock));
Jay Srinivasan43488792012-06-19 00:25:31 -0700138}
139
140void ConnectionManagerTest::TestWithServiceType(
141 const char* service_type,
Alex Deymo1c4e6382013-07-15 12:09:51 -0700142 const char* physical_technology,
Sen Jiang255e22b2016-05-20 16:15:29 -0700143 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(
159 const char* service_tethering,
Sen Jiang255e22b2016-05-20 16:15:29 -0700160 ConnectionTethering expected_tethering) {
Alex Deymo758dd532015-09-09 15:21:22 -0700161 SetManagerReply("/service/guest/network", true);
Alex Deymo30534502015-07-20 15:06:33 -0700162 SetServiceReply(
Alex Deymo758dd532015-09-09 15:21:22 -0700163 "/service/guest/network", shill::kTypeWifi, nullptr, service_tethering);
Alex Deymo6ae91202014-03-10 19:21:25 -0700164
Sen Jiang255e22b2016-05-20 16:15:29 -0700165 ConnectionType type;
166 ConnectionTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700167 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Alex Deymo6ae91202014-03-10 19:21:25 -0700168 EXPECT_EQ(expected_tethering, tethering);
Alex Deymo30534502015-07-20 15:06:33 -0700169 testing::Mock::VerifyAndClearExpectations(
Sen Jiangf5bebae2016-06-03 15:36:54 -0700170 fake_shill_proxy_->GetManagerProxy());
Alex Deymo6ae91202014-03-10 19:21:25 -0700171}
172
Jay Srinivasan43488792012-06-19 00:25:31 -0700173TEST_F(ConnectionManagerTest, SimpleTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700174 TestWithServiceType(shill::kTypeEthernet, nullptr, ConnectionType::kEthernet);
175 TestWithServiceType(shill::kTypeWifi, nullptr, ConnectionType::kWifi);
176 TestWithServiceType(shill::kTypeWimax, nullptr, ConnectionType::kWimax);
177 TestWithServiceType(
178 shill::kTypeBluetooth, nullptr, ConnectionType::kBluetooth);
179 TestWithServiceType(shill::kTypeCellular, nullptr, ConnectionType::kCellular);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700180}
181
182TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700183 TestWithServiceType(shill::kTypeVPN, nullptr, ConnectionType::kUnknown);
184 TestWithServiceType(
185 shill::kTypeVPN, shill::kTypeVPN, ConnectionType::kUnknown);
186 TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi, ConnectionType::kWifi);
187 TestWithServiceType(
188 shill::kTypeVPN, shill::kTypeWimax, ConnectionType::kWimax);
Jay Srinivasan43488792012-06-19 00:25:31 -0700189}
190
Alex Deymo6ae91202014-03-10 19:21:25 -0700191TEST_F(ConnectionManagerTest, TetheringTest) {
192 TestWithServiceTethering(shill::kTetheringConfirmedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700193 ConnectionTethering::kConfirmed);
Alex Deymo6ae91202014-03-10 19:21:25 -0700194 TestWithServiceTethering(shill::kTetheringNotDetectedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700195 ConnectionTethering::kNotDetected);
Alex Deymo6ae91202014-03-10 19:21:25 -0700196 TestWithServiceTethering(shill::kTetheringSuspectedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700197 ConnectionTethering::kSuspected);
Alex Deymo6ae91202014-03-10 19:21:25 -0700198 TestWithServiceTethering("I'm not a valid property value =)",
Sen Jiang255e22b2016-05-20 16:15:29 -0700199 ConnectionTethering::kUnknown);
Alex Deymo6ae91202014-03-10 19:21:25 -0700200}
201
Jay Srinivasan43488792012-06-19 00:25:31 -0700202TEST_F(ConnectionManagerTest, UnknownTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700203 TestWithServiceType("foo", nullptr, ConnectionType::kUnknown);
Jay Srinivasan43488792012-06-19 00:25:31 -0700204}
205
206TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) {
Jay Srinivasan43488792012-06-19 00:25:31 -0700207 // Updates over Ethernet are allowed even if there's no policy.
Sen Jiang255e22b2016-05-20 16:15:29 -0700208 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
209 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700210}
211
212TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700213 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
214 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700215}
216
217TEST_F(ConnectionManagerTest, AllowUpdatesOverWimaxTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700218 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWimax,
219 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700220}
221
222TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700223 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kBluetooth,
224 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700225}
226
227TEST_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
251 // setting, the others are ignored (see Bluetooth for example).
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));
254 allowed_set.insert(StringForConnectionType(ConnectionType::kBluetooth));
Jay Srinivasan43488792012-06-19 00:25:31 -0700255
256 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymo6ae91202014-03-10 19:21:25 -0700257 .Times(3)
Alex Deymo30534502015-07-20 15:06:33 -0700258 .WillRepeatedly(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700259
Sen Jiang255e22b2016-05-20 16:15:29 -0700260 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
261 ConnectionTethering::kUnknown));
262 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
263 ConnectionTethering::kNotDetected));
264 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
265 ConnectionTethering::kUnknown));
266 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
267 ConnectionTethering::kUnknown));
268 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWimax,
269 ConnectionTethering::kUnknown));
270 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kBluetooth,
271 ConnectionTethering::kUnknown));
Alex Deymo6ae91202014-03-10 19:21:25 -0700272
273 // Tethered networks are treated in the same way as Cellular networks and
274 // thus allowed.
Sen Jiang255e22b2016-05-20 16:15:29 -0700275 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
276 ConnectionTethering::kConfirmed));
277 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
278 ConnectionTethering::kConfirmed));
Jay Srinivasan43488792012-06-19 00:25:31 -0700279}
280
Weidong Guo421ff332017-04-17 10:08:38 -0700281TEST_F(ConnectionManagerTest, AllowUpdatesOverCellularByDefaultTest) {
282 policy::MockDevicePolicy device_policy;
283 // Set an empty device policy.
284 fake_system_state_.set_device_policy(&device_policy);
285
286 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
287 ConnectionTethering::kUnknown));
Alex Deymo6ae91202014-03-10 19:21:25 -0700288}
289
Weidong Guo421ff332017-04-17 10:08:38 -0700290TEST_F(ConnectionManagerTest, AllowUpdatesOverTetheredNetworkByDefaultTest) {
291 policy::MockDevicePolicy device_policy;
292 // Set an empty device policy.
293 fake_system_state_.set_device_policy(&device_policy);
294
295 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
296 ConnectionTethering::kConfirmed));
297 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
298 ConnectionTethering::kConfirmed));
Sen Jiang255e22b2016-05-20 16:15:29 -0700299 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
300 ConnectionTethering::kSuspected));
Jay Srinivasan43488792012-06-19 00:25:31 -0700301}
302
303TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) {
304 policy::MockDevicePolicy block_3g_policy;
305
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700306 fake_system_state_.set_device_policy(&block_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700307
308 // Test that updates for 3G are blocked while updates are allowed
309 // over several other types.
310 set<string> allowed_set;
Sen Jiang255e22b2016-05-20 16:15:29 -0700311 allowed_set.insert(StringForConnectionType(ConnectionType::kEthernet));
312 allowed_set.insert(StringForConnectionType(ConnectionType::kWifi));
313 allowed_set.insert(StringForConnectionType(ConnectionType::kWimax));
Jay Srinivasan43488792012-06-19 00:25:31 -0700314
315 EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_))
316 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700317 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700318
Sen Jiang255e22b2016-05-20 16:15:29 -0700319 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
320 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700321}
322
Weidong Guo421ff332017-04-17 10:08:38 -0700323TEST_F(ConnectionManagerTest, AllowUpdatesOver3GIfPolicyIsNotSet) {
324 policy::MockDevicePolicy device_policy;
Jay Srinivasan43488792012-06-19 00:25:31 -0700325
Weidong Guo421ff332017-04-17 10:08:38 -0700326 fake_system_state_.set_device_policy(&device_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700327
328 // Return false for GetAllowedConnectionTypesForUpdate and see
Weidong Guo421ff332017-04-17 10:08:38 -0700329 // that updates are allowed as device policy is not set. Further
330 // check is left to |OmahaRequestAction|.
331 EXPECT_CALL(device_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymof4867c42013-06-28 14:41:39 -0700332 .Times(1)
333 .WillOnce(Return(false));
Alex Deymof4867c42013-06-28 14:41:39 -0700334
Sen Jiang255e22b2016-05-20 16:15:29 -0700335 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
336 ConnectionTethering::kUnknown));
Weidong Guo421ff332017-04-17 10:08:38 -0700337}
Tao Bao5688d162017-06-06 13:09:06 -0700338
Weidong Guo421ff332017-04-17 10:08:38 -0700339TEST_F(ConnectionManagerTest, AllowUpdatesOverCellularIfPolicyFailsToBeLoaded) {
340 fake_system_state_.set_device_policy(nullptr);
341
342 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
343 ConnectionTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700344}
345
Jay Srinivasan43488792012-06-19 00:25:31 -0700346TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700347 EXPECT_STREQ(shill::kTypeEthernet,
Sen Jiang255e22b2016-05-20 16:15:29 -0700348 StringForConnectionType(ConnectionType::kEthernet));
Ben Chanc6007e42013-09-19 23:49:22 -0700349 EXPECT_STREQ(shill::kTypeWifi,
Sen Jiang255e22b2016-05-20 16:15:29 -0700350 StringForConnectionType(ConnectionType::kWifi));
Ben Chanc6007e42013-09-19 23:49:22 -0700351 EXPECT_STREQ(shill::kTypeWimax,
Sen Jiang255e22b2016-05-20 16:15:29 -0700352 StringForConnectionType(ConnectionType::kWimax));
Ben Chanc6007e42013-09-19 23:49:22 -0700353 EXPECT_STREQ(shill::kTypeBluetooth,
Sen Jiang255e22b2016-05-20 16:15:29 -0700354 StringForConnectionType(ConnectionType::kBluetooth));
Ben Chanc6007e42013-09-19 23:49:22 -0700355 EXPECT_STREQ(shill::kTypeCellular,
Sen Jiang255e22b2016-05-20 16:15:29 -0700356 StringForConnectionType(ConnectionType::kCellular));
357 EXPECT_STREQ("Unknown", StringForConnectionType(ConnectionType::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700358 EXPECT_STREQ("Unknown",
Sen Jiang255e22b2016-05-20 16:15:29 -0700359 StringForConnectionType(static_cast<ConnectionType>(999999)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700360}
361
362TEST_F(ConnectionManagerTest, MalformedServiceList) {
Alex Deymo758dd532015-09-09 15:21:22 -0700363 SetManagerReply("/service/guest/network", false);
Jay Srinivasan43488792012-06-19 00:25:31 -0700364
Sen Jiang255e22b2016-05-20 16:15:29 -0700365 ConnectionType type;
366 ConnectionTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700367 EXPECT_FALSE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700368}
369
370} // namespace chromeos_update_engine