blob: e54ce4c7fbba4e79fd86dea6f3b7e02a5a84d28b [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"
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;
38using std::string;
39using std::vector;
40using testing::Invoke;
41using testing::Mock;
42using testing::NiceMock;
43using testing::Return;
44using testing::SetArgumentPointee;
45using testing::_;
46
47namespace shill {
48
49class CellularCapabilityUniversalCDMATest : public testing::Test {
50 public:
Arman Uguray0a3e2792013-01-17 16:31:50 -080051 CellularCapabilityUniversalCDMATest(EventDispatcher *dispatcher)
Arman Uguray72fab6a2013-01-10 19:32:42 -080052 : capability_(NULL),
53 device_adaptor_(NULL),
Arman Uguray0a3e2792013-01-17 16:31:50 -080054 modem_info_(NULL, dispatcher, NULL, NULL, NULL),
Arman Uguray72fab6a2013-01-10 19:32:42 -080055 modem_3gpp_proxy_(new mm1::MockModemModem3gppProxy()),
56 modem_cdma_proxy_(new mm1::MockModemModemCdmaProxy()),
57 modem_proxy_(new mm1::MockModemProxy()),
58 modem_simple_proxy_(new mm1::MockModemSimpleProxy()),
59 sim_proxy_(new mm1::MockSimProxy()),
60 properties_proxy_(new MockDBusPropertiesProxy()),
61 proxy_factory_(this),
Prathmesh Prabhu92df6192014-04-29 18:08:08 -070062 mock_home_provider_info_(new MockMobileOperatorInfo(dispatcher)),
63 mock_serving_operator_info_(new MockMobileOperatorInfo(dispatcher)),
Arman Uguray72fab6a2013-01-10 19:32:42 -080064 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_,
74 cellular_)) {}
75
76 virtual ~CellularCapabilityUniversalCDMATest() {
77 cellular_->service_ = NULL;
78 capability_ = NULL;
79 device_adaptor_ = NULL;
80 }
81
82 virtual void SetUp() {
83 capability_ = dynamic_cast<CellularCapabilityUniversalCDMA *>(
84 cellular_->capability_.get());
85 device_adaptor_ =
86 dynamic_cast<NiceMock<DeviceMockAdaptor> *>(cellular_->adaptor());
87 cellular_->service_ = service_;
88 }
89
90 virtual void TearDown() {
91 capability_->proxy_factory_ = NULL;
92 }
93
94 void SetService() {
95 cellular_->service_ = new CellularService(&modem_info_, cellular_);
96 }
97
Arman Ugurayc5391232013-09-23 21:30:46 -070098 void ClearService() {
99 cellular_->service_ = NULL;
100 }
101
Arman Uguray72fab6a2013-01-10 19:32:42 -0800102 void ReleaseCapabilityProxies() {
103 capability_->ReleaseProxies();
104 }
105
106 void SetCdmaProxy() {
107 capability_->modem_cdma_proxy_.reset(modem_cdma_proxy_.release());
108 }
109
110 void SetSimpleProxy() {
111 capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release());
112 }
113
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700114 void SetMockMobileOperatorInfoObjects() {
115 CHECK(mock_home_provider_info_);
116 CHECK(mock_serving_operator_info_);
117 cellular_->set_home_provider_info(mock_home_provider_info_.release());
118 cellular_->set_serving_operator_info(mock_serving_operator_info_.release());
119 }
120
Arman Uguray72fab6a2013-01-10 19:32:42 -0800121 protected:
122 static const char kEsn[];
123 static const char kMachineAddress[];
124 static const char kMeid[];
125
126 class TestProxyFactory : public ProxyFactory {
127 public:
128 explicit TestProxyFactory(CellularCapabilityUniversalCDMATest *test) :
129 test_(test) {}
130
131 // TODO(armansito): Some of these methods won't be necessary after 3GPP
132 // gets refactored out of CellularCapabilityUniversal.
Arman Uguray72fab6a2013-01-10 19:32:42 -0800133 virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy(
134 const std::string &/*path*/,
135 const std::string &/*service*/) {
136 return test_->modem_3gpp_proxy_.release();
137 }
138
139 virtual mm1::ModemModemCdmaProxyInterface *CreateMM1ModemModemCdmaProxy(
140 const std::string &/*path*/,
141 const std::string &/*service*/) {
142 return test_->modem_cdma_proxy_.release();
143 }
144
145 virtual mm1::ModemProxyInterface *CreateMM1ModemProxy(
146 const std::string &/*path*/,
147 const std::string &/*service*/) {
148 return test_->modem_proxy_.release();
149 }
150
151 virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy(
152 const std::string &/*path*/,
153 const std::string &/*service*/) {
154 return test_->modem_simple_proxy_.release();
155 }
156
157 virtual mm1::SimProxyInterface *CreateSimProxy(
158 const std::string &/*path*/,
159 const std::string &/*service*/) {
160 return test_->sim_proxy_.release();
161 }
162
163 virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy(
164 const std::string &/*path*/,
165 const std::string &/*service*/) {
166 return test_->properties_proxy_.release();
167 }
168
169 private:
170 CellularCapabilityUniversalCDMATest *test_;
171 };
172
173
174 CellularCapabilityUniversalCDMA *capability_;
175 NiceMock<DeviceMockAdaptor> *device_adaptor_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800176 MockModemInfo modem_info_;
177 MockGLib glib_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800178 // TODO(armansito): Remove |modem_3gpp_proxy_| after refactor.
179 scoped_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_;
180 scoped_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_;
181 scoped_ptr<mm1::MockModemProxy> modem_proxy_;
182 scoped_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_;
183 scoped_ptr<mm1::MockSimProxy> sim_proxy_;
184 scoped_ptr<MockDBusPropertiesProxy> properties_proxy_;
185 TestProxyFactory proxy_factory_;
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700186 scoped_ptr<MockMobileOperatorInfo> mock_home_provider_info_;
187 scoped_ptr<MockMobileOperatorInfo> mock_serving_operator_info_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800188 CellularRefPtr cellular_;
189 MockCellularService *service_;
190};
191
192// static
193const char CellularCapabilityUniversalCDMATest::kEsn[] = "0000";
194// static
195const char CellularCapabilityUniversalCDMATest::kMachineAddress[] =
196 "TestMachineAddress";
197// static
198const char CellularCapabilityUniversalCDMATest::kMeid[] = "11111111111111";
199
Arman Uguray0a3e2792013-01-17 16:31:50 -0800200class CellularCapabilityUniversalCDMAMainTest
201 : public CellularCapabilityUniversalCDMATest {
202 public:
203 CellularCapabilityUniversalCDMAMainTest()
204 : CellularCapabilityUniversalCDMATest(&dispatcher_) {}
205
206 private:
207 EventDispatcher dispatcher_;
208};
209
210class CellularCapabilityUniversalCDMADispatcherTest
211 : public CellularCapabilityUniversalCDMATest {
212 public:
213 CellularCapabilityUniversalCDMADispatcherTest()
214 : CellularCapabilityUniversalCDMATest(NULL) {}
215};
216
217TEST_F(CellularCapabilityUniversalCDMAMainTest, PropertiesChanged) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800218 // Set up mock modem CDMA properties.
219 DBusPropertiesMap modem_cdma_properties;
220 modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_MEID].
221 writer().append_string(kMeid);
222 modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_ESN].
223 writer().append_string(kEsn);
224
225 SetUp();
226
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800227 EXPECT_TRUE(cellular_->meid().empty());
228 EXPECT_TRUE(cellular_->esn().empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800229
230 // Changing properties on wrong interface will not have an effect
231 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
232 modem_cdma_properties,
233 vector<string>());
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 the right interface gets reflected in the
238 // capabilities object
239 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEMCDMA,
240 modem_cdma_properties,
241 vector<string>());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800242 EXPECT_EQ(kMeid, cellular_->meid());
243 EXPECT_EQ(kEsn, cellular_->esn());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800244}
245
Arman Uguray0a3e2792013-01-17 16:31:50 -0800246TEST_F(CellularCapabilityUniversalCDMAMainTest, OnCDMARegistrationChanged) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800247 EXPECT_EQ(0, capability_->sid_);
248 EXPECT_EQ(0, capability_->nid_);
249 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
250 capability_->cdma_1x_registration_state_);
251 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
252 capability_->cdma_evdo_registration_state_);
253
254 EXPECT_EQ("", capability_->provider_.GetCode());
255 EXPECT_EQ("", capability_->provider_.GetName());
256 EXPECT_EQ("", capability_->provider_.GetCountry());
257
258 CellularOperatorInfo::CellularOperator *provider =
259 new CellularOperatorInfo::CellularOperator();
260
261 provider->country_ = "us";
262 provider->is_primary_ = true;
263 provider->name_list_.push_back(
264 CellularOperatorInfo::LocalizedName("Test", ""));
265
266 scoped_ptr<const CellularOperatorInfo::CellularOperator> ptr(provider);
267
268 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
269 GetCellularOperatorBySID("2"))
270 .WillOnce(Return(ptr.get()));
271
272 capability_->OnCDMARegistrationChanged(
273 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
274 MM_MODEM_CDMA_REGISTRATION_STATE_HOME,
275 2,
276 0);
277 EXPECT_EQ(2, capability_->sid_);
278 EXPECT_EQ(0, capability_->nid_);
279 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
280 capability_->cdma_1x_registration_state_);
281 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_HOME,
282 capability_->cdma_evdo_registration_state_);
283
284 EXPECT_TRUE(capability_->IsRegistered());
285 EXPECT_EQ("2", capability_->provider_.GetCode());
286 EXPECT_EQ("Test", capability_->provider_.GetName());
287 EXPECT_EQ("us", capability_->provider_.GetCountry());
288}
289
Arman Uguray0a3e2792013-01-17 16:31:50 -0800290TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateOperatorInfo) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800291 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_->UpdateOperatorInfo();
297 EXPECT_EQ("", capability_->provider_.GetCode());
298 EXPECT_EQ("", capability_->provider_.GetName());
299 EXPECT_EQ("", capability_->provider_.GetCountry());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800300 EXPECT_TRUE(capability_->activation_code_.empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800301
Arman Uguray72fab6a2013-01-10 19:32:42 -0800302 capability_->UpdateOperatorInfo();
303 EXPECT_EQ("", capability_->provider_.GetCode());
304 EXPECT_EQ("", capability_->provider_.GetName());
305 EXPECT_EQ("", capability_->provider_.GetCountry());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800306 EXPECT_TRUE(capability_->activation_code_.empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800307
308 capability_->sid_ = 1;
309 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
310 GetCellularOperatorBySID(_))
311 .WillOnce(Return((const CellularOperatorInfo::CellularOperator *)NULL));
312
313 capability_->UpdateOperatorInfo();
Arman Uguraye015faf2013-08-16 17:54:59 -0700314 EXPECT_EQ("1", capability_->provider_.GetCode());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800315 EXPECT_EQ("", capability_->provider_.GetName());
316 EXPECT_EQ("", capability_->provider_.GetCountry());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800317 EXPECT_TRUE(capability_->activation_code_.empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800318
319 CellularOperatorInfo::CellularOperator *provider =
320 new CellularOperatorInfo::CellularOperator();
321
322 provider->country_ = "us";
323 provider->is_primary_ = true;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800324 provider->activation_code_ = "1234";
Arman Uguray72fab6a2013-01-10 19:32:42 -0800325 provider->name_list_.push_back(
326 CellularOperatorInfo::LocalizedName("Test", ""));
327
328 scoped_ptr<const CellularOperatorInfo::CellularOperator> ptr(provider);
329
330 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
331 GetCellularOperatorBySID(_))
332 .WillOnce(Return(ptr.get()));
333
334 capability_->UpdateOperatorInfo();
335
336 EXPECT_EQ("1", capability_->provider_.GetCode());
337 EXPECT_EQ("Test", capability_->provider_.GetName());
338 EXPECT_EQ("us", capability_->provider_.GetCountry());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800339 EXPECT_EQ("1234", capability_->activation_code_);
Arman Uguray2269bb62013-07-26 14:53:30 -0700340 EXPECT_EQ("1", cellular_->service()->serving_operator().GetCode());
341 EXPECT_EQ("Test", cellular_->service()->serving_operator().GetName());
342 EXPECT_EQ("us", cellular_->service()->serving_operator().GetCountry());
Arman Uguraye015faf2013-08-16 17:54:59 -0700343
344 capability_->sid_ = 1;
345 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(),
346 GetCellularOperatorBySID(_))
347 .WillOnce(Return(nullptr));
348
349 capability_->UpdateOperatorInfo();
350 EXPECT_EQ("1", capability_->provider_.GetCode());
351 EXPECT_EQ("", capability_->provider_.GetName());
352 EXPECT_EQ("", capability_->provider_.GetCountry());
353 EXPECT_TRUE(capability_->activation_code_.empty());
354
Arman Uguray72fab6a2013-01-10 19:32:42 -0800355}
356
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700357TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateServiceOLP) {
358 const MobileOperatorInfo::OnlinePortal kOlp {
359 "http://testurl",
360 "POST",
361 "esn=${esn}&mdn=${mdn}&meid=${meid}"};
362 const vector<MobileOperatorInfo::OnlinePortal> kOlpList {kOlp};
363 const string kUuidVzw = "vzw";
364 const string kUuidFoo = "foo";
Arman Uguray72fab6a2013-01-10 19:32:42 -0800365
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700366 MockMobileOperatorInfo *serving_operator_info =
367 mock_serving_operator_info_.get();
368 SetMockMobileOperatorInfoObjects();
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800369 cellular_->set_esn("0");
370 cellular_->set_mdn("10123456789");
371 cellular_->set_meid("4");
Arman Uguray72fab6a2013-01-10 19:32:42 -0800372
Arman Uguray72fab6a2013-01-10 19:32:42 -0800373
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700374 serving_operator_info->SetEmptyDefaultsForProperties();
375 EXPECT_CALL(*serving_operator_info, IsMobileNetworkOperatorKnown())
376 .WillRepeatedly(Return(true));
377 EXPECT_CALL(*serving_operator_info, olp_list())
378 .WillRepeatedly(ReturnRef(kOlpList));
379 EXPECT_CALL(*serving_operator_info, uuid())
380 .WillOnce(ReturnRef(kUuidVzw));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800381 SetService();
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700382 capability_->UpdateServiceOLP();
383 // Copy to simplify assertions below.
384 Stringmap vzw_olp = cellular_->service()->olp();
385 EXPECT_EQ("http://testurl", vzw_olp[kPaymentPortalURL]);
386 EXPECT_EQ("POST", vzw_olp[kPaymentPortalMethod]);
387 EXPECT_EQ("esn=0&mdn=0123456789&meid=4",
388 vzw_olp[kPaymentPortalPostData]);
389 Mock::VerifyAndClearExpectations(serving_operator_info);
Ben Chan07193fd2013-07-12 22:10:55 -0700390
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700391 serving_operator_info->SetEmptyDefaultsForProperties();
392 EXPECT_CALL(*serving_operator_info, IsMobileNetworkOperatorKnown())
393 .WillRepeatedly(Return(true));
394 EXPECT_CALL(*serving_operator_info, olp_list())
395 .WillRepeatedly(ReturnRef(kOlpList));
396 EXPECT_CALL(*serving_operator_info, uuid())
397 .WillOnce(ReturnRef(kUuidFoo));
398 capability_->UpdateServiceOLP();
399 // Copy to simplify assertions below.
400 Stringmap olp = cellular_->service()->olp();
401 EXPECT_EQ("http://testurl", olp[kPaymentPortalURL]);
402 EXPECT_EQ("POST", olp[kPaymentPortalMethod]);
403 EXPECT_EQ("esn=0&mdn=10123456789&meid=4",
404 olp[kPaymentPortalPostData]);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800405}
406
Arman Uguray0a3e2792013-01-17 16:31:50 -0800407TEST_F(CellularCapabilityUniversalCDMAMainTest, ActivateAutomatic) {
408 mm1::MockModemModemCdmaProxy *cdma_proxy = modem_cdma_proxy_.get();
409 SetUp();
410 capability_->InitProxies();
411
412 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
413 GetActivationState(_,_))
414 .Times(0);
415 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
416 SetActivationState(_,_,_))
417 .Times(0);
418 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0);
419 capability_->ActivateAutomatic();
420 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
421 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
422
423 capability_->activation_code_ = "1234";
424
425 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
426 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
427 .WillOnce(Return(PendingActivationStore::kStatePending))
428 .WillOnce(Return(PendingActivationStore::kStateActivated));
429 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
430 SetActivationState(_,_,_))
431 .Times(0);
432 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(0);
433 capability_->ActivateAutomatic();
434 capability_->ActivateAutomatic();
435 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
436 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
437
438 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
439 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
440 .WillOnce(Return(PendingActivationStore::kStateUnknown))
441 .WillOnce(Return(PendingActivationStore::kStateFailureRetry));
442 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
443 SetActivationState(_,_, PendingActivationStore::kStatePending))
444 .Times(2);
445 EXPECT_CALL(*cdma_proxy, Activate(_,_,_,_)).Times(2);
446 capability_->ActivateAutomatic();
447 capability_->ActivateAutomatic();
448 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
449 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
450}
451
452TEST_F(CellularCapabilityUniversalCDMAMainTest, IsServiceActivationRequired) {
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700453 CellularOperatorInfo::OLP olp;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800454 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_))
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700455 .WillOnce(Return((const CellularOperatorInfo::OLP *)NULL))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800456 .WillRepeatedly(Return(&olp));
457 capability_->activation_state_ =
458 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
459 EXPECT_FALSE(capability_->IsServiceActivationRequired());
460 EXPECT_TRUE(capability_->IsServiceActivationRequired());
461 capability_->activation_state_ =
462 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
463 EXPECT_FALSE(capability_->IsServiceActivationRequired());
464 capability_->activation_state_ =
465 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
466 EXPECT_FALSE(capability_->IsServiceActivationRequired());
467}
468
469TEST_F(CellularCapabilityUniversalCDMAMainTest,
470 UpdateServiceActivationStateProperty) {
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700471 CellularOperatorInfo::OLP olp;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800472 EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_))
473 .WillRepeatedly(Return(&olp));
474 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Ben Chan7ea768e2013-09-20 15:08:40 -0700475 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800476 .WillOnce(Return(PendingActivationStore::kStatePending))
477 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
478
Ben Chan7ea768e2013-09-20 15:08:40 -0700479 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
480 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800481 .Times(1);
482 capability_->UpdateServiceActivationStateProperty();
483 Mock::VerifyAndClearExpectations(service_);
484
Ben Chan7ea768e2013-09-20 15:08:40 -0700485 EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800486 .Times(1);
487 capability_->UpdateServiceActivationStateProperty();
488 Mock::VerifyAndClearExpectations(service_);
489
Ben Chan7ea768e2013-09-20 15:08:40 -0700490 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
491 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800492 .Times(1);
493 capability_->UpdateServiceActivationStateProperty();
494 Mock::VerifyAndClearExpectations(service_);
495
Ben Chan7ea768e2013-09-20 15:08:40 -0700496 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
497 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800498 .Times(1);
499 capability_->UpdateServiceActivationStateProperty();
500 Mock::VerifyAndClearExpectations(service_);
501 Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info());
Ben Chan7ea768e2013-09-20 15:08:40 -0700502 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800503}
504
505TEST_F(CellularCapabilityUniversalCDMAMainTest, IsActivating) {
506 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
507 GetActivationState(_,_))
508 .WillOnce(Return(PendingActivationStore::kStatePending))
509 .WillOnce(Return(PendingActivationStore::kStatePending))
510 .WillOnce(Return(PendingActivationStore::kStateFailureRetry))
511 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
512
513 capability_->activation_state_ =
514 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
515 EXPECT_TRUE(capability_->IsActivating());
516 EXPECT_TRUE(capability_->IsActivating());
517 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
518 EXPECT_TRUE(capability_->IsActivating());
519 EXPECT_TRUE(capability_->IsActivating());
520 capability_->activation_state_ =
521 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
522 EXPECT_FALSE(capability_->IsActivating());
523}
524
Ben Chanb2c4a802013-11-14 12:47:52 -0800525TEST_F(CellularCapabilityUniversalCDMAMainTest, IsRegistered) {
526 capability_->cdma_1x_registration_state_ =
527 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
528 capability_->cdma_evdo_registration_state_ =
529 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
530 EXPECT_FALSE(capability_->IsRegistered());
531
532 capability_->cdma_evdo_registration_state_ =
533 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
534 EXPECT_TRUE(capability_->IsRegistered());
535
536 capability_->cdma_evdo_registration_state_ =
537 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
538 EXPECT_TRUE(capability_->IsRegistered());
539
540 capability_->cdma_evdo_registration_state_ =
541 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
542 EXPECT_TRUE(capability_->IsRegistered());
543
544 capability_->cdma_1x_registration_state_ =
545 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
546 capability_->cdma_evdo_registration_state_ =
547 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
548 EXPECT_TRUE(capability_->IsRegistered());
549
550 capability_->cdma_evdo_registration_state_ =
551 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
552 EXPECT_TRUE(capability_->IsRegistered());
553
554 capability_->cdma_evdo_registration_state_ =
555 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
556 EXPECT_TRUE(capability_->IsRegistered());
557
558 capability_->cdma_evdo_registration_state_ =
559 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
560 EXPECT_TRUE(capability_->IsRegistered());
561
562 capability_->cdma_1x_registration_state_ =
563 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
564 capability_->cdma_evdo_registration_state_ =
565 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
566 EXPECT_TRUE(capability_->IsRegistered());
567
568 capability_->cdma_evdo_registration_state_ =
569 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
570 EXPECT_TRUE(capability_->IsRegistered());
571
572 capability_->cdma_evdo_registration_state_ =
573 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
574 EXPECT_TRUE(capability_->IsRegistered());
575
576 capability_->cdma_evdo_registration_state_ =
577 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
578 EXPECT_TRUE(capability_->IsRegistered());
579
580 capability_->cdma_1x_registration_state_ =
581 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
582 capability_->cdma_evdo_registration_state_ =
583 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
584 EXPECT_TRUE(capability_->IsRegistered());
585
586 capability_->cdma_evdo_registration_state_ =
587 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
588 EXPECT_TRUE(capability_->IsRegistered());
589
590 capability_->cdma_evdo_registration_state_ =
591 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
592 EXPECT_TRUE(capability_->IsRegistered());
593
594 capability_->cdma_evdo_registration_state_ =
595 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
596 EXPECT_TRUE(capability_->IsRegistered());
597}
598
Arman Ugurayc9673062013-05-13 21:21:53 -0700599TEST_F(CellularCapabilityUniversalCDMAMainTest, SetupConnectProperties) {
600 DBusPropertiesMap map;
601 capability_->SetupConnectProperties(&map);
602 EXPECT_EQ(1, map.size());
603 EXPECT_STREQ("#777", map["number"].reader().get_string());
604}
605
Arman Uguray0a3e2792013-01-17 16:31:50 -0800606TEST_F(CellularCapabilityUniversalCDMADispatcherTest,
607 UpdatePendingActivationState) {
608 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
609 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
610 .Times(1);
611 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
612 GetActivationState(_,_))
613 .Times(0);
614 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
615 capability_->UpdatePendingActivationState();
616 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
617 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
618
619 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
620 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
621 .Times(0);
622 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
623 GetActivationState(_,_))
624 .Times(2)
625 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
626 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
627 capability_->UpdatePendingActivationState();
628 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
629 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
630
631 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
632 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
633 .Times(0);
634 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
635 GetActivationState(_,_))
636 .Times(2)
637 .WillRepeatedly(Return(PendingActivationStore::kStatePending));
638 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
639 capability_->UpdatePendingActivationState();
640 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
641 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
642
643 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
644 .Times(0);
645 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
646 GetActivationState(_,_))
647 .Times(2)
648 .WillRepeatedly(Return(PendingActivationStore::kStateFailureRetry));
649 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(1);
650 capability_->UpdatePendingActivationState();
651 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
652 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
653
654 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_,_))
655 .Times(0);
656 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
657 GetActivationState(_,_))
658 .Times(4)
659 .WillOnce(Return(PendingActivationStore::kStateActivated))
660 .WillOnce(Return(PendingActivationStore::kStateActivated))
661 .WillOnce(Return(PendingActivationStore::kStateUnknown))
662 .WillOnce(Return(PendingActivationStore::kStateUnknown));
663 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
664 capability_->UpdatePendingActivationState();
665 capability_->UpdatePendingActivationState();
666 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
667 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
668}
669
Arman Uguray72fab6a2013-01-10 19:32:42 -0800670} // namespace shill