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 | |
| 10 | #include <base/stringprintf.h> |
| 11 | #include <gmock/gmock.h> |
| 12 | #include <gtest/gtest.h> |
| 13 | #include <ModemManager/ModemManager.h> |
| 14 | |
| 15 | #include "shill/cellular.h" |
| 16 | #include "shill/cellular_service.h" |
| 17 | #include "shill/event_dispatcher.h" |
| 18 | #include "shill/mock_adaptors.h" |
| 19 | #include "shill/mock_cellular_operator_info.h" |
| 20 | #include "shill/mock_cellular_service.h" |
| 21 | #include "shill/mock_dbus_properties_proxy.h" |
| 22 | #include "shill/mock_glib.h" |
| 23 | #include "shill/mock_manager.h" |
| 24 | #include "shill/mock_metrics.h" |
| 25 | #include "shill/mock_mm1_bearer_proxy.h" |
| 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" |
| 31 | #include "shill/mock_modem_info.h" |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 32 | #include "shill/mock_pending_activation_store.h" |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 33 | #include "shill/nice_mock_control.h" |
| 34 | #include "shill/proxy_factory.h" |
| 35 | |
| 36 | using base::StringPrintf; |
| 37 | using std::string; |
| 38 | using std::vector; |
| 39 | using testing::Invoke; |
| 40 | using testing::Mock; |
| 41 | using testing::NiceMock; |
| 42 | using testing::Return; |
| 43 | using testing::SetArgumentPointee; |
| 44 | using testing::_; |
| 45 | |
| 46 | namespace shill { |
| 47 | |
| 48 | class CellularCapabilityUniversalCDMATest : public testing::Test { |
| 49 | public: |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 50 | CellularCapabilityUniversalCDMATest(EventDispatcher *dispatcher) |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 51 | : capability_(NULL), |
| 52 | device_adaptor_(NULL), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 53 | modem_info_(NULL, dispatcher, NULL, NULL, NULL), |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 54 | bearer_proxy_(new mm1::MockBearerProxy()), |
| 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), |
| 62 | cellular_(new Cellular(&modem_info_, |
| 63 | "", |
| 64 | kMachineAddress, |
| 65 | 0, |
| 66 | Cellular::kTypeUniversalCDMA, |
| 67 | "", |
| 68 | "", |
| 69 | "", |
| 70 | &proxy_factory_)), |
| 71 | service_(new MockCellularService(&modem_info_, |
| 72 | cellular_)) {} |
| 73 | |
| 74 | virtual ~CellularCapabilityUniversalCDMATest() { |
| 75 | cellular_->service_ = NULL; |
| 76 | capability_ = NULL; |
| 77 | device_adaptor_ = NULL; |
| 78 | } |
| 79 | |
| 80 | virtual void SetUp() { |
| 81 | capability_ = dynamic_cast<CellularCapabilityUniversalCDMA *>( |
| 82 | cellular_->capability_.get()); |
| 83 | device_adaptor_ = |
| 84 | dynamic_cast<NiceMock<DeviceMockAdaptor> *>(cellular_->adaptor()); |
| 85 | cellular_->service_ = service_; |
| 86 | } |
| 87 | |
| 88 | virtual void TearDown() { |
| 89 | capability_->proxy_factory_ = NULL; |
| 90 | } |
| 91 | |
| 92 | void SetService() { |
| 93 | cellular_->service_ = new CellularService(&modem_info_, cellular_); |
| 94 | } |
| 95 | |
| 96 | void ReleaseCapabilityProxies() { |
| 97 | capability_->ReleaseProxies(); |
| 98 | } |
| 99 | |
| 100 | void SetCdmaProxy() { |
| 101 | capability_->modem_cdma_proxy_.reset(modem_cdma_proxy_.release()); |
| 102 | } |
| 103 | |
| 104 | void SetSimpleProxy() { |
| 105 | capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release()); |
| 106 | } |
| 107 | |
| 108 | protected: |
| 109 | static const char kEsn[]; |
| 110 | static const char kMachineAddress[]; |
| 111 | static const char kMeid[]; |
| 112 | |
| 113 | class TestProxyFactory : public ProxyFactory { |
| 114 | public: |
| 115 | explicit TestProxyFactory(CellularCapabilityUniversalCDMATest *test) : |
| 116 | test_(test) {} |
| 117 | |
| 118 | // TODO(armansito): Some of these methods won't be necessary after 3GPP |
| 119 | // gets refactored out of CellularCapabilityUniversal. |
| 120 | virtual mm1::BearerProxyInterface *CreateBearerProxy( |
| 121 | const std::string &path, |
| 122 | const std::string &/*service*/) { |
| 123 | return test_->bearer_proxy_.release(); |
| 124 | } |
| 125 | |
| 126 | virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy( |
| 127 | const std::string &/*path*/, |
| 128 | const std::string &/*service*/) { |
| 129 | return test_->modem_3gpp_proxy_.release(); |
| 130 | } |
| 131 | |
| 132 | virtual mm1::ModemModemCdmaProxyInterface *CreateMM1ModemModemCdmaProxy( |
| 133 | const std::string &/*path*/, |
| 134 | const std::string &/*service*/) { |
| 135 | return test_->modem_cdma_proxy_.release(); |
| 136 | } |
| 137 | |
| 138 | virtual mm1::ModemProxyInterface *CreateMM1ModemProxy( |
| 139 | const std::string &/*path*/, |
| 140 | const std::string &/*service*/) { |
| 141 | return test_->modem_proxy_.release(); |
| 142 | } |
| 143 | |
| 144 | virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy( |
| 145 | const std::string &/*path*/, |
| 146 | const std::string &/*service*/) { |
| 147 | return test_->modem_simple_proxy_.release(); |
| 148 | } |
| 149 | |
| 150 | virtual mm1::SimProxyInterface *CreateSimProxy( |
| 151 | const std::string &/*path*/, |
| 152 | const std::string &/*service*/) { |
| 153 | return test_->sim_proxy_.release(); |
| 154 | } |
| 155 | |
| 156 | virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy( |
| 157 | const std::string &/*path*/, |
| 158 | const std::string &/*service*/) { |
| 159 | return test_->properties_proxy_.release(); |
| 160 | } |
| 161 | |
| 162 | private: |
| 163 | CellularCapabilityUniversalCDMATest *test_; |
| 164 | }; |
| 165 | |
| 166 | |
| 167 | CellularCapabilityUniversalCDMA *capability_; |
| 168 | NiceMock<DeviceMockAdaptor> *device_adaptor_; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 169 | MockModemInfo modem_info_; |
| 170 | MockGLib glib_; |
| 171 | scoped_ptr<mm1::MockBearerProxy> bearer_proxy_; |
| 172 | // TODO(armansito): Remove |modem_3gpp_proxy_| after refactor. |
| 173 | scoped_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_; |
| 174 | scoped_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_; |
| 175 | scoped_ptr<mm1::MockModemProxy> modem_proxy_; |
| 176 | scoped_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_; |
| 177 | scoped_ptr<mm1::MockSimProxy> sim_proxy_; |
| 178 | scoped_ptr<MockDBusPropertiesProxy> properties_proxy_; |
| 179 | TestProxyFactory proxy_factory_; |
| 180 | CellularRefPtr cellular_; |
| 181 | MockCellularService *service_; |
| 182 | }; |
| 183 | |
| 184 | // static |
| 185 | const char CellularCapabilityUniversalCDMATest::kEsn[] = "0000"; |
| 186 | // static |
| 187 | const char CellularCapabilityUniversalCDMATest::kMachineAddress[] = |
| 188 | "TestMachineAddress"; |
| 189 | // static |
| 190 | const char CellularCapabilityUniversalCDMATest::kMeid[] = "11111111111111"; |
| 191 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 192 | class CellularCapabilityUniversalCDMAMainTest |
| 193 | : public CellularCapabilityUniversalCDMATest { |
| 194 | public: |
| 195 | CellularCapabilityUniversalCDMAMainTest() |
| 196 | : CellularCapabilityUniversalCDMATest(&dispatcher_) {} |
| 197 | |
| 198 | private: |
| 199 | EventDispatcher dispatcher_; |
| 200 | }; |
| 201 | |
| 202 | class CellularCapabilityUniversalCDMADispatcherTest |
| 203 | : public CellularCapabilityUniversalCDMATest { |
| 204 | public: |
| 205 | CellularCapabilityUniversalCDMADispatcherTest() |
| 206 | : CellularCapabilityUniversalCDMATest(NULL) {} |
| 207 | }; |
| 208 | |
| 209 | TEST_F(CellularCapabilityUniversalCDMAMainTest, PropertiesChanged) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 210 | // Set up mock modem CDMA properties. |
| 211 | DBusPropertiesMap modem_cdma_properties; |
| 212 | modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_MEID]. |
| 213 | writer().append_string(kMeid); |
| 214 | modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_ESN]. |
| 215 | writer().append_string(kEsn); |
| 216 | |
| 217 | SetUp(); |
| 218 | |
| 219 | EXPECT_TRUE(capability_->meid().empty()); |
| 220 | EXPECT_TRUE(capability_->esn().empty()); |
| 221 | |
| 222 | // Changing properties on wrong interface will not have an effect |
| 223 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 224 | modem_cdma_properties, |
| 225 | vector<string>()); |
| 226 | EXPECT_TRUE(capability_->meid().empty()); |
| 227 | EXPECT_TRUE(capability_->esn().empty()); |
| 228 | |
| 229 | // Changing properties on the right interface gets reflected in the |
| 230 | // capabilities object |
| 231 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEMCDMA, |
| 232 | modem_cdma_properties, |
| 233 | vector<string>()); |
| 234 | EXPECT_EQ(kMeid, capability_->meid()); |
| 235 | EXPECT_EQ(kEsn, capability_->esn()); |
| 236 | } |
| 237 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 238 | TEST_F(CellularCapabilityUniversalCDMAMainTest, OnCDMARegistrationChanged) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 239 | EXPECT_EQ(0, capability_->sid_); |
| 240 | EXPECT_EQ(0, capability_->nid_); |
| 241 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 242 | capability_->cdma_1x_registration_state_); |
| 243 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 244 | capability_->cdma_evdo_registration_state_); |
| 245 | |
| 246 | EXPECT_EQ("", capability_->provider_.GetCode()); |
| 247 | EXPECT_EQ("", capability_->provider_.GetName()); |
| 248 | EXPECT_EQ("", capability_->provider_.GetCountry()); |
| 249 | |
| 250 | CellularOperatorInfo::CellularOperator *provider = |
| 251 | new CellularOperatorInfo::CellularOperator(); |
| 252 | |
| 253 | provider->country_ = "us"; |
| 254 | provider->is_primary_ = true; |
| 255 | provider->name_list_.push_back( |
| 256 | CellularOperatorInfo::LocalizedName("Test", "")); |
| 257 | |
| 258 | scoped_ptr<const CellularOperatorInfo::CellularOperator> ptr(provider); |
| 259 | |
| 260 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 261 | GetCellularOperatorBySID("2")) |
| 262 | .WillOnce(Return(ptr.get())); |
| 263 | |
| 264 | capability_->OnCDMARegistrationChanged( |
| 265 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 266 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
| 267 | 2, |
| 268 | 0); |
| 269 | EXPECT_EQ(2, capability_->sid_); |
| 270 | EXPECT_EQ(0, capability_->nid_); |
| 271 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 272 | capability_->cdma_1x_registration_state_); |
| 273 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
| 274 | capability_->cdma_evdo_registration_state_); |
| 275 | |
| 276 | EXPECT_TRUE(capability_->IsRegistered()); |
| 277 | EXPECT_EQ("2", capability_->provider_.GetCode()); |
| 278 | EXPECT_EQ("Test", capability_->provider_.GetName()); |
| 279 | EXPECT_EQ("us", capability_->provider_.GetCountry()); |
| 280 | } |
| 281 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 282 | TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateOperatorInfo) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 283 | EXPECT_EQ("", capability_->provider_.GetCode()); |
| 284 | EXPECT_EQ("", capability_->provider_.GetName()); |
| 285 | EXPECT_EQ("", capability_->provider_.GetCountry()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 286 | EXPECT_TRUE(capability_->activation_code_.empty()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 287 | |
| 288 | capability_->UpdateOperatorInfo(); |
| 289 | EXPECT_EQ("", capability_->provider_.GetCode()); |
| 290 | EXPECT_EQ("", capability_->provider_.GetName()); |
| 291 | EXPECT_EQ("", capability_->provider_.GetCountry()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 292 | EXPECT_TRUE(capability_->activation_code_.empty()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 293 | |
| 294 | |
| 295 | capability_->UpdateOperatorInfo(); |
| 296 | EXPECT_EQ("", capability_->provider_.GetCode()); |
| 297 | EXPECT_EQ("", capability_->provider_.GetName()); |
| 298 | EXPECT_EQ("", capability_->provider_.GetCountry()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 299 | EXPECT_TRUE(capability_->activation_code_.empty()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 300 | |
| 301 | capability_->sid_ = 1; |
| 302 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 303 | GetCellularOperatorBySID(_)) |
| 304 | .WillOnce(Return((const CellularOperatorInfo::CellularOperator *)NULL)); |
| 305 | |
| 306 | capability_->UpdateOperatorInfo(); |
| 307 | EXPECT_EQ("", capability_->provider_.GetCode()); |
| 308 | EXPECT_EQ("", capability_->provider_.GetName()); |
| 309 | EXPECT_EQ("", capability_->provider_.GetCountry()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 310 | EXPECT_TRUE(capability_->activation_code_.empty()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 311 | |
| 312 | CellularOperatorInfo::CellularOperator *provider = |
| 313 | new CellularOperatorInfo::CellularOperator(); |
| 314 | |
| 315 | provider->country_ = "us"; |
| 316 | provider->is_primary_ = true; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 317 | provider->activation_code_ = "1234"; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 318 | provider->name_list_.push_back( |
| 319 | CellularOperatorInfo::LocalizedName("Test", "")); |
| 320 | |
| 321 | scoped_ptr<const CellularOperatorInfo::CellularOperator> ptr(provider); |
| 322 | |
| 323 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 324 | GetCellularOperatorBySID(_)) |
| 325 | .WillOnce(Return(ptr.get())); |
| 326 | |
| 327 | capability_->UpdateOperatorInfo(); |
| 328 | |
| 329 | EXPECT_EQ("1", capability_->provider_.GetCode()); |
| 330 | EXPECT_EQ("Test", capability_->provider_.GetName()); |
| 331 | EXPECT_EQ("us", capability_->provider_.GetCountry()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 332 | EXPECT_EQ("1234", capability_->activation_code_); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 333 | } |
| 334 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 335 | TEST_F(CellularCapabilityUniversalCDMAMainTest, CreateFriendlyServiceName) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 336 | CellularCapabilityUniversalCDMA::friendly_service_name_id_cdma_ = 0; |
| 337 | EXPECT_EQ(0, capability_->sid_); |
| 338 | EXPECT_EQ("CDMANetwork0", capability_->CreateFriendlyServiceName()); |
| 339 | EXPECT_EQ("CDMANetwork1", capability_->CreateFriendlyServiceName()); |
| 340 | |
| 341 | capability_->provider_.SetCode("0123"); |
| 342 | EXPECT_EQ("cellular_sid_0123", capability_->CreateFriendlyServiceName()); |
| 343 | |
| 344 | CellularOperatorInfo::CellularOperator *provider = |
| 345 | new CellularOperatorInfo::CellularOperator(); |
| 346 | |
| 347 | capability_->sid_ = 1; |
| 348 | provider->name_list_.push_back( |
| 349 | CellularOperatorInfo::LocalizedName("Test", "")); |
| 350 | capability_->provider_.SetCode(""); |
| 351 | |
| 352 | scoped_ptr<const CellularOperatorInfo::CellularOperator> ptr(provider); |
| 353 | |
| 354 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 355 | GetCellularOperatorBySID(_)) |
| 356 | .WillOnce(Return(ptr.get())); |
| 357 | EXPECT_EQ("Test", capability_->CreateFriendlyServiceName()); |
| 358 | } |
| 359 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 360 | TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateOLP) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 361 | CellularService::OLP test_olp; |
| 362 | test_olp.SetURL("http://testurl"); |
| 363 | test_olp.SetMethod("POST"); |
| 364 | test_olp.SetPostData("esn=${esn}&mdn=${mdn}&meid=${meid}"); |
| 365 | |
| 366 | capability_->esn_ = "0"; |
| 367 | capability_->mdn_ = "3"; |
| 368 | capability_->meid_= "4"; |
| 369 | capability_->sid_ = 1; |
| 370 | |
| 371 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 372 | GetOLPBySID(base::StringPrintf("%u", capability_->sid_))) |
| 373 | .WillRepeatedly(Return(&test_olp)); |
| 374 | |
| 375 | SetService(); |
| 376 | capability_->UpdateOLP(); |
| 377 | const CellularService::OLP &olp = cellular_->service()->olp(); |
| 378 | EXPECT_EQ("http://testurl", olp.GetURL()); |
| 379 | EXPECT_EQ("POST", olp.GetMethod()); |
| 380 | EXPECT_EQ("esn=0&mdn=3&meid=4", olp.GetPostData()); |
| 381 | } |
| 382 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 383 | TEST_F(CellularCapabilityUniversalCDMAMainTest, ActivateAutomatic) { |
| 384 | mm1::MockModemModemCdmaProxy *cdma_proxy = modem_cdma_proxy_.get(); |
| 385 | SetUp(); |
| 386 | capability_->InitProxies(); |
| 387 | |
| 388 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 389 | GetActivationState(_,_)) |
| 390 | .Times(0); |
| 391 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 392 | SetActivationState(_,_,_)) |
| 393 | .Times(0); |
| 394 | EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0); |
| 395 | capability_->ActivateAutomatic(); |
| 396 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 397 | Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get()); |
| 398 | |
| 399 | capability_->activation_code_ = "1234"; |
| 400 | |
| 401 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 402 | GetActivationState(PendingActivationStore::kIdentifierMEID, _)) |
| 403 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 404 | .WillOnce(Return(PendingActivationStore::kStateActivated)); |
| 405 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 406 | SetActivationState(_,_,_)) |
| 407 | .Times(0); |
| 408 | EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0); |
| 409 | capability_->ActivateAutomatic(); |
| 410 | capability_->ActivateAutomatic(); |
| 411 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 412 | Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get()); |
| 413 | |
| 414 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 415 | GetActivationState(PendingActivationStore::kIdentifierMEID, _)) |
| 416 | .WillOnce(Return(PendingActivationStore::kStateUnknown)) |
| 417 | .WillOnce(Return(PendingActivationStore::kStateFailureRetry)); |
| 418 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 419 | SetActivationState(_,_, PendingActivationStore::kStatePending)) |
| 420 | .Times(2); |
| 421 | EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(2); |
| 422 | capability_->ActivateAutomatic(); |
| 423 | capability_->ActivateAutomatic(); |
| 424 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 425 | Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get()); |
| 426 | } |
| 427 | |
| 428 | TEST_F(CellularCapabilityUniversalCDMAMainTest, IsServiceActivationRequired) { |
| 429 | CellularService::OLP olp; |
| 430 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_)) |
| 431 | .WillOnce(Return((const CellularService::OLP *)NULL)) |
| 432 | .WillRepeatedly(Return(&olp)); |
| 433 | capability_->activation_state_ = |
| 434 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 435 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 436 | EXPECT_TRUE(capability_->IsServiceActivationRequired()); |
| 437 | capability_->activation_state_ = |
| 438 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 439 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 440 | capability_->activation_state_ = |
| 441 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED; |
| 442 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 443 | } |
| 444 | |
| 445 | TEST_F(CellularCapabilityUniversalCDMAMainTest, |
| 446 | UpdateServiceActivationStateProperty) { |
| 447 | CellularService::OLP olp; |
| 448 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_)) |
| 449 | .WillRepeatedly(Return(&olp)); |
| 450 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 451 | GetActivationState(_,_)) |
| 452 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 453 | .WillRepeatedly(Return(PendingActivationStore::kStateUnknown)); |
| 454 | |
| 455 | capability_->activation_state_ = |
| 456 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 457 | EXPECT_CALL(*service_, |
| 458 | SetActivationState(flimflam::kActivationStateActivating)) |
| 459 | .Times(1); |
| 460 | capability_->UpdateServiceActivationStateProperty(); |
| 461 | Mock::VerifyAndClearExpectations(service_); |
| 462 | |
| 463 | EXPECT_CALL(*service_, |
| 464 | SetActivationState(flimflam::kActivationStateNotActivated)) |
| 465 | .Times(1); |
| 466 | capability_->UpdateServiceActivationStateProperty(); |
| 467 | Mock::VerifyAndClearExpectations(service_); |
| 468 | |
| 469 | capability_->activation_state_ = |
| 470 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 471 | EXPECT_CALL(*service_, |
| 472 | SetActivationState(flimflam::kActivationStateActivating)) |
| 473 | .Times(1); |
| 474 | capability_->UpdateServiceActivationStateProperty(); |
| 475 | Mock::VerifyAndClearExpectations(service_); |
| 476 | |
| 477 | capability_->activation_state_ = |
| 478 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED; |
| 479 | EXPECT_CALL(*service_, |
| 480 | SetActivationState(flimflam::kActivationStateActivated)) |
| 481 | .Times(1); |
| 482 | capability_->UpdateServiceActivationStateProperty(); |
| 483 | Mock::VerifyAndClearExpectations(service_); |
| 484 | Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info()); |
| 485 | Mock::VerifyAndClearExpectations( |
| 486 | modem_info_.mock_pending_activation_store()); |
| 487 | } |
| 488 | |
| 489 | TEST_F(CellularCapabilityUniversalCDMAMainTest, IsActivating) { |
| 490 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 491 | GetActivationState(_,_)) |
| 492 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 493 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 494 | .WillOnce(Return(PendingActivationStore::kStateFailureRetry)) |
| 495 | .WillRepeatedly(Return(PendingActivationStore::kStateUnknown)); |
| 496 | |
| 497 | capability_->activation_state_ = |
| 498 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 499 | EXPECT_TRUE(capability_->IsActivating()); |
| 500 | EXPECT_TRUE(capability_->IsActivating()); |
| 501 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 502 | EXPECT_TRUE(capability_->IsActivating()); |
| 503 | EXPECT_TRUE(capability_->IsActivating()); |
| 504 | capability_->activation_state_ = |
| 505 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 506 | EXPECT_FALSE(capability_->IsActivating()); |
| 507 | } |
| 508 | |
| 509 | TEST_F(CellularCapabilityUniversalCDMADispatcherTest, |
| 510 | UpdatePendingActivationState) { |
| 511 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED; |
| 512 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 513 | .Times(1); |
| 514 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 515 | GetActivationState(_,_)) |
| 516 | .Times(0); |
| 517 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0); |
| 518 | capability_->UpdatePendingActivationState(); |
| 519 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 520 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 521 | |
| 522 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 523 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 524 | .Times(0); |
| 525 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 526 | GetActivationState(_,_)) |
| 527 | .Times(2) |
| 528 | .WillRepeatedly(Return(PendingActivationStore::kStateUnknown)); |
| 529 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0); |
| 530 | capability_->UpdatePendingActivationState(); |
| 531 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 532 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 533 | |
| 534 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 535 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 536 | .Times(0); |
| 537 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 538 | GetActivationState(_,_)) |
| 539 | .Times(2) |
| 540 | .WillRepeatedly(Return(PendingActivationStore::kStatePending)); |
| 541 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0); |
| 542 | capability_->UpdatePendingActivationState(); |
| 543 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 544 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 545 | |
| 546 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 547 | .Times(0); |
| 548 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 549 | GetActivationState(_,_)) |
| 550 | .Times(2) |
| 551 | .WillRepeatedly(Return(PendingActivationStore::kStateFailureRetry)); |
| 552 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(1); |
| 553 | capability_->UpdatePendingActivationState(); |
| 554 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 555 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 556 | |
| 557 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 558 | .Times(0); |
| 559 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 560 | GetActivationState(_,_)) |
| 561 | .Times(4) |
| 562 | .WillOnce(Return(PendingActivationStore::kStateActivated)) |
| 563 | .WillOnce(Return(PendingActivationStore::kStateActivated)) |
| 564 | .WillOnce(Return(PendingActivationStore::kStateUnknown)) |
| 565 | .WillOnce(Return(PendingActivationStore::kStateUnknown)); |
| 566 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0); |
| 567 | capability_->UpdatePendingActivationState(); |
| 568 | capability_->UpdatePendingActivationState(); |
| 569 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 570 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 571 | } |
| 572 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 573 | } // namespace shill |