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" |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 17 | #include "shill/cellular_capability_gsm.h" |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 18 | #include "shill/cellular_service.h" |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 19 | #include "shill/error.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 20 | #include "shill/event_dispatcher.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 21 | #include "shill/mock_device_info.h" |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 22 | #include "shill/mock_dhcp_config.h" |
| 23 | #include "shill/mock_dhcp_provider.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 24 | #include "shill/mock_manager.h" |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 25 | #include "shill/mock_metrics.h" |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 26 | #include "shill/mock_modem_cdma_proxy.h" |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 27 | #include "shill/mock_modem_gsm_card_proxy.h" |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 28 | #include "shill/mock_modem_gsm_network_proxy.h" |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 29 | #include "shill/mock_modem_proxy.h" |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 30 | #include "shill/mock_modem_simple_proxy.h" |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 31 | #include "shill/mock_rtnl_handler.h" |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 32 | #include "shill/nice_mock_control.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 33 | #include "shill/property_store_unittest.h" |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 34 | #include "shill/proxy_factory.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 35 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 36 | using base::Bind; |
| 37 | using base::Unretained; |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 38 | using std::map; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 39 | using std::string; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 40 | using testing::_; |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 41 | using testing::AnyNumber; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 42 | using testing::Invoke; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 43 | using testing::NiceMock; |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 44 | using testing::Return; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 45 | using testing::SetArgumentPointee; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 46 | using testing::Unused; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 47 | |
| 48 | namespace shill { |
| 49 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 50 | MATCHER(IsSuccess, "") { |
| 51 | return arg.IsSuccess(); |
| 52 | } |
| 53 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 54 | class CellularPropertyTest : public PropertyStoreTest { |
| 55 | public: |
| 56 | CellularPropertyTest() |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 57 | : device_(new Cellular(control_interface(), |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 58 | NULL, |
| 59 | NULL, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 60 | NULL, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 61 | "usb0", |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 62 | "00:01:02:03:04:05", |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 63 | 3, |
| 64 | Cellular::kTypeGSM, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 65 | "", |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 66 | "", |
| 67 | NULL)) {} |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 68 | virtual ~CellularPropertyTest() {} |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 69 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 70 | protected: |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 71 | DeviceRefPtr device_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 74 | TEST_F(CellularPropertyTest, Contains) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 75 | EXPECT_TRUE(device_->store().Contains(flimflam::kNameProperty)); |
| 76 | EXPECT_FALSE(device_->store().Contains("")); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 77 | } |
| 78 | |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 79 | TEST_F(CellularPropertyTest, SetProperty) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 80 | { |
| 81 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 82 | EXPECT_TRUE(DBusAdaptor::SetProperty( |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 83 | device_->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 84 | flimflam::kCellularAllowRoamingProperty, |
| 85 | PropertyStoreTest::kBoolV, |
| 86 | &error)); |
| 87 | } |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 88 | // Ensure that attempting to write a R/O property returns InvalidArgs error. |
| 89 | { |
| 90 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 91 | EXPECT_FALSE(DBusAdaptor::SetProperty(device_->mutable_store(), |
| 92 | flimflam::kAddressProperty, |
| 93 | PropertyStoreTest::kStringV, |
| 94 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 95 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 96 | } |
| 97 | { |
| 98 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 99 | EXPECT_FALSE(DBusAdaptor::SetProperty(device_->mutable_store(), |
| 100 | flimflam::kCarrierProperty, |
| 101 | PropertyStoreTest::kStringV, |
| 102 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 103 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 104 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 107 | class CellularTest : public testing::Test { |
| 108 | public: |
| 109 | CellularTest() |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 110 | : manager_(&control_interface_, &dispatcher_, &metrics_, &glib_), |
| 111 | device_info_(&control_interface_, &dispatcher_, &metrics_, &manager_), |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 112 | dhcp_config_(new MockDHCPConfig(&control_interface_, |
| 113 | &dispatcher_, |
| 114 | &dhcp_provider_, |
| 115 | kTestDeviceName, |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 116 | "", |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 117 | &glib_)), |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 118 | device_(new Cellular(&control_interface_, |
| 119 | &dispatcher_, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 120 | &metrics_, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 121 | &manager_, |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 122 | kTestDeviceName, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 123 | kTestDeviceAddress, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 124 | 3, |
| 125 | Cellular::kTypeGSM, |
| 126 | kDBusOwner, |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 127 | kDBusPath, |
| 128 | NULL)), |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 129 | proxy_(new MockModemProxy()), |
| 130 | simple_proxy_(new MockModemSimpleProxy()), |
| 131 | cdma_proxy_(new MockModemCDMAProxy()), |
| 132 | gsm_card_proxy_(new MockModemGSMCardProxy()), |
| 133 | gsm_network_proxy_(new MockModemGSMNetworkProxy()), |
| 134 | proxy_factory_(this), |
| 135 | provider_db_(NULL) { |
| 136 | device_->capability_->proxy_factory_ = &proxy_factory_; |
| 137 | } |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 138 | |
| 139 | virtual ~CellularTest() { |
| 140 | mobile_provider_close_db(provider_db_); |
| 141 | provider_db_ = NULL; |
| 142 | } |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 143 | |
| 144 | virtual void SetUp() { |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 145 | static_cast<Device *>(device_)->rtnl_handler_ = &rtnl_handler_; |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 146 | device_->set_dhcp_provider(&dhcp_provider_); |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 147 | EXPECT_CALL(manager_, device_info()).WillRepeatedly(Return(&device_info_)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 148 | EXPECT_CALL(manager_, DeregisterService(_)).Times(AnyNumber()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | virtual void TearDown() { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 152 | device_->DestroyIPConfig(); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 153 | device_->state_ = Cellular::kStateDisabled; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 154 | device_->capability_->ReleaseProxies(); |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 155 | device_->set_dhcp_provider(NULL); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 158 | void InvokeEnable(bool enable, Error *error, |
| 159 | const ResultCallback &callback, int timeout) { |
| 160 | callback.Run(Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 161 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 162 | void InvokeGetSignalQuality(Error *error, |
| 163 | const SignalQualityCallback &callback, |
| 164 | int timeout) { |
| 165 | callback.Run(kStrength, Error()); |
| 166 | } |
| 167 | void InvokeGetModemStatus(Error *error, |
| 168 | const DBusPropertyMapCallback &callback, |
| 169 | int timeout) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 170 | DBusPropertiesMap props; |
| 171 | props["carrier"].writer().append_string(kTestCarrier); |
| 172 | props["unknown-property"].writer().append_string("irrelevant-value"); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 173 | callback.Run(props, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 174 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 175 | void InvokeGetModemInfo(Error *error, const ModemInfoCallback &callback, |
| 176 | int timeout) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 177 | static const char kManufacturer[] = "Company"; |
| 178 | static const char kModelID[] = "Gobi 2000"; |
| 179 | static const char kHWRev[] = "A00B1234"; |
| 180 | ModemHardwareInfo info; |
| 181 | info._1 = kManufacturer; |
| 182 | info._2 = kModelID; |
| 183 | info._3 = kHWRev; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 184 | callback.Run(info, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 185 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 186 | void InvokeGetRegistrationState1X(Error *error, |
| 187 | const RegistrationStateCallback &callback, |
| 188 | int timeout) { |
| 189 | callback.Run(MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
| 190 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 191 | Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 192 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 193 | void InvokeGetIMEI(Error *error, const GSMIdentifierCallback &callback, |
| 194 | int timeout) { |
| 195 | callback.Run(kIMEI, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 196 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 197 | void InvokeGetIMSI(Error *error, const GSMIdentifierCallback &callback, |
| 198 | int timeout) { |
| 199 | callback.Run(kIMSI, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 200 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 201 | void InvokeGetMSISDN(Error *error, const GSMIdentifierCallback &callback, |
| 202 | int timeout) { |
| 203 | callback.Run(kMSISDN, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 204 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 205 | void InvokeGetSPN(Error *error, const GSMIdentifierCallback &callback, |
| 206 | int timeout) { |
| 207 | callback.Run(kTestCarrier, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 208 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 209 | void InvokeGetRegistrationInfo(Error *error, |
| 210 | const RegistrationInfoCallback &callback, |
| 211 | int timeout) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 212 | static const char kNetworkID[] = "22803"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 213 | callback.Run(MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING, |
| 214 | kNetworkID, kTestCarrier, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 215 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 216 | void InvokeRegister(const string &network_id, |
| 217 | Error *error, |
| 218 | const ResultCallback &callback, |
| 219 | int timeout) { |
| 220 | callback.Run(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 InvokeGetRegistrationState(Error *error, |
| 223 | const RegistrationStateCallback &callback, |
| 224 | int timeout) { |
| 225 | callback.Run(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED, |
| 226 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
| 227 | Error()); |
| 228 | } |
| 229 | void InvokeConnect(DBusPropertiesMap props, Error *error, |
| 230 | const ResultCallback &callback, int timeout) { |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 231 | EXPECT_EQ(Service::kStateAssociating, device_->service_->state()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 232 | callback.Run(Error()); |
| 233 | } |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 234 | void InvokeConnectFail(DBusPropertiesMap props, Error *error, |
| 235 | const ResultCallback &callback, int timeout) { |
| 236 | EXPECT_EQ(Service::kStateAssociating, device_->service_->state()); |
| 237 | callback.Run(Error(Error::kNotOnHomeNetwork)); |
| 238 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 239 | void InvokeDisconnect(Error *error, const ResultCallback &callback, |
| 240 | int timeout) { |
| 241 | if (!callback.is_null()) |
| 242 | callback.Run(Error()); |
| 243 | } |
| 244 | |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 245 | void ExpectCdmaStartModem(string network_technology) { |
| 246 | EXPECT_CALL(*proxy_, Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 247 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
| 248 | EXPECT_CALL(*simple_proxy_, |
| 249 | GetModemStatus(_, _, CellularCapability::kTimeoutDefault)) |
| 250 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemStatus)); |
| 251 | EXPECT_CALL(*proxy_, |
| 252 | GetModemInfo(_, _, CellularCapability::kTimeoutDefault)) |
| 253 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemInfo)); |
| 254 | if (network_technology == flimflam::kNetworkTechnology1Xrtt) |
| 255 | EXPECT_CALL(*cdma_proxy_, GetRegistrationState(NULL, _, _)) |
| 256 | .WillOnce(Invoke(this, |
| 257 | &CellularTest::InvokeGetRegistrationState1X)); |
| 258 | else |
| 259 | EXPECT_CALL(*cdma_proxy_, GetRegistrationState(NULL, _, _)) |
| 260 | .WillOnce(Invoke(this, |
| 261 | &CellularTest::InvokeGetRegistrationState)); |
| 262 | EXPECT_CALL(*cdma_proxy_, GetSignalQuality(NULL, _, _)) |
| 263 | .Times(2) |
| 264 | .WillRepeatedly(Invoke(this, |
| 265 | &CellularTest::InvokeGetSignalQuality)); |
| 266 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 267 | } |
| 268 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 269 | MOCK_METHOD1(TestCallback, void(const Error &error)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 270 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 271 | protected: |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 272 | static const char kTestDeviceName[]; |
| 273 | static const char kTestDeviceAddress[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 274 | static const char kDBusOwner[]; |
| 275 | static const char kDBusPath[]; |
| 276 | static const char kTestCarrier[]; |
| 277 | static const char kMEID[]; |
| 278 | static const char kIMEI[]; |
| 279 | static const char kIMSI[]; |
| 280 | static const char kMSISDN[]; |
| 281 | static const char kTestMobileProviderDBPath[]; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 282 | static const int kStrength; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 283 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 284 | class TestProxyFactory : public ProxyFactory { |
| 285 | public: |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 286 | explicit TestProxyFactory(CellularTest *test) : test_(test) {} |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 287 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 288 | virtual ModemProxyInterface *CreateModemProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 289 | const string &/*path*/, |
| 290 | const string &/*service*/) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 291 | return test_->proxy_.release(); |
| 292 | } |
| 293 | |
| 294 | virtual ModemSimpleProxyInterface *CreateModemSimpleProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 295 | const string &/*path*/, |
| 296 | const string &/*service*/) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 297 | return test_->simple_proxy_.release(); |
| 298 | } |
| 299 | |
| 300 | virtual ModemCDMAProxyInterface *CreateModemCDMAProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 301 | const string &/*path*/, |
| 302 | const string &/*service*/) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 303 | return test_->cdma_proxy_.release(); |
| 304 | } |
| 305 | |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 306 | virtual ModemGSMCardProxyInterface *CreateModemGSMCardProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 307 | const string &/*path*/, |
| 308 | const string &/*service*/) { |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 309 | return test_->gsm_card_proxy_.release(); |
| 310 | } |
| 311 | |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 312 | virtual ModemGSMNetworkProxyInterface *CreateModemGSMNetworkProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 313 | const string &/*path*/, |
| 314 | const string &/*service*/) { |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 315 | return test_->gsm_network_proxy_.release(); |
| 316 | } |
| 317 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 318 | private: |
| 319 | CellularTest *test_; |
| 320 | }; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 321 | void StartRTNLHandler(); |
| 322 | void StopRTNLHandler(); |
| 323 | |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 324 | void SetCellularType(Cellular::Type type) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 325 | device_->InitCapability(type, &proxy_factory_); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 328 | CellularCapabilityCDMA *GetCapabilityCDMA() { |
| 329 | return dynamic_cast<CellularCapabilityCDMA *>(device_->capability_.get()); |
| 330 | } |
| 331 | |
| 332 | CellularCapabilityGSM *GetCapabilityGSM() { |
| 333 | return dynamic_cast<CellularCapabilityGSM *>(device_->capability_.get()); |
| 334 | } |
| 335 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 336 | NiceMockControl control_interface_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 337 | EventDispatcher dispatcher_; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 338 | MockMetrics metrics_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 339 | MockGLib glib_; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 340 | MockManager manager_; |
| 341 | MockDeviceInfo device_info_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 342 | NiceMock<MockRTNLHandler> rtnl_handler_; |
| 343 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 344 | MockDHCPProvider dhcp_provider_; |
| 345 | scoped_refptr<MockDHCPConfig> dhcp_config_; |
| 346 | |
| 347 | CellularRefPtr device_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 348 | scoped_ptr<MockModemProxy> proxy_; |
| 349 | scoped_ptr<MockModemSimpleProxy> simple_proxy_; |
| 350 | scoped_ptr<MockModemCDMAProxy> cdma_proxy_; |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 351 | scoped_ptr<MockModemGSMCardProxy> gsm_card_proxy_; |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 352 | scoped_ptr<MockModemGSMNetworkProxy> gsm_network_proxy_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 353 | TestProxyFactory proxy_factory_; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 354 | mobile_provider_db *provider_db_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 355 | }; |
| 356 | |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 357 | const char CellularTest::kTestDeviceName[] = "usb0"; |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 358 | const char CellularTest::kTestDeviceAddress[] = "00:01:02:03:04:05"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 359 | const char CellularTest::kDBusOwner[] = ":1.19"; |
| 360 | const char CellularTest::kDBusPath[] = "/org/chromium/ModemManager/Gobi/0"; |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 361 | const char CellularTest::kTestCarrier[] = "The Cellular Carrier"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 362 | const char CellularTest::kMEID[] = "01234567EF8901"; |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 363 | const char CellularTest::kIMEI[] = "987654321098765"; |
| 364 | const char CellularTest::kIMSI[] = "123456789012345"; |
| 365 | const char CellularTest::kMSISDN[] = "12345678901"; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 366 | const char CellularTest::kTestMobileProviderDBPath[] = |
| 367 | "provider_db_unittest.bfd"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 368 | const int CellularTest::kStrength = 90; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 369 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 370 | TEST_F(CellularTest, GetStateString) { |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 371 | EXPECT_EQ("CellularStateDisabled", |
| 372 | device_->GetStateString(Cellular::kStateDisabled)); |
| 373 | EXPECT_EQ("CellularStateEnabled", |
| 374 | device_->GetStateString(Cellular::kStateEnabled)); |
| 375 | EXPECT_EQ("CellularStateRegistered", |
| 376 | device_->GetStateString(Cellular::kStateRegistered)); |
| 377 | EXPECT_EQ("CellularStateConnected", |
| 378 | device_->GetStateString(Cellular::kStateConnected)); |
| 379 | EXPECT_EQ("CellularStateLinked", |
| 380 | device_->GetStateString(Cellular::kStateLinked)); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 383 | TEST_F(CellularTest, StartCDMARegister) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 384 | SetCellularType(Cellular::kTypeCDMA); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 385 | ExpectCdmaStartModem(flimflam::kNetworkTechnology1Xrtt); |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 386 | EXPECT_CALL(*cdma_proxy_, MEID()).WillOnce(Return(kMEID)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 387 | Error error; |
| 388 | device_->Start(&error, Bind(&CellularTest::TestCallback, Unretained(this))); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 389 | dispatcher_.DispatchPendingEvents(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 390 | EXPECT_EQ(kMEID, device_->capability_->meid_); |
| 391 | EXPECT_EQ(kTestCarrier, device_->capability_->carrier_); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 392 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 393 | ASSERT_TRUE(device_->service_.get()); |
| 394 | EXPECT_EQ(flimflam::kNetworkTechnology1Xrtt, |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 395 | device_->service_->network_technology()); |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 396 | EXPECT_EQ(kStrength, device_->service_->strength()); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 397 | EXPECT_EQ(flimflam::kRoamingStateHome, device_->service_->roaming_state()); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 400 | TEST_F(CellularTest, StartGSMRegister) { |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 401 | provider_db_ = mobile_provider_open_db(kTestMobileProviderDBPath); |
| 402 | ASSERT_TRUE(provider_db_); |
| 403 | device_->provider_db_ = provider_db_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 404 | EXPECT_CALL(*proxy_, Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 405 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
| 406 | EXPECT_CALL(*gsm_network_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 407 | Register("", _, _, CellularCapability::kTimeoutRegister)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 408 | .WillOnce(Invoke(this, &CellularTest::InvokeRegister)); |
| 409 | EXPECT_CALL(*simple_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 410 | GetModemStatus(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 411 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemStatus)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 412 | EXPECT_CALL(*gsm_card_proxy_, |
| 413 | GetIMEI(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 414 | .WillOnce(Invoke(this, &CellularTest::InvokeGetIMEI)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 415 | EXPECT_CALL(*gsm_card_proxy_, |
| 416 | GetIMSI(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 417 | .WillOnce(Invoke(this, &CellularTest::InvokeGetIMSI)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 418 | EXPECT_CALL(*gsm_card_proxy_, |
| 419 | GetSPN(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 420 | .WillOnce(Invoke(this, &CellularTest::InvokeGetSPN)); |
| 421 | EXPECT_CALL(*gsm_card_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 422 | GetMSISDN(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 423 | .WillOnce(Invoke(this, &CellularTest::InvokeGetMSISDN)); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 424 | EXPECT_CALL(*gsm_network_proxy_, AccessTechnology()) |
| 425 | .WillOnce(Return(MM_MODEM_GSM_ACCESS_TECH_EDGE)); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 426 | EXPECT_CALL(*gsm_card_proxy_, EnabledFacilityLocks()) |
| 427 | .WillOnce(Return(MM_MODEM_GSM_FACILITY_SIM)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 428 | EXPECT_CALL(*proxy_, GetModemInfo(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 429 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemInfo)); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 430 | static const char kNetworkID[] = "22803"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 431 | EXPECT_CALL(*gsm_network_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 432 | GetRegistrationInfo(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 433 | .WillOnce(Invoke(this, &CellularTest::InvokeGetRegistrationInfo)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 434 | EXPECT_CALL(*gsm_network_proxy_, GetSignalQuality(NULL, _, _)) |
| 435 | .Times(2) |
| 436 | .WillRepeatedly(Invoke(this, |
| 437 | &CellularTest::InvokeGetSignalQuality)); |
| 438 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 439 | Error error; |
| 440 | device_->Start(&error, Bind(&CellularTest::TestCallback, Unretained(this))); |
| 441 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 442 | dispatcher_.DispatchPendingEvents(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 443 | EXPECT_EQ(kIMEI, device_->capability_->imei_); |
| 444 | EXPECT_EQ(kIMSI, device_->capability_->imsi_); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 445 | EXPECT_EQ(kTestCarrier, GetCapabilityGSM()->spn_); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 446 | EXPECT_EQ(kMSISDN, device_->capability_->mdn_); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 447 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
| 448 | ASSERT_TRUE(device_->service_.get()); |
| 449 | EXPECT_EQ(flimflam::kNetworkTechnologyEdge, |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 450 | device_->service_->network_technology()); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 451 | EXPECT_TRUE(GetCapabilityGSM()->sim_lock_status_.enabled); |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 452 | EXPECT_EQ(kStrength, device_->service_->strength()); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 453 | EXPECT_EQ(flimflam::kRoamingStateRoaming, device_->service_->roaming_state()); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 454 | EXPECT_EQ(kNetworkID, device_->service_->serving_operator().GetCode()); |
| 455 | EXPECT_EQ("Orange", device_->service_->serving_operator().GetName()); |
| 456 | EXPECT_EQ("ch", device_->service_->serving_operator().GetCountry()); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 459 | TEST_F(CellularTest, StartConnected) { |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 460 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
| 461 | .WillOnce(Return(true)); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 462 | SetCellularType(Cellular::kTypeCDMA); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 463 | device_->set_modem_state(Cellular::kModemStateConnected); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 464 | device_->capability_->meid_ = kMEID; |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 465 | ExpectCdmaStartModem(flimflam::kNetworkTechnologyEvdo); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 466 | Error error; |
| 467 | device_->Start(&error, Bind(&CellularTest::TestCallback, Unretained(this))); |
| 468 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 469 | dispatcher_.DispatchPendingEvents(); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 470 | EXPECT_EQ(Cellular::kStateConnected, device_->state_); |
| 471 | } |
| 472 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 473 | TEST_F(CellularTest, StartLinked) { |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 474 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
| 475 | .WillOnce(DoAll(SetArgumentPointee<1>(IFF_UP), Return(true))); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 476 | SetCellularType(Cellular::kTypeCDMA); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 477 | device_->set_modem_state(Cellular::kModemStateConnected); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 478 | device_->capability_->meid_ = kMEID; |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 479 | ExpectCdmaStartModem(flimflam::kNetworkTechnologyEvdo); |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 480 | EXPECT_CALL(dhcp_provider_, CreateConfig(kTestDeviceName, _)) |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 481 | .WillOnce(Return(dhcp_config_)); |
| 482 | EXPECT_CALL(*dhcp_config_, RequestIP()).WillOnce(Return(true)); |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 483 | EXPECT_CALL(manager_, UpdateService(_)).Times(2); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 484 | Error error; |
| 485 | device_->Start(&error, Bind(&CellularTest::TestCallback, Unretained(this))); |
| 486 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 487 | dispatcher_.DispatchPendingEvents(); |
| 488 | EXPECT_EQ(Cellular::kStateLinked, device_->state_); |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 489 | EXPECT_EQ(Service::kStateConfiguring, device_->service_->state()); |
| 490 | device_->SelectService(NULL); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 493 | TEST_F(CellularTest, CreateService) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 494 | SetCellularType(Cellular::kTypeCDMA); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 495 | static const char kPaymentURL[] = "https://payment.url"; |
| 496 | static const char kUsageURL[] = "https://usage.url"; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 497 | device_->home_provider_.SetName(kTestCarrier); |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 498 | GetCapabilityCDMA()->olp_.SetURL(kPaymentURL); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 499 | GetCapabilityCDMA()->usage_url_ = kUsageURL; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 500 | device_->CreateService(); |
| 501 | ASSERT_TRUE(device_->service_.get()); |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 502 | EXPECT_EQ(kPaymentURL, device_->service_->olp().GetURL()); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 503 | EXPECT_EQ(kUsageURL, device_->service_->usage_url()); |
| 504 | EXPECT_EQ(kTestCarrier, device_->service_->serving_operator().GetName()); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 505 | EXPECT_TRUE(device_->service_->TechnologyIs(Technology::kCellular)); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 508 | namespace { |
| 509 | |
| 510 | MATCHER(ContainsPhoneNumber, "") { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 511 | return ContainsKey(arg, CellularCapability::kConnectPropertyPhoneNumber); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 514 | } // namespace |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 515 | |
| 516 | TEST_F(CellularTest, Connect) { |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 517 | Error error; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 518 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 519 | .Times(2) |
| 520 | .WillRepeatedly(Return(true)); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 521 | device_->state_ = Cellular::kStateConnected; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 522 | device_->Connect(&error); |
| 523 | EXPECT_EQ(Error::kAlreadyConnected, error.type()); |
| 524 | error.Populate(Error::kSuccess); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 525 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 526 | device_->state_ = Cellular::kStateLinked; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 527 | device_->Connect(&error); |
| 528 | EXPECT_EQ(Error::kAlreadyConnected, error.type()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 529 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 530 | device_->state_ = Cellular::kStateRegistered; |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 531 | device_->service_ = new CellularService( |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 532 | &control_interface_, &dispatcher_, &metrics_, &manager_, device_); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 533 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 534 | device_->capability_->allow_roaming_ = false; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 535 | device_->service_->roaming_state_ = flimflam::kRoamingStateRoaming; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 536 | device_->Connect(&error); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 537 | EXPECT_EQ(Error::kNotOnHomeNetwork, error.type()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 538 | |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 539 | error.Populate(Error::kSuccess); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 540 | EXPECT_CALL(*simple_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 541 | Connect(ContainsPhoneNumber(), _, _, |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 542 | CellularCapability::kTimeoutConnect)) |
| 543 | .Times(2) |
| 544 | .WillRepeatedly(Invoke(this, &CellularTest::InvokeConnect)); |
| 545 | device_->capability_->simple_proxy_.reset(simple_proxy_.release()); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 546 | device_->service_->roaming_state_ = flimflam::kRoamingStateHome; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 547 | device_->state_ = Cellular::kStateRegistered; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 548 | device_->Connect(&error); |
| 549 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 550 | dispatcher_.DispatchPendingEvents(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 551 | EXPECT_EQ(Cellular::kStateConnected, device_->state_); |
| 552 | |
| 553 | device_->capability_->allow_roaming_ = true; |
| 554 | device_->service_->roaming_state_ = flimflam::kRoamingStateRoaming; |
| 555 | device_->state_ = Cellular::kStateRegistered; |
| 556 | device_->Connect(&error); |
| 557 | EXPECT_TRUE(error.IsSuccess()); |
| 558 | dispatcher_.DispatchPendingEvents(); |
| 559 | EXPECT_EQ(Cellular::kStateConnected, device_->state_); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 562 | TEST_F(CellularTest, Disconnect) { |
| 563 | Error error; |
| 564 | device_->state_ = Cellular::kStateRegistered; |
| 565 | device_->Disconnect(&error); |
| 566 | EXPECT_EQ(Error::kNotConnected, error.type()); |
| 567 | error.Reset(); |
| 568 | |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 569 | device_->state_ = Cellular::kStateConnected; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 570 | EXPECT_CALL(*proxy_, |
| 571 | Disconnect(_, _, CellularCapability::kTimeoutDefault)) |
| 572 | .WillOnce(Invoke(this, &CellularTest::InvokeDisconnect)); |
| 573 | device_->capability_->proxy_.reset(proxy_.release()); |
| 574 | device_->Disconnect(&error); |
| 575 | EXPECT_TRUE(error.IsSuccess()); |
| 576 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 577 | } |
| 578 | |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 579 | TEST_F(CellularTest, ConnectFailure) { |
| 580 | SetCellularType(Cellular::kTypeCDMA); |
| 581 | device_->state_ = Cellular::kStateRegistered; |
| 582 | device_->service_ = new CellularService( |
| 583 | &control_interface_, &dispatcher_, &metrics_, &manager_, device_); |
| 584 | ASSERT_EQ(Service::kStateIdle, device_->service_->state()); |
| 585 | EXPECT_CALL(*simple_proxy_, |
| 586 | Connect(_, _, _, CellularCapability::kTimeoutConnect)) |
| 587 | .WillOnce(Invoke(this, &CellularTest::InvokeConnectFail)); |
| 588 | device_->capability_->simple_proxy_.reset(simple_proxy_.release()); |
| 589 | Error error; |
| 590 | device_->Connect(&error); |
| 591 | EXPECT_EQ(Service::kStateFailure, device_->service_->state()); |
| 592 | } |
| 593 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 594 | } // namespace shill |