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