Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 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_universal_cdma.h" |
| 6 | |
| 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 10 | #include <base/strings/string_util.h> |
| 11 | #include <base/strings/stringprintf.h> |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 12 | #include <gmock/gmock.h> |
| 13 | #include <gtest/gtest.h> |
| 14 | #include <ModemManager/ModemManager.h> |
| 15 | |
| 16 | #include "shill/cellular.h" |
| 17 | #include "shill/cellular_service.h" |
| 18 | #include "shill/event_dispatcher.h" |
| 19 | #include "shill/mock_adaptors.h" |
| 20 | #include "shill/mock_cellular_operator_info.h" |
| 21 | #include "shill/mock_cellular_service.h" |
| 22 | #include "shill/mock_dbus_properties_proxy.h" |
| 23 | #include "shill/mock_glib.h" |
| 24 | #include "shill/mock_manager.h" |
| 25 | #include "shill/mock_metrics.h" |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 26 | #include "shill/mock_mm1_modem_modem3gpp_proxy.h" |
| 27 | #include "shill/mock_mm1_modem_modemcdma_proxy.h" |
| 28 | #include "shill/mock_mm1_modem_proxy.h" |
| 29 | #include "shill/mock_mm1_modem_simple_proxy.h" |
| 30 | #include "shill/mock_mm1_sim_proxy.h" |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame^] | 31 | #include "shill/mock_mobile_operator_info.h" |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 32 | #include "shill/mock_modem_info.h" |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 33 | #include "shill/mock_pending_activation_store.h" |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 34 | #include "shill/nice_mock_control.h" |
| 35 | #include "shill/proxy_factory.h" |
| 36 | |
| 37 | using base::StringPrintf; |
| 38 | using std::string; |
| 39 | using std::vector; |
| 40 | using testing::Invoke; |
| 41 | using testing::Mock; |
| 42 | using testing::NiceMock; |
| 43 | using testing::Return; |
| 44 | using testing::SetArgumentPointee; |
| 45 | using testing::_; |
| 46 | |
| 47 | namespace shill { |
| 48 | |
| 49 | class CellularCapabilityUniversalCDMATest : public testing::Test { |
| 50 | public: |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 51 | CellularCapabilityUniversalCDMATest(EventDispatcher *dispatcher) |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 52 | : capability_(NULL), |
| 53 | device_adaptor_(NULL), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 54 | modem_info_(NULL, dispatcher, NULL, NULL, NULL), |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 55 | modem_3gpp_proxy_(new mm1::MockModemModem3gppProxy()), |
| 56 | modem_cdma_proxy_(new mm1::MockModemModemCdmaProxy()), |
| 57 | modem_proxy_(new mm1::MockModemProxy()), |
| 58 | modem_simple_proxy_(new mm1::MockModemSimpleProxy()), |
| 59 | sim_proxy_(new mm1::MockSimProxy()), |
| 60 | properties_proxy_(new MockDBusPropertiesProxy()), |
| 61 | proxy_factory_(this), |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame^] | 62 | mock_home_provider_info_(new MockMobileOperatorInfo(dispatcher)), |
| 63 | mock_serving_operator_info_(new MockMobileOperatorInfo(dispatcher)), |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 64 | cellular_(new Cellular(&modem_info_, |
| 65 | "", |
| 66 | kMachineAddress, |
| 67 | 0, |
| 68 | Cellular::kTypeUniversalCDMA, |
| 69 | "", |
| 70 | "", |
| 71 | "", |
| 72 | &proxy_factory_)), |
| 73 | service_(new MockCellularService(&modem_info_, |
| 74 | cellular_)) {} |
| 75 | |
| 76 | virtual ~CellularCapabilityUniversalCDMATest() { |
| 77 | cellular_->service_ = NULL; |
| 78 | capability_ = NULL; |
| 79 | device_adaptor_ = NULL; |
| 80 | } |
| 81 | |
| 82 | virtual void SetUp() { |
| 83 | capability_ = dynamic_cast<CellularCapabilityUniversalCDMA *>( |
| 84 | cellular_->capability_.get()); |
| 85 | device_adaptor_ = |
| 86 | dynamic_cast<NiceMock<DeviceMockAdaptor> *>(cellular_->adaptor()); |
| 87 | cellular_->service_ = service_; |
| 88 | } |
| 89 | |
| 90 | virtual void TearDown() { |
| 91 | capability_->proxy_factory_ = NULL; |
| 92 | } |
| 93 | |
| 94 | void SetService() { |
| 95 | cellular_->service_ = new CellularService(&modem_info_, cellular_); |
| 96 | } |
| 97 | |
Arman Uguray | c539123 | 2013-09-23 21:30:46 -0700 | [diff] [blame] | 98 | void ClearService() { |
| 99 | cellular_->service_ = NULL; |
| 100 | } |
| 101 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 102 | void ReleaseCapabilityProxies() { |
| 103 | capability_->ReleaseProxies(); |
| 104 | } |
| 105 | |
| 106 | void SetCdmaProxy() { |
| 107 | capability_->modem_cdma_proxy_.reset(modem_cdma_proxy_.release()); |
| 108 | } |
| 109 | |
| 110 | void SetSimpleProxy() { |
| 111 | capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release()); |
| 112 | } |
| 113 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame^] | 114 | void SetMockMobileOperatorInfoObjects() { |
| 115 | CHECK(mock_home_provider_info_); |
| 116 | CHECK(mock_serving_operator_info_); |
| 117 | cellular_->set_home_provider_info(mock_home_provider_info_.release()); |
| 118 | cellular_->set_serving_operator_info(mock_serving_operator_info_.release()); |
| 119 | } |
| 120 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 121 | protected: |
| 122 | static const char kEsn[]; |
| 123 | static const char kMachineAddress[]; |
| 124 | static const char kMeid[]; |
| 125 | |
| 126 | class TestProxyFactory : public ProxyFactory { |
| 127 | public: |
| 128 | explicit TestProxyFactory(CellularCapabilityUniversalCDMATest *test) : |
| 129 | test_(test) {} |
| 130 | |
| 131 | // TODO(armansito): Some of these methods won't be necessary after 3GPP |
| 132 | // gets refactored out of CellularCapabilityUniversal. |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 133 | virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy( |
| 134 | const std::string &/*path*/, |
| 135 | const std::string &/*service*/) { |
| 136 | return test_->modem_3gpp_proxy_.release(); |
| 137 | } |
| 138 | |
| 139 | virtual mm1::ModemModemCdmaProxyInterface *CreateMM1ModemModemCdmaProxy( |
| 140 | const std::string &/*path*/, |
| 141 | const std::string &/*service*/) { |
| 142 | return test_->modem_cdma_proxy_.release(); |
| 143 | } |
| 144 | |
| 145 | virtual mm1::ModemProxyInterface *CreateMM1ModemProxy( |
| 146 | const std::string &/*path*/, |
| 147 | const std::string &/*service*/) { |
| 148 | return test_->modem_proxy_.release(); |
| 149 | } |
| 150 | |
| 151 | virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy( |
| 152 | const std::string &/*path*/, |
| 153 | const std::string &/*service*/) { |
| 154 | return test_->modem_simple_proxy_.release(); |
| 155 | } |
| 156 | |
| 157 | virtual mm1::SimProxyInterface *CreateSimProxy( |
| 158 | const std::string &/*path*/, |
| 159 | const std::string &/*service*/) { |
| 160 | return test_->sim_proxy_.release(); |
| 161 | } |
| 162 | |
| 163 | virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy( |
| 164 | const std::string &/*path*/, |
| 165 | const std::string &/*service*/) { |
| 166 | return test_->properties_proxy_.release(); |
| 167 | } |
| 168 | |
| 169 | private: |
| 170 | CellularCapabilityUniversalCDMATest *test_; |
| 171 | }; |
| 172 | |
| 173 | |
| 174 | CellularCapabilityUniversalCDMA *capability_; |
| 175 | NiceMock<DeviceMockAdaptor> *device_adaptor_; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 176 | MockModemInfo modem_info_; |
| 177 | MockGLib glib_; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 178 | // TODO(armansito): Remove |modem_3gpp_proxy_| after refactor. |
| 179 | scoped_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_; |
| 180 | scoped_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_; |
| 181 | scoped_ptr<mm1::MockModemProxy> modem_proxy_; |
| 182 | scoped_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_; |
| 183 | scoped_ptr<mm1::MockSimProxy> sim_proxy_; |
| 184 | scoped_ptr<MockDBusPropertiesProxy> properties_proxy_; |
| 185 | TestProxyFactory proxy_factory_; |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame^] | 186 | scoped_ptr<MockMobileOperatorInfo> mock_home_provider_info_; |
| 187 | scoped_ptr<MockMobileOperatorInfo> mock_serving_operator_info_; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 188 | CellularRefPtr cellular_; |
| 189 | MockCellularService *service_; |
| 190 | }; |
| 191 | |
| 192 | // static |
| 193 | const char CellularCapabilityUniversalCDMATest::kEsn[] = "0000"; |
| 194 | // static |
| 195 | const char CellularCapabilityUniversalCDMATest::kMachineAddress[] = |
| 196 | "TestMachineAddress"; |
| 197 | // static |
| 198 | const char CellularCapabilityUniversalCDMATest::kMeid[] = "11111111111111"; |
| 199 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 200 | class CellularCapabilityUniversalCDMAMainTest |
| 201 | : public CellularCapabilityUniversalCDMATest { |
| 202 | public: |
| 203 | CellularCapabilityUniversalCDMAMainTest() |
| 204 | : CellularCapabilityUniversalCDMATest(&dispatcher_) {} |
| 205 | |
| 206 | private: |
| 207 | EventDispatcher dispatcher_; |
| 208 | }; |
| 209 | |
| 210 | class CellularCapabilityUniversalCDMADispatcherTest |
| 211 | : public CellularCapabilityUniversalCDMATest { |
| 212 | public: |
| 213 | CellularCapabilityUniversalCDMADispatcherTest() |
| 214 | : CellularCapabilityUniversalCDMATest(NULL) {} |
| 215 | }; |
| 216 | |
| 217 | TEST_F(CellularCapabilityUniversalCDMAMainTest, PropertiesChanged) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 218 | // Set up mock modem CDMA properties. |
| 219 | DBusPropertiesMap modem_cdma_properties; |
| 220 | modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_MEID]. |
| 221 | writer().append_string(kMeid); |
| 222 | modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_ESN]. |
| 223 | writer().append_string(kEsn); |
| 224 | |
| 225 | SetUp(); |
| 226 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 227 | EXPECT_TRUE(cellular_->meid().empty()); |
| 228 | EXPECT_TRUE(cellular_->esn().empty()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 229 | |
| 230 | // Changing properties on wrong interface will not have an effect |
| 231 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 232 | modem_cdma_properties, |
| 233 | vector<string>()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 234 | EXPECT_TRUE(cellular_->meid().empty()); |
| 235 | EXPECT_TRUE(cellular_->esn().empty()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 236 | |
| 237 | // Changing properties on the right interface gets reflected in the |
| 238 | // capabilities object |
| 239 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEMCDMA, |
| 240 | modem_cdma_properties, |
| 241 | vector<string>()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 242 | EXPECT_EQ(kMeid, cellular_->meid()); |
| 243 | EXPECT_EQ(kEsn, cellular_->esn()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 246 | TEST_F(CellularCapabilityUniversalCDMAMainTest, OnCDMARegistrationChanged) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 247 | EXPECT_EQ(0, capability_->sid_); |
| 248 | EXPECT_EQ(0, capability_->nid_); |
| 249 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 250 | capability_->cdma_1x_registration_state_); |
| 251 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 252 | capability_->cdma_evdo_registration_state_); |
| 253 | |
| 254 | EXPECT_EQ("", capability_->provider_.GetCode()); |
| 255 | EXPECT_EQ("", capability_->provider_.GetName()); |
| 256 | EXPECT_EQ("", capability_->provider_.GetCountry()); |
| 257 | |
| 258 | CellularOperatorInfo::CellularOperator *provider = |
| 259 | new CellularOperatorInfo::CellularOperator(); |
| 260 | |
| 261 | provider->country_ = "us"; |
| 262 | provider->is_primary_ = true; |
| 263 | provider->name_list_.push_back( |
| 264 | CellularOperatorInfo::LocalizedName("Test", "")); |
| 265 | |
| 266 | scoped_ptr<const CellularOperatorInfo::CellularOperator> ptr(provider); |
| 267 | |
| 268 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 269 | GetCellularOperatorBySID("2")) |
| 270 | .WillOnce(Return(ptr.get())); |
| 271 | |
| 272 | capability_->OnCDMARegistrationChanged( |
| 273 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 274 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
| 275 | 2, |
| 276 | 0); |
| 277 | EXPECT_EQ(2, capability_->sid_); |
| 278 | EXPECT_EQ(0, capability_->nid_); |
| 279 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 280 | capability_->cdma_1x_registration_state_); |
| 281 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
| 282 | capability_->cdma_evdo_registration_state_); |
| 283 | |
| 284 | EXPECT_TRUE(capability_->IsRegistered()); |
| 285 | EXPECT_EQ("2", capability_->provider_.GetCode()); |
| 286 | EXPECT_EQ("Test", capability_->provider_.GetName()); |
| 287 | EXPECT_EQ("us", capability_->provider_.GetCountry()); |
| 288 | } |
| 289 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 290 | TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateOperatorInfo) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 291 | EXPECT_EQ("", capability_->provider_.GetCode()); |
| 292 | EXPECT_EQ("", capability_->provider_.GetName()); |
| 293 | EXPECT_EQ("", capability_->provider_.GetCountry()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 294 | EXPECT_TRUE(capability_->activation_code_.empty()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 295 | |
| 296 | capability_->UpdateOperatorInfo(); |
| 297 | EXPECT_EQ("", capability_->provider_.GetCode()); |
| 298 | EXPECT_EQ("", capability_->provider_.GetName()); |
| 299 | EXPECT_EQ("", capability_->provider_.GetCountry()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 300 | EXPECT_TRUE(capability_->activation_code_.empty()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 301 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 302 | capability_->UpdateOperatorInfo(); |
| 303 | EXPECT_EQ("", capability_->provider_.GetCode()); |
| 304 | EXPECT_EQ("", capability_->provider_.GetName()); |
| 305 | EXPECT_EQ("", capability_->provider_.GetCountry()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 306 | EXPECT_TRUE(capability_->activation_code_.empty()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 307 | |
| 308 | capability_->sid_ = 1; |
| 309 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 310 | GetCellularOperatorBySID(_)) |
| 311 | .WillOnce(Return((const CellularOperatorInfo::CellularOperator *)NULL)); |
| 312 | |
| 313 | capability_->UpdateOperatorInfo(); |
Arman Uguray | e015faf | 2013-08-16 17:54:59 -0700 | [diff] [blame] | 314 | EXPECT_EQ("1", capability_->provider_.GetCode()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 315 | EXPECT_EQ("", capability_->provider_.GetName()); |
| 316 | EXPECT_EQ("", capability_->provider_.GetCountry()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 317 | EXPECT_TRUE(capability_->activation_code_.empty()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 318 | |
| 319 | CellularOperatorInfo::CellularOperator *provider = |
| 320 | new CellularOperatorInfo::CellularOperator(); |
| 321 | |
| 322 | provider->country_ = "us"; |
| 323 | provider->is_primary_ = true; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 324 | provider->activation_code_ = "1234"; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 325 | provider->name_list_.push_back( |
| 326 | CellularOperatorInfo::LocalizedName("Test", "")); |
| 327 | |
| 328 | scoped_ptr<const CellularOperatorInfo::CellularOperator> ptr(provider); |
| 329 | |
| 330 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 331 | GetCellularOperatorBySID(_)) |
| 332 | .WillOnce(Return(ptr.get())); |
| 333 | |
| 334 | capability_->UpdateOperatorInfo(); |
| 335 | |
| 336 | EXPECT_EQ("1", capability_->provider_.GetCode()); |
| 337 | EXPECT_EQ("Test", capability_->provider_.GetName()); |
| 338 | EXPECT_EQ("us", capability_->provider_.GetCountry()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 339 | EXPECT_EQ("1234", capability_->activation_code_); |
Arman Uguray | 2269bb6 | 2013-07-26 14:53:30 -0700 | [diff] [blame] | 340 | EXPECT_EQ("1", cellular_->service()->serving_operator().GetCode()); |
| 341 | EXPECT_EQ("Test", cellular_->service()->serving_operator().GetName()); |
| 342 | EXPECT_EQ("us", cellular_->service()->serving_operator().GetCountry()); |
Arman Uguray | e015faf | 2013-08-16 17:54:59 -0700 | [diff] [blame] | 343 | |
| 344 | capability_->sid_ = 1; |
| 345 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 346 | GetCellularOperatorBySID(_)) |
| 347 | .WillOnce(Return(nullptr)); |
| 348 | |
| 349 | capability_->UpdateOperatorInfo(); |
| 350 | EXPECT_EQ("1", capability_->provider_.GetCode()); |
| 351 | EXPECT_EQ("", capability_->provider_.GetName()); |
| 352 | EXPECT_EQ("", capability_->provider_.GetCountry()); |
| 353 | EXPECT_TRUE(capability_->activation_code_.empty()); |
| 354 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame^] | 357 | TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateServiceOLP) { |
| 358 | const MobileOperatorInfo::OnlinePortal kOlp { |
| 359 | "http://testurl", |
| 360 | "POST", |
| 361 | "esn=${esn}&mdn=${mdn}&meid=${meid}"}; |
| 362 | const vector<MobileOperatorInfo::OnlinePortal> kOlpList {kOlp}; |
| 363 | const string kUuidVzw = "vzw"; |
| 364 | const string kUuidFoo = "foo"; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 365 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame^] | 366 | MockMobileOperatorInfo *serving_operator_info = |
| 367 | mock_serving_operator_info_.get(); |
| 368 | SetMockMobileOperatorInfoObjects(); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 369 | cellular_->set_esn("0"); |
| 370 | cellular_->set_mdn("10123456789"); |
| 371 | cellular_->set_meid("4"); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 372 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 373 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame^] | 374 | serving_operator_info->SetEmptyDefaultsForProperties(); |
| 375 | EXPECT_CALL(*serving_operator_info, IsMobileNetworkOperatorKnown()) |
| 376 | .WillRepeatedly(Return(true)); |
| 377 | EXPECT_CALL(*serving_operator_info, olp_list()) |
| 378 | .WillRepeatedly(ReturnRef(kOlpList)); |
| 379 | EXPECT_CALL(*serving_operator_info, uuid()) |
| 380 | .WillOnce(ReturnRef(kUuidVzw)); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 381 | SetService(); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame^] | 382 | capability_->UpdateServiceOLP(); |
| 383 | // Copy to simplify assertions below. |
| 384 | Stringmap vzw_olp = cellular_->service()->olp(); |
| 385 | EXPECT_EQ("http://testurl", vzw_olp[kPaymentPortalURL]); |
| 386 | EXPECT_EQ("POST", vzw_olp[kPaymentPortalMethod]); |
| 387 | EXPECT_EQ("esn=0&mdn=0123456789&meid=4", |
| 388 | vzw_olp[kPaymentPortalPostData]); |
| 389 | Mock::VerifyAndClearExpectations(serving_operator_info); |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 390 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame^] | 391 | serving_operator_info->SetEmptyDefaultsForProperties(); |
| 392 | EXPECT_CALL(*serving_operator_info, IsMobileNetworkOperatorKnown()) |
| 393 | .WillRepeatedly(Return(true)); |
| 394 | EXPECT_CALL(*serving_operator_info, olp_list()) |
| 395 | .WillRepeatedly(ReturnRef(kOlpList)); |
| 396 | EXPECT_CALL(*serving_operator_info, uuid()) |
| 397 | .WillOnce(ReturnRef(kUuidFoo)); |
| 398 | capability_->UpdateServiceOLP(); |
| 399 | // Copy to simplify assertions below. |
| 400 | Stringmap olp = cellular_->service()->olp(); |
| 401 | EXPECT_EQ("http://testurl", olp[kPaymentPortalURL]); |
| 402 | EXPECT_EQ("POST", olp[kPaymentPortalMethod]); |
| 403 | EXPECT_EQ("esn=0&mdn=10123456789&meid=4", |
| 404 | olp[kPaymentPortalPostData]); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 407 | TEST_F(CellularCapabilityUniversalCDMAMainTest, ActivateAutomatic) { |
| 408 | mm1::MockModemModemCdmaProxy *cdma_proxy = modem_cdma_proxy_.get(); |
| 409 | SetUp(); |
| 410 | capability_->InitProxies(); |
| 411 | |
| 412 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 413 | GetActivationState(_,_)) |
| 414 | .Times(0); |
| 415 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 416 | SetActivationState(_,_,_)) |
| 417 | .Times(0); |
| 418 | EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0); |
| 419 | capability_->ActivateAutomatic(); |
| 420 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 421 | Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get()); |
| 422 | |
| 423 | capability_->activation_code_ = "1234"; |
| 424 | |
| 425 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 426 | GetActivationState(PendingActivationStore::kIdentifierMEID, _)) |
| 427 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 428 | .WillOnce(Return(PendingActivationStore::kStateActivated)); |
| 429 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 430 | SetActivationState(_,_,_)) |
| 431 | .Times(0); |
| 432 | EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0); |
| 433 | capability_->ActivateAutomatic(); |
| 434 | capability_->ActivateAutomatic(); |
| 435 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 436 | Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get()); |
| 437 | |
| 438 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 439 | GetActivationState(PendingActivationStore::kIdentifierMEID, _)) |
| 440 | .WillOnce(Return(PendingActivationStore::kStateUnknown)) |
| 441 | .WillOnce(Return(PendingActivationStore::kStateFailureRetry)); |
| 442 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 443 | SetActivationState(_,_, PendingActivationStore::kStatePending)) |
| 444 | .Times(2); |
| 445 | EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(2); |
| 446 | capability_->ActivateAutomatic(); |
| 447 | capability_->ActivateAutomatic(); |
| 448 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 449 | Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get()); |
| 450 | } |
| 451 | |
| 452 | TEST_F(CellularCapabilityUniversalCDMAMainTest, IsServiceActivationRequired) { |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame^] | 453 | CellularOperatorInfo::OLP olp; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 454 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_)) |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame^] | 455 | .WillOnce(Return((const CellularOperatorInfo::OLP *)NULL)) |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 456 | .WillRepeatedly(Return(&olp)); |
| 457 | capability_->activation_state_ = |
| 458 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 459 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 460 | EXPECT_TRUE(capability_->IsServiceActivationRequired()); |
| 461 | capability_->activation_state_ = |
| 462 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 463 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 464 | capability_->activation_state_ = |
| 465 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED; |
| 466 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 467 | } |
| 468 | |
| 469 | TEST_F(CellularCapabilityUniversalCDMAMainTest, |
| 470 | UpdateServiceActivationStateProperty) { |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame^] | 471 | CellularOperatorInfo::OLP olp; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 472 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_)) |
| 473 | .WillRepeatedly(Return(&olp)); |
| 474 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 475 | GetActivationState(_, _)) |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 476 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 477 | .WillRepeatedly(Return(PendingActivationStore::kStateUnknown)); |
| 478 | |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 479 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 480 | EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating)) |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 481 | .Times(1); |
| 482 | capability_->UpdateServiceActivationStateProperty(); |
| 483 | Mock::VerifyAndClearExpectations(service_); |
| 484 | |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 485 | EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated)) |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 486 | .Times(1); |
| 487 | capability_->UpdateServiceActivationStateProperty(); |
| 488 | Mock::VerifyAndClearExpectations(service_); |
| 489 | |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 490 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 491 | EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating)) |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 492 | .Times(1); |
| 493 | capability_->UpdateServiceActivationStateProperty(); |
| 494 | Mock::VerifyAndClearExpectations(service_); |
| 495 | |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 496 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED; |
| 497 | EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated)) |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 498 | .Times(1); |
| 499 | capability_->UpdateServiceActivationStateProperty(); |
| 500 | Mock::VerifyAndClearExpectations(service_); |
| 501 | Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info()); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 502 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | TEST_F(CellularCapabilityUniversalCDMAMainTest, IsActivating) { |
| 506 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 507 | GetActivationState(_,_)) |
| 508 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 509 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 510 | .WillOnce(Return(PendingActivationStore::kStateFailureRetry)) |
| 511 | .WillRepeatedly(Return(PendingActivationStore::kStateUnknown)); |
| 512 | |
| 513 | capability_->activation_state_ = |
| 514 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 515 | EXPECT_TRUE(capability_->IsActivating()); |
| 516 | EXPECT_TRUE(capability_->IsActivating()); |
| 517 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 518 | EXPECT_TRUE(capability_->IsActivating()); |
| 519 | EXPECT_TRUE(capability_->IsActivating()); |
| 520 | capability_->activation_state_ = |
| 521 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 522 | EXPECT_FALSE(capability_->IsActivating()); |
| 523 | } |
| 524 | |
Ben Chan | b2c4a80 | 2013-11-14 12:47:52 -0800 | [diff] [blame] | 525 | TEST_F(CellularCapabilityUniversalCDMAMainTest, IsRegistered) { |
| 526 | capability_->cdma_1x_registration_state_ = |
| 527 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 528 | capability_->cdma_evdo_registration_state_ = |
| 529 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 530 | EXPECT_FALSE(capability_->IsRegistered()); |
| 531 | |
| 532 | capability_->cdma_evdo_registration_state_ = |
| 533 | MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; |
| 534 | EXPECT_TRUE(capability_->IsRegistered()); |
| 535 | |
| 536 | capability_->cdma_evdo_registration_state_ = |
| 537 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME; |
| 538 | EXPECT_TRUE(capability_->IsRegistered()); |
| 539 | |
| 540 | capability_->cdma_evdo_registration_state_ = |
| 541 | MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING; |
| 542 | EXPECT_TRUE(capability_->IsRegistered()); |
| 543 | |
| 544 | capability_->cdma_1x_registration_state_ = |
| 545 | MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; |
| 546 | capability_->cdma_evdo_registration_state_ = |
| 547 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 548 | EXPECT_TRUE(capability_->IsRegistered()); |
| 549 | |
| 550 | capability_->cdma_evdo_registration_state_ = |
| 551 | MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; |
| 552 | EXPECT_TRUE(capability_->IsRegistered()); |
| 553 | |
| 554 | capability_->cdma_evdo_registration_state_ = |
| 555 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME; |
| 556 | EXPECT_TRUE(capability_->IsRegistered()); |
| 557 | |
| 558 | capability_->cdma_evdo_registration_state_ = |
| 559 | MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING; |
| 560 | EXPECT_TRUE(capability_->IsRegistered()); |
| 561 | |
| 562 | capability_->cdma_1x_registration_state_ = |
| 563 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME; |
| 564 | capability_->cdma_evdo_registration_state_ = |
| 565 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 566 | EXPECT_TRUE(capability_->IsRegistered()); |
| 567 | |
| 568 | capability_->cdma_evdo_registration_state_ = |
| 569 | MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; |
| 570 | EXPECT_TRUE(capability_->IsRegistered()); |
| 571 | |
| 572 | capability_->cdma_evdo_registration_state_ = |
| 573 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME; |
| 574 | EXPECT_TRUE(capability_->IsRegistered()); |
| 575 | |
| 576 | capability_->cdma_evdo_registration_state_ = |
| 577 | MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING; |
| 578 | EXPECT_TRUE(capability_->IsRegistered()); |
| 579 | |
| 580 | capability_->cdma_1x_registration_state_ = |
| 581 | MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING; |
| 582 | capability_->cdma_evdo_registration_state_ = |
| 583 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 584 | EXPECT_TRUE(capability_->IsRegistered()); |
| 585 | |
| 586 | capability_->cdma_evdo_registration_state_ = |
| 587 | MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; |
| 588 | EXPECT_TRUE(capability_->IsRegistered()); |
| 589 | |
| 590 | capability_->cdma_evdo_registration_state_ = |
| 591 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME; |
| 592 | EXPECT_TRUE(capability_->IsRegistered()); |
| 593 | |
| 594 | capability_->cdma_evdo_registration_state_ = |
| 595 | MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING; |
| 596 | EXPECT_TRUE(capability_->IsRegistered()); |
| 597 | } |
| 598 | |
Arman Uguray | c967306 | 2013-05-13 21:21:53 -0700 | [diff] [blame] | 599 | TEST_F(CellularCapabilityUniversalCDMAMainTest, SetupConnectProperties) { |
| 600 | DBusPropertiesMap map; |
| 601 | capability_->SetupConnectProperties(&map); |
| 602 | EXPECT_EQ(1, map.size()); |
| 603 | EXPECT_STREQ("#777", map["number"].reader().get_string()); |
| 604 | } |
| 605 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 606 | TEST_F(CellularCapabilityUniversalCDMADispatcherTest, |
| 607 | UpdatePendingActivationState) { |
| 608 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED; |
| 609 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 610 | .Times(1); |
| 611 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 612 | GetActivationState(_,_)) |
| 613 | .Times(0); |
| 614 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0); |
| 615 | capability_->UpdatePendingActivationState(); |
| 616 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 617 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 618 | |
| 619 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 620 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 621 | .Times(0); |
| 622 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 623 | GetActivationState(_,_)) |
| 624 | .Times(2) |
| 625 | .WillRepeatedly(Return(PendingActivationStore::kStateUnknown)); |
| 626 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0); |
| 627 | capability_->UpdatePendingActivationState(); |
| 628 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 629 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 630 | |
| 631 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 632 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 633 | .Times(0); |
| 634 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 635 | GetActivationState(_,_)) |
| 636 | .Times(2) |
| 637 | .WillRepeatedly(Return(PendingActivationStore::kStatePending)); |
| 638 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0); |
| 639 | capability_->UpdatePendingActivationState(); |
| 640 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 641 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 642 | |
| 643 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 644 | .Times(0); |
| 645 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 646 | GetActivationState(_,_)) |
| 647 | .Times(2) |
| 648 | .WillRepeatedly(Return(PendingActivationStore::kStateFailureRetry)); |
| 649 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(1); |
| 650 | capability_->UpdatePendingActivationState(); |
| 651 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 652 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 653 | |
| 654 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 655 | .Times(0); |
| 656 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 657 | GetActivationState(_,_)) |
| 658 | .Times(4) |
| 659 | .WillOnce(Return(PendingActivationStore::kStateActivated)) |
| 660 | .WillOnce(Return(PendingActivationStore::kStateActivated)) |
| 661 | .WillOnce(Return(PendingActivationStore::kStateUnknown)) |
| 662 | .WillOnce(Return(PendingActivationStore::kStateUnknown)); |
| 663 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0); |
| 664 | capability_->UpdatePendingActivationState(); |
| 665 | capability_->UpdatePendingActivationState(); |
| 666 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 667 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 668 | } |
| 669 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 670 | } // namespace shill |