| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 1 | // 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 Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 5 | #include "update_engine/connection_manager.h" | 
|  | 6 |  | 
| Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 7 | #include <set> | 
|  | 8 | #include <string> | 
|  | 9 |  | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 10 | #include <base/logging.h> | 
|  | 11 | #include <chromeos/dbus/service_constants.h> | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 12 | #include <gmock/gmock.h> | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 13 | #include <gtest/gtest.h> | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 14 |  | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 15 | #include "update_engine/fake_system_state.h" | 
| Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 16 | #include "update_engine/mock_dbus_wrapper.h" | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 17 | #include "update_engine/test_utils.h" | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 18 |  | 
|  | 19 | using std::set; | 
|  | 20 | using std::string; | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 21 | using testing::AnyNumber; | 
|  | 22 | using testing::Return; | 
|  | 23 | using testing::SetArgumentPointee; | 
|  | 24 | using testing::StrEq; | 
| Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 25 | using testing::_; | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 26 |  | 
|  | 27 | namespace chromeos_update_engine { | 
|  | 28 |  | 
|  | 29 | class ConnectionManagerTest : public ::testing::Test { | 
|  | 30 | public: | 
|  | 31 | ConnectionManagerTest() | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 32 | : kMockFlimFlamManagerProxy_(nullptr), | 
|  | 33 | kMockFlimFlamServiceProxy_(nullptr), | 
|  | 34 | kServicePath_(nullptr), | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 35 | cmut_(&fake_system_state_) { | 
|  | 36 | fake_system_state_.set_connection_manager(&cmut_); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 37 | } | 
|  | 38 |  | 
|  | 39 | protected: | 
|  | 40 | void SetupMocks(const char* service_path); | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 41 | void SetManagerReply(const char* reply_value, const GType& reply_type); | 
| Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 42 |  | 
|  | 43 | // Sets the |service_type| Type and the |physical_technology| | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 44 | // PhysicalTechnology properties in the mocked service. If a null | 
| Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 45 | // |physical_technology| is passed, the property is not set (not present). | 
|  | 46 | void SetServiceReply(const char* service_type, | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 47 | const char* physical_technology, | 
|  | 48 | const char* service_tethering); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 49 | void TestWithServiceType( | 
| Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 50 | const char* service_type, | 
|  | 51 | const char* physical_technology, | 
|  | 52 | NetworkConnectionType expected_type); | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 53 | void TestWithServiceTethering( | 
|  | 54 | const char* service_tethering, | 
|  | 55 | NetworkTethering expected_tethering); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 56 |  | 
|  | 57 | static const char* kGetPropertiesMethod; | 
|  | 58 | DBusGProxy* kMockFlimFlamManagerProxy_; | 
|  | 59 | DBusGProxy* kMockFlimFlamServiceProxy_; | 
|  | 60 | DBusGConnection* kMockSystemBus_; | 
|  | 61 | const char* kServicePath_; | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 62 | testing::StrictMock<MockDBusWrapper> dbus_iface_; | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 63 | ConnectionManager cmut_;  // ConnectionManager under test. | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 64 | FakeSystemState fake_system_state_; | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 65 | }; | 
|  | 66 |  | 
|  | 67 | // static | 
|  | 68 | const char* ConnectionManagerTest::kGetPropertiesMethod = "GetProperties"; | 
|  | 69 |  | 
|  | 70 | void ConnectionManagerTest::SetupMocks(const char* service_path) { | 
|  | 71 | int number = 1; | 
|  | 72 | kMockSystemBus_ = reinterpret_cast<DBusGConnection*>(number++); | 
|  | 73 | kMockFlimFlamManagerProxy_ = reinterpret_cast<DBusGProxy*>(number++); | 
|  | 74 | kMockFlimFlamServiceProxy_ = reinterpret_cast<DBusGProxy*>(number++); | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 75 | ASSERT_NE(kMockSystemBus_, static_cast<DBusGConnection*>(nullptr)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 76 |  | 
|  | 77 | kServicePath_ = service_path; | 
|  | 78 |  | 
|  | 79 | ON_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _)) | 
|  | 80 | .WillByDefault(Return(kMockSystemBus_)); | 
|  | 81 | EXPECT_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _)) | 
|  | 82 | .Times(AnyNumber()); | 
|  | 83 | } | 
|  | 84 |  | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 85 | void ConnectionManagerTest::SetManagerReply(const char *reply_value, | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 86 | const GType& reply_type) { | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 87 | ASSERT_TRUE(dbus_g_type_is_collection(reply_type)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 88 |  | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 89 | // Create the GPtrArray array holding the |reply_value| pointer. The | 
|  | 90 | // |reply_value| string is duplicated because it should be mutable on the | 
|  | 91 | // interface and is because dbus-glib collections will g_free() each element | 
|  | 92 | // of the GPtrArray automatically when the |array_as_value| GValue is unset. | 
|  | 93 | // The g_strdup() is not being leaked. | 
|  | 94 | GPtrArray* array = g_ptr_array_new(); | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 95 | ASSERT_NE(nullptr, array); | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 96 | g_ptr_array_add(array, g_strdup(reply_value)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 97 |  | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 98 | GValue* array_as_value = g_new0(GValue, 1); | 
|  | 99 | EXPECT_EQ(array_as_value, g_value_init(array_as_value, reply_type)); | 
|  | 100 | g_value_take_boxed(array_as_value, array); | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 101 |  | 
|  | 102 | // Initialize return value for D-Bus call to Manager object, which is a | 
|  | 103 | // hash table of static strings (char*) in GValue* containing a single array. | 
|  | 104 | GHashTable* manager_hash_table = g_hash_table_new_full( | 
|  | 105 | g_str_hash, g_str_equal, | 
|  | 106 | nullptr,  // no key_destroy_func because keys are static. | 
|  | 107 | GValueFree);  // value_destroy_func | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 108 | g_hash_table_insert(manager_hash_table, | 
|  | 109 | const_cast<char*>("Services"), | 
|  | 110 | array_as_value); | 
|  | 111 |  | 
|  | 112 | // Plumb return value into mock object. | 
| Gilad Arnold | b752fb3 | 2014-03-03 12:23:39 -0800 | [diff] [blame] | 113 | EXPECT_CALL(dbus_iface_, ProxyCall_0_1(kMockFlimFlamManagerProxy_, | 
|  | 114 | StrEq(kGetPropertiesMethod), | 
|  | 115 | _, _)) | 
|  | 116 | .WillOnce(DoAll(SetArgumentPointee<3>(manager_hash_table), Return(TRUE))); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 117 |  | 
|  | 118 | // Set other expectations. | 
|  | 119 | EXPECT_CALL(dbus_iface_, | 
| Gilad Arnold | b752fb3 | 2014-03-03 12:23:39 -0800 | [diff] [blame] | 120 | ProxyNewForName(kMockSystemBus_, | 
|  | 121 | StrEq(shill::kFlimflamServiceName), | 
|  | 122 | StrEq(shill::kFlimflamServicePath), | 
|  | 123 | StrEq(shill::kFlimflamManagerInterface))) | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 124 | .WillOnce(Return(kMockFlimFlamManagerProxy_)); | 
|  | 125 | EXPECT_CALL(dbus_iface_, ProxyUnref(kMockFlimFlamManagerProxy_)); | 
|  | 126 | EXPECT_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _)) | 
|  | 127 | .RetiresOnSaturation(); | 
|  | 128 | } | 
|  | 129 |  | 
| Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 130 | void ConnectionManagerTest::SetServiceReply(const char* service_type, | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 131 | const char* physical_technology, | 
|  | 132 | const char* service_tethering) { | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 133 | // Initialize return value for D-Bus call to Service object, which is a | 
|  | 134 | // hash table of static strings (char*) in GValue*. | 
|  | 135 | GHashTable* service_hash_table = g_hash_table_new_full( | 
|  | 136 | g_str_hash, g_str_equal, | 
|  | 137 | nullptr,  // no key_destroy_func because keys are static. | 
|  | 138 | GValueFree);  // value_destroy_func | 
|  | 139 | GValue* service_type_value = GValueNewString(service_type); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 140 | g_hash_table_insert(service_hash_table, | 
|  | 141 | const_cast<char*>("Type"), | 
|  | 142 | service_type_value); | 
|  | 143 |  | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 144 | if (physical_technology) { | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 145 | GValue* physical_technology_value = GValueNewString(physical_technology); | 
| Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 146 | g_hash_table_insert(service_hash_table, | 
|  | 147 | const_cast<char*>("PhysicalTechnology"), | 
|  | 148 | physical_technology_value); | 
|  | 149 | } | 
|  | 150 |  | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 151 | if (service_tethering) { | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 152 | GValue* service_tethering_value = GValueNewString(service_tethering); | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 153 | g_hash_table_insert(service_hash_table, | 
|  | 154 | const_cast<char*>("Tethering"), | 
|  | 155 | service_tethering_value); | 
|  | 156 | } | 
|  | 157 |  | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 158 | // Plumb return value into mock object. | 
| Gilad Arnold | b752fb3 | 2014-03-03 12:23:39 -0800 | [diff] [blame] | 159 | EXPECT_CALL(dbus_iface_, ProxyCall_0_1(kMockFlimFlamServiceProxy_, | 
|  | 160 | StrEq(kGetPropertiesMethod), | 
|  | 161 | _, _)) | 
|  | 162 | .WillOnce(DoAll(SetArgumentPointee<3>(service_hash_table), Return(TRUE))); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 163 |  | 
|  | 164 | // Set other expectations. | 
|  | 165 | EXPECT_CALL(dbus_iface_, | 
| Gilad Arnold | b752fb3 | 2014-03-03 12:23:39 -0800 | [diff] [blame] | 166 | ProxyNewForName(kMockSystemBus_, | 
|  | 167 | StrEq(shill::kFlimflamServiceName), | 
|  | 168 | StrEq(kServicePath_), | 
|  | 169 | StrEq(shill::kFlimflamServiceInterface))) | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 170 | .WillOnce(Return(kMockFlimFlamServiceProxy_)); | 
|  | 171 | EXPECT_CALL(dbus_iface_, ProxyUnref(kMockFlimFlamServiceProxy_)); | 
|  | 172 | EXPECT_CALL(dbus_iface_, BusGet(DBUS_BUS_SYSTEM, _)) | 
|  | 173 | .RetiresOnSaturation(); | 
|  | 174 | } | 
|  | 175 |  | 
|  | 176 | void ConnectionManagerTest::TestWithServiceType( | 
|  | 177 | const char* service_type, | 
| Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 178 | const char* physical_technology, | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 179 | NetworkConnectionType expected_type) { | 
|  | 180 |  | 
|  | 181 | SetupMocks("/service/guest-network"); | 
|  | 182 | SetManagerReply(kServicePath_, DBUS_TYPE_G_OBJECT_PATH_ARRAY); | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 183 | SetServiceReply(service_type, physical_technology, | 
|  | 184 | shill::kTetheringNotDetectedState); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 185 |  | 
|  | 186 | NetworkConnectionType type; | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 187 | NetworkTethering tethering; | 
|  | 188 | EXPECT_TRUE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 189 | EXPECT_EQ(expected_type, type); | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 190 | testing::Mock::VerifyAndClearExpectations(&dbus_iface_); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 191 | } | 
|  | 192 |  | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 193 | void ConnectionManagerTest::TestWithServiceTethering( | 
|  | 194 | const char* service_tethering, | 
|  | 195 | NetworkTethering expected_tethering) { | 
|  | 196 |  | 
|  | 197 | SetupMocks("/service/guest-network"); | 
|  | 198 | SetManagerReply(kServicePath_, DBUS_TYPE_G_OBJECT_PATH_ARRAY); | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 199 | SetServiceReply(shill::kTypeWifi, nullptr, service_tethering); | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 200 |  | 
|  | 201 | NetworkConnectionType type; | 
|  | 202 | NetworkTethering tethering; | 
|  | 203 | EXPECT_TRUE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering)); | 
|  | 204 | EXPECT_EQ(expected_tethering, tethering); | 
|  | 205 | } | 
|  | 206 |  | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 207 | TEST_F(ConnectionManagerTest, SimpleTest) { | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 208 | TestWithServiceType(shill::kTypeEthernet, nullptr, kNetEthernet); | 
|  | 209 | TestWithServiceType(shill::kTypeWifi, nullptr, kNetWifi); | 
|  | 210 | TestWithServiceType(shill::kTypeWimax, nullptr, kNetWimax); | 
|  | 211 | TestWithServiceType(shill::kTypeBluetooth, nullptr, kNetBluetooth); | 
|  | 212 | TestWithServiceType(shill::kTypeCellular, nullptr, kNetCellular); | 
| Alex Deymo | 1c4e638 | 2013-07-15 12:09:51 -0700 | [diff] [blame] | 213 | } | 
|  | 214 |  | 
|  | 215 | TEST_F(ConnectionManagerTest, PhysicalTechnologyTest) { | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 216 | TestWithServiceType(shill::kTypeVPN, nullptr, kNetUnknown); | 
| Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 217 | TestWithServiceType(shill::kTypeVPN, shill::kTypeVPN, kNetUnknown); | 
|  | 218 | TestWithServiceType(shill::kTypeVPN, shill::kTypeWifi, kNetWifi); | 
|  | 219 | TestWithServiceType(shill::kTypeVPN, shill::kTypeWimax, kNetWimax); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 220 | } | 
|  | 221 |  | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 222 | TEST_F(ConnectionManagerTest, TetheringTest) { | 
|  | 223 | TestWithServiceTethering(shill::kTetheringConfirmedState, | 
|  | 224 | NetworkTethering::kConfirmed); | 
|  | 225 | TestWithServiceTethering(shill::kTetheringNotDetectedState, | 
|  | 226 | NetworkTethering::kNotDetected); | 
|  | 227 | TestWithServiceTethering(shill::kTetheringSuspectedState, | 
|  | 228 | NetworkTethering::kSuspected); | 
|  | 229 | TestWithServiceTethering("I'm not a valid property value =)", | 
|  | 230 | NetworkTethering::kUnknown); | 
|  | 231 | } | 
|  | 232 |  | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 233 | TEST_F(ConnectionManagerTest, UnknownTest) { | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 234 | TestWithServiceType("foo", nullptr, kNetUnknown); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 235 | } | 
|  | 236 |  | 
|  | 237 | TEST_F(ConnectionManagerTest, AllowUpdatesOverEthernetTest) { | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 238 | // Updates over Ethernet are allowed even if there's no policy. | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 239 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet, | 
|  | 240 | NetworkTethering::kUnknown)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 241 | } | 
|  | 242 |  | 
|  | 243 | TEST_F(ConnectionManagerTest, AllowUpdatesOverWifiTest) { | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 244 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, NetworkTethering::kUnknown)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 245 | } | 
|  | 246 |  | 
|  | 247 | TEST_F(ConnectionManagerTest, AllowUpdatesOverWimaxTest) { | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 248 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWimax, | 
|  | 249 | NetworkTethering::kUnknown)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 250 | } | 
|  | 251 |  | 
|  | 252 | TEST_F(ConnectionManagerTest, BlockUpdatesOverBluetoothTest) { | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 253 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetBluetooth, | 
|  | 254 | NetworkTethering::kUnknown)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 255 | } | 
|  | 256 |  | 
|  | 257 | TEST_F(ConnectionManagerTest, AllowUpdatesOnlyOver3GPerPolicyTest) { | 
|  | 258 | policy::MockDevicePolicy allow_3g_policy; | 
|  | 259 |  | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 260 | fake_system_state_.set_device_policy(&allow_3g_policy); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 261 |  | 
| Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 262 | // This test tests cellular (3G) being the only connection type being allowed. | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 263 | set<string> allowed_set; | 
|  | 264 | allowed_set.insert(cmut_.StringForConnectionType(kNetCellular)); | 
|  | 265 |  | 
|  | 266 | EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_)) | 
|  | 267 | .Times(1) | 
|  | 268 | .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(true))); | 
|  | 269 |  | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 270 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular, | 
|  | 271 | NetworkTethering::kUnknown)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 272 | } | 
|  | 273 |  | 
|  | 274 | TEST_F(ConnectionManagerTest, AllowUpdatesOver3GAndOtherTypesPerPolicyTest) { | 
|  | 275 | policy::MockDevicePolicy allow_3g_policy; | 
|  | 276 |  | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 277 | fake_system_state_.set_device_policy(&allow_3g_policy); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 278 |  | 
|  | 279 | // This test tests multiple connection types being allowed, with | 
| Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 280 | // 3G one among them. Only Cellular is currently enforced by the policy | 
|  | 281 | // setting, the others are ignored (see Bluetooth for example). | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 282 | set<string> allowed_set; | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 283 | allowed_set.insert(cmut_.StringForConnectionType(kNetCellular)); | 
| Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 284 | allowed_set.insert(cmut_.StringForConnectionType(kNetBluetooth)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 285 |  | 
|  | 286 | EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_)) | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 287 | .Times(3) | 
|  | 288 | .WillRepeatedly(DoAll(SetArgumentPointee<0>(allowed_set), Return(true))); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 289 |  | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 290 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet, | 
|  | 291 | NetworkTethering::kUnknown)); | 
|  | 292 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet, | 
|  | 293 | NetworkTethering::kNotDetected)); | 
|  | 294 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular, | 
|  | 295 | NetworkTethering::kUnknown)); | 
|  | 296 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, NetworkTethering::kUnknown)); | 
|  | 297 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWimax, NetworkTethering::kUnknown)); | 
|  | 298 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetBluetooth, | 
|  | 299 | NetworkTethering::kUnknown)); | 
|  | 300 |  | 
|  | 301 | // Tethered networks are treated in the same way as Cellular networks and | 
|  | 302 | // thus allowed. | 
|  | 303 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetEthernet, | 
|  | 304 | NetworkTethering::kConfirmed)); | 
|  | 305 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, | 
|  | 306 | NetworkTethering::kConfirmed)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 307 | } | 
|  | 308 |  | 
| Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 309 | TEST_F(ConnectionManagerTest, BlockUpdatesOverCellularByDefaultTest) { | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 310 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular, | 
|  | 311 | NetworkTethering::kUnknown)); | 
|  | 312 | } | 
|  | 313 |  | 
|  | 314 | TEST_F(ConnectionManagerTest, BlockUpdatesOverTetheredNetworkByDefaultTest) { | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 315 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetWifi, | 
|  | 316 | NetworkTethering::kConfirmed)); | 
|  | 317 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetEthernet, | 
|  | 318 | NetworkTethering::kConfirmed)); | 
|  | 319 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetWifi, | 
|  | 320 | NetworkTethering::kSuspected)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 321 | } | 
|  | 322 |  | 
|  | 323 | TEST_F(ConnectionManagerTest, BlockUpdatesOver3GPerPolicyTest) { | 
|  | 324 | policy::MockDevicePolicy block_3g_policy; | 
|  | 325 |  | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 326 | fake_system_state_.set_device_policy(&block_3g_policy); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 327 |  | 
|  | 328 | // Test that updates for 3G are blocked while updates are allowed | 
|  | 329 | // over several other types. | 
|  | 330 | set<string> allowed_set; | 
|  | 331 | allowed_set.insert(cmut_.StringForConnectionType(kNetEthernet)); | 
|  | 332 | allowed_set.insert(cmut_.StringForConnectionType(kNetWifi)); | 
|  | 333 | allowed_set.insert(cmut_.StringForConnectionType(kNetWimax)); | 
|  | 334 |  | 
|  | 335 | EXPECT_CALL(block_3g_policy, GetAllowedConnectionTypesForUpdate(_)) | 
|  | 336 | .Times(1) | 
|  | 337 | .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(true))); | 
|  | 338 |  | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 339 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular, | 
|  | 340 | NetworkTethering::kUnknown)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 341 | } | 
|  | 342 |  | 
|  | 343 | TEST_F(ConnectionManagerTest, BlockUpdatesOver3GIfErrorInPolicyFetchTest) { | 
|  | 344 | policy::MockDevicePolicy allow_3g_policy; | 
|  | 345 |  | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 346 | fake_system_state_.set_device_policy(&allow_3g_policy); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 347 |  | 
|  | 348 | set<string> allowed_set; | 
|  | 349 | allowed_set.insert(cmut_.StringForConnectionType(kNetCellular)); | 
|  | 350 |  | 
|  | 351 | // Return false for GetAllowedConnectionTypesForUpdate and see | 
|  | 352 | // that updates are still blocked for 3G despite the value being in | 
|  | 353 | // the string set above. | 
|  | 354 | EXPECT_CALL(allow_3g_policy, GetAllowedConnectionTypesForUpdate(_)) | 
|  | 355 | .Times(1) | 
|  | 356 | .WillOnce(DoAll(SetArgumentPointee<0>(allowed_set), Return(false))); | 
|  | 357 |  | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 358 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular, | 
|  | 359 | NetworkTethering::kUnknown)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 360 | } | 
|  | 361 |  | 
| Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 362 | TEST_F(ConnectionManagerTest, UseUserPrefForUpdatesOverCellularIfNoPolicyTest) { | 
|  | 363 | policy::MockDevicePolicy no_policy; | 
| Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 364 | testing::NiceMock<MockPrefs>* prefs = fake_system_state_.mock_prefs(); | 
| Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 365 |  | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 366 | fake_system_state_.set_device_policy(&no_policy); | 
| Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 367 |  | 
|  | 368 | // No setting enforced by the device policy, user prefs should be used. | 
|  | 369 | EXPECT_CALL(no_policy, GetAllowedConnectionTypesForUpdate(_)) | 
|  | 370 | .Times(3) | 
|  | 371 | .WillRepeatedly(Return(false)); | 
|  | 372 |  | 
|  | 373 | // No user pref: block. | 
|  | 374 | EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission)) | 
|  | 375 | .Times(1) | 
|  | 376 | .WillOnce(Return(false)); | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 377 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular, | 
|  | 378 | NetworkTethering::kUnknown)); | 
| Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 379 |  | 
|  | 380 | // Allow per user pref. | 
|  | 381 | EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission)) | 
|  | 382 | .Times(1) | 
|  | 383 | .WillOnce(Return(true)); | 
| Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 384 | EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _)) | 
| Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 385 | .Times(1) | 
| Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 386 | .WillOnce(DoAll(SetArgumentPointee<1>(true), Return(true))); | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 387 | EXPECT_TRUE(cmut_.IsUpdateAllowedOver(kNetCellular, | 
|  | 388 | NetworkTethering::kUnknown)); | 
| Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 389 |  | 
|  | 390 | // Block per user pref. | 
|  | 391 | EXPECT_CALL(*prefs, Exists(kPrefsUpdateOverCellularPermission)) | 
|  | 392 | .Times(1) | 
|  | 393 | .WillOnce(Return(true)); | 
| Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 394 | EXPECT_CALL(*prefs, GetBoolean(kPrefsUpdateOverCellularPermission, _)) | 
| Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 395 | .Times(1) | 
| Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 396 | .WillOnce(DoAll(SetArgumentPointee<1>(false), Return(true))); | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 397 | EXPECT_FALSE(cmut_.IsUpdateAllowedOver(kNetCellular, | 
|  | 398 | NetworkTethering::kUnknown)); | 
| Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 399 | } | 
|  | 400 |  | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 401 | TEST_F(ConnectionManagerTest, StringForConnectionTypeTest) { | 
| Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 402 | EXPECT_STREQ(shill::kTypeEthernet, | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 403 | cmut_.StringForConnectionType(kNetEthernet)); | 
| Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 404 | EXPECT_STREQ(shill::kTypeWifi, | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 405 | cmut_.StringForConnectionType(kNetWifi)); | 
| Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 406 | EXPECT_STREQ(shill::kTypeWimax, | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 407 | cmut_.StringForConnectionType(kNetWimax)); | 
| Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 408 | EXPECT_STREQ(shill::kTypeBluetooth, | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 409 | cmut_.StringForConnectionType(kNetBluetooth)); | 
| Ben Chan | c6007e4 | 2013-09-19 23:49:22 -0700 | [diff] [blame] | 410 | EXPECT_STREQ(shill::kTypeCellular, | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 411 | cmut_.StringForConnectionType(kNetCellular)); | 
|  | 412 | EXPECT_STREQ("Unknown", | 
|  | 413 | cmut_.StringForConnectionType(kNetUnknown)); | 
|  | 414 | EXPECT_STREQ("Unknown", | 
|  | 415 | cmut_.StringForConnectionType( | 
|  | 416 | static_cast<NetworkConnectionType>(999999))); | 
|  | 417 | } | 
|  | 418 |  | 
|  | 419 | TEST_F(ConnectionManagerTest, MalformedServiceList) { | 
|  | 420 | SetupMocks("/service/guest-network"); | 
| Alex Deymo | 5665d0c | 2014-05-28 17:45:43 -0700 | [diff] [blame] | 421 | SetManagerReply(kServicePath_, DBUS_TYPE_G_STRING_ARRAY); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 422 |  | 
|  | 423 | NetworkConnectionType type; | 
| Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 424 | NetworkTethering tethering; | 
|  | 425 | EXPECT_FALSE(cmut_.GetConnectionProperties(&dbus_iface_, &type, &tethering)); | 
| Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 426 | } | 
|  | 427 |  | 
|  | 428 | }  // namespace chromeos_update_engine |