blob: 3dc065ed195a94bc068b3548797297a06394da50 [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>
7#include <gtest/gtest.h>
8#include <string>
9
10#include "update_engine/connection_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080011#include "update_engine/mock_dbus_wrapper.h"
Jay Srinivasan43488792012-06-19 00:25:31 -070012#include "update_engine/mock_system_state.h"
13
14using std::set;
15using std::string;
16using testing::_;
17using testing::AnyNumber;
18using testing::Return;
19using testing::SetArgumentPointee;
20using testing::StrEq;
21
22namespace chromeos_update_engine {
23
24class ConnectionManagerTest : public ::testing::Test {
25 public:
26 ConnectionManagerTest()
27 : kMockFlimFlamManagerProxy_(NULL),
28 kMockFlimFlamServiceProxy_(NULL),
29 kServicePath_(NULL),
30 cmut_(&mock_system_state_) {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080031 mock_system_state_.set_connection_manager(&cmut_);
Jay Srinivasan43488792012-06-19 00:25:31 -070032 }
33
34 protected:
35 void SetupMocks(const char* service_path);
36 void SetManagerReply(gconstpointer value, const GType& type);
Alex Deymo1c4e6382013-07-15 12:09:51 -070037
38 // Sets the |service_type| Type and the |physical_technology|
39 // PhysicalTechnology properties in the mocked service. If a NULL
40 // |physical_technology| is passed, the property is not set (not present).
41 void SetServiceReply(const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -070042 const char* physical_technology,
43 const char* service_tethering);
Jay Srinivasan43488792012-06-19 00:25:31 -070044 void TestWithServiceType(
Alex Deymo1c4e6382013-07-15 12:09:51 -070045 const char* service_type,
46 const char* physical_technology,
47 NetworkConnectionType expected_type);
Alex Deymo6ae91202014-03-10 19:21:25 -070048 void TestWithServiceTethering(
49 const char* service_tethering,
50 NetworkTethering expected_tethering);
Jay Srinivasan43488792012-06-19 00:25:31 -070051
52 static const char* kGetPropertiesMethod;
53 DBusGProxy* kMockFlimFlamManagerProxy_;
54 DBusGProxy* kMockFlimFlamServiceProxy_;
55 DBusGConnection* kMockSystemBus_;
56 const char* kServicePath_;
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080057 MockDBusWrapper dbus_iface_;
Jay Srinivasan43488792012-06-19 00:25:31 -070058 ConnectionManager cmut_; // ConnectionManager under test.
59 MockSystemState mock_system_state_;
60};
61
62// static
63const char* ConnectionManagerTest::kGetPropertiesMethod = "GetProperties";
64
65void ConnectionManagerTest::SetupMocks(const char* service_path) {
66 int number = 1;
67 kMockSystemBus_ = reinterpret_cast<DBusGConnection*>(number++);
68 kMockFlimFlamManagerProxy_ = reinterpret_cast<DBusGProxy*>(number++);
69 kMockFlimFlamServiceProxy_ = reinterpret_cast<DBusGProxy*>(number++);
70 ASSERT_NE(kMockSystemBus_, reinterpret_cast<DBusGConnection*>(NULL));
71
72 kServicePath_ = service_path;
73
74 ON_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _))
75 .WillByDefault(Return(kMockSystemBus_));
76 EXPECT_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _))
77 .Times(AnyNumber());
78}
79
80void ConnectionManagerTest::SetManagerReply(gconstpointer reply_value,
81 const GType& reply_type) {
82 // Initialize return value for D-Bus call to Manager object.
83 // TODO (jaysri): Free the objects allocated here.
84 GHashTable* manager_hash_table = g_hash_table_new(g_str_hash, g_str_equal);
85
86 GArray* array = g_array_new(FALSE, FALSE, sizeof(const char*));
87 ASSERT_TRUE(array != NULL);
88
89 EXPECT_EQ(array, g_array_append_val(array, reply_value));
90 GValue* array_as_value = g_new0(GValue, 1);
91 EXPECT_EQ(array_as_value, g_value_init(array_as_value, reply_type));
92 g_value_take_boxed(array_as_value, array);
93 g_hash_table_insert(manager_hash_table,
94 const_cast<char*>("Services"),
95 array_as_value);
96
97 // Plumb return value into mock object.
Gilad Arnoldb752fb32014-03-03 12:23:39 -080098 EXPECT_CALL(dbus_iface_, ProxyCall_0_1(kMockFlimFlamManagerProxy_,
99 StrEq(kGetPropertiesMethod),
100 _, _))
101 .WillOnce(DoAll(SetArgumentPointee<3>(manager_hash_table), Return(TRUE)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700102
103 // Set other expectations.
104 EXPECT_CALL(dbus_iface_,
Gilad Arnoldb752fb32014-03-03 12:23:39 -0800105 ProxyNewForName(kMockSystemBus_,
106 StrEq(shill::kFlimflamServiceName),
107 StrEq(shill::kFlimflamServicePath),
108 StrEq(shill::kFlimflamManagerInterface)))
Jay Srinivasan43488792012-06-19 00:25:31 -0700109 .WillOnce(Return(kMockFlimFlamManagerProxy_));
110 EXPECT_CALL(dbus_iface_, ProxyUnref(kMockFlimFlamManagerProxy_));
111 EXPECT_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _))
112 .RetiresOnSaturation();
113}
114
Alex Deymo1c4e6382013-07-15 12:09:51 -0700115void ConnectionManagerTest::SetServiceReply(const char* service_type,
Alex Deymo6ae91202014-03-10 19:21:25 -0700116 const char* physical_technology,
117 const char* service_tethering) {
Jay Srinivasan43488792012-06-19 00:25:31 -0700118 // Initialize return value for D-Bus call to Service object.
119 // TODO (jaysri): Free the objects allocated here.
120 GHashTable* service_hash_table = g_hash_table_new(g_str_hash, g_str_equal);
121
122 GValue* service_type_value = g_new0(GValue, 1);
123 EXPECT_EQ(service_type_value,
124 g_value_init(service_type_value, G_TYPE_STRING));
125 g_value_set_static_string(service_type_value, service_type);
126
127 g_hash_table_insert(service_hash_table,
128 const_cast<char*>("Type"),
129 service_type_value);
130
Alex Deymo1c4e6382013-07-15 12:09:51 -0700131 if (physical_technology != NULL) {
132 GValue* physical_technology_value = g_new0(GValue, 1);
133 EXPECT_EQ(physical_technology_value,
134 g_value_init(physical_technology_value, G_TYPE_STRING));
135 g_value_set_static_string(physical_technology_value, physical_technology);
136
137 g_hash_table_insert(service_hash_table,
138 const_cast<char*>("PhysicalTechnology"),
139 physical_technology_value);
140 }
141
Alex Deymo6ae91202014-03-10 19:21:25 -0700142 if (service_tethering != NULL) {
143 GValue* service_tethering_value = g_new0(GValue, 1);
144 EXPECT_EQ(service_tethering_value,
145 g_value_init(service_tethering_value, G_TYPE_STRING));
146 g_value_set_static_string(service_tethering_value, service_tethering);
147
148 g_hash_table_insert(service_hash_table,
149 const_cast<char*>("Tethering"),
150 service_tethering_value);
151 }
152
Jay Srinivasan43488792012-06-19 00:25:31 -0700153 // Plumb return value into mock object.
Gilad Arnoldb752fb32014-03-03 12:23:39 -0800154 EXPECT_CALL(dbus_iface_, ProxyCall_0_1(kMockFlimFlamServiceProxy_,
155 StrEq(kGetPropertiesMethod),
156 _, _))
157 .WillOnce(DoAll(SetArgumentPointee<3>(service_hash_table), Return(TRUE)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700158
159 // Set other expectations.
160 EXPECT_CALL(dbus_iface_,
Gilad Arnoldb752fb32014-03-03 12:23:39 -0800161 ProxyNewForName(kMockSystemBus_,
162 StrEq(shill::kFlimflamServiceName),
163 StrEq(kServicePath_),
164 StrEq(shill::kFlimflamServiceInterface)))
Jay Srinivasan43488792012-06-19 00:25:31 -0700165 .WillOnce(Return(kMockFlimFlamServiceProxy_));
166 EXPECT_CALL(dbus_iface_, ProxyUnref(kMockFlimFlamServiceProxy_));
167 EXPECT_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _))
168 .RetiresOnSaturation();
169}
170
171void ConnectionManagerTest::TestWithServiceType(
172 const char* service_type,
Alex Deymo1c4e6382013-07-15 12:09:51 -0700173 const char* physical_technology,
Jay Srinivasan43488792012-06-19 00:25:31 -0700174 NetworkConnectionType expected_type) {
175
176 SetupMocks("/service/guest-network");
177 SetManagerReply(kServicePath_, DBUS_TYPE_G_OBJECT_PATH_ARRAY);
Alex Deymo6ae91202014-03-10 19:21:25 -0700178 SetServiceReply(service_type, physical_technology,
179 shill::kTetheringNotDetectedState);
Jay Srinivasan43488792012-06-19 00:25:31 -0700180
181 NetworkConnectionType type;
Alex Deymo6ae91202014-03-10 19:21:25 -0700182 NetworkTethering tethering;
183 EXPECT_TRUE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700184 EXPECT_EQ(expected_type, type);
185}
186
Alex Deymo6ae91202014-03-10 19:21:25 -0700187void ConnectionManagerTest::TestWithServiceTethering(
188 const char* service_tethering,
189 NetworkTethering expected_tethering) {
190
191 SetupMocks("/service/guest-network");
192 SetManagerReply(kServicePath_, DBUS_TYPE_G_OBJECT_PATH_ARRAY);
193 SetServiceReply(shill::kTypeWifi, NULL, service_tethering);
194
195 NetworkConnectionType type;
196 NetworkTethering tethering;
197 EXPECT_TRUE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering));
198 EXPECT_EQ(expected_tethering, tethering);
199}
200
Jay Srinivasan43488792012-06-19 00:25:31 -0700201TEST_F(ConnectionManagerTest, SimpleTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700202 TestWithServiceType(shill::kTypeEthernet, NULL, kNetEthernet);
203 TestWithServiceType(shill::kTypeWifi, NULL, kNetWifi);
204 TestWithServiceType(shill::kTypeWimax, NULL, kNetWimax);
205 TestWithServiceType(shill::kTypeBluetooth, NULL, kNetBluetooth);
206 TestWithServiceType(shill::kTypeCellular, NULL, kNetCellular);
Alex Deymo1c4e6382013-07-15 12:09:51 -0700207}
208
209TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700210 TestWithServiceType(shill::kTypeVPN, NULL, kNetUnknown);
211 TestWithServiceType(shill::kTypeVPN, shill::kTypeVPN, kNetUnknown);
212 TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi, kNetWifi);
213 TestWithServiceType(shill::kTypeVPN, shill::kTypeWimax, kNetWimax);
Jay Srinivasan43488792012-06-19 00:25:31 -0700214}
215
Alex Deymo6ae91202014-03-10 19:21:25 -0700216TEST_F(ConnectionManagerTest, TetheringTest) {
217 TestWithServiceTethering(shill::kTetheringConfirmedState,
218 NetworkTethering::kConfirmed);
219 TestWithServiceTethering(shill::kTetheringNotDetectedState,
220 NetworkTethering::kNotDetected);
221 TestWithServiceTethering(shill::kTetheringSuspectedState,
222 NetworkTethering::kSuspected);
223 TestWithServiceTethering("I'm not a valid property value =)",
224 NetworkTethering::kUnknown);
225}
226
Jay Srinivasan43488792012-06-19 00:25:31 -0700227TEST_F(ConnectionManagerTest, UnknownTest) {
Alex Deymo1c4e6382013-07-15 12:09:51 -0700228 TestWithServiceType("foo", NULL, kNetUnknown);
Jay Srinivasan43488792012-06-19 00:25:31 -0700229}
230
231TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800232 EXPECT_CALL(mock_system_state_, device_policy()).Times(0);
Jay Srinivasan43488792012-06-19 00:25:31 -0700233
234 // Updates over Ethernet are allowed even if there's no policy.
Alex Deymo6ae91202014-03-10 19:21:25 -0700235 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet,
236 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700237}
238
239TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800240 EXPECT_CALL(mock_system_state_, device_policy()).Times(0);
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) {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800245 EXPECT_CALL(mock_system_state_, device_policy()).Times(0);
Alex Deymo6ae91202014-03-10 19:21:25 -0700246 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWimax,
247 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700248}
249
250TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800251 EXPECT_CALL(mock_system_state_, device_policy()).Times(0);
Alex Deymo6ae91202014-03-10 19:21:25 -0700252 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetBluetooth,
253 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700254}
255
256TEST_F(ConnectionManagerTest, AllowUpdatesOnlyOver3GPerPolicyTest) {
257 policy::MockDevicePolicy allow_3g_policy;
258
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800259 EXPECT_CALL(mock_system_state_, device_policy())
Jay Srinivasan43488792012-06-19 00:25:31 -0700260 .Times(1)
261 .WillOnce(Return(&allow_3g_policy));
262
Alex Deymof4867c42013-06-28 14:41:39 -0700263 // This test tests cellular (3G) being the only connection type being allowed.
Jay Srinivasan43488792012-06-19 00:25:31 -0700264 set<string> allowed_set;
265 allowed_set.insert(cmut_.StringForConnectionType(kNetCellular));
266
267 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
268 .Times(1)
269 .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(true)));
270
Alex Deymo6ae91202014-03-10 19:21:25 -0700271 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular,
272 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700273}
274
275TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) {
276 policy::MockDevicePolicy allow_3g_policy;
277
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800278 EXPECT_CALL(mock_system_state_, device_policy())
Alex Deymo6ae91202014-03-10 19:21:25 -0700279 .Times(3)
280 .WillRepeatedly(Return(&allow_3g_policy));
Jay Srinivasan43488792012-06-19 00:25:31 -0700281
282 // This test tests multiple connection types being allowed, with
Alex Deymof4867c42013-06-28 14:41:39 -0700283 // 3G one among them. Only Cellular is currently enforced by the policy
284 // setting, the others are ignored (see Bluetooth for example).
Jay Srinivasan43488792012-06-19 00:25:31 -0700285 set<string> allowed_set;
Jay Srinivasan43488792012-06-19 00:25:31 -0700286 allowed_set.insert(cmut_.StringForConnectionType(kNetCellular));
Alex Deymof4867c42013-06-28 14:41:39 -0700287 allowed_set.insert(cmut_.StringForConnectionType(kNetBluetooth));
Jay Srinivasan43488792012-06-19 00:25:31 -0700288
289 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymo6ae91202014-03-10 19:21:25 -0700290 .Times(3)
291 .WillRepeatedly(DoAll(SetArgumentPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700292
Alex Deymo6ae91202014-03-10 19:21:25 -0700293 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet,
294 NetworkTethering::kUnknown));
295 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet,
296 NetworkTethering::kNotDetected));
297 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular,
298 NetworkTethering::kUnknown));
299 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, NetworkTethering::kUnknown));
300 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWimax, NetworkTethering::kUnknown));
301 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetBluetooth,
302 NetworkTethering::kUnknown));
303
304 // Tethered networks are treated in the same way as Cellular networks and
305 // thus allowed.
306 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet,
307 NetworkTethering::kConfirmed));
308 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi,
309 NetworkTethering::kConfirmed));
Jay Srinivasan43488792012-06-19 00:25:31 -0700310}
311
Alex Deymof4867c42013-06-28 14:41:39 -0700312TEST_F(ConnectionManagerTest, BlockUpdatesOverCellularByDefaultTest) {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800313 EXPECT_CALL(mock_system_state_, device_policy()).Times(1);
Alex Deymo6ae91202014-03-10 19:21:25 -0700314 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
315 NetworkTethering::kUnknown));
316}
317
318TEST_F(ConnectionManagerTest, BlockUpdatesOverTetheredNetworkByDefaultTest) {
319 EXPECT_CALL(mock_system_state_, device_policy()).Times(2);
320 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetWifi,
321 NetworkTethering::kConfirmed));
322 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetEthernet,
323 NetworkTethering::kConfirmed));
324 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi,
325 NetworkTethering::kSuspected));
Jay Srinivasan43488792012-06-19 00:25:31 -0700326}
327
328TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) {
329 policy::MockDevicePolicy block_3g_policy;
330
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800331 EXPECT_CALL(mock_system_state_, device_policy())
Jay Srinivasan43488792012-06-19 00:25:31 -0700332 .Times(1)
333 .WillOnce(Return(&block_3g_policy));
334
335 // Test that updates for 3G are blocked while updates are allowed
336 // over several other types.
337 set<string> allowed_set;
338 allowed_set.insert(cmut_.StringForConnectionType(kNetEthernet));
339 allowed_set.insert(cmut_.StringForConnectionType(kNetWifi));
340 allowed_set.insert(cmut_.StringForConnectionType(kNetWimax));
341
342 EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_))
343 .Times(1)
344 .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(true)));
345
Alex Deymo6ae91202014-03-10 19:21:25 -0700346 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
347 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700348}
349
350TEST_F(ConnectionManagerTest, BlockUpdatesOver3GIfErrorInPolicyFetchTest) {
351 policy::MockDevicePolicy allow_3g_policy;
352
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800353 EXPECT_CALL(mock_system_state_, device_policy())
Jay Srinivasan43488792012-06-19 00:25:31 -0700354 .Times(1)
355 .WillOnce(Return(&allow_3g_policy));
356
357 set<string> allowed_set;
358 allowed_set.insert(cmut_.StringForConnectionType(kNetCellular));
359
360 // Return false for GetAllowedConnectionTypesForUpdate and see
361 // that updates are still blocked for 3G despite the value being in
362 // the string set above.
363 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
364 .Times(1)
365 .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(false)));
366
Alex Deymo6ae91202014-03-10 19:21:25 -0700367 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
368 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700369}
370
Alex Deymof4867c42013-06-28 14:41:39 -0700371TEST_F(ConnectionManagerTest, UseUserPrefForUpdatesOverCellularIfNoPolicyTest) {
372 policy::MockDevicePolicy no_policy;
373 testing::NiceMock<PrefsMock>* prefs = mock_system_state_.mock_prefs();
374
375 EXPECT_CALL(mock_system_state_, device_policy())
376 .Times(3)
377 .WillRepeatedly(Return(&no_policy));
378
379 // No setting enforced by the device policy, user prefs should be used.
380 EXPECT_CALL(no_policy, GetAllowedConnectionTypesForUpdate(_))
381 .Times(3)
382 .WillRepeatedly(Return(false));
383
384 // No user pref: block.
385 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
386 .Times(1)
387 .WillOnce(Return(false));
Alex Deymo6ae91202014-03-10 19:21:25 -0700388 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
389 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700390
391 // Allow per user pref.
392 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
393 .Times(1)
394 .WillOnce(Return(true));
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700395 EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _))
Alex Deymof4867c42013-06-28 14:41:39 -0700396 .Times(1)
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700397 .WillOnce(DoAll(SetArgumentPointee<1>(true), Return(true)));
Alex Deymo6ae91202014-03-10 19:21:25 -0700398 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular,
399 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700400
401 // Block per user pref.
402 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
403 .Times(1)
404 .WillOnce(Return(true));
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700405 EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _))
Alex Deymof4867c42013-06-28 14:41:39 -0700406 .Times(1)
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700407 .WillOnce(DoAll(SetArgumentPointee<1>(false), Return(true)));
Alex Deymo6ae91202014-03-10 19:21:25 -0700408 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
409 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700410}
411
Jay Srinivasan43488792012-06-19 00:25:31 -0700412TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700413 EXPECT_STREQ(shill::kTypeEthernet,
Jay Srinivasan43488792012-06-19 00:25:31 -0700414 cmut_.StringForConnectionType(kNetEthernet));
Ben Chanc6007e42013-09-19 23:49:22 -0700415 EXPECT_STREQ(shill::kTypeWifi,
Jay Srinivasan43488792012-06-19 00:25:31 -0700416 cmut_.StringForConnectionType(kNetWifi));
Ben Chanc6007e42013-09-19 23:49:22 -0700417 EXPECT_STREQ(shill::kTypeWimax,
Jay Srinivasan43488792012-06-19 00:25:31 -0700418 cmut_.StringForConnectionType(kNetWimax));
Ben Chanc6007e42013-09-19 23:49:22 -0700419 EXPECT_STREQ(shill::kTypeBluetooth,
Jay Srinivasan43488792012-06-19 00:25:31 -0700420 cmut_.StringForConnectionType(kNetBluetooth));
Ben Chanc6007e42013-09-19 23:49:22 -0700421 EXPECT_STREQ(shill::kTypeCellular,
Jay Srinivasan43488792012-06-19 00:25:31 -0700422 cmut_.StringForConnectionType(kNetCellular));
423 EXPECT_STREQ("Unknown",
424 cmut_.StringForConnectionType(kNetUnknown));
425 EXPECT_STREQ("Unknown",
426 cmut_.StringForConnectionType(
427 static_cast<NetworkConnectionType>(999999)));
428}
429
430TEST_F(ConnectionManagerTest, MalformedServiceList) {
431 SetupMocks("/service/guest-network");
432 string service_name(kServicePath_);
433 SetManagerReply(&service_name, DBUS_TYPE_G_STRING_ARRAY);
434
435 NetworkConnectionType type;
Alex Deymo6ae91202014-03-10 19:21:25 -0700436 NetworkTethering tethering;
437 EXPECT_FALSE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700438}
439
440} // namespace chromeos_update_engine