blob: 681fd76a154816100c9ab0968bb79b378df36985 [file] [log] [blame]
Arman Uguray72fab6a2013-01-10 19:32:42 -08001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// 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_cdma.h"
6
7#include <string>
8#include <vector>
9
Arman Ugurayc5391232013-09-23 21:30:46 -070010#include <base/string_util.h>
Arman Uguray72fab6a2013-01-10 19:32:42 -080011#include <base/stringprintf.h>
12#include <gmock/gmock.h>
13#include <gtest/gtest.h>
14#include <ModemManager/ModemManager.h>
15
16#include "shill/cellular.h"
17#include "shill/cellular_service.h"
18#include "shill/event_dispatcher.h"
19#include "shill/mock_adaptors.h"
20#include "shill/mock_cellular_operator_info.h"
21#include "shill/mock_cellular_service.h"
22#include "shill/mock_dbus_properties_proxy.h"
23#include "shill/mock_glib.h"
24#include "shill/mock_manager.h"
25#include "shill/mock_metrics.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080026#include "shill/mock_mm1_modem_modem3gpp_proxy.h"
27#include "shill/mock_mm1_modem_modemcdma_proxy.h"
28#include "shill/mock_mm1_modem_proxy.h"
29#include "shill/mock_mm1_modem_simple_proxy.h"
30#include "shill/mock_mm1_sim_proxy.h"
31#include "shill/mock_modem_info.h"
Arman Uguray0a3e2792013-01-17 16:31:50 -080032#include "shill/mock_pending_activation_store.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080033#include "shill/nice_mock_control.h"
34#include "shill/proxy_factory.h"
35
36using base::StringPrintf;
37using std::string;
38using std::vector;
39using testing::Invoke;
40using testing::Mock;
41using testing::NiceMock;
42using testing::Return;
43using testing::SetArgumentPointee;
44using testing::_;
45
46namespace shill {
47
48class CellularCapabilityUniversalCDMATest : public testing::Test {
49 public:
Arman Uguray0a3e2792013-01-17 16:31:50 -080050 CellularCapabilityUniversalCDMATest(EventDispatcher *dispatcher)
Arman Uguray72fab6a2013-01-10 19:32:42 -080051 : capability_(NULL),
52 device_adaptor_(NULL),
Arman Uguray0a3e2792013-01-17 16:31:50 -080053 modem_info_(NULL, dispatcher, NULL, NULL, NULL),
Arman Uguray72fab6a2013-01-10 19:32:42 -080054 modem_3gpp_proxy_(new mm1::MockModemModem3gppProxy()),
55 modem_cdma_proxy_(new mm1::MockModemModemCdmaProxy()),
56 modem_proxy_(new mm1::MockModemProxy()),
57 modem_simple_proxy_(new mm1::MockModemSimpleProxy()),
58 sim_proxy_(new mm1::MockSimProxy()),
59 properties_proxy_(new MockDBusPropertiesProxy()),
60 proxy_factory_(this),
61 cellular_(new Cellular(&modem_info_,
62 "",
63 kMachineAddress,
64 0,
65 Cellular::kTypeUniversalCDMA,
66 "",
67 "",
68 "",
69 &proxy_factory_)),
70 service_(new MockCellularService(&modem_info_,
71 cellular_)) {}
72
73 virtual ~CellularCapabilityUniversalCDMATest() {
74 cellular_->service_ = NULL;
75 capability_ = NULL;
76 device_adaptor_ = NULL;
77 }
78
79 virtual void SetUp() {
80 capability_ = dynamic_cast<CellularCapabilityUniversalCDMA *>(
81 cellular_->capability_.get());
82 device_adaptor_ =
83 dynamic_cast<NiceMock<DeviceMockAdaptor> *>(cellular_->adaptor());
84 cellular_->service_ = service_;
85 }
86
87 virtual void TearDown() {
88 capability_->proxy_factory_ = NULL;
89 }
90
91 void SetService() {
92 cellular_->service_ = new CellularService(&modem_info_, cellular_);
93 }
94
Arman Ugurayc5391232013-09-23 21:30:46 -070095 void ClearService() {
96 cellular_->service_ = NULL;
97 }
98
Arman Uguray72fab6a2013-01-10 19:32:42 -080099 void ReleaseCapabilityProxies() {
100 capability_->ReleaseProxies();
101 }
102
103 void SetCdmaProxy() {
104 capability_->modem_cdma_proxy_.reset(modem_cdma_proxy_.release());
105 }
106
107 void SetSimpleProxy() {
108 capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release());
109 }
110
111 protected:
112 static const char kEsn[];
113 static const char kMachineAddress[];
114 static const char kMeid[];
115
116 class TestProxyFactory : public ProxyFactory {
117 public:
118 explicit TestProxyFactory(CellularCapabilityUniversalCDMATest *test) :
119 test_(test) {}
120
121 // TODO(armansito): Some of these methods won't be necessary after 3GPP
122 // gets refactored out of CellularCapabilityUniversal.
Arman Uguray72fab6a2013-01-10 19:32:42 -0800123 virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy(
124 const std::string &/*path*/,
125 const std::string &/*service*/) {
126 return test_->modem_3gpp_proxy_.release();
127 }
128
129 virtual mm1::ModemModemCdmaProxyInterface *CreateMM1ModemModemCdmaProxy(
130 const std::string &/*path*/,
131 const std::string &/*service*/) {
132 return test_->modem_cdma_proxy_.release();
133 }
134
135 virtual mm1::ModemProxyInterface *CreateMM1ModemProxy(
136 const std::string &/*path*/,
137 const std::string &/*service*/) {
138 return test_->modem_proxy_.release();
139 }
140
141 virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy(
142 const std::string &/*path*/,
143 const std::string &/*service*/) {
144 return test_->modem_simple_proxy_.release();
145 }
146
147 virtual mm1::SimProxyInterface *CreateSimProxy(
148 const std::string &/*path*/,
149 const std::string &/*service*/) {
150 return test_->sim_proxy_.release();
151 }
152
153 virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy(
154 const std::string &/*path*/,
155 const std::string &/*service*/) {
156 return test_->properties_proxy_.release();
157 }
158
159 private:
160 CellularCapabilityUniversalCDMATest *test_;
161 };
162
163
164 CellularCapabilityUniversalCDMA *capability_;
165 NiceMock<DeviceMockAdaptor> *device_adaptor_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800166 MockModemInfo modem_info_;
167 MockGLib glib_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800168 // TODO(armansito): Remove |modem_3gpp_proxy_| after refactor.
169 scoped_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_;
170 scoped_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_;
171 scoped_ptr<mm1::MockModemProxy> modem_proxy_;
172 scoped_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_;
173 scoped_ptr<mm1::MockSimProxy> sim_proxy_;
174 scoped_ptr<MockDBusPropertiesProxy> properties_proxy_;
175 TestProxyFactory proxy_factory_;
176 CellularRefPtr cellular_;
177 MockCellularService *service_;
178};
179
180// static
181const char CellularCapabilityUniversalCDMATest::kEsn[] = "0000";
182// static
183const char CellularCapabilityUniversalCDMATest::kMachineAddress[] =
184 "TestMachineAddress";
185// static
186const char CellularCapabilityUniversalCDMATest::kMeid[] = "11111111111111";
187
Arman Uguray0a3e2792013-01-17 16:31:50 -0800188class CellularCapabilityUniversalCDMAMainTest
189 : public CellularCapabilityUniversalCDMATest {
190 public:
191 CellularCapabilityUniversalCDMAMainTest()
192 : CellularCapabilityUniversalCDMATest(&dispatcher_) {}
193
194 private:
195 EventDispatcher dispatcher_;
196};
197
198class CellularCapabilityUniversalCDMADispatcherTest
199 : public CellularCapabilityUniversalCDMATest {
200 public:
201 CellularCapabilityUniversalCDMADispatcherTest()
202 : CellularCapabilityUniversalCDMATest(NULL) {}
203};
204
205TEST_F(CellularCapabilityUniversalCDMAMainTest, PropertiesChanged) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800206 // Set up mock modem CDMA properties.
207 DBusPropertiesMap modem_cdma_properties;
208 modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_MEID].
209 writer().append_string(kMeid);
210 modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_ESN].
211 writer().append_string(kEsn);
212
213 SetUp();
214
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800215 EXPECT_TRUE(cellular_->meid().empty());
216 EXPECT_TRUE(cellular_->esn().empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800217
218 // Changing properties on wrong interface will not have an effect
219 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
220 modem_cdma_properties,
221 vector<string>());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800222 EXPECT_TRUE(cellular_->meid().empty());
223 EXPECT_TRUE(cellular_->esn().empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800224
225 // Changing properties on the right interface gets reflected in the
226 // capabilities object
227 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEMCDMA,
228 modem_cdma_properties,
229 vector<string>());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800230 EXPECT_EQ(kMeid, cellular_->meid());
231 EXPECT_EQ(kEsn, cellular_->esn());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800232}
233
Arman Uguray0a3e2792013-01-17 16:31:50 -0800234TEST_F(CellularCapabilityUniversalCDMAMainTest, OnCDMARegistrationChanged) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800235 EXPECT_EQ(0, capability_->sid_);
236 EXPECT_EQ(0, capability_->nid_);
237 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
238 capability_->cdma_1x_registration_state_);
239 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
240 capability_->cdma_evdo_registration_state_);
241
242 EXPECT_EQ("", capability_->provider_.GetCode());
243 EXPECT_EQ("", capability_->provider_.GetName());
244 EXPECT_EQ("", capability_->provider_.GetCountry());
245
246 CellularOperatorInfo::CellularOperator *provider =
247 new CellularOperatorInfo::CellularOperator();
248
249 provider->country_ = "us";
250 provider->is_primary_ = true;
251 provider->name_list_.push_back(
252 CellularOperatorInfo::LocalizedName("Test", ""));
253
254 scoped_ptr<const CellularOperatorInfo::CellularOperator> ptr(provider);
255
256 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
257 GetCellularOperatorBySID("2"))
258 .WillOnce(Return(ptr.get()));
259
260 capability_->OnCDMARegistrationChanged(
261 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
262 MM_MODEM_CDMA_REGISTRATION_STATE_HOME,
263 2,
264 0);
265 EXPECT_EQ(2, capability_->sid_);
266 EXPECT_EQ(0, capability_->nid_);
267 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
268 capability_->cdma_1x_registration_state_);
269 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_HOME,
270 capability_->cdma_evdo_registration_state_);
271
272 EXPECT_TRUE(capability_->IsRegistered());
273 EXPECT_EQ("2", capability_->provider_.GetCode());
274 EXPECT_EQ("Test", capability_->provider_.GetName());
275 EXPECT_EQ("us", capability_->provider_.GetCountry());
276}
277
Arman Uguray0a3e2792013-01-17 16:31:50 -0800278TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateOperatorInfo) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800279 EXPECT_EQ("", capability_->provider_.GetCode());
280 EXPECT_EQ("", capability_->provider_.GetName());
281 EXPECT_EQ("", capability_->provider_.GetCountry());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800282 EXPECT_TRUE(capability_->activation_code_.empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800283
284 capability_->UpdateOperatorInfo();
285 EXPECT_EQ("", capability_->provider_.GetCode());
286 EXPECT_EQ("", capability_->provider_.GetName());
287 EXPECT_EQ("", capability_->provider_.GetCountry());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800288 EXPECT_TRUE(capability_->activation_code_.empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800289
Arman Uguray72fab6a2013-01-10 19:32:42 -0800290 capability_->UpdateOperatorInfo();
291 EXPECT_EQ("", capability_->provider_.GetCode());
292 EXPECT_EQ("", capability_->provider_.GetName());
293 EXPECT_EQ("", capability_->provider_.GetCountry());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800294 EXPECT_TRUE(capability_->activation_code_.empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800295
296 capability_->sid_ = 1;
297 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
298 GetCellularOperatorBySID(_))
299 .WillOnce(Return((const CellularOperatorInfo::CellularOperator *)NULL));
300
301 capability_->UpdateOperatorInfo();
Arman Uguraye015faf2013-08-16 17:54:59 -0700302 EXPECT_EQ("1", capability_->provider_.GetCode());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800303 EXPECT_EQ("", capability_->provider_.GetName());
304 EXPECT_EQ("", capability_->provider_.GetCountry());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800305 EXPECT_TRUE(capability_->activation_code_.empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800306
307 CellularOperatorInfo::CellularOperator *provider =
308 new CellularOperatorInfo::CellularOperator();
309
310 provider->country_ = "us";
311 provider->is_primary_ = true;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800312 provider->activation_code_ = "1234";
Arman Uguray72fab6a2013-01-10 19:32:42 -0800313 provider->name_list_.push_back(
314 CellularOperatorInfo::LocalizedName("Test", ""));
315
316 scoped_ptr<const CellularOperatorInfo::CellularOperator> ptr(provider);
317
318 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
319 GetCellularOperatorBySID(_))
320 .WillOnce(Return(ptr.get()));
321
322 capability_->UpdateOperatorInfo();
323
324 EXPECT_EQ("1", capability_->provider_.GetCode());
325 EXPECT_EQ("Test", capability_->provider_.GetName());
326 EXPECT_EQ("us", capability_->provider_.GetCountry());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800327 EXPECT_EQ("1234", capability_->activation_code_);
Arman Uguray2269bb62013-07-26 14:53:30 -0700328 EXPECT_EQ("1", cellular_->service()->serving_operator().GetCode());
329 EXPECT_EQ("Test", cellular_->service()->serving_operator().GetName());
330 EXPECT_EQ("us", cellular_->service()->serving_operator().GetCountry());
331 EXPECT_EQ("Test", cellular_->service()->friendly_name());
Arman Uguraye015faf2013-08-16 17:54:59 -0700332
333 capability_->sid_ = 1;
334 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
335 GetCellularOperatorBySID(_))
336 .WillOnce(Return(nullptr));
337
338 capability_->UpdateOperatorInfo();
339 EXPECT_EQ("1", capability_->provider_.GetCode());
340 EXPECT_EQ("", capability_->provider_.GetName());
341 EXPECT_EQ("", capability_->provider_.GetCountry());
342 EXPECT_TRUE(capability_->activation_code_.empty());
343
Arman Uguray72fab6a2013-01-10 19:32:42 -0800344}
345
Arman Uguray0a3e2792013-01-17 16:31:50 -0800346TEST_F(CellularCapabilityUniversalCDMAMainTest, CreateFriendlyServiceName) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800347 CellularCapabilityUniversalCDMA::friendly_service_name_id_cdma_ = 0;
348 EXPECT_EQ(0, capability_->sid_);
349 EXPECT_EQ("CDMANetwork0", capability_->CreateFriendlyServiceName());
350 EXPECT_EQ("CDMANetwork1", capability_->CreateFriendlyServiceName());
351
352 capability_->provider_.SetCode("0123");
353 EXPECT_EQ("cellular_sid_0123", capability_->CreateFriendlyServiceName());
354
355 CellularOperatorInfo::CellularOperator *provider =
356 new CellularOperatorInfo::CellularOperator();
357
358 capability_->sid_ = 1;
359 provider->name_list_.push_back(
360 CellularOperatorInfo::LocalizedName("Test", ""));
361 capability_->provider_.SetCode("");
362
363 scoped_ptr<const CellularOperatorInfo::CellularOperator> ptr(provider);
364
365 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
366 GetCellularOperatorBySID(_))
367 .WillOnce(Return(ptr.get()));
368 EXPECT_EQ("Test", capability_->CreateFriendlyServiceName());
369}
370
Arman Uguray0a3e2792013-01-17 16:31:50 -0800371TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateOLP) {
Ben Chan07193fd2013-07-12 22:10:55 -0700372 CellularOperatorInfo::CellularOperator cellular_operator;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800373 CellularService::OLP test_olp;
374 test_olp.SetURL("http://testurl");
375 test_olp.SetMethod("POST");
376 test_olp.SetPostData("esn=${esn}&mdn=${mdn}&meid=${meid}");
377
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800378 cellular_->set_esn("0");
379 cellular_->set_mdn("10123456789");
380 cellular_->set_meid("4");
Arman Uguray72fab6a2013-01-10 19:32:42 -0800381 capability_->sid_ = 1;
382
Ben Chan07193fd2013-07-12 22:10:55 -0700383 string sid_string = base::StringPrintf("%u", capability_->sid_);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800384 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Ben Chan07193fd2013-07-12 22:10:55 -0700385 GetCellularOperatorBySID(sid_string))
386 .WillRepeatedly(Return(&cellular_operator));
387 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
388 GetOLPBySID(sid_string))
Arman Uguray72fab6a2013-01-10 19:32:42 -0800389 .WillRepeatedly(Return(&test_olp));
390
391 SetService();
Ben Chan07193fd2013-07-12 22:10:55 -0700392
393 cellular_operator.identifier_ = "vzw";
394 capability_->UpdateOLP();
395 const CellularService::OLP &vzw_olp = cellular_->service()->olp();
396 EXPECT_EQ("http://testurl", vzw_olp.GetURL());
397 EXPECT_EQ("POST", vzw_olp.GetMethod());
398 EXPECT_EQ("esn=0&mdn=0123456789&meid=4", vzw_olp.GetPostData());
399
400 cellular_operator.identifier_ = "foo";
Arman Uguray72fab6a2013-01-10 19:32:42 -0800401 capability_->UpdateOLP();
402 const CellularService::OLP &olp = cellular_->service()->olp();
403 EXPECT_EQ("http://testurl", olp.GetURL());
404 EXPECT_EQ("POST", olp.GetMethod());
Ben Chan07193fd2013-07-12 22:10:55 -0700405 EXPECT_EQ("esn=0&mdn=10123456789&meid=4", olp.GetPostData());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800406}
407
Arman Uguray0a3e2792013-01-17 16:31:50 -0800408TEST_F(CellularCapabilityUniversalCDMAMainTest, ActivateAutomatic) {
409 mm1::MockModemModemCdmaProxy *cdma_proxy = modem_cdma_proxy_.get();
410 SetUp();
411 capability_->InitProxies();
412
413 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
414 GetActivationState(_,_))
415 .Times(0);
416 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
417 SetActivationState(_,_,_))
418 .Times(0);
419 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0);
420 capability_->ActivateAutomatic();
421 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
422 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
423
424 capability_->activation_code_ = "1234";
425
426 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
427 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
428 .WillOnce(Return(PendingActivationStore::kStatePending))
429 .WillOnce(Return(PendingActivationStore::kStateActivated));
430 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
431 SetActivationState(_,_,_))
432 .Times(0);
433 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0);
434 capability_->ActivateAutomatic();
435 capability_->ActivateAutomatic();
436 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
437 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
438
439 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
440 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
441 .WillOnce(Return(PendingActivationStore::kStateUnknown))
442 .WillOnce(Return(PendingActivationStore::kStateFailureRetry));
443 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
444 SetActivationState(_,_, PendingActivationStore::kStatePending))
445 .Times(2);
446 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(2);
447 capability_->ActivateAutomatic();
448 capability_->ActivateAutomatic();
449 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
450 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
451}
452
453TEST_F(CellularCapabilityUniversalCDMAMainTest, IsServiceActivationRequired) {
454 CellularService::OLP olp;
455 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_))
456 .WillOnce(Return((const CellularService::OLP *)NULL))
457 .WillRepeatedly(Return(&olp));
458 capability_->activation_state_ =
459 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
460 EXPECT_FALSE(capability_->IsServiceActivationRequired());
461 EXPECT_TRUE(capability_->IsServiceActivationRequired());
462 capability_->activation_state_ =
463 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
464 EXPECT_FALSE(capability_->IsServiceActivationRequired());
465 capability_->activation_state_ =
466 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
467 EXPECT_FALSE(capability_->IsServiceActivationRequired());
468}
469
470TEST_F(CellularCapabilityUniversalCDMAMainTest,
471 UpdateServiceActivationStateProperty) {
472 CellularService::OLP olp;
473 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_))
474 .WillRepeatedly(Return(&olp));
475 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Ben Chan7ea768e2013-09-20 15:08:40 -0700476 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800477 .WillOnce(Return(PendingActivationStore::kStatePending))
478 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
479
Ben Chan7ea768e2013-09-20 15:08:40 -0700480 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
481 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800482 .Times(1);
483 capability_->UpdateServiceActivationStateProperty();
484 Mock::VerifyAndClearExpectations(service_);
485
Ben Chan7ea768e2013-09-20 15:08:40 -0700486 EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800487 .Times(1);
488 capability_->UpdateServiceActivationStateProperty();
489 Mock::VerifyAndClearExpectations(service_);
490
Ben Chan7ea768e2013-09-20 15:08:40 -0700491 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
492 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800493 .Times(1);
494 capability_->UpdateServiceActivationStateProperty();
495 Mock::VerifyAndClearExpectations(service_);
496
Ben Chan7ea768e2013-09-20 15:08:40 -0700497 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
498 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800499 .Times(1);
500 capability_->UpdateServiceActivationStateProperty();
501 Mock::VerifyAndClearExpectations(service_);
502 Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info());
Ben Chan7ea768e2013-09-20 15:08:40 -0700503 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800504}
505
506TEST_F(CellularCapabilityUniversalCDMAMainTest, IsActivating) {
507 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
508 GetActivationState(_,_))
509 .WillOnce(Return(PendingActivationStore::kStatePending))
510 .WillOnce(Return(PendingActivationStore::kStatePending))
511 .WillOnce(Return(PendingActivationStore::kStateFailureRetry))
512 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
513
514 capability_->activation_state_ =
515 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
516 EXPECT_TRUE(capability_->IsActivating());
517 EXPECT_TRUE(capability_->IsActivating());
518 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
519 EXPECT_TRUE(capability_->IsActivating());
520 EXPECT_TRUE(capability_->IsActivating());
521 capability_->activation_state_ =
522 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
523 EXPECT_FALSE(capability_->IsActivating());
524}
525
Ben Chanb2c4a802013-11-14 12:47:52 -0800526TEST_F(CellularCapabilityUniversalCDMAMainTest, IsRegistered) {
527 capability_->cdma_1x_registration_state_ =
528 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
529 capability_->cdma_evdo_registration_state_ =
530 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
531 EXPECT_FALSE(capability_->IsRegistered());
532
533 capability_->cdma_evdo_registration_state_ =
534 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
535 EXPECT_TRUE(capability_->IsRegistered());
536
537 capability_->cdma_evdo_registration_state_ =
538 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
539 EXPECT_TRUE(capability_->IsRegistered());
540
541 capability_->cdma_evdo_registration_state_ =
542 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
543 EXPECT_TRUE(capability_->IsRegistered());
544
545 capability_->cdma_1x_registration_state_ =
546 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
547 capability_->cdma_evdo_registration_state_ =
548 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
549 EXPECT_TRUE(capability_->IsRegistered());
550
551 capability_->cdma_evdo_registration_state_ =
552 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
553 EXPECT_TRUE(capability_->IsRegistered());
554
555 capability_->cdma_evdo_registration_state_ =
556 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
557 EXPECT_TRUE(capability_->IsRegistered());
558
559 capability_->cdma_evdo_registration_state_ =
560 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
561 EXPECT_TRUE(capability_->IsRegistered());
562
563 capability_->cdma_1x_registration_state_ =
564 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
565 capability_->cdma_evdo_registration_state_ =
566 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
567 EXPECT_TRUE(capability_->IsRegistered());
568
569 capability_->cdma_evdo_registration_state_ =
570 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
571 EXPECT_TRUE(capability_->IsRegistered());
572
573 capability_->cdma_evdo_registration_state_ =
574 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
575 EXPECT_TRUE(capability_->IsRegistered());
576
577 capability_->cdma_evdo_registration_state_ =
578 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
579 EXPECT_TRUE(capability_->IsRegistered());
580
581 capability_->cdma_1x_registration_state_ =
582 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
583 capability_->cdma_evdo_registration_state_ =
584 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
585 EXPECT_TRUE(capability_->IsRegistered());
586
587 capability_->cdma_evdo_registration_state_ =
588 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
589 EXPECT_TRUE(capability_->IsRegistered());
590
591 capability_->cdma_evdo_registration_state_ =
592 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
593 EXPECT_TRUE(capability_->IsRegistered());
594
595 capability_->cdma_evdo_registration_state_ =
596 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
597 EXPECT_TRUE(capability_->IsRegistered());
598}
599
Arman Ugurayc9673062013-05-13 21:21:53 -0700600TEST_F(CellularCapabilityUniversalCDMAMainTest, SetupConnectProperties) {
601 DBusPropertiesMap map;
602 capability_->SetupConnectProperties(&map);
603 EXPECT_EQ(1, map.size());
604 EXPECT_STREQ("#777", map["number"].reader().get_string());
605}
606
Arman Ugurayc5391232013-09-23 21:30:46 -0700607TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateStorageIdentifier) {
608 ClearService();
609 EXPECT_FALSE(cellular_->service().get());
610 capability_->UpdateStorageIdentifier();
611 EXPECT_FALSE(cellular_->service().get());
612
613 SetService();
614 EXPECT_TRUE(cellular_->service().get());
615
616 const string kPrefix =
617 string(shill::kTypeCellular) + "_" + string(kMachineAddress) + "_";
618 const string kDefaultIdentifierPattern = kPrefix + "CDMANetwork*";
619
620 // GetCellularOperatorBySID returns NULL.
621 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
622 GetCellularOperatorBySID(_))
623 .WillOnce(Return(nullptr));
624 capability_->UpdateStorageIdentifier();
625 EXPECT_TRUE(::MatchPattern(cellular_->service()->GetStorageIdentifier(),
626 kDefaultIdentifierPattern));
627 Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info());
628
629 CellularOperatorInfo::CellularOperator provider;
630 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
631 GetCellularOperatorBySID(_))
632 .Times(2)
633 .WillRepeatedly(Return(&provider));
634
635 // |provider.identifier_| is empty.
636 capability_->UpdateStorageIdentifier();
637 EXPECT_TRUE(::MatchPattern(cellular_->service()->GetStorageIdentifier(),
638 kDefaultIdentifierPattern));
639
640 // Success.
641 provider.identifier_ = "testidentifier";
642 capability_->UpdateStorageIdentifier();
643 EXPECT_EQ(kPrefix + "testidentifier",
644 cellular_->service()->GetStorageIdentifier());
645}
646
Arman Uguray0a3e2792013-01-17 16:31:50 -0800647TEST_F(CellularCapabilityUniversalCDMADispatcherTest,
648 UpdatePendingActivationState) {
649 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
650 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
651 .Times(1);
652 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
653 GetActivationState(_,_))
654 .Times(0);
655 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
656 capability_->UpdatePendingActivationState();
657 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
658 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
659
660 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
661 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
662 .Times(0);
663 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
664 GetActivationState(_,_))
665 .Times(2)
666 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
667 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
668 capability_->UpdatePendingActivationState();
669 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
670 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
671
672 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
673 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
674 .Times(0);
675 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
676 GetActivationState(_,_))
677 .Times(2)
678 .WillRepeatedly(Return(PendingActivationStore::kStatePending));
679 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
680 capability_->UpdatePendingActivationState();
681 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
682 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
683
684 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
685 .Times(0);
686 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
687 GetActivationState(_,_))
688 .Times(2)
689 .WillRepeatedly(Return(PendingActivationStore::kStateFailureRetry));
690 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(1);
691 capability_->UpdatePendingActivationState();
692 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
693 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
694
695 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
696 .Times(0);
697 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
698 GetActivationState(_,_))
699 .Times(4)
700 .WillOnce(Return(PendingActivationStore::kStateActivated))
701 .WillOnce(Return(PendingActivationStore::kStateActivated))
702 .WillOnce(Return(PendingActivationStore::kStateUnknown))
703 .WillOnce(Return(PendingActivationStore::kStateUnknown));
704 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
705 capability_->UpdatePendingActivationState();
706 capability_->UpdatePendingActivationState();
707 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
708 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
709}
710
Arman Uguray72fab6a2013-01-10 19:32:42 -0800711} // namespace shill