blob: f0a2ab6e0c0a79975f4b2d5369b11bb6e17f8f1f [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"
Eric Shienbrood9a245532012-03-07 14:20:39 -050018#include "shill/mock_glib.h"
19#include "shill/mock_manager.h"
20#include "shill/mock_metrics.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050021#include "shill/mock_modem_cdma_proxy.h"
22#include "shill/mock_modem_gsm_card_proxy.h"
23#include "shill/mock_modem_gsm_network_proxy.h"
24#include "shill/mock_modem_proxy.h"
25#include "shill/mock_modem_simple_proxy.h"
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040026#include "shill/mock_profile.h"
Eric Shienbrood9a245532012-03-07 14:20:39 -050027#include "shill/mock_rtnl_handler.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050028#include "shill/nice_mock_control.h"
29#include "shill/proxy_factory.h"
30
Eric Shienbrood9a245532012-03-07 14:20:39 -050031using base::Bind;
32using base::Unretained;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050033using std::string;
Darin Petkov9c1dcef2012-02-07 15:58:26 +010034using testing::InSequence;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050035using testing::NiceMock;
Eric Shienbrood9a245532012-03-07 14:20:39 -050036using testing::_;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050037
38namespace shill {
39
Eric Shienbrood9a245532012-03-07 14:20:39 -050040MATCHER(IsSuccess, "") {
41 return arg.IsSuccess();
42}
43MATCHER(IsFailure, "") {
44 return arg.IsFailure();
45}
46
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050047class CellularCapabilityTest : public testing::Test {
48 public:
49 CellularCapabilityTest()
Eric Shienbrood9a245532012-03-07 14:20:39 -050050 : manager_(&control_, &dispatcher_, &metrics_, &glib_),
Ben Chan3ecdf822012-08-06 12:29:23 -070051 create_gsm_card_proxy_from_factory_(false),
52 proxy_(new MockModemProxy()),
53 simple_proxy_(new MockModemSimpleProxy()),
54 cdma_proxy_(new MockModemCDMAProxy()),
55 gsm_card_proxy_(new MockModemGSMCardProxy()),
56 gsm_network_proxy_(new MockModemGSMNetworkProxy()),
57 proxy_factory_(this),
58 capability_(NULL),
59 device_adaptor_(NULL),
60 provider_db_(NULL),
Eric Shienbrood9a245532012-03-07 14:20:39 -050061 cellular_(new Cellular(&control_,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050062 &dispatcher_,
63 NULL,
Eric Shienbrood9a245532012-03-07 14:20:39 -050064 &manager_,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050065 "",
66 "",
67 0,
68 Cellular::kTypeGSM,
69 "",
70 "",
Jason Glasgowa585fc32012-06-06 11:04:09 -040071 "",
Ben Chan3ecdf822012-08-06 12:29:23 -070072 NULL,
73 &proxy_factory_)) {}
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050074
75 virtual ~CellularCapabilityTest() {
76 cellular_->service_ = NULL;
77 capability_ = NULL;
78 device_adaptor_ = NULL;
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040079 mobile_provider_close_db(provider_db_);
80 provider_db_ = NULL;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050081 }
82
83 virtual void SetUp() {
Eric Shienbrood9a245532012-03-07 14:20:39 -050084 static_cast<Device *>(cellular_)->rtnl_handler_ = &rtnl_handler_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040085
86 capability_ = dynamic_cast<CellularCapabilityClassic *>(
87 cellular_->capability_.get());
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050088 device_adaptor_ =
89 dynamic_cast<NiceMock<DeviceMockAdaptor> *>(cellular_->adaptor());
90 }
91
92 virtual void TearDown() {
93 capability_->proxy_factory_ = NULL;
94 }
95
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040096 void InitProviderDB() {
97 provider_db_ = mobile_provider_open_db(kTestMobileProviderDBPath);
98 ASSERT_TRUE(provider_db_);
99 cellular_->provider_db_ = provider_db_;
100 }
101
102 void SetService() {
103 cellular_->service_ = new CellularService(
104 &control_, &dispatcher_, &metrics_, NULL, cellular_);
105 }
106
107 CellularCapabilityGSM *GetGsmCapability() {
108 return dynamic_cast<CellularCapabilityGSM *>(cellular_->capability_.get());
109 }
110
Thieu Le3d275392012-07-20 15:32:58 -0700111 void ReleaseCapabilityProxies() {
112 capability_->ReleaseProxies();
113 }
114
Eric Shienbrood9a245532012-03-07 14:20:39 -0500115 void InvokeEnable(bool enable, Error *error,
116 const ResultCallback &callback, int timeout) {
117 callback.Run(Error());
118 }
119 void InvokeEnableFail(bool enable, Error *error,
120 const ResultCallback &callback, int timeout) {
121 callback.Run(Error(Error::kOperationFailed));
122 }
123 void InvokeDisconnect(Error *error, const ResultCallback &callback,
124 int timeout) {
125 callback.Run(Error());
126 }
Thieu Le923006b2012-04-05 16:32:58 -0700127 void InvokeDisconnectFail(Error *error, const ResultCallback &callback,
128 int timeout) {
129 callback.Run(Error(Error::kOperationFailed));
130 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500131 void InvokeGetModemStatus(Error *error,
132 const DBusPropertyMapCallback &callback,
133 int timeout) {
134 DBusPropertiesMap props;
135 props["carrier"].writer().append_string(kTestCarrier);
136 props["unknown-property"].writer().append_string("irrelevant-value");
137 callback.Run(props, Error());
138 }
139 void InvokeGetModemInfo(Error *error, const ModemInfoCallback &callback,
140 int timeout) {
141 ModemHardwareInfo info;
142 info._1 = kManufacturer;
143 info._2 = kModelID;
144 info._3 = kHWRev;
145 callback.Run(info, Error());
146 }
147
148 MOCK_METHOD1(TestCallback, void(const Error &error));
149
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500150 protected:
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400151 static const char kTestMobileProviderDBPath[];
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500152 static const char kTestCarrier[];
Eric Shienbrood9a245532012-03-07 14:20:39 -0500153 static const char kManufacturer[];
154 static const char kModelID[];
155 static const char kHWRev[];
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500156
157 class TestProxyFactory : public ProxyFactory {
158 public:
159 explicit TestProxyFactory(CellularCapabilityTest *test) : test_(test) {}
160
161 virtual ModemProxyInterface *CreateModemProxy(
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500162 const string &/*path*/,
163 const string &/*service*/) {
164 return test_->proxy_.release();
165 }
166
167 virtual ModemSimpleProxyInterface *CreateModemSimpleProxy(
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500168 const string &/*path*/,
169 const string &/*service*/) {
170 return test_->simple_proxy_.release();
171 }
172
173 virtual ModemCDMAProxyInterface *CreateModemCDMAProxy(
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500174 const string &/*path*/,
175 const string &/*service*/) {
176 return test_->cdma_proxy_.release();
177 }
178
179 virtual ModemGSMCardProxyInterface *CreateModemGSMCardProxy(
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500180 const string &/*path*/,
181 const string &/*service*/) {
Ben Chan3ecdf822012-08-06 12:29:23 -0700182 // TODO(benchan): This code conditionally returns a NULL pointer to avoid
183 // CellularCapabilityGSM::InitProperties (and thus
184 // CellularCapabilityGSM::GetIMSI) from being called during the
185 // construction. Remove this workaround after refactoring the tests.
186 return test_->create_gsm_card_proxy_from_factory_ ?
187 test_->gsm_card_proxy_.release() : NULL;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500188 }
189
190 virtual ModemGSMNetworkProxyInterface *CreateModemGSMNetworkProxy(
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500191 const string &/*path*/,
192 const string &/*service*/) {
193 return test_->gsm_network_proxy_.release();
194 }
195
196 private:
197 CellularCapabilityTest *test_;
198 };
199
200 void SetProxy() {
201 capability_->proxy_.reset(proxy_.release());
202 }
203
204 void SetSimpleProxy() {
205 capability_->simple_proxy_.reset(simple_proxy_.release());
206 }
207
Eric Shienbrood9a245532012-03-07 14:20:39 -0500208 void SetGSMNetworkProxy() {
209 CellularCapabilityGSM *gsm_capability =
210 dynamic_cast<CellularCapabilityGSM *>(cellular_->capability_.get());
211 gsm_capability->network_proxy_.reset(gsm_network_proxy_.release());
212 }
213
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500214 void SetCellularType(Cellular::Type type) {
Ben Chan3ecdf822012-08-06 12:29:23 -0700215 cellular_->InitCapability(type);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400216 capability_ = dynamic_cast<CellularCapabilityClassic *>(
217 cellular_->capability_.get());
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500218 }
219
Ben Chan3ecdf822012-08-06 12:29:23 -0700220 void AllowCreateGSMCardProxyFromFactory() {
221 create_gsm_card_proxy_from_factory_ = true;
222 }
223
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500224 NiceMockControl control_;
225 EventDispatcher dispatcher_;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500226 MockMetrics metrics_;
227 MockGLib glib_;
228 MockManager manager_;
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_;
236 TestProxyFactory proxy_factory_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400237 CellularCapabilityClassic *capability_; // Owned by |cellular_|.
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500238 NiceMock<DeviceMockAdaptor> *device_adaptor_; // Owned by |cellular_|.
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400239 mobile_provider_db *provider_db_;
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
Eric Shienbrood9a245532012-03-07 14:20:39 -0500338 EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDefault))
339 .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
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400347MATCHER_P(HasApn, apn, "") {
348 DBusPropertiesMap::const_iterator it = arg.find(flimflam::kApnProperty);
349 return it != arg.end() && apn == it->second.reader().get_string();
350}
351
352MATCHER(HasNoApn, "") {
353 return arg.find(flimflam::kApnProperty) == arg.end();
354}
355
356TEST_F(CellularCapabilityTest, TryApns) {
357 static const string kLastGoodApn("remembered.apn");
358 static const string kSuppliedApn("my.apn");
359 static const string kTmobileApn1("epc.tmobile.com");
360 static const string kTmobileApn2("wap.voicestream.com");
361 static const string kTmobileApn3("internet2.voicestream.com");
362 static const string kTmobileApn4("internet3.voicestream.com");
363
364 using testing::InSequence;
365 {
366 InSequence dummy;
367 EXPECT_CALL(*simple_proxy_, Connect(HasApn(kLastGoodApn), _, _, _));
368 EXPECT_CALL(*simple_proxy_, Connect(HasApn(kSuppliedApn), _, _, _));
369 EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn1), _, _, _));
370 EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn2), _, _, _));
371 EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn3), _, _, _));
372 EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn4), _, _, _));
373 EXPECT_CALL(*simple_proxy_, Connect(HasNoApn(), _, _, _));
374 }
375 CellularCapabilityGSM *gsm_capability = GetGsmCapability();
376 SetService();
377 gsm_capability->imsi_ = "310240123456789";
378 InitProviderDB();
379 gsm_capability->SetHomeProvider();
380 ProfileRefPtr profile(new NiceMock<MockProfile>(
381 &control_, reinterpret_cast<Manager *>(NULL)));
382 cellular_->service()->set_profile(profile);
383
384 Error error;
385 Stringmap apn_info;
386 DBusPropertiesMap props;
387 apn_info[flimflam::kApnProperty] = kSuppliedApn;
388 cellular_->service()->SetApn(apn_info, &error);
389
390 apn_info.clear();
391 apn_info[flimflam::kApnProperty] = kLastGoodApn;
392 cellular_->service()->SetLastGoodApn(apn_info);
393
394 capability_->SetupConnectProperties(&props);
395 // We expect the list to contain the last good APN, plus
396 // the user-supplied APN, plus the 4 APNs from the mobile
397 // provider info database.
398 EXPECT_EQ(6, gsm_capability->apn_try_list_.size());
399 EXPECT_FALSE(props.find(flimflam::kApnProperty) == props.end());
400 EXPECT_EQ(kLastGoodApn, props[flimflam::kApnProperty].reader().get_string());
401
402 SetSimpleProxy();
403 capability_->Connect(props, &error, ResultCallback());
404 Error cerror(Error::kInvalidApn);
Nathan Williamsb54974f2012-04-19 11:16:30 -0400405 gsm_capability->OnConnectReply(ResultCallback(), cerror);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400406 EXPECT_EQ(5, gsm_capability->apn_try_list_.size());
Nathan Williamsb54974f2012-04-19 11:16:30 -0400407 gsm_capability->OnConnectReply(ResultCallback(), cerror);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400408 EXPECT_EQ(4, gsm_capability->apn_try_list_.size());
Nathan Williamsb54974f2012-04-19 11:16:30 -0400409 gsm_capability->OnConnectReply(ResultCallback(), cerror);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400410 EXPECT_EQ(3, gsm_capability->apn_try_list_.size());
Nathan Williamsb54974f2012-04-19 11:16:30 -0400411 gsm_capability->OnConnectReply(ResultCallback(), cerror);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400412 EXPECT_EQ(2, gsm_capability->apn_try_list_.size());
Nathan Williamsb54974f2012-04-19 11:16:30 -0400413 gsm_capability->OnConnectReply(ResultCallback(), cerror);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400414 EXPECT_EQ(1, gsm_capability->apn_try_list_.size());
Nathan Williamsb54974f2012-04-19 11:16:30 -0400415 gsm_capability->OnConnectReply(ResultCallback(), cerror);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400416 EXPECT_EQ(0, gsm_capability->apn_try_list_.size());
417}
418
Thieu Le923006b2012-04-05 16:32:58 -0700419TEST_F(CellularCapabilityTest, StopModemDisconnectSuccess) {
420 EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDefault))
421 .WillOnce(Invoke(this,
422 &CellularCapabilityTest::InvokeDisconnect));
Thieu Lec8d2d962012-05-15 14:31:18 -0700423 EXPECT_CALL(*proxy_, Enable(_, _, _, CellularCapability::kTimeoutEnable))
Thieu Le923006b2012-04-05 16:32:58 -0700424 .WillOnce(Invoke(this,
425 &CellularCapabilityTest::InvokeEnable));
426 EXPECT_CALL(*this, TestCallback(IsSuccess()));
427 SetProxy();
428
429 Error error;
430 capability_->StopModem(
431 &error, Bind(&CellularCapabilityTest::TestCallback, Unretained(this)));
432 dispatcher_.DispatchPendingEvents();
433}
434
435TEST_F(CellularCapabilityTest, StopModemDisconnectFail) {
436 EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDefault))
437 .WillOnce(Invoke(this,
438 &CellularCapabilityTest::InvokeDisconnectFail));
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
Thieu Le3d275392012-07-20 15:32:58 -0700451TEST_F(CellularCapabilityTest, DisconnectNoProxy) {
452 Error error;
453 ResultCallback disconnect_callback;
454 EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDefault))
455 .Times(0);
456 ReleaseCapabilityProxies();
457 capability_->Disconnect(&error, disconnect_callback);
458}
459
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500460} // namespace shill