blob: f527f10e85eb6921c1a3093ecad0a88b47851e17 [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
Ben Chana0ddf462014-02-06 11:32:42 -080010#include <base/strings/string_util.h>
11#include <base/strings/stringprintf.h>
Arman Uguray72fab6a2013-01-10 19:32:42 -080012#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());
Arman Uguraye015faf2013-08-16 17:54:59 -0700331
332 capability_->sid_ = 1;
333 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
334 GetCellularOperatorBySID(_))
335 .WillOnce(Return(nullptr));
336
337 capability_->UpdateOperatorInfo();
338 EXPECT_EQ("1", capability_->provider_.GetCode());
339 EXPECT_EQ("", capability_->provider_.GetName());
340 EXPECT_EQ("", capability_->provider_.GetCountry());
341 EXPECT_TRUE(capability_->activation_code_.empty());
342
Arman Uguray72fab6a2013-01-10 19:32:42 -0800343}
344
Arman Uguray0a3e2792013-01-17 16:31:50 -0800345TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateOLP) {
Ben Chan07193fd2013-07-12 22:10:55 -0700346 CellularOperatorInfo::CellularOperator cellular_operator;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800347 CellularService::OLP test_olp;
348 test_olp.SetURL("http://testurl");
349 test_olp.SetMethod("POST");
350 test_olp.SetPostData("esn=${esn}&mdn=${mdn}&meid=${meid}");
351
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800352 cellular_->set_esn("0");
353 cellular_->set_mdn("10123456789");
354 cellular_->set_meid("4");
Arman Uguray72fab6a2013-01-10 19:32:42 -0800355 capability_->sid_ = 1;
356
Ben Chan07193fd2013-07-12 22:10:55 -0700357 string sid_string = base::StringPrintf("%u", capability_->sid_);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800358 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
Ben Chan07193fd2013-07-12 22:10:55 -0700359 GetCellularOperatorBySID(sid_string))
360 .WillRepeatedly(Return(&cellular_operator));
361 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
362 GetOLPBySID(sid_string))
Arman Uguray72fab6a2013-01-10 19:32:42 -0800363 .WillRepeatedly(Return(&test_olp));
364
365 SetService();
Ben Chan07193fd2013-07-12 22:10:55 -0700366
367 cellular_operator.identifier_ = "vzw";
368 capability_->UpdateOLP();
369 const CellularService::OLP &vzw_olp = cellular_->service()->olp();
370 EXPECT_EQ("http://testurl", vzw_olp.GetURL());
371 EXPECT_EQ("POST", vzw_olp.GetMethod());
372 EXPECT_EQ("esn=0&mdn=0123456789&meid=4", vzw_olp.GetPostData());
373
374 cellular_operator.identifier_ = "foo";
Arman Uguray72fab6a2013-01-10 19:32:42 -0800375 capability_->UpdateOLP();
376 const CellularService::OLP &olp = cellular_->service()->olp();
377 EXPECT_EQ("http://testurl", olp.GetURL());
378 EXPECT_EQ("POST", olp.GetMethod());
Ben Chan07193fd2013-07-12 22:10:55 -0700379 EXPECT_EQ("esn=0&mdn=10123456789&meid=4", olp.GetPostData());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800380}
381
Arman Uguray0a3e2792013-01-17 16:31:50 -0800382TEST_F(CellularCapabilityUniversalCDMAMainTest, ActivateAutomatic) {
383 mm1::MockModemModemCdmaProxy *cdma_proxy = modem_cdma_proxy_.get();
384 SetUp();
385 capability_->InitProxies();
386
387 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
388 GetActivationState(_,_))
389 .Times(0);
390 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
391 SetActivationState(_,_,_))
392 .Times(0);
393 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0);
394 capability_->ActivateAutomatic();
395 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
396 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
397
398 capability_->activation_code_ = "1234";
399
400 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
401 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
402 .WillOnce(Return(PendingActivationStore::kStatePending))
403 .WillOnce(Return(PendingActivationStore::kStateActivated));
404 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
405 SetActivationState(_,_,_))
406 .Times(0);
407 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0);
408 capability_->ActivateAutomatic();
409 capability_->ActivateAutomatic();
410 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
411 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
412
413 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
414 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
415 .WillOnce(Return(PendingActivationStore::kStateUnknown))
416 .WillOnce(Return(PendingActivationStore::kStateFailureRetry));
417 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
418 SetActivationState(_,_, PendingActivationStore::kStatePending))
419 .Times(2);
420 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(2);
421 capability_->ActivateAutomatic();
422 capability_->ActivateAutomatic();
423 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
424 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
425}
426
427TEST_F(CellularCapabilityUniversalCDMAMainTest, IsServiceActivationRequired) {
428 CellularService::OLP olp;
429 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_))
430 .WillOnce(Return((const CellularService::OLP *)NULL))
431 .WillRepeatedly(Return(&olp));
432 capability_->activation_state_ =
433 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
434 EXPECT_FALSE(capability_->IsServiceActivationRequired());
435 EXPECT_TRUE(capability_->IsServiceActivationRequired());
436 capability_->activation_state_ =
437 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
438 EXPECT_FALSE(capability_->IsServiceActivationRequired());
439 capability_->activation_state_ =
440 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
441 EXPECT_FALSE(capability_->IsServiceActivationRequired());
442}
443
444TEST_F(CellularCapabilityUniversalCDMAMainTest,
445 UpdateServiceActivationStateProperty) {
446 CellularService::OLP olp;
447 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_))
448 .WillRepeatedly(Return(&olp));
449 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Ben Chan7ea768e2013-09-20 15:08:40 -0700450 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800451 .WillOnce(Return(PendingActivationStore::kStatePending))
452 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
453
Ben Chan7ea768e2013-09-20 15:08:40 -0700454 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
455 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800456 .Times(1);
457 capability_->UpdateServiceActivationStateProperty();
458 Mock::VerifyAndClearExpectations(service_);
459
Ben Chan7ea768e2013-09-20 15:08:40 -0700460 EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800461 .Times(1);
462 capability_->UpdateServiceActivationStateProperty();
463 Mock::VerifyAndClearExpectations(service_);
464
Ben Chan7ea768e2013-09-20 15:08:40 -0700465 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
466 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800467 .Times(1);
468 capability_->UpdateServiceActivationStateProperty();
469 Mock::VerifyAndClearExpectations(service_);
470
Ben Chan7ea768e2013-09-20 15:08:40 -0700471 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
472 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800473 .Times(1);
474 capability_->UpdateServiceActivationStateProperty();
475 Mock::VerifyAndClearExpectations(service_);
476 Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info());
Ben Chan7ea768e2013-09-20 15:08:40 -0700477 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800478}
479
480TEST_F(CellularCapabilityUniversalCDMAMainTest, IsActivating) {
481 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
482 GetActivationState(_,_))
483 .WillOnce(Return(PendingActivationStore::kStatePending))
484 .WillOnce(Return(PendingActivationStore::kStatePending))
485 .WillOnce(Return(PendingActivationStore::kStateFailureRetry))
486 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
487
488 capability_->activation_state_ =
489 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
490 EXPECT_TRUE(capability_->IsActivating());
491 EXPECT_TRUE(capability_->IsActivating());
492 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
493 EXPECT_TRUE(capability_->IsActivating());
494 EXPECT_TRUE(capability_->IsActivating());
495 capability_->activation_state_ =
496 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
497 EXPECT_FALSE(capability_->IsActivating());
498}
499
Ben Chanb2c4a802013-11-14 12:47:52 -0800500TEST_F(CellularCapabilityUniversalCDMAMainTest, IsRegistered) {
501 capability_->cdma_1x_registration_state_ =
502 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
503 capability_->cdma_evdo_registration_state_ =
504 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
505 EXPECT_FALSE(capability_->IsRegistered());
506
507 capability_->cdma_evdo_registration_state_ =
508 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
509 EXPECT_TRUE(capability_->IsRegistered());
510
511 capability_->cdma_evdo_registration_state_ =
512 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
513 EXPECT_TRUE(capability_->IsRegistered());
514
515 capability_->cdma_evdo_registration_state_ =
516 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
517 EXPECT_TRUE(capability_->IsRegistered());
518
519 capability_->cdma_1x_registration_state_ =
520 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
521 capability_->cdma_evdo_registration_state_ =
522 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
523 EXPECT_TRUE(capability_->IsRegistered());
524
525 capability_->cdma_evdo_registration_state_ =
526 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
527 EXPECT_TRUE(capability_->IsRegistered());
528
529 capability_->cdma_evdo_registration_state_ =
530 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
531 EXPECT_TRUE(capability_->IsRegistered());
532
533 capability_->cdma_evdo_registration_state_ =
534 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
535 EXPECT_TRUE(capability_->IsRegistered());
536
537 capability_->cdma_1x_registration_state_ =
538 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
539 capability_->cdma_evdo_registration_state_ =
540 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
541 EXPECT_TRUE(capability_->IsRegistered());
542
543 capability_->cdma_evdo_registration_state_ =
544 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
545 EXPECT_TRUE(capability_->IsRegistered());
546
547 capability_->cdma_evdo_registration_state_ =
548 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
549 EXPECT_TRUE(capability_->IsRegistered());
550
551 capability_->cdma_evdo_registration_state_ =
552 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
553 EXPECT_TRUE(capability_->IsRegistered());
554
555 capability_->cdma_1x_registration_state_ =
556 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
557 capability_->cdma_evdo_registration_state_ =
558 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
559 EXPECT_TRUE(capability_->IsRegistered());
560
561 capability_->cdma_evdo_registration_state_ =
562 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
563 EXPECT_TRUE(capability_->IsRegistered());
564
565 capability_->cdma_evdo_registration_state_ =
566 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
567 EXPECT_TRUE(capability_->IsRegistered());
568
569 capability_->cdma_evdo_registration_state_ =
570 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
571 EXPECT_TRUE(capability_->IsRegistered());
572}
573
Arman Ugurayc9673062013-05-13 21:21:53 -0700574TEST_F(CellularCapabilityUniversalCDMAMainTest, SetupConnectProperties) {
575 DBusPropertiesMap map;
576 capability_->SetupConnectProperties(&map);
577 EXPECT_EQ(1, map.size());
578 EXPECT_STREQ("#777", map["number"].reader().get_string());
579}
580
Arman Uguray0a3e2792013-01-17 16:31:50 -0800581TEST_F(CellularCapabilityUniversalCDMADispatcherTest,
582 UpdatePendingActivationState) {
583 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
584 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
585 .Times(1);
586 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
587 GetActivationState(_,_))
588 .Times(0);
589 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
590 capability_->UpdatePendingActivationState();
591 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
592 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
593
594 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
595 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
596 .Times(0);
597 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
598 GetActivationState(_,_))
599 .Times(2)
600 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
601 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
602 capability_->UpdatePendingActivationState();
603 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
604 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
605
606 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
607 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
608 .Times(0);
609 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
610 GetActivationState(_,_))
611 .Times(2)
612 .WillRepeatedly(Return(PendingActivationStore::kStatePending));
613 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
614 capability_->UpdatePendingActivationState();
615 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
616 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
617
618 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
619 .Times(0);
620 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
621 GetActivationState(_,_))
622 .Times(2)
623 .WillRepeatedly(Return(PendingActivationStore::kStateFailureRetry));
624 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(1);
625 capability_->UpdatePendingActivationState();
626 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
627 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
628
629 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
630 .Times(0);
631 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
632 GetActivationState(_,_))
633 .Times(4)
634 .WillOnce(Return(PendingActivationStore::kStateActivated))
635 .WillOnce(Return(PendingActivationStore::kStateActivated))
636 .WillOnce(Return(PendingActivationStore::kStateUnknown))
637 .WillOnce(Return(PendingActivationStore::kStateUnknown));
638 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
639 capability_->UpdatePendingActivationState();
640 capability_->UpdatePendingActivationState();
641 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
642 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
643}
644
Arman Uguray72fab6a2013-01-10 19:32:42 -0800645} // namespace shill