Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/cellular_capability_gsm.h" |
| 6 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 7 | #include <base/bind.h> |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 8 | #include <chromeos/dbus/service_constants.h> |
| 9 | #include <gtest/gtest.h> |
| 10 | #include <mm/mm-modem.h> |
| 11 | #include <mobile_provider.h> |
| 12 | |
| 13 | #include "shill/cellular.h" |
| 14 | #include "shill/cellular_service.h" |
| 15 | #include "shill/error.h" |
| 16 | #include "shill/event_dispatcher.h" |
| 17 | #include "shill/mock_adaptors.h" |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 18 | #include "shill/mock_glib.h" |
| 19 | #include "shill/mock_manager.h" |
| 20 | #include "shill/mock_metrics.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 21 | #include "shill/mock_modem_cdma_proxy.h" |
| 22 | #include "shill/mock_modem_gsm_card_proxy.h" |
| 23 | #include "shill/mock_modem_gsm_network_proxy.h" |
| 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" |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 27 | #include "shill/mock_rtnl_handler.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 28 | #include "shill/nice_mock_control.h" |
| 29 | #include "shill/proxy_factory.h" |
| 30 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 31 | using base::Bind; |
| 32 | using base::Unretained; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 33 | using std::string; |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 34 | using testing::InSequence; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 35 | using testing::NiceMock; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 36 | using testing::_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 37 | |
| 38 | namespace shill { |
| 39 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 40 | MATCHER(IsSuccess, "") { |
| 41 | return arg.IsSuccess(); |
| 42 | } |
| 43 | MATCHER(IsFailure, "") { |
| 44 | return arg.IsFailure(); |
| 45 | } |
| 46 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 47 | class CellularCapabilityTest : public testing::Test { |
| 48 | public: |
| 49 | CellularCapabilityTest() |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 50 | : manager_(&control_, &dispatcher_, &metrics_, &glib_), |
| 51 | cellular_(new Cellular(&control_, |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 52 | &dispatcher_, |
| 53 | NULL, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 54 | &manager_, |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 55 | "", |
| 56 | "", |
| 57 | 0, |
| 58 | Cellular::kTypeGSM, |
| 59 | "", |
| 60 | "", |
| 61 | NULL)), |
| 62 | proxy_(new MockModemProxy()), |
| 63 | simple_proxy_(new MockModemSimpleProxy()), |
| 64 | cdma_proxy_(new MockModemCDMAProxy()), |
| 65 | gsm_card_proxy_(new MockModemGSMCardProxy()), |
| 66 | gsm_network_proxy_(new MockModemGSMNetworkProxy()), |
| 67 | proxy_factory_(this), |
| 68 | capability_(NULL), |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 69 | device_adaptor_(NULL), |
| 70 | provider_db_(NULL) {} |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 71 | |
| 72 | virtual ~CellularCapabilityTest() { |
| 73 | cellular_->service_ = NULL; |
| 74 | capability_ = NULL; |
| 75 | device_adaptor_ = NULL; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 76 | mobile_provider_close_db(provider_db_); |
| 77 | provider_db_ = NULL; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | virtual void SetUp() { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 81 | static_cast<Device *>(cellular_)->rtnl_handler_ = &rtnl_handler_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 82 | |
| 83 | capability_ = dynamic_cast<CellularCapabilityClassic *>( |
| 84 | cellular_->capability_.get()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 85 | device_adaptor_ = |
| 86 | dynamic_cast<NiceMock<DeviceMockAdaptor> *>(cellular_->adaptor()); |
| 87 | } |
| 88 | |
| 89 | virtual void TearDown() { |
| 90 | capability_->proxy_factory_ = NULL; |
| 91 | } |
| 92 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 93 | void InitProviderDB() { |
| 94 | provider_db_ = mobile_provider_open_db(kTestMobileProviderDBPath); |
| 95 | ASSERT_TRUE(provider_db_); |
| 96 | cellular_->provider_db_ = provider_db_; |
| 97 | } |
| 98 | |
| 99 | void SetService() { |
| 100 | cellular_->service_ = new CellularService( |
| 101 | &control_, &dispatcher_, &metrics_, NULL, cellular_); |
| 102 | } |
| 103 | |
| 104 | CellularCapabilityGSM *GetGsmCapability() { |
| 105 | return dynamic_cast<CellularCapabilityGSM *>(cellular_->capability_.get()); |
| 106 | } |
| 107 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 108 | void InvokeEnable(bool enable, Error *error, |
| 109 | const ResultCallback &callback, int timeout) { |
| 110 | callback.Run(Error()); |
| 111 | } |
| 112 | void InvokeEnableFail(bool enable, Error *error, |
| 113 | const ResultCallback &callback, int timeout) { |
| 114 | callback.Run(Error(Error::kOperationFailed)); |
| 115 | } |
| 116 | void InvokeDisconnect(Error *error, const ResultCallback &callback, |
| 117 | int timeout) { |
| 118 | callback.Run(Error()); |
| 119 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 120 | void InvokeDisconnectFail(Error *error, const ResultCallback &callback, |
| 121 | int timeout) { |
| 122 | callback.Run(Error(Error::kOperationFailed)); |
| 123 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 124 | void InvokeGetModemStatus(Error *error, |
| 125 | const DBusPropertyMapCallback &callback, |
| 126 | int timeout) { |
| 127 | DBusPropertiesMap props; |
| 128 | props["carrier"].writer().append_string(kTestCarrier); |
| 129 | props["unknown-property"].writer().append_string("irrelevant-value"); |
| 130 | callback.Run(props, Error()); |
| 131 | } |
| 132 | void InvokeGetModemInfo(Error *error, const ModemInfoCallback &callback, |
| 133 | int timeout) { |
| 134 | ModemHardwareInfo info; |
| 135 | info._1 = kManufacturer; |
| 136 | info._2 = kModelID; |
| 137 | info._3 = kHWRev; |
| 138 | callback.Run(info, Error()); |
| 139 | } |
| 140 | |
| 141 | MOCK_METHOD1(TestCallback, void(const Error &error)); |
| 142 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 143 | protected: |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 144 | static const char kTestMobileProviderDBPath[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 145 | static const char kTestCarrier[]; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 146 | static const char kManufacturer[]; |
| 147 | static const char kModelID[]; |
| 148 | static const char kHWRev[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 149 | |
| 150 | class TestProxyFactory : public ProxyFactory { |
| 151 | public: |
| 152 | explicit TestProxyFactory(CellularCapabilityTest *test) : test_(test) {} |
| 153 | |
| 154 | virtual ModemProxyInterface *CreateModemProxy( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 155 | const string &/*path*/, |
| 156 | const string &/*service*/) { |
| 157 | return test_->proxy_.release(); |
| 158 | } |
| 159 | |
| 160 | virtual ModemSimpleProxyInterface *CreateModemSimpleProxy( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 161 | const string &/*path*/, |
| 162 | const string &/*service*/) { |
| 163 | return test_->simple_proxy_.release(); |
| 164 | } |
| 165 | |
| 166 | virtual ModemCDMAProxyInterface *CreateModemCDMAProxy( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 167 | const string &/*path*/, |
| 168 | const string &/*service*/) { |
| 169 | return test_->cdma_proxy_.release(); |
| 170 | } |
| 171 | |
| 172 | virtual ModemGSMCardProxyInterface *CreateModemGSMCardProxy( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 173 | const string &/*path*/, |
| 174 | const string &/*service*/) { |
| 175 | return test_->gsm_card_proxy_.release(); |
| 176 | } |
| 177 | |
| 178 | virtual ModemGSMNetworkProxyInterface *CreateModemGSMNetworkProxy( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 179 | const string &/*path*/, |
| 180 | const string &/*service*/) { |
| 181 | return test_->gsm_network_proxy_.release(); |
| 182 | } |
| 183 | |
| 184 | private: |
| 185 | CellularCapabilityTest *test_; |
| 186 | }; |
| 187 | |
| 188 | void SetProxy() { |
| 189 | capability_->proxy_.reset(proxy_.release()); |
| 190 | } |
| 191 | |
| 192 | void SetSimpleProxy() { |
| 193 | capability_->simple_proxy_.reset(simple_proxy_.release()); |
| 194 | } |
| 195 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 196 | void SetGSMNetworkProxy() { |
| 197 | CellularCapabilityGSM *gsm_capability = |
| 198 | dynamic_cast<CellularCapabilityGSM *>(cellular_->capability_.get()); |
| 199 | gsm_capability->network_proxy_.reset(gsm_network_proxy_.release()); |
| 200 | } |
| 201 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 202 | void SetCellularType(Cellular::Type type) { |
| 203 | cellular_->InitCapability(type, &proxy_factory_); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 204 | capability_ = dynamic_cast<CellularCapabilityClassic *>( |
| 205 | cellular_->capability_.get()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | NiceMockControl control_; |
| 209 | EventDispatcher dispatcher_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 210 | MockMetrics metrics_; |
| 211 | MockGLib glib_; |
| 212 | MockManager manager_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 213 | CellularRefPtr cellular_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 214 | MockRTNLHandler rtnl_handler_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 215 | scoped_ptr<MockModemProxy> proxy_; |
| 216 | scoped_ptr<MockModemSimpleProxy> simple_proxy_; |
| 217 | scoped_ptr<MockModemCDMAProxy> cdma_proxy_; |
| 218 | scoped_ptr<MockModemGSMCardProxy> gsm_card_proxy_; |
| 219 | scoped_ptr<MockModemGSMNetworkProxy> gsm_network_proxy_; |
| 220 | TestProxyFactory proxy_factory_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 221 | CellularCapabilityClassic *capability_; // Owned by |cellular_|. |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 222 | NiceMock<DeviceMockAdaptor> *device_adaptor_; // Owned by |cellular_|. |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 223 | mobile_provider_db *provider_db_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 224 | }; |
| 225 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 226 | const char CellularCapabilityTest::kTestMobileProviderDBPath[] = |
| 227 | "provider_db_unittest.bfd"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 228 | const char CellularCapabilityTest::kTestCarrier[] = "The Cellular Carrier"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 229 | const char CellularCapabilityTest::kManufacturer[] = "Company"; |
| 230 | const char CellularCapabilityTest::kModelID[] = "Gobi 2000"; |
| 231 | const char CellularCapabilityTest::kHWRev[] = "A00B1234"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 232 | |
| 233 | TEST_F(CellularCapabilityTest, GetModemStatus) { |
| 234 | SetCellularType(Cellular::kTypeCDMA); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 235 | EXPECT_CALL(*simple_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 236 | GetModemStatus(_, _, CellularCapability::kTimeoutDefault)). |
| 237 | WillOnce(Invoke(this, &CellularCapabilityTest::InvokeGetModemStatus)); |
| 238 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 239 | SetSimpleProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 240 | ResultCallback callback = |
| 241 | Bind(&CellularCapabilityTest::TestCallback, Unretained(this)); |
| 242 | capability_->GetModemStatus(callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 243 | EXPECT_EQ(kTestCarrier, capability_->carrier_); |
| 244 | EXPECT_EQ(kTestCarrier, cellular_->home_provider_.GetName()); |
| 245 | } |
| 246 | |
| 247 | TEST_F(CellularCapabilityTest, GetModemInfo) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 248 | EXPECT_CALL(*proxy_, GetModemInfo(_, _, CellularCapability::kTimeoutDefault)) |
| 249 | .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeGetModemInfo)); |
| 250 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 251 | SetProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 252 | ResultCallback callback = |
| 253 | Bind(&CellularCapabilityTest::TestCallback, Unretained(this)); |
| 254 | capability_->GetModemInfo(callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 255 | EXPECT_EQ(kManufacturer, capability_->manufacturer_); |
| 256 | EXPECT_EQ(kModelID, capability_->model_id_); |
| 257 | EXPECT_EQ(kHWRev, capability_->hardware_revision_); |
| 258 | } |
| 259 | |
| 260 | TEST_F(CellularCapabilityTest, EnableModemSucceed) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 261 | EXPECT_CALL(*proxy_, Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 262 | .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeEnable)); |
| 263 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 264 | ResultCallback callback = |
| 265 | Bind(&CellularCapabilityTest::TestCallback, Unretained(this)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 266 | SetProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 267 | capability_->EnableModem(callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | TEST_F(CellularCapabilityTest, EnableModemFail) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 271 | EXPECT_CALL(*proxy_, Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 272 | .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeEnableFail)); |
| 273 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 274 | ResultCallback callback = |
| 275 | Bind(&CellularCapabilityTest::TestCallback, Unretained(this)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 276 | SetProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 277 | capability_->EnableModem(callback); |
| 278 | } |
| 279 | |
| 280 | TEST_F(CellularCapabilityTest, FinishEnable) { |
| 281 | EXPECT_CALL(*gsm_network_proxy_, |
| 282 | GetRegistrationInfo(NULL, _, |
| 283 | CellularCapability::kTimeoutDefault)); |
| 284 | EXPECT_CALL(*gsm_network_proxy_, |
| 285 | GetSignalQuality(NULL, _, CellularCapability::kTimeoutDefault)); |
| 286 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 287 | SetGSMNetworkProxy(); |
| 288 | capability_->FinishEnable( |
| 289 | Bind(&CellularCapabilityTest::TestCallback, Unretained(this))); |
| 290 | } |
| 291 | |
| 292 | TEST_F(CellularCapabilityTest, UnsupportedOperation) { |
| 293 | Error error; |
| 294 | EXPECT_CALL(*this, TestCallback(IsSuccess())).Times(0); |
| 295 | capability_->CellularCapability::Scan(&error, |
| 296 | Bind(&CellularCapabilityTest::TestCallback, Unretained(this))); |
| 297 | EXPECT_TRUE(error.IsFailure()); |
| 298 | EXPECT_EQ(Error::kNotSupported, error.type()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 299 | } |
| 300 | |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 301 | TEST_F(CellularCapabilityTest, AllowRoaming) { |
| 302 | EXPECT_FALSE(capability_->GetAllowRoaming(NULL)); |
| 303 | capability_->SetAllowRoaming(false, NULL); |
| 304 | EXPECT_FALSE(capability_->GetAllowRoaming(NULL)); |
| 305 | |
| 306 | { |
| 307 | InSequence seq; |
| 308 | EXPECT_CALL(*device_adaptor_, EmitBoolChanged( |
| 309 | flimflam::kCellularAllowRoamingProperty, true)); |
| 310 | EXPECT_CALL(*device_adaptor_, EmitBoolChanged( |
| 311 | flimflam::kCellularAllowRoamingProperty, false)); |
| 312 | } |
| 313 | |
| 314 | cellular_->state_ = Cellular::kStateConnected; |
| 315 | dynamic_cast<CellularCapabilityGSM *>(capability_)->registration_state_ = |
| 316 | MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING; |
| 317 | capability_->SetAllowRoaming(true, NULL); |
| 318 | EXPECT_TRUE(capability_->GetAllowRoaming(NULL)); |
| 319 | EXPECT_EQ(Cellular::kStateConnected, cellular_->state_); |
| 320 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 321 | EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDefault)) |
| 322 | .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeDisconnect)); |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 323 | SetProxy(); |
| 324 | cellular_->state_ = Cellular::kStateConnected; |
| 325 | capability_->SetAllowRoaming(false, NULL); |
| 326 | EXPECT_FALSE(capability_->GetAllowRoaming(NULL)); |
| 327 | EXPECT_EQ(Cellular::kStateRegistered, cellular_->state_); |
| 328 | } |
| 329 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 330 | MATCHER_P(HasApn, apn, "") { |
| 331 | DBusPropertiesMap::const_iterator it = arg.find(flimflam::kApnProperty); |
| 332 | return it != arg.end() && apn == it->second.reader().get_string(); |
| 333 | } |
| 334 | |
| 335 | MATCHER(HasNoApn, "") { |
| 336 | return arg.find(flimflam::kApnProperty) == arg.end(); |
| 337 | } |
| 338 | |
| 339 | TEST_F(CellularCapabilityTest, TryApns) { |
| 340 | static const string kLastGoodApn("remembered.apn"); |
| 341 | static const string kSuppliedApn("my.apn"); |
| 342 | static const string kTmobileApn1("epc.tmobile.com"); |
| 343 | static const string kTmobileApn2("wap.voicestream.com"); |
| 344 | static const string kTmobileApn3("internet2.voicestream.com"); |
| 345 | static const string kTmobileApn4("internet3.voicestream.com"); |
| 346 | |
| 347 | using testing::InSequence; |
| 348 | { |
| 349 | InSequence dummy; |
| 350 | EXPECT_CALL(*simple_proxy_, Connect(HasApn(kLastGoodApn), _, _, _)); |
| 351 | EXPECT_CALL(*simple_proxy_, Connect(HasApn(kSuppliedApn), _, _, _)); |
| 352 | EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn1), _, _, _)); |
| 353 | EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn2), _, _, _)); |
| 354 | EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn3), _, _, _)); |
| 355 | EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn4), _, _, _)); |
| 356 | EXPECT_CALL(*simple_proxy_, Connect(HasNoApn(), _, _, _)); |
| 357 | } |
| 358 | CellularCapabilityGSM *gsm_capability = GetGsmCapability(); |
| 359 | SetService(); |
| 360 | gsm_capability->imsi_ = "310240123456789"; |
| 361 | InitProviderDB(); |
| 362 | gsm_capability->SetHomeProvider(); |
| 363 | ProfileRefPtr profile(new NiceMock<MockProfile>( |
| 364 | &control_, reinterpret_cast<Manager *>(NULL))); |
| 365 | cellular_->service()->set_profile(profile); |
| 366 | |
| 367 | Error error; |
| 368 | Stringmap apn_info; |
| 369 | DBusPropertiesMap props; |
| 370 | apn_info[flimflam::kApnProperty] = kSuppliedApn; |
| 371 | cellular_->service()->SetApn(apn_info, &error); |
| 372 | |
| 373 | apn_info.clear(); |
| 374 | apn_info[flimflam::kApnProperty] = kLastGoodApn; |
| 375 | cellular_->service()->SetLastGoodApn(apn_info); |
| 376 | |
| 377 | capability_->SetupConnectProperties(&props); |
| 378 | // We expect the list to contain the last good APN, plus |
| 379 | // the user-supplied APN, plus the 4 APNs from the mobile |
| 380 | // provider info database. |
| 381 | EXPECT_EQ(6, gsm_capability->apn_try_list_.size()); |
| 382 | EXPECT_FALSE(props.find(flimflam::kApnProperty) == props.end()); |
| 383 | EXPECT_EQ(kLastGoodApn, props[flimflam::kApnProperty].reader().get_string()); |
| 384 | |
| 385 | SetSimpleProxy(); |
| 386 | capability_->Connect(props, &error, ResultCallback()); |
| 387 | Error cerror(Error::kInvalidApn); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 388 | gsm_capability->OnConnectReply(ResultCallback(), cerror); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 389 | EXPECT_EQ(5, gsm_capability->apn_try_list_.size()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 390 | gsm_capability->OnConnectReply(ResultCallback(), cerror); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 391 | EXPECT_EQ(4, gsm_capability->apn_try_list_.size()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 392 | gsm_capability->OnConnectReply(ResultCallback(), cerror); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 393 | EXPECT_EQ(3, gsm_capability->apn_try_list_.size()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 394 | gsm_capability->OnConnectReply(ResultCallback(), cerror); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 395 | EXPECT_EQ(2, gsm_capability->apn_try_list_.size()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 396 | gsm_capability->OnConnectReply(ResultCallback(), cerror); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 397 | EXPECT_EQ(1, gsm_capability->apn_try_list_.size()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 398 | gsm_capability->OnConnectReply(ResultCallback(), cerror); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 399 | EXPECT_EQ(0, gsm_capability->apn_try_list_.size()); |
| 400 | } |
| 401 | |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 402 | TEST_F(CellularCapabilityTest, StopModemDisconnectSuccess) { |
| 403 | EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDefault)) |
| 404 | .WillOnce(Invoke(this, |
| 405 | &CellularCapabilityTest::InvokeDisconnect)); |
| 406 | EXPECT_CALL(*proxy_, Enable(_, _, _, CellularCapability::kTimeoutDefault)) |
| 407 | .WillOnce(Invoke(this, |
| 408 | &CellularCapabilityTest::InvokeEnable)); |
| 409 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 410 | SetProxy(); |
| 411 | |
| 412 | Error error; |
| 413 | capability_->StopModem( |
| 414 | &error, Bind(&CellularCapabilityTest::TestCallback, Unretained(this))); |
| 415 | dispatcher_.DispatchPendingEvents(); |
| 416 | } |
| 417 | |
| 418 | TEST_F(CellularCapabilityTest, StopModemDisconnectFail) { |
| 419 | EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDefault)) |
| 420 | .WillOnce(Invoke(this, |
| 421 | &CellularCapabilityTest::InvokeDisconnectFail)); |
| 422 | EXPECT_CALL(*proxy_, Enable(_, _, _, CellularCapability::kTimeoutDefault)) |
| 423 | .WillOnce(Invoke(this, |
| 424 | &CellularCapabilityTest::InvokeEnable)); |
| 425 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 426 | SetProxy(); |
| 427 | |
| 428 | Error error; |
| 429 | capability_->StopModem( |
| 430 | &error, Bind(&CellularCapabilityTest::TestCallback, Unretained(this))); |
| 431 | dispatcher_.DispatchPendingEvents(); |
| 432 | } |
| 433 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 434 | } // namespace shill |