blob: a65148b7c71d8bccffe008088c5cfe240f24f251 [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"
Arman Uguray72fab6a2013-01-10 19:32:42 -080021#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"
Prathmesh Prabhu92df6192014-04-29 18:08:08 -070031#include "shill/mock_mobile_operator_info.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080032#include "shill/mock_modem_info.h"
Arman Uguray0a3e2792013-01-17 16:31:50 -080033#include "shill/mock_pending_activation_store.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080034#include "shill/nice_mock_control.h"
35#include "shill/proxy_factory.h"
36
37using base::StringPrintf;
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070038using base::UintToString;
Arman Uguray72fab6a2013-01-10 19:32:42 -080039using std::string;
40using std::vector;
41using testing::Invoke;
42using testing::Mock;
43using testing::NiceMock;
44using testing::Return;
45using testing::SetArgumentPointee;
46using testing::_;
47
48namespace shill {
49
50class CellularCapabilityUniversalCDMATest : public testing::Test {
51 public:
Arman Uguray0a3e2792013-01-17 16:31:50 -080052 CellularCapabilityUniversalCDMATest(EventDispatcher *dispatcher)
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070053 : dispatcher_(dispatcher),
54 capability_(NULL),
Arman Uguray72fab6a2013-01-10 19:32:42 -080055 device_adaptor_(NULL),
Arman Uguray0a3e2792013-01-17 16:31:50 -080056 modem_info_(NULL, dispatcher, NULL, NULL, NULL),
Arman Uguray72fab6a2013-01-10 19:32:42 -080057 modem_3gpp_proxy_(new mm1::MockModemModem3gppProxy()),
58 modem_cdma_proxy_(new mm1::MockModemModemCdmaProxy()),
59 modem_proxy_(new mm1::MockModemProxy()),
60 modem_simple_proxy_(new mm1::MockModemSimpleProxy()),
61 sim_proxy_(new mm1::MockSimProxy()),
62 properties_proxy_(new MockDBusPropertiesProxy()),
63 proxy_factory_(this),
64 cellular_(new Cellular(&modem_info_,
65 "",
66 kMachineAddress,
67 0,
68 Cellular::kTypeUniversalCDMA,
69 "",
70 "",
71 "",
72 &proxy_factory_)),
73 service_(new MockCellularService(&modem_info_,
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070074 cellular_)),
75 mock_home_provider_info_(NULL),
76 mock_serving_operator_info_(NULL) {}
Arman Uguray72fab6a2013-01-10 19:32:42 -080077
78 virtual ~CellularCapabilityUniversalCDMATest() {
79 cellular_->service_ = NULL;
80 capability_ = NULL;
81 device_adaptor_ = NULL;
82 }
83
84 virtual void SetUp() {
85 capability_ = dynamic_cast<CellularCapabilityUniversalCDMA *>(
86 cellular_->capability_.get());
87 device_adaptor_ =
88 dynamic_cast<NiceMock<DeviceMockAdaptor> *>(cellular_->adaptor());
89 cellular_->service_ = service_;
90 }
91
92 virtual void TearDown() {
93 capability_->proxy_factory_ = NULL;
94 }
95
96 void SetService() {
97 cellular_->service_ = new CellularService(&modem_info_, cellular_);
98 }
99
Arman Ugurayc5391232013-09-23 21:30:46 -0700100 void ClearService() {
101 cellular_->service_ = NULL;
102 }
103
Arman Uguray72fab6a2013-01-10 19:32:42 -0800104 void ReleaseCapabilityProxies() {
105 capability_->ReleaseProxies();
106 }
107
108 void SetCdmaProxy() {
109 capability_->modem_cdma_proxy_.reset(modem_cdma_proxy_.release());
110 }
111
112 void SetSimpleProxy() {
113 capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release());
114 }
115
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700116 void SetMockMobileOperatorInfoObjects() {
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700117 CHECK(!mock_home_provider_info_);
118 CHECK(!mock_serving_operator_info_);
Miao-chen Chou70190b32014-05-14 18:24:30 -0700119 mock_home_provider_info_ =
120 new MockMobileOperatorInfo(dispatcher_, "HomeProvider");
121 mock_serving_operator_info_ =
122 new MockMobileOperatorInfo(dispatcher_, "ServingOperator");
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700123 cellular_->set_home_provider_info(mock_home_provider_info_);
124 cellular_->set_serving_operator_info(mock_serving_operator_info_);
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700125 }
126
Arman Uguray72fab6a2013-01-10 19:32:42 -0800127 protected:
128 static const char kEsn[];
129 static const char kMachineAddress[];
130 static const char kMeid[];
131
132 class TestProxyFactory : public ProxyFactory {
133 public:
134 explicit TestProxyFactory(CellularCapabilityUniversalCDMATest *test) :
135 test_(test) {}
136
137 // TODO(armansito): Some of these methods won't be necessary after 3GPP
138 // gets refactored out of CellularCapabilityUniversal.
Arman Uguray72fab6a2013-01-10 19:32:42 -0800139 virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy(
140 const std::string &/*path*/,
141 const std::string &/*service*/) {
142 return test_->modem_3gpp_proxy_.release();
143 }
144
145 virtual mm1::ModemModemCdmaProxyInterface *CreateMM1ModemModemCdmaProxy(
146 const std::string &/*path*/,
147 const std::string &/*service*/) {
148 return test_->modem_cdma_proxy_.release();
149 }
150
151 virtual mm1::ModemProxyInterface *CreateMM1ModemProxy(
152 const std::string &/*path*/,
153 const std::string &/*service*/) {
154 return test_->modem_proxy_.release();
155 }
156
157 virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy(
158 const std::string &/*path*/,
159 const std::string &/*service*/) {
160 return test_->modem_simple_proxy_.release();
161 }
162
163 virtual mm1::SimProxyInterface *CreateSimProxy(
164 const std::string &/*path*/,
165 const std::string &/*service*/) {
166 return test_->sim_proxy_.release();
167 }
168
169 virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy(
170 const std::string &/*path*/,
171 const std::string &/*service*/) {
172 return test_->properties_proxy_.release();
173 }
174
175 private:
176 CellularCapabilityUniversalCDMATest *test_;
177 };
178
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700179 EventDispatcher *dispatcher_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800180 CellularCapabilityUniversalCDMA *capability_;
181 NiceMock<DeviceMockAdaptor> *device_adaptor_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800182 MockModemInfo modem_info_;
183 MockGLib glib_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800184 // TODO(armansito): Remove |modem_3gpp_proxy_| after refactor.
185 scoped_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_;
186 scoped_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_;
187 scoped_ptr<mm1::MockModemProxy> modem_proxy_;
188 scoped_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_;
189 scoped_ptr<mm1::MockSimProxy> sim_proxy_;
190 scoped_ptr<MockDBusPropertiesProxy> properties_proxy_;
191 TestProxyFactory proxy_factory_;
192 CellularRefPtr cellular_;
193 MockCellularService *service_;
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700194
195 // Set when required and passed to |cellular_|. Owned by |cellular_|.
196 MockMobileOperatorInfo *mock_home_provider_info_;
197 MockMobileOperatorInfo *mock_serving_operator_info_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800198};
199
200// static
201const char CellularCapabilityUniversalCDMATest::kEsn[] = "0000";
202// static
203const char CellularCapabilityUniversalCDMATest::kMachineAddress[] =
204 "TestMachineAddress";
205// static
206const char CellularCapabilityUniversalCDMATest::kMeid[] = "11111111111111";
207
Arman Uguray0a3e2792013-01-17 16:31:50 -0800208class CellularCapabilityUniversalCDMAMainTest
209 : public CellularCapabilityUniversalCDMATest {
210 public:
211 CellularCapabilityUniversalCDMAMainTest()
212 : CellularCapabilityUniversalCDMATest(&dispatcher_) {}
213
214 private:
215 EventDispatcher dispatcher_;
216};
217
218class CellularCapabilityUniversalCDMADispatcherTest
219 : public CellularCapabilityUniversalCDMATest {
220 public:
221 CellularCapabilityUniversalCDMADispatcherTest()
222 : CellularCapabilityUniversalCDMATest(NULL) {}
223};
224
225TEST_F(CellularCapabilityUniversalCDMAMainTest, PropertiesChanged) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800226 // Set up mock modem CDMA properties.
227 DBusPropertiesMap modem_cdma_properties;
228 modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_MEID].
229 writer().append_string(kMeid);
230 modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_ESN].
231 writer().append_string(kEsn);
232
233 SetUp();
234
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800235 EXPECT_TRUE(cellular_->meid().empty());
236 EXPECT_TRUE(cellular_->esn().empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800237
238 // Changing properties on wrong interface will not have an effect
239 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
240 modem_cdma_properties,
241 vector<string>());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800242 EXPECT_TRUE(cellular_->meid().empty());
243 EXPECT_TRUE(cellular_->esn().empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800244
245 // Changing properties on the right interface gets reflected in the
246 // capabilities object
247 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEMCDMA,
248 modem_cdma_properties,
249 vector<string>());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800250 EXPECT_EQ(kMeid, cellular_->meid());
251 EXPECT_EQ(kEsn, cellular_->esn());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800252}
253
Arman Uguray0a3e2792013-01-17 16:31:50 -0800254TEST_F(CellularCapabilityUniversalCDMAMainTest, OnCDMARegistrationChanged) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800255 EXPECT_EQ(0, capability_->sid_);
256 EXPECT_EQ(0, capability_->nid_);
257 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
258 capability_->cdma_1x_registration_state_);
259 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
260 capability_->cdma_evdo_registration_state_);
261
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700262 const unsigned kSid = 2;
263 const unsigned kNid = 1;
264 SetMockMobileOperatorInfoObjects();
265 EXPECT_CALL(*mock_serving_operator_info_, UpdateSID(UintToString(kSid)));
266 EXPECT_CALL(*mock_serving_operator_info_, UpdateNID(UintToString(kNid)));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800267 capability_->OnCDMARegistrationChanged(
268 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
269 MM_MODEM_CDMA_REGISTRATION_STATE_HOME,
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700270 kSid,
271 kNid);
272 EXPECT_EQ(kSid, capability_->sid_);
273 EXPECT_EQ(kNid, capability_->nid_);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800274 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
275 capability_->cdma_1x_registration_state_);
276 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_HOME,
277 capability_->cdma_evdo_registration_state_);
278
279 EXPECT_TRUE(capability_->IsRegistered());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800280}
281
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700282TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateServiceOLP) {
283 const MobileOperatorInfo::OnlinePortal kOlp {
284 "http://testurl",
285 "POST",
286 "esn=${esn}&mdn=${mdn}&meid=${meid}"};
287 const vector<MobileOperatorInfo::OnlinePortal> kOlpList {kOlp};
Prathmesh Prabhu5089a6e2014-05-07 20:49:16 -0700288 const string kUuidVzw = "c83d6597-dc91-4d48-a3a7-d86b80123751";
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700289 const string kUuidFoo = "foo";
Arman Uguray72fab6a2013-01-10 19:32:42 -0800290
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700291 SetMockMobileOperatorInfoObjects();
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800292 cellular_->set_esn("0");
293 cellular_->set_mdn("10123456789");
294 cellular_->set_meid("4");
Arman Uguray72fab6a2013-01-10 19:32:42 -0800295
Arman Uguray72fab6a2013-01-10 19:32:42 -0800296
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700297 mock_serving_operator_info_->SetEmptyDefaultsForProperties();
298 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700299 .WillRepeatedly(Return(true));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700300 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700301 .WillRepeatedly(ReturnRef(kOlpList));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700302 EXPECT_CALL(*mock_serving_operator_info_, uuid())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700303 .WillOnce(ReturnRef(kUuidVzw));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800304 SetService();
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700305 capability_->UpdateServiceOLP();
306 // Copy to simplify assertions below.
307 Stringmap vzw_olp = cellular_->service()->olp();
308 EXPECT_EQ("http://testurl", vzw_olp[kPaymentPortalURL]);
309 EXPECT_EQ("POST", vzw_olp[kPaymentPortalMethod]);
310 EXPECT_EQ("esn=0&mdn=0123456789&meid=4",
311 vzw_olp[kPaymentPortalPostData]);
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700312 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
Ben Chan07193fd2013-07-12 22:10:55 -0700313
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700314 mock_serving_operator_info_->SetEmptyDefaultsForProperties();
315 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700316 .WillRepeatedly(Return(true));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700317 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700318 .WillRepeatedly(ReturnRef(kOlpList));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700319 EXPECT_CALL(*mock_serving_operator_info_, uuid())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700320 .WillOnce(ReturnRef(kUuidFoo));
321 capability_->UpdateServiceOLP();
322 // Copy to simplify assertions below.
323 Stringmap olp = cellular_->service()->olp();
324 EXPECT_EQ("http://testurl", olp[kPaymentPortalURL]);
325 EXPECT_EQ("POST", olp[kPaymentPortalMethod]);
326 EXPECT_EQ("esn=0&mdn=10123456789&meid=4",
327 olp[kPaymentPortalPostData]);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800328}
329
Arman Uguray0a3e2792013-01-17 16:31:50 -0800330TEST_F(CellularCapabilityUniversalCDMAMainTest, ActivateAutomatic) {
331 mm1::MockModemModemCdmaProxy *cdma_proxy = modem_cdma_proxy_.get();
332 SetUp();
333 capability_->InitProxies();
334
335 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
336 GetActivationState(_,_))
337 .Times(0);
338 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
339 SetActivationState(_,_,_))
340 .Times(0);
341 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0);
342 capability_->ActivateAutomatic();
343 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
344 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
345
346 capability_->activation_code_ = "1234";
347
348 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
349 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
350 .WillOnce(Return(PendingActivationStore::kStatePending))
351 .WillOnce(Return(PendingActivationStore::kStateActivated));
352 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
353 SetActivationState(_,_,_))
354 .Times(0);
355 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0);
356 capability_->ActivateAutomatic();
357 capability_->ActivateAutomatic();
358 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
359 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
360
361 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
362 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
363 .WillOnce(Return(PendingActivationStore::kStateUnknown))
364 .WillOnce(Return(PendingActivationStore::kStateFailureRetry));
365 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
366 SetActivationState(_,_, PendingActivationStore::kStatePending))
367 .Times(2);
368 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(2);
369 capability_->ActivateAutomatic();
370 capability_->ActivateAutomatic();
371 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
372 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
373}
374
375TEST_F(CellularCapabilityUniversalCDMAMainTest, IsServiceActivationRequired) {
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700376 const vector<MobileOperatorInfo::OnlinePortal> empty_list;
377 const vector<MobileOperatorInfo::OnlinePortal> olp_list {
378 {"some@url", "some_method", "some_post_data"}
379 };
380 SetMockMobileOperatorInfoObjects();
381
Arman Uguray0a3e2792013-01-17 16:31:50 -0800382 capability_->activation_state_ =
383 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700384 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
385 .WillRepeatedly(Return(false));
Arman Uguray0a3e2792013-01-17 16:31:50 -0800386 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700387 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
388
389 capability_->activation_state_ =
390 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
391 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
392 .WillRepeatedly(Return(true));
393 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
394 .WillRepeatedly(ReturnRef(empty_list));
395 EXPECT_FALSE(capability_->IsServiceActivationRequired());
396 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
397
398 // These expectations hold for all subsequent tests.
399 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
400 .WillRepeatedly(Return(true));
401 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
402 .WillRepeatedly(ReturnRef(olp_list));
403
404 capability_->activation_state_ =
405 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800406 EXPECT_TRUE(capability_->IsServiceActivationRequired());
407 capability_->activation_state_ =
408 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
409 EXPECT_FALSE(capability_->IsServiceActivationRequired());
410 capability_->activation_state_ =
411 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
412 EXPECT_FALSE(capability_->IsServiceActivationRequired());
413}
414
415TEST_F(CellularCapabilityUniversalCDMAMainTest,
416 UpdateServiceActivationStateProperty) {
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700417 const vector<MobileOperatorInfo::OnlinePortal> olp_list {
418 {"some@url", "some_method", "some_post_data"}
419 };
420 SetMockMobileOperatorInfoObjects();
421 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
422 .WillRepeatedly(Return(true));
423 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
424 .WillRepeatedly(ReturnRef(olp_list));
425
Arman Uguray0a3e2792013-01-17 16:31:50 -0800426 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Ben Chan7ea768e2013-09-20 15:08:40 -0700427 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800428 .WillOnce(Return(PendingActivationStore::kStatePending))
429 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
430
Ben Chan7ea768e2013-09-20 15:08:40 -0700431 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
432 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800433 .Times(1);
434 capability_->UpdateServiceActivationStateProperty();
435 Mock::VerifyAndClearExpectations(service_);
436
Ben Chan7ea768e2013-09-20 15:08:40 -0700437 EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800438 .Times(1);
439 capability_->UpdateServiceActivationStateProperty();
440 Mock::VerifyAndClearExpectations(service_);
441
Ben Chan7ea768e2013-09-20 15:08:40 -0700442 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
443 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800444 .Times(1);
445 capability_->UpdateServiceActivationStateProperty();
446 Mock::VerifyAndClearExpectations(service_);
447
Ben Chan7ea768e2013-09-20 15:08:40 -0700448 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
449 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800450 .Times(1);
451 capability_->UpdateServiceActivationStateProperty();
452 Mock::VerifyAndClearExpectations(service_);
Ben Chan7ea768e2013-09-20 15:08:40 -0700453 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800454}
455
456TEST_F(CellularCapabilityUniversalCDMAMainTest, IsActivating) {
457 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
458 GetActivationState(_,_))
459 .WillOnce(Return(PendingActivationStore::kStatePending))
460 .WillOnce(Return(PendingActivationStore::kStatePending))
461 .WillOnce(Return(PendingActivationStore::kStateFailureRetry))
462 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
463
464 capability_->activation_state_ =
465 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
466 EXPECT_TRUE(capability_->IsActivating());
467 EXPECT_TRUE(capability_->IsActivating());
468 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
469 EXPECT_TRUE(capability_->IsActivating());
470 EXPECT_TRUE(capability_->IsActivating());
471 capability_->activation_state_ =
472 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
473 EXPECT_FALSE(capability_->IsActivating());
474}
475
Ben Chanb2c4a802013-11-14 12:47:52 -0800476TEST_F(CellularCapabilityUniversalCDMAMainTest, IsRegistered) {
477 capability_->cdma_1x_registration_state_ =
478 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
479 capability_->cdma_evdo_registration_state_ =
480 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
481 EXPECT_FALSE(capability_->IsRegistered());
482
483 capability_->cdma_evdo_registration_state_ =
484 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
485 EXPECT_TRUE(capability_->IsRegistered());
486
487 capability_->cdma_evdo_registration_state_ =
488 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
489 EXPECT_TRUE(capability_->IsRegistered());
490
491 capability_->cdma_evdo_registration_state_ =
492 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
493 EXPECT_TRUE(capability_->IsRegistered());
494
495 capability_->cdma_1x_registration_state_ =
496 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
497 capability_->cdma_evdo_registration_state_ =
498 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
499 EXPECT_TRUE(capability_->IsRegistered());
500
501 capability_->cdma_evdo_registration_state_ =
502 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
503 EXPECT_TRUE(capability_->IsRegistered());
504
505 capability_->cdma_evdo_registration_state_ =
506 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
507 EXPECT_TRUE(capability_->IsRegistered());
508
509 capability_->cdma_evdo_registration_state_ =
510 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
511 EXPECT_TRUE(capability_->IsRegistered());
512
513 capability_->cdma_1x_registration_state_ =
514 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
515 capability_->cdma_evdo_registration_state_ =
516 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
517 EXPECT_TRUE(capability_->IsRegistered());
518
519 capability_->cdma_evdo_registration_state_ =
520 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
521 EXPECT_TRUE(capability_->IsRegistered());
522
523 capability_->cdma_evdo_registration_state_ =
524 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
525 EXPECT_TRUE(capability_->IsRegistered());
526
527 capability_->cdma_evdo_registration_state_ =
528 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
529 EXPECT_TRUE(capability_->IsRegistered());
530
531 capability_->cdma_1x_registration_state_ =
532 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
533 capability_->cdma_evdo_registration_state_ =
534 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
535 EXPECT_TRUE(capability_->IsRegistered());
536
537 capability_->cdma_evdo_registration_state_ =
538 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
539 EXPECT_TRUE(capability_->IsRegistered());
540
541 capability_->cdma_evdo_registration_state_ =
542 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
543 EXPECT_TRUE(capability_->IsRegistered());
544
545 capability_->cdma_evdo_registration_state_ =
546 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
547 EXPECT_TRUE(capability_->IsRegistered());
548}
549
Arman Ugurayc9673062013-05-13 21:21:53 -0700550TEST_F(CellularCapabilityUniversalCDMAMainTest, SetupConnectProperties) {
551 DBusPropertiesMap map;
552 capability_->SetupConnectProperties(&map);
553 EXPECT_EQ(1, map.size());
554 EXPECT_STREQ("#777", map["number"].reader().get_string());
555}
556
Arman Uguray0a3e2792013-01-17 16:31:50 -0800557TEST_F(CellularCapabilityUniversalCDMADispatcherTest,
558 UpdatePendingActivationState) {
559 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
560 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
561 .Times(1);
562 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
563 GetActivationState(_,_))
564 .Times(0);
565 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
566 capability_->UpdatePendingActivationState();
567 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
568 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
569
570 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
571 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
572 .Times(0);
573 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
574 GetActivationState(_,_))
575 .Times(2)
576 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
577 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
578 capability_->UpdatePendingActivationState();
579 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
580 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
581
582 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
583 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
584 .Times(0);
585 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
586 GetActivationState(_,_))
587 .Times(2)
588 .WillRepeatedly(Return(PendingActivationStore::kStatePending));
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 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
595 .Times(0);
596 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
597 GetActivationState(_,_))
598 .Times(2)
599 .WillRepeatedly(Return(PendingActivationStore::kStateFailureRetry));
600 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(1);
601 capability_->UpdatePendingActivationState();
602 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
603 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
604
605 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
606 .Times(0);
607 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
608 GetActivationState(_,_))
609 .Times(4)
610 .WillOnce(Return(PendingActivationStore::kStateActivated))
611 .WillOnce(Return(PendingActivationStore::kStateActivated))
612 .WillOnce(Return(PendingActivationStore::kStateUnknown))
613 .WillOnce(Return(PendingActivationStore::kStateUnknown));
614 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
615 capability_->UpdatePendingActivationState();
616 capability_->UpdatePendingActivationState();
617 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
618 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
619}
620
Arman Uguray72fab6a2013-01-10 19:32:42 -0800621} // namespace shill