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 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 285 | capability_->UpdateOperatorInfo(); |
| 286 | EXPECT_EQ("", capability_->provider_.GetCode()); |
| 287 | EXPECT_EQ("", capability_->provider_.GetName()); |
| 288 | EXPECT_EQ("", capability_->provider_.GetCountry()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 289 | EXPECT_TRUE(capability_->activation_code_.empty()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 290 | |
| 291 | capability_->sid_ = 1; |
| 292 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 293 | GetCellularOperatorBySID(_)) |
| 294 | .WillOnce(Return((const CellularOperatorInfo::CellularOperator *)NULL)); |
| 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 | |
| 302 | CellularOperatorInfo::CellularOperator *provider = |
| 303 | new CellularOperatorInfo::CellularOperator(); |
| 304 | |
| 305 | provider->country_ = "us"; |
| 306 | provider->is_primary_ = true; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 307 | provider->activation_code_ = "1234"; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 308 | provider->name_list_.push_back( |
| 309 | CellularOperatorInfo::LocalizedName("Test", "")); |
| 310 | |
| 311 | scoped_ptr<const CellularOperatorInfo::CellularOperator> ptr(provider); |
| 312 | |
| 313 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 314 | GetCellularOperatorBySID(_)) |
| 315 | .WillOnce(Return(ptr.get())); |
| 316 | |
| 317 | capability_->UpdateOperatorInfo(); |
| 318 | |
| 319 | EXPECT_EQ("1", capability_->provider_.GetCode()); |
| 320 | EXPECT_EQ("Test", capability_->provider_.GetName()); |
| 321 | EXPECT_EQ("us", capability_->provider_.GetCountry()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 322 | EXPECT_EQ("1234", capability_->activation_code_); |
Arman Uguray | 2269bb6 | 2013-07-26 14:53:30 -0700 | [diff] [blame] | 323 | EXPECT_EQ("1", cellular_->service()->serving_operator().GetCode()); |
| 324 | EXPECT_EQ("Test", cellular_->service()->serving_operator().GetName()); |
| 325 | EXPECT_EQ("us", cellular_->service()->serving_operator().GetCountry()); |
| 326 | EXPECT_EQ("Test", cellular_->service()->friendly_name()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 327 | } |
| 328 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 329 | TEST_F(CellularCapabilityUniversalCDMAMainTest, CreateFriendlyServiceName) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 330 | CellularCapabilityUniversalCDMA::friendly_service_name_id_cdma_ = 0; |
| 331 | EXPECT_EQ(0, capability_->sid_); |
| 332 | EXPECT_EQ("CDMANetwork0", capability_->CreateFriendlyServiceName()); |
| 333 | EXPECT_EQ("CDMANetwork1", capability_->CreateFriendlyServiceName()); |
| 334 | |
| 335 | capability_->provider_.SetCode("0123"); |
| 336 | EXPECT_EQ("cellular_sid_0123", capability_->CreateFriendlyServiceName()); |
| 337 | |
| 338 | CellularOperatorInfo::CellularOperator *provider = |
| 339 | new CellularOperatorInfo::CellularOperator(); |
| 340 | |
| 341 | capability_->sid_ = 1; |
| 342 | provider->name_list_.push_back( |
| 343 | CellularOperatorInfo::LocalizedName("Test", "")); |
| 344 | capability_->provider_.SetCode(""); |
| 345 | |
| 346 | scoped_ptr<const CellularOperatorInfo::CellularOperator> ptr(provider); |
| 347 | |
| 348 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 349 | GetCellularOperatorBySID(_)) |
| 350 | .WillOnce(Return(ptr.get())); |
| 351 | EXPECT_EQ("Test", capability_->CreateFriendlyServiceName()); |
| 352 | } |
| 353 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 354 | TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateOLP) { |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 355 | CellularOperatorInfo::CellularOperator cellular_operator; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 356 | CellularService::OLP test_olp; |
| 357 | test_olp.SetURL("http://testurl"); |
| 358 | test_olp.SetMethod("POST"); |
| 359 | test_olp.SetPostData("esn=${esn}&mdn=${mdn}&meid=${meid}"); |
| 360 | |
| 361 | capability_->esn_ = "0"; |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 362 | capability_->mdn_ = "10123456789"; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 363 | capability_->meid_= "4"; |
| 364 | capability_->sid_ = 1; |
| 365 | |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 366 | string sid_string = base::StringPrintf("%u", capability_->sid_); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 367 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 368 | GetCellularOperatorBySID(sid_string)) |
| 369 | .WillRepeatedly(Return(&cellular_operator)); |
| 370 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 371 | GetOLPBySID(sid_string)) |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 372 | .WillRepeatedly(Return(&test_olp)); |
| 373 | |
| 374 | SetService(); |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 375 | |
| 376 | cellular_operator.identifier_ = "vzw"; |
| 377 | capability_->UpdateOLP(); |
| 378 | const CellularService::OLP &vzw_olp = cellular_->service()->olp(); |
| 379 | EXPECT_EQ("http://testurl", vzw_olp.GetURL()); |
| 380 | EXPECT_EQ("POST", vzw_olp.GetMethod()); |
| 381 | EXPECT_EQ("esn=0&mdn=0123456789&meid=4", vzw_olp.GetPostData()); |
| 382 | |
| 383 | cellular_operator.identifier_ = "foo"; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 384 | capability_->UpdateOLP(); |
| 385 | const CellularService::OLP &olp = cellular_->service()->olp(); |
| 386 | EXPECT_EQ("http://testurl", olp.GetURL()); |
| 387 | EXPECT_EQ("POST", olp.GetMethod()); |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 388 | EXPECT_EQ("esn=0&mdn=10123456789&meid=4", olp.GetPostData()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 391 | TEST_F(CellularCapabilityUniversalCDMAMainTest, ActivateAutomatic) { |
| 392 | mm1::MockModemModemCdmaProxy *cdma_proxy = modem_cdma_proxy_.get(); |
| 393 | SetUp(); |
| 394 | capability_->InitProxies(); |
| 395 | |
| 396 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 397 | GetActivationState(_,_)) |
| 398 | .Times(0); |
| 399 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 400 | SetActivationState(_,_,_)) |
| 401 | .Times(0); |
| 402 | EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0); |
| 403 | capability_->ActivateAutomatic(); |
| 404 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 405 | Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get()); |
| 406 | |
| 407 | capability_->activation_code_ = "1234"; |
| 408 | |
| 409 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 410 | GetActivationState(PendingActivationStore::kIdentifierMEID, _)) |
| 411 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 412 | .WillOnce(Return(PendingActivationStore::kStateActivated)); |
| 413 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 414 | SetActivationState(_,_,_)) |
| 415 | .Times(0); |
| 416 | EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0); |
| 417 | capability_->ActivateAutomatic(); |
| 418 | capability_->ActivateAutomatic(); |
| 419 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 420 | Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get()); |
| 421 | |
| 422 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 423 | GetActivationState(PendingActivationStore::kIdentifierMEID, _)) |
| 424 | .WillOnce(Return(PendingActivationStore::kStateUnknown)) |
| 425 | .WillOnce(Return(PendingActivationStore::kStateFailureRetry)); |
| 426 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 427 | SetActivationState(_,_, PendingActivationStore::kStatePending)) |
| 428 | .Times(2); |
| 429 | EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(2); |
| 430 | capability_->ActivateAutomatic(); |
| 431 | capability_->ActivateAutomatic(); |
| 432 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 433 | Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get()); |
| 434 | } |
| 435 | |
| 436 | TEST_F(CellularCapabilityUniversalCDMAMainTest, IsServiceActivationRequired) { |
| 437 | CellularService::OLP olp; |
| 438 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_)) |
| 439 | .WillOnce(Return((const CellularService::OLP *)NULL)) |
| 440 | .WillRepeatedly(Return(&olp)); |
| 441 | capability_->activation_state_ = |
| 442 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 443 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 444 | EXPECT_TRUE(capability_->IsServiceActivationRequired()); |
| 445 | capability_->activation_state_ = |
| 446 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 447 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 448 | capability_->activation_state_ = |
| 449 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED; |
| 450 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 451 | } |
| 452 | |
| 453 | TEST_F(CellularCapabilityUniversalCDMAMainTest, |
| 454 | UpdateServiceActivationStateProperty) { |
| 455 | CellularService::OLP olp; |
| 456 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_)) |
| 457 | .WillRepeatedly(Return(&olp)); |
| 458 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 459 | GetActivationState(_,_)) |
| 460 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 461 | .WillRepeatedly(Return(PendingActivationStore::kStateUnknown)); |
| 462 | |
| 463 | capability_->activation_state_ = |
| 464 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 465 | EXPECT_CALL(*service_, |
| 466 | SetActivationState(flimflam::kActivationStateActivating)) |
| 467 | .Times(1); |
| 468 | capability_->UpdateServiceActivationStateProperty(); |
| 469 | Mock::VerifyAndClearExpectations(service_); |
| 470 | |
| 471 | EXPECT_CALL(*service_, |
| 472 | SetActivationState(flimflam::kActivationStateNotActivated)) |
| 473 | .Times(1); |
| 474 | capability_->UpdateServiceActivationStateProperty(); |
| 475 | Mock::VerifyAndClearExpectations(service_); |
| 476 | |
| 477 | capability_->activation_state_ = |
| 478 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 479 | EXPECT_CALL(*service_, |
| 480 | SetActivationState(flimflam::kActivationStateActivating)) |
| 481 | .Times(1); |
| 482 | capability_->UpdateServiceActivationStateProperty(); |
| 483 | Mock::VerifyAndClearExpectations(service_); |
| 484 | |
| 485 | capability_->activation_state_ = |
| 486 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED; |
| 487 | EXPECT_CALL(*service_, |
| 488 | SetActivationState(flimflam::kActivationStateActivated)) |
| 489 | .Times(1); |
| 490 | capability_->UpdateServiceActivationStateProperty(); |
| 491 | Mock::VerifyAndClearExpectations(service_); |
| 492 | Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info()); |
| 493 | Mock::VerifyAndClearExpectations( |
| 494 | modem_info_.mock_pending_activation_store()); |
| 495 | } |
| 496 | |
| 497 | TEST_F(CellularCapabilityUniversalCDMAMainTest, IsActivating) { |
| 498 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 499 | GetActivationState(_,_)) |
| 500 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 501 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 502 | .WillOnce(Return(PendingActivationStore::kStateFailureRetry)) |
| 503 | .WillRepeatedly(Return(PendingActivationStore::kStateUnknown)); |
| 504 | |
| 505 | capability_->activation_state_ = |
| 506 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 507 | EXPECT_TRUE(capability_->IsActivating()); |
| 508 | EXPECT_TRUE(capability_->IsActivating()); |
| 509 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 510 | EXPECT_TRUE(capability_->IsActivating()); |
| 511 | EXPECT_TRUE(capability_->IsActivating()); |
| 512 | capability_->activation_state_ = |
| 513 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 514 | EXPECT_FALSE(capability_->IsActivating()); |
| 515 | } |
| 516 | |
Arman Uguray | c967306 | 2013-05-13 21:21:53 -0700 | [diff] [blame] | 517 | TEST_F(CellularCapabilityUniversalCDMAMainTest, SetupConnectProperties) { |
| 518 | DBusPropertiesMap map; |
| 519 | capability_->SetupConnectProperties(&map); |
| 520 | EXPECT_EQ(1, map.size()); |
| 521 | EXPECT_STREQ("#777", map["number"].reader().get_string()); |
| 522 | } |
| 523 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 524 | TEST_F(CellularCapabilityUniversalCDMADispatcherTest, |
| 525 | UpdatePendingActivationState) { |
| 526 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED; |
| 527 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 528 | .Times(1); |
| 529 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 530 | GetActivationState(_,_)) |
| 531 | .Times(0); |
| 532 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0); |
| 533 | capability_->UpdatePendingActivationState(); |
| 534 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 535 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 536 | |
| 537 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 538 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 539 | .Times(0); |
| 540 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 541 | GetActivationState(_,_)) |
| 542 | .Times(2) |
| 543 | .WillRepeatedly(Return(PendingActivationStore::kStateUnknown)); |
| 544 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0); |
| 545 | capability_->UpdatePendingActivationState(); |
| 546 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 547 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 548 | |
| 549 | capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED; |
| 550 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 551 | .Times(0); |
| 552 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 553 | GetActivationState(_,_)) |
| 554 | .Times(2) |
| 555 | .WillRepeatedly(Return(PendingActivationStore::kStatePending)); |
| 556 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0); |
| 557 | capability_->UpdatePendingActivationState(); |
| 558 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 559 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 560 | |
| 561 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 562 | .Times(0); |
| 563 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 564 | GetActivationState(_,_)) |
| 565 | .Times(2) |
| 566 | .WillRepeatedly(Return(PendingActivationStore::kStateFailureRetry)); |
| 567 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(1); |
| 568 | capability_->UpdatePendingActivationState(); |
| 569 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 570 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 571 | |
| 572 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_)) |
| 573 | .Times(0); |
| 574 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 575 | GetActivationState(_,_)) |
| 576 | .Times(4) |
| 577 | .WillOnce(Return(PendingActivationStore::kStateActivated)) |
| 578 | .WillOnce(Return(PendingActivationStore::kStateActivated)) |
| 579 | .WillOnce(Return(PendingActivationStore::kStateUnknown)) |
| 580 | .WillOnce(Return(PendingActivationStore::kStateUnknown)); |
| 581 | EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0); |
| 582 | capability_->UpdatePendingActivationState(); |
| 583 | capability_->UpdatePendingActivationState(); |
| 584 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 585 | Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher()); |
| 586 | } |
| 587 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 588 | } // namespace shill |