blob: 400ee6aadb25dd8a4b9e436e252cc1122d8d4cf3 [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 Deymo30534502015-07-20 15:06:33 -070023#include <chromeos/any.h>
Jay Srinivasan43488792012-06-19 00:25:31 -070024#include <chromeos/dbus/service_constants.h>
Alex Deymo30534502015-07-20 15:06:33 -070025#include <chromeos/make_unique_ptr.h>
26#include <chromeos/message_loops/fake_message_loop.h>
27#include <chromeos/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>
Jay Srinivasan43488792012-06-19 00:25:31 -070030
Alex Deymo30534502015-07-20 15:06:33 -070031#include "update_engine/fake_shill_proxy.h"
Gilad Arnold5bb4c902014-04-10 12:32:13 -070032#include "update_engine/fake_system_state.h"
Alex Deymo5665d0c2014-05-28 17:45:43 -070033#include "update_engine/test_utils.h"
Jay Srinivasan43488792012-06-19 00:25:31 -070034
Alex Deymo30534502015-07-20 15:06:33 -070035using org::chromium::flimflam::ManagerProxyMock;
36using org::chromium::flimflam::ServiceProxyMock;
Jay Srinivasan43488792012-06-19 00:25:31 -070037using std::set;
38using std::string;
Jay Srinivasan43488792012-06-19 00:25:31 -070039using testing::Return;
Alex Deymo30534502015-07-20 15:06:33 -070040using testing::SetArgPointee;
Alex Deymof329b932014-10-30 01:37:48 -070041using testing::_;
Jay Srinivasan43488792012-06-19 00:25:31 -070042
43namespace chromeos_update_engine {
44
45class ConnectionManagerTest : public ::testing::Test {
46 public:
Alex Deymo30534502015-07-20 15:06:33 -070047 void SetUp() override {
48 loop_.SetAsCurrent();
Gilad Arnold5bb4c902014-04-10 12:32:13 -070049 fake_system_state_.set_connection_manager(&cmut_);
Jay Srinivasan43488792012-06-19 00:25:31 -070050 }
51
Alex Deymo30534502015-07-20 15:06:33 -070052 void TearDown() override { EXPECT_FALSE(loop_.PendingTasks()); }
Alex Deymo1c4e6382013-07-15 12:09:51 -070053
Alex Deymo30534502015-07-20 15:06:33 -070054 protected:
55 // Sets the default_service object path in the response from the
56 // ManagerProxyMock instance.
57 void SetManagerReply(const char* default_service, bool reply_succeeds);
58
59 // Sets the |service_type|, |physical_technology| and |service_tethering|
60 // properties in the mocked service |service_path|. If any of the three
61 // const char* is a nullptr, the corresponding property will not be included
62 // in the response.
63 void SetServiceReply(const string& service_path,
64 const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -070065 const char* physical_technology,
66 const char* service_tethering);
Alex Deymo30534502015-07-20 15:06:33 -070067
Jay Srinivasan43488792012-06-19 00:25:31 -070068 void TestWithServiceType(
Alex Deymo1c4e6382013-07-15 12:09:51 -070069 const char* service_type,
70 const char* physical_technology,
71 NetworkConnectionType expected_type);
Alex Deymo6ae91202014-03-10 19:21:25 -070072 void TestWithServiceTethering(
73 const char* service_tethering,
74 NetworkTethering expected_tethering);
Jay Srinivasan43488792012-06-19 00:25:31 -070075
Alex Deymo30534502015-07-20 15:06:33 -070076 chromeos::FakeMessageLoop loop_{nullptr};
Gilad Arnold5bb4c902014-04-10 12:32:13 -070077 FakeSystemState fake_system_state_;
Alex Deymo30534502015-07-20 15:06:33 -070078 FakeShillProxy fake_shill_proxy_;
79
80 // ConnectionManager under test.
81 ConnectionManager cmut_{&fake_shill_proxy_, &fake_system_state_};
Jay Srinivasan43488792012-06-19 00:25:31 -070082};
83
Alex Deymo30534502015-07-20 15:06:33 -070084void ConnectionManagerTest::SetManagerReply(const char* default_service,
85 bool reply_succeeds) {
86 ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_.GetManagerProxy();
87 if (!reply_succeeds) {
88 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
89 .WillOnce(Return(false));
90 return;
91 }
Jay Srinivasan43488792012-06-19 00:25:31 -070092
Alex Deymo30534502015-07-20 15:06:33 -070093 // Create a dictionary of properties and optionally include the default
94 // service.
95 chromeos::VariantDictionary reply_dict;
96 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
Jay Srinivasan43488792012-06-19 00:25:31 -070097
Alex Deymo30534502015-07-20 15:06:33 -070098 if (default_service) {
99 reply_dict[shill::kDefaultServiceProperty] =
100 dbus::ObjectPath(default_service);
101 }
102 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
103 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700104}
105
Alex Deymo30534502015-07-20 15:06:33 -0700106void ConnectionManagerTest::SetServiceReply(const string& service_path,
107 const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -0700108 const char* physical_technology,
109 const char* service_tethering) {
Alex Deymo30534502015-07-20 15:06:33 -0700110 chromeos::VariantDictionary reply_dict;
111 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
112
113 if (service_type)
114 reply_dict[shill::kTypeProperty] = string(service_type);
Jay Srinivasan43488792012-06-19 00:25:31 -0700115
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700116 if (physical_technology) {
Alex Deymo30534502015-07-20 15:06:33 -0700117 reply_dict[shill::kPhysicalTechnologyProperty] =
118 string(physical_technology);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700119 }
120
Alex Deymo30534502015-07-20 15:06:33 -0700121 if (service_tethering)
122 reply_dict[shill::kTetheringProperty] = string(service_tethering);
123
124 std::unique_ptr<ServiceProxyMock> service_proxy_mock(new ServiceProxyMock());
Alex Deymo6ae91202014-03-10 19:21:25 -0700125
Jay Srinivasan43488792012-06-19 00:25:31 -0700126 // Plumb return value into mock object.
Alex Deymo30534502015-07-20 15:06:33 -0700127 EXPECT_CALL(*service_proxy_mock.get(), GetProperties(_, _, _))
128 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700129
Alex Deymo30534502015-07-20 15:06:33 -0700130 fake_shill_proxy_.SetServiceForPath(service_path,
131 std::move(service_proxy_mock));
Jay Srinivasan43488792012-06-19 00:25:31 -0700132}
133
134void ConnectionManagerTest::TestWithServiceType(
135 const char* service_type,
Alex Deymo1c4e6382013-07-15 12:09:51 -0700136 const char* physical_technology,
Jay Srinivasan43488792012-06-19 00:25:31 -0700137 NetworkConnectionType expected_type) {
Alex Deymo30534502015-07-20 15:06:33 -0700138 SetManagerReply("/service/guest-network", true);
139 SetServiceReply("/service/guest-network",
140 service_type,
141 physical_technology,
Alex Deymo6ae91202014-03-10 19:21:25 -0700142 shill::kTetheringNotDetectedState);
Jay Srinivasan43488792012-06-19 00:25:31 -0700143
144 NetworkConnectionType type;
Alex Deymo6ae91202014-03-10 19:21:25 -0700145 NetworkTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700146 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700147 EXPECT_EQ(expected_type, type);
Alex Deymo30534502015-07-20 15:06:33 -0700148 testing::Mock::VerifyAndClearExpectations(
149 fake_shill_proxy_.GetManagerProxy());
Jay Srinivasan43488792012-06-19 00:25:31 -0700150}
151
Alex Deymo6ae91202014-03-10 19:21:25 -0700152void ConnectionManagerTest::TestWithServiceTethering(
153 const char* service_tethering,
154 NetworkTethering expected_tethering) {
Alex Deymo30534502015-07-20 15:06:33 -0700155 SetManagerReply("/service/guest-network", true);
156 SetServiceReply(
157 "/service/guest-network", shill::kTypeWifi, nullptr, service_tethering);
Alex Deymo6ae91202014-03-10 19:21:25 -0700158
159 NetworkConnectionType type;
160 NetworkTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700161 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Alex Deymo6ae91202014-03-10 19:21:25 -0700162 EXPECT_EQ(expected_tethering, tethering);
Alex Deymo30534502015-07-20 15:06:33 -0700163 testing::Mock::VerifyAndClearExpectations(
164 fake_shill_proxy_.GetManagerProxy());
Alex Deymo6ae91202014-03-10 19:21:25 -0700165}
166
Jay Srinivasan43488792012-06-19 00:25:31 -0700167TEST_F(ConnectionManagerTest, SimpleTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700168 TestWithServiceType(shill::kTypeEthernet, nullptr,
169 NetworkConnectionType::kEthernet);
170 TestWithServiceType(shill::kTypeWifi, nullptr,
171 NetworkConnectionType::kWifi);
172 TestWithServiceType(shill::kTypeWimax, nullptr,
173 NetworkConnectionType::kWimax);
174 TestWithServiceType(shill::kTypeBluetooth, nullptr,
175 NetworkConnectionType::kBluetooth);
176 TestWithServiceType(shill::kTypeCellular, nullptr,
177 NetworkConnectionType::kCellular);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700178}
179
180TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700181 TestWithServiceType(shill::kTypeVPN, nullptr,
182 NetworkConnectionType::kUnknown);
183 TestWithServiceType(shill::kTypeVPN, shill::kTypeVPN,
184 NetworkConnectionType::kUnknown);
185 TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi,
186 NetworkConnectionType::kWifi);
187 TestWithServiceType(shill::kTypeVPN, shill::kTypeWimax,
188 NetworkConnectionType::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,
193 NetworkTethering::kConfirmed);
194 TestWithServiceTethering(shill::kTetheringNotDetectedState,
195 NetworkTethering::kNotDetected);
196 TestWithServiceTethering(shill::kTetheringSuspectedState,
197 NetworkTethering::kSuspected);
198 TestWithServiceTethering("I'm not a valid property value =)",
199 NetworkTethering::kUnknown);
200}
201
Jay Srinivasan43488792012-06-19 00:25:31 -0700202TEST_F(ConnectionManagerTest, UnknownTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700203 TestWithServiceType("foo", nullptr, NetworkConnectionType::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.
Alex Deymo75eac7e2015-07-29 13:39:14 -0700208 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700209 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700210}
211
212TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700213 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
214 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700215}
216
217TEST_F(ConnectionManagerTest, AllowUpdatesOverWimaxTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700218 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWimax,
Alex Deymo6ae91202014-03-10 19:21:25 -0700219 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700220}
221
222TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700223 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kBluetooth,
Alex Deymo6ae91202014-03-10 19:21:25 -0700224 NetworkTethering::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;
Alex Deymo75eac7e2015-07-29 13:39:14 -0700234 allowed_set.insert(
235 cmut_.StringForConnectionType(NetworkConnectionType::kCellular));
Jay Srinivasan43488792012-06-19 00:25:31 -0700236
237 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
238 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700239 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700240
Alex Deymo75eac7e2015-07-29 13:39:14 -0700241 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700242 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700243}
244
245TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) {
246 policy::MockDevicePolicy allow_3g_policy;
247
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700248 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700249
250 // This test tests multiple connection types being allowed, with
Alex Deymof4867c42013-06-28 14:41:39 -0700251 // 3G one among them. Only Cellular is currently enforced by the policy
252 // setting, the others are ignored (see Bluetooth for example).
Jay Srinivasan43488792012-06-19 00:25:31 -0700253 set<string> allowed_set;
Alex Deymo75eac7e2015-07-29 13:39:14 -0700254 allowed_set.insert(
255 cmut_.StringForConnectionType(NetworkConnectionType::kCellular));
256 allowed_set.insert(
257 cmut_.StringForConnectionType(NetworkConnectionType::kBluetooth));
Jay Srinivasan43488792012-06-19 00:25:31 -0700258
259 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymo6ae91202014-03-10 19:21:25 -0700260 .Times(3)
Alex Deymo30534502015-07-20 15:06:33 -0700261 .WillRepeatedly(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700262
Alex Deymo75eac7e2015-07-29 13:39:14 -0700263 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700264 NetworkTethering::kUnknown));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700265 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700266 NetworkTethering::kNotDetected));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700267 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700268 NetworkTethering::kUnknown));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700269 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
270 NetworkTethering::kUnknown));
271 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWimax,
272 NetworkTethering::kUnknown));
273 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kBluetooth,
Alex Deymo6ae91202014-03-10 19:21:25 -0700274 NetworkTethering::kUnknown));
275
276 // Tethered networks are treated in the same way as Cellular networks and
277 // thus allowed.
Alex Deymo75eac7e2015-07-29 13:39:14 -0700278 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700279 NetworkTethering::kConfirmed));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700280 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
Alex Deymo6ae91202014-03-10 19:21:25 -0700281 NetworkTethering::kConfirmed));
Jay Srinivasan43488792012-06-19 00:25:31 -0700282}
283
Alex Deymof4867c42013-06-28 14:41:39 -0700284TEST_F(ConnectionManagerTest, BlockUpdatesOverCellularByDefaultTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700285 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700286 NetworkTethering::kUnknown));
287}
288
289TEST_F(ConnectionManagerTest, BlockUpdatesOverTetheredNetworkByDefaultTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700290 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
Alex Deymo6ae91202014-03-10 19:21:25 -0700291 NetworkTethering::kConfirmed));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700292 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700293 NetworkTethering::kConfirmed));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700294 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
Alex Deymo6ae91202014-03-10 19:21:25 -0700295 NetworkTethering::kSuspected));
Jay Srinivasan43488792012-06-19 00:25:31 -0700296}
297
298TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) {
299 policy::MockDevicePolicy block_3g_policy;
300
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700301 fake_system_state_.set_device_policy(&block_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700302
303 // Test that updates for 3G are blocked while updates are allowed
304 // over several other types.
305 set<string> allowed_set;
Alex Deymo75eac7e2015-07-29 13:39:14 -0700306 allowed_set.insert(
307 cmut_.StringForConnectionType(NetworkConnectionType::kEthernet));
308 allowed_set.insert(
309 cmut_.StringForConnectionType(NetworkConnectionType::kWifi));
310 allowed_set.insert(
311 cmut_.StringForConnectionType(NetworkConnectionType::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
Alex Deymo75eac7e2015-07-29 13:39:14 -0700317 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700318 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700319}
320
321TEST_F(ConnectionManagerTest, BlockUpdatesOver3GIfErrorInPolicyFetchTest) {
322 policy::MockDevicePolicy allow_3g_policy;
323
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700324 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700325
326 set<string> allowed_set;
Alex Deymo75eac7e2015-07-29 13:39:14 -0700327 allowed_set.insert(
328 cmut_.StringForConnectionType(NetworkConnectionType::kCellular));
Jay Srinivasan43488792012-06-19 00:25:31 -0700329
330 // Return false for GetAllowedConnectionTypesForUpdate and see
331 // that updates are still blocked for 3G despite the value being in
332 // the string set above.
333 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
334 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700335 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(false)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700336
Alex Deymo75eac7e2015-07-29 13:39:14 -0700337 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700338 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700339}
340
Alex Deymof4867c42013-06-28 14:41:39 -0700341TEST_F(ConnectionManagerTest, UseUserPrefForUpdatesOverCellularIfNoPolicyTest) {
342 policy::MockDevicePolicy no_policy;
Alex Deymo8427b4a2014-11-05 14:00:32 -0800343 testing::NiceMock<MockPrefs>* prefs = fake_system_state_.mock_prefs();
Alex Deymof4867c42013-06-28 14:41:39 -0700344
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700345 fake_system_state_.set_device_policy(&no_policy);
Alex Deymof4867c42013-06-28 14:41:39 -0700346
347 // No setting enforced by the device policy, user prefs should be used.
348 EXPECT_CALL(no_policy, GetAllowedConnectionTypesForUpdate(_))
349 .Times(3)
350 .WillRepeatedly(Return(false));
351
352 // No user pref: block.
353 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
354 .Times(1)
355 .WillOnce(Return(false));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700356 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700357 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700358
359 // Allow per user pref.
360 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
361 .Times(1)
362 .WillOnce(Return(true));
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700363 EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _))
Alex Deymof4867c42013-06-28 14:41:39 -0700364 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700365 .WillOnce(DoAll(SetArgPointee<1>(true), Return(true)));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700366 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700367 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700368
369 // Block per user pref.
370 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
371 .Times(1)
372 .WillOnce(Return(true));
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700373 EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _))
Alex Deymof4867c42013-06-28 14:41:39 -0700374 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700375 .WillOnce(DoAll(SetArgPointee<1>(false), Return(true)));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700376 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700377 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700378}
379
Jay Srinivasan43488792012-06-19 00:25:31 -0700380TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700381 EXPECT_STREQ(shill::kTypeEthernet,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700382 cmut_.StringForConnectionType(NetworkConnectionType::kEthernet));
Ben Chanc6007e42013-09-19 23:49:22 -0700383 EXPECT_STREQ(shill::kTypeWifi,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700384 cmut_.StringForConnectionType(NetworkConnectionType::kWifi));
Ben Chanc6007e42013-09-19 23:49:22 -0700385 EXPECT_STREQ(shill::kTypeWimax,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700386 cmut_.StringForConnectionType(NetworkConnectionType::kWimax));
Ben Chanc6007e42013-09-19 23:49:22 -0700387 EXPECT_STREQ(shill::kTypeBluetooth,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700388 cmut_.StringForConnectionType(
389 NetworkConnectionType::kBluetooth));
Ben Chanc6007e42013-09-19 23:49:22 -0700390 EXPECT_STREQ(shill::kTypeCellular,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700391 cmut_.StringForConnectionType(NetworkConnectionType::kCellular));
Jay Srinivasan43488792012-06-19 00:25:31 -0700392 EXPECT_STREQ("Unknown",
Alex Deymo75eac7e2015-07-29 13:39:14 -0700393 cmut_.StringForConnectionType(NetworkConnectionType::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700394 EXPECT_STREQ("Unknown",
395 cmut_.StringForConnectionType(
396 static_cast<NetworkConnectionType>(999999)));
397}
398
399TEST_F(ConnectionManagerTest, MalformedServiceList) {
Alex Deymo30534502015-07-20 15:06:33 -0700400 SetManagerReply("/service/guest-network", false);
Jay Srinivasan43488792012-06-19 00:25:31 -0700401
402 NetworkConnectionType type;
Alex Deymo6ae91202014-03-10 19:21:25 -0700403 NetworkTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700404 EXPECT_FALSE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700405}
406
407} // namespace chromeos_update_engine