blob: 905f58bf820204e6b05671a29f32364059a611b9 [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_);
120 mock_home_provider_info_ = new MockMobileOperatorInfo(dispatcher_);
121 mock_serving_operator_info_ = new MockMobileOperatorInfo(dispatcher_);
122 cellular_->set_home_provider_info(mock_home_provider_info_);
123 cellular_->set_serving_operator_info(mock_serving_operator_info_);
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700124 }
125
Arman Uguray72fab6a2013-01-10 19:32:42 -0800126 protected:
127 static const char kEsn[];
128 static const char kMachineAddress[];
129 static const char kMeid[];
130
131 class TestProxyFactory : public ProxyFactory {
132 public:
133 explicit TestProxyFactory(CellularCapabilityUniversalCDMATest *test) :
134 test_(test) {}
135
136 // TODO(armansito): Some of these methods won't be necessary after 3GPP
137 // gets refactored out of CellularCapabilityUniversal.
Arman Uguray72fab6a2013-01-10 19:32:42 -0800138 virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy(
139 const std::string &/*path*/,
140 const std::string &/*service*/) {
141 return test_->modem_3gpp_proxy_.release();
142 }
143
144 virtual mm1::ModemModemCdmaProxyInterface *CreateMM1ModemModemCdmaProxy(
145 const std::string &/*path*/,
146 const std::string &/*service*/) {
147 return test_->modem_cdma_proxy_.release();
148 }
149
150 virtual mm1::ModemProxyInterface *CreateMM1ModemProxy(
151 const std::string &/*path*/,
152 const std::string &/*service*/) {
153 return test_->modem_proxy_.release();
154 }
155
156 virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy(
157 const std::string &/*path*/,
158 const std::string &/*service*/) {
159 return test_->modem_simple_proxy_.release();
160 }
161
162 virtual mm1::SimProxyInterface *CreateSimProxy(
163 const std::string &/*path*/,
164 const std::string &/*service*/) {
165 return test_->sim_proxy_.release();
166 }
167
168 virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy(
169 const std::string &/*path*/,
170 const std::string &/*service*/) {
171 return test_->properties_proxy_.release();
172 }
173
174 private:
175 CellularCapabilityUniversalCDMATest *test_;
176 };
177
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700178 EventDispatcher *dispatcher_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800179 CellularCapabilityUniversalCDMA *capability_;
180 NiceMock<DeviceMockAdaptor> *device_adaptor_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800181 MockModemInfo modem_info_;
182 MockGLib glib_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800183 // TODO(armansito): Remove |modem_3gpp_proxy_| after refactor.
184 scoped_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_;
185 scoped_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_;
186 scoped_ptr<mm1::MockModemProxy> modem_proxy_;
187 scoped_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_;
188 scoped_ptr<mm1::MockSimProxy> sim_proxy_;
189 scoped_ptr<MockDBusPropertiesProxy> properties_proxy_;
190 TestProxyFactory proxy_factory_;
191 CellularRefPtr cellular_;
192 MockCellularService *service_;
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700193
194 // Set when required and passed to |cellular_|. Owned by |cellular_|.
195 MockMobileOperatorInfo *mock_home_provider_info_;
196 MockMobileOperatorInfo *mock_serving_operator_info_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800197};
198
199// static
200const char CellularCapabilityUniversalCDMATest::kEsn[] = "0000";
201// static
202const char CellularCapabilityUniversalCDMATest::kMachineAddress[] =
203 "TestMachineAddress";
204// static
205const char CellularCapabilityUniversalCDMATest::kMeid[] = "11111111111111";
206
Arman Uguray0a3e2792013-01-17 16:31:50 -0800207class CellularCapabilityUniversalCDMAMainTest
208 : public CellularCapabilityUniversalCDMATest {
209 public:
210 CellularCapabilityUniversalCDMAMainTest()
211 : CellularCapabilityUniversalCDMATest(&dispatcher_) {}
212
213 private:
214 EventDispatcher dispatcher_;
215};
216
217class CellularCapabilityUniversalCDMADispatcherTest
218 : public CellularCapabilityUniversalCDMATest {
219 public:
220 CellularCapabilityUniversalCDMADispatcherTest()
221 : CellularCapabilityUniversalCDMATest(NULL) {}
222};
223
224TEST_F(CellularCapabilityUniversalCDMAMainTest, PropertiesChanged) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800225 // Set up mock modem CDMA properties.
226 DBusPropertiesMap modem_cdma_properties;
227 modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_MEID].
228 writer().append_string(kMeid);
229 modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_ESN].
230 writer().append_string(kEsn);
231
232 SetUp();
233
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800234 EXPECT_TRUE(cellular_->meid().empty());
235 EXPECT_TRUE(cellular_->esn().empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800236
237 // Changing properties on wrong interface will not have an effect
238 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
239 modem_cdma_properties,
240 vector<string>());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800241 EXPECT_TRUE(cellular_->meid().empty());
242 EXPECT_TRUE(cellular_->esn().empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800243
244 // Changing properties on the right interface gets reflected in the
245 // capabilities object
246 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEMCDMA,
247 modem_cdma_properties,
248 vector<string>());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800249 EXPECT_EQ(kMeid, cellular_->meid());
250 EXPECT_EQ(kEsn, cellular_->esn());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800251}
252
Arman Uguray0a3e2792013-01-17 16:31:50 -0800253TEST_F(CellularCapabilityUniversalCDMAMainTest, OnCDMARegistrationChanged) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800254 EXPECT_EQ(0, capability_->sid_);
255 EXPECT_EQ(0, capability_->nid_);
256 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
257 capability_->cdma_1x_registration_state_);
258 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
259 capability_->cdma_evdo_registration_state_);
260
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700261 const unsigned kSid = 2;
262 const unsigned kNid = 1;
263 SetMockMobileOperatorInfoObjects();
264 EXPECT_CALL(*mock_serving_operator_info_, UpdateSID(UintToString(kSid)));
265 EXPECT_CALL(*mock_serving_operator_info_, UpdateNID(UintToString(kNid)));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800266 capability_->OnCDMARegistrationChanged(
267 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
268 MM_MODEM_CDMA_REGISTRATION_STATE_HOME,
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700269 kSid,
270 kNid);
271 EXPECT_EQ(kSid, capability_->sid_);
272 EXPECT_EQ(kNid, capability_->nid_);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800273 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
274 capability_->cdma_1x_registration_state_);
275 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_HOME,
276 capability_->cdma_evdo_registration_state_);
277
278 EXPECT_TRUE(capability_->IsRegistered());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800279}
280
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700281TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateServiceOLP) {
282 const MobileOperatorInfo::OnlinePortal kOlp {
283 "http://testurl",
284 "POST",
285 "esn=${esn}&mdn=${mdn}&meid=${meid}"};
286 const vector<MobileOperatorInfo::OnlinePortal> kOlpList {kOlp};
Prathmesh Prabhu5089a6e2014-05-07 20:49:16 -0700287 const string kUuidVzw = "c83d6597-dc91-4d48-a3a7-d86b80123751";
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700288 const string kUuidFoo = "foo";
Arman Uguray72fab6a2013-01-10 19:32:42 -0800289
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700290 SetMockMobileOperatorInfoObjects();
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800291 cellular_->set_esn("0");
292 cellular_->set_mdn("10123456789");
293 cellular_->set_meid("4");
Arman Uguray72fab6a2013-01-10 19:32:42 -0800294
Arman Uguray72fab6a2013-01-10 19:32:42 -0800295
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700296 mock_serving_operator_info_->SetEmptyDefaultsForProperties();
297 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700298 .WillRepeatedly(Return(true));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700299 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700300 .WillRepeatedly(ReturnRef(kOlpList));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700301 EXPECT_CALL(*mock_serving_operator_info_, uuid())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700302 .WillOnce(ReturnRef(kUuidVzw));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800303 SetService();
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700304 capability_->UpdateServiceOLP();
305 // Copy to simplify assertions below.
306 Stringmap vzw_olp = cellular_->service()->olp();
307 EXPECT_EQ("http://testurl", vzw_olp[kPaymentPortalURL]);
308 EXPECT_EQ("POST", vzw_olp[kPaymentPortalMethod]);
309 EXPECT_EQ("esn=0&mdn=0123456789&meid=4",
310 vzw_olp[kPaymentPortalPostData]);
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700311 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
Ben Chan07193fd2013-07-12 22:10:55 -0700312
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700313 mock_serving_operator_info_->SetEmptyDefaultsForProperties();
314 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700315 .WillRepeatedly(Return(true));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700316 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700317 .WillRepeatedly(ReturnRef(kOlpList));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700318 EXPECT_CALL(*mock_serving_operator_info_, uuid())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700319 .WillOnce(ReturnRef(kUuidFoo));
320 capability_->UpdateServiceOLP();
321 // Copy to simplify assertions below.
322 Stringmap olp = cellular_->service()->olp();
323 EXPECT_EQ("http://testurl", olp[kPaymentPortalURL]);
324 EXPECT_EQ("POST", olp[kPaymentPortalMethod]);
325 EXPECT_EQ("esn=0&mdn=10123456789&meid=4",
326 olp[kPaymentPortalPostData]);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800327}
328
Arman Uguray0a3e2792013-01-17 16:31:50 -0800329TEST_F(CellularCapabilityUniversalCDMAMainTest, ActivateAutomatic) {
330 mm1::MockModemModemCdmaProxy *cdma_proxy = modem_cdma_proxy_.get();
331 SetUp();
332 capability_->InitProxies();
333
334 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
335 GetActivationState(_,_))
336 .Times(0);
337 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
338 SetActivationState(_,_,_))
339 .Times(0);
340 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0);
341 capability_->ActivateAutomatic();
342 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
343 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
344
345 capability_->activation_code_ = "1234";
346
347 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
348 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
349 .WillOnce(Return(PendingActivationStore::kStatePending))
350 .WillOnce(Return(PendingActivationStore::kStateActivated));
351 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
352 SetActivationState(_,_,_))
353 .Times(0);
354 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0);
355 capability_->ActivateAutomatic();
356 capability_->ActivateAutomatic();
357 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
358 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
359
360 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
361 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
362 .WillOnce(Return(PendingActivationStore::kStateUnknown))
363 .WillOnce(Return(PendingActivationStore::kStateFailureRetry));
364 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
365 SetActivationState(_,_, PendingActivationStore::kStatePending))
366 .Times(2);
367 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(2);
368 capability_->ActivateAutomatic();
369 capability_->ActivateAutomatic();
370 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
371 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
372}
373
374TEST_F(CellularCapabilityUniversalCDMAMainTest, IsServiceActivationRequired) {
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700375 CellularOperatorInfo::OLP olp;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800376 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_))
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700377 .WillOnce(Return((const CellularOperatorInfo::OLP *)NULL))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800378 .WillRepeatedly(Return(&olp));
379 capability_->activation_state_ =
380 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
381 EXPECT_FALSE(capability_->IsServiceActivationRequired());
382 EXPECT_TRUE(capability_->IsServiceActivationRequired());
383 capability_->activation_state_ =
384 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
385 EXPECT_FALSE(capability_->IsServiceActivationRequired());
386 capability_->activation_state_ =
387 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
388 EXPECT_FALSE(capability_->IsServiceActivationRequired());
389}
390
391TEST_F(CellularCapabilityUniversalCDMAMainTest,
392 UpdateServiceActivationStateProperty) {
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700393 CellularOperatorInfo::OLP olp;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800394 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_))
395 .WillRepeatedly(Return(&olp));
396 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Ben Chan7ea768e2013-09-20 15:08:40 -0700397 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800398 .WillOnce(Return(PendingActivationStore::kStatePending))
399 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
400
Ben Chan7ea768e2013-09-20 15:08:40 -0700401 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
402 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800403 .Times(1);
404 capability_->UpdateServiceActivationStateProperty();
405 Mock::VerifyAndClearExpectations(service_);
406
Ben Chan7ea768e2013-09-20 15:08:40 -0700407 EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800408 .Times(1);
409 capability_->UpdateServiceActivationStateProperty();
410 Mock::VerifyAndClearExpectations(service_);
411
Ben Chan7ea768e2013-09-20 15:08:40 -0700412 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
413 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800414 .Times(1);
415 capability_->UpdateServiceActivationStateProperty();
416 Mock::VerifyAndClearExpectations(service_);
417
Ben Chan7ea768e2013-09-20 15:08:40 -0700418 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
419 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800420 .Times(1);
421 capability_->UpdateServiceActivationStateProperty();
422 Mock::VerifyAndClearExpectations(service_);
423 Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info());
Ben Chan7ea768e2013-09-20 15:08:40 -0700424 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800425}
426
427TEST_F(CellularCapabilityUniversalCDMAMainTest, IsActivating) {
428 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
429 GetActivationState(_,_))
430 .WillOnce(Return(PendingActivationStore::kStatePending))
431 .WillOnce(Return(PendingActivationStore::kStatePending))
432 .WillOnce(Return(PendingActivationStore::kStateFailureRetry))
433 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
434
435 capability_->activation_state_ =
436 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
437 EXPECT_TRUE(capability_->IsActivating());
438 EXPECT_TRUE(capability_->IsActivating());
439 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
440 EXPECT_TRUE(capability_->IsActivating());
441 EXPECT_TRUE(capability_->IsActivating());
442 capability_->activation_state_ =
443 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
444 EXPECT_FALSE(capability_->IsActivating());
445}
446
Ben Chanb2c4a802013-11-14 12:47:52 -0800447TEST_F(CellularCapabilityUniversalCDMAMainTest, IsRegistered) {
448 capability_->cdma_1x_registration_state_ =
449 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
450 capability_->cdma_evdo_registration_state_ =
451 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
452 EXPECT_FALSE(capability_->IsRegistered());
453
454 capability_->cdma_evdo_registration_state_ =
455 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
456 EXPECT_TRUE(capability_->IsRegistered());
457
458 capability_->cdma_evdo_registration_state_ =
459 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
460 EXPECT_TRUE(capability_->IsRegistered());
461
462 capability_->cdma_evdo_registration_state_ =
463 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
464 EXPECT_TRUE(capability_->IsRegistered());
465
466 capability_->cdma_1x_registration_state_ =
467 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
468 capability_->cdma_evdo_registration_state_ =
469 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
470 EXPECT_TRUE(capability_->IsRegistered());
471
472 capability_->cdma_evdo_registration_state_ =
473 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
474 EXPECT_TRUE(capability_->IsRegistered());
475
476 capability_->cdma_evdo_registration_state_ =
477 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
478 EXPECT_TRUE(capability_->IsRegistered());
479
480 capability_->cdma_evdo_registration_state_ =
481 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
482 EXPECT_TRUE(capability_->IsRegistered());
483
484 capability_->cdma_1x_registration_state_ =
485 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
486 capability_->cdma_evdo_registration_state_ =
487 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
488 EXPECT_TRUE(capability_->IsRegistered());
489
490 capability_->cdma_evdo_registration_state_ =
491 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
492 EXPECT_TRUE(capability_->IsRegistered());
493
494 capability_->cdma_evdo_registration_state_ =
495 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
496 EXPECT_TRUE(capability_->IsRegistered());
497
498 capability_->cdma_evdo_registration_state_ =
499 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
500 EXPECT_TRUE(capability_->IsRegistered());
501
502 capability_->cdma_1x_registration_state_ =
503 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
504 capability_->cdma_evdo_registration_state_ =
505 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
506 EXPECT_TRUE(capability_->IsRegistered());
507
508 capability_->cdma_evdo_registration_state_ =
509 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
510 EXPECT_TRUE(capability_->IsRegistered());
511
512 capability_->cdma_evdo_registration_state_ =
513 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
514 EXPECT_TRUE(capability_->IsRegistered());
515
516 capability_->cdma_evdo_registration_state_ =
517 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
518 EXPECT_TRUE(capability_->IsRegistered());
519}
520
Arman Ugurayc9673062013-05-13 21:21:53 -0700521TEST_F(CellularCapabilityUniversalCDMAMainTest, SetupConnectProperties) {
522 DBusPropertiesMap map;
523 capability_->SetupConnectProperties(&map);
524 EXPECT_EQ(1, map.size());
525 EXPECT_STREQ("#777", map["number"].reader().get_string());
526}
527
Arman Uguray0a3e2792013-01-17 16:31:50 -0800528TEST_F(CellularCapabilityUniversalCDMADispatcherTest,
529 UpdatePendingActivationState) {
530 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
531 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
532 .Times(1);
533 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
534 GetActivationState(_,_))
535 .Times(0);
536 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
537 capability_->UpdatePendingActivationState();
538 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
539 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
540
541 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
542 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
543 .Times(0);
544 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
545 GetActivationState(_,_))
546 .Times(2)
547 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
548 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
549 capability_->UpdatePendingActivationState();
550 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
551 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
552
553 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
554 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
555 .Times(0);
556 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
557 GetActivationState(_,_))
558 .Times(2)
559 .WillRepeatedly(Return(PendingActivationStore::kStatePending));
560 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
561 capability_->UpdatePendingActivationState();
562 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
563 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
564
565 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
566 .Times(0);
567 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
568 GetActivationState(_,_))
569 .Times(2)
570 .WillRepeatedly(Return(PendingActivationStore::kStateFailureRetry));
571 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(1);
572 capability_->UpdatePendingActivationState();
573 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
574 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
575
576 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
577 .Times(0);
578 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
579 GetActivationState(_,_))
580 .Times(4)
581 .WillOnce(Return(PendingActivationStore::kStateActivated))
582 .WillOnce(Return(PendingActivationStore::kStateActivated))
583 .WillOnce(Return(PendingActivationStore::kStateUnknown))
584 .WillOnce(Return(PendingActivationStore::kStateUnknown));
585 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
586 capability_->UpdatePendingActivationState();
587 capability_->UpdatePendingActivationState();
588 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
589 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
590}
591
Arman Uguray72fab6a2013-01-10 19:32:42 -0800592} // namespace shill