blob: ab2dd6002202443a0e3673cdb2bcf9053385e131 [file] [log] [blame]
Arman Ugurayf4c61812013-01-10 18:58:39 -08001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
Jason Glasgowef965562012-04-10 16:12:35 -04002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Ben Chanc54afe52014-11-05 10:28:08 -08005#include "shill/cellular/cellular_capability_universal.h"
Jason Glasgowef965562012-04-10 16:12:35 -04006
Nathan Williams4b7c2a82012-04-13 15:19:47 -04007#include <string>
8#include <vector>
9
Jason Glasgowef965562012-04-10 16:12:35 -040010#include <base/bind.h>
Ben Chana0ddf462014-02-06 11:32:42 -080011#include <base/strings/string_util.h>
12#include <base/strings/stringprintf.h>
Jason Glasgowef965562012-04-10 16:12:35 -040013#include <chromeos/dbus/service_constants.h>
Ben Chan5c853ef2012-10-05 00:05:37 -070014#include <ModemManager/ModemManager.h>
Jason Glasgowef965562012-04-10 16:12:35 -040015
Ben Chanc54afe52014-11-05 10:28:08 -080016#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 Glasgowaf583282012-04-18 15:18:22 -040028#include "shill/dbus_adaptor.h"
Jason Glasgowef965562012-04-10 16:12:35 -040029#include "shill/error.h"
30#include "shill/event_dispatcher.h"
31#include "shill/mock_adaptors.h"
Jason Glasgowaf583282012-04-18 15:18:22 -040032#include "shill/mock_dbus_properties_proxy.h"
Arman Uguray1361c032013-02-11 17:53:39 -080033#include "shill/mock_event_dispatcher.h"
Arman Uguray41cc6342013-03-29 16:34:39 -070034#include "shill/mock_pending_activation_store.h"
Jason Glasgowef965562012-04-10 16:12:35 -040035#include "shill/mock_profile.h"
Peter Qiu8d6b5972014-10-28 15:33:34 -070036#include "shill/net/mock_rtnl_handler.h"
Jason Glasgowef965562012-04-10 16:12:35 -040037#include "shill/proxy_factory.h"
Ben Chanbe277dd2014-02-05 17:26:47 -080038#include "shill/testing.h"
Jason Glasgowef965562012-04-10 16:12:35 -040039
40using base::Bind;
Darin Petkova4ca3c32012-08-17 16:05:24 +020041using base::StringPrintf;
Jason Glasgowef965562012-04-10 16:12:35 -040042using base::Unretained;
43using std::string;
Ben Chanc20ed132014-10-16 12:25:03 -070044using std::unique_ptr;
Nathan Williams4b7c2a82012-04-13 15:19:47 -040045using std::vector;
mukesh agrawal83a98f42013-07-31 16:25:53 -070046using testing::AnyNumber;
Jason Glasgowef965562012-04-10 16:12:35 -040047using testing::InSequence;
Ben Chan6d0d1e72012-11-06 21:19:28 -080048using testing::Invoke;
Arman Uguray1361c032013-02-11 17:53:39 -080049using testing::InvokeWithoutArgs;
Gary Moraine285a842012-08-15 08:23:57 -070050using testing::Mock;
Jason Glasgowef965562012-04-10 16:12:35 -040051using testing::NiceMock;
52using testing::Return;
Thieu Le247416e2014-02-25 18:19:53 -080053using testing::ReturnRef;
Jason Glasgowcd0349c2012-05-03 23:32:15 -040054using testing::SaveArg;
Jason Glasgowef965562012-04-10 16:12:35 -040055using testing::_;
56
57namespace shill {
58
Jason Glasgow14521872012-05-07 19:12:15 -040059MATCHER_P(HasApn, expected_apn, "") {
60 string apn;
61 return (DBusProperties::GetString(arg,
62 CellularCapabilityUniversal::kConnectApn,
63 &apn) &&
64 apn == expected_apn);
65}
Jason Glasgowef965562012-04-10 16:12:35 -040066
Arman Uguray1361c032013-02-11 17:53:39 -080067class CellularCapabilityUniversalTest : public testing::TestWithParam<string> {
Jason Glasgowef965562012-04-10 16:12:35 -040068 public:
Paul Stewart2f6c7892015-06-16 13:13:10 -070069 explicit CellularCapabilityUniversalTest(EventDispatcher* dispatcher)
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070070 : dispatcher_(dispatcher),
Ben Chanea18c6c2014-09-30 13:08:26 -070071 modem_info_(nullptr, dispatcher, nullptr, nullptr, nullptr),
Ben Chan3ecdf822012-08-06 12:29:23 -070072 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 Chanea18c6c2014-09-30 13:08:26 -070079 capability_(nullptr),
80 device_adaptor_(nullptr),
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070081 cellular_(new Cellular(&modem_info_,
Jason Glasgowef965562012-04-10 16:12:35 -040082 "",
Prathmesh Prabhu401a5b92014-04-29 17:37:55 -070083 "00:01:02:03:04:05",
Jason Glasgowef965562012-04-10 16:12:35 -040084 0,
85 Cellular::kTypeUniversal,
86 "",
87 "",
Jason Glasgowa585fc32012-06-06 11:04:09 -040088 "",
Ben Chan3ecdf822012-08-06 12:29:23 -070089 &proxy_factory_)),
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070090 service_(new MockCellularService(&modem_info_, cellular_)),
Ben Chanea18c6c2014-09-30 13:08:26 -070091 mock_home_provider_info_(nullptr),
92 mock_serving_operator_info_(nullptr) {
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070093 modem_info_.metrics()->RegisterDevice(cellular_->interface_index(),
94 Technology::kCellular);
Thieu Lece4483e2013-01-23 15:12:03 -080095 }
Jason Glasgowef965562012-04-10 16:12:35 -040096
97 virtual ~CellularCapabilityUniversalTest() {
Ben Chanea18c6c2014-09-30 13:08:26 -070098 cellular_->service_ = nullptr;
99 capability_ = nullptr;
100 device_adaptor_ = nullptr;
Jason Glasgowef965562012-04-10 16:12:35 -0400101 }
102
103 virtual void SetUp() {
Paul Stewart2f6c7892015-06-16 13:13:10 -0700104 capability_ = dynamic_cast<CellularCapabilityUniversal*>(
Jason Glasgowef965562012-04-10 16:12:35 -0400105 cellular_->capability_.get());
Jason Glasgowef965562012-04-10 16:12:35 -0400106 device_adaptor_ =
Paul Stewart2f6c7892015-06-16 13:13:10 -0700107 dynamic_cast<DeviceMockAdaptor*>(cellular_->adaptor());
Jason Glasgow14521872012-05-07 19:12:15 -0400108 cellular_->service_ = service_;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700109
110 // kStateUnknown leads to minimal extra work in maintaining
111 // activation state.
Arman Uguray41cc6342013-03-29 16:34:39 -0700112 ON_CALL(*modem_info_.mock_pending_activation_store(),
113 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
114 .WillByDefault(Return(PendingActivationStore::kStateUnknown));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700115
116 SetMockMobileOperatorInfoObjects();
Jason Glasgowef965562012-04-10 16:12:35 -0400117 }
118
119 virtual void TearDown() {
Ben Chanea18c6c2014-09-30 13:08:26 -0700120 capability_->proxy_factory_ = nullptr;
Jason Glasgowef965562012-04-10 16:12:35 -0400121 }
122
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700123 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 Prabhu27526f12013-03-25 19:42:18 -0700130
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700131 // 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 Piusec77f592014-10-29 15:07:38 -0700136 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 Prabhu6e0a8ef2014-05-05 22:30:07 -0700142 cellular_->service_ = service;
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400143 }
144
Arman Ugurayc5391232013-09-23 21:30:46 -0700145 void ClearService() {
Ben Chanea18c6c2014-09-30 13:08:26 -0700146 cellular_->service_ = nullptr;
Arman Ugurayc5391232013-09-23 21:30:46 -0700147 }
148
Ben Chan9f3dcf82013-09-25 18:04:58 -0700149 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 Stewart2f6c7892015-06-16 13:13:10 -0700181 void InvokeEnable(bool enable, Error* error,
182 const ResultCallback& callback, int timeout) {
Jason Glasgowef965562012-04-10 16:12:35 -0400183 callback.Run(Error());
184 }
Paul Stewart2f6c7892015-06-16 13:13:10 -0700185 void InvokeEnableFail(bool enable, Error* error,
186 const ResultCallback& callback, int timeout) {
Jason Glasgowef965562012-04-10 16:12:35 -0400187 callback.Run(Error(Error::kOperationFailed));
188 }
Paul Stewart2f6c7892015-06-16 13:13:10 -0700189 void InvokeEnableInWrongState(bool enable, Error* error,
190 const ResultCallback& callback, int timeout) {
Ben Chan151d4472013-09-06 13:29:46 -0700191 callback.Run(Error(Error::kWrongState));
192 }
Paul Stewart2f6c7892015-06-16 13:13:10 -0700193 void InvokeRegister(const string& operator_id, Error* error,
194 const ResultCallback& callback, int timeout) {
Jason Glasgowaf583282012-04-18 15:18:22 -0400195 callback.Run(Error());
196 }
Paul Stewart2f6c7892015-06-16 13:13:10 -0700197 void InvokeSetPowerState(const uint32_t& power_state,
198 Error* error,
199 const ResultCallback& callback,
Ben Chan9f3dcf82013-09-25 18:04:58 -0700200 int timeout) {
201 callback.Run(Error());
202 }
Gary Morainceba6aa2012-05-03 10:28:26 -0700203 void Set3gppProxy() {
204 capability_->modem_3gpp_proxy_.reset(modem_3gpp_proxy_.release());
205 }
206
Jason Glasgow14521872012-05-07 19:12:15 -0400207 void SetSimpleProxy() {
208 capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release());
209 }
210
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700211 void SetMockMobileOperatorInfoObjects() {
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700212 CHECK(!mock_home_provider_info_);
213 CHECK(!mock_serving_operator_info_);
Miao-chen Chou70190b32014-05-14 18:24:30 -0700214 mock_home_provider_info_ =
215 new MockMobileOperatorInfo(dispatcher_, "HomeProvider");
216 mock_serving_operator_info_ =
217 new MockMobileOperatorInfo(dispatcher_, "ServingOperator");
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700218 cellular_->set_home_provider_info(mock_home_provider_info_);
219 cellular_->set_serving_operator_info(mock_serving_operator_info_);
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700220 }
221
Thieu Le3d275392012-07-20 15:32:58 -0700222 void ReleaseCapabilityProxies() {
223 capability_->ReleaseProxies();
224 }
225
Ben Chan7fab8972014-08-10 17:14:46 -0700226 void SetRegistrationDroppedUpdateTimeout(int64_t timeout_milliseconds) {
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700227 capability_->registration_dropped_update_timeout_milliseconds_ =
228 timeout_milliseconds;
229 }
230
Paul Stewart2f6c7892015-06-16 13:13:10 -0700231 MOCK_METHOD1(TestCallback, void(const Error& error));
Jason Glasgowef965562012-04-10 16:12:35 -0400232
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700233 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 Glasgowef965562012-04-10 16:12:35 -0400241 protected:
Arman Uguray6e5639f2012-11-15 20:30:19 -0800242 static const char kActiveBearerPathPrefix[];
Jason Glasgowef965562012-04-10 16:12:35 -0400243 static const char kImei[];
Arman Uguray6e5639f2012-11-15 20:30:19 -0800244 static const char kInactiveBearerPathPrefix[];
Jason Glasgowaf583282012-04-18 15:18:22 -0400245 static const char kSimPath[];
Ben Chan7fab8972014-08-10 17:14:46 -0700246 static const uint32_t kAccessTechnologies;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700247 static const char kTestMobileProviderDBPath[];
Jason Glasgowef965562012-04-10 16:12:35 -0400248
249 class TestProxyFactory : public ProxyFactory {
250 public:
Paul Stewart2f6c7892015-06-16 13:13:10 -0700251 explicit TestProxyFactory(CellularCapabilityUniversalTest* test) :
mukesh agrawal9da07772013-05-15 14:15:17 -0700252 test_(test) {
Ben Chan5db19692013-07-09 23:07:03 -0700253 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 Glasgowef965562012-04-10 16:12:35 -0400257
Ben Chan5db19692013-07-09 23:07:03 -0700258 DBusPropertiesMap ip4config;
Ben Chan539ab022014-02-03 16:34:57 -0800259 ip4config["method"].writer().append_uint32(MM_BEARER_IP_METHOD_DHCP);
Ben Chan5db19692013-07-09 23:07:03 -0700260 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 Uguray6e5639f2012-11-15 20:30:19 -0800266 }
267
Paul Stewart2f6c7892015-06-16 13:13:10 -0700268 DBusPropertiesMap* mutable_active_bearer_properties() {
mukesh agrawal83a98f42013-07-31 16:25:53 -0700269 return &active_bearer_properties_;
270 }
271
Paul Stewart2f6c7892015-06-16 13:13:10 -0700272 DBusPropertiesMap* mutable_inactive_bearer_properties() {
mukesh agrawal83a98f42013-07-31 16:25:53 -0700273 return &inactive_bearer_properties_;
274 }
275
Paul Stewart2f6c7892015-06-16 13:13:10 -0700276 virtual mm1::ModemModem3gppProxyInterface* CreateMM1ModemModem3gppProxy(
277 const std::string& /*path*/,
278 const std::string& /*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400279 return test_->modem_3gpp_proxy_.release();
280 }
281
Paul Stewart2f6c7892015-06-16 13:13:10 -0700282 virtual mm1::ModemModemCdmaProxyInterface* CreateMM1ModemModemCdmaProxy(
283 const std::string& /*path*/,
284 const std::string& /*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400285 return test_->modem_cdma_proxy_.release();
286 }
287
Paul Stewart2f6c7892015-06-16 13:13:10 -0700288 virtual mm1::ModemProxyInterface* CreateMM1ModemProxy(
289 const std::string& /*path*/,
290 const std::string& /*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400291 return test_->modem_proxy_.release();
292 }
293
Paul Stewart2f6c7892015-06-16 13:13:10 -0700294 virtual mm1::ModemSimpleProxyInterface* CreateMM1ModemSimpleProxy(
295 const std::string& /*path*/,
296 const std::string& /*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400297 return test_->modem_simple_proxy_.release();
298 }
299
Paul Stewart2f6c7892015-06-16 13:13:10 -0700300 virtual mm1::SimProxyInterface* CreateSimProxy(
301 const std::string& /*path*/,
302 const std::string& /*service*/) {
303 mm1::MockSimProxy* sim_proxy = test_->sim_proxy_.release();
Arman Uguray6552f8c2013-02-12 15:33:18 -0800304 test_->sim_proxy_.reset(new mm1::MockSimProxy());
305 return sim_proxy;
Jason Glasgowef965562012-04-10 16:12:35 -0400306 }
mukesh agrawal83a98f42013-07-31 16:25:53 -0700307
Paul Stewart2f6c7892015-06-16 13:13:10 -0700308 virtual DBusPropertiesProxyInterface* CreateDBusPropertiesProxy(
309 const std::string& path,
310 const std::string& /*service*/) {
311 MockDBusPropertiesProxy* properties_proxy =
Arman Uguray6552f8c2013-02-12 15:33:18 -0800312 test_->properties_proxy_.release();
Ben Chan5db19692013-07-09 23:07:03 -0700313 if (path.find(kActiveBearerPathPrefix) != std::string::npos) {
mukesh agrawal83a98f42013-07-31 16:25:53 -0700314 EXPECT_CALL(*properties_proxy, GetAll(MM_DBUS_INTERFACE_BEARER))
315 .Times(AnyNumber())
316 .WillRepeatedly(Return(active_bearer_properties_));
Ben Chan5db19692013-07-09 23:07:03 -0700317 } else {
mukesh agrawal83a98f42013-07-31 16:25:53 -0700318 EXPECT_CALL(*properties_proxy, GetAll(MM_DBUS_INTERFACE_BEARER))
319 .Times(AnyNumber())
320 .WillRepeatedly(Return(inactive_bearer_properties_));
Ben Chan5db19692013-07-09 23:07:03 -0700321 }
Arman Uguray6552f8c2013-02-12 15:33:18 -0800322 test_->properties_proxy_.reset(new MockDBusPropertiesProxy());
323 return properties_proxy;
Jason Glasgowaf583282012-04-18 15:18:22 -0400324 }
Jason Glasgowef965562012-04-10 16:12:35 -0400325
326 private:
Paul Stewart2f6c7892015-06-16 13:13:10 -0700327 CellularCapabilityUniversalTest* test_;
Ben Chan5db19692013-07-09 23:07:03 -0700328 DBusPropertiesMap active_bearer_properties_;
329 DBusPropertiesMap inactive_bearer_properties_;
Jason Glasgowef965562012-04-10 16:12:35 -0400330 };
331
Paul Stewart2f6c7892015-06-16 13:13:10 -0700332 EventDispatcher* dispatcher_;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700333 MockModemInfo modem_info_;
Ben Chanc20ed132014-10-16 12:25:03 -0700334 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 Glasgowef965562012-04-10 16:12:35 -0400340 TestProxyFactory proxy_factory_;
Paul Stewart2f6c7892015-06-16 13:13:10 -0700341 CellularCapabilityUniversal* capability_; // Owned by |cellular_|.
342 DeviceMockAdaptor* device_adaptor_; // Owned by |cellular_|.
Ben Chan3ecdf822012-08-06 12:29:23 -0700343 CellularRefPtr cellular_;
Paul Stewart2f6c7892015-06-16 13:13:10 -0700344 MockCellularService* service_; // owned by cellular_
Jason Glasgow14521872012-05-07 19:12:15 -0400345 DBusPathCallback connect_callback_; // saved for testing connect operations
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700346
347 // Set when required and passed to |cellular_|. Owned by |cellular_|.
Paul Stewart2f6c7892015-06-16 13:13:10 -0700348 MockMobileOperatorInfo* mock_home_provider_info_;
349 MockMobileOperatorInfo* mock_serving_operator_info_;
Jason Glasgowef965562012-04-10 16:12:35 -0400350};
351
Arman Uguray1361c032013-02-11 17:53:39 -0800352// Most of our tests involve using a real EventDispatcher object.
353class 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.
365class CellularCapabilityUniversalTimerTest
366 : public CellularCapabilityUniversalTest {
367 public:
368 CellularCapabilityUniversalTimerTest()
369 : CellularCapabilityUniversalTest(&mock_dispatcher_) {}
370
371 protected:
372 ::testing::StrictMock<MockEventDispatcher> mock_dispatcher_;
373};
374
Arman Uguray6e5639f2012-11-15 20:30:19 -0800375const char CellularCapabilityUniversalTest::kActiveBearerPathPrefix[] =
376 "/bearer/active";
Jason Glasgowef965562012-04-10 16:12:35 -0400377const char CellularCapabilityUniversalTest::kImei[] = "999911110000";
Arman Uguray6e5639f2012-11-15 20:30:19 -0800378const char CellularCapabilityUniversalTest::kInactiveBearerPathPrefix[] =
379 "/bearer/inactive";
Jason Glasgowaf583282012-04-18 15:18:22 -0400380const char CellularCapabilityUniversalTest::kSimPath[] = "/foo/sim";
Ben Chan7fab8972014-08-10 17:14:46 -0700381const uint32_t CellularCapabilityUniversalTest::kAccessTechnologies =
Jason Glasgowaf583282012-04-18 15:18:22 -0400382 MM_MODEM_ACCESS_TECHNOLOGY_LTE |
383 MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700384const char CellularCapabilityUniversalTest::kTestMobileProviderDBPath[] =
385 "provider_db_unittest.bfd";
Jason Glasgowef965562012-04-10 16:12:35 -0400386
Arman Uguray1361c032013-02-11 17:53:39 -0800387TEST_F(CellularCapabilityUniversalMainTest, StartModem) {
Ben Chan9f3dcf82013-09-25 18:04:58 -0700388 ExpectModemAndModem3gppProperties();
Jason Glasgowaf583282012-04-18 15:18:22 -0400389
390 EXPECT_CALL(*modem_proxy_,
391 Enable(true, _, _, CellularCapability::kTimeoutEnable))
Ben Chan151d4472013-09-06 13:29:46 -0700392 .WillOnce(Invoke(
393 this, &CellularCapabilityUniversalTest::InvokeEnable));
Jason Glasgowef965562012-04-10 16:12:35 -0400394
Ben Chan151d4472013-09-06 13:29:46 -0700395 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 Prabhu9f06c872013-11-21 14:08:23 -0800402 EXPECT_EQ(kImei, cellular_->imei());
Ben Chan151d4472013-09-06 13:29:46 -0700403 EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_);
404}
405
406TEST_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
423TEST_F(CellularCapabilityUniversalMainTest, StartModemInWrongState) {
Ben Chan9f3dcf82013-09-25 18:04:58 -0700424 ExpectModemAndModem3gppProperties();
Ben Chan151d4472013-09-06 13:29:46 -0700425
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 Moraine285a842012-08-15 08:23:57 -0700432
Jason Glasgowef965562012-04-10 16:12:35 -0400433 Error error;
Gary Moraine285a842012-08-15 08:23:57 -0700434 EXPECT_CALL(*this, TestCallback(_)).Times(0);
Jason Glasgowef965562012-04-10 16:12:35 -0400435 ResultCallback callback =
436 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
437 capability_->StartModem(&error, callback);
Ben Chan151d4472013-09-06 13:29:46 -0700438 EXPECT_TRUE(error.IsOngoing());
Gary Moraine285a842012-08-15 08:23:57 -0700439
Arman Uguray6e5639f2012-11-15 20:30:19 -0800440 // Verify that the modem has not been enabled.
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800441 EXPECT_TRUE(cellular_->imei().empty());
Gary Moraine285a842012-08-15 08:23:57 -0700442 EXPECT_EQ(0, capability_->access_technologies_);
443 Mock::VerifyAndClearExpectations(this);
444
Ben Chan151d4472013-09-06 13:29:46 -0700445 // Change the state to kModemStateEnabling and verify that it still has not
446 // been enabled.
Arman Uguray1ee93912013-09-24 21:24:10 -0700447 capability_->OnModemStateChanged(Cellular::kModemStateEnabling);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800448 EXPECT_TRUE(cellular_->imei().empty());
Ben Chan151d4472013-09-06 13:29:46 -0700449 EXPECT_EQ(0, capability_->access_technologies_);
450 Mock::VerifyAndClearExpectations(this);
451
Gary Moraine285a842012-08-15 08:23:57 -0700452 // Change the state to kModemStateDisabling and verify that it still has not
Arman Uguray6e5639f2012-11-15 20:30:19 -0800453 // been enabled.
Gary Moraine285a842012-08-15 08:23:57 -0700454 EXPECT_CALL(*this, TestCallback(_)).Times(0);
Arman Uguray1ee93912013-09-24 21:24:10 -0700455 capability_->OnModemStateChanged(Cellular::kModemStateDisabling);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800456 EXPECT_TRUE(cellular_->imei().empty());
Gary Moraine285a842012-08-15 08:23:57 -0700457 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 Uguray1ee93912013-09-24 21:24:10 -0700462 capability_->OnModemStateChanged(Cellular::kModemStateDisabled);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800463 EXPECT_EQ(kImei, cellular_->imei());
Jason Glasgowaf583282012-04-18 15:18:22 -0400464 EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_);
Jason Glasgowef965562012-04-10 16:12:35 -0400465}
466
Ben Chan151d4472013-09-06 13:29:46 -0700467TEST_F(CellularCapabilityUniversalMainTest,
468 StartModemWithDeferredEnableFailure) {
Jason Glasgowef965562012-04-10 16:12:35 -0400469 EXPECT_CALL(*modem_proxy_,
470 Enable(true, _, _, CellularCapability::kTimeoutEnable))
Ben Chan151d4472013-09-06 13:29:46 -0700471 .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 Glasgowef965562012-04-10 16:12:35 -0400477
478 Error error;
Ben Chan151d4472013-09-06 13:29:46 -0700479 EXPECT_CALL(*this, TestCallback(_)).Times(0);
Ben Chanfd1144d2013-09-06 09:10:16 -0700480 ResultCallback callback =
481 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
Ben Chanfd1144d2013-09-06 09:10:16 -0700482 capability_->StartModem(&error, callback);
483 EXPECT_TRUE(error.IsOngoing());
Ben Chan151d4472013-09-06 13:29:46 -0700484 Mock::VerifyAndClearExpectations(this);
Ben Chanfd1144d2013-09-06 09:10:16 -0700485
Ben Chan151d4472013-09-06 13:29:46 -0700486 // 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 Uguray1ee93912013-09-24 21:24:10 -0700490 capability_->OnModemStateChanged(Cellular::kModemStateDisabled);
Thieu Leb9c05e02013-03-04 14:09:32 -0800491}
492
Arman Uguray1361c032013-02-11 17:53:39 -0800493TEST_F(CellularCapabilityUniversalMainTest, StopModem) {
Jason Glasgow02401cc2012-05-16 10:35:37 -0400494 // Save pointers to proxies before they are lost by the call to InitProxies
Paul Stewart2f6c7892015-06-16 13:13:10 -0700495 mm1::MockModemProxy* modem_proxy = modem_proxy_.get();
Jason Glasgow02401cc2012-05-16 10:35:37 -0400496 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 Ugurayee464d32013-02-13 17:14:36 -0800511 ResultCallback set_power_state_callback;
Thieu Le2cac2942013-03-05 18:41:08 -0800512 EXPECT_CALL(
513 *modem_proxy,
514 SetPowerState(
515 MM_MODEM_POWER_STATE_LOW, _, _,
516 CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds))
Arman Ugurayee464d32013-02-13 17:14:36 -0800517 .WillOnce(SaveArg<2>(&set_power_state_callback));
Jason Glasgow02401cc2012-05-16 10:35:37 -0400518 disable_callback.Run(Error(Error::kSuccess));
Arman Ugurayee464d32013-02-13 17:14:36 -0800519
520 EXPECT_CALL(*this, TestCallback(IsSuccess()));
521 set_power_state_callback.Run(Error(Error::kSuccess));
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700522 Mock::VerifyAndClearExpectations(this);
Arman Ugurayee464d32013-02-13 17:14:36 -0800523
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 Glasgow02401cc2012-05-16 10:35:37 -0400528}
529
Thieu Lec466ccb2014-06-23 15:24:56 -0700530TEST_F(CellularCapabilityUniversalMainTest, StopModemAltair) {
Thieu Le28492142014-04-08 16:41:13 -0700531 // Save pointers to proxies before they are lost by the call to InitProxies
Paul Stewart2f6c7892015-06-16 13:13:10 -0700532 mm1::MockModemProxy* modem_proxy = modem_proxy_.get();
Thieu Le28492142014-04-08 16:41:13 -0700533 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 Lec466ccb2014-06-23 15:24:56 -0700542 cellular_->set_mm_plugin(CellularCapabilityUniversal::kAltairLTEMMPlugin);
Thieu Le28492142014-04-08 16:41:13 -0700543
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 Leb0074e82014-04-15 14:28:21 -0700576TEST_F(CellularCapabilityUniversalMainTest,
Thieu Lec466ccb2014-06-23 15:24:56 -0700577 StopModemAltairDeleteBearerFailure) {
Thieu Leb0074e82014-04-15 14:28:21 -0700578 // Save pointers to proxies before they are lost by the call to InitProxies
Paul Stewart2f6c7892015-06-16 13:13:10 -0700579 mm1::MockModemProxy* modem_proxy = modem_proxy_.get();
Thieu Leb0074e82014-04-15 14:28:21 -0700580 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 Lec466ccb2014-06-23 15:24:56 -0700589 cellular_->set_mm_plugin(CellularCapabilityUniversal::kAltairLTEMMPlugin);
Thieu Leb0074e82014-04-15 14:28:21 -0700590
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 Lec466ccb2014-06-23 15:24:56 -0700623TEST_F(CellularCapabilityUniversalMainTest, StopModemAltairNotConnected) {
Thieu Leb0074e82014-04-15 14:28:21 -0700624 // Save pointers to proxies before they are lost by the call to InitProxies
Paul Stewart2f6c7892015-06-16 13:13:10 -0700625 mm1::MockModemProxy* modem_proxy = modem_proxy_.get();
Thieu Leb0074e82014-04-15 14:28:21 -0700626 EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
627 capability_->InitProxies();
Ben Chanea18c6c2014-09-30 13:08:26 -0700628 capability_->set_active_bearer(nullptr);
Thieu Lec466ccb2014-06-23 15:24:56 -0700629 cellular_->set_mm_plugin(CellularCapabilityUniversal::kAltairLTEMMPlugin);
Thieu Leb0074e82014-04-15 14:28:21 -0700630
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 Chan9f3dcf82013-09-25 18:04:58 -0700662TEST_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
714TEST_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 Uguray1361c032013-02-11 17:53:39 -0800762TEST_F(CellularCapabilityUniversalMainTest, DisconnectModemNoBearer) {
Thieu Le5d6864a2012-07-20 11:43:51 -0700763 Error error;
764 ResultCallback disconnect_callback;
Thieu Le3d275392012-07-20 15:32:58 -0700765 EXPECT_CALL(*modem_simple_proxy_,
Thieu Le049adb52012-11-12 17:14:51 -0800766 Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect))
Thieu Le5d6864a2012-07-20 11:43:51 -0700767 .Times(0);
768 capability_->Disconnect(&error, disconnect_callback);
769}
770
Arman Uguray1361c032013-02-11 17:53:39 -0800771TEST_F(CellularCapabilityUniversalMainTest, DisconnectNoProxy) {
Thieu Le3d275392012-07-20 15:32:58 -0700772 Error error;
773 ResultCallback disconnect_callback;
Thieu Le3d275392012-07-20 15:32:58 -0700774 EXPECT_CALL(*modem_simple_proxy_,
Thieu Le049adb52012-11-12 17:14:51 -0800775 Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect))
Thieu Le3d275392012-07-20 15:32:58 -0700776 .Times(0);
777 ReleaseCapabilityProxies();
778 capability_->Disconnect(&error, disconnect_callback);
779}
780
Arman Uguray1361c032013-02-11 17:53:39 -0800781TEST_F(CellularCapabilityUniversalMainTest, SimLockStatusChanged) {
Arman Ugurayab9364e2012-12-19 20:45:25 -0800782 // 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 Uguray41cc6342013-03-29 16:34:39 -0700798 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
799 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700800 .Times(1);
Arman Ugurayab9364e2012-12-19 20:45:25 -0800801
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800802 EXPECT_FALSE(cellular_->sim_present());
Ben Chanea18c6c2014-09-30 13:08:26 -0700803 EXPECT_EQ(nullptr, capability_->sim_proxy_);;
Arman Ugurayab9364e2012-12-19 20:45:25 -0800804
805 capability_->OnSimPathChanged(kSimPath);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800806 EXPECT_TRUE(cellular_->sim_present());
Ben Chanea18c6c2014-09-30 13:08:26 -0700807 EXPECT_NE(nullptr, capability_->sim_proxy_);;
Arman Ugurayab9364e2012-12-19 20:45:25 -0800808 EXPECT_EQ(kSimPath, capability_->sim_path_);
809
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800810 cellular_->set_imsi("");
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -0800811 cellular_->set_sim_identifier("");
Arman Ugurayab9364e2012-12-19 20:45:25 -0800812 capability_->spn_ = "";
813
814 // SIM is locked.
Arman Ugurayc7e63af2013-06-13 17:07:32 -0700815 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN;
Arman Ugurayab9364e2012-12-19 20:45:25 -0800816 capability_->OnSimLockStatusChanged();
Arman Uguray41cc6342013-03-29 16:34:39 -0700817 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayab9364e2012-12-19 20:45:25 -0800818
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800819 EXPECT_EQ("", cellular_->imsi());
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -0800820 EXPECT_EQ("", cellular_->sim_identifier());
Arman Ugurayab9364e2012-12-19 20:45:25 -0800821 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 Uguray41cc6342013-03-29 16:34:39 -0700827 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
828 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700829 .Times(1);
Arman Ugurayab9364e2012-12-19 20:45:25 -0800830
Arman Ugurayc7e63af2013-06-13 17:07:32 -0700831 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_NONE;
Arman Ugurayab9364e2012-12-19 20:45:25 -0800832 capability_->OnSimLockStatusChanged();
Arman Uguray41cc6342013-03-29 16:34:39 -0700833 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayab9364e2012-12-19 20:45:25 -0800834
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800835 EXPECT_EQ(kImsi, cellular_->imsi());
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -0800836 EXPECT_EQ(kSimIdentifier, cellular_->sim_identifier());
Arman Ugurayab9364e2012-12-19 20:45:25 -0800837 EXPECT_EQ(kOperatorName, capability_->spn_);
Ben Chand3b18742013-07-12 00:30:25 -0700838
839 // SIM is missing and SIM path is "/".
840 capability_->OnSimPathChanged(CellularCapabilityUniversal::kRootPath);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800841 EXPECT_FALSE(cellular_->sim_present());
Ben Chanea18c6c2014-09-30 13:08:26 -0700842 EXPECT_EQ(nullptr, capability_->sim_proxy_);;
Ben Chand3b18742013-07-12 00:30:25 -0700843 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 Prabhu9f06c872013-11-21 14:08:23 -0800850 EXPECT_EQ("", cellular_->imsi());
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -0800851 EXPECT_EQ("", cellular_->sim_identifier());
Ben Chand3b18742013-07-12 00:30:25 -0700852 EXPECT_EQ("", capability_->spn_);
853
854 // SIM is missing and SIM path is empty.
855 capability_->OnSimPathChanged("");
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800856 EXPECT_FALSE(cellular_->sim_present());
Ben Chanea18c6c2014-09-30 13:08:26 -0700857 EXPECT_EQ(nullptr, capability_->sim_proxy_);;
Ben Chand3b18742013-07-12 00:30:25 -0700858 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 Prabhu9f06c872013-11-21 14:08:23 -0800865 EXPECT_EQ("", cellular_->imsi());
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -0800866 EXPECT_EQ("", cellular_->sim_identifier());
Ben Chand3b18742013-07-12 00:30:25 -0700867 EXPECT_EQ("", capability_->spn_);
Arman Ugurayab9364e2012-12-19 20:45:25 -0800868}
869
Arman Uguray1361c032013-02-11 17:53:39 -0800870TEST_F(CellularCapabilityUniversalMainTest, PropertiesChanged) {
Jason Glasgowaf583282012-04-18 15:18:22 -0400871 // 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 Glasgowaf583282012-04-18 15:18:22 -0400888 EXPECT_CALL(*properties_proxy_,
889 GetAll(MM_DBUS_INTERFACE_SIM))
890 .WillOnce(Return(sim_properties));
891
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800892 EXPECT_EQ("", cellular_->imei());
Jason Glasgowaf583282012-04-18 15:18:22 -0400893 EXPECT_EQ(MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN,
894 capability_->access_technologies_);
895 EXPECT_FALSE(capability_->sim_proxy_.get());
Jason Glasgowbad114b2012-05-21 15:24:16 -0400896 EXPECT_CALL(*device_adaptor_, EmitStringChanged(
Ben Chan7ea768e2013-09-20 15:08:40 -0700897 kTechnologyFamilyProperty, kTechnologyFamilyGsm));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800898 EXPECT_CALL(*device_adaptor_, EmitStringChanged(kImeiProperty, kImei));
Jason Glasgowaf583282012-04-18 15:18:22 -0400899 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 Prabhu9f06c872013-11-21 14:08:23 -0800909 EXPECT_EQ("", cellular_->imei());
Jason Glasgowaf583282012-04-18 15:18:22 -0400910
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 Prabhu9f06c872013-11-21 14:08:23 -0800916 EXPECT_EQ(kImei, cellular_->imei());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700917 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowbad114b2012-05-21 15:24:16 -0400918
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 Chan7ea768e2013-09-20 15:08:40 -0700924 kTechnologyFamilyProperty, kTechnologyFamilyCdma)).
Jason Glasgowbad114b2012-05-21 15:24:16 -0400925 Times(1);
926 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
927 modem_properties,
928 vector<string>());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700929 Mock::VerifyAndClearExpectations(device_adaptor_);
930
Jason Glasgowbad114b2012-05-21 15:24:16 -0400931 // 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 Chan7ea768e2013-09-20 15:08:40 -0700936 kTechnologyFamilyProperty, kTechnologyFamilyGsm)).
Jason Glasgowbad114b2012-05-21 15:24:16 -0400937 Times(1);
938 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
939 modem_properties,
940 vector<string>());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700941 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowbad114b2012-05-21 15:24:16 -0400942
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 Glasgowaf583282012-04-18 15:18:22 -0400952}
953
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700954TEST_F(CellularCapabilityUniversalMainTest, UpdateRegistrationState) {
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700955 capability_->InitProxies();
956
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700957 CreateService();
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800958 cellular_->set_imsi("310240123456789");
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700959 cellular_->set_modem_state(Cellular::kModemStateConnected);
960 SetRegistrationDroppedUpdateTimeout(0);
961
Paul Stewart2f6c7892015-06-16 13:13:10 -0700962 const Stringmap& home_provider_map = cellular_->home_provider();
Roshan Piusec77f592014-10-29 15:07:38 -0700963 ASSERT_NE(home_provider_map.end(), home_provider_map.find(kOperatorNameKey));
964 string home_provider = home_provider_map.find(kOperatorNameKey)->second;
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700965 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 Prabhu08757aa2013-05-15 17:17:33 -07001012 EXPECT_CALL(*(modem_info_.mock_metrics()),
1013 Notify3GPPRegistrationDelayedDropPosted());
1014 EXPECT_CALL(*(modem_info_.mock_metrics()),
1015 Notify3GPPRegistrationDelayedDropCanceled());
1016
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -07001017 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 Prabhu08757aa2013-05-15 17:17:33 -07001038 Mock::VerifyAndClearExpectations(modem_info_.mock_metrics());
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -07001039
1040 // Home --> Searching --> wait till dispatch should see Searching
Prathmesh Prabhu08757aa2013-05-15 17:17:33 -07001041 EXPECT_CALL(*(modem_info_.mock_metrics()),
1042 Notify3GPPRegistrationDelayedDropPosted());
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -07001043 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 Prabhu08757aa2013-05-15 17:17:33 -07001058 Mock::VerifyAndClearExpectations(modem_info_.mock_metrics());
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -07001059
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 Prabhu08757aa2013-05-15 17:17:33 -07001063 EXPECT_CALL(*(modem_info_.mock_metrics()),
1064 Notify3GPPRegistrationDelayedDropPosted());
1065
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -07001066 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 Prabhu8f6479f2013-05-15 12:56:13 -07001086}
1087
Ben Chan31ce5642013-11-14 13:37:40 -08001088TEST_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 Prabhu8f6479f2013-05-15 12:56:13 -07001108TEST_F(CellularCapabilityUniversalMainTest,
1109 UpdateRegistrationStateModemNotConnected) {
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -07001110 capability_->InitProxies();
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -07001111 CreateService();
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -07001112
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001113 cellular_->set_imsi("310240123456789");
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -07001114 cellular_->set_modem_state(Cellular::kModemStateRegistered);
1115 SetRegistrationDroppedUpdateTimeout(0);
1116
Paul Stewart2f6c7892015-06-16 13:13:10 -07001117 const Stringmap& home_provider_map = cellular_->home_provider();
Roshan Piusec77f592014-10-29 15:07:38 -07001118 ASSERT_NE(home_provider_map.end(), home_provider_map.find(kOperatorNameKey));
1119 string home_provider = home_provider_map.find(kOperatorNameKey)->second;
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -07001120 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 Uguray6552f8c2013-02-12 15:33:18 -08001137TEST_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 Chand7592522013-02-13 16:02:01 -08001152TEST_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 Uguray1361c032013-02-11 17:53:39 -08001162TEST_F(CellularCapabilityUniversalMainTest, SimPathChanged) {
Ben Chanbd3aee82012-10-16 23:52:04 -07001163 // 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 Uguray41cc6342013-03-29 16:34:39 -07001179 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1180 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -07001181 .Times(1);
Ben Chanbd3aee82012-10-16 23:52:04 -07001182
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001183 EXPECT_FALSE(cellular_->sim_present());
Ben Chanea18c6c2014-09-30 13:08:26 -07001184 EXPECT_EQ(nullptr, capability_->sim_proxy_);;
Ben Chanbd3aee82012-10-16 23:52:04 -07001185 EXPECT_EQ("", capability_->sim_path_);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001186 EXPECT_EQ("", cellular_->imsi());
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001187 EXPECT_EQ("", cellular_->sim_identifier());
Ben Chanbd3aee82012-10-16 23:52:04 -07001188 EXPECT_EQ("", capability_->spn_);
1189
1190 capability_->OnSimPathChanged(kSimPath);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001191 EXPECT_TRUE(cellular_->sim_present());
Ben Chanea18c6c2014-09-30 13:08:26 -07001192 EXPECT_NE(nullptr, capability_->sim_proxy_);;
Ben Chanbd3aee82012-10-16 23:52:04 -07001193 EXPECT_EQ(kSimPath, capability_->sim_path_);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001194 EXPECT_EQ(kImsi, cellular_->imsi());
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001195 EXPECT_EQ(kSimIdentifier, cellular_->sim_identifier());
Ben Chanbd3aee82012-10-16 23:52:04 -07001196 EXPECT_EQ(kOperatorName, capability_->spn_);
1197
1198 // Changing to the same SIM path should be a no-op.
1199 capability_->OnSimPathChanged(kSimPath);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001200 EXPECT_TRUE(cellular_->sim_present());
Ben Chanea18c6c2014-09-30 13:08:26 -07001201 EXPECT_NE(nullptr, capability_->sim_proxy_);;
Ben Chanbd3aee82012-10-16 23:52:04 -07001202 EXPECT_EQ(kSimPath, capability_->sim_path_);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001203 EXPECT_EQ(kImsi, cellular_->imsi());
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001204 EXPECT_EQ(kSimIdentifier, cellular_->sim_identifier());
Ben Chanbd3aee82012-10-16 23:52:04 -07001205 EXPECT_EQ(kOperatorName, capability_->spn_);
1206
1207 capability_->OnSimPathChanged("");
Arman Uguray41cc6342013-03-29 16:34:39 -07001208 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001209 Mock::VerifyAndClearExpectations(properties_proxy_.get());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001210 EXPECT_FALSE(cellular_->sim_present());
Ben Chanea18c6c2014-09-30 13:08:26 -07001211 EXPECT_EQ(nullptr, capability_->sim_proxy_);;
Ben Chanbd3aee82012-10-16 23:52:04 -07001212 EXPECT_EQ("", capability_->sim_path_);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001213 EXPECT_EQ("", cellular_->imsi());
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001214 EXPECT_EQ("", cellular_->sim_identifier());
Ben Chanbd3aee82012-10-16 23:52:04 -07001215 EXPECT_EQ("", capability_->spn_);
Arman Uguray6552f8c2013-02-12 15:33:18 -08001216
1217 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
1218 .Times(1).WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -07001219 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1220 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -07001221 .Times(1);
Arman Uguray6552f8c2013-02-12 15:33:18 -08001222
1223 capability_->OnSimPathChanged(kSimPath);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001224 EXPECT_TRUE(cellular_->sim_present());
Ben Chanea18c6c2014-09-30 13:08:26 -07001225 EXPECT_NE(nullptr, capability_->sim_proxy_);;
Arman Uguray6552f8c2013-02-12 15:33:18 -08001226 EXPECT_EQ(kSimPath, capability_->sim_path_);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001227 EXPECT_EQ(kImsi, cellular_->imsi());
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001228 EXPECT_EQ(kSimIdentifier, cellular_->sim_identifier());
Arman Uguray6552f8c2013-02-12 15:33:18 -08001229 EXPECT_EQ(kOperatorName, capability_->spn_);
1230
1231 capability_->OnSimPathChanged("/");
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001232 EXPECT_FALSE(cellular_->sim_present());
Ben Chanea18c6c2014-09-30 13:08:26 -07001233 EXPECT_EQ(nullptr, capability_->sim_proxy_);;
Arman Uguray6552f8c2013-02-12 15:33:18 -08001234 EXPECT_EQ("/", capability_->sim_path_);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001235 EXPECT_EQ("", cellular_->imsi());
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001236 EXPECT_EQ("", cellular_->sim_identifier());
Arman Uguray6552f8c2013-02-12 15:33:18 -08001237 EXPECT_EQ("", capability_->spn_);
Ben Chanbd3aee82012-10-16 23:52:04 -07001238}
1239
Arman Uguray1361c032013-02-11 17:53:39 -08001240TEST_F(CellularCapabilityUniversalMainTest, SimPropertiesChanged) {
Jason Glasgowaf583282012-04-18 15:18:22 -04001241 // 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 Uguray41cc6342013-03-29 16:34:39 -07001252 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1253 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -07001254 .Times(0);
Jason Glasgowaf583282012-04-18 15:18:22 -04001255
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 Prabhu9f06c872013-11-21 14:08:23 -08001261 EXPECT_EQ(kImsi, cellular_->imsi());
Arman Uguray41cc6342013-03-29 16:34:39 -07001262 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Jason Glasgowaf583282012-04-18 15:18:22 -04001263
1264 // Updating the SIM
1265 DBusPropertiesMap new_properties;
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001266 const char kNewImsi[] = "310240123456789";
Jason Glasgowaf583282012-04-18 15:18:22 -04001267 const char kSimIdentifier[] = "9999888";
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001268 const char kOperatorIdentifier[] = "310240";
1269 const char kOperatorName[] = "Custom SPN";
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -07001270 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 Glasgowaf583282012-04-18 15:18:22 -04001274 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 Glasgowaf583282012-04-18 15:18:22 -04001279 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM,
1280 new_properties,
1281 vector<string>());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001282 EXPECT_EQ(kNewImsi, cellular_->imsi());
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001283 EXPECT_EQ(kSimIdentifier, cellular_->sim_identifier());
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001284 EXPECT_EQ("", capability_->spn_);
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001285
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 Glasgowaf583282012-04-18 15:18:22 -04001291 EXPECT_EQ(kOperatorName, capability_->spn_);
1292}
1293
Gary Morainceba6aa2012-05-03 10:28:26 -07001294MATCHER_P(SizeIs, value, "") {
1295 return static_cast<size_t>(value) == arg.size();
1296}
1297
Arman Uguray1361c032013-02-11 17:53:39 -08001298TEST_F(CellularCapabilityUniversalMainTest, Reset) {
Ben Chan5d0d32c2013-01-08 02:05:29 -08001299 // Save pointers to proxies before they are lost by the call to InitProxies
Paul Stewart2f6c7892015-06-16 13:13:10 -07001300 mm1::MockModemProxy* modem_proxy = modem_proxy_.get();
Ben Chan5d0d32c2013-01-08 02:05:29 -08001301 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 Chan539ab022014-02-03 16:34:57 -08001316TEST_F(CellularCapabilityUniversalMainTest, UpdateActiveBearer) {
mukesh agrawal83a98f42013-07-31 16:25:53 -07001317 // Common resources.
Arman Uguray6e5639f2012-11-15 20:30:19 -08001318 const size_t kPathCount = 3;
1319 DBus::Path active_paths[kPathCount], inactive_paths[kPathCount];
1320 for (size_t i = 0; i < kPathCount; ++i) {
Ben Chancbef8122014-01-06 17:31:30 -08001321 active_paths[i] = base::StringPrintf("%s/%zu", kActiveBearerPathPrefix, i);
Arman Uguray6e5639f2012-11-15 20:30:19 -08001322 inactive_paths[i] =
Ben Chancbef8122014-01-06 17:31:30 -08001323 base::StringPrintf("%s/%zu", kInactiveBearerPathPrefix, i);
Arman Uguray6e5639f2012-11-15 20:30:19 -08001324 }
1325
Ben Chanea18c6c2014-09-30 13:08:26 -07001326 EXPECT_EQ(nullptr, capability_->GetActiveBearer());;
Arman Uguray6e5639f2012-11-15 20:30:19 -08001327
Ben Chan539ab022014-02-03 16:34:57 -08001328 // Check that |active_bearer_| is set correctly when an active bearer is
1329 // returned.
Ben Chancbef8122014-01-06 17:31:30 -08001330 capability_->OnBearersChanged({inactive_paths[0],
1331 inactive_paths[1],
1332 active_paths[2],
1333 inactive_paths[1],
1334 inactive_paths[2]});
Ben Chan539ab022014-02-03 16:34:57 -08001335 capability_->UpdateActiveBearer();
Ben Chanea18c6c2014-09-30 13:08:26 -07001336 ASSERT_NE(nullptr, capability_->GetActiveBearer());;
Ben Chan539ab022014-02-03 16:34:57 -08001337 EXPECT_EQ(active_paths[2], capability_->GetActiveBearer()->dbus_path());
Ben Chancbef8122014-01-06 17:31:30 -08001338
Ben Chanea18c6c2014-09-30 13:08:26 -07001339 // Check that |active_bearer_| is nullptr if no active bearers are returned.
Ben Chancbef8122014-01-06 17:31:30 -08001340 capability_->OnBearersChanged({inactive_paths[0],
1341 inactive_paths[1],
1342 inactive_paths[2],
1343 inactive_paths[1]});
Ben Chan539ab022014-02-03 16:34:57 -08001344 capability_->UpdateActiveBearer();
Ben Chanea18c6c2014-09-30 13:08:26 -07001345 EXPECT_EQ(nullptr, capability_->GetActiveBearer());;
Arman Uguray6e5639f2012-11-15 20:30:19 -08001346
1347 // Check that returning multiple bearers causes death.
Ben Chancbef8122014-01-06 17:31:30 -08001348 capability_->OnBearersChanged({active_paths[0],
1349 inactive_paths[1],
1350 inactive_paths[2],
1351 active_paths[1],
1352 inactive_paths[1]});
Ben Chan539ab022014-02-03 16:34:57 -08001353 EXPECT_DEATH(capability_->UpdateActiveBearer(),
Ben Chancbef8122014-01-06 17:31:30 -08001354 "Found more than one active bearer.");
1355
1356 capability_->OnBearersChanged({});
Ben Chan539ab022014-02-03 16:34:57 -08001357 capability_->UpdateActiveBearer();
Ben Chanea18c6c2014-09-30 13:08:26 -07001358 EXPECT_EQ(nullptr, capability_->GetActiveBearer());;
Arman Uguray6e5639f2012-11-15 20:30:19 -08001359}
1360
Jason Glasgow14521872012-05-07 19:12:15 -04001361// Validates expected behavior of Connect function
Arman Uguray1361c032013-02-11 17:53:39 -08001362TEST_F(CellularCapabilityUniversalMainTest, Connect) {
Paul Stewart2f6c7892015-06-16 13:13:10 -07001363 mm1::MockModemSimpleProxy* modem_simple_proxy = modem_simple_proxy_.get();
Jason Glasgow14521872012-05-07 19:12:15 -04001364 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 Prabhub5fde532013-03-19 17:36:09 -07001374 .WillRepeatedly(SaveArg<2>(&connect_callback_));
Jason Glasgow14521872012-05-07 19:12:15 -04001375 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 Prabhub5fde532013-03-19 17:36:09 -07001380 Mock::VerifyAndClearExpectations(this);
Jason Glasgow14521872012-05-07 19:12:15 -04001381
1382 // Test connect success
Jason Glasgow14521872012-05-07 19:12:15 -04001383 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 Prabhub5fde532013-03-19 17:36:09 -07001387 Mock::VerifyAndClearExpectations(this);
Jason Glasgow7234ec32012-05-23 16:01:21 -04001388
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 Chanea18c6c2014-09-30 13:08:26 -07001393 cellular_->service_ = nullptr;
Jason Glasgow7234ec32012-05-23 16:01:21 -04001394 EXPECT_FALSE(capability_->cellular()->service());
Jason Glasgow7234ec32012-05-23 16:01:21 -04001395 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 Glasgow14521872012-05-07 19:12:15 -04001399}
1400
1401// Validates Connect iterates over APNs
Arman Uguray1361c032013-02-11 17:53:39 -08001402TEST_F(CellularCapabilityUniversalMainTest, ConnectApns) {
Paul Stewart2f6c7892015-06-16 13:13:10 -07001403 mm1::MockModemSimpleProxy* modem_simple_proxy = modem_simple_proxy_.get();
Jason Glasgow14521872012-05-07 19:12:15 -04001404 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 Chan7ea768e2013-09-20 15:08:40 -07001417 apn1[kApnProperty] = apn_name_foo;
Jason Glasgow14521872012-05-07 19:12:15 -04001418 capability_->apn_try_list_.push_back(apn1);
1419 Stringmap apn2;
Ben Chan7ea768e2013-09-20 15:08:40 -07001420 apn2[kApnProperty] = apn_name_bar;
Jason Glasgow14521872012-05-07 19:12:15 -04001421 capability_->apn_try_list_.push_back(apn2);
1422 capability_->FillConnectPropertyMap(&properties);
1423 capability_->Connect(properties, &error, callback);
1424 EXPECT_TRUE(error.IsSuccess());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001425 Mock::VerifyAndClearExpectations(modem_simple_proxy);
Jason Glasgow14521872012-05-07 19:12:15 -04001426
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 Glasgow9f09aef2012-05-08 16:26:55 -04001437// Validates GetTypeString and AccessTechnologyToTechnologyFamily
Arman Uguray1361c032013-02-11 17:53:39 -08001438TEST_F(CellularCapabilityUniversalMainTest, GetTypeString) {
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001439 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 Chan62028b22012-11-05 11:20:02 -08001458 for (size_t i = 0; i < arraysize(gsm_technologies); ++i) {
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001459 capability_->access_technologies_ = gsm_technologies[i];
Ben Chan7ea768e2013-09-20 15:08:40 -07001460 ASSERT_EQ(capability_->GetTypeString(), kTechnologyFamilyGsm);
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001461 }
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 Chan62028b22012-11-05 11:20:02 -08001470 for (size_t i = 0; i < arraysize(cdma_technologies); ++i) {
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001471 capability_->access_technologies_ = cdma_technologies[i];
Ben Chan7ea768e2013-09-20 15:08:40 -07001472 ASSERT_EQ(capability_->GetTypeString(), kTechnologyFamilyCdma);
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001473 }
1474 capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
1475 ASSERT_EQ(capability_->GetTypeString(), "");
1476}
1477
Arman Uguray1361c032013-02-11 17:53:39 -08001478TEST_F(CellularCapabilityUniversalMainTest, AllowRoaming) {
Darin Petkovf508c822012-09-21 13:43:17 +02001479 EXPECT_FALSE(cellular_->allow_roaming_);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001480 EXPECT_FALSE(cellular_->provider_requires_roaming());
Darin Petkovf508c822012-09-21 13:43:17 +02001481 EXPECT_FALSE(capability_->AllowRoaming());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001482 cellular_->set_provider_requires_roaming(true);
Darin Petkovf508c822012-09-21 13:43:17 +02001483 EXPECT_TRUE(capability_->AllowRoaming());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001484 cellular_->set_provider_requires_roaming(false);
Darin Petkovf508c822012-09-21 13:43:17 +02001485 cellular_->allow_roaming_ = true;
1486 EXPECT_TRUE(capability_->AllowRoaming());
1487}
1488
Ben Chan07193fd2013-07-12 22:10:55 -07001489TEST_F(CellularCapabilityUniversalMainTest, GetMdnForOLP) {
Prathmesh Prabhu5089a6e2014-05-07 20:49:16 -07001490 const string kVzwUUID = "c83d6597-dc91-4d48-a3a7-d86b80123751";
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001491 const string kFooUUID = "foo";
Miao-chen Chou70190b32014-05-14 18:24:30 -07001492 MockMobileOperatorInfo mock_operator_info(&dispatcher_,
1493 "MobileOperatorInfo");
Ben Chan07193fd2013-07-12 22:10:55 -07001494
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001495 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 Prabhu9a0534e2013-10-10 16:20:34 -07001499 capability_->subscription_state_ =
1500 CellularCapabilityUniversal::kSubscriptionStateUnknown;
1501
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001502 cellular_->set_mdn("");
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001503 EXPECT_EQ("0000000000", capability_->GetMdnForOLP(&mock_operator_info));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001504 cellular_->set_mdn("0123456789");
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001505 EXPECT_EQ("0123456789", capability_->GetMdnForOLP(&mock_operator_info));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001506 cellular_->set_mdn("10123456789");
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001507 EXPECT_EQ("0123456789", capability_->GetMdnForOLP(&mock_operator_info));
1508
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001509 cellular_->set_mdn("1021232333");
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001510 capability_->subscription_state_ =
1511 CellularCapabilityUniversal::kSubscriptionStateUnprovisioned;
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001512 EXPECT_EQ("0000000000", capability_->GetMdnForOLP(&mock_operator_info));
1513 Mock::VerifyAndClearExpectations(&mock_operator_info);
Ben Chan07193fd2013-07-12 22:10:55 -07001514
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001515 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 Prabhu9f06c872013-11-21 14:08:23 -08001520 cellular_->set_mdn("");
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001521 EXPECT_EQ("", capability_->GetMdnForOLP(&mock_operator_info));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001522 cellular_->set_mdn("0123456789");
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001523 EXPECT_EQ("0123456789", capability_->GetMdnForOLP(&mock_operator_info));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001524 cellular_->set_mdn("10123456789");
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001525 EXPECT_EQ("10123456789", capability_->GetMdnForOLP(&mock_operator_info));
Ben Chan07193fd2013-07-12 22:10:55 -07001526}
1527
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001528TEST_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 Prabhu5089a6e2014-05-07 20:49:16 -07001534 const string kUuidVzw = "c83d6597-dc91-4d48-a3a7-d86b80123751";
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001535 const string kUuidFoo = "foo";
Ben Chan07193fd2013-07-12 22:10:55 -07001536
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001537 cellular_->set_imei("1");
1538 cellular_->set_imsi("2");
1539 cellular_->set_mdn("10123456789");
1540 cellular_->set_min("5");
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001541 cellular_->set_sim_identifier("6");
Ben Chan6d0d1e72012-11-06 21:19:28 -08001542
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -07001543 mock_home_provider_info_->SetEmptyDefaultsForProperties();
1544 EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001545 .WillRepeatedly(Return(true));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -07001546 EXPECT_CALL(*mock_home_provider_info_, olp_list())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001547 .WillRepeatedly(ReturnRef(kOlpList));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -07001548 EXPECT_CALL(*mock_home_provider_info_, uuid())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001549 .WillOnce(ReturnRef(kUuidVzw));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -07001550 CreateService();
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001551 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 Chan07193fd2013-07-12 22:10:55 -07001556 EXPECT_EQ("imei=1&imsi=2&mdn=0123456789&min=5&iccid=6",
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001557 vzw_olp[kPaymentPortalPostData]);
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -07001558 Mock::VerifyAndClearExpectations(mock_home_provider_info_);
Ben Chan07193fd2013-07-12 22:10:55 -07001559
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -07001560 mock_home_provider_info_->SetEmptyDefaultsForProperties();
1561 EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001562 .WillRepeatedly(Return(true));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -07001563 EXPECT_CALL(*mock_home_provider_info_, olp_list())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001564 .WillRepeatedly(ReturnRef(kOlpList));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -07001565 EXPECT_CALL(*mock_home_provider_info_, uuid())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001566 .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 Chan07193fd2013-07-12 22:10:55 -07001572 EXPECT_EQ("imei=1&imsi=2&mdn=10123456789&min=5&iccid=6",
Prathmesh Prabhu92df6192014-04-29 18:08:08 -07001573 olp[kPaymentPortalPostData]);
Ben Chan6d0d1e72012-11-06 21:19:28 -08001574}
1575
Arman Ugurayc7b15602013-02-16 00:56:18 -08001576TEST_F(CellularCapabilityUniversalMainTest, IsMdnValid) {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001577 cellular_->set_mdn("");
Arman Ugurayc7b15602013-02-16 00:56:18 -08001578 EXPECT_FALSE(capability_->IsMdnValid());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001579 cellular_->set_mdn("0000000");
Arman Ugurayc7b15602013-02-16 00:56:18 -08001580 EXPECT_FALSE(capability_->IsMdnValid());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001581 cellular_->set_mdn("0000001");
Arman Ugurayc7b15602013-02-16 00:56:18 -08001582 EXPECT_TRUE(capability_->IsMdnValid());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001583 cellular_->set_mdn("1231223");
Arman Ugurayc7b15602013-02-16 00:56:18 -08001584 EXPECT_TRUE(capability_->IsMdnValid());
1585}
1586
Arman Uguraya14941d2013-04-12 16:58:26 -07001587TEST_F(CellularCapabilityUniversalTimerTest, CompleteActivation) {
Arman Ugurayefea6e02013-02-21 13:28:04 -08001588 const char kIccid[] = "1234567";
1589
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001590 cellular_->set_sim_identifier(kIccid);
Arman Uguray41cc6342013-03-29 16:34:39 -07001591 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1592 SetActivationState(PendingActivationStore::kIdentifierICCID,
1593 kIccid,
1594 PendingActivationStore::kStatePending))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001595 .Times(1);
Thieu Le7de12f52014-07-11 15:30:43 -07001596 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1597 GetActivationState(PendingActivationStore::kIdentifierICCID,
1598 kIccid))
1599 .WillOnce(Return(PendingActivationStore::kStatePending));
Ben Chan7ea768e2013-09-20 15:08:40 -07001600 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001601 .Times(1);
Thieu Le7de12f52014-07-11 15:30:43 -07001602 EXPECT_CALL(*modem_proxy_.get(), Reset(_, _, _)).Times(1);
1603 Error error;
1604 capability_->InitProxies();
Arman Ugurayefea6e02013-02-21 13:28:04 -08001605 capability_->CompleteActivation(&error);
Arman Uguray41cc6342013-03-29 16:34:39 -07001606 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001607 Mock::VerifyAndClearExpectations(service_);
Arman Uguraya14941d2013-04-12 16:58:26 -07001608 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001609}
1610
1611TEST_F(CellularCapabilityUniversalMainTest, UpdateServiceActivationState) {
1612 const char kIccid[] = "1234567";
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -07001613 const vector<MobileOperatorInfo::OnlinePortal> olp_list {
1614 {"some@url", "some_method", "some_post_data"}
1615 };
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001616 capability_->subscription_state_ =
1617 CellularCapabilityUniversal::kSubscriptionStateUnprovisioned;
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001618 cellular_->set_sim_identifier("");
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001619 cellular_->set_mdn("0000000000");
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -07001620 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 Ugurayefea6e02013-02-21 13:28:04 -08001624
Arman Uguray6bb252d2013-05-15 14:29:53 -07001625 service_->SetAutoConnect(false);
Ben Chan7ea768e2013-09-20 15:08:40 -07001626 EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001627 .Times(1);
1628 capability_->UpdateServiceActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001629 Mock::VerifyAndClearExpectations(service_);
Arman Uguray6bb252d2013-05-15 14:29:53 -07001630 EXPECT_FALSE(service_->auto_connect());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001631
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001632 cellular_->set_mdn("1231231122");
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001633 capability_->subscription_state_ =
1634 CellularCapabilityUniversal::kSubscriptionStateUnknown;
Ben Chan7ea768e2013-09-20 15:08:40 -07001635 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001636 .Times(1);
1637 capability_->UpdateServiceActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001638 Mock::VerifyAndClearExpectations(service_);
Arman Uguray6bb252d2013-05-15 14:29:53 -07001639 EXPECT_TRUE(service_->auto_connect());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001640
Thieu Le247416e2014-02-25 18:19:53 -08001641 // 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 Uguray6bb252d2013-05-15 14:29:53 -07001654 service_->SetAutoConnect(false);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001655 cellular_->set_mdn("0000000000");
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001656 cellular_->set_sim_identifier(kIccid);
Arman Uguray41cc6342013-03-29 16:34:39 -07001657 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1658 GetActivationState(PendingActivationStore::kIdentifierICCID,
1659 kIccid))
Thieu Le29007182014-08-13 18:02:39 -07001660 .Times(1)
Thieu Le7de12f52014-07-11 15:30:43 -07001661 .WillRepeatedly(Return(PendingActivationStore::kStatePending));
Ben Chan7ea768e2013-09-20 15:08:40 -07001662 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001663 .Times(1);
1664 capability_->UpdateServiceActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001665 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001666 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguray6bb252d2013-05-15 14:29:53 -07001667 EXPECT_FALSE(service_->auto_connect());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001668
Arman Uguray41cc6342013-03-29 16:34:39 -07001669 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1670 GetActivationState(PendingActivationStore::kIdentifierICCID,
1671 kIccid))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001672 .Times(2)
Arman Uguray41cc6342013-03-29 16:34:39 -07001673 .WillRepeatedly(Return(PendingActivationStore::kStateActivated));
Ben Chan7ea768e2013-09-20 15:08:40 -07001674 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001675 .Times(1);
1676 capability_->UpdateServiceActivationState();
Arman Uguray6bb252d2013-05-15 14:29:53 -07001677 Mock::VerifyAndClearExpectations(service_);
1678 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
1679 EXPECT_TRUE(service_->auto_connect());
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001680
1681 // SubscriptionStateUnprovisioned overrides valid MDN.
1682 capability_->subscription_state_ =
1683 CellularCapabilityUniversal::kSubscriptionStateUnprovisioned;
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001684 cellular_->set_mdn("1231231122");
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001685 cellular_->set_sim_identifier("");
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001686 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 Prabhu9f06c872013-11-21 14:08:23 -08001696 cellular_->set_mdn("0000000000");
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001697 cellular_->set_sim_identifier("");
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001698 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 Ugurayefea6e02013-02-21 13:28:04 -08001704}
1705
Arman Uguray0a3e2792013-01-17 16:31:50 -08001706TEST_F(CellularCapabilityUniversalMainTest, UpdatePendingActivationState) {
Arman Ugurayc7b15602013-02-16 00:56:18 -08001707 const char kIccid[] = "1234567";
1708
Arman Ugurayc7b15602013-02-16 00:56:18 -08001709 capability_->InitProxies();
1710 capability_->registration_state_ =
1711 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING;
1712
1713 // No MDN, no ICCID.
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001714 cellular_->set_mdn("0000000");
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001715 capability_->subscription_state_ =
1716 CellularCapabilityUniversal::kSubscriptionStateUnknown;
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001717 cellular_->set_sim_identifier("");
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001718 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 Prabhu9f06c872013-11-21 14:08:23 -08001725 cellular_->set_mdn("1234567");
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001726 capability_->subscription_state_ =
1727 CellularCapabilityUniversal::kSubscriptionStateUnprovisioned;
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001728 cellular_->set_sim_identifier("");
Arman Uguray41cc6342013-03-29 16:34:39 -07001729 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1730 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001731 .Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001732 capability_->UpdatePendingActivationState();
Arman Uguray41cc6342013-03-29 16:34:39 -07001733 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001734
1735 // ICCID known.
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001736 cellular_->set_sim_identifier(kIccid);
Arman Ugurayc7b15602013-02-16 00:56:18 -08001737
1738 // After the modem has reset.
1739 capability_->reset_done_ = true;
Arman Uguray41cc6342013-03-29 16:34:39 -07001740 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 Ugurayc7b15602013-02-16 00:56:18 -08001748 .Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001749 capability_->UpdatePendingActivationState();
Arman Uguray41cc6342013-03-29 16:34:39 -07001750 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001751
Arman Ugurayc7b15602013-02-16 00:56:18 -08001752 // Not registered.
1753 capability_->registration_state_ =
1754 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING;
Arman Uguray41cc6342013-03-29 16:34:39 -07001755 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1756 GetActivationState(PendingActivationStore::kIdentifierICCID,
1757 kIccid))
1758 .Times(2).WillRepeatedly(Return(PendingActivationStore::kStateActivated));
Arman Ugurayc7b15602013-02-16 00:56:18 -08001759 EXPECT_CALL(*service_, AutoConnect()).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001760 capability_->UpdatePendingActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001761 Mock::VerifyAndClearExpectations(service_);
Arman Ugurayc7b15602013-02-16 00:56:18 -08001762
1763 // Service, registered.
1764 capability_->registration_state_ =
1765 MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
1766 EXPECT_CALL(*service_, AutoConnect()).Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001767 capability_->UpdatePendingActivationState();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001768
Ben Chan7ea768e2013-09-20 15:08:40 -07001769 cellular_->service_->activation_state_ = kActivationStateNotActivated;
Arman Ugurayc7b15602013-02-16 00:56:18 -08001770
Thieu Le7de12f52014-07-11 15:30:43 -07001771 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001772 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07001773
Arman Ugurayc7b15602013-02-16 00:56:18 -08001774 // Device is connected.
1775 cellular_->state_ = Cellular::kStateConnected;
Arman Uguray0a3e2792013-01-17 16:31:50 -08001776 capability_->UpdatePendingActivationState();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001777
1778 // Device is linked.
1779 cellular_->state_ = Cellular::kStateLinked;
Arman Uguray0a3e2792013-01-17 16:31:50 -08001780 capability_->UpdatePendingActivationState();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001781
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001782 // Got valid MDN, subscription_state_ is kSubscriptionStateUnknown
Thieu Le7de12f52014-07-11 15:30:43 -07001783 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1784 RemoveEntry(PendingActivationStore::kIdentifierICCID, kIccid));
Arman Ugurayc7b15602013-02-16 00:56:18 -08001785 cellular_->state_ = Cellular::kStateRegistered;
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001786 cellular_->set_mdn("1020304");
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001787 capability_->subscription_state_ =
1788 CellularCapabilityUniversal::kSubscriptionStateUnknown;
1789 capability_->UpdatePendingActivationState();
Thieu Le7de12f52014-07-11 15:30:43 -07001790 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001791
1792 // Got invalid MDN, subscription_state_ is kSubscriptionStateProvisioned
Thieu Le7de12f52014-07-11 15:30:43 -07001793 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1794 RemoveEntry(PendingActivationStore::kIdentifierICCID, kIccid));
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001795 cellular_->state_ = Cellular::kStateRegistered;
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001796 cellular_->set_mdn("0000000");
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001797 capability_->subscription_state_ =
1798 CellularCapabilityUniversal::kSubscriptionStateProvisioned;
Arman Uguray0a3e2792013-01-17 16:31:50 -08001799 capability_->UpdatePendingActivationState();
Arman Uguray41cc6342013-03-29 16:34:39 -07001800 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001801}
1802
Arman Uguray1361c032013-02-11 17:53:39 -08001803TEST_F(CellularCapabilityUniversalMainTest, IsServiceActivationRequired) {
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -07001804 const vector<MobileOperatorInfo::OnlinePortal> empty_list;
1805 const vector<MobileOperatorInfo::OnlinePortal> olp_list {
1806 {"some@url", "some_method", "some_post_data"}
1807 };
1808
Prathmesh Prabhu9a0534e2013-10-10 16:20:34 -07001809 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 Prabhu9f06c872013-11-21 14:08:23 -08001819 cellular_->set_mdn("0000000000");
Ben Chan15786032012-11-04 21:28:02 -08001820 EXPECT_FALSE(capability_->IsServiceActivationRequired());
1821
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -07001822 EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown())
1823 .WillRepeatedly(Return(false));
Ben Chan15786032012-11-04 21:28:02 -08001824 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -07001825 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 Chan15786032012-11-04 21:28:02 -08001839
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001840 cellular_->set_mdn("");
Ben Chan200591a2013-08-07 14:39:04 -07001841 EXPECT_TRUE(capability_->IsServiceActivationRequired());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001842 cellular_->set_mdn("1234567890");
Ben Chan15786032012-11-04 21:28:02 -08001843 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001844 cellular_->set_mdn("0000000000");
Ben Chan15786032012-11-04 21:28:02 -08001845 EXPECT_TRUE(capability_->IsServiceActivationRequired());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001846
1847 const char kIccid[] = "1234567890";
Prathmesh Prabhu700ff4d2014-01-16 15:59:33 -08001848 cellular_->set_sim_identifier(kIccid);
Arman Uguray41cc6342013-03-29 16:34:39 -07001849 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 Uguray41cc6342013-03-29 16:34:39 -07001854 .WillOnce(Return(PendingActivationStore::kStateUnknown));
Arman Ugurayefea6e02013-02-21 13:28:04 -08001855 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Arman Uguraya14941d2013-04-12 16:58:26 -07001856 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Arman Uguraya14941d2013-04-12 16:58:26 -07001857 EXPECT_TRUE(capability_->IsServiceActivationRequired());
Arman Uguray41cc6342013-03-29 16:34:39 -07001858 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Ben Chan15786032012-11-04 21:28:02 -08001859}
1860
Arman Uguray1361c032013-02-11 17:53:39 -08001861TEST_F(CellularCapabilityUniversalMainTest, OnModemCurrentCapabilitiesChanged) {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001862 EXPECT_FALSE(cellular_->scanning_supported());
Ben Chanfcca27b2013-01-22 15:03:44 -08001863 capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_LTE);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001864 EXPECT_FALSE(cellular_->scanning_supported());
Ben Chanfcca27b2013-01-22 15:03:44 -08001865 capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_CDMA_EVDO);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001866 EXPECT_FALSE(cellular_->scanning_supported());
Ben Chanfcca27b2013-01-22 15:03:44 -08001867 capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_GSM_UMTS);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001868 EXPECT_TRUE(cellular_->scanning_supported());
Ben Chanfcca27b2013-01-22 15:03:44 -08001869 capability_->OnModemCurrentCapabilitiesChanged(
1870 MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_CDMA_EVDO);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001871 EXPECT_TRUE(cellular_->scanning_supported());
Ben Chanfcca27b2013-01-22 15:03:44 -08001872}
1873
Arman Uguray7af0fac2013-03-18 17:35:35 -07001874TEST_F(CellularCapabilityUniversalMainTest, GetNetworkTechnologyStringOnE362) {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001875 cellular_->set_model_id("");;
Arman Uguray7af0fac2013-03-18 17:35:35 -07001876 capability_->access_technologies_ = 0;
1877 EXPECT_TRUE(capability_->GetNetworkTechnologyString().empty());
1878
Ben Chan3dddd042014-10-19 14:08:10 -07001879 cellular_->set_mm_plugin(CellularCapabilityUniversal::kNovatelLTEMMPlugin);
Ben Chan7ea768e2013-09-20 15:08:40 -07001880 EXPECT_EQ(kNetworkTechnologyLte, capability_->GetNetworkTechnologyString());
Arman Uguray7af0fac2013-03-18 17:35:35 -07001881
1882 capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_GPRS;
Ben Chan7ea768e2013-09-20 15:08:40 -07001883 EXPECT_EQ(kNetworkTechnologyLte, capability_->GetNetworkTechnologyString());
Arman Uguray7af0fac2013-03-18 17:35:35 -07001884
Ben Chan3dddd042014-10-19 14:08:10 -07001885 cellular_->set_mm_plugin("");
Ben Chan7ea768e2013-09-20 15:08:40 -07001886 EXPECT_EQ(kNetworkTechnologyGprs, capability_->GetNetworkTechnologyString());
Arman Uguray7af0fac2013-03-18 17:35:35 -07001887}
1888
Thieu Le43ce4d42013-10-04 16:08:55 -07001889TEST_F(CellularCapabilityUniversalMainTest, GetOutOfCreditsDetectionType) {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -08001890 cellular_->set_model_id("");;
Thieu Le43ce4d42013-10-04 16:08:55 -07001891 EXPECT_EQ(OutOfCreditsDetector::OOCTypeNone,
1892 capability_->GetOutOfCreditsDetectionType());
Thieu Lec466ccb2014-06-23 15:24:56 -07001893 cellular_->set_mm_plugin(CellularCapabilityUniversal::kAltairLTEMMPlugin);
Thieu Le43ce4d42013-10-04 16:08:55 -07001894 EXPECT_EQ(OutOfCreditsDetector::OOCTypeSubscriptionState,
1895 capability_->GetOutOfCreditsDetectionType());
Arman Ugurayd42d8ec2013-04-08 19:28:21 -07001896}
1897
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001898TEST_F(CellularCapabilityUniversalMainTest, SimLockStatusToProperty) {
1899 Error error;
1900 KeyValueStore store = capability_->SimLockStatusToProperty(&error);
Ben Chan7ea768e2013-09-20 15:08:40 -07001901 EXPECT_FALSE(store.GetBool(kSIMLockEnabledProperty));
1902 EXPECT_TRUE(store.GetString(kSIMLockTypeProperty).empty());
1903 EXPECT_EQ(0, store.GetUint(kSIMLockRetriesLeftProperty));
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001904
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 Chan7ea768e2013-09-20 15:08:40 -07001909 EXPECT_TRUE(store.GetBool(kSIMLockEnabledProperty));
1910 EXPECT_EQ("sim-pin", store.GetString(kSIMLockTypeProperty));
1911 EXPECT_EQ(3, store.GetUint(kSIMLockRetriesLeftProperty));
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001912
1913 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK;
1914 store = capability_->SimLockStatusToProperty(&error);
Ben Chan7ea768e2013-09-20 15:08:40 -07001915 EXPECT_EQ("sim-puk", store.GetString(kSIMLockTypeProperty));
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001916
1917 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN2;
1918 store = capability_->SimLockStatusToProperty(&error);
Ben Chan7ea768e2013-09-20 15:08:40 -07001919 EXPECT_TRUE(store.GetString(kSIMLockTypeProperty).empty());
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001920
1921 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK2;
1922 store = capability_->SimLockStatusToProperty(&error);
Ben Chan7ea768e2013-09-20 15:08:40 -07001923 EXPECT_TRUE(store.GetString(kSIMLockTypeProperty).empty());
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001924}
1925
1926TEST_F(CellularCapabilityUniversalMainTest, OnLockRetriesChanged) {
1927 CellularCapabilityUniversal::LockRetryData data;
Ben Chan7fab8972014-08-10 17:14:46 -07001928 const uint32_t kDefaultRetries = 999;
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001929
1930 capability_->OnLockRetriesChanged(data);
1931 EXPECT_EQ(kDefaultRetries, capability_->sim_lock_status_.retries_left);
1932
1933 data[MM_MODEM_LOCK_SIM_PIN] = 3;
Arman Ugurayea5ff272013-06-25 10:28:02 -07001934 data[MM_MODEM_LOCK_SIM_PUK] = 10;
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001935 capability_->OnLockRetriesChanged(data);
Arman Uguray192ad822013-06-13 19:49:16 -07001936 EXPECT_EQ(3, capability_->sim_lock_status_.retries_left);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001937
Arman Ugurayea5ff272013-06-25 10:28:02 -07001938 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK;
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001939 capability_->OnLockRetriesChanged(data);
Arman Ugurayea5ff272013-06-25 10:28:02 -07001940 EXPECT_EQ(10, capability_->sim_lock_status_.retries_left);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001941
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 Uguray192ad822013-06-13 19:49:16 -07001945
1946 data.clear();
1947 capability_->OnLockRetriesChanged(data);
1948 EXPECT_EQ(kDefaultRetries, capability_->sim_lock_status_.retries_left);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001949}
1950
1951TEST_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 Uguray4ef02fd2013-06-13 20:14:20 -07001956 EXPECT_FALSE(capability_->sim_lock_status_.enabled);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001957
1958 capability_->OnLockTypeChanged(MM_MODEM_LOCK_SIM_PIN);
1959 EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type);
Arman Uguray4ef02fd2013-06-13 20:14:20 -07001960 EXPECT_TRUE(capability_->sim_lock_status_.enabled);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001961
Arman Uguray4ef02fd2013-06-13 20:14:20 -07001962 capability_->sim_lock_status_.enabled = false;
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001963 capability_->OnLockTypeChanged(MM_MODEM_LOCK_SIM_PUK);
1964 EXPECT_EQ(MM_MODEM_LOCK_SIM_PUK, capability_->sim_lock_status_.lock_type);
Arman Uguray4ef02fd2013-06-13 20:14:20 -07001965 EXPECT_TRUE(capability_->sim_lock_status_.enabled);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001966}
1967
1968TEST_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 Uguray192ad822013-06-13 19:49:16 -07001990 EXPECT_EQ(3, capability_->sim_lock_status_.retries_left);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001991
1992 // Unlock retries changed and the SIM got locked.
1993 variant.clear();
1994 writer = variant.writer();
Ben Chan7fab8972014-08-10 17:14:46 -07001995 writer << static_cast<uint32_t>(MM_MODEM_LOCK_SIM_PIN);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07001996 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 Uguray192ad822013-06-13 19:49:16 -07002011
2012 // Unlock retries changed with a value that doesn't match the current
Arman Ugurayea5ff272013-06-25 10:28:02 -07002013 // lock type. Default to whatever count is available.
Arman Uguray192ad822013-06-13 19:49:16 -07002014 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 Ugurayea5ff272013-06-25 10:28:02 -07002022 EXPECT_EQ(2, capability_->sim_lock_status_.retries_left);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002023}
2024
Jason Glasgowef965562012-04-10 16:12:35 -04002025} // namespace shill