blob: 1d80a86559201368e42f387955affe66598ab97f [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
5#include "shill/cellular_capability_universal.h"
6
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>
Darin Petkova4ca3c32012-08-17 16:05:24 +020011#include <base/stringprintf.h>
Arman Ugurayc9533572013-01-22 17:34:20 -080012#include <base/string_util.h>
Jason Glasgowef965562012-04-10 16:12:35 -040013#include <chromeos/dbus/service_constants.h>
Arman Uguray1361c032013-02-11 17:53:39 -080014#include <gmock/gmock.h>
Jason Glasgowef965562012-04-10 16:12:35 -040015#include <gtest/gtest.h>
16#include <mobile_provider.h>
Ben Chan5c853ef2012-10-05 00:05:37 -070017#include <ModemManager/ModemManager.h>
Jason Glasgowef965562012-04-10 16:12:35 -040018
19#include "shill/cellular.h"
20#include "shill/cellular_service.h"
Jason Glasgowaf583282012-04-18 15:18:22 -040021#include "shill/dbus_adaptor.h"
Jason Glasgowef965562012-04-10 16:12:35 -040022#include "shill/error.h"
23#include "shill/event_dispatcher.h"
24#include "shill/mock_adaptors.h"
Ben Chan15786032012-11-04 21:28:02 -080025#include "shill/mock_cellular_operator_info.h"
Jason Glasgow14521872012-05-07 19:12:15 -040026#include "shill/mock_cellular_service.h"
Jason Glasgowaf583282012-04-18 15:18:22 -040027#include "shill/mock_dbus_properties_proxy.h"
Arman Uguray1361c032013-02-11 17:53:39 -080028#include "shill/mock_event_dispatcher.h"
Jason Glasgowef965562012-04-10 16:12:35 -040029#include "shill/mock_mm1_modem_modem3gpp_proxy.h"
30#include "shill/mock_mm1_modem_modemcdma_proxy.h"
31#include "shill/mock_mm1_modem_proxy.h"
32#include "shill/mock_mm1_modem_simple_proxy.h"
33#include "shill/mock_mm1_sim_proxy.h"
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070034#include "shill/mock_modem_info.h"
Arman Uguray41cc6342013-03-29 16:34:39 -070035#include "shill/mock_pending_activation_store.h"
Jason Glasgowef965562012-04-10 16:12:35 -040036#include "shill/mock_profile.h"
37#include "shill/mock_rtnl_handler.h"
Jason Glasgowef965562012-04-10 16:12:35 -040038#include "shill/proxy_factory.h"
39
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;
Nathan Williams4b7c2a82012-04-13 15:19:47 -040044using std::vector;
Jason Glasgowef965562012-04-10 16:12:35 -040045using testing::InSequence;
Ben Chan6d0d1e72012-11-06 21:19:28 -080046using testing::Invoke;
Arman Uguray1361c032013-02-11 17:53:39 -080047using testing::InvokeWithoutArgs;
Gary Moraine285a842012-08-15 08:23:57 -070048using testing::Mock;
Jason Glasgowef965562012-04-10 16:12:35 -040049using testing::NiceMock;
50using testing::Return;
Jason Glasgowcd0349c2012-05-03 23:32:15 -040051using testing::SaveArg;
Jason Glasgowef965562012-04-10 16:12:35 -040052using testing::_;
53
54namespace shill {
55
56MATCHER(IsSuccess, "") {
57 return arg.IsSuccess();
58}
59MATCHER(IsFailure, "") {
60 return arg.IsFailure();
61}
Jason Glasgow14521872012-05-07 19:12:15 -040062MATCHER_P(HasApn, expected_apn, "") {
63 string apn;
64 return (DBusProperties::GetString(arg,
65 CellularCapabilityUniversal::kConnectApn,
66 &apn) &&
67 apn == expected_apn);
68}
Jason Glasgowef965562012-04-10 16:12:35 -040069
Arman Uguray1361c032013-02-11 17:53:39 -080070class CellularCapabilityUniversalTest : public testing::TestWithParam<string> {
Jason Glasgowef965562012-04-10 16:12:35 -040071 public:
Arman Uguray1361c032013-02-11 17:53:39 -080072 CellularCapabilityUniversalTest(EventDispatcher *dispatcher)
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070073 : modem_info_(NULL, dispatcher, NULL, NULL, NULL),
Ben Chan3ecdf822012-08-06 12:29:23 -070074 modem_3gpp_proxy_(new mm1::MockModemModem3gppProxy()),
75 modem_cdma_proxy_(new mm1::MockModemModemCdmaProxy()),
76 modem_proxy_(new mm1::MockModemProxy()),
77 modem_simple_proxy_(new mm1::MockModemSimpleProxy()),
78 sim_proxy_(new mm1::MockSimProxy()),
79 properties_proxy_(new MockDBusPropertiesProxy()),
80 proxy_factory_(this),
81 capability_(NULL),
82 device_adaptor_(NULL),
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070083 cellular_(new Cellular(&modem_info_,
Jason Glasgowef965562012-04-10 16:12:35 -040084 "",
Arman Ugurayc9533572013-01-22 17:34:20 -080085 kMachineAddress,
Jason Glasgowef965562012-04-10 16:12:35 -040086 0,
87 Cellular::kTypeUniversal,
88 "",
89 "",
Jason Glasgowa585fc32012-06-06 11:04:09 -040090 "",
Ben Chan3ecdf822012-08-06 12:29:23 -070091 &proxy_factory_)),
Prathmesh Prabhu0d36b4f2013-04-01 11:45:54 -070092 service_(new MockCellularService(&modem_info_, cellular_)) {
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() {
98 cellular_->service_ = NULL;
99 capability_ = NULL;
100 device_adaptor_ = NULL;
101 }
102
103 virtual void SetUp() {
104 capability_ = dynamic_cast<CellularCapabilityUniversal *>(
105 cellular_->capability_.get());
Jason Glasgowef965562012-04-10 16:12:35 -0400106 device_adaptor_ =
Prathmesh Prabhu27526f12013-03-25 19:42:18 -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));
Jason Glasgowef965562012-04-10 16:12:35 -0400115 }
116
117 virtual void TearDown() {
118 capability_->proxy_factory_ = NULL;
119 }
120
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700121 void InitProviderDB() {
122 modem_info_.SetProviderDB(kTestMobileProviderDBPath);
123 }
124
Darin Petkova4ca3c32012-08-17 16:05:24 +0200125 void SetService() {
Prathmesh Prabhu0d36b4f2013-04-01 11:45:54 -0700126 cellular_->service_ = new CellularService(&modem_info_, cellular_);
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400127 }
128
Jason Glasgowef965562012-04-10 16:12:35 -0400129 void InvokeEnable(bool enable, Error *error,
130 const ResultCallback &callback, int timeout) {
131 callback.Run(Error());
132 }
133 void InvokeEnableFail(bool enable, Error *error,
134 const ResultCallback &callback, int timeout) {
135 callback.Run(Error(Error::kOperationFailed));
136 }
Jason Glasgowaf583282012-04-18 15:18:22 -0400137 void InvokeRegister(const string &operator_id, Error *error,
138 const ResultCallback &callback, int timeout) {
139 callback.Run(Error());
140 }
141
Gary Morainceba6aa2012-05-03 10:28:26 -0700142 void InvokeScan(Error *error, const DBusPropertyMapsCallback &callback,
143 int timeout) {
144 callback.Run(CellularCapabilityUniversal::ScanResults(), Error());
145 }
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400146 void ScanError(Error *error, const DBusPropertyMapsCallback &callback,
147 int timeout) {
148 error->Populate(Error::kOperationFailed);
149 }
Gary Morainceba6aa2012-05-03 10:28:26 -0700150
Arman Uguray1361c032013-02-11 17:53:39 -0800151 bool InvokeScanningOrSearchingTimeout() {
152 capability_->OnScanningOrSearchingTimeout();
153 return true;
154 }
155
Gary Morainceba6aa2012-05-03 10:28:26 -0700156 void Set3gppProxy() {
157 capability_->modem_3gpp_proxy_.reset(modem_3gpp_proxy_.release());
158 }
159
Jason Glasgow14521872012-05-07 19:12:15 -0400160 void SetSimpleProxy() {
161 capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release());
162 }
163
Thieu Le3d275392012-07-20 15:32:58 -0700164 void ReleaseCapabilityProxies() {
165 capability_->ReleaseProxies();
166 }
167
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700168 void SetRegistrationDroppedUpdateTimeout(int64 timeout_milliseconds) {
169 capability_->registration_dropped_update_timeout_milliseconds_ =
170 timeout_milliseconds;
171 }
172
Jason Glasgowef965562012-04-10 16:12:35 -0400173 MOCK_METHOD1(TestCallback, void(const Error &error));
174
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700175 MOCK_METHOD0(DummyCallback, void(void));
176
177 void SetMockRegistrationDroppedUpdateCallback() {
178 capability_->registration_dropped_update_callback_.Reset(
179 Bind(&CellularCapabilityUniversalTest::DummyCallback,
180 Unretained(this)));
181 }
182
Jason Glasgowef965562012-04-10 16:12:35 -0400183 protected:
Arman Uguray6e5639f2012-11-15 20:30:19 -0800184 static const char kActiveBearerPathPrefix[];
Jason Glasgowef965562012-04-10 16:12:35 -0400185 static const char kImei[];
Arman Uguray6e5639f2012-11-15 20:30:19 -0800186 static const char kInactiveBearerPathPrefix[];
Arman Ugurayc9533572013-01-22 17:34:20 -0800187 static const char kMachineAddress[];
Jason Glasgowaf583282012-04-18 15:18:22 -0400188 static const char kSimPath[];
189 static const uint32 kAccessTechnologies;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700190 static const char kTestMobileProviderDBPath[];
Jason Glasgowef965562012-04-10 16:12:35 -0400191
192 class TestProxyFactory : public ProxyFactory {
193 public:
194 explicit TestProxyFactory(CellularCapabilityUniversalTest *test) :
mukesh agrawal9da07772013-05-15 14:15:17 -0700195 test_(test) {
Ben Chan5db19692013-07-09 23:07:03 -0700196 active_bearer_properties_[MM_BEARER_PROPERTY_CONNECTED].writer()
197 .append_bool(true);
198 active_bearer_properties_[MM_BEARER_PROPERTY_INTERFACE].writer()
199 .append_string("/dev/fake");
Jason Glasgowef965562012-04-10 16:12:35 -0400200
Ben Chan5db19692013-07-09 23:07:03 -0700201 DBusPropertiesMap ip4config;
202 ip4config[CellularCapabilityUniversal::kIpConfigPropertyMethod].writer()
203 .append_uint32(MM_BEARER_IP_METHOD_DHCP);
204 DBus::MessageIter writer =
205 active_bearer_properties_[MM_BEARER_PROPERTY_IP4CONFIG].writer();
206 writer << ip4config;
207
208 inactive_bearer_properties_[MM_BEARER_PROPERTY_CONNECTED].writer()
209 .append_bool(false);
Arman Uguray6e5639f2012-11-15 20:30:19 -0800210 }
211
Jason Glasgowef965562012-04-10 16:12:35 -0400212 virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800213 const std::string &/*path*/,
214 const std::string &/*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400215 return test_->modem_3gpp_proxy_.release();
216 }
217
218 virtual mm1::ModemModemCdmaProxyInterface *CreateMM1ModemModemCdmaProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800219 const std::string &/*path*/,
220 const std::string &/*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400221 return test_->modem_cdma_proxy_.release();
222 }
223
224 virtual mm1::ModemProxyInterface *CreateMM1ModemProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800225 const std::string &/*path*/,
226 const std::string &/*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400227 return test_->modem_proxy_.release();
228 }
229
230 virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800231 const std::string &/*path*/,
232 const std::string &/*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400233 return test_->modem_simple_proxy_.release();
234 }
235
236 virtual mm1::SimProxyInterface *CreateSimProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800237 const std::string &/*path*/,
238 const std::string &/*service*/) {
Arman Uguray6552f8c2013-02-12 15:33:18 -0800239 mm1::MockSimProxy *sim_proxy = test_->sim_proxy_.release();
240 test_->sim_proxy_.reset(new mm1::MockSimProxy());
241 return sim_proxy;
Jason Glasgowef965562012-04-10 16:12:35 -0400242 }
Jason Glasgowaf583282012-04-18 15:18:22 -0400243 virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy(
Ben Chan5db19692013-07-09 23:07:03 -0700244 const std::string &path,
Arman Uguray6e5639f2012-11-15 20:30:19 -0800245 const std::string &/*service*/) {
Arman Uguray6552f8c2013-02-12 15:33:18 -0800246 MockDBusPropertiesProxy *properties_proxy =
247 test_->properties_proxy_.release();
Ben Chan5db19692013-07-09 23:07:03 -0700248 if (path.find(kActiveBearerPathPrefix) != std::string::npos) {
249 ON_CALL(*properties_proxy, GetAll(MM_DBUS_INTERFACE_BEARER))
250 .WillByDefault(Return(active_bearer_properties_));
251 } else {
252 ON_CALL(*properties_proxy, GetAll(MM_DBUS_INTERFACE_BEARER))
253 .WillByDefault(Return(inactive_bearer_properties_));
254 }
Arman Uguray6552f8c2013-02-12 15:33:18 -0800255 test_->properties_proxy_.reset(new MockDBusPropertiesProxy());
256 return properties_proxy;
Jason Glasgowaf583282012-04-18 15:18:22 -0400257 }
Jason Glasgowef965562012-04-10 16:12:35 -0400258
259 private:
Ben Chan5db19692013-07-09 23:07:03 -0700260 DBusPropertiesMap GetActiveBearerProperties(
261 const string &/*interface_name*/) {
262 DBusPropertiesMap properties;
263 properties[MM_BEARER_PROPERTY_CONNECTED].writer().append_bool(true);
264 return properties;
265 }
266
267 DBusPropertiesMap GetInactiveBearerProperties(
268 const string &/*interface_name*/) {
269 DBusPropertiesMap properties;
270 properties[MM_BEARER_PROPERTY_CONNECTED].writer().append_bool(false);
271 return properties;
272 }
273
Jason Glasgowef965562012-04-10 16:12:35 -0400274 CellularCapabilityUniversalTest *test_;
Ben Chan5db19692013-07-09 23:07:03 -0700275 DBusPropertiesMap active_bearer_properties_;
276 DBusPropertiesMap inactive_bearer_properties_;
Jason Glasgowef965562012-04-10 16:12:35 -0400277 };
278
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700279 MockModemInfo modem_info_;
Jason Glasgowef965562012-04-10 16:12:35 -0400280 scoped_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_;
281 scoped_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_;
282 scoped_ptr<mm1::MockModemProxy> modem_proxy_;
283 scoped_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_;
284 scoped_ptr<mm1::MockSimProxy> sim_proxy_;
Jason Glasgowaf583282012-04-18 15:18:22 -0400285 scoped_ptr<MockDBusPropertiesProxy> properties_proxy_;
Jason Glasgowef965562012-04-10 16:12:35 -0400286 TestProxyFactory proxy_factory_;
287 CellularCapabilityUniversal *capability_; // Owned by |cellular_|.
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700288 DeviceMockAdaptor *device_adaptor_; // Owned by |cellular_|.
Ben Chan3ecdf822012-08-06 12:29:23 -0700289 CellularRefPtr cellular_;
290 MockCellularService *service_; // owned by cellular_
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400291 DBusPropertyMapsCallback scan_callback_; // saved for testing scan operations
Jason Glasgow14521872012-05-07 19:12:15 -0400292 DBusPathCallback connect_callback_; // saved for testing connect operations
Jason Glasgowef965562012-04-10 16:12:35 -0400293};
294
Arman Uguray1361c032013-02-11 17:53:39 -0800295// Most of our tests involve using a real EventDispatcher object.
296class CellularCapabilityUniversalMainTest
297 : public CellularCapabilityUniversalTest {
298 public:
299 CellularCapabilityUniversalMainTest() :
300 CellularCapabilityUniversalTest(&dispatcher_) {}
301
302 protected:
303 EventDispatcher dispatcher_;
304};
305
306// Tests that involve timers will (or may) use a mock of the event dispatcher
307// instead of a real one.
308class CellularCapabilityUniversalTimerTest
309 : public CellularCapabilityUniversalTest {
310 public:
311 CellularCapabilityUniversalTimerTest()
312 : CellularCapabilityUniversalTest(&mock_dispatcher_) {}
313
314 protected:
315 ::testing::StrictMock<MockEventDispatcher> mock_dispatcher_;
316};
317
Arman Uguray6e5639f2012-11-15 20:30:19 -0800318const char CellularCapabilityUniversalTest::kActiveBearerPathPrefix[] =
319 "/bearer/active";
Jason Glasgowef965562012-04-10 16:12:35 -0400320const char CellularCapabilityUniversalTest::kImei[] = "999911110000";
Arman Uguray6e5639f2012-11-15 20:30:19 -0800321const char CellularCapabilityUniversalTest::kInactiveBearerPathPrefix[] =
322 "/bearer/inactive";
Arman Ugurayc9533572013-01-22 17:34:20 -0800323const char CellularCapabilityUniversalTest::kMachineAddress[] =
324 "TestMachineAddress";
Jason Glasgowaf583282012-04-18 15:18:22 -0400325const char CellularCapabilityUniversalTest::kSimPath[] = "/foo/sim";
326const uint32 CellularCapabilityUniversalTest::kAccessTechnologies =
327 MM_MODEM_ACCESS_TECHNOLOGY_LTE |
328 MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700329const char CellularCapabilityUniversalTest::kTestMobileProviderDBPath[] =
330 "provider_db_unittest.bfd";
Jason Glasgowef965562012-04-10 16:12:35 -0400331
Arman Uguray1361c032013-02-11 17:53:39 -0800332TEST_F(CellularCapabilityUniversalMainTest, StartModem) {
Jason Glasgowaf583282012-04-18 15:18:22 -0400333 // Set up mock modem properties
334 DBusPropertiesMap modem_properties;
335 string operator_name = "TestOperator";
336 string operator_code = "001400";
337
338 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
339 writer().append_uint32(kAccessTechnologies);
340
341 ::DBus::Variant v;
342 ::DBus::MessageIter writer = v.writer();
Jason Glasgowef965562012-04-10 16:12:35 -0400343 ::DBus::Struct< uint32_t, bool > quality;
344 quality._1 = 90;
345 quality._2 = true;
Jason Glasgowaf583282012-04-18 15:18:22 -0400346 writer << quality;
347 modem_properties[MM_MODEM_PROPERTY_SIGNALQUALITY] = v;
348
349 // Set up mock modem 3gpp properties
350 DBusPropertiesMap modem3gpp_properties;
351 modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS].
352 writer().append_uint32(0);
353 modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_IMEI].
354 writer().append_string(kImei);
355
356 EXPECT_CALL(*modem_proxy_,
357 Enable(true, _, _, CellularCapability::kTimeoutEnable))
358 .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeEnable));
359 EXPECT_CALL(*properties_proxy_,
360 GetAll(MM_DBUS_INTERFACE_MODEM))
361 .WillOnce(Return(modem_properties));
362 EXPECT_CALL(*properties_proxy_,
363 GetAll(MM_DBUS_INTERFACE_MODEM_MODEM3GPP))
364 .WillOnce(Return(modem3gpp_properties));
Jason Glasgowef965562012-04-10 16:12:35 -0400365
Gary Moraine285a842012-08-15 08:23:57 -0700366 // Let the modem report that it is initializing. StartModem() should defer
367 // enabling the modem until its state changes to disabled.
368 EXPECT_CALL(*modem_proxy_, State())
369 .WillOnce(Return(Cellular::kModemStateInitializing));
370
Jason Glasgowef965562012-04-10 16:12:35 -0400371 // After setup we lose pointers to the proxies, so it is hard to set
372 // expectations.
373 SetUp();
374
375 Error error;
Gary Moraine285a842012-08-15 08:23:57 -0700376 EXPECT_CALL(*this, TestCallback(_)).Times(0);
Jason Glasgowef965562012-04-10 16:12:35 -0400377 ResultCallback callback =
378 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
379 capability_->StartModem(&error, callback);
Gary Moraine285a842012-08-15 08:23:57 -0700380
Arman Uguray6e5639f2012-11-15 20:30:19 -0800381 // Verify that the modem has not been enabled.
Gary Moraine285a842012-08-15 08:23:57 -0700382 EXPECT_TRUE(capability_->imei_.empty());
383 EXPECT_EQ(0, capability_->access_technologies_);
384 Mock::VerifyAndClearExpectations(this);
385
386 // Change the state to kModemStateDisabling and verify that it still has not
Arman Uguray6e5639f2012-11-15 20:30:19 -0800387 // been enabled.
Gary Moraine285a842012-08-15 08:23:57 -0700388 EXPECT_CALL(*this, TestCallback(_)).Times(0);
389 capability_->OnModemStateChangedSignal(Cellular::kModemStateInitializing,
390 Cellular::kModemStateDisabling, 0);
391 EXPECT_TRUE(capability_->imei_.empty());
392 EXPECT_EQ(0, capability_->access_technologies_);
393 Mock::VerifyAndClearExpectations(this);
394
395 // Change the state of the modem to disabled and verify that it gets enabled.
396 EXPECT_CALL(*this, TestCallback(IsSuccess()));
397 capability_->OnModemStateChangedSignal(Cellular::kModemStateDisabling,
398 Cellular::kModemStateDisabled, 0);
Jason Glasgowef965562012-04-10 16:12:35 -0400399 EXPECT_TRUE(error.IsSuccess());
Jason Glasgowaf583282012-04-18 15:18:22 -0400400 EXPECT_EQ(kImei, capability_->imei_);
401 EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_);
Jason Glasgowef965562012-04-10 16:12:35 -0400402}
403
Arman Uguray1361c032013-02-11 17:53:39 -0800404TEST_F(CellularCapabilityUniversalMainTest, StartModemFail) {
Gary Moraine285a842012-08-15 08:23:57 -0700405 EXPECT_CALL(*modem_proxy_, State())
406 .WillOnce(Return(Cellular::kModemStateDisabled));
Jason Glasgowef965562012-04-10 16:12:35 -0400407 EXPECT_CALL(*modem_proxy_,
408 Enable(true, _, _, CellularCapability::kTimeoutEnable))
409 .WillOnce(
410 Invoke(this, &CellularCapabilityUniversalTest::InvokeEnableFail));
411 EXPECT_CALL(*this, TestCallback(IsFailure()));
412 ResultCallback callback =
413 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
414 SetUp();
415
416 Error error;
417 capability_->StartModem(&error, callback);
Thieu Lee3b36592012-08-30 17:50:26 -0700418 EXPECT_TRUE(error.IsOngoing());
Jason Glasgowef965562012-04-10 16:12:35 -0400419}
420
Thieu Leb9c05e02013-03-04 14:09:32 -0800421TEST_F(CellularCapabilityUniversalMainTest, StartModemAlreadyEnabled) {
422 EXPECT_CALL(*modem_proxy_, State())
423 .WillOnce(Return(Cellular::kModemStateEnabled));
424 SetUp();
425 capability_->cellular()->modem_state_ = Cellular::kModemStateConnected;
426
427 // Make sure the call to StartModem() doesn't attempt to complete the
428 // request synchronously, else it will crash DBus-C++.
429 Error error(Error::kOperationInitiated);
430 capability_->StartModem(&error, ResultCallback());
431 EXPECT_TRUE(error.IsOngoing());
432}
433
Arman Uguray1361c032013-02-11 17:53:39 -0800434TEST_F(CellularCapabilityUniversalMainTest, StopModem) {
Jason Glasgow02401cc2012-05-16 10:35:37 -0400435 // Save pointers to proxies before they are lost by the call to InitProxies
436 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
437 SetUp();
438 EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
439 capability_->InitProxies();
440
441 Error error;
442 ResultCallback callback =
443 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
444 capability_->StopModem(&error, callback);
445 EXPECT_TRUE(error.IsSuccess());
446
447 ResultCallback disable_callback;
448 EXPECT_CALL(*modem_proxy,
449 Enable(false, _, _, CellularCapability::kTimeoutEnable))
450 .WillOnce(SaveArg<2>(&disable_callback));
451 dispatcher_.DispatchPendingEvents();
452
Arman Ugurayee464d32013-02-13 17:14:36 -0800453 ResultCallback set_power_state_callback;
Thieu Le2cac2942013-03-05 18:41:08 -0800454 EXPECT_CALL(
455 *modem_proxy,
456 SetPowerState(
457 MM_MODEM_POWER_STATE_LOW, _, _,
458 CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds))
Arman Ugurayee464d32013-02-13 17:14:36 -0800459 .WillOnce(SaveArg<2>(&set_power_state_callback));
Jason Glasgow02401cc2012-05-16 10:35:37 -0400460 disable_callback.Run(Error(Error::kSuccess));
Arman Ugurayee464d32013-02-13 17:14:36 -0800461
462 EXPECT_CALL(*this, TestCallback(IsSuccess()));
463 set_power_state_callback.Run(Error(Error::kSuccess));
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700464 Mock::VerifyAndClearExpectations(this);
Arman Ugurayee464d32013-02-13 17:14:36 -0800465
466 // TestCallback should get called with success even if the power state
467 // callback gets called with an error
468 EXPECT_CALL(*this, TestCallback(IsSuccess()));
469 set_power_state_callback.Run(Error(Error::kOperationFailed));
Jason Glasgow02401cc2012-05-16 10:35:37 -0400470}
471
Arman Uguray1361c032013-02-11 17:53:39 -0800472TEST_F(CellularCapabilityUniversalMainTest, StopModemConnected) {
Jason Glasgow02401cc2012-05-16 10:35:37 -0400473 // Save pointers to proxies before they are lost by the call to InitProxies
474 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
475 mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get();
476 SetUp();
477 EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
478 capability_->InitProxies();
479
480 ResultCallback disconnect_callback;
481 Error error;
482 ResultCallback callback =
483 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
484 EXPECT_CALL(*modem_simple_proxy,
485 Disconnect(::DBus::Path("/"), _, _,
Thieu Le049adb52012-11-12 17:14:51 -0800486 CellularCapability::kTimeoutDisconnect))
Jason Glasgow02401cc2012-05-16 10:35:37 -0400487 .WillOnce(SaveArg<2>(&disconnect_callback));
Thieu Led0012052012-07-25 16:09:09 -0700488 capability_->cellular()->modem_state_ = Cellular::kModemStateConnected;
Jason Glasgow02401cc2012-05-16 10:35:37 -0400489 capability_->StopModem(&error, callback);
490 EXPECT_TRUE(error.IsSuccess());
491
492 ResultCallback disable_callback;
493 EXPECT_CALL(*modem_proxy,
494 Enable(false, _, _, CellularCapability::kTimeoutEnable))
495 .WillOnce(SaveArg<2>(&disable_callback));
496 disconnect_callback.Run(Error(Error::kSuccess));
497
Arman Ugurayee464d32013-02-13 17:14:36 -0800498 ResultCallback set_power_state_callback;
Thieu Le2cac2942013-03-05 18:41:08 -0800499 EXPECT_CALL(
500 *modem_proxy,
501 SetPowerState(
502 MM_MODEM_POWER_STATE_LOW, _, _,
503 CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds))
Arman Ugurayee464d32013-02-13 17:14:36 -0800504 .WillOnce(SaveArg<2>(&set_power_state_callback));
505
Jason Glasgow02401cc2012-05-16 10:35:37 -0400506 disable_callback.Run(Error(Error::kSuccess));
Arman Ugurayee464d32013-02-13 17:14:36 -0800507
508 EXPECT_CALL(*this, TestCallback(IsSuccess()));
509 set_power_state_callback.Run(Error(Error::kSuccess));
Jason Glasgow02401cc2012-05-16 10:35:37 -0400510}
511
Arman Uguray1361c032013-02-11 17:53:39 -0800512TEST_F(CellularCapabilityUniversalMainTest, DisconnectModemNoBearer) {
Thieu Le5d6864a2012-07-20 11:43:51 -0700513 Error error;
514 ResultCallback disconnect_callback;
Thieu Le3d275392012-07-20 15:32:58 -0700515 EXPECT_CALL(*modem_simple_proxy_,
Thieu Le049adb52012-11-12 17:14:51 -0800516 Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect))
Thieu Le5d6864a2012-07-20 11:43:51 -0700517 .Times(0);
518 capability_->Disconnect(&error, disconnect_callback);
519}
520
Arman Uguray1361c032013-02-11 17:53:39 -0800521TEST_F(CellularCapabilityUniversalMainTest, DisconnectNoProxy) {
Thieu Le3d275392012-07-20 15:32:58 -0700522 Error error;
523 ResultCallback disconnect_callback;
524 capability_->bearer_path_ = "/foo";
525 EXPECT_CALL(*modem_simple_proxy_,
Thieu Le049adb52012-11-12 17:14:51 -0800526 Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect))
Thieu Le3d275392012-07-20 15:32:58 -0700527 .Times(0);
528 ReleaseCapabilityProxies();
529 capability_->Disconnect(&error, disconnect_callback);
530}
531
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700532TEST_F(CellularCapabilityUniversalMainTest, DisconnectWithDeferredCallback) {
533 Error error;
534 ResultCallback disconnect_callback;
535 capability_->bearer_path_ = "/foo";
536 EXPECT_CALL(*modem_simple_proxy_,
537 Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect));
538 SetSimpleProxy();
539 SetMockRegistrationDroppedUpdateCallback();
540 EXPECT_CALL(*this, DummyCallback());
541 capability_->Disconnect(&error, disconnect_callback);
542}
543
Arman Uguray1361c032013-02-11 17:53:39 -0800544TEST_F(CellularCapabilityUniversalMainTest, SimLockStatusChanged) {
Arman Ugurayab9364e2012-12-19 20:45:25 -0800545 // Set up mock SIM properties
546 const char kImsi[] = "310100000001";
547 const char kSimIdentifier[] = "9999888";
548 const char kOperatorIdentifier[] = "310240";
549 const char kOperatorName[] = "Custom SPN";
550 DBusPropertiesMap sim_properties;
551 sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi);
552 sim_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer()
553 .append_string(kSimIdentifier);
554 sim_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer()
555 .append_string(kOperatorIdentifier);
556 sim_properties[MM_SIM_PROPERTY_OPERATORNAME].writer()
557 .append_string(kOperatorName);
558
559 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
560 .WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -0700561 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
562 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700563 .Times(1);
Arman Ugurayab9364e2012-12-19 20:45:25 -0800564
565 SetUp();
566 InitProviderDB();
567
568 EXPECT_FALSE(capability_->sim_present_);
569 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
570
571 capability_->OnSimPathChanged(kSimPath);
572 EXPECT_TRUE(capability_->sim_present_);
573 EXPECT_TRUE(capability_->sim_proxy_ != NULL);
574 EXPECT_EQ(kSimPath, capability_->sim_path_);
575
576 capability_->imsi_ = "";
577 capability_->sim_identifier_ = "";
578 capability_->operator_id_ = "";
579 capability_->spn_ = "";
580
581 // SIM is locked.
Arman Ugurayc7e63af2013-06-13 17:07:32 -0700582 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN;
Arman Ugurayab9364e2012-12-19 20:45:25 -0800583 capability_->OnSimLockStatusChanged();
Arman Uguray41cc6342013-03-29 16:34:39 -0700584 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayab9364e2012-12-19 20:45:25 -0800585
586 EXPECT_EQ("", capability_->imsi_);
587 EXPECT_EQ("", capability_->sim_identifier_);
588 EXPECT_EQ("", capability_->operator_id_);
589 EXPECT_EQ("", capability_->spn_);
590
591 // SIM is unlocked.
592 properties_proxy_.reset(new MockDBusPropertiesProxy());
593 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
594 .WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -0700595 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
596 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700597 .Times(1);
Arman Ugurayab9364e2012-12-19 20:45:25 -0800598
Arman Ugurayc7e63af2013-06-13 17:07:32 -0700599 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_NONE;
Arman Ugurayab9364e2012-12-19 20:45:25 -0800600 capability_->OnSimLockStatusChanged();
Arman Uguray41cc6342013-03-29 16:34:39 -0700601 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayab9364e2012-12-19 20:45:25 -0800602
603 EXPECT_EQ(kImsi, capability_->imsi_);
604 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
605 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
606 EXPECT_EQ(kOperatorName, capability_->spn_);
Ben Chand3b18742013-07-12 00:30:25 -0700607
608 // SIM is missing and SIM path is "/".
609 capability_->OnSimPathChanged(CellularCapabilityUniversal::kRootPath);
610 EXPECT_FALSE(capability_->sim_present_);
611 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
612 EXPECT_EQ(CellularCapabilityUniversal::kRootPath, capability_->sim_path_);
613
614 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
615 GetActivationState(_, _)).Times(0);
616 capability_->OnSimLockStatusChanged();
617 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
618
619 EXPECT_EQ("", capability_->imsi_);
620 EXPECT_EQ("", capability_->sim_identifier_);
621 EXPECT_EQ("", capability_->operator_id_);
622 EXPECT_EQ("", capability_->spn_);
623
624 // SIM is missing and SIM path is empty.
625 capability_->OnSimPathChanged("");
626 EXPECT_FALSE(capability_->sim_present_);
627 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
628 EXPECT_EQ("", capability_->sim_path_);
629
630 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
631 GetActivationState(_, _)).Times(0);
632 capability_->OnSimLockStatusChanged();
633 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
634
635 EXPECT_EQ("", capability_->imsi_);
636 EXPECT_EQ("", capability_->sim_identifier_);
637 EXPECT_EQ("", capability_->operator_id_);
638 EXPECT_EQ("", capability_->spn_);
Arman Ugurayab9364e2012-12-19 20:45:25 -0800639}
640
Arman Uguray1361c032013-02-11 17:53:39 -0800641TEST_F(CellularCapabilityUniversalMainTest, PropertiesChanged) {
Jason Glasgowaf583282012-04-18 15:18:22 -0400642 // Set up mock modem properties
643 DBusPropertiesMap modem_properties;
644 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
645 writer().append_uint32(kAccessTechnologies);
646 modem_properties[MM_MODEM_PROPERTY_SIM].
647 writer().append_path(kSimPath);
648
649 // Set up mock modem 3gpp properties
650 DBusPropertiesMap modem3gpp_properties;
651 modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS].
652 writer().append_uint32(0);
653 modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_IMEI].
654 writer().append_string(kImei);
655
656 // Set up mock modem sim properties
657 DBusPropertiesMap sim_properties;
658
659 // After setup we lose pointers to the proxies, so it is hard to set
660 // expectations.
661 EXPECT_CALL(*properties_proxy_,
662 GetAll(MM_DBUS_INTERFACE_SIM))
663 .WillOnce(Return(sim_properties));
664
665 SetUp();
666
667 EXPECT_EQ("", capability_->imei_);
668 EXPECT_EQ(MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN,
669 capability_->access_technologies_);
670 EXPECT_FALSE(capability_->sim_proxy_.get());
Jason Glasgowbad114b2012-05-21 15:24:16 -0400671 EXPECT_CALL(*device_adaptor_, EmitStringChanged(
672 flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyGsm));
Jason Glasgowaf583282012-04-18 15:18:22 -0400673 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
674 modem_properties, vector<string>());
675 EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_);
676 EXPECT_EQ(kSimPath, capability_->sim_path_);
677 EXPECT_TRUE(capability_->sim_proxy_.get());
678
679 // Changing properties on wrong interface will not have an effect
680 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
681 modem3gpp_properties,
682 vector<string>());
683 EXPECT_EQ("", capability_->imei_);
684
685 // Changing properties on the right interface gets reflected in the
686 // capabilities object
687 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEM3GPP,
688 modem3gpp_properties,
689 vector<string>());
690 EXPECT_EQ(kImei, capability_->imei_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700691 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowbad114b2012-05-21 15:24:16 -0400692
693 // Expect to see changes when the family changes
694 modem_properties.clear();
695 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
696 writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_1XRTT);
697 EXPECT_CALL(*device_adaptor_, EmitStringChanged(
698 flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyCdma)).
699 Times(1);
700 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
701 modem_properties,
702 vector<string>());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700703 Mock::VerifyAndClearExpectations(device_adaptor_);
704
Jason Glasgowbad114b2012-05-21 15:24:16 -0400705 // Back to LTE
706 modem_properties.clear();
707 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
708 writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_LTE);
709 EXPECT_CALL(*device_adaptor_, EmitStringChanged(
710 flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyGsm)).
711 Times(1);
712 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
713 modem_properties,
714 vector<string>());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700715 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowbad114b2012-05-21 15:24:16 -0400716
717 // LTE & CDMA - the device adaptor should not be called!
718 modem_properties.clear();
719 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
720 writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_LTE |
721 MM_MODEM_ACCESS_TECHNOLOGY_1XRTT);
722 EXPECT_CALL(*device_adaptor_, EmitStringChanged(_, _)).Times(0);
723 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
724 modem_properties,
725 vector<string>());
Jason Glasgowaf583282012-04-18 15:18:22 -0400726}
727
Arman Uguray1361c032013-02-11 17:53:39 -0800728TEST_F(CellularCapabilityUniversalMainTest, UpdateServiceName) {
Arman Uguray2717a102013-01-29 23:36:06 -0800729 ::DBus::Struct<uint32_t, bool> data;
730 data._1 = 100;
731 data._2 = true;
732 EXPECT_CALL(*modem_proxy_, SignalQuality()).WillRepeatedly(Return(data));
733
734 SetUp();
735 InitProviderDB();
736 capability_->InitProxies();
Arman Uguray2717a102013-01-29 23:36:06 -0800737
738 SetService();
739
740 size_t len = strlen(CellularCapabilityUniversal::kGenericServiceNamePrefix);
741 EXPECT_EQ(CellularCapabilityUniversal::kGenericServiceNamePrefix,
742 cellular_->service_->friendly_name().substr(0, len));
743
744 capability_->imsi_ = "310240123456789";
745 capability_->SetHomeProvider();
746 EXPECT_EQ("", capability_->spn_);
747 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
748 EXPECT_EQ(CellularCapabilityUniversal::kGenericServiceNamePrefix,
749 cellular_->service_->friendly_name().substr(0, len));
750
751 capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
752 capability_->SetHomeProvider();
753 EXPECT_EQ("", capability_->spn_);
754 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
755 EXPECT_EQ("T-Mobile", cellular_->service_->friendly_name());
756
757 capability_->spn_ = "Test Home Provider";
758 capability_->SetHomeProvider();
759 EXPECT_EQ("Test Home Provider", cellular_->home_provider().GetName());
760 EXPECT_EQ("Test Home Provider", cellular_->service_->friendly_name());
761
762 capability_->On3GPPRegistrationChanged(
763 MM_MODEM_3GPP_REGISTRATION_STATE_HOME, "", "OTA Name");
764 EXPECT_EQ("OTA Name", cellular_->service_->friendly_name());
765
766 capability_->On3GPPRegistrationChanged(
767 MM_MODEM_3GPP_REGISTRATION_STATE_HOME, "123", "OTA Name 2");
768 EXPECT_EQ("OTA Name 2", cellular_->service_->friendly_name());
769
770 capability_->On3GPPRegistrationChanged(
771 MM_MODEM_3GPP_REGISTRATION_STATE_HOME, "123", "");
772 EXPECT_EQ("Test Home Provider", cellular_->service_->friendly_name());
773}
774
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700775TEST_F(CellularCapabilityUniversalMainTest, UpdateRegistrationState) {
776 SetUp();
777 InitProviderDB();
778 capability_->InitProxies();
779
780 SetService();
781 capability_->imsi_ = "310240123456789";
782 capability_->SetHomeProvider();
783 cellular_->set_modem_state(Cellular::kModemStateConnected);
784 SetRegistrationDroppedUpdateTimeout(0);
785
786 string home_provider = cellular_->home_provider().GetName();
787 string ota_name = cellular_->service_->friendly_name();
788
789 // Home --> Roaming should be effective immediately.
790 capability_->On3GPPRegistrationChanged(
791 MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
792 home_provider,
793 ota_name);
794 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
795 capability_->registration_state_);
796 capability_->On3GPPRegistrationChanged(
797 MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING,
798 home_provider,
799 ota_name);
800 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING,
801 capability_->registration_state_);
802
803 // Idle --> Roaming should be effective immediately.
804 capability_->On3GPPRegistrationChanged(
805 MM_MODEM_3GPP_REGISTRATION_STATE_IDLE,
806 home_provider,
807 ota_name);
808 dispatcher_.DispatchPendingEvents();
809 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_IDLE,
810 capability_->registration_state_);
811 capability_->On3GPPRegistrationChanged(
812 MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING,
813 home_provider,
814 ota_name);
815 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING,
816 capability_->registration_state_);
817
818 // Idle --> Searching should be effective immediately.
819 capability_->On3GPPRegistrationChanged(
820 MM_MODEM_3GPP_REGISTRATION_STATE_IDLE,
821 home_provider,
822 ota_name);
823 dispatcher_.DispatchPendingEvents();
824 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_IDLE,
825 capability_->registration_state_);
826 capability_->On3GPPRegistrationChanged(
827 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
828 home_provider,
829 ota_name);
830 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
831 capability_->registration_state_);
832
833 // Home --> Searching --> Home should never see Searching.
Prathmesh Prabhu08757aa2013-05-15 17:17:33 -0700834 EXPECT_CALL(*(modem_info_.mock_metrics()),
835 Notify3GPPRegistrationDelayedDropPosted());
836 EXPECT_CALL(*(modem_info_.mock_metrics()),
837 Notify3GPPRegistrationDelayedDropCanceled());
838
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700839 capability_->On3GPPRegistrationChanged(
840 MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
841 home_provider,
842 ota_name);
843 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
844 capability_->registration_state_);
845 capability_->On3GPPRegistrationChanged(
846 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
847 home_provider,
848 ota_name);
849 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
850 capability_->registration_state_);
851 capability_->On3GPPRegistrationChanged(
852 MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
853 home_provider,
854 ota_name);
855 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
856 capability_->registration_state_);
857 dispatcher_.DispatchPendingEvents();
858 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
859 capability_->registration_state_);
Prathmesh Prabhu08757aa2013-05-15 17:17:33 -0700860 Mock::VerifyAndClearExpectations(modem_info_.mock_metrics());
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700861
862 // Home --> Searching --> wait till dispatch should see Searching
Prathmesh Prabhu08757aa2013-05-15 17:17:33 -0700863 EXPECT_CALL(*(modem_info_.mock_metrics()),
864 Notify3GPPRegistrationDelayedDropPosted());
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700865 capability_->On3GPPRegistrationChanged(
866 MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
867 home_provider,
868 ota_name);
869 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
870 capability_->registration_state_);
871 capability_->On3GPPRegistrationChanged(
872 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
873 home_provider,
874 ota_name);
875 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
876 capability_->registration_state_);
877 dispatcher_.DispatchPendingEvents();
878 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
879 capability_->registration_state_);
Prathmesh Prabhu08757aa2013-05-15 17:17:33 -0700880 Mock::VerifyAndClearExpectations(modem_info_.mock_metrics());
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700881
882 // Home --> Searching --> Searching --> wait till dispatch should see
883 // Searching *and* the first callback should be cancelled.
884 EXPECT_CALL(*this, DummyCallback()).Times(0);
Prathmesh Prabhu08757aa2013-05-15 17:17:33 -0700885 EXPECT_CALL(*(modem_info_.mock_metrics()),
886 Notify3GPPRegistrationDelayedDropPosted());
887
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700888 capability_->On3GPPRegistrationChanged(
889 MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
890 home_provider,
891 ota_name);
892 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
893 capability_->registration_state_);
894 capability_->On3GPPRegistrationChanged(
895 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
896 home_provider,
897 ota_name);
898 SetMockRegistrationDroppedUpdateCallback();
899 capability_->On3GPPRegistrationChanged(
900 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
901 home_provider,
902 ota_name);
903 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
904 capability_->registration_state_);
905 dispatcher_.DispatchPendingEvents();
906 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
907 capability_->registration_state_);
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700908}
909
910TEST_F(CellularCapabilityUniversalMainTest,
911 UpdateRegistrationStateModemNotConnected) {
912 SetUp();
913 InitProviderDB();
914 capability_->InitProxies();
915 SetService();
916
917 capability_->imsi_ = "310240123456789";
918 capability_->SetHomeProvider();
919 cellular_->set_modem_state(Cellular::kModemStateRegistered);
920 SetRegistrationDroppedUpdateTimeout(0);
921
922 string home_provider = cellular_->home_provider().GetName();
923 string ota_name = cellular_->service_->friendly_name();
924
925 // Home --> Searching should be effective immediately.
926 capability_->On3GPPRegistrationChanged(
927 MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
928 home_provider,
929 ota_name);
930 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
931 capability_->registration_state_);
932 capability_->On3GPPRegistrationChanged(
933 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
934 home_provider,
935 ota_name);
936 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
937 capability_->registration_state_);
938}
939
Arman Uguray6552f8c2013-02-12 15:33:18 -0800940TEST_F(CellularCapabilityUniversalMainTest, IsValidSimPath) {
941 // Invalid paths
942 EXPECT_FALSE(capability_->IsValidSimPath(""));
943 EXPECT_FALSE(capability_->IsValidSimPath("/"));
944
945 // A valid path
946 EXPECT_TRUE(capability_->IsValidSimPath(
947 "/org/freedesktop/ModemManager1/SIM/0"));
948
949 // Note that any string that is not one of the above invalid paths is
950 // currently regarded as valid, since the ModemManager spec doesn't impose
951 // a strict format on the path. The validity of this is subject to change.
952 EXPECT_TRUE(capability_->IsValidSimPath("path"));
953}
954
Ben Chand7592522013-02-13 16:02:01 -0800955TEST_F(CellularCapabilityUniversalMainTest, NormalizeMdn) {
956 EXPECT_EQ("", capability_->NormalizeMdn(""));
957 EXPECT_EQ("12345678901", capability_->NormalizeMdn("12345678901"));
958 EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1 234 567 8901"));
959 EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1-234-567-8901"));
960 EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1 (234) 567-8901"));
961 EXPECT_EQ("12345678901", capability_->NormalizeMdn("1 234 567 8901 "));
962 EXPECT_EQ("2345678901", capability_->NormalizeMdn("(234) 567-8901"));
963}
964
Arman Uguray1361c032013-02-11 17:53:39 -0800965TEST_F(CellularCapabilityUniversalMainTest, SimPathChanged) {
Ben Chanbd3aee82012-10-16 23:52:04 -0700966 // Set up mock modem SIM properties
967 const char kImsi[] = "310100000001";
968 const char kSimIdentifier[] = "9999888";
969 const char kOperatorIdentifier[] = "310240";
970 const char kOperatorName[] = "Custom SPN";
971 DBusPropertiesMap sim_properties;
972 sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi);
973 sim_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer()
974 .append_string(kSimIdentifier);
975 sim_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer()
976 .append_string(kOperatorIdentifier);
977 sim_properties[MM_SIM_PROPERTY_OPERATORNAME].writer()
978 .append_string(kOperatorName);
979
980 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
981 .Times(1).WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -0700982 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
983 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700984 .Times(1);
Ben Chanbd3aee82012-10-16 23:52:04 -0700985
986 EXPECT_FALSE(capability_->sim_present_);
987 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
988 EXPECT_EQ("", capability_->sim_path_);
989 EXPECT_EQ("", capability_->imsi_);
990 EXPECT_EQ("", capability_->sim_identifier_);
991 EXPECT_EQ("", capability_->operator_id_);
992 EXPECT_EQ("", capability_->spn_);
993
994 capability_->OnSimPathChanged(kSimPath);
995 EXPECT_TRUE(capability_->sim_present_);
996 EXPECT_TRUE(capability_->sim_proxy_ != NULL);
997 EXPECT_EQ(kSimPath, capability_->sim_path_);
998 EXPECT_EQ(kImsi, capability_->imsi_);
999 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
1000 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
1001 EXPECT_EQ(kOperatorName, capability_->spn_);
1002
1003 // Changing to the same SIM path should be a no-op.
1004 capability_->OnSimPathChanged(kSimPath);
1005 EXPECT_TRUE(capability_->sim_present_);
1006 EXPECT_TRUE(capability_->sim_proxy_ != NULL);
1007 EXPECT_EQ(kSimPath, capability_->sim_path_);
1008 EXPECT_EQ(kImsi, capability_->imsi_);
1009 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
1010 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
1011 EXPECT_EQ(kOperatorName, capability_->spn_);
1012
1013 capability_->OnSimPathChanged("");
Arman Uguray41cc6342013-03-29 16:34:39 -07001014 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001015 Mock::VerifyAndClearExpectations(properties_proxy_.get());
Ben Chanbd3aee82012-10-16 23:52:04 -07001016 EXPECT_FALSE(capability_->sim_present_);
1017 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
1018 EXPECT_EQ("", capability_->sim_path_);
1019 EXPECT_EQ("", capability_->imsi_);
1020 EXPECT_EQ("", capability_->sim_identifier_);
1021 EXPECT_EQ("", capability_->operator_id_);
1022 EXPECT_EQ("", capability_->spn_);
Arman Uguray6552f8c2013-02-12 15:33:18 -08001023
1024 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
1025 .Times(1).WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -07001026 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1027 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -07001028 .Times(1);
Arman Uguray6552f8c2013-02-12 15:33:18 -08001029
1030 capability_->OnSimPathChanged(kSimPath);
1031 EXPECT_TRUE(capability_->sim_present_);
1032 EXPECT_TRUE(capability_->sim_proxy_ != NULL);
1033 EXPECT_EQ(kSimPath, capability_->sim_path_);
1034 EXPECT_EQ(kImsi, capability_->imsi_);
1035 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
1036 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
1037 EXPECT_EQ(kOperatorName, capability_->spn_);
1038
1039 capability_->OnSimPathChanged("/");
1040 EXPECT_FALSE(capability_->sim_present_);
1041 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
1042 EXPECT_EQ("/", capability_->sim_path_);
1043 EXPECT_EQ("", capability_->imsi_);
1044 EXPECT_EQ("", capability_->sim_identifier_);
1045 EXPECT_EQ("", capability_->operator_id_);
1046 EXPECT_EQ("", capability_->spn_);
Ben Chanbd3aee82012-10-16 23:52:04 -07001047}
1048
Arman Uguray1361c032013-02-11 17:53:39 -08001049TEST_F(CellularCapabilityUniversalMainTest, SimPropertiesChanged) {
Jason Glasgowaf583282012-04-18 15:18:22 -04001050 // Set up mock modem properties
1051 DBusPropertiesMap modem_properties;
1052 modem_properties[MM_MODEM_PROPERTY_SIM].writer().append_path(kSimPath);
1053
1054 // Set up mock modem sim properties
1055 const char kImsi[] = "310100000001";
1056 DBusPropertiesMap sim_properties;
1057 sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi);
1058
1059 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
1060 .WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -07001061 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1062 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -07001063 .Times(0);
Jason Glasgowaf583282012-04-18 15:18:22 -04001064 // After setup we lose pointers to the proxies, so it is hard to set
1065 // expectations.
1066 SetUp();
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001067 InitProviderDB();
Jason Glasgowaf583282012-04-18 15:18:22 -04001068
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001069 EXPECT_TRUE(cellular_->home_provider().GetName().empty());
1070 EXPECT_TRUE(cellular_->home_provider().GetCountry().empty());
1071 EXPECT_TRUE(cellular_->home_provider().GetCode().empty());
Jason Glasgowaf583282012-04-18 15:18:22 -04001072 EXPECT_FALSE(capability_->sim_proxy_.get());
1073 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
1074 modem_properties, vector<string>());
1075 EXPECT_EQ(kSimPath, capability_->sim_path_);
1076 EXPECT_TRUE(capability_->sim_proxy_.get());
1077 EXPECT_EQ(kImsi, capability_->imsi_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001078 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Jason Glasgowaf583282012-04-18 15:18:22 -04001079
1080 // Updating the SIM
Arman Uguray41cc6342013-03-29 16:34:39 -07001081 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1082 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -07001083 .Times(2);
Jason Glasgowaf583282012-04-18 15:18:22 -04001084 DBusPropertiesMap new_properties;
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001085 const char kCountry[] = "us";
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001086 const char kNewImsi[] = "310240123456789";
Jason Glasgowaf583282012-04-18 15:18:22 -04001087 const char kSimIdentifier[] = "9999888";
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001088 const char kOperatorIdentifier[] = "310240";
1089 const char kOperatorName[] = "Custom SPN";
Jason Glasgowaf583282012-04-18 15:18:22 -04001090 new_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kNewImsi);
1091 new_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer().
1092 append_string(kSimIdentifier);
1093 new_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer().
1094 append_string(kOperatorIdentifier);
Jason Glasgowaf583282012-04-18 15:18:22 -04001095 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM,
1096 new_properties,
1097 vector<string>());
1098 EXPECT_EQ(kNewImsi, capability_->imsi_);
1099 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
1100 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001101 EXPECT_EQ("", capability_->spn_);
1102 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
1103 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
Arman Ugurayd73783f2013-01-31 16:11:21 -08001104 EXPECT_EQ(kOperatorIdentifier, cellular_->home_provider().GetCode());
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001105 EXPECT_EQ(4, capability_->apn_list_.size());
1106
1107 new_properties[MM_SIM_PROPERTY_OPERATORNAME].writer().
1108 append_string(kOperatorName);
1109 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM,
1110 new_properties,
1111 vector<string>());
1112 EXPECT_EQ(kOperatorName, cellular_->home_provider().GetName());
Jason Glasgowaf583282012-04-18 15:18:22 -04001113 EXPECT_EQ(kOperatorName, capability_->spn_);
1114}
1115
Gary Morainceba6aa2012-05-03 10:28:26 -07001116MATCHER_P(SizeIs, value, "") {
1117 return static_cast<size_t>(value) == arg.size();
1118}
1119
Arman Uguray1361c032013-02-11 17:53:39 -08001120TEST_F(CellularCapabilityUniversalMainTest, Reset) {
Ben Chan5d0d32c2013-01-08 02:05:29 -08001121 // Save pointers to proxies before they are lost by the call to InitProxies
1122 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
1123 SetUp();
1124 EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
1125 capability_->InitProxies();
1126
1127 Error error;
1128 ResultCallback reset_callback;
1129
1130 EXPECT_CALL(*modem_proxy, Reset(_, _, CellularCapability::kTimeoutReset))
1131 .WillOnce(SaveArg<1>(&reset_callback));
1132
1133 capability_->Reset(&error, ResultCallback());
1134 EXPECT_TRUE(capability_->resetting_);
1135 reset_callback.Run(error);
1136 EXPECT_FALSE(capability_->resetting_);
1137}
1138
Gary Morainceba6aa2012-05-03 10:28:26 -07001139// Validates that OnScanReply does not crash with a null callback.
Arman Uguray1361c032013-02-11 17:53:39 -08001140TEST_F(CellularCapabilityUniversalMainTest, ScanWithNullCallback) {
Gary Morainceba6aa2012-05-03 10:28:26 -07001141 Error error;
1142 EXPECT_CALL(*modem_3gpp_proxy_, Scan(_, _, CellularCapability::kTimeoutScan))
1143 .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeScan));
1144 EXPECT_CALL(*device_adaptor_,
1145 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
1146 SizeIs(0)));
1147 Set3gppProxy();
1148 capability_->Scan(&error, ResultCallback());
1149 EXPECT_TRUE(error.IsSuccess());
1150}
1151
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001152// Validates that the scanning property is updated
Arman Uguray1361c032013-02-11 17:53:39 -08001153TEST_F(CellularCapabilityUniversalMainTest, Scan) {
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001154 Error error;
1155
1156 EXPECT_CALL(*modem_3gpp_proxy_, Scan(_, _, CellularCapability::kTimeoutScan))
1157 .WillRepeatedly(SaveArg<1>(&scan_callback_));
1158 EXPECT_CALL(*device_adaptor_,
1159 EmitBoolChanged(flimflam::kScanningProperty, true));
1160 Set3gppProxy();
1161 capability_->Scan(&error, ResultCallback());
1162 EXPECT_TRUE(capability_->scanning_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001163 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001164
1165 // Simulate the completion of the scan with 2 networks in the results.
1166 EXPECT_CALL(*device_adaptor_,
1167 EmitBoolChanged(flimflam::kScanningProperty, false));
1168 EXPECT_CALL(*device_adaptor_,
1169 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
1170 SizeIs(2)));
1171 vector<DBusPropertiesMap> results;
1172 const char kScanID0[] = "testID0";
1173 const char kScanID1[] = "testID1";
1174 results.push_back(DBusPropertiesMap());
1175 results[0][CellularCapabilityUniversal::kOperatorLongProperty].
1176 writer().append_string(kScanID0);
1177 results.push_back(DBusPropertiesMap());
1178 results[1][CellularCapabilityUniversal::kOperatorLongProperty].
1179 writer().append_string(kScanID1);
1180 scan_callback_.Run(results, error);
1181 EXPECT_FALSE(capability_->scanning_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001182 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001183
1184 // Simulate the completion of the scan with no networks in the results.
1185 EXPECT_CALL(*device_adaptor_,
1186 EmitBoolChanged(flimflam::kScanningProperty, true));
1187 capability_->Scan(&error, ResultCallback());
1188 EXPECT_TRUE(capability_->scanning_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001189 Mock::VerifyAndClearExpectations(device_adaptor_);
1190
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001191 EXPECT_CALL(*device_adaptor_,
1192 EmitBoolChanged(flimflam::kScanningProperty, false));
1193 EXPECT_CALL(*device_adaptor_,
1194 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
1195 SizeIs(0)));
1196 scan_callback_.Run(vector<DBusPropertiesMap>(), Error());
1197 EXPECT_FALSE(capability_->scanning_);
1198}
1199
1200// Validates expected property updates when scan fails
Arman Uguray1361c032013-02-11 17:53:39 -08001201TEST_F(CellularCapabilityUniversalMainTest, ScanFailure) {
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001202 Error error;
1203
1204 // Test immediate error
1205 {
1206 InSequence seq;
1207 EXPECT_CALL(*modem_3gpp_proxy_,
1208 Scan(_, _, CellularCapability::kTimeoutScan))
1209 .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::ScanError));
1210 EXPECT_CALL(*modem_3gpp_proxy_,
1211 Scan(_, _, CellularCapability::kTimeoutScan))
1212 .WillOnce(SaveArg<1>(&scan_callback_));
1213 }
1214 Set3gppProxy();
1215 capability_->Scan(&error, ResultCallback());
1216 EXPECT_FALSE(capability_->scanning_);
1217 EXPECT_TRUE(error.IsFailure());
1218
1219 // Initiate a scan
1220 error.Populate(Error::kSuccess);
1221 EXPECT_CALL(*device_adaptor_,
1222 EmitBoolChanged(flimflam::kScanningProperty, true));
1223 capability_->Scan(&error, ResultCallback());
1224 EXPECT_TRUE(capability_->scanning_);
1225 EXPECT_TRUE(error.IsSuccess());
1226
1227 // Validate that error is returned if Scan is called while already scanning.
1228 capability_->Scan(&error, ResultCallback());
1229 EXPECT_TRUE(capability_->scanning_);
1230 EXPECT_TRUE(error.IsFailure());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001231 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001232
1233 // Validate that signals are emitted even if an error is reported.
1234 capability_->found_networks_.clear();
1235 capability_->found_networks_.push_back(Stringmap());
1236 EXPECT_CALL(*device_adaptor_,
1237 EmitBoolChanged(flimflam::kScanningProperty, false));
1238 EXPECT_CALL(*device_adaptor_,
1239 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
1240 SizeIs(0)));
1241 vector<DBusPropertiesMap> results;
1242 scan_callback_.Run(results, Error(Error::kOperationFailed));
1243 EXPECT_FALSE(capability_->scanning_);
1244}
1245
Arman Uguray6e5639f2012-11-15 20:30:19 -08001246// Validates expected behavior of OnListBearersReply function
Arman Uguray1361c032013-02-11 17:53:39 -08001247TEST_F(CellularCapabilityUniversalMainTest, OnListBearersReply) {
Arman Uguray6e5639f2012-11-15 20:30:19 -08001248 // Check that bearer_path_ is set correctly when an active bearer
1249 // is returned.
1250 const size_t kPathCount = 3;
1251 DBus::Path active_paths[kPathCount], inactive_paths[kPathCount];
1252 for (size_t i = 0; i < kPathCount; ++i) {
1253 active_paths[i] =
1254 DBus::Path(base::StringPrintf("%s/%zu", kActiveBearerPathPrefix, i));
1255 inactive_paths[i] =
1256 DBus::Path(base::StringPrintf("%s/%zu", kInactiveBearerPathPrefix, i));
1257 }
1258
1259 std::vector<DBus::Path> paths;
1260 paths.push_back(inactive_paths[0]);
1261 paths.push_back(inactive_paths[1]);
1262 paths.push_back(active_paths[2]);
1263 paths.push_back(inactive_paths[1]);
1264 paths.push_back(inactive_paths[2]);
1265
1266 Error error;
1267 capability_->OnListBearersReply(paths, error);
1268 EXPECT_STREQ(capability_->bearer_path_.c_str(), active_paths[2].c_str());
1269
1270 paths.clear();
1271
1272 // Check that bearer_path_ is empty if no active bearers are returned.
1273 paths.push_back(inactive_paths[0]);
1274 paths.push_back(inactive_paths[1]);
1275 paths.push_back(inactive_paths[2]);
1276 paths.push_back(inactive_paths[1]);
1277
1278 capability_->OnListBearersReply(paths, error);
1279 EXPECT_TRUE(capability_->bearer_path_.empty());
1280
1281 // Check that returning multiple bearers causes death.
1282 paths.push_back(active_paths[0]);
1283 paths.push_back(inactive_paths[1]);
1284 paths.push_back(inactive_paths[2]);
1285 paths.push_back(active_paths[1]);
1286 paths.push_back(inactive_paths[1]);
1287
1288 EXPECT_DEATH(capability_->OnListBearersReply(paths, error),
1289 "Found more than one active bearer.");
1290}
1291
Jason Glasgow14521872012-05-07 19:12:15 -04001292// Validates expected behavior of Connect function
Arman Uguray1361c032013-02-11 17:53:39 -08001293TEST_F(CellularCapabilityUniversalMainTest, Connect) {
Jason Glasgow14521872012-05-07 19:12:15 -04001294 mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get();
1295 SetSimpleProxy();
1296 Error error;
1297 DBusPropertiesMap properties;
1298 capability_->apn_try_list_.clear();
1299 ResultCallback callback =
1300 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
1301 DBus::Path bearer("/foo");
1302
1303 // Test connect failures
1304 EXPECT_CALL(*modem_simple_proxy, Connect(_, _, _, _))
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001305 .WillRepeatedly(SaveArg<2>(&connect_callback_));
Jason Glasgow14521872012-05-07 19:12:15 -04001306 capability_->Connect(properties, &error, callback);
1307 EXPECT_TRUE(error.IsSuccess());
1308 EXPECT_CALL(*this, TestCallback(IsFailure()));
1309 EXPECT_CALL(*service_, ClearLastGoodApn());
1310 connect_callback_.Run(bearer, Error(Error::kOperationFailed));
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001311 Mock::VerifyAndClearExpectations(this);
Jason Glasgow14521872012-05-07 19:12:15 -04001312
1313 // Test connect success
Jason Glasgow14521872012-05-07 19:12:15 -04001314 capability_->Connect(properties, &error, callback);
1315 EXPECT_TRUE(error.IsSuccess());
1316 EXPECT_CALL(*this, TestCallback(IsSuccess()));
1317 connect_callback_.Run(bearer, Error(Error::kSuccess));
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001318 Mock::VerifyAndClearExpectations(this);
Jason Glasgow7234ec32012-05-23 16:01:21 -04001319
1320 // Test connect failures without a service. Make sure that shill
1321 // does not crash if the connect failed and there is no
1322 // CellularService object. This can happen if the modem is enabled
1323 // and then quickly disabled.
1324 cellular_->service_ = NULL;
1325 EXPECT_FALSE(capability_->cellular()->service());
Jason Glasgow7234ec32012-05-23 16:01:21 -04001326 capability_->Connect(properties, &error, callback);
1327 EXPECT_TRUE(error.IsSuccess());
1328 EXPECT_CALL(*this, TestCallback(IsFailure()));
1329 connect_callback_.Run(bearer, Error(Error::kOperationFailed));
Jason Glasgow14521872012-05-07 19:12:15 -04001330}
1331
1332// Validates Connect iterates over APNs
Arman Uguray1361c032013-02-11 17:53:39 -08001333TEST_F(CellularCapabilityUniversalMainTest, ConnectApns) {
Jason Glasgow14521872012-05-07 19:12:15 -04001334 mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get();
1335 SetSimpleProxy();
1336 Error error;
1337 DBusPropertiesMap properties;
1338 capability_->apn_try_list_.clear();
1339 ResultCallback callback =
1340 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
1341 DBus::Path bearer("/bearer0");
1342
1343 const char apn_name_foo[] = "foo";
1344 const char apn_name_bar[] = "bar";
1345 EXPECT_CALL(*modem_simple_proxy, Connect(HasApn(apn_name_foo), _, _, _))
1346 .WillOnce(SaveArg<2>(&connect_callback_));
1347 Stringmap apn1;
1348 apn1[flimflam::kApnProperty] = apn_name_foo;
1349 capability_->apn_try_list_.push_back(apn1);
1350 Stringmap apn2;
1351 apn2[flimflam::kApnProperty] = apn_name_bar;
1352 capability_->apn_try_list_.push_back(apn2);
1353 capability_->FillConnectPropertyMap(&properties);
1354 capability_->Connect(properties, &error, callback);
1355 EXPECT_TRUE(error.IsSuccess());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001356 Mock::VerifyAndClearExpectations(modem_simple_proxy);
Jason Glasgow14521872012-05-07 19:12:15 -04001357
1358 EXPECT_CALL(*modem_simple_proxy, Connect(HasApn(apn_name_bar), _, _, _))
1359 .WillOnce(SaveArg<2>(&connect_callback_));
1360 EXPECT_CALL(*service_, ClearLastGoodApn());
1361 connect_callback_.Run(bearer, Error(Error::kInvalidApn));
1362
1363 EXPECT_CALL(*service_, SetLastGoodApn(apn2));
1364 EXPECT_CALL(*this, TestCallback(IsSuccess()));
1365 connect_callback_.Run(bearer, Error(Error::kSuccess));
1366}
1367
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001368// Validates GetTypeString and AccessTechnologyToTechnologyFamily
Arman Uguray1361c032013-02-11 17:53:39 -08001369TEST_F(CellularCapabilityUniversalMainTest, GetTypeString) {
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001370 const int gsm_technologies[] = {
1371 MM_MODEM_ACCESS_TECHNOLOGY_LTE,
1372 MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS,
1373 MM_MODEM_ACCESS_TECHNOLOGY_HSPA,
1374 MM_MODEM_ACCESS_TECHNOLOGY_HSUPA,
1375 MM_MODEM_ACCESS_TECHNOLOGY_HSDPA,
1376 MM_MODEM_ACCESS_TECHNOLOGY_UMTS,
1377 MM_MODEM_ACCESS_TECHNOLOGY_EDGE,
1378 MM_MODEM_ACCESS_TECHNOLOGY_GPRS,
1379 MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT,
1380 MM_MODEM_ACCESS_TECHNOLOGY_GSM,
1381 MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1382 MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1383 MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA,
1384 MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA,
1385 MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB,
1386 MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB,
1387 MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT,
1388 };
Ben Chan62028b22012-11-05 11:20:02 -08001389 for (size_t i = 0; i < arraysize(gsm_technologies); ++i) {
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001390 capability_->access_technologies_ = gsm_technologies[i];
1391 ASSERT_EQ(capability_->GetTypeString(), flimflam::kTechnologyFamilyGsm);
1392 }
1393 const int cdma_technologies[] = {
1394 MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1395 MM_MODEM_ACCESS_TECHNOLOGY_EVDOA,
1396 MM_MODEM_ACCESS_TECHNOLOGY_EVDOA | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1397 MM_MODEM_ACCESS_TECHNOLOGY_EVDOB,
1398 MM_MODEM_ACCESS_TECHNOLOGY_EVDOB | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1399 MM_MODEM_ACCESS_TECHNOLOGY_1XRTT,
1400 };
Ben Chan62028b22012-11-05 11:20:02 -08001401 for (size_t i = 0; i < arraysize(cdma_technologies); ++i) {
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001402 capability_->access_technologies_ = cdma_technologies[i];
1403 ASSERT_EQ(capability_->GetTypeString(), flimflam::kTechnologyFamilyCdma);
1404 }
1405 capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
1406 ASSERT_EQ(capability_->GetTypeString(), "");
1407}
1408
Arman Uguray1361c032013-02-11 17:53:39 -08001409TEST_F(CellularCapabilityUniversalMainTest, AllowRoaming) {
Darin Petkovf508c822012-09-21 13:43:17 +02001410 EXPECT_FALSE(cellular_->allow_roaming_);
1411 EXPECT_FALSE(capability_->provider_requires_roaming_);
1412 EXPECT_FALSE(capability_->AllowRoaming());
1413 capability_->provider_requires_roaming_ = true;
1414 EXPECT_TRUE(capability_->AllowRoaming());
1415 capability_->provider_requires_roaming_ = false;
1416 cellular_->allow_roaming_ = true;
1417 EXPECT_TRUE(capability_->AllowRoaming());
1418}
1419
Arman Uguray1361c032013-02-11 17:53:39 -08001420TEST_F(CellularCapabilityUniversalMainTest, SetHomeProvider) {
Darin Petkovb4fccd22012-08-10 11:59:26 +02001421 static const char kTestCarrier[] = "The Cellular Carrier";
1422 static const char kCountry[] = "us";
1423 static const char kCode[] = "310160";
Darin Petkovb4fccd22012-08-10 11:59:26 +02001424
Darin Petkovf508c822012-09-21 13:43:17 +02001425 EXPECT_FALSE(capability_->home_provider_);
1426 EXPECT_FALSE(capability_->provider_requires_roaming_);
1427
Arman Ugurayd73783f2013-01-31 16:11:21 -08001428 // No mobile provider DB available.
1429 capability_->SetHomeProvider();
Darin Petkovb4fccd22012-08-10 11:59:26 +02001430 EXPECT_TRUE(cellular_->home_provider().GetName().empty());
1431 EXPECT_TRUE(cellular_->home_provider().GetCountry().empty());
1432 EXPECT_TRUE(cellular_->home_provider().GetCode().empty());
Darin Petkovf508c822012-09-21 13:43:17 +02001433 EXPECT_FALSE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001434
1435 InitProviderDB();
Arman Ugurayd73783f2013-01-31 16:11:21 -08001436
1437 // IMSI and Operator Code not available.
1438 capability_->SetHomeProvider();
1439 EXPECT_TRUE(cellular_->home_provider().GetName().empty());
1440 EXPECT_TRUE(cellular_->home_provider().GetCountry().empty());
1441 EXPECT_TRUE(cellular_->home_provider().GetCode().empty());
1442 EXPECT_FALSE(capability_->provider_requires_roaming_);
1443
1444 // Operator Code available.
1445 capability_->operator_id_ = "310240";
1446 capability_->SetHomeProvider();
1447 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
1448 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
1449 EXPECT_EQ("310240", cellular_->home_provider().GetCode());
1450 EXPECT_EQ(4, capability_->apn_list_.size());
1451 ASSERT_TRUE(capability_->home_provider_);
1452 EXPECT_FALSE(capability_->provider_requires_roaming_);
1453
1454 cellular_->home_provider_.SetName("");
1455 cellular_->home_provider_.SetCountry("");
1456 cellular_->home_provider_.SetCode("");
1457
1458 // IMSI available
1459 capability_->imsi_ = "310240123456789";
1460 capability_->operator_id_.clear();
Darin Petkovb4fccd22012-08-10 11:59:26 +02001461 capability_->SetHomeProvider();
1462 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
1463 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
1464 EXPECT_EQ(kCode, cellular_->home_provider().GetCode());
1465 EXPECT_EQ(4, capability_->apn_list_.size());
1466 ASSERT_TRUE(capability_->home_provider_);
Darin Petkovf508c822012-09-21 13:43:17 +02001467 EXPECT_FALSE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001468
1469 Cellular::Operator oper;
1470 cellular_->set_home_provider(oper);
1471 capability_->spn_ = kTestCarrier;
1472 capability_->SetHomeProvider();
1473 EXPECT_EQ(kTestCarrier, cellular_->home_provider().GetName());
1474 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
1475 EXPECT_EQ(kCode, cellular_->home_provider().GetCode());
Darin Petkovf508c822012-09-21 13:43:17 +02001476 EXPECT_FALSE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001477
1478 static const char kCubic[] = "Cubic";
1479 capability_->spn_ = kCubic;
1480 capability_->SetHomeProvider();
1481 EXPECT_EQ(kCubic, cellular_->home_provider().GetName());
1482 EXPECT_EQ("", cellular_->home_provider().GetCode());
1483 ASSERT_TRUE(capability_->home_provider_);
Darin Petkovf508c822012-09-21 13:43:17 +02001484 EXPECT_TRUE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001485
1486 static const char kCUBIC[] = "CUBIC";
1487 capability_->spn_ = kCUBIC;
1488 capability_->home_provider_ = NULL;
1489 capability_->SetHomeProvider();
1490 EXPECT_EQ(kCUBIC, cellular_->home_provider().GetName());
1491 EXPECT_EQ("", cellular_->home_provider().GetCode());
1492 ASSERT_TRUE(capability_->home_provider_);
Darin Petkovf508c822012-09-21 13:43:17 +02001493 EXPECT_TRUE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001494}
1495
Arman Uguray1361c032013-02-11 17:53:39 -08001496TEST_F(CellularCapabilityUniversalMainTest, UpdateScanningProperty) {
Ben Chan8a2c01e2013-01-23 10:09:14 -08001497 // Save pointers to proxies before they are lost by the call to InitProxies
1498 // mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
1499 SetUp();
1500 //EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
1501 capability_->InitProxies();
1502
1503 EXPECT_FALSE(capability_->scanning_or_searching_);
1504 capability_->UpdateScanningProperty();
1505 EXPECT_FALSE(capability_->scanning_or_searching_);
1506
1507 capability_->scanning_ = true;
1508 capability_->UpdateScanningProperty();
1509 EXPECT_TRUE(capability_->scanning_or_searching_);
1510
1511 capability_->scanning_ = false;
1512 capability_->cellular()->modem_state_ = Cellular::kModemStateInitializing;
1513 capability_->UpdateScanningProperty();
1514 EXPECT_FALSE(capability_->scanning_or_searching_);
1515 capability_->cellular()->modem_state_ = Cellular::kModemStateLocked;
1516 capability_->UpdateScanningProperty();
1517 EXPECT_FALSE(capability_->scanning_or_searching_);
1518 capability_->cellular()->modem_state_ = Cellular::kModemStateDisabled;
1519 capability_->UpdateScanningProperty();
1520 EXPECT_FALSE(capability_->scanning_or_searching_);
1521 capability_->cellular()->modem_state_ = Cellular::kModemStateEnabling;
1522 capability_->UpdateScanningProperty();
1523 EXPECT_TRUE(capability_->scanning_or_searching_);
1524 capability_->cellular()->modem_state_ = Cellular::kModemStateEnabled;
1525 capability_->UpdateScanningProperty();
1526 EXPECT_TRUE(capability_->scanning_or_searching_);
1527 capability_->cellular()->modem_state_ = Cellular::kModemStateSearching;
1528 capability_->UpdateScanningProperty();
1529 EXPECT_TRUE(capability_->scanning_or_searching_);
1530 capability_->cellular()->modem_state_ = Cellular::kModemStateRegistered;
1531 capability_->UpdateScanningProperty();
1532 EXPECT_FALSE(capability_->scanning_or_searching_);
1533 capability_->cellular()->modem_state_ = Cellular::kModemStateConnecting;
1534 capability_->UpdateScanningProperty();
1535 EXPECT_FALSE(capability_->scanning_or_searching_);
1536 capability_->cellular()->modem_state_ = Cellular::kModemStateConnected;
1537 capability_->UpdateScanningProperty();
1538 EXPECT_FALSE(capability_->scanning_or_searching_);
1539 capability_->cellular()->modem_state_ = Cellular::kModemStateDisconnecting;
1540 capability_->UpdateScanningProperty();
1541 EXPECT_FALSE(capability_->scanning_or_searching_);
Ben Chane1e1e562013-01-26 00:39:01 -08001542
Ben Chan40a2f862013-02-13 17:44:38 -08001543 // Modem with an unactivated service in the 'enabled' or 'searching' state
1544 capability_->cellular()->modem_state_ = Cellular::kModemStateEnabled;
Ben Chane1e1e562013-01-26 00:39:01 -08001545 capability_->mdn_ = "0000000000";
Ben Chane1e1e562013-01-26 00:39:01 -08001546 CellularService::OLP olp;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001547 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
Ben Chan40a2f862013-02-13 17:44:38 -08001548 .WillRepeatedly(Return(&olp));
1549 capability_->UpdateScanningProperty();
1550 EXPECT_FALSE(capability_->scanning_or_searching_);
1551
1552 capability_->cellular()->modem_state_ = Cellular::kModemStateSearching;
Ben Chane1e1e562013-01-26 00:39:01 -08001553 capability_->UpdateScanningProperty();
1554 EXPECT_FALSE(capability_->scanning_or_searching_);
Ben Chan8a2c01e2013-01-23 10:09:14 -08001555}
1556
Arman Uguray1361c032013-02-11 17:53:39 -08001557TEST_F(CellularCapabilityUniversalTimerTest, UpdateScanningPropertyTimeout) {
1558 SetUp();
1559 capability_->InitProxies();
1560
1561 EXPECT_FALSE(capability_->scanning_or_searching_);
1562 EXPECT_TRUE(
1563 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1564 capability_->UpdateScanningProperty();
1565 EXPECT_FALSE(capability_->scanning_or_searching_);
1566 EXPECT_TRUE(
1567 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1568
1569 EXPECT_CALL(mock_dispatcher_,
1570 PostDelayedTask(
1571 _,
1572 CellularCapabilityUniversal::
1573 kDefaultScanningOrSearchingTimeoutMilliseconds));
1574
1575 capability_->scanning_ = true;
1576 capability_->UpdateScanningProperty();
1577 EXPECT_FALSE(
1578 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1579 EXPECT_TRUE(capability_->scanning_or_searching_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001580 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
Arman Uguray1361c032013-02-11 17:53:39 -08001581
1582 EXPECT_CALL(mock_dispatcher_,
1583 PostDelayedTask(
1584 _,
1585 CellularCapabilityUniversal::
1586 kDefaultScanningOrSearchingTimeoutMilliseconds))
1587 .Times(0);
1588
1589 capability_->scanning_ = false;
1590 capability_->UpdateScanningProperty();
1591 EXPECT_TRUE(
1592 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1593 EXPECT_FALSE(capability_->scanning_or_searching_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001594 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
Arman Uguray1361c032013-02-11 17:53:39 -08001595
1596 EXPECT_CALL(mock_dispatcher_,
1597 PostDelayedTask(
1598 _,
1599 CellularCapabilityUniversal::
1600 kDefaultScanningOrSearchingTimeoutMilliseconds))
1601 .WillOnce(InvokeWithoutArgs(
1602 this,
1603 &CellularCapabilityUniversalTest::InvokeScanningOrSearchingTimeout));
1604
1605 capability_->scanning_ = true;
1606 capability_->UpdateScanningProperty();
1607 // The callback has been scheduled
1608 EXPECT_FALSE(
1609 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1610 // Our mock invocation worked
1611 EXPECT_FALSE(capability_->scanning_or_searching_);
1612}
1613
1614TEST_F(CellularCapabilityUniversalMainTest, UpdateStorageIdentifier) {
Arman Ugurayc9533572013-01-22 17:34:20 -08001615 CellularOperatorInfo::CellularOperator provider;
Arman Ugurayc9533572013-01-22 17:34:20 -08001616
1617 SetService();
1618
1619 const string prefix = "cellular_" + string(kMachineAddress) + "_";
Arman Uguray2717a102013-01-29 23:36:06 -08001620 string default_identifier_pattern =
1621 prefix + string(CellularCapabilityUniversal::kGenericServiceNamePrefix);
1622 std::replace_if(default_identifier_pattern.begin(),
1623 default_identifier_pattern.end(),
1624 &Service::IllegalChar, '_');
1625 default_identifier_pattern += "*";
Arman Ugurayc9533572013-01-22 17:34:20 -08001626
1627 // |capability_->operator_id_| is "".
1628 capability_->UpdateStorageIdentifier();
1629 EXPECT_TRUE(::MatchPattern(cellular_->service()->storage_identifier_,
1630 default_identifier_pattern));
1631
1632 // GetCellularOperatorByMCCMNC returns NULL.
1633 capability_->operator_id_ = "1";
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001634 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Arman Ugurayc9533572013-01-22 17:34:20 -08001635 GetCellularOperatorByMCCMNC(capability_->operator_id_))
1636 .WillOnce(
1637 Return((const CellularOperatorInfo::CellularOperator *)NULL));
1638
1639 capability_->UpdateStorageIdentifier();
1640 EXPECT_TRUE(::MatchPattern(cellular_->service()->storage_identifier_,
1641 default_identifier_pattern));
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001642 Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info());
Arman Ugurayc9533572013-01-22 17:34:20 -08001643
1644 // |capability_->imsi_| is not ""
1645 capability_->imsi_ = "TESTIMSI";
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001646 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Arman Ugurayc9533572013-01-22 17:34:20 -08001647 GetCellularOperatorByMCCMNC(capability_->operator_id_))
1648 .WillOnce(
1649 Return((const CellularOperatorInfo::CellularOperator *)NULL));
1650
1651 capability_->UpdateStorageIdentifier();
1652 EXPECT_EQ(prefix + "TESTIMSI", cellular_->service()->storage_identifier_);
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001653 Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info());
Arman Ugurayc9533572013-01-22 17:34:20 -08001654
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001655 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Arman Ugurayc9533572013-01-22 17:34:20 -08001656 GetCellularOperatorByMCCMNC(capability_->operator_id_))
1657 .Times(2)
1658 .WillRepeatedly(Return(&provider));
1659
1660 // |provider.identifier_| is "".
1661 capability_->UpdateStorageIdentifier();
1662 EXPECT_EQ(prefix + "TESTIMSI", cellular_->service()->storage_identifier_);
1663
1664 // Success.
1665 provider.identifier_ = "testidentifier";
1666 capability_->UpdateStorageIdentifier();
1667 EXPECT_EQ(prefix + "testidentifier",
1668 cellular_->service()->storage_identifier_);
1669}
1670
Ben Chan07193fd2013-07-12 22:10:55 -07001671TEST_F(CellularCapabilityUniversalMainTest, GetMdnForOLP) {
1672 CellularOperatorInfo::CellularOperator cellular_operator;
1673
1674 cellular_operator.identifier_ = "vzw";
1675 capability_->mdn_ = "";
1676 EXPECT_EQ("", capability_->GetMdnForOLP(cellular_operator));
1677 capability_->mdn_ = "0123456789";
1678 EXPECT_EQ("0123456789", capability_->GetMdnForOLP(cellular_operator));
1679 capability_->mdn_ = "10123456789";
1680 EXPECT_EQ("0123456789", capability_->GetMdnForOLP(cellular_operator));
1681
1682 cellular_operator.identifier_ = "foo";
1683 capability_->mdn_ = "";
1684 EXPECT_EQ("", capability_->GetMdnForOLP(cellular_operator));
1685 capability_->mdn_ = "0123456789";
1686 EXPECT_EQ("0123456789", capability_->GetMdnForOLP(cellular_operator));
1687 capability_->mdn_ = "10123456789";
1688 EXPECT_EQ("10123456789", capability_->GetMdnForOLP(cellular_operator));
1689}
1690
Arman Uguray1361c032013-02-11 17:53:39 -08001691TEST_F(CellularCapabilityUniversalMainTest, UpdateOLP) {
Ben Chan07193fd2013-07-12 22:10:55 -07001692 CellularOperatorInfo::CellularOperator cellular_operator;
1693
Ben Chan6d0d1e72012-11-06 21:19:28 -08001694 CellularService::OLP test_olp;
1695 test_olp.SetURL("http://testurl");
1696 test_olp.SetMethod("POST");
Arman Uguray72fab6a2013-01-10 19:32:42 -08001697 test_olp.SetPostData("imei=${imei}&imsi=${imsi}&mdn=${mdn}&"
1698 "min=${min}&iccid=${iccid}");
Ben Chan6d0d1e72012-11-06 21:19:28 -08001699
Ben Chan6d0d1e72012-11-06 21:19:28 -08001700 capability_->imei_ = "1";
1701 capability_->imsi_ = "2";
Ben Chan07193fd2013-07-12 22:10:55 -07001702 capability_->mdn_ = "10123456789";
Ben Chan6d0d1e72012-11-06 21:19:28 -08001703 capability_->min_ = "5";
1704 capability_->sim_identifier_ = "6";
1705 capability_->operator_id_ = "123456";
Ben Chan6d0d1e72012-11-06 21:19:28 -08001706
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001707 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Ben Chan07193fd2013-07-12 22:10:55 -07001708 GetCellularOperatorByMCCMNC(capability_->operator_id_))
1709 .WillRepeatedly(Return(&cellular_operator));
1710 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Arman Ugurayf4c61812013-01-10 18:58:39 -08001711 GetOLPByMCCMNC(capability_->operator_id_))
1712 .WillRepeatedly(Return(&test_olp));
Ben Chan6d0d1e72012-11-06 21:19:28 -08001713
1714 SetService();
Ben Chan07193fd2013-07-12 22:10:55 -07001715 cellular_operator.identifier_ = "vzw";
1716 capability_->UpdateOLP();
1717 const CellularService::OLP &vzw_olp = cellular_->service()->olp();
1718 EXPECT_EQ("http://testurl", vzw_olp.GetURL());
1719 EXPECT_EQ("POST", vzw_olp.GetMethod());
1720 EXPECT_EQ("imei=1&imsi=2&mdn=0123456789&min=5&iccid=6",
1721 vzw_olp.GetPostData());
1722
1723 cellular_operator.identifier_ = "foo";
Ben Chan6d0d1e72012-11-06 21:19:28 -08001724 capability_->UpdateOLP();
1725 const CellularService::OLP &olp = cellular_->service()->olp();
1726 EXPECT_EQ("http://testurl", olp.GetURL());
1727 EXPECT_EQ("POST", olp.GetMethod());
Ben Chan07193fd2013-07-12 22:10:55 -07001728 EXPECT_EQ("imei=1&imsi=2&mdn=10123456789&min=5&iccid=6",
Ben Chan6d0d1e72012-11-06 21:19:28 -08001729 olp.GetPostData());
1730}
1731
Arman Ugurayc7b15602013-02-16 00:56:18 -08001732TEST_F(CellularCapabilityUniversalMainTest, IsMdnValid) {
1733 capability_->mdn_.clear();
1734 EXPECT_FALSE(capability_->IsMdnValid());
1735 capability_->mdn_ = "0000000";
1736 EXPECT_FALSE(capability_->IsMdnValid());
1737 capability_->mdn_ = "0000001";
1738 EXPECT_TRUE(capability_->IsMdnValid());
1739 capability_->mdn_ = "1231223";
1740 EXPECT_TRUE(capability_->IsMdnValid());
1741}
1742
Arman Uguraya14941d2013-04-12 16:58:26 -07001743TEST_F(CellularCapabilityUniversalTimerTest, CompleteActivation) {
Arman Ugurayefea6e02013-02-21 13:28:04 -08001744 const char kIccid[] = "1234567";
1745
1746 capability_->mdn_.clear();
1747 capability_->sim_identifier_.clear();
Arman Ugurayefea6e02013-02-21 13:28:04 -08001748
Arman Ugurayefea6e02013-02-21 13:28:04 -08001749 EXPECT_CALL(*service_,
1750 SetActivationState(flimflam::kActivationStateActivating))
1751 .Times(0);
Arman Uguray41cc6342013-03-29 16:34:39 -07001752 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1753 SetActivationState(
1754 PendingActivationStore::kIdentifierICCID, _, _))
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001755 .Times(0);
Arman Uguraya14941d2013-04-12 16:58:26 -07001756 EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(0);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001757 Error error;
1758 capability_->CompleteActivation(&error);
Arman Uguray41cc6342013-03-29 16:34:39 -07001759 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001760 Mock::VerifyAndClearExpectations(service_);
Arman Uguraya14941d2013-04-12 16:58:26 -07001761 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
1762 EXPECT_TRUE(
1763 capability_->activation_wait_for_registration_callback_.IsCancelled());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001764
1765 capability_->sim_identifier_ = kIccid;
Arman Uguray41cc6342013-03-29 16:34:39 -07001766 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1767 SetActivationState(PendingActivationStore::kIdentifierICCID,
1768 kIccid,
1769 PendingActivationStore::kStatePending))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001770 .Times(1);
1771 EXPECT_CALL(*service_,
1772 SetActivationState(flimflam::kActivationStateActivating))
1773 .Times(1);
Arman Uguraya14941d2013-04-12 16:58:26 -07001774 EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(1);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001775 capability_->CompleteActivation(&error);
Arman Uguray41cc6342013-03-29 16:34:39 -07001776 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001777 Mock::VerifyAndClearExpectations(service_);
Arman Uguraya14941d2013-04-12 16:58:26 -07001778 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
1779 EXPECT_FALSE(
1780 capability_->activation_wait_for_registration_callback_.IsCancelled());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001781
Arman Uguray41cc6342013-03-29 16:34:39 -07001782 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1783 SetActivationState(PendingActivationStore::kIdentifierICCID,
1784 kIccid,
1785 PendingActivationStore::kStatePending))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001786 .Times(0);
1787 EXPECT_CALL(*service_,
1788 SetActivationState(flimflam::kActivationStateActivating))
1789 .Times(0);
Arman Uguraya14941d2013-04-12 16:58:26 -07001790 EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(0);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001791 capability_->mdn_ = "1231231212";
1792 capability_->CompleteActivation(&error);
1793}
1794
1795TEST_F(CellularCapabilityUniversalMainTest, UpdateServiceActivationState) {
1796 const char kIccid[] = "1234567";
Arman Ugurayefea6e02013-02-21 13:28:04 -08001797 capability_->sim_identifier_.clear();
1798 capability_->mdn_ = "0000000000";
Arman Ugurayefea6e02013-02-21 13:28:04 -08001799 CellularService::OLP olp;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001800 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001801 .WillRepeatedly(Return(&olp));
1802
Arman Uguray6bb252d2013-05-15 14:29:53 -07001803 service_->SetAutoConnect(false);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001804 EXPECT_CALL(*service_,
1805 SetActivationState(flimflam::kActivationStateNotActivated))
1806 .Times(1);
1807 capability_->UpdateServiceActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001808 Mock::VerifyAndClearExpectations(service_);
Arman Uguray6bb252d2013-05-15 14:29:53 -07001809 EXPECT_FALSE(service_->auto_connect());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001810
1811 capability_->mdn_ = "1231231122";
1812 EXPECT_CALL(*service_,
1813 SetActivationState(flimflam::kActivationStateActivated))
1814 .Times(1);
1815 capability_->UpdateServiceActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001816 Mock::VerifyAndClearExpectations(service_);
Arman Uguray6bb252d2013-05-15 14:29:53 -07001817 EXPECT_TRUE(service_->auto_connect());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001818
Arman Uguray6bb252d2013-05-15 14:29:53 -07001819 service_->SetAutoConnect(false);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001820 capability_->mdn_ = "0000000000";
1821 capability_->sim_identifier_ = kIccid;
Arman Uguray41cc6342013-03-29 16:34:39 -07001822 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1823 GetActivationState(PendingActivationStore::kIdentifierICCID,
1824 kIccid))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001825 .Times(2)
Arman Uguray41cc6342013-03-29 16:34:39 -07001826 .WillOnce(Return(PendingActivationStore::kStatePending))
1827 .WillOnce(Return(PendingActivationStore::kStatePendingTimeout));
Arman Ugurayefea6e02013-02-21 13:28:04 -08001828 EXPECT_CALL(*service_,
1829 SetActivationState(flimflam::kActivationStateActivating))
1830 .Times(1);
1831 capability_->UpdateServiceActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001832 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001833 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguray6bb252d2013-05-15 14:29:53 -07001834 EXPECT_FALSE(service_->auto_connect());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001835
Arman Uguray41cc6342013-03-29 16:34:39 -07001836 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1837 GetActivationState(PendingActivationStore::kIdentifierICCID,
1838 kIccid))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001839 .Times(2)
Arman Uguray41cc6342013-03-29 16:34:39 -07001840 .WillRepeatedly(Return(PendingActivationStore::kStateActivated));
Arman Ugurayefea6e02013-02-21 13:28:04 -08001841 EXPECT_CALL(*service_,
1842 SetActivationState(flimflam::kActivationStateActivated))
1843 .Times(1);
1844 capability_->UpdateServiceActivationState();
Arman Uguray6bb252d2013-05-15 14:29:53 -07001845 Mock::VerifyAndClearExpectations(service_);
1846 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
1847 EXPECT_TRUE(service_->auto_connect());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001848}
1849
Arman Uguraya14941d2013-04-12 16:58:26 -07001850TEST_F(CellularCapabilityUniversalMainTest, ActivationWaitForRegisterTimeout) {
1851 const char kIccid[] = "1234567";
1852
1853 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
1854 capability_->InitProxies();
Arman Uguray41cc6342013-03-29 16:34:39 -07001855 EXPECT_CALL(*modem_proxy, Reset(_, _, _)).Times(0);
1856 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1857 SetActivationState(_, _, _))
Arman Uguraya14941d2013-04-12 16:58:26 -07001858 .Times(0);
1859
1860 // No ICCID, no MDN
1861 capability_->sim_identifier_.clear();
1862 capability_->mdn_.clear();
1863 capability_->reset_done_ = false;
1864 capability_->OnActivationWaitForRegisterTimeout();
1865
1866 // State is not activated.
1867 capability_->sim_identifier_ = kIccid;
Arman Uguray41cc6342013-03-29 16:34:39 -07001868 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1869 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
1870 .WillOnce(Return(PendingActivationStore::kStateActivated))
1871 .WillRepeatedly(Return(PendingActivationStore::kStatePending));
Arman Uguraya14941d2013-04-12 16:58:26 -07001872 capability_->OnActivationWaitForRegisterTimeout();
1873
1874 // Valid MDN.
1875 capability_->mdn_ = "0000000001";
1876 capability_->OnActivationWaitForRegisterTimeout();
1877
1878 // Invalid MDN, reset done.
1879 capability_->mdn_ = "0000000000";
1880 capability_->reset_done_ = true;
1881 capability_->OnActivationWaitForRegisterTimeout();
1882
1883 Mock::VerifyAndClearExpectations(modem_proxy);
Arman Uguray41cc6342013-03-29 16:34:39 -07001884 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07001885
1886 // Reset not done.
1887 capability_->reset_done_ = false;
1888 EXPECT_CALL(*modem_proxy, Reset(_,_,_)).Times(1);
Arman Uguray41cc6342013-03-29 16:34:39 -07001889 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1890 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
1891 .WillOnce(Return(PendingActivationStore::kStatePending));
1892 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1893 SetActivationState(PendingActivationStore::kIdentifierICCID,
1894 kIccid,
1895 PendingActivationStore::kStatePendingTimeout))
Arman Uguraya14941d2013-04-12 16:58:26 -07001896 .Times(1);
1897 capability_->OnActivationWaitForRegisterTimeout();
1898}
1899
Arman Uguray0a3e2792013-01-17 16:31:50 -08001900TEST_F(CellularCapabilityUniversalMainTest, UpdatePendingActivationState) {
Arman Ugurayc7b15602013-02-16 00:56:18 -08001901 const char kIccid[] = "1234567";
1902
1903 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001904 capability_->InitProxies();
1905 capability_->registration_state_ =
1906 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING;
1907
1908 // No MDN, no ICCID.
1909 capability_->mdn_ = "0000000";
1910 capability_->sim_identifier_.clear();
Arman Uguray41cc6342013-03-29 16:34:39 -07001911 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1912 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001913 .Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001914 capability_->UpdatePendingActivationState();
Arman Uguray41cc6342013-03-29 16:34:39 -07001915 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001916
1917 // ICCID known.
1918 capability_->sim_identifier_ = kIccid;
1919
1920 // After the modem has reset.
1921 capability_->reset_done_ = true;
Arman Uguray41cc6342013-03-29 16:34:39 -07001922 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1923 GetActivationState(PendingActivationStore::kIdentifierICCID,
1924 kIccid))
1925 .Times(1).WillOnce(Return(PendingActivationStore::kStatePending));
1926 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1927 SetActivationState(PendingActivationStore::kIdentifierICCID,
1928 kIccid,
1929 PendingActivationStore::kStateActivated))
Arman Ugurayc7b15602013-02-16 00:56:18 -08001930 .Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001931 capability_->UpdatePendingActivationState();
Arman Uguray41cc6342013-03-29 16:34:39 -07001932 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001933
1934 // Before reset, not registered.
1935 capability_->reset_done_ = false;
Arman Uguray41cc6342013-03-29 16:34:39 -07001936 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1937 GetActivationState(PendingActivationStore::kIdentifierICCID,
1938 kIccid))
1939 .Times(2).WillRepeatedly(Return(PendingActivationStore::kStatePending));
Arman Ugurayefea6e02013-02-21 13:28:04 -08001940 EXPECT_CALL(*service_,
1941 SetActivationState(flimflam::kActivationStateActivating))
1942 .Times(2);
Arman Ugurayc7b15602013-02-16 00:56:18 -08001943 EXPECT_CALL(*modem_proxy, Reset(_, _, _)).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001944 capability_->UpdatePendingActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001945 Mock::VerifyAndClearExpectations(modem_proxy);
Arman Ugurayc7b15602013-02-16 00:56:18 -08001946
1947 // Before reset, registered.
1948 capability_->registration_state_ =
1949 MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
1950 EXPECT_CALL(*modem_proxy, Reset(_, _, _)).Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001951 capability_->UpdatePendingActivationState();
Arman Uguray41cc6342013-03-29 16:34:39 -07001952 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001953
1954 // Not registered.
1955 capability_->registration_state_ =
1956 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING;
Arman Uguray41cc6342013-03-29 16:34:39 -07001957 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1958 GetActivationState(PendingActivationStore::kIdentifierICCID,
1959 kIccid))
1960 .Times(2).WillRepeatedly(Return(PendingActivationStore::kStateActivated));
Arman Ugurayc7b15602013-02-16 00:56:18 -08001961 EXPECT_CALL(*service_, AutoConnect()).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001962 capability_->UpdatePendingActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001963 Mock::VerifyAndClearExpectations(service_);
Arman Ugurayc7b15602013-02-16 00:56:18 -08001964
1965 // Service, registered.
1966 capability_->registration_state_ =
1967 MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
1968 EXPECT_CALL(*service_, AutoConnect()).Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001969 capability_->UpdatePendingActivationState();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001970
1971 cellular_->service_->activation_state_ =
1972 flimflam::kActivationStateNotActivated;
1973
Arman Uguray41cc6342013-03-29 16:34:39 -07001974 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07001975
Arman Ugurayc7b15602013-02-16 00:56:18 -08001976 // Device is connected.
1977 cellular_->state_ = Cellular::kStateConnected;
1978 EXPECT_CALL(*service_,
1979 SetActivationState(flimflam::kActivationStateActivated))
1980 .Times(3);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001981 capability_->UpdatePendingActivationState();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001982
1983 // Device is linked.
1984 cellular_->state_ = Cellular::kStateLinked;
Arman Uguray0a3e2792013-01-17 16:31:50 -08001985 capability_->UpdatePendingActivationState();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001986
1987 // Got valid MDN.
1988 cellular_->state_ = Cellular::kStateRegistered;
1989 capability_->mdn_ = "1231223";
Arman Uguray41cc6342013-03-29 16:34:39 -07001990 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1991 RemoveEntry(PendingActivationStore::kIdentifierICCID, kIccid))
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001992 .Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001993 capability_->UpdatePendingActivationState();
Arman Uguraya14941d2013-04-12 16:58:26 -07001994
1995 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001996 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07001997
1998 // Timed out, not registered.
1999 capability_->mdn_.clear();
Arman Uguray41cc6342013-03-29 16:34:39 -07002000 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
2001 GetActivationState(PendingActivationStore::kIdentifierICCID,
2002 kIccid))
Arman Uguraya14941d2013-04-12 16:58:26 -07002003 .Times(1)
Arman Uguray41cc6342013-03-29 16:34:39 -07002004 .WillOnce(Return(PendingActivationStore::kStatePendingTimeout));
Arman Uguraya14941d2013-04-12 16:58:26 -07002005 capability_->registration_state_ =
2006 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING;
Arman Uguray41cc6342013-03-29 16:34:39 -07002007 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
2008 SetActivationState(_, _, _))
Arman Uguraya14941d2013-04-12 16:58:26 -07002009 .Times(0);
2010 EXPECT_CALL(*service_, SetActivationState(_)).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08002011 capability_->UpdatePendingActivationState();
Arman Uguraya14941d2013-04-12 16:58:26 -07002012 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07002013 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07002014
2015 // Timed out, registered.
Arman Uguray41cc6342013-03-29 16:34:39 -07002016 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
2017 GetActivationState(PendingActivationStore::kIdentifierICCID,
2018 kIccid))
Arman Uguraya14941d2013-04-12 16:58:26 -07002019 .Times(1)
Arman Uguray41cc6342013-03-29 16:34:39 -07002020 .WillOnce(Return(PendingActivationStore::kStatePendingTimeout));
Arman Uguraya14941d2013-04-12 16:58:26 -07002021 capability_->registration_state_ =
2022 MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
Arman Uguray41cc6342013-03-29 16:34:39 -07002023 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
2024 SetActivationState(PendingActivationStore::kIdentifierICCID,
2025 kIccid,
2026 PendingActivationStore::kStateActivated))
Arman Uguraya14941d2013-04-12 16:58:26 -07002027 .Times(1);
2028 EXPECT_CALL(*service_,
2029 SetActivationState(flimflam::kActivationStateActivated))
2030 .Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08002031 capability_->UpdatePendingActivationState();
Arman Uguraya14941d2013-04-12 16:58:26 -07002032 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07002033 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08002034}
2035
Arman Uguray1361c032013-02-11 17:53:39 -08002036TEST_F(CellularCapabilityUniversalMainTest, UpdateOperatorInfo) {
Darin Petkova4ca3c32012-08-17 16:05:24 +02002037 static const char kOperatorName[] = "Swisscom";
2038 InitProviderDB();
2039 capability_->serving_operator_.SetCode("22801");
2040 SetService();
2041 capability_->UpdateOperatorInfo();
2042 EXPECT_EQ(kOperatorName, capability_->serving_operator_.GetName());
2043 EXPECT_EQ("ch", capability_->serving_operator_.GetCountry());
2044 EXPECT_EQ(kOperatorName, cellular_->service()->serving_operator().GetName());
2045
2046 static const char kTestOperator[] = "Testcom";
2047 capability_->serving_operator_.SetName(kTestOperator);
2048 capability_->serving_operator_.SetCountry("");
2049 capability_->UpdateOperatorInfo();
2050 EXPECT_EQ(kTestOperator, capability_->serving_operator_.GetName());
2051 EXPECT_EQ("ch", capability_->serving_operator_.GetCountry());
2052 EXPECT_EQ(kTestOperator, cellular_->service()->serving_operator().GetName());
2053}
2054
Arman Uguray1361c032013-02-11 17:53:39 -08002055TEST_F(CellularCapabilityUniversalMainTest, UpdateOperatorInfoViaOperatorId) {
Ben Chan092b12b2012-11-07 22:04:05 -08002056 static const char kOperatorName[] = "Swisscom";
2057 static const char kOperatorId[] = "22801";
2058 InitProviderDB();
2059 capability_->serving_operator_.SetCode("");
2060 SetService();
2061 capability_->UpdateOperatorInfo();
2062 EXPECT_EQ("", capability_->serving_operator_.GetName());
2063 EXPECT_EQ("", capability_->serving_operator_.GetCountry());
2064 EXPECT_EQ("", cellular_->service()->serving_operator().GetName());
2065
2066 capability_->operator_id_ = kOperatorId;
2067
Ben Chan092b12b2012-11-07 22:04:05 -08002068 capability_->UpdateOperatorInfo();
2069 EXPECT_EQ(kOperatorId, capability_->serving_operator_.GetCode());
2070 EXPECT_EQ(kOperatorName, capability_->serving_operator_.GetName());
2071 EXPECT_EQ("ch", capability_->serving_operator_.GetCountry());
2072 EXPECT_EQ(kOperatorName, cellular_->service()->serving_operator().GetName());
2073}
2074
Arman Uguray1361c032013-02-11 17:53:39 -08002075TEST_F(CellularCapabilityUniversalMainTest, CreateFriendlyServiceName) {
Darin Petkova4ca3c32012-08-17 16:05:24 +02002076 CellularCapabilityUniversal::friendly_service_name_id_ = 0;
Arman Uguray2717a102013-01-29 23:36:06 -08002077 EXPECT_EQ("Mobile Network 0", capability_->CreateFriendlyServiceName());
2078 EXPECT_EQ("Mobile Network 1", capability_->CreateFriendlyServiceName());
Darin Petkova4ca3c32012-08-17 16:05:24 +02002079
Ben Chan092b12b2012-11-07 22:04:05 -08002080 capability_->operator_id_ = "0123";
Ben Chan092b12b2012-11-07 22:04:05 -08002081 EXPECT_EQ("cellular_0123", capability_->CreateFriendlyServiceName());
2082 EXPECT_EQ("0123", capability_->serving_operator_.GetCode());
2083
Darin Petkova4ca3c32012-08-17 16:05:24 +02002084 capability_->serving_operator_.SetCode("1234");
2085 EXPECT_EQ("cellular_1234", capability_->CreateFriendlyServiceName());
2086
2087 static const char kHomeProvider[] = "The GSM Home Provider";
2088 cellular_->home_provider_.SetName(kHomeProvider);
2089 EXPECT_EQ("cellular_1234", capability_->CreateFriendlyServiceName());
2090 capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
2091 EXPECT_EQ(kHomeProvider, capability_->CreateFriendlyServiceName());
2092
2093 static const char kTestOperator[] = "A GSM Operator";
2094 capability_->serving_operator_.SetName(kTestOperator);
2095 EXPECT_EQ(kTestOperator, capability_->CreateFriendlyServiceName());
2096
2097 capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING;
2098 EXPECT_EQ(StringPrintf("%s | %s", kHomeProvider, kTestOperator),
2099 capability_->CreateFriendlyServiceName());
2100}
2101
Arman Uguray1361c032013-02-11 17:53:39 -08002102TEST_F(CellularCapabilityUniversalMainTest, IsServiceActivationRequired) {
Ben Chan15786032012-11-04 21:28:02 -08002103 capability_->mdn_ = "0000000000";
Ben Chan15786032012-11-04 21:28:02 -08002104 EXPECT_FALSE(capability_->IsServiceActivationRequired());
2105
Arman Ugurayf4c61812013-01-10 18:58:39 -08002106 CellularService::OLP olp;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07002107 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
Arman Ugurayf4c61812013-01-10 18:58:39 -08002108 .WillOnce(Return((const CellularService::OLP *)NULL))
2109 .WillRepeatedly(Return(&olp));
Ben Chan15786032012-11-04 21:28:02 -08002110 EXPECT_FALSE(capability_->IsServiceActivationRequired());
2111
2112 capability_->mdn_ = "";
2113 EXPECT_FALSE(capability_->IsServiceActivationRequired());
2114 capability_->mdn_ = "1234567890";
2115 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Ben Chan15786032012-11-04 21:28:02 -08002116 capability_->mdn_ = "0000000000";
2117 EXPECT_TRUE(capability_->IsServiceActivationRequired());
Arman Ugurayefea6e02013-02-21 13:28:04 -08002118
2119 const char kIccid[] = "1234567890";
2120 capability_->sim_identifier_ = kIccid;
Arman Uguray41cc6342013-03-29 16:34:39 -07002121 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
2122 GetActivationState(PendingActivationStore::kIdentifierICCID,
2123 kIccid))
2124 .WillOnce(Return(PendingActivationStore::kStateActivated))
2125 .WillOnce(Return(PendingActivationStore::kStatePending))
2126 .WillOnce(Return(PendingActivationStore::kStatePendingTimeout))
2127 .WillOnce(Return(PendingActivationStore::kStateUnknown));
Arman Ugurayefea6e02013-02-21 13:28:04 -08002128 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Arman Uguraya14941d2013-04-12 16:58:26 -07002129 EXPECT_FALSE(capability_->IsServiceActivationRequired());
2130 EXPECT_FALSE(capability_->IsServiceActivationRequired());
2131 EXPECT_TRUE(capability_->IsServiceActivationRequired());
Arman Uguray41cc6342013-03-29 16:34:39 -07002132 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Ben Chan15786032012-11-04 21:28:02 -08002133}
2134
Arman Uguray1361c032013-02-11 17:53:39 -08002135TEST_F(CellularCapabilityUniversalMainTest, OnModemCurrentCapabilitiesChanged) {
Ben Chanfcca27b2013-01-22 15:03:44 -08002136 EXPECT_FALSE(capability_->scanning_supported_);
2137 capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_LTE);
2138 EXPECT_FALSE(capability_->scanning_supported_);
2139 capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_CDMA_EVDO);
2140 EXPECT_FALSE(capability_->scanning_supported_);
2141 capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_GSM_UMTS);
2142 EXPECT_TRUE(capability_->scanning_supported_);
2143 capability_->OnModemCurrentCapabilitiesChanged(
2144 MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_CDMA_EVDO);
2145 EXPECT_TRUE(capability_->scanning_supported_);
2146}
2147
Arman Uguray7af0fac2013-03-18 17:35:35 -07002148TEST_F(CellularCapabilityUniversalMainTest, GetNetworkTechnologyStringOnE362) {
2149 capability_->model_id_.clear();
2150 capability_->access_technologies_ = 0;
2151 EXPECT_TRUE(capability_->GetNetworkTechnologyString().empty());
2152
2153 capability_->model_id_ = CellularCapabilityUniversal::kE362ModelId;
2154 EXPECT_EQ(flimflam::kNetworkTechnologyLte,
2155 capability_->GetNetworkTechnologyString());
2156
2157 capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_GPRS;
2158 EXPECT_EQ(flimflam::kNetworkTechnologyLte,
2159 capability_->GetNetworkTechnologyString());
2160
2161 capability_->model_id_.clear();
2162 EXPECT_EQ(flimflam::kNetworkTechnologyGprs,
2163 capability_->GetNetworkTechnologyString());
2164}
2165
Arman Ugurayf84a4242013-04-09 20:01:07 -07002166TEST_F(CellularCapabilityUniversalMainTest, ShouldDetectOutOfCredit) {
Arman Ugurayd42d8ec2013-04-08 19:28:21 -07002167 capability_->model_id_.clear();
Arman Ugurayf84a4242013-04-09 20:01:07 -07002168 EXPECT_FALSE(capability_->ShouldDetectOutOfCredit());
Arman Ugurayd42d8ec2013-04-08 19:28:21 -07002169 capability_->model_id_ = CellularCapabilityUniversal::kE362ModelId;
Arman Ugurayf84a4242013-04-09 20:01:07 -07002170 EXPECT_TRUE(capability_->ShouldDetectOutOfCredit());
Arman Ugurayd42d8ec2013-04-08 19:28:21 -07002171}
2172
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002173TEST_F(CellularCapabilityUniversalMainTest, SimLockStatusToProperty) {
2174 Error error;
2175 KeyValueStore store = capability_->SimLockStatusToProperty(&error);
2176 EXPECT_FALSE(store.GetBool(flimflam::kSIMLockEnabledProperty));
2177 EXPECT_TRUE(store.GetString(flimflam::kSIMLockTypeProperty).empty());
2178 EXPECT_EQ(0, store.GetUint(flimflam::kSIMLockRetriesLeftProperty));
2179
2180 capability_->sim_lock_status_.enabled = true;
2181 capability_->sim_lock_status_.retries_left = 3;
2182 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN;
2183 store = capability_->SimLockStatusToProperty(&error);
2184 EXPECT_TRUE(store.GetBool(flimflam::kSIMLockEnabledProperty));
2185 EXPECT_EQ("sim-pin", store.GetString(flimflam::kSIMLockTypeProperty));
2186 EXPECT_EQ(3, store.GetUint(flimflam::kSIMLockRetriesLeftProperty));
2187
2188 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK;
2189 store = capability_->SimLockStatusToProperty(&error);
2190 EXPECT_EQ("sim-puk", store.GetString(flimflam::kSIMLockTypeProperty));
2191
2192 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN2;
2193 store = capability_->SimLockStatusToProperty(&error);
2194 EXPECT_TRUE(store.GetString(flimflam::kSIMLockTypeProperty).empty());
2195
2196 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK2;
2197 store = capability_->SimLockStatusToProperty(&error);
2198 EXPECT_TRUE(store.GetString(flimflam::kSIMLockTypeProperty).empty());
2199}
2200
2201TEST_F(CellularCapabilityUniversalMainTest, OnLockRetriesChanged) {
2202 CellularCapabilityUniversal::LockRetryData data;
2203 const uint32 kDefaultRetries = 999;
2204
2205 capability_->OnLockRetriesChanged(data);
2206 EXPECT_EQ(kDefaultRetries, capability_->sim_lock_status_.retries_left);
2207
2208 data[MM_MODEM_LOCK_SIM_PIN] = 3;
Arman Ugurayea5ff272013-06-25 10:28:02 -07002209 data[MM_MODEM_LOCK_SIM_PUK] = 10;
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002210 capability_->OnLockRetriesChanged(data);
Arman Uguray192ad822013-06-13 19:49:16 -07002211 EXPECT_EQ(3, capability_->sim_lock_status_.retries_left);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002212
Arman Ugurayea5ff272013-06-25 10:28:02 -07002213 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK;
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002214 capability_->OnLockRetriesChanged(data);
Arman Ugurayea5ff272013-06-25 10:28:02 -07002215 EXPECT_EQ(10, capability_->sim_lock_status_.retries_left);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002216
2217 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN;
2218 capability_->OnLockRetriesChanged(data);
2219 EXPECT_EQ(3, capability_->sim_lock_status_.retries_left);
Arman Uguray192ad822013-06-13 19:49:16 -07002220
2221 data.clear();
2222 capability_->OnLockRetriesChanged(data);
2223 EXPECT_EQ(kDefaultRetries, capability_->sim_lock_status_.retries_left);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002224}
2225
2226TEST_F(CellularCapabilityUniversalMainTest, OnLockTypeChanged) {
2227 EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type);
2228
2229 capability_->OnLockTypeChanged(MM_MODEM_LOCK_NONE);
2230 EXPECT_EQ(MM_MODEM_LOCK_NONE, capability_->sim_lock_status_.lock_type);
Arman Uguray4ef02fd2013-06-13 20:14:20 -07002231 EXPECT_FALSE(capability_->sim_lock_status_.enabled);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002232
2233 capability_->OnLockTypeChanged(MM_MODEM_LOCK_SIM_PIN);
2234 EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type);
Arman Uguray4ef02fd2013-06-13 20:14:20 -07002235 EXPECT_TRUE(capability_->sim_lock_status_.enabled);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002236
Arman Uguray4ef02fd2013-06-13 20:14:20 -07002237 capability_->sim_lock_status_.enabled = false;
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002238 capability_->OnLockTypeChanged(MM_MODEM_LOCK_SIM_PUK);
2239 EXPECT_EQ(MM_MODEM_LOCK_SIM_PUK, capability_->sim_lock_status_.lock_type);
Arman Uguray4ef02fd2013-06-13 20:14:20 -07002240 EXPECT_TRUE(capability_->sim_lock_status_.enabled);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002241}
2242
2243TEST_F(CellularCapabilityUniversalMainTest, OnSimLockPropertiesChanged) {
2244 EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type);
2245 EXPECT_EQ(0, capability_->sim_lock_status_.retries_left);
2246
2247 DBusPropertiesMap changed;
2248 vector<string> invalidated;
2249
2250 capability_->OnModemPropertiesChanged(changed, invalidated);
2251 EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type);
2252 EXPECT_EQ(0, capability_->sim_lock_status_.retries_left);
2253
2254 ::DBus::Variant variant;
2255 ::DBus::MessageIter writer = variant.writer();
2256
2257 // Unlock retries changed, but the SIM wasn't locked.
2258 CellularCapabilityUniversal::LockRetryData retry_data;
2259 retry_data[MM_MODEM_LOCK_SIM_PIN] = 3;
2260 writer << retry_data;
2261 changed[MM_MODEM_PROPERTY_UNLOCKRETRIES] = variant;
2262
2263 capability_->OnModemPropertiesChanged(changed, invalidated);
2264 EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type);
Arman Uguray192ad822013-06-13 19:49:16 -07002265 EXPECT_EQ(3, capability_->sim_lock_status_.retries_left);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002266
2267 // Unlock retries changed and the SIM got locked.
2268 variant.clear();
2269 writer = variant.writer();
2270 writer << static_cast<uint32>(MM_MODEM_LOCK_SIM_PIN);
2271 changed[MM_MODEM_PROPERTY_UNLOCKREQUIRED] = variant;
2272 capability_->OnModemPropertiesChanged(changed, invalidated);
2273 EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type);
2274 EXPECT_EQ(3, capability_->sim_lock_status_.retries_left);
2275
2276 // Only unlock retries changed.
2277 changed.erase(MM_MODEM_PROPERTY_UNLOCKREQUIRED);
2278 retry_data[MM_MODEM_LOCK_SIM_PIN] = 2;
2279 variant.clear();
2280 writer = variant.writer();
2281 writer << retry_data;
2282 changed[MM_MODEM_PROPERTY_UNLOCKRETRIES] = variant;
2283 capability_->OnModemPropertiesChanged(changed, invalidated);
2284 EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type);
2285 EXPECT_EQ(2, capability_->sim_lock_status_.retries_left);
Arman Uguray192ad822013-06-13 19:49:16 -07002286
2287 // Unlock retries changed with a value that doesn't match the current
Arman Ugurayea5ff272013-06-25 10:28:02 -07002288 // lock type. Default to whatever count is available.
Arman Uguray192ad822013-06-13 19:49:16 -07002289 retry_data.clear();
2290 retry_data[MM_MODEM_LOCK_SIM_PIN2] = 2;
2291 variant.clear();
2292 writer = variant.writer();
2293 writer << retry_data;
2294 changed[MM_MODEM_PROPERTY_UNLOCKRETRIES] = variant;
2295 capability_->OnModemPropertiesChanged(changed, invalidated);
2296 EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type);
Arman Ugurayea5ff272013-06-25 10:28:02 -07002297 EXPECT_EQ(2, capability_->sim_lock_status_.retries_left);
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002298}
2299
Jason Glasgowef965562012-04-10 16:12:35 -04002300} // namespace shill