Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Chan | c54afe5 | 2014-11-05 10:28:08 -0800 | [diff] [blame] | 5 | #include "shill/cellular/cellular_capability_universal.h" |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 6 | |
Nathan Williams | 4b7c2a8 | 2012-04-13 15:19:47 -0400 | [diff] [blame] | 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 10 | #include <base/bind.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> |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 13 | #include <chromeos/dbus/service_constants.h> |
Ben Chan | 5c853ef | 2012-10-05 00:05:37 -0700 | [diff] [blame] | 14 | #include <ModemManager/ModemManager.h> |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 15 | |
Ben Chan | c54afe5 | 2014-11-05 10:28:08 -0800 | [diff] [blame] | 16 | #include "shill/cellular/cellular.h" |
| 17 | #include "shill/cellular/cellular_bearer.h" |
| 18 | #include "shill/cellular/cellular_service.h" |
| 19 | #include "shill/cellular/mock_cellular.h" |
| 20 | #include "shill/cellular/mock_cellular_service.h" |
| 21 | #include "shill/cellular/mock_mm1_modem_modem3gpp_proxy.h" |
| 22 | #include "shill/cellular/mock_mm1_modem_modemcdma_proxy.h" |
| 23 | #include "shill/cellular/mock_mm1_modem_proxy.h" |
| 24 | #include "shill/cellular/mock_mm1_modem_simple_proxy.h" |
| 25 | #include "shill/cellular/mock_mm1_sim_proxy.h" |
| 26 | #include "shill/cellular/mock_mobile_operator_info.h" |
| 27 | #include "shill/cellular/mock_modem_info.h" |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 28 | #include "shill/dbus_adaptor.h" |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 29 | #include "shill/error.h" |
| 30 | #include "shill/event_dispatcher.h" |
| 31 | #include "shill/mock_adaptors.h" |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 32 | #include "shill/mock_dbus_properties_proxy.h" |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 33 | #include "shill/mock_event_dispatcher.h" |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 34 | #include "shill/mock_pending_activation_store.h" |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 35 | #include "shill/mock_profile.h" |
Peter Qiu | 8d6b597 | 2014-10-28 15:33:34 -0700 | [diff] [blame] | 36 | #include "shill/net/mock_rtnl_handler.h" |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 37 | #include "shill/proxy_factory.h" |
Ben Chan | be277dd | 2014-02-05 17:26:47 -0800 | [diff] [blame] | 38 | #include "shill/testing.h" |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 39 | |
| 40 | using base::Bind; |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 41 | using base::StringPrintf; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 42 | using base::Unretained; |
| 43 | using std::string; |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 44 | using std::unique_ptr; |
Nathan Williams | 4b7c2a8 | 2012-04-13 15:19:47 -0400 | [diff] [blame] | 45 | using std::vector; |
mukesh agrawal | 83a98f4 | 2013-07-31 16:25:53 -0700 | [diff] [blame] | 46 | using testing::AnyNumber; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 47 | using testing::InSequence; |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 48 | using testing::Invoke; |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 49 | using testing::InvokeWithoutArgs; |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 50 | using testing::Mock; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 51 | using testing::NiceMock; |
| 52 | using testing::Return; |
Thieu Le | 247416e | 2014-02-25 18:19:53 -0800 | [diff] [blame] | 53 | using testing::ReturnRef; |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 54 | using testing::SaveArg; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 55 | using testing::_; |
| 56 | |
| 57 | namespace shill { |
| 58 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 59 | MATCHER_P(HasApn, expected_apn, "") { |
| 60 | string apn; |
| 61 | return (DBusProperties::GetString(arg, |
| 62 | CellularCapabilityUniversal::kConnectApn, |
| 63 | &apn) && |
| 64 | apn == expected_apn); |
| 65 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 66 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 67 | class CellularCapabilityUniversalTest : public testing::TestWithParam<string> { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 68 | public: |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 69 | explicit CellularCapabilityUniversalTest(EventDispatcher* dispatcher) |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 70 | : dispatcher_(dispatcher), |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 71 | modem_info_(nullptr, dispatcher, nullptr, nullptr, nullptr), |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 72 | modem_3gpp_proxy_(new mm1::MockModemModem3gppProxy()), |
| 73 | modem_cdma_proxy_(new mm1::MockModemModemCdmaProxy()), |
| 74 | modem_proxy_(new mm1::MockModemProxy()), |
| 75 | modem_simple_proxy_(new mm1::MockModemSimpleProxy()), |
| 76 | sim_proxy_(new mm1::MockSimProxy()), |
| 77 | properties_proxy_(new MockDBusPropertiesProxy()), |
| 78 | proxy_factory_(this), |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 79 | capability_(nullptr), |
| 80 | device_adaptor_(nullptr), |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 81 | cellular_(new Cellular(&modem_info_, |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 82 | "", |
Prathmesh Prabhu | 401a5b9 | 2014-04-29 17:37:55 -0700 | [diff] [blame] | 83 | "00:01:02:03:04:05", |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 84 | 0, |
| 85 | Cellular::kTypeUniversal, |
| 86 | "", |
| 87 | "", |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 88 | "", |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 89 | &proxy_factory_)), |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 90 | service_(new MockCellularService(&modem_info_, cellular_)), |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 91 | mock_home_provider_info_(nullptr), |
| 92 | mock_serving_operator_info_(nullptr) { |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 93 | modem_info_.metrics()->RegisterDevice(cellular_->interface_index(), |
| 94 | Technology::kCellular); |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 95 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 96 | |
| 97 | virtual ~CellularCapabilityUniversalTest() { |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 98 | cellular_->service_ = nullptr; |
| 99 | capability_ = nullptr; |
| 100 | device_adaptor_ = nullptr; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | virtual void SetUp() { |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 104 | capability_ = dynamic_cast<CellularCapabilityUniversal*>( |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 105 | cellular_->capability_.get()); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 106 | device_adaptor_ = |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 107 | dynamic_cast<DeviceMockAdaptor*>(cellular_->adaptor()); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 108 | cellular_->service_ = service_; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 109 | |
| 110 | // kStateUnknown leads to minimal extra work in maintaining |
| 111 | // activation state. |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 112 | ON_CALL(*modem_info_.mock_pending_activation_store(), |
| 113 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
| 114 | .WillByDefault(Return(PendingActivationStore::kStateUnknown)); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 115 | |
| 116 | SetMockMobileOperatorInfoObjects(); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | virtual void TearDown() { |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 120 | capability_->proxy_factory_ = nullptr; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 123 | void CreateService() { |
| 124 | // The following constants are never directly accessed by the tests. |
| 125 | const char kStorageIdentifier[] = "default_test_storage_id"; |
| 126 | const char kFriendlyServiceName[] = "default_test_service_name"; |
| 127 | const char kOperatorCode[] = "10010"; |
| 128 | const char kOperatorName[] = "default_test_operator_name"; |
| 129 | const char kOperatorCountry[] = "us"; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 130 | |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 131 | // Simulate all the side-effects of Cellular::CreateService |
| 132 | auto service = new CellularService(&modem_info_, cellular_); |
| 133 | service->SetStorageIdentifier(kStorageIdentifier); |
| 134 | service->SetFriendlyName(kFriendlyServiceName); |
| 135 | |
Roshan Pius | ec77f59 | 2014-10-29 15:07:38 -0700 | [diff] [blame] | 136 | Stringmap serving_operator; |
| 137 | serving_operator[kOperatorCodeKey] = kOperatorCode; |
| 138 | serving_operator[kOperatorNameKey] = kOperatorName; |
| 139 | serving_operator[kOperatorCountryKey] = kOperatorCountry; |
| 140 | service->set_serving_operator(serving_operator); |
| 141 | cellular_->set_home_provider(serving_operator); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 142 | cellular_->service_ = service; |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 143 | } |
| 144 | |
Arman Uguray | c539123 | 2013-09-23 21:30:46 -0700 | [diff] [blame] | 145 | void ClearService() { |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 146 | cellular_->service_ = nullptr; |
Arman Uguray | c539123 | 2013-09-23 21:30:46 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Ben Chan | 9f3dcf8 | 2013-09-25 18:04:58 -0700 | [diff] [blame] | 149 | void ExpectModemAndModem3gppProperties() { |
| 150 | // Set up mock modem properties. |
| 151 | DBusPropertiesMap modem_properties; |
| 152 | string operator_name = "TestOperator"; |
| 153 | string operator_code = "001400"; |
| 154 | |
| 155 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 156 | writer().append_uint32(kAccessTechnologies); |
| 157 | |
| 158 | DBus::Variant variant; |
| 159 | DBus::MessageIter writer = variant.writer(); |
| 160 | DBus::Struct<uint32_t, bool> signal_signal; |
| 161 | signal_signal._1 = 90; |
| 162 | signal_signal._2 = true; |
| 163 | writer << signal_signal; |
| 164 | modem_properties[MM_MODEM_PROPERTY_SIGNALQUALITY] = variant; |
| 165 | |
| 166 | // Set up mock modem 3gpp properties. |
| 167 | DBusPropertiesMap modem3gpp_properties; |
| 168 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS]. |
| 169 | writer().append_uint32(0); |
| 170 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_IMEI]. |
| 171 | writer().append_string(kImei); |
| 172 | |
| 173 | EXPECT_CALL(*properties_proxy_, |
| 174 | GetAll(MM_DBUS_INTERFACE_MODEM)) |
| 175 | .WillOnce(Return(modem_properties)); |
| 176 | EXPECT_CALL(*properties_proxy_, |
| 177 | GetAll(MM_DBUS_INTERFACE_MODEM_MODEM3GPP)) |
| 178 | .WillOnce(Return(modem3gpp_properties)); |
| 179 | } |
| 180 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 181 | void InvokeEnable(bool enable, Error* error, |
| 182 | const ResultCallback& callback, int timeout) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 183 | callback.Run(Error()); |
| 184 | } |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 185 | void InvokeEnableFail(bool enable, Error* error, |
| 186 | const ResultCallback& callback, int timeout) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 187 | callback.Run(Error(Error::kOperationFailed)); |
| 188 | } |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 189 | void InvokeEnableInWrongState(bool enable, Error* error, |
| 190 | const ResultCallback& callback, int timeout) { |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 191 | callback.Run(Error(Error::kWrongState)); |
| 192 | } |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 193 | void InvokeRegister(const string& operator_id, Error* error, |
| 194 | const ResultCallback& callback, int timeout) { |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 195 | callback.Run(Error()); |
| 196 | } |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 197 | void InvokeSetPowerState(const uint32_t& power_state, |
| 198 | Error* error, |
| 199 | const ResultCallback& callback, |
Ben Chan | 9f3dcf8 | 2013-09-25 18:04:58 -0700 | [diff] [blame] | 200 | int timeout) { |
| 201 | callback.Run(Error()); |
| 202 | } |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 203 | void Set3gppProxy() { |
| 204 | capability_->modem_3gpp_proxy_.reset(modem_3gpp_proxy_.release()); |
| 205 | } |
| 206 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 207 | void SetSimpleProxy() { |
| 208 | capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release()); |
| 209 | } |
| 210 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 211 | void SetMockMobileOperatorInfoObjects() { |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 212 | CHECK(!mock_home_provider_info_); |
| 213 | CHECK(!mock_serving_operator_info_); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 214 | mock_home_provider_info_ = |
| 215 | new MockMobileOperatorInfo(dispatcher_, "HomeProvider"); |
| 216 | mock_serving_operator_info_ = |
| 217 | new MockMobileOperatorInfo(dispatcher_, "ServingOperator"); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 218 | cellular_->set_home_provider_info(mock_home_provider_info_); |
| 219 | cellular_->set_serving_operator_info(mock_serving_operator_info_); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 222 | void ReleaseCapabilityProxies() { |
| 223 | capability_->ReleaseProxies(); |
| 224 | } |
| 225 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 226 | void SetRegistrationDroppedUpdateTimeout(int64_t timeout_milliseconds) { |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 227 | capability_->registration_dropped_update_timeout_milliseconds_ = |
| 228 | timeout_milliseconds; |
| 229 | } |
| 230 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 231 | MOCK_METHOD1(TestCallback, void(const Error& error)); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 232 | |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 233 | MOCK_METHOD0(DummyCallback, void(void)); |
| 234 | |
| 235 | void SetMockRegistrationDroppedUpdateCallback() { |
| 236 | capability_->registration_dropped_update_callback_.Reset( |
| 237 | Bind(&CellularCapabilityUniversalTest::DummyCallback, |
| 238 | Unretained(this))); |
| 239 | } |
| 240 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 241 | protected: |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 242 | static const char kActiveBearerPathPrefix[]; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 243 | static const char kImei[]; |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 244 | static const char kInactiveBearerPathPrefix[]; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 245 | static const char kSimPath[]; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 246 | static const uint32_t kAccessTechnologies; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 247 | static const char kTestMobileProviderDBPath[]; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 248 | |
| 249 | class TestProxyFactory : public ProxyFactory { |
| 250 | public: |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 251 | explicit TestProxyFactory(CellularCapabilityUniversalTest* test) : |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 252 | test_(test) { |
Ben Chan | 5db1969 | 2013-07-09 23:07:03 -0700 | [diff] [blame] | 253 | active_bearer_properties_[MM_BEARER_PROPERTY_CONNECTED].writer() |
| 254 | .append_bool(true); |
| 255 | active_bearer_properties_[MM_BEARER_PROPERTY_INTERFACE].writer() |
| 256 | .append_string("/dev/fake"); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 257 | |
Ben Chan | 5db1969 | 2013-07-09 23:07:03 -0700 | [diff] [blame] | 258 | DBusPropertiesMap ip4config; |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 259 | ip4config["method"].writer().append_uint32(MM_BEARER_IP_METHOD_DHCP); |
Ben Chan | 5db1969 | 2013-07-09 23:07:03 -0700 | [diff] [blame] | 260 | DBus::MessageIter writer = |
| 261 | active_bearer_properties_[MM_BEARER_PROPERTY_IP4CONFIG].writer(); |
| 262 | writer << ip4config; |
| 263 | |
| 264 | inactive_bearer_properties_[MM_BEARER_PROPERTY_CONNECTED].writer() |
| 265 | .append_bool(false); |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 268 | DBusPropertiesMap* mutable_active_bearer_properties() { |
mukesh agrawal | 83a98f4 | 2013-07-31 16:25:53 -0700 | [diff] [blame] | 269 | return &active_bearer_properties_; |
| 270 | } |
| 271 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 272 | DBusPropertiesMap* mutable_inactive_bearer_properties() { |
mukesh agrawal | 83a98f4 | 2013-07-31 16:25:53 -0700 | [diff] [blame] | 273 | return &inactive_bearer_properties_; |
| 274 | } |
| 275 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 276 | virtual mm1::ModemModem3gppProxyInterface* CreateMM1ModemModem3gppProxy( |
| 277 | const std::string& /*path*/, |
| 278 | const std::string& /*service*/) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 279 | return test_->modem_3gpp_proxy_.release(); |
| 280 | } |
| 281 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 282 | virtual mm1::ModemModemCdmaProxyInterface* CreateMM1ModemModemCdmaProxy( |
| 283 | const std::string& /*path*/, |
| 284 | const std::string& /*service*/) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 285 | return test_->modem_cdma_proxy_.release(); |
| 286 | } |
| 287 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 288 | virtual mm1::ModemProxyInterface* CreateMM1ModemProxy( |
| 289 | const std::string& /*path*/, |
| 290 | const std::string& /*service*/) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 291 | return test_->modem_proxy_.release(); |
| 292 | } |
| 293 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 294 | virtual mm1::ModemSimpleProxyInterface* CreateMM1ModemSimpleProxy( |
| 295 | const std::string& /*path*/, |
| 296 | const std::string& /*service*/) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 297 | return test_->modem_simple_proxy_.release(); |
| 298 | } |
| 299 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 300 | virtual mm1::SimProxyInterface* CreateSimProxy( |
| 301 | const std::string& /*path*/, |
| 302 | const std::string& /*service*/) { |
| 303 | mm1::MockSimProxy* sim_proxy = test_->sim_proxy_.release(); |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 304 | test_->sim_proxy_.reset(new mm1::MockSimProxy()); |
| 305 | return sim_proxy; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 306 | } |
mukesh agrawal | 83a98f4 | 2013-07-31 16:25:53 -0700 | [diff] [blame] | 307 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 308 | virtual DBusPropertiesProxyInterface* CreateDBusPropertiesProxy( |
| 309 | const std::string& path, |
| 310 | const std::string& /*service*/) { |
| 311 | MockDBusPropertiesProxy* properties_proxy = |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 312 | test_->properties_proxy_.release(); |
Ben Chan | 5db1969 | 2013-07-09 23:07:03 -0700 | [diff] [blame] | 313 | if (path.find(kActiveBearerPathPrefix) != std::string::npos) { |
mukesh agrawal | 83a98f4 | 2013-07-31 16:25:53 -0700 | [diff] [blame] | 314 | EXPECT_CALL(*properties_proxy, GetAll(MM_DBUS_INTERFACE_BEARER)) |
| 315 | .Times(AnyNumber()) |
| 316 | .WillRepeatedly(Return(active_bearer_properties_)); |
Ben Chan | 5db1969 | 2013-07-09 23:07:03 -0700 | [diff] [blame] | 317 | } else { |
mukesh agrawal | 83a98f4 | 2013-07-31 16:25:53 -0700 | [diff] [blame] | 318 | EXPECT_CALL(*properties_proxy, GetAll(MM_DBUS_INTERFACE_BEARER)) |
| 319 | .Times(AnyNumber()) |
| 320 | .WillRepeatedly(Return(inactive_bearer_properties_)); |
Ben Chan | 5db1969 | 2013-07-09 23:07:03 -0700 | [diff] [blame] | 321 | } |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 322 | test_->properties_proxy_.reset(new MockDBusPropertiesProxy()); |
| 323 | return properties_proxy; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 324 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 325 | |
| 326 | private: |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 327 | CellularCapabilityUniversalTest* test_; |
Ben Chan | 5db1969 | 2013-07-09 23:07:03 -0700 | [diff] [blame] | 328 | DBusPropertiesMap active_bearer_properties_; |
| 329 | DBusPropertiesMap inactive_bearer_properties_; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 330 | }; |
| 331 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 332 | EventDispatcher* dispatcher_; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 333 | MockModemInfo modem_info_; |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 334 | unique_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_; |
| 335 | unique_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_; |
| 336 | unique_ptr<mm1::MockModemProxy> modem_proxy_; |
| 337 | unique_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_; |
| 338 | unique_ptr<mm1::MockSimProxy> sim_proxy_; |
| 339 | unique_ptr<MockDBusPropertiesProxy> properties_proxy_; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 340 | TestProxyFactory proxy_factory_; |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 341 | CellularCapabilityUniversal* capability_; // Owned by |cellular_|. |
| 342 | DeviceMockAdaptor* device_adaptor_; // Owned by |cellular_|. |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 343 | CellularRefPtr cellular_; |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 344 | MockCellularService* service_; // owned by cellular_ |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 345 | DBusPathCallback connect_callback_; // saved for testing connect operations |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 346 | |
| 347 | // Set when required and passed to |cellular_|. Owned by |cellular_|. |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 348 | MockMobileOperatorInfo* mock_home_provider_info_; |
| 349 | MockMobileOperatorInfo* mock_serving_operator_info_; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 350 | }; |
| 351 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 352 | // Most of our tests involve using a real EventDispatcher object. |
| 353 | class CellularCapabilityUniversalMainTest |
| 354 | : public CellularCapabilityUniversalTest { |
| 355 | public: |
| 356 | CellularCapabilityUniversalMainTest() : |
| 357 | CellularCapabilityUniversalTest(&dispatcher_) {} |
| 358 | |
| 359 | protected: |
| 360 | EventDispatcher dispatcher_; |
| 361 | }; |
| 362 | |
| 363 | // Tests that involve timers will (or may) use a mock of the event dispatcher |
| 364 | // instead of a real one. |
| 365 | class CellularCapabilityUniversalTimerTest |
| 366 | : public CellularCapabilityUniversalTest { |
| 367 | public: |
| 368 | CellularCapabilityUniversalTimerTest() |
| 369 | : CellularCapabilityUniversalTest(&mock_dispatcher_) {} |
| 370 | |
| 371 | protected: |
| 372 | ::testing::StrictMock<MockEventDispatcher> mock_dispatcher_; |
| 373 | }; |
| 374 | |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 375 | const char CellularCapabilityUniversalTest::kActiveBearerPathPrefix[] = |
| 376 | "/bearer/active"; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 377 | const char CellularCapabilityUniversalTest::kImei[] = "999911110000"; |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 378 | const char CellularCapabilityUniversalTest::kInactiveBearerPathPrefix[] = |
| 379 | "/bearer/inactive"; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 380 | const char CellularCapabilityUniversalTest::kSimPath[] = "/foo/sim"; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 381 | const uint32_t CellularCapabilityUniversalTest::kAccessTechnologies = |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 382 | MM_MODEM_ACCESS_TECHNOLOGY_LTE | |
| 383 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 384 | const char CellularCapabilityUniversalTest::kTestMobileProviderDBPath[] = |
| 385 | "provider_db_unittest.bfd"; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 386 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 387 | TEST_F(CellularCapabilityUniversalMainTest, StartModem) { |
Ben Chan | 9f3dcf8 | 2013-09-25 18:04:58 -0700 | [diff] [blame] | 388 | ExpectModemAndModem3gppProperties(); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 389 | |
| 390 | EXPECT_CALL(*modem_proxy_, |
| 391 | Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 392 | .WillOnce(Invoke( |
| 393 | this, &CellularCapabilityUniversalTest::InvokeEnable)); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 394 | |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 395 | Error error; |
| 396 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 397 | ResultCallback callback = |
| 398 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 399 | capability_->StartModem(&error, callback); |
| 400 | |
| 401 | EXPECT_TRUE(error.IsOngoing()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 402 | EXPECT_EQ(kImei, cellular_->imei()); |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 403 | EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_); |
| 404 | } |
| 405 | |
| 406 | TEST_F(CellularCapabilityUniversalMainTest, StartModemFailure) { |
| 407 | EXPECT_CALL(*modem_proxy_, |
| 408 | Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 409 | .WillOnce(Invoke( |
| 410 | this, &CellularCapabilityUniversalTest::InvokeEnableFail)); |
| 411 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_MODEM)).Times(0); |
| 412 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_MODEM_MODEM3GPP)) |
| 413 | .Times(0); |
| 414 | |
| 415 | Error error; |
| 416 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 417 | ResultCallback callback = |
| 418 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 419 | capability_->StartModem(&error, callback); |
| 420 | EXPECT_TRUE(error.IsOngoing()); |
| 421 | } |
| 422 | |
| 423 | TEST_F(CellularCapabilityUniversalMainTest, StartModemInWrongState) { |
Ben Chan | 9f3dcf8 | 2013-09-25 18:04:58 -0700 | [diff] [blame] | 424 | ExpectModemAndModem3gppProperties(); |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 425 | |
| 426 | EXPECT_CALL(*modem_proxy_, |
| 427 | Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 428 | .WillOnce(Invoke( |
| 429 | this, &CellularCapabilityUniversalTest::InvokeEnableInWrongState)) |
| 430 | .WillOnce(Invoke( |
| 431 | this, &CellularCapabilityUniversalTest::InvokeEnable)); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 432 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 433 | Error error; |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 434 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 435 | ResultCallback callback = |
| 436 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 437 | capability_->StartModem(&error, callback); |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 438 | EXPECT_TRUE(error.IsOngoing()); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 439 | |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 440 | // Verify that the modem has not been enabled. |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 441 | EXPECT_TRUE(cellular_->imei().empty()); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 442 | EXPECT_EQ(0, capability_->access_technologies_); |
| 443 | Mock::VerifyAndClearExpectations(this); |
| 444 | |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 445 | // Change the state to kModemStateEnabling and verify that it still has not |
| 446 | // been enabled. |
Arman Uguray | 1ee9391 | 2013-09-24 21:24:10 -0700 | [diff] [blame] | 447 | capability_->OnModemStateChanged(Cellular::kModemStateEnabling); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 448 | EXPECT_TRUE(cellular_->imei().empty()); |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 449 | EXPECT_EQ(0, capability_->access_technologies_); |
| 450 | Mock::VerifyAndClearExpectations(this); |
| 451 | |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 452 | // Change the state to kModemStateDisabling and verify that it still has not |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 453 | // been enabled. |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 454 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
Arman Uguray | 1ee9391 | 2013-09-24 21:24:10 -0700 | [diff] [blame] | 455 | capability_->OnModemStateChanged(Cellular::kModemStateDisabling); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 456 | EXPECT_TRUE(cellular_->imei().empty()); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 457 | EXPECT_EQ(0, capability_->access_technologies_); |
| 458 | Mock::VerifyAndClearExpectations(this); |
| 459 | |
| 460 | // Change the state of the modem to disabled and verify that it gets enabled. |
| 461 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Arman Uguray | 1ee9391 | 2013-09-24 21:24:10 -0700 | [diff] [blame] | 462 | capability_->OnModemStateChanged(Cellular::kModemStateDisabled); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 463 | EXPECT_EQ(kImei, cellular_->imei()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 464 | EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 465 | } |
| 466 | |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 467 | TEST_F(CellularCapabilityUniversalMainTest, |
| 468 | StartModemWithDeferredEnableFailure) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 469 | EXPECT_CALL(*modem_proxy_, |
| 470 | Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 471 | .Times(2) |
| 472 | .WillRepeatedly(Invoke( |
| 473 | this, &CellularCapabilityUniversalTest::InvokeEnableInWrongState)); |
| 474 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_MODEM)).Times(0); |
| 475 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_MODEM_MODEM3GPP)) |
| 476 | .Times(0); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 477 | |
| 478 | Error error; |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 479 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
Ben Chan | fd1144d | 2013-09-06 09:10:16 -0700 | [diff] [blame] | 480 | ResultCallback callback = |
| 481 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
Ben Chan | fd1144d | 2013-09-06 09:10:16 -0700 | [diff] [blame] | 482 | capability_->StartModem(&error, callback); |
| 483 | EXPECT_TRUE(error.IsOngoing()); |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 484 | Mock::VerifyAndClearExpectations(this); |
Ben Chan | fd1144d | 2013-09-06 09:10:16 -0700 | [diff] [blame] | 485 | |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 486 | // Change the state of the modem to disabled but fail the deferred enable |
| 487 | // operation with the WrongState error in order to verify that the deferred |
| 488 | // enable operation does not trigger another deferred enable operation. |
| 489 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
Arman Uguray | 1ee9391 | 2013-09-24 21:24:10 -0700 | [diff] [blame] | 490 | capability_->OnModemStateChanged(Cellular::kModemStateDisabled); |
Thieu Le | b9c05e0 | 2013-03-04 14:09:32 -0800 | [diff] [blame] | 491 | } |
| 492 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 493 | TEST_F(CellularCapabilityUniversalMainTest, StopModem) { |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 494 | // Save pointers to proxies before they are lost by the call to InitProxies |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 495 | mm1::MockModemProxy* modem_proxy = modem_proxy_.get(); |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 496 | EXPECT_CALL(*modem_proxy, set_state_changed_callback(_)); |
| 497 | capability_->InitProxies(); |
| 498 | |
| 499 | Error error; |
| 500 | ResultCallback callback = |
| 501 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 502 | capability_->StopModem(&error, callback); |
| 503 | EXPECT_TRUE(error.IsSuccess()); |
| 504 | |
| 505 | ResultCallback disable_callback; |
| 506 | EXPECT_CALL(*modem_proxy, |
| 507 | Enable(false, _, _, CellularCapability::kTimeoutEnable)) |
| 508 | .WillOnce(SaveArg<2>(&disable_callback)); |
| 509 | dispatcher_.DispatchPendingEvents(); |
| 510 | |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 511 | ResultCallback set_power_state_callback; |
Thieu Le | 2cac294 | 2013-03-05 18:41:08 -0800 | [diff] [blame] | 512 | EXPECT_CALL( |
| 513 | *modem_proxy, |
| 514 | SetPowerState( |
| 515 | MM_MODEM_POWER_STATE_LOW, _, _, |
| 516 | CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds)) |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 517 | .WillOnce(SaveArg<2>(&set_power_state_callback)); |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 518 | disable_callback.Run(Error(Error::kSuccess)); |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 519 | |
| 520 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 521 | set_power_state_callback.Run(Error(Error::kSuccess)); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 522 | Mock::VerifyAndClearExpectations(this); |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 523 | |
| 524 | // TestCallback should get called with success even if the power state |
| 525 | // callback gets called with an error |
| 526 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 527 | set_power_state_callback.Run(Error(Error::kOperationFailed)); |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 528 | } |
| 529 | |
Thieu Le | c466ccb | 2014-06-23 15:24:56 -0700 | [diff] [blame] | 530 | TEST_F(CellularCapabilityUniversalMainTest, StopModemAltair) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 531 | // Save pointers to proxies before they are lost by the call to InitProxies |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 532 | mm1::MockModemProxy* modem_proxy = modem_proxy_.get(); |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 533 | EXPECT_CALL(*modem_proxy, set_state_changed_callback(_)); |
| 534 | capability_->InitProxies(); |
| 535 | |
| 536 | const char kBearerDBusPath[] = "/bearer/dbus/path"; |
| 537 | capability_->set_active_bearer( |
| 538 | new CellularBearer(&proxy_factory_, |
| 539 | kBearerDBusPath, |
| 540 | cellular_->dbus_service())); // Passes ownership. |
| 541 | |
Thieu Le | c466ccb | 2014-06-23 15:24:56 -0700 | [diff] [blame] | 542 | cellular_->set_mm_plugin(CellularCapabilityUniversal::kAltairLTEMMPlugin); |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 543 | |
| 544 | Error error; |
| 545 | ResultCallback callback = |
| 546 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 547 | capability_->StopModem(&error, callback); |
| 548 | EXPECT_TRUE(error.IsSuccess()); |
| 549 | |
| 550 | ResultCallback delete_bearer_callback; |
| 551 | EXPECT_CALL(*modem_proxy, |
| 552 | DeleteBearer(::DBus::Path(kBearerDBusPath), _, _, |
| 553 | CellularCapability::kTimeoutDefault)) |
| 554 | .WillOnce(SaveArg<2>(&delete_bearer_callback)); |
| 555 | dispatcher_.DispatchPendingEvents(); |
| 556 | |
| 557 | ResultCallback disable_callback; |
| 558 | EXPECT_CALL(*modem_proxy, |
| 559 | Enable(false, _, _, CellularCapability::kTimeoutEnable)) |
| 560 | .WillOnce(SaveArg<2>(&disable_callback)); |
| 561 | delete_bearer_callback.Run(Error(Error::kSuccess)); |
| 562 | |
| 563 | ResultCallback set_power_state_callback; |
| 564 | EXPECT_CALL( |
| 565 | *modem_proxy, |
| 566 | SetPowerState( |
| 567 | MM_MODEM_POWER_STATE_LOW, _, _, |
| 568 | CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds)) |
| 569 | .WillOnce(SaveArg<2>(&set_power_state_callback)); |
| 570 | disable_callback.Run(Error(Error::kSuccess)); |
| 571 | |
| 572 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 573 | set_power_state_callback.Run(Error(Error::kSuccess)); |
| 574 | } |
| 575 | |
Thieu Le | b0074e8 | 2014-04-15 14:28:21 -0700 | [diff] [blame] | 576 | TEST_F(CellularCapabilityUniversalMainTest, |
Thieu Le | c466ccb | 2014-06-23 15:24:56 -0700 | [diff] [blame] | 577 | StopModemAltairDeleteBearerFailure) { |
Thieu Le | b0074e8 | 2014-04-15 14:28:21 -0700 | [diff] [blame] | 578 | // Save pointers to proxies before they are lost by the call to InitProxies |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 579 | mm1::MockModemProxy* modem_proxy = modem_proxy_.get(); |
Thieu Le | b0074e8 | 2014-04-15 14:28:21 -0700 | [diff] [blame] | 580 | EXPECT_CALL(*modem_proxy, set_state_changed_callback(_)); |
| 581 | capability_->InitProxies(); |
| 582 | |
| 583 | const char kBearerDBusPath[] = "/bearer/dbus/path"; |
| 584 | capability_->set_active_bearer( |
| 585 | new CellularBearer(&proxy_factory_, |
| 586 | kBearerDBusPath, |
| 587 | cellular_->dbus_service())); // Passes ownership. |
| 588 | |
Thieu Le | c466ccb | 2014-06-23 15:24:56 -0700 | [diff] [blame] | 589 | cellular_->set_mm_plugin(CellularCapabilityUniversal::kAltairLTEMMPlugin); |
Thieu Le | b0074e8 | 2014-04-15 14:28:21 -0700 | [diff] [blame] | 590 | |
| 591 | Error error; |
| 592 | ResultCallback callback = |
| 593 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 594 | capability_->StopModem(&error, callback); |
| 595 | EXPECT_TRUE(error.IsSuccess()); |
| 596 | |
| 597 | ResultCallback delete_bearer_callback; |
| 598 | EXPECT_CALL(*modem_proxy, |
| 599 | DeleteBearer(::DBus::Path(kBearerDBusPath), _, _, |
| 600 | CellularCapability::kTimeoutDefault)) |
| 601 | .WillOnce(SaveArg<2>(&delete_bearer_callback)); |
| 602 | dispatcher_.DispatchPendingEvents(); |
| 603 | |
| 604 | ResultCallback disable_callback; |
| 605 | EXPECT_CALL(*modem_proxy, |
| 606 | Enable(false, _, _, CellularCapability::kTimeoutEnable)) |
| 607 | .WillOnce(SaveArg<2>(&disable_callback)); |
| 608 | delete_bearer_callback.Run(Error(Error::kOperationFailed)); |
| 609 | |
| 610 | ResultCallback set_power_state_callback; |
| 611 | EXPECT_CALL( |
| 612 | *modem_proxy, |
| 613 | SetPowerState( |
| 614 | MM_MODEM_POWER_STATE_LOW, _, _, |
| 615 | CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds)) |
| 616 | .WillOnce(SaveArg<2>(&set_power_state_callback)); |
| 617 | disable_callback.Run(Error(Error::kSuccess)); |
| 618 | |
| 619 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 620 | set_power_state_callback.Run(Error(Error::kSuccess)); |
| 621 | } |
| 622 | |
Thieu Le | c466ccb | 2014-06-23 15:24:56 -0700 | [diff] [blame] | 623 | TEST_F(CellularCapabilityUniversalMainTest, StopModemAltairNotConnected) { |
Thieu Le | b0074e8 | 2014-04-15 14:28:21 -0700 | [diff] [blame] | 624 | // Save pointers to proxies before they are lost by the call to InitProxies |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 625 | mm1::MockModemProxy* modem_proxy = modem_proxy_.get(); |
Thieu Le | b0074e8 | 2014-04-15 14:28:21 -0700 | [diff] [blame] | 626 | EXPECT_CALL(*modem_proxy, set_state_changed_callback(_)); |
| 627 | capability_->InitProxies(); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 628 | capability_->set_active_bearer(nullptr); |
Thieu Le | c466ccb | 2014-06-23 15:24:56 -0700 | [diff] [blame] | 629 | cellular_->set_mm_plugin(CellularCapabilityUniversal::kAltairLTEMMPlugin); |
Thieu Le | b0074e8 | 2014-04-15 14:28:21 -0700 | [diff] [blame] | 630 | |
| 631 | Error error; |
| 632 | ResultCallback callback = |
| 633 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 634 | capability_->StopModem(&error, callback); |
| 635 | EXPECT_TRUE(error.IsSuccess()); |
| 636 | |
| 637 | ResultCallback disable_callback; |
| 638 | EXPECT_CALL(*modem_proxy, |
| 639 | Enable(false, _, _, CellularCapability::kTimeoutEnable)) |
| 640 | .WillOnce(SaveArg<2>(&disable_callback)); |
| 641 | dispatcher_.DispatchPendingEvents(); |
| 642 | |
| 643 | ResultCallback set_power_state_callback; |
| 644 | EXPECT_CALL( |
| 645 | *modem_proxy, |
| 646 | SetPowerState( |
| 647 | MM_MODEM_POWER_STATE_LOW, _, _, |
| 648 | CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds)) |
| 649 | .WillOnce(SaveArg<2>(&set_power_state_callback)); |
| 650 | disable_callback.Run(Error(Error::kSuccess)); |
| 651 | |
| 652 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 653 | set_power_state_callback.Run(Error(Error::kSuccess)); |
| 654 | Mock::VerifyAndClearExpectations(this); |
| 655 | |
| 656 | // TestCallback should get called with success even if the power state |
| 657 | // callback gets called with an error |
| 658 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 659 | set_power_state_callback.Run(Error(Error::kOperationFailed)); |
| 660 | } |
| 661 | |
Ben Chan | 9f3dcf8 | 2013-09-25 18:04:58 -0700 | [diff] [blame] | 662 | TEST_F(CellularCapabilityUniversalMainTest, TerminationAction) { |
| 663 | ExpectModemAndModem3gppProperties(); |
| 664 | |
| 665 | { |
| 666 | InSequence seq; |
| 667 | |
| 668 | EXPECT_CALL(*modem_proxy_, |
| 669 | Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 670 | .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeEnable)); |
| 671 | EXPECT_CALL(*modem_proxy_, |
| 672 | Enable(false, _, _, CellularCapability::kTimeoutEnable)) |
| 673 | .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeEnable)); |
| 674 | EXPECT_CALL( |
| 675 | *modem_proxy_, |
| 676 | SetPowerState( |
| 677 | MM_MODEM_POWER_STATE_LOW, _, _, |
| 678 | CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds)) |
| 679 | .WillOnce(Invoke( |
| 680 | this, &CellularCapabilityUniversalTest::InvokeSetPowerState)); |
| 681 | } |
| 682 | EXPECT_CALL(*this, TestCallback(IsSuccess())).Times(2); |
| 683 | |
| 684 | EXPECT_EQ(Cellular::kStateDisabled, cellular_->state()); |
| 685 | EXPECT_EQ(Cellular::kModemStateUnknown, cellular_->modem_state()); |
| 686 | EXPECT_TRUE(modem_info_.manager()->termination_actions_.IsEmpty()); |
| 687 | |
| 688 | // Here we mimic the modem state change from ModemManager. When the modem is |
| 689 | // enabled, a termination action should be added. |
| 690 | cellular_->OnModemStateChanged(Cellular::kModemStateEnabled); |
| 691 | dispatcher_.DispatchPendingEvents(); |
| 692 | EXPECT_EQ(Cellular::kStateEnabled, cellular_->state()); |
| 693 | EXPECT_EQ(Cellular::kModemStateEnabled, cellular_->modem_state()); |
| 694 | EXPECT_FALSE(modem_info_.manager()->termination_actions_.IsEmpty()); |
| 695 | |
| 696 | // Running the termination action should disable the modem. |
| 697 | modem_info_.manager()->RunTerminationActions(Bind( |
| 698 | &CellularCapabilityUniversalMainTest::TestCallback, Unretained(this))); |
| 699 | dispatcher_.DispatchPendingEvents(); |
| 700 | // Here we mimic the modem state change from ModemManager. When the modem is |
| 701 | // disabled, the termination action should be removed. |
| 702 | cellular_->OnModemStateChanged(Cellular::kModemStateDisabled); |
| 703 | dispatcher_.DispatchPendingEvents(); |
| 704 | EXPECT_EQ(Cellular::kStateDisabled, cellular_->state()); |
| 705 | EXPECT_EQ(Cellular::kModemStateDisabled, cellular_->modem_state()); |
| 706 | EXPECT_TRUE(modem_info_.manager()->termination_actions_.IsEmpty()); |
| 707 | |
| 708 | // No termination action should be called here. |
| 709 | modem_info_.manager()->RunTerminationActions(Bind( |
| 710 | &CellularCapabilityUniversalMainTest::TestCallback, Unretained(this))); |
| 711 | dispatcher_.DispatchPendingEvents(); |
| 712 | } |
| 713 | |
| 714 | TEST_F(CellularCapabilityUniversalMainTest, |
| 715 | TerminationActionRemovedByStopModem) { |
| 716 | ExpectModemAndModem3gppProperties(); |
| 717 | |
| 718 | { |
| 719 | InSequence seq; |
| 720 | |
| 721 | EXPECT_CALL(*modem_proxy_, |
| 722 | Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 723 | .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeEnable)); |
| 724 | EXPECT_CALL(*modem_proxy_, |
| 725 | Enable(false, _, _, CellularCapability::kTimeoutEnable)) |
| 726 | .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeEnable)); |
| 727 | EXPECT_CALL( |
| 728 | *modem_proxy_, |
| 729 | SetPowerState( |
| 730 | MM_MODEM_POWER_STATE_LOW, _, _, |
| 731 | CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds)) |
| 732 | .WillOnce(Invoke( |
| 733 | this, &CellularCapabilityUniversalTest::InvokeSetPowerState)); |
| 734 | } |
| 735 | EXPECT_CALL(*this, TestCallback(IsSuccess())).Times(1); |
| 736 | |
| 737 | EXPECT_EQ(Cellular::kStateDisabled, cellular_->state()); |
| 738 | EXPECT_EQ(Cellular::kModemStateUnknown, cellular_->modem_state()); |
| 739 | EXPECT_TRUE(modem_info_.manager()->termination_actions_.IsEmpty()); |
| 740 | |
| 741 | // Here we mimic the modem state change from ModemManager. When the modem is |
| 742 | // enabled, a termination action should be added. |
| 743 | cellular_->OnModemStateChanged(Cellular::kModemStateEnabled); |
| 744 | dispatcher_.DispatchPendingEvents(); |
| 745 | EXPECT_EQ(Cellular::kStateEnabled, cellular_->state()); |
| 746 | EXPECT_EQ(Cellular::kModemStateEnabled, cellular_->modem_state()); |
| 747 | EXPECT_FALSE(modem_info_.manager()->termination_actions_.IsEmpty()); |
| 748 | |
| 749 | // Verify that the termination action is removed when the modem is disabled |
| 750 | // not due to a suspend request. |
| 751 | cellular_->SetEnabled(false); |
| 752 | dispatcher_.DispatchPendingEvents(); |
| 753 | EXPECT_EQ(Cellular::kStateDisabled, cellular_->state()); |
| 754 | EXPECT_TRUE(modem_info_.manager()->termination_actions_.IsEmpty()); |
| 755 | |
| 756 | // No termination action should be called here. |
| 757 | modem_info_.manager()->RunTerminationActions(Bind( |
| 758 | &CellularCapabilityUniversalMainTest::TestCallback, Unretained(this))); |
| 759 | dispatcher_.DispatchPendingEvents(); |
| 760 | } |
| 761 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 762 | TEST_F(CellularCapabilityUniversalMainTest, DisconnectModemNoBearer) { |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 763 | Error error; |
| 764 | ResultCallback disconnect_callback; |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 765 | EXPECT_CALL(*modem_simple_proxy_, |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 766 | Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect)) |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 767 | .Times(0); |
| 768 | capability_->Disconnect(&error, disconnect_callback); |
| 769 | } |
| 770 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 771 | TEST_F(CellularCapabilityUniversalMainTest, DisconnectNoProxy) { |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 772 | Error error; |
| 773 | ResultCallback disconnect_callback; |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 774 | EXPECT_CALL(*modem_simple_proxy_, |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 775 | Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect)) |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 776 | .Times(0); |
| 777 | ReleaseCapabilityProxies(); |
| 778 | capability_->Disconnect(&error, disconnect_callback); |
| 779 | } |
| 780 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 781 | TEST_F(CellularCapabilityUniversalMainTest, SimLockStatusChanged) { |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 782 | // Set up mock SIM properties |
| 783 | const char kImsi[] = "310100000001"; |
| 784 | const char kSimIdentifier[] = "9999888"; |
| 785 | const char kOperatorIdentifier[] = "310240"; |
| 786 | const char kOperatorName[] = "Custom SPN"; |
| 787 | DBusPropertiesMap sim_properties; |
| 788 | sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi); |
| 789 | sim_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer() |
| 790 | .append_string(kSimIdentifier); |
| 791 | sim_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer() |
| 792 | .append_string(kOperatorIdentifier); |
| 793 | sim_properties[MM_SIM_PROPERTY_OPERATORNAME].writer() |
| 794 | .append_string(kOperatorName); |
| 795 | |
| 796 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM)) |
| 797 | .WillOnce(Return(sim_properties)); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 798 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 799 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 800 | .Times(1); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 801 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 802 | EXPECT_FALSE(cellular_->sim_present()); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 803 | EXPECT_EQ(nullptr, capability_->sim_proxy_);; |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 804 | |
| 805 | capability_->OnSimPathChanged(kSimPath); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 806 | EXPECT_TRUE(cellular_->sim_present()); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 807 | EXPECT_NE(nullptr, capability_->sim_proxy_);; |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 808 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 809 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 810 | cellular_->set_imsi(""); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 811 | cellular_->set_sim_identifier(""); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 812 | capability_->spn_ = ""; |
| 813 | |
| 814 | // SIM is locked. |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 815 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN; |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 816 | capability_->OnSimLockStatusChanged(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 817 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 818 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 819 | EXPECT_EQ("", cellular_->imsi()); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 820 | EXPECT_EQ("", cellular_->sim_identifier()); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 821 | EXPECT_EQ("", capability_->spn_); |
| 822 | |
| 823 | // SIM is unlocked. |
| 824 | properties_proxy_.reset(new MockDBusPropertiesProxy()); |
| 825 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM)) |
| 826 | .WillOnce(Return(sim_properties)); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 827 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 828 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 829 | .Times(1); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 830 | |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 831 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_NONE; |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 832 | capability_->OnSimLockStatusChanged(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 833 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 834 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 835 | EXPECT_EQ(kImsi, cellular_->imsi()); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 836 | EXPECT_EQ(kSimIdentifier, cellular_->sim_identifier()); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 837 | EXPECT_EQ(kOperatorName, capability_->spn_); |
Ben Chan | d3b1874 | 2013-07-12 00:30:25 -0700 | [diff] [blame] | 838 | |
| 839 | // SIM is missing and SIM path is "/". |
| 840 | capability_->OnSimPathChanged(CellularCapabilityUniversal::kRootPath); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 841 | EXPECT_FALSE(cellular_->sim_present()); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 842 | EXPECT_EQ(nullptr, capability_->sim_proxy_);; |
Ben Chan | d3b1874 | 2013-07-12 00:30:25 -0700 | [diff] [blame] | 843 | EXPECT_EQ(CellularCapabilityUniversal::kRootPath, capability_->sim_path_); |
| 844 | |
| 845 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 846 | GetActivationState(_, _)).Times(0); |
| 847 | capability_->OnSimLockStatusChanged(); |
| 848 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 849 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 850 | EXPECT_EQ("", cellular_->imsi()); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 851 | EXPECT_EQ("", cellular_->sim_identifier()); |
Ben Chan | d3b1874 | 2013-07-12 00:30:25 -0700 | [diff] [blame] | 852 | EXPECT_EQ("", capability_->spn_); |
| 853 | |
| 854 | // SIM is missing and SIM path is empty. |
| 855 | capability_->OnSimPathChanged(""); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 856 | EXPECT_FALSE(cellular_->sim_present()); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 857 | EXPECT_EQ(nullptr, capability_->sim_proxy_);; |
Ben Chan | d3b1874 | 2013-07-12 00:30:25 -0700 | [diff] [blame] | 858 | EXPECT_EQ("", capability_->sim_path_); |
| 859 | |
| 860 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 861 | GetActivationState(_, _)).Times(0); |
| 862 | capability_->OnSimLockStatusChanged(); |
| 863 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 864 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 865 | EXPECT_EQ("", cellular_->imsi()); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 866 | EXPECT_EQ("", cellular_->sim_identifier()); |
Ben Chan | d3b1874 | 2013-07-12 00:30:25 -0700 | [diff] [blame] | 867 | EXPECT_EQ("", capability_->spn_); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 868 | } |
| 869 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 870 | TEST_F(CellularCapabilityUniversalMainTest, PropertiesChanged) { |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 871 | // Set up mock modem properties |
| 872 | DBusPropertiesMap modem_properties; |
| 873 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 874 | writer().append_uint32(kAccessTechnologies); |
| 875 | modem_properties[MM_MODEM_PROPERTY_SIM]. |
| 876 | writer().append_path(kSimPath); |
| 877 | |
| 878 | // Set up mock modem 3gpp properties |
| 879 | DBusPropertiesMap modem3gpp_properties; |
| 880 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS]. |
| 881 | writer().append_uint32(0); |
| 882 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_IMEI]. |
| 883 | writer().append_string(kImei); |
| 884 | |
| 885 | // Set up mock modem sim properties |
| 886 | DBusPropertiesMap sim_properties; |
| 887 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 888 | EXPECT_CALL(*properties_proxy_, |
| 889 | GetAll(MM_DBUS_INTERFACE_SIM)) |
| 890 | .WillOnce(Return(sim_properties)); |
| 891 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 892 | EXPECT_EQ("", cellular_->imei()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 893 | EXPECT_EQ(MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, |
| 894 | capability_->access_technologies_); |
| 895 | EXPECT_FALSE(capability_->sim_proxy_.get()); |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 896 | EXPECT_CALL(*device_adaptor_, EmitStringChanged( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 897 | kTechnologyFamilyProperty, kTechnologyFamilyGsm)); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 898 | EXPECT_CALL(*device_adaptor_, EmitStringChanged(kImeiProperty, kImei)); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 899 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 900 | modem_properties, vector<string>()); |
| 901 | EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_); |
| 902 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 903 | EXPECT_TRUE(capability_->sim_proxy_.get()); |
| 904 | |
| 905 | // Changing properties on wrong interface will not have an effect |
| 906 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 907 | modem3gpp_properties, |
| 908 | vector<string>()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 909 | EXPECT_EQ("", cellular_->imei()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 910 | |
| 911 | // Changing properties on the right interface gets reflected in the |
| 912 | // capabilities object |
| 913 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEM3GPP, |
| 914 | modem3gpp_properties, |
| 915 | vector<string>()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 916 | EXPECT_EQ(kImei, cellular_->imei()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 917 | Mock::VerifyAndClearExpectations(device_adaptor_); |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 918 | |
| 919 | // Expect to see changes when the family changes |
| 920 | modem_properties.clear(); |
| 921 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 922 | writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_1XRTT); |
| 923 | EXPECT_CALL(*device_adaptor_, EmitStringChanged( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 924 | kTechnologyFamilyProperty, kTechnologyFamilyCdma)). |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 925 | Times(1); |
| 926 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 927 | modem_properties, |
| 928 | vector<string>()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 929 | Mock::VerifyAndClearExpectations(device_adaptor_); |
| 930 | |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 931 | // Back to LTE |
| 932 | modem_properties.clear(); |
| 933 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 934 | writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_LTE); |
| 935 | EXPECT_CALL(*device_adaptor_, EmitStringChanged( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 936 | kTechnologyFamilyProperty, kTechnologyFamilyGsm)). |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 937 | Times(1); |
| 938 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 939 | modem_properties, |
| 940 | vector<string>()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 941 | Mock::VerifyAndClearExpectations(device_adaptor_); |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 942 | |
| 943 | // LTE & CDMA - the device adaptor should not be called! |
| 944 | modem_properties.clear(); |
| 945 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 946 | writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_LTE | |
| 947 | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT); |
| 948 | EXPECT_CALL(*device_adaptor_, EmitStringChanged(_, _)).Times(0); |
| 949 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 950 | modem_properties, |
| 951 | vector<string>()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 952 | } |
| 953 | |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 954 | TEST_F(CellularCapabilityUniversalMainTest, UpdateRegistrationState) { |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 955 | capability_->InitProxies(); |
| 956 | |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 957 | CreateService(); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 958 | cellular_->set_imsi("310240123456789"); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 959 | cellular_->set_modem_state(Cellular::kModemStateConnected); |
| 960 | SetRegistrationDroppedUpdateTimeout(0); |
| 961 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 962 | const Stringmap& home_provider_map = cellular_->home_provider(); |
Roshan Pius | ec77f59 | 2014-10-29 15:07:38 -0700 | [diff] [blame] | 963 | ASSERT_NE(home_provider_map.end(), home_provider_map.find(kOperatorNameKey)); |
| 964 | string home_provider = home_provider_map.find(kOperatorNameKey)->second; |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 965 | string ota_name = cellular_->service_->friendly_name(); |
| 966 | |
| 967 | // Home --> Roaming should be effective immediately. |
| 968 | capability_->On3GPPRegistrationChanged( |
| 969 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 970 | home_provider, |
| 971 | ota_name); |
| 972 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 973 | capability_->registration_state_); |
| 974 | capability_->On3GPPRegistrationChanged( |
| 975 | MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, |
| 976 | home_provider, |
| 977 | ota_name); |
| 978 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, |
| 979 | capability_->registration_state_); |
| 980 | |
| 981 | // Idle --> Roaming should be effective immediately. |
| 982 | capability_->On3GPPRegistrationChanged( |
| 983 | MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, |
| 984 | home_provider, |
| 985 | ota_name); |
| 986 | dispatcher_.DispatchPendingEvents(); |
| 987 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, |
| 988 | capability_->registration_state_); |
| 989 | capability_->On3GPPRegistrationChanged( |
| 990 | MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, |
| 991 | home_provider, |
| 992 | ota_name); |
| 993 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, |
| 994 | capability_->registration_state_); |
| 995 | |
| 996 | // Idle --> Searching should be effective immediately. |
| 997 | capability_->On3GPPRegistrationChanged( |
| 998 | MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, |
| 999 | home_provider, |
| 1000 | ota_name); |
| 1001 | dispatcher_.DispatchPendingEvents(); |
| 1002 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, |
| 1003 | capability_->registration_state_); |
| 1004 | capability_->On3GPPRegistrationChanged( |
| 1005 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 1006 | home_provider, |
| 1007 | ota_name); |
| 1008 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 1009 | capability_->registration_state_); |
| 1010 | |
| 1011 | // Home --> Searching --> Home should never see Searching. |
Prathmesh Prabhu | 08757aa | 2013-05-15 17:17:33 -0700 | [diff] [blame] | 1012 | EXPECT_CALL(*(modem_info_.mock_metrics()), |
| 1013 | Notify3GPPRegistrationDelayedDropPosted()); |
| 1014 | EXPECT_CALL(*(modem_info_.mock_metrics()), |
| 1015 | Notify3GPPRegistrationDelayedDropCanceled()); |
| 1016 | |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1017 | capability_->On3GPPRegistrationChanged( |
| 1018 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1019 | home_provider, |
| 1020 | ota_name); |
| 1021 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1022 | capability_->registration_state_); |
| 1023 | capability_->On3GPPRegistrationChanged( |
| 1024 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 1025 | home_provider, |
| 1026 | ota_name); |
| 1027 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1028 | capability_->registration_state_); |
| 1029 | capability_->On3GPPRegistrationChanged( |
| 1030 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1031 | home_provider, |
| 1032 | ota_name); |
| 1033 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1034 | capability_->registration_state_); |
| 1035 | dispatcher_.DispatchPendingEvents(); |
| 1036 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1037 | capability_->registration_state_); |
Prathmesh Prabhu | 08757aa | 2013-05-15 17:17:33 -0700 | [diff] [blame] | 1038 | Mock::VerifyAndClearExpectations(modem_info_.mock_metrics()); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1039 | |
| 1040 | // Home --> Searching --> wait till dispatch should see Searching |
Prathmesh Prabhu | 08757aa | 2013-05-15 17:17:33 -0700 | [diff] [blame] | 1041 | EXPECT_CALL(*(modem_info_.mock_metrics()), |
| 1042 | Notify3GPPRegistrationDelayedDropPosted()); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1043 | capability_->On3GPPRegistrationChanged( |
| 1044 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1045 | home_provider, |
| 1046 | ota_name); |
| 1047 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1048 | capability_->registration_state_); |
| 1049 | capability_->On3GPPRegistrationChanged( |
| 1050 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 1051 | home_provider, |
| 1052 | ota_name); |
| 1053 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1054 | capability_->registration_state_); |
| 1055 | dispatcher_.DispatchPendingEvents(); |
| 1056 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 1057 | capability_->registration_state_); |
Prathmesh Prabhu | 08757aa | 2013-05-15 17:17:33 -0700 | [diff] [blame] | 1058 | Mock::VerifyAndClearExpectations(modem_info_.mock_metrics()); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1059 | |
| 1060 | // Home --> Searching --> Searching --> wait till dispatch should see |
| 1061 | // Searching *and* the first callback should be cancelled. |
| 1062 | EXPECT_CALL(*this, DummyCallback()).Times(0); |
Prathmesh Prabhu | 08757aa | 2013-05-15 17:17:33 -0700 | [diff] [blame] | 1063 | EXPECT_CALL(*(modem_info_.mock_metrics()), |
| 1064 | Notify3GPPRegistrationDelayedDropPosted()); |
| 1065 | |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1066 | capability_->On3GPPRegistrationChanged( |
| 1067 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1068 | home_provider, |
| 1069 | ota_name); |
| 1070 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1071 | capability_->registration_state_); |
| 1072 | capability_->On3GPPRegistrationChanged( |
| 1073 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 1074 | home_provider, |
| 1075 | ota_name); |
| 1076 | SetMockRegistrationDroppedUpdateCallback(); |
| 1077 | capability_->On3GPPRegistrationChanged( |
| 1078 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 1079 | home_provider, |
| 1080 | ota_name); |
| 1081 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1082 | capability_->registration_state_); |
| 1083 | dispatcher_.DispatchPendingEvents(); |
| 1084 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 1085 | capability_->registration_state_); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
Ben Chan | 31ce564 | 2013-11-14 13:37:40 -0800 | [diff] [blame] | 1088 | TEST_F(CellularCapabilityUniversalMainTest, IsRegistered) { |
| 1089 | capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_IDLE; |
| 1090 | EXPECT_FALSE(capability_->IsRegistered()); |
| 1091 | |
| 1092 | capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_HOME; |
| 1093 | EXPECT_TRUE(capability_->IsRegistered()); |
| 1094 | |
| 1095 | capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING; |
| 1096 | EXPECT_FALSE(capability_->IsRegistered()); |
| 1097 | |
| 1098 | capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_DENIED; |
| 1099 | EXPECT_FALSE(capability_->IsRegistered()); |
| 1100 | |
| 1101 | capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; |
| 1102 | EXPECT_FALSE(capability_->IsRegistered()); |
| 1103 | |
| 1104 | capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING; |
| 1105 | EXPECT_TRUE(capability_->IsRegistered()); |
| 1106 | } |
| 1107 | |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1108 | TEST_F(CellularCapabilityUniversalMainTest, |
| 1109 | UpdateRegistrationStateModemNotConnected) { |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1110 | capability_->InitProxies(); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 1111 | CreateService(); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1112 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1113 | cellular_->set_imsi("310240123456789"); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1114 | cellular_->set_modem_state(Cellular::kModemStateRegistered); |
| 1115 | SetRegistrationDroppedUpdateTimeout(0); |
| 1116 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1117 | const Stringmap& home_provider_map = cellular_->home_provider(); |
Roshan Pius | ec77f59 | 2014-10-29 15:07:38 -0700 | [diff] [blame] | 1118 | ASSERT_NE(home_provider_map.end(), home_provider_map.find(kOperatorNameKey)); |
| 1119 | string home_provider = home_provider_map.find(kOperatorNameKey)->second; |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1120 | string ota_name = cellular_->service_->friendly_name(); |
| 1121 | |
| 1122 | // Home --> Searching should be effective immediately. |
| 1123 | capability_->On3GPPRegistrationChanged( |
| 1124 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1125 | home_provider, |
| 1126 | ota_name); |
| 1127 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 1128 | capability_->registration_state_); |
| 1129 | capability_->On3GPPRegistrationChanged( |
| 1130 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 1131 | home_provider, |
| 1132 | ota_name); |
| 1133 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 1134 | capability_->registration_state_); |
| 1135 | } |
| 1136 | |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1137 | TEST_F(CellularCapabilityUniversalMainTest, IsValidSimPath) { |
| 1138 | // Invalid paths |
| 1139 | EXPECT_FALSE(capability_->IsValidSimPath("")); |
| 1140 | EXPECT_FALSE(capability_->IsValidSimPath("/")); |
| 1141 | |
| 1142 | // A valid path |
| 1143 | EXPECT_TRUE(capability_->IsValidSimPath( |
| 1144 | "/org/freedesktop/ModemManager1/SIM/0")); |
| 1145 | |
| 1146 | // Note that any string that is not one of the above invalid paths is |
| 1147 | // currently regarded as valid, since the ModemManager spec doesn't impose |
| 1148 | // a strict format on the path. The validity of this is subject to change. |
| 1149 | EXPECT_TRUE(capability_->IsValidSimPath("path")); |
| 1150 | } |
| 1151 | |
Ben Chan | d759252 | 2013-02-13 16:02:01 -0800 | [diff] [blame] | 1152 | TEST_F(CellularCapabilityUniversalMainTest, NormalizeMdn) { |
| 1153 | EXPECT_EQ("", capability_->NormalizeMdn("")); |
| 1154 | EXPECT_EQ("12345678901", capability_->NormalizeMdn("12345678901")); |
| 1155 | EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1 234 567 8901")); |
| 1156 | EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1-234-567-8901")); |
| 1157 | EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1 (234) 567-8901")); |
| 1158 | EXPECT_EQ("12345678901", capability_->NormalizeMdn("1 234 567 8901 ")); |
| 1159 | EXPECT_EQ("2345678901", capability_->NormalizeMdn("(234) 567-8901")); |
| 1160 | } |
| 1161 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1162 | TEST_F(CellularCapabilityUniversalMainTest, SimPathChanged) { |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1163 | // Set up mock modem SIM properties |
| 1164 | const char kImsi[] = "310100000001"; |
| 1165 | const char kSimIdentifier[] = "9999888"; |
| 1166 | const char kOperatorIdentifier[] = "310240"; |
| 1167 | const char kOperatorName[] = "Custom SPN"; |
| 1168 | DBusPropertiesMap sim_properties; |
| 1169 | sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi); |
| 1170 | sim_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer() |
| 1171 | .append_string(kSimIdentifier); |
| 1172 | sim_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer() |
| 1173 | .append_string(kOperatorIdentifier); |
| 1174 | sim_properties[MM_SIM_PROPERTY_OPERATORNAME].writer() |
| 1175 | .append_string(kOperatorName); |
| 1176 | |
| 1177 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM)) |
| 1178 | .Times(1).WillOnce(Return(sim_properties)); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1179 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1180 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 1181 | .Times(1); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1182 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1183 | EXPECT_FALSE(cellular_->sim_present()); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 1184 | EXPECT_EQ(nullptr, capability_->sim_proxy_);; |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1185 | EXPECT_EQ("", capability_->sim_path_); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1186 | EXPECT_EQ("", cellular_->imsi()); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1187 | EXPECT_EQ("", cellular_->sim_identifier()); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1188 | EXPECT_EQ("", capability_->spn_); |
| 1189 | |
| 1190 | capability_->OnSimPathChanged(kSimPath); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1191 | EXPECT_TRUE(cellular_->sim_present()); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 1192 | EXPECT_NE(nullptr, capability_->sim_proxy_);; |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1193 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1194 | EXPECT_EQ(kImsi, cellular_->imsi()); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1195 | EXPECT_EQ(kSimIdentifier, cellular_->sim_identifier()); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1196 | EXPECT_EQ(kOperatorName, capability_->spn_); |
| 1197 | |
| 1198 | // Changing to the same SIM path should be a no-op. |
| 1199 | capability_->OnSimPathChanged(kSimPath); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1200 | EXPECT_TRUE(cellular_->sim_present()); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 1201 | EXPECT_NE(nullptr, capability_->sim_proxy_);; |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1202 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1203 | EXPECT_EQ(kImsi, cellular_->imsi()); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1204 | EXPECT_EQ(kSimIdentifier, cellular_->sim_identifier()); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1205 | EXPECT_EQ(kOperatorName, capability_->spn_); |
| 1206 | |
| 1207 | capability_->OnSimPathChanged(""); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1208 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1209 | Mock::VerifyAndClearExpectations(properties_proxy_.get()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1210 | EXPECT_FALSE(cellular_->sim_present()); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 1211 | EXPECT_EQ(nullptr, capability_->sim_proxy_);; |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1212 | EXPECT_EQ("", capability_->sim_path_); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1213 | EXPECT_EQ("", cellular_->imsi()); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1214 | EXPECT_EQ("", cellular_->sim_identifier()); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1215 | EXPECT_EQ("", capability_->spn_); |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1216 | |
| 1217 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM)) |
| 1218 | .Times(1).WillOnce(Return(sim_properties)); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1219 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1220 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 1221 | .Times(1); |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1222 | |
| 1223 | capability_->OnSimPathChanged(kSimPath); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1224 | EXPECT_TRUE(cellular_->sim_present()); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 1225 | EXPECT_NE(nullptr, capability_->sim_proxy_);; |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1226 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1227 | EXPECT_EQ(kImsi, cellular_->imsi()); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1228 | EXPECT_EQ(kSimIdentifier, cellular_->sim_identifier()); |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1229 | EXPECT_EQ(kOperatorName, capability_->spn_); |
| 1230 | |
| 1231 | capability_->OnSimPathChanged("/"); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1232 | EXPECT_FALSE(cellular_->sim_present()); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 1233 | EXPECT_EQ(nullptr, capability_->sim_proxy_);; |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1234 | EXPECT_EQ("/", capability_->sim_path_); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1235 | EXPECT_EQ("", cellular_->imsi()); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1236 | EXPECT_EQ("", cellular_->sim_identifier()); |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1237 | EXPECT_EQ("", capability_->spn_); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1240 | TEST_F(CellularCapabilityUniversalMainTest, SimPropertiesChanged) { |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1241 | // Set up mock modem properties |
| 1242 | DBusPropertiesMap modem_properties; |
| 1243 | modem_properties[MM_MODEM_PROPERTY_SIM].writer().append_path(kSimPath); |
| 1244 | |
| 1245 | // Set up mock modem sim properties |
| 1246 | const char kImsi[] = "310100000001"; |
| 1247 | DBusPropertiesMap sim_properties; |
| 1248 | sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi); |
| 1249 | |
| 1250 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM)) |
| 1251 | .WillOnce(Return(sim_properties)); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1252 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1253 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 1254 | .Times(0); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1255 | |
| 1256 | EXPECT_FALSE(capability_->sim_proxy_.get()); |
| 1257 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 1258 | modem_properties, vector<string>()); |
| 1259 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 1260 | EXPECT_TRUE(capability_->sim_proxy_.get()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1261 | EXPECT_EQ(kImsi, cellular_->imsi()); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1262 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1263 | |
| 1264 | // Updating the SIM |
| 1265 | DBusPropertiesMap new_properties; |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1266 | const char kNewImsi[] = "310240123456789"; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1267 | const char kSimIdentifier[] = "9999888"; |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1268 | const char kOperatorIdentifier[] = "310240"; |
| 1269 | const char kOperatorName[] = "Custom SPN"; |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 1270 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1271 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
| 1272 | .Times(2); |
| 1273 | EXPECT_CALL(*mock_home_provider_info_, UpdateIMSI(kNewImsi)).Times(2); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1274 | new_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kNewImsi); |
| 1275 | new_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer(). |
| 1276 | append_string(kSimIdentifier); |
| 1277 | new_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer(). |
| 1278 | append_string(kOperatorIdentifier); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1279 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM, |
| 1280 | new_properties, |
| 1281 | vector<string>()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1282 | EXPECT_EQ(kNewImsi, cellular_->imsi()); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1283 | EXPECT_EQ(kSimIdentifier, cellular_->sim_identifier()); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1284 | EXPECT_EQ("", capability_->spn_); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1285 | |
| 1286 | new_properties[MM_SIM_PROPERTY_OPERATORNAME].writer(). |
| 1287 | append_string(kOperatorName); |
| 1288 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM, |
| 1289 | new_properties, |
| 1290 | vector<string>()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1291 | EXPECT_EQ(kOperatorName, capability_->spn_); |
| 1292 | } |
| 1293 | |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 1294 | MATCHER_P(SizeIs, value, "") { |
| 1295 | return static_cast<size_t>(value) == arg.size(); |
| 1296 | } |
| 1297 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1298 | TEST_F(CellularCapabilityUniversalMainTest, Reset) { |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 1299 | // Save pointers to proxies before they are lost by the call to InitProxies |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1300 | mm1::MockModemProxy* modem_proxy = modem_proxy_.get(); |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 1301 | EXPECT_CALL(*modem_proxy, set_state_changed_callback(_)); |
| 1302 | capability_->InitProxies(); |
| 1303 | |
| 1304 | Error error; |
| 1305 | ResultCallback reset_callback; |
| 1306 | |
| 1307 | EXPECT_CALL(*modem_proxy, Reset(_, _, CellularCapability::kTimeoutReset)) |
| 1308 | .WillOnce(SaveArg<1>(&reset_callback)); |
| 1309 | |
| 1310 | capability_->Reset(&error, ResultCallback()); |
| 1311 | EXPECT_TRUE(capability_->resetting_); |
| 1312 | reset_callback.Run(error); |
| 1313 | EXPECT_FALSE(capability_->resetting_); |
| 1314 | } |
| 1315 | |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 1316 | TEST_F(CellularCapabilityUniversalMainTest, UpdateActiveBearer) { |
mukesh agrawal | 83a98f4 | 2013-07-31 16:25:53 -0700 | [diff] [blame] | 1317 | // Common resources. |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1318 | const size_t kPathCount = 3; |
| 1319 | DBus::Path active_paths[kPathCount], inactive_paths[kPathCount]; |
| 1320 | for (size_t i = 0; i < kPathCount; ++i) { |
Ben Chan | cbef812 | 2014-01-06 17:31:30 -0800 | [diff] [blame] | 1321 | active_paths[i] = base::StringPrintf("%s/%zu", kActiveBearerPathPrefix, i); |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1322 | inactive_paths[i] = |
Ben Chan | cbef812 | 2014-01-06 17:31:30 -0800 | [diff] [blame] | 1323 | base::StringPrintf("%s/%zu", kInactiveBearerPathPrefix, i); |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1324 | } |
| 1325 | |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 1326 | EXPECT_EQ(nullptr, capability_->GetActiveBearer());; |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1327 | |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 1328 | // Check that |active_bearer_| is set correctly when an active bearer is |
| 1329 | // returned. |
Ben Chan | cbef812 | 2014-01-06 17:31:30 -0800 | [diff] [blame] | 1330 | capability_->OnBearersChanged({inactive_paths[0], |
| 1331 | inactive_paths[1], |
| 1332 | active_paths[2], |
| 1333 | inactive_paths[1], |
| 1334 | inactive_paths[2]}); |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 1335 | capability_->UpdateActiveBearer(); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 1336 | ASSERT_NE(nullptr, capability_->GetActiveBearer());; |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 1337 | EXPECT_EQ(active_paths[2], capability_->GetActiveBearer()->dbus_path()); |
Ben Chan | cbef812 | 2014-01-06 17:31:30 -0800 | [diff] [blame] | 1338 | |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 1339 | // Check that |active_bearer_| is nullptr if no active bearers are returned. |
Ben Chan | cbef812 | 2014-01-06 17:31:30 -0800 | [diff] [blame] | 1340 | capability_->OnBearersChanged({inactive_paths[0], |
| 1341 | inactive_paths[1], |
| 1342 | inactive_paths[2], |
| 1343 | inactive_paths[1]}); |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 1344 | capability_->UpdateActiveBearer(); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 1345 | EXPECT_EQ(nullptr, capability_->GetActiveBearer());; |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1346 | |
| 1347 | // Check that returning multiple bearers causes death. |
Ben Chan | cbef812 | 2014-01-06 17:31:30 -0800 | [diff] [blame] | 1348 | capability_->OnBearersChanged({active_paths[0], |
| 1349 | inactive_paths[1], |
| 1350 | inactive_paths[2], |
| 1351 | active_paths[1], |
| 1352 | inactive_paths[1]}); |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 1353 | EXPECT_DEATH(capability_->UpdateActiveBearer(), |
Ben Chan | cbef812 | 2014-01-06 17:31:30 -0800 | [diff] [blame] | 1354 | "Found more than one active bearer."); |
| 1355 | |
| 1356 | capability_->OnBearersChanged({}); |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 1357 | capability_->UpdateActiveBearer(); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 1358 | EXPECT_EQ(nullptr, capability_->GetActiveBearer());; |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1359 | } |
| 1360 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1361 | // Validates expected behavior of Connect function |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1362 | TEST_F(CellularCapabilityUniversalMainTest, Connect) { |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1363 | mm1::MockModemSimpleProxy* modem_simple_proxy = modem_simple_proxy_.get(); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1364 | SetSimpleProxy(); |
| 1365 | Error error; |
| 1366 | DBusPropertiesMap properties; |
| 1367 | capability_->apn_try_list_.clear(); |
| 1368 | ResultCallback callback = |
| 1369 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 1370 | DBus::Path bearer("/foo"); |
| 1371 | |
| 1372 | // Test connect failures |
| 1373 | EXPECT_CALL(*modem_simple_proxy, Connect(_, _, _, _)) |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1374 | .WillRepeatedly(SaveArg<2>(&connect_callback_)); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1375 | capability_->Connect(properties, &error, callback); |
| 1376 | EXPECT_TRUE(error.IsSuccess()); |
| 1377 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 1378 | EXPECT_CALL(*service_, ClearLastGoodApn()); |
| 1379 | connect_callback_.Run(bearer, Error(Error::kOperationFailed)); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1380 | Mock::VerifyAndClearExpectations(this); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1381 | |
| 1382 | // Test connect success |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1383 | capability_->Connect(properties, &error, callback); |
| 1384 | EXPECT_TRUE(error.IsSuccess()); |
| 1385 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 1386 | connect_callback_.Run(bearer, Error(Error::kSuccess)); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1387 | Mock::VerifyAndClearExpectations(this); |
Jason Glasgow | 7234ec3 | 2012-05-23 16:01:21 -0400 | [diff] [blame] | 1388 | |
| 1389 | // Test connect failures without a service. Make sure that shill |
| 1390 | // does not crash if the connect failed and there is no |
| 1391 | // CellularService object. This can happen if the modem is enabled |
| 1392 | // and then quickly disabled. |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 1393 | cellular_->service_ = nullptr; |
Jason Glasgow | 7234ec3 | 2012-05-23 16:01:21 -0400 | [diff] [blame] | 1394 | EXPECT_FALSE(capability_->cellular()->service()); |
Jason Glasgow | 7234ec3 | 2012-05-23 16:01:21 -0400 | [diff] [blame] | 1395 | capability_->Connect(properties, &error, callback); |
| 1396 | EXPECT_TRUE(error.IsSuccess()); |
| 1397 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 1398 | connect_callback_.Run(bearer, Error(Error::kOperationFailed)); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | // Validates Connect iterates over APNs |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1402 | TEST_F(CellularCapabilityUniversalMainTest, ConnectApns) { |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1403 | mm1::MockModemSimpleProxy* modem_simple_proxy = modem_simple_proxy_.get(); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1404 | SetSimpleProxy(); |
| 1405 | Error error; |
| 1406 | DBusPropertiesMap properties; |
| 1407 | capability_->apn_try_list_.clear(); |
| 1408 | ResultCallback callback = |
| 1409 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 1410 | DBus::Path bearer("/bearer0"); |
| 1411 | |
| 1412 | const char apn_name_foo[] = "foo"; |
| 1413 | const char apn_name_bar[] = "bar"; |
| 1414 | EXPECT_CALL(*modem_simple_proxy, Connect(HasApn(apn_name_foo), _, _, _)) |
| 1415 | .WillOnce(SaveArg<2>(&connect_callback_)); |
| 1416 | Stringmap apn1; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1417 | apn1[kApnProperty] = apn_name_foo; |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1418 | capability_->apn_try_list_.push_back(apn1); |
| 1419 | Stringmap apn2; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1420 | apn2[kApnProperty] = apn_name_bar; |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1421 | capability_->apn_try_list_.push_back(apn2); |
| 1422 | capability_->FillConnectPropertyMap(&properties); |
| 1423 | capability_->Connect(properties, &error, callback); |
| 1424 | EXPECT_TRUE(error.IsSuccess()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1425 | Mock::VerifyAndClearExpectations(modem_simple_proxy); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1426 | |
| 1427 | EXPECT_CALL(*modem_simple_proxy, Connect(HasApn(apn_name_bar), _, _, _)) |
| 1428 | .WillOnce(SaveArg<2>(&connect_callback_)); |
| 1429 | EXPECT_CALL(*service_, ClearLastGoodApn()); |
| 1430 | connect_callback_.Run(bearer, Error(Error::kInvalidApn)); |
| 1431 | |
| 1432 | EXPECT_CALL(*service_, SetLastGoodApn(apn2)); |
| 1433 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 1434 | connect_callback_.Run(bearer, Error(Error::kSuccess)); |
| 1435 | } |
| 1436 | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1437 | // Validates GetTypeString and AccessTechnologyToTechnologyFamily |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1438 | TEST_F(CellularCapabilityUniversalMainTest, GetTypeString) { |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1439 | const int gsm_technologies[] = { |
| 1440 | MM_MODEM_ACCESS_TECHNOLOGY_LTE, |
| 1441 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS, |
| 1442 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA, |
| 1443 | MM_MODEM_ACCESS_TECHNOLOGY_HSUPA, |
| 1444 | MM_MODEM_ACCESS_TECHNOLOGY_HSDPA, |
| 1445 | MM_MODEM_ACCESS_TECHNOLOGY_UMTS, |
| 1446 | MM_MODEM_ACCESS_TECHNOLOGY_EDGE, |
| 1447 | MM_MODEM_ACCESS_TECHNOLOGY_GPRS, |
| 1448 | MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT, |
| 1449 | MM_MODEM_ACCESS_TECHNOLOGY_GSM, |
| 1450 | MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 1451 | MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 1452 | MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA, |
| 1453 | MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA, |
| 1454 | MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB, |
| 1455 | MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB, |
| 1456 | MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT, |
| 1457 | }; |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 1458 | for (size_t i = 0; i < arraysize(gsm_technologies); ++i) { |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1459 | capability_->access_technologies_ = gsm_technologies[i]; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1460 | ASSERT_EQ(capability_->GetTypeString(), kTechnologyFamilyGsm); |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1461 | } |
| 1462 | const int cdma_technologies[] = { |
| 1463 | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 1464 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA, |
| 1465 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 1466 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB, |
| 1467 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 1468 | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT, |
| 1469 | }; |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 1470 | for (size_t i = 0; i < arraysize(cdma_technologies); ++i) { |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1471 | capability_->access_technologies_ = cdma_technologies[i]; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1472 | ASSERT_EQ(capability_->GetTypeString(), kTechnologyFamilyCdma); |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1473 | } |
| 1474 | capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; |
| 1475 | ASSERT_EQ(capability_->GetTypeString(), ""); |
| 1476 | } |
| 1477 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1478 | TEST_F(CellularCapabilityUniversalMainTest, AllowRoaming) { |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 1479 | EXPECT_FALSE(cellular_->allow_roaming_); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1480 | EXPECT_FALSE(cellular_->provider_requires_roaming()); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 1481 | EXPECT_FALSE(capability_->AllowRoaming()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1482 | cellular_->set_provider_requires_roaming(true); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 1483 | EXPECT_TRUE(capability_->AllowRoaming()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1484 | cellular_->set_provider_requires_roaming(false); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 1485 | cellular_->allow_roaming_ = true; |
| 1486 | EXPECT_TRUE(capability_->AllowRoaming()); |
| 1487 | } |
| 1488 | |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 1489 | TEST_F(CellularCapabilityUniversalMainTest, GetMdnForOLP) { |
Prathmesh Prabhu | 5089a6e | 2014-05-07 20:49:16 -0700 | [diff] [blame] | 1490 | const string kVzwUUID = "c83d6597-dc91-4d48-a3a7-d86b80123751"; |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1491 | const string kFooUUID = "foo"; |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 1492 | MockMobileOperatorInfo mock_operator_info(&dispatcher_, |
| 1493 | "MobileOperatorInfo"); |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 1494 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1495 | mock_operator_info.SetEmptyDefaultsForProperties(); |
| 1496 | EXPECT_CALL(mock_operator_info, IsMobileNetworkOperatorKnown()) |
| 1497 | .WillRepeatedly(Return(true)); |
| 1498 | EXPECT_CALL(mock_operator_info, uuid()).WillRepeatedly(ReturnRef(kVzwUUID)); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1499 | capability_->subscription_state_ = |
| 1500 | CellularCapabilityUniversal::kSubscriptionStateUnknown; |
| 1501 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1502 | cellular_->set_mdn(""); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1503 | EXPECT_EQ("0000000000", capability_->GetMdnForOLP(&mock_operator_info)); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1504 | cellular_->set_mdn("0123456789"); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1505 | EXPECT_EQ("0123456789", capability_->GetMdnForOLP(&mock_operator_info)); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1506 | cellular_->set_mdn("10123456789"); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1507 | EXPECT_EQ("0123456789", capability_->GetMdnForOLP(&mock_operator_info)); |
| 1508 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1509 | cellular_->set_mdn("1021232333"); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1510 | capability_->subscription_state_ = |
| 1511 | CellularCapabilityUniversal::kSubscriptionStateUnprovisioned; |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1512 | EXPECT_EQ("0000000000", capability_->GetMdnForOLP(&mock_operator_info)); |
| 1513 | Mock::VerifyAndClearExpectations(&mock_operator_info); |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 1514 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1515 | mock_operator_info.SetEmptyDefaultsForProperties(); |
| 1516 | EXPECT_CALL(mock_operator_info, IsMobileNetworkOperatorKnown()) |
| 1517 | .WillRepeatedly(Return(true)); |
| 1518 | EXPECT_CALL(mock_operator_info, uuid()).WillRepeatedly(ReturnRef(kFooUUID)); |
| 1519 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1520 | cellular_->set_mdn(""); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1521 | EXPECT_EQ("", capability_->GetMdnForOLP(&mock_operator_info)); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1522 | cellular_->set_mdn("0123456789"); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1523 | EXPECT_EQ("0123456789", capability_->GetMdnForOLP(&mock_operator_info)); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1524 | cellular_->set_mdn("10123456789"); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1525 | EXPECT_EQ("10123456789", capability_->GetMdnForOLP(&mock_operator_info)); |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1528 | TEST_F(CellularCapabilityUniversalMainTest, UpdateServiceOLP) { |
| 1529 | const MobileOperatorInfo::OnlinePortal kOlp { |
| 1530 | "http://testurl", |
| 1531 | "POST", |
| 1532 | "imei=${imei}&imsi=${imsi}&mdn=${mdn}&min=${min}&iccid=${iccid}"}; |
| 1533 | const vector<MobileOperatorInfo::OnlinePortal> kOlpList {kOlp}; |
Prathmesh Prabhu | 5089a6e | 2014-05-07 20:49:16 -0700 | [diff] [blame] | 1534 | const string kUuidVzw = "c83d6597-dc91-4d48-a3a7-d86b80123751"; |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1535 | const string kUuidFoo = "foo"; |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 1536 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1537 | cellular_->set_imei("1"); |
| 1538 | cellular_->set_imsi("2"); |
| 1539 | cellular_->set_mdn("10123456789"); |
| 1540 | cellular_->set_min("5"); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1541 | cellular_->set_sim_identifier("6"); |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1542 | |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 1543 | mock_home_provider_info_->SetEmptyDefaultsForProperties(); |
| 1544 | EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown()) |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1545 | .WillRepeatedly(Return(true)); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 1546 | EXPECT_CALL(*mock_home_provider_info_, olp_list()) |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1547 | .WillRepeatedly(ReturnRef(kOlpList)); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 1548 | EXPECT_CALL(*mock_home_provider_info_, uuid()) |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1549 | .WillOnce(ReturnRef(kUuidVzw)); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 1550 | CreateService(); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1551 | capability_->UpdateServiceOLP(); |
| 1552 | // Copy to simplify assertions below. |
| 1553 | Stringmap vzw_olp = cellular_->service()->olp(); |
| 1554 | EXPECT_EQ("http://testurl", vzw_olp[kPaymentPortalURL]); |
| 1555 | EXPECT_EQ("POST", vzw_olp[kPaymentPortalMethod]); |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 1556 | EXPECT_EQ("imei=1&imsi=2&mdn=0123456789&min=5&iccid=6", |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1557 | vzw_olp[kPaymentPortalPostData]); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 1558 | Mock::VerifyAndClearExpectations(mock_home_provider_info_); |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 1559 | |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 1560 | mock_home_provider_info_->SetEmptyDefaultsForProperties(); |
| 1561 | EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown()) |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1562 | .WillRepeatedly(Return(true)); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 1563 | EXPECT_CALL(*mock_home_provider_info_, olp_list()) |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1564 | .WillRepeatedly(ReturnRef(kOlpList)); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 1565 | EXPECT_CALL(*mock_home_provider_info_, uuid()) |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1566 | .WillOnce(ReturnRef(kUuidFoo)); |
| 1567 | capability_->UpdateServiceOLP(); |
| 1568 | // Copy to simplify assertions below. |
| 1569 | Stringmap olp = cellular_->service()->olp(); |
| 1570 | EXPECT_EQ("http://testurl", olp[kPaymentPortalURL]); |
| 1571 | EXPECT_EQ("POST", olp[kPaymentPortalMethod]); |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 1572 | EXPECT_EQ("imei=1&imsi=2&mdn=10123456789&min=5&iccid=6", |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 1573 | olp[kPaymentPortalPostData]); |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1574 | } |
| 1575 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1576 | TEST_F(CellularCapabilityUniversalMainTest, IsMdnValid) { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1577 | cellular_->set_mdn(""); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1578 | EXPECT_FALSE(capability_->IsMdnValid()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1579 | cellular_->set_mdn("0000000"); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1580 | EXPECT_FALSE(capability_->IsMdnValid()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1581 | cellular_->set_mdn("0000001"); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1582 | EXPECT_TRUE(capability_->IsMdnValid()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1583 | cellular_->set_mdn("1231223"); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1584 | EXPECT_TRUE(capability_->IsMdnValid()); |
| 1585 | } |
| 1586 | |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1587 | TEST_F(CellularCapabilityUniversalTimerTest, CompleteActivation) { |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1588 | const char kIccid[] = "1234567"; |
| 1589 | |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1590 | cellular_->set_sim_identifier(kIccid); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1591 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1592 | SetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1593 | kIccid, |
| 1594 | PendingActivationStore::kStatePending)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1595 | .Times(1); |
Thieu Le | 7de12f5 | 2014-07-11 15:30:43 -0700 | [diff] [blame] | 1596 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1597 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1598 | kIccid)) |
| 1599 | .WillOnce(Return(PendingActivationStore::kStatePending)); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1600 | EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1601 | .Times(1); |
Thieu Le | 7de12f5 | 2014-07-11 15:30:43 -0700 | [diff] [blame] | 1602 | EXPECT_CALL(*modem_proxy_.get(), Reset(_, _, _)).Times(1); |
| 1603 | Error error; |
| 1604 | capability_->InitProxies(); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1605 | capability_->CompleteActivation(&error); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1606 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1607 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1608 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | TEST_F(CellularCapabilityUniversalMainTest, UpdateServiceActivationState) { |
| 1612 | const char kIccid[] = "1234567"; |
Prathmesh Prabhu | 3ee2f41 | 2014-05-20 17:30:19 -0700 | [diff] [blame] | 1613 | const vector<MobileOperatorInfo::OnlinePortal> olp_list { |
| 1614 | {"some@url", "some_method", "some_post_data"} |
| 1615 | }; |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1616 | capability_->subscription_state_ = |
| 1617 | CellularCapabilityUniversal::kSubscriptionStateUnprovisioned; |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1618 | cellular_->set_sim_identifier(""); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1619 | cellular_->set_mdn("0000000000"); |
Prathmesh Prabhu | 3ee2f41 | 2014-05-20 17:30:19 -0700 | [diff] [blame] | 1620 | EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown()) |
| 1621 | .WillRepeatedly(Return(true)); |
| 1622 | EXPECT_CALL(*mock_home_provider_info_, olp_list()) |
| 1623 | .WillRepeatedly(ReturnRef(olp_list)); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1624 | |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 1625 | service_->SetAutoConnect(false); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1626 | EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1627 | .Times(1); |
| 1628 | capability_->UpdateServiceActivationState(); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1629 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 1630 | EXPECT_FALSE(service_->auto_connect()); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1631 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1632 | cellular_->set_mdn("1231231122"); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1633 | capability_->subscription_state_ = |
| 1634 | CellularCapabilityUniversal::kSubscriptionStateUnknown; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1635 | EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1636 | .Times(1); |
| 1637 | capability_->UpdateServiceActivationState(); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1638 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 1639 | EXPECT_TRUE(service_->auto_connect()); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1640 | |
Thieu Le | 247416e | 2014-02-25 18:19:53 -0800 | [diff] [blame] | 1641 | // Make sure we don't overwrite auto-connect if a service is already |
| 1642 | // activated before calling UpdateServiceActivationState(). |
| 1643 | service_->SetAutoConnect(false); |
| 1644 | EXPECT_FALSE(service_->auto_connect()); |
| 1645 | const string activation_state = kActivationStateActivated; |
| 1646 | EXPECT_CALL(*service_, activation_state()) |
| 1647 | .WillOnce(ReturnRef(activation_state)); |
| 1648 | EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated)) |
| 1649 | .Times(1); |
| 1650 | capability_->UpdateServiceActivationState(); |
| 1651 | Mock::VerifyAndClearExpectations(service_); |
| 1652 | EXPECT_FALSE(service_->auto_connect()); |
| 1653 | |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 1654 | service_->SetAutoConnect(false); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1655 | cellular_->set_mdn("0000000000"); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1656 | cellular_->set_sim_identifier(kIccid); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1657 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1658 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1659 | kIccid)) |
Thieu Le | 2900718 | 2014-08-13 18:02:39 -0700 | [diff] [blame] | 1660 | .Times(1) |
Thieu Le | 7de12f5 | 2014-07-11 15:30:43 -0700 | [diff] [blame] | 1661 | .WillRepeatedly(Return(PendingActivationStore::kStatePending)); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1662 | EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1663 | .Times(1); |
| 1664 | capability_->UpdateServiceActivationState(); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1665 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1666 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 1667 | EXPECT_FALSE(service_->auto_connect()); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1668 | |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1669 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1670 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1671 | kIccid)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1672 | .Times(2) |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1673 | .WillRepeatedly(Return(PendingActivationStore::kStateActivated)); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1674 | EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1675 | .Times(1); |
| 1676 | capability_->UpdateServiceActivationState(); |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 1677 | Mock::VerifyAndClearExpectations(service_); |
| 1678 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 1679 | EXPECT_TRUE(service_->auto_connect()); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1680 | |
| 1681 | // SubscriptionStateUnprovisioned overrides valid MDN. |
| 1682 | capability_->subscription_state_ = |
| 1683 | CellularCapabilityUniversal::kSubscriptionStateUnprovisioned; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1684 | cellular_->set_mdn("1231231122"); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1685 | cellular_->set_sim_identifier(""); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1686 | service_->SetAutoConnect(false); |
| 1687 | EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated)) |
| 1688 | .Times(1); |
| 1689 | capability_->UpdateServiceActivationState(); |
| 1690 | Mock::VerifyAndClearExpectations(service_); |
| 1691 | EXPECT_FALSE(service_->auto_connect()); |
| 1692 | |
| 1693 | // SubscriptionStateProvisioned overrides invalid MDN. |
| 1694 | capability_->subscription_state_ = |
| 1695 | CellularCapabilityUniversal::kSubscriptionStateProvisioned; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1696 | cellular_->set_mdn("0000000000"); |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1697 | cellular_->set_sim_identifier(""); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1698 | service_->SetAutoConnect(false); |
| 1699 | EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated)) |
| 1700 | .Times(1); |
| 1701 | capability_->UpdateServiceActivationState(); |
| 1702 | Mock::VerifyAndClearExpectations(service_); |
| 1703 | EXPECT_TRUE(service_->auto_connect()); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1704 | } |
| 1705 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1706 | TEST_F(CellularCapabilityUniversalMainTest, UpdatePendingActivationState) { |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1707 | const char kIccid[] = "1234567"; |
| 1708 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1709 | capability_->InitProxies(); |
| 1710 | capability_->registration_state_ = |
| 1711 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING; |
| 1712 | |
| 1713 | // No MDN, no ICCID. |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1714 | cellular_->set_mdn("0000000"); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1715 | capability_->subscription_state_ = |
| 1716 | CellularCapabilityUniversal::kSubscriptionStateUnknown; |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1717 | cellular_->set_sim_identifier(""); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1718 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1719 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
| 1720 | .Times(0); |
| 1721 | capability_->UpdatePendingActivationState(); |
| 1722 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 1723 | |
| 1724 | // Valid MDN, but subsciption_state_ Unprovisioned |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1725 | cellular_->set_mdn("1234567"); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1726 | capability_->subscription_state_ = |
| 1727 | CellularCapabilityUniversal::kSubscriptionStateUnprovisioned; |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1728 | cellular_->set_sim_identifier(""); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1729 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1730 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1731 | .Times(0); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1732 | capability_->UpdatePendingActivationState(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1733 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1734 | |
| 1735 | // ICCID known. |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1736 | cellular_->set_sim_identifier(kIccid); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1737 | |
| 1738 | // After the modem has reset. |
| 1739 | capability_->reset_done_ = true; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1740 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1741 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1742 | kIccid)) |
| 1743 | .Times(1).WillOnce(Return(PendingActivationStore::kStatePending)); |
| 1744 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1745 | SetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1746 | kIccid, |
| 1747 | PendingActivationStore::kStateActivated)) |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1748 | .Times(1); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1749 | capability_->UpdatePendingActivationState(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1750 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1751 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1752 | // Not registered. |
| 1753 | capability_->registration_state_ = |
| 1754 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1755 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1756 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1757 | kIccid)) |
| 1758 | .Times(2).WillRepeatedly(Return(PendingActivationStore::kStateActivated)); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1759 | EXPECT_CALL(*service_, AutoConnect()).Times(0); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1760 | capability_->UpdatePendingActivationState(); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1761 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1762 | |
| 1763 | // Service, registered. |
| 1764 | capability_->registration_state_ = |
| 1765 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME; |
| 1766 | EXPECT_CALL(*service_, AutoConnect()).Times(1); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1767 | capability_->UpdatePendingActivationState(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1768 | |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1769 | cellular_->service_->activation_state_ = kActivationStateNotActivated; |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1770 | |
Thieu Le | 7de12f5 | 2014-07-11 15:30:43 -0700 | [diff] [blame] | 1771 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1772 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1773 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1774 | // Device is connected. |
| 1775 | cellular_->state_ = Cellular::kStateConnected; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1776 | capability_->UpdatePendingActivationState(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1777 | |
| 1778 | // Device is linked. |
| 1779 | cellular_->state_ = Cellular::kStateLinked; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1780 | capability_->UpdatePendingActivationState(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1781 | |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1782 | // Got valid MDN, subscription_state_ is kSubscriptionStateUnknown |
Thieu Le | 7de12f5 | 2014-07-11 15:30:43 -0700 | [diff] [blame] | 1783 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1784 | RemoveEntry(PendingActivationStore::kIdentifierICCID, kIccid)); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1785 | cellular_->state_ = Cellular::kStateRegistered; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1786 | cellular_->set_mdn("1020304"); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1787 | capability_->subscription_state_ = |
| 1788 | CellularCapabilityUniversal::kSubscriptionStateUnknown; |
| 1789 | capability_->UpdatePendingActivationState(); |
Thieu Le | 7de12f5 | 2014-07-11 15:30:43 -0700 | [diff] [blame] | 1790 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1791 | |
| 1792 | // Got invalid MDN, subscription_state_ is kSubscriptionStateProvisioned |
Thieu Le | 7de12f5 | 2014-07-11 15:30:43 -0700 | [diff] [blame] | 1793 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1794 | RemoveEntry(PendingActivationStore::kIdentifierICCID, kIccid)); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1795 | cellular_->state_ = Cellular::kStateRegistered; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1796 | cellular_->set_mdn("0000000"); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1797 | capability_->subscription_state_ = |
| 1798 | CellularCapabilityUniversal::kSubscriptionStateProvisioned; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1799 | capability_->UpdatePendingActivationState(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1800 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1801 | } |
| 1802 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1803 | TEST_F(CellularCapabilityUniversalMainTest, IsServiceActivationRequired) { |
Prathmesh Prabhu | 3ee2f41 | 2014-05-20 17:30:19 -0700 | [diff] [blame] | 1804 | const vector<MobileOperatorInfo::OnlinePortal> empty_list; |
| 1805 | const vector<MobileOperatorInfo::OnlinePortal> olp_list { |
| 1806 | {"some@url", "some_method", "some_post_data"} |
| 1807 | }; |
| 1808 | |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1809 | capability_->subscription_state_ = |
| 1810 | CellularCapabilityUniversal::kSubscriptionStateProvisioned; |
| 1811 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 1812 | |
| 1813 | capability_->subscription_state_ = |
| 1814 | CellularCapabilityUniversal::kSubscriptionStateUnprovisioned; |
| 1815 | EXPECT_TRUE(capability_->IsServiceActivationRequired()); |
| 1816 | |
| 1817 | capability_->subscription_state_ = |
| 1818 | CellularCapabilityUniversal::kSubscriptionStateUnknown; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1819 | cellular_->set_mdn("0000000000"); |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1820 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 1821 | |
Prathmesh Prabhu | 3ee2f41 | 2014-05-20 17:30:19 -0700 | [diff] [blame] | 1822 | EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown()) |
| 1823 | .WillRepeatedly(Return(false)); |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1824 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
Prathmesh Prabhu | 3ee2f41 | 2014-05-20 17:30:19 -0700 | [diff] [blame] | 1825 | Mock::VerifyAndClearExpectations(mock_home_provider_info_); |
| 1826 | |
| 1827 | EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown()) |
| 1828 | .WillRepeatedly(Return(true)); |
| 1829 | EXPECT_CALL(*mock_home_provider_info_, olp_list()) |
| 1830 | .WillRepeatedly(ReturnRef(empty_list)); |
| 1831 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 1832 | Mock::VerifyAndClearExpectations(mock_home_provider_info_); |
| 1833 | |
| 1834 | // Set expectations for all subsequent cases. |
| 1835 | EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown()) |
| 1836 | .WillRepeatedly(Return(true)); |
| 1837 | EXPECT_CALL(*mock_home_provider_info_, olp_list()) |
| 1838 | .WillRepeatedly(ReturnRef(olp_list)); |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1839 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1840 | cellular_->set_mdn(""); |
Ben Chan | 200591a | 2013-08-07 14:39:04 -0700 | [diff] [blame] | 1841 | EXPECT_TRUE(capability_->IsServiceActivationRequired()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1842 | cellular_->set_mdn("1234567890"); |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1843 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1844 | cellular_->set_mdn("0000000000"); |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1845 | EXPECT_TRUE(capability_->IsServiceActivationRequired()); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1846 | |
| 1847 | const char kIccid[] = "1234567890"; |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1848 | cellular_->set_sim_identifier(kIccid); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1849 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1850 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1851 | kIccid)) |
| 1852 | .WillOnce(Return(PendingActivationStore::kStateActivated)) |
| 1853 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1854 | .WillOnce(Return(PendingActivationStore::kStateUnknown)); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1855 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1856 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1857 | EXPECT_TRUE(capability_->IsServiceActivationRequired()); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1858 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1859 | } |
| 1860 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1861 | TEST_F(CellularCapabilityUniversalMainTest, OnModemCurrentCapabilitiesChanged) { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1862 | EXPECT_FALSE(cellular_->scanning_supported()); |
Ben Chan | fcca27b | 2013-01-22 15:03:44 -0800 | [diff] [blame] | 1863 | capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_LTE); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1864 | EXPECT_FALSE(cellular_->scanning_supported()); |
Ben Chan | fcca27b | 2013-01-22 15:03:44 -0800 | [diff] [blame] | 1865 | capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_CDMA_EVDO); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1866 | EXPECT_FALSE(cellular_->scanning_supported()); |
Ben Chan | fcca27b | 2013-01-22 15:03:44 -0800 | [diff] [blame] | 1867 | capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_GSM_UMTS); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1868 | EXPECT_TRUE(cellular_->scanning_supported()); |
Ben Chan | fcca27b | 2013-01-22 15:03:44 -0800 | [diff] [blame] | 1869 | capability_->OnModemCurrentCapabilitiesChanged( |
| 1870 | MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_CDMA_EVDO); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1871 | EXPECT_TRUE(cellular_->scanning_supported()); |
Ben Chan | fcca27b | 2013-01-22 15:03:44 -0800 | [diff] [blame] | 1872 | } |
| 1873 | |
Arman Uguray | 7af0fac | 2013-03-18 17:35:35 -0700 | [diff] [blame] | 1874 | TEST_F(CellularCapabilityUniversalMainTest, GetNetworkTechnologyStringOnE362) { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1875 | cellular_->set_model_id("");; |
Arman Uguray | 7af0fac | 2013-03-18 17:35:35 -0700 | [diff] [blame] | 1876 | capability_->access_technologies_ = 0; |
| 1877 | EXPECT_TRUE(capability_->GetNetworkTechnologyString().empty()); |
| 1878 | |
Ben Chan | 3dddd04 | 2014-10-19 14:08:10 -0700 | [diff] [blame] | 1879 | cellular_->set_mm_plugin(CellularCapabilityUniversal::kNovatelLTEMMPlugin); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1880 | EXPECT_EQ(kNetworkTechnologyLte, capability_->GetNetworkTechnologyString()); |
Arman Uguray | 7af0fac | 2013-03-18 17:35:35 -0700 | [diff] [blame] | 1881 | |
| 1882 | capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_GPRS; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1883 | EXPECT_EQ(kNetworkTechnologyLte, capability_->GetNetworkTechnologyString()); |
Arman Uguray | 7af0fac | 2013-03-18 17:35:35 -0700 | [diff] [blame] | 1884 | |
Ben Chan | 3dddd04 | 2014-10-19 14:08:10 -0700 | [diff] [blame] | 1885 | cellular_->set_mm_plugin(""); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1886 | EXPECT_EQ(kNetworkTechnologyGprs, capability_->GetNetworkTechnologyString()); |
Arman Uguray | 7af0fac | 2013-03-18 17:35:35 -0700 | [diff] [blame] | 1887 | } |
| 1888 | |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 1889 | TEST_F(CellularCapabilityUniversalMainTest, GetOutOfCreditsDetectionType) { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1890 | cellular_->set_model_id("");; |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 1891 | EXPECT_EQ(OutOfCreditsDetector::OOCTypeNone, |
| 1892 | capability_->GetOutOfCreditsDetectionType()); |
Thieu Le | c466ccb | 2014-06-23 15:24:56 -0700 | [diff] [blame] | 1893 | cellular_->set_mm_plugin(CellularCapabilityUniversal::kAltairLTEMMPlugin); |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 1894 | EXPECT_EQ(OutOfCreditsDetector::OOCTypeSubscriptionState, |
| 1895 | capability_->GetOutOfCreditsDetectionType()); |
Arman Uguray | d42d8ec | 2013-04-08 19:28:21 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1898 | TEST_F(CellularCapabilityUniversalMainTest, SimLockStatusToProperty) { |
| 1899 | Error error; |
| 1900 | KeyValueStore store = capability_->SimLockStatusToProperty(&error); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1901 | EXPECT_FALSE(store.GetBool(kSIMLockEnabledProperty)); |
| 1902 | EXPECT_TRUE(store.GetString(kSIMLockTypeProperty).empty()); |
| 1903 | EXPECT_EQ(0, store.GetUint(kSIMLockRetriesLeftProperty)); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1904 | |
| 1905 | capability_->sim_lock_status_.enabled = true; |
| 1906 | capability_->sim_lock_status_.retries_left = 3; |
| 1907 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN; |
| 1908 | store = capability_->SimLockStatusToProperty(&error); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1909 | EXPECT_TRUE(store.GetBool(kSIMLockEnabledProperty)); |
| 1910 | EXPECT_EQ("sim-pin", store.GetString(kSIMLockTypeProperty)); |
| 1911 | EXPECT_EQ(3, store.GetUint(kSIMLockRetriesLeftProperty)); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1912 | |
| 1913 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK; |
| 1914 | store = capability_->SimLockStatusToProperty(&error); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1915 | EXPECT_EQ("sim-puk", store.GetString(kSIMLockTypeProperty)); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1916 | |
| 1917 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN2; |
| 1918 | store = capability_->SimLockStatusToProperty(&error); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1919 | EXPECT_TRUE(store.GetString(kSIMLockTypeProperty).empty()); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1920 | |
| 1921 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK2; |
| 1922 | store = capability_->SimLockStatusToProperty(&error); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1923 | EXPECT_TRUE(store.GetString(kSIMLockTypeProperty).empty()); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | TEST_F(CellularCapabilityUniversalMainTest, OnLockRetriesChanged) { |
| 1927 | CellularCapabilityUniversal::LockRetryData data; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1928 | const uint32_t kDefaultRetries = 999; |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1929 | |
| 1930 | capability_->OnLockRetriesChanged(data); |
| 1931 | EXPECT_EQ(kDefaultRetries, capability_->sim_lock_status_.retries_left); |
| 1932 | |
| 1933 | data[MM_MODEM_LOCK_SIM_PIN] = 3; |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 1934 | data[MM_MODEM_LOCK_SIM_PUK] = 10; |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1935 | capability_->OnLockRetriesChanged(data); |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 1936 | EXPECT_EQ(3, capability_->sim_lock_status_.retries_left); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1937 | |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 1938 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK; |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1939 | capability_->OnLockRetriesChanged(data); |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 1940 | EXPECT_EQ(10, capability_->sim_lock_status_.retries_left); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1941 | |
| 1942 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN; |
| 1943 | capability_->OnLockRetriesChanged(data); |
| 1944 | EXPECT_EQ(3, capability_->sim_lock_status_.retries_left); |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 1945 | |
| 1946 | data.clear(); |
| 1947 | capability_->OnLockRetriesChanged(data); |
| 1948 | EXPECT_EQ(kDefaultRetries, capability_->sim_lock_status_.retries_left); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | TEST_F(CellularCapabilityUniversalMainTest, OnLockTypeChanged) { |
| 1952 | EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type); |
| 1953 | |
| 1954 | capability_->OnLockTypeChanged(MM_MODEM_LOCK_NONE); |
| 1955 | EXPECT_EQ(MM_MODEM_LOCK_NONE, capability_->sim_lock_status_.lock_type); |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 1956 | EXPECT_FALSE(capability_->sim_lock_status_.enabled); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1957 | |
| 1958 | capability_->OnLockTypeChanged(MM_MODEM_LOCK_SIM_PIN); |
| 1959 | EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type); |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 1960 | EXPECT_TRUE(capability_->sim_lock_status_.enabled); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1961 | |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 1962 | capability_->sim_lock_status_.enabled = false; |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1963 | capability_->OnLockTypeChanged(MM_MODEM_LOCK_SIM_PUK); |
| 1964 | EXPECT_EQ(MM_MODEM_LOCK_SIM_PUK, capability_->sim_lock_status_.lock_type); |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 1965 | EXPECT_TRUE(capability_->sim_lock_status_.enabled); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | TEST_F(CellularCapabilityUniversalMainTest, OnSimLockPropertiesChanged) { |
| 1969 | EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type); |
| 1970 | EXPECT_EQ(0, capability_->sim_lock_status_.retries_left); |
| 1971 | |
| 1972 | DBusPropertiesMap changed; |
| 1973 | vector<string> invalidated; |
| 1974 | |
| 1975 | capability_->OnModemPropertiesChanged(changed, invalidated); |
| 1976 | EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type); |
| 1977 | EXPECT_EQ(0, capability_->sim_lock_status_.retries_left); |
| 1978 | |
| 1979 | ::DBus::Variant variant; |
| 1980 | ::DBus::MessageIter writer = variant.writer(); |
| 1981 | |
| 1982 | // Unlock retries changed, but the SIM wasn't locked. |
| 1983 | CellularCapabilityUniversal::LockRetryData retry_data; |
| 1984 | retry_data[MM_MODEM_LOCK_SIM_PIN] = 3; |
| 1985 | writer << retry_data; |
| 1986 | changed[MM_MODEM_PROPERTY_UNLOCKRETRIES] = variant; |
| 1987 | |
| 1988 | capability_->OnModemPropertiesChanged(changed, invalidated); |
| 1989 | EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type); |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 1990 | EXPECT_EQ(3, capability_->sim_lock_status_.retries_left); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1991 | |
| 1992 | // Unlock retries changed and the SIM got locked. |
| 1993 | variant.clear(); |
| 1994 | writer = variant.writer(); |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1995 | writer << static_cast<uint32_t>(MM_MODEM_LOCK_SIM_PIN); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1996 | changed[MM_MODEM_PROPERTY_UNLOCKREQUIRED] = variant; |
| 1997 | capability_->OnModemPropertiesChanged(changed, invalidated); |
| 1998 | EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type); |
| 1999 | EXPECT_EQ(3, capability_->sim_lock_status_.retries_left); |
| 2000 | |
| 2001 | // Only unlock retries changed. |
| 2002 | changed.erase(MM_MODEM_PROPERTY_UNLOCKREQUIRED); |
| 2003 | retry_data[MM_MODEM_LOCK_SIM_PIN] = 2; |
| 2004 | variant.clear(); |
| 2005 | writer = variant.writer(); |
| 2006 | writer << retry_data; |
| 2007 | changed[MM_MODEM_PROPERTY_UNLOCKRETRIES] = variant; |
| 2008 | capability_->OnModemPropertiesChanged(changed, invalidated); |
| 2009 | EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type); |
| 2010 | EXPECT_EQ(2, capability_->sim_lock_status_.retries_left); |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 2011 | |
| 2012 | // Unlock retries changed with a value that doesn't match the current |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 2013 | // lock type. Default to whatever count is available. |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 2014 | retry_data.clear(); |
| 2015 | retry_data[MM_MODEM_LOCK_SIM_PIN2] = 2; |
| 2016 | variant.clear(); |
| 2017 | writer = variant.writer(); |
| 2018 | writer << retry_data; |
| 2019 | changed[MM_MODEM_PROPERTY_UNLOCKRETRIES] = variant; |
| 2020 | capability_->OnModemPropertiesChanged(changed, invalidated); |
| 2021 | EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type); |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 2022 | EXPECT_EQ(2, capability_->sim_lock_status_.retries_left); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 2025 | } // namespace shill |