Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 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_gsm.h" |
| 6 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 10 | #include <base/bind.h> |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 11 | #include <base/strings/stringprintf.h> |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 12 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 13 | #include <mm/mm-modem.h> |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 14 | |
| 15 | #include "shill/cellular.h" |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 16 | #include "shill/cellular_service.h" |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 17 | #include "shill/error.h" |
| 18 | #include "shill/event_dispatcher.h" |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 19 | #include "shill/mock_adaptors.h" |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 20 | #include "shill/mock_log.h" |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 21 | #include "shill/mock_mobile_operator_info.h" |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 22 | #include "shill/mock_modem_gsm_card_proxy.h" |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 23 | #include "shill/mock_modem_gsm_network_proxy.h" |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 24 | #include "shill/mock_modem_info.h" |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 25 | #include "shill/mock_modem_proxy.h" |
| 26 | #include "shill/mock_modem_simple_proxy.h" |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 27 | #include "shill/mock_profile.h" |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 28 | #include "shill/proxy_factory.h" |
Ben Chan | be277dd | 2014-02-05 17:26:47 -0800 | [diff] [blame] | 29 | #include "shill/testing.h" |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 30 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 31 | using base::Bind; |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 32 | using base::StringPrintf; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 33 | using base::Unretained; |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 34 | using std::string; |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 35 | using std::vector; |
Darin Petkov | e5bc2cb | 2011-12-07 14:47:32 +0100 | [diff] [blame] | 36 | using testing::_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 37 | using testing::Invoke; |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 38 | using testing::NiceMock; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 39 | using testing::Return; |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 40 | using testing::SaveArg; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 41 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 42 | namespace shill { |
| 43 | |
| 44 | class CellularCapabilityGSMTest : public testing::Test { |
| 45 | public: |
| 46 | CellularCapabilityGSMTest() |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 47 | : modem_info_(NULL, &dispatcher_, NULL, NULL, NULL), |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 48 | create_card_proxy_from_factory_(false), |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 49 | proxy_(new MockModemProxy()), |
| 50 | simple_proxy_(new MockModemSimpleProxy()), |
| 51 | card_proxy_(new MockModemGSMCardProxy()), |
| 52 | network_proxy_(new MockModemGSMNetworkProxy()), |
| 53 | proxy_factory_(this), |
| 54 | capability_(NULL), |
| 55 | device_adaptor_(NULL), |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 56 | cellular_(new Cellular(&modem_info_, |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 57 | "", |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 58 | kAddress, |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 59 | 0, |
| 60 | Cellular::kTypeGSM, |
| 61 | "", |
| 62 | "", |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 63 | "", |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 64 | &proxy_factory_)), |
| 65 | mock_home_provider_info_(NULL), |
| 66 | mock_serving_operator_info_(NULL) { |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 67 | modem_info_.metrics()->RegisterDevice(cellular_->interface_index(), |
| 68 | Technology::kCellular); |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 69 | } |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 70 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 71 | virtual ~CellularCapabilityGSMTest() { |
| 72 | cellular_->service_ = NULL; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 73 | capability_ = NULL; |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 74 | device_adaptor_ = NULL; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | virtual void SetUp() { |
| 78 | capability_ = |
| 79 | dynamic_cast<CellularCapabilityGSM *>(cellular_->capability_.get()); |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 80 | device_adaptor_ = |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 81 | dynamic_cast<DeviceMockAdaptor *>(cellular_->adaptor()); |
| 82 | } |
| 83 | |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 84 | void InvokeEnable(bool enable, Error *error, |
| 85 | const ResultCallback &callback, int timeout) { |
| 86 | callback.Run(Error()); |
| 87 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 88 | void InvokeGetIMEI(Error *error, const GSMIdentifierCallback &callback, |
| 89 | int timeout) { |
| 90 | callback.Run(kIMEI, Error()); |
| 91 | } |
| 92 | void InvokeGetIMSI(Error *error, const GSMIdentifierCallback &callback, |
| 93 | int timeout) { |
| 94 | callback.Run(kIMSI, Error()); |
| 95 | } |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 96 | void InvokeGetIMSIFails(Error *error, const GSMIdentifierCallback &callback, |
| 97 | int timeout) { |
| 98 | callback.Run("", Error(Error::kOperationFailed)); |
| 99 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 100 | void InvokeGetMSISDN(Error *error, const GSMIdentifierCallback &callback, |
| 101 | int timeout) { |
| 102 | callback.Run(kMSISDN, Error()); |
| 103 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 104 | void InvokeGetMSISDNFail(Error *error, const GSMIdentifierCallback &callback, |
| 105 | int timeout) { |
| 106 | callback.Run("", Error(Error::kOperationFailed)); |
| 107 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 108 | void InvokeGetSPN(Error *error, const GSMIdentifierCallback &callback, |
| 109 | int timeout) { |
| 110 | callback.Run(kTestCarrier, Error()); |
| 111 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 112 | void InvokeGetSPNFail(Error *error, const GSMIdentifierCallback &callback, |
| 113 | int timeout) { |
| 114 | callback.Run("", Error(Error::kOperationFailed)); |
| 115 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 116 | void InvokeGetSignalQuality(Error *error, |
| 117 | const SignalQualityCallback &callback, |
| 118 | int timeout) { |
| 119 | callback.Run(kStrength, Error()); |
| 120 | } |
| 121 | void InvokeGetRegistrationInfo(Error *error, |
| 122 | const RegistrationInfoCallback &callback, |
| 123 | int timeout) { |
| 124 | callback.Run(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME, |
| 125 | kTestNetwork, kTestCarrier, Error()); |
| 126 | } |
| 127 | void InvokeRegister(const string &network_id, |
| 128 | Error *error, |
| 129 | const ResultCallback &callback, |
| 130 | int timeout) { |
| 131 | callback.Run(Error()); |
| 132 | } |
| 133 | void InvokeEnablePIN(const string &pin, bool enable, |
| 134 | Error *error, const ResultCallback &callback, |
| 135 | int timeout) { |
| 136 | callback.Run(Error()); |
| 137 | } |
| 138 | void InvokeSendPIN(const string &pin, Error *error, |
| 139 | const ResultCallback &callback, int timeout) { |
| 140 | callback.Run(Error()); |
| 141 | } |
| 142 | void InvokeSendPUK(const string &puk, const string &pin, Error *error, |
| 143 | const ResultCallback &callback, int timeout) { |
| 144 | callback.Run(Error()); |
| 145 | } |
| 146 | void InvokeChangePIN(const string &old_pin, const string &pin, Error *error, |
| 147 | const ResultCallback &callback, int timeout) { |
| 148 | callback.Run(Error()); |
| 149 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 150 | void InvokeGetModemStatus(Error *error, |
| 151 | const DBusPropertyMapCallback &callback, |
| 152 | int timeout) { |
| 153 | DBusPropertiesMap props; |
| 154 | callback.Run(props, Error()); |
| 155 | } |
| 156 | void InvokeGetModemInfo(Error *error, const ModemInfoCallback &callback, |
| 157 | int timeout) { |
| 158 | ModemHardwareInfo info; |
| 159 | callback.Run(info, Error()); |
| 160 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 161 | |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 162 | void InvokeConnectFail(DBusPropertiesMap props, Error *error, |
| 163 | const ResultCallback &callback, int timeout) { |
| 164 | callback.Run(Error(Error::kOperationFailed)); |
| 165 | } |
| 166 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 167 | MOCK_METHOD1(TestCallback, void(const Error &error)); |
| 168 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 169 | protected: |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 170 | static const char kAddress[]; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 171 | static const char kTestMobileProviderDBPath[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 172 | static const char kTestNetwork[]; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 173 | static const char kTestCarrier[]; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 174 | static const char kPIN[]; |
| 175 | static const char kPUK[]; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 176 | static const char kIMEI[]; |
| 177 | static const char kIMSI[]; |
| 178 | static const char kMSISDN[]; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 179 | static const int kStrength; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 180 | |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 181 | class TestProxyFactory : public ProxyFactory { |
| 182 | public: |
| 183 | explicit TestProxyFactory(CellularCapabilityGSMTest *test) : test_(test) {} |
| 184 | |
| 185 | virtual ModemProxyInterface *CreateModemProxy( |
| 186 | const string &/*path*/, |
| 187 | const string &/*service*/) { |
| 188 | return test_->proxy_.release(); |
| 189 | } |
| 190 | |
| 191 | virtual ModemSimpleProxyInterface *CreateModemSimpleProxy( |
| 192 | const string &/*path*/, |
| 193 | const string &/*service*/) { |
| 194 | return test_->simple_proxy_.release(); |
| 195 | } |
| 196 | |
| 197 | virtual ModemGSMCardProxyInterface *CreateModemGSMCardProxy( |
| 198 | const string &/*path*/, |
| 199 | const string &/*service*/) { |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 200 | // TODO(benchan): This code conditionally returns a NULL pointer to avoid |
| 201 | // CellularCapabilityGSM::InitProperties (and thus |
| 202 | // CellularCapabilityGSM::GetIMSI) from being called during the |
| 203 | // construction. Remove this workaround after refactoring the tests. |
| 204 | return test_->create_card_proxy_from_factory_ ? |
| 205 | test_->card_proxy_.release() : NULL; |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | virtual ModemGSMNetworkProxyInterface *CreateModemGSMNetworkProxy( |
| 209 | const string &/*path*/, |
| 210 | const string &/*service*/) { |
| 211 | return test_->network_proxy_.release(); |
| 212 | } |
| 213 | |
| 214 | private: |
| 215 | CellularCapabilityGSMTest *test_; |
| 216 | }; |
| 217 | |
| 218 | void SetProxy() { |
| 219 | capability_->proxy_.reset(proxy_.release()); |
| 220 | } |
| 221 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 222 | void SetCardProxy() { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 223 | capability_->card_proxy_.reset(card_proxy_.release()); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 224 | } |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 225 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 226 | void SetNetworkProxy() { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 227 | capability_->network_proxy_.reset(network_proxy_.release()); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 228 | } |
| 229 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 230 | void SetAccessTechnology(uint32_t technology) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 231 | capability_->access_technology_ = technology; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 232 | } |
| 233 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 234 | void SetRegistrationState(uint32_t state) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 235 | capability_->registration_state_ = state; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 238 | void CreateService() { |
| 239 | // The following constants are never directly accessed by the tests. |
| 240 | const char kStorageIdentifier[] = "default_test_storage_id"; |
| 241 | const char kFriendlyServiceName[] = "default_test_service_name"; |
| 242 | const char kOperatorCode[] = "10010"; |
| 243 | const char kOperatorName[] = "default_test_operator_name"; |
| 244 | const char kOperatorCountry[] = "us"; |
| 245 | |
| 246 | // Simulate all the side-effects of Cellular::CreateService |
| 247 | auto service = new CellularService(&modem_info_, cellular_); |
| 248 | service->SetStorageIdentifier(kStorageIdentifier); |
| 249 | service->SetFriendlyName(kFriendlyServiceName); |
| 250 | |
| 251 | Cellular::Operator oper; |
| 252 | oper.SetCode(kOperatorCode); |
| 253 | oper.SetName(kOperatorName); |
| 254 | oper.SetCountry(kOperatorCountry); |
| 255 | |
| 256 | service->SetServingOperator(oper); |
| 257 | |
| 258 | cellular_->set_home_provider(oper); |
| 259 | cellular_->service_ = service; |
| 260 | } |
| 261 | |
| 262 | void SetMockMobileOperatorInfoObjects() { |
| 263 | CHECK(!mock_home_provider_info_); |
| 264 | CHECK(!mock_serving_operator_info_); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 265 | mock_home_provider_info_ = |
| 266 | new MockMobileOperatorInfo(&dispatcher_, "HomeProvider"); |
| 267 | mock_serving_operator_info_ = |
| 268 | new MockMobileOperatorInfo(&dispatcher_, "ServingOperator"); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 269 | cellular_->set_home_provider_info(mock_home_provider_info_); |
| 270 | cellular_->set_serving_operator_info(mock_serving_operator_info_); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 271 | } |
| 272 | |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 273 | void SetupCommonProxiesExpectations() { |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 274 | EXPECT_CALL(*proxy_, set_state_changed_callback(_)); |
| 275 | EXPECT_CALL(*network_proxy_, set_signal_quality_callback(_)); |
| 276 | EXPECT_CALL(*network_proxy_, set_network_mode_callback(_)); |
| 277 | EXPECT_CALL(*network_proxy_, set_registration_info_callback(_)); |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void SetupCommonStartModemExpectations() { |
| 281 | SetupCommonProxiesExpectations(); |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 282 | |
| 283 | EXPECT_CALL(*proxy_, Enable(_, _, _, CellularCapability::kTimeoutEnable)) |
| 284 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeEnable)); |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 285 | EXPECT_CALL(*card_proxy_, |
| 286 | GetIMEI(_, _, CellularCapability::kTimeoutDefault)) |
| 287 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetIMEI)); |
| 288 | EXPECT_CALL(*card_proxy_, |
| 289 | GetIMSI(_, _, CellularCapability::kTimeoutDefault)) |
| 290 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetIMSI)); |
| 291 | EXPECT_CALL(*network_proxy_, AccessTechnology()); |
| 292 | EXPECT_CALL(*card_proxy_, EnabledFacilityLocks()); |
| 293 | EXPECT_CALL(*proxy_, |
| 294 | GetModemInfo(_, _, CellularCapability::kTimeoutDefault)) |
| 295 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetModemInfo)); |
| 296 | EXPECT_CALL(*network_proxy_, |
| 297 | GetRegistrationInfo(_, _, CellularCapability::kTimeoutDefault)); |
| 298 | EXPECT_CALL(*network_proxy_, |
| 299 | GetSignalQuality(_, _, CellularCapability::kTimeoutDefault)); |
| 300 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 301 | } |
| 302 | |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 303 | void InitProxies() { |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 304 | AllowCreateCardProxyFromFactory(); |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 305 | capability_->InitProxies(); |
| 306 | } |
| 307 | |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 308 | void AllowCreateCardProxyFromFactory() { |
| 309 | create_card_proxy_from_factory_ = true; |
| 310 | } |
| 311 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 312 | EventDispatcher dispatcher_; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 313 | MockModemInfo modem_info_; |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 314 | bool create_card_proxy_from_factory_; |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 315 | scoped_ptr<MockModemProxy> proxy_; |
| 316 | scoped_ptr<MockModemSimpleProxy> simple_proxy_; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 317 | scoped_ptr<MockModemGSMCardProxy> card_proxy_; |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 318 | scoped_ptr<MockModemGSMNetworkProxy> network_proxy_; |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 319 | TestProxyFactory proxy_factory_; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 320 | CellularCapabilityGSM *capability_; // Owned by |cellular_|. |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 321 | DeviceMockAdaptor *device_adaptor_; // Owned by |cellular_|. |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 322 | CellularRefPtr cellular_; |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 323 | |
| 324 | // Set when required and passed to |cellular_|. Owned by |cellular_|. |
| 325 | MockMobileOperatorInfo *mock_home_provider_info_; |
| 326 | MockMobileOperatorInfo *mock_serving_operator_info_; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 327 | }; |
| 328 | |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 329 | const char CellularCapabilityGSMTest::kAddress[] = "1122334455"; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 330 | const char CellularCapabilityGSMTest::kTestMobileProviderDBPath[] = |
| 331 | "provider_db_unittest.bfd"; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 332 | const char CellularCapabilityGSMTest::kTestCarrier[] = "The Cellular Carrier"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 333 | const char CellularCapabilityGSMTest::kTestNetwork[] = "310555"; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 334 | const char CellularCapabilityGSMTest::kPIN[] = "9876"; |
| 335 | const char CellularCapabilityGSMTest::kPUK[] = "8765"; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 336 | const char CellularCapabilityGSMTest::kIMEI[] = "987654321098765"; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 337 | const char CellularCapabilityGSMTest::kIMSI[] = "310150123456789"; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 338 | const char CellularCapabilityGSMTest::kMSISDN[] = "12345678901"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 339 | const int CellularCapabilityGSMTest::kStrength = 80; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 340 | |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 341 | TEST_F(CellularCapabilityGSMTest, PropertyStore) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 342 | EXPECT_TRUE(cellular_->store().Contains(kSIMLockStatusProperty)); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 343 | } |
| 344 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 345 | TEST_F(CellularCapabilityGSMTest, GetIMEI) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 346 | EXPECT_CALL(*card_proxy_, GetIMEI(_, _, CellularCapability::kTimeoutDefault)) |
| 347 | .WillOnce(Invoke(this, |
| 348 | &CellularCapabilityGSMTest::InvokeGetIMEI)); |
| 349 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 350 | SetCardProxy(); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 351 | ASSERT_TRUE(cellular_->imei().empty()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 352 | capability_->GetIMEI(Bind(&CellularCapabilityGSMTest::TestCallback, |
| 353 | Unretained(this))); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 354 | EXPECT_EQ(kIMEI, cellular_->imei()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | TEST_F(CellularCapabilityGSMTest, GetIMSI) { |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 358 | SetMockMobileOperatorInfoObjects(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 359 | EXPECT_CALL(*card_proxy_, GetIMSI(_, _, CellularCapability::kTimeoutDefault)) |
| 360 | .WillOnce(Invoke(this, |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 361 | &CellularCapabilityGSMTest::InvokeGetIMSI)); |
| 362 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 363 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 364 | ResultCallback callback = Bind(&CellularCapabilityGSMTest::TestCallback, |
| 365 | Unretained(this)); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 366 | EXPECT_TRUE(cellular_->imsi().empty()); |
| 367 | EXPECT_FALSE(cellular_->sim_present()); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 368 | EXPECT_CALL(*mock_home_provider_info_, UpdateIMSI(kIMSI)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 369 | capability_->GetIMSI(callback); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 370 | EXPECT_EQ(kIMSI, cellular_->imsi()); |
| 371 | EXPECT_TRUE(cellular_->sim_present()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 372 | } |
| 373 | |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 374 | // In this test, the call to the proxy's GetIMSI() will always indicate failure, |
| 375 | // which will cause the retry logic to call the proxy again a number of times. |
| 376 | // Eventually, the retries expire. |
| 377 | TEST_F(CellularCapabilityGSMTest, GetIMSIFails) { |
| 378 | ScopedMockLog log; |
Liam McLoughlin | ef342b4 | 2013-09-13 21:05:36 +0100 | [diff] [blame] | 379 | EXPECT_CALL(log, Log(logging::LOG_INFO, |
| 380 | ::testing::EndsWith("cellular_capability_gsm.cc"), |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 381 | ::testing::StartsWith("GetIMSI failed - "))); |
| 382 | EXPECT_CALL(*card_proxy_, GetIMSI(_, _, CellularCapability::kTimeoutDefault)) |
Arman Uguray | 29505ec | 2013-09-12 20:37:53 -0700 | [diff] [blame] | 383 | .Times(CellularCapabilityGSM::kGetIMSIRetryLimit + 2) |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 384 | .WillRepeatedly(Invoke(this, |
| 385 | &CellularCapabilityGSMTest::InvokeGetIMSIFails)); |
Arman Uguray | 29505ec | 2013-09-12 20:37:53 -0700 | [diff] [blame] | 386 | EXPECT_CALL(*this, TestCallback(IsFailure())).Times(2); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 387 | SetCardProxy(); |
| 388 | ResultCallback callback = Bind(&CellularCapabilityGSMTest::TestCallback, |
| 389 | Unretained(this)); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 390 | EXPECT_TRUE(cellular_->imsi().empty()); |
| 391 | EXPECT_FALSE(cellular_->sim_present()); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 392 | |
Arman Uguray | 29505ec | 2013-09-12 20:37:53 -0700 | [diff] [blame] | 393 | capability_->sim_lock_status_.lock_type = "sim-pin"; |
| 394 | capability_->GetIMSI(callback); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 395 | EXPECT_TRUE(cellular_->imsi().empty()); |
| 396 | EXPECT_TRUE(cellular_->sim_present()); |
Arman Uguray | 29505ec | 2013-09-12 20:37:53 -0700 | [diff] [blame] | 397 | |
| 398 | capability_->sim_lock_status_.lock_type.clear(); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 399 | cellular_->set_sim_present(false); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 400 | capability_->get_imsi_retries_ = 0; |
| 401 | EXPECT_EQ(CellularCapabilityGSM::kGetIMSIRetryDelayMilliseconds, |
| 402 | capability_->get_imsi_retry_delay_milliseconds_); |
| 403 | |
| 404 | // Set the delay to zero to speed up the test. |
| 405 | capability_->get_imsi_retry_delay_milliseconds_ = 0; |
| 406 | capability_->GetIMSI(callback); |
| 407 | for (int i = 0; i < CellularCapabilityGSM::kGetIMSIRetryLimit; ++i) { |
| 408 | dispatcher_.DispatchPendingEvents(); |
| 409 | } |
| 410 | EXPECT_EQ(CellularCapabilityGSM::kGetIMSIRetryLimit + 1, |
| 411 | capability_->get_imsi_retries_); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 412 | EXPECT_TRUE(cellular_->imsi().empty()); |
| 413 | EXPECT_FALSE(cellular_->sim_present()); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 416 | TEST_F(CellularCapabilityGSMTest, GetMSISDN) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 417 | EXPECT_CALL(*card_proxy_, GetMSISDN(_, _, |
| 418 | CellularCapability::kTimeoutDefault)) |
| 419 | .WillOnce(Invoke(this, |
| 420 | &CellularCapabilityGSMTest::InvokeGetMSISDN)); |
| 421 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 422 | SetCardProxy(); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 423 | ASSERT_TRUE(cellular_->mdn().empty()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 424 | capability_->GetMSISDN(Bind(&CellularCapabilityGSMTest::TestCallback, |
| 425 | Unretained(this))); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 426 | EXPECT_EQ(kMSISDN, cellular_->mdn()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | TEST_F(CellularCapabilityGSMTest, GetSPN) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 430 | EXPECT_CALL(*card_proxy_, GetSPN(_, _, CellularCapability::kTimeoutDefault)) |
| 431 | .WillOnce(Invoke(this, |
| 432 | &CellularCapabilityGSMTest::InvokeGetSPN)); |
| 433 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 434 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 435 | ASSERT_TRUE(capability_->spn_.empty()); |
| 436 | capability_->GetSPN(Bind(&CellularCapabilityGSMTest::TestCallback, |
| 437 | Unretained(this))); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 438 | EXPECT_EQ(kTestCarrier, capability_->spn_); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 439 | } |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 440 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 441 | TEST_F(CellularCapabilityGSMTest, GetSignalQuality) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 442 | EXPECT_CALL(*network_proxy_, |
| 443 | GetSignalQuality(_, _, CellularCapability::kTimeoutDefault)) |
| 444 | .WillOnce(Invoke(this, |
| 445 | &CellularCapabilityGSMTest::InvokeGetSignalQuality)); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 446 | SetNetworkProxy(); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 447 | CreateService(); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 448 | EXPECT_EQ(0, cellular_->service()->strength()); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 449 | capability_->GetSignalQuality(); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 450 | EXPECT_EQ(kStrength, cellular_->service()->strength()); |
| 451 | } |
| 452 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 453 | TEST_F(CellularCapabilityGSMTest, RegisterOnNetwork) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 454 | EXPECT_CALL(*network_proxy_, Register(kTestNetwork, _, _, |
| 455 | CellularCapability::kTimeoutRegister)) |
| 456 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeRegister)); |
| 457 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 458 | SetNetworkProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 459 | Error error; |
| 460 | capability_->RegisterOnNetwork(kTestNetwork, &error, |
| 461 | Bind(&CellularCapabilityGSMTest::TestCallback, |
| 462 | Unretained(this))); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 463 | EXPECT_EQ(kTestNetwork, cellular_->selected_network()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 464 | } |
| 465 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 466 | TEST_F(CellularCapabilityGSMTest, IsRegistered) { |
| 467 | EXPECT_FALSE(capability_->IsRegistered()); |
| 468 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE); |
| 469 | EXPECT_FALSE(capability_->IsRegistered()); |
| 470 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME); |
| 471 | EXPECT_TRUE(capability_->IsRegistered()); |
| 472 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING); |
| 473 | EXPECT_FALSE(capability_->IsRegistered()); |
| 474 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED); |
| 475 | EXPECT_FALSE(capability_->IsRegistered()); |
| 476 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN); |
| 477 | EXPECT_FALSE(capability_->IsRegistered()); |
| 478 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING); |
| 479 | EXPECT_TRUE(capability_->IsRegistered()); |
| 480 | } |
| 481 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 482 | TEST_F(CellularCapabilityGSMTest, GetRegistrationState) { |
| 483 | ASSERT_FALSE(capability_->IsRegistered()); |
| 484 | EXPECT_CALL(*network_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 485 | GetRegistrationInfo(_, _, CellularCapability::kTimeoutDefault)) |
| 486 | .WillOnce(Invoke(this, |
| 487 | &CellularCapabilityGSMTest::InvokeGetRegistrationInfo)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 488 | SetNetworkProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 489 | capability_->GetRegistrationState(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 490 | EXPECT_TRUE(capability_->IsRegistered()); |
| 491 | EXPECT_EQ(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME, |
| 492 | capability_->registration_state_); |
| 493 | } |
| 494 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 495 | TEST_F(CellularCapabilityGSMTest, RequirePIN) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 496 | EXPECT_CALL(*card_proxy_, EnablePIN(kPIN, true, _, _, |
| 497 | CellularCapability::kTimeoutDefault)) |
| 498 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeEnablePIN)); |
| 499 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 500 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 501 | Error error; |
| 502 | capability_->RequirePIN(kPIN, true, &error, |
| 503 | Bind(&CellularCapabilityGSMTest::TestCallback, |
| 504 | Unretained(this))); |
| 505 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | TEST_F(CellularCapabilityGSMTest, EnterPIN) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 509 | EXPECT_CALL(*card_proxy_, SendPIN(kPIN, _, _, |
| 510 | CellularCapability::kTimeoutDefault)) |
| 511 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeSendPIN)); |
| 512 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 513 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 514 | Error error; |
| 515 | capability_->EnterPIN(kPIN, &error, |
| 516 | Bind(&CellularCapabilityGSMTest::TestCallback, |
| 517 | Unretained(this))); |
| 518 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | TEST_F(CellularCapabilityGSMTest, UnblockPIN) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 522 | EXPECT_CALL(*card_proxy_, SendPUK(kPUK, kPIN, _, _, |
| 523 | CellularCapability::kTimeoutDefault)) |
| 524 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeSendPUK)); |
| 525 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 526 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 527 | Error error; |
| 528 | capability_->UnblockPIN(kPUK, kPIN, &error, |
| 529 | Bind(&CellularCapabilityGSMTest::TestCallback, |
| 530 | Unretained(this))); |
| 531 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | TEST_F(CellularCapabilityGSMTest, ChangePIN) { |
| 535 | static const char kOldPIN[] = "1111"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 536 | EXPECT_CALL(*card_proxy_, ChangePIN(kOldPIN, kPIN, _, _, |
| 537 | CellularCapability::kTimeoutDefault)) |
| 538 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeChangePIN)); |
| 539 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 540 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 541 | Error error; |
| 542 | capability_->ChangePIN(kOldPIN, kPIN, &error, |
| 543 | Bind(&CellularCapabilityGSMTest::TestCallback, |
| 544 | Unretained(this))); |
| 545 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 546 | } |
| 547 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 548 | |
| 549 | TEST_F(CellularCapabilityGSMTest, ParseScanResult) { |
| 550 | static const char kID[] = "123"; |
| 551 | static const char kLongName[] = "long name"; |
| 552 | static const char kShortName[] = "short name"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 553 | GSMScanResult result; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 554 | result[CellularCapabilityGSM::kNetworkPropertyStatus] = "1"; |
| 555 | result[CellularCapabilityGSM::kNetworkPropertyID] = kID; |
| 556 | result[CellularCapabilityGSM::kNetworkPropertyLongName] = kLongName; |
| 557 | result[CellularCapabilityGSM::kNetworkPropertyShortName] = kShortName; |
| 558 | result[CellularCapabilityGSM::kNetworkPropertyAccessTechnology] = "3"; |
| 559 | result["unknown property"] = "random value"; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 560 | Stringmap parsed = capability_->ParseScanResult(result); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 561 | EXPECT_EQ(5, parsed.size()); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 562 | EXPECT_EQ("available", parsed[kStatusProperty]); |
| 563 | EXPECT_EQ(kID, parsed[kNetworkIdProperty]); |
| 564 | EXPECT_EQ(kLongName, parsed[kLongNameProperty]); |
| 565 | EXPECT_EQ(kShortName, parsed[kShortNameProperty]); |
| 566 | EXPECT_EQ(kNetworkTechnologyEdge, parsed[kTechnologyProperty]); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | TEST_F(CellularCapabilityGSMTest, ParseScanResultProviderLookup) { |
Prathmesh Prabhu | afe6366 | 2014-05-20 11:03:58 -0700 | [diff] [blame] | 570 | static const char kID[] = "10001"; |
| 571 | const string kLongName = "TestNetworkLongName"; |
| 572 | // Replace the |MobileOperatorInfo| used by |ParseScanResult| by a mock. |
| 573 | auto *mock_mobile_operator_info = new MockMobileOperatorInfo( |
| 574 | &dispatcher_, |
| 575 | "MockParseScanResult"); |
| 576 | capability_->mobile_operator_info_.reset(mock_mobile_operator_info); |
| 577 | |
| 578 | mock_mobile_operator_info->SetEmptyDefaultsForProperties(); |
| 579 | EXPECT_CALL(*mock_mobile_operator_info, UpdateMCCMNC(kID)); |
| 580 | EXPECT_CALL(*mock_mobile_operator_info, IsMobileNetworkOperatorKnown()). |
| 581 | WillOnce(Return(true)); |
| 582 | EXPECT_CALL(*mock_mobile_operator_info, operator_name()). |
| 583 | WillRepeatedly(ReturnRef(kLongName)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 584 | GSMScanResult result; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 585 | result[CellularCapabilityGSM::kNetworkPropertyID] = kID; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 586 | Stringmap parsed = capability_->ParseScanResult(result); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 587 | EXPECT_EQ(2, parsed.size()); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 588 | EXPECT_EQ(kID, parsed[kNetworkIdProperty]); |
Prathmesh Prabhu | afe6366 | 2014-05-20 11:03:58 -0700 | [diff] [blame] | 589 | EXPECT_EQ(kLongName, parsed[kLongNameProperty]); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 590 | } |
| 591 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 592 | TEST_F(CellularCapabilityGSMTest, SetAccessTechnology) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 593 | capability_->SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM); |
| 594 | EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_GSM, capability_->access_technology_); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 595 | CreateService(); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 596 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 597 | capability_->SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GPRS); |
| 598 | EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_GPRS, capability_->access_technology_); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 599 | EXPECT_EQ(kNetworkTechnologyGprs, cellular_->service()->network_technology()); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 600 | } |
| 601 | |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 602 | TEST_F(CellularCapabilityGSMTest, AllowRoaming) { |
| 603 | EXPECT_FALSE(cellular_->allow_roaming_); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 604 | EXPECT_FALSE(cellular_->provider_requires_roaming()); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 605 | EXPECT_FALSE(capability_->AllowRoaming()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 606 | cellular_->set_provider_requires_roaming(true); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 607 | EXPECT_TRUE(capability_->AllowRoaming()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 608 | cellular_->set_provider_requires_roaming(false); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 609 | cellular_->allow_roaming_ = true; |
| 610 | EXPECT_TRUE(capability_->AllowRoaming()); |
| 611 | } |
| 612 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 613 | TEST_F(CellularCapabilityGSMTest, GetNetworkTechnologyString) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 614 | EXPECT_EQ("", capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 615 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 616 | EXPECT_EQ(kNetworkTechnologyGsm, capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 617 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 618 | EXPECT_EQ(kNetworkTechnologyGsm, capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 619 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GPRS); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 620 | EXPECT_EQ(kNetworkTechnologyGprs, capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 621 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_EDGE); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 622 | EXPECT_EQ(kNetworkTechnologyEdge, capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 623 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_UMTS); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 624 | EXPECT_EQ(kNetworkTechnologyUmts, capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 625 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSDPA); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 626 | EXPECT_EQ(kNetworkTechnologyHspa, capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 627 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSUPA); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 628 | EXPECT_EQ(kNetworkTechnologyHspa, capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 629 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSPA); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 630 | EXPECT_EQ(kNetworkTechnologyHspa, capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 631 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 632 | EXPECT_EQ(kNetworkTechnologyHspaPlus, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 633 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | TEST_F(CellularCapabilityGSMTest, GetRoamingStateString) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 637 | EXPECT_EQ(kRoamingStateUnknown, capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 638 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 639 | EXPECT_EQ(kRoamingStateHome, capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 640 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 641 | EXPECT_EQ(kRoamingStateRoaming, capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 642 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 643 | EXPECT_EQ(kRoamingStateUnknown, capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 644 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 645 | EXPECT_EQ(kRoamingStateUnknown, capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 646 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 647 | EXPECT_EQ(kRoamingStateUnknown, capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 648 | } |
| 649 | |
Gaurav Shah | 6780822 | 2013-03-27 13:29:36 -0700 | [diff] [blame] | 650 | MATCHER_P(KeyValueStoreEq, value, "") { |
| 651 | bool match = value.bool_properties() == arg.bool_properties() && |
| 652 | value.int_properties() == arg.int_properties() && |
| 653 | value.string_properties() == arg.string_properties() && |
| 654 | value.uint_properties() == arg.uint_properties(); |
Gaurav Shah | 6780822 | 2013-03-27 13:29:36 -0700 | [diff] [blame] | 655 | if (!match) { |
| 656 | *result_listener << "\nExpected KeyValueStore:\n" |
| 657 | << "\tbool_properties: " |
| 658 | << testing::PrintToString(value.bool_properties()) |
| 659 | << "\n\tint_properties: " |
| 660 | << testing::PrintToString(value.int_properties()) |
| 661 | << "\n\tstring_properties: " |
| 662 | << testing::PrintToString(value.string_properties()) |
| 663 | << "\n\tint_properties: " |
| 664 | << testing::PrintToString(value.uint_properties()) |
| 665 | << "\nGot KeyValueStore:\n" |
| 666 | << "\tbool_properties: " |
| 667 | << testing::PrintToString(arg.bool_properties()) |
| 668 | << "\n\tint_properties: " |
| 669 | << testing::PrintToString(arg.int_properties()) |
| 670 | << "\n\tstring_properties: " |
| 671 | << testing::PrintToString(arg.string_properties()) |
| 672 | << "\n\tuint_properties: " |
| 673 | << testing::PrintToString(arg.uint_properties()); |
| 674 | } |
Gaurav Shah | 6780822 | 2013-03-27 13:29:36 -0700 | [diff] [blame] | 675 | return match; |
| 676 | } |
| 677 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 678 | TEST_F(CellularCapabilityGSMTest, OnDBusPropertiesChanged) { |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 679 | EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN, capability_->access_technology_); |
| 680 | EXPECT_FALSE(capability_->sim_lock_status_.enabled); |
| 681 | EXPECT_EQ("", capability_->sim_lock_status_.lock_type); |
| 682 | EXPECT_EQ(0, capability_->sim_lock_status_.retries_left); |
| 683 | DBusPropertiesMap props; |
| 684 | static const char kLockType[] = "sim-pin"; |
| 685 | const int kRetries = 3; |
| 686 | props[CellularCapabilityGSM::kPropertyAccessTechnology].writer(). |
| 687 | append_uint32(MM_MODEM_GSM_ACCESS_TECH_EDGE); |
| 688 | props[CellularCapabilityGSM::kPropertyEnabledFacilityLocks].writer(). |
| 689 | append_uint32(MM_MODEM_GSM_FACILITY_SIM); |
| 690 | props[CellularCapabilityGSM::kPropertyUnlockRequired].writer().append_string( |
| 691 | kLockType); |
| 692 | props[CellularCapabilityGSM::kPropertyUnlockRetries].writer().append_uint32( |
| 693 | kRetries); |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 694 | // Call with the 'wrong' interface and nothing should change. |
| 695 | capability_->OnDBusPropertiesChanged(MM_MODEM_GSM_INTERFACE, props, |
| 696 | vector<string>()); |
| 697 | EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN, capability_->access_technology_); |
| 698 | EXPECT_FALSE(capability_->sim_lock_status_.enabled); |
| 699 | EXPECT_EQ("", capability_->sim_lock_status_.lock_type); |
| 700 | EXPECT_EQ(0, capability_->sim_lock_status_.retries_left); |
| 701 | |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 702 | // Call with the MM_MODEM_GSM_NETWORK_INTERFACE interface and expect a change |
| 703 | // to the enabled state of the SIM lock. |
| 704 | KeyValueStore lock_status; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 705 | lock_status.SetBool(kSIMLockEnabledProperty, true); |
| 706 | lock_status.SetString(kSIMLockTypeProperty, ""); |
| 707 | lock_status.SetUint(kSIMLockRetriesLeftProperty, 0); |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 708 | |
| 709 | EXPECT_CALL(*device_adaptor_, EmitKeyValueStoreChanged( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 710 | kSIMLockStatusProperty, |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 711 | KeyValueStoreEq(lock_status))); |
| 712 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 713 | capability_->OnDBusPropertiesChanged(MM_MODEM_GSM_NETWORK_INTERFACE, props, |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 714 | vector<string>()); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 715 | EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_EDGE, capability_->access_technology_); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 716 | capability_->OnDBusPropertiesChanged(MM_MODEM_GSM_CARD_INTERFACE, props, |
| 717 | vector<string>()); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 718 | EXPECT_TRUE(capability_->sim_lock_status_.enabled); |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 719 | EXPECT_TRUE(capability_->sim_lock_status_.lock_type.empty()); |
| 720 | EXPECT_EQ(0, capability_->sim_lock_status_.retries_left); |
| 721 | |
| 722 | // Some properties are sent on the MM_MODEM_INTERFACE. |
| 723 | capability_->sim_lock_status_.enabled = false; |
| 724 | capability_->sim_lock_status_.lock_type = ""; |
| 725 | capability_->sim_lock_status_.retries_left = 0; |
| 726 | KeyValueStore lock_status2; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 727 | lock_status2.SetBool(kSIMLockEnabledProperty, false); |
| 728 | lock_status2.SetString(kSIMLockTypeProperty, kLockType); |
| 729 | lock_status2.SetUint(kSIMLockRetriesLeftProperty, kRetries); |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 730 | EXPECT_CALL(*device_adaptor_, |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 731 | EmitKeyValueStoreChanged(kSIMLockStatusProperty, |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 732 | KeyValueStoreEq(lock_status2))); |
| 733 | capability_->OnDBusPropertiesChanged(MM_MODEM_INTERFACE, props, |
| 734 | vector<string>()); |
| 735 | EXPECT_FALSE(capability_->sim_lock_status_.enabled); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 736 | EXPECT_EQ(kLockType, capability_->sim_lock_status_.lock_type); |
| 737 | EXPECT_EQ(kRetries, capability_->sim_lock_status_.retries_left); |
| 738 | } |
| 739 | |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 740 | TEST_F(CellularCapabilityGSMTest, StartModemSuccess) { |
| 741 | SetupCommonStartModemExpectations(); |
| 742 | EXPECT_CALL(*card_proxy_, |
| 743 | GetSPN(_, _, CellularCapability::kTimeoutDefault)) |
| 744 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetSPN)); |
| 745 | EXPECT_CALL(*card_proxy_, |
| 746 | GetMSISDN(_, _, CellularCapability::kTimeoutDefault)) |
| 747 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetMSISDN)); |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 748 | AllowCreateCardProxyFromFactory(); |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 749 | |
| 750 | Error error; |
| 751 | capability_->StartModem( |
| 752 | &error, Bind(&CellularCapabilityGSMTest::TestCallback, Unretained(this))); |
| 753 | dispatcher_.DispatchPendingEvents(); |
| 754 | } |
| 755 | |
| 756 | TEST_F(CellularCapabilityGSMTest, StartModemGetSPNFail) { |
| 757 | SetupCommonStartModemExpectations(); |
| 758 | EXPECT_CALL(*card_proxy_, |
| 759 | GetSPN(_, _, CellularCapability::kTimeoutDefault)) |
| 760 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetSPNFail)); |
| 761 | EXPECT_CALL(*card_proxy_, |
| 762 | GetMSISDN(_, _, CellularCapability::kTimeoutDefault)) |
| 763 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetMSISDN)); |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 764 | AllowCreateCardProxyFromFactory(); |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 765 | |
| 766 | Error error; |
| 767 | capability_->StartModem( |
| 768 | &error, Bind(&CellularCapabilityGSMTest::TestCallback, Unretained(this))); |
| 769 | dispatcher_.DispatchPendingEvents(); |
| 770 | } |
| 771 | |
| 772 | TEST_F(CellularCapabilityGSMTest, StartModemGetMSISDNFail) { |
| 773 | SetupCommonStartModemExpectations(); |
| 774 | EXPECT_CALL(*card_proxy_, |
| 775 | GetSPN(_, _, CellularCapability::kTimeoutDefault)) |
| 776 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetSPN)); |
| 777 | EXPECT_CALL(*card_proxy_, |
| 778 | GetMSISDN(_, _, CellularCapability::kTimeoutDefault)) |
| 779 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetMSISDNFail)); |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 780 | AllowCreateCardProxyFromFactory(); |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 781 | |
| 782 | Error error; |
| 783 | capability_->StartModem( |
| 784 | &error, Bind(&CellularCapabilityGSMTest::TestCallback, Unretained(this))); |
| 785 | dispatcher_.DispatchPendingEvents(); |
| 786 | } |
| 787 | |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 788 | TEST_F(CellularCapabilityGSMTest, ConnectFailureNoService) { |
| 789 | // Make sure we don't crash if the connect failed and there is no |
| 790 | // CellularService object. This can happen if the modem is enabled and |
| 791 | // then quickly disabled. |
| 792 | SetupCommonProxiesExpectations(); |
| 793 | EXPECT_CALL(*simple_proxy_, |
| 794 | Connect(_, _, _, CellularCapabilityGSM::kTimeoutConnect)) |
| 795 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeConnectFail)); |
| 796 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 797 | InitProxies(); |
| 798 | EXPECT_FALSE(capability_->cellular()->service()); |
| 799 | Error error; |
| 800 | DBusPropertiesMap props; |
| 801 | capability_->Connect(props, &error, |
| 802 | Bind(&CellularCapabilityGSMTest::TestCallback, |
| 803 | Unretained(this))); |
| 804 | } |
| 805 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 806 | } // namespace shill |