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