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