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