blob: 4259882484c6e7a3b26c555a78d6a654f1afd123 [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"
Arman Uguray6e5639f2012-11-15 20:30:19 -080029#include "shill/mock_mm1_bearer_proxy.h"
Jason Glasgowef965562012-04-10 16:12:35 -040030#include "shill/mock_mm1_modem_modem3gpp_proxy.h"
31#include "shill/mock_mm1_modem_modemcdma_proxy.h"
32#include "shill/mock_mm1_modem_proxy.h"
33#include "shill/mock_mm1_modem_simple_proxy.h"
34#include "shill/mock_mm1_sim_proxy.h"
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070035#include "shill/mock_modem_info.h"
Arman Uguray41cc6342013-03-29 16:34:39 -070036#include "shill/mock_pending_activation_store.h"
Jason Glasgowef965562012-04-10 16:12:35 -040037#include "shill/mock_profile.h"
38#include "shill/mock_rtnl_handler.h"
Jason Glasgowef965562012-04-10 16:12:35 -040039#include "shill/proxy_factory.h"
40
41using base::Bind;
Darin Petkova4ca3c32012-08-17 16:05:24 +020042using base::StringPrintf;
Jason Glasgowef965562012-04-10 16:12:35 -040043using base::Unretained;
44using std::string;
Nathan Williams4b7c2a82012-04-13 15:19:47 -040045using std::vector;
Jason Glasgowef965562012-04-10 16:12:35 -040046using testing::InSequence;
Ben Chan6d0d1e72012-11-06 21:19:28 -080047using testing::Invoke;
Arman Uguray1361c032013-02-11 17:53:39 -080048using testing::InvokeWithoutArgs;
Gary Moraine285a842012-08-15 08:23:57 -070049using testing::Mock;
Jason Glasgowef965562012-04-10 16:12:35 -040050using testing::NiceMock;
51using testing::Return;
Jason Glasgowcd0349c2012-05-03 23:32:15 -040052using testing::SaveArg;
Jason Glasgowef965562012-04-10 16:12:35 -040053using testing::_;
54
55namespace shill {
56
57MATCHER(IsSuccess, "") {
58 return arg.IsSuccess();
59}
60MATCHER(IsFailure, "") {
61 return arg.IsFailure();
62}
Jason Glasgow14521872012-05-07 19:12:15 -040063MATCHER_P(HasApn, expected_apn, "") {
64 string apn;
65 return (DBusProperties::GetString(arg,
66 CellularCapabilityUniversal::kConnectApn,
67 &apn) &&
68 apn == expected_apn);
69}
Jason Glasgowef965562012-04-10 16:12:35 -040070
Arman Uguray1361c032013-02-11 17:53:39 -080071class CellularCapabilityUniversalTest : public testing::TestWithParam<string> {
Jason Glasgowef965562012-04-10 16:12:35 -040072 public:
Arman Uguray1361c032013-02-11 17:53:39 -080073 CellularCapabilityUniversalTest(EventDispatcher *dispatcher)
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070074 : modem_info_(NULL, dispatcher, NULL, NULL, NULL),
Arman Uguray6e5639f2012-11-15 20:30:19 -080075 bearer_proxy_(new mm1::MockBearerProxy()),
Ben Chan3ecdf822012-08-06 12:29:23 -070076 modem_3gpp_proxy_(new mm1::MockModemModem3gppProxy()),
77 modem_cdma_proxy_(new mm1::MockModemModemCdmaProxy()),
78 modem_proxy_(new mm1::MockModemProxy()),
79 modem_simple_proxy_(new mm1::MockModemSimpleProxy()),
80 sim_proxy_(new mm1::MockSimProxy()),
81 properties_proxy_(new MockDBusPropertiesProxy()),
82 proxy_factory_(this),
83 capability_(NULL),
84 device_adaptor_(NULL),
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070085 cellular_(new Cellular(&modem_info_,
Jason Glasgowef965562012-04-10 16:12:35 -040086 "",
Arman Ugurayc9533572013-01-22 17:34:20 -080087 kMachineAddress,
Jason Glasgowef965562012-04-10 16:12:35 -040088 0,
89 Cellular::kTypeUniversal,
90 "",
91 "",
Jason Glasgowa585fc32012-06-06 11:04:09 -040092 "",
Ben Chan3ecdf822012-08-06 12:29:23 -070093 &proxy_factory_)),
Prathmesh Prabhu0d36b4f2013-04-01 11:45:54 -070094 service_(new MockCellularService(&modem_info_, cellular_)) {
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070095 modem_info_.metrics()->RegisterDevice(cellular_->interface_index(),
96 Technology::kCellular);
Thieu Lece4483e2013-01-23 15:12:03 -080097 }
Jason Glasgowef965562012-04-10 16:12:35 -040098
99 virtual ~CellularCapabilityUniversalTest() {
100 cellular_->service_ = NULL;
101 capability_ = NULL;
102 device_adaptor_ = NULL;
103 }
104
105 virtual void SetUp() {
106 capability_ = dynamic_cast<CellularCapabilityUniversal *>(
107 cellular_->capability_.get());
Jason Glasgowef965562012-04-10 16:12:35 -0400108 device_adaptor_ =
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700109 dynamic_cast<DeviceMockAdaptor *>(cellular_->adaptor());
Jason Glasgow14521872012-05-07 19:12:15 -0400110 cellular_->service_ = service_;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700111
112 // kStateUnknown leads to minimal extra work in maintaining
113 // activation state.
Arman Uguray41cc6342013-03-29 16:34:39 -0700114 ON_CALL(*modem_info_.mock_pending_activation_store(),
115 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
116 .WillByDefault(Return(PendingActivationStore::kStateUnknown));
Jason Glasgowef965562012-04-10 16:12:35 -0400117 }
118
119 virtual void TearDown() {
120 capability_->proxy_factory_ = NULL;
121 }
122
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700123 void InitProviderDB() {
124 modem_info_.SetProviderDB(kTestMobileProviderDBPath);
125 }
126
Darin Petkova4ca3c32012-08-17 16:05:24 +0200127 void SetService() {
Prathmesh Prabhu0d36b4f2013-04-01 11:45:54 -0700128 cellular_->service_ = new CellularService(&modem_info_, cellular_);
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400129 }
130
Jason Glasgowef965562012-04-10 16:12:35 -0400131 void InvokeEnable(bool enable, Error *error,
132 const ResultCallback &callback, int timeout) {
133 callback.Run(Error());
134 }
135 void InvokeEnableFail(bool enable, Error *error,
136 const ResultCallback &callback, int timeout) {
137 callback.Run(Error(Error::kOperationFailed));
138 }
Jason Glasgowaf583282012-04-18 15:18:22 -0400139 void InvokeRegister(const string &operator_id, Error *error,
140 const ResultCallback &callback, int timeout) {
141 callback.Run(Error());
142 }
143
Gary Morainceba6aa2012-05-03 10:28:26 -0700144 void InvokeScan(Error *error, const DBusPropertyMapsCallback &callback,
145 int timeout) {
146 callback.Run(CellularCapabilityUniversal::ScanResults(), Error());
147 }
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400148 void ScanError(Error *error, const DBusPropertyMapsCallback &callback,
149 int timeout) {
150 error->Populate(Error::kOperationFailed);
151 }
Gary Morainceba6aa2012-05-03 10:28:26 -0700152
Arman Uguray1361c032013-02-11 17:53:39 -0800153 bool InvokeScanningOrSearchingTimeout() {
154 capability_->OnScanningOrSearchingTimeout();
155 return true;
156 }
157
Gary Morainceba6aa2012-05-03 10:28:26 -0700158 void Set3gppProxy() {
159 capability_->modem_3gpp_proxy_.reset(modem_3gpp_proxy_.release());
160 }
161
Jason Glasgow14521872012-05-07 19:12:15 -0400162 void SetSimpleProxy() {
163 capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release());
164 }
165
Thieu Le3d275392012-07-20 15:32:58 -0700166 void ReleaseCapabilityProxies() {
167 capability_->ReleaseProxies();
168 }
169
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700170 void SetRegistrationDroppedUpdateTimeout(int64 timeout_milliseconds) {
171 capability_->registration_dropped_update_timeout_milliseconds_ =
172 timeout_milliseconds;
173 }
174
Jason Glasgowef965562012-04-10 16:12:35 -0400175 MOCK_METHOD1(TestCallback, void(const Error &error));
176
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700177 MOCK_METHOD0(DummyCallback, void(void));
178
179 void SetMockRegistrationDroppedUpdateCallback() {
180 capability_->registration_dropped_update_callback_.Reset(
181 Bind(&CellularCapabilityUniversalTest::DummyCallback,
182 Unretained(this)));
183 }
184
Jason Glasgowef965562012-04-10 16:12:35 -0400185 protected:
Arman Uguray6e5639f2012-11-15 20:30:19 -0800186 static const char kActiveBearerPathPrefix[];
Jason Glasgowef965562012-04-10 16:12:35 -0400187 static const char kImei[];
Arman Uguray6e5639f2012-11-15 20:30:19 -0800188 static const char kInactiveBearerPathPrefix[];
Arman Ugurayc9533572013-01-22 17:34:20 -0800189 static const char kMachineAddress[];
Jason Glasgowaf583282012-04-18 15:18:22 -0400190 static const char kSimPath[];
191 static const uint32 kAccessTechnologies;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700192 static const char kTestMobileProviderDBPath[];
Jason Glasgowef965562012-04-10 16:12:35 -0400193
194 class TestProxyFactory : public ProxyFactory {
195 public:
196 explicit TestProxyFactory(CellularCapabilityUniversalTest *test) :
mukesh agrawal9da07772013-05-15 14:15:17 -0700197 test_(test) {
198 ::DBus::Variant ip_method_dhcp;
199 ip_method_dhcp.writer().append_uint32(MM_BEARER_IP_METHOD_DHCP);
200 bearer_ip4config_dhcp_[
201 CellularCapabilityUniversal::kIpConfigPropertyMethod] =
202 ip_method_dhcp;
203 }
Jason Glasgowef965562012-04-10 16:12:35 -0400204
Arman Uguray6e5639f2012-11-15 20:30:19 -0800205 virtual mm1::BearerProxyInterface *CreateBearerProxy(
206 const std::string &path,
207 const std::string &/*service*/) {
208 mm1::MockBearerProxy *bearer_proxy = test_->bearer_proxy_.release();
209 if (path.find(kActiveBearerPathPrefix) != std::string::npos)
210 ON_CALL(*bearer_proxy, Connected()).WillByDefault(Return(true));
211 else
212 ON_CALL(*bearer_proxy, Connected()).WillByDefault(Return(false));
mukesh agrawal9da07772013-05-15 14:15:17 -0700213 ON_CALL(*bearer_proxy, Ip4Config()).WillByDefault(Return(
214 bearer_ip4config_dhcp_));
Arman Uguray6e5639f2012-11-15 20:30:19 -0800215 test_->bearer_proxy_.reset(new mm1::MockBearerProxy());
216 return bearer_proxy;
217 }
218
Jason Glasgowef965562012-04-10 16:12:35 -0400219 virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800220 const std::string &/*path*/,
221 const std::string &/*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400222 return test_->modem_3gpp_proxy_.release();
223 }
224
225 virtual mm1::ModemModemCdmaProxyInterface *CreateMM1ModemModemCdmaProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800226 const std::string &/*path*/,
227 const std::string &/*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400228 return test_->modem_cdma_proxy_.release();
229 }
230
231 virtual mm1::ModemProxyInterface *CreateMM1ModemProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800232 const std::string &/*path*/,
233 const std::string &/*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400234 return test_->modem_proxy_.release();
235 }
236
237 virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800238 const std::string &/*path*/,
239 const std::string &/*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400240 return test_->modem_simple_proxy_.release();
241 }
242
243 virtual mm1::SimProxyInterface *CreateSimProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800244 const std::string &/*path*/,
245 const std::string &/*service*/) {
Arman Uguray6552f8c2013-02-12 15:33:18 -0800246 mm1::MockSimProxy *sim_proxy = test_->sim_proxy_.release();
247 test_->sim_proxy_.reset(new mm1::MockSimProxy());
248 return sim_proxy;
Jason Glasgowef965562012-04-10 16:12:35 -0400249 }
Jason Glasgowaf583282012-04-18 15:18:22 -0400250 virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800251 const std::string &/*path*/,
252 const std::string &/*service*/) {
Arman Uguray6552f8c2013-02-12 15:33:18 -0800253 MockDBusPropertiesProxy *properties_proxy =
254 test_->properties_proxy_.release();
255 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:
260 CellularCapabilityUniversalTest *test_;
mukesh agrawal9da07772013-05-15 14:15:17 -0700261 DBusPropertiesMap bearer_ip4config_dhcp_;
Jason Glasgowef965562012-04-10 16:12:35 -0400262 };
263
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700264 MockModemInfo modem_info_;
Arman Uguray6e5639f2012-11-15 20:30:19 -0800265 scoped_ptr<mm1::MockBearerProxy> bearer_proxy_;
Jason Glasgowef965562012-04-10 16:12:35 -0400266 scoped_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_;
267 scoped_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_;
268 scoped_ptr<mm1::MockModemProxy> modem_proxy_;
269 scoped_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_;
270 scoped_ptr<mm1::MockSimProxy> sim_proxy_;
Jason Glasgowaf583282012-04-18 15:18:22 -0400271 scoped_ptr<MockDBusPropertiesProxy> properties_proxy_;
Jason Glasgowef965562012-04-10 16:12:35 -0400272 TestProxyFactory proxy_factory_;
273 CellularCapabilityUniversal *capability_; // Owned by |cellular_|.
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700274 DeviceMockAdaptor *device_adaptor_; // Owned by |cellular_|.
Ben Chan3ecdf822012-08-06 12:29:23 -0700275 CellularRefPtr cellular_;
276 MockCellularService *service_; // owned by cellular_
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400277 DBusPropertyMapsCallback scan_callback_; // saved for testing scan operations
Jason Glasgow14521872012-05-07 19:12:15 -0400278 DBusPathCallback connect_callback_; // saved for testing connect operations
Jason Glasgowef965562012-04-10 16:12:35 -0400279};
280
Arman Uguray1361c032013-02-11 17:53:39 -0800281// Most of our tests involve using a real EventDispatcher object.
282class CellularCapabilityUniversalMainTest
283 : public CellularCapabilityUniversalTest {
284 public:
285 CellularCapabilityUniversalMainTest() :
286 CellularCapabilityUniversalTest(&dispatcher_) {}
287
288 protected:
289 EventDispatcher dispatcher_;
290};
291
292// Tests that involve timers will (or may) use a mock of the event dispatcher
293// instead of a real one.
294class CellularCapabilityUniversalTimerTest
295 : public CellularCapabilityUniversalTest {
296 public:
297 CellularCapabilityUniversalTimerTest()
298 : CellularCapabilityUniversalTest(&mock_dispatcher_) {}
299
300 protected:
301 ::testing::StrictMock<MockEventDispatcher> mock_dispatcher_;
302};
303
Arman Uguray6e5639f2012-11-15 20:30:19 -0800304const char CellularCapabilityUniversalTest::kActiveBearerPathPrefix[] =
305 "/bearer/active";
Jason Glasgowef965562012-04-10 16:12:35 -0400306const char CellularCapabilityUniversalTest::kImei[] = "999911110000";
Arman Uguray6e5639f2012-11-15 20:30:19 -0800307const char CellularCapabilityUniversalTest::kInactiveBearerPathPrefix[] =
308 "/bearer/inactive";
Arman Ugurayc9533572013-01-22 17:34:20 -0800309const char CellularCapabilityUniversalTest::kMachineAddress[] =
310 "TestMachineAddress";
Jason Glasgowaf583282012-04-18 15:18:22 -0400311const char CellularCapabilityUniversalTest::kSimPath[] = "/foo/sim";
312const uint32 CellularCapabilityUniversalTest::kAccessTechnologies =
313 MM_MODEM_ACCESS_TECHNOLOGY_LTE |
314 MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700315const char CellularCapabilityUniversalTest::kTestMobileProviderDBPath[] =
316 "provider_db_unittest.bfd";
Jason Glasgowef965562012-04-10 16:12:35 -0400317
Arman Uguray1361c032013-02-11 17:53:39 -0800318TEST_F(CellularCapabilityUniversalMainTest, StartModem) {
Jason Glasgowaf583282012-04-18 15:18:22 -0400319 // Set up mock modem properties
320 DBusPropertiesMap modem_properties;
321 string operator_name = "TestOperator";
322 string operator_code = "001400";
323
324 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
325 writer().append_uint32(kAccessTechnologies);
326
327 ::DBus::Variant v;
328 ::DBus::MessageIter writer = v.writer();
Jason Glasgowef965562012-04-10 16:12:35 -0400329 ::DBus::Struct< uint32_t, bool > quality;
330 quality._1 = 90;
331 quality._2 = true;
Jason Glasgowaf583282012-04-18 15:18:22 -0400332 writer << quality;
333 modem_properties[MM_MODEM_PROPERTY_SIGNALQUALITY] = v;
334
335 // Set up mock modem 3gpp properties
336 DBusPropertiesMap modem3gpp_properties;
337 modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS].
338 writer().append_uint32(0);
339 modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_IMEI].
340 writer().append_string(kImei);
341
342 EXPECT_CALL(*modem_proxy_,
343 Enable(true, _, _, CellularCapability::kTimeoutEnable))
344 .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeEnable));
345 EXPECT_CALL(*properties_proxy_,
346 GetAll(MM_DBUS_INTERFACE_MODEM))
347 .WillOnce(Return(modem_properties));
348 EXPECT_CALL(*properties_proxy_,
349 GetAll(MM_DBUS_INTERFACE_MODEM_MODEM3GPP))
350 .WillOnce(Return(modem3gpp_properties));
Jason Glasgowef965562012-04-10 16:12:35 -0400351
Gary Moraine285a842012-08-15 08:23:57 -0700352 // Let the modem report that it is initializing. StartModem() should defer
353 // enabling the modem until its state changes to disabled.
354 EXPECT_CALL(*modem_proxy_, State())
355 .WillOnce(Return(Cellular::kModemStateInitializing));
356
Jason Glasgowef965562012-04-10 16:12:35 -0400357 // After setup we lose pointers to the proxies, so it is hard to set
358 // expectations.
359 SetUp();
360
361 Error error;
Gary Moraine285a842012-08-15 08:23:57 -0700362 EXPECT_CALL(*this, TestCallback(_)).Times(0);
Jason Glasgowef965562012-04-10 16:12:35 -0400363 ResultCallback callback =
364 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
365 capability_->StartModem(&error, callback);
Gary Moraine285a842012-08-15 08:23:57 -0700366
Arman Uguray6e5639f2012-11-15 20:30:19 -0800367 // Verify that the modem has not been enabled.
Gary Moraine285a842012-08-15 08:23:57 -0700368 EXPECT_TRUE(capability_->imei_.empty());
369 EXPECT_EQ(0, capability_->access_technologies_);
370 Mock::VerifyAndClearExpectations(this);
371
372 // Change the state to kModemStateDisabling and verify that it still has not
Arman Uguray6e5639f2012-11-15 20:30:19 -0800373 // been enabled.
Gary Moraine285a842012-08-15 08:23:57 -0700374 EXPECT_CALL(*this, TestCallback(_)).Times(0);
375 capability_->OnModemStateChangedSignal(Cellular::kModemStateInitializing,
376 Cellular::kModemStateDisabling, 0);
377 EXPECT_TRUE(capability_->imei_.empty());
378 EXPECT_EQ(0, capability_->access_technologies_);
379 Mock::VerifyAndClearExpectations(this);
380
381 // Change the state of the modem to disabled and verify that it gets enabled.
382 EXPECT_CALL(*this, TestCallback(IsSuccess()));
383 capability_->OnModemStateChangedSignal(Cellular::kModemStateDisabling,
384 Cellular::kModemStateDisabled, 0);
Jason Glasgowef965562012-04-10 16:12:35 -0400385 EXPECT_TRUE(error.IsSuccess());
Jason Glasgowaf583282012-04-18 15:18:22 -0400386 EXPECT_EQ(kImei, capability_->imei_);
387 EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_);
Jason Glasgowef965562012-04-10 16:12:35 -0400388}
389
Arman Uguray1361c032013-02-11 17:53:39 -0800390TEST_F(CellularCapabilityUniversalMainTest, StartModemFail) {
Gary Moraine285a842012-08-15 08:23:57 -0700391 EXPECT_CALL(*modem_proxy_, State())
392 .WillOnce(Return(Cellular::kModemStateDisabled));
Jason Glasgowef965562012-04-10 16:12:35 -0400393 EXPECT_CALL(*modem_proxy_,
394 Enable(true, _, _, CellularCapability::kTimeoutEnable))
395 .WillOnce(
396 Invoke(this, &CellularCapabilityUniversalTest::InvokeEnableFail));
397 EXPECT_CALL(*this, TestCallback(IsFailure()));
398 ResultCallback callback =
399 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
400 SetUp();
401
402 Error error;
403 capability_->StartModem(&error, callback);
Thieu Lee3b36592012-08-30 17:50:26 -0700404 EXPECT_TRUE(error.IsOngoing());
Jason Glasgowef965562012-04-10 16:12:35 -0400405}
406
Thieu Leb9c05e02013-03-04 14:09:32 -0800407TEST_F(CellularCapabilityUniversalMainTest, StartModemAlreadyEnabled) {
408 EXPECT_CALL(*modem_proxy_, State())
409 .WillOnce(Return(Cellular::kModemStateEnabled));
410 SetUp();
411 capability_->cellular()->modem_state_ = Cellular::kModemStateConnected;
412
413 // Make sure the call to StartModem() doesn't attempt to complete the
414 // request synchronously, else it will crash DBus-C++.
415 Error error(Error::kOperationInitiated);
416 capability_->StartModem(&error, ResultCallback());
417 EXPECT_TRUE(error.IsOngoing());
418}
419
Arman Uguray1361c032013-02-11 17:53:39 -0800420TEST_F(CellularCapabilityUniversalMainTest, StopModem) {
Jason Glasgow02401cc2012-05-16 10:35:37 -0400421 // Save pointers to proxies before they are lost by the call to InitProxies
422 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
423 SetUp();
424 EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
425 capability_->InitProxies();
426
427 Error error;
428 ResultCallback callback =
429 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
430 capability_->StopModem(&error, callback);
431 EXPECT_TRUE(error.IsSuccess());
432
433 ResultCallback disable_callback;
434 EXPECT_CALL(*modem_proxy,
435 Enable(false, _, _, CellularCapability::kTimeoutEnable))
436 .WillOnce(SaveArg<2>(&disable_callback));
437 dispatcher_.DispatchPendingEvents();
438
Arman Ugurayee464d32013-02-13 17:14:36 -0800439 ResultCallback set_power_state_callback;
Thieu Le2cac2942013-03-05 18:41:08 -0800440 EXPECT_CALL(
441 *modem_proxy,
442 SetPowerState(
443 MM_MODEM_POWER_STATE_LOW, _, _,
444 CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds))
Arman Ugurayee464d32013-02-13 17:14:36 -0800445 .WillOnce(SaveArg<2>(&set_power_state_callback));
Jason Glasgow02401cc2012-05-16 10:35:37 -0400446 disable_callback.Run(Error(Error::kSuccess));
Arman Ugurayee464d32013-02-13 17:14:36 -0800447
448 EXPECT_CALL(*this, TestCallback(IsSuccess()));
449 set_power_state_callback.Run(Error(Error::kSuccess));
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700450 Mock::VerifyAndClearExpectations(this);
Arman Ugurayee464d32013-02-13 17:14:36 -0800451
452 // TestCallback should get called with success even if the power state
453 // callback gets called with an error
454 EXPECT_CALL(*this, TestCallback(IsSuccess()));
455 set_power_state_callback.Run(Error(Error::kOperationFailed));
Jason Glasgow02401cc2012-05-16 10:35:37 -0400456}
457
Arman Uguray1361c032013-02-11 17:53:39 -0800458TEST_F(CellularCapabilityUniversalMainTest, StopModemConnected) {
Jason Glasgow02401cc2012-05-16 10:35:37 -0400459 // Save pointers to proxies before they are lost by the call to InitProxies
460 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
461 mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get();
462 SetUp();
463 EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
464 capability_->InitProxies();
465
466 ResultCallback disconnect_callback;
467 Error error;
468 ResultCallback callback =
469 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
470 EXPECT_CALL(*modem_simple_proxy,
471 Disconnect(::DBus::Path("/"), _, _,
Thieu Le049adb52012-11-12 17:14:51 -0800472 CellularCapability::kTimeoutDisconnect))
Jason Glasgow02401cc2012-05-16 10:35:37 -0400473 .WillOnce(SaveArg<2>(&disconnect_callback));
Thieu Led0012052012-07-25 16:09:09 -0700474 capability_->cellular()->modem_state_ = Cellular::kModemStateConnected;
Jason Glasgow02401cc2012-05-16 10:35:37 -0400475 capability_->StopModem(&error, callback);
476 EXPECT_TRUE(error.IsSuccess());
477
478 ResultCallback disable_callback;
479 EXPECT_CALL(*modem_proxy,
480 Enable(false, _, _, CellularCapability::kTimeoutEnable))
481 .WillOnce(SaveArg<2>(&disable_callback));
482 disconnect_callback.Run(Error(Error::kSuccess));
483
Arman Ugurayee464d32013-02-13 17:14:36 -0800484 ResultCallback set_power_state_callback;
Thieu Le2cac2942013-03-05 18:41:08 -0800485 EXPECT_CALL(
486 *modem_proxy,
487 SetPowerState(
488 MM_MODEM_POWER_STATE_LOW, _, _,
489 CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds))
Arman Ugurayee464d32013-02-13 17:14:36 -0800490 .WillOnce(SaveArg<2>(&set_power_state_callback));
491
Jason Glasgow02401cc2012-05-16 10:35:37 -0400492 disable_callback.Run(Error(Error::kSuccess));
Arman Ugurayee464d32013-02-13 17:14:36 -0800493
494 EXPECT_CALL(*this, TestCallback(IsSuccess()));
495 set_power_state_callback.Run(Error(Error::kSuccess));
Jason Glasgow02401cc2012-05-16 10:35:37 -0400496}
497
Arman Uguray1361c032013-02-11 17:53:39 -0800498TEST_F(CellularCapabilityUniversalMainTest, DisconnectModemNoBearer) {
Thieu Le5d6864a2012-07-20 11:43:51 -0700499 Error error;
500 ResultCallback disconnect_callback;
Thieu Le3d275392012-07-20 15:32:58 -0700501 EXPECT_CALL(*modem_simple_proxy_,
Thieu Le049adb52012-11-12 17:14:51 -0800502 Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect))
Thieu Le5d6864a2012-07-20 11:43:51 -0700503 .Times(0);
504 capability_->Disconnect(&error, disconnect_callback);
505}
506
Arman Uguray1361c032013-02-11 17:53:39 -0800507TEST_F(CellularCapabilityUniversalMainTest, DisconnectNoProxy) {
Thieu Le3d275392012-07-20 15:32:58 -0700508 Error error;
509 ResultCallback disconnect_callback;
510 capability_->bearer_path_ = "/foo";
511 EXPECT_CALL(*modem_simple_proxy_,
Thieu Le049adb52012-11-12 17:14:51 -0800512 Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect))
Thieu Le3d275392012-07-20 15:32:58 -0700513 .Times(0);
514 ReleaseCapabilityProxies();
515 capability_->Disconnect(&error, disconnect_callback);
516}
517
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700518TEST_F(CellularCapabilityUniversalMainTest, DisconnectWithDeferredCallback) {
519 Error error;
520 ResultCallback disconnect_callback;
521 capability_->bearer_path_ = "/foo";
522 EXPECT_CALL(*modem_simple_proxy_,
523 Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect));
524 SetSimpleProxy();
525 SetMockRegistrationDroppedUpdateCallback();
526 EXPECT_CALL(*this, DummyCallback());
527 capability_->Disconnect(&error, disconnect_callback);
528}
529
Arman Uguray1361c032013-02-11 17:53:39 -0800530TEST_F(CellularCapabilityUniversalMainTest, SimLockStatusChanged) {
Arman Ugurayab9364e2012-12-19 20:45:25 -0800531 // Set up mock SIM properties
532 const char kImsi[] = "310100000001";
533 const char kSimIdentifier[] = "9999888";
534 const char kOperatorIdentifier[] = "310240";
535 const char kOperatorName[] = "Custom SPN";
536 DBusPropertiesMap sim_properties;
537 sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi);
538 sim_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer()
539 .append_string(kSimIdentifier);
540 sim_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer()
541 .append_string(kOperatorIdentifier);
542 sim_properties[MM_SIM_PROPERTY_OPERATORNAME].writer()
543 .append_string(kOperatorName);
544
545 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
546 .WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -0700547 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
548 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700549 .Times(1);
Arman Ugurayab9364e2012-12-19 20:45:25 -0800550
551 SetUp();
552 InitProviderDB();
553
554 EXPECT_FALSE(capability_->sim_present_);
555 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
556
557 capability_->OnSimPathChanged(kSimPath);
558 EXPECT_TRUE(capability_->sim_present_);
559 EXPECT_TRUE(capability_->sim_proxy_ != NULL);
560 EXPECT_EQ(kSimPath, capability_->sim_path_);
561
562 capability_->imsi_ = "";
563 capability_->sim_identifier_ = "";
564 capability_->operator_id_ = "";
565 capability_->spn_ = "";
566
567 // SIM is locked.
Arman Ugurayc7e63af2013-06-13 17:07:32 -0700568 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN;
Arman Ugurayab9364e2012-12-19 20:45:25 -0800569 capability_->OnSimLockStatusChanged();
Arman Uguray41cc6342013-03-29 16:34:39 -0700570 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayab9364e2012-12-19 20:45:25 -0800571
572 EXPECT_EQ("", capability_->imsi_);
573 EXPECT_EQ("", capability_->sim_identifier_);
574 EXPECT_EQ("", capability_->operator_id_);
575 EXPECT_EQ("", capability_->spn_);
576
577 // SIM is unlocked.
578 properties_proxy_.reset(new MockDBusPropertiesProxy());
579 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
580 .WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -0700581 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
582 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700583 .Times(1);
Arman Ugurayab9364e2012-12-19 20:45:25 -0800584
Arman Ugurayc7e63af2013-06-13 17:07:32 -0700585 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_NONE;
Arman Ugurayab9364e2012-12-19 20:45:25 -0800586 capability_->OnSimLockStatusChanged();
Arman Uguray41cc6342013-03-29 16:34:39 -0700587 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayab9364e2012-12-19 20:45:25 -0800588
589 EXPECT_EQ(kImsi, capability_->imsi_);
590 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
591 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
592 EXPECT_EQ(kOperatorName, capability_->spn_);
593}
594
Arman Uguray1361c032013-02-11 17:53:39 -0800595TEST_F(CellularCapabilityUniversalMainTest, PropertiesChanged) {
Jason Glasgowaf583282012-04-18 15:18:22 -0400596 // Set up mock modem properties
597 DBusPropertiesMap modem_properties;
598 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
599 writer().append_uint32(kAccessTechnologies);
600 modem_properties[MM_MODEM_PROPERTY_SIM].
601 writer().append_path(kSimPath);
602
603 // Set up mock modem 3gpp properties
604 DBusPropertiesMap modem3gpp_properties;
605 modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS].
606 writer().append_uint32(0);
607 modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_IMEI].
608 writer().append_string(kImei);
609
610 // Set up mock modem sim properties
611 DBusPropertiesMap sim_properties;
612
613 // After setup we lose pointers to the proxies, so it is hard to set
614 // expectations.
615 EXPECT_CALL(*properties_proxy_,
616 GetAll(MM_DBUS_INTERFACE_SIM))
617 .WillOnce(Return(sim_properties));
618
619 SetUp();
620
621 EXPECT_EQ("", capability_->imei_);
622 EXPECT_EQ(MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN,
623 capability_->access_technologies_);
624 EXPECT_FALSE(capability_->sim_proxy_.get());
Jason Glasgowbad114b2012-05-21 15:24:16 -0400625 EXPECT_CALL(*device_adaptor_, EmitStringChanged(
626 flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyGsm));
Jason Glasgowaf583282012-04-18 15:18:22 -0400627 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
628 modem_properties, vector<string>());
629 EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_);
630 EXPECT_EQ(kSimPath, capability_->sim_path_);
631 EXPECT_TRUE(capability_->sim_proxy_.get());
632
633 // Changing properties on wrong interface will not have an effect
634 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
635 modem3gpp_properties,
636 vector<string>());
637 EXPECT_EQ("", capability_->imei_);
638
639 // Changing properties on the right interface gets reflected in the
640 // capabilities object
641 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEM3GPP,
642 modem3gpp_properties,
643 vector<string>());
644 EXPECT_EQ(kImei, capability_->imei_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700645 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowbad114b2012-05-21 15:24:16 -0400646
647 // Expect to see changes when the family changes
648 modem_properties.clear();
649 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
650 writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_1XRTT);
651 EXPECT_CALL(*device_adaptor_, EmitStringChanged(
652 flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyCdma)).
653 Times(1);
654 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
655 modem_properties,
656 vector<string>());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700657 Mock::VerifyAndClearExpectations(device_adaptor_);
658
Jason Glasgowbad114b2012-05-21 15:24:16 -0400659 // Back to LTE
660 modem_properties.clear();
661 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
662 writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_LTE);
663 EXPECT_CALL(*device_adaptor_, EmitStringChanged(
664 flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyGsm)).
665 Times(1);
666 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
667 modem_properties,
668 vector<string>());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700669 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowbad114b2012-05-21 15:24:16 -0400670
671 // LTE & CDMA - the device adaptor should not be called!
672 modem_properties.clear();
673 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
674 writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_LTE |
675 MM_MODEM_ACCESS_TECHNOLOGY_1XRTT);
676 EXPECT_CALL(*device_adaptor_, EmitStringChanged(_, _)).Times(0);
677 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
678 modem_properties,
679 vector<string>());
Jason Glasgowaf583282012-04-18 15:18:22 -0400680}
681
Arman Uguray1361c032013-02-11 17:53:39 -0800682TEST_F(CellularCapabilityUniversalMainTest, UpdateServiceName) {
Arman Uguray2717a102013-01-29 23:36:06 -0800683 ::DBus::Struct<uint32_t, bool> data;
684 data._1 = 100;
685 data._2 = true;
686 EXPECT_CALL(*modem_proxy_, SignalQuality()).WillRepeatedly(Return(data));
687
688 SetUp();
689 InitProviderDB();
690 capability_->InitProxies();
Arman Uguray2717a102013-01-29 23:36:06 -0800691
692 SetService();
693
694 size_t len = strlen(CellularCapabilityUniversal::kGenericServiceNamePrefix);
695 EXPECT_EQ(CellularCapabilityUniversal::kGenericServiceNamePrefix,
696 cellular_->service_->friendly_name().substr(0, len));
697
698 capability_->imsi_ = "310240123456789";
699 capability_->SetHomeProvider();
700 EXPECT_EQ("", capability_->spn_);
701 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
702 EXPECT_EQ(CellularCapabilityUniversal::kGenericServiceNamePrefix,
703 cellular_->service_->friendly_name().substr(0, len));
704
705 capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
706 capability_->SetHomeProvider();
707 EXPECT_EQ("", capability_->spn_);
708 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
709 EXPECT_EQ("T-Mobile", cellular_->service_->friendly_name());
710
711 capability_->spn_ = "Test Home Provider";
712 capability_->SetHomeProvider();
713 EXPECT_EQ("Test Home Provider", cellular_->home_provider().GetName());
714 EXPECT_EQ("Test Home Provider", cellular_->service_->friendly_name());
715
716 capability_->On3GPPRegistrationChanged(
717 MM_MODEM_3GPP_REGISTRATION_STATE_HOME, "", "OTA Name");
718 EXPECT_EQ("OTA Name", cellular_->service_->friendly_name());
719
720 capability_->On3GPPRegistrationChanged(
721 MM_MODEM_3GPP_REGISTRATION_STATE_HOME, "123", "OTA Name 2");
722 EXPECT_EQ("OTA Name 2", cellular_->service_->friendly_name());
723
724 capability_->On3GPPRegistrationChanged(
725 MM_MODEM_3GPP_REGISTRATION_STATE_HOME, "123", "");
726 EXPECT_EQ("Test Home Provider", cellular_->service_->friendly_name());
727}
728
Prathmesh Prabhu8f6479f2013-05-15 12:56:13 -0700729TEST_F(CellularCapabilityUniversalMainTest, UpdateRegistrationState) {
730 SetUp();
731 InitProviderDB();
732 capability_->InitProxies();
733
734 SetService();
735 capability_->imsi_ = "310240123456789";
736 capability_->SetHomeProvider();
737 cellular_->set_modem_state(Cellular::kModemStateConnected);
738 SetRegistrationDroppedUpdateTimeout(0);
739
740 string home_provider = cellular_->home_provider().GetName();
741 string ota_name = cellular_->service_->friendly_name();
742
743 // Home --> Roaming should be effective immediately.
744 capability_->On3GPPRegistrationChanged(
745 MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
746 home_provider,
747 ota_name);
748 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
749 capability_->registration_state_);
750 capability_->On3GPPRegistrationChanged(
751 MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING,
752 home_provider,
753 ota_name);
754 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING,
755 capability_->registration_state_);
756
757 // Idle --> Roaming should be effective immediately.
758 capability_->On3GPPRegistrationChanged(
759 MM_MODEM_3GPP_REGISTRATION_STATE_IDLE,
760 home_provider,
761 ota_name);
762 dispatcher_.DispatchPendingEvents();
763 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_IDLE,
764 capability_->registration_state_);
765 capability_->On3GPPRegistrationChanged(
766 MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING,
767 home_provider,
768 ota_name);
769 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING,
770 capability_->registration_state_);
771
772 // Idle --> Searching should be effective immediately.
773 capability_->On3GPPRegistrationChanged(
774 MM_MODEM_3GPP_REGISTRATION_STATE_IDLE,
775 home_provider,
776 ota_name);
777 dispatcher_.DispatchPendingEvents();
778 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_IDLE,
779 capability_->registration_state_);
780 capability_->On3GPPRegistrationChanged(
781 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
782 home_provider,
783 ota_name);
784 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
785 capability_->registration_state_);
786
787 // Home --> Searching --> Home should never see Searching.
788 capability_->On3GPPRegistrationChanged(
789 MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
790 home_provider,
791 ota_name);
792 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
793 capability_->registration_state_);
794 capability_->On3GPPRegistrationChanged(
795 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
796 home_provider,
797 ota_name);
798 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
799 capability_->registration_state_);
800 capability_->On3GPPRegistrationChanged(
801 MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
802 home_provider,
803 ota_name);
804 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
805 capability_->registration_state_);
806 dispatcher_.DispatchPendingEvents();
807 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
808 capability_->registration_state_);
809
810 // Home --> Searching --> wait till dispatch should see Searching
811 capability_->On3GPPRegistrationChanged(
812 MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
813 home_provider,
814 ota_name);
815 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
816 capability_->registration_state_);
817 capability_->On3GPPRegistrationChanged(
818 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
819 home_provider,
820 ota_name);
821 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
822 capability_->registration_state_);
823 dispatcher_.DispatchPendingEvents();
824 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
825 capability_->registration_state_);
826
827 // Home --> Searching --> Searching --> wait till dispatch should see
828 // Searching *and* the first callback should be cancelled.
829 EXPECT_CALL(*this, DummyCallback()).Times(0);
830 capability_->On3GPPRegistrationChanged(
831 MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
832 home_provider,
833 ota_name);
834 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
835 capability_->registration_state_);
836 capability_->On3GPPRegistrationChanged(
837 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
838 home_provider,
839 ota_name);
840 SetMockRegistrationDroppedUpdateCallback();
841 capability_->On3GPPRegistrationChanged(
842 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
843 home_provider,
844 ota_name);
845 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
846 capability_->registration_state_);
847 dispatcher_.DispatchPendingEvents();
848 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
849 capability_->registration_state_);
850
851}
852
853TEST_F(CellularCapabilityUniversalMainTest,
854 UpdateRegistrationStateModemNotConnected) {
855 SetUp();
856 InitProviderDB();
857 capability_->InitProxies();
858 SetService();
859
860 capability_->imsi_ = "310240123456789";
861 capability_->SetHomeProvider();
862 cellular_->set_modem_state(Cellular::kModemStateRegistered);
863 SetRegistrationDroppedUpdateTimeout(0);
864
865 string home_provider = cellular_->home_provider().GetName();
866 string ota_name = cellular_->service_->friendly_name();
867
868 // Home --> Searching should be effective immediately.
869 capability_->On3GPPRegistrationChanged(
870 MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
871 home_provider,
872 ota_name);
873 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME,
874 capability_->registration_state_);
875 capability_->On3GPPRegistrationChanged(
876 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
877 home_provider,
878 ota_name);
879 EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING,
880 capability_->registration_state_);
881}
882
Arman Uguray6552f8c2013-02-12 15:33:18 -0800883TEST_F(CellularCapabilityUniversalMainTest, IsValidSimPath) {
884 // Invalid paths
885 EXPECT_FALSE(capability_->IsValidSimPath(""));
886 EXPECT_FALSE(capability_->IsValidSimPath("/"));
887
888 // A valid path
889 EXPECT_TRUE(capability_->IsValidSimPath(
890 "/org/freedesktop/ModemManager1/SIM/0"));
891
892 // Note that any string that is not one of the above invalid paths is
893 // currently regarded as valid, since the ModemManager spec doesn't impose
894 // a strict format on the path. The validity of this is subject to change.
895 EXPECT_TRUE(capability_->IsValidSimPath("path"));
896}
897
Ben Chand7592522013-02-13 16:02:01 -0800898TEST_F(CellularCapabilityUniversalMainTest, NormalizeMdn) {
899 EXPECT_EQ("", capability_->NormalizeMdn(""));
900 EXPECT_EQ("12345678901", capability_->NormalizeMdn("12345678901"));
901 EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1 234 567 8901"));
902 EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1-234-567-8901"));
903 EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1 (234) 567-8901"));
904 EXPECT_EQ("12345678901", capability_->NormalizeMdn("1 234 567 8901 "));
905 EXPECT_EQ("2345678901", capability_->NormalizeMdn("(234) 567-8901"));
906}
907
Arman Uguray1361c032013-02-11 17:53:39 -0800908TEST_F(CellularCapabilityUniversalMainTest, SimPathChanged) {
Ben Chanbd3aee82012-10-16 23:52:04 -0700909 // Set up mock modem SIM properties
910 const char kImsi[] = "310100000001";
911 const char kSimIdentifier[] = "9999888";
912 const char kOperatorIdentifier[] = "310240";
913 const char kOperatorName[] = "Custom SPN";
914 DBusPropertiesMap sim_properties;
915 sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi);
916 sim_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer()
917 .append_string(kSimIdentifier);
918 sim_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer()
919 .append_string(kOperatorIdentifier);
920 sim_properties[MM_SIM_PROPERTY_OPERATORNAME].writer()
921 .append_string(kOperatorName);
922
923 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
924 .Times(1).WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -0700925 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
926 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700927 .Times(1);
Ben Chanbd3aee82012-10-16 23:52:04 -0700928
929 EXPECT_FALSE(capability_->sim_present_);
930 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
931 EXPECT_EQ("", capability_->sim_path_);
932 EXPECT_EQ("", capability_->imsi_);
933 EXPECT_EQ("", capability_->sim_identifier_);
934 EXPECT_EQ("", capability_->operator_id_);
935 EXPECT_EQ("", capability_->spn_);
936
937 capability_->OnSimPathChanged(kSimPath);
938 EXPECT_TRUE(capability_->sim_present_);
939 EXPECT_TRUE(capability_->sim_proxy_ != NULL);
940 EXPECT_EQ(kSimPath, capability_->sim_path_);
941 EXPECT_EQ(kImsi, capability_->imsi_);
942 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
943 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
944 EXPECT_EQ(kOperatorName, capability_->spn_);
945
946 // Changing to the same SIM path should be a no-op.
947 capability_->OnSimPathChanged(kSimPath);
948 EXPECT_TRUE(capability_->sim_present_);
949 EXPECT_TRUE(capability_->sim_proxy_ != NULL);
950 EXPECT_EQ(kSimPath, capability_->sim_path_);
951 EXPECT_EQ(kImsi, capability_->imsi_);
952 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
953 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
954 EXPECT_EQ(kOperatorName, capability_->spn_);
955
956 capability_->OnSimPathChanged("");
Arman Uguray41cc6342013-03-29 16:34:39 -0700957 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700958 Mock::VerifyAndClearExpectations(properties_proxy_.get());
Ben Chanbd3aee82012-10-16 23:52:04 -0700959 EXPECT_FALSE(capability_->sim_present_);
960 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
961 EXPECT_EQ("", capability_->sim_path_);
962 EXPECT_EQ("", capability_->imsi_);
963 EXPECT_EQ("", capability_->sim_identifier_);
964 EXPECT_EQ("", capability_->operator_id_);
965 EXPECT_EQ("", capability_->spn_);
Arman Uguray6552f8c2013-02-12 15:33:18 -0800966
967 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
968 .Times(1).WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -0700969 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
970 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700971 .Times(1);
Arman Uguray6552f8c2013-02-12 15:33:18 -0800972
973 capability_->OnSimPathChanged(kSimPath);
974 EXPECT_TRUE(capability_->sim_present_);
975 EXPECT_TRUE(capability_->sim_proxy_ != NULL);
976 EXPECT_EQ(kSimPath, capability_->sim_path_);
977 EXPECT_EQ(kImsi, capability_->imsi_);
978 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
979 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
980 EXPECT_EQ(kOperatorName, capability_->spn_);
981
982 capability_->OnSimPathChanged("/");
983 EXPECT_FALSE(capability_->sim_present_);
984 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
985 EXPECT_EQ("/", capability_->sim_path_);
986 EXPECT_EQ("", capability_->imsi_);
987 EXPECT_EQ("", capability_->sim_identifier_);
988 EXPECT_EQ("", capability_->operator_id_);
989 EXPECT_EQ("", capability_->spn_);
Ben Chanbd3aee82012-10-16 23:52:04 -0700990}
991
Arman Uguray1361c032013-02-11 17:53:39 -0800992TEST_F(CellularCapabilityUniversalMainTest, SimPropertiesChanged) {
Jason Glasgowaf583282012-04-18 15:18:22 -0400993 // Set up mock modem properties
994 DBusPropertiesMap modem_properties;
995 modem_properties[MM_MODEM_PROPERTY_SIM].writer().append_path(kSimPath);
996
997 // Set up mock modem sim properties
998 const char kImsi[] = "310100000001";
999 DBusPropertiesMap sim_properties;
1000 sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi);
1001
1002 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
1003 .WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -07001004 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1005 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -07001006 .Times(0);
Jason Glasgowaf583282012-04-18 15:18:22 -04001007 // After setup we lose pointers to the proxies, so it is hard to set
1008 // expectations.
1009 SetUp();
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001010 InitProviderDB();
Jason Glasgowaf583282012-04-18 15:18:22 -04001011
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001012 EXPECT_TRUE(cellular_->home_provider().GetName().empty());
1013 EXPECT_TRUE(cellular_->home_provider().GetCountry().empty());
1014 EXPECT_TRUE(cellular_->home_provider().GetCode().empty());
Jason Glasgowaf583282012-04-18 15:18:22 -04001015 EXPECT_FALSE(capability_->sim_proxy_.get());
1016 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
1017 modem_properties, vector<string>());
1018 EXPECT_EQ(kSimPath, capability_->sim_path_);
1019 EXPECT_TRUE(capability_->sim_proxy_.get());
1020 EXPECT_EQ(kImsi, capability_->imsi_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001021 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Jason Glasgowaf583282012-04-18 15:18:22 -04001022
1023 // Updating the SIM
Arman Uguray41cc6342013-03-29 16:34:39 -07001024 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1025 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -07001026 .Times(2);
Jason Glasgowaf583282012-04-18 15:18:22 -04001027 DBusPropertiesMap new_properties;
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001028 const char kCountry[] = "us";
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001029 const char kNewImsi[] = "310240123456789";
Jason Glasgowaf583282012-04-18 15:18:22 -04001030 const char kSimIdentifier[] = "9999888";
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001031 const char kOperatorIdentifier[] = "310240";
1032 const char kOperatorName[] = "Custom SPN";
Jason Glasgowaf583282012-04-18 15:18:22 -04001033 new_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kNewImsi);
1034 new_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer().
1035 append_string(kSimIdentifier);
1036 new_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer().
1037 append_string(kOperatorIdentifier);
Jason Glasgowaf583282012-04-18 15:18:22 -04001038 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM,
1039 new_properties,
1040 vector<string>());
1041 EXPECT_EQ(kNewImsi, capability_->imsi_);
1042 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
1043 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001044 EXPECT_EQ("", capability_->spn_);
1045 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
1046 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
Arman Ugurayd73783f2013-01-31 16:11:21 -08001047 EXPECT_EQ(kOperatorIdentifier, cellular_->home_provider().GetCode());
Jason Glasgow4380f0d2012-05-03 18:05:04 -04001048 EXPECT_EQ(4, capability_->apn_list_.size());
1049
1050 new_properties[MM_SIM_PROPERTY_OPERATORNAME].writer().
1051 append_string(kOperatorName);
1052 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM,
1053 new_properties,
1054 vector<string>());
1055 EXPECT_EQ(kOperatorName, cellular_->home_provider().GetName());
Jason Glasgowaf583282012-04-18 15:18:22 -04001056 EXPECT_EQ(kOperatorName, capability_->spn_);
1057}
1058
Gary Morainceba6aa2012-05-03 10:28:26 -07001059MATCHER_P(SizeIs, value, "") {
1060 return static_cast<size_t>(value) == arg.size();
1061}
1062
Arman Uguray1361c032013-02-11 17:53:39 -08001063TEST_F(CellularCapabilityUniversalMainTest, Reset) {
Ben Chan5d0d32c2013-01-08 02:05:29 -08001064 // Save pointers to proxies before they are lost by the call to InitProxies
1065 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
1066 SetUp();
1067 EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
1068 capability_->InitProxies();
1069
1070 Error error;
1071 ResultCallback reset_callback;
1072
1073 EXPECT_CALL(*modem_proxy, Reset(_, _, CellularCapability::kTimeoutReset))
1074 .WillOnce(SaveArg<1>(&reset_callback));
1075
1076 capability_->Reset(&error, ResultCallback());
1077 EXPECT_TRUE(capability_->resetting_);
1078 reset_callback.Run(error);
1079 EXPECT_FALSE(capability_->resetting_);
1080}
1081
Gary Morainceba6aa2012-05-03 10:28:26 -07001082// Validates that OnScanReply does not crash with a null callback.
Arman Uguray1361c032013-02-11 17:53:39 -08001083TEST_F(CellularCapabilityUniversalMainTest, ScanWithNullCallback) {
Gary Morainceba6aa2012-05-03 10:28:26 -07001084 Error error;
1085 EXPECT_CALL(*modem_3gpp_proxy_, Scan(_, _, CellularCapability::kTimeoutScan))
1086 .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeScan));
1087 EXPECT_CALL(*device_adaptor_,
1088 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
1089 SizeIs(0)));
1090 Set3gppProxy();
1091 capability_->Scan(&error, ResultCallback());
1092 EXPECT_TRUE(error.IsSuccess());
1093}
1094
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001095// Validates that the scanning property is updated
Arman Uguray1361c032013-02-11 17:53:39 -08001096TEST_F(CellularCapabilityUniversalMainTest, Scan) {
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001097 Error error;
1098
1099 EXPECT_CALL(*modem_3gpp_proxy_, Scan(_, _, CellularCapability::kTimeoutScan))
1100 .WillRepeatedly(SaveArg<1>(&scan_callback_));
1101 EXPECT_CALL(*device_adaptor_,
1102 EmitBoolChanged(flimflam::kScanningProperty, true));
1103 Set3gppProxy();
1104 capability_->Scan(&error, ResultCallback());
1105 EXPECT_TRUE(capability_->scanning_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001106 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001107
1108 // Simulate the completion of the scan with 2 networks in the results.
1109 EXPECT_CALL(*device_adaptor_,
1110 EmitBoolChanged(flimflam::kScanningProperty, false));
1111 EXPECT_CALL(*device_adaptor_,
1112 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
1113 SizeIs(2)));
1114 vector<DBusPropertiesMap> results;
1115 const char kScanID0[] = "testID0";
1116 const char kScanID1[] = "testID1";
1117 results.push_back(DBusPropertiesMap());
1118 results[0][CellularCapabilityUniversal::kOperatorLongProperty].
1119 writer().append_string(kScanID0);
1120 results.push_back(DBusPropertiesMap());
1121 results[1][CellularCapabilityUniversal::kOperatorLongProperty].
1122 writer().append_string(kScanID1);
1123 scan_callback_.Run(results, error);
1124 EXPECT_FALSE(capability_->scanning_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001125 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001126
1127 // Simulate the completion of the scan with no networks in the results.
1128 EXPECT_CALL(*device_adaptor_,
1129 EmitBoolChanged(flimflam::kScanningProperty, true));
1130 capability_->Scan(&error, ResultCallback());
1131 EXPECT_TRUE(capability_->scanning_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001132 Mock::VerifyAndClearExpectations(device_adaptor_);
1133
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001134 EXPECT_CALL(*device_adaptor_,
1135 EmitBoolChanged(flimflam::kScanningProperty, false));
1136 EXPECT_CALL(*device_adaptor_,
1137 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
1138 SizeIs(0)));
1139 scan_callback_.Run(vector<DBusPropertiesMap>(), Error());
1140 EXPECT_FALSE(capability_->scanning_);
1141}
1142
1143// Validates expected property updates when scan fails
Arman Uguray1361c032013-02-11 17:53:39 -08001144TEST_F(CellularCapabilityUniversalMainTest, ScanFailure) {
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001145 Error error;
1146
1147 // Test immediate error
1148 {
1149 InSequence seq;
1150 EXPECT_CALL(*modem_3gpp_proxy_,
1151 Scan(_, _, CellularCapability::kTimeoutScan))
1152 .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::ScanError));
1153 EXPECT_CALL(*modem_3gpp_proxy_,
1154 Scan(_, _, CellularCapability::kTimeoutScan))
1155 .WillOnce(SaveArg<1>(&scan_callback_));
1156 }
1157 Set3gppProxy();
1158 capability_->Scan(&error, ResultCallback());
1159 EXPECT_FALSE(capability_->scanning_);
1160 EXPECT_TRUE(error.IsFailure());
1161
1162 // Initiate a scan
1163 error.Populate(Error::kSuccess);
1164 EXPECT_CALL(*device_adaptor_,
1165 EmitBoolChanged(flimflam::kScanningProperty, true));
1166 capability_->Scan(&error, ResultCallback());
1167 EXPECT_TRUE(capability_->scanning_);
1168 EXPECT_TRUE(error.IsSuccess());
1169
1170 // Validate that error is returned if Scan is called while already scanning.
1171 capability_->Scan(&error, ResultCallback());
1172 EXPECT_TRUE(capability_->scanning_);
1173 EXPECT_TRUE(error.IsFailure());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001174 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowcd0349c2012-05-03 23:32:15 -04001175
1176 // Validate that signals are emitted even if an error is reported.
1177 capability_->found_networks_.clear();
1178 capability_->found_networks_.push_back(Stringmap());
1179 EXPECT_CALL(*device_adaptor_,
1180 EmitBoolChanged(flimflam::kScanningProperty, false));
1181 EXPECT_CALL(*device_adaptor_,
1182 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
1183 SizeIs(0)));
1184 vector<DBusPropertiesMap> results;
1185 scan_callback_.Run(results, Error(Error::kOperationFailed));
1186 EXPECT_FALSE(capability_->scanning_);
1187}
1188
Arman Uguray6e5639f2012-11-15 20:30:19 -08001189// Validates expected behavior of OnListBearersReply function
Arman Uguray1361c032013-02-11 17:53:39 -08001190TEST_F(CellularCapabilityUniversalMainTest, OnListBearersReply) {
Arman Uguray6e5639f2012-11-15 20:30:19 -08001191 // Check that bearer_path_ is set correctly when an active bearer
1192 // is returned.
1193 const size_t kPathCount = 3;
1194 DBus::Path active_paths[kPathCount], inactive_paths[kPathCount];
1195 for (size_t i = 0; i < kPathCount; ++i) {
1196 active_paths[i] =
1197 DBus::Path(base::StringPrintf("%s/%zu", kActiveBearerPathPrefix, i));
1198 inactive_paths[i] =
1199 DBus::Path(base::StringPrintf("%s/%zu", kInactiveBearerPathPrefix, i));
1200 }
1201
1202 std::vector<DBus::Path> paths;
1203 paths.push_back(inactive_paths[0]);
1204 paths.push_back(inactive_paths[1]);
1205 paths.push_back(active_paths[2]);
1206 paths.push_back(inactive_paths[1]);
1207 paths.push_back(inactive_paths[2]);
1208
1209 Error error;
1210 capability_->OnListBearersReply(paths, error);
1211 EXPECT_STREQ(capability_->bearer_path_.c_str(), active_paths[2].c_str());
1212
1213 paths.clear();
1214
1215 // Check that bearer_path_ is empty if no active bearers are returned.
1216 paths.push_back(inactive_paths[0]);
1217 paths.push_back(inactive_paths[1]);
1218 paths.push_back(inactive_paths[2]);
1219 paths.push_back(inactive_paths[1]);
1220
1221 capability_->OnListBearersReply(paths, error);
1222 EXPECT_TRUE(capability_->bearer_path_.empty());
1223
1224 // Check that returning multiple bearers causes death.
1225 paths.push_back(active_paths[0]);
1226 paths.push_back(inactive_paths[1]);
1227 paths.push_back(inactive_paths[2]);
1228 paths.push_back(active_paths[1]);
1229 paths.push_back(inactive_paths[1]);
1230
1231 EXPECT_DEATH(capability_->OnListBearersReply(paths, error),
1232 "Found more than one active bearer.");
1233}
1234
Jason Glasgow14521872012-05-07 19:12:15 -04001235// Validates expected behavior of Connect function
Arman Uguray1361c032013-02-11 17:53:39 -08001236TEST_F(CellularCapabilityUniversalMainTest, Connect) {
Jason Glasgow14521872012-05-07 19:12:15 -04001237 mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get();
1238 SetSimpleProxy();
1239 Error error;
1240 DBusPropertiesMap properties;
1241 capability_->apn_try_list_.clear();
1242 ResultCallback callback =
1243 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
1244 DBus::Path bearer("/foo");
1245
1246 // Test connect failures
1247 EXPECT_CALL(*modem_simple_proxy, Connect(_, _, _, _))
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001248 .WillRepeatedly(SaveArg<2>(&connect_callback_));
Jason Glasgow14521872012-05-07 19:12:15 -04001249 capability_->Connect(properties, &error, callback);
1250 EXPECT_TRUE(error.IsSuccess());
1251 EXPECT_CALL(*this, TestCallback(IsFailure()));
1252 EXPECT_CALL(*service_, ClearLastGoodApn());
1253 connect_callback_.Run(bearer, Error(Error::kOperationFailed));
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001254 Mock::VerifyAndClearExpectations(this);
Jason Glasgow14521872012-05-07 19:12:15 -04001255
1256 // Test connect success
Jason Glasgow14521872012-05-07 19:12:15 -04001257 capability_->Connect(properties, &error, callback);
1258 EXPECT_TRUE(error.IsSuccess());
1259 EXPECT_CALL(*this, TestCallback(IsSuccess()));
1260 connect_callback_.Run(bearer, Error(Error::kSuccess));
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001261 Mock::VerifyAndClearExpectations(this);
Jason Glasgow7234ec32012-05-23 16:01:21 -04001262
1263 // Test connect failures without a service. Make sure that shill
1264 // does not crash if the connect failed and there is no
1265 // CellularService object. This can happen if the modem is enabled
1266 // and then quickly disabled.
1267 cellular_->service_ = NULL;
1268 EXPECT_FALSE(capability_->cellular()->service());
Jason Glasgow7234ec32012-05-23 16:01:21 -04001269 capability_->Connect(properties, &error, callback);
1270 EXPECT_TRUE(error.IsSuccess());
1271 EXPECT_CALL(*this, TestCallback(IsFailure()));
1272 connect_callback_.Run(bearer, Error(Error::kOperationFailed));
Jason Glasgow14521872012-05-07 19:12:15 -04001273}
1274
1275// Validates Connect iterates over APNs
Arman Uguray1361c032013-02-11 17:53:39 -08001276TEST_F(CellularCapabilityUniversalMainTest, ConnectApns) {
Jason Glasgow14521872012-05-07 19:12:15 -04001277 mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get();
1278 SetSimpleProxy();
1279 Error error;
1280 DBusPropertiesMap properties;
1281 capability_->apn_try_list_.clear();
1282 ResultCallback callback =
1283 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
1284 DBus::Path bearer("/bearer0");
1285
1286 const char apn_name_foo[] = "foo";
1287 const char apn_name_bar[] = "bar";
1288 EXPECT_CALL(*modem_simple_proxy, Connect(HasApn(apn_name_foo), _, _, _))
1289 .WillOnce(SaveArg<2>(&connect_callback_));
1290 Stringmap apn1;
1291 apn1[flimflam::kApnProperty] = apn_name_foo;
1292 capability_->apn_try_list_.push_back(apn1);
1293 Stringmap apn2;
1294 apn2[flimflam::kApnProperty] = apn_name_bar;
1295 capability_->apn_try_list_.push_back(apn2);
1296 capability_->FillConnectPropertyMap(&properties);
1297 capability_->Connect(properties, &error, callback);
1298 EXPECT_TRUE(error.IsSuccess());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001299 Mock::VerifyAndClearExpectations(modem_simple_proxy);
Jason Glasgow14521872012-05-07 19:12:15 -04001300
1301 EXPECT_CALL(*modem_simple_proxy, Connect(HasApn(apn_name_bar), _, _, _))
1302 .WillOnce(SaveArg<2>(&connect_callback_));
1303 EXPECT_CALL(*service_, ClearLastGoodApn());
1304 connect_callback_.Run(bearer, Error(Error::kInvalidApn));
1305
1306 EXPECT_CALL(*service_, SetLastGoodApn(apn2));
1307 EXPECT_CALL(*this, TestCallback(IsSuccess()));
1308 connect_callback_.Run(bearer, Error(Error::kSuccess));
1309}
1310
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001311// Validates GetTypeString and AccessTechnologyToTechnologyFamily
Arman Uguray1361c032013-02-11 17:53:39 -08001312TEST_F(CellularCapabilityUniversalMainTest, GetTypeString) {
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001313 const int gsm_technologies[] = {
1314 MM_MODEM_ACCESS_TECHNOLOGY_LTE,
1315 MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS,
1316 MM_MODEM_ACCESS_TECHNOLOGY_HSPA,
1317 MM_MODEM_ACCESS_TECHNOLOGY_HSUPA,
1318 MM_MODEM_ACCESS_TECHNOLOGY_HSDPA,
1319 MM_MODEM_ACCESS_TECHNOLOGY_UMTS,
1320 MM_MODEM_ACCESS_TECHNOLOGY_EDGE,
1321 MM_MODEM_ACCESS_TECHNOLOGY_GPRS,
1322 MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT,
1323 MM_MODEM_ACCESS_TECHNOLOGY_GSM,
1324 MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1325 MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1326 MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA,
1327 MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA,
1328 MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB,
1329 MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB,
1330 MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT,
1331 };
Ben Chan62028b22012-11-05 11:20:02 -08001332 for (size_t i = 0; i < arraysize(gsm_technologies); ++i) {
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001333 capability_->access_technologies_ = gsm_technologies[i];
1334 ASSERT_EQ(capability_->GetTypeString(), flimflam::kTechnologyFamilyGsm);
1335 }
1336 const int cdma_technologies[] = {
1337 MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1338 MM_MODEM_ACCESS_TECHNOLOGY_EVDOA,
1339 MM_MODEM_ACCESS_TECHNOLOGY_EVDOA | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1340 MM_MODEM_ACCESS_TECHNOLOGY_EVDOB,
1341 MM_MODEM_ACCESS_TECHNOLOGY_EVDOB | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1342 MM_MODEM_ACCESS_TECHNOLOGY_1XRTT,
1343 };
Ben Chan62028b22012-11-05 11:20:02 -08001344 for (size_t i = 0; i < arraysize(cdma_technologies); ++i) {
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001345 capability_->access_technologies_ = cdma_technologies[i];
1346 ASSERT_EQ(capability_->GetTypeString(), flimflam::kTechnologyFamilyCdma);
1347 }
1348 capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
1349 ASSERT_EQ(capability_->GetTypeString(), "");
1350}
1351
Arman Uguray1361c032013-02-11 17:53:39 -08001352TEST_F(CellularCapabilityUniversalMainTest, AllowRoaming) {
Darin Petkovf508c822012-09-21 13:43:17 +02001353 EXPECT_FALSE(cellular_->allow_roaming_);
1354 EXPECT_FALSE(capability_->provider_requires_roaming_);
1355 EXPECT_FALSE(capability_->AllowRoaming());
1356 capability_->provider_requires_roaming_ = true;
1357 EXPECT_TRUE(capability_->AllowRoaming());
1358 capability_->provider_requires_roaming_ = false;
1359 cellular_->allow_roaming_ = true;
1360 EXPECT_TRUE(capability_->AllowRoaming());
1361}
1362
Arman Uguray1361c032013-02-11 17:53:39 -08001363TEST_F(CellularCapabilityUniversalMainTest, SetHomeProvider) {
Darin Petkovb4fccd22012-08-10 11:59:26 +02001364 static const char kTestCarrier[] = "The Cellular Carrier";
1365 static const char kCountry[] = "us";
1366 static const char kCode[] = "310160";
Darin Petkovb4fccd22012-08-10 11:59:26 +02001367
Darin Petkovf508c822012-09-21 13:43:17 +02001368 EXPECT_FALSE(capability_->home_provider_);
1369 EXPECT_FALSE(capability_->provider_requires_roaming_);
1370
Arman Ugurayd73783f2013-01-31 16:11:21 -08001371 // No mobile provider DB available.
1372 capability_->SetHomeProvider();
Darin Petkovb4fccd22012-08-10 11:59:26 +02001373 EXPECT_TRUE(cellular_->home_provider().GetName().empty());
1374 EXPECT_TRUE(cellular_->home_provider().GetCountry().empty());
1375 EXPECT_TRUE(cellular_->home_provider().GetCode().empty());
Darin Petkovf508c822012-09-21 13:43:17 +02001376 EXPECT_FALSE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001377
1378 InitProviderDB();
Arman Ugurayd73783f2013-01-31 16:11:21 -08001379
1380 // IMSI and Operator Code not available.
1381 capability_->SetHomeProvider();
1382 EXPECT_TRUE(cellular_->home_provider().GetName().empty());
1383 EXPECT_TRUE(cellular_->home_provider().GetCountry().empty());
1384 EXPECT_TRUE(cellular_->home_provider().GetCode().empty());
1385 EXPECT_FALSE(capability_->provider_requires_roaming_);
1386
1387 // Operator Code available.
1388 capability_->operator_id_ = "310240";
1389 capability_->SetHomeProvider();
1390 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
1391 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
1392 EXPECT_EQ("310240", cellular_->home_provider().GetCode());
1393 EXPECT_EQ(4, capability_->apn_list_.size());
1394 ASSERT_TRUE(capability_->home_provider_);
1395 EXPECT_FALSE(capability_->provider_requires_roaming_);
1396
1397 cellular_->home_provider_.SetName("");
1398 cellular_->home_provider_.SetCountry("");
1399 cellular_->home_provider_.SetCode("");
1400
1401 // IMSI available
1402 capability_->imsi_ = "310240123456789";
1403 capability_->operator_id_.clear();
Darin Petkovb4fccd22012-08-10 11:59:26 +02001404 capability_->SetHomeProvider();
1405 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
1406 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
1407 EXPECT_EQ(kCode, cellular_->home_provider().GetCode());
1408 EXPECT_EQ(4, capability_->apn_list_.size());
1409 ASSERT_TRUE(capability_->home_provider_);
Darin Petkovf508c822012-09-21 13:43:17 +02001410 EXPECT_FALSE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001411
1412 Cellular::Operator oper;
1413 cellular_->set_home_provider(oper);
1414 capability_->spn_ = kTestCarrier;
1415 capability_->SetHomeProvider();
1416 EXPECT_EQ(kTestCarrier, cellular_->home_provider().GetName());
1417 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
1418 EXPECT_EQ(kCode, cellular_->home_provider().GetCode());
Darin Petkovf508c822012-09-21 13:43:17 +02001419 EXPECT_FALSE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001420
1421 static const char kCubic[] = "Cubic";
1422 capability_->spn_ = kCubic;
1423 capability_->SetHomeProvider();
1424 EXPECT_EQ(kCubic, cellular_->home_provider().GetName());
1425 EXPECT_EQ("", cellular_->home_provider().GetCode());
1426 ASSERT_TRUE(capability_->home_provider_);
Darin Petkovf508c822012-09-21 13:43:17 +02001427 EXPECT_TRUE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001428
1429 static const char kCUBIC[] = "CUBIC";
1430 capability_->spn_ = kCUBIC;
1431 capability_->home_provider_ = NULL;
1432 capability_->SetHomeProvider();
1433 EXPECT_EQ(kCUBIC, cellular_->home_provider().GetName());
1434 EXPECT_EQ("", cellular_->home_provider().GetCode());
1435 ASSERT_TRUE(capability_->home_provider_);
Darin Petkovf508c822012-09-21 13:43:17 +02001436 EXPECT_TRUE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001437}
1438
Arman Uguray1361c032013-02-11 17:53:39 -08001439TEST_F(CellularCapabilityUniversalMainTest, UpdateScanningProperty) {
Ben Chan8a2c01e2013-01-23 10:09:14 -08001440 // Save pointers to proxies before they are lost by the call to InitProxies
1441 // mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
1442 SetUp();
1443 //EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
1444 capability_->InitProxies();
1445
1446 EXPECT_FALSE(capability_->scanning_or_searching_);
1447 capability_->UpdateScanningProperty();
1448 EXPECT_FALSE(capability_->scanning_or_searching_);
1449
1450 capability_->scanning_ = true;
1451 capability_->UpdateScanningProperty();
1452 EXPECT_TRUE(capability_->scanning_or_searching_);
1453
1454 capability_->scanning_ = false;
1455 capability_->cellular()->modem_state_ = Cellular::kModemStateInitializing;
1456 capability_->UpdateScanningProperty();
1457 EXPECT_FALSE(capability_->scanning_or_searching_);
1458 capability_->cellular()->modem_state_ = Cellular::kModemStateLocked;
1459 capability_->UpdateScanningProperty();
1460 EXPECT_FALSE(capability_->scanning_or_searching_);
1461 capability_->cellular()->modem_state_ = Cellular::kModemStateDisabled;
1462 capability_->UpdateScanningProperty();
1463 EXPECT_FALSE(capability_->scanning_or_searching_);
1464 capability_->cellular()->modem_state_ = Cellular::kModemStateEnabling;
1465 capability_->UpdateScanningProperty();
1466 EXPECT_TRUE(capability_->scanning_or_searching_);
1467 capability_->cellular()->modem_state_ = Cellular::kModemStateEnabled;
1468 capability_->UpdateScanningProperty();
1469 EXPECT_TRUE(capability_->scanning_or_searching_);
1470 capability_->cellular()->modem_state_ = Cellular::kModemStateSearching;
1471 capability_->UpdateScanningProperty();
1472 EXPECT_TRUE(capability_->scanning_or_searching_);
1473 capability_->cellular()->modem_state_ = Cellular::kModemStateRegistered;
1474 capability_->UpdateScanningProperty();
1475 EXPECT_FALSE(capability_->scanning_or_searching_);
1476 capability_->cellular()->modem_state_ = Cellular::kModemStateConnecting;
1477 capability_->UpdateScanningProperty();
1478 EXPECT_FALSE(capability_->scanning_or_searching_);
1479 capability_->cellular()->modem_state_ = Cellular::kModemStateConnected;
1480 capability_->UpdateScanningProperty();
1481 EXPECT_FALSE(capability_->scanning_or_searching_);
1482 capability_->cellular()->modem_state_ = Cellular::kModemStateDisconnecting;
1483 capability_->UpdateScanningProperty();
1484 EXPECT_FALSE(capability_->scanning_or_searching_);
Ben Chane1e1e562013-01-26 00:39:01 -08001485
Ben Chan40a2f862013-02-13 17:44:38 -08001486 // Modem with an unactivated service in the 'enabled' or 'searching' state
1487 capability_->cellular()->modem_state_ = Cellular::kModemStateEnabled;
Ben Chane1e1e562013-01-26 00:39:01 -08001488 capability_->mdn_ = "0000000000";
Ben Chane1e1e562013-01-26 00:39:01 -08001489 CellularService::OLP olp;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001490 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
Ben Chan40a2f862013-02-13 17:44:38 -08001491 .WillRepeatedly(Return(&olp));
1492 capability_->UpdateScanningProperty();
1493 EXPECT_FALSE(capability_->scanning_or_searching_);
1494
1495 capability_->cellular()->modem_state_ = Cellular::kModemStateSearching;
Ben Chane1e1e562013-01-26 00:39:01 -08001496 capability_->UpdateScanningProperty();
1497 EXPECT_FALSE(capability_->scanning_or_searching_);
Ben Chan8a2c01e2013-01-23 10:09:14 -08001498}
1499
Arman Uguray1361c032013-02-11 17:53:39 -08001500TEST_F(CellularCapabilityUniversalTimerTest, UpdateScanningPropertyTimeout) {
1501 SetUp();
1502 capability_->InitProxies();
1503
1504 EXPECT_FALSE(capability_->scanning_or_searching_);
1505 EXPECT_TRUE(
1506 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1507 capability_->UpdateScanningProperty();
1508 EXPECT_FALSE(capability_->scanning_or_searching_);
1509 EXPECT_TRUE(
1510 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1511
1512 EXPECT_CALL(mock_dispatcher_,
1513 PostDelayedTask(
1514 _,
1515 CellularCapabilityUniversal::
1516 kDefaultScanningOrSearchingTimeoutMilliseconds));
1517
1518 capability_->scanning_ = true;
1519 capability_->UpdateScanningProperty();
1520 EXPECT_FALSE(
1521 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1522 EXPECT_TRUE(capability_->scanning_or_searching_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001523 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
Arman Uguray1361c032013-02-11 17:53:39 -08001524
1525 EXPECT_CALL(mock_dispatcher_,
1526 PostDelayedTask(
1527 _,
1528 CellularCapabilityUniversal::
1529 kDefaultScanningOrSearchingTimeoutMilliseconds))
1530 .Times(0);
1531
1532 capability_->scanning_ = false;
1533 capability_->UpdateScanningProperty();
1534 EXPECT_TRUE(
1535 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1536 EXPECT_FALSE(capability_->scanning_or_searching_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001537 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
Arman Uguray1361c032013-02-11 17:53:39 -08001538
1539 EXPECT_CALL(mock_dispatcher_,
1540 PostDelayedTask(
1541 _,
1542 CellularCapabilityUniversal::
1543 kDefaultScanningOrSearchingTimeoutMilliseconds))
1544 .WillOnce(InvokeWithoutArgs(
1545 this,
1546 &CellularCapabilityUniversalTest::InvokeScanningOrSearchingTimeout));
1547
1548 capability_->scanning_ = true;
1549 capability_->UpdateScanningProperty();
1550 // The callback has been scheduled
1551 EXPECT_FALSE(
1552 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1553 // Our mock invocation worked
1554 EXPECT_FALSE(capability_->scanning_or_searching_);
1555}
1556
1557TEST_F(CellularCapabilityUniversalMainTest, UpdateStorageIdentifier) {
Arman Ugurayc9533572013-01-22 17:34:20 -08001558 CellularOperatorInfo::CellularOperator provider;
Arman Ugurayc9533572013-01-22 17:34:20 -08001559
1560 SetService();
1561
1562 const string prefix = "cellular_" + string(kMachineAddress) + "_";
Arman Uguray2717a102013-01-29 23:36:06 -08001563 string default_identifier_pattern =
1564 prefix + string(CellularCapabilityUniversal::kGenericServiceNamePrefix);
1565 std::replace_if(default_identifier_pattern.begin(),
1566 default_identifier_pattern.end(),
1567 &Service::IllegalChar, '_');
1568 default_identifier_pattern += "*";
Arman Ugurayc9533572013-01-22 17:34:20 -08001569
1570 // |capability_->operator_id_| is "".
1571 capability_->UpdateStorageIdentifier();
1572 EXPECT_TRUE(::MatchPattern(cellular_->service()->storage_identifier_,
1573 default_identifier_pattern));
1574
1575 // GetCellularOperatorByMCCMNC returns NULL.
1576 capability_->operator_id_ = "1";
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001577 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Arman Ugurayc9533572013-01-22 17:34:20 -08001578 GetCellularOperatorByMCCMNC(capability_->operator_id_))
1579 .WillOnce(
1580 Return((const CellularOperatorInfo::CellularOperator *)NULL));
1581
1582 capability_->UpdateStorageIdentifier();
1583 EXPECT_TRUE(::MatchPattern(cellular_->service()->storage_identifier_,
1584 default_identifier_pattern));
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001585 Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info());
Arman Ugurayc9533572013-01-22 17:34:20 -08001586
1587 // |capability_->imsi_| is not ""
1588 capability_->imsi_ = "TESTIMSI";
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001589 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Arman Ugurayc9533572013-01-22 17:34:20 -08001590 GetCellularOperatorByMCCMNC(capability_->operator_id_))
1591 .WillOnce(
1592 Return((const CellularOperatorInfo::CellularOperator *)NULL));
1593
1594 capability_->UpdateStorageIdentifier();
1595 EXPECT_EQ(prefix + "TESTIMSI", cellular_->service()->storage_identifier_);
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001596 Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info());
Arman Ugurayc9533572013-01-22 17:34:20 -08001597
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001598 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Arman Ugurayc9533572013-01-22 17:34:20 -08001599 GetCellularOperatorByMCCMNC(capability_->operator_id_))
1600 .Times(2)
1601 .WillRepeatedly(Return(&provider));
1602
1603 // |provider.identifier_| is "".
1604 capability_->UpdateStorageIdentifier();
1605 EXPECT_EQ(prefix + "TESTIMSI", cellular_->service()->storage_identifier_);
1606
1607 // Success.
1608 provider.identifier_ = "testidentifier";
1609 capability_->UpdateStorageIdentifier();
1610 EXPECT_EQ(prefix + "testidentifier",
1611 cellular_->service()->storage_identifier_);
1612}
1613
Arman Uguray1361c032013-02-11 17:53:39 -08001614TEST_F(CellularCapabilityUniversalMainTest, UpdateOLP) {
Ben Chan6d0d1e72012-11-06 21:19:28 -08001615 CellularService::OLP test_olp;
1616 test_olp.SetURL("http://testurl");
1617 test_olp.SetMethod("POST");
Arman Uguray72fab6a2013-01-10 19:32:42 -08001618 test_olp.SetPostData("imei=${imei}&imsi=${imsi}&mdn=${mdn}&"
1619 "min=${min}&iccid=${iccid}");
Ben Chan6d0d1e72012-11-06 21:19:28 -08001620
Ben Chan6d0d1e72012-11-06 21:19:28 -08001621 capability_->imei_ = "1";
1622 capability_->imsi_ = "2";
1623 capability_->mdn_ = "3";
Ben Chan6d0d1e72012-11-06 21:19:28 -08001624 capability_->min_ = "5";
1625 capability_->sim_identifier_ = "6";
1626 capability_->operator_id_ = "123456";
Ben Chan6d0d1e72012-11-06 21:19:28 -08001627
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001628 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Arman Ugurayf4c61812013-01-10 18:58:39 -08001629 GetOLPByMCCMNC(capability_->operator_id_))
1630 .WillRepeatedly(Return(&test_olp));
Ben Chan6d0d1e72012-11-06 21:19:28 -08001631
1632 SetService();
1633 capability_->UpdateOLP();
1634 const CellularService::OLP &olp = cellular_->service()->olp();
1635 EXPECT_EQ("http://testurl", olp.GetURL());
1636 EXPECT_EQ("POST", olp.GetMethod());
Arman Uguray72fab6a2013-01-10 19:32:42 -08001637 EXPECT_EQ("imei=1&imsi=2&mdn=3&min=5&iccid=6",
Ben Chan6d0d1e72012-11-06 21:19:28 -08001638 olp.GetPostData());
1639}
1640
Arman Ugurayc7b15602013-02-16 00:56:18 -08001641TEST_F(CellularCapabilityUniversalMainTest, IsMdnValid) {
1642 capability_->mdn_.clear();
1643 EXPECT_FALSE(capability_->IsMdnValid());
1644 capability_->mdn_ = "0000000";
1645 EXPECT_FALSE(capability_->IsMdnValid());
1646 capability_->mdn_ = "0000001";
1647 EXPECT_TRUE(capability_->IsMdnValid());
1648 capability_->mdn_ = "1231223";
1649 EXPECT_TRUE(capability_->IsMdnValid());
1650}
1651
Arman Uguraya14941d2013-04-12 16:58:26 -07001652TEST_F(CellularCapabilityUniversalTimerTest, CompleteActivation) {
Arman Ugurayefea6e02013-02-21 13:28:04 -08001653 const char kIccid[] = "1234567";
1654
1655 capability_->mdn_.clear();
1656 capability_->sim_identifier_.clear();
Arman Ugurayefea6e02013-02-21 13:28:04 -08001657
Arman Ugurayefea6e02013-02-21 13:28:04 -08001658 EXPECT_CALL(*service_,
1659 SetActivationState(flimflam::kActivationStateActivating))
1660 .Times(0);
Arman Uguray41cc6342013-03-29 16:34:39 -07001661 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1662 SetActivationState(
1663 PendingActivationStore::kIdentifierICCID, _, _))
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001664 .Times(0);
Arman Uguraya14941d2013-04-12 16:58:26 -07001665 EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(0);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001666 Error error;
1667 capability_->CompleteActivation(&error);
Arman Uguray41cc6342013-03-29 16:34:39 -07001668 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001669 Mock::VerifyAndClearExpectations(service_);
Arman Uguraya14941d2013-04-12 16:58:26 -07001670 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
1671 EXPECT_TRUE(
1672 capability_->activation_wait_for_registration_callback_.IsCancelled());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001673
1674 capability_->sim_identifier_ = kIccid;
Arman Uguray41cc6342013-03-29 16:34:39 -07001675 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1676 SetActivationState(PendingActivationStore::kIdentifierICCID,
1677 kIccid,
1678 PendingActivationStore::kStatePending))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001679 .Times(1);
1680 EXPECT_CALL(*service_,
1681 SetActivationState(flimflam::kActivationStateActivating))
1682 .Times(1);
Arman Uguraya14941d2013-04-12 16:58:26 -07001683 EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(1);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001684 capability_->CompleteActivation(&error);
Arman Uguray41cc6342013-03-29 16:34:39 -07001685 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001686 Mock::VerifyAndClearExpectations(service_);
Arman Uguraya14941d2013-04-12 16:58:26 -07001687 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
1688 EXPECT_FALSE(
1689 capability_->activation_wait_for_registration_callback_.IsCancelled());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001690
Arman Uguray41cc6342013-03-29 16:34:39 -07001691 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1692 SetActivationState(PendingActivationStore::kIdentifierICCID,
1693 kIccid,
1694 PendingActivationStore::kStatePending))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001695 .Times(0);
1696 EXPECT_CALL(*service_,
1697 SetActivationState(flimflam::kActivationStateActivating))
1698 .Times(0);
Arman Uguraya14941d2013-04-12 16:58:26 -07001699 EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(0);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001700 capability_->mdn_ = "1231231212";
1701 capability_->CompleteActivation(&error);
1702}
1703
1704TEST_F(CellularCapabilityUniversalMainTest, UpdateServiceActivationState) {
1705 const char kIccid[] = "1234567";
Arman Ugurayefea6e02013-02-21 13:28:04 -08001706 capability_->sim_identifier_.clear();
1707 capability_->mdn_ = "0000000000";
Arman Ugurayefea6e02013-02-21 13:28:04 -08001708 CellularService::OLP olp;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001709 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001710 .WillRepeatedly(Return(&olp));
1711
Arman Uguray6bb252d2013-05-15 14:29:53 -07001712 service_->SetAutoConnect(false);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001713 EXPECT_CALL(*service_,
1714 SetActivationState(flimflam::kActivationStateNotActivated))
1715 .Times(1);
1716 capability_->UpdateServiceActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001717 Mock::VerifyAndClearExpectations(service_);
Arman Uguray6bb252d2013-05-15 14:29:53 -07001718 EXPECT_FALSE(service_->auto_connect());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001719
1720 capability_->mdn_ = "1231231122";
1721 EXPECT_CALL(*service_,
1722 SetActivationState(flimflam::kActivationStateActivated))
1723 .Times(1);
1724 capability_->UpdateServiceActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001725 Mock::VerifyAndClearExpectations(service_);
Arman Uguray6bb252d2013-05-15 14:29:53 -07001726 EXPECT_TRUE(service_->auto_connect());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001727
Arman Uguray6bb252d2013-05-15 14:29:53 -07001728 service_->SetAutoConnect(false);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001729 capability_->mdn_ = "0000000000";
1730 capability_->sim_identifier_ = kIccid;
Arman Uguray41cc6342013-03-29 16:34:39 -07001731 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1732 GetActivationState(PendingActivationStore::kIdentifierICCID,
1733 kIccid))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001734 .Times(2)
Arman Uguray41cc6342013-03-29 16:34:39 -07001735 .WillOnce(Return(PendingActivationStore::kStatePending))
1736 .WillOnce(Return(PendingActivationStore::kStatePendingTimeout));
Arman Ugurayefea6e02013-02-21 13:28:04 -08001737 EXPECT_CALL(*service_,
1738 SetActivationState(flimflam::kActivationStateActivating))
1739 .Times(1);
1740 capability_->UpdateServiceActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001741 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001742 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguray6bb252d2013-05-15 14:29:53 -07001743 EXPECT_FALSE(service_->auto_connect());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001744
Arman Uguray41cc6342013-03-29 16:34:39 -07001745 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1746 GetActivationState(PendingActivationStore::kIdentifierICCID,
1747 kIccid))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001748 .Times(2)
Arman Uguray41cc6342013-03-29 16:34:39 -07001749 .WillRepeatedly(Return(PendingActivationStore::kStateActivated));
Arman Ugurayefea6e02013-02-21 13:28:04 -08001750 EXPECT_CALL(*service_,
1751 SetActivationState(flimflam::kActivationStateActivated))
1752 .Times(1);
1753 capability_->UpdateServiceActivationState();
Arman Uguray6bb252d2013-05-15 14:29:53 -07001754 Mock::VerifyAndClearExpectations(service_);
1755 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
1756 EXPECT_TRUE(service_->auto_connect());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001757}
1758
Arman Uguraya14941d2013-04-12 16:58:26 -07001759TEST_F(CellularCapabilityUniversalMainTest, ActivationWaitForRegisterTimeout) {
1760 const char kIccid[] = "1234567";
1761
1762 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
1763 capability_->InitProxies();
Arman Uguray41cc6342013-03-29 16:34:39 -07001764 EXPECT_CALL(*modem_proxy, Reset(_, _, _)).Times(0);
1765 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1766 SetActivationState(_, _, _))
Arman Uguraya14941d2013-04-12 16:58:26 -07001767 .Times(0);
1768
1769 // No ICCID, no MDN
1770 capability_->sim_identifier_.clear();
1771 capability_->mdn_.clear();
1772 capability_->reset_done_ = false;
1773 capability_->OnActivationWaitForRegisterTimeout();
1774
1775 // State is not activated.
1776 capability_->sim_identifier_ = kIccid;
Arman Uguray41cc6342013-03-29 16:34:39 -07001777 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1778 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
1779 .WillOnce(Return(PendingActivationStore::kStateActivated))
1780 .WillRepeatedly(Return(PendingActivationStore::kStatePending));
Arman Uguraya14941d2013-04-12 16:58:26 -07001781 capability_->OnActivationWaitForRegisterTimeout();
1782
1783 // Valid MDN.
1784 capability_->mdn_ = "0000000001";
1785 capability_->OnActivationWaitForRegisterTimeout();
1786
1787 // Invalid MDN, reset done.
1788 capability_->mdn_ = "0000000000";
1789 capability_->reset_done_ = true;
1790 capability_->OnActivationWaitForRegisterTimeout();
1791
1792 Mock::VerifyAndClearExpectations(modem_proxy);
Arman Uguray41cc6342013-03-29 16:34:39 -07001793 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07001794
1795 // Reset not done.
1796 capability_->reset_done_ = false;
1797 EXPECT_CALL(*modem_proxy, Reset(_,_,_)).Times(1);
Arman Uguray41cc6342013-03-29 16:34:39 -07001798 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1799 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
1800 .WillOnce(Return(PendingActivationStore::kStatePending));
1801 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1802 SetActivationState(PendingActivationStore::kIdentifierICCID,
1803 kIccid,
1804 PendingActivationStore::kStatePendingTimeout))
Arman Uguraya14941d2013-04-12 16:58:26 -07001805 .Times(1);
1806 capability_->OnActivationWaitForRegisterTimeout();
1807}
1808
Arman Uguray0a3e2792013-01-17 16:31:50 -08001809TEST_F(CellularCapabilityUniversalMainTest, UpdatePendingActivationState) {
Arman Ugurayc7b15602013-02-16 00:56:18 -08001810 const char kIccid[] = "1234567";
1811
1812 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001813 capability_->InitProxies();
1814 capability_->registration_state_ =
1815 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING;
1816
1817 // No MDN, no ICCID.
1818 capability_->mdn_ = "0000000";
1819 capability_->sim_identifier_.clear();
Arman Uguray41cc6342013-03-29 16:34:39 -07001820 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1821 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001822 .Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001823 capability_->UpdatePendingActivationState();
Arman Uguray41cc6342013-03-29 16:34:39 -07001824 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001825
1826 // ICCID known.
1827 capability_->sim_identifier_ = kIccid;
1828
1829 // After the modem has reset.
1830 capability_->reset_done_ = true;
Arman Uguray41cc6342013-03-29 16:34:39 -07001831 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1832 GetActivationState(PendingActivationStore::kIdentifierICCID,
1833 kIccid))
1834 .Times(1).WillOnce(Return(PendingActivationStore::kStatePending));
1835 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1836 SetActivationState(PendingActivationStore::kIdentifierICCID,
1837 kIccid,
1838 PendingActivationStore::kStateActivated))
Arman Ugurayc7b15602013-02-16 00:56:18 -08001839 .Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001840 capability_->UpdatePendingActivationState();
Arman Uguray41cc6342013-03-29 16:34:39 -07001841 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001842
1843 // Before reset, not registered.
1844 capability_->reset_done_ = false;
Arman Uguray41cc6342013-03-29 16:34:39 -07001845 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1846 GetActivationState(PendingActivationStore::kIdentifierICCID,
1847 kIccid))
1848 .Times(2).WillRepeatedly(Return(PendingActivationStore::kStatePending));
Arman Ugurayefea6e02013-02-21 13:28:04 -08001849 EXPECT_CALL(*service_,
1850 SetActivationState(flimflam::kActivationStateActivating))
1851 .Times(2);
Arman Ugurayc7b15602013-02-16 00:56:18 -08001852 EXPECT_CALL(*modem_proxy, Reset(_, _, _)).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001853 capability_->UpdatePendingActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001854 Mock::VerifyAndClearExpectations(modem_proxy);
Arman Ugurayc7b15602013-02-16 00:56:18 -08001855
1856 // Before reset, registered.
1857 capability_->registration_state_ =
1858 MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
1859 EXPECT_CALL(*modem_proxy, Reset(_, _, _)).Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001860 capability_->UpdatePendingActivationState();
Arman Uguray41cc6342013-03-29 16:34:39 -07001861 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001862
1863 // Not registered.
1864 capability_->registration_state_ =
1865 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING;
Arman Uguray41cc6342013-03-29 16:34:39 -07001866 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1867 GetActivationState(PendingActivationStore::kIdentifierICCID,
1868 kIccid))
1869 .Times(2).WillRepeatedly(Return(PendingActivationStore::kStateActivated));
Arman Ugurayc7b15602013-02-16 00:56:18 -08001870 EXPECT_CALL(*service_, AutoConnect()).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001871 capability_->UpdatePendingActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001872 Mock::VerifyAndClearExpectations(service_);
Arman Ugurayc7b15602013-02-16 00:56:18 -08001873
1874 // Service, registered.
1875 capability_->registration_state_ =
1876 MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
1877 EXPECT_CALL(*service_, AutoConnect()).Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001878 capability_->UpdatePendingActivationState();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001879
1880 cellular_->service_->activation_state_ =
1881 flimflam::kActivationStateNotActivated;
1882
Arman Uguray41cc6342013-03-29 16:34:39 -07001883 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07001884
Arman Ugurayc7b15602013-02-16 00:56:18 -08001885 // Device is connected.
1886 cellular_->state_ = Cellular::kStateConnected;
1887 EXPECT_CALL(*service_,
1888 SetActivationState(flimflam::kActivationStateActivated))
1889 .Times(3);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001890 capability_->UpdatePendingActivationState();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001891
1892 // Device is linked.
1893 cellular_->state_ = Cellular::kStateLinked;
Arman Uguray0a3e2792013-01-17 16:31:50 -08001894 capability_->UpdatePendingActivationState();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001895
1896 // Got valid MDN.
1897 cellular_->state_ = Cellular::kStateRegistered;
1898 capability_->mdn_ = "1231223";
Arman Uguray41cc6342013-03-29 16:34:39 -07001899 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1900 RemoveEntry(PendingActivationStore::kIdentifierICCID, kIccid))
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001901 .Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001902 capability_->UpdatePendingActivationState();
Arman Uguraya14941d2013-04-12 16:58:26 -07001903
1904 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001905 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07001906
1907 // Timed out, not registered.
1908 capability_->mdn_.clear();
Arman Uguray41cc6342013-03-29 16:34:39 -07001909 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1910 GetActivationState(PendingActivationStore::kIdentifierICCID,
1911 kIccid))
Arman Uguraya14941d2013-04-12 16:58:26 -07001912 .Times(1)
Arman Uguray41cc6342013-03-29 16:34:39 -07001913 .WillOnce(Return(PendingActivationStore::kStatePendingTimeout));
Arman Uguraya14941d2013-04-12 16:58:26 -07001914 capability_->registration_state_ =
1915 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING;
Arman Uguray41cc6342013-03-29 16:34:39 -07001916 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1917 SetActivationState(_, _, _))
Arman Uguraya14941d2013-04-12 16:58:26 -07001918 .Times(0);
1919 EXPECT_CALL(*service_, SetActivationState(_)).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001920 capability_->UpdatePendingActivationState();
Arman Uguraya14941d2013-04-12 16:58:26 -07001921 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001922 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07001923
1924 // Timed out, registered.
Arman Uguray41cc6342013-03-29 16:34:39 -07001925 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1926 GetActivationState(PendingActivationStore::kIdentifierICCID,
1927 kIccid))
Arman Uguraya14941d2013-04-12 16:58:26 -07001928 .Times(1)
Arman Uguray41cc6342013-03-29 16:34:39 -07001929 .WillOnce(Return(PendingActivationStore::kStatePendingTimeout));
Arman Uguraya14941d2013-04-12 16:58:26 -07001930 capability_->registration_state_ =
1931 MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
Arman Uguray41cc6342013-03-29 16:34:39 -07001932 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1933 SetActivationState(PendingActivationStore::kIdentifierICCID,
1934 kIccid,
1935 PendingActivationStore::kStateActivated))
Arman Uguraya14941d2013-04-12 16:58:26 -07001936 .Times(1);
1937 EXPECT_CALL(*service_,
1938 SetActivationState(flimflam::kActivationStateActivated))
1939 .Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001940 capability_->UpdatePendingActivationState();
Arman Uguraya14941d2013-04-12 16:58:26 -07001941 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001942 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001943}
1944
Arman Uguray1361c032013-02-11 17:53:39 -08001945TEST_F(CellularCapabilityUniversalMainTest, UpdateOperatorInfo) {
Darin Petkova4ca3c32012-08-17 16:05:24 +02001946 static const char kOperatorName[] = "Swisscom";
1947 InitProviderDB();
1948 capability_->serving_operator_.SetCode("22801");
1949 SetService();
1950 capability_->UpdateOperatorInfo();
1951 EXPECT_EQ(kOperatorName, capability_->serving_operator_.GetName());
1952 EXPECT_EQ("ch", capability_->serving_operator_.GetCountry());
1953 EXPECT_EQ(kOperatorName, cellular_->service()->serving_operator().GetName());
1954
1955 static const char kTestOperator[] = "Testcom";
1956 capability_->serving_operator_.SetName(kTestOperator);
1957 capability_->serving_operator_.SetCountry("");
1958 capability_->UpdateOperatorInfo();
1959 EXPECT_EQ(kTestOperator, capability_->serving_operator_.GetName());
1960 EXPECT_EQ("ch", capability_->serving_operator_.GetCountry());
1961 EXPECT_EQ(kTestOperator, cellular_->service()->serving_operator().GetName());
1962}
1963
Arman Uguray1361c032013-02-11 17:53:39 -08001964TEST_F(CellularCapabilityUniversalMainTest, UpdateOperatorInfoViaOperatorId) {
Ben Chan092b12b2012-11-07 22:04:05 -08001965 static const char kOperatorName[] = "Swisscom";
1966 static const char kOperatorId[] = "22801";
1967 InitProviderDB();
1968 capability_->serving_operator_.SetCode("");
1969 SetService();
1970 capability_->UpdateOperatorInfo();
1971 EXPECT_EQ("", capability_->serving_operator_.GetName());
1972 EXPECT_EQ("", capability_->serving_operator_.GetCountry());
1973 EXPECT_EQ("", cellular_->service()->serving_operator().GetName());
1974
1975 capability_->operator_id_ = kOperatorId;
1976
Ben Chan092b12b2012-11-07 22:04:05 -08001977 capability_->UpdateOperatorInfo();
1978 EXPECT_EQ(kOperatorId, capability_->serving_operator_.GetCode());
1979 EXPECT_EQ(kOperatorName, capability_->serving_operator_.GetName());
1980 EXPECT_EQ("ch", capability_->serving_operator_.GetCountry());
1981 EXPECT_EQ(kOperatorName, cellular_->service()->serving_operator().GetName());
1982}
1983
Arman Uguray1361c032013-02-11 17:53:39 -08001984TEST_F(CellularCapabilityUniversalMainTest, CreateFriendlyServiceName) {
Darin Petkova4ca3c32012-08-17 16:05:24 +02001985 CellularCapabilityUniversal::friendly_service_name_id_ = 0;
Arman Uguray2717a102013-01-29 23:36:06 -08001986 EXPECT_EQ("Mobile Network 0", capability_->CreateFriendlyServiceName());
1987 EXPECT_EQ("Mobile Network 1", capability_->CreateFriendlyServiceName());
Darin Petkova4ca3c32012-08-17 16:05:24 +02001988
Ben Chan092b12b2012-11-07 22:04:05 -08001989 capability_->operator_id_ = "0123";
Ben Chan092b12b2012-11-07 22:04:05 -08001990 EXPECT_EQ("cellular_0123", capability_->CreateFriendlyServiceName());
1991 EXPECT_EQ("0123", capability_->serving_operator_.GetCode());
1992
Darin Petkova4ca3c32012-08-17 16:05:24 +02001993 capability_->serving_operator_.SetCode("1234");
1994 EXPECT_EQ("cellular_1234", capability_->CreateFriendlyServiceName());
1995
1996 static const char kHomeProvider[] = "The GSM Home Provider";
1997 cellular_->home_provider_.SetName(kHomeProvider);
1998 EXPECT_EQ("cellular_1234", capability_->CreateFriendlyServiceName());
1999 capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
2000 EXPECT_EQ(kHomeProvider, capability_->CreateFriendlyServiceName());
2001
2002 static const char kTestOperator[] = "A GSM Operator";
2003 capability_->serving_operator_.SetName(kTestOperator);
2004 EXPECT_EQ(kTestOperator, capability_->CreateFriendlyServiceName());
2005
2006 capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING;
2007 EXPECT_EQ(StringPrintf("%s | %s", kHomeProvider, kTestOperator),
2008 capability_->CreateFriendlyServiceName());
2009}
2010
Arman Uguray1361c032013-02-11 17:53:39 -08002011TEST_F(CellularCapabilityUniversalMainTest, IsServiceActivationRequired) {
Ben Chan15786032012-11-04 21:28:02 -08002012 capability_->mdn_ = "0000000000";
Ben Chan15786032012-11-04 21:28:02 -08002013 EXPECT_FALSE(capability_->IsServiceActivationRequired());
2014
Arman Ugurayf4c61812013-01-10 18:58:39 -08002015 CellularService::OLP olp;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07002016 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
Arman Ugurayf4c61812013-01-10 18:58:39 -08002017 .WillOnce(Return((const CellularService::OLP *)NULL))
2018 .WillRepeatedly(Return(&olp));
Ben Chan15786032012-11-04 21:28:02 -08002019 EXPECT_FALSE(capability_->IsServiceActivationRequired());
2020
2021 capability_->mdn_ = "";
2022 EXPECT_FALSE(capability_->IsServiceActivationRequired());
2023 capability_->mdn_ = "1234567890";
2024 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Ben Chan15786032012-11-04 21:28:02 -08002025 capability_->mdn_ = "0000000000";
2026 EXPECT_TRUE(capability_->IsServiceActivationRequired());
Arman Ugurayefea6e02013-02-21 13:28:04 -08002027
2028 const char kIccid[] = "1234567890";
2029 capability_->sim_identifier_ = kIccid;
Arman Uguray41cc6342013-03-29 16:34:39 -07002030 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
2031 GetActivationState(PendingActivationStore::kIdentifierICCID,
2032 kIccid))
2033 .WillOnce(Return(PendingActivationStore::kStateActivated))
2034 .WillOnce(Return(PendingActivationStore::kStatePending))
2035 .WillOnce(Return(PendingActivationStore::kStatePendingTimeout))
2036 .WillOnce(Return(PendingActivationStore::kStateUnknown));
Arman Ugurayefea6e02013-02-21 13:28:04 -08002037 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Arman Uguraya14941d2013-04-12 16:58:26 -07002038 EXPECT_FALSE(capability_->IsServiceActivationRequired());
2039 EXPECT_FALSE(capability_->IsServiceActivationRequired());
2040 EXPECT_TRUE(capability_->IsServiceActivationRequired());
Arman Uguray41cc6342013-03-29 16:34:39 -07002041 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Ben Chan15786032012-11-04 21:28:02 -08002042}
2043
Arman Uguray1361c032013-02-11 17:53:39 -08002044TEST_F(CellularCapabilityUniversalMainTest, OnModemCurrentCapabilitiesChanged) {
Ben Chanfcca27b2013-01-22 15:03:44 -08002045 EXPECT_FALSE(capability_->scanning_supported_);
2046 capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_LTE);
2047 EXPECT_FALSE(capability_->scanning_supported_);
2048 capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_CDMA_EVDO);
2049 EXPECT_FALSE(capability_->scanning_supported_);
2050 capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_GSM_UMTS);
2051 EXPECT_TRUE(capability_->scanning_supported_);
2052 capability_->OnModemCurrentCapabilitiesChanged(
2053 MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_CDMA_EVDO);
2054 EXPECT_TRUE(capability_->scanning_supported_);
2055}
2056
Arman Uguray7af0fac2013-03-18 17:35:35 -07002057TEST_F(CellularCapabilityUniversalMainTest, GetNetworkTechnologyStringOnE362) {
2058 capability_->model_id_.clear();
2059 capability_->access_technologies_ = 0;
2060 EXPECT_TRUE(capability_->GetNetworkTechnologyString().empty());
2061
2062 capability_->model_id_ = CellularCapabilityUniversal::kE362ModelId;
2063 EXPECT_EQ(flimflam::kNetworkTechnologyLte,
2064 capability_->GetNetworkTechnologyString());
2065
2066 capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_GPRS;
2067 EXPECT_EQ(flimflam::kNetworkTechnologyLte,
2068 capability_->GetNetworkTechnologyString());
2069
2070 capability_->model_id_.clear();
2071 EXPECT_EQ(flimflam::kNetworkTechnologyGprs,
2072 capability_->GetNetworkTechnologyString());
2073}
2074
Arman Ugurayf84a4242013-04-09 20:01:07 -07002075TEST_F(CellularCapabilityUniversalMainTest, ShouldDetectOutOfCredit) {
Arman Ugurayd42d8ec2013-04-08 19:28:21 -07002076 capability_->model_id_.clear();
Arman Ugurayf84a4242013-04-09 20:01:07 -07002077 EXPECT_FALSE(capability_->ShouldDetectOutOfCredit());
Arman Ugurayd42d8ec2013-04-08 19:28:21 -07002078 capability_->model_id_ = CellularCapabilityUniversal::kE362ModelId;
Arman Ugurayf84a4242013-04-09 20:01:07 -07002079 EXPECT_TRUE(capability_->ShouldDetectOutOfCredit());
Arman Ugurayd42d8ec2013-04-08 19:28:21 -07002080}
2081
Arman Ugurayc7e63af2013-06-13 17:07:32 -07002082TEST_F(CellularCapabilityUniversalMainTest, SimLockStatusToProperty) {
2083 Error error;
2084 KeyValueStore store = capability_->SimLockStatusToProperty(&error);
2085 EXPECT_FALSE(store.GetBool(flimflam::kSIMLockEnabledProperty));
2086 EXPECT_TRUE(store.GetString(flimflam::kSIMLockTypeProperty).empty());
2087 EXPECT_EQ(0, store.GetUint(flimflam::kSIMLockRetriesLeftProperty));
2088
2089 capability_->sim_lock_status_.enabled = true;
2090 capability_->sim_lock_status_.retries_left = 3;
2091 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN;
2092 store = capability_->SimLockStatusToProperty(&error);
2093 EXPECT_TRUE(store.GetBool(flimflam::kSIMLockEnabledProperty));
2094 EXPECT_EQ("sim-pin", store.GetString(flimflam::kSIMLockTypeProperty));
2095 EXPECT_EQ(3, store.GetUint(flimflam::kSIMLockRetriesLeftProperty));
2096
2097 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK;
2098 store = capability_->SimLockStatusToProperty(&error);
2099 EXPECT_EQ("sim-puk", store.GetString(flimflam::kSIMLockTypeProperty));
2100
2101 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN2;
2102 store = capability_->SimLockStatusToProperty(&error);
2103 EXPECT_TRUE(store.GetString(flimflam::kSIMLockTypeProperty).empty());
2104
2105 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK2;
2106 store = capability_->SimLockStatusToProperty(&error);
2107 EXPECT_TRUE(store.GetString(flimflam::kSIMLockTypeProperty).empty());
2108}
2109
2110TEST_F(CellularCapabilityUniversalMainTest, OnLockRetriesChanged) {
2111 CellularCapabilityUniversal::LockRetryData data;
2112 const uint32 kDefaultRetries = 999;
2113
2114 capability_->OnLockRetriesChanged(data);
2115 EXPECT_EQ(kDefaultRetries, capability_->sim_lock_status_.retries_left);
2116
2117 data[MM_MODEM_LOCK_SIM_PIN] = 3;
2118 capability_->OnLockRetriesChanged(data);
2119 EXPECT_EQ(kDefaultRetries, capability_->sim_lock_status_.retries_left);
2120
2121 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN2;
2122 capability_->OnLockRetriesChanged(data);
2123 EXPECT_EQ(kDefaultRetries, capability_->sim_lock_status_.retries_left);
2124
2125 capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN;
2126 capability_->OnLockRetriesChanged(data);
2127 EXPECT_EQ(3, capability_->sim_lock_status_.retries_left);
2128}
2129
2130TEST_F(CellularCapabilityUniversalMainTest, OnLockTypeChanged) {
2131 EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type);
2132
2133 capability_->OnLockTypeChanged(MM_MODEM_LOCK_NONE);
2134 EXPECT_EQ(MM_MODEM_LOCK_NONE, capability_->sim_lock_status_.lock_type);
2135
2136 capability_->OnLockTypeChanged(MM_MODEM_LOCK_SIM_PIN);
2137 EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type);
2138
2139 capability_->OnLockTypeChanged(MM_MODEM_LOCK_SIM_PUK);
2140 EXPECT_EQ(MM_MODEM_LOCK_SIM_PUK, capability_->sim_lock_status_.lock_type);
2141}
2142
2143TEST_F(CellularCapabilityUniversalMainTest, OnSimLockPropertiesChanged) {
2144 EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type);
2145 EXPECT_EQ(0, capability_->sim_lock_status_.retries_left);
2146
2147 DBusPropertiesMap changed;
2148 vector<string> invalidated;
2149
2150 capability_->OnModemPropertiesChanged(changed, invalidated);
2151 EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type);
2152 EXPECT_EQ(0, capability_->sim_lock_status_.retries_left);
2153
2154 ::DBus::Variant variant;
2155 ::DBus::MessageIter writer = variant.writer();
2156
2157 // Unlock retries changed, but the SIM wasn't locked.
2158 CellularCapabilityUniversal::LockRetryData retry_data;
2159 retry_data[MM_MODEM_LOCK_SIM_PIN] = 3;
2160 writer << retry_data;
2161 changed[MM_MODEM_PROPERTY_UNLOCKRETRIES] = variant;
2162
2163 capability_->OnModemPropertiesChanged(changed, invalidated);
2164 EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type);
2165 EXPECT_EQ(999, capability_->sim_lock_status_.retries_left);
2166
2167 // Unlock retries changed and the SIM got locked.
2168 variant.clear();
2169 writer = variant.writer();
2170 writer << static_cast<uint32>(MM_MODEM_LOCK_SIM_PIN);
2171 changed[MM_MODEM_PROPERTY_UNLOCKREQUIRED] = variant;
2172 capability_->OnModemPropertiesChanged(changed, invalidated);
2173 EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type);
2174 EXPECT_EQ(3, capability_->sim_lock_status_.retries_left);
2175
2176 // Only unlock retries changed.
2177 changed.erase(MM_MODEM_PROPERTY_UNLOCKREQUIRED);
2178 retry_data[MM_MODEM_LOCK_SIM_PIN] = 2;
2179 variant.clear();
2180 writer = variant.writer();
2181 writer << retry_data;
2182 changed[MM_MODEM_PROPERTY_UNLOCKRETRIES] = variant;
2183 capability_->OnModemPropertiesChanged(changed, invalidated);
2184 EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type);
2185 EXPECT_EQ(2, capability_->sim_lock_status_.retries_left);
2186}
2187
Jason Glasgowef965562012-04-10 16:12:35 -04002188} // namespace shill