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