Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [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 | |
| 5 | #include "shill/cellular_capability_universal.h" |
| 6 | |
Nathan Williams | 4b7c2a8 | 2012-04-13 15:19:47 -0400 | [diff] [blame] | 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 10 | #include <base/bind.h> |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 11 | #include <base/stringprintf.h> |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 12 | #include <chromeos/dbus/service_constants.h> |
| 13 | #include <gtest/gtest.h> |
| 14 | #include <mobile_provider.h> |
Ben Chan | 5c853ef | 2012-10-05 00:05:37 -0700 | [diff] [blame] | 15 | #include <ModemManager/ModemManager.h> |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 16 | |
| 17 | #include "shill/cellular.h" |
| 18 | #include "shill/cellular_service.h" |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 19 | #include "shill/dbus_adaptor.h" |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 20 | #include "shill/error.h" |
| 21 | #include "shill/event_dispatcher.h" |
| 22 | #include "shill/mock_adaptors.h" |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 23 | #include "shill/mock_cellular_service.h" |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 24 | #include "shill/mock_dbus_properties_proxy.h" |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 25 | #include "shill/mock_glib.h" |
| 26 | #include "shill/mock_manager.h" |
| 27 | #include "shill/mock_metrics.h" |
| 28 | #include "shill/mock_mm1_modem_modem3gpp_proxy.h" |
| 29 | #include "shill/mock_mm1_modem_modemcdma_proxy.h" |
| 30 | #include "shill/mock_mm1_modem_proxy.h" |
| 31 | #include "shill/mock_mm1_modem_simple_proxy.h" |
| 32 | #include "shill/mock_mm1_sim_proxy.h" |
| 33 | #include "shill/mock_profile.h" |
| 34 | #include "shill/mock_rtnl_handler.h" |
| 35 | #include "shill/nice_mock_control.h" |
| 36 | #include "shill/proxy_factory.h" |
| 37 | |
| 38 | using base::Bind; |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 39 | using base::StringPrintf; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 40 | using base::Unretained; |
| 41 | using std::string; |
Nathan Williams | 4b7c2a8 | 2012-04-13 15:19:47 -0400 | [diff] [blame] | 42 | using std::vector; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 43 | using testing::InSequence; |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 44 | using testing::Mock; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 45 | using testing::NiceMock; |
| 46 | using testing::Return; |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 47 | using testing::SaveArg; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 48 | using testing::_; |
| 49 | |
| 50 | namespace shill { |
| 51 | |
| 52 | MATCHER(IsSuccess, "") { |
| 53 | return arg.IsSuccess(); |
| 54 | } |
| 55 | MATCHER(IsFailure, "") { |
| 56 | return arg.IsFailure(); |
| 57 | } |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 58 | MATCHER_P(HasApn, expected_apn, "") { |
| 59 | string apn; |
| 60 | return (DBusProperties::GetString(arg, |
| 61 | CellularCapabilityUniversal::kConnectApn, |
| 62 | &apn) && |
| 63 | apn == expected_apn); |
| 64 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 65 | |
| 66 | class CellularCapabilityUniversalTest : public testing::Test { |
| 67 | public: |
| 68 | CellularCapabilityUniversalTest() |
| 69 | : manager_(&control_, &dispatcher_, &metrics_, &glib_), |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 70 | modem_3gpp_proxy_(new mm1::MockModemModem3gppProxy()), |
| 71 | modem_cdma_proxy_(new mm1::MockModemModemCdmaProxy()), |
| 72 | modem_proxy_(new mm1::MockModemProxy()), |
| 73 | modem_simple_proxy_(new mm1::MockModemSimpleProxy()), |
| 74 | sim_proxy_(new mm1::MockSimProxy()), |
| 75 | properties_proxy_(new MockDBusPropertiesProxy()), |
| 76 | proxy_factory_(this), |
| 77 | capability_(NULL), |
| 78 | device_adaptor_(NULL), |
| 79 | provider_db_(NULL), |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 80 | cellular_(new Cellular(&control_, |
| 81 | &dispatcher_, |
| 82 | NULL, |
| 83 | &manager_, |
| 84 | "", |
| 85 | "", |
| 86 | 0, |
| 87 | Cellular::kTypeUniversal, |
| 88 | "", |
| 89 | "", |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 90 | "", |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 91 | NULL, |
| 92 | &proxy_factory_)), |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 93 | service_(new MockCellularService(&control_, |
| 94 | &dispatcher_, |
| 95 | &metrics_, |
| 96 | &manager_, |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 97 | cellular_)) {} |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 98 | |
| 99 | virtual ~CellularCapabilityUniversalTest() { |
| 100 | cellular_->service_ = NULL; |
| 101 | capability_ = NULL; |
| 102 | device_adaptor_ = NULL; |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 103 | if (provider_db_) { |
| 104 | mobile_provider_close_db(provider_db_); |
| 105 | provider_db_ = NULL; |
| 106 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | virtual void SetUp() { |
| 110 | capability_ = dynamic_cast<CellularCapabilityUniversal *>( |
| 111 | cellular_->capability_.get()); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 112 | device_adaptor_ = |
| 113 | dynamic_cast<NiceMock<DeviceMockAdaptor> *>(cellular_->adaptor()); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 114 | cellular_->service_ = service_; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | virtual void TearDown() { |
| 118 | capability_->proxy_factory_ = NULL; |
| 119 | } |
| 120 | |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 121 | void SetService() { |
| 122 | cellular_->service_ = new CellularService( |
| 123 | &control_, &dispatcher_, &metrics_, NULL, cellular_); |
| 124 | } |
| 125 | |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 126 | void InitProviderDB() { |
| 127 | const char kTestMobileProviderDBPath[] = "provider_db_unittest.bfd"; |
| 128 | |
| 129 | provider_db_ = mobile_provider_open_db(kTestMobileProviderDBPath); |
| 130 | ASSERT_TRUE(provider_db_); |
| 131 | cellular_->provider_db_ = provider_db_; |
| 132 | } |
| 133 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 134 | void InvokeEnable(bool enable, Error *error, |
| 135 | const ResultCallback &callback, int timeout) { |
| 136 | callback.Run(Error()); |
| 137 | } |
| 138 | void InvokeEnableFail(bool enable, Error *error, |
| 139 | const ResultCallback &callback, int timeout) { |
| 140 | callback.Run(Error(Error::kOperationFailed)); |
| 141 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 142 | void InvokeRegister(const string &operator_id, Error *error, |
| 143 | const ResultCallback &callback, int timeout) { |
| 144 | callback.Run(Error()); |
| 145 | } |
| 146 | |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 147 | void InvokeScan(Error *error, const DBusPropertyMapsCallback &callback, |
| 148 | int timeout) { |
| 149 | callback.Run(CellularCapabilityUniversal::ScanResults(), Error()); |
| 150 | } |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 151 | void ScanError(Error *error, const DBusPropertyMapsCallback &callback, |
| 152 | int timeout) { |
| 153 | error->Populate(Error::kOperationFailed); |
| 154 | } |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 155 | |
| 156 | void Set3gppProxy() { |
| 157 | capability_->modem_3gpp_proxy_.reset(modem_3gpp_proxy_.release()); |
| 158 | } |
| 159 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 160 | void SetSimpleProxy() { |
| 161 | capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release()); |
| 162 | } |
| 163 | |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 164 | void ReleaseCapabilityProxies() { |
| 165 | capability_->ReleaseProxies(); |
| 166 | } |
| 167 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 168 | MOCK_METHOD1(TestCallback, void(const Error &error)); |
| 169 | |
| 170 | protected: |
| 171 | static const char kImei[]; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 172 | static const char kSimPath[]; |
| 173 | static const uint32 kAccessTechnologies; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 174 | |
| 175 | class TestProxyFactory : public ProxyFactory { |
| 176 | public: |
| 177 | explicit TestProxyFactory(CellularCapabilityUniversalTest *test) : |
| 178 | test_(test) {} |
| 179 | |
| 180 | virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy( |
| 181 | const std::string &/* path */, |
| 182 | const std::string &/* service */) { |
| 183 | return test_->modem_3gpp_proxy_.release(); |
| 184 | } |
| 185 | |
| 186 | virtual mm1::ModemModemCdmaProxyInterface *CreateMM1ModemModemCdmaProxy( |
| 187 | const std::string &/* path */, |
| 188 | const std::string &/* service */) { |
| 189 | return test_->modem_cdma_proxy_.release(); |
| 190 | } |
| 191 | |
| 192 | virtual mm1::ModemProxyInterface *CreateMM1ModemProxy( |
| 193 | const std::string &/* path */, |
| 194 | const std::string &/* service */) { |
| 195 | return test_->modem_proxy_.release(); |
| 196 | } |
| 197 | |
| 198 | virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy( |
| 199 | const std::string &/* path */, |
| 200 | const std::string &/* service */) { |
| 201 | return test_->modem_simple_proxy_.release(); |
| 202 | } |
| 203 | |
| 204 | virtual mm1::SimProxyInterface *CreateSimProxy( |
| 205 | const std::string &/* path */, |
| 206 | const std::string &/* service */) { |
| 207 | return test_->sim_proxy_.release(); |
| 208 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 209 | virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy( |
| 210 | const std::string &/* path */, |
| 211 | const std::string &/* service */) { |
| 212 | return test_->properties_proxy_.release(); |
| 213 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 214 | |
| 215 | private: |
| 216 | CellularCapabilityUniversalTest *test_; |
| 217 | }; |
| 218 | |
| 219 | NiceMockControl control_; |
| 220 | EventDispatcher dispatcher_; |
| 221 | MockMetrics metrics_; |
| 222 | MockGLib glib_; |
| 223 | MockManager manager_; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 224 | scoped_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_; |
| 225 | scoped_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_; |
| 226 | scoped_ptr<mm1::MockModemProxy> modem_proxy_; |
| 227 | scoped_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_; |
| 228 | scoped_ptr<mm1::MockSimProxy> sim_proxy_; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 229 | scoped_ptr<MockDBusPropertiesProxy> properties_proxy_; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 230 | TestProxyFactory proxy_factory_; |
| 231 | CellularCapabilityUniversal *capability_; // Owned by |cellular_|. |
| 232 | NiceMock<DeviceMockAdaptor> *device_adaptor_; // Owned by |cellular_|. |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 233 | mobile_provider_db *provider_db_; |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 234 | CellularRefPtr cellular_; |
| 235 | MockCellularService *service_; // owned by cellular_ |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 236 | DBusPropertyMapsCallback scan_callback_; // saved for testing scan operations |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 237 | DBusPathCallback connect_callback_; // saved for testing connect operations |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | const char CellularCapabilityUniversalTest::kImei[] = "999911110000"; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 241 | const char CellularCapabilityUniversalTest::kSimPath[] = "/foo/sim"; |
| 242 | const uint32 CellularCapabilityUniversalTest::kAccessTechnologies = |
| 243 | MM_MODEM_ACCESS_TECHNOLOGY_LTE | |
| 244 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 245 | |
| 246 | TEST_F(CellularCapabilityUniversalTest, StartModem) { |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 247 | // Set up mock modem properties |
| 248 | DBusPropertiesMap modem_properties; |
| 249 | string operator_name = "TestOperator"; |
| 250 | string operator_code = "001400"; |
| 251 | |
| 252 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 253 | writer().append_uint32(kAccessTechnologies); |
| 254 | |
| 255 | ::DBus::Variant v; |
| 256 | ::DBus::MessageIter writer = v.writer(); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 257 | ::DBus::Struct< uint32_t, bool > quality; |
| 258 | quality._1 = 90; |
| 259 | quality._2 = true; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 260 | writer << quality; |
| 261 | modem_properties[MM_MODEM_PROPERTY_SIGNALQUALITY] = v; |
| 262 | |
| 263 | // Set up mock modem 3gpp properties |
| 264 | DBusPropertiesMap modem3gpp_properties; |
| 265 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS]. |
| 266 | writer().append_uint32(0); |
| 267 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_IMEI]. |
| 268 | writer().append_string(kImei); |
| 269 | |
| 270 | EXPECT_CALL(*modem_proxy_, |
| 271 | Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 272 | .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeEnable)); |
| 273 | EXPECT_CALL(*properties_proxy_, |
| 274 | GetAll(MM_DBUS_INTERFACE_MODEM)) |
| 275 | .WillOnce(Return(modem_properties)); |
| 276 | EXPECT_CALL(*properties_proxy_, |
| 277 | GetAll(MM_DBUS_INTERFACE_MODEM_MODEM3GPP)) |
| 278 | .WillOnce(Return(modem3gpp_properties)); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 279 | |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 280 | // Let the modem report that it is initializing. StartModem() should defer |
| 281 | // enabling the modem until its state changes to disabled. |
| 282 | EXPECT_CALL(*modem_proxy_, State()) |
| 283 | .WillOnce(Return(Cellular::kModemStateInitializing)); |
| 284 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 285 | // After setup we lose pointers to the proxies, so it is hard to set |
| 286 | // expectations. |
| 287 | SetUp(); |
| 288 | |
| 289 | Error error; |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 290 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 291 | ResultCallback callback = |
| 292 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 293 | capability_->StartModem(&error, callback); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 294 | |
| 295 | // Verify that the modem has not been eabled. |
| 296 | EXPECT_TRUE(capability_->imei_.empty()); |
| 297 | EXPECT_EQ(0, capability_->access_technologies_); |
| 298 | Mock::VerifyAndClearExpectations(this); |
| 299 | |
| 300 | // Change the state to kModemStateDisabling and verify that it still has not |
| 301 | // been eabled. |
| 302 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
| 303 | capability_->OnModemStateChangedSignal(Cellular::kModemStateInitializing, |
| 304 | Cellular::kModemStateDisabling, 0); |
| 305 | EXPECT_TRUE(capability_->imei_.empty()); |
| 306 | EXPECT_EQ(0, capability_->access_technologies_); |
| 307 | Mock::VerifyAndClearExpectations(this); |
| 308 | |
| 309 | // Change the state of the modem to disabled and verify that it gets enabled. |
| 310 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 311 | capability_->OnModemStateChangedSignal(Cellular::kModemStateDisabling, |
| 312 | Cellular::kModemStateDisabled, 0); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 313 | EXPECT_TRUE(error.IsSuccess()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 314 | EXPECT_EQ(kImei, capability_->imei_); |
| 315 | EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | TEST_F(CellularCapabilityUniversalTest, StartModemFail) { |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 319 | EXPECT_CALL(*modem_proxy_, State()) |
| 320 | .WillOnce(Return(Cellular::kModemStateDisabled)); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 321 | EXPECT_CALL(*modem_proxy_, |
| 322 | Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 323 | .WillOnce( |
| 324 | Invoke(this, &CellularCapabilityUniversalTest::InvokeEnableFail)); |
| 325 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 326 | ResultCallback callback = |
| 327 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 328 | SetUp(); |
| 329 | |
| 330 | Error error; |
| 331 | capability_->StartModem(&error, callback); |
Thieu Le | e3b3659 | 2012-08-30 17:50:26 -0700 | [diff] [blame] | 332 | EXPECT_TRUE(error.IsOngoing()); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 333 | } |
| 334 | |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 335 | TEST_F(CellularCapabilityUniversalTest, StopModem) { |
| 336 | // Save pointers to proxies before they are lost by the call to InitProxies |
| 337 | mm1::MockModemProxy *modem_proxy = modem_proxy_.get(); |
| 338 | SetUp(); |
| 339 | EXPECT_CALL(*modem_proxy, set_state_changed_callback(_)); |
| 340 | capability_->InitProxies(); |
| 341 | |
| 342 | Error error; |
| 343 | ResultCallback callback = |
| 344 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 345 | capability_->StopModem(&error, callback); |
| 346 | EXPECT_TRUE(error.IsSuccess()); |
| 347 | |
| 348 | ResultCallback disable_callback; |
| 349 | EXPECT_CALL(*modem_proxy, |
| 350 | Enable(false, _, _, CellularCapability::kTimeoutEnable)) |
| 351 | .WillOnce(SaveArg<2>(&disable_callback)); |
| 352 | dispatcher_.DispatchPendingEvents(); |
| 353 | |
| 354 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 355 | disable_callback.Run(Error(Error::kSuccess)); |
| 356 | } |
| 357 | |
| 358 | TEST_F(CellularCapabilityUniversalTest, StopModemConnected) { |
| 359 | // Save pointers to proxies before they are lost by the call to InitProxies |
| 360 | mm1::MockModemProxy *modem_proxy = modem_proxy_.get(); |
| 361 | mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get(); |
| 362 | SetUp(); |
| 363 | EXPECT_CALL(*modem_proxy, set_state_changed_callback(_)); |
| 364 | capability_->InitProxies(); |
| 365 | |
| 366 | ResultCallback disconnect_callback; |
| 367 | Error error; |
| 368 | ResultCallback callback = |
| 369 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 370 | EXPECT_CALL(*modem_simple_proxy, |
| 371 | Disconnect(::DBus::Path("/"), _, _, |
| 372 | CellularCapability::kTimeoutDefault)) |
| 373 | .WillOnce(SaveArg<2>(&disconnect_callback)); |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 374 | capability_->cellular()->modem_state_ = Cellular::kModemStateConnected; |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 375 | capability_->StopModem(&error, callback); |
| 376 | EXPECT_TRUE(error.IsSuccess()); |
| 377 | |
| 378 | ResultCallback disable_callback; |
| 379 | EXPECT_CALL(*modem_proxy, |
| 380 | Enable(false, _, _, CellularCapability::kTimeoutEnable)) |
| 381 | .WillOnce(SaveArg<2>(&disable_callback)); |
| 382 | disconnect_callback.Run(Error(Error::kSuccess)); |
| 383 | |
| 384 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 385 | disable_callback.Run(Error(Error::kSuccess)); |
| 386 | } |
| 387 | |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 388 | TEST_F(CellularCapabilityUniversalTest, DisconnectModemNoBearer) { |
| 389 | Error error; |
| 390 | ResultCallback disconnect_callback; |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 391 | EXPECT_CALL(*modem_simple_proxy_, |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 392 | Disconnect(_, _, _, CellularCapability::kTimeoutDefault)) |
| 393 | .Times(0); |
| 394 | capability_->Disconnect(&error, disconnect_callback); |
| 395 | } |
| 396 | |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 397 | TEST_F(CellularCapabilityUniversalTest, DisconnectNoProxy) { |
| 398 | Error error; |
| 399 | ResultCallback disconnect_callback; |
| 400 | capability_->bearer_path_ = "/foo"; |
| 401 | EXPECT_CALL(*modem_simple_proxy_, |
| 402 | Disconnect(_, _, _, CellularCapability::kTimeoutDefault)) |
| 403 | .Times(0); |
| 404 | ReleaseCapabilityProxies(); |
| 405 | capability_->Disconnect(&error, disconnect_callback); |
| 406 | } |
| 407 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 408 | TEST_F(CellularCapabilityUniversalTest, PropertiesChanged) { |
| 409 | // Set up mock modem properties |
| 410 | DBusPropertiesMap modem_properties; |
| 411 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 412 | writer().append_uint32(kAccessTechnologies); |
| 413 | modem_properties[MM_MODEM_PROPERTY_SIM]. |
| 414 | writer().append_path(kSimPath); |
| 415 | |
| 416 | // Set up mock modem 3gpp properties |
| 417 | DBusPropertiesMap modem3gpp_properties; |
| 418 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS]. |
| 419 | writer().append_uint32(0); |
| 420 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_IMEI]. |
| 421 | writer().append_string(kImei); |
| 422 | |
| 423 | // Set up mock modem sim properties |
| 424 | DBusPropertiesMap sim_properties; |
| 425 | |
| 426 | // After setup we lose pointers to the proxies, so it is hard to set |
| 427 | // expectations. |
| 428 | EXPECT_CALL(*properties_proxy_, |
| 429 | GetAll(MM_DBUS_INTERFACE_SIM)) |
| 430 | .WillOnce(Return(sim_properties)); |
| 431 | |
| 432 | SetUp(); |
| 433 | |
| 434 | EXPECT_EQ("", capability_->imei_); |
| 435 | EXPECT_EQ(MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, |
| 436 | capability_->access_technologies_); |
| 437 | EXPECT_FALSE(capability_->sim_proxy_.get()); |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 438 | EXPECT_CALL(*device_adaptor_, EmitStringChanged( |
| 439 | flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyGsm)); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 440 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 441 | modem_properties, vector<string>()); |
| 442 | EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_); |
| 443 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 444 | EXPECT_TRUE(capability_->sim_proxy_.get()); |
| 445 | |
| 446 | // Changing properties on wrong interface will not have an effect |
| 447 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 448 | modem3gpp_properties, |
| 449 | vector<string>()); |
| 450 | EXPECT_EQ("", capability_->imei_); |
| 451 | |
| 452 | // Changing properties on the right interface gets reflected in the |
| 453 | // capabilities object |
| 454 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEM3GPP, |
| 455 | modem3gpp_properties, |
| 456 | vector<string>()); |
| 457 | EXPECT_EQ(kImei, capability_->imei_); |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 458 | |
| 459 | // Expect to see changes when the family changes |
| 460 | modem_properties.clear(); |
| 461 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 462 | writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_1XRTT); |
| 463 | EXPECT_CALL(*device_adaptor_, EmitStringChanged( |
| 464 | flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyCdma)). |
| 465 | Times(1); |
| 466 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 467 | modem_properties, |
| 468 | vector<string>()); |
| 469 | // Back to LTE |
| 470 | modem_properties.clear(); |
| 471 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 472 | writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_LTE); |
| 473 | EXPECT_CALL(*device_adaptor_, EmitStringChanged( |
| 474 | flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyGsm)). |
| 475 | Times(1); |
| 476 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 477 | modem_properties, |
| 478 | vector<string>()); |
| 479 | |
| 480 | // LTE & CDMA - the device adaptor should not be called! |
| 481 | modem_properties.clear(); |
| 482 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 483 | writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_LTE | |
| 484 | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT); |
| 485 | EXPECT_CALL(*device_adaptor_, EmitStringChanged(_, _)).Times(0); |
| 486 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 487 | modem_properties, |
| 488 | vector<string>()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 489 | } |
| 490 | |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 491 | TEST_F(CellularCapabilityUniversalTest, SimPathChanged) { |
| 492 | // Set up mock modem SIM properties |
| 493 | const char kImsi[] = "310100000001"; |
| 494 | const char kSimIdentifier[] = "9999888"; |
| 495 | const char kOperatorIdentifier[] = "310240"; |
| 496 | const char kOperatorName[] = "Custom SPN"; |
| 497 | DBusPropertiesMap sim_properties; |
| 498 | sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi); |
| 499 | sim_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer() |
| 500 | .append_string(kSimIdentifier); |
| 501 | sim_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer() |
| 502 | .append_string(kOperatorIdentifier); |
| 503 | sim_properties[MM_SIM_PROPERTY_OPERATORNAME].writer() |
| 504 | .append_string(kOperatorName); |
| 505 | |
| 506 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM)) |
| 507 | .Times(1).WillOnce(Return(sim_properties)); |
| 508 | |
| 509 | EXPECT_FALSE(capability_->sim_present_); |
| 510 | EXPECT_TRUE(capability_->sim_proxy_ == NULL); |
| 511 | EXPECT_EQ("", capability_->sim_path_); |
| 512 | EXPECT_EQ("", capability_->imsi_); |
| 513 | EXPECT_EQ("", capability_->sim_identifier_); |
| 514 | EXPECT_EQ("", capability_->operator_id_); |
| 515 | EXPECT_EQ("", capability_->spn_); |
| 516 | |
| 517 | capability_->OnSimPathChanged(kSimPath); |
| 518 | EXPECT_TRUE(capability_->sim_present_); |
| 519 | EXPECT_TRUE(capability_->sim_proxy_ != NULL); |
| 520 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 521 | EXPECT_EQ(kImsi, capability_->imsi_); |
| 522 | EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_); |
| 523 | EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_); |
| 524 | EXPECT_EQ(kOperatorName, capability_->spn_); |
| 525 | |
| 526 | // Changing to the same SIM path should be a no-op. |
| 527 | capability_->OnSimPathChanged(kSimPath); |
| 528 | EXPECT_TRUE(capability_->sim_present_); |
| 529 | EXPECT_TRUE(capability_->sim_proxy_ != NULL); |
| 530 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 531 | EXPECT_EQ(kImsi, capability_->imsi_); |
| 532 | EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_); |
| 533 | EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_); |
| 534 | EXPECT_EQ(kOperatorName, capability_->spn_); |
| 535 | |
| 536 | capability_->OnSimPathChanged(""); |
| 537 | EXPECT_FALSE(capability_->sim_present_); |
| 538 | EXPECT_TRUE(capability_->sim_proxy_ == NULL); |
| 539 | EXPECT_EQ("", capability_->sim_path_); |
| 540 | EXPECT_EQ("", capability_->imsi_); |
| 541 | EXPECT_EQ("", capability_->sim_identifier_); |
| 542 | EXPECT_EQ("", capability_->operator_id_); |
| 543 | EXPECT_EQ("", capability_->spn_); |
| 544 | } |
| 545 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 546 | TEST_F(CellularCapabilityUniversalTest, SimPropertiesChanged) { |
| 547 | // Set up mock modem properties |
| 548 | DBusPropertiesMap modem_properties; |
| 549 | modem_properties[MM_MODEM_PROPERTY_SIM].writer().append_path(kSimPath); |
| 550 | |
| 551 | // Set up mock modem sim properties |
| 552 | const char kImsi[] = "310100000001"; |
| 553 | DBusPropertiesMap sim_properties; |
| 554 | sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi); |
| 555 | |
| 556 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM)) |
| 557 | .WillOnce(Return(sim_properties)); |
| 558 | |
| 559 | // After setup we lose pointers to the proxies, so it is hard to set |
| 560 | // expectations. |
| 561 | SetUp(); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 562 | InitProviderDB(); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 563 | |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 564 | EXPECT_TRUE(cellular_->home_provider().GetName().empty()); |
| 565 | EXPECT_TRUE(cellular_->home_provider().GetCountry().empty()); |
| 566 | EXPECT_TRUE(cellular_->home_provider().GetCode().empty()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 567 | EXPECT_FALSE(capability_->sim_proxy_.get()); |
| 568 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 569 | modem_properties, vector<string>()); |
| 570 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 571 | EXPECT_TRUE(capability_->sim_proxy_.get()); |
| 572 | EXPECT_EQ(kImsi, capability_->imsi_); |
| 573 | |
| 574 | // Updating the SIM |
| 575 | DBusPropertiesMap new_properties; |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 576 | const char kCountry[] = "us"; |
| 577 | const char kCode[] = "310160"; |
| 578 | const char kNewImsi[] = "310240123456789"; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 579 | const char kSimIdentifier[] = "9999888"; |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 580 | const char kOperatorIdentifier[] = "310240"; |
| 581 | const char kOperatorName[] = "Custom SPN"; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 582 | new_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kNewImsi); |
| 583 | new_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer(). |
| 584 | append_string(kSimIdentifier); |
| 585 | new_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer(). |
| 586 | append_string(kOperatorIdentifier); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 587 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM, |
| 588 | new_properties, |
| 589 | vector<string>()); |
| 590 | EXPECT_EQ(kNewImsi, capability_->imsi_); |
| 591 | EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_); |
| 592 | EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 593 | EXPECT_EQ("", capability_->spn_); |
| 594 | EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName()); |
| 595 | EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry()); |
| 596 | EXPECT_EQ(kCode, cellular_->home_provider().GetCode()); |
| 597 | EXPECT_EQ(4, capability_->apn_list_.size()); |
| 598 | |
| 599 | new_properties[MM_SIM_PROPERTY_OPERATORNAME].writer(). |
| 600 | append_string(kOperatorName); |
| 601 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM, |
| 602 | new_properties, |
| 603 | vector<string>()); |
| 604 | EXPECT_EQ(kOperatorName, cellular_->home_provider().GetName()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 605 | EXPECT_EQ(kOperatorName, capability_->spn_); |
| 606 | } |
| 607 | |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 608 | MATCHER_P(SizeIs, value, "") { |
| 609 | return static_cast<size_t>(value) == arg.size(); |
| 610 | } |
| 611 | |
| 612 | // Validates that OnScanReply does not crash with a null callback. |
| 613 | TEST_F(CellularCapabilityUniversalTest, ScanWithNullCallback) { |
| 614 | Error error; |
| 615 | EXPECT_CALL(*modem_3gpp_proxy_, Scan(_, _, CellularCapability::kTimeoutScan)) |
| 616 | .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeScan)); |
| 617 | EXPECT_CALL(*device_adaptor_, |
| 618 | EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 619 | SizeIs(0))); |
| 620 | Set3gppProxy(); |
| 621 | capability_->Scan(&error, ResultCallback()); |
| 622 | EXPECT_TRUE(error.IsSuccess()); |
| 623 | } |
| 624 | |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 625 | // Validates that the scanning property is updated |
| 626 | TEST_F(CellularCapabilityUniversalTest, Scan) { |
| 627 | Error error; |
| 628 | |
| 629 | EXPECT_CALL(*modem_3gpp_proxy_, Scan(_, _, CellularCapability::kTimeoutScan)) |
| 630 | .WillRepeatedly(SaveArg<1>(&scan_callback_)); |
| 631 | EXPECT_CALL(*device_adaptor_, |
| 632 | EmitBoolChanged(flimflam::kScanningProperty, true)); |
| 633 | Set3gppProxy(); |
| 634 | capability_->Scan(&error, ResultCallback()); |
| 635 | EXPECT_TRUE(capability_->scanning_); |
| 636 | |
| 637 | // Simulate the completion of the scan with 2 networks in the results. |
| 638 | EXPECT_CALL(*device_adaptor_, |
| 639 | EmitBoolChanged(flimflam::kScanningProperty, false)); |
| 640 | EXPECT_CALL(*device_adaptor_, |
| 641 | EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 642 | SizeIs(2))); |
| 643 | vector<DBusPropertiesMap> results; |
| 644 | const char kScanID0[] = "testID0"; |
| 645 | const char kScanID1[] = "testID1"; |
| 646 | results.push_back(DBusPropertiesMap()); |
| 647 | results[0][CellularCapabilityUniversal::kOperatorLongProperty]. |
| 648 | writer().append_string(kScanID0); |
| 649 | results.push_back(DBusPropertiesMap()); |
| 650 | results[1][CellularCapabilityUniversal::kOperatorLongProperty]. |
| 651 | writer().append_string(kScanID1); |
| 652 | scan_callback_.Run(results, error); |
| 653 | EXPECT_FALSE(capability_->scanning_); |
| 654 | |
| 655 | // Simulate the completion of the scan with no networks in the results. |
| 656 | EXPECT_CALL(*device_adaptor_, |
| 657 | EmitBoolChanged(flimflam::kScanningProperty, true)); |
| 658 | capability_->Scan(&error, ResultCallback()); |
| 659 | EXPECT_TRUE(capability_->scanning_); |
| 660 | EXPECT_CALL(*device_adaptor_, |
| 661 | EmitBoolChanged(flimflam::kScanningProperty, false)); |
| 662 | EXPECT_CALL(*device_adaptor_, |
| 663 | EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 664 | SizeIs(0))); |
| 665 | scan_callback_.Run(vector<DBusPropertiesMap>(), Error()); |
| 666 | EXPECT_FALSE(capability_->scanning_); |
| 667 | } |
| 668 | |
| 669 | // Validates expected property updates when scan fails |
| 670 | TEST_F(CellularCapabilityUniversalTest, ScanFailure) { |
| 671 | Error error; |
| 672 | |
| 673 | // Test immediate error |
| 674 | { |
| 675 | InSequence seq; |
| 676 | EXPECT_CALL(*modem_3gpp_proxy_, |
| 677 | Scan(_, _, CellularCapability::kTimeoutScan)) |
| 678 | .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::ScanError)); |
| 679 | EXPECT_CALL(*modem_3gpp_proxy_, |
| 680 | Scan(_, _, CellularCapability::kTimeoutScan)) |
| 681 | .WillOnce(SaveArg<1>(&scan_callback_)); |
| 682 | } |
| 683 | Set3gppProxy(); |
| 684 | capability_->Scan(&error, ResultCallback()); |
| 685 | EXPECT_FALSE(capability_->scanning_); |
| 686 | EXPECT_TRUE(error.IsFailure()); |
| 687 | |
| 688 | // Initiate a scan |
| 689 | error.Populate(Error::kSuccess); |
| 690 | EXPECT_CALL(*device_adaptor_, |
| 691 | EmitBoolChanged(flimflam::kScanningProperty, true)); |
| 692 | capability_->Scan(&error, ResultCallback()); |
| 693 | EXPECT_TRUE(capability_->scanning_); |
| 694 | EXPECT_TRUE(error.IsSuccess()); |
| 695 | |
| 696 | // Validate that error is returned if Scan is called while already scanning. |
| 697 | capability_->Scan(&error, ResultCallback()); |
| 698 | EXPECT_TRUE(capability_->scanning_); |
| 699 | EXPECT_TRUE(error.IsFailure()); |
| 700 | |
| 701 | // Validate that signals are emitted even if an error is reported. |
| 702 | capability_->found_networks_.clear(); |
| 703 | capability_->found_networks_.push_back(Stringmap()); |
| 704 | EXPECT_CALL(*device_adaptor_, |
| 705 | EmitBoolChanged(flimflam::kScanningProperty, false)); |
| 706 | EXPECT_CALL(*device_adaptor_, |
| 707 | EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 708 | SizeIs(0))); |
| 709 | vector<DBusPropertiesMap> results; |
| 710 | scan_callback_.Run(results, Error(Error::kOperationFailed)); |
| 711 | EXPECT_FALSE(capability_->scanning_); |
| 712 | } |
| 713 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 714 | // Validates expected behavior of Connect function |
| 715 | TEST_F(CellularCapabilityUniversalTest, Connect) { |
| 716 | mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get(); |
| 717 | SetSimpleProxy(); |
| 718 | Error error; |
| 719 | DBusPropertiesMap properties; |
| 720 | capability_->apn_try_list_.clear(); |
| 721 | ResultCallback callback = |
| 722 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 723 | DBus::Path bearer("/foo"); |
| 724 | |
| 725 | // Test connect failures |
| 726 | EXPECT_CALL(*modem_simple_proxy, Connect(_, _, _, _)) |
| 727 | .WillOnce(SaveArg<2>(&connect_callback_)); |
| 728 | capability_->Connect(properties, &error, callback); |
| 729 | EXPECT_TRUE(error.IsSuccess()); |
| 730 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 731 | EXPECT_CALL(*service_, ClearLastGoodApn()); |
| 732 | connect_callback_.Run(bearer, Error(Error::kOperationFailed)); |
| 733 | |
| 734 | // Test connect success |
| 735 | EXPECT_CALL(*modem_simple_proxy, Connect(_, _, _, _)) |
| 736 | .WillOnce(SaveArg<2>(&connect_callback_)); |
| 737 | capability_->Connect(properties, &error, callback); |
| 738 | EXPECT_TRUE(error.IsSuccess()); |
| 739 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 740 | connect_callback_.Run(bearer, Error(Error::kSuccess)); |
Jason Glasgow | 7234ec3 | 2012-05-23 16:01:21 -0400 | [diff] [blame] | 741 | |
| 742 | // Test connect failures without a service. Make sure that shill |
| 743 | // does not crash if the connect failed and there is no |
| 744 | // CellularService object. This can happen if the modem is enabled |
| 745 | // and then quickly disabled. |
| 746 | cellular_->service_ = NULL; |
| 747 | EXPECT_FALSE(capability_->cellular()->service()); |
| 748 | EXPECT_CALL(*modem_simple_proxy, Connect(_, _, _, _)) |
| 749 | .WillOnce(SaveArg<2>(&connect_callback_)); |
| 750 | capability_->Connect(properties, &error, callback); |
| 751 | EXPECT_TRUE(error.IsSuccess()); |
| 752 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 753 | connect_callback_.Run(bearer, Error(Error::kOperationFailed)); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | // Validates Connect iterates over APNs |
| 757 | TEST_F(CellularCapabilityUniversalTest, ConnectApns) { |
| 758 | mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get(); |
| 759 | SetSimpleProxy(); |
| 760 | Error error; |
| 761 | DBusPropertiesMap properties; |
| 762 | capability_->apn_try_list_.clear(); |
| 763 | ResultCallback callback = |
| 764 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 765 | DBus::Path bearer("/bearer0"); |
| 766 | |
| 767 | const char apn_name_foo[] = "foo"; |
| 768 | const char apn_name_bar[] = "bar"; |
| 769 | EXPECT_CALL(*modem_simple_proxy, Connect(HasApn(apn_name_foo), _, _, _)) |
| 770 | .WillOnce(SaveArg<2>(&connect_callback_)); |
| 771 | Stringmap apn1; |
| 772 | apn1[flimflam::kApnProperty] = apn_name_foo; |
| 773 | capability_->apn_try_list_.push_back(apn1); |
| 774 | Stringmap apn2; |
| 775 | apn2[flimflam::kApnProperty] = apn_name_bar; |
| 776 | capability_->apn_try_list_.push_back(apn2); |
| 777 | capability_->FillConnectPropertyMap(&properties); |
| 778 | capability_->Connect(properties, &error, callback); |
| 779 | EXPECT_TRUE(error.IsSuccess()); |
| 780 | |
| 781 | EXPECT_CALL(*modem_simple_proxy, Connect(HasApn(apn_name_bar), _, _, _)) |
| 782 | .WillOnce(SaveArg<2>(&connect_callback_)); |
| 783 | EXPECT_CALL(*service_, ClearLastGoodApn()); |
| 784 | connect_callback_.Run(bearer, Error(Error::kInvalidApn)); |
| 785 | |
| 786 | EXPECT_CALL(*service_, SetLastGoodApn(apn2)); |
| 787 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 788 | connect_callback_.Run(bearer, Error(Error::kSuccess)); |
| 789 | } |
| 790 | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 791 | // Validates GetTypeString and AccessTechnologyToTechnologyFamily |
| 792 | TEST_F(CellularCapabilityUniversalTest, GetTypeString) { |
| 793 | const int gsm_technologies[] = { |
| 794 | MM_MODEM_ACCESS_TECHNOLOGY_LTE, |
| 795 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS, |
| 796 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA, |
| 797 | MM_MODEM_ACCESS_TECHNOLOGY_HSUPA, |
| 798 | MM_MODEM_ACCESS_TECHNOLOGY_HSDPA, |
| 799 | MM_MODEM_ACCESS_TECHNOLOGY_UMTS, |
| 800 | MM_MODEM_ACCESS_TECHNOLOGY_EDGE, |
| 801 | MM_MODEM_ACCESS_TECHNOLOGY_GPRS, |
| 802 | MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT, |
| 803 | MM_MODEM_ACCESS_TECHNOLOGY_GSM, |
| 804 | MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 805 | MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 806 | MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA, |
| 807 | MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA, |
| 808 | MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB, |
| 809 | MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB, |
| 810 | MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT, |
| 811 | }; |
| 812 | for(size_t i = 0; i < arraysize(gsm_technologies); ++i) { |
| 813 | capability_->access_technologies_ = gsm_technologies[i]; |
| 814 | ASSERT_EQ(capability_->GetTypeString(), flimflam::kTechnologyFamilyGsm); |
| 815 | } |
| 816 | const int cdma_technologies[] = { |
| 817 | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 818 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA, |
| 819 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 820 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB, |
| 821 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 822 | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT, |
| 823 | }; |
| 824 | for(size_t i = 0; i < arraysize(cdma_technologies); ++i) { |
| 825 | capability_->access_technologies_ = cdma_technologies[i]; |
| 826 | ASSERT_EQ(capability_->GetTypeString(), flimflam::kTechnologyFamilyCdma); |
| 827 | } |
| 828 | capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; |
| 829 | ASSERT_EQ(capability_->GetTypeString(), ""); |
| 830 | } |
| 831 | |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 832 | TEST_F(CellularCapabilityUniversalTest, AllowRoaming) { |
| 833 | EXPECT_FALSE(cellular_->allow_roaming_); |
| 834 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
| 835 | EXPECT_FALSE(capability_->AllowRoaming()); |
| 836 | capability_->provider_requires_roaming_ = true; |
| 837 | EXPECT_TRUE(capability_->AllowRoaming()); |
| 838 | capability_->provider_requires_roaming_ = false; |
| 839 | cellular_->allow_roaming_ = true; |
| 840 | EXPECT_TRUE(capability_->AllowRoaming()); |
| 841 | } |
| 842 | |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 843 | TEST_F(CellularCapabilityUniversalTest, SetHomeProvider) { |
| 844 | static const char kTestCarrier[] = "The Cellular Carrier"; |
| 845 | static const char kCountry[] = "us"; |
| 846 | static const char kCode[] = "310160"; |
| 847 | capability_->imsi_ = "310240123456789"; |
| 848 | |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 849 | EXPECT_FALSE(capability_->home_provider_); |
| 850 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
| 851 | |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 852 | capability_->SetHomeProvider(); // No mobile provider DB available. |
| 853 | EXPECT_TRUE(cellular_->home_provider().GetName().empty()); |
| 854 | EXPECT_TRUE(cellular_->home_provider().GetCountry().empty()); |
| 855 | EXPECT_TRUE(cellular_->home_provider().GetCode().empty()); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 856 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 857 | |
| 858 | InitProviderDB(); |
| 859 | capability_->SetHomeProvider(); |
| 860 | EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName()); |
| 861 | EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry()); |
| 862 | EXPECT_EQ(kCode, cellular_->home_provider().GetCode()); |
| 863 | EXPECT_EQ(4, capability_->apn_list_.size()); |
| 864 | ASSERT_TRUE(capability_->home_provider_); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 865 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 866 | |
| 867 | Cellular::Operator oper; |
| 868 | cellular_->set_home_provider(oper); |
| 869 | capability_->spn_ = kTestCarrier; |
| 870 | capability_->SetHomeProvider(); |
| 871 | EXPECT_EQ(kTestCarrier, cellular_->home_provider().GetName()); |
| 872 | EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry()); |
| 873 | EXPECT_EQ(kCode, cellular_->home_provider().GetCode()); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 874 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 875 | |
| 876 | static const char kCubic[] = "Cubic"; |
| 877 | capability_->spn_ = kCubic; |
| 878 | capability_->SetHomeProvider(); |
| 879 | EXPECT_EQ(kCubic, cellular_->home_provider().GetName()); |
| 880 | EXPECT_EQ("", cellular_->home_provider().GetCode()); |
| 881 | ASSERT_TRUE(capability_->home_provider_); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 882 | EXPECT_TRUE(capability_->provider_requires_roaming_); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 883 | |
| 884 | static const char kCUBIC[] = "CUBIC"; |
| 885 | capability_->spn_ = kCUBIC; |
| 886 | capability_->home_provider_ = NULL; |
| 887 | capability_->SetHomeProvider(); |
| 888 | EXPECT_EQ(kCUBIC, cellular_->home_provider().GetName()); |
| 889 | EXPECT_EQ("", cellular_->home_provider().GetCode()); |
| 890 | ASSERT_TRUE(capability_->home_provider_); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 891 | EXPECT_TRUE(capability_->provider_requires_roaming_); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 892 | } |
| 893 | |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 894 | TEST_F(CellularCapabilityUniversalTest, UpdateOperatorInfo) { |
| 895 | static const char kOperatorName[] = "Swisscom"; |
| 896 | InitProviderDB(); |
| 897 | capability_->serving_operator_.SetCode("22801"); |
| 898 | SetService(); |
| 899 | capability_->UpdateOperatorInfo(); |
| 900 | EXPECT_EQ(kOperatorName, capability_->serving_operator_.GetName()); |
| 901 | EXPECT_EQ("ch", capability_->serving_operator_.GetCountry()); |
| 902 | EXPECT_EQ(kOperatorName, cellular_->service()->serving_operator().GetName()); |
| 903 | |
| 904 | static const char kTestOperator[] = "Testcom"; |
| 905 | capability_->serving_operator_.SetName(kTestOperator); |
| 906 | capability_->serving_operator_.SetCountry(""); |
| 907 | capability_->UpdateOperatorInfo(); |
| 908 | EXPECT_EQ(kTestOperator, capability_->serving_operator_.GetName()); |
| 909 | EXPECT_EQ("ch", capability_->serving_operator_.GetCountry()); |
| 910 | EXPECT_EQ(kTestOperator, cellular_->service()->serving_operator().GetName()); |
| 911 | } |
| 912 | |
| 913 | TEST_F(CellularCapabilityUniversalTest, CreateFriendlyServiceName) { |
| 914 | CellularCapabilityUniversal::friendly_service_name_id_ = 0; |
| 915 | EXPECT_EQ("GSMNetwork0", capability_->CreateFriendlyServiceName()); |
| 916 | EXPECT_EQ("GSMNetwork1", capability_->CreateFriendlyServiceName()); |
| 917 | |
| 918 | capability_->serving_operator_.SetCode("1234"); |
| 919 | EXPECT_EQ("cellular_1234", capability_->CreateFriendlyServiceName()); |
| 920 | |
| 921 | static const char kHomeProvider[] = "The GSM Home Provider"; |
| 922 | cellular_->home_provider_.SetName(kHomeProvider); |
| 923 | EXPECT_EQ("cellular_1234", capability_->CreateFriendlyServiceName()); |
| 924 | capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_HOME; |
| 925 | EXPECT_EQ(kHomeProvider, capability_->CreateFriendlyServiceName()); |
| 926 | |
| 927 | static const char kTestOperator[] = "A GSM Operator"; |
| 928 | capability_->serving_operator_.SetName(kTestOperator); |
| 929 | EXPECT_EQ(kTestOperator, capability_->CreateFriendlyServiceName()); |
| 930 | |
| 931 | capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING; |
| 932 | EXPECT_EQ(StringPrintf("%s | %s", kHomeProvider, kTestOperator), |
| 933 | capability_->CreateFriendlyServiceName()); |
| 934 | } |
| 935 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 936 | } // namespace shill |