blob: b6115c0fa742ceb74ddf5b3f7d20703f0c8e66b4 [file] [log] [blame]
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05001// Copyright (c) 2012 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_gsm.h"
6
Eric Shienbrood9a245532012-03-07 14:20:39 -05007#include <base/bind.h>
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05008#include <chromeos/dbus/service_constants.h>
9#include <gtest/gtest.h>
10#include <mm/mm-modem.h>
11#include <mobile_provider.h>
12
13#include "shill/cellular.h"
14#include "shill/cellular_service.h"
15#include "shill/error.h"
16#include "shill/event_dispatcher.h"
17#include "shill/mock_adaptors.h"
18#include "shill/mock_modem_cdma_proxy.h"
Darin Petkovc37a9c42012-09-06 15:28:22 +020019#include "shill/mock_modem_gobi_proxy.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050020#include "shill/mock_modem_gsm_card_proxy.h"
21#include "shill/mock_modem_gsm_network_proxy.h"
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070022#include "shill/mock_modem_info.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050023#include "shill/mock_modem_proxy.h"
24#include "shill/mock_modem_simple_proxy.h"
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040025#include "shill/mock_profile.h"
Eric Shienbrood9a245532012-03-07 14:20:39 -050026#include "shill/mock_rtnl_handler.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050027#include "shill/proxy_factory.h"
28
Eric Shienbrood9a245532012-03-07 14:20:39 -050029using base::Bind;
30using base::Unretained;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050031using std::string;
Darin Petkov9c1dcef2012-02-07 15:58:26 +010032using testing::InSequence;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050033using testing::NiceMock;
Eric Shienbrood9a245532012-03-07 14:20:39 -050034using testing::_;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050035
36namespace shill {
37
Eric Shienbrood9a245532012-03-07 14:20:39 -050038MATCHER(IsSuccess, "") {
39 return arg.IsSuccess();
40}
41MATCHER(IsFailure, "") {
42 return arg.IsFailure();
43}
44
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050045class CellularCapabilityTest : public testing::Test {
46 public:
47 CellularCapabilityTest()
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070048 : modem_info_(NULL, &dispatcher_, NULL, NULL, NULL),
Ben Chan3ecdf822012-08-06 12:29:23 -070049 create_gsm_card_proxy_from_factory_(false),
50 proxy_(new MockModemProxy()),
51 simple_proxy_(new MockModemSimpleProxy()),
52 cdma_proxy_(new MockModemCDMAProxy()),
53 gsm_card_proxy_(new MockModemGSMCardProxy()),
54 gsm_network_proxy_(new MockModemGSMNetworkProxy()),
Darin Petkovc37a9c42012-09-06 15:28:22 +020055 gobi_proxy_(new MockModemGobiProxy()),
Ben Chan3ecdf822012-08-06 12:29:23 -070056 proxy_factory_(this),
57 capability_(NULL),
58 device_adaptor_(NULL),
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070059 cellular_(new Cellular(&modem_info_,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050060 "",
61 "",
62 0,
63 Cellular::kTypeGSM,
64 "",
65 "",
Jason Glasgowa585fc32012-06-06 11:04:09 -040066 "",
Thieu Lece4483e2013-01-23 15:12:03 -080067 &proxy_factory_)) {
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070068 modem_info_.metrics()->RegisterDevice(cellular_->interface_index(),
Thieu Lece4483e2013-01-23 15:12:03 -080069 Technology::kCellular);
70 }
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050071
72 virtual ~CellularCapabilityTest() {
73 cellular_->service_ = NULL;
74 capability_ = NULL;
75 device_adaptor_ = NULL;
76 }
77
78 virtual void SetUp() {
Eric Shienbrood9a245532012-03-07 14:20:39 -050079 static_cast<Device *>(cellular_)->rtnl_handler_ = &rtnl_handler_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040080
81 capability_ = dynamic_cast<CellularCapabilityClassic *>(
82 cellular_->capability_.get());
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050083 device_adaptor_ =
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070084 dynamic_cast<DeviceMockAdaptor*>(cellular_->adaptor());
85 ASSERT_TRUE(device_adaptor_ != NULL);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050086 }
87
88 virtual void TearDown() {
89 capability_->proxy_factory_ = NULL;
90 }
91
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040092 void SetService() {
Prathmesh Prabhu0d36b4f2013-04-01 11:45:54 -070093 cellular_->service_ = new CellularService(&modem_info_, cellular_);
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070094 }
95
96 void InitProviderDB() {
97 modem_info_.SetProviderDB(kTestMobileProviderDBPath);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040098 }
99
100 CellularCapabilityGSM *GetGsmCapability() {
101 return dynamic_cast<CellularCapabilityGSM *>(cellular_->capability_.get());
102 }
103
Thieu Le3d275392012-07-20 15:32:58 -0700104 void ReleaseCapabilityProxies() {
105 capability_->ReleaseProxies();
106 }
107
Eric Shienbrood9a245532012-03-07 14:20:39 -0500108 void InvokeEnable(bool enable, Error *error,
109 const ResultCallback &callback, int timeout) {
110 callback.Run(Error());
111 }
112 void InvokeEnableFail(bool enable, Error *error,
113 const ResultCallback &callback, int timeout) {
114 callback.Run(Error(Error::kOperationFailed));
115 }
116 void InvokeDisconnect(Error *error, const ResultCallback &callback,
117 int timeout) {
118 callback.Run(Error());
119 }
Thieu Le923006b2012-04-05 16:32:58 -0700120 void InvokeDisconnectFail(Error *error, const ResultCallback &callback,
121 int timeout) {
122 callback.Run(Error(Error::kOperationFailed));
123 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500124 void InvokeGetModemStatus(Error *error,
125 const DBusPropertyMapCallback &callback,
126 int timeout) {
127 DBusPropertiesMap props;
128 props["carrier"].writer().append_string(kTestCarrier);
129 props["unknown-property"].writer().append_string("irrelevant-value");
130 callback.Run(props, Error());
131 }
132 void InvokeGetModemInfo(Error *error, const ModemInfoCallback &callback,
133 int timeout) {
134 ModemHardwareInfo info;
135 info._1 = kManufacturer;
136 info._2 = kModelID;
137 info._3 = kHWRev;
138 callback.Run(info, Error());
139 }
Darin Petkovc37a9c42012-09-06 15:28:22 +0200140 void InvokeSetCarrier(const string &carrier, Error *error,
141 const ResultCallback &callback, int timeout) {
142 callback.Run(Error());
143 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500144
145 MOCK_METHOD1(TestCallback, void(const Error &error));
146
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500147 protected:
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400148 static const char kTestMobileProviderDBPath[];
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500149 static const char kTestCarrier[];
Eric Shienbrood9a245532012-03-07 14:20:39 -0500150 static const char kManufacturer[];
151 static const char kModelID[];
152 static const char kHWRev[];
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500153
154 class TestProxyFactory : public ProxyFactory {
155 public:
156 explicit TestProxyFactory(CellularCapabilityTest *test) : test_(test) {}
157
158 virtual ModemProxyInterface *CreateModemProxy(
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500159 const string &/*path*/,
160 const string &/*service*/) {
161 return test_->proxy_.release();
162 }
163
164 virtual ModemSimpleProxyInterface *CreateModemSimpleProxy(
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500165 const string &/*path*/,
166 const string &/*service*/) {
167 return test_->simple_proxy_.release();
168 }
169
170 virtual ModemCDMAProxyInterface *CreateModemCDMAProxy(
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500171 const string &/*path*/,
172 const string &/*service*/) {
173 return test_->cdma_proxy_.release();
174 }
175
176 virtual ModemGSMCardProxyInterface *CreateModemGSMCardProxy(
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500177 const string &/*path*/,
178 const string &/*service*/) {
Ben Chan3ecdf822012-08-06 12:29:23 -0700179 // TODO(benchan): This code conditionally returns a NULL pointer to avoid
180 // CellularCapabilityGSM::InitProperties (and thus
181 // CellularCapabilityGSM::GetIMSI) from being called during the
182 // construction. Remove this workaround after refactoring the tests.
183 return test_->create_gsm_card_proxy_from_factory_ ?
184 test_->gsm_card_proxy_.release() : NULL;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500185 }
186
187 virtual ModemGSMNetworkProxyInterface *CreateModemGSMNetworkProxy(
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500188 const string &/*path*/,
189 const string &/*service*/) {
190 return test_->gsm_network_proxy_.release();
191 }
192
Darin Petkovc37a9c42012-09-06 15:28:22 +0200193 virtual ModemGobiProxyInterface *CreateModemGobiProxy(
194 const string &/*path*/,
195 const string &/*service*/) {
196 return test_->gobi_proxy_.release();
197 }
198
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500199 private:
200 CellularCapabilityTest *test_;
201 };
202
203 void SetProxy() {
204 capability_->proxy_.reset(proxy_.release());
205 }
206
207 void SetSimpleProxy() {
208 capability_->simple_proxy_.reset(simple_proxy_.release());
209 }
210
Eric Shienbrood9a245532012-03-07 14:20:39 -0500211 void SetGSMNetworkProxy() {
212 CellularCapabilityGSM *gsm_capability =
213 dynamic_cast<CellularCapabilityGSM *>(cellular_->capability_.get());
214 gsm_capability->network_proxy_.reset(gsm_network_proxy_.release());
215 }
216
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500217 void SetCellularType(Cellular::Type type) {
Ben Chan3ecdf822012-08-06 12:29:23 -0700218 cellular_->InitCapability(type);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400219 capability_ = dynamic_cast<CellularCapabilityClassic *>(
220 cellular_->capability_.get());
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500221 }
222
Ben Chan3ecdf822012-08-06 12:29:23 -0700223 void AllowCreateGSMCardProxyFromFactory() {
224 create_gsm_card_proxy_from_factory_ = true;
225 }
226
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500227 EventDispatcher dispatcher_;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700228 MockModemInfo modem_info_;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500229 MockRTNLHandler rtnl_handler_;
Ben Chan3ecdf822012-08-06 12:29:23 -0700230 bool create_gsm_card_proxy_from_factory_;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500231 scoped_ptr<MockModemProxy> proxy_;
232 scoped_ptr<MockModemSimpleProxy> simple_proxy_;
233 scoped_ptr<MockModemCDMAProxy> cdma_proxy_;
234 scoped_ptr<MockModemGSMCardProxy> gsm_card_proxy_;
235 scoped_ptr<MockModemGSMNetworkProxy> gsm_network_proxy_;
Darin Petkovc37a9c42012-09-06 15:28:22 +0200236 scoped_ptr<MockModemGobiProxy> gobi_proxy_;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500237 TestProxyFactory proxy_factory_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400238 CellularCapabilityClassic *capability_; // Owned by |cellular_|.
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700239 DeviceMockAdaptor *device_adaptor_; // Owned by |cellular_|.
Ben Chan3ecdf822012-08-06 12:29:23 -0700240 CellularRefPtr cellular_;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500241};
242
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400243const char CellularCapabilityTest::kTestMobileProviderDBPath[] =
244 "provider_db_unittest.bfd";
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500245const char CellularCapabilityTest::kTestCarrier[] = "The Cellular Carrier";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500246const char CellularCapabilityTest::kManufacturer[] = "Company";
247const char CellularCapabilityTest::kModelID[] = "Gobi 2000";
248const char CellularCapabilityTest::kHWRev[] = "A00B1234";
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500249
250TEST_F(CellularCapabilityTest, GetModemStatus) {
251 SetCellularType(Cellular::kTypeCDMA);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500252 EXPECT_CALL(*simple_proxy_,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500253 GetModemStatus(_, _, CellularCapability::kTimeoutDefault)).
254 WillOnce(Invoke(this, &CellularCapabilityTest::InvokeGetModemStatus));
255 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500256 SetSimpleProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500257 ResultCallback callback =
258 Bind(&CellularCapabilityTest::TestCallback, Unretained(this));
259 capability_->GetModemStatus(callback);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500260 EXPECT_EQ(kTestCarrier, capability_->carrier_);
261 EXPECT_EQ(kTestCarrier, cellular_->home_provider_.GetName());
262}
263
264TEST_F(CellularCapabilityTest, GetModemInfo) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500265 EXPECT_CALL(*proxy_, GetModemInfo(_, _, CellularCapability::kTimeoutDefault))
266 .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeGetModemInfo));
267 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500268 SetProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500269 ResultCallback callback =
270 Bind(&CellularCapabilityTest::TestCallback, Unretained(this));
271 capability_->GetModemInfo(callback);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500272 EXPECT_EQ(kManufacturer, capability_->manufacturer_);
273 EXPECT_EQ(kModelID, capability_->model_id_);
274 EXPECT_EQ(kHWRev, capability_->hardware_revision_);
275}
276
277TEST_F(CellularCapabilityTest, EnableModemSucceed) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500278 EXPECT_CALL(*proxy_, Enable(true, _, _, CellularCapability::kTimeoutEnable))
279 .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeEnable));
280 EXPECT_CALL(*this, TestCallback(IsSuccess()));
281 ResultCallback callback =
282 Bind(&CellularCapabilityTest::TestCallback, Unretained(this));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500283 SetProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500284 capability_->EnableModem(callback);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500285}
286
287TEST_F(CellularCapabilityTest, EnableModemFail) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500288 EXPECT_CALL(*proxy_, Enable(true, _, _, CellularCapability::kTimeoutEnable))
289 .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeEnableFail));
290 EXPECT_CALL(*this, TestCallback(IsFailure()));
291 ResultCallback callback =
292 Bind(&CellularCapabilityTest::TestCallback, Unretained(this));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500293 SetProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500294 capability_->EnableModem(callback);
295}
296
297TEST_F(CellularCapabilityTest, FinishEnable) {
298 EXPECT_CALL(*gsm_network_proxy_,
299 GetRegistrationInfo(NULL, _,
300 CellularCapability::kTimeoutDefault));
301 EXPECT_CALL(*gsm_network_proxy_,
302 GetSignalQuality(NULL, _, CellularCapability::kTimeoutDefault));
303 EXPECT_CALL(*this, TestCallback(IsSuccess()));
304 SetGSMNetworkProxy();
305 capability_->FinishEnable(
306 Bind(&CellularCapabilityTest::TestCallback, Unretained(this)));
307}
308
309TEST_F(CellularCapabilityTest, UnsupportedOperation) {
310 Error error;
311 EXPECT_CALL(*this, TestCallback(IsSuccess())).Times(0);
312 capability_->CellularCapability::Scan(&error,
313 Bind(&CellularCapabilityTest::TestCallback, Unretained(this)));
314 EXPECT_TRUE(error.IsFailure());
315 EXPECT_EQ(Error::kNotSupported, error.type());
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500316}
317
Darin Petkov9c1dcef2012-02-07 15:58:26 +0100318TEST_F(CellularCapabilityTest, AllowRoaming) {
Jason Glasgow7b461df2012-05-01 16:38:45 -0400319 EXPECT_FALSE(cellular_->GetAllowRoaming(NULL));
320 cellular_->SetAllowRoaming(false, NULL);
321 EXPECT_FALSE(cellular_->GetAllowRoaming(NULL));
Darin Petkov9c1dcef2012-02-07 15:58:26 +0100322
323 {
324 InSequence seq;
325 EXPECT_CALL(*device_adaptor_, EmitBoolChanged(
326 flimflam::kCellularAllowRoamingProperty, true));
327 EXPECT_CALL(*device_adaptor_, EmitBoolChanged(
328 flimflam::kCellularAllowRoamingProperty, false));
329 }
330
331 cellular_->state_ = Cellular::kStateConnected;
332 dynamic_cast<CellularCapabilityGSM *>(capability_)->registration_state_ =
333 MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING;
Jason Glasgow7b461df2012-05-01 16:38:45 -0400334 cellular_->SetAllowRoaming(true, NULL);
335 EXPECT_TRUE(cellular_->GetAllowRoaming(NULL));
Darin Petkov9c1dcef2012-02-07 15:58:26 +0100336 EXPECT_EQ(Cellular::kStateConnected, cellular_->state_);
337
Thieu Le049adb52012-11-12 17:14:51 -0800338 EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDisconnect))
Eric Shienbrood9a245532012-03-07 14:20:39 -0500339 .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeDisconnect));
Darin Petkov9c1dcef2012-02-07 15:58:26 +0100340 SetProxy();
341 cellular_->state_ = Cellular::kStateConnected;
Jason Glasgow7b461df2012-05-01 16:38:45 -0400342 cellular_->SetAllowRoaming(false, NULL);
343 EXPECT_FALSE(cellular_->GetAllowRoaming(NULL));
Darin Petkov9c1dcef2012-02-07 15:58:26 +0100344 EXPECT_EQ(Cellular::kStateRegistered, cellular_->state_);
345}
346
Darin Petkovc37a9c42012-09-06 15:28:22 +0200347TEST_F(CellularCapabilityTest, SetCarrier) {
348 static const char kCarrier[] = "Generic UMTS";
349 EXPECT_CALL(
350 *gobi_proxy_,
351 SetCarrier(kCarrier, _, _,
352 CellularCapabilityClassic::kTimeoutSetCarrierMilliseconds))
353 .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeSetCarrier));
354 EXPECT_CALL(*this, TestCallback(IsSuccess()));
355 Error error;
356 capability_->SetCarrier(kCarrier, &error,
357 Bind(&CellularCapabilityTest::TestCallback,
358 Unretained(this)));
359 EXPECT_TRUE(error.IsSuccess());
360}
361
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400362MATCHER_P(HasApn, apn, "") {
363 DBusPropertiesMap::const_iterator it = arg.find(flimflam::kApnProperty);
364 return it != arg.end() && apn == it->second.reader().get_string();
365}
366
367MATCHER(HasNoApn, "") {
368 return arg.find(flimflam::kApnProperty) == arg.end();
369}
370
371TEST_F(CellularCapabilityTest, TryApns) {
372 static const string kLastGoodApn("remembered.apn");
373 static const string kSuppliedApn("my.apn");
374 static const string kTmobileApn1("epc.tmobile.com");
375 static const string kTmobileApn2("wap.voicestream.com");
376 static const string kTmobileApn3("internet2.voicestream.com");
377 static const string kTmobileApn4("internet3.voicestream.com");
378
379 using testing::InSequence;
380 {
381 InSequence dummy;
382 EXPECT_CALL(*simple_proxy_, Connect(HasApn(kLastGoodApn), _, _, _));
383 EXPECT_CALL(*simple_proxy_, Connect(HasApn(kSuppliedApn), _, _, _));
384 EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn1), _, _, _));
385 EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn2), _, _, _));
386 EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn3), _, _, _));
387 EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn4), _, _, _));
388 EXPECT_CALL(*simple_proxy_, Connect(HasNoApn(), _, _, _));
389 }
390 CellularCapabilityGSM *gsm_capability = GetGsmCapability();
391 SetService();
392 gsm_capability->imsi_ = "310240123456789";
393 InitProviderDB();
394 gsm_capability->SetHomeProvider();
395 ProfileRefPtr profile(new NiceMock<MockProfile>(
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700396 modem_info_.control_interface(), modem_info_.metrics(),
397 modem_info_.manager()));
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400398 cellular_->service()->set_profile(profile);
399
400 Error error;
401 Stringmap apn_info;
402 DBusPropertiesMap props;
403 apn_info[flimflam::kApnProperty] = kSuppliedApn;
404 cellular_->service()->SetApn(apn_info, &error);
405
406 apn_info.clear();
407 apn_info[flimflam::kApnProperty] = kLastGoodApn;
408 cellular_->service()->SetLastGoodApn(apn_info);
409
410 capability_->SetupConnectProperties(&props);
411 // We expect the list to contain the last good APN, plus
412 // the user-supplied APN, plus the 4 APNs from the mobile
413 // provider info database.
414 EXPECT_EQ(6, gsm_capability->apn_try_list_.size());
415 EXPECT_FALSE(props.find(flimflam::kApnProperty) == props.end());
416 EXPECT_EQ(kLastGoodApn, props[flimflam::kApnProperty].reader().get_string());
417
418 SetSimpleProxy();
419 capability_->Connect(props, &error, ResultCallback());
420 Error cerror(Error::kInvalidApn);
Nathan Williamsb54974f2012-04-19 11:16:30 -0400421 gsm_capability->OnConnectReply(ResultCallback(), cerror);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400422 EXPECT_EQ(5, gsm_capability->apn_try_list_.size());
Nathan Williamsb54974f2012-04-19 11:16:30 -0400423 gsm_capability->OnConnectReply(ResultCallback(), cerror);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400424 EXPECT_EQ(4, gsm_capability->apn_try_list_.size());
Nathan Williamsb54974f2012-04-19 11:16:30 -0400425 gsm_capability->OnConnectReply(ResultCallback(), cerror);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400426 EXPECT_EQ(3, gsm_capability->apn_try_list_.size());
Nathan Williamsb54974f2012-04-19 11:16:30 -0400427 gsm_capability->OnConnectReply(ResultCallback(), cerror);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400428 EXPECT_EQ(2, gsm_capability->apn_try_list_.size());
Nathan Williamsb54974f2012-04-19 11:16:30 -0400429 gsm_capability->OnConnectReply(ResultCallback(), cerror);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400430 EXPECT_EQ(1, gsm_capability->apn_try_list_.size());
Nathan Williamsb54974f2012-04-19 11:16:30 -0400431 gsm_capability->OnConnectReply(ResultCallback(), cerror);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400432 EXPECT_EQ(0, gsm_capability->apn_try_list_.size());
433}
434
Thieu Le923006b2012-04-05 16:32:58 -0700435TEST_F(CellularCapabilityTest, StopModemDisconnectSuccess) {
Thieu Le049adb52012-11-12 17:14:51 -0800436 EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDisconnect))
Thieu Le923006b2012-04-05 16:32:58 -0700437 .WillOnce(Invoke(this,
438 &CellularCapabilityTest::InvokeDisconnect));
Thieu Lec8d2d962012-05-15 14:31:18 -0700439 EXPECT_CALL(*proxy_, Enable(_, _, _, CellularCapability::kTimeoutEnable))
Thieu Le923006b2012-04-05 16:32:58 -0700440 .WillOnce(Invoke(this,
441 &CellularCapabilityTest::InvokeEnable));
442 EXPECT_CALL(*this, TestCallback(IsSuccess()));
443 SetProxy();
444
445 Error error;
446 capability_->StopModem(
447 &error, Bind(&CellularCapabilityTest::TestCallback, Unretained(this)));
448 dispatcher_.DispatchPendingEvents();
449}
450
451TEST_F(CellularCapabilityTest, StopModemDisconnectFail) {
Thieu Le049adb52012-11-12 17:14:51 -0800452 EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDisconnect))
Thieu Le923006b2012-04-05 16:32:58 -0700453 .WillOnce(Invoke(this,
454 &CellularCapabilityTest::InvokeDisconnectFail));
Thieu Lec8d2d962012-05-15 14:31:18 -0700455 EXPECT_CALL(*proxy_, Enable(_, _, _, CellularCapability::kTimeoutEnable))
Thieu Le923006b2012-04-05 16:32:58 -0700456 .WillOnce(Invoke(this,
457 &CellularCapabilityTest::InvokeEnable));
458 EXPECT_CALL(*this, TestCallback(IsSuccess()));
459 SetProxy();
460
461 Error error;
462 capability_->StopModem(
463 &error, Bind(&CellularCapabilityTest::TestCallback, Unretained(this)));
464 dispatcher_.DispatchPendingEvents();
465}
466
Thieu Le3d275392012-07-20 15:32:58 -0700467TEST_F(CellularCapabilityTest, DisconnectNoProxy) {
468 Error error;
469 ResultCallback disconnect_callback;
Thieu Le049adb52012-11-12 17:14:51 -0800470 EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDisconnect))
Thieu Le3d275392012-07-20 15:32:58 -0700471 .Times(0);
472 ReleaseCapabilityProxies();
473 capability_->Disconnect(&error, disconnect_callback);
474}
475
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500476} // namespace shill