blob: bd5771052d4bd1fdc01a4767576edea49d00bde4 [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
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070010#include <base/strings/string_number_conversions.h>
Ben Chana0ddf462014-02-06 11:32:42 -080011#include <base/strings/string_util.h>
12#include <base/strings/stringprintf.h>
Arman Uguray72fab6a2013-01-10 19:32:42 -080013#include <gmock/gmock.h>
14#include <gtest/gtest.h>
15#include <ModemManager/ModemManager.h>
16
17#include "shill/cellular.h"
18#include "shill/cellular_service.h"
19#include "shill/event_dispatcher.h"
20#include "shill/mock_adaptors.h"
21#include "shill/mock_cellular_operator_info.h"
22#include "shill/mock_cellular_service.h"
23#include "shill/mock_dbus_properties_proxy.h"
24#include "shill/mock_glib.h"
25#include "shill/mock_manager.h"
26#include "shill/mock_metrics.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080027#include "shill/mock_mm1_modem_modem3gpp_proxy.h"
28#include "shill/mock_mm1_modem_modemcdma_proxy.h"
29#include "shill/mock_mm1_modem_proxy.h"
30#include "shill/mock_mm1_modem_simple_proxy.h"
31#include "shill/mock_mm1_sim_proxy.h"
Prathmesh Prabhu92df6192014-04-29 18:08:08 -070032#include "shill/mock_mobile_operator_info.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080033#include "shill/mock_modem_info.h"
Arman Uguray0a3e2792013-01-17 16:31:50 -080034#include "shill/mock_pending_activation_store.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080035#include "shill/nice_mock_control.h"
36#include "shill/proxy_factory.h"
37
38using base::StringPrintf;
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070039using base::UintToString;
Arman Uguray72fab6a2013-01-10 19:32:42 -080040using std::string;
41using std::vector;
42using testing::Invoke;
43using testing::Mock;
44using testing::NiceMock;
45using testing::Return;
46using testing::SetArgumentPointee;
47using testing::_;
48
49namespace shill {
50
51class CellularCapabilityUniversalCDMATest : public testing::Test {
52 public:
Arman Uguray0a3e2792013-01-17 16:31:50 -080053 CellularCapabilityUniversalCDMATest(EventDispatcher *dispatcher)
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070054 : dispatcher_(dispatcher),
55 capability_(NULL),
Arman Uguray72fab6a2013-01-10 19:32:42 -080056 device_adaptor_(NULL),
Arman Uguray0a3e2792013-01-17 16:31:50 -080057 modem_info_(NULL, dispatcher, NULL, NULL, NULL),
Arman Uguray72fab6a2013-01-10 19:32:42 -080058 modem_3gpp_proxy_(new mm1::MockModemModem3gppProxy()),
59 modem_cdma_proxy_(new mm1::MockModemModemCdmaProxy()),
60 modem_proxy_(new mm1::MockModemProxy()),
61 modem_simple_proxy_(new mm1::MockModemSimpleProxy()),
62 sim_proxy_(new mm1::MockSimProxy()),
63 properties_proxy_(new MockDBusPropertiesProxy()),
64 proxy_factory_(this),
65 cellular_(new Cellular(&modem_info_,
66 "",
67 kMachineAddress,
68 0,
69 Cellular::kTypeUniversalCDMA,
70 "",
71 "",
72 "",
73 &proxy_factory_)),
74 service_(new MockCellularService(&modem_info_,
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070075 cellular_)),
76 mock_home_provider_info_(NULL),
77 mock_serving_operator_info_(NULL) {}
Arman Uguray72fab6a2013-01-10 19:32:42 -080078
79 virtual ~CellularCapabilityUniversalCDMATest() {
80 cellular_->service_ = NULL;
81 capability_ = NULL;
82 device_adaptor_ = NULL;
83 }
84
85 virtual void SetUp() {
86 capability_ = dynamic_cast<CellularCapabilityUniversalCDMA *>(
87 cellular_->capability_.get());
88 device_adaptor_ =
89 dynamic_cast<NiceMock<DeviceMockAdaptor> *>(cellular_->adaptor());
90 cellular_->service_ = service_;
91 }
92
93 virtual void TearDown() {
94 capability_->proxy_factory_ = NULL;
95 }
96
97 void SetService() {
98 cellular_->service_ = new CellularService(&modem_info_, cellular_);
99 }
100
Arman Ugurayc5391232013-09-23 21:30:46 -0700101 void ClearService() {
102 cellular_->service_ = NULL;
103 }
104
Arman Uguray72fab6a2013-01-10 19:32:42 -0800105 void ReleaseCapabilityProxies() {
106 capability_->ReleaseProxies();
107 }
108
109 void SetCdmaProxy() {
110 capability_->modem_cdma_proxy_.reset(modem_cdma_proxy_.release());
111 }
112
113 void SetSimpleProxy() {
114 capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release());
115 }
116
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700117 void SetMockMobileOperatorInfoObjects() {
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700118 CHECK(!mock_home_provider_info_);
119 CHECK(!mock_serving_operator_info_);
Miao-chen Chou70190b32014-05-14 18:24:30 -0700120 mock_home_provider_info_ =
121 new MockMobileOperatorInfo(dispatcher_, "HomeProvider");
122 mock_serving_operator_info_ =
123 new MockMobileOperatorInfo(dispatcher_, "ServingOperator");
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700124 cellular_->set_home_provider_info(mock_home_provider_info_);
125 cellular_->set_serving_operator_info(mock_serving_operator_info_);
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700126 }
127
Arman Uguray72fab6a2013-01-10 19:32:42 -0800128 protected:
129 static const char kEsn[];
130 static const char kMachineAddress[];
131 static const char kMeid[];
132
133 class TestProxyFactory : public ProxyFactory {
134 public:
135 explicit TestProxyFactory(CellularCapabilityUniversalCDMATest *test) :
136 test_(test) {}
137
138 // TODO(armansito): Some of these methods won't be necessary after 3GPP
139 // gets refactored out of CellularCapabilityUniversal.
Arman Uguray72fab6a2013-01-10 19:32:42 -0800140 virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy(
141 const std::string &/*path*/,
142 const std::string &/*service*/) {
143 return test_->modem_3gpp_proxy_.release();
144 }
145
146 virtual mm1::ModemModemCdmaProxyInterface *CreateMM1ModemModemCdmaProxy(
147 const std::string &/*path*/,
148 const std::string &/*service*/) {
149 return test_->modem_cdma_proxy_.release();
150 }
151
152 virtual mm1::ModemProxyInterface *CreateMM1ModemProxy(
153 const std::string &/*path*/,
154 const std::string &/*service*/) {
155 return test_->modem_proxy_.release();
156 }
157
158 virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy(
159 const std::string &/*path*/,
160 const std::string &/*service*/) {
161 return test_->modem_simple_proxy_.release();
162 }
163
164 virtual mm1::SimProxyInterface *CreateSimProxy(
165 const std::string &/*path*/,
166 const std::string &/*service*/) {
167 return test_->sim_proxy_.release();
168 }
169
170 virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy(
171 const std::string &/*path*/,
172 const std::string &/*service*/) {
173 return test_->properties_proxy_.release();
174 }
175
176 private:
177 CellularCapabilityUniversalCDMATest *test_;
178 };
179
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700180 EventDispatcher *dispatcher_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800181 CellularCapabilityUniversalCDMA *capability_;
182 NiceMock<DeviceMockAdaptor> *device_adaptor_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800183 MockModemInfo modem_info_;
184 MockGLib glib_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800185 // TODO(armansito): Remove |modem_3gpp_proxy_| after refactor.
186 scoped_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_;
187 scoped_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_;
188 scoped_ptr<mm1::MockModemProxy> modem_proxy_;
189 scoped_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_;
190 scoped_ptr<mm1::MockSimProxy> sim_proxy_;
191 scoped_ptr<MockDBusPropertiesProxy> properties_proxy_;
192 TestProxyFactory proxy_factory_;
193 CellularRefPtr cellular_;
194 MockCellularService *service_;
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700195
196 // Set when required and passed to |cellular_|. Owned by |cellular_|.
197 MockMobileOperatorInfo *mock_home_provider_info_;
198 MockMobileOperatorInfo *mock_serving_operator_info_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800199};
200
201// static
202const char CellularCapabilityUniversalCDMATest::kEsn[] = "0000";
203// static
204const char CellularCapabilityUniversalCDMATest::kMachineAddress[] =
205 "TestMachineAddress";
206// static
207const char CellularCapabilityUniversalCDMATest::kMeid[] = "11111111111111";
208
Arman Uguray0a3e2792013-01-17 16:31:50 -0800209class CellularCapabilityUniversalCDMAMainTest
210 : public CellularCapabilityUniversalCDMATest {
211 public:
212 CellularCapabilityUniversalCDMAMainTest()
213 : CellularCapabilityUniversalCDMATest(&dispatcher_) {}
214
215 private:
216 EventDispatcher dispatcher_;
217};
218
219class CellularCapabilityUniversalCDMADispatcherTest
220 : public CellularCapabilityUniversalCDMATest {
221 public:
222 CellularCapabilityUniversalCDMADispatcherTest()
223 : CellularCapabilityUniversalCDMATest(NULL) {}
224};
225
226TEST_F(CellularCapabilityUniversalCDMAMainTest, PropertiesChanged) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800227 // Set up mock modem CDMA properties.
228 DBusPropertiesMap modem_cdma_properties;
229 modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_MEID].
230 writer().append_string(kMeid);
231 modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_ESN].
232 writer().append_string(kEsn);
233
234 SetUp();
235
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800236 EXPECT_TRUE(cellular_->meid().empty());
237 EXPECT_TRUE(cellular_->esn().empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800238
239 // Changing properties on wrong interface will not have an effect
240 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
241 modem_cdma_properties,
242 vector<string>());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800243 EXPECT_TRUE(cellular_->meid().empty());
244 EXPECT_TRUE(cellular_->esn().empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800245
246 // Changing properties on the right interface gets reflected in the
247 // capabilities object
248 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEMCDMA,
249 modem_cdma_properties,
250 vector<string>());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800251 EXPECT_EQ(kMeid, cellular_->meid());
252 EXPECT_EQ(kEsn, cellular_->esn());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800253}
254
Arman Uguray0a3e2792013-01-17 16:31:50 -0800255TEST_F(CellularCapabilityUniversalCDMAMainTest, OnCDMARegistrationChanged) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800256 EXPECT_EQ(0, capability_->sid_);
257 EXPECT_EQ(0, capability_->nid_);
258 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
259 capability_->cdma_1x_registration_state_);
260 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
261 capability_->cdma_evdo_registration_state_);
262
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700263 const unsigned kSid = 2;
264 const unsigned kNid = 1;
265 SetMockMobileOperatorInfoObjects();
266 EXPECT_CALL(*mock_serving_operator_info_, UpdateSID(UintToString(kSid)));
267 EXPECT_CALL(*mock_serving_operator_info_, UpdateNID(UintToString(kNid)));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800268 capability_->OnCDMARegistrationChanged(
269 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
270 MM_MODEM_CDMA_REGISTRATION_STATE_HOME,
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700271 kSid,
272 kNid);
273 EXPECT_EQ(kSid, capability_->sid_);
274 EXPECT_EQ(kNid, capability_->nid_);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800275 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
276 capability_->cdma_1x_registration_state_);
277 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_HOME,
278 capability_->cdma_evdo_registration_state_);
279
280 EXPECT_TRUE(capability_->IsRegistered());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800281}
282
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700283TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateServiceOLP) {
284 const MobileOperatorInfo::OnlinePortal kOlp {
285 "http://testurl",
286 "POST",
287 "esn=${esn}&mdn=${mdn}&meid=${meid}"};
288 const vector<MobileOperatorInfo::OnlinePortal> kOlpList {kOlp};
Prathmesh Prabhu5089a6e2014-05-07 20:49:16 -0700289 const string kUuidVzw = "c83d6597-dc91-4d48-a3a7-d86b80123751";
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700290 const string kUuidFoo = "foo";
Arman Uguray72fab6a2013-01-10 19:32:42 -0800291
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700292 SetMockMobileOperatorInfoObjects();
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800293 cellular_->set_esn("0");
294 cellular_->set_mdn("10123456789");
295 cellular_->set_meid("4");
Arman Uguray72fab6a2013-01-10 19:32:42 -0800296
Arman Uguray72fab6a2013-01-10 19:32:42 -0800297
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700298 mock_serving_operator_info_->SetEmptyDefaultsForProperties();
299 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700300 .WillRepeatedly(Return(true));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700301 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700302 .WillRepeatedly(ReturnRef(kOlpList));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700303 EXPECT_CALL(*mock_serving_operator_info_, uuid())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700304 .WillOnce(ReturnRef(kUuidVzw));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800305 SetService();
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700306 capability_->UpdateServiceOLP();
307 // Copy to simplify assertions below.
308 Stringmap vzw_olp = cellular_->service()->olp();
309 EXPECT_EQ("http://testurl", vzw_olp[kPaymentPortalURL]);
310 EXPECT_EQ("POST", vzw_olp[kPaymentPortalMethod]);
311 EXPECT_EQ("esn=0&mdn=0123456789&meid=4",
312 vzw_olp[kPaymentPortalPostData]);
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700313 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
Ben Chan07193fd2013-07-12 22:10:55 -0700314
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700315 mock_serving_operator_info_->SetEmptyDefaultsForProperties();
316 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700317 .WillRepeatedly(Return(true));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700318 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700319 .WillRepeatedly(ReturnRef(kOlpList));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700320 EXPECT_CALL(*mock_serving_operator_info_, uuid())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700321 .WillOnce(ReturnRef(kUuidFoo));
322 capability_->UpdateServiceOLP();
323 // Copy to simplify assertions below.
324 Stringmap olp = cellular_->service()->olp();
325 EXPECT_EQ("http://testurl", olp[kPaymentPortalURL]);
326 EXPECT_EQ("POST", olp[kPaymentPortalMethod]);
327 EXPECT_EQ("esn=0&mdn=10123456789&meid=4",
328 olp[kPaymentPortalPostData]);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800329}
330
Arman Uguray0a3e2792013-01-17 16:31:50 -0800331TEST_F(CellularCapabilityUniversalCDMAMainTest, ActivateAutomatic) {
332 mm1::MockModemModemCdmaProxy *cdma_proxy = modem_cdma_proxy_.get();
333 SetUp();
334 capability_->InitProxies();
335
336 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
337 GetActivationState(_,_))
338 .Times(0);
339 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
340 SetActivationState(_,_,_))
341 .Times(0);
342 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0);
343 capability_->ActivateAutomatic();
344 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
345 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
346
347 capability_->activation_code_ = "1234";
348
349 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
350 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
351 .WillOnce(Return(PendingActivationStore::kStatePending))
352 .WillOnce(Return(PendingActivationStore::kStateActivated));
353 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
354 SetActivationState(_,_,_))
355 .Times(0);
356 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0);
357 capability_->ActivateAutomatic();
358 capability_->ActivateAutomatic();
359 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
360 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
361
362 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
363 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
364 .WillOnce(Return(PendingActivationStore::kStateUnknown))
365 .WillOnce(Return(PendingActivationStore::kStateFailureRetry));
366 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
367 SetActivationState(_,_, PendingActivationStore::kStatePending))
368 .Times(2);
369 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(2);
370 capability_->ActivateAutomatic();
371 capability_->ActivateAutomatic();
372 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
373 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
374}
375
376TEST_F(CellularCapabilityUniversalCDMAMainTest, IsServiceActivationRequired) {
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700377 CellularOperatorInfo::OLP olp;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800378 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_))
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700379 .WillOnce(Return((const CellularOperatorInfo::OLP *)NULL))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800380 .WillRepeatedly(Return(&olp));
381 capability_->activation_state_ =
382 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
383 EXPECT_FALSE(capability_->IsServiceActivationRequired());
384 EXPECT_TRUE(capability_->IsServiceActivationRequired());
385 capability_->activation_state_ =
386 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
387 EXPECT_FALSE(capability_->IsServiceActivationRequired());
388 capability_->activation_state_ =
389 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
390 EXPECT_FALSE(capability_->IsServiceActivationRequired());
391}
392
393TEST_F(CellularCapabilityUniversalCDMAMainTest,
394 UpdateServiceActivationStateProperty) {
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700395 CellularOperatorInfo::OLP olp;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800396 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_))
397 .WillRepeatedly(Return(&olp));
398 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Ben Chan7ea768e2013-09-20 15:08:40 -0700399 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800400 .WillOnce(Return(PendingActivationStore::kStatePending))
401 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
402
Ben Chan7ea768e2013-09-20 15:08:40 -0700403 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
404 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800405 .Times(1);
406 capability_->UpdateServiceActivationStateProperty();
407 Mock::VerifyAndClearExpectations(service_);
408
Ben Chan7ea768e2013-09-20 15:08:40 -0700409 EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800410 .Times(1);
411 capability_->UpdateServiceActivationStateProperty();
412 Mock::VerifyAndClearExpectations(service_);
413
Ben Chan7ea768e2013-09-20 15:08:40 -0700414 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
415 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800416 .Times(1);
417 capability_->UpdateServiceActivationStateProperty();
418 Mock::VerifyAndClearExpectations(service_);
419
Ben Chan7ea768e2013-09-20 15:08:40 -0700420 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
421 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800422 .Times(1);
423 capability_->UpdateServiceActivationStateProperty();
424 Mock::VerifyAndClearExpectations(service_);
425 Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info());
Ben Chan7ea768e2013-09-20 15:08:40 -0700426 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800427}
428
429TEST_F(CellularCapabilityUniversalCDMAMainTest, IsActivating) {
430 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
431 GetActivationState(_,_))
432 .WillOnce(Return(PendingActivationStore::kStatePending))
433 .WillOnce(Return(PendingActivationStore::kStatePending))
434 .WillOnce(Return(PendingActivationStore::kStateFailureRetry))
435 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
436
437 capability_->activation_state_ =
438 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
439 EXPECT_TRUE(capability_->IsActivating());
440 EXPECT_TRUE(capability_->IsActivating());
441 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
442 EXPECT_TRUE(capability_->IsActivating());
443 EXPECT_TRUE(capability_->IsActivating());
444 capability_->activation_state_ =
445 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
446 EXPECT_FALSE(capability_->IsActivating());
447}
448
Ben Chanb2c4a802013-11-14 12:47:52 -0800449TEST_F(CellularCapabilityUniversalCDMAMainTest, IsRegistered) {
450 capability_->cdma_1x_registration_state_ =
451 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
452 capability_->cdma_evdo_registration_state_ =
453 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
454 EXPECT_FALSE(capability_->IsRegistered());
455
456 capability_->cdma_evdo_registration_state_ =
457 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
458 EXPECT_TRUE(capability_->IsRegistered());
459
460 capability_->cdma_evdo_registration_state_ =
461 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
462 EXPECT_TRUE(capability_->IsRegistered());
463
464 capability_->cdma_evdo_registration_state_ =
465 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
466 EXPECT_TRUE(capability_->IsRegistered());
467
468 capability_->cdma_1x_registration_state_ =
469 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
470 capability_->cdma_evdo_registration_state_ =
471 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
472 EXPECT_TRUE(capability_->IsRegistered());
473
474 capability_->cdma_evdo_registration_state_ =
475 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
476 EXPECT_TRUE(capability_->IsRegistered());
477
478 capability_->cdma_evdo_registration_state_ =
479 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
480 EXPECT_TRUE(capability_->IsRegistered());
481
482 capability_->cdma_evdo_registration_state_ =
483 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
484 EXPECT_TRUE(capability_->IsRegistered());
485
486 capability_->cdma_1x_registration_state_ =
487 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
488 capability_->cdma_evdo_registration_state_ =
489 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
490 EXPECT_TRUE(capability_->IsRegistered());
491
492 capability_->cdma_evdo_registration_state_ =
493 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
494 EXPECT_TRUE(capability_->IsRegistered());
495
496 capability_->cdma_evdo_registration_state_ =
497 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
498 EXPECT_TRUE(capability_->IsRegistered());
499
500 capability_->cdma_evdo_registration_state_ =
501 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
502 EXPECT_TRUE(capability_->IsRegistered());
503
504 capability_->cdma_1x_registration_state_ =
505 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
506 capability_->cdma_evdo_registration_state_ =
507 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
508 EXPECT_TRUE(capability_->IsRegistered());
509
510 capability_->cdma_evdo_registration_state_ =
511 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
512 EXPECT_TRUE(capability_->IsRegistered());
513
514 capability_->cdma_evdo_registration_state_ =
515 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
516 EXPECT_TRUE(capability_->IsRegistered());
517
518 capability_->cdma_evdo_registration_state_ =
519 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
520 EXPECT_TRUE(capability_->IsRegistered());
521}
522
Arman Ugurayc9673062013-05-13 21:21:53 -0700523TEST_F(CellularCapabilityUniversalCDMAMainTest, SetupConnectProperties) {
524 DBusPropertiesMap map;
525 capability_->SetupConnectProperties(&map);
526 EXPECT_EQ(1, map.size());
527 EXPECT_STREQ("#777", map["number"].reader().get_string());
528}
529
Arman Uguray0a3e2792013-01-17 16:31:50 -0800530TEST_F(CellularCapabilityUniversalCDMADispatcherTest,
531 UpdatePendingActivationState) {
532 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
533 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
534 .Times(1);
535 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
536 GetActivationState(_,_))
537 .Times(0);
538 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
539 capability_->UpdatePendingActivationState();
540 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
541 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
542
543 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
544 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
545 .Times(0);
546 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
547 GetActivationState(_,_))
548 .Times(2)
549 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
550 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
551 capability_->UpdatePendingActivationState();
552 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
553 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
554
555 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
556 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
557 .Times(0);
558 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
559 GetActivationState(_,_))
560 .Times(2)
561 .WillRepeatedly(Return(PendingActivationStore::kStatePending));
562 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
563 capability_->UpdatePendingActivationState();
564 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
565 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
566
567 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
568 .Times(0);
569 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
570 GetActivationState(_,_))
571 .Times(2)
572 .WillRepeatedly(Return(PendingActivationStore::kStateFailureRetry));
573 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(1);
574 capability_->UpdatePendingActivationState();
575 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
576 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
577
578 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
579 .Times(0);
580 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
581 GetActivationState(_,_))
582 .Times(4)
583 .WillOnce(Return(PendingActivationStore::kStateActivated))
584 .WillOnce(Return(PendingActivationStore::kStateActivated))
585 .WillOnce(Return(PendingActivationStore::kStateUnknown))
586 .WillOnce(Return(PendingActivationStore::kStateUnknown));
587 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
588 capability_->UpdatePendingActivationState();
589 capability_->UpdatePendingActivationState();
590 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
591 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
592}
593
Arman Uguray72fab6a2013-01-10 19:32:42 -0800594} // namespace shill