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