blob: 348afe55e8b161f1b1ff4d69b1f7876bca771642 [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
Ben Chanc54afe52014-11-05 10:28:08 -08005#include "shill/cellular/cellular_capability_universal_cdma.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -08006
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
Ben Chanc54afe52014-11-05 10:28:08 -080017#include "shill/cellular/cellular.h"
18#include "shill/cellular/cellular_service.h"
19#include "shill/cellular/mock_cellular_service.h"
20#include "shill/cellular/mock_mm1_modem_modem3gpp_proxy.h"
21#include "shill/cellular/mock_mm1_modem_modemcdma_proxy.h"
22#include "shill/cellular/mock_mm1_modem_proxy.h"
23#include "shill/cellular/mock_mm1_modem_simple_proxy.h"
24#include "shill/cellular/mock_mm1_sim_proxy.h"
25#include "shill/cellular/mock_mobile_operator_info.h"
26#include "shill/cellular/mock_modem_info.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080027#include "shill/event_dispatcher.h"
28#include "shill/mock_adaptors.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080029#include "shill/mock_dbus_properties_proxy.h"
30#include "shill/mock_glib.h"
31#include "shill/mock_manager.h"
32#include "shill/mock_metrics.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;
Ben Chanc20ed132014-10-16 12:25:03 -070040using std::unique_ptr;
Arman Uguray72fab6a2013-01-10 19:32:42 -080041using 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:
Paul Stewart2f6c7892015-06-16 13:13:10 -070053 explicit CellularCapabilityUniversalCDMATest(EventDispatcher* dispatcher)
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070054 : dispatcher_(dispatcher),
Ben Chanea18c6c2014-09-30 13:08:26 -070055 capability_(nullptr),
56 device_adaptor_(nullptr),
57 modem_info_(nullptr, dispatcher, nullptr, nullptr, nullptr),
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_)),
Ben Chanea18c6c2014-09-30 13:08:26 -070076 mock_home_provider_info_(nullptr),
77 mock_serving_operator_info_(nullptr) {}
Arman Uguray72fab6a2013-01-10 19:32:42 -080078
79 virtual ~CellularCapabilityUniversalCDMATest() {
Ben Chanea18c6c2014-09-30 13:08:26 -070080 cellular_->service_ = nullptr;
81 capability_ = nullptr;
82 device_adaptor_ = nullptr;
Arman Uguray72fab6a2013-01-10 19:32:42 -080083 }
84
85 virtual void SetUp() {
Paul Stewart2f6c7892015-06-16 13:13:10 -070086 capability_ = dynamic_cast<CellularCapabilityUniversalCDMA*>(
Arman Uguray72fab6a2013-01-10 19:32:42 -080087 cellular_->capability_.get());
88 device_adaptor_ =
Paul Stewart2f6c7892015-06-16 13:13:10 -070089 dynamic_cast<NiceMock<DeviceMockAdaptor>*>(cellular_->adaptor());
Arman Uguray72fab6a2013-01-10 19:32:42 -080090 cellular_->service_ = service_;
91 }
92
93 virtual void TearDown() {
Ben Chanea18c6c2014-09-30 13:08:26 -070094 capability_->proxy_factory_ = nullptr;
Arman Uguray72fab6a2013-01-10 19:32:42 -080095 }
96
97 void SetService() {
98 cellular_->service_ = new CellularService(&modem_info_, cellular_);
99 }
100
Arman Ugurayc5391232013-09-23 21:30:46 -0700101 void ClearService() {
Ben Chanea18c6c2014-09-30 13:08:26 -0700102 cellular_->service_ = nullptr;
Arman Ugurayc5391232013-09-23 21:30:46 -0700103 }
104
Arman Uguray72fab6a2013-01-10 19:32:42 -0800105 void ReleaseCapabilityProxies() {
106 capability_->ReleaseProxies();
107 }
108
109 void SetCdmaProxy() {
110 capability_->modem_cdma_proxy_.reset(modem_cdma_proxy_.release());
111 }
112
113 void SetSimpleProxy() {
114 capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release());
115 }
116
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700117 void SetMockMobileOperatorInfoObjects() {
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700118 CHECK(!mock_home_provider_info_);
119 CHECK(!mock_serving_operator_info_);
Miao-chen Chou70190b32014-05-14 18:24:30 -0700120 mock_home_provider_info_ =
121 new MockMobileOperatorInfo(dispatcher_, "HomeProvider");
122 mock_serving_operator_info_ =
123 new MockMobileOperatorInfo(dispatcher_, "ServingOperator");
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700124 cellular_->set_home_provider_info(mock_home_provider_info_);
125 cellular_->set_serving_operator_info(mock_serving_operator_info_);
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700126 }
127
Arman Uguray72fab6a2013-01-10 19:32:42 -0800128 protected:
129 static const char kEsn[];
130 static const char kMachineAddress[];
131 static const char kMeid[];
132
133 class TestProxyFactory : public ProxyFactory {
134 public:
Paul Stewart2f6c7892015-06-16 13:13:10 -0700135 explicit TestProxyFactory(CellularCapabilityUniversalCDMATest* test) :
Arman Uguray72fab6a2013-01-10 19:32:42 -0800136 test_(test) {}
137
138 // TODO(armansito): Some of these methods won't be necessary after 3GPP
139 // gets refactored out of CellularCapabilityUniversal.
Paul Stewart2f6c7892015-06-16 13:13:10 -0700140 virtual mm1::ModemModem3gppProxyInterface* CreateMM1ModemModem3gppProxy(
141 const std::string& /*path*/,
142 const std::string& /*service*/) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800143 return test_->modem_3gpp_proxy_.release();
144 }
145
Paul Stewart2f6c7892015-06-16 13:13:10 -0700146 virtual mm1::ModemModemCdmaProxyInterface* CreateMM1ModemModemCdmaProxy(
147 const std::string& /*path*/,
148 const std::string& /*service*/) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800149 return test_->modem_cdma_proxy_.release();
150 }
151
Paul Stewart2f6c7892015-06-16 13:13:10 -0700152 virtual mm1::ModemProxyInterface* CreateMM1ModemProxy(
153 const std::string& /*path*/,
154 const std::string& /*service*/) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800155 return test_->modem_proxy_.release();
156 }
157
Paul Stewart2f6c7892015-06-16 13:13:10 -0700158 virtual mm1::ModemSimpleProxyInterface* CreateMM1ModemSimpleProxy(
159 const std::string& /*path*/,
160 const std::string& /*service*/) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800161 return test_->modem_simple_proxy_.release();
162 }
163
Paul Stewart2f6c7892015-06-16 13:13:10 -0700164 virtual mm1::SimProxyInterface* CreateSimProxy(
165 const std::string& /*path*/,
166 const std::string& /*service*/) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800167 return test_->sim_proxy_.release();
168 }
169
Paul Stewart2f6c7892015-06-16 13:13:10 -0700170 virtual DBusPropertiesProxyInterface* CreateDBusPropertiesProxy(
171 const std::string& /*path*/,
172 const std::string& /*service*/) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800173 return test_->properties_proxy_.release();
174 }
175
176 private:
Paul Stewart2f6c7892015-06-16 13:13:10 -0700177 CellularCapabilityUniversalCDMATest* test_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800178 };
179
Paul Stewart2f6c7892015-06-16 13:13:10 -0700180 EventDispatcher* dispatcher_;
181 CellularCapabilityUniversalCDMA* capability_;
182 NiceMock<DeviceMockAdaptor>* device_adaptor_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800183 MockModemInfo modem_info_;
184 MockGLib glib_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800185 // TODO(armansito): Remove |modem_3gpp_proxy_| after refactor.
Ben Chanc20ed132014-10-16 12:25:03 -0700186 unique_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_;
187 unique_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_;
188 unique_ptr<mm1::MockModemProxy> modem_proxy_;
189 unique_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_;
190 unique_ptr<mm1::MockSimProxy> sim_proxy_;
191 unique_ptr<MockDBusPropertiesProxy> properties_proxy_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800192 TestProxyFactory proxy_factory_;
193 CellularRefPtr cellular_;
Paul Stewart2f6c7892015-06-16 13:13:10 -0700194 MockCellularService* service_;
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700195
196 // Set when required and passed to |cellular_|. Owned by |cellular_|.
Paul Stewart2f6c7892015-06-16 13:13:10 -0700197 MockMobileOperatorInfo* mock_home_provider_info_;
198 MockMobileOperatorInfo* mock_serving_operator_info_;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800199};
200
201// static
202const char CellularCapabilityUniversalCDMATest::kEsn[] = "0000";
203// static
204const char CellularCapabilityUniversalCDMATest::kMachineAddress[] =
205 "TestMachineAddress";
206// static
207const char CellularCapabilityUniversalCDMATest::kMeid[] = "11111111111111";
208
Arman Uguray0a3e2792013-01-17 16:31:50 -0800209class CellularCapabilityUniversalCDMAMainTest
210 : public CellularCapabilityUniversalCDMATest {
211 public:
212 CellularCapabilityUniversalCDMAMainTest()
213 : CellularCapabilityUniversalCDMATest(&dispatcher_) {}
214
215 private:
216 EventDispatcher dispatcher_;
217};
218
219class CellularCapabilityUniversalCDMADispatcherTest
220 : public CellularCapabilityUniversalCDMATest {
221 public:
222 CellularCapabilityUniversalCDMADispatcherTest()
Ben Chanea18c6c2014-09-30 13:08:26 -0700223 : CellularCapabilityUniversalCDMATest(nullptr) {}
Arman Uguray0a3e2792013-01-17 16:31:50 -0800224};
225
226TEST_F(CellularCapabilityUniversalCDMAMainTest, PropertiesChanged) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800227 // Set up mock modem CDMA properties.
228 DBusPropertiesMap modem_cdma_properties;
229 modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_MEID].
230 writer().append_string(kMeid);
231 modem_cdma_properties[MM_MODEM_MODEMCDMA_PROPERTY_ESN].
232 writer().append_string(kEsn);
233
234 SetUp();
235
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800236 EXPECT_TRUE(cellular_->meid().empty());
237 EXPECT_TRUE(cellular_->esn().empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800238
239 // Changing properties on wrong interface will not have an effect
240 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM,
241 modem_cdma_properties,
242 vector<string>());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800243 EXPECT_TRUE(cellular_->meid().empty());
244 EXPECT_TRUE(cellular_->esn().empty());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800245
246 // Changing properties on the right interface gets reflected in the
247 // capabilities object
248 capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEMCDMA,
249 modem_cdma_properties,
250 vector<string>());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800251 EXPECT_EQ(kMeid, cellular_->meid());
252 EXPECT_EQ(kEsn, cellular_->esn());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800253}
254
Arman Uguray0a3e2792013-01-17 16:31:50 -0800255TEST_F(CellularCapabilityUniversalCDMAMainTest, OnCDMARegistrationChanged) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800256 EXPECT_EQ(0, capability_->sid_);
257 EXPECT_EQ(0, capability_->nid_);
258 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
259 capability_->cdma_1x_registration_state_);
260 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
261 capability_->cdma_evdo_registration_state_);
262
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700263 const unsigned kSid = 2;
264 const unsigned kNid = 1;
265 SetMockMobileOperatorInfoObjects();
266 EXPECT_CALL(*mock_serving_operator_info_, UpdateSID(UintToString(kSid)));
267 EXPECT_CALL(*mock_serving_operator_info_, UpdateNID(UintToString(kNid)));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800268 capability_->OnCDMARegistrationChanged(
269 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
270 MM_MODEM_CDMA_REGISTRATION_STATE_HOME,
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700271 kSid,
272 kNid);
273 EXPECT_EQ(kSid, capability_->sid_);
274 EXPECT_EQ(kNid, capability_->nid_);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800275 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
276 capability_->cdma_1x_registration_state_);
277 EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_HOME,
278 capability_->cdma_evdo_registration_state_);
279
280 EXPECT_TRUE(capability_->IsRegistered());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800281}
282
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700283TEST_F(CellularCapabilityUniversalCDMAMainTest, UpdateServiceOLP) {
284 const MobileOperatorInfo::OnlinePortal kOlp {
285 "http://testurl",
286 "POST",
287 "esn=${esn}&mdn=${mdn}&meid=${meid}"};
288 const vector<MobileOperatorInfo::OnlinePortal> kOlpList {kOlp};
Prathmesh Prabhu5089a6e2014-05-07 20:49:16 -0700289 const string kUuidVzw = "c83d6597-dc91-4d48-a3a7-d86b80123751";
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700290 const string kUuidFoo = "foo";
Arman Uguray72fab6a2013-01-10 19:32:42 -0800291
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700292 SetMockMobileOperatorInfoObjects();
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800293 cellular_->set_esn("0");
294 cellular_->set_mdn("10123456789");
295 cellular_->set_meid("4");
Arman Uguray72fab6a2013-01-10 19:32:42 -0800296
Arman Uguray72fab6a2013-01-10 19:32:42 -0800297
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700298 mock_serving_operator_info_->SetEmptyDefaultsForProperties();
299 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700300 .WillRepeatedly(Return(true));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700301 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700302 .WillRepeatedly(ReturnRef(kOlpList));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700303 EXPECT_CALL(*mock_serving_operator_info_, uuid())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700304 .WillOnce(ReturnRef(kUuidVzw));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800305 SetService();
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700306 capability_->UpdateServiceOLP();
307 // Copy to simplify assertions below.
308 Stringmap vzw_olp = cellular_->service()->olp();
309 EXPECT_EQ("http://testurl", vzw_olp[kPaymentPortalURL]);
310 EXPECT_EQ("POST", vzw_olp[kPaymentPortalMethod]);
311 EXPECT_EQ("esn=0&mdn=0123456789&meid=4",
312 vzw_olp[kPaymentPortalPostData]);
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700313 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
Ben Chan07193fd2013-07-12 22:10:55 -0700314
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700315 mock_serving_operator_info_->SetEmptyDefaultsForProperties();
316 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700317 .WillRepeatedly(Return(true));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700318 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700319 .WillRepeatedly(ReturnRef(kOlpList));
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700320 EXPECT_CALL(*mock_serving_operator_info_, uuid())
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700321 .WillOnce(ReturnRef(kUuidFoo));
322 capability_->UpdateServiceOLP();
323 // Copy to simplify assertions below.
324 Stringmap olp = cellular_->service()->olp();
325 EXPECT_EQ("http://testurl", olp[kPaymentPortalURL]);
326 EXPECT_EQ("POST", olp[kPaymentPortalMethod]);
327 EXPECT_EQ("esn=0&mdn=10123456789&meid=4",
328 olp[kPaymentPortalPostData]);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800329}
330
Arman Uguray0a3e2792013-01-17 16:31:50 -0800331TEST_F(CellularCapabilityUniversalCDMAMainTest, ActivateAutomatic) {
Prathmesh Prabhuf2288212014-05-21 19:19:19 -0700332 const string activation_code {"1234"};
333 SetMockMobileOperatorInfoObjects();
334
Paul Stewart2f6c7892015-06-16 13:13:10 -0700335 mm1::MockModemModemCdmaProxy* cdma_proxy = modem_cdma_proxy_.get();
Arman Uguray0a3e2792013-01-17 16:31:50 -0800336 SetUp();
337 capability_->InitProxies();
338
Prathmesh Prabhuf2288212014-05-21 19:19:19 -0700339 // Cases when activation fails because |activation_code| is not available.
340 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
341 .WillRepeatedly(Return(false));
Alex Vakulenko8a532292014-06-16 17:18:44 -0700342 EXPECT_CALL(*cdma_proxy, Activate(_, _, _, _)).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800343 capability_->ActivateAutomatic();
Prathmesh Prabhuf2288212014-05-21 19:19:19 -0700344 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
345 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
346 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
347 .WillRepeatedly(Return(true));
348 mock_serving_operator_info_->SetEmptyDefaultsForProperties();
Alex Vakulenko8a532292014-06-16 17:18:44 -0700349 EXPECT_CALL(*cdma_proxy, Activate(_, _, _, _)).Times(0);
Prathmesh Prabhuf2288212014-05-21 19:19:19 -0700350 capability_->ActivateAutomatic();
351 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800352 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
353
Prathmesh Prabhuf2288212014-05-21 19:19:19 -0700354 // These expectations hold for all subsequent tests.
355 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
356 .WillRepeatedly(Return(true));
357 EXPECT_CALL(*mock_serving_operator_info_, activation_code())
358 .WillRepeatedly(ReturnRef(activation_code));
Arman Uguray0a3e2792013-01-17 16:31:50 -0800359
360 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
361 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
362 .WillOnce(Return(PendingActivationStore::kStatePending))
363 .WillOnce(Return(PendingActivationStore::kStateActivated));
364 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700365 SetActivationState(_, _, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800366 .Times(0);
Alex Vakulenko8a532292014-06-16 17:18:44 -0700367 EXPECT_CALL(*cdma_proxy, Activate(_, _, _, _)).Times(0);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800368 capability_->ActivateAutomatic();
369 capability_->ActivateAutomatic();
370 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
371 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
372
373 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
374 GetActivationState(PendingActivationStore::kIdentifierMEID, _))
375 .WillOnce(Return(PendingActivationStore::kStateUnknown))
376 .WillOnce(Return(PendingActivationStore::kStateFailureRetry));
377 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700378 SetActivationState(_, _, PendingActivationStore::kStatePending))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800379 .Times(2);
Alex Vakulenko8a532292014-06-16 17:18:44 -0700380 EXPECT_CALL(*cdma_proxy, Activate(_, _, _, _)).Times(2);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800381 capability_->ActivateAutomatic();
382 capability_->ActivateAutomatic();
383 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
384 Mock::VerifyAndClearExpectations(modem_cdma_proxy_.get());
385}
386
387TEST_F(CellularCapabilityUniversalCDMAMainTest, IsServiceActivationRequired) {
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700388 const vector<MobileOperatorInfo::OnlinePortal> empty_list;
389 const vector<MobileOperatorInfo::OnlinePortal> olp_list {
390 {"some@url", "some_method", "some_post_data"}
391 };
392 SetMockMobileOperatorInfoObjects();
393
Arman Uguray0a3e2792013-01-17 16:31:50 -0800394 capability_->activation_state_ =
395 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700396 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
397 .WillRepeatedly(Return(false));
Arman Uguray0a3e2792013-01-17 16:31:50 -0800398 EXPECT_FALSE(capability_->IsServiceActivationRequired());
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700399 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
400
401 capability_->activation_state_ =
402 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
403 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
404 .WillRepeatedly(Return(true));
405 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
406 .WillRepeatedly(ReturnRef(empty_list));
407 EXPECT_FALSE(capability_->IsServiceActivationRequired());
408 Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
409
410 // These expectations hold for all subsequent tests.
411 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
412 .WillRepeatedly(Return(true));
413 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
414 .WillRepeatedly(ReturnRef(olp_list));
415
416 capability_->activation_state_ =
417 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800418 EXPECT_TRUE(capability_->IsServiceActivationRequired());
419 capability_->activation_state_ =
420 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
421 EXPECT_FALSE(capability_->IsServiceActivationRequired());
422 capability_->activation_state_ =
423 MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
424 EXPECT_FALSE(capability_->IsServiceActivationRequired());
425}
426
427TEST_F(CellularCapabilityUniversalCDMAMainTest,
428 UpdateServiceActivationStateProperty) {
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700429 const vector<MobileOperatorInfo::OnlinePortal> olp_list {
430 {"some@url", "some_method", "some_post_data"}
431 };
432 SetMockMobileOperatorInfoObjects();
433 EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
434 .WillRepeatedly(Return(true));
435 EXPECT_CALL(*mock_serving_operator_info_, olp_list())
436 .WillRepeatedly(ReturnRef(olp_list));
437
Arman Uguray0a3e2792013-01-17 16:31:50 -0800438 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Ben Chan7ea768e2013-09-20 15:08:40 -0700439 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800440 .WillOnce(Return(PendingActivationStore::kStatePending))
441 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
442
Ben Chan7ea768e2013-09-20 15:08:40 -0700443 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
444 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800445 .Times(1);
446 capability_->UpdateServiceActivationStateProperty();
447 Mock::VerifyAndClearExpectations(service_);
448
Ben Chan7ea768e2013-09-20 15:08:40 -0700449 EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800450 .Times(1);
451 capability_->UpdateServiceActivationStateProperty();
452 Mock::VerifyAndClearExpectations(service_);
453
Ben Chan7ea768e2013-09-20 15:08:40 -0700454 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
455 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivating))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800456 .Times(1);
457 capability_->UpdateServiceActivationStateProperty();
458 Mock::VerifyAndClearExpectations(service_);
459
Ben Chan7ea768e2013-09-20 15:08:40 -0700460 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
461 EXPECT_CALL(*service_, SetActivationState(kActivationStateActivated))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800462 .Times(1);
463 capability_->UpdateServiceActivationStateProperty();
464 Mock::VerifyAndClearExpectations(service_);
Ben Chan7ea768e2013-09-20 15:08:40 -0700465 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800466}
467
468TEST_F(CellularCapabilityUniversalCDMAMainTest, IsActivating) {
469 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700470 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800471 .WillOnce(Return(PendingActivationStore::kStatePending))
472 .WillOnce(Return(PendingActivationStore::kStatePending))
473 .WillOnce(Return(PendingActivationStore::kStateFailureRetry))
474 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
475
476 capability_->activation_state_ =
477 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
478 EXPECT_TRUE(capability_->IsActivating());
479 EXPECT_TRUE(capability_->IsActivating());
480 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
481 EXPECT_TRUE(capability_->IsActivating());
482 EXPECT_TRUE(capability_->IsActivating());
483 capability_->activation_state_ =
484 MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
485 EXPECT_FALSE(capability_->IsActivating());
486}
487
Ben Chanb2c4a802013-11-14 12:47:52 -0800488TEST_F(CellularCapabilityUniversalCDMAMainTest, IsRegistered) {
489 capability_->cdma_1x_registration_state_ =
490 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
491 capability_->cdma_evdo_registration_state_ =
492 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
493 EXPECT_FALSE(capability_->IsRegistered());
494
495 capability_->cdma_evdo_registration_state_ =
496 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
497 EXPECT_TRUE(capability_->IsRegistered());
498
499 capability_->cdma_evdo_registration_state_ =
500 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
501 EXPECT_TRUE(capability_->IsRegistered());
502
503 capability_->cdma_evdo_registration_state_ =
504 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
505 EXPECT_TRUE(capability_->IsRegistered());
506
507 capability_->cdma_1x_registration_state_ =
508 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
509 capability_->cdma_evdo_registration_state_ =
510 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
511 EXPECT_TRUE(capability_->IsRegistered());
512
513 capability_->cdma_evdo_registration_state_ =
514 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
515 EXPECT_TRUE(capability_->IsRegistered());
516
517 capability_->cdma_evdo_registration_state_ =
518 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
519 EXPECT_TRUE(capability_->IsRegistered());
520
521 capability_->cdma_evdo_registration_state_ =
522 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
523 EXPECT_TRUE(capability_->IsRegistered());
524
525 capability_->cdma_1x_registration_state_ =
526 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
527 capability_->cdma_evdo_registration_state_ =
528 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
529 EXPECT_TRUE(capability_->IsRegistered());
530
531 capability_->cdma_evdo_registration_state_ =
532 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
533 EXPECT_TRUE(capability_->IsRegistered());
534
535 capability_->cdma_evdo_registration_state_ =
536 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
537 EXPECT_TRUE(capability_->IsRegistered());
538
539 capability_->cdma_evdo_registration_state_ =
540 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
541 EXPECT_TRUE(capability_->IsRegistered());
542
543 capability_->cdma_1x_registration_state_ =
544 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
545 capability_->cdma_evdo_registration_state_ =
546 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
547 EXPECT_TRUE(capability_->IsRegistered());
548
549 capability_->cdma_evdo_registration_state_ =
550 MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
551 EXPECT_TRUE(capability_->IsRegistered());
552
553 capability_->cdma_evdo_registration_state_ =
554 MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
555 EXPECT_TRUE(capability_->IsRegistered());
556
557 capability_->cdma_evdo_registration_state_ =
558 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
559 EXPECT_TRUE(capability_->IsRegistered());
560}
561
Arman Ugurayc9673062013-05-13 21:21:53 -0700562TEST_F(CellularCapabilityUniversalCDMAMainTest, SetupConnectProperties) {
563 DBusPropertiesMap map;
564 capability_->SetupConnectProperties(&map);
565 EXPECT_EQ(1, map.size());
566 EXPECT_STREQ("#777", map["number"].reader().get_string());
567}
568
Arman Uguray0a3e2792013-01-17 16:31:50 -0800569TEST_F(CellularCapabilityUniversalCDMADispatcherTest,
570 UpdatePendingActivationState) {
571 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED;
Alex Vakulenko8a532292014-06-16 17:18:44 -0700572 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800573 .Times(1);
574 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700575 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800576 .Times(0);
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_ACTIVATING;
Alex Vakulenko8a532292014-06-16 17:18:44 -0700583 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800584 .Times(0);
585 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700586 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800587 .Times(2)
588 .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));
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 capability_->activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
Alex Vakulenko8a532292014-06-16 17:18:44 -0700595 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800596 .Times(0);
597 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700598 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800599 .Times(2)
600 .WillRepeatedly(Return(PendingActivationStore::kStatePending));
601 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
602 capability_->UpdatePendingActivationState();
603 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
604 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
605
Alex Vakulenko8a532292014-06-16 17:18:44 -0700606 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800607 .Times(0);
608 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700609 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800610 .Times(2)
611 .WillRepeatedly(Return(PendingActivationStore::kStateFailureRetry));
612 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(1);
613 capability_->UpdatePendingActivationState();
614 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
615 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
616
Alex Vakulenko8a532292014-06-16 17:18:44 -0700617 EXPECT_CALL(*modem_info_.mock_pending_activation_store(), RemoveEntry(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800618 .Times(0);
619 EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
Alex Vakulenko8a532292014-06-16 17:18:44 -0700620 GetActivationState(_, _))
Arman Uguray0a3e2792013-01-17 16:31:50 -0800621 .Times(4)
622 .WillOnce(Return(PendingActivationStore::kStateActivated))
623 .WillOnce(Return(PendingActivationStore::kStateActivated))
624 .WillOnce(Return(PendingActivationStore::kStateUnknown))
625 .WillOnce(Return(PendingActivationStore::kStateUnknown));
626 EXPECT_CALL(*modem_info_.mock_dispatcher(), PostTask(_)).Times(0);
627 capability_->UpdatePendingActivationState();
628 capability_->UpdatePendingActivationState();
629 Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
630 Mock::VerifyAndClearExpectations(modem_info_.mock_dispatcher());
631}
632
Arman Uguray72fab6a2013-01-10 19:32:42 -0800633} // namespace shill