blob: c495fbfb727d33e791f0b83ad20868258dfff8ed [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
5#include <base/logging.h>
6#include <chromeos/dbus/service_constants.h>
Alex Deymo5665d0c2014-05-28 17:45:43 -07007#include <gmock/gmock.h>
Jay Srinivasan43488792012-06-19 00:25:31 -07008#include <gtest/gtest.h>
9#include <string>
10
11#include "update_engine/connection_manager.h"
Gilad Arnold5bb4c902014-04-10 12:32:13 -070012#include "update_engine/fake_system_state.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080013#include "update_engine/mock_dbus_wrapper.h"
Alex Deymo5665d0c2014-05-28 17:45:43 -070014#include "update_engine/test_utils.h"
Jay Srinivasan43488792012-06-19 00:25:31 -070015
16using std::set;
17using std::string;
18using testing::_;
19using testing::AnyNumber;
20using testing::Return;
21using testing::SetArgumentPointee;
22using testing::StrEq;
23
24namespace chromeos_update_engine {
25
26class ConnectionManagerTest : public ::testing::Test {
27 public:
28 ConnectionManagerTest()
29 : kMockFlimFlamManagerProxy_(NULL),
30 kMockFlimFlamServiceProxy_(NULL),
31 kServicePath_(NULL),
Gilad Arnold5bb4c902014-04-10 12:32:13 -070032 cmut_(&fake_system_state_) {
33 fake_system_state_.set_connection_manager(&cmut_);
Jay Srinivasan43488792012-06-19 00:25:31 -070034 }
35
36 protected:
37 void SetupMocks(const char* service_path);
Alex Deymo5665d0c2014-05-28 17:45:43 -070038 void SetManagerReply(const char* reply_value, const GType& reply_type);
Alex Deymo1c4e6382013-07-15 12:09:51 -070039
40 // Sets the |service_type| Type and the |physical_technology|
41 // PhysicalTechnology properties in the mocked service. If a NULL
42 // |physical_technology| is passed, the property is not set (not present).
43 void SetServiceReply(const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -070044 const char* physical_technology,
45 const char* service_tethering);
Jay Srinivasan43488792012-06-19 00:25:31 -070046 void TestWithServiceType(
Alex Deymo1c4e6382013-07-15 12:09:51 -070047 const char* service_type,
48 const char* physical_technology,
49 NetworkConnectionType expected_type);
Alex Deymo6ae91202014-03-10 19:21:25 -070050 void TestWithServiceTethering(
51 const char* service_tethering,
52 NetworkTethering expected_tethering);
Jay Srinivasan43488792012-06-19 00:25:31 -070053
54 static const char* kGetPropertiesMethod;
55 DBusGProxy* kMockFlimFlamManagerProxy_;
56 DBusGProxy* kMockFlimFlamServiceProxy_;
57 DBusGConnection* kMockSystemBus_;
58 const char* kServicePath_;
Alex Deymo5665d0c2014-05-28 17:45:43 -070059 testing::StrictMock<MockDBusWrapper> dbus_iface_;
Jay Srinivasan43488792012-06-19 00:25:31 -070060 ConnectionManager cmut_; // ConnectionManager under test.
Gilad Arnold5bb4c902014-04-10 12:32:13 -070061 FakeSystemState fake_system_state_;
Jay Srinivasan43488792012-06-19 00:25:31 -070062};
63
64// static
65const char* ConnectionManagerTest::kGetPropertiesMethod = "GetProperties";
66
67void ConnectionManagerTest::SetupMocks(const char* service_path) {
68 int number = 1;
69 kMockSystemBus_ = reinterpret_cast<DBusGConnection*>(number++);
70 kMockFlimFlamManagerProxy_ = reinterpret_cast<DBusGProxy*>(number++);
71 kMockFlimFlamServiceProxy_ = reinterpret_cast<DBusGProxy*>(number++);
72 ASSERT_NE(kMockSystemBus_, reinterpret_cast<DBusGConnection*>(NULL));
73
74 kServicePath_ = service_path;
75
76 ON_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _))
77 .WillByDefault(Return(kMockSystemBus_));
78 EXPECT_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _))
79 .Times(AnyNumber());
80}
81
Alex Deymo5665d0c2014-05-28 17:45:43 -070082void ConnectionManagerTest::SetManagerReply(const char *reply_value,
Jay Srinivasan43488792012-06-19 00:25:31 -070083 const GType& reply_type) {
Alex Deymo5665d0c2014-05-28 17:45:43 -070084 ASSERT_TRUE(dbus_g_type_is_collection(reply_type));
Jay Srinivasan43488792012-06-19 00:25:31 -070085
Alex Deymo5665d0c2014-05-28 17:45:43 -070086 // Create the GPtrArray array holding the |reply_value| pointer. The
87 // |reply_value| string is duplicated because it should be mutable on the
88 // interface and is because dbus-glib collections will g_free() each element
89 // of the GPtrArray automatically when the |array_as_value| GValue is unset.
90 // The g_strdup() is not being leaked.
91 GPtrArray* array = g_ptr_array_new();
Jay Srinivasan43488792012-06-19 00:25:31 -070092 ASSERT_TRUE(array != NULL);
Alex Deymo5665d0c2014-05-28 17:45:43 -070093 g_ptr_array_add(array, g_strdup(reply_value));
Jay Srinivasan43488792012-06-19 00:25:31 -070094
Jay Srinivasan43488792012-06-19 00:25:31 -070095 GValue* array_as_value = g_new0(GValue, 1);
96 EXPECT_EQ(array_as_value, g_value_init(array_as_value, reply_type));
97 g_value_take_boxed(array_as_value, array);
Alex Deymo5665d0c2014-05-28 17:45:43 -070098
99 // Initialize return value for D-Bus call to Manager object, which is a
100 // hash table of static strings (char*) in GValue* containing a single array.
101 GHashTable* manager_hash_table = g_hash_table_new_full(
102 g_str_hash, g_str_equal,
103 nullptr, // no key_destroy_func because keys are static.
104 GValueFree); // value_destroy_func
Jay Srinivasan43488792012-06-19 00:25:31 -0700105 g_hash_table_insert(manager_hash_table,
106 const_cast<char*>("Services"),
107 array_as_value);
108
109 // Plumb return value into mock object.
Gilad Arnoldb752fb32014-03-03 12:23:39 -0800110 EXPECT_CALL(dbus_iface_, ProxyCall_0_1(kMockFlimFlamManagerProxy_,
111 StrEq(kGetPropertiesMethod),
112 _, _))
113 .WillOnce(DoAll(SetArgumentPointee<3>(manager_hash_table), Return(TRUE)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700114
115 // Set other expectations.
116 EXPECT_CALL(dbus_iface_,
Gilad Arnoldb752fb32014-03-03 12:23:39 -0800117 ProxyNewForName(kMockSystemBus_,
118 StrEq(shill::kFlimflamServiceName),
119 StrEq(shill::kFlimflamServicePath),
120 StrEq(shill::kFlimflamManagerInterface)))
Jay Srinivasan43488792012-06-19 00:25:31 -0700121 .WillOnce(Return(kMockFlimFlamManagerProxy_));
122 EXPECT_CALL(dbus_iface_, ProxyUnref(kMockFlimFlamManagerProxy_));
123 EXPECT_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _))
124 .RetiresOnSaturation();
125}
126
Alex Deymo1c4e6382013-07-15 12:09:51 -0700127void ConnectionManagerTest::SetServiceReply(const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -0700128 const char* physical_technology,
129 const char* service_tethering) {
Alex Deymo5665d0c2014-05-28 17:45:43 -0700130 // Initialize return value for D-Bus call to Service object, which is a
131 // hash table of static strings (char*) in GValue*.
132 GHashTable* service_hash_table = g_hash_table_new_full(
133 g_str_hash, g_str_equal,
134 nullptr, // no key_destroy_func because keys are static.
135 GValueFree); // value_destroy_func
136 GValue* service_type_value = GValueNewString(service_type);
Jay Srinivasan43488792012-06-19 00:25:31 -0700137 g_hash_table_insert(service_hash_table,
138 const_cast<char*>("Type"),
139 service_type_value);
140
Alex Deymo1c4e6382013-07-15 12:09:51 -0700141 if (physical_technology != NULL) {
Alex Deymo5665d0c2014-05-28 17:45:43 -0700142 GValue* physical_technology_value = GValueNewString(physical_technology);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700143 g_hash_table_insert(service_hash_table,
144 const_cast<char*>("PhysicalTechnology"),
145 physical_technology_value);
146 }
147
Alex Deymo6ae91202014-03-10 19:21:25 -0700148 if (service_tethering != NULL) {
Alex Deymo5665d0c2014-05-28 17:45:43 -0700149 GValue* service_tethering_value = GValueNewString(service_tethering);
Alex Deymo6ae91202014-03-10 19:21:25 -0700150 g_hash_table_insert(service_hash_table,
151 const_cast<char*>("Tethering"),
152 service_tethering_value);
153 }
154
Jay Srinivasan43488792012-06-19 00:25:31 -0700155 // Plumb return value into mock object.
Gilad Arnoldb752fb32014-03-03 12:23:39 -0800156 EXPECT_CALL(dbus_iface_, ProxyCall_0_1(kMockFlimFlamServiceProxy_,
157 StrEq(kGetPropertiesMethod),
158 _, _))
159 .WillOnce(DoAll(SetArgumentPointee<3>(service_hash_table), Return(TRUE)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700160
161 // Set other expectations.
162 EXPECT_CALL(dbus_iface_,
Gilad Arnoldb752fb32014-03-03 12:23:39 -0800163 ProxyNewForName(kMockSystemBus_,
164 StrEq(shill::kFlimflamServiceName),
165 StrEq(kServicePath_),
166 StrEq(shill::kFlimflamServiceInterface)))
Jay Srinivasan43488792012-06-19 00:25:31 -0700167 .WillOnce(Return(kMockFlimFlamServiceProxy_));
168 EXPECT_CALL(dbus_iface_, ProxyUnref(kMockFlimFlamServiceProxy_));
169 EXPECT_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _))
170 .RetiresOnSaturation();
171}
172
173void ConnectionManagerTest::TestWithServiceType(
174 const char* service_type,
Alex Deymo1c4e6382013-07-15 12:09:51 -0700175 const char* physical_technology,
Jay Srinivasan43488792012-06-19 00:25:31 -0700176 NetworkConnectionType expected_type) {
177
178 SetupMocks("/service/guest-network");
179 SetManagerReply(kServicePath_, DBUS_TYPE_G_OBJECT_PATH_ARRAY);
Alex Deymo6ae91202014-03-10 19:21:25 -0700180 SetServiceReply(service_type, physical_technology,
181 shill::kTetheringNotDetectedState);
Jay Srinivasan43488792012-06-19 00:25:31 -0700182
183 NetworkConnectionType type;
Alex Deymo6ae91202014-03-10 19:21:25 -0700184 NetworkTethering tethering;
185 EXPECT_TRUE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700186 EXPECT_EQ(expected_type, type);
Alex Deymo5665d0c2014-05-28 17:45:43 -0700187 testing::Mock::VerifyAndClearExpectations(&dbus_iface_);
Jay Srinivasan43488792012-06-19 00:25:31 -0700188}
189
Alex Deymo6ae91202014-03-10 19:21:25 -0700190void ConnectionManagerTest::TestWithServiceTethering(
191 const char* service_tethering,
192 NetworkTethering expected_tethering) {
193
194 SetupMocks("/service/guest-network");
195 SetManagerReply(kServicePath_, DBUS_TYPE_G_OBJECT_PATH_ARRAY);
196 SetServiceReply(shill::kTypeWifi, NULL, service_tethering);
197
198 NetworkConnectionType type;
199 NetworkTethering tethering;
200 EXPECT_TRUE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering));
201 EXPECT_EQ(expected_tethering, tethering);
202}
203
Jay Srinivasan43488792012-06-19 00:25:31 -0700204TEST_F(ConnectionManagerTest, SimpleTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700205 TestWithServiceType(shill::kTypeEthernet, NULL, kNetEthernet);
206 TestWithServiceType(shill::kTypeWifi, NULL, kNetWifi);
207 TestWithServiceType(shill::kTypeWimax, NULL, kNetWimax);
208 TestWithServiceType(shill::kTypeBluetooth, NULL, kNetBluetooth);
209 TestWithServiceType(shill::kTypeCellular, NULL, kNetCellular);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700210}
211
212TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700213 TestWithServiceType(shill::kTypeVPN, NULL, kNetUnknown);
214 TestWithServiceType(shill::kTypeVPN, shill::kTypeVPN, kNetUnknown);
215 TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi, kNetWifi);
216 TestWithServiceType(shill::kTypeVPN, shill::kTypeWimax, kNetWimax);
Jay Srinivasan43488792012-06-19 00:25:31 -0700217}
218
Alex Deymo6ae91202014-03-10 19:21:25 -0700219TEST_F(ConnectionManagerTest, TetheringTest) {
220 TestWithServiceTethering(shill::kTetheringConfirmedState,
221 NetworkTethering::kConfirmed);
222 TestWithServiceTethering(shill::kTetheringNotDetectedState,
223 NetworkTethering::kNotDetected);
224 TestWithServiceTethering(shill::kTetheringSuspectedState,
225 NetworkTethering::kSuspected);
226 TestWithServiceTethering("I'm not a valid property value =)",
227 NetworkTethering::kUnknown);
228}
229
Jay Srinivasan43488792012-06-19 00:25:31 -0700230TEST_F(ConnectionManagerTest, UnknownTest) {
Alex Deymo1c4e6382013-07-15 12:09:51 -0700231 TestWithServiceType("foo", NULL, kNetUnknown);
Jay Srinivasan43488792012-06-19 00:25:31 -0700232}
233
234TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) {
Jay Srinivasan43488792012-06-19 00:25:31 -0700235 // Updates over Ethernet are allowed even if there's no policy.
Alex Deymo6ae91202014-03-10 19:21:25 -0700236 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet,
237 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700238}
239
240TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) {
Alex Deymo6ae91202014-03-10 19:21:25 -0700241 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700242}
243
244TEST_F(ConnectionManagerTest, AllowUpdatesOverWimaxTest) {
Alex Deymo6ae91202014-03-10 19:21:25 -0700245 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWimax,
246 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700247}
248
249TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) {
Alex Deymo6ae91202014-03-10 19:21:25 -0700250 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetBluetooth,
251 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700252}
253
254TEST_F(ConnectionManagerTest, AllowUpdatesOnlyOver3GPerPolicyTest) {
255 policy::MockDevicePolicy allow_3g_policy;
256
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700257 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700258
Alex Deymof4867c42013-06-28 14:41:39 -0700259 // This test tests cellular (3G) being the only connection type being allowed.
Jay Srinivasan43488792012-06-19 00:25:31 -0700260 set<string> allowed_set;
261 allowed_set.insert(cmut_.StringForConnectionType(kNetCellular));
262
263 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
264 .Times(1)
265 .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(true)));
266
Alex Deymo6ae91202014-03-10 19:21:25 -0700267 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular,
268 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700269}
270
271TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) {
272 policy::MockDevicePolicy allow_3g_policy;
273
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700274 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700275
276 // This test tests multiple connection types being allowed, with
Alex Deymof4867c42013-06-28 14:41:39 -0700277 // 3G one among them. Only Cellular is currently enforced by the policy
278 // setting, the others are ignored (see Bluetooth for example).
Jay Srinivasan43488792012-06-19 00:25:31 -0700279 set<string> allowed_set;
Jay Srinivasan43488792012-06-19 00:25:31 -0700280 allowed_set.insert(cmut_.StringForConnectionType(kNetCellular));
Alex Deymof4867c42013-06-28 14:41:39 -0700281 allowed_set.insert(cmut_.StringForConnectionType(kNetBluetooth));
Jay Srinivasan43488792012-06-19 00:25:31 -0700282
283 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymo6ae91202014-03-10 19:21:25 -0700284 .Times(3)
285 .WillRepeatedly(DoAll(SetArgumentPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700286
Alex Deymo6ae91202014-03-10 19:21:25 -0700287 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet,
288 NetworkTethering::kUnknown));
289 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet,
290 NetworkTethering::kNotDetected));
291 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular,
292 NetworkTethering::kUnknown));
293 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, NetworkTethering::kUnknown));
294 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWimax, NetworkTethering::kUnknown));
295 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetBluetooth,
296 NetworkTethering::kUnknown));
297
298 // Tethered networks are treated in the same way as Cellular networks and
299 // thus allowed.
300 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet,
301 NetworkTethering::kConfirmed));
302 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi,
303 NetworkTethering::kConfirmed));
Jay Srinivasan43488792012-06-19 00:25:31 -0700304}
305
Alex Deymof4867c42013-06-28 14:41:39 -0700306TEST_F(ConnectionManagerTest, BlockUpdatesOverCellularByDefaultTest) {
Alex Deymo6ae91202014-03-10 19:21:25 -0700307 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
308 NetworkTethering::kUnknown));
309}
310
311TEST_F(ConnectionManagerTest, BlockUpdatesOverTetheredNetworkByDefaultTest) {
Alex Deymo6ae91202014-03-10 19:21:25 -0700312 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetWifi,
313 NetworkTethering::kConfirmed));
314 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetEthernet,
315 NetworkTethering::kConfirmed));
316 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi,
317 NetworkTethering::kSuspected));
Jay Srinivasan43488792012-06-19 00:25:31 -0700318}
319
320TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) {
321 policy::MockDevicePolicy block_3g_policy;
322
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700323 fake_system_state_.set_device_policy(&block_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700324
325 // Test that updates for 3G are blocked while updates are allowed
326 // over several other types.
327 set<string> allowed_set;
328 allowed_set.insert(cmut_.StringForConnectionType(kNetEthernet));
329 allowed_set.insert(cmut_.StringForConnectionType(kNetWifi));
330 allowed_set.insert(cmut_.StringForConnectionType(kNetWimax));
331
332 EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_))
333 .Times(1)
334 .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(true)));
335
Alex Deymo6ae91202014-03-10 19:21:25 -0700336 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
337 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700338}
339
340TEST_F(ConnectionManagerTest, BlockUpdatesOver3GIfErrorInPolicyFetchTest) {
341 policy::MockDevicePolicy allow_3g_policy;
342
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700343 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700344
345 set<string> allowed_set;
346 allowed_set.insert(cmut_.StringForConnectionType(kNetCellular));
347
348 // Return false for GetAllowedConnectionTypesForUpdate and see
349 // that updates are still blocked for 3G despite the value being in
350 // the string set above.
351 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
352 .Times(1)
353 .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(false)));
354
Alex Deymo6ae91202014-03-10 19:21:25 -0700355 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
356 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700357}
358
Alex Deymof4867c42013-06-28 14:41:39 -0700359TEST_F(ConnectionManagerTest, UseUserPrefForUpdatesOverCellularIfNoPolicyTest) {
360 policy::MockDevicePolicy no_policy;
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700361 testing::NiceMock<PrefsMock>* prefs = fake_system_state_.mock_prefs();
Alex Deymof4867c42013-06-28 14:41:39 -0700362
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700363 fake_system_state_.set_device_policy(&no_policy);
Alex Deymof4867c42013-06-28 14:41:39 -0700364
365 // No setting enforced by the device policy, user prefs should be used.
366 EXPECT_CALL(no_policy, GetAllowedConnectionTypesForUpdate(_))
367 .Times(3)
368 .WillRepeatedly(Return(false));
369
370 // No user pref: block.
371 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
372 .Times(1)
373 .WillOnce(Return(false));
Alex Deymo6ae91202014-03-10 19:21:25 -0700374 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
375 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700376
377 // Allow per user pref.
378 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
379 .Times(1)
380 .WillOnce(Return(true));
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700381 EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _))
Alex Deymof4867c42013-06-28 14:41:39 -0700382 .Times(1)
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700383 .WillOnce(DoAll(SetArgumentPointee<1>(true), Return(true)));
Alex Deymo6ae91202014-03-10 19:21:25 -0700384 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular,
385 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700386
387 // Block per user pref.
388 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
389 .Times(1)
390 .WillOnce(Return(true));
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700391 EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _))
Alex Deymof4867c42013-06-28 14:41:39 -0700392 .Times(1)
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700393 .WillOnce(DoAll(SetArgumentPointee<1>(false), Return(true)));
Alex Deymo6ae91202014-03-10 19:21:25 -0700394 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
395 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700396}
397
Jay Srinivasan43488792012-06-19 00:25:31 -0700398TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700399 EXPECT_STREQ(shill::kTypeEthernet,
Jay Srinivasan43488792012-06-19 00:25:31 -0700400 cmut_.StringForConnectionType(kNetEthernet));
Ben Chanc6007e42013-09-19 23:49:22 -0700401 EXPECT_STREQ(shill::kTypeWifi,
Jay Srinivasan43488792012-06-19 00:25:31 -0700402 cmut_.StringForConnectionType(kNetWifi));
Ben Chanc6007e42013-09-19 23:49:22 -0700403 EXPECT_STREQ(shill::kTypeWimax,
Jay Srinivasan43488792012-06-19 00:25:31 -0700404 cmut_.StringForConnectionType(kNetWimax));
Ben Chanc6007e42013-09-19 23:49:22 -0700405 EXPECT_STREQ(shill::kTypeBluetooth,
Jay Srinivasan43488792012-06-19 00:25:31 -0700406 cmut_.StringForConnectionType(kNetBluetooth));
Ben Chanc6007e42013-09-19 23:49:22 -0700407 EXPECT_STREQ(shill::kTypeCellular,
Jay Srinivasan43488792012-06-19 00:25:31 -0700408 cmut_.StringForConnectionType(kNetCellular));
409 EXPECT_STREQ("Unknown",
410 cmut_.StringForConnectionType(kNetUnknown));
411 EXPECT_STREQ("Unknown",
412 cmut_.StringForConnectionType(
413 static_cast<NetworkConnectionType>(999999)));
414}
415
416TEST_F(ConnectionManagerTest, MalformedServiceList) {
417 SetupMocks("/service/guest-network");
Alex Deymo5665d0c2014-05-28 17:45:43 -0700418 SetManagerReply(kServicePath_, DBUS_TYPE_G_STRING_ARRAY);
Jay Srinivasan43488792012-06-19 00:25:31 -0700419
420 NetworkConnectionType type;
Alex Deymo6ae91202014-03-10 19:21:25 -0700421 NetworkTethering tethering;
422 EXPECT_FALSE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700423}
424
425} // namespace chromeos_update_engine