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> |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 11 | #include <base/stringprintf.h> |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 12 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 13 | #include <gtest/gtest.h> |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 14 | #include <mm/mm-modem.h> |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 15 | #include <mobile_provider.h> |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 16 | |
| 17 | #include "shill/cellular.h" |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 18 | #include "shill/cellular_service.h" |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 19 | #include "shill/error.h" |
| 20 | #include "shill/event_dispatcher.h" |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 21 | #include "shill/mock_adaptors.h" |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 22 | #include "shill/mock_log.h" |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 23 | #include "shill/mock_modem_gsm_card_proxy.h" |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 24 | #include "shill/mock_modem_gsm_network_proxy.h" |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 25 | #include "shill/mock_modem_info.h" |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 26 | #include "shill/mock_modem_proxy.h" |
| 27 | #include "shill/mock_modem_simple_proxy.h" |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 28 | #include "shill/mock_profile.h" |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 29 | #include "shill/proxy_factory.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; |
Paul Stewart | 1e5bad5 | 2012-08-04 17:13:19 -0700 | [diff] [blame] | 41 | using testing::StrEq; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 42 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 43 | namespace shill { |
| 44 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 45 | MATCHER(IsSuccess, "") { |
| 46 | return arg.IsSuccess(); |
| 47 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 48 | |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 49 | MATCHER(IsFailure, "") { |
| 50 | return arg.IsFailure(); |
| 51 | } |
| 52 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 53 | class CellularCapabilityGSMTest : public testing::Test { |
| 54 | public: |
| 55 | CellularCapabilityGSMTest() |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 56 | : modem_info_(NULL, &dispatcher_, NULL, NULL, NULL), |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 57 | create_card_proxy_from_factory_(false), |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 58 | proxy_(new MockModemProxy()), |
| 59 | simple_proxy_(new MockModemSimpleProxy()), |
| 60 | card_proxy_(new MockModemGSMCardProxy()), |
| 61 | network_proxy_(new MockModemGSMNetworkProxy()), |
| 62 | proxy_factory_(this), |
| 63 | capability_(NULL), |
| 64 | device_adaptor_(NULL), |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 65 | cellular_(new Cellular(&modem_info_, |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 66 | "", |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 67 | kAddress, |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 68 | 0, |
| 69 | Cellular::kTypeGSM, |
| 70 | "", |
| 71 | "", |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 72 | "", |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 73 | &proxy_factory_)) { |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 74 | modem_info_.metrics()->RegisterDevice(cellular_->interface_index(), |
| 75 | Technology::kCellular); |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 76 | } |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 77 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 78 | virtual ~CellularCapabilityGSMTest() { |
| 79 | cellular_->service_ = NULL; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 80 | capability_ = NULL; |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 81 | device_adaptor_ = NULL; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | virtual void SetUp() { |
| 85 | capability_ = |
| 86 | dynamic_cast<CellularCapabilityGSM *>(cellular_->capability_.get()); |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 87 | device_adaptor_ = |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 88 | dynamic_cast<DeviceMockAdaptor *>(cellular_->adaptor()); |
| 89 | } |
| 90 | |
| 91 | void InitProviderDB() { |
| 92 | modem_info_.SetProviderDB(kTestMobileProviderDBPath); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 95 | void InvokeEnable(bool enable, Error *error, |
| 96 | const ResultCallback &callback, int timeout) { |
| 97 | callback.Run(Error()); |
| 98 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 99 | void InvokeGetIMEI(Error *error, const GSMIdentifierCallback &callback, |
| 100 | int timeout) { |
| 101 | callback.Run(kIMEI, Error()); |
| 102 | } |
| 103 | void InvokeGetIMSI(Error *error, const GSMIdentifierCallback &callback, |
| 104 | int timeout) { |
| 105 | callback.Run(kIMSI, Error()); |
| 106 | } |
| 107 | void InvokeGetIMSI2(Error *error, const GSMIdentifierCallback &callback, |
| 108 | int timeout) { |
| 109 | callback.Run("310240123456789", Error()); |
| 110 | } |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 111 | void InvokeGetIMSIFails(Error *error, const GSMIdentifierCallback &callback, |
| 112 | int timeout) { |
| 113 | callback.Run("", Error(Error::kOperationFailed)); |
| 114 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 115 | void InvokeGetMSISDN(Error *error, const GSMIdentifierCallback &callback, |
| 116 | int timeout) { |
| 117 | callback.Run(kMSISDN, Error()); |
| 118 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 119 | void InvokeGetMSISDNFail(Error *error, const GSMIdentifierCallback &callback, |
| 120 | int timeout) { |
| 121 | callback.Run("", Error(Error::kOperationFailed)); |
| 122 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 123 | void InvokeGetSPN(Error *error, const GSMIdentifierCallback &callback, |
| 124 | int timeout) { |
| 125 | callback.Run(kTestCarrier, Error()); |
| 126 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 127 | void InvokeGetSPNFail(Error *error, const GSMIdentifierCallback &callback, |
| 128 | int timeout) { |
| 129 | callback.Run("", Error(Error::kOperationFailed)); |
| 130 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 131 | void InvokeGetSignalQuality(Error *error, |
| 132 | const SignalQualityCallback &callback, |
| 133 | int timeout) { |
| 134 | callback.Run(kStrength, Error()); |
| 135 | } |
| 136 | void InvokeGetRegistrationInfo(Error *error, |
| 137 | const RegistrationInfoCallback &callback, |
| 138 | int timeout) { |
| 139 | callback.Run(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME, |
| 140 | kTestNetwork, kTestCarrier, Error()); |
| 141 | } |
| 142 | void InvokeRegister(const string &network_id, |
| 143 | Error *error, |
| 144 | const ResultCallback &callback, |
| 145 | int timeout) { |
| 146 | callback.Run(Error()); |
| 147 | } |
| 148 | void InvokeEnablePIN(const string &pin, bool enable, |
| 149 | Error *error, const ResultCallback &callback, |
| 150 | int timeout) { |
| 151 | callback.Run(Error()); |
| 152 | } |
| 153 | void InvokeSendPIN(const string &pin, Error *error, |
| 154 | const ResultCallback &callback, int timeout) { |
| 155 | callback.Run(Error()); |
| 156 | } |
| 157 | void InvokeSendPUK(const string &puk, const string &pin, Error *error, |
| 158 | const ResultCallback &callback, int timeout) { |
| 159 | callback.Run(Error()); |
| 160 | } |
| 161 | void InvokeChangePIN(const string &old_pin, const string &pin, Error *error, |
| 162 | const ResultCallback &callback, int timeout) { |
| 163 | callback.Run(Error()); |
| 164 | } |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 165 | void InvokeScanReply() { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 166 | GSMScanResults results; |
| 167 | results.push_back(GSMScanResult()); |
| 168 | results[0][CellularCapabilityGSM::kNetworkPropertyID] = kScanID0; |
| 169 | results.push_back(GSMScanResult()); |
| 170 | results[1][CellularCapabilityGSM::kNetworkPropertyID] = kScanID1; |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 171 | scan_callback_.Run(results, Error()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 172 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 173 | void InvokeGetModemStatus(Error *error, |
| 174 | const DBusPropertyMapCallback &callback, |
| 175 | int timeout) { |
| 176 | DBusPropertiesMap props; |
| 177 | callback.Run(props, Error()); |
| 178 | } |
| 179 | void InvokeGetModemInfo(Error *error, const ModemInfoCallback &callback, |
| 180 | int timeout) { |
| 181 | ModemHardwareInfo info; |
| 182 | callback.Run(info, Error()); |
| 183 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 184 | |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 185 | void InvokeConnectFail(DBusPropertiesMap props, Error *error, |
| 186 | const ResultCallback &callback, int timeout) { |
| 187 | callback.Run(Error(Error::kOperationFailed)); |
| 188 | } |
| 189 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 190 | MOCK_METHOD1(TestCallback, void(const Error &error)); |
| 191 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 192 | protected: |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 193 | static const char kAddress[]; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 194 | static const char kTestMobileProviderDBPath[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 195 | static const char kTestNetwork[]; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 196 | static const char kTestCarrier[]; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 197 | static const char kPIN[]; |
| 198 | static const char kPUK[]; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 199 | static const char kIMEI[]; |
| 200 | static const char kIMSI[]; |
| 201 | static const char kMSISDN[]; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 202 | static const char kScanID0[]; |
| 203 | static const char kScanID1[]; |
| 204 | static const int kStrength; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 205 | |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 206 | class TestProxyFactory : public ProxyFactory { |
| 207 | public: |
| 208 | explicit TestProxyFactory(CellularCapabilityGSMTest *test) : test_(test) {} |
| 209 | |
| 210 | virtual ModemProxyInterface *CreateModemProxy( |
| 211 | const string &/*path*/, |
| 212 | const string &/*service*/) { |
| 213 | return test_->proxy_.release(); |
| 214 | } |
| 215 | |
| 216 | virtual ModemSimpleProxyInterface *CreateModemSimpleProxy( |
| 217 | const string &/*path*/, |
| 218 | const string &/*service*/) { |
| 219 | return test_->simple_proxy_.release(); |
| 220 | } |
| 221 | |
| 222 | virtual ModemGSMCardProxyInterface *CreateModemGSMCardProxy( |
| 223 | const string &/*path*/, |
| 224 | const string &/*service*/) { |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 225 | // TODO(benchan): This code conditionally returns a NULL pointer to avoid |
| 226 | // CellularCapabilityGSM::InitProperties (and thus |
| 227 | // CellularCapabilityGSM::GetIMSI) from being called during the |
| 228 | // construction. Remove this workaround after refactoring the tests. |
| 229 | return test_->create_card_proxy_from_factory_ ? |
| 230 | test_->card_proxy_.release() : NULL; |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | virtual ModemGSMNetworkProxyInterface *CreateModemGSMNetworkProxy( |
| 234 | const string &/*path*/, |
| 235 | const string &/*service*/) { |
| 236 | return test_->network_proxy_.release(); |
| 237 | } |
| 238 | |
| 239 | private: |
| 240 | CellularCapabilityGSMTest *test_; |
| 241 | }; |
| 242 | |
| 243 | void SetProxy() { |
| 244 | capability_->proxy_.reset(proxy_.release()); |
| 245 | } |
| 246 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 247 | void SetCardProxy() { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 248 | capability_->card_proxy_.reset(card_proxy_.release()); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 249 | } |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 250 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 251 | void SetNetworkProxy() { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 252 | capability_->network_proxy_.reset(network_proxy_.release()); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 253 | } |
| 254 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 255 | void SetAccessTechnology(uint32 technology) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 256 | capability_->access_technology_ = technology; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | void SetRegistrationState(uint32 state) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 260 | capability_->registration_state_ = state; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 263 | void SetService() { |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 264 | cellular_->service_ = new CellularService(&modem_info_, cellular_); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 265 | } |
| 266 | |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 267 | void SetupCommonProxiesExpectations() { |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 268 | EXPECT_CALL(*proxy_, set_state_changed_callback(_)); |
| 269 | EXPECT_CALL(*network_proxy_, set_signal_quality_callback(_)); |
| 270 | EXPECT_CALL(*network_proxy_, set_network_mode_callback(_)); |
| 271 | EXPECT_CALL(*network_proxy_, set_registration_info_callback(_)); |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void SetupCommonStartModemExpectations() { |
| 275 | SetupCommonProxiesExpectations(); |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 276 | |
| 277 | EXPECT_CALL(*proxy_, Enable(_, _, _, CellularCapability::kTimeoutEnable)) |
| 278 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeEnable)); |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 279 | EXPECT_CALL(*card_proxy_, |
| 280 | GetIMEI(_, _, CellularCapability::kTimeoutDefault)) |
| 281 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetIMEI)); |
| 282 | EXPECT_CALL(*card_proxy_, |
| 283 | GetIMSI(_, _, CellularCapability::kTimeoutDefault)) |
| 284 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetIMSI)); |
| 285 | EXPECT_CALL(*network_proxy_, AccessTechnology()); |
| 286 | EXPECT_CALL(*card_proxy_, EnabledFacilityLocks()); |
| 287 | EXPECT_CALL(*proxy_, |
| 288 | GetModemInfo(_, _, CellularCapability::kTimeoutDefault)) |
| 289 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetModemInfo)); |
| 290 | EXPECT_CALL(*network_proxy_, |
| 291 | GetRegistrationInfo(_, _, CellularCapability::kTimeoutDefault)); |
| 292 | EXPECT_CALL(*network_proxy_, |
| 293 | GetSignalQuality(_, _, CellularCapability::kTimeoutDefault)); |
| 294 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 295 | } |
| 296 | |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 297 | void InitProxies() { |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 298 | AllowCreateCardProxyFromFactory(); |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 299 | capability_->InitProxies(); |
| 300 | } |
| 301 | |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 302 | void AllowCreateCardProxyFromFactory() { |
| 303 | create_card_proxy_from_factory_ = true; |
| 304 | } |
| 305 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 306 | EventDispatcher dispatcher_; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 307 | MockModemInfo modem_info_; |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 308 | bool create_card_proxy_from_factory_; |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 309 | scoped_ptr<MockModemProxy> proxy_; |
| 310 | scoped_ptr<MockModemSimpleProxy> simple_proxy_; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 311 | scoped_ptr<MockModemGSMCardProxy> card_proxy_; |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 312 | scoped_ptr<MockModemGSMNetworkProxy> network_proxy_; |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 313 | TestProxyFactory proxy_factory_; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 314 | CellularCapabilityGSM *capability_; // Owned by |cellular_|. |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 315 | DeviceMockAdaptor *device_adaptor_; // Owned by |cellular_|. |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 316 | CellularRefPtr cellular_; |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 317 | ScanResultsCallback scan_callback_; // saved for testing scan operations |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 318 | }; |
| 319 | |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 320 | const char CellularCapabilityGSMTest::kAddress[] = "1122334455"; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 321 | const char CellularCapabilityGSMTest::kTestMobileProviderDBPath[] = |
| 322 | "provider_db_unittest.bfd"; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 323 | const char CellularCapabilityGSMTest::kTestCarrier[] = "The Cellular Carrier"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 324 | const char CellularCapabilityGSMTest::kTestNetwork[] = "310555"; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 325 | const char CellularCapabilityGSMTest::kPIN[] = "9876"; |
| 326 | const char CellularCapabilityGSMTest::kPUK[] = "8765"; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 327 | const char CellularCapabilityGSMTest::kIMEI[] = "987654321098765"; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 328 | const char CellularCapabilityGSMTest::kIMSI[] = "310150123456789"; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 329 | const char CellularCapabilityGSMTest::kMSISDN[] = "12345678901"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 330 | const char CellularCapabilityGSMTest::kScanID0[] = "123"; |
| 331 | const char CellularCapabilityGSMTest::kScanID1[] = "456"; |
| 332 | const int CellularCapabilityGSMTest::kStrength = 80; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 333 | |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 334 | TEST_F(CellularCapabilityGSMTest, PropertyStore) { |
| 335 | EXPECT_TRUE(cellular_->store().Contains(flimflam::kSIMLockStatusProperty)); |
| 336 | } |
| 337 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 338 | TEST_F(CellularCapabilityGSMTest, GetIMEI) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 339 | EXPECT_CALL(*card_proxy_, GetIMEI(_, _, CellularCapability::kTimeoutDefault)) |
| 340 | .WillOnce(Invoke(this, |
| 341 | &CellularCapabilityGSMTest::InvokeGetIMEI)); |
| 342 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 343 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 344 | ASSERT_TRUE(capability_->imei_.empty()); |
| 345 | capability_->GetIMEI(Bind(&CellularCapabilityGSMTest::TestCallback, |
| 346 | Unretained(this))); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 347 | EXPECT_EQ(kIMEI, capability_->imei_); |
| 348 | } |
| 349 | |
| 350 | TEST_F(CellularCapabilityGSMTest, GetIMSI) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 351 | EXPECT_CALL(*card_proxy_, GetIMSI(_, _, CellularCapability::kTimeoutDefault)) |
| 352 | .WillOnce(Invoke(this, |
| 353 | &CellularCapabilityGSMTest::InvokeGetIMSI)) |
| 354 | .WillOnce(Invoke(this, |
| 355 | &CellularCapabilityGSMTest::InvokeGetIMSI2)); |
| 356 | EXPECT_CALL(*this, TestCallback(IsSuccess())).Times(2); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 357 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 358 | ResultCallback callback = Bind(&CellularCapabilityGSMTest::TestCallback, |
| 359 | Unretained(this)); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 360 | EXPECT_TRUE(capability_->imsi_.empty()); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 361 | EXPECT_FALSE(capability_->sim_present_); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 362 | capability_->GetIMSI(callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 363 | EXPECT_EQ(kIMSI, capability_->imsi_); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 364 | EXPECT_TRUE(capability_->sim_present_); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 365 | capability_->imsi_.clear(); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 366 | InitProviderDB(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 367 | capability_->GetIMSI(callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 368 | EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName()); |
| 369 | } |
| 370 | |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 371 | // In this test, the call to the proxy's GetIMSI() will always indicate failure, |
| 372 | // which will cause the retry logic to call the proxy again a number of times. |
| 373 | // Eventually, the retries expire. |
| 374 | TEST_F(CellularCapabilityGSMTest, GetIMSIFails) { |
| 375 | ScopedMockLog log; |
Paul Stewart | 1e5bad5 | 2012-08-04 17:13:19 -0700 | [diff] [blame] | 376 | EXPECT_CALL(log, Log(logging::LOG_INFO, StrEq("cellular_capability_gsm.cc"), |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 377 | ::testing::StartsWith("GetIMSI failed - "))); |
| 378 | EXPECT_CALL(*card_proxy_, GetIMSI(_, _, CellularCapability::kTimeoutDefault)) |
| 379 | .Times(CellularCapabilityGSM::kGetIMSIRetryLimit + 1) |
| 380 | .WillRepeatedly(Invoke(this, |
| 381 | &CellularCapabilityGSMTest::InvokeGetIMSIFails)); |
| 382 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 383 | SetCardProxy(); |
| 384 | ResultCallback callback = Bind(&CellularCapabilityGSMTest::TestCallback, |
| 385 | Unretained(this)); |
| 386 | EXPECT_TRUE(capability_->imsi_.empty()); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 387 | EXPECT_FALSE(capability_->sim_present_); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 388 | |
| 389 | capability_->get_imsi_retries_ = 0; |
| 390 | EXPECT_EQ(CellularCapabilityGSM::kGetIMSIRetryDelayMilliseconds, |
| 391 | capability_->get_imsi_retry_delay_milliseconds_); |
| 392 | |
| 393 | // Set the delay to zero to speed up the test. |
| 394 | capability_->get_imsi_retry_delay_milliseconds_ = 0; |
| 395 | capability_->GetIMSI(callback); |
| 396 | for (int i = 0; i < CellularCapabilityGSM::kGetIMSIRetryLimit; ++i) { |
| 397 | dispatcher_.DispatchPendingEvents(); |
| 398 | } |
| 399 | EXPECT_EQ(CellularCapabilityGSM::kGetIMSIRetryLimit + 1, |
| 400 | capability_->get_imsi_retries_); |
| 401 | EXPECT_TRUE(capability_->imsi_.empty()); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 402 | EXPECT_FALSE(capability_->sim_present_); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 405 | TEST_F(CellularCapabilityGSMTest, GetMSISDN) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 406 | EXPECT_CALL(*card_proxy_, GetMSISDN(_, _, |
| 407 | CellularCapability::kTimeoutDefault)) |
| 408 | .WillOnce(Invoke(this, |
| 409 | &CellularCapabilityGSMTest::InvokeGetMSISDN)); |
| 410 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 411 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 412 | ASSERT_TRUE(capability_->mdn_.empty()); |
| 413 | capability_->GetMSISDN(Bind(&CellularCapabilityGSMTest::TestCallback, |
| 414 | Unretained(this))); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 415 | EXPECT_EQ(kMSISDN, capability_->mdn_); |
| 416 | } |
| 417 | |
| 418 | TEST_F(CellularCapabilityGSMTest, GetSPN) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 419 | EXPECT_CALL(*card_proxy_, GetSPN(_, _, CellularCapability::kTimeoutDefault)) |
| 420 | .WillOnce(Invoke(this, |
| 421 | &CellularCapabilityGSMTest::InvokeGetSPN)); |
| 422 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 423 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 424 | ASSERT_TRUE(capability_->spn_.empty()); |
| 425 | capability_->GetSPN(Bind(&CellularCapabilityGSMTest::TestCallback, |
| 426 | Unretained(this))); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 427 | EXPECT_EQ(kTestCarrier, capability_->spn_); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 428 | } |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 429 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 430 | TEST_F(CellularCapabilityGSMTest, GetSignalQuality) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 431 | EXPECT_CALL(*network_proxy_, |
| 432 | GetSignalQuality(_, _, CellularCapability::kTimeoutDefault)) |
| 433 | .WillOnce(Invoke(this, |
| 434 | &CellularCapabilityGSMTest::InvokeGetSignalQuality)); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 435 | SetNetworkProxy(); |
| 436 | SetService(); |
| 437 | EXPECT_EQ(0, cellular_->service()->strength()); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 438 | capability_->GetSignalQuality(); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 439 | EXPECT_EQ(kStrength, cellular_->service()->strength()); |
| 440 | } |
| 441 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 442 | TEST_F(CellularCapabilityGSMTest, RegisterOnNetwork) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 443 | EXPECT_CALL(*network_proxy_, Register(kTestNetwork, _, _, |
| 444 | CellularCapability::kTimeoutRegister)) |
| 445 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeRegister)); |
| 446 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 447 | SetNetworkProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 448 | Error error; |
| 449 | capability_->RegisterOnNetwork(kTestNetwork, &error, |
| 450 | Bind(&CellularCapabilityGSMTest::TestCallback, |
| 451 | Unretained(this))); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 452 | EXPECT_EQ(kTestNetwork, capability_->selected_network_); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 453 | } |
| 454 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 455 | TEST_F(CellularCapabilityGSMTest, IsRegistered) { |
| 456 | EXPECT_FALSE(capability_->IsRegistered()); |
| 457 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE); |
| 458 | EXPECT_FALSE(capability_->IsRegistered()); |
| 459 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME); |
| 460 | EXPECT_TRUE(capability_->IsRegistered()); |
| 461 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING); |
| 462 | EXPECT_FALSE(capability_->IsRegistered()); |
| 463 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED); |
| 464 | EXPECT_FALSE(capability_->IsRegistered()); |
| 465 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN); |
| 466 | EXPECT_FALSE(capability_->IsRegistered()); |
| 467 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING); |
| 468 | EXPECT_TRUE(capability_->IsRegistered()); |
| 469 | } |
| 470 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 471 | TEST_F(CellularCapabilityGSMTest, GetRegistrationState) { |
| 472 | ASSERT_FALSE(capability_->IsRegistered()); |
| 473 | EXPECT_CALL(*network_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 474 | GetRegistrationInfo(_, _, CellularCapability::kTimeoutDefault)) |
| 475 | .WillOnce(Invoke(this, |
| 476 | &CellularCapabilityGSMTest::InvokeGetRegistrationInfo)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 477 | SetNetworkProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 478 | capability_->GetRegistrationState(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 479 | EXPECT_TRUE(capability_->IsRegistered()); |
| 480 | EXPECT_EQ(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME, |
| 481 | capability_->registration_state_); |
| 482 | } |
| 483 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 484 | TEST_F(CellularCapabilityGSMTest, RequirePIN) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 485 | EXPECT_CALL(*card_proxy_, EnablePIN(kPIN, true, _, _, |
| 486 | CellularCapability::kTimeoutDefault)) |
| 487 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeEnablePIN)); |
| 488 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 489 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 490 | Error error; |
| 491 | capability_->RequirePIN(kPIN, true, &error, |
| 492 | Bind(&CellularCapabilityGSMTest::TestCallback, |
| 493 | Unretained(this))); |
| 494 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | TEST_F(CellularCapabilityGSMTest, EnterPIN) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 498 | EXPECT_CALL(*card_proxy_, SendPIN(kPIN, _, _, |
| 499 | CellularCapability::kTimeoutDefault)) |
| 500 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeSendPIN)); |
| 501 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 502 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 503 | Error error; |
| 504 | capability_->EnterPIN(kPIN, &error, |
| 505 | Bind(&CellularCapabilityGSMTest::TestCallback, |
| 506 | Unretained(this))); |
| 507 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | TEST_F(CellularCapabilityGSMTest, UnblockPIN) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 511 | EXPECT_CALL(*card_proxy_, SendPUK(kPUK, kPIN, _, _, |
| 512 | CellularCapability::kTimeoutDefault)) |
| 513 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeSendPUK)); |
| 514 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 515 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 516 | Error error; |
| 517 | capability_->UnblockPIN(kPUK, kPIN, &error, |
| 518 | Bind(&CellularCapabilityGSMTest::TestCallback, |
| 519 | Unretained(this))); |
| 520 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | TEST_F(CellularCapabilityGSMTest, ChangePIN) { |
| 524 | static const char kOldPIN[] = "1111"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 525 | EXPECT_CALL(*card_proxy_, ChangePIN(kOldPIN, kPIN, _, _, |
| 526 | CellularCapability::kTimeoutDefault)) |
| 527 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeChangePIN)); |
| 528 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 529 | SetCardProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 530 | Error error; |
| 531 | capability_->ChangePIN(kOldPIN, kPIN, &error, |
| 532 | Bind(&CellularCapabilityGSMTest::TestCallback, |
| 533 | Unretained(this))); |
| 534 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 535 | } |
| 536 | |
Darin Petkov | b7828b0 | 2012-02-03 12:34:30 +0100 | [diff] [blame] | 537 | namespace { |
| 538 | |
| 539 | MATCHER(SizeIs2, "") { |
| 540 | return arg.size() == 2; |
| 541 | } |
| 542 | |
| 543 | } // namespace |
| 544 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 545 | TEST_F(CellularCapabilityGSMTest, Scan) { |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 546 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 547 | EXPECT_CALL(*network_proxy_, Scan(_, _, CellularCapability::kTimeoutScan)) |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 548 | .WillOnce(SaveArg<1>(&scan_callback_)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 549 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 550 | capability_->found_networks_.resize(3, Stringmap()); |
Darin Petkov | b7828b0 | 2012-02-03 12:34:30 +0100 | [diff] [blame] | 551 | EXPECT_CALL(*device_adaptor_, |
| 552 | EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 553 | SizeIs2())); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 554 | EXPECT_CALL(*device_adaptor_, |
| 555 | EmitBoolChanged(flimflam::kScanningProperty, true)); |
| 556 | EXPECT_FALSE(capability_->scanning_); |
| 557 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 558 | SetNetworkProxy(); |
| 559 | capability_->Scan(&error, Bind(&CellularCapabilityGSMTest::TestCallback, |
| 560 | Unretained(this))); |
| 561 | EXPECT_TRUE(error.IsSuccess()); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 562 | EXPECT_TRUE(capability_->scanning_); |
| 563 | |
| 564 | // Simulate the completion of the scan... |
| 565 | EXPECT_CALL(*device_adaptor_, |
| 566 | EmitBoolChanged(flimflam::kScanningProperty, false)); |
| 567 | InvokeScanReply(); |
| 568 | EXPECT_FALSE(capability_->scanning_); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 569 | EXPECT_EQ(2, capability_->found_networks_.size()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 570 | EXPECT_EQ(kScanID0, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 571 | capability_->found_networks_[0][flimflam::kNetworkIdProperty]); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 572 | EXPECT_EQ(kScanID1, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 573 | capability_->found_networks_[1][flimflam::kNetworkIdProperty]); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | TEST_F(CellularCapabilityGSMTest, ParseScanResult) { |
| 577 | static const char kID[] = "123"; |
| 578 | static const char kLongName[] = "long name"; |
| 579 | static const char kShortName[] = "short name"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 580 | GSMScanResult result; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 581 | result[CellularCapabilityGSM::kNetworkPropertyStatus] = "1"; |
| 582 | result[CellularCapabilityGSM::kNetworkPropertyID] = kID; |
| 583 | result[CellularCapabilityGSM::kNetworkPropertyLongName] = kLongName; |
| 584 | result[CellularCapabilityGSM::kNetworkPropertyShortName] = kShortName; |
| 585 | result[CellularCapabilityGSM::kNetworkPropertyAccessTechnology] = "3"; |
| 586 | result["unknown property"] = "random value"; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 587 | Stringmap parsed = capability_->ParseScanResult(result); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 588 | EXPECT_EQ(5, parsed.size()); |
| 589 | EXPECT_EQ("available", parsed[flimflam::kStatusProperty]); |
| 590 | EXPECT_EQ(kID, parsed[flimflam::kNetworkIdProperty]); |
| 591 | EXPECT_EQ(kLongName, parsed[flimflam::kLongNameProperty]); |
| 592 | EXPECT_EQ(kShortName, parsed[flimflam::kShortNameProperty]); |
| 593 | EXPECT_EQ(flimflam::kNetworkTechnologyEdge, |
| 594 | parsed[flimflam::kTechnologyProperty]); |
| 595 | } |
| 596 | |
| 597 | TEST_F(CellularCapabilityGSMTest, ParseScanResultProviderLookup) { |
| 598 | InitProviderDB(); |
| 599 | static const char kID[] = "310210"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 600 | GSMScanResult result; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 601 | result[CellularCapabilityGSM::kNetworkPropertyID] = kID; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 602 | Stringmap parsed = capability_->ParseScanResult(result); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 603 | EXPECT_EQ(2, parsed.size()); |
| 604 | EXPECT_EQ(kID, parsed[flimflam::kNetworkIdProperty]); |
| 605 | EXPECT_EQ("T-Mobile", parsed[flimflam::kLongNameProperty]); |
| 606 | } |
| 607 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 608 | TEST_F(CellularCapabilityGSMTest, SetAccessTechnology) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 609 | capability_->SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM); |
| 610 | EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_GSM, capability_->access_technology_); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 611 | SetService(); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 612 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 613 | capability_->SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GPRS); |
| 614 | EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_GPRS, capability_->access_technology_); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 615 | EXPECT_EQ(flimflam::kNetworkTechnologyGprs, |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 616 | cellular_->service()->network_technology()); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | TEST_F(CellularCapabilityGSMTest, UpdateOperatorInfo) { |
| 620 | static const char kOperatorName[] = "Swisscom"; |
| 621 | InitProviderDB(); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 622 | capability_->serving_operator_.SetCode("22801"); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 623 | SetService(); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 624 | capability_->UpdateOperatorInfo(); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 625 | EXPECT_EQ(kOperatorName, capability_->serving_operator_.GetName()); |
| 626 | EXPECT_EQ("ch", capability_->serving_operator_.GetCountry()); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 627 | EXPECT_EQ(kOperatorName, cellular_->service()->serving_operator().GetName()); |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 628 | |
| 629 | static const char kTestOperator[] = "Testcom"; |
| 630 | capability_->serving_operator_.SetName(kTestOperator); |
| 631 | capability_->serving_operator_.SetCountry(""); |
| 632 | capability_->UpdateOperatorInfo(); |
| 633 | EXPECT_EQ(kTestOperator, capability_->serving_operator_.GetName()); |
| 634 | EXPECT_EQ("ch", capability_->serving_operator_.GetCountry()); |
| 635 | EXPECT_EQ(kTestOperator, cellular_->service()->serving_operator().GetName()); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 636 | } |
| 637 | |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 638 | TEST_F(CellularCapabilityGSMTest, UpdateStatus) { |
| 639 | InitProviderDB(); |
| 640 | DBusPropertiesMap props; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 641 | capability_->imsi_ = "310240123456789"; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 642 | props[CellularCapability::kModemPropertyIMSI].writer().append_string(""); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 643 | capability_->UpdateStatus(props); |
| 644 | EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName()); |
| 645 | } |
| 646 | |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 647 | TEST_F(CellularCapabilityGSMTest, AllowRoaming) { |
| 648 | EXPECT_FALSE(cellular_->allow_roaming_); |
| 649 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
| 650 | EXPECT_FALSE(capability_->AllowRoaming()); |
| 651 | capability_->provider_requires_roaming_ = true; |
| 652 | EXPECT_TRUE(capability_->AllowRoaming()); |
| 653 | capability_->provider_requires_roaming_ = false; |
| 654 | cellular_->allow_roaming_ = true; |
| 655 | EXPECT_TRUE(capability_->AllowRoaming()); |
| 656 | } |
| 657 | |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 658 | TEST_F(CellularCapabilityGSMTest, SetHomeProvider) { |
| 659 | static const char kCountry[] = "us"; |
| 660 | static const char kCode[] = "310160"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 661 | capability_->imsi_ = "310240123456789"; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 662 | |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 663 | EXPECT_FALSE(capability_->home_provider_); |
| 664 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
| 665 | |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 666 | capability_->SetHomeProvider(); // No mobile provider DB available. |
| 667 | EXPECT_TRUE(cellular_->home_provider().GetName().empty()); |
| 668 | EXPECT_TRUE(cellular_->home_provider().GetCountry().empty()); |
| 669 | EXPECT_TRUE(cellular_->home_provider().GetCode().empty()); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 670 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 671 | |
| 672 | InitProviderDB(); |
| 673 | capability_->SetHomeProvider(); |
| 674 | EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName()); |
| 675 | EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry()); |
| 676 | EXPECT_EQ(kCode, cellular_->home_provider().GetCode()); |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 677 | EXPECT_EQ(4, capability_->apn_list_.size()); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 678 | ASSERT_TRUE(capability_->home_provider_); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 679 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 680 | |
| 681 | Cellular::Operator oper; |
| 682 | cellular_->set_home_provider(oper); |
| 683 | capability_->spn_ = kTestCarrier; |
| 684 | capability_->SetHomeProvider(); |
| 685 | EXPECT_EQ(kTestCarrier, cellular_->home_provider().GetName()); |
| 686 | EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry()); |
| 687 | EXPECT_EQ(kCode, cellular_->home_provider().GetCode()); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 688 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 689 | |
| 690 | static const char kCubic[] = "Cubic"; |
| 691 | capability_->spn_ = kCubic; |
| 692 | capability_->SetHomeProvider(); |
| 693 | EXPECT_EQ(kCubic, cellular_->home_provider().GetName()); |
| 694 | EXPECT_EQ("", cellular_->home_provider().GetCode()); |
| 695 | ASSERT_TRUE(capability_->home_provider_); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 696 | EXPECT_TRUE(capability_->provider_requires_roaming_); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 697 | |
| 698 | static const char kCUBIC[] = "CUBIC"; |
| 699 | capability_->spn_ = kCUBIC; |
| 700 | capability_->home_provider_ = NULL; |
| 701 | capability_->SetHomeProvider(); |
| 702 | EXPECT_EQ(kCUBIC, cellular_->home_provider().GetName()); |
| 703 | EXPECT_EQ("", cellular_->home_provider().GetCode()); |
| 704 | ASSERT_TRUE(capability_->home_provider_); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 705 | EXPECT_TRUE(capability_->provider_requires_roaming_); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 706 | } |
| 707 | |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 708 | namespace { |
| 709 | |
| 710 | MATCHER(SizeIs4, "") { |
| 711 | return arg.size() == 4; |
| 712 | } |
| 713 | |
| 714 | } // namespace |
| 715 | |
| 716 | TEST_F(CellularCapabilityGSMTest, InitAPNList) { |
| 717 | InitProviderDB(); |
| 718 | capability_->home_provider_ = |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 719 | mobile_provider_lookup_by_name(modem_info_.provider_db(), "T-Mobile"); |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 720 | ASSERT_TRUE(capability_->home_provider_); |
| 721 | EXPECT_EQ(0, capability_->apn_list_.size()); |
| 722 | EXPECT_CALL(*device_adaptor_, |
| 723 | EmitStringmapsChanged(flimflam::kCellularApnListProperty, |
| 724 | SizeIs4())); |
| 725 | capability_->InitAPNList(); |
| 726 | EXPECT_EQ(4, capability_->apn_list_.size()); |
| 727 | EXPECT_EQ("wap.voicestream.com", |
| 728 | capability_->apn_list_[1][flimflam::kApnProperty]); |
| 729 | EXPECT_EQ("Web2Go/t-zones", |
| 730 | capability_->apn_list_[1][flimflam::kApnNameProperty]); |
| 731 | } |
| 732 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 733 | TEST_F(CellularCapabilityGSMTest, GetNetworkTechnologyString) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 734 | EXPECT_EQ("", capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 735 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 736 | EXPECT_EQ(flimflam::kNetworkTechnologyGsm, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 737 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 738 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT); |
| 739 | EXPECT_EQ(flimflam::kNetworkTechnologyGsm, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 740 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 741 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GPRS); |
| 742 | EXPECT_EQ(flimflam::kNetworkTechnologyGprs, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 743 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 744 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_EDGE); |
| 745 | EXPECT_EQ(flimflam::kNetworkTechnologyEdge, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 746 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 747 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_UMTS); |
| 748 | EXPECT_EQ(flimflam::kNetworkTechnologyUmts, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 749 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 750 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSDPA); |
| 751 | EXPECT_EQ(flimflam::kNetworkTechnologyHspa, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 752 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 753 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSUPA); |
| 754 | EXPECT_EQ(flimflam::kNetworkTechnologyHspa, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 755 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 756 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSPA); |
| 757 | EXPECT_EQ(flimflam::kNetworkTechnologyHspa, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 758 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 759 | SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS); |
| 760 | EXPECT_EQ(flimflam::kNetworkTechnologyHspaPlus, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 761 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | TEST_F(CellularCapabilityGSMTest, GetRoamingStateString) { |
| 765 | EXPECT_EQ(flimflam::kRoamingStateUnknown, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 766 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 767 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME); |
| 768 | EXPECT_EQ(flimflam::kRoamingStateHome, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 769 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 770 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING); |
| 771 | EXPECT_EQ(flimflam::kRoamingStateRoaming, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 772 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 773 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING); |
| 774 | EXPECT_EQ(flimflam::kRoamingStateUnknown, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 775 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 776 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED); |
| 777 | EXPECT_EQ(flimflam::kRoamingStateUnknown, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 778 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 779 | SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE); |
| 780 | EXPECT_EQ(flimflam::kRoamingStateUnknown, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 781 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 782 | } |
| 783 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 784 | TEST_F(CellularCapabilityGSMTest, CreateFriendlyServiceName) { |
| 785 | CellularCapabilityGSM::friendly_service_name_id_ = 0; |
| 786 | EXPECT_EQ("GSMNetwork0", capability_->CreateFriendlyServiceName()); |
| 787 | EXPECT_EQ("GSMNetwork1", capability_->CreateFriendlyServiceName()); |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 788 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 789 | capability_->serving_operator_.SetCode("1234"); |
| 790 | EXPECT_EQ("cellular_1234", capability_->CreateFriendlyServiceName()); |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 791 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 792 | static const char kTestCarrier[] = "A GSM Carrier"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 793 | capability_->carrier_ = kTestCarrier; |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 794 | EXPECT_EQ(kTestCarrier, capability_->CreateFriendlyServiceName()); |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 795 | |
| 796 | static const char kHomeProvider[] = "The GSM Home Provider"; |
| 797 | cellular_->home_provider_.SetName(kHomeProvider); |
| 798 | EXPECT_EQ(kTestCarrier, capability_->CreateFriendlyServiceName()); |
| 799 | capability_->registration_state_ = MM_MODEM_GSM_NETWORK_REG_STATUS_HOME; |
| 800 | EXPECT_EQ(kHomeProvider, capability_->CreateFriendlyServiceName()); |
| 801 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 802 | static const char kTestOperator[] = "A GSM Operator"; |
| 803 | capability_->serving_operator_.SetName(kTestOperator); |
| 804 | EXPECT_EQ(kTestOperator, capability_->CreateFriendlyServiceName()); |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 805 | |
| 806 | capability_->registration_state_ = MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING; |
| 807 | EXPECT_EQ(StringPrintf("%s | %s", kHomeProvider, kTestOperator), |
| 808 | capability_->CreateFriendlyServiceName()); |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 809 | } |
| 810 | |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 811 | TEST_F(CellularCapabilityGSMTest, SetStorageIdentifier) { |
| 812 | SetService(); |
| 813 | capability_->OnServiceCreated(); |
Darin Petkov | dd3e866 | 2012-02-03 13:16:20 +0100 | [diff] [blame] | 814 | EXPECT_EQ(string(flimflam::kTypeCellular) + "_" + kAddress + "_" + |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 815 | cellular_->service()->friendly_name(), |
| 816 | cellular_->service()->GetStorageIdentifier()); |
| 817 | capability_->imsi_ = kIMSI; |
| 818 | capability_->OnServiceCreated(); |
Darin Petkov | dd3e866 | 2012-02-03 13:16:20 +0100 | [diff] [blame] | 819 | EXPECT_EQ(string(flimflam::kTypeCellular) + "_" + kAddress + "_" + kIMSI, |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 820 | cellular_->service()->GetStorageIdentifier()); |
| 821 | } |
| 822 | |
Gaurav Shah | 6780822 | 2013-03-27 13:29:36 -0700 | [diff] [blame] | 823 | MATCHER_P(KeyValueStoreEq, value, "") { |
| 824 | bool match = value.bool_properties() == arg.bool_properties() && |
| 825 | value.int_properties() == arg.int_properties() && |
| 826 | value.string_properties() == arg.string_properties() && |
| 827 | value.uint_properties() == arg.uint_properties(); |
Gaurav Shah | 6780822 | 2013-03-27 13:29:36 -0700 | [diff] [blame] | 828 | if (!match) { |
| 829 | *result_listener << "\nExpected KeyValueStore:\n" |
| 830 | << "\tbool_properties: " |
| 831 | << testing::PrintToString(value.bool_properties()) |
| 832 | << "\n\tint_properties: " |
| 833 | << testing::PrintToString(value.int_properties()) |
| 834 | << "\n\tstring_properties: " |
| 835 | << testing::PrintToString(value.string_properties()) |
| 836 | << "\n\tint_properties: " |
| 837 | << testing::PrintToString(value.uint_properties()) |
| 838 | << "\nGot KeyValueStore:\n" |
| 839 | << "\tbool_properties: " |
| 840 | << testing::PrintToString(arg.bool_properties()) |
| 841 | << "\n\tint_properties: " |
| 842 | << testing::PrintToString(arg.int_properties()) |
| 843 | << "\n\tstring_properties: " |
| 844 | << testing::PrintToString(arg.string_properties()) |
| 845 | << "\n\tuint_properties: " |
| 846 | << testing::PrintToString(arg.uint_properties()); |
| 847 | } |
Gaurav Shah | 6780822 | 2013-03-27 13:29:36 -0700 | [diff] [blame] | 848 | return match; |
| 849 | } |
| 850 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 851 | TEST_F(CellularCapabilityGSMTest, OnDBusPropertiesChanged) { |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 852 | EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN, capability_->access_technology_); |
| 853 | EXPECT_FALSE(capability_->sim_lock_status_.enabled); |
| 854 | EXPECT_EQ("", capability_->sim_lock_status_.lock_type); |
| 855 | EXPECT_EQ(0, capability_->sim_lock_status_.retries_left); |
| 856 | DBusPropertiesMap props; |
| 857 | static const char kLockType[] = "sim-pin"; |
| 858 | const int kRetries = 3; |
| 859 | props[CellularCapabilityGSM::kPropertyAccessTechnology].writer(). |
| 860 | append_uint32(MM_MODEM_GSM_ACCESS_TECH_EDGE); |
| 861 | props[CellularCapabilityGSM::kPropertyEnabledFacilityLocks].writer(). |
| 862 | append_uint32(MM_MODEM_GSM_FACILITY_SIM); |
| 863 | props[CellularCapabilityGSM::kPropertyUnlockRequired].writer().append_string( |
| 864 | kLockType); |
| 865 | props[CellularCapabilityGSM::kPropertyUnlockRetries].writer().append_uint32( |
| 866 | kRetries); |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 867 | // Call with the 'wrong' interface and nothing should change. |
| 868 | capability_->OnDBusPropertiesChanged(MM_MODEM_GSM_INTERFACE, props, |
| 869 | vector<string>()); |
| 870 | EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN, capability_->access_technology_); |
| 871 | EXPECT_FALSE(capability_->sim_lock_status_.enabled); |
| 872 | EXPECT_EQ("", capability_->sim_lock_status_.lock_type); |
| 873 | EXPECT_EQ(0, capability_->sim_lock_status_.retries_left); |
| 874 | |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 875 | // Call with the MM_MODEM_GSM_NETWORK_INTERFACE interface and expect a change |
| 876 | // to the enabled state of the SIM lock. |
| 877 | KeyValueStore lock_status; |
| 878 | lock_status.SetBool(flimflam::kSIMLockEnabledProperty, true); |
| 879 | lock_status.SetString(flimflam::kSIMLockTypeProperty, ""); |
| 880 | lock_status.SetUint(flimflam::kSIMLockRetriesLeftProperty, 0); |
| 881 | |
| 882 | EXPECT_CALL(*device_adaptor_, EmitKeyValueStoreChanged( |
| 883 | flimflam::kSIMLockStatusProperty, |
| 884 | KeyValueStoreEq(lock_status))); |
| 885 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 886 | capability_->OnDBusPropertiesChanged(MM_MODEM_GSM_NETWORK_INTERFACE, props, |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 887 | vector<string>()); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 888 | EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_EDGE, capability_->access_technology_); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 889 | capability_->OnDBusPropertiesChanged(MM_MODEM_GSM_CARD_INTERFACE, props, |
| 890 | vector<string>()); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 891 | EXPECT_TRUE(capability_->sim_lock_status_.enabled); |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 892 | EXPECT_TRUE(capability_->sim_lock_status_.lock_type.empty()); |
| 893 | EXPECT_EQ(0, capability_->sim_lock_status_.retries_left); |
| 894 | |
| 895 | // Some properties are sent on the MM_MODEM_INTERFACE. |
| 896 | capability_->sim_lock_status_.enabled = false; |
| 897 | capability_->sim_lock_status_.lock_type = ""; |
| 898 | capability_->sim_lock_status_.retries_left = 0; |
| 899 | KeyValueStore lock_status2; |
| 900 | lock_status2.SetBool(flimflam::kSIMLockEnabledProperty, false); |
| 901 | lock_status2.SetString(flimflam::kSIMLockTypeProperty, kLockType); |
| 902 | lock_status2.SetUint(flimflam::kSIMLockRetriesLeftProperty, kRetries); |
| 903 | EXPECT_CALL(*device_adaptor_, |
| 904 | EmitKeyValueStoreChanged(flimflam::kSIMLockStatusProperty, |
| 905 | KeyValueStoreEq(lock_status2))); |
| 906 | capability_->OnDBusPropertiesChanged(MM_MODEM_INTERFACE, props, |
| 907 | vector<string>()); |
| 908 | EXPECT_FALSE(capability_->sim_lock_status_.enabled); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 909 | EXPECT_EQ(kLockType, capability_->sim_lock_status_.lock_type); |
| 910 | EXPECT_EQ(kRetries, capability_->sim_lock_status_.retries_left); |
| 911 | } |
| 912 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 913 | TEST_F(CellularCapabilityGSMTest, SetupApnTryList) { |
| 914 | static const string kTmobileApn("epc.tmobile.com"); |
| 915 | static const string kLastGoodApn("remembered.apn"); |
| 916 | static const string kLastGoodUsername("remembered.user"); |
| 917 | static const string kSuppliedApn("my.apn"); |
| 918 | |
| 919 | SetService(); |
| 920 | capability_->imsi_ = "310240123456789"; |
| 921 | InitProviderDB(); |
| 922 | capability_->SetHomeProvider(); |
| 923 | DBusPropertiesMap props; |
| 924 | capability_->SetupConnectProperties(&props); |
| 925 | EXPECT_FALSE(props.find(flimflam::kApnProperty) == props.end()); |
| 926 | EXPECT_EQ(kTmobileApn, props[flimflam::kApnProperty].reader().get_string()); |
| 927 | |
| 928 | ProfileRefPtr profile(new NiceMock<MockProfile>( |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 929 | modem_info_.control_interface(), modem_info_.metrics(), |
| 930 | modem_info_.manager())); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 931 | cellular_->service()->set_profile(profile); |
| 932 | Stringmap apn_info; |
| 933 | apn_info[flimflam::kApnProperty] = kLastGoodApn; |
| 934 | apn_info[flimflam::kApnUsernameProperty] = kLastGoodUsername; |
| 935 | cellular_->service()->SetLastGoodApn(apn_info); |
| 936 | props.clear(); |
| 937 | EXPECT_TRUE(props.find(flimflam::kApnProperty) == props.end()); |
| 938 | capability_->SetupConnectProperties(&props); |
| 939 | // We expect the list to contain the last good APN, plus |
| 940 | // the 4 APNs from the mobile provider info database. |
| 941 | EXPECT_EQ(5, capability_->apn_try_list_.size()); |
| 942 | EXPECT_FALSE(props.find(flimflam::kApnProperty) == props.end()); |
| 943 | EXPECT_EQ(kLastGoodApn, props[flimflam::kApnProperty].reader().get_string()); |
| 944 | EXPECT_FALSE(props.find(flimflam::kApnUsernameProperty) == props.end()); |
| 945 | EXPECT_EQ(kLastGoodUsername, |
| 946 | props[flimflam::kApnUsernameProperty].reader().get_string()); |
| 947 | |
| 948 | Error error; |
| 949 | apn_info.clear(); |
| 950 | props.clear(); |
| 951 | apn_info[flimflam::kApnProperty] = kSuppliedApn; |
| 952 | // Setting the APN has the side effect of clearing the LastGoodApn, |
| 953 | // so the try list will have 5 elements, with the first one being |
| 954 | // the supplied APN. |
| 955 | cellular_->service()->SetApn(apn_info, &error); |
| 956 | EXPECT_TRUE(props.find(flimflam::kApnProperty) == props.end()); |
| 957 | capability_->SetupConnectProperties(&props); |
| 958 | EXPECT_EQ(5, capability_->apn_try_list_.size()); |
| 959 | EXPECT_FALSE(props.find(flimflam::kApnProperty) == props.end()); |
| 960 | EXPECT_EQ(kSuppliedApn, props[flimflam::kApnProperty].reader().get_string()); |
| 961 | |
| 962 | apn_info.clear(); |
| 963 | props.clear(); |
| 964 | apn_info[flimflam::kApnProperty] = kLastGoodApn; |
| 965 | apn_info[flimflam::kApnUsernameProperty] = kLastGoodUsername; |
| 966 | // Now when LastGoodAPN is set, it will be the one selected. |
| 967 | cellular_->service()->SetLastGoodApn(apn_info); |
| 968 | EXPECT_TRUE(props.find(flimflam::kApnProperty) == props.end()); |
| 969 | capability_->SetupConnectProperties(&props); |
| 970 | // We expect the list to contain the last good APN, plus |
| 971 | // the user-supplied APN, plus the 4 APNs from the mobile |
| 972 | // provider info database. |
| 973 | EXPECT_EQ(6, capability_->apn_try_list_.size()); |
| 974 | EXPECT_FALSE(props.find(flimflam::kApnProperty) == props.end()); |
| 975 | EXPECT_EQ(kLastGoodApn, props[flimflam::kApnProperty].reader().get_string()); |
| 976 | EXPECT_FALSE(props.find(flimflam::kApnUsernameProperty) == props.end()); |
| 977 | EXPECT_EQ(kLastGoodUsername, |
| 978 | props[flimflam::kApnUsernameProperty].reader().get_string()); |
| 979 | } |
| 980 | |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 981 | TEST_F(CellularCapabilityGSMTest, StartModemSuccess) { |
| 982 | SetupCommonStartModemExpectations(); |
| 983 | EXPECT_CALL(*card_proxy_, |
| 984 | GetSPN(_, _, CellularCapability::kTimeoutDefault)) |
| 985 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetSPN)); |
| 986 | EXPECT_CALL(*card_proxy_, |
| 987 | GetMSISDN(_, _, CellularCapability::kTimeoutDefault)) |
| 988 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetMSISDN)); |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 989 | AllowCreateCardProxyFromFactory(); |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 990 | |
| 991 | Error error; |
| 992 | capability_->StartModem( |
| 993 | &error, Bind(&CellularCapabilityGSMTest::TestCallback, Unretained(this))); |
| 994 | dispatcher_.DispatchPendingEvents(); |
| 995 | } |
| 996 | |
| 997 | TEST_F(CellularCapabilityGSMTest, StartModemGetSPNFail) { |
| 998 | SetupCommonStartModemExpectations(); |
| 999 | EXPECT_CALL(*card_proxy_, |
| 1000 | GetSPN(_, _, CellularCapability::kTimeoutDefault)) |
| 1001 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetSPNFail)); |
| 1002 | EXPECT_CALL(*card_proxy_, |
| 1003 | GetMSISDN(_, _, CellularCapability::kTimeoutDefault)) |
| 1004 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetMSISDN)); |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 1005 | AllowCreateCardProxyFromFactory(); |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 1006 | |
| 1007 | Error error; |
| 1008 | capability_->StartModem( |
| 1009 | &error, Bind(&CellularCapabilityGSMTest::TestCallback, Unretained(this))); |
| 1010 | dispatcher_.DispatchPendingEvents(); |
| 1011 | } |
| 1012 | |
| 1013 | TEST_F(CellularCapabilityGSMTest, StartModemGetMSISDNFail) { |
| 1014 | SetupCommonStartModemExpectations(); |
| 1015 | EXPECT_CALL(*card_proxy_, |
| 1016 | GetSPN(_, _, CellularCapability::kTimeoutDefault)) |
| 1017 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetSPN)); |
| 1018 | EXPECT_CALL(*card_proxy_, |
| 1019 | GetMSISDN(_, _, CellularCapability::kTimeoutDefault)) |
| 1020 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetMSISDNFail)); |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 1021 | AllowCreateCardProxyFromFactory(); |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 1022 | |
| 1023 | Error error; |
| 1024 | capability_->StartModem( |
| 1025 | &error, Bind(&CellularCapabilityGSMTest::TestCallback, Unretained(this))); |
| 1026 | dispatcher_.DispatchPendingEvents(); |
| 1027 | } |
| 1028 | |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 1029 | TEST_F(CellularCapabilityGSMTest, ConnectFailureNoService) { |
| 1030 | // Make sure we don't crash if the connect failed and there is no |
| 1031 | // CellularService object. This can happen if the modem is enabled and |
| 1032 | // then quickly disabled. |
| 1033 | SetupCommonProxiesExpectations(); |
| 1034 | EXPECT_CALL(*simple_proxy_, |
| 1035 | Connect(_, _, _, CellularCapabilityGSM::kTimeoutConnect)) |
| 1036 | .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeConnectFail)); |
| 1037 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 1038 | InitProxies(); |
| 1039 | EXPECT_FALSE(capability_->cellular()->service()); |
| 1040 | Error error; |
| 1041 | DBusPropertiesMap props; |
| 1042 | capability_->Connect(props, &error, |
| 1043 | Bind(&CellularCapabilityGSMTest::TestCallback, |
| 1044 | Unretained(this))); |
| 1045 | } |
| 1046 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 1047 | } // namespace shill |