shill: cellular: Handle invalid SIM object path "/".
This CL modifies CellularCapabilityUniversal::OnSimLockStatusChanged()
to properly handle an invalid SIM object path "/".
BUG=None
TEST=Build and run unit tests.
Change-Id: Ifb8e468671d11a3360ffbb6a96607d8c3c064a75
Reviewed-on: https://gerrit.chromium.org/gerrit/61651
Reviewed-by: Thieu Le <thieule@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
Commit-Queue: Ben Chan <benchan@chromium.org>
diff --git a/cellular_capability_universal.cc b/cellular_capability_universal.cc
index 482d89c..3311aea 100644
--- a/cellular_capability_universal.cc
+++ b/cellular_capability_universal.cc
@@ -1826,7 +1826,7 @@
// If the SIM is currently unlocked, assume that we need to refresh
// carrier information, since a locked SIM prevents shill from obtaining
// the necessary data to establish a connection later (e.g. IMSI).
- if (!sim_path_.empty() &&
+ if (IsValidSimPath(sim_path_) &&
(sim_lock_status_.lock_type == MM_MODEM_LOCK_NONE ||
sim_lock_status_.lock_type == MM_MODEM_LOCK_UNKNOWN)) {
scoped_ptr<DBusPropertiesProxyInterface> properties_proxy(
diff --git a/cellular_capability_universal_unittest.cc b/cellular_capability_universal_unittest.cc
index 98a4179..152da83 100644
--- a/cellular_capability_universal_unittest.cc
+++ b/cellular_capability_universal_unittest.cc
@@ -604,6 +604,38 @@
EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
EXPECT_EQ(kOperatorName, capability_->spn_);
+
+ // SIM is missing and SIM path is "/".
+ capability_->OnSimPathChanged(CellularCapabilityUniversal::kRootPath);
+ EXPECT_FALSE(capability_->sim_present_);
+ EXPECT_TRUE(capability_->sim_proxy_ == NULL);
+ EXPECT_EQ(CellularCapabilityUniversal::kRootPath, capability_->sim_path_);
+
+ EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
+ GetActivationState(_, _)).Times(0);
+ capability_->OnSimLockStatusChanged();
+ Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
+
+ EXPECT_EQ("", capability_->imsi_);
+ EXPECT_EQ("", capability_->sim_identifier_);
+ EXPECT_EQ("", capability_->operator_id_);
+ EXPECT_EQ("", capability_->spn_);
+
+ // SIM is missing and SIM path is empty.
+ capability_->OnSimPathChanged("");
+ EXPECT_FALSE(capability_->sim_present_);
+ EXPECT_TRUE(capability_->sim_proxy_ == NULL);
+ EXPECT_EQ("", capability_->sim_path_);
+
+ EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
+ GetActivationState(_, _)).Times(0);
+ capability_->OnSimLockStatusChanged();
+ Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
+
+ EXPECT_EQ("", capability_->imsi_);
+ EXPECT_EQ("", capability_->sim_identifier_);
+ EXPECT_EQ("", capability_->operator_id_);
+ EXPECT_EQ("", capability_->spn_);
}
TEST_F(CellularCapabilityUniversalMainTest, PropertiesChanged) {