blob: 1867108fc50e099e46ed19a76d30b4fa41959c94 [file] [log] [blame]
Jay Srinivasan43488792012-06-19 00:25:31 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Alex Deymo8427b4a2014-11-05 14:00:32 -08005#include "update_engine/connection_manager.h"
6
Alex Vakulenkod2779df2014-06-16 13:19:00 -07007#include <set>
8#include <string>
9
Jay Srinivasan43488792012-06-19 00:25:31 -070010#include <base/logging.h>
Alex Deymo30534502015-07-20 15:06:33 -070011#include <chromeos/any.h>
Jay Srinivasan43488792012-06-19 00:25:31 -070012#include <chromeos/dbus/service_constants.h>
Alex Deymo30534502015-07-20 15:06:33 -070013#include <chromeos/make_unique_ptr.h>
14#include <chromeos/message_loops/fake_message_loop.h>
15#include <chromeos/variant_dictionary.h>
Alex Deymo5665d0c2014-05-28 17:45:43 -070016#include <gmock/gmock.h>
Jay Srinivasan43488792012-06-19 00:25:31 -070017#include <gtest/gtest.h>
Jay Srinivasan43488792012-06-19 00:25:31 -070018
Alex Deymo30534502015-07-20 15:06:33 -070019#include "update_engine/fake_shill_proxy.h"
Gilad Arnold5bb4c902014-04-10 12:32:13 -070020#include "update_engine/fake_system_state.h"
Alex Deymo5665d0c2014-05-28 17:45:43 -070021#include "update_engine/test_utils.h"
Jay Srinivasan43488792012-06-19 00:25:31 -070022
Alex Deymo30534502015-07-20 15:06:33 -070023using org::chromium::flimflam::ManagerProxyMock;
24using org::chromium::flimflam::ServiceProxyMock;
Jay Srinivasan43488792012-06-19 00:25:31 -070025using std::set;
26using std::string;
Jay Srinivasan43488792012-06-19 00:25:31 -070027using testing::Return;
Alex Deymo30534502015-07-20 15:06:33 -070028using testing::SetArgPointee;
Alex Deymof329b932014-10-30 01:37:48 -070029using testing::_;
Jay Srinivasan43488792012-06-19 00:25:31 -070030
31namespace chromeos_update_engine {
32
33class ConnectionManagerTest : public ::testing::Test {
34 public:
Alex Deymo30534502015-07-20 15:06:33 -070035 void SetUp() override {
36 loop_.SetAsCurrent();
Gilad Arnold5bb4c902014-04-10 12:32:13 -070037 fake_system_state_.set_connection_manager(&cmut_);
Jay Srinivasan43488792012-06-19 00:25:31 -070038 }
39
Alex Deymo30534502015-07-20 15:06:33 -070040 void TearDown() override { EXPECT_FALSE(loop_.PendingTasks()); }
Alex Deymo1c4e6382013-07-15 12:09:51 -070041
Alex Deymo30534502015-07-20 15:06:33 -070042 protected:
43 // Sets the default_service object path in the response from the
44 // ManagerProxyMock instance.
45 void SetManagerReply(const char* default_service, bool reply_succeeds);
46
47 // Sets the |service_type|, |physical_technology| and |service_tethering|
48 // properties in the mocked service |service_path|. If any of the three
49 // const char* is a nullptr, the corresponding property will not be included
50 // in the response.
51 void SetServiceReply(const string& service_path,
52 const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -070053 const char* physical_technology,
54 const char* service_tethering);
Alex Deymo30534502015-07-20 15:06:33 -070055
Jay Srinivasan43488792012-06-19 00:25:31 -070056 void TestWithServiceType(
Alex Deymo1c4e6382013-07-15 12:09:51 -070057 const char* service_type,
58 const char* physical_technology,
59 NetworkConnectionType expected_type);
Alex Deymo6ae91202014-03-10 19:21:25 -070060 void TestWithServiceTethering(
61 const char* service_tethering,
62 NetworkTethering expected_tethering);
Jay Srinivasan43488792012-06-19 00:25:31 -070063
Alex Deymo30534502015-07-20 15:06:33 -070064 chromeos::FakeMessageLoop loop_{nullptr};
Gilad Arnold5bb4c902014-04-10 12:32:13 -070065 FakeSystemState fake_system_state_;
Alex Deymo30534502015-07-20 15:06:33 -070066 FakeShillProxy fake_shill_proxy_;
67
68 // ConnectionManager under test.
69 ConnectionManager cmut_{&fake_shill_proxy_, &fake_system_state_};
Jay Srinivasan43488792012-06-19 00:25:31 -070070};
71
Alex Deymo30534502015-07-20 15:06:33 -070072void ConnectionManagerTest::SetManagerReply(const char* default_service,
73 bool reply_succeeds) {
74 ManagerProxyMock* manager_proxy_mock = fake_shill_proxy_.GetManagerProxy();
75 if (!reply_succeeds) {
76 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
77 .WillOnce(Return(false));
78 return;
79 }
Jay Srinivasan43488792012-06-19 00:25:31 -070080
Alex Deymo30534502015-07-20 15:06:33 -070081 // Create a dictionary of properties and optionally include the default
82 // service.
83 chromeos::VariantDictionary reply_dict;
84 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
Jay Srinivasan43488792012-06-19 00:25:31 -070085
Alex Deymo30534502015-07-20 15:06:33 -070086 if (default_service) {
87 reply_dict[shill::kDefaultServiceProperty] =
88 dbus::ObjectPath(default_service);
89 }
90 EXPECT_CALL(*manager_proxy_mock, GetProperties(_, _, _))
91 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -070092}
93
Alex Deymo30534502015-07-20 15:06:33 -070094void ConnectionManagerTest::SetServiceReply(const string& service_path,
95 const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -070096 const char* physical_technology,
97 const char* service_tethering) {
Alex Deymo30534502015-07-20 15:06:33 -070098 chromeos::VariantDictionary reply_dict;
99 reply_dict["SomeOtherProperty"] = 0xC0FFEE;
100
101 if (service_type)
102 reply_dict[shill::kTypeProperty] = string(service_type);
Jay Srinivasan43488792012-06-19 00:25:31 -0700103
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700104 if (physical_technology) {
Alex Deymo30534502015-07-20 15:06:33 -0700105 reply_dict[shill::kPhysicalTechnologyProperty] =
106 string(physical_technology);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700107 }
108
Alex Deymo30534502015-07-20 15:06:33 -0700109 if (service_tethering)
110 reply_dict[shill::kTetheringProperty] = string(service_tethering);
111
112 std::unique_ptr<ServiceProxyMock> service_proxy_mock(new ServiceProxyMock());
Alex Deymo6ae91202014-03-10 19:21:25 -0700113
Jay Srinivasan43488792012-06-19 00:25:31 -0700114 // Plumb return value into mock object.
Alex Deymo30534502015-07-20 15:06:33 -0700115 EXPECT_CALL(*service_proxy_mock.get(), GetProperties(_, _, _))
116 .WillOnce(DoAll(SetArgPointee<0>(reply_dict), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700117
Alex Deymo30534502015-07-20 15:06:33 -0700118 fake_shill_proxy_.SetServiceForPath(service_path,
119 std::move(service_proxy_mock));
Jay Srinivasan43488792012-06-19 00:25:31 -0700120}
121
122void ConnectionManagerTest::TestWithServiceType(
123 const char* service_type,
Alex Deymo1c4e6382013-07-15 12:09:51 -0700124 const char* physical_technology,
Jay Srinivasan43488792012-06-19 00:25:31 -0700125 NetworkConnectionType expected_type) {
Alex Deymo30534502015-07-20 15:06:33 -0700126 SetManagerReply("/service/guest-network", true);
127 SetServiceReply("/service/guest-network",
128 service_type,
129 physical_technology,
Alex Deymo6ae91202014-03-10 19:21:25 -0700130 shill::kTetheringNotDetectedState);
Jay Srinivasan43488792012-06-19 00:25:31 -0700131
132 NetworkConnectionType type;
Alex Deymo6ae91202014-03-10 19:21:25 -0700133 NetworkTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700134 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700135 EXPECT_EQ(expected_type, type);
Alex Deymo30534502015-07-20 15:06:33 -0700136 testing::Mock::VerifyAndClearExpectations(
137 fake_shill_proxy_.GetManagerProxy());
Jay Srinivasan43488792012-06-19 00:25:31 -0700138}
139
Alex Deymo6ae91202014-03-10 19:21:25 -0700140void ConnectionManagerTest::TestWithServiceTethering(
141 const char* service_tethering,
142 NetworkTethering expected_tethering) {
Alex Deymo30534502015-07-20 15:06:33 -0700143 SetManagerReply("/service/guest-network", true);
144 SetServiceReply(
145 "/service/guest-network", shill::kTypeWifi, nullptr, service_tethering);
Alex Deymo6ae91202014-03-10 19:21:25 -0700146
147 NetworkConnectionType type;
148 NetworkTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700149 EXPECT_TRUE(cmut_.GetConnectionProperties(&type, &tethering));
Alex Deymo6ae91202014-03-10 19:21:25 -0700150 EXPECT_EQ(expected_tethering, tethering);
Alex Deymo30534502015-07-20 15:06:33 -0700151 testing::Mock::VerifyAndClearExpectations(
152 fake_shill_proxy_.GetManagerProxy());
Alex Deymo6ae91202014-03-10 19:21:25 -0700153}
154
Jay Srinivasan43488792012-06-19 00:25:31 -0700155TEST_F(ConnectionManagerTest, SimpleTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700156 TestWithServiceType(shill::kTypeEthernet, nullptr,
157 NetworkConnectionType::kEthernet);
158 TestWithServiceType(shill::kTypeWifi, nullptr,
159 NetworkConnectionType::kWifi);
160 TestWithServiceType(shill::kTypeWimax, nullptr,
161 NetworkConnectionType::kWimax);
162 TestWithServiceType(shill::kTypeBluetooth, nullptr,
163 NetworkConnectionType::kBluetooth);
164 TestWithServiceType(shill::kTypeCellular, nullptr,
165 NetworkConnectionType::kCellular);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700166}
167
168TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700169 TestWithServiceType(shill::kTypeVPN, nullptr,
170 NetworkConnectionType::kUnknown);
171 TestWithServiceType(shill::kTypeVPN, shill::kTypeVPN,
172 NetworkConnectionType::kUnknown);
173 TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi,
174 NetworkConnectionType::kWifi);
175 TestWithServiceType(shill::kTypeVPN, shill::kTypeWimax,
176 NetworkConnectionType::kWimax);
Jay Srinivasan43488792012-06-19 00:25:31 -0700177}
178
Alex Deymo6ae91202014-03-10 19:21:25 -0700179TEST_F(ConnectionManagerTest, TetheringTest) {
180 TestWithServiceTethering(shill::kTetheringConfirmedState,
181 NetworkTethering::kConfirmed);
182 TestWithServiceTethering(shill::kTetheringNotDetectedState,
183 NetworkTethering::kNotDetected);
184 TestWithServiceTethering(shill::kTetheringSuspectedState,
185 NetworkTethering::kSuspected);
186 TestWithServiceTethering("I'm not a valid property value =)",
187 NetworkTethering::kUnknown);
188}
189
Jay Srinivasan43488792012-06-19 00:25:31 -0700190TEST_F(ConnectionManagerTest, UnknownTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700191 TestWithServiceType("foo", nullptr, NetworkConnectionType::kUnknown);
Jay Srinivasan43488792012-06-19 00:25:31 -0700192}
193
194TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) {
Jay Srinivasan43488792012-06-19 00:25:31 -0700195 // Updates over Ethernet are allowed even if there's no policy.
Alex Deymo75eac7e2015-07-29 13:39:14 -0700196 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700197 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700198}
199
200TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700201 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
202 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700203}
204
205TEST_F(ConnectionManagerTest, AllowUpdatesOverWimaxTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700206 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWimax,
Alex Deymo6ae91202014-03-10 19:21:25 -0700207 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700208}
209
210TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700211 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kBluetooth,
Alex Deymo6ae91202014-03-10 19:21:25 -0700212 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700213}
214
215TEST_F(ConnectionManagerTest, AllowUpdatesOnlyOver3GPerPolicyTest) {
216 policy::MockDevicePolicy allow_3g_policy;
217
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700218 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700219
Alex Deymof4867c42013-06-28 14:41:39 -0700220 // This test tests cellular (3G) being the only connection type being allowed.
Jay Srinivasan43488792012-06-19 00:25:31 -0700221 set<string> allowed_set;
Alex Deymo75eac7e2015-07-29 13:39:14 -0700222 allowed_set.insert(
223 cmut_.StringForConnectionType(NetworkConnectionType::kCellular));
Jay Srinivasan43488792012-06-19 00:25:31 -0700224
225 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
226 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700227 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700228
Alex Deymo75eac7e2015-07-29 13:39:14 -0700229 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700230 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700231}
232
233TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) {
234 policy::MockDevicePolicy allow_3g_policy;
235
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700236 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700237
238 // This test tests multiple connection types being allowed, with
Alex Deymof4867c42013-06-28 14:41:39 -0700239 // 3G one among them. Only Cellular is currently enforced by the policy
240 // setting, the others are ignored (see Bluetooth for example).
Jay Srinivasan43488792012-06-19 00:25:31 -0700241 set<string> allowed_set;
Alex Deymo75eac7e2015-07-29 13:39:14 -0700242 allowed_set.insert(
243 cmut_.StringForConnectionType(NetworkConnectionType::kCellular));
244 allowed_set.insert(
245 cmut_.StringForConnectionType(NetworkConnectionType::kBluetooth));
Jay Srinivasan43488792012-06-19 00:25:31 -0700246
247 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymo6ae91202014-03-10 19:21:25 -0700248 .Times(3)
Alex Deymo30534502015-07-20 15:06:33 -0700249 .WillRepeatedly(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700250
Alex Deymo75eac7e2015-07-29 13:39:14 -0700251 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700252 NetworkTethering::kUnknown));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700253 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700254 NetworkTethering::kNotDetected));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700255 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700256 NetworkTethering::kUnknown));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700257 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
258 NetworkTethering::kUnknown));
259 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWimax,
260 NetworkTethering::kUnknown));
261 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kBluetooth,
Alex Deymo6ae91202014-03-10 19:21:25 -0700262 NetworkTethering::kUnknown));
263
264 // Tethered networks are treated in the same way as Cellular networks and
265 // thus allowed.
Alex Deymo75eac7e2015-07-29 13:39:14 -0700266 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kEthernet,
Alex Deymo6ae91202014-03-10 19:21:25 -0700267 NetworkTethering::kConfirmed));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700268 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
Alex Deymo6ae91202014-03-10 19:21:25 -0700269 NetworkTethering::kConfirmed));
Jay Srinivasan43488792012-06-19 00:25:31 -0700270}
271
Alex Deymof4867c42013-06-28 14:41:39 -0700272TEST_F(ConnectionManagerTest, BlockUpdatesOverCellularByDefaultTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700273 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700274 NetworkTethering::kUnknown));
275}
276
277TEST_F(ConnectionManagerTest, BlockUpdatesOverTetheredNetworkByDefaultTest) {
Alex Deymo75eac7e2015-07-29 13:39:14 -0700278 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kWifi,
Alex Deymo6ae91202014-03-10 19:21:25 -0700279 NetworkTethering::kConfirmed));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700280 EXPECT_FALSE(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::kSuspected));
Jay Srinivasan43488792012-06-19 00:25:31 -0700284}
285
286TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) {
287 policy::MockDevicePolicy block_3g_policy;
288
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700289 fake_system_state_.set_device_policy(&block_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700290
291 // Test that updates for 3G are blocked while updates are allowed
292 // over several other types.
293 set<string> allowed_set;
Alex Deymo75eac7e2015-07-29 13:39:14 -0700294 allowed_set.insert(
295 cmut_.StringForConnectionType(NetworkConnectionType::kEthernet));
296 allowed_set.insert(
297 cmut_.StringForConnectionType(NetworkConnectionType::kWifi));
298 allowed_set.insert(
299 cmut_.StringForConnectionType(NetworkConnectionType::kWimax));
Jay Srinivasan43488792012-06-19 00:25:31 -0700300
301 EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_))
302 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700303 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700304
Alex Deymo75eac7e2015-07-29 13:39:14 -0700305 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700306 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700307}
308
309TEST_F(ConnectionManagerTest, BlockUpdatesOver3GIfErrorInPolicyFetchTest) {
310 policy::MockDevicePolicy allow_3g_policy;
311
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700312 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700313
314 set<string> allowed_set;
Alex Deymo75eac7e2015-07-29 13:39:14 -0700315 allowed_set.insert(
316 cmut_.StringForConnectionType(NetworkConnectionType::kCellular));
Jay Srinivasan43488792012-06-19 00:25:31 -0700317
318 // Return false for GetAllowedConnectionTypesForUpdate and see
319 // that updates are still blocked for 3G despite the value being in
320 // the string set above.
321 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
322 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700323 .WillOnce(DoAll(SetArgPointee<0>(allowed_set), Return(false)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700324
Alex Deymo75eac7e2015-07-29 13:39:14 -0700325 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700326 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700327}
328
Alex Deymof4867c42013-06-28 14:41:39 -0700329TEST_F(ConnectionManagerTest, UseUserPrefForUpdatesOverCellularIfNoPolicyTest) {
330 policy::MockDevicePolicy no_policy;
Alex Deymo8427b4a2014-11-05 14:00:32 -0800331 testing::NiceMock<MockPrefs>* prefs = fake_system_state_.mock_prefs();
Alex Deymof4867c42013-06-28 14:41:39 -0700332
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700333 fake_system_state_.set_device_policy(&no_policy);
Alex Deymof4867c42013-06-28 14:41:39 -0700334
335 // No setting enforced by the device policy, user prefs should be used.
336 EXPECT_CALL(no_policy, GetAllowedConnectionTypesForUpdate(_))
337 .Times(3)
338 .WillRepeatedly(Return(false));
339
340 // No user pref: block.
341 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
342 .Times(1)
343 .WillOnce(Return(false));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700344 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700345 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700346
347 // Allow per user pref.
348 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
349 .Times(1)
350 .WillOnce(Return(true));
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700351 EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _))
Alex Deymof4867c42013-06-28 14:41:39 -0700352 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700353 .WillOnce(DoAll(SetArgPointee<1>(true), Return(true)));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700354 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700355 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700356
357 // Block per user pref.
358 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
359 .Times(1)
360 .WillOnce(Return(true));
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700361 EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _))
Alex Deymof4867c42013-06-28 14:41:39 -0700362 .Times(1)
Alex Deymo30534502015-07-20 15:06:33 -0700363 .WillOnce(DoAll(SetArgPointee<1>(false), Return(true)));
Alex Deymo75eac7e2015-07-29 13:39:14 -0700364 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(NetworkConnectionType::kCellular,
Alex Deymo6ae91202014-03-10 19:21:25 -0700365 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700366}
367
Jay Srinivasan43488792012-06-19 00:25:31 -0700368TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700369 EXPECT_STREQ(shill::kTypeEthernet,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700370 cmut_.StringForConnectionType(NetworkConnectionType::kEthernet));
Ben Chanc6007e42013-09-19 23:49:22 -0700371 EXPECT_STREQ(shill::kTypeWifi,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700372 cmut_.StringForConnectionType(NetworkConnectionType::kWifi));
Ben Chanc6007e42013-09-19 23:49:22 -0700373 EXPECT_STREQ(shill::kTypeWimax,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700374 cmut_.StringForConnectionType(NetworkConnectionType::kWimax));
Ben Chanc6007e42013-09-19 23:49:22 -0700375 EXPECT_STREQ(shill::kTypeBluetooth,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700376 cmut_.StringForConnectionType(
377 NetworkConnectionType::kBluetooth));
Ben Chanc6007e42013-09-19 23:49:22 -0700378 EXPECT_STREQ(shill::kTypeCellular,
Alex Deymo75eac7e2015-07-29 13:39:14 -0700379 cmut_.StringForConnectionType(NetworkConnectionType::kCellular));
Jay Srinivasan43488792012-06-19 00:25:31 -0700380 EXPECT_STREQ("Unknown",
Alex Deymo75eac7e2015-07-29 13:39:14 -0700381 cmut_.StringForConnectionType(NetworkConnectionType::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700382 EXPECT_STREQ("Unknown",
383 cmut_.StringForConnectionType(
384 static_cast<NetworkConnectionType>(999999)));
385}
386
387TEST_F(ConnectionManagerTest, MalformedServiceList) {
Alex Deymo30534502015-07-20 15:06:33 -0700388 SetManagerReply("/service/guest-network", false);
Jay Srinivasan43488792012-06-19 00:25:31 -0700389
390 NetworkConnectionType type;
Alex Deymo6ae91202014-03-10 19:21:25 -0700391 NetworkTethering tethering;
Alex Deymo30534502015-07-20 15:06:33 -0700392 EXPECT_FALSE(cmut_.GetConnectionProperties(&type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700393}
394
395} // namespace chromeos_update_engine