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