blob: 3597e51478a935f63257166568d87639f86c043c [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:
Alex Vakulenko8a532292014-06-16 17:18:44 -070052 explicit 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) {
Prathmesh Prabhuf2288212014-05-21 19:19:19 -0700331 const string activation_code {"1234"};
332 SetMockMobileOperatorInfoObjects();
333
Arman Uguray0a3e2792013-01-17 16:31:50 -0800334 mm1::MockModemModemCdmaProxy *cdma_proxy = modem_cdma_proxy_.get();
335 SetUp();
336 capability_->InitProxies();
337
Prathmesh Prabhuf2288212014-05-21 19:19:19 -0700338 // Cases when activation fails because |activation_code| is not available.
339 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
340 .WillRepeatedly(Return(false));
Alex Vakulenko8a532292014-06-16 17:18:44 -0700341 EXPECT_CALL(*cdma_proxy, Activate(_, _, _, _)).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800342 capability_->ActivateAutomatic();
Prathmesh Prabhuf2288212014-05-21 19:19:19 -0700343 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
344 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
345 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
346 .WillRepeatedly(Return(true));
347 mock_serving_operator_info_->SetEmptyDefaultsForProperties();
Alex Vakulenko8a532292014-06-16 17:18:44 -0700348 EXPECT_CALL(*cdma_proxy, Activate(_, _, _, _)).Times(0);
Prathmesh Prabhuf2288212014-05-21 19:19:19 -0700349 capability_->ActivateAutomatic();
350 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800351 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
352
Prathmesh Prabhuf2288212014-05-21 19:19:19 -0700353 // These expectations hold for all subsequent tests.
354 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
355 .WillRepeatedly(Return(true));
356 EXPECT_CALL(*mock_serving_operator_info_, activation_code())
357 .WillRepeatedly(ReturnRef(activation_code));
Arman Uguray0a3e2792013-01-17 16:31:50 -0800358
359 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
360 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
361 .WillOnce(Return(PendingActivationStore::kStatePending))
362 .WillOnce(Return(PendingActivationStore::kStateActivated));
363 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700364 SetActivationState(_, _, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800365 .Times(0);
Alex Vakulenko8a532292014-06-16 17:18:44 -0700366 EXPECT_CALL(*cdma_proxy, Activate(_, _, _, _)).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800367 capability_->ActivateAutomatic();
368 capability_->ActivateAutomatic();
369 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
370 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
371
372 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
373 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
374 .WillOnce(Return(PendingActivationStore::kStateUnknown))
375 .WillOnce(Return(PendingActivationStore::kStateFailureRetry));
376 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700377 SetActivationState(_, _, PendingActivationStore::kStatePending))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800378 .Times(2);
Alex Vakulenko8a532292014-06-16 17:18:44 -0700379 EXPECT_CALL(*cdma_proxy, Activate(_, _, _, _)).Times(2);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800380 capability_->ActivateAutomatic();
381 capability_->ActivateAutomatic();
382 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
383 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
384}
385
386TEST_F(CellularCapabilityUniversalCDMAMainTest, IsServiceActivationRequired) {
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700387 const vector<MobileOperatorInfo::OnlinePortal> empty_list;
388 const vector<MobileOperatorInfo::OnlinePortal> olp_list {
389 {"some@url", "some_method", "some_post_data"}
390 };
391 SetMockMobileOperatorInfoObjects();
392
Arman Uguray0a3e2792013-01-17 16:31:50 -0800393 capability_->activation_state_ =
394 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700395 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
396 .WillRepeatedly(Return(false));
Arman Uguray0a3e2792013-01-17 16:31:50 -0800397 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700398 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
399
400 capability_->activation_state_ =
401 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
402 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
403 .WillRepeatedly(Return(true));
404 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
405 .WillRepeatedly(ReturnRef(empty_list));
406 EXPECT_FALSE(capability_->IsServiceActivationRequired());
407 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
408
409 // These expectations hold for all subsequent tests.
410 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
411 .WillRepeatedly(Return(true));
412 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
413 .WillRepeatedly(ReturnRef(olp_list));
414
415 capability_->activation_state_ =
416 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800417 EXPECT_TRUE(capability_->IsServiceActivationRequired());
418 capability_->activation_state_ =
419 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
420 EXPECT_FALSE(capability_->IsServiceActivationRequired());
421 capability_->activation_state_ =
422 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
423 EXPECT_FALSE(capability_->IsServiceActivationRequired());
424}
425
426TEST_F(CellularCapabilityUniversalCDMAMainTest,
427 UpdateServiceActivationStateProperty) {
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700428 const vector<MobileOperatorInfo::OnlinePortal> olp_list {
429 {"some@url", "some_method", "some_post_data"}
430 };
431 SetMockMobileOperatorInfoObjects();
432 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
433 .WillRepeatedly(Return(true));
434 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
435 .WillRepeatedly(ReturnRef(olp_list));
436
Arman Uguray0a3e2792013-01-17 16:31:50 -0800437 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Ben Chan7ea768e2013-09-20 15:08:40 -0700438 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800439 .WillOnce(Return(PendingActivationStore::kStatePending))
440 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
441
Ben Chan7ea768e2013-09-20 15:08:40 -0700442 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
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 EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800449 .Times(1);
450 capability_->UpdateServiceActivationStateProperty();
451 Mock::VerifyAndClearExpectations(service_);
452
Ben Chan7ea768e2013-09-20 15:08:40 -0700453 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
454 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800455 .Times(1);
456 capability_->UpdateServiceActivationStateProperty();
457 Mock::VerifyAndClearExpectations(service_);
458
Ben Chan7ea768e2013-09-20 15:08:40 -0700459 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
460 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800461 .Times(1);
462 capability_->UpdateServiceActivationStateProperty();
463 Mock::VerifyAndClearExpectations(service_);
Ben Chan7ea768e2013-09-20 15:08:40 -0700464 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800465}
466
467TEST_F(CellularCapabilityUniversalCDMAMainTest, IsActivating) {
468 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700469 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800470 .WillOnce(Return(PendingActivationStore::kStatePending))
471 .WillOnce(Return(PendingActivationStore::kStatePending))
472 .WillOnce(Return(PendingActivationStore::kStateFailureRetry))
473 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
474
475 capability_->activation_state_ =
476 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
477 EXPECT_TRUE(capability_->IsActivating());
478 EXPECT_TRUE(capability_->IsActivating());
479 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
480 EXPECT_TRUE(capability_->IsActivating());
481 EXPECT_TRUE(capability_->IsActivating());
482 capability_->activation_state_ =
483 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
484 EXPECT_FALSE(capability_->IsActivating());
485}
486
Ben Chanb2c4a802013-11-14 12:47:52 -0800487TEST_F(CellularCapabilityUniversalCDMAMainTest, IsRegistered) {
488 capability_->cdma_1x_registration_state_ =
489 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
490 capability_->cdma_evdo_registration_state_ =
491 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
492 EXPECT_FALSE(capability_->IsRegistered());
493
494 capability_->cdma_evdo_registration_state_ =
495 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
496 EXPECT_TRUE(capability_->IsRegistered());
497
498 capability_->cdma_evdo_registration_state_ =
499 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
500 EXPECT_TRUE(capability_->IsRegistered());
501
502 capability_->cdma_evdo_registration_state_ =
503 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
504 EXPECT_TRUE(capability_->IsRegistered());
505
506 capability_->cdma_1x_registration_state_ =
507 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
508 capability_->cdma_evdo_registration_state_ =
509 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
510 EXPECT_TRUE(capability_->IsRegistered());
511
512 capability_->cdma_evdo_registration_state_ =
513 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
514 EXPECT_TRUE(capability_->IsRegistered());
515
516 capability_->cdma_evdo_registration_state_ =
517 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
518 EXPECT_TRUE(capability_->IsRegistered());
519
520 capability_->cdma_evdo_registration_state_ =
521 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
522 EXPECT_TRUE(capability_->IsRegistered());
523
524 capability_->cdma_1x_registration_state_ =
525 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
526 capability_->cdma_evdo_registration_state_ =
527 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
528 EXPECT_TRUE(capability_->IsRegistered());
529
530 capability_->cdma_evdo_registration_state_ =
531 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
532 EXPECT_TRUE(capability_->IsRegistered());
533
534 capability_->cdma_evdo_registration_state_ =
535 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
536 EXPECT_TRUE(capability_->IsRegistered());
537
538 capability_->cdma_evdo_registration_state_ =
539 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
540 EXPECT_TRUE(capability_->IsRegistered());
541
542 capability_->cdma_1x_registration_state_ =
543 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
544 capability_->cdma_evdo_registration_state_ =
545 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
546 EXPECT_TRUE(capability_->IsRegistered());
547
548 capability_->cdma_evdo_registration_state_ =
549 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
550 EXPECT_TRUE(capability_->IsRegistered());
551
552 capability_->cdma_evdo_registration_state_ =
553 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
554 EXPECT_TRUE(capability_->IsRegistered());
555
556 capability_->cdma_evdo_registration_state_ =
557 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
558 EXPECT_TRUE(capability_->IsRegistered());
559}
560
Arman Ugurayc9673062013-05-13 21:21:53 -0700561TEST_F(CellularCapabilityUniversalCDMAMainTest, SetupConnectProperties) {
562 DBusPropertiesMap map;
563 capability_->SetupConnectProperties(&map);
564 EXPECT_EQ(1, map.size());
565 EXPECT_STREQ("#777", map["number"].reader().get_string());
566}
567
Arman Uguray0a3e2792013-01-17 16:31:50 -0800568TEST_F(CellularCapabilityUniversalCDMADispatcherTest,
569 UpdatePendingActivationState) {
570 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
Alex Vakulenko8a532292014-06-16 17:18:44 -0700571 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800572 .Times(1);
573 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700574 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800575 .Times(0);
576 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
577 capability_->UpdatePendingActivationState();
578 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
579 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
580
581 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
Alex Vakulenko8a532292014-06-16 17:18:44 -0700582 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800583 .Times(0);
584 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700585 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800586 .Times(2)
587 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
588 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
589 capability_->UpdatePendingActivationState();
590 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
591 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
592
593 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
Alex Vakulenko8a532292014-06-16 17:18:44 -0700594 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800595 .Times(0);
596 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700597 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800598 .Times(2)
599 .WillRepeatedly(Return(PendingActivationStore::kStatePending));
600 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
601 capability_->UpdatePendingActivationState();
602 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
603 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
604
Alex Vakulenko8a532292014-06-16 17:18:44 -0700605 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800606 .Times(0);
607 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700608 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800609 .Times(2)
610 .WillRepeatedly(Return(PendingActivationStore::kStateFailureRetry));
611 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(1);
612 capability_->UpdatePendingActivationState();
613 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
614 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
615
Alex Vakulenko8a532292014-06-16 17:18:44 -0700616 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800617 .Times(0);
618 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700619 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800620 .Times(4)
621 .WillOnce(Return(PendingActivationStore::kStateActivated))
622 .WillOnce(Return(PendingActivationStore::kStateActivated))
623 .WillOnce(Return(PendingActivationStore::kStateUnknown))
624 .WillOnce(Return(PendingActivationStore::kStateUnknown));
625 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
626 capability_->UpdatePendingActivationState();
627 capability_->UpdatePendingActivationState();
628 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
629 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
630}
631
Arman Uguray72fab6a2013-01-10 19:32:42 -0800632} // namespace shill