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