Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 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.h" |
| 6 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 7 | #include <sys/socket.h> |
| 8 | #include <linux/if.h> |
| 9 | #include <linux/netlink.h> // Needs typedefs from sys/socket.h. |
| 10 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 11 | #include <base/bind.h> |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 12 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 13 | #include <mm/mm-modem.h> |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 14 | #include <mobile_provider.h> |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 15 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 16 | #include "shill/cellular_capability_cdma.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 17 | #include "shill/cellular_capability_classic.h" |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 18 | #include "shill/cellular_capability_gsm.h" |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 19 | #include "shill/cellular_service.h" |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 20 | #include "shill/error.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 21 | #include "shill/event_dispatcher.h" |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 22 | #include "shill/mock_cellular_service.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 23 | #include "shill/mock_device_info.h" |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 24 | #include "shill/mock_dhcp_config.h" |
| 25 | #include "shill/mock_dhcp_provider.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 26 | #include "shill/mock_manager.h" |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 27 | #include "shill/mock_metrics.h" |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 28 | #include "shill/mock_modem_cdma_proxy.h" |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 29 | #include "shill/mock_modem_gsm_card_proxy.h" |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 30 | #include "shill/mock_modem_gsm_network_proxy.h" |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 31 | #include "shill/mock_modem_proxy.h" |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 32 | #include "shill/mock_modem_simple_proxy.h" |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 33 | #include "shill/mock_rtnl_handler.h" |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 34 | #include "shill/nice_mock_control.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 35 | #include "shill/property_store_unittest.h" |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 36 | #include "shill/proxy_factory.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 37 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 38 | using base::Bind; |
| 39 | using base::Unretained; |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 40 | using std::map; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 41 | using std::string; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 42 | using std::vector; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 43 | using testing::_; |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 44 | using testing::AnyNumber; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 45 | using testing::Invoke; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 46 | using testing::NiceMock; |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 47 | using testing::Return; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 48 | using testing::SetArgumentPointee; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 49 | using testing::Unused; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 50 | |
| 51 | namespace shill { |
| 52 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 53 | MATCHER(IsSuccess, "") { |
| 54 | return arg.IsSuccess(); |
| 55 | } |
| 56 | |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 57 | MATCHER(IsFailure, "") { |
| 58 | return arg.IsFailure(); |
| 59 | } |
| 60 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 61 | class CellularPropertyTest : public PropertyStoreTest { |
| 62 | public: |
| 63 | CellularPropertyTest() |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 64 | : device_(new Cellular(control_interface(), |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 65 | NULL, |
| 66 | NULL, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 67 | NULL, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 68 | "usb0", |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 69 | "00:01:02:03:04:05", |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 70 | 3, |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 71 | Cellular::kTypeCDMA, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 72 | "", |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 73 | "", |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 74 | "", |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 75 | NULL, |
| 76 | ProxyFactory::GetInstance())) {} |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 77 | virtual ~CellularPropertyTest() {} |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 78 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 79 | protected: |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 80 | DeviceRefPtr device_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 83 | TEST_F(CellularPropertyTest, Contains) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 84 | EXPECT_TRUE(device_->store().Contains(flimflam::kNameProperty)); |
| 85 | EXPECT_FALSE(device_->store().Contains("")); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 86 | } |
| 87 | |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 88 | TEST_F(CellularPropertyTest, SetProperty) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 89 | { |
| 90 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 91 | EXPECT_TRUE(DBusAdaptor::SetProperty( |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 92 | device_->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 93 | flimflam::kCellularAllowRoamingProperty, |
| 94 | PropertyStoreTest::kBoolV, |
| 95 | &error)); |
| 96 | } |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 97 | // Ensure that attempting to write a R/O property returns InvalidArgs error. |
| 98 | { |
| 99 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 100 | EXPECT_FALSE(DBusAdaptor::SetProperty(device_->mutable_store(), |
| 101 | flimflam::kAddressProperty, |
| 102 | PropertyStoreTest::kStringV, |
| 103 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 104 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 105 | } |
| 106 | { |
| 107 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 108 | EXPECT_FALSE(DBusAdaptor::SetProperty(device_->mutable_store(), |
| 109 | flimflam::kCarrierProperty, |
| 110 | PropertyStoreTest::kStringV, |
| 111 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 112 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 113 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 116 | class CellularTest : public testing::Test { |
| 117 | public: |
| 118 | CellularTest() |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 119 | : manager_(&control_interface_, &dispatcher_, &metrics_, &glib_), |
| 120 | device_info_(&control_interface_, &dispatcher_, &metrics_, &manager_), |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 121 | dhcp_config_(new MockDHCPConfig(&control_interface_, |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 122 | kTestDeviceName)), |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 123 | create_gsm_card_proxy_from_factory_(false), |
| 124 | proxy_(new MockModemProxy()), |
| 125 | simple_proxy_(new MockModemSimpleProxy()), |
| 126 | cdma_proxy_(new MockModemCDMAProxy()), |
| 127 | gsm_card_proxy_(new MockModemGSMCardProxy()), |
| 128 | gsm_network_proxy_(new MockModemGSMNetworkProxy()), |
| 129 | proxy_factory_(this), |
| 130 | provider_db_(NULL), |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 131 | device_(new Cellular(&control_interface_, |
| 132 | &dispatcher_, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 133 | &metrics_, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 134 | &manager_, |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 135 | kTestDeviceName, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 136 | kTestDeviceAddress, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 137 | 3, |
| 138 | Cellular::kTypeGSM, |
| 139 | kDBusOwner, |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 140 | kDBusService, |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 141 | kDBusPath, |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 142 | NULL, |
| 143 | &proxy_factory_)) {} |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 144 | |
| 145 | virtual ~CellularTest() { |
| 146 | mobile_provider_close_db(provider_db_); |
| 147 | provider_db_ = NULL; |
| 148 | } |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 149 | |
| 150 | virtual void SetUp() { |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 151 | static_cast<Device *>(device_)->rtnl_handler_ = &rtnl_handler_; |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 152 | device_->set_dhcp_provider(&dhcp_provider_); |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 153 | EXPECT_CALL(manager_, device_info()).WillRepeatedly(Return(&device_info_)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 154 | EXPECT_CALL(manager_, DeregisterService(_)).Times(AnyNumber()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | virtual void TearDown() { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 158 | device_->DestroyIPConfig(); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 159 | device_->state_ = Cellular::kStateDisabled; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 160 | device_->capability_->ReleaseProxies(); |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 161 | device_->set_dhcp_provider(NULL); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 164 | void InvokeEnable(bool enable, Error *error, |
| 165 | const ResultCallback &callback, int timeout) { |
| 166 | callback.Run(Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 167 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 168 | void InvokeGetSignalQuality(Error *error, |
| 169 | const SignalQualityCallback &callback, |
| 170 | int timeout) { |
| 171 | callback.Run(kStrength, Error()); |
| 172 | } |
| 173 | void InvokeGetModemStatus(Error *error, |
| 174 | const DBusPropertyMapCallback &callback, |
| 175 | int timeout) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 176 | DBusPropertiesMap props; |
| 177 | props["carrier"].writer().append_string(kTestCarrier); |
| 178 | props["unknown-property"].writer().append_string("irrelevant-value"); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 179 | callback.Run(props, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 180 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 181 | void InvokeGetModemInfo(Error *error, const ModemInfoCallback &callback, |
| 182 | int timeout) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 183 | static const char kManufacturer[] = "Company"; |
| 184 | static const char kModelID[] = "Gobi 2000"; |
| 185 | static const char kHWRev[] = "A00B1234"; |
| 186 | ModemHardwareInfo info; |
| 187 | info._1 = kManufacturer; |
| 188 | info._2 = kModelID; |
| 189 | info._3 = kHWRev; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 190 | callback.Run(info, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 191 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 192 | void InvokeGetRegistrationState1X(Error *error, |
| 193 | const RegistrationStateCallback &callback, |
| 194 | int timeout) { |
| 195 | callback.Run(MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
| 196 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 197 | Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 198 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 199 | void InvokeGetIMEI(Error *error, const GSMIdentifierCallback &callback, |
| 200 | int timeout) { |
| 201 | callback.Run(kIMEI, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 202 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 203 | void InvokeGetIMSI(Error *error, const GSMIdentifierCallback &callback, |
| 204 | int timeout) { |
| 205 | callback.Run(kIMSI, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 206 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 207 | void InvokeGetMSISDN(Error *error, const GSMIdentifierCallback &callback, |
| 208 | int timeout) { |
| 209 | callback.Run(kMSISDN, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 210 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 211 | void InvokeGetSPN(Error *error, const GSMIdentifierCallback &callback, |
| 212 | int timeout) { |
| 213 | callback.Run(kTestCarrier, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 214 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 215 | void InvokeGetRegistrationInfo(Error *error, |
| 216 | const RegistrationInfoCallback &callback, |
| 217 | int timeout) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 218 | static const char kNetworkID[] = "22803"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 219 | callback.Run(MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING, |
| 220 | kNetworkID, kTestCarrier, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 221 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 222 | void InvokeRegister(const string &network_id, |
| 223 | Error *error, |
| 224 | const ResultCallback &callback, |
| 225 | int timeout) { |
| 226 | callback.Run(Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 227 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 228 | void InvokeGetRegistrationState(Error *error, |
| 229 | const RegistrationStateCallback &callback, |
| 230 | int timeout) { |
| 231 | callback.Run(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED, |
| 232 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
| 233 | Error()); |
| 234 | } |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 235 | void InvokeGetRegistrationStateUnregistered( |
| 236 | Error *error, |
| 237 | const RegistrationStateCallback &callback, |
| 238 | int timeout) { |
| 239 | callback.Run(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 240 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 241 | Error()); |
| 242 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 243 | void InvokeConnect(DBusPropertiesMap props, Error *error, |
| 244 | const ResultCallback &callback, int timeout) { |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 245 | EXPECT_EQ(Service::kStateAssociating, device_->service_->state()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 246 | callback.Run(Error()); |
| 247 | } |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 248 | void InvokeConnectFail(DBusPropertiesMap props, Error *error, |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 249 | const ResultCallback &callback, int timeout) { |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 250 | EXPECT_EQ(Service::kStateAssociating, device_->service_->state()); |
| 251 | callback.Run(Error(Error::kNotOnHomeNetwork)); |
| 252 | } |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 253 | void InvokeConnectFailNoService(DBusPropertiesMap props, Error *error, |
| 254 | const ResultCallback &callback, int timeout) { |
| 255 | device_->service_ = NULL; |
| 256 | callback.Run(Error(Error::kNotOnHomeNetwork)); |
| 257 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 258 | void InvokeDisconnect(Error *error, const ResultCallback &callback, |
| 259 | int timeout) { |
| 260 | if (!callback.is_null()) |
| 261 | callback.Run(Error()); |
| 262 | } |
| 263 | |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 264 | void ExpectCdmaStartModem(string network_technology) { |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 265 | if (!device_->IsUnderlyingDeviceEnabled()) |
| 266 | EXPECT_CALL(*proxy_, |
| 267 | Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 268 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 269 | EXPECT_CALL(*simple_proxy_, |
| 270 | GetModemStatus(_, _, CellularCapability::kTimeoutDefault)) |
| 271 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemStatus)); |
| 272 | EXPECT_CALL(*proxy_, |
| 273 | GetModemInfo(_, _, CellularCapability::kTimeoutDefault)) |
| 274 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemInfo)); |
| 275 | if (network_technology == flimflam::kNetworkTechnology1Xrtt) |
| 276 | EXPECT_CALL(*cdma_proxy_, GetRegistrationState(NULL, _, _)) |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 277 | .WillOnce(Invoke(this, &CellularTest::InvokeGetRegistrationState1X)); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 278 | else |
| 279 | EXPECT_CALL(*cdma_proxy_, GetRegistrationState(NULL, _, _)) |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 280 | .WillOnce(Invoke(this, &CellularTest::InvokeGetRegistrationState)); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 281 | EXPECT_CALL(*cdma_proxy_, GetSignalQuality(NULL, _, _)) |
| 282 | .Times(2) |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 283 | .WillRepeatedly(Invoke(this, &CellularTest::InvokeGetSignalQuality)); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 284 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 285 | EXPECT_CALL(manager_, RegisterService(_)); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 286 | } |
| 287 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 288 | MOCK_METHOD1(TestCallback, void(const Error &error)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 289 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 290 | protected: |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 291 | static const char kTestDeviceName[]; |
| 292 | static const char kTestDeviceAddress[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 293 | static const char kDBusOwner[]; |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 294 | static const char kDBusService[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 295 | static const char kDBusPath[]; |
| 296 | static const char kTestCarrier[]; |
| 297 | static const char kMEID[]; |
| 298 | static const char kIMEI[]; |
| 299 | static const char kIMSI[]; |
| 300 | static const char kMSISDN[]; |
| 301 | static const char kTestMobileProviderDBPath[]; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 302 | static const int kStrength; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 303 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 304 | class TestProxyFactory : public ProxyFactory { |
| 305 | public: |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 306 | explicit TestProxyFactory(CellularTest *test) : test_(test) {} |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 307 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 308 | virtual ModemProxyInterface *CreateModemProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 309 | const string &/*path*/, |
| 310 | const string &/*service*/) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 311 | return test_->proxy_.release(); |
| 312 | } |
| 313 | |
| 314 | virtual ModemSimpleProxyInterface *CreateModemSimpleProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 315 | const string &/*path*/, |
| 316 | const string &/*service*/) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 317 | return test_->simple_proxy_.release(); |
| 318 | } |
| 319 | |
| 320 | virtual ModemCDMAProxyInterface *CreateModemCDMAProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 321 | const string &/*path*/, |
| 322 | const string &/*service*/) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 323 | return test_->cdma_proxy_.release(); |
| 324 | } |
| 325 | |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 326 | virtual ModemGSMCardProxyInterface *CreateModemGSMCardProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 327 | const string &/*path*/, |
| 328 | const string &/*service*/) { |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 329 | // TODO(benchan): This code conditionally returns a NULL pointer to avoid |
| 330 | // CellularCapabilityGSM::InitProperties (and thus |
| 331 | // CellularCapabilityGSM::GetIMSI) from being called during the |
| 332 | // construction. Remove this workaround after refactoring the tests. |
| 333 | return test_->create_gsm_card_proxy_from_factory_ ? |
| 334 | test_->gsm_card_proxy_.release() : NULL; |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 337 | virtual ModemGSMNetworkProxyInterface *CreateModemGSMNetworkProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 338 | const string &/*path*/, |
| 339 | const string &/*service*/) { |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 340 | return test_->gsm_network_proxy_.release(); |
| 341 | } |
| 342 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 343 | private: |
| 344 | CellularTest *test_; |
| 345 | }; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 346 | void StartRTNLHandler(); |
| 347 | void StopRTNLHandler(); |
| 348 | |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 349 | void AllowCreateGSMCardProxyFromFactory() { |
| 350 | create_gsm_card_proxy_from_factory_ = true; |
| 351 | } |
| 352 | |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 353 | void SetCellularType(Cellular::Type type) { |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 354 | device_->InitCapability(type); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 355 | } |
| 356 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 357 | CellularCapabilityClassic *GetCapabilityClassic() { |
| 358 | return dynamic_cast<CellularCapabilityClassic *>( |
| 359 | device_->capability_.get()); |
| 360 | } |
| 361 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 362 | CellularCapabilityCDMA *GetCapabilityCDMA() { |
| 363 | return dynamic_cast<CellularCapabilityCDMA *>(device_->capability_.get()); |
| 364 | } |
| 365 | |
| 366 | CellularCapabilityGSM *GetCapabilityGSM() { |
| 367 | return dynamic_cast<CellularCapabilityGSM *>(device_->capability_.get()); |
| 368 | } |
| 369 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 370 | NiceMockControl control_interface_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 371 | EventDispatcher dispatcher_; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 372 | MockMetrics metrics_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 373 | MockGLib glib_; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 374 | MockManager manager_; |
| 375 | MockDeviceInfo device_info_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 376 | NiceMock<MockRTNLHandler> rtnl_handler_; |
| 377 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 378 | MockDHCPProvider dhcp_provider_; |
| 379 | scoped_refptr<MockDHCPConfig> dhcp_config_; |
| 380 | |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 381 | bool create_gsm_card_proxy_from_factory_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 382 | scoped_ptr<MockModemProxy> proxy_; |
| 383 | scoped_ptr<MockModemSimpleProxy> simple_proxy_; |
| 384 | scoped_ptr<MockModemCDMAProxy> cdma_proxy_; |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 385 | scoped_ptr<MockModemGSMCardProxy> gsm_card_proxy_; |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 386 | scoped_ptr<MockModemGSMNetworkProxy> gsm_network_proxy_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 387 | TestProxyFactory proxy_factory_; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 388 | mobile_provider_db *provider_db_; |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 389 | CellularRefPtr device_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 390 | }; |
| 391 | |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 392 | const char CellularTest::kTestDeviceName[] = "usb0"; |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 393 | const char CellularTest::kTestDeviceAddress[] = "00:01:02:03:04:05"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 394 | const char CellularTest::kDBusOwner[] = ":1.19"; |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 395 | const char CellularTest::kDBusService[] = "org.chromium.ModemManager"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 396 | const char CellularTest::kDBusPath[] = "/org/chromium/ModemManager/Gobi/0"; |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 397 | const char CellularTest::kTestCarrier[] = "The Cellular Carrier"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 398 | const char CellularTest::kMEID[] = "01234567EF8901"; |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 399 | const char CellularTest::kIMEI[] = "987654321098765"; |
| 400 | const char CellularTest::kIMSI[] = "123456789012345"; |
| 401 | const char CellularTest::kMSISDN[] = "12345678901"; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 402 | const char CellularTest::kTestMobileProviderDBPath[] = |
| 403 | "provider_db_unittest.bfd"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 404 | const int CellularTest::kStrength = 90; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 405 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 406 | TEST_F(CellularTest, GetStateString) { |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 407 | EXPECT_EQ("CellularStateDisabled", |
| 408 | device_->GetStateString(Cellular::kStateDisabled)); |
| 409 | EXPECT_EQ("CellularStateEnabled", |
| 410 | device_->GetStateString(Cellular::kStateEnabled)); |
| 411 | EXPECT_EQ("CellularStateRegistered", |
| 412 | device_->GetStateString(Cellular::kStateRegistered)); |
| 413 | EXPECT_EQ("CellularStateConnected", |
| 414 | device_->GetStateString(Cellular::kStateConnected)); |
| 415 | EXPECT_EQ("CellularStateLinked", |
| 416 | device_->GetStateString(Cellular::kStateLinked)); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 419 | TEST_F(CellularTest, StartCDMARegister) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 420 | SetCellularType(Cellular::kTypeCDMA); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 421 | ExpectCdmaStartModem(flimflam::kNetworkTechnology1Xrtt); |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 422 | EXPECT_CALL(*cdma_proxy_, MEID()).WillOnce(Return(kMEID)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 423 | Error error; |
| 424 | device_->Start(&error, Bind(&CellularTest::TestCallback, Unretained(this))); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 425 | dispatcher_.DispatchPendingEvents(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 426 | EXPECT_EQ(kMEID, GetCapabilityClassic()->meid_); |
| 427 | EXPECT_EQ(kTestCarrier, GetCapabilityClassic()->carrier_); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 428 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 429 | ASSERT_TRUE(device_->service_.get()); |
| 430 | EXPECT_EQ(flimflam::kNetworkTechnology1Xrtt, |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 431 | device_->service_->network_technology()); |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 432 | EXPECT_EQ(kStrength, device_->service_->strength()); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 433 | EXPECT_EQ(flimflam::kRoamingStateHome, device_->service_->roaming_state()); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 436 | TEST_F(CellularTest, StartGSMRegister) { |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 437 | provider_db_ = mobile_provider_open_db(kTestMobileProviderDBPath); |
| 438 | ASSERT_TRUE(provider_db_); |
| 439 | device_->provider_db_ = provider_db_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 440 | EXPECT_CALL(*proxy_, Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 441 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 442 | EXPECT_CALL(*gsm_card_proxy_, |
| 443 | GetIMEI(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 444 | .WillOnce(Invoke(this, &CellularTest::InvokeGetIMEI)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 445 | EXPECT_CALL(*gsm_card_proxy_, |
| 446 | GetIMSI(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 447 | .WillOnce(Invoke(this, &CellularTest::InvokeGetIMSI)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 448 | EXPECT_CALL(*gsm_card_proxy_, |
| 449 | GetSPN(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 450 | .WillOnce(Invoke(this, &CellularTest::InvokeGetSPN)); |
| 451 | EXPECT_CALL(*gsm_card_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 452 | GetMSISDN(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 453 | .WillOnce(Invoke(this, &CellularTest::InvokeGetMSISDN)); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 454 | EXPECT_CALL(*gsm_network_proxy_, AccessTechnology()) |
| 455 | .WillOnce(Return(MM_MODEM_GSM_ACCESS_TECH_EDGE)); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 456 | EXPECT_CALL(*gsm_card_proxy_, EnabledFacilityLocks()) |
| 457 | .WillOnce(Return(MM_MODEM_GSM_FACILITY_SIM)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 458 | EXPECT_CALL(*proxy_, GetModemInfo(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 459 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemInfo)); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 460 | static const char kNetworkID[] = "22803"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 461 | EXPECT_CALL(*gsm_network_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 462 | GetRegistrationInfo(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 463 | .WillOnce(Invoke(this, &CellularTest::InvokeGetRegistrationInfo)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 464 | EXPECT_CALL(*gsm_network_proxy_, GetSignalQuality(NULL, _, _)) |
| 465 | .Times(2) |
| 466 | .WillRepeatedly(Invoke(this, |
| 467 | &CellularTest::InvokeGetSignalQuality)); |
| 468 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 469 | EXPECT_CALL(manager_, RegisterService(_)); |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 470 | AllowCreateGSMCardProxyFromFactory(); |
| 471 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 472 | Error error; |
| 473 | device_->Start(&error, Bind(&CellularTest::TestCallback, Unretained(this))); |
| 474 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 475 | dispatcher_.DispatchPendingEvents(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 476 | EXPECT_EQ(kIMEI, GetCapabilityGSM()->imei_); |
| 477 | EXPECT_EQ(kIMSI, GetCapabilityGSM()->imsi_); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 478 | EXPECT_EQ(kTestCarrier, GetCapabilityGSM()->spn_); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 479 | EXPECT_EQ(kMSISDN, GetCapabilityGSM()->mdn_); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 480 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
| 481 | ASSERT_TRUE(device_->service_.get()); |
| 482 | EXPECT_EQ(flimflam::kNetworkTechnologyEdge, |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 483 | device_->service_->network_technology()); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 484 | EXPECT_TRUE(GetCapabilityGSM()->sim_lock_status_.enabled); |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 485 | EXPECT_EQ(kStrength, device_->service_->strength()); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 486 | EXPECT_EQ(flimflam::kRoamingStateRoaming, device_->service_->roaming_state()); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 487 | EXPECT_EQ(kNetworkID, device_->service_->serving_operator().GetCode()); |
| 488 | EXPECT_EQ("Orange", device_->service_->serving_operator().GetName()); |
| 489 | EXPECT_EQ("ch", device_->service_->serving_operator().GetCountry()); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 492 | TEST_F(CellularTest, StartConnected) { |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 493 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
| 494 | .WillOnce(Return(true)); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 495 | SetCellularType(Cellular::kTypeCDMA); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 496 | device_->set_modem_state(Cellular::kModemStateConnected); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 497 | GetCapabilityClassic()->meid_ = kMEID; |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 498 | ExpectCdmaStartModem(flimflam::kNetworkTechnologyEvdo); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 499 | Error error; |
| 500 | device_->Start(&error, Bind(&CellularTest::TestCallback, Unretained(this))); |
| 501 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 502 | dispatcher_.DispatchPendingEvents(); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 503 | EXPECT_EQ(Cellular::kStateConnected, device_->state_); |
| 504 | } |
| 505 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 506 | TEST_F(CellularTest, StartLinked) { |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 507 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
| 508 | .WillOnce(DoAll(SetArgumentPointee<1>(IFF_UP), Return(true))); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 509 | SetCellularType(Cellular::kTypeCDMA); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 510 | device_->set_modem_state(Cellular::kModemStateConnected); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 511 | GetCapabilityClassic()->meid_ = kMEID; |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 512 | ExpectCdmaStartModem(flimflam::kNetworkTechnologyEvdo); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 513 | EXPECT_CALL(dhcp_provider_, CreateConfig(kTestDeviceName, _, _, _)) |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 514 | .WillOnce(Return(dhcp_config_)); |
| 515 | EXPECT_CALL(*dhcp_config_, RequestIP()).WillOnce(Return(true)); |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 516 | EXPECT_CALL(manager_, UpdateService(_)).Times(2); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 517 | Error error; |
| 518 | device_->Start(&error, Bind(&CellularTest::TestCallback, Unretained(this))); |
| 519 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 520 | dispatcher_.DispatchPendingEvents(); |
| 521 | EXPECT_EQ(Cellular::kStateLinked, device_->state_); |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 522 | EXPECT_EQ(Service::kStateConfiguring, device_->service_->state()); |
| 523 | device_->SelectService(NULL); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 526 | TEST_F(CellularTest, CreateService) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 527 | SetCellularType(Cellular::kTypeCDMA); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 528 | static const char kPaymentURL[] = "https://payment.url"; |
| 529 | static const char kUsageURL[] = "https://usage.url"; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 530 | device_->home_provider_.SetName(kTestCarrier); |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 531 | GetCapabilityCDMA()->olp_.SetURL(kPaymentURL); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 532 | GetCapabilityCDMA()->usage_url_ = kUsageURL; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 533 | device_->CreateService(); |
| 534 | ASSERT_TRUE(device_->service_.get()); |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 535 | EXPECT_EQ(kPaymentURL, device_->service_->olp().GetURL()); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 536 | EXPECT_EQ(kUsageURL, device_->service_->usage_url()); |
| 537 | EXPECT_EQ(kTestCarrier, device_->service_->serving_operator().GetName()); |
| 538 | } |
| 539 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 540 | namespace { |
| 541 | |
| 542 | MATCHER(ContainsPhoneNumber, "") { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 543 | return ContainsKey(arg, |
| 544 | CellularCapabilityClassic::kConnectPropertyPhoneNumber); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 547 | } // namespace |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 548 | |
| 549 | TEST_F(CellularTest, Connect) { |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 550 | Error error; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 551 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 552 | .Times(2) |
| 553 | .WillRepeatedly(Return(true)); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 554 | device_->state_ = Cellular::kStateConnected; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 555 | device_->Connect(&error); |
| 556 | EXPECT_EQ(Error::kAlreadyConnected, error.type()); |
| 557 | error.Populate(Error::kSuccess); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 558 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 559 | device_->state_ = Cellular::kStateLinked; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 560 | device_->Connect(&error); |
| 561 | EXPECT_EQ(Error::kAlreadyConnected, error.type()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 562 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 563 | device_->state_ = Cellular::kStateRegistered; |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 564 | device_->service_ = new CellularService( |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 565 | &control_interface_, &dispatcher_, &metrics_, &manager_, device_); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 566 | |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 567 | device_->allow_roaming_ = false; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 568 | device_->service_->roaming_state_ = flimflam::kRoamingStateRoaming; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 569 | device_->Connect(&error); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 570 | EXPECT_EQ(Error::kNotOnHomeNetwork, error.type()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 571 | |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 572 | error.Populate(Error::kSuccess); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 573 | EXPECT_CALL(*simple_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 574 | Connect(ContainsPhoneNumber(), _, _, |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 575 | CellularCapability::kTimeoutConnect)) |
| 576 | .Times(2) |
| 577 | .WillRepeatedly(Invoke(this, &CellularTest::InvokeConnect)); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 578 | GetCapabilityClassic()->simple_proxy_.reset(simple_proxy_.release()); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 579 | device_->service_->roaming_state_ = flimflam::kRoamingStateHome; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 580 | device_->state_ = Cellular::kStateRegistered; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 581 | device_->Connect(&error); |
| 582 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 583 | dispatcher_.DispatchPendingEvents(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 584 | EXPECT_EQ(Cellular::kStateConnected, device_->state_); |
| 585 | |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 586 | device_->allow_roaming_ = true; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 587 | device_->service_->roaming_state_ = flimflam::kRoamingStateRoaming; |
| 588 | device_->state_ = Cellular::kStateRegistered; |
| 589 | device_->Connect(&error); |
| 590 | EXPECT_TRUE(error.IsSuccess()); |
| 591 | dispatcher_.DispatchPendingEvents(); |
| 592 | EXPECT_EQ(Cellular::kStateConnected, device_->state_); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 595 | TEST_F(CellularTest, Disconnect) { |
| 596 | Error error; |
| 597 | device_->state_ = Cellular::kStateRegistered; |
| 598 | device_->Disconnect(&error); |
| 599 | EXPECT_EQ(Error::kNotConnected, error.type()); |
| 600 | error.Reset(); |
| 601 | |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 602 | device_->state_ = Cellular::kStateConnected; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 603 | EXPECT_CALL(*proxy_, |
| 604 | Disconnect(_, _, CellularCapability::kTimeoutDefault)) |
| 605 | .WillOnce(Invoke(this, &CellularTest::InvokeDisconnect)); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 606 | GetCapabilityClassic()->proxy_.reset(proxy_.release()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 607 | device_->Disconnect(&error); |
| 608 | EXPECT_TRUE(error.IsSuccess()); |
| 609 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 610 | } |
| 611 | |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 612 | TEST_F(CellularTest, ConnectFailure) { |
| 613 | SetCellularType(Cellular::kTypeCDMA); |
| 614 | device_->state_ = Cellular::kStateRegistered; |
| 615 | device_->service_ = new CellularService( |
| 616 | &control_interface_, &dispatcher_, &metrics_, &manager_, device_); |
| 617 | ASSERT_EQ(Service::kStateIdle, device_->service_->state()); |
| 618 | EXPECT_CALL(*simple_proxy_, |
| 619 | Connect(_, _, _, CellularCapability::kTimeoutConnect)) |
| 620 | .WillOnce(Invoke(this, &CellularTest::InvokeConnectFail)); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 621 | GetCapabilityClassic()->simple_proxy_.reset(simple_proxy_.release()); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 622 | Error error; |
| 623 | device_->Connect(&error); |
| 624 | EXPECT_EQ(Service::kStateFailure, device_->service_->state()); |
| 625 | } |
| 626 | |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 627 | TEST_F(CellularTest, ConnectFailureNoService) { |
| 628 | // Make sure we don't crash if the connect failed and there is no |
| 629 | // CellularService object. This can happen if the modem is enabled and |
| 630 | // then quick disabled. |
| 631 | SetCellularType(Cellular::kTypeCDMA); |
| 632 | device_->state_ = Cellular::kStateRegistered; |
| 633 | device_->service_ = new CellularService( |
| 634 | &control_interface_, &dispatcher_, &metrics_, &manager_, device_); |
| 635 | EXPECT_CALL( |
| 636 | *simple_proxy_, |
| 637 | Connect(_, _, _, CellularCapability::kTimeoutConnect)) |
| 638 | .WillOnce(Invoke(this, &CellularTest::InvokeConnectFailNoService)); |
| 639 | EXPECT_CALL(manager_, UpdateService(_)); |
| 640 | GetCapabilityClassic()->simple_proxy_.reset(simple_proxy_.release()); |
| 641 | Error error; |
| 642 | device_->Connect(&error); |
| 643 | } |
| 644 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 645 | TEST_F(CellularTest, ModemStateChangeEnable) { |
| 646 | EXPECT_CALL(*simple_proxy_, |
| 647 | GetModemStatus(_, _, CellularCapability::kTimeoutDefault)) |
| 648 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemStatus)); |
| 649 | EXPECT_CALL(*cdma_proxy_, MEID()).WillOnce(Return(kMEID)); |
| 650 | EXPECT_CALL(*proxy_, |
| 651 | GetModemInfo(_, _, CellularCapability::kTimeoutDefault)) |
| 652 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemInfo)); |
| 653 | EXPECT_CALL(*cdma_proxy_, GetRegistrationState(NULL, _, _)) |
| 654 | .WillOnce(Invoke(this, |
| 655 | &CellularTest::InvokeGetRegistrationStateUnregistered)); |
| 656 | EXPECT_CALL(*cdma_proxy_, GetSignalQuality(NULL, _, _)) |
| 657 | .WillOnce(Invoke(this, &CellularTest::InvokeGetSignalQuality)); |
| 658 | EXPECT_CALL(manager_, UpdateEnabledTechnologies()); |
| 659 | device_->state_ = Cellular::kStateDisabled; |
| 660 | device_->set_modem_state(Cellular::kModemStateDisabled); |
| 661 | SetCellularType(Cellular::kTypeCDMA); |
| 662 | |
| 663 | DBusPropertiesMap props; |
| 664 | props[CellularCapabilityClassic::kModemPropertyEnabled].writer(). |
| 665 | append_bool(true); |
| 666 | device_->OnDBusPropertiesChanged(MM_MODEM_INTERFACE, props, vector<string>()); |
| 667 | dispatcher_.DispatchPendingEvents(); |
| 668 | |
| 669 | EXPECT_EQ(Cellular::kModemStateEnabled, device_->modem_state()); |
| 670 | EXPECT_EQ(Cellular::kStateEnabled, device_->state()); |
| 671 | EXPECT_TRUE(device_->enabled()); |
| 672 | } |
| 673 | |
| 674 | TEST_F(CellularTest, ModemStateChangeDisable) { |
| 675 | EXPECT_CALL(*proxy_, |
| 676 | Disconnect(_, _, CellularCapability::kTimeoutDefault)) |
| 677 | .WillOnce(Invoke(this, &CellularTest::InvokeDisconnect)); |
| 678 | EXPECT_CALL(*proxy_, |
Thieu Le | c8d2d96 | 2012-05-15 14:31:18 -0700 | [diff] [blame] | 679 | Enable(false, _, _, CellularCapability::kTimeoutEnable)) |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 680 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
| 681 | EXPECT_CALL(manager_, UpdateEnabledTechnologies()); |
| 682 | device_->enabled_ = true; |
| 683 | device_->enabled_pending_ = true; |
| 684 | device_->state_ = Cellular::kStateEnabled; |
| 685 | device_->set_modem_state(Cellular::kModemStateEnabled); |
| 686 | SetCellularType(Cellular::kTypeCDMA); |
| 687 | GetCapabilityClassic()->InitProxies(); |
| 688 | |
| 689 | GetCapabilityClassic()->OnModemStateChangedSignal(kModemClassicStateEnabled, |
| 690 | kModemClassicStateDisabled, |
| 691 | 0); |
| 692 | dispatcher_.DispatchPendingEvents(); |
| 693 | |
| 694 | EXPECT_EQ(Cellular::kModemStateDisabled, device_->modem_state()); |
| 695 | EXPECT_EQ(Cellular::kStateDisabled, device_->state()); |
| 696 | EXPECT_FALSE(device_->enabled()); |
| 697 | } |
| 698 | |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 699 | TEST_F(CellularTest, ModemStateChangeStaleConnected) { |
| 700 | // Test to make sure that we ignore stale modem Connected state transitions. |
| 701 | // When a modem is asked to connect and before the connect completes, the |
| 702 | // modem is disabled, it may send a stale Connected state transition after |
| 703 | // it has been disabled. |
| 704 | device_->state_ = Cellular::kStateDisabled; |
| 705 | device_->OnModemStateChanged(Cellular::kModemStateEnabling, |
| 706 | Cellular::kModemStateConnected, |
| 707 | 0); |
| 708 | EXPECT_EQ(Cellular::kStateDisabled, device_->state()); |
| 709 | } |
| 710 | |
| 711 | TEST_F(CellularTest, ModemStateChangeValidConnected) { |
| 712 | device_->state_ = Cellular::kStateEnabled; |
| 713 | device_->service_ = new CellularService( |
| 714 | &control_interface_, &dispatcher_, &metrics_, &manager_, device_); |
| 715 | device_->OnModemStateChanged(Cellular::kModemStateConnecting, |
| 716 | Cellular::kModemStateConnected, |
| 717 | 0); |
| 718 | EXPECT_EQ(Cellular::kStateConnected, device_->state()); |
| 719 | } |
| 720 | |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 721 | TEST_F(CellularTest, StartModemCallback) { |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 722 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 723 | EXPECT_EQ(device_->state_, Cellular::kStateDisabled); |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 724 | device_->StartModemCallback(Bind(&CellularTest::TestCallback, |
| 725 | Unretained(this)), |
| 726 | Error(Error::kSuccess)); |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 727 | EXPECT_EQ(device_->state_, Cellular::kStateEnabled); |
| 728 | } |
| 729 | |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 730 | TEST_F(CellularTest, StartModemCallbackFail) { |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 731 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 732 | EXPECT_EQ(device_->state_, Cellular::kStateDisabled); |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 733 | device_->StartModemCallback(Bind(&CellularTest::TestCallback, |
| 734 | Unretained(this)), |
| 735 | Error(Error::kOperationFailed)); |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 736 | EXPECT_EQ(device_->state_, Cellular::kStateDisabled); |
| 737 | } |
| 738 | |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 739 | TEST_F(CellularTest, StopModemCallback) { |
| 740 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 741 | device_->service_ = new MockCellularService(&control_interface_, |
| 742 | &dispatcher_, |
| 743 | &metrics_, |
| 744 | &manager_, |
| 745 | device_); |
| 746 | device_->StopModemCallback(Bind(&CellularTest::TestCallback, |
| 747 | Unretained(this)), |
| 748 | Error(Error::kSuccess)); |
| 749 | EXPECT_EQ(device_->state_, Cellular::kStateDisabled); |
| 750 | EXPECT_FALSE(device_->service_.get()); |
| 751 | } |
| 752 | |
| 753 | TEST_F(CellularTest, StopModemCallbackFail) { |
| 754 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 755 | device_->service_ = new MockCellularService(&control_interface_, |
| 756 | &dispatcher_, |
| 757 | &metrics_, |
| 758 | &manager_, |
| 759 | device_); |
| 760 | device_->StopModemCallback(Bind(&CellularTest::TestCallback, |
| 761 | Unretained(this)), |
| 762 | Error(Error::kOperationFailed)); |
| 763 | EXPECT_EQ(device_->state_, Cellular::kStateDisabled); |
| 764 | EXPECT_FALSE(device_->service_.get()); |
| 765 | } |
| 766 | |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 767 | TEST_F(CellularTest, ConnectAddsTerminationAction) { |
| 768 | Error error; |
| 769 | EXPECT_CALL(*simple_proxy_, |
| 770 | Connect(ContainsPhoneNumber(), _, _, |
| 771 | CellularCapability::kTimeoutConnect)) |
| 772 | .WillRepeatedly(Invoke(this, &CellularTest::InvokeConnect)); |
| 773 | EXPECT_CALL(*proxy_, |
| 774 | Disconnect(_, _, CellularCapability::kTimeoutDefault)) |
| 775 | .WillOnce(Invoke(this, &CellularTest::InvokeDisconnect)); |
| 776 | |
| 777 | // TestCallback() will be called when the termination actions complete. This |
| 778 | // verifies that the actions were registered, invoked, and report their |
| 779 | // status. |
| 780 | EXPECT_CALL(*this, TestCallback(IsSuccess())).Times(2); |
| 781 | |
| 782 | device_->service_ = new CellularService( |
| 783 | &control_interface_, &dispatcher_, &metrics_, &manager_, device_); |
| 784 | GetCapabilityClassic()->proxy_.reset(proxy_.release()); |
| 785 | GetCapabilityClassic()->simple_proxy_.reset(simple_proxy_.release()); |
| 786 | device_->state_ = Cellular::kStateRegistered; |
| 787 | device_->Connect(&error); |
| 788 | EXPECT_TRUE(error.IsSuccess()); |
| 789 | dispatcher_.DispatchPendingEvents(); |
| 790 | EXPECT_EQ(Cellular::kStateConnected, device_->state_); |
| 791 | |
| 792 | // If the action of establishing a connection registered a termination action |
| 793 | // with the manager, then running the termination action will result in a |
| 794 | // disconnect. |
| 795 | manager_.RunTerminationActions( |
| 796 | 0, Bind(&CellularTest::TestCallback, Unretained(this))); |
| 797 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
| 798 | dispatcher_.DispatchPendingEvents(); |
| 799 | |
| 800 | // Verify that the termination action has been removed from the manager. |
| 801 | // Running the registered termination actions again should result in |
| 802 | // TestCallback being called with success because there are no registered |
| 803 | // termination actions.. If the termination action is not removed, then |
| 804 | // TestCallback will be called with kOperationTimeout. |
| 805 | manager_.RunTerminationActions( |
| 806 | 0, Bind(&CellularTest::TestCallback, Unretained(this))); |
| 807 | dispatcher_.DispatchPendingEvents(); |
| 808 | } |
| 809 | |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 810 | TEST_F(CellularTest, SetAllowRoaming) { |
| 811 | EXPECT_FALSE(device_->allow_roaming_); |
| 812 | EXPECT_CALL(manager_, UpdateDevice(_)); |
| 813 | Error error; |
| 814 | device_->SetAllowRoaming(true, &error); |
| 815 | EXPECT_TRUE(error.IsSuccess()); |
| 816 | EXPECT_TRUE(device_->allow_roaming_); |
| 817 | } |
| 818 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 819 | } // namespace shill |