blob: 02f9e4fccdcb51c6d62ff9566856bfa1d0182174 [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
Jason Glasgowef965562012-04-10 16:12:35 -0400170 MOCK_METHOD1(TestCallback, void(const Error &error));
171
172 protected:
Arman Uguray6e5639f2012-11-15 20:30:19 -0800173 static const char kActiveBearerPathPrefix[];
Jason Glasgowef965562012-04-10 16:12:35 -0400174 static const char kImei[];
Arman Uguray6e5639f2012-11-15 20:30:19 -0800175 static const char kInactiveBearerPathPrefix[];
Arman Ugurayc9533572013-01-22 17:34:20 -0800176 static const char kMachineAddress[];
Jason Glasgowaf583282012-04-18 15:18:22 -0400177 static const char kSimPath[];
178 static const uint32 kAccessTechnologies;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700179 static const char kTestMobileProviderDBPath[];
Jason Glasgowef965562012-04-10 16:12:35 -0400180
181 class TestProxyFactory : public ProxyFactory {
182 public:
183 explicit TestProxyFactory(CellularCapabilityUniversalTest *test) :
184 test_(test) {}
185
Arman Uguray6e5639f2012-11-15 20:30:19 -0800186 virtual mm1::BearerProxyInterface *CreateBearerProxy(
187 const std::string &path,
188 const std::string &/*service*/) {
189 mm1::MockBearerProxy *bearer_proxy = test_->bearer_proxy_.release();
190 if (path.find(kActiveBearerPathPrefix) != std::string::npos)
191 ON_CALL(*bearer_proxy, Connected()).WillByDefault(Return(true));
192 else
193 ON_CALL(*bearer_proxy, Connected()).WillByDefault(Return(false));
194 test_->bearer_proxy_.reset(new mm1::MockBearerProxy());
195 return bearer_proxy;
196 }
197
Jason Glasgowef965562012-04-10 16:12:35 -0400198 virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800199 const std::string &/*path*/,
200 const std::string &/*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400201 return test_->modem_3gpp_proxy_.release();
202 }
203
204 virtual mm1::ModemModemCdmaProxyInterface *CreateMM1ModemModemCdmaProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800205 const std::string &/*path*/,
206 const std::string &/*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400207 return test_->modem_cdma_proxy_.release();
208 }
209
210 virtual mm1::ModemProxyInterface *CreateMM1ModemProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800211 const std::string &/*path*/,
212 const std::string &/*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400213 return test_->modem_proxy_.release();
214 }
215
216 virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800217 const std::string &/*path*/,
218 const std::string &/*service*/) {
Jason Glasgowef965562012-04-10 16:12:35 -0400219 return test_->modem_simple_proxy_.release();
220 }
221
222 virtual mm1::SimProxyInterface *CreateSimProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800223 const std::string &/*path*/,
224 const std::string &/*service*/) {
Arman Uguray6552f8c2013-02-12 15:33:18 -0800225 mm1::MockSimProxy *sim_proxy = test_->sim_proxy_.release();
226 test_->sim_proxy_.reset(new mm1::MockSimProxy());
227 return sim_proxy;
Jason Glasgowef965562012-04-10 16:12:35 -0400228 }
Jason Glasgowaf583282012-04-18 15:18:22 -0400229 virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy(
Arman Uguray6e5639f2012-11-15 20:30:19 -0800230 const std::string &/*path*/,
231 const std::string &/*service*/) {
Arman Uguray6552f8c2013-02-12 15:33:18 -0800232 MockDBusPropertiesProxy *properties_proxy =
233 test_->properties_proxy_.release();
234 test_->properties_proxy_.reset(new MockDBusPropertiesProxy());
235 return properties_proxy;
Jason Glasgowaf583282012-04-18 15:18:22 -0400236 }
Jason Glasgowef965562012-04-10 16:12:35 -0400237
238 private:
239 CellularCapabilityUniversalTest *test_;
240 };
241
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700242 MockModemInfo modem_info_;
Arman Uguray6e5639f2012-11-15 20:30:19 -0800243 scoped_ptr<mm1::MockBearerProxy> bearer_proxy_;
Jason Glasgowef965562012-04-10 16:12:35 -0400244 scoped_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_;
245 scoped_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_;
246 scoped_ptr<mm1::MockModemProxy> modem_proxy_;
247 scoped_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_;
248 scoped_ptr<mm1::MockSimProxy> sim_proxy_;
Jason Glasgowaf583282012-04-18 15:18:22 -0400249 scoped_ptr<MockDBusPropertiesProxy> properties_proxy_;
Jason Glasgowef965562012-04-10 16:12:35 -0400250 TestProxyFactory proxy_factory_;
251 CellularCapabilityUniversal *capability_; // Owned by |cellular_|.
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700252 DeviceMockAdaptor *device_adaptor_; // Owned by |cellular_|.
Ben Chan3ecdf822012-08-06 12:29:23 -0700253 CellularRefPtr cellular_;
254 MockCellularService *service_; // owned by cellular_
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400255 DBusPropertyMapsCallback scan_callback_; // saved for testing scan operations
Jason Glasgow14521872012-05-07 19:12:15 -0400256 DBusPathCallback connect_callback_; // saved for testing connect operations
Jason Glasgowef965562012-04-10 16:12:35 -0400257};
258
Arman Uguray1361c032013-02-11 17:53:39 -0800259// Most of our tests involve using a real EventDispatcher object.
260class CellularCapabilityUniversalMainTest
261 : public CellularCapabilityUniversalTest {
262 public:
263 CellularCapabilityUniversalMainTest() :
264 CellularCapabilityUniversalTest(&dispatcher_) {}
265
266 protected:
267 EventDispatcher dispatcher_;
268};
269
270// Tests that involve timers will (or may) use a mock of the event dispatcher
271// instead of a real one.
272class CellularCapabilityUniversalTimerTest
273 : public CellularCapabilityUniversalTest {
274 public:
275 CellularCapabilityUniversalTimerTest()
276 : CellularCapabilityUniversalTest(&mock_dispatcher_) {}
277
278 protected:
279 ::testing::StrictMock<MockEventDispatcher> mock_dispatcher_;
280};
281
Arman Uguray6e5639f2012-11-15 20:30:19 -0800282const char CellularCapabilityUniversalTest::kActiveBearerPathPrefix[] =
283 "/bearer/active";
Jason Glasgowef965562012-04-10 16:12:35 -0400284const char CellularCapabilityUniversalTest::kImei[] = "999911110000";
Arman Uguray6e5639f2012-11-15 20:30:19 -0800285const char CellularCapabilityUniversalTest::kInactiveBearerPathPrefix[] =
286 "/bearer/inactive";
Arman Ugurayc9533572013-01-22 17:34:20 -0800287const char CellularCapabilityUniversalTest::kMachineAddress[] =
288 "TestMachineAddress";
Jason Glasgowaf583282012-04-18 15:18:22 -0400289const char CellularCapabilityUniversalTest::kSimPath[] = "/foo/sim";
290const uint32 CellularCapabilityUniversalTest::kAccessTechnologies =
291 MM_MODEM_ACCESS_TECHNOLOGY_LTE |
292 MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700293const char CellularCapabilityUniversalTest::kTestMobileProviderDBPath[] =
294 "provider_db_unittest.bfd";
Jason Glasgowef965562012-04-10 16:12:35 -0400295
Arman Uguray1361c032013-02-11 17:53:39 -0800296TEST_F(CellularCapabilityUniversalMainTest, StartModem) {
Jason Glasgowaf583282012-04-18 15:18:22 -0400297 // Set up mock modem properties
298 DBusPropertiesMap modem_properties;
299 string operator_name = "TestOperator";
300 string operator_code = "001400";
301
302 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
303 writer().append_uint32(kAccessTechnologies);
304
305 ::DBus::Variant v;
306 ::DBus::MessageIter writer = v.writer();
Jason Glasgowef965562012-04-10 16:12:35 -0400307 ::DBus::Struct< uint32_t, bool > quality;
308 quality._1 = 90;
309 quality._2 = true;
Jason Glasgowaf583282012-04-18 15:18:22 -0400310 writer << quality;
311 modem_properties[MM_MODEM_PROPERTY_SIGNALQUALITY] = v;
312
313 // Set up mock modem 3gpp properties
314 DBusPropertiesMap modem3gpp_properties;
315 modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS].
316 writer().append_uint32(0);
317 modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_IMEI].
318 writer().append_string(kImei);
319
320 EXPECT_CALL(*modem_proxy_,
321 Enable(true, _, _, CellularCapability::kTimeoutEnable))
322 .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeEnable));
323 EXPECT_CALL(*properties_proxy_,
324 GetAll(MM_DBUS_INTERFACE_MODEM))
325 .WillOnce(Return(modem_properties));
326 EXPECT_CALL(*properties_proxy_,
327 GetAll(MM_DBUS_INTERFACE_MODEM_MODEM3GPP))
328 .WillOnce(Return(modem3gpp_properties));
Jason Glasgowef965562012-04-10 16:12:35 -0400329
Gary Moraine285a842012-08-15 08:23:57 -0700330 // Let the modem report that it is initializing. StartModem() should defer
331 // enabling the modem until its state changes to disabled.
332 EXPECT_CALL(*modem_proxy_, State())
333 .WillOnce(Return(Cellular::kModemStateInitializing));
334
Jason Glasgowef965562012-04-10 16:12:35 -0400335 // After setup we lose pointers to the proxies, so it is hard to set
336 // expectations.
337 SetUp();
338
339 Error error;
Gary Moraine285a842012-08-15 08:23:57 -0700340 EXPECT_CALL(*this, TestCallback(_)).Times(0);
Jason Glasgowef965562012-04-10 16:12:35 -0400341 ResultCallback callback =
342 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
343 capability_->StartModem(&error, callback);
Gary Moraine285a842012-08-15 08:23:57 -0700344
Arman Uguray6e5639f2012-11-15 20:30:19 -0800345 // Verify that the modem has not been enabled.
Gary Moraine285a842012-08-15 08:23:57 -0700346 EXPECT_TRUE(capability_->imei_.empty());
347 EXPECT_EQ(0, capability_->access_technologies_);
348 Mock::VerifyAndClearExpectations(this);
349
350 // Change the state to kModemStateDisabling and verify that it still has not
Arman Uguray6e5639f2012-11-15 20:30:19 -0800351 // been enabled.
Gary Moraine285a842012-08-15 08:23:57 -0700352 EXPECT_CALL(*this, TestCallback(_)).Times(0);
353 capability_->OnModemStateChangedSignal(Cellular::kModemStateInitializing,
354 Cellular::kModemStateDisabling, 0);
355 EXPECT_TRUE(capability_->imei_.empty());
356 EXPECT_EQ(0, capability_->access_technologies_);
357 Mock::VerifyAndClearExpectations(this);
358
359 // Change the state of the modem to disabled and verify that it gets enabled.
360 EXPECT_CALL(*this, TestCallback(IsSuccess()));
361 capability_->OnModemStateChangedSignal(Cellular::kModemStateDisabling,
362 Cellular::kModemStateDisabled, 0);
Jason Glasgowef965562012-04-10 16:12:35 -0400363 EXPECT_TRUE(error.IsSuccess());
Jason Glasgowaf583282012-04-18 15:18:22 -0400364 EXPECT_EQ(kImei, capability_->imei_);
365 EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_);
Jason Glasgowef965562012-04-10 16:12:35 -0400366}
367
Arman Uguray1361c032013-02-11 17:53:39 -0800368TEST_F(CellularCapabilityUniversalMainTest, StartModemFail) {
Gary Moraine285a842012-08-15 08:23:57 -0700369 EXPECT_CALL(*modem_proxy_, State())
370 .WillOnce(Return(Cellular::kModemStateDisabled));
Jason Glasgowef965562012-04-10 16:12:35 -0400371 EXPECT_CALL(*modem_proxy_,
372 Enable(true, _, _, CellularCapability::kTimeoutEnable))
373 .WillOnce(
374 Invoke(this, &CellularCapabilityUniversalTest::InvokeEnableFail));
375 EXPECT_CALL(*this, TestCallback(IsFailure()));
376 ResultCallback callback =
377 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
378 SetUp();
379
380 Error error;
381 capability_->StartModem(&error, callback);
Thieu Lee3b36592012-08-30 17:50:26 -0700382 EXPECT_TRUE(error.IsOngoing());
Jason Glasgowef965562012-04-10 16:12:35 -0400383}
384
Thieu Leb9c05e02013-03-04 14:09:32 -0800385TEST_F(CellularCapabilityUniversalMainTest, StartModemAlreadyEnabled) {
386 EXPECT_CALL(*modem_proxy_, State())
387 .WillOnce(Return(Cellular::kModemStateEnabled));
388 SetUp();
389 capability_->cellular()->modem_state_ = Cellular::kModemStateConnected;
390
391 // Make sure the call to StartModem() doesn't attempt to complete the
392 // request synchronously, else it will crash DBus-C++.
393 Error error(Error::kOperationInitiated);
394 capability_->StartModem(&error, ResultCallback());
395 EXPECT_TRUE(error.IsOngoing());
396}
397
Arman Uguray1361c032013-02-11 17:53:39 -0800398TEST_F(CellularCapabilityUniversalMainTest, StopModem) {
Jason Glasgow02401cc2012-05-16 10:35:37 -0400399 // Save pointers to proxies before they are lost by the call to InitProxies
400 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
401 SetUp();
402 EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
403 capability_->InitProxies();
404
405 Error error;
406 ResultCallback callback =
407 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
408 capability_->StopModem(&error, callback);
409 EXPECT_TRUE(error.IsSuccess());
410
411 ResultCallback disable_callback;
412 EXPECT_CALL(*modem_proxy,
413 Enable(false, _, _, CellularCapability::kTimeoutEnable))
414 .WillOnce(SaveArg<2>(&disable_callback));
415 dispatcher_.DispatchPendingEvents();
416
Arman Ugurayee464d32013-02-13 17:14:36 -0800417 ResultCallback set_power_state_callback;
Thieu Le2cac2942013-03-05 18:41:08 -0800418 EXPECT_CALL(
419 *modem_proxy,
420 SetPowerState(
421 MM_MODEM_POWER_STATE_LOW, _, _,
422 CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds))
Arman Ugurayee464d32013-02-13 17:14:36 -0800423 .WillOnce(SaveArg<2>(&set_power_state_callback));
Jason Glasgow02401cc2012-05-16 10:35:37 -0400424 disable_callback.Run(Error(Error::kSuccess));
Arman Ugurayee464d32013-02-13 17:14:36 -0800425
426 EXPECT_CALL(*this, TestCallback(IsSuccess()));
427 set_power_state_callback.Run(Error(Error::kSuccess));
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700428 Mock::VerifyAndClearExpectations(this);
Arman Ugurayee464d32013-02-13 17:14:36 -0800429
430 // TestCallback should get called with success even if the power state
431 // callback gets called with an error
432 EXPECT_CALL(*this, TestCallback(IsSuccess()));
433 set_power_state_callback.Run(Error(Error::kOperationFailed));
Jason Glasgow02401cc2012-05-16 10:35:37 -0400434}
435
Arman Uguray1361c032013-02-11 17:53:39 -0800436TEST_F(CellularCapabilityUniversalMainTest, StopModemConnected) {
Jason Glasgow02401cc2012-05-16 10:35:37 -0400437 // Save pointers to proxies before they are lost by the call to InitProxies
438 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
439 mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get();
440 SetUp();
441 EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
442 capability_->InitProxies();
443
444 ResultCallback disconnect_callback;
445 Error error;
446 ResultCallback callback =
447 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
448 EXPECT_CALL(*modem_simple_proxy,
449 Disconnect(::DBus::Path("/"), _, _,
Thieu Le049adb52012-11-12 17:14:51 -0800450 CellularCapability::kTimeoutDisconnect))
Jason Glasgow02401cc2012-05-16 10:35:37 -0400451 .WillOnce(SaveArg<2>(&disconnect_callback));
Thieu Led0012052012-07-25 16:09:09 -0700452 capability_->cellular()->modem_state_ = Cellular::kModemStateConnected;
Jason Glasgow02401cc2012-05-16 10:35:37 -0400453 capability_->StopModem(&error, callback);
454 EXPECT_TRUE(error.IsSuccess());
455
456 ResultCallback disable_callback;
457 EXPECT_CALL(*modem_proxy,
458 Enable(false, _, _, CellularCapability::kTimeoutEnable))
459 .WillOnce(SaveArg<2>(&disable_callback));
460 disconnect_callback.Run(Error(Error::kSuccess));
461
Arman Ugurayee464d32013-02-13 17:14:36 -0800462 ResultCallback set_power_state_callback;
Thieu Le2cac2942013-03-05 18:41:08 -0800463 EXPECT_CALL(
464 *modem_proxy,
465 SetPowerState(
466 MM_MODEM_POWER_STATE_LOW, _, _,
467 CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds))
Arman Ugurayee464d32013-02-13 17:14:36 -0800468 .WillOnce(SaveArg<2>(&set_power_state_callback));
469
Jason Glasgow02401cc2012-05-16 10:35:37 -0400470 disable_callback.Run(Error(Error::kSuccess));
Arman Ugurayee464d32013-02-13 17:14:36 -0800471
472 EXPECT_CALL(*this, TestCallback(IsSuccess()));
473 set_power_state_callback.Run(Error(Error::kSuccess));
Jason Glasgow02401cc2012-05-16 10:35:37 -0400474}
475
Arman Uguray1361c032013-02-11 17:53:39 -0800476TEST_F(CellularCapabilityUniversalMainTest, DisconnectModemNoBearer) {
Thieu Le5d6864a2012-07-20 11:43:51 -0700477 Error error;
478 ResultCallback disconnect_callback;
Thieu Le3d275392012-07-20 15:32:58 -0700479 EXPECT_CALL(*modem_simple_proxy_,
Thieu Le049adb52012-11-12 17:14:51 -0800480 Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect))
Thieu Le5d6864a2012-07-20 11:43:51 -0700481 .Times(0);
482 capability_->Disconnect(&error, disconnect_callback);
483}
484
Arman Uguray1361c032013-02-11 17:53:39 -0800485TEST_F(CellularCapabilityUniversalMainTest, DisconnectNoProxy) {
Thieu Le3d275392012-07-20 15:32:58 -0700486 Error error;
487 ResultCallback disconnect_callback;
488 capability_->bearer_path_ = "/foo";
489 EXPECT_CALL(*modem_simple_proxy_,
Thieu Le049adb52012-11-12 17:14:51 -0800490 Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect))
Thieu Le3d275392012-07-20 15:32:58 -0700491 .Times(0);
492 ReleaseCapabilityProxies();
493 capability_->Disconnect(&error, disconnect_callback);
494}
495
Arman Uguray1361c032013-02-11 17:53:39 -0800496TEST_F(CellularCapabilityUniversalMainTest, SimLockStatusChanged) {
Arman Ugurayab9364e2012-12-19 20:45:25 -0800497 // Set up mock SIM properties
498 const char kImsi[] = "310100000001";
499 const char kSimIdentifier[] = "9999888";
500 const char kOperatorIdentifier[] = "310240";
501 const char kOperatorName[] = "Custom SPN";
502 DBusPropertiesMap sim_properties;
503 sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi);
504 sim_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer()
505 .append_string(kSimIdentifier);
506 sim_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer()
507 .append_string(kOperatorIdentifier);
508 sim_properties[MM_SIM_PROPERTY_OPERATORNAME].writer()
509 .append_string(kOperatorName);
510
511 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
512 .WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -0700513 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
514 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700515 .Times(1);
Arman Ugurayab9364e2012-12-19 20:45:25 -0800516
517 SetUp();
518 InitProviderDB();
519
520 EXPECT_FALSE(capability_->sim_present_);
521 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
522
523 capability_->OnSimPathChanged(kSimPath);
524 EXPECT_TRUE(capability_->sim_present_);
525 EXPECT_TRUE(capability_->sim_proxy_ != NULL);
526 EXPECT_EQ(kSimPath, capability_->sim_path_);
527
528 capability_->imsi_ = "";
529 capability_->sim_identifier_ = "";
530 capability_->operator_id_ = "";
531 capability_->spn_ = "";
532
533 // SIM is locked.
534 capability_->sim_lock_status_.lock_type = "sim-pin";
535 capability_->OnSimLockStatusChanged();
Arman Uguray41cc6342013-03-29 16:34:39 -0700536 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayab9364e2012-12-19 20:45:25 -0800537
538 EXPECT_EQ("", capability_->imsi_);
539 EXPECT_EQ("", capability_->sim_identifier_);
540 EXPECT_EQ("", capability_->operator_id_);
541 EXPECT_EQ("", capability_->spn_);
542
543 // SIM is unlocked.
544 properties_proxy_.reset(new MockDBusPropertiesProxy());
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 capability_->sim_lock_status_.lock_type = "";
552 capability_->OnSimLockStatusChanged();
Arman Uguray41cc6342013-03-29 16:34:39 -0700553 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayab9364e2012-12-19 20:45:25 -0800554
555 EXPECT_EQ(kImsi, capability_->imsi_);
556 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
557 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
558 EXPECT_EQ(kOperatorName, capability_->spn_);
559}
560
Arman Uguray1361c032013-02-11 17:53:39 -0800561TEST_F(CellularCapabilityUniversalMainTest, PropertiesChanged) {
Jason Glasgowaf583282012-04-18 15:18:22 -0400562 // Set up mock modem properties
563 DBusPropertiesMap modem_properties;
564 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
565 writer().append_uint32(kAccessTechnologies);
566 modem_properties[MM_MODEM_PROPERTY_SIM].
567 writer().append_path(kSimPath);
568
569 // Set up mock modem 3gpp properties
570 DBusPropertiesMap modem3gpp_properties;
571 modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS].
572 writer().append_uint32(0);
573 modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_IMEI].
574 writer().append_string(kImei);
575
576 // Set up mock modem sim properties
577 DBusPropertiesMap sim_properties;
578
579 // After setup we lose pointers to the proxies, so it is hard to set
580 // expectations.
581 EXPECT_CALL(*properties_proxy_,
582 GetAll(MM_DBUS_INTERFACE_SIM))
583 .WillOnce(Return(sim_properties));
584
585 SetUp();
586
587 EXPECT_EQ("", capability_->imei_);
588 EXPECT_EQ(MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN,
589 capability_->access_technologies_);
590 EXPECT_FALSE(capability_->sim_proxy_.get());
Jason Glasgowbad114b2012-05-21 15:24:16 -0400591 EXPECT_CALL(*device_adaptor_, EmitStringChanged(
592 flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyGsm));
Jason Glasgowaf583282012-04-18 15:18:22 -0400593 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
594 modem_properties, vector<string>());
595 EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_);
596 EXPECT_EQ(kSimPath, capability_->sim_path_);
597 EXPECT_TRUE(capability_->sim_proxy_.get());
598
599 // Changing properties on wrong interface will not have an effect
600 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
601 modem3gpp_properties,
602 vector<string>());
603 EXPECT_EQ("", capability_->imei_);
604
605 // Changing properties on the right interface gets reflected in the
606 // capabilities object
607 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEM3GPP,
608 modem3gpp_properties,
609 vector<string>());
610 EXPECT_EQ(kImei, capability_->imei_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700611 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowbad114b2012-05-21 15:24:16 -0400612
613 // Expect to see changes when the family changes
614 modem_properties.clear();
615 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
616 writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_1XRTT);
617 EXPECT_CALL(*device_adaptor_, EmitStringChanged(
618 flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyCdma)).
619 Times(1);
620 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
621 modem_properties,
622 vector<string>());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700623 Mock::VerifyAndClearExpectations(device_adaptor_);
624
Jason Glasgowbad114b2012-05-21 15:24:16 -0400625 // Back to LTE
626 modem_properties.clear();
627 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
628 writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_LTE);
629 EXPECT_CALL(*device_adaptor_, EmitStringChanged(
630 flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyGsm)).
631 Times(1);
632 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
633 modem_properties,
634 vector<string>());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700635 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowbad114b2012-05-21 15:24:16 -0400636
637 // LTE & CDMA - the device adaptor should not be called!
638 modem_properties.clear();
639 modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES].
640 writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_LTE |
641 MM_MODEM_ACCESS_TECHNOLOGY_1XRTT);
642 EXPECT_CALL(*device_adaptor_, EmitStringChanged(_, _)).Times(0);
643 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
644 modem_properties,
645 vector<string>());
Jason Glasgowaf583282012-04-18 15:18:22 -0400646}
647
Arman Uguray1361c032013-02-11 17:53:39 -0800648TEST_F(CellularCapabilityUniversalMainTest, UpdateServiceName) {
Arman Uguray2717a102013-01-29 23:36:06 -0800649 ::DBus::Struct<uint32_t, bool> data;
650 data._1 = 100;
651 data._2 = true;
652 EXPECT_CALL(*modem_proxy_, SignalQuality()).WillRepeatedly(Return(data));
653
654 SetUp();
655 InitProviderDB();
656 capability_->InitProxies();
Arman Uguray2717a102013-01-29 23:36:06 -0800657
658 SetService();
659
660 size_t len = strlen(CellularCapabilityUniversal::kGenericServiceNamePrefix);
661 EXPECT_EQ(CellularCapabilityUniversal::kGenericServiceNamePrefix,
662 cellular_->service_->friendly_name().substr(0, len));
663
664 capability_->imsi_ = "310240123456789";
665 capability_->SetHomeProvider();
666 EXPECT_EQ("", capability_->spn_);
667 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
668 EXPECT_EQ(CellularCapabilityUniversal::kGenericServiceNamePrefix,
669 cellular_->service_->friendly_name().substr(0, len));
670
671 capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
672 capability_->SetHomeProvider();
673 EXPECT_EQ("", capability_->spn_);
674 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
675 EXPECT_EQ("T-Mobile", cellular_->service_->friendly_name());
676
677 capability_->spn_ = "Test Home Provider";
678 capability_->SetHomeProvider();
679 EXPECT_EQ("Test Home Provider", cellular_->home_provider().GetName());
680 EXPECT_EQ("Test Home Provider", cellular_->service_->friendly_name());
681
682 capability_->On3GPPRegistrationChanged(
683 MM_MODEM_3GPP_REGISTRATION_STATE_HOME, "", "OTA Name");
684 EXPECT_EQ("OTA Name", cellular_->service_->friendly_name());
685
686 capability_->On3GPPRegistrationChanged(
687 MM_MODEM_3GPP_REGISTRATION_STATE_HOME, "123", "OTA Name 2");
688 EXPECT_EQ("OTA Name 2", cellular_->service_->friendly_name());
689
690 capability_->On3GPPRegistrationChanged(
691 MM_MODEM_3GPP_REGISTRATION_STATE_HOME, "123", "");
692 EXPECT_EQ("Test Home Provider", cellular_->service_->friendly_name());
693}
694
Arman Uguray6552f8c2013-02-12 15:33:18 -0800695TEST_F(CellularCapabilityUniversalMainTest, IsValidSimPath) {
696 // Invalid paths
697 EXPECT_FALSE(capability_->IsValidSimPath(""));
698 EXPECT_FALSE(capability_->IsValidSimPath("/"));
699
700 // A valid path
701 EXPECT_TRUE(capability_->IsValidSimPath(
702 "/org/freedesktop/ModemManager1/SIM/0"));
703
704 // Note that any string that is not one of the above invalid paths is
705 // currently regarded as valid, since the ModemManager spec doesn't impose
706 // a strict format on the path. The validity of this is subject to change.
707 EXPECT_TRUE(capability_->IsValidSimPath("path"));
708}
709
Ben Chand7592522013-02-13 16:02:01 -0800710TEST_F(CellularCapabilityUniversalMainTest, NormalizeMdn) {
711 EXPECT_EQ("", capability_->NormalizeMdn(""));
712 EXPECT_EQ("12345678901", capability_->NormalizeMdn("12345678901"));
713 EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1 234 567 8901"));
714 EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1-234-567-8901"));
715 EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1 (234) 567-8901"));
716 EXPECT_EQ("12345678901", capability_->NormalizeMdn("1 234 567 8901 "));
717 EXPECT_EQ("2345678901", capability_->NormalizeMdn("(234) 567-8901"));
718}
719
Arman Uguray1361c032013-02-11 17:53:39 -0800720TEST_F(CellularCapabilityUniversalMainTest, SimPathChanged) {
Ben Chanbd3aee82012-10-16 23:52:04 -0700721 // Set up mock modem SIM properties
722 const char kImsi[] = "310100000001";
723 const char kSimIdentifier[] = "9999888";
724 const char kOperatorIdentifier[] = "310240";
725 const char kOperatorName[] = "Custom SPN";
726 DBusPropertiesMap sim_properties;
727 sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi);
728 sim_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer()
729 .append_string(kSimIdentifier);
730 sim_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer()
731 .append_string(kOperatorIdentifier);
732 sim_properties[MM_SIM_PROPERTY_OPERATORNAME].writer()
733 .append_string(kOperatorName);
734
735 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
736 .Times(1).WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -0700737 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
738 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700739 .Times(1);
Ben Chanbd3aee82012-10-16 23:52:04 -0700740
741 EXPECT_FALSE(capability_->sim_present_);
742 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
743 EXPECT_EQ("", capability_->sim_path_);
744 EXPECT_EQ("", capability_->imsi_);
745 EXPECT_EQ("", capability_->sim_identifier_);
746 EXPECT_EQ("", capability_->operator_id_);
747 EXPECT_EQ("", capability_->spn_);
748
749 capability_->OnSimPathChanged(kSimPath);
750 EXPECT_TRUE(capability_->sim_present_);
751 EXPECT_TRUE(capability_->sim_proxy_ != NULL);
752 EXPECT_EQ(kSimPath, capability_->sim_path_);
753 EXPECT_EQ(kImsi, capability_->imsi_);
754 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
755 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
756 EXPECT_EQ(kOperatorName, capability_->spn_);
757
758 // Changing to the same SIM path should be a no-op.
759 capability_->OnSimPathChanged(kSimPath);
760 EXPECT_TRUE(capability_->sim_present_);
761 EXPECT_TRUE(capability_->sim_proxy_ != NULL);
762 EXPECT_EQ(kSimPath, capability_->sim_path_);
763 EXPECT_EQ(kImsi, capability_->imsi_);
764 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
765 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
766 EXPECT_EQ(kOperatorName, capability_->spn_);
767
768 capability_->OnSimPathChanged("");
Arman Uguray41cc6342013-03-29 16:34:39 -0700769 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700770 Mock::VerifyAndClearExpectations(properties_proxy_.get());
Ben Chanbd3aee82012-10-16 23:52:04 -0700771 EXPECT_FALSE(capability_->sim_present_);
772 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
773 EXPECT_EQ("", capability_->sim_path_);
774 EXPECT_EQ("", capability_->imsi_);
775 EXPECT_EQ("", capability_->sim_identifier_);
776 EXPECT_EQ("", capability_->operator_id_);
777 EXPECT_EQ("", capability_->spn_);
Arman Uguray6552f8c2013-02-12 15:33:18 -0800778
779 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
780 .Times(1).WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -0700781 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
782 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700783 .Times(1);
Arman Uguray6552f8c2013-02-12 15:33:18 -0800784
785 capability_->OnSimPathChanged(kSimPath);
786 EXPECT_TRUE(capability_->sim_present_);
787 EXPECT_TRUE(capability_->sim_proxy_ != NULL);
788 EXPECT_EQ(kSimPath, capability_->sim_path_);
789 EXPECT_EQ(kImsi, capability_->imsi_);
790 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
791 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
792 EXPECT_EQ(kOperatorName, capability_->spn_);
793
794 capability_->OnSimPathChanged("/");
795 EXPECT_FALSE(capability_->sim_present_);
796 EXPECT_TRUE(capability_->sim_proxy_ == NULL);
797 EXPECT_EQ("/", capability_->sim_path_);
798 EXPECT_EQ("", capability_->imsi_);
799 EXPECT_EQ("", capability_->sim_identifier_);
800 EXPECT_EQ("", capability_->operator_id_);
801 EXPECT_EQ("", capability_->spn_);
Ben Chanbd3aee82012-10-16 23:52:04 -0700802}
803
Arman Uguray1361c032013-02-11 17:53:39 -0800804TEST_F(CellularCapabilityUniversalMainTest, SimPropertiesChanged) {
Jason Glasgowaf583282012-04-18 15:18:22 -0400805 // Set up mock modem properties
806 DBusPropertiesMap modem_properties;
807 modem_properties[MM_MODEM_PROPERTY_SIM].writer().append_path(kSimPath);
808
809 // Set up mock modem sim properties
810 const char kImsi[] = "310100000001";
811 DBusPropertiesMap sim_properties;
812 sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi);
813
814 EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM))
815 .WillOnce(Return(sim_properties));
Arman Uguray41cc6342013-03-29 16:34:39 -0700816 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
817 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700818 .Times(0);
Jason Glasgowaf583282012-04-18 15:18:22 -0400819 // After setup we lose pointers to the proxies, so it is hard to set
820 // expectations.
821 SetUp();
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400822 InitProviderDB();
Jason Glasgowaf583282012-04-18 15:18:22 -0400823
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400824 EXPECT_TRUE(cellular_->home_provider().GetName().empty());
825 EXPECT_TRUE(cellular_->home_provider().GetCountry().empty());
826 EXPECT_TRUE(cellular_->home_provider().GetCode().empty());
Jason Glasgowaf583282012-04-18 15:18:22 -0400827 EXPECT_FALSE(capability_->sim_proxy_.get());
828 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
829 modem_properties, vector<string>());
830 EXPECT_EQ(kSimPath, capability_->sim_path_);
831 EXPECT_TRUE(capability_->sim_proxy_.get());
832 EXPECT_EQ(kImsi, capability_->imsi_);
Arman Uguray41cc6342013-03-29 16:34:39 -0700833 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Jason Glasgowaf583282012-04-18 15:18:22 -0400834
835 // Updating the SIM
Arman Uguray41cc6342013-03-29 16:34:39 -0700836 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
837 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -0700838 .Times(2);
Jason Glasgowaf583282012-04-18 15:18:22 -0400839 DBusPropertiesMap new_properties;
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400840 const char kCountry[] = "us";
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400841 const char kNewImsi[] = "310240123456789";
Jason Glasgowaf583282012-04-18 15:18:22 -0400842 const char kSimIdentifier[] = "9999888";
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400843 const char kOperatorIdentifier[] = "310240";
844 const char kOperatorName[] = "Custom SPN";
Jason Glasgowaf583282012-04-18 15:18:22 -0400845 new_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kNewImsi);
846 new_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer().
847 append_string(kSimIdentifier);
848 new_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer().
849 append_string(kOperatorIdentifier);
Jason Glasgowaf583282012-04-18 15:18:22 -0400850 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM,
851 new_properties,
852 vector<string>());
853 EXPECT_EQ(kNewImsi, capability_->imsi_);
854 EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_);
855 EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_);
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400856 EXPECT_EQ("", capability_->spn_);
857 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
858 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
Arman Ugurayd73783f2013-01-31 16:11:21 -0800859 EXPECT_EQ(kOperatorIdentifier, cellular_->home_provider().GetCode());
Jason Glasgow4380f0d2012-05-03 18:05:04 -0400860 EXPECT_EQ(4, capability_->apn_list_.size());
861
862 new_properties[MM_SIM_PROPERTY_OPERATORNAME].writer().
863 append_string(kOperatorName);
864 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM,
865 new_properties,
866 vector<string>());
867 EXPECT_EQ(kOperatorName, cellular_->home_provider().GetName());
Jason Glasgowaf583282012-04-18 15:18:22 -0400868 EXPECT_EQ(kOperatorName, capability_->spn_);
869}
870
Gary Morainceba6aa2012-05-03 10:28:26 -0700871MATCHER_P(SizeIs, value, "") {
872 return static_cast<size_t>(value) == arg.size();
873}
874
Arman Uguray1361c032013-02-11 17:53:39 -0800875TEST_F(CellularCapabilityUniversalMainTest, Reset) {
Ben Chan5d0d32c2013-01-08 02:05:29 -0800876 // Save pointers to proxies before they are lost by the call to InitProxies
877 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
878 SetUp();
879 EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
880 capability_->InitProxies();
881
882 Error error;
883 ResultCallback reset_callback;
884
885 EXPECT_CALL(*modem_proxy, Reset(_, _, CellularCapability::kTimeoutReset))
886 .WillOnce(SaveArg<1>(&reset_callback));
887
888 capability_->Reset(&error, ResultCallback());
889 EXPECT_TRUE(capability_->resetting_);
890 reset_callback.Run(error);
891 EXPECT_FALSE(capability_->resetting_);
892}
893
Gary Morainceba6aa2012-05-03 10:28:26 -0700894// Validates that OnScanReply does not crash with a null callback.
Arman Uguray1361c032013-02-11 17:53:39 -0800895TEST_F(CellularCapabilityUniversalMainTest, ScanWithNullCallback) {
Gary Morainceba6aa2012-05-03 10:28:26 -0700896 Error error;
897 EXPECT_CALL(*modem_3gpp_proxy_, Scan(_, _, CellularCapability::kTimeoutScan))
898 .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeScan));
899 EXPECT_CALL(*device_adaptor_,
900 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
901 SizeIs(0)));
902 Set3gppProxy();
903 capability_->Scan(&error, ResultCallback());
904 EXPECT_TRUE(error.IsSuccess());
905}
906
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400907// Validates that the scanning property is updated
Arman Uguray1361c032013-02-11 17:53:39 -0800908TEST_F(CellularCapabilityUniversalMainTest, Scan) {
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400909 Error error;
910
911 EXPECT_CALL(*modem_3gpp_proxy_, Scan(_, _, CellularCapability::kTimeoutScan))
912 .WillRepeatedly(SaveArg<1>(&scan_callback_));
913 EXPECT_CALL(*device_adaptor_,
914 EmitBoolChanged(flimflam::kScanningProperty, true));
915 Set3gppProxy();
916 capability_->Scan(&error, ResultCallback());
917 EXPECT_TRUE(capability_->scanning_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700918 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400919
920 // Simulate the completion of the scan with 2 networks in the results.
921 EXPECT_CALL(*device_adaptor_,
922 EmitBoolChanged(flimflam::kScanningProperty, false));
923 EXPECT_CALL(*device_adaptor_,
924 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
925 SizeIs(2)));
926 vector<DBusPropertiesMap> results;
927 const char kScanID0[] = "testID0";
928 const char kScanID1[] = "testID1";
929 results.push_back(DBusPropertiesMap());
930 results[0][CellularCapabilityUniversal::kOperatorLongProperty].
931 writer().append_string(kScanID0);
932 results.push_back(DBusPropertiesMap());
933 results[1][CellularCapabilityUniversal::kOperatorLongProperty].
934 writer().append_string(kScanID1);
935 scan_callback_.Run(results, error);
936 EXPECT_FALSE(capability_->scanning_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700937 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400938
939 // Simulate the completion of the scan with no networks in the results.
940 EXPECT_CALL(*device_adaptor_,
941 EmitBoolChanged(flimflam::kScanningProperty, true));
942 capability_->Scan(&error, ResultCallback());
943 EXPECT_TRUE(capability_->scanning_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700944 Mock::VerifyAndClearExpectations(device_adaptor_);
945
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400946 EXPECT_CALL(*device_adaptor_,
947 EmitBoolChanged(flimflam::kScanningProperty, false));
948 EXPECT_CALL(*device_adaptor_,
949 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
950 SizeIs(0)));
951 scan_callback_.Run(vector<DBusPropertiesMap>(), Error());
952 EXPECT_FALSE(capability_->scanning_);
953}
954
955// Validates expected property updates when scan fails
Arman Uguray1361c032013-02-11 17:53:39 -0800956TEST_F(CellularCapabilityUniversalMainTest, ScanFailure) {
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400957 Error error;
958
959 // Test immediate error
960 {
961 InSequence seq;
962 EXPECT_CALL(*modem_3gpp_proxy_,
963 Scan(_, _, CellularCapability::kTimeoutScan))
964 .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::ScanError));
965 EXPECT_CALL(*modem_3gpp_proxy_,
966 Scan(_, _, CellularCapability::kTimeoutScan))
967 .WillOnce(SaveArg<1>(&scan_callback_));
968 }
969 Set3gppProxy();
970 capability_->Scan(&error, ResultCallback());
971 EXPECT_FALSE(capability_->scanning_);
972 EXPECT_TRUE(error.IsFailure());
973
974 // Initiate a scan
975 error.Populate(Error::kSuccess);
976 EXPECT_CALL(*device_adaptor_,
977 EmitBoolChanged(flimflam::kScanningProperty, true));
978 capability_->Scan(&error, ResultCallback());
979 EXPECT_TRUE(capability_->scanning_);
980 EXPECT_TRUE(error.IsSuccess());
981
982 // Validate that error is returned if Scan is called while already scanning.
983 capability_->Scan(&error, ResultCallback());
984 EXPECT_TRUE(capability_->scanning_);
985 EXPECT_TRUE(error.IsFailure());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -0700986 Mock::VerifyAndClearExpectations(device_adaptor_);
Jason Glasgowcd0349c2012-05-03 23:32:15 -0400987
988 // Validate that signals are emitted even if an error is reported.
989 capability_->found_networks_.clear();
990 capability_->found_networks_.push_back(Stringmap());
991 EXPECT_CALL(*device_adaptor_,
992 EmitBoolChanged(flimflam::kScanningProperty, false));
993 EXPECT_CALL(*device_adaptor_,
994 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
995 SizeIs(0)));
996 vector<DBusPropertiesMap> results;
997 scan_callback_.Run(results, Error(Error::kOperationFailed));
998 EXPECT_FALSE(capability_->scanning_);
999}
1000
Arman Uguray6e5639f2012-11-15 20:30:19 -08001001// Validates expected behavior of OnListBearersReply function
Arman Uguray1361c032013-02-11 17:53:39 -08001002TEST_F(CellularCapabilityUniversalMainTest, OnListBearersReply) {
Arman Uguray6e5639f2012-11-15 20:30:19 -08001003 // Check that bearer_path_ is set correctly when an active bearer
1004 // is returned.
1005 const size_t kPathCount = 3;
1006 DBus::Path active_paths[kPathCount], inactive_paths[kPathCount];
1007 for (size_t i = 0; i < kPathCount; ++i) {
1008 active_paths[i] =
1009 DBus::Path(base::StringPrintf("%s/%zu", kActiveBearerPathPrefix, i));
1010 inactive_paths[i] =
1011 DBus::Path(base::StringPrintf("%s/%zu", kInactiveBearerPathPrefix, i));
1012 }
1013
1014 std::vector<DBus::Path> paths;
1015 paths.push_back(inactive_paths[0]);
1016 paths.push_back(inactive_paths[1]);
1017 paths.push_back(active_paths[2]);
1018 paths.push_back(inactive_paths[1]);
1019 paths.push_back(inactive_paths[2]);
1020
1021 Error error;
1022 capability_->OnListBearersReply(paths, error);
1023 EXPECT_STREQ(capability_->bearer_path_.c_str(), active_paths[2].c_str());
1024
1025 paths.clear();
1026
1027 // Check that bearer_path_ is empty if no active bearers are returned.
1028 paths.push_back(inactive_paths[0]);
1029 paths.push_back(inactive_paths[1]);
1030 paths.push_back(inactive_paths[2]);
1031 paths.push_back(inactive_paths[1]);
1032
1033 capability_->OnListBearersReply(paths, error);
1034 EXPECT_TRUE(capability_->bearer_path_.empty());
1035
1036 // Check that returning multiple bearers causes death.
1037 paths.push_back(active_paths[0]);
1038 paths.push_back(inactive_paths[1]);
1039 paths.push_back(inactive_paths[2]);
1040 paths.push_back(active_paths[1]);
1041 paths.push_back(inactive_paths[1]);
1042
1043 EXPECT_DEATH(capability_->OnListBearersReply(paths, error),
1044 "Found more than one active bearer.");
1045}
1046
Jason Glasgow14521872012-05-07 19:12:15 -04001047// Validates expected behavior of Connect function
Arman Uguray1361c032013-02-11 17:53:39 -08001048TEST_F(CellularCapabilityUniversalMainTest, Connect) {
Jason Glasgow14521872012-05-07 19:12:15 -04001049 mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get();
1050 SetSimpleProxy();
1051 Error error;
1052 DBusPropertiesMap properties;
1053 capability_->apn_try_list_.clear();
1054 ResultCallback callback =
1055 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
1056 DBus::Path bearer("/foo");
1057
1058 // Test connect failures
1059 EXPECT_CALL(*modem_simple_proxy, Connect(_, _, _, _))
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001060 .WillRepeatedly(SaveArg<2>(&connect_callback_));
Jason Glasgow14521872012-05-07 19:12:15 -04001061 capability_->Connect(properties, &error, callback);
1062 EXPECT_TRUE(error.IsSuccess());
1063 EXPECT_CALL(*this, TestCallback(IsFailure()));
1064 EXPECT_CALL(*service_, ClearLastGoodApn());
1065 connect_callback_.Run(bearer, Error(Error::kOperationFailed));
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001066 Mock::VerifyAndClearExpectations(this);
Jason Glasgow14521872012-05-07 19:12:15 -04001067
1068 // Test connect success
Jason Glasgow14521872012-05-07 19:12:15 -04001069 capability_->Connect(properties, &error, callback);
1070 EXPECT_TRUE(error.IsSuccess());
1071 EXPECT_CALL(*this, TestCallback(IsSuccess()));
1072 connect_callback_.Run(bearer, Error(Error::kSuccess));
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001073 Mock::VerifyAndClearExpectations(this);
Jason Glasgow7234ec32012-05-23 16:01:21 -04001074
1075 // Test connect failures without a service. Make sure that shill
1076 // does not crash if the connect failed and there is no
1077 // CellularService object. This can happen if the modem is enabled
1078 // and then quickly disabled.
1079 cellular_->service_ = NULL;
1080 EXPECT_FALSE(capability_->cellular()->service());
Jason Glasgow7234ec32012-05-23 16:01:21 -04001081 capability_->Connect(properties, &error, callback);
1082 EXPECT_TRUE(error.IsSuccess());
1083 EXPECT_CALL(*this, TestCallback(IsFailure()));
1084 connect_callback_.Run(bearer, Error(Error::kOperationFailed));
Jason Glasgow14521872012-05-07 19:12:15 -04001085}
1086
1087// Validates Connect iterates over APNs
Arman Uguray1361c032013-02-11 17:53:39 -08001088TEST_F(CellularCapabilityUniversalMainTest, ConnectApns) {
Jason Glasgow14521872012-05-07 19:12:15 -04001089 mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get();
1090 SetSimpleProxy();
1091 Error error;
1092 DBusPropertiesMap properties;
1093 capability_->apn_try_list_.clear();
1094 ResultCallback callback =
1095 Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
1096 DBus::Path bearer("/bearer0");
1097
1098 const char apn_name_foo[] = "foo";
1099 const char apn_name_bar[] = "bar";
1100 EXPECT_CALL(*modem_simple_proxy, Connect(HasApn(apn_name_foo), _, _, _))
1101 .WillOnce(SaveArg<2>(&connect_callback_));
1102 Stringmap apn1;
1103 apn1[flimflam::kApnProperty] = apn_name_foo;
1104 capability_->apn_try_list_.push_back(apn1);
1105 Stringmap apn2;
1106 apn2[flimflam::kApnProperty] = apn_name_bar;
1107 capability_->apn_try_list_.push_back(apn2);
1108 capability_->FillConnectPropertyMap(&properties);
1109 capability_->Connect(properties, &error, callback);
1110 EXPECT_TRUE(error.IsSuccess());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001111 Mock::VerifyAndClearExpectations(modem_simple_proxy);
Jason Glasgow14521872012-05-07 19:12:15 -04001112
1113 EXPECT_CALL(*modem_simple_proxy, Connect(HasApn(apn_name_bar), _, _, _))
1114 .WillOnce(SaveArg<2>(&connect_callback_));
1115 EXPECT_CALL(*service_, ClearLastGoodApn());
1116 connect_callback_.Run(bearer, Error(Error::kInvalidApn));
1117
1118 EXPECT_CALL(*service_, SetLastGoodApn(apn2));
1119 EXPECT_CALL(*this, TestCallback(IsSuccess()));
1120 connect_callback_.Run(bearer, Error(Error::kSuccess));
1121}
1122
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001123// Validates GetTypeString and AccessTechnologyToTechnologyFamily
Arman Uguray1361c032013-02-11 17:53:39 -08001124TEST_F(CellularCapabilityUniversalMainTest, GetTypeString) {
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001125 const int gsm_technologies[] = {
1126 MM_MODEM_ACCESS_TECHNOLOGY_LTE,
1127 MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS,
1128 MM_MODEM_ACCESS_TECHNOLOGY_HSPA,
1129 MM_MODEM_ACCESS_TECHNOLOGY_HSUPA,
1130 MM_MODEM_ACCESS_TECHNOLOGY_HSDPA,
1131 MM_MODEM_ACCESS_TECHNOLOGY_UMTS,
1132 MM_MODEM_ACCESS_TECHNOLOGY_EDGE,
1133 MM_MODEM_ACCESS_TECHNOLOGY_GPRS,
1134 MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT,
1135 MM_MODEM_ACCESS_TECHNOLOGY_GSM,
1136 MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1137 MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1138 MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA,
1139 MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA,
1140 MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB,
1141 MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB,
1142 MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT,
1143 };
Ben Chan62028b22012-11-05 11:20:02 -08001144 for (size_t i = 0; i < arraysize(gsm_technologies); ++i) {
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001145 capability_->access_technologies_ = gsm_technologies[i];
1146 ASSERT_EQ(capability_->GetTypeString(), flimflam::kTechnologyFamilyGsm);
1147 }
1148 const int cdma_technologies[] = {
1149 MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1150 MM_MODEM_ACCESS_TECHNOLOGY_EVDOA,
1151 MM_MODEM_ACCESS_TECHNOLOGY_EVDOA | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1152 MM_MODEM_ACCESS_TECHNOLOGY_EVDOB,
1153 MM_MODEM_ACCESS_TECHNOLOGY_EVDOB | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0,
1154 MM_MODEM_ACCESS_TECHNOLOGY_1XRTT,
1155 };
Ben Chan62028b22012-11-05 11:20:02 -08001156 for (size_t i = 0; i < arraysize(cdma_technologies); ++i) {
Jason Glasgow9f09aef2012-05-08 16:26:55 -04001157 capability_->access_technologies_ = cdma_technologies[i];
1158 ASSERT_EQ(capability_->GetTypeString(), flimflam::kTechnologyFamilyCdma);
1159 }
1160 capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
1161 ASSERT_EQ(capability_->GetTypeString(), "");
1162}
1163
Arman Uguray1361c032013-02-11 17:53:39 -08001164TEST_F(CellularCapabilityUniversalMainTest, AllowRoaming) {
Darin Petkovf508c822012-09-21 13:43:17 +02001165 EXPECT_FALSE(cellular_->allow_roaming_);
1166 EXPECT_FALSE(capability_->provider_requires_roaming_);
1167 EXPECT_FALSE(capability_->AllowRoaming());
1168 capability_->provider_requires_roaming_ = true;
1169 EXPECT_TRUE(capability_->AllowRoaming());
1170 capability_->provider_requires_roaming_ = false;
1171 cellular_->allow_roaming_ = true;
1172 EXPECT_TRUE(capability_->AllowRoaming());
1173}
1174
Arman Uguray1361c032013-02-11 17:53:39 -08001175TEST_F(CellularCapabilityUniversalMainTest, SetHomeProvider) {
Darin Petkovb4fccd22012-08-10 11:59:26 +02001176 static const char kTestCarrier[] = "The Cellular Carrier";
1177 static const char kCountry[] = "us";
1178 static const char kCode[] = "310160";
Darin Petkovb4fccd22012-08-10 11:59:26 +02001179
Darin Petkovf508c822012-09-21 13:43:17 +02001180 EXPECT_FALSE(capability_->home_provider_);
1181 EXPECT_FALSE(capability_->provider_requires_roaming_);
1182
Arman Ugurayd73783f2013-01-31 16:11:21 -08001183 // No mobile provider DB available.
1184 capability_->SetHomeProvider();
Darin Petkovb4fccd22012-08-10 11:59:26 +02001185 EXPECT_TRUE(cellular_->home_provider().GetName().empty());
1186 EXPECT_TRUE(cellular_->home_provider().GetCountry().empty());
1187 EXPECT_TRUE(cellular_->home_provider().GetCode().empty());
Darin Petkovf508c822012-09-21 13:43:17 +02001188 EXPECT_FALSE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001189
1190 InitProviderDB();
Arman Ugurayd73783f2013-01-31 16:11:21 -08001191
1192 // IMSI and Operator Code not available.
1193 capability_->SetHomeProvider();
1194 EXPECT_TRUE(cellular_->home_provider().GetName().empty());
1195 EXPECT_TRUE(cellular_->home_provider().GetCountry().empty());
1196 EXPECT_TRUE(cellular_->home_provider().GetCode().empty());
1197 EXPECT_FALSE(capability_->provider_requires_roaming_);
1198
1199 // Operator Code available.
1200 capability_->operator_id_ = "310240";
1201 capability_->SetHomeProvider();
1202 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
1203 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
1204 EXPECT_EQ("310240", cellular_->home_provider().GetCode());
1205 EXPECT_EQ(4, capability_->apn_list_.size());
1206 ASSERT_TRUE(capability_->home_provider_);
1207 EXPECT_FALSE(capability_->provider_requires_roaming_);
1208
1209 cellular_->home_provider_.SetName("");
1210 cellular_->home_provider_.SetCountry("");
1211 cellular_->home_provider_.SetCode("");
1212
1213 // IMSI available
1214 capability_->imsi_ = "310240123456789";
1215 capability_->operator_id_.clear();
Darin Petkovb4fccd22012-08-10 11:59:26 +02001216 capability_->SetHomeProvider();
1217 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
1218 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
1219 EXPECT_EQ(kCode, cellular_->home_provider().GetCode());
1220 EXPECT_EQ(4, capability_->apn_list_.size());
1221 ASSERT_TRUE(capability_->home_provider_);
Darin Petkovf508c822012-09-21 13:43:17 +02001222 EXPECT_FALSE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001223
1224 Cellular::Operator oper;
1225 cellular_->set_home_provider(oper);
1226 capability_->spn_ = kTestCarrier;
1227 capability_->SetHomeProvider();
1228 EXPECT_EQ(kTestCarrier, cellular_->home_provider().GetName());
1229 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
1230 EXPECT_EQ(kCode, cellular_->home_provider().GetCode());
Darin Petkovf508c822012-09-21 13:43:17 +02001231 EXPECT_FALSE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001232
1233 static const char kCubic[] = "Cubic";
1234 capability_->spn_ = kCubic;
1235 capability_->SetHomeProvider();
1236 EXPECT_EQ(kCubic, cellular_->home_provider().GetName());
1237 EXPECT_EQ("", cellular_->home_provider().GetCode());
1238 ASSERT_TRUE(capability_->home_provider_);
Darin Petkovf508c822012-09-21 13:43:17 +02001239 EXPECT_TRUE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001240
1241 static const char kCUBIC[] = "CUBIC";
1242 capability_->spn_ = kCUBIC;
1243 capability_->home_provider_ = NULL;
1244 capability_->SetHomeProvider();
1245 EXPECT_EQ(kCUBIC, cellular_->home_provider().GetName());
1246 EXPECT_EQ("", cellular_->home_provider().GetCode());
1247 ASSERT_TRUE(capability_->home_provider_);
Darin Petkovf508c822012-09-21 13:43:17 +02001248 EXPECT_TRUE(capability_->provider_requires_roaming_);
Darin Petkovb4fccd22012-08-10 11:59:26 +02001249}
1250
Arman Uguray1361c032013-02-11 17:53:39 -08001251TEST_F(CellularCapabilityUniversalMainTest, UpdateScanningProperty) {
Ben Chan8a2c01e2013-01-23 10:09:14 -08001252 // Save pointers to proxies before they are lost by the call to InitProxies
1253 // mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
1254 SetUp();
1255 //EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
1256 capability_->InitProxies();
1257
1258 EXPECT_FALSE(capability_->scanning_or_searching_);
1259 capability_->UpdateScanningProperty();
1260 EXPECT_FALSE(capability_->scanning_or_searching_);
1261
1262 capability_->scanning_ = true;
1263 capability_->UpdateScanningProperty();
1264 EXPECT_TRUE(capability_->scanning_or_searching_);
1265
1266 capability_->scanning_ = false;
1267 capability_->cellular()->modem_state_ = Cellular::kModemStateInitializing;
1268 capability_->UpdateScanningProperty();
1269 EXPECT_FALSE(capability_->scanning_or_searching_);
1270 capability_->cellular()->modem_state_ = Cellular::kModemStateLocked;
1271 capability_->UpdateScanningProperty();
1272 EXPECT_FALSE(capability_->scanning_or_searching_);
1273 capability_->cellular()->modem_state_ = Cellular::kModemStateDisabled;
1274 capability_->UpdateScanningProperty();
1275 EXPECT_FALSE(capability_->scanning_or_searching_);
1276 capability_->cellular()->modem_state_ = Cellular::kModemStateEnabling;
1277 capability_->UpdateScanningProperty();
1278 EXPECT_TRUE(capability_->scanning_or_searching_);
1279 capability_->cellular()->modem_state_ = Cellular::kModemStateEnabled;
1280 capability_->UpdateScanningProperty();
1281 EXPECT_TRUE(capability_->scanning_or_searching_);
1282 capability_->cellular()->modem_state_ = Cellular::kModemStateSearching;
1283 capability_->UpdateScanningProperty();
1284 EXPECT_TRUE(capability_->scanning_or_searching_);
1285 capability_->cellular()->modem_state_ = Cellular::kModemStateRegistered;
1286 capability_->UpdateScanningProperty();
1287 EXPECT_FALSE(capability_->scanning_or_searching_);
1288 capability_->cellular()->modem_state_ = Cellular::kModemStateConnecting;
1289 capability_->UpdateScanningProperty();
1290 EXPECT_FALSE(capability_->scanning_or_searching_);
1291 capability_->cellular()->modem_state_ = Cellular::kModemStateConnected;
1292 capability_->UpdateScanningProperty();
1293 EXPECT_FALSE(capability_->scanning_or_searching_);
1294 capability_->cellular()->modem_state_ = Cellular::kModemStateDisconnecting;
1295 capability_->UpdateScanningProperty();
1296 EXPECT_FALSE(capability_->scanning_or_searching_);
Ben Chane1e1e562013-01-26 00:39:01 -08001297
Ben Chan40a2f862013-02-13 17:44:38 -08001298 // Modem with an unactivated service in the 'enabled' or 'searching' state
1299 capability_->cellular()->modem_state_ = Cellular::kModemStateEnabled;
Ben Chane1e1e562013-01-26 00:39:01 -08001300 capability_->mdn_ = "0000000000";
Ben Chane1e1e562013-01-26 00:39:01 -08001301 CellularService::OLP olp;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001302 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
Ben Chan40a2f862013-02-13 17:44:38 -08001303 .WillRepeatedly(Return(&olp));
1304 capability_->UpdateScanningProperty();
1305 EXPECT_FALSE(capability_->scanning_or_searching_);
1306
1307 capability_->cellular()->modem_state_ = Cellular::kModemStateSearching;
Ben Chane1e1e562013-01-26 00:39:01 -08001308 capability_->UpdateScanningProperty();
1309 EXPECT_FALSE(capability_->scanning_or_searching_);
Ben Chan8a2c01e2013-01-23 10:09:14 -08001310}
1311
Arman Uguray1361c032013-02-11 17:53:39 -08001312TEST_F(CellularCapabilityUniversalTimerTest, UpdateScanningPropertyTimeout) {
1313 SetUp();
1314 capability_->InitProxies();
1315
1316 EXPECT_FALSE(capability_->scanning_or_searching_);
1317 EXPECT_TRUE(
1318 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1319 capability_->UpdateScanningProperty();
1320 EXPECT_FALSE(capability_->scanning_or_searching_);
1321 EXPECT_TRUE(
1322 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1323
1324 EXPECT_CALL(mock_dispatcher_,
1325 PostDelayedTask(
1326 _,
1327 CellularCapabilityUniversal::
1328 kDefaultScanningOrSearchingTimeoutMilliseconds));
1329
1330 capability_->scanning_ = true;
1331 capability_->UpdateScanningProperty();
1332 EXPECT_FALSE(
1333 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1334 EXPECT_TRUE(capability_->scanning_or_searching_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001335 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
Arman Uguray1361c032013-02-11 17:53:39 -08001336
1337 EXPECT_CALL(mock_dispatcher_,
1338 PostDelayedTask(
1339 _,
1340 CellularCapabilityUniversal::
1341 kDefaultScanningOrSearchingTimeoutMilliseconds))
1342 .Times(0);
1343
1344 capability_->scanning_ = false;
1345 capability_->UpdateScanningProperty();
1346 EXPECT_TRUE(
1347 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1348 EXPECT_FALSE(capability_->scanning_or_searching_);
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001349 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
Arman Uguray1361c032013-02-11 17:53:39 -08001350
1351 EXPECT_CALL(mock_dispatcher_,
1352 PostDelayedTask(
1353 _,
1354 CellularCapabilityUniversal::
1355 kDefaultScanningOrSearchingTimeoutMilliseconds))
1356 .WillOnce(InvokeWithoutArgs(
1357 this,
1358 &CellularCapabilityUniversalTest::InvokeScanningOrSearchingTimeout));
1359
1360 capability_->scanning_ = true;
1361 capability_->UpdateScanningProperty();
1362 // The callback has been scheduled
1363 EXPECT_FALSE(
1364 capability_->scanning_or_searching_timeout_callback_.IsCancelled());
1365 // Our mock invocation worked
1366 EXPECT_FALSE(capability_->scanning_or_searching_);
1367}
1368
1369TEST_F(CellularCapabilityUniversalMainTest, UpdateStorageIdentifier) {
Arman Ugurayc9533572013-01-22 17:34:20 -08001370 CellularOperatorInfo::CellularOperator provider;
Arman Ugurayc9533572013-01-22 17:34:20 -08001371
1372 SetService();
1373
1374 const string prefix = "cellular_" + string(kMachineAddress) + "_";
Arman Uguray2717a102013-01-29 23:36:06 -08001375 string default_identifier_pattern =
1376 prefix + string(CellularCapabilityUniversal::kGenericServiceNamePrefix);
1377 std::replace_if(default_identifier_pattern.begin(),
1378 default_identifier_pattern.end(),
1379 &Service::IllegalChar, '_');
1380 default_identifier_pattern += "*";
Arman Ugurayc9533572013-01-22 17:34:20 -08001381
1382 // |capability_->operator_id_| is "".
1383 capability_->UpdateStorageIdentifier();
1384 EXPECT_TRUE(::MatchPattern(cellular_->service()->storage_identifier_,
1385 default_identifier_pattern));
1386
1387 // GetCellularOperatorByMCCMNC returns NULL.
1388 capability_->operator_id_ = "1";
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001389 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Arman Ugurayc9533572013-01-22 17:34:20 -08001390 GetCellularOperatorByMCCMNC(capability_->operator_id_))
1391 .WillOnce(
1392 Return((const CellularOperatorInfo::CellularOperator *)NULL));
1393
1394 capability_->UpdateStorageIdentifier();
1395 EXPECT_TRUE(::MatchPattern(cellular_->service()->storage_identifier_,
1396 default_identifier_pattern));
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001397 Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info());
Arman Ugurayc9533572013-01-22 17:34:20 -08001398
1399 // |capability_->imsi_| is not ""
1400 capability_->imsi_ = "TESTIMSI";
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001401 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Arman Ugurayc9533572013-01-22 17:34:20 -08001402 GetCellularOperatorByMCCMNC(capability_->operator_id_))
1403 .WillOnce(
1404 Return((const CellularOperatorInfo::CellularOperator *)NULL));
1405
1406 capability_->UpdateStorageIdentifier();
1407 EXPECT_EQ(prefix + "TESTIMSI", cellular_->service()->storage_identifier_);
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001408 Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info());
Arman Ugurayc9533572013-01-22 17:34:20 -08001409
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001410 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Arman Ugurayc9533572013-01-22 17:34:20 -08001411 GetCellularOperatorByMCCMNC(capability_->operator_id_))
1412 .Times(2)
1413 .WillRepeatedly(Return(&provider));
1414
1415 // |provider.identifier_| is "".
1416 capability_->UpdateStorageIdentifier();
1417 EXPECT_EQ(prefix + "TESTIMSI", cellular_->service()->storage_identifier_);
1418
1419 // Success.
1420 provider.identifier_ = "testidentifier";
1421 capability_->UpdateStorageIdentifier();
1422 EXPECT_EQ(prefix + "testidentifier",
1423 cellular_->service()->storage_identifier_);
1424}
1425
Arman Uguray1361c032013-02-11 17:53:39 -08001426TEST_F(CellularCapabilityUniversalMainTest, UpdateOLP) {
Ben Chan6d0d1e72012-11-06 21:19:28 -08001427 CellularService::OLP test_olp;
1428 test_olp.SetURL("http://testurl");
1429 test_olp.SetMethod("POST");
Arman Uguray72fab6a2013-01-10 19:32:42 -08001430 test_olp.SetPostData("imei=${imei}&imsi=${imsi}&mdn=${mdn}&"
1431 "min=${min}&iccid=${iccid}");
Ben Chan6d0d1e72012-11-06 21:19:28 -08001432
Ben Chan6d0d1e72012-11-06 21:19:28 -08001433 capability_->imei_ = "1";
1434 capability_->imsi_ = "2";
1435 capability_->mdn_ = "3";
Ben Chan6d0d1e72012-11-06 21:19:28 -08001436 capability_->min_ = "5";
1437 capability_->sim_identifier_ = "6";
1438 capability_->operator_id_ = "123456";
Ben Chan6d0d1e72012-11-06 21:19:28 -08001439
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001440 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Arman Ugurayf4c61812013-01-10 18:58:39 -08001441 GetOLPByMCCMNC(capability_->operator_id_))
1442 .WillRepeatedly(Return(&test_olp));
Ben Chan6d0d1e72012-11-06 21:19:28 -08001443
1444 SetService();
1445 capability_->UpdateOLP();
1446 const CellularService::OLP &olp = cellular_->service()->olp();
1447 EXPECT_EQ("http://testurl", olp.GetURL());
1448 EXPECT_EQ("POST", olp.GetMethod());
Arman Uguray72fab6a2013-01-10 19:32:42 -08001449 EXPECT_EQ("imei=1&imsi=2&mdn=3&min=5&iccid=6",
Ben Chan6d0d1e72012-11-06 21:19:28 -08001450 olp.GetPostData());
1451}
1452
Arman Ugurayc7b15602013-02-16 00:56:18 -08001453TEST_F(CellularCapabilityUniversalMainTest, IsMdnValid) {
1454 capability_->mdn_.clear();
1455 EXPECT_FALSE(capability_->IsMdnValid());
1456 capability_->mdn_ = "0000000";
1457 EXPECT_FALSE(capability_->IsMdnValid());
1458 capability_->mdn_ = "0000001";
1459 EXPECT_TRUE(capability_->IsMdnValid());
1460 capability_->mdn_ = "1231223";
1461 EXPECT_TRUE(capability_->IsMdnValid());
1462}
1463
Arman Uguraya14941d2013-04-12 16:58:26 -07001464TEST_F(CellularCapabilityUniversalTimerTest, CompleteActivation) {
Arman Ugurayefea6e02013-02-21 13:28:04 -08001465 const char kIccid[] = "1234567";
1466
1467 capability_->mdn_.clear();
1468 capability_->sim_identifier_.clear();
Arman Ugurayefea6e02013-02-21 13:28:04 -08001469
Arman Ugurayefea6e02013-02-21 13:28:04 -08001470 EXPECT_CALL(*service_,
1471 SetActivationState(flimflam::kActivationStateActivating))
1472 .Times(0);
Arman Uguray41cc6342013-03-29 16:34:39 -07001473 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1474 SetActivationState(
1475 PendingActivationStore::kIdentifierICCID, _, _))
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001476 .Times(0);
Arman Uguraya14941d2013-04-12 16:58:26 -07001477 EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(0);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001478 Error error;
1479 capability_->CompleteActivation(&error);
Arman Uguray41cc6342013-03-29 16:34:39 -07001480 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001481 Mock::VerifyAndClearExpectations(service_);
Arman Uguraya14941d2013-04-12 16:58:26 -07001482 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
1483 EXPECT_TRUE(
1484 capability_->activation_wait_for_registration_callback_.IsCancelled());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001485
1486 capability_->sim_identifier_ = kIccid;
Arman Uguray41cc6342013-03-29 16:34:39 -07001487 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1488 SetActivationState(PendingActivationStore::kIdentifierICCID,
1489 kIccid,
1490 PendingActivationStore::kStatePending))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001491 .Times(1);
1492 EXPECT_CALL(*service_,
1493 SetActivationState(flimflam::kActivationStateActivating))
1494 .Times(1);
Arman Uguraya14941d2013-04-12 16:58:26 -07001495 EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(1);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001496 capability_->CompleteActivation(&error);
Arman Uguray41cc6342013-03-29 16:34:39 -07001497 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001498 Mock::VerifyAndClearExpectations(service_);
Arman Uguraya14941d2013-04-12 16:58:26 -07001499 Mock::VerifyAndClearExpectations(&mock_dispatcher_);
1500 EXPECT_FALSE(
1501 capability_->activation_wait_for_registration_callback_.IsCancelled());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001502
Arman Uguray41cc6342013-03-29 16:34:39 -07001503 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1504 SetActivationState(PendingActivationStore::kIdentifierICCID,
1505 kIccid,
1506 PendingActivationStore::kStatePending))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001507 .Times(0);
1508 EXPECT_CALL(*service_,
1509 SetActivationState(flimflam::kActivationStateActivating))
1510 .Times(0);
Arman Uguraya14941d2013-04-12 16:58:26 -07001511 EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(0);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001512 capability_->mdn_ = "1231231212";
1513 capability_->CompleteActivation(&error);
1514}
1515
1516TEST_F(CellularCapabilityUniversalMainTest, UpdateServiceActivationState) {
1517 const char kIccid[] = "1234567";
Arman Ugurayefea6e02013-02-21 13:28:04 -08001518 capability_->sim_identifier_.clear();
1519 capability_->mdn_ = "0000000000";
Arman Ugurayefea6e02013-02-21 13:28:04 -08001520 CellularService::OLP olp;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001521 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001522 .WillRepeatedly(Return(&olp));
1523
1524 EXPECT_CALL(*service_,
1525 SetActivationState(flimflam::kActivationStateNotActivated))
1526 .Times(1);
1527 capability_->UpdateServiceActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001528 Mock::VerifyAndClearExpectations(service_);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001529
1530 capability_->mdn_ = "1231231122";
1531 EXPECT_CALL(*service_,
1532 SetActivationState(flimflam::kActivationStateActivated))
1533 .Times(1);
1534 capability_->UpdateServiceActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001535 Mock::VerifyAndClearExpectations(service_);
Arman Ugurayefea6e02013-02-21 13:28:04 -08001536
1537 capability_->mdn_ = "0000000000";
1538 capability_->sim_identifier_ = kIccid;
Arman Uguray41cc6342013-03-29 16:34:39 -07001539 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1540 GetActivationState(PendingActivationStore::kIdentifierICCID,
1541 kIccid))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001542 .Times(2)
Arman Uguray41cc6342013-03-29 16:34:39 -07001543 .WillOnce(Return(PendingActivationStore::kStatePending))
1544 .WillOnce(Return(PendingActivationStore::kStatePendingTimeout));
Arman Ugurayefea6e02013-02-21 13:28:04 -08001545 EXPECT_CALL(*service_,
1546 SetActivationState(flimflam::kActivationStateActivating))
1547 .Times(1);
1548 capability_->UpdateServiceActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001549 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001550 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001551
Arman Uguray41cc6342013-03-29 16:34:39 -07001552 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1553 GetActivationState(PendingActivationStore::kIdentifierICCID,
1554 kIccid))
Arman Ugurayefea6e02013-02-21 13:28:04 -08001555 .Times(2)
Arman Uguray41cc6342013-03-29 16:34:39 -07001556 .WillRepeatedly(Return(PendingActivationStore::kStateActivated));
Arman Ugurayefea6e02013-02-21 13:28:04 -08001557 EXPECT_CALL(*service_,
1558 SetActivationState(flimflam::kActivationStateActivated))
1559 .Times(1);
1560 capability_->UpdateServiceActivationState();
1561}
1562
Arman Uguraya14941d2013-04-12 16:58:26 -07001563TEST_F(CellularCapabilityUniversalMainTest, ActivationWaitForRegisterTimeout) {
1564 const char kIccid[] = "1234567";
1565
1566 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
1567 capability_->InitProxies();
Arman Uguray41cc6342013-03-29 16:34:39 -07001568 EXPECT_CALL(*modem_proxy, Reset(_, _, _)).Times(0);
1569 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1570 SetActivationState(_, _, _))
Arman Uguraya14941d2013-04-12 16:58:26 -07001571 .Times(0);
1572
1573 // No ICCID, no MDN
1574 capability_->sim_identifier_.clear();
1575 capability_->mdn_.clear();
1576 capability_->reset_done_ = false;
1577 capability_->OnActivationWaitForRegisterTimeout();
1578
1579 // State is not activated.
1580 capability_->sim_identifier_ = kIccid;
Arman Uguray41cc6342013-03-29 16:34:39 -07001581 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1582 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
1583 .WillOnce(Return(PendingActivationStore::kStateActivated))
1584 .WillRepeatedly(Return(PendingActivationStore::kStatePending));
Arman Uguraya14941d2013-04-12 16:58:26 -07001585 capability_->OnActivationWaitForRegisterTimeout();
1586
1587 // Valid MDN.
1588 capability_->mdn_ = "0000000001";
1589 capability_->OnActivationWaitForRegisterTimeout();
1590
1591 // Invalid MDN, reset done.
1592 capability_->mdn_ = "0000000000";
1593 capability_->reset_done_ = true;
1594 capability_->OnActivationWaitForRegisterTimeout();
1595
1596 Mock::VerifyAndClearExpectations(modem_proxy);
Arman Uguray41cc6342013-03-29 16:34:39 -07001597 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07001598
1599 // Reset not done.
1600 capability_->reset_done_ = false;
1601 EXPECT_CALL(*modem_proxy, Reset(_,_,_)).Times(1);
Arman Uguray41cc6342013-03-29 16:34:39 -07001602 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1603 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
1604 .WillOnce(Return(PendingActivationStore::kStatePending));
1605 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1606 SetActivationState(PendingActivationStore::kIdentifierICCID,
1607 kIccid,
1608 PendingActivationStore::kStatePendingTimeout))
Arman Uguraya14941d2013-04-12 16:58:26 -07001609 .Times(1);
1610 capability_->OnActivationWaitForRegisterTimeout();
1611}
1612
Arman Uguray0a3e2792013-01-17 16:31:50 -08001613TEST_F(CellularCapabilityUniversalMainTest, UpdatePendingActivationState) {
Arman Ugurayc7b15602013-02-16 00:56:18 -08001614 const char kIccid[] = "1234567";
1615
1616 mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001617 capability_->InitProxies();
1618 capability_->registration_state_ =
1619 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING;
1620
1621 // No MDN, no ICCID.
1622 capability_->mdn_ = "0000000";
1623 capability_->sim_identifier_.clear();
Arman Uguray41cc6342013-03-29 16:34:39 -07001624 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1625 GetActivationState(PendingActivationStore::kIdentifierICCID, _))
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001626 .Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001627 capability_->UpdatePendingActivationState();
Arman Uguray41cc6342013-03-29 16:34:39 -07001628 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001629
1630 // ICCID known.
1631 capability_->sim_identifier_ = kIccid;
1632
1633 // After the modem has reset.
1634 capability_->reset_done_ = true;
Arman Uguray41cc6342013-03-29 16:34:39 -07001635 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1636 GetActivationState(PendingActivationStore::kIdentifierICCID,
1637 kIccid))
1638 .Times(1).WillOnce(Return(PendingActivationStore::kStatePending));
1639 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1640 SetActivationState(PendingActivationStore::kIdentifierICCID,
1641 kIccid,
1642 PendingActivationStore::kStateActivated))
Arman Ugurayc7b15602013-02-16 00:56:18 -08001643 .Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001644 capability_->UpdatePendingActivationState();
Arman Uguray41cc6342013-03-29 16:34:39 -07001645 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001646
1647 // Before reset, not registered.
1648 capability_->reset_done_ = false;
Arman Uguray41cc6342013-03-29 16:34:39 -07001649 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1650 GetActivationState(PendingActivationStore::kIdentifierICCID,
1651 kIccid))
1652 .Times(2).WillRepeatedly(Return(PendingActivationStore::kStatePending));
Arman Ugurayefea6e02013-02-21 13:28:04 -08001653 EXPECT_CALL(*service_,
1654 SetActivationState(flimflam::kActivationStateActivating))
1655 .Times(2);
Arman Ugurayc7b15602013-02-16 00:56:18 -08001656 EXPECT_CALL(*modem_proxy, Reset(_, _, _)).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001657 capability_->UpdatePendingActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001658 Mock::VerifyAndClearExpectations(modem_proxy);
Arman Ugurayc7b15602013-02-16 00:56:18 -08001659
1660 // Before reset, registered.
1661 capability_->registration_state_ =
1662 MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
1663 EXPECT_CALL(*modem_proxy, Reset(_, _, _)).Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001664 capability_->UpdatePendingActivationState();
Arman Uguray41cc6342013-03-29 16:34:39 -07001665 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001666
1667 // Not registered.
1668 capability_->registration_state_ =
1669 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING;
Arman Uguray41cc6342013-03-29 16:34:39 -07001670 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1671 GetActivationState(PendingActivationStore::kIdentifierICCID,
1672 kIccid))
1673 .Times(2).WillRepeatedly(Return(PendingActivationStore::kStateActivated));
Arman Ugurayc7b15602013-02-16 00:56:18 -08001674 EXPECT_CALL(*service_, AutoConnect()).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001675 capability_->UpdatePendingActivationState();
Prathmesh Prabhub5fde532013-03-19 17:36:09 -07001676 Mock::VerifyAndClearExpectations(service_);
Arman Ugurayc7b15602013-02-16 00:56:18 -08001677
1678 // Service, registered.
1679 capability_->registration_state_ =
1680 MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
1681 EXPECT_CALL(*service_, AutoConnect()).Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001682 capability_->UpdatePendingActivationState();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001683
1684 cellular_->service_->activation_state_ =
1685 flimflam::kActivationStateNotActivated;
1686
Arman Uguray41cc6342013-03-29 16:34:39 -07001687 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07001688
Arman Ugurayc7b15602013-02-16 00:56:18 -08001689 // Device is connected.
1690 cellular_->state_ = Cellular::kStateConnected;
1691 EXPECT_CALL(*service_,
1692 SetActivationState(flimflam::kActivationStateActivated))
1693 .Times(3);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001694 capability_->UpdatePendingActivationState();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001695
1696 // Device is linked.
1697 cellular_->state_ = Cellular::kStateLinked;
Arman Uguray0a3e2792013-01-17 16:31:50 -08001698 capability_->UpdatePendingActivationState();
Arman Ugurayc7b15602013-02-16 00:56:18 -08001699
1700 // Got valid MDN.
1701 cellular_->state_ = Cellular::kStateRegistered;
1702 capability_->mdn_ = "1231223";
Arman Uguray41cc6342013-03-29 16:34:39 -07001703 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1704 RemoveEntry(PendingActivationStore::kIdentifierICCID, kIccid))
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001705 .Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001706 capability_->UpdatePendingActivationState();
Arman Uguraya14941d2013-04-12 16:58:26 -07001707
1708 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001709 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07001710
1711 // Timed out, not registered.
1712 capability_->mdn_.clear();
Arman Uguray41cc6342013-03-29 16:34:39 -07001713 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1714 GetActivationState(PendingActivationStore::kIdentifierICCID,
1715 kIccid))
Arman Uguraya14941d2013-04-12 16:58:26 -07001716 .Times(1)
Arman Uguray41cc6342013-03-29 16:34:39 -07001717 .WillOnce(Return(PendingActivationStore::kStatePendingTimeout));
Arman Uguraya14941d2013-04-12 16:58:26 -07001718 capability_->registration_state_ =
1719 MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING;
Arman Uguray41cc6342013-03-29 16:34:39 -07001720 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1721 SetActivationState(_, _, _))
Arman Uguraya14941d2013-04-12 16:58:26 -07001722 .Times(0);
1723 EXPECT_CALL(*service_, SetActivationState(_)).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001724 capability_->UpdatePendingActivationState();
Arman Uguraya14941d2013-04-12 16:58:26 -07001725 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001726 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguraya14941d2013-04-12 16:58:26 -07001727
1728 // Timed out, registered.
Arman Uguray41cc6342013-03-29 16:34:39 -07001729 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1730 GetActivationState(PendingActivationStore::kIdentifierICCID,
1731 kIccid))
Arman Uguraya14941d2013-04-12 16:58:26 -07001732 .Times(1)
Arman Uguray41cc6342013-03-29 16:34:39 -07001733 .WillOnce(Return(PendingActivationStore::kStatePendingTimeout));
Arman Uguraya14941d2013-04-12 16:58:26 -07001734 capability_->registration_state_ =
1735 MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
Arman Uguray41cc6342013-03-29 16:34:39 -07001736 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1737 SetActivationState(PendingActivationStore::kIdentifierICCID,
1738 kIccid,
1739 PendingActivationStore::kStateActivated))
Arman Uguraya14941d2013-04-12 16:58:26 -07001740 .Times(1);
1741 EXPECT_CALL(*service_,
1742 SetActivationState(flimflam::kActivationStateActivated))
1743 .Times(1);
Arman Uguray0a3e2792013-01-17 16:31:50 -08001744 capability_->UpdatePendingActivationState();
Arman Uguraya14941d2013-04-12 16:58:26 -07001745 Mock::VerifyAndClearExpectations(service_);
Arman Uguray41cc6342013-03-29 16:34:39 -07001746 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Ugurayc7b15602013-02-16 00:56:18 -08001747}
1748
Arman Uguray1361c032013-02-11 17:53:39 -08001749TEST_F(CellularCapabilityUniversalMainTest, UpdateOperatorInfo) {
Darin Petkova4ca3c32012-08-17 16:05:24 +02001750 static const char kOperatorName[] = "Swisscom";
1751 InitProviderDB();
1752 capability_->serving_operator_.SetCode("22801");
1753 SetService();
1754 capability_->UpdateOperatorInfo();
1755 EXPECT_EQ(kOperatorName, capability_->serving_operator_.GetName());
1756 EXPECT_EQ("ch", capability_->serving_operator_.GetCountry());
1757 EXPECT_EQ(kOperatorName, cellular_->service()->serving_operator().GetName());
1758
1759 static const char kTestOperator[] = "Testcom";
1760 capability_->serving_operator_.SetName(kTestOperator);
1761 capability_->serving_operator_.SetCountry("");
1762 capability_->UpdateOperatorInfo();
1763 EXPECT_EQ(kTestOperator, capability_->serving_operator_.GetName());
1764 EXPECT_EQ("ch", capability_->serving_operator_.GetCountry());
1765 EXPECT_EQ(kTestOperator, cellular_->service()->serving_operator().GetName());
1766}
1767
Arman Uguray1361c032013-02-11 17:53:39 -08001768TEST_F(CellularCapabilityUniversalMainTest, UpdateOperatorInfoViaOperatorId) {
Ben Chan092b12b2012-11-07 22:04:05 -08001769 static const char kOperatorName[] = "Swisscom";
1770 static const char kOperatorId[] = "22801";
1771 InitProviderDB();
1772 capability_->serving_operator_.SetCode("");
1773 SetService();
1774 capability_->UpdateOperatorInfo();
1775 EXPECT_EQ("", capability_->serving_operator_.GetName());
1776 EXPECT_EQ("", capability_->serving_operator_.GetCountry());
1777 EXPECT_EQ("", cellular_->service()->serving_operator().GetName());
1778
1779 capability_->operator_id_ = kOperatorId;
1780
Ben Chan092b12b2012-11-07 22:04:05 -08001781 capability_->UpdateOperatorInfo();
1782 EXPECT_EQ(kOperatorId, capability_->serving_operator_.GetCode());
1783 EXPECT_EQ(kOperatorName, capability_->serving_operator_.GetName());
1784 EXPECT_EQ("ch", capability_->serving_operator_.GetCountry());
1785 EXPECT_EQ(kOperatorName, cellular_->service()->serving_operator().GetName());
1786}
1787
Arman Uguray1361c032013-02-11 17:53:39 -08001788TEST_F(CellularCapabilityUniversalMainTest, CreateFriendlyServiceName) {
Darin Petkova4ca3c32012-08-17 16:05:24 +02001789 CellularCapabilityUniversal::friendly_service_name_id_ = 0;
Arman Uguray2717a102013-01-29 23:36:06 -08001790 EXPECT_EQ("Mobile Network 0", capability_->CreateFriendlyServiceName());
1791 EXPECT_EQ("Mobile Network 1", capability_->CreateFriendlyServiceName());
Darin Petkova4ca3c32012-08-17 16:05:24 +02001792
Ben Chan092b12b2012-11-07 22:04:05 -08001793 capability_->operator_id_ = "0123";
Ben Chan092b12b2012-11-07 22:04:05 -08001794 EXPECT_EQ("cellular_0123", capability_->CreateFriendlyServiceName());
1795 EXPECT_EQ("0123", capability_->serving_operator_.GetCode());
1796
Darin Petkova4ca3c32012-08-17 16:05:24 +02001797 capability_->serving_operator_.SetCode("1234");
1798 EXPECT_EQ("cellular_1234", capability_->CreateFriendlyServiceName());
1799
1800 static const char kHomeProvider[] = "The GSM Home Provider";
1801 cellular_->home_provider_.SetName(kHomeProvider);
1802 EXPECT_EQ("cellular_1234", capability_->CreateFriendlyServiceName());
1803 capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_HOME;
1804 EXPECT_EQ(kHomeProvider, capability_->CreateFriendlyServiceName());
1805
1806 static const char kTestOperator[] = "A GSM Operator";
1807 capability_->serving_operator_.SetName(kTestOperator);
1808 EXPECT_EQ(kTestOperator, capability_->CreateFriendlyServiceName());
1809
1810 capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING;
1811 EXPECT_EQ(StringPrintf("%s | %s", kHomeProvider, kTestOperator),
1812 capability_->CreateFriendlyServiceName());
1813}
1814
Arman Uguray1361c032013-02-11 17:53:39 -08001815TEST_F(CellularCapabilityUniversalMainTest, IsServiceActivationRequired) {
Ben Chan15786032012-11-04 21:28:02 -08001816 capability_->mdn_ = "0000000000";
Ben Chan15786032012-11-04 21:28:02 -08001817 EXPECT_FALSE(capability_->IsServiceActivationRequired());
1818
Arman Ugurayf4c61812013-01-10 18:58:39 -08001819 CellularService::OLP olp;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -07001820 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
Arman Ugurayf4c61812013-01-10 18:58:39 -08001821 .WillOnce(Return((const CellularService::OLP *)NULL))
1822 .WillRepeatedly(Return(&olp));
Ben Chan15786032012-11-04 21:28:02 -08001823 EXPECT_FALSE(capability_->IsServiceActivationRequired());
1824
1825 capability_->mdn_ = "";
1826 EXPECT_FALSE(capability_->IsServiceActivationRequired());
1827 capability_->mdn_ = "1234567890";
1828 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Ben Chan15786032012-11-04 21:28:02 -08001829 capability_->mdn_ = "0000000000";
1830 EXPECT_TRUE(capability_->IsServiceActivationRequired());
Arman Ugurayefea6e02013-02-21 13:28:04 -08001831
1832 const char kIccid[] = "1234567890";
1833 capability_->sim_identifier_ = kIccid;
Arman Uguray41cc6342013-03-29 16:34:39 -07001834 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
1835 GetActivationState(PendingActivationStore::kIdentifierICCID,
1836 kIccid))
1837 .WillOnce(Return(PendingActivationStore::kStateActivated))
1838 .WillOnce(Return(PendingActivationStore::kStatePending))
1839 .WillOnce(Return(PendingActivationStore::kStatePendingTimeout))
1840 .WillOnce(Return(PendingActivationStore::kStateUnknown));
Arman Ugurayefea6e02013-02-21 13:28:04 -08001841 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Arman Uguraya14941d2013-04-12 16:58:26 -07001842 EXPECT_FALSE(capability_->IsServiceActivationRequired());
1843 EXPECT_FALSE(capability_->IsServiceActivationRequired());
1844 EXPECT_TRUE(capability_->IsServiceActivationRequired());
Arman Uguray41cc6342013-03-29 16:34:39 -07001845 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Ben Chan15786032012-11-04 21:28:02 -08001846}
1847
Arman Uguray1361c032013-02-11 17:53:39 -08001848TEST_F(CellularCapabilityUniversalMainTest, OnModemCurrentCapabilitiesChanged) {
Ben Chanfcca27b2013-01-22 15:03:44 -08001849 EXPECT_FALSE(capability_->scanning_supported_);
1850 capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_LTE);
1851 EXPECT_FALSE(capability_->scanning_supported_);
1852 capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_CDMA_EVDO);
1853 EXPECT_FALSE(capability_->scanning_supported_);
1854 capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_GSM_UMTS);
1855 EXPECT_TRUE(capability_->scanning_supported_);
1856 capability_->OnModemCurrentCapabilitiesChanged(
1857 MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_CDMA_EVDO);
1858 EXPECT_TRUE(capability_->scanning_supported_);
1859}
1860
Arman Uguray7af0fac2013-03-18 17:35:35 -07001861TEST_F(CellularCapabilityUniversalMainTest, GetNetworkTechnologyStringOnE362) {
1862 capability_->model_id_.clear();
1863 capability_->access_technologies_ = 0;
1864 EXPECT_TRUE(capability_->GetNetworkTechnologyString().empty());
1865
1866 capability_->model_id_ = CellularCapabilityUniversal::kE362ModelId;
1867 EXPECT_EQ(flimflam::kNetworkTechnologyLte,
1868 capability_->GetNetworkTechnologyString());
1869
1870 capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_GPRS;
1871 EXPECT_EQ(flimflam::kNetworkTechnologyLte,
1872 capability_->GetNetworkTechnologyString());
1873
1874 capability_->model_id_.clear();
1875 EXPECT_EQ(flimflam::kNetworkTechnologyGprs,
1876 capability_->GetNetworkTechnologyString());
1877}
1878
Arman Ugurayf84a4242013-04-09 20:01:07 -07001879TEST_F(CellularCapabilityUniversalMainTest, ShouldDetectOutOfCredit) {
Arman Ugurayd42d8ec2013-04-08 19:28:21 -07001880 capability_->model_id_.clear();
Arman Ugurayf84a4242013-04-09 20:01:07 -07001881 EXPECT_FALSE(capability_->ShouldDetectOutOfCredit());
Arman Ugurayd42d8ec2013-04-08 19:28:21 -07001882 capability_->model_id_ = CellularCapabilityUniversal::kE362ModelId;
Arman Ugurayf84a4242013-04-09 20:01:07 -07001883 EXPECT_TRUE(capability_->ShouldDetectOutOfCredit());
Arman Ugurayd42d8ec2013-04-08 19:28:21 -07001884}
1885
Jason Glasgowef965562012-04-10 16:12:35 -04001886} // namespace shill