blob: 7cd858d46651183d42aef85dfc31822235600f4c [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);
Colin Howesc9e98d62018-09-18 10:35:20 -070078
79 void TestWithServiceDisconnected(ConnectionType expected_type);
80
Alex Deymo6ae91202014-03-10 19:21:25 -070081 void TestWithServiceTethering(
82 const char* service_tethering,
Sen Jiang255e22b2016-05-20 16:15:29 -070083 ConnectionTethering expected_tethering);
Jay Srinivasan43488792012-06-19 00:25:31 -070084
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070085 brillo::FakeMessageLoop loop_{nullptr};
Gilad Arnold5bb4c902014-04-10 12:32:13 -070086 FakeSystemState fake_system_state_;
Sen Jiangf5bebae2016-06-03 15:36:54 -070087 FakeShillProxy* fake_shill_proxy_;
Alex Deymo30534502015-07-20 15:06:33 -070088
89 // ConnectionManager under test.
Sen Jiangf5bebae2016-06-03 15:36:54 -070090 ConnectionManager cmut_{fake_shill_proxy_, &fake_system_state_};
Jay Srinivasan43488792012-06-19 00:25:31 -070091};
92
Alex Deymo30534502015-07-20 15:06:33 -070093void ConnectionManagerTest::SetManagerReply(const char* default_service,
94 bool reply_succeeds) {
Sen Jiangf5bebae2016-06-03 15:36:54 -070095 ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_->GetManagerProxy();
Alex Deymo30534502015-07-20 15:06:33 -070096 if (!reply_succeeds) {
97 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
98 .WillOnce(Return(false));
99 return;
100 }
Jay Srinivasan43488792012-06-19 00:25:31 -0700101
Alex Deymo30534502015-07-20 15:06:33 -0700102 // Create a dictionary of properties and optionally include the default
103 // service.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700104 brillo::VariantDictionary reply_dict;
Alex Deymo30534502015-07-20 15:06:33 -0700105 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
Jay Srinivasan43488792012-06-19 00:25:31 -0700106
Alex Deymo30534502015-07-20 15:06:33 -0700107 if (default_service) {
108 reply_dict[shill::kDefaultServiceProperty] =
109 dbus::ObjectPath(default_service);
110 }
111 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
112 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700113}
114
Alex Deymo30534502015-07-20 15:06:33 -0700115void ConnectionManagerTest::SetServiceReply(const string& service_path,
116 const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -0700117 const char* physical_technology,
118 const char* service_tethering) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700119 brillo::VariantDictionary reply_dict;
Alex Deymo30534502015-07-20 15:06:33 -0700120 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
121
122 if (service_type)
123 reply_dict[shill::kTypeProperty] = string(service_type);
Jay Srinivasan43488792012-06-19 00:25:31 -0700124
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700125 if (physical_technology) {
Alex Deymo30534502015-07-20 15:06:33 -0700126 reply_dict[shill::kPhysicalTechnologyProperty] =
127 string(physical_technology);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700128 }
129
Alex Deymo30534502015-07-20 15:06:33 -0700130 if (service_tethering)
131 reply_dict[shill::kTetheringProperty] = string(service_tethering);
132
133 std::unique_ptr<ServiceProxyMock> service_proxy_mock(new ServiceProxyMock());
Alex Deymo6ae91202014-03-10 19:21:25 -0700134
Jay Srinivasan43488792012-06-19 00:25:31 -0700135 // Plumb return value into mock object.
Alex Deymo30534502015-07-20 15:06:33 -0700136 EXPECT_CALL(*service_proxy_mock.get(), GetProperties(_, _, _))
137 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700138
Sen Jiangf5bebae2016-06-03 15:36:54 -0700139 fake_shill_proxy_->SetServiceForPath(dbus::ObjectPath(service_path),
140 std::move(service_proxy_mock));
Jay Srinivasan43488792012-06-19 00:25:31 -0700141}
142
143void ConnectionManagerTest::TestWithServiceType(
144 const char* service_type,
Alex Deymo1c4e6382013-07-15 12:09:51 -0700145 const char* physical_technology,
Sen Jiang255e22b2016-05-20 16:15:29 -0700146 ConnectionType expected_type) {
Alex Deymo758dd532015-09-09 15:21:22 -0700147 SetManagerReply("/service/guest/network", true);
148 SetServiceReply("/service/guest/network",
Alex Deymo30534502015-07-20 15:06:33 -0700149 service_type,
150 physical_technology,
Alex Deymo6ae91202014-03-10 19:21:25 -0700151 shill::kTetheringNotDetectedState);
Jay Srinivasan43488792012-06-19 00:25:31 -0700152
Sen Jiang255e22b2016-05-20 16:15:29 -0700153 ConnectionType type;
154 ConnectionTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700155 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700156 EXPECT_EQ(expected_type, type);
Alex Deymo30534502015-07-20 15:06:33 -0700157 testing::Mock::VerifyAndClearExpectations(
Sen Jiangf5bebae2016-06-03 15:36:54 -0700158 fake_shill_proxy_->GetManagerProxy());
Jay Srinivasan43488792012-06-19 00:25:31 -0700159}
160
Alex Deymo6ae91202014-03-10 19:21:25 -0700161void ConnectionManagerTest::TestWithServiceTethering(
162 const char* service_tethering,
Sen Jiang255e22b2016-05-20 16:15:29 -0700163 ConnectionTethering expected_tethering) {
Alex Deymo758dd532015-09-09 15:21:22 -0700164 SetManagerReply("/service/guest/network", true);
Alex Deymo30534502015-07-20 15:06:33 -0700165 SetServiceReply(
Alex Deymo758dd532015-09-09 15:21:22 -0700166 "/service/guest/network", shill::kTypeWifi, nullptr, service_tethering);
Alex Deymo6ae91202014-03-10 19:21:25 -0700167
Sen Jiang255e22b2016-05-20 16:15:29 -0700168 ConnectionType type;
169 ConnectionTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700170 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Alex Deymo6ae91202014-03-10 19:21:25 -0700171 EXPECT_EQ(expected_tethering, tethering);
Alex Deymo30534502015-07-20 15:06:33 -0700172 testing::Mock::VerifyAndClearExpectations(
Sen Jiangf5bebae2016-06-03 15:36:54 -0700173 fake_shill_proxy_->GetManagerProxy());
Alex Deymo6ae91202014-03-10 19:21:25 -0700174}
175
Colin Howesc9e98d62018-09-18 10:35:20 -0700176void ConnectionManagerTest::TestWithServiceDisconnected(
177 ConnectionType expected_type) {
178 SetManagerReply("/", true);
179
180 ConnectionType type;
181 ConnectionTethering tethering;
182 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
183 EXPECT_EQ(expected_type, type);
184 testing::Mock::VerifyAndClearExpectations(
185 fake_shill_proxy_->GetManagerProxy());
186}
187
Jay Srinivasan43488792012-06-19 00:25:31 -0700188TEST_F(ConnectionManagerTest, SimpleTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700189 TestWithServiceType(shill::kTypeEthernet, nullptr, ConnectionType::kEthernet);
190 TestWithServiceType(shill::kTypeWifi, nullptr, ConnectionType::kWifi);
191 TestWithServiceType(shill::kTypeWimax, nullptr, ConnectionType::kWimax);
192 TestWithServiceType(
193 shill::kTypeBluetooth, nullptr, ConnectionType::kBluetooth);
194 TestWithServiceType(shill::kTypeCellular, nullptr, ConnectionType::kCellular);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700195}
196
197TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700198 TestWithServiceType(shill::kTypeVPN, nullptr, ConnectionType::kUnknown);
199 TestWithServiceType(
200 shill::kTypeVPN, shill::kTypeVPN, ConnectionType::kUnknown);
201 TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi, ConnectionType::kWifi);
202 TestWithServiceType(
203 shill::kTypeVPN, shill::kTypeWimax, ConnectionType::kWimax);
Jay Srinivasan43488792012-06-19 00:25:31 -0700204}
205
Alex Deymo6ae91202014-03-10 19:21:25 -0700206TEST_F(ConnectionManagerTest, TetheringTest) {
207 TestWithServiceTethering(shill::kTetheringConfirmedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700208 ConnectionTethering::kConfirmed);
Alex Deymo6ae91202014-03-10 19:21:25 -0700209 TestWithServiceTethering(shill::kTetheringNotDetectedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700210 ConnectionTethering::kNotDetected);
Alex Deymo6ae91202014-03-10 19:21:25 -0700211 TestWithServiceTethering(shill::kTetheringSuspectedState,
Sen Jiang255e22b2016-05-20 16:15:29 -0700212 ConnectionTethering::kSuspected);
Alex Deymo6ae91202014-03-10 19:21:25 -0700213 TestWithServiceTethering("I'm not a valid property value =)",
Sen Jiang255e22b2016-05-20 16:15:29 -0700214 ConnectionTethering::kUnknown);
Alex Deymo6ae91202014-03-10 19:21:25 -0700215}
216
Jay Srinivasan43488792012-06-19 00:25:31 -0700217TEST_F(ConnectionManagerTest, UnknownTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700218 TestWithServiceType("foo", nullptr, ConnectionType::kUnknown);
Jay Srinivasan43488792012-06-19 00:25:31 -0700219}
220
Colin Howesc9e98d62018-09-18 10:35:20 -0700221TEST_F(ConnectionManagerTest, DisconnectTest) {
222 TestWithServiceDisconnected(ConnectionType::kDisconnected);
223}
224
Jay Srinivasan43488792012-06-19 00:25:31 -0700225TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) {
Jay Srinivasan43488792012-06-19 00:25:31 -0700226 // Updates over Ethernet are allowed even if there's no policy.
Sen Jiang255e22b2016-05-20 16:15:29 -0700227 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
228 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700229}
230
231TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700232 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
233 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700234}
235
236TEST_F(ConnectionManagerTest, AllowUpdatesOverWimaxTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700237 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWimax,
238 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700239}
240
241TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) {
Sen Jiang255e22b2016-05-20 16:15:29 -0700242 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kBluetooth,
243 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700244}
245
246TEST_F(ConnectionManagerTest, AllowUpdatesOnlyOver3GPerPolicyTest) {
247 policy::MockDevicePolicy allow_3g_policy;
248
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700249 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700250
Alex Deymof4867c42013-06-28 14:41:39 -0700251 // This test tests cellular (3G) being the only connection type being allowed.
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(_))
256 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700257 .WillOnce(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::kCellular,
260 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700261}
262
263TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) {
264 policy::MockDevicePolicy allow_3g_policy;
265
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700266 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700267
268 // This test tests multiple connection types being allowed, with
Alex Deymof4867c42013-06-28 14:41:39 -0700269 // 3G one among them. Only Cellular is currently enforced by the policy
270 // setting, the others are ignored (see Bluetooth for example).
Jay Srinivasan43488792012-06-19 00:25:31 -0700271 set<string> allowed_set;
Sen Jiang255e22b2016-05-20 16:15:29 -0700272 allowed_set.insert(StringForConnectionType(ConnectionType::kCellular));
273 allowed_set.insert(StringForConnectionType(ConnectionType::kBluetooth));
Jay Srinivasan43488792012-06-19 00:25:31 -0700274
275 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymo6ae91202014-03-10 19:21:25 -0700276 .Times(3)
Alex Deymo30534502015-07-20 15:06:33 -0700277 .WillRepeatedly(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700278
Sen Jiang255e22b2016-05-20 16:15:29 -0700279 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
280 ConnectionTethering::kUnknown));
281 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
282 ConnectionTethering::kNotDetected));
283 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
284 ConnectionTethering::kUnknown));
285 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
286 ConnectionTethering::kUnknown));
287 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWimax,
288 ConnectionTethering::kUnknown));
289 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kBluetooth,
290 ConnectionTethering::kUnknown));
Alex Deymo6ae91202014-03-10 19:21:25 -0700291
292 // Tethered networks are treated in the same way as Cellular networks and
293 // thus allowed.
Sen Jiang255e22b2016-05-20 16:15:29 -0700294 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
295 ConnectionTethering::kConfirmed));
296 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
297 ConnectionTethering::kConfirmed));
Jay Srinivasan43488792012-06-19 00:25:31 -0700298}
299
Weidong Guo421ff332017-04-17 10:08:38 -0700300TEST_F(ConnectionManagerTest, AllowUpdatesOverCellularByDefaultTest) {
301 policy::MockDevicePolicy device_policy;
302 // Set an empty device policy.
303 fake_system_state_.set_device_policy(&device_policy);
304
305 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
306 ConnectionTethering::kUnknown));
Alex Deymo6ae91202014-03-10 19:21:25 -0700307}
308
Weidong Guo421ff332017-04-17 10:08:38 -0700309TEST_F(ConnectionManagerTest, AllowUpdatesOverTetheredNetworkByDefaultTest) {
310 policy::MockDevicePolicy device_policy;
311 // Set an empty device policy.
312 fake_system_state_.set_device_policy(&device_policy);
313
314 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
315 ConnectionTethering::kConfirmed));
316 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kEthernet,
317 ConnectionTethering::kConfirmed));
Sen Jiang255e22b2016-05-20 16:15:29 -0700318 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kWifi,
319 ConnectionTethering::kSuspected));
Jay Srinivasan43488792012-06-19 00:25:31 -0700320}
321
322TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) {
323 policy::MockDevicePolicy block_3g_policy;
324
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700325 fake_system_state_.set_device_policy(&block_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700326
327 // Test that updates for 3G are blocked while updates are allowed
328 // over several other types.
329 set<string> allowed_set;
Sen Jiang255e22b2016-05-20 16:15:29 -0700330 allowed_set.insert(StringForConnectionType(ConnectionType::kEthernet));
331 allowed_set.insert(StringForConnectionType(ConnectionType::kWifi));
332 allowed_set.insert(StringForConnectionType(ConnectionType::kWimax));
Jay Srinivasan43488792012-06-19 00:25:31 -0700333
334 EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_))
335 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700336 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700337
Sen Jiang255e22b2016-05-20 16:15:29 -0700338 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
339 ConnectionTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700340}
341
Weidong Guo421ff332017-04-17 10:08:38 -0700342TEST_F(ConnectionManagerTest, AllowUpdatesOver3GIfPolicyIsNotSet) {
343 policy::MockDevicePolicy device_policy;
Jay Srinivasan43488792012-06-19 00:25:31 -0700344
Weidong Guo421ff332017-04-17 10:08:38 -0700345 fake_system_state_.set_device_policy(&device_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700346
347 // Return false for GetAllowedConnectionTypesForUpdate and see
Weidong Guo421ff332017-04-17 10:08:38 -0700348 // that updates are allowed as device policy is not set. Further
349 // check is left to |OmahaRequestAction|.
350 EXPECT_CALL(device_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymof4867c42013-06-28 14:41:39 -0700351 .Times(1)
352 .WillOnce(Return(false));
Alex Deymof4867c42013-06-28 14:41:39 -0700353
Sen Jiang255e22b2016-05-20 16:15:29 -0700354 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
355 ConnectionTethering::kUnknown));
Weidong Guo421ff332017-04-17 10:08:38 -0700356}
Tao Bao5688d162017-06-06 13:09:06 -0700357
Weidong Guo421ff332017-04-17 10:08:38 -0700358TEST_F(ConnectionManagerTest, AllowUpdatesOverCellularIfPolicyFailsToBeLoaded) {
359 fake_system_state_.set_device_policy(nullptr);
360
361 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(ConnectionType::kCellular,
362 ConnectionTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700363}
364
Jay Srinivasan43488792012-06-19 00:25:31 -0700365TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700366 EXPECT_STREQ(shill::kTypeEthernet,
Sen Jiang255e22b2016-05-20 16:15:29 -0700367 StringForConnectionType(ConnectionType::kEthernet));
Ben Chanc6007e42013-09-19 23:49:22 -0700368 EXPECT_STREQ(shill::kTypeWifi,
Sen Jiang255e22b2016-05-20 16:15:29 -0700369 StringForConnectionType(ConnectionType::kWifi));
Ben Chanc6007e42013-09-19 23:49:22 -0700370 EXPECT_STREQ(shill::kTypeWimax,
Sen Jiang255e22b2016-05-20 16:15:29 -0700371 StringForConnectionType(ConnectionType::kWimax));
Ben Chanc6007e42013-09-19 23:49:22 -0700372 EXPECT_STREQ(shill::kTypeBluetooth,
Sen Jiang255e22b2016-05-20 16:15:29 -0700373 StringForConnectionType(ConnectionType::kBluetooth));
Ben Chanc6007e42013-09-19 23:49:22 -0700374 EXPECT_STREQ(shill::kTypeCellular,
Sen Jiang255e22b2016-05-20 16:15:29 -0700375 StringForConnectionType(ConnectionType::kCellular));
376 EXPECT_STREQ("Unknown", StringForConnectionType(ConnectionType::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700377 EXPECT_STREQ("Unknown",
Sen Jiang255e22b2016-05-20 16:15:29 -0700378 StringForConnectionType(static_cast<ConnectionType>(999999)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700379}
380
381TEST_F(ConnectionManagerTest, MalformedServiceList) {
Alex Deymo758dd532015-09-09 15:21:22 -0700382 SetManagerReply("/service/guest/network", false);
Jay Srinivasan43488792012-06-19 00:25:31 -0700383
Sen Jiang255e22b2016-05-20 16:15:29 -0700384 ConnectionType type;
385 ConnectionTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700386 EXPECT_FALSE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700387}
388
389} // namespace chromeos_update_engine