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