blob: 6b3e26b1772586d1ffe2ba9d9eef4187efac5efd [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 Arnold5bb4c902014-04-10 12:32:13 -070011#include "update_engine/fake_system_state.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080012#include "update_engine/mock_dbus_wrapper.h"
Jay Srinivasan43488792012-06-19 00:25:31 -070013
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),
Gilad Arnold5bb4c902014-04-10 12:32:13 -070030 cmut_(&fake_system_state_) {
31 fake_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.
Gilad Arnold5bb4c902014-04-10 12:32:13 -070059 FakeSystemState fake_system_state_;
Jay Srinivasan43488792012-06-19 00:25:31 -070060};
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 Srinivasan43488792012-06-19 00:25:31 -0700232 // Updates over Ethernet are allowed even if there's no policy.
Alex Deymo6ae91202014-03-10 19:21:25 -0700233 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet,
234 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700235}
236
237TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) {
Alex Deymo6ae91202014-03-10 19:21:25 -0700238 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700239}
240
241TEST_F(ConnectionManagerTest, AllowUpdatesOverWimaxTest) {
Alex Deymo6ae91202014-03-10 19:21:25 -0700242 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWimax,
243 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700244}
245
246TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) {
Alex Deymo6ae91202014-03-10 19:21:25 -0700247 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetBluetooth,
248 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700249}
250
251TEST_F(ConnectionManagerTest, AllowUpdatesOnlyOver3GPerPolicyTest) {
252 policy::MockDevicePolicy allow_3g_policy;
253
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700254 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700255
Alex Deymof4867c42013-06-28 14:41:39 -0700256 // This test tests cellular (3G) being the only connection type being allowed.
Jay Srinivasan43488792012-06-19 00:25:31 -0700257 set<string> allowed_set;
258 allowed_set.insert(cmut_.StringForConnectionType(kNetCellular));
259
260 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
261 .Times(1)
262 .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(true)));
263
Alex Deymo6ae91202014-03-10 19:21:25 -0700264 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular,
265 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700266}
267
268TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) {
269 policy::MockDevicePolicy allow_3g_policy;
270
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700271 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700272
273 // This test tests multiple connection types being allowed, with
Alex Deymof4867c42013-06-28 14:41:39 -0700274 // 3G one among them. Only Cellular is currently enforced by the policy
275 // setting, the others are ignored (see Bluetooth for example).
Jay Srinivasan43488792012-06-19 00:25:31 -0700276 set<string> allowed_set;
Jay Srinivasan43488792012-06-19 00:25:31 -0700277 allowed_set.insert(cmut_.StringForConnectionType(kNetCellular));
Alex Deymof4867c42013-06-28 14:41:39 -0700278 allowed_set.insert(cmut_.StringForConnectionType(kNetBluetooth));
Jay Srinivasan43488792012-06-19 00:25:31 -0700279
280 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
Alex Deymo6ae91202014-03-10 19:21:25 -0700281 .Times(3)
282 .WillRepeatedly(DoAll(SetArgumentPointee<0>(allowed_set), Return(true)));
Jay Srinivasan43488792012-06-19 00:25:31 -0700283
Alex Deymo6ae91202014-03-10 19:21:25 -0700284 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet,
285 NetworkTethering::kUnknown));
286 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet,
287 NetworkTethering::kNotDetected));
288 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular,
289 NetworkTethering::kUnknown));
290 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, NetworkTethering::kUnknown));
291 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWimax, NetworkTethering::kUnknown));
292 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetBluetooth,
293 NetworkTethering::kUnknown));
294
295 // Tethered networks are treated in the same way as Cellular networks and
296 // thus allowed.
297 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet,
298 NetworkTethering::kConfirmed));
299 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi,
300 NetworkTethering::kConfirmed));
Jay Srinivasan43488792012-06-19 00:25:31 -0700301}
302
Alex Deymof4867c42013-06-28 14:41:39 -0700303TEST_F(ConnectionManagerTest, BlockUpdatesOverCellularByDefaultTest) {
Alex Deymo6ae91202014-03-10 19:21:25 -0700304 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
305 NetworkTethering::kUnknown));
306}
307
308TEST_F(ConnectionManagerTest, BlockUpdatesOverTetheredNetworkByDefaultTest) {
Alex Deymo6ae91202014-03-10 19:21:25 -0700309 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetWifi,
310 NetworkTethering::kConfirmed));
311 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetEthernet,
312 NetworkTethering::kConfirmed));
313 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi,
314 NetworkTethering::kSuspected));
Jay Srinivasan43488792012-06-19 00:25:31 -0700315}
316
317TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) {
318 policy::MockDevicePolicy block_3g_policy;
319
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700320 fake_system_state_.set_device_policy(&block_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700321
322 // Test that updates for 3G are blocked while updates are allowed
323 // over several other types.
324 set<string> allowed_set;
325 allowed_set.insert(cmut_.StringForConnectionType(kNetEthernet));
326 allowed_set.insert(cmut_.StringForConnectionType(kNetWifi));
327 allowed_set.insert(cmut_.StringForConnectionType(kNetWimax));
328
329 EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_))
330 .Times(1)
331 .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(true)));
332
Alex Deymo6ae91202014-03-10 19:21:25 -0700333 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
334 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700335}
336
337TEST_F(ConnectionManagerTest, BlockUpdatesOver3GIfErrorInPolicyFetchTest) {
338 policy::MockDevicePolicy allow_3g_policy;
339
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700340 fake_system_state_.set_device_policy(&allow_3g_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700341
342 set<string> allowed_set;
343 allowed_set.insert(cmut_.StringForConnectionType(kNetCellular));
344
345 // Return false for GetAllowedConnectionTypesForUpdate and see
346 // that updates are still blocked for 3G despite the value being in
347 // the string set above.
348 EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_))
349 .Times(1)
350 .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(false)));
351
Alex Deymo6ae91202014-03-10 19:21:25 -0700352 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
353 NetworkTethering::kUnknown));
Jay Srinivasan43488792012-06-19 00:25:31 -0700354}
355
Alex Deymof4867c42013-06-28 14:41:39 -0700356TEST_F(ConnectionManagerTest, UseUserPrefForUpdatesOverCellularIfNoPolicyTest) {
357 policy::MockDevicePolicy no_policy;
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700358 testing::NiceMock<PrefsMock>* prefs = fake_system_state_.mock_prefs();
Alex Deymof4867c42013-06-28 14:41:39 -0700359
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700360 fake_system_state_.set_device_policy(&no_policy);
Alex Deymof4867c42013-06-28 14:41:39 -0700361
362 // No setting enforced by the device policy, user prefs should be used.
363 EXPECT_CALL(no_policy, GetAllowedConnectionTypesForUpdate(_))
364 .Times(3)
365 .WillRepeatedly(Return(false));
366
367 // No user pref: block.
368 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
369 .Times(1)
370 .WillOnce(Return(false));
Alex Deymo6ae91202014-03-10 19:21:25 -0700371 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
372 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700373
374 // Allow per user pref.
375 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
376 .Times(1)
377 .WillOnce(Return(true));
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700378 EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _))
Alex Deymof4867c42013-06-28 14:41:39 -0700379 .Times(1)
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700380 .WillOnce(DoAll(SetArgumentPointee<1>(true), Return(true)));
Alex Deymo6ae91202014-03-10 19:21:25 -0700381 EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular,
382 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700383
384 // Block per user pref.
385 EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission))
386 .Times(1)
387 .WillOnce(Return(true));
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700388 EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _))
Alex Deymof4867c42013-06-28 14:41:39 -0700389 .Times(1)
Alex Deymoefb7c4c2013-07-09 14:34:00 -0700390 .WillOnce(DoAll(SetArgumentPointee<1>(false), Return(true)));
Alex Deymo6ae91202014-03-10 19:21:25 -0700391 EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular,
392 NetworkTethering::kUnknown));
Alex Deymof4867c42013-06-28 14:41:39 -0700393}
394
Jay Srinivasan43488792012-06-19 00:25:31 -0700395TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) {
Ben Chanc6007e42013-09-19 23:49:22 -0700396 EXPECT_STREQ(shill::kTypeEthernet,
Jay Srinivasan43488792012-06-19 00:25:31 -0700397 cmut_.StringForConnectionType(kNetEthernet));
Ben Chanc6007e42013-09-19 23:49:22 -0700398 EXPECT_STREQ(shill::kTypeWifi,
Jay Srinivasan43488792012-06-19 00:25:31 -0700399 cmut_.StringForConnectionType(kNetWifi));
Ben Chanc6007e42013-09-19 23:49:22 -0700400 EXPECT_STREQ(shill::kTypeWimax,
Jay Srinivasan43488792012-06-19 00:25:31 -0700401 cmut_.StringForConnectionType(kNetWimax));
Ben Chanc6007e42013-09-19 23:49:22 -0700402 EXPECT_STREQ(shill::kTypeBluetooth,
Jay Srinivasan43488792012-06-19 00:25:31 -0700403 cmut_.StringForConnectionType(kNetBluetooth));
Ben Chanc6007e42013-09-19 23:49:22 -0700404 EXPECT_STREQ(shill::kTypeCellular,
Jay Srinivasan43488792012-06-19 00:25:31 -0700405 cmut_.StringForConnectionType(kNetCellular));
406 EXPECT_STREQ("Unknown",
407 cmut_.StringForConnectionType(kNetUnknown));
408 EXPECT_STREQ("Unknown",
409 cmut_.StringForConnectionType(
410 static_cast<NetworkConnectionType>(999999)));
411}
412
413TEST_F(ConnectionManagerTest, MalformedServiceList) {
414 SetupMocks("/service/guest-network");
415 string service_name(kServicePath_);
416 SetManagerReply(&service_name, DBUS_TYPE_G_STRING_ARRAY);
417
418 NetworkConnectionType type;
Alex Deymo6ae91202014-03-10 19:21:25 -0700419 NetworkTethering tethering;
420 EXPECT_FALSE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering));
Jay Srinivasan43488792012-06-19 00:25:31 -0700421}
422
423} // namespace chromeos_update_engine