Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 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> |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 13 | |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 14 | #include "shill/cellular_bearer.h" |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 15 | #include "shill/cellular_capability_cdma.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 16 | #include "shill/cellular_capability_classic.h" |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 17 | #include "shill/cellular_capability_gsm.h" |
Ben Chan | 09fa2a0 | 2012-11-07 22:09:09 -0800 | [diff] [blame] | 18 | #include "shill/cellular_capability_universal.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" |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 22 | #include "shill/mock_adaptors.h" |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 23 | #include "shill/mock_cellular_service.h" |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 24 | #include "shill/mock_dbus_properties_proxy.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 25 | #include "shill/mock_device_info.h" |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 26 | #include "shill/mock_dhcp_config.h" |
| 27 | #include "shill/mock_dhcp_provider.h" |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 28 | #include "shill/mock_external_task.h" |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 29 | #include "shill/mock_mm1_modem_modem3gpp_proxy.h" |
| 30 | #include "shill/mock_mm1_modem_proxy.h" |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 31 | #include "shill/mock_mm1_modem_simple_proxy.h" |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 32 | #include "shill/mock_modem_cdma_proxy.h" |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 33 | #include "shill/mock_modem_gsm_card_proxy.h" |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 34 | #include "shill/mock_modem_gsm_network_proxy.h" |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 35 | #include "shill/mock_modem_info.h" |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 36 | #include "shill/mock_modem_proxy.h" |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 37 | #include "shill/mock_modem_simple_proxy.h" |
mukesh agrawal | 5d851b1 | 2013-07-11 14:09:41 -0700 | [diff] [blame] | 38 | #include "shill/mock_ppp_device.h" |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 39 | #include "shill/mock_ppp_device_factory.h" |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 40 | #include "shill/mock_rtnl_handler.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 41 | #include "shill/property_store_unittest.h" |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 42 | #include "shill/proxy_factory.h" |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 43 | #include "shill/rpc_task.h" // for RpcTaskDelegate |
Ben Chan | be277dd | 2014-02-05 17:26:47 -0800 | [diff] [blame] | 44 | #include "shill/testing.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 45 | |
Ben Chan | 09fa2a0 | 2012-11-07 22:09:09 -0800 | [diff] [blame] | 46 | // mm/mm-modem.h must be included after cellular_capability_universal.h |
| 47 | // in order to allow MM_MODEM_CDMA_* to be defined properly. |
| 48 | #include <mm/mm-modem.h> |
| 49 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 50 | using base::Bind; |
| 51 | using base::Unretained; |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 52 | using std::map; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 53 | using std::string; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 54 | using std::vector; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 55 | using testing::_; |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 56 | using testing::AnyNumber; |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 57 | using testing::DoAll; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 58 | using testing::Invoke; |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 59 | using testing::Mock; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 60 | using testing::NiceMock; |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 61 | using testing::Return; |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 62 | using testing::SaveArg; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 63 | using testing::SetArgumentPointee; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 64 | using testing::Unused; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 65 | |
| 66 | namespace shill { |
| 67 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 68 | class CellularPropertyTest : public PropertyStoreTest { |
| 69 | public: |
| 70 | CellularPropertyTest() |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 71 | : modem_info_(control_interface(), |
| 72 | dispatcher(), |
| 73 | metrics(), |
| 74 | manager(), |
| 75 | glib()), |
| 76 | device_(new Cellular(&modem_info_, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 77 | "usb0", |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 78 | "00:01:02:03:04:05", |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 79 | 3, |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 80 | Cellular::kTypeCDMA, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 81 | "", |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 82 | "", |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 83 | "", |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 84 | ProxyFactory::GetInstance())) {} |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 85 | virtual ~CellularPropertyTest() {} |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 86 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 87 | protected: |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 88 | MockModemInfo modem_info_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 89 | DeviceRefPtr device_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 92 | TEST_F(CellularPropertyTest, Contains) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 93 | EXPECT_TRUE(device_->store().Contains(kNameProperty)); |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 94 | EXPECT_FALSE(device_->store().Contains("")); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 95 | } |
| 96 | |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 97 | TEST_F(CellularPropertyTest, SetProperty) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 98 | { |
| 99 | ::DBus::Error error; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 100 | ::DBus::Variant allow_roaming; |
| 101 | allow_roaming.writer().append_bool(true); |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 102 | EXPECT_TRUE(DBusAdaptor::SetProperty( |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 103 | device_->mutable_store(), |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 104 | kCellularAllowRoamingProperty, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 105 | allow_roaming, |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 106 | &error)); |
| 107 | } |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 108 | // Ensure that attempting to write a R/O property returns InvalidArgs error. |
| 109 | { |
| 110 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 111 | EXPECT_FALSE(DBusAdaptor::SetProperty(device_->mutable_store(), |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 112 | kAddressProperty, |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 113 | PropertyStoreTest::kStringV, |
| 114 | &error)); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 115 | ASSERT_TRUE(error.is_set()); // name() may be invalid otherwise |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 116 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 117 | } |
| 118 | { |
| 119 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 120 | EXPECT_FALSE(DBusAdaptor::SetProperty(device_->mutable_store(), |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 121 | kCarrierProperty, |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 122 | PropertyStoreTest::kStringV, |
| 123 | &error)); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 124 | ASSERT_TRUE(error.is_set()); // name() may be invalid otherwise |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 125 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 126 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 129 | class CellularTest : public testing::Test { |
| 130 | public: |
| 131 | CellularTest() |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 132 | : modem_info_(NULL, &dispatcher_, NULL, NULL, NULL), |
| 133 | device_info_(modem_info_.control_interface(), &dispatcher_, |
| 134 | modem_info_.metrics(), modem_info_.manager()), |
| 135 | dhcp_config_(new MockDHCPConfig(modem_info_.control_interface(), |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 136 | kTestDeviceName)), |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 137 | create_gsm_card_proxy_from_factory_(false), |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 138 | proxy_factory_(this), |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 139 | device_(new Cellular(&modem_info_, |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 140 | kTestDeviceName, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 141 | kTestDeviceAddress, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 142 | 3, |
| 143 | Cellular::kTypeGSM, |
| 144 | kDBusOwner, |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 145 | kDBusService, |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 146 | kDBusPath, |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 147 | &proxy_factory_)) { |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 148 | PopulateProxies(); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 149 | modem_info_.metrics()->RegisterDevice(device_->interface_index(), |
| 150 | Technology::kCellular); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 151 | } |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 152 | |
| 153 | virtual void SetUp() { |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 154 | static_cast<Device *>(device_)->rtnl_handler_ = &rtnl_handler_; |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 155 | device_->set_dhcp_provider(&dhcp_provider_); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 156 | EXPECT_CALL(*modem_info_.mock_manager(), device_info()) |
| 157 | .WillRepeatedly(Return(&device_info_)); |
| 158 | EXPECT_CALL(*modem_info_.mock_manager(), DeregisterService(_)) |
| 159 | .Times(AnyNumber()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | virtual void TearDown() { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 163 | device_->DestroyIPConfig(); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 164 | device_->state_ = Cellular::kStateDisabled; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 165 | device_->capability_->ReleaseProxies(); |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 166 | device_->set_dhcp_provider(NULL); |
mukesh agrawal | 0381f9a | 2013-07-11 16:41:52 -0700 | [diff] [blame] | 167 | // Break cycle between Cellular and CellularService. |
| 168 | device_->service_ = NULL; |
| 169 | device_->SelectService(NULL); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 170 | } |
| 171 | |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 172 | void PopulateProxies() { |
| 173 | dbus_properties_proxy_.reset(new MockDBusPropertiesProxy()); |
| 174 | proxy_.reset(new MockModemProxy()); |
| 175 | simple_proxy_.reset(new MockModemSimpleProxy()); |
| 176 | cdma_proxy_.reset(new MockModemCDMAProxy()); |
| 177 | gsm_card_proxy_.reset(new MockModemGSMCardProxy()); |
| 178 | gsm_network_proxy_.reset(new MockModemGSMNetworkProxy()); |
| 179 | mm1_modem_3gpp_proxy_.reset(new mm1::MockModemModem3gppProxy()); |
| 180 | mm1_proxy_.reset(new mm1::MockModemProxy()); |
| 181 | mm1_simple_proxy_.reset(new mm1::MockModemSimpleProxy()); |
| 182 | } |
| 183 | |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 184 | void InitProviderDB() { |
| 185 | modem_info_.SetProviderDB(kTestMobileProviderDBPath); |
| 186 | } |
| 187 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 188 | void InvokeEnable(bool enable, Error *error, |
| 189 | const ResultCallback &callback, int timeout) { |
| 190 | callback.Run(Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 191 | } |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 192 | void InvokeEnableReturningWrongState( |
| 193 | bool enable, Error *error, const ResultCallback &callback, int timeout) { |
| 194 | callback.Run(Error(Error::kWrongState)); |
| 195 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 196 | void InvokeGetSignalQuality(Error *error, |
| 197 | const SignalQualityCallback &callback, |
| 198 | int timeout) { |
| 199 | callback.Run(kStrength, Error()); |
| 200 | } |
| 201 | void InvokeGetModemStatus(Error *error, |
| 202 | const DBusPropertyMapCallback &callback, |
| 203 | int timeout) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 204 | DBusPropertiesMap props; |
| 205 | props["carrier"].writer().append_string(kTestCarrier); |
| 206 | props["unknown-property"].writer().append_string("irrelevant-value"); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 207 | callback.Run(props, 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 InvokeGetModemInfo(Error *error, const ModemInfoCallback &callback, |
| 210 | int timeout) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 211 | static const char kManufacturer[] = "Company"; |
| 212 | static const char kModelID[] = "Gobi 2000"; |
| 213 | static const char kHWRev[] = "A00B1234"; |
| 214 | ModemHardwareInfo info; |
| 215 | info._1 = kManufacturer; |
| 216 | info._2 = kModelID; |
| 217 | info._3 = kHWRev; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 218 | callback.Run(info, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 219 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 220 | void InvokeGetRegistrationState1X(Error *error, |
| 221 | const RegistrationStateCallback &callback, |
| 222 | int timeout) { |
| 223 | callback.Run(MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
| 224 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 225 | Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 226 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 227 | void InvokeGetIMEI(Error *error, const GSMIdentifierCallback &callback, |
| 228 | int timeout) { |
| 229 | callback.Run(kIMEI, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 230 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 231 | void InvokeGetIMSI(Error *error, const GSMIdentifierCallback &callback, |
| 232 | int timeout) { |
| 233 | callback.Run(kIMSI, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 234 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 235 | void InvokeGetMSISDN(Error *error, const GSMIdentifierCallback &callback, |
| 236 | int timeout) { |
| 237 | callback.Run(kMSISDN, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 238 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 239 | void InvokeGetSPN(Error *error, const GSMIdentifierCallback &callback, |
| 240 | int timeout) { |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 241 | callback.Run(kTestCarrierSPN, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 242 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 243 | void InvokeGetRegistrationInfo(Error *error, |
| 244 | const RegistrationInfoCallback &callback, |
| 245 | int timeout) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 246 | static const char kNetworkID[] = "22803"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 247 | callback.Run(MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING, |
| 248 | kNetworkID, kTestCarrier, Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 249 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 250 | void InvokeRegister(const string &network_id, |
| 251 | Error *error, |
| 252 | const ResultCallback &callback, |
| 253 | int timeout) { |
| 254 | callback.Run(Error()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 255 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 256 | void InvokeGetRegistrationState(Error *error, |
| 257 | const RegistrationStateCallback &callback, |
| 258 | int timeout) { |
| 259 | callback.Run(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED, |
| 260 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
| 261 | Error()); |
| 262 | } |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 263 | void InvokeGetRegistrationStateUnregistered( |
| 264 | Error *error, |
| 265 | const RegistrationStateCallback &callback, |
| 266 | int timeout) { |
| 267 | callback.Run(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 268 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
| 269 | Error()); |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 270 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 271 | void InvokeConnect(DBusPropertiesMap props, Error *error, |
| 272 | const ResultCallback &callback, int timeout) { |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 273 | EXPECT_EQ(Service::kStateAssociating, device_->service_->state()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 274 | callback.Run(Error()); |
| 275 | } |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 276 | void InvokeConnectFail(DBusPropertiesMap props, Error *error, |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 277 | const ResultCallback &callback, int timeout) { |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 278 | EXPECT_EQ(Service::kStateAssociating, device_->service_->state()); |
| 279 | callback.Run(Error(Error::kNotOnHomeNetwork)); |
| 280 | } |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 281 | void InvokeConnectFailNoService(DBusPropertiesMap props, Error *error, |
| 282 | const ResultCallback &callback, int timeout) { |
| 283 | device_->service_ = NULL; |
| 284 | callback.Run(Error(Error::kNotOnHomeNetwork)); |
| 285 | } |
Thieu Le | d4974cd | 2013-05-23 10:39:28 -0700 | [diff] [blame] | 286 | void InvokeConnectSuccessNoService(DBusPropertiesMap props, Error *error, |
| 287 | const ResultCallback &callback, |
| 288 | int timeout) { |
| 289 | device_->service_ = NULL; |
| 290 | callback.Run(Error()); |
| 291 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 292 | void InvokeDisconnect(Error *error, const ResultCallback &callback, |
| 293 | int timeout) { |
| 294 | if (!callback.is_null()) |
| 295 | callback.Run(Error()); |
| 296 | } |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 297 | void InvokeDisconnectFail(Error *error, const ResultCallback &callback, |
| 298 | int timeout) { |
| 299 | error->Populate(Error::kOperationFailed); |
| 300 | if (!callback.is_null()) |
| 301 | callback.Run(*error); |
| 302 | } |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 303 | void InvokeDisconnectMM1(const ::DBus::Path &bearer, Error *error, |
| 304 | const ResultCallback &callback, int timeout) { |
| 305 | if (!callback.is_null()) |
| 306 | callback.Run(Error()); |
| 307 | } |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 308 | void InvokeScanFailed(Error *error, Unused, Unused) { |
| 309 | error->Populate(Error::kOperationFailed); |
| 310 | } |
| 311 | void InvokeScanInitiated(Error *error, Unused, Unused) { |
| 312 | error->Populate(Error::kOperationInitiated); |
| 313 | } |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 314 | void InvokeSetPowerState(const uint32_t &power_state, |
| 315 | Error *error, |
| 316 | const ResultCallback &callback, |
| 317 | int timeout) { |
| 318 | callback.Run(Error()); |
| 319 | } |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 320 | void ExpectCdmaStartModem(string network_technology) { |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 321 | if (!device_->IsUnderlyingDeviceEnabled()) |
| 322 | EXPECT_CALL(*proxy_, |
| 323 | Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 324 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 325 | EXPECT_CALL(*simple_proxy_, |
| 326 | GetModemStatus(_, _, CellularCapability::kTimeoutDefault)) |
| 327 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemStatus)); |
| 328 | EXPECT_CALL(*proxy_, |
| 329 | GetModemInfo(_, _, CellularCapability::kTimeoutDefault)) |
| 330 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemInfo)); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 331 | if (network_technology == kNetworkTechnology1Xrtt) |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 332 | EXPECT_CALL(*cdma_proxy_, GetRegistrationState(NULL, _, _)) |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 333 | .WillOnce(Invoke(this, &CellularTest::InvokeGetRegistrationState1X)); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 334 | else |
| 335 | EXPECT_CALL(*cdma_proxy_, GetRegistrationState(NULL, _, _)) |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 336 | .WillOnce(Invoke(this, &CellularTest::InvokeGetRegistrationState)); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 337 | EXPECT_CALL(*cdma_proxy_, GetSignalQuality(NULL, _, _)) |
| 338 | .Times(2) |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 339 | .WillRepeatedly(Invoke(this, &CellularTest::InvokeGetSignalQuality)); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 340 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 341 | EXPECT_CALL(*modem_info_.mock_manager(), RegisterService(_)); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 342 | } |
| 343 | |
mukesh agrawal | ee10f37 | 2013-08-14 14:07:11 -0700 | [diff] [blame] | 344 | void ExpectDisconnectCapabilityUniversal() { |
| 345 | SetCellularType(Cellular::kTypeUniversal); |
| 346 | device_->state_ = Cellular::kStateConnected; |
| 347 | EXPECT_CALL(*mm1_simple_proxy_, Disconnect(_, _, _, _)) |
| 348 | .WillOnce(Invoke(this, &CellularTest::InvokeDisconnectMM1)); |
| 349 | GetCapabilityUniversal()->modem_simple_proxy_.reset( |
| 350 | mm1_simple_proxy_.release()); |
mukesh agrawal | ee10f37 | 2013-08-14 14:07:11 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | void VerifyDisconnect() { |
| 354 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
| 355 | } |
| 356 | |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 357 | void StartPPP(int pid) { |
| 358 | MockGLib &mock_glib(*dynamic_cast<MockGLib *>(modem_info_.glib())); |
| 359 | EXPECT_CALL(mock_glib, ChildWatchAdd(pid, _, _)); |
| 360 | EXPECT_CALL(mock_glib, SpawnAsync(_, _, _, _, _, _, _, _)) |
| 361 | .WillOnce(DoAll(SetArgumentPointee<6>(pid), Return(true))); |
| 362 | device_->StartPPP("fake_serial_device"); |
| 363 | EXPECT_FALSE(device_->ipconfig()); // No DHCP client. |
| 364 | EXPECT_FALSE(device_->selected_service()); |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 365 | EXPECT_FALSE(device_->is_ppp_authenticating_); |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 366 | EXPECT_TRUE(device_->ppp_task_); |
| 367 | Mock::VerifyAndClearExpectations(&mock_glib); |
| 368 | } |
| 369 | |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 370 | void FakeUpConnectedPPP() { |
| 371 | const char kInterfaceName[] = "fake-ppp-device"; |
| 372 | const int kInterfaceIndex = -1; |
| 373 | auto mock_ppp_device = make_scoped_refptr(new MockPPPDevice( |
| 374 | modem_info_.control_interface(), NULL, NULL, NULL, kInterfaceName, |
| 375 | kInterfaceIndex)); |
| 376 | device_->ppp_device_ = mock_ppp_device; |
| 377 | device_->state_ = Cellular::kStateConnected; |
| 378 | } |
| 379 | |
| 380 | void ExpectPPPStopped() { |
| 381 | auto mock_ppp_device = |
| 382 | dynamic_cast<MockPPPDevice *>(device_->ppp_device_.get()); |
| 383 | EXPECT_CALL(*mock_ppp_device, DropConnection()); |
| 384 | } |
| 385 | |
| 386 | void VerifyPPPStopped() { |
| 387 | EXPECT_FALSE(device_->ppp_task_); |
| 388 | EXPECT_FALSE(device_->ppp_device_); |
| 389 | } |
| 390 | |
| 391 | void SetCommonOnAfterResumeExpectations() { |
| 392 | EXPECT_CALL(*dbus_properties_proxy_, GetAll(_)) |
| 393 | .WillRepeatedly(Return(DBusPropertiesMap())); |
| 394 | EXPECT_CALL(*mm1_proxy_, set_state_changed_callback(_)).Times(AnyNumber()); |
| 395 | EXPECT_CALL(*modem_info_.mock_metrics(), NotifyDeviceScanStarted(_)) |
| 396 | .Times(AnyNumber()); |
| 397 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
| 398 | GetOLPByMCCMNC(_)).Times(AnyNumber()); |
| 399 | EXPECT_CALL(*modem_info_.mock_manager(), UpdateEnabledTechnologies()) |
| 400 | .Times(AnyNumber()); |
| 401 | EXPECT_CALL(*dynamic_cast<DeviceMockAdaptor *>(device_->adaptor()), |
| 402 | EmitBoolChanged(_, _)).Times(AnyNumber()); |
| 403 | } |
| 404 | |
| 405 | mm1::MockModemProxy *SetupOnAfterResume() { |
| 406 | SetCellularType(Cellular::kTypeUniversal); |
| 407 | SetCommonOnAfterResumeExpectations(); |
| 408 | return mm1_proxy_.get(); // Before the capability snags it. |
| 409 | } |
| 410 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 411 | MOCK_METHOD1(TestCallback, void(const Error &error)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 412 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 413 | protected: |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 414 | static const char kTestDeviceName[]; |
| 415 | static const char kTestDeviceAddress[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 416 | static const char kDBusOwner[]; |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 417 | static const char kDBusService[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 418 | static const char kDBusPath[]; |
| 419 | static const char kTestCarrier[]; |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 420 | static const char kTestCarrierSPN[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 421 | static const char kMEID[]; |
| 422 | static const char kIMEI[]; |
| 423 | static const char kIMSI[]; |
| 424 | static const char kMSISDN[]; |
| 425 | static const char kTestMobileProviderDBPath[]; |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 426 | static const Stringmaps kTestNetworksGSM; |
| 427 | static const Stringmaps kTestNetworksCellular; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 428 | static const int kStrength; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 429 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 430 | class TestProxyFactory : public ProxyFactory { |
| 431 | public: |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 432 | explicit TestProxyFactory(CellularTest *test) : test_(test) {} |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 433 | |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 434 | virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy( |
| 435 | const std::string &path, |
| 436 | const std::string &service) { |
| 437 | return test_->dbus_properties_proxy_.release(); |
| 438 | } |
| 439 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 440 | virtual ModemProxyInterface *CreateModemProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 441 | const string &/*path*/, |
| 442 | const string &/*service*/) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 443 | return test_->proxy_.release(); |
| 444 | } |
| 445 | |
| 446 | virtual ModemSimpleProxyInterface *CreateModemSimpleProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 447 | const string &/*path*/, |
| 448 | const string &/*service*/) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 449 | return test_->simple_proxy_.release(); |
| 450 | } |
| 451 | |
| 452 | virtual ModemCDMAProxyInterface *CreateModemCDMAProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 453 | const string &/*path*/, |
| 454 | const string &/*service*/) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 455 | return test_->cdma_proxy_.release(); |
| 456 | } |
| 457 | |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 458 | virtual ModemGSMCardProxyInterface *CreateModemGSMCardProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 459 | const string &/*path*/, |
| 460 | const string &/*service*/) { |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 461 | // TODO(benchan): This code conditionally returns a NULL pointer to avoid |
| 462 | // CellularCapabilityGSM::InitProperties (and thus |
| 463 | // CellularCapabilityGSM::GetIMSI) from being called during the |
| 464 | // construction. Remove this workaround after refactoring the tests. |
| 465 | return test_->create_gsm_card_proxy_from_factory_ ? |
| 466 | test_->gsm_card_proxy_.release() : NULL; |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 469 | virtual ModemGSMNetworkProxyInterface *CreateModemGSMNetworkProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 470 | const string &/*path*/, |
| 471 | const string &/*service*/) { |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 472 | return test_->gsm_network_proxy_.release(); |
| 473 | } |
| 474 | |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 475 | virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy( |
| 476 | const std::string &path, |
| 477 | const std::string &service) { |
| 478 | return test_->mm1_modem_3gpp_proxy_.release(); |
| 479 | } |
| 480 | |
| 481 | virtual mm1::ModemProxyInterface *CreateMM1ModemProxy( |
| 482 | const std::string &path, |
| 483 | const std::string &service) { |
| 484 | return test_->mm1_proxy_.release(); |
| 485 | } |
| 486 | |
| 487 | virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy( |
| 488 | const string &/*path*/, |
| 489 | const string &/*service*/) { |
| 490 | return test_->mm1_simple_proxy_.release(); |
| 491 | } |
| 492 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 493 | private: |
| 494 | CellularTest *test_; |
| 495 | }; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 496 | void StartRTNLHandler(); |
| 497 | void StopRTNLHandler(); |
| 498 | |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 499 | void AllowCreateGSMCardProxyFromFactory() { |
| 500 | create_gsm_card_proxy_from_factory_ = true; |
| 501 | } |
| 502 | |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 503 | void SetCellularType(Cellular::Type type) { |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 504 | device_->InitCapability(type); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 505 | } |
| 506 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 507 | CellularCapabilityClassic *GetCapabilityClassic() { |
| 508 | return dynamic_cast<CellularCapabilityClassic *>( |
| 509 | device_->capability_.get()); |
| 510 | } |
| 511 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 512 | CellularCapabilityCDMA *GetCapabilityCDMA() { |
| 513 | return dynamic_cast<CellularCapabilityCDMA *>(device_->capability_.get()); |
| 514 | } |
| 515 | |
| 516 | CellularCapabilityGSM *GetCapabilityGSM() { |
| 517 | return dynamic_cast<CellularCapabilityGSM *>(device_->capability_.get()); |
| 518 | } |
| 519 | |
Ben Chan | 09fa2a0 | 2012-11-07 22:09:09 -0800 | [diff] [blame] | 520 | CellularCapabilityUniversal *GetCapabilityUniversal() { |
| 521 | return dynamic_cast<CellularCapabilityUniversal *>( |
| 522 | device_->capability_.get()); |
| 523 | } |
| 524 | |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 525 | // Different tests simulate a cellular service being set using a real /mock |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 526 | // service. |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 527 | CellularService *SetService() { |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 528 | device_->service_ = new CellularService(&modem_info_, device_); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 529 | return device_->service_; |
| 530 | } |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 531 | MockCellularService *SetMockService() { |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 532 | device_->service_ = new MockCellularService(&modem_info_, device_); |
| 533 | return static_cast<MockCellularService *>(device_->service_.get()); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 534 | } |
| 535 | |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 536 | void set_enabled_persistent(bool new_value) { |
| 537 | device_->enabled_persistent_ = new_value; |
| 538 | } |
| 539 | |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 540 | void SetCapabilityUniversalActiveBearer(scoped_ptr<CellularBearer> bearer) { |
| 541 | SetCellularType(Cellular::kTypeUniversal); |
| 542 | CellularCapabilityUniversal *capability = GetCapabilityUniversal(); |
| 543 | capability->active_bearer_ = bearer.Pass(); |
| 544 | } |
| 545 | |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 546 | EventDispatcher dispatcher_; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 547 | MockModemInfo modem_info_; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 548 | MockDeviceInfo device_info_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 549 | NiceMock<MockRTNLHandler> rtnl_handler_; |
| 550 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 551 | MockDHCPProvider dhcp_provider_; |
| 552 | scoped_refptr<MockDHCPConfig> dhcp_config_; |
| 553 | |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 554 | bool create_gsm_card_proxy_from_factory_; |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 555 | scoped_ptr<MockDBusPropertiesProxy> dbus_properties_proxy_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 556 | scoped_ptr<MockModemProxy> proxy_; |
| 557 | scoped_ptr<MockModemSimpleProxy> simple_proxy_; |
| 558 | scoped_ptr<MockModemCDMAProxy> cdma_proxy_; |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 559 | scoped_ptr<MockModemGSMCardProxy> gsm_card_proxy_; |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 560 | scoped_ptr<MockModemGSMNetworkProxy> gsm_network_proxy_; |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 561 | scoped_ptr<mm1::MockModemModem3gppProxy> mm1_modem_3gpp_proxy_; |
| 562 | scoped_ptr<mm1::MockModemProxy> mm1_proxy_; |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 563 | scoped_ptr<mm1::MockModemSimpleProxy> mm1_simple_proxy_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 564 | TestProxyFactory proxy_factory_; |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 565 | CellularRefPtr device_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 566 | }; |
| 567 | |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 568 | const char CellularTest::kTestDeviceName[] = "usb0"; |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 569 | const char CellularTest::kTestDeviceAddress[] = "00:01:02:03:04:05"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 570 | const char CellularTest::kDBusOwner[] = ":1.19"; |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 571 | const char CellularTest::kDBusService[] = "org.chromium.ModemManager"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 572 | const char CellularTest::kDBusPath[] = "/org/chromium/ModemManager/Gobi/0"; |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 573 | const char CellularTest::kTestCarrier[] = "The Cellular Carrier"; |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 574 | const char CellularTest::kTestCarrierSPN[] = "Home Provider"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 575 | const char CellularTest::kMEID[] = "01234567EF8901"; |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 576 | const char CellularTest::kIMEI[] = "987654321098765"; |
| 577 | const char CellularTest::kIMSI[] = "123456789012345"; |
| 578 | const char CellularTest::kMSISDN[] = "12345678901"; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 579 | const char CellularTest::kTestMobileProviderDBPath[] = |
| 580 | "provider_db_unittest.bfd"; |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 581 | const Stringmaps CellularTest::kTestNetworksGSM = |
| 582 | {{{CellularCapabilityGSM::kNetworkPropertyStatus, "1"}, |
| 583 | {CellularCapabilityGSM::kNetworkPropertyID, "0000"}, |
| 584 | {CellularCapabilityGSM::kNetworkPropertyLongName, "some_long_name"}, |
| 585 | {CellularCapabilityGSM::kNetworkPropertyShortName, "short"}}}; |
| 586 | const Stringmaps CellularTest::kTestNetworksCellular = |
| 587 | {{{kStatusProperty, "available"}, |
| 588 | {kNetworkIdProperty, "0000"}, |
| 589 | {kLongNameProperty, "some_long_name"}, |
| 590 | {kShortNameProperty, "short"}}}; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 591 | const int CellularTest::kStrength = 90; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 592 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 593 | TEST_F(CellularTest, GetStateString) { |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 594 | EXPECT_EQ("CellularStateDisabled", |
Ben Chan | f45b323 | 2013-10-08 20:54:01 -0700 | [diff] [blame] | 595 | Cellular::GetStateString(Cellular::kStateDisabled)); |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 596 | EXPECT_EQ("CellularStateEnabled", |
Ben Chan | f45b323 | 2013-10-08 20:54:01 -0700 | [diff] [blame] | 597 | Cellular::GetStateString(Cellular::kStateEnabled)); |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 598 | EXPECT_EQ("CellularStateRegistered", |
Ben Chan | f45b323 | 2013-10-08 20:54:01 -0700 | [diff] [blame] | 599 | Cellular::GetStateString(Cellular::kStateRegistered)); |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 600 | EXPECT_EQ("CellularStateConnected", |
Ben Chan | f45b323 | 2013-10-08 20:54:01 -0700 | [diff] [blame] | 601 | Cellular::GetStateString(Cellular::kStateConnected)); |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 602 | EXPECT_EQ("CellularStateLinked", |
Ben Chan | f45b323 | 2013-10-08 20:54:01 -0700 | [diff] [blame] | 603 | Cellular::GetStateString(Cellular::kStateLinked)); |
| 604 | } |
| 605 | |
| 606 | TEST_F(CellularTest, GetModemStateString) { |
Ben Chan | 7b7d63d | 2013-10-18 14:53:05 -0700 | [diff] [blame] | 607 | EXPECT_EQ("CellularModemStateFailed", |
| 608 | Cellular::GetModemStateString(Cellular::kModemStateFailed)); |
Ben Chan | f45b323 | 2013-10-08 20:54:01 -0700 | [diff] [blame] | 609 | EXPECT_EQ("CellularModemStateUnknown", |
| 610 | Cellular::GetModemStateString(Cellular::kModemStateUnknown)); |
| 611 | EXPECT_EQ("CellularModemStateInitializing", |
| 612 | Cellular::GetModemStateString(Cellular::kModemStateInitializing)); |
| 613 | EXPECT_EQ("CellularModemStateLocked", |
| 614 | Cellular::GetModemStateString(Cellular::kModemStateLocked)); |
| 615 | EXPECT_EQ("CellularModemStateDisabled", |
| 616 | Cellular::GetModemStateString(Cellular::kModemStateDisabled)); |
| 617 | EXPECT_EQ("CellularModemStateDisabling", |
| 618 | Cellular::GetModemStateString(Cellular::kModemStateDisabling)); |
| 619 | EXPECT_EQ("CellularModemStateEnabling", |
| 620 | Cellular::GetModemStateString(Cellular::kModemStateEnabling)); |
| 621 | EXPECT_EQ("CellularModemStateEnabled", |
| 622 | Cellular::GetModemStateString(Cellular::kModemStateEnabled)); |
| 623 | EXPECT_EQ("CellularModemStateSearching", |
| 624 | Cellular::GetModemStateString(Cellular::kModemStateSearching)); |
| 625 | EXPECT_EQ("CellularModemStateRegistered", |
| 626 | Cellular::GetModemStateString(Cellular::kModemStateRegistered)); |
| 627 | EXPECT_EQ("CellularModemStateDisconnecting", |
| 628 | Cellular::GetModemStateString(Cellular::kModemStateDisconnecting)); |
| 629 | EXPECT_EQ("CellularModemStateConnecting", |
| 630 | Cellular::GetModemStateString(Cellular::kModemStateConnecting)); |
| 631 | EXPECT_EQ("CellularModemStateConnected", |
| 632 | Cellular::GetModemStateString(Cellular::kModemStateConnected)); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 635 | TEST_F(CellularTest, StartCDMARegister) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 636 | SetCellularType(Cellular::kTypeCDMA); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 637 | ExpectCdmaStartModem(kNetworkTechnology1Xrtt); |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 638 | EXPECT_CALL(*cdma_proxy_, MEID()).WillOnce(Return(kMEID)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 639 | Error error; |
| 640 | device_->Start(&error, Bind(&CellularTest::TestCallback, Unretained(this))); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 641 | dispatcher_.DispatchPendingEvents(); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 642 | EXPECT_EQ(kMEID, device_->meid()); |
| 643 | EXPECT_EQ(kTestCarrier, device_->carrier()); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 644 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 645 | ASSERT_TRUE(device_->service_.get()); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 646 | EXPECT_EQ(kNetworkTechnology1Xrtt, device_->service_->network_technology()); |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 647 | EXPECT_EQ(kStrength, device_->service_->strength()); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 648 | EXPECT_EQ(kRoamingStateHome, device_->service_->roaming_state()); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 651 | TEST_F(CellularTest, StartGSMRegister) { |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 652 | InitProviderDB(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 653 | EXPECT_CALL(*proxy_, Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 654 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 655 | EXPECT_CALL(*gsm_card_proxy_, |
| 656 | GetIMEI(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 657 | .WillOnce(Invoke(this, &CellularTest::InvokeGetIMEI)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 658 | EXPECT_CALL(*gsm_card_proxy_, |
| 659 | GetIMSI(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 660 | .WillOnce(Invoke(this, &CellularTest::InvokeGetIMSI)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 661 | EXPECT_CALL(*gsm_card_proxy_, |
| 662 | GetSPN(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 663 | .WillOnce(Invoke(this, &CellularTest::InvokeGetSPN)); |
| 664 | EXPECT_CALL(*gsm_card_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 665 | GetMSISDN(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 666 | .WillOnce(Invoke(this, &CellularTest::InvokeGetMSISDN)); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 667 | EXPECT_CALL(*gsm_network_proxy_, AccessTechnology()) |
| 668 | .WillOnce(Return(MM_MODEM_GSM_ACCESS_TECH_EDGE)); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 669 | EXPECT_CALL(*gsm_card_proxy_, EnabledFacilityLocks()) |
| 670 | .WillOnce(Return(MM_MODEM_GSM_FACILITY_SIM)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 671 | EXPECT_CALL(*proxy_, GetModemInfo(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 672 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemInfo)); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 673 | static const char kNetworkID[] = "22803"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 674 | EXPECT_CALL(*gsm_network_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 675 | GetRegistrationInfo(_, _, CellularCapability::kTimeoutDefault)) |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 676 | .WillOnce(Invoke(this, &CellularTest::InvokeGetRegistrationInfo)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 677 | EXPECT_CALL(*gsm_network_proxy_, GetSignalQuality(NULL, _, _)) |
| 678 | .Times(2) |
| 679 | .WillRepeatedly(Invoke(this, |
| 680 | &CellularTest::InvokeGetSignalQuality)); |
| 681 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 682 | EXPECT_CALL(*modem_info_.mock_manager(), RegisterService(_)); |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 683 | AllowCreateGSMCardProxyFromFactory(); |
| 684 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 685 | Error error; |
| 686 | device_->Start(&error, Bind(&CellularTest::TestCallback, Unretained(this))); |
| 687 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 688 | dispatcher_.DispatchPendingEvents(); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 689 | EXPECT_EQ(kIMEI, device_->imei()); |
| 690 | EXPECT_EQ(kIMSI, device_->imsi()); |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 691 | EXPECT_EQ(kTestCarrierSPN, GetCapabilityGSM()->spn_); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 692 | EXPECT_EQ(kMSISDN, device_->mdn()); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 693 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
| 694 | ASSERT_TRUE(device_->service_.get()); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 695 | EXPECT_EQ(kNetworkTechnologyEdge, device_->service_->network_technology()); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 696 | EXPECT_TRUE(GetCapabilityGSM()->sim_lock_status_.enabled); |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 697 | EXPECT_EQ(kStrength, device_->service_->strength()); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 698 | EXPECT_EQ(kRoamingStateRoaming, device_->service_->roaming_state()); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 699 | EXPECT_EQ(kNetworkID, device_->service_->serving_operator().GetCode()); |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 700 | EXPECT_EQ(kTestCarrier, device_->service_->serving_operator().GetName()); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 701 | EXPECT_EQ("ch", device_->service_->serving_operator().GetCountry()); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 704 | TEST_F(CellularTest, StartConnected) { |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 705 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
| 706 | .WillOnce(Return(true)); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 707 | SetCellularType(Cellular::kTypeCDMA); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 708 | device_->set_modem_state(Cellular::kModemStateConnected); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 709 | device_->set_meid(kMEID); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 710 | ExpectCdmaStartModem(kNetworkTechnologyEvdo); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 711 | Error error; |
| 712 | device_->Start(&error, Bind(&CellularTest::TestCallback, Unretained(this))); |
| 713 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 714 | dispatcher_.DispatchPendingEvents(); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 715 | EXPECT_EQ(Cellular::kStateConnected, device_->state_); |
| 716 | } |
| 717 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 718 | TEST_F(CellularTest, StartLinked) { |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 719 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
| 720 | .WillOnce(DoAll(SetArgumentPointee<1>(IFF_UP), Return(true))); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 721 | SetCellularType(Cellular::kTypeCDMA); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 722 | device_->set_modem_state(Cellular::kModemStateConnected); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 723 | device_->set_meid(kMEID); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 724 | ExpectCdmaStartModem(kNetworkTechnologyEvdo); |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 725 | EXPECT_CALL(dhcp_provider_, CreateConfig(kTestDeviceName, _, _, _, _)) |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 726 | .WillOnce(Return(dhcp_config_)); |
| 727 | EXPECT_CALL(*dhcp_config_, RequestIP()).WillOnce(Return(true)); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 728 | EXPECT_CALL(*modem_info_.mock_manager(), UpdateService(_)).Times(3); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 729 | Error error; |
| 730 | device_->Start(&error, Bind(&CellularTest::TestCallback, Unretained(this))); |
| 731 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 732 | dispatcher_.DispatchPendingEvents(); |
| 733 | EXPECT_EQ(Cellular::kStateLinked, device_->state_); |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 734 | EXPECT_EQ(Service::kStateConfiguring, device_->service_->state()); |
| 735 | device_->SelectService(NULL); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 738 | TEST_F(CellularTest, CreateService) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 739 | SetCellularType(Cellular::kTypeCDMA); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 740 | static const char kPaymentURL[] = "https://payment.url"; |
| 741 | static const char kUsageURL[] = "https://usage.url"; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 742 | device_->home_provider_.SetName(kTestCarrier); |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 743 | GetCapabilityCDMA()->olp_.SetURL(kPaymentURL); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 744 | GetCapabilityCDMA()->usage_url_ = kUsageURL; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 745 | device_->CreateService(); |
| 746 | ASSERT_TRUE(device_->service_.get()); |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 747 | EXPECT_EQ(kPaymentURL, device_->service_->olp().GetURL()); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 748 | EXPECT_EQ(kUsageURL, device_->service_->usage_url()); |
| 749 | EXPECT_EQ(kTestCarrier, device_->service_->serving_operator().GetName()); |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 750 | ASSERT_FALSE(device_->service_->activate_over_non_cellular_network()); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 753 | namespace { |
| 754 | |
| 755 | MATCHER(ContainsPhoneNumber, "") { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 756 | return ContainsKey(arg, |
| 757 | CellularCapabilityClassic::kConnectPropertyPhoneNumber); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 760 | } // namespace |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 761 | |
| 762 | TEST_F(CellularTest, Connect) { |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 763 | Error error; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 764 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 765 | .Times(2) |
| 766 | .WillRepeatedly(Return(true)); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 767 | device_->state_ = Cellular::kStateConnected; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 768 | device_->Connect(&error); |
| 769 | EXPECT_EQ(Error::kAlreadyConnected, error.type()); |
| 770 | error.Populate(Error::kSuccess); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 771 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 772 | device_->state_ = Cellular::kStateLinked; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 773 | device_->Connect(&error); |
| 774 | EXPECT_EQ(Error::kAlreadyConnected, error.type()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 775 | |
Thieu Le | c7d8cd1 | 2013-02-13 11:38:14 -0800 | [diff] [blame] | 776 | device_->state_ = Cellular::kStateEnabled; |
| 777 | device_->Connect(&error); |
| 778 | EXPECT_EQ(Error::kNotRegistered, error.type()); |
| 779 | |
| 780 | error.Reset(); |
| 781 | device_->state_ = Cellular::kStateDisabled; |
| 782 | device_->Connect(&error); |
| 783 | EXPECT_EQ(Error::kNotRegistered, error.type()); |
| 784 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 785 | device_->state_ = Cellular::kStateRegistered; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 786 | SetService(); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 787 | |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 788 | device_->allow_roaming_ = false; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 789 | device_->service_->roaming_state_ = kRoamingStateRoaming; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 790 | device_->Connect(&error); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 791 | EXPECT_EQ(Error::kNotOnHomeNetwork, error.type()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 792 | |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 793 | error.Populate(Error::kSuccess); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 794 | EXPECT_CALL(*simple_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 795 | Connect(ContainsPhoneNumber(), _, _, |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 796 | CellularCapability::kTimeoutConnect)) |
| 797 | .Times(2) |
| 798 | .WillRepeatedly(Invoke(this, &CellularTest::InvokeConnect)); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 799 | GetCapabilityClassic()->simple_proxy_.reset(simple_proxy_.release()); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 800 | device_->service_->roaming_state_ = kRoamingStateHome; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 801 | device_->state_ = Cellular::kStateRegistered; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 802 | device_->Connect(&error); |
| 803 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 804 | dispatcher_.DispatchPendingEvents(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 805 | EXPECT_EQ(Cellular::kStateConnected, device_->state_); |
| 806 | |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 807 | device_->allow_roaming_ = true; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 808 | device_->service_->roaming_state_ = kRoamingStateRoaming; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 809 | device_->state_ = Cellular::kStateRegistered; |
| 810 | device_->Connect(&error); |
| 811 | EXPECT_TRUE(error.IsSuccess()); |
| 812 | dispatcher_.DispatchPendingEvents(); |
| 813 | EXPECT_EQ(Cellular::kStateConnected, device_->state_); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 816 | TEST_F(CellularTest, Disconnect) { |
| 817 | Error error; |
| 818 | device_->state_ = Cellular::kStateRegistered; |
| 819 | device_->Disconnect(&error); |
| 820 | EXPECT_EQ(Error::kNotConnected, error.type()); |
| 821 | error.Reset(); |
| 822 | |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 823 | device_->state_ = Cellular::kStateConnected; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 824 | EXPECT_CALL(*proxy_, |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 825 | Disconnect(_, _, CellularCapability::kTimeoutDisconnect)) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 826 | .WillOnce(Invoke(this, &CellularTest::InvokeDisconnect)); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 827 | GetCapabilityClassic()->proxy_.reset(proxy_.release()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 828 | device_->Disconnect(&error); |
| 829 | EXPECT_TRUE(error.IsSuccess()); |
| 830 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 831 | } |
| 832 | |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 833 | TEST_F(CellularTest, DisconnectFailure) { |
| 834 | // Test the case where the underlying modem state is set |
| 835 | // to disconnecting, but shill thinks it's still connected |
| 836 | Error error; |
| 837 | device_->state_ = Cellular::kStateConnected; |
| 838 | EXPECT_CALL(*proxy_, |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 839 | Disconnect(_, _, CellularCapability::kTimeoutDisconnect)) |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 840 | .Times(2) |
| 841 | .WillRepeatedly(Invoke(this, &CellularTest::InvokeDisconnectFail)); |
| 842 | GetCapabilityClassic()->proxy_.reset(proxy_.release()); |
| 843 | device_->modem_state_ = Cellular::kModemStateDisconnecting; |
| 844 | device_->Disconnect(&error); |
| 845 | EXPECT_TRUE(error.IsFailure()); |
| 846 | EXPECT_EQ(Cellular::kStateConnected, device_->state_); |
| 847 | |
| 848 | device_->modem_state_ = Cellular::kModemStateConnected; |
| 849 | device_->Disconnect(&error); |
| 850 | EXPECT_TRUE(error.IsFailure()); |
| 851 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
| 852 | } |
| 853 | |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 854 | TEST_F(CellularTest, ConnectFailure) { |
| 855 | SetCellularType(Cellular::kTypeCDMA); |
| 856 | device_->state_ = Cellular::kStateRegistered; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 857 | SetService(); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 858 | ASSERT_EQ(Service::kStateIdle, device_->service_->state()); |
| 859 | EXPECT_CALL(*simple_proxy_, |
| 860 | Connect(_, _, _, CellularCapability::kTimeoutConnect)) |
| 861 | .WillOnce(Invoke(this, &CellularTest::InvokeConnectFail)); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 862 | GetCapabilityClassic()->simple_proxy_.reset(simple_proxy_.release()); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 863 | Error error; |
| 864 | device_->Connect(&error); |
| 865 | EXPECT_EQ(Service::kStateFailure, device_->service_->state()); |
| 866 | } |
| 867 | |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 868 | TEST_F(CellularTest, ConnectFailureNoService) { |
| 869 | // Make sure we don't crash if the connect failed and there is no |
| 870 | // CellularService object. This can happen if the modem is enabled and |
| 871 | // then quick disabled. |
| 872 | SetCellularType(Cellular::kTypeCDMA); |
| 873 | device_->state_ = Cellular::kStateRegistered; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 874 | SetService(); |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 875 | EXPECT_CALL( |
| 876 | *simple_proxy_, |
| 877 | Connect(_, _, _, CellularCapability::kTimeoutConnect)) |
| 878 | .WillOnce(Invoke(this, &CellularTest::InvokeConnectFailNoService)); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 879 | EXPECT_CALL(*modem_info_.mock_manager(), UpdateService(_)); |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 880 | GetCapabilityClassic()->simple_proxy_.reset(simple_proxy_.release()); |
| 881 | Error error; |
| 882 | device_->Connect(&error); |
| 883 | } |
| 884 | |
Thieu Le | d4974cd | 2013-05-23 10:39:28 -0700 | [diff] [blame] | 885 | TEST_F(CellularTest, ConnectSuccessNoService) { |
| 886 | // Make sure we don't crash if the connect succeeds but the service was |
| 887 | // destroyed before the connect request completes. |
| 888 | SetCellularType(Cellular::kTypeCDMA); |
| 889 | device_->state_ = Cellular::kStateRegistered; |
| 890 | SetService(); |
| 891 | EXPECT_CALL( |
| 892 | *simple_proxy_, |
| 893 | Connect(_, _, _, CellularCapability::kTimeoutConnect)) |
| 894 | .WillOnce(Invoke(this, &CellularTest::InvokeConnectSuccessNoService)); |
| 895 | EXPECT_CALL(*modem_info_.mock_manager(), UpdateService(_)); |
| 896 | GetCapabilityClassic()->simple_proxy_.reset(simple_proxy_.release()); |
| 897 | Error error; |
| 898 | device_->Connect(&error); |
| 899 | } |
| 900 | |
Arman Uguray | 32c7640 | 2012-11-27 14:01:13 -0800 | [diff] [blame] | 901 | TEST_F(CellularTest, LinkEventWontDestroyService) { |
| 902 | // If the network interface goes down, Cellular::LinkEvent should |
| 903 | // drop the connection but the service object should persist. |
| 904 | device_->state_ = Cellular::kStateLinked; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 905 | CellularService *service = SetService(); |
Arman Uguray | 32c7640 | 2012-11-27 14:01:13 -0800 | [diff] [blame] | 906 | device_->LinkEvent(0, 0); // flags doesn't contain IFF_UP |
| 907 | EXPECT_EQ(device_->state_, Cellular::kStateConnected); |
| 908 | EXPECT_EQ(device_->service_, service); |
| 909 | } |
| 910 | |
Arman Uguray | ed8e610 | 2012-11-29 14:47:20 -0800 | [diff] [blame] | 911 | TEST_F(CellularTest, UseNoArpGateway) { |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 912 | EXPECT_CALL(dhcp_provider_, CreateConfig(kTestDeviceName, _, _, false, false)) |
Arman Uguray | ed8e610 | 2012-11-29 14:47:20 -0800 | [diff] [blame] | 913 | .WillOnce(Return(dhcp_config_)); |
| 914 | device_->AcquireIPConfig(); |
| 915 | } |
| 916 | |
Ben Chan | 09fa2a0 | 2012-11-07 22:09:09 -0800 | [diff] [blame] | 917 | TEST_F(CellularTest, HandleNewRegistrationStateForServiceRequiringActivation) { |
| 918 | SetCellularType(Cellular::kTypeUniversal); |
| 919 | |
| 920 | // Service activation is needed |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 921 | device_->set_mdn("0000000000"); |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 922 | CellularService::OLP olp; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 923 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_)) |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 924 | .WillRepeatedly(Return(&olp)); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 925 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 926 | GetActivationState(_,_)) |
| 927 | .WillRepeatedly(Return(PendingActivationStore::kStateUnknown)); |
Ben Chan | 09fa2a0 | 2012-11-07 22:09:09 -0800 | [diff] [blame] | 928 | |
| 929 | device_->state_ = Cellular::kStateDisabled; |
| 930 | device_->HandleNewRegistrationState(); |
| 931 | EXPECT_FALSE(device_->service_.get()); |
| 932 | |
| 933 | device_->state_ = Cellular::kStateEnabled; |
| 934 | device_->HandleNewRegistrationState(); |
| 935 | EXPECT_TRUE(device_->service_.get()); |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 936 | EXPECT_TRUE(device_->service_->activate_over_non_cellular_network()); |
Ben Chan | 09fa2a0 | 2012-11-07 22:09:09 -0800 | [diff] [blame] | 937 | } |
| 938 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 939 | TEST_F(CellularTest, ModemStateChangeEnable) { |
| 940 | EXPECT_CALL(*simple_proxy_, |
| 941 | GetModemStatus(_, _, CellularCapability::kTimeoutDefault)) |
| 942 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemStatus)); |
| 943 | EXPECT_CALL(*cdma_proxy_, MEID()).WillOnce(Return(kMEID)); |
| 944 | EXPECT_CALL(*proxy_, |
| 945 | GetModemInfo(_, _, CellularCapability::kTimeoutDefault)) |
| 946 | .WillOnce(Invoke(this, &CellularTest::InvokeGetModemInfo)); |
| 947 | EXPECT_CALL(*cdma_proxy_, GetRegistrationState(NULL, _, _)) |
| 948 | .WillOnce(Invoke(this, |
| 949 | &CellularTest::InvokeGetRegistrationStateUnregistered)); |
| 950 | EXPECT_CALL(*cdma_proxy_, GetSignalQuality(NULL, _, _)) |
| 951 | .WillOnce(Invoke(this, &CellularTest::InvokeGetSignalQuality)); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 952 | EXPECT_CALL(*modem_info_.mock_manager(), UpdateEnabledTechnologies()); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 953 | device_->state_ = Cellular::kStateDisabled; |
| 954 | device_->set_modem_state(Cellular::kModemStateDisabled); |
| 955 | SetCellularType(Cellular::kTypeCDMA); |
| 956 | |
| 957 | DBusPropertiesMap props; |
| 958 | props[CellularCapabilityClassic::kModemPropertyEnabled].writer(). |
| 959 | append_bool(true); |
| 960 | device_->OnDBusPropertiesChanged(MM_MODEM_INTERFACE, props, vector<string>()); |
| 961 | dispatcher_.DispatchPendingEvents(); |
| 962 | |
| 963 | EXPECT_EQ(Cellular::kModemStateEnabled, device_->modem_state()); |
| 964 | EXPECT_EQ(Cellular::kStateEnabled, device_->state()); |
| 965 | EXPECT_TRUE(device_->enabled()); |
| 966 | } |
| 967 | |
| 968 | TEST_F(CellularTest, ModemStateChangeDisable) { |
| 969 | EXPECT_CALL(*proxy_, |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 970 | Disconnect(_, _, CellularCapability::kTimeoutDisconnect)) |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 971 | .WillOnce(Invoke(this, &CellularTest::InvokeDisconnect)); |
| 972 | EXPECT_CALL(*proxy_, |
Thieu Le | c8d2d96 | 2012-05-15 14:31:18 -0700 | [diff] [blame] | 973 | Enable(false, _, _, CellularCapability::kTimeoutEnable)) |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 974 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 975 | EXPECT_CALL(*modem_info_.mock_manager(), UpdateEnabledTechnologies()); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 976 | device_->enabled_ = true; |
| 977 | device_->enabled_pending_ = true; |
| 978 | device_->state_ = Cellular::kStateEnabled; |
| 979 | device_->set_modem_state(Cellular::kModemStateEnabled); |
| 980 | SetCellularType(Cellular::kTypeCDMA); |
| 981 | GetCapabilityClassic()->InitProxies(); |
| 982 | |
| 983 | GetCapabilityClassic()->OnModemStateChangedSignal(kModemClassicStateEnabled, |
| 984 | kModemClassicStateDisabled, |
| 985 | 0); |
| 986 | dispatcher_.DispatchPendingEvents(); |
| 987 | |
| 988 | EXPECT_EQ(Cellular::kModemStateDisabled, device_->modem_state()); |
| 989 | EXPECT_EQ(Cellular::kStateDisabled, device_->state()); |
| 990 | EXPECT_FALSE(device_->enabled()); |
| 991 | } |
| 992 | |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 993 | TEST_F(CellularTest, ModemStateChangeStaleConnected) { |
| 994 | // Test to make sure that we ignore stale modem Connected state transitions. |
| 995 | // When a modem is asked to connect and before the connect completes, the |
| 996 | // modem is disabled, it may send a stale Connected state transition after |
| 997 | // it has been disabled. |
| 998 | device_->state_ = Cellular::kStateDisabled; |
Arman Uguray | 1ee9391 | 2013-09-24 21:24:10 -0700 | [diff] [blame] | 999 | device_->modem_state_ = Cellular::kModemStateEnabling; |
| 1000 | device_->OnModemStateChanged(Cellular::kModemStateConnected); |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 1001 | EXPECT_EQ(Cellular::kStateDisabled, device_->state()); |
| 1002 | } |
| 1003 | |
| 1004 | TEST_F(CellularTest, ModemStateChangeValidConnected) { |
| 1005 | device_->state_ = Cellular::kStateEnabled; |
Arman Uguray | 1ee9391 | 2013-09-24 21:24:10 -0700 | [diff] [blame] | 1006 | device_->modem_state_ = Cellular::kModemStateConnecting; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1007 | SetService(); |
Arman Uguray | 1ee9391 | 2013-09-24 21:24:10 -0700 | [diff] [blame] | 1008 | device_->OnModemStateChanged(Cellular::kModemStateConnected); |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 1009 | EXPECT_EQ(Cellular::kStateConnected, device_->state()); |
| 1010 | } |
| 1011 | |
Thieu Le | 5218cf2 | 2012-11-26 11:52:57 -0800 | [diff] [blame] | 1012 | TEST_F(CellularTest, ModemStateChangeLostRegistration) { |
| 1013 | SetCellularType(Cellular::kTypeUniversal); |
| 1014 | CellularCapabilityUniversal *capability = GetCapabilityUniversal(); |
| 1015 | capability->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_HOME; |
| 1016 | EXPECT_TRUE(capability->IsRegistered()); |
Arman Uguray | 1ee9391 | 2013-09-24 21:24:10 -0700 | [diff] [blame] | 1017 | device_->set_modem_state(Cellular::kModemStateRegistered); |
| 1018 | device_->OnModemStateChanged(Cellular::kModemStateEnabled); |
Thieu Le | 5218cf2 | 2012-11-26 11:52:57 -0800 | [diff] [blame] | 1019 | EXPECT_FALSE(capability->IsRegistered()); |
| 1020 | } |
| 1021 | |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 1022 | TEST_F(CellularTest, StartModemCallback) { |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 1023 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 1024 | EXPECT_EQ(device_->state_, Cellular::kStateDisabled); |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 1025 | device_->StartModemCallback(Bind(&CellularTest::TestCallback, |
| 1026 | Unretained(this)), |
| 1027 | Error(Error::kSuccess)); |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 1028 | EXPECT_EQ(device_->state_, Cellular::kStateEnabled); |
| 1029 | } |
| 1030 | |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 1031 | TEST_F(CellularTest, StartModemCallbackFail) { |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 1032 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 1033 | EXPECT_EQ(device_->state_, Cellular::kStateDisabled); |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 1034 | device_->StartModemCallback(Bind(&CellularTest::TestCallback, |
| 1035 | Unretained(this)), |
| 1036 | Error(Error::kOperationFailed)); |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 1037 | EXPECT_EQ(device_->state_, Cellular::kStateDisabled); |
| 1038 | } |
| 1039 | |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 1040 | TEST_F(CellularTest, StopModemCallback) { |
| 1041 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1042 | SetMockService(); |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 1043 | device_->StopModemCallback(Bind(&CellularTest::TestCallback, |
| 1044 | Unretained(this)), |
| 1045 | Error(Error::kSuccess)); |
| 1046 | EXPECT_EQ(device_->state_, Cellular::kStateDisabled); |
| 1047 | EXPECT_FALSE(device_->service_.get()); |
| 1048 | } |
| 1049 | |
| 1050 | TEST_F(CellularTest, StopModemCallbackFail) { |
| 1051 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1052 | SetMockService(); |
Thieu Le | 37b9003 | 2012-05-15 15:18:41 -0700 | [diff] [blame] | 1053 | device_->StopModemCallback(Bind(&CellularTest::TestCallback, |
| 1054 | Unretained(this)), |
| 1055 | Error(Error::kOperationFailed)); |
| 1056 | EXPECT_EQ(device_->state_, Cellular::kStateDisabled); |
| 1057 | EXPECT_FALSE(device_->service_.get()); |
| 1058 | } |
| 1059 | |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 1060 | TEST_F(CellularTest, SetAllowRoaming) { |
| 1061 | EXPECT_FALSE(device_->allow_roaming_); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1062 | EXPECT_CALL(*modem_info_.mock_manager(), UpdateDevice(_)); |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 1063 | Error error; |
| 1064 | device_->SetAllowRoaming(true, &error); |
| 1065 | EXPECT_TRUE(error.IsSuccess()); |
| 1066 | EXPECT_TRUE(device_->allow_roaming_); |
| 1067 | } |
| 1068 | |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 1069 | class TestRPCTaskDelegate : |
| 1070 | public RPCTaskDelegate, |
| 1071 | public base::SupportsWeakPtr<TestRPCTaskDelegate> { |
| 1072 | public: |
| 1073 | virtual void GetLogin(std::string *user, std::string *password) {} |
| 1074 | virtual void Notify(const std::string &reason, |
| 1075 | const std::map<std::string, std::string> &dict) {} |
| 1076 | }; |
| 1077 | |
| 1078 | TEST_F(CellularTest, LinkEventUpWithPPP) { |
| 1079 | // If PPP is running, don't run DHCP as well. |
| 1080 | TestRPCTaskDelegate task_delegate; |
| 1081 | base::Callback<void(pid_t, int)> death_callback; |
| 1082 | scoped_ptr<NiceMock<MockExternalTask>> mock_task( |
| 1083 | new NiceMock<MockExternalTask>(modem_info_.control_interface(), |
| 1084 | modem_info_.glib(), |
| 1085 | task_delegate.AsWeakPtr(), |
| 1086 | death_callback)); |
| 1087 | EXPECT_CALL(*mock_task, OnDelete()).Times(AnyNumber()); |
| 1088 | device_->ppp_task_ = mock_task.Pass(); |
| 1089 | device_->state_ = Cellular::kStateConnected; |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 1090 | EXPECT_CALL(dhcp_provider_, CreateConfig(kTestDeviceName, _, _, _, _)) |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 1091 | .Times(0); |
| 1092 | EXPECT_CALL(*dhcp_config_, RequestIP()).Times(0); |
| 1093 | device_->LinkEvent(IFF_UP, 0); |
| 1094 | } |
| 1095 | |
| 1096 | TEST_F(CellularTest, LinkEventUpWithoutPPP) { |
| 1097 | // If PPP is not running, fire up DHCP. |
| 1098 | device_->state_ = Cellular::kStateConnected; |
Paul Stewart | 75a68b9 | 2013-10-24 10:50:27 -0700 | [diff] [blame] | 1099 | EXPECT_CALL(dhcp_provider_, CreateConfig(kTestDeviceName, _, _, _, _)) |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 1100 | .WillOnce(Return(dhcp_config_)); |
| 1101 | EXPECT_CALL(*dhcp_config_, RequestIP()); |
| 1102 | EXPECT_CALL(*dhcp_config_, ReleaseIP(_)).Times(AnyNumber()); |
| 1103 | device_->LinkEvent(IFF_UP, 0); |
| 1104 | } |
| 1105 | |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 1106 | TEST_F(CellularTest, StartPPP) { |
| 1107 | const int kPID = 234; |
| 1108 | EXPECT_FALSE(device_->ppp_task_); |
| 1109 | StartPPP(kPID); |
| 1110 | } |
| 1111 | |
| 1112 | TEST_F(CellularTest, StartPPPAlreadyStarted) { |
| 1113 | const int kPID = 234; |
| 1114 | StartPPP(kPID); |
| 1115 | |
| 1116 | const int kPID2 = 235; |
| 1117 | StartPPP(kPID2); |
| 1118 | } |
| 1119 | |
mukesh agrawal | 35ec840 | 2013-07-19 14:49:08 -0700 | [diff] [blame] | 1120 | TEST_F(CellularTest, StartPPPAfterEthernetUp) { |
| 1121 | CellularService *service(SetService()); |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 1122 | device_->state_ = Cellular::kStateLinked; |
mukesh agrawal | 35ec840 | 2013-07-19 14:49:08 -0700 | [diff] [blame] | 1123 | device_->set_ipconfig(dhcp_config_); |
| 1124 | device_->SelectService(service); |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 1125 | EXPECT_CALL(*dhcp_config_, ReleaseIP(_)) |
| 1126 | .Times(AnyNumber()) |
| 1127 | .WillRepeatedly(Return(true)); |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 1128 | const int kPID = 234; |
| 1129 | EXPECT_FALSE(device_->ppp_task_); |
| 1130 | StartPPP(kPID); |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 1131 | EXPECT_EQ(Cellular::kStateLinked, device_->state()); |
mukesh agrawal | fbc40d2 | 2013-06-28 00:25:13 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
mukesh agrawal | 3ffe52c | 2013-06-20 15:21:29 -0700 | [diff] [blame] | 1134 | TEST_F(CellularTest, GetLogin) { |
| 1135 | // Doesn't crash when there is no service. |
| 1136 | string username_to_pppd; |
| 1137 | string password_to_pppd; |
| 1138 | EXPECT_FALSE(device_->service()); |
| 1139 | device_->GetLogin(&username_to_pppd, &password_to_pppd); |
| 1140 | |
| 1141 | // Provides expected username and password in normal case. |
| 1142 | const char kFakeUsername[] = "fake-user"; |
| 1143 | const char kFakePassword[] = "fake-password"; |
| 1144 | CellularService &service(*SetService()); |
| 1145 | service.ppp_username_ = kFakeUsername; |
| 1146 | service.ppp_password_ = kFakePassword; |
| 1147 | device_->GetLogin(&username_to_pppd, &password_to_pppd); |
| 1148 | } |
| 1149 | |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 1150 | TEST_F(CellularTest, Notify) { |
| 1151 | // Common setup. |
| 1152 | MockPPPDeviceFactory *ppp_device_factory = |
| 1153 | MockPPPDeviceFactory::GetInstance(); |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 1154 | const int kPID = 91; |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 1155 | device_->ppp_device_factory_ = ppp_device_factory; |
| 1156 | SetMockService(); |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 1157 | StartPPP(kPID); |
| 1158 | |
| 1159 | const map<string, string> kEmptyArgs; |
| 1160 | device_->Notify(kPPPReasonAuthenticating, kEmptyArgs); |
| 1161 | EXPECT_TRUE(device_->is_ppp_authenticating_); |
| 1162 | device_->Notify(kPPPReasonAuthenticated, kEmptyArgs); |
| 1163 | EXPECT_FALSE(device_->is_ppp_authenticating_); |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 1164 | |
| 1165 | // Normal connect. |
| 1166 | const string kInterfaceName("fake-device"); |
| 1167 | const int kInterfaceIndex = 1; |
| 1168 | scoped_refptr<MockPPPDevice> ppp_device; |
| 1169 | map<string, string> ppp_config; |
| 1170 | ppp_device = |
| 1171 | new MockPPPDevice(modem_info_.control_interface(), |
| 1172 | NULL, NULL, NULL, kInterfaceName, kInterfaceIndex); |
| 1173 | ppp_config[kPPPInterfaceName] = kInterfaceName; |
| 1174 | EXPECT_CALL(device_info_, GetIndex(kInterfaceName)) |
| 1175 | .WillOnce(Return(kInterfaceIndex)); |
| 1176 | EXPECT_CALL(device_info_, RegisterDevice(_)); |
| 1177 | EXPECT_CALL(*ppp_device_factory, |
| 1178 | CreatePPPDevice(_, _, _, _, kInterfaceName, kInterfaceIndex)) |
| 1179 | .WillOnce(Return(ppp_device)); |
| 1180 | EXPECT_CALL(*ppp_device, SetEnabled(true)); |
| 1181 | EXPECT_CALL(*ppp_device, SelectService(_)); |
| 1182 | EXPECT_CALL(*ppp_device, UpdateIPConfigFromPPP(ppp_config, false)); |
| 1183 | device_->Notify(kPPPReasonConnect, ppp_config); |
| 1184 | Mock::VerifyAndClearExpectations(&device_info_); |
| 1185 | Mock::VerifyAndClearExpectations(ppp_device); |
| 1186 | |
| 1187 | // Re-connect on same network device: if pppd sends us multiple connect |
| 1188 | // events, we behave sanely. |
| 1189 | EXPECT_CALL(device_info_, GetIndex(kInterfaceName)) |
| 1190 | .WillOnce(Return(kInterfaceIndex)); |
| 1191 | EXPECT_CALL(*ppp_device, SetEnabled(true)); |
| 1192 | EXPECT_CALL(*ppp_device, SelectService(_)); |
| 1193 | EXPECT_CALL(*ppp_device, UpdateIPConfigFromPPP(ppp_config, false)); |
| 1194 | device_->Notify(kPPPReasonConnect, ppp_config); |
| 1195 | Mock::VerifyAndClearExpectations(&device_info_); |
| 1196 | Mock::VerifyAndClearExpectations(ppp_device); |
| 1197 | |
| 1198 | // Re-connect on new network device: if we still have the PPPDevice |
| 1199 | // from a prior connect, this new connect should DTRT. This is |
| 1200 | // probably an unlikely case. |
| 1201 | const string kInterfaceName2("fake-device2"); |
| 1202 | const int kInterfaceIndex2 = 2; |
| 1203 | scoped_refptr<MockPPPDevice> ppp_device2; |
| 1204 | map<string, string> ppp_config2; |
| 1205 | ppp_device2 = |
| 1206 | new MockPPPDevice(modem_info_.control_interface(), |
| 1207 | NULL, NULL, NULL, kInterfaceName2, kInterfaceIndex2); |
| 1208 | ppp_config2[kPPPInterfaceName] = kInterfaceName2; |
| 1209 | EXPECT_CALL(device_info_, GetIndex(kInterfaceName2)) |
| 1210 | .WillOnce(Return(kInterfaceIndex2)); |
| 1211 | EXPECT_CALL(device_info_, |
| 1212 | RegisterDevice(static_cast<DeviceRefPtr>(ppp_device2))); |
| 1213 | EXPECT_CALL(*ppp_device_factory, |
| 1214 | CreatePPPDevice(_, _, _, _, kInterfaceName2, kInterfaceIndex2)) |
| 1215 | .WillOnce(Return(ppp_device2)); |
| 1216 | EXPECT_CALL(*ppp_device, SelectService(ServiceRefPtr(nullptr))); |
| 1217 | EXPECT_CALL(*ppp_device2, SetEnabled(true)); |
| 1218 | EXPECT_CALL(*ppp_device2, SelectService(_)); |
| 1219 | EXPECT_CALL(*ppp_device2, UpdateIPConfigFromPPP(ppp_config2, false)); |
| 1220 | device_->Notify(kPPPReasonConnect, ppp_config2); |
| 1221 | Mock::VerifyAndClearExpectations(&device_info_); |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 1222 | Mock::VerifyAndClearExpectations(ppp_device); |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 1223 | Mock::VerifyAndClearExpectations(ppp_device2); |
| 1224 | |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 1225 | // Disconnect should report unknown failure, since we had a |
| 1226 | // Notify(kPPPReasonAuthenticated, ...). |
| 1227 | EXPECT_CALL(*ppp_device2, SetServiceFailure(Service::kFailureUnknown)); |
| 1228 | device_->Notify(kPPPReasonDisconnect, kEmptyArgs); |
| 1229 | EXPECT_FALSE(device_->ppp_task_); |
| 1230 | } |
| 1231 | |
| 1232 | TEST_F(CellularTest, PPPConnectionFailedBeforeAuth) { |
| 1233 | // Test that we properly set Service state in the case where pppd |
| 1234 | // disconnects before authenticating (as opposed to the Notify test, |
| 1235 | // where pppd disconnects after connecting). |
| 1236 | const int kPID = 52; |
| 1237 | const map<string, string> kEmptyArgs; |
| 1238 | MockCellularService *service = SetMockService(); |
| 1239 | StartPPP(kPID); |
mukesh agrawal | ee10f37 | 2013-08-14 14:07:11 -0700 | [diff] [blame] | 1240 | |
| 1241 | ExpectDisconnectCapabilityUniversal(); |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 1242 | EXPECT_CALL(*service, SetFailure(Service::kFailureUnknown)); |
| 1243 | device_->Notify(kPPPReasonDisconnect, kEmptyArgs); |
| 1244 | EXPECT_FALSE(device_->ppp_task_); |
mukesh agrawal | ee10f37 | 2013-08-14 14:07:11 -0700 | [diff] [blame] | 1245 | VerifyDisconnect(); |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | TEST_F(CellularTest, PPPConnectionFailedDuringAuth) { |
| 1249 | // Test that we properly set Service state in the case where pppd |
| 1250 | // disconnects during authentication (as opposed to the Notify test, |
| 1251 | // where pppd disconnects after connecting). |
| 1252 | const int kPID = 52; |
| 1253 | const map<string, string> kEmptyArgs; |
| 1254 | MockCellularService *service = SetMockService(); |
| 1255 | StartPPP(kPID); |
mukesh agrawal | ee10f37 | 2013-08-14 14:07:11 -0700 | [diff] [blame] | 1256 | |
| 1257 | ExpectDisconnectCapabilityUniversal(); |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 1258 | EXPECT_CALL(*service, SetFailure(Service::kFailurePPPAuth)); |
| 1259 | device_->Notify(kPPPReasonAuthenticating, kEmptyArgs); |
| 1260 | device_->Notify(kPPPReasonDisconnect, kEmptyArgs); |
| 1261 | EXPECT_FALSE(device_->ppp_task_); |
mukesh agrawal | ee10f37 | 2013-08-14 14:07:11 -0700 | [diff] [blame] | 1262 | VerifyDisconnect(); |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | TEST_F(CellularTest, PPPConnectionFailedAfterAuth) { |
| 1266 | // Test that we properly set Service state in the case where pppd |
| 1267 | // disconnects after authenticating, but before connecting (as |
| 1268 | // opposed to the Notify test, where pppd disconnects after |
| 1269 | // connecting). |
| 1270 | const int kPID = 52; |
| 1271 | const map<string, string> kEmptyArgs; |
| 1272 | MockCellularService *service = SetMockService(); |
| 1273 | StartPPP(kPID); |
mukesh agrawal | ee10f37 | 2013-08-14 14:07:11 -0700 | [diff] [blame] | 1274 | |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 1275 | EXPECT_CALL(*service, SetFailure(Service::kFailureUnknown)); |
mukesh agrawal | ee10f37 | 2013-08-14 14:07:11 -0700 | [diff] [blame] | 1276 | ExpectDisconnectCapabilityUniversal(); |
mukesh agrawal | fc36291 | 2013-08-06 18:10:07 -0700 | [diff] [blame] | 1277 | device_->Notify(kPPPReasonAuthenticating, kEmptyArgs); |
| 1278 | device_->Notify(kPPPReasonAuthenticated, kEmptyArgs); |
| 1279 | device_->Notify(kPPPReasonDisconnect, kEmptyArgs); |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 1280 | EXPECT_FALSE(device_->ppp_task_); |
mukesh agrawal | ee10f37 | 2013-08-14 14:07:11 -0700 | [diff] [blame] | 1281 | VerifyDisconnect(); |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | TEST_F(CellularTest, OnPPPDied) { |
| 1285 | const int kPID = 1234; |
| 1286 | const int kExitStatus = 5; |
mukesh agrawal | ee10f37 | 2013-08-14 14:07:11 -0700 | [diff] [blame] | 1287 | ExpectDisconnectCapabilityUniversal(); |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 1288 | device_->OnPPPDied(kPID, kExitStatus); |
mukesh agrawal | ee10f37 | 2013-08-14 14:07:11 -0700 | [diff] [blame] | 1289 | VerifyDisconnect(); |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
mukesh agrawal | 5d851b1 | 2013-07-11 14:09:41 -0700 | [diff] [blame] | 1292 | TEST_F(CellularTest, DropConnection) { |
| 1293 | device_->set_ipconfig(dhcp_config_); |
| 1294 | EXPECT_CALL(*dhcp_config_, ReleaseIP(_)); |
| 1295 | device_->DropConnection(); |
| 1296 | Mock::VerifyAndClearExpectations(dhcp_config_); // verify before dtor |
| 1297 | EXPECT_FALSE(device_->ipconfig()); |
| 1298 | } |
| 1299 | |
| 1300 | TEST_F(CellularTest, DropConnectionPPP) { |
| 1301 | scoped_refptr<MockPPPDevice> ppp_device( |
| 1302 | new MockPPPDevice(modem_info_.control_interface(), |
| 1303 | NULL, NULL, NULL, "fake_ppp0", -1)); |
| 1304 | EXPECT_CALL(*ppp_device, DropConnection()); |
| 1305 | device_->ppp_device_ = ppp_device; |
| 1306 | device_->DropConnection(); |
| 1307 | } |
| 1308 | |
mukesh agrawal | 0381f9a | 2013-07-11 16:41:52 -0700 | [diff] [blame] | 1309 | TEST_F(CellularTest, ChangeServiceState) { |
| 1310 | MockCellularService *service(SetMockService()); |
| 1311 | EXPECT_CALL(*service, SetState(_)); |
| 1312 | EXPECT_CALL(*service, SetFailure(_)); |
| 1313 | EXPECT_CALL(*service, SetFailureSilent(_)); |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 1314 | ON_CALL(*service, state()).WillByDefault(Return(Service::kStateUnknown)); |
mukesh agrawal | 0381f9a | 2013-07-11 16:41:52 -0700 | [diff] [blame] | 1315 | |
| 1316 | // Without PPP, these should be handled by our selected_service(). |
| 1317 | device_->SelectService(service); |
| 1318 | device_->SetServiceState(Service::kStateConfiguring); |
| 1319 | device_->SetServiceFailure(Service::kFailurePPPAuth); |
| 1320 | device_->SetServiceFailureSilent(Service::kFailureUnknown); |
| 1321 | Mock::VerifyAndClearExpectations(service); // before Cellular dtor |
| 1322 | } |
| 1323 | |
| 1324 | TEST_F(CellularTest, ChangeServiceStatePPP) { |
| 1325 | MockCellularService *service(SetMockService()); |
| 1326 | scoped_refptr<MockPPPDevice> ppp_device( |
| 1327 | new MockPPPDevice(modem_info_.control_interface(), |
| 1328 | NULL, NULL, NULL, "fake_ppp0", -1)); |
| 1329 | EXPECT_CALL(*ppp_device, SetServiceState(_)); |
| 1330 | EXPECT_CALL(*ppp_device, SetServiceFailure(_)); |
| 1331 | EXPECT_CALL(*ppp_device, SetServiceFailureSilent(_)); |
| 1332 | EXPECT_CALL(*service, SetState(_)).Times(0); |
| 1333 | EXPECT_CALL(*service, SetFailure(_)).Times(0); |
| 1334 | EXPECT_CALL(*service, SetFailureSilent(_)).Times(0); |
| 1335 | device_->ppp_device_ = ppp_device; |
| 1336 | |
| 1337 | // With PPP, these should all be punted over to the |ppp_device|. |
| 1338 | // Note in particular that Cellular does not manipulate |service| in |
| 1339 | // this case. |
| 1340 | device_->SetServiceState(Service::kStateConfiguring); |
| 1341 | device_->SetServiceFailure(Service::kFailurePPPAuth); |
| 1342 | device_->SetServiceFailureSilent(Service::kFailureUnknown); |
| 1343 | } |
| 1344 | |
mukesh agrawal | 5c8ed24 | 2013-10-04 11:59:58 -0700 | [diff] [blame] | 1345 | TEST_F(CellularTest, StopPPPOnDisconnect) { |
| 1346 | const int kPID = 123; |
mukesh agrawal | 5c8ed24 | 2013-10-04 11:59:58 -0700 | [diff] [blame] | 1347 | Error error; |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 1348 | StartPPP(kPID); |
| 1349 | FakeUpConnectedPPP(); |
| 1350 | ExpectPPPStopped(); |
mukesh agrawal | 5c8ed24 | 2013-10-04 11:59:58 -0700 | [diff] [blame] | 1351 | device_->Disconnect(&error); |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 1352 | VerifyPPPStopped(); |
| 1353 | } |
| 1354 | |
| 1355 | TEST_F(CellularTest, StopPPPOnTermination) { |
| 1356 | const int kPID = 123; |
| 1357 | StartPPP(kPID); |
| 1358 | FakeUpConnectedPPP(); |
| 1359 | ExpectPPPStopped(); |
| 1360 | device_->StartTermination(); |
| 1361 | VerifyPPPStopped(); |
| 1362 | } |
| 1363 | |
| 1364 | TEST_F(CellularTest, OnAfterResumeDisabledWantDisabled) { |
| 1365 | // The Device was disabled prior to resume, and the profile settings |
| 1366 | // indicate that the device should be disabled. We should leave |
| 1367 | // things alone. |
| 1368 | |
| 1369 | // Initial state. |
| 1370 | mm1::MockModemProxy *mm1_proxy = SetupOnAfterResume(); |
| 1371 | set_enabled_persistent(false); |
| 1372 | EXPECT_FALSE(device_->running()); |
| 1373 | EXPECT_FALSE(device_->enabled_persistent()); |
| 1374 | EXPECT_EQ(Cellular::kStateDisabled, device_->state_); |
| 1375 | |
| 1376 | // Resume, while device is disabled. |
| 1377 | EXPECT_CALL(*mm1_proxy, Enable(_, _, _, _)).Times(0); |
| 1378 | device_->OnAfterResume(); |
| 1379 | EXPECT_FALSE(device_->running()); |
| 1380 | EXPECT_FALSE(device_->enabled_persistent()); |
| 1381 | EXPECT_EQ(Cellular::kStateDisabled, device_->state_); |
| 1382 | } |
| 1383 | |
| 1384 | TEST_F(CellularTest, OnAfterResumeDisableInProgressWantDisabled) { |
| 1385 | // The Device was not disabled prior to resume, but the profile |
| 1386 | // settings indicate that the device _should be_ disabled. Most |
| 1387 | // likely, we started disabling the device, but that did not |
| 1388 | // complete before we suspended. We should leave things alone. |
| 1389 | |
| 1390 | // Initial state. |
| 1391 | mm1::MockModemProxy *mm1_proxy = SetupOnAfterResume(); |
| 1392 | Error error; |
| 1393 | EXPECT_CALL(*mm1_proxy, Enable(true, _, _, _)) |
| 1394 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
| 1395 | device_->SetEnabled(true); |
| 1396 | EXPECT_TRUE(device_->running()); |
| 1397 | EXPECT_EQ(Cellular::kStateEnabled, device_->state_); |
| 1398 | |
| 1399 | // Start disable. |
| 1400 | EXPECT_CALL(*modem_info_.mock_manager(), UpdateDevice(_)); |
| 1401 | device_->SetEnabledPersistent(false, &error, ResultCallback()); |
| 1402 | EXPECT_FALSE(device_->running()); // changes immediately |
| 1403 | EXPECT_FALSE(device_->enabled_persistent()); // changes immediately |
| 1404 | EXPECT_EQ(Cellular::kStateEnabled, device_->state_); // changes on completion |
| 1405 | |
| 1406 | // Resume, with disable still in progress. |
| 1407 | device_->OnAfterResume(); |
| 1408 | EXPECT_FALSE(device_->running()); |
| 1409 | EXPECT_FALSE(device_->enabled_persistent()); |
| 1410 | EXPECT_EQ(Cellular::kStateEnabled, device_->state_); |
| 1411 | |
| 1412 | // Finish the disable operation. |
| 1413 | EXPECT_CALL(*mm1_proxy, Enable(false, _, _, _)) |
| 1414 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
| 1415 | EXPECT_CALL(*mm1_proxy, SetPowerState(_, _, _, _)) |
| 1416 | .WillOnce(Invoke(this, &CellularTest::InvokeSetPowerState)); |
| 1417 | dispatcher_.DispatchPendingEvents(); |
| 1418 | EXPECT_FALSE(device_->running()); |
| 1419 | EXPECT_FALSE(device_->enabled_persistent()); |
| 1420 | EXPECT_EQ(Cellular::kStateDisabled, device_->state_); |
| 1421 | } |
| 1422 | |
| 1423 | TEST_F(CellularTest, OnAfterResumeDisableQueuedWantEnabled) { |
| 1424 | // The Device was not disabled prior to resume, and the profile |
| 1425 | // settings indicate that the device should be enabled. In |
| 1426 | // particular, we went into suspend before we actually processed the |
| 1427 | // task queued by CellularCapabilityUniversal::StopModem. |
| 1428 | // |
| 1429 | // This is unlikely, and a case where we fail to do the right thing. |
| 1430 | // The tests exists to document this corner case, which we get wrong. |
| 1431 | |
| 1432 | // Initial state. |
| 1433 | mm1::MockModemProxy *mm1_proxy = SetupOnAfterResume(); |
| 1434 | EXPECT_CALL(*mm1_proxy, Enable(true, _, _, _)) |
| 1435 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
| 1436 | device_->SetEnabled(true); |
| 1437 | EXPECT_TRUE(device_->running()); |
| 1438 | EXPECT_TRUE(device_->enabled_persistent()); |
| 1439 | EXPECT_EQ(Cellular::kStateEnabled, device_->state_); |
| 1440 | |
| 1441 | // Start disable. |
| 1442 | device_->SetEnabled(false); |
| 1443 | EXPECT_FALSE(device_->running()); // changes immediately |
| 1444 | EXPECT_TRUE(device_->enabled_persistent()); // no change |
| 1445 | EXPECT_EQ(Cellular::kStateEnabled, device_->state_); // changes on completion |
| 1446 | |
| 1447 | // Refresh proxies, since CellularCapabilityUniversal::StartModem wants |
| 1448 | // new proxies. Also, stash away references for later. |
| 1449 | PopulateProxies(); |
| 1450 | SetCommonOnAfterResumeExpectations(); |
| 1451 | mm1_proxy = mm1_proxy_.get(); |
| 1452 | auto dbus_properties_proxy = dbus_properties_proxy_.get(); |
| 1453 | |
| 1454 | // Resume, with disable still in progress. |
| 1455 | EXPECT_CALL(*mm1_proxy, Enable(true, _, _, _)) |
| 1456 | .WillOnce(Invoke(this, &CellularTest::InvokeEnableReturningWrongState)); |
| 1457 | EXPECT_EQ(Cellular::kStateEnabled, device_->state_); // disable still pending |
| 1458 | device_->OnAfterResume(); |
| 1459 | EXPECT_TRUE(device_->running()); // changes immediately |
| 1460 | EXPECT_TRUE(device_->enabled_persistent()); // no change |
| 1461 | EXPECT_EQ(Cellular::kStateDisabled, device_->state_); // by OnAfterResume |
| 1462 | |
| 1463 | // Set up state that we need. |
| 1464 | DBusPropertiesMap modem_properties; |
| 1465 | DBus::Variant modem_state; |
| 1466 | modem_state.writer().append_int32(Cellular::kModemStateDisabled); |
| 1467 | modem_properties = DBusPropertiesMap{{MM_MODEM_PROPERTY_STATE, modem_state}}; |
| 1468 | |
| 1469 | // Let the disable complete. |
| 1470 | EXPECT_CALL(*mm1_proxy, Enable(false, _, _, _)) |
| 1471 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
| 1472 | EXPECT_CALL(*mm1_proxy, SetPowerState(_, _, _, _)) |
| 1473 | .WillOnce(Invoke(this, &CellularTest::InvokeSetPowerState)); |
| 1474 | EXPECT_CALL(*dbus_properties_proxy, GetAll(_)) |
| 1475 | .WillRepeatedly(Return(modem_properties)); |
| 1476 | dispatcher_.DispatchPendingEvents(); |
| 1477 | EXPECT_TRUE(device_->running()); // last changed by OnAfterResume |
| 1478 | EXPECT_TRUE(device_->enabled_persistent()); // last changed by OnAfterResume |
| 1479 | EXPECT_EQ(Cellular::kStateDisabled, device_->state_); |
| 1480 | |
| 1481 | // There's nothing queued up to restart the modem. Even though we |
| 1482 | // want to be running, we're stuck in the disabled state. |
| 1483 | dispatcher_.DispatchPendingEvents(); |
| 1484 | EXPECT_TRUE(device_->running()); |
| 1485 | EXPECT_TRUE(device_->enabled_persistent()); |
| 1486 | EXPECT_EQ(Cellular::kStateDisabled, device_->state_); |
| 1487 | } |
| 1488 | |
| 1489 | TEST_F(CellularTest, OnAfterResumePowerDownInProgressWantEnabled) { |
| 1490 | // The Device was not fully disabled prior to resume, and the |
| 1491 | // profile settings indicate that the device should be enabled. In |
| 1492 | // this case, we have disabled the device, but are waiting for the |
| 1493 | // power-down (switch to low power) to complete. |
| 1494 | // |
| 1495 | // This test emulates the behavior of the Huawei E303 dongle, when |
| 1496 | // Manager::kTerminationActionsTimeoutMilliseconds is 9500 |
| 1497 | // msec. (The dongle takes 10-11 seconds to go through the whole |
| 1498 | // disable, power-down sequence). |
| 1499 | // |
| 1500 | // Eventually, the power-down would complete, and the device would |
| 1501 | // be stuck in the disabled state. To counter-act that, |
| 1502 | // OnAfterResume tries to enable the device now, even though the |
| 1503 | // device is currently enabled. |
| 1504 | |
| 1505 | // Initial state. |
| 1506 | mm1::MockModemProxy *mm1_proxy = SetupOnAfterResume(); |
| 1507 | EXPECT_CALL(*mm1_proxy, Enable(true, _, _, _)) |
| 1508 | .WillOnce(Invoke(this, &CellularTest::InvokeEnable)); |
| 1509 | device_->SetEnabled(true); |
| 1510 | EXPECT_TRUE(device_->running()); |
| 1511 | EXPECT_TRUE(device_->enabled_persistent()); |
| 1512 | EXPECT_EQ(Cellular::kStateEnabled, device_->state_); |
| 1513 | |
| 1514 | // Start disable. |
| 1515 | ResultCallback modem_proxy_enable_callback; |
| 1516 | EXPECT_CALL(*mm1_proxy, Enable(false, _, _, _)) |
| 1517 | .WillOnce(SaveArg<2>(&modem_proxy_enable_callback)); |
| 1518 | device_->SetEnabled(false); |
| 1519 | dispatcher_.DispatchPendingEvents(); // SetEnabled yields a deferred task |
| 1520 | EXPECT_FALSE(device_->running()); // changes immediately |
| 1521 | EXPECT_TRUE(device_->enabled_persistent()); // no change |
| 1522 | EXPECT_EQ(Cellular::kStateEnabled, device_->state_); // changes on completion |
| 1523 | |
| 1524 | // Let the disable complete. That will trigger power-down. |
| 1525 | // |
| 1526 | // Note that, unlike for mm1_proxy->Enable, we don't save the |
| 1527 | // callback for mm1_proxy->SetPowerState. We expect the callback not |
| 1528 | // to be executed, as explained in the comment about having a fresh |
| 1529 | // proxy OnAfterResume, below. |
| 1530 | Error error; |
| 1531 | ASSERT_TRUE(error.IsSuccess()); |
| 1532 | EXPECT_CALL(*mm1_proxy, SetPowerState(MM_MODEM_POWER_STATE_LOW, _, _, _)); |
| 1533 | modem_proxy_enable_callback.Run(error); |
| 1534 | |
| 1535 | // No response to power-down yet. It probably completed while the host |
| 1536 | // was asleep, and so the reply from the modem was lost. |
| 1537 | |
| 1538 | // Refresh proxies, since CellularCapabilityUniversal::StartModem wants |
| 1539 | // new proxies. Also, stash away references for later. |
| 1540 | PopulateProxies(); |
| 1541 | SetCommonOnAfterResumeExpectations(); |
| 1542 | auto new_mm1_proxy = mm1_proxy_.get(); |
| 1543 | auto dbus_properties_proxy = dbus_properties_proxy_.get(); |
| 1544 | |
| 1545 | // Resume. |
| 1546 | ResultCallback new_callback; |
| 1547 | EXPECT_EQ(Cellular::kStateEnabled, device_->state_); // disable still pending |
| 1548 | EXPECT_CALL(*new_mm1_proxy, Enable(true, _, _, _)) |
| 1549 | .WillOnce(SaveArg<2>(&modem_proxy_enable_callback)); |
| 1550 | device_->OnAfterResume(); |
| 1551 | EXPECT_TRUE(device_->running()); // changes immediately |
| 1552 | EXPECT_TRUE(device_->enabled_persistent()); // no change |
| 1553 | EXPECT_EQ(Cellular::kStateDisabled, device_->state_); // by OnAfterResume |
| 1554 | |
| 1555 | // We should have a fresh proxy OnAfterResume. Otherwise, we may get |
| 1556 | // confused when the SetPowerState call completes (either naturally, |
| 1557 | // or via a time-out from dbus-c++). |
| 1558 | // |
| 1559 | // The pointers must differ, because the new proxy is constructed |
| 1560 | // before the old one is destructed. |
| 1561 | EXPECT_FALSE(new_mm1_proxy == mm1_proxy); |
| 1562 | |
| 1563 | // Set up state that we need. |
| 1564 | DBusPropertiesMap modem_properties; |
| 1565 | DBus::Variant modem_state; |
| 1566 | modem_state.writer().append_int32(Cellular::kModemStateEnabled); |
| 1567 | modem_properties = DBusPropertiesMap{{MM_MODEM_PROPERTY_STATE, modem_state}}; |
| 1568 | |
| 1569 | // Let the enable complete. |
| 1570 | ASSERT_TRUE(error.IsSuccess()); |
| 1571 | EXPECT_CALL(*dbus_properties_proxy, GetAll(_)) |
| 1572 | .WillRepeatedly(Return(modem_properties)); |
| 1573 | ASSERT_TRUE(!modem_proxy_enable_callback.is_null()); |
| 1574 | modem_proxy_enable_callback.Run(error); |
| 1575 | EXPECT_TRUE(device_->running()); |
| 1576 | EXPECT_TRUE(device_->enabled_persistent()); |
| 1577 | EXPECT_EQ(Cellular::kStateEnabled, device_->state_); |
| 1578 | } |
| 1579 | |
| 1580 | TEST_F(CellularTest, OnAfterResumeDisabledWantEnabled) { |
| 1581 | // This is the ideal case. The disable process completed before |
| 1582 | // going into suspend. |
| 1583 | mm1::MockModemProxy *mm1_proxy = SetupOnAfterResume(); |
| 1584 | EXPECT_FALSE(device_->running()); |
| 1585 | EXPECT_TRUE(device_->enabled_persistent()); |
| 1586 | EXPECT_EQ(Cellular::kStateDisabled, device_->state_); |
| 1587 | |
| 1588 | // Resume. |
| 1589 | ResultCallback modem_proxy_enable_callback; |
| 1590 | EXPECT_CALL(*mm1_proxy, Enable(true, _, _, _)) |
| 1591 | .WillOnce(SaveArg<2>(&modem_proxy_enable_callback)); |
| 1592 | device_->OnAfterResume(); |
| 1593 | |
| 1594 | // Complete enable. |
| 1595 | Error error; |
| 1596 | ASSERT_TRUE(error.IsSuccess()); |
| 1597 | modem_proxy_enable_callback.Run(error); |
| 1598 | EXPECT_TRUE(device_->running()); |
| 1599 | EXPECT_TRUE(device_->enabled_persistent()); |
| 1600 | EXPECT_EQ(Cellular::kStateEnabled, device_->state_); |
mukesh agrawal | 5c8ed24 | 2013-10-04 11:59:58 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1603 | // Custom property setters should return false, and make no changes, if |
| 1604 | // the new value is the same as the old value. |
| 1605 | TEST_F(CellularTest, CustomSetterNoopChange) { |
| 1606 | Error error; |
| 1607 | EXPECT_FALSE(device_->allow_roaming_); |
| 1608 | EXPECT_FALSE(device_->SetAllowRoaming(false, &error)); |
| 1609 | EXPECT_TRUE(error.IsSuccess()); |
| 1610 | } |
| 1611 | |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 1612 | TEST_F(CellularTest, ScanImmediateFailure) { |
| 1613 | Error error; |
| 1614 | |
| 1615 | device_->set_found_networks(kTestNetworksCellular); |
| 1616 | EXPECT_CALL(*gsm_network_proxy_, Scan(&error, _, _)) |
| 1617 | .WillOnce(Invoke(this, &CellularTest::InvokeScanFailed)); |
| 1618 | EXPECT_FALSE(device_->scanning_); |
| 1619 | // |InitProxies| must be called before calling any functions on the |
| 1620 | // Capability*, to set up the modem proxies. |
| 1621 | // Warning: The test loses all references to the proxies when |InitProxies| is |
| 1622 | // called. |
| 1623 | GetCapabilityGSM()->InitProxies(); |
| 1624 | device_->Scan(Device::kFullScan, &error, ""); |
| 1625 | EXPECT_TRUE(error.IsFailure()); |
| 1626 | EXPECT_FALSE(device_->scanning_); |
| 1627 | EXPECT_EQ(kTestNetworksCellular, device_->found_networks()); |
| 1628 | } |
| 1629 | |
| 1630 | TEST_F(CellularTest, ScanAsynchronousFailure) { |
| 1631 | Error error; |
| 1632 | ScanResultsCallback results_callback; |
| 1633 | |
| 1634 | device_->set_found_networks(kTestNetworksCellular); |
| 1635 | EXPECT_CALL(*gsm_network_proxy_, Scan(&error, _, _)) |
| 1636 | .WillOnce(DoAll(Invoke(this, &CellularTest::InvokeScanInitiated), |
| 1637 | SaveArg<1>(&results_callback))); |
| 1638 | EXPECT_FALSE(device_->scanning_); |
| 1639 | // |InitProxies| must be called before calling any functions on the |
| 1640 | // Capability*, to set up the modem proxies. |
| 1641 | // Warning: The test loses all references to the proxies when |InitProxies| is |
| 1642 | // called. |
| 1643 | GetCapabilityGSM()->InitProxies(); |
| 1644 | device_->Scan(Device::kFullScan, &error, ""); |
| 1645 | EXPECT_TRUE(error.IsOngoing()); |
| 1646 | EXPECT_TRUE(device_->scanning_); |
| 1647 | |
| 1648 | // Asynchronously fail the scan. |
| 1649 | error.Populate(Error::kOperationFailed); |
| 1650 | results_callback.Run(kTestNetworksGSM, error); |
| 1651 | EXPECT_FALSE(device_->scanning_); |
| 1652 | EXPECT_TRUE(device_->found_networks().empty()); |
| 1653 | } |
| 1654 | |
| 1655 | TEST_F(CellularTest, ScanSuccess) { |
| 1656 | Error error; |
| 1657 | ScanResultsCallback results_callback; |
| 1658 | |
| 1659 | device_->clear_found_networks(); |
| 1660 | EXPECT_CALL(*gsm_network_proxy_, Scan(&error, _, _)) |
| 1661 | .WillOnce(DoAll(Invoke(this, &CellularTest::InvokeScanInitiated), |
| 1662 | SaveArg<1>(&results_callback))); |
| 1663 | EXPECT_FALSE(device_->scanning_); |
| 1664 | // |InitProxies| must be called before calling any functions on the |
| 1665 | // Capability*, to set up the modem proxies. |
| 1666 | // Warning: The test loses all references to the proxies when |InitProxies| is |
| 1667 | // called. |
| 1668 | GetCapabilityGSM()->InitProxies(); |
| 1669 | device_->Scan(Device::kFullScan, &error, ""); |
| 1670 | EXPECT_TRUE(error.IsOngoing()); |
| 1671 | EXPECT_TRUE(device_->scanning_); |
| 1672 | |
| 1673 | // Successfully complete the scan. |
| 1674 | const GSMScanResults gsm_results{}; |
| 1675 | error.Populate(Error::kSuccess); |
| 1676 | results_callback.Run(kTestNetworksGSM, error); |
| 1677 | EXPECT_FALSE(device_->scanning_); |
| 1678 | EXPECT_EQ(kTestNetworksCellular, device_->found_networks()); |
| 1679 | } |
| 1680 | |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 1681 | TEST_F(CellularTest, EstablishLinkDHCP) { |
| 1682 | scoped_ptr<CellularBearer> bearer( |
| 1683 | new CellularBearer(&proxy_factory_, "", "")); |
| 1684 | bearer->set_ipv4_config_method(IPConfig::kMethodDHCP); |
| 1685 | SetCapabilityUniversalActiveBearer(bearer.Pass()); |
| 1686 | device_->state_ = Cellular::kStateConnected; |
| 1687 | |
| 1688 | MockCellularService *service = SetMockService(); |
| 1689 | ON_CALL(*service, state()).WillByDefault(Return(Service::kStateUnknown)); |
| 1690 | |
| 1691 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
| 1692 | .WillOnce(DoAll(SetArgumentPointee<1>(IFF_UP), Return(true))); |
| 1693 | EXPECT_CALL(dhcp_provider_, CreateConfig(kTestDeviceName, _, _, _, _)) |
| 1694 | .WillOnce(Return(dhcp_config_)); |
| 1695 | EXPECT_CALL(*dhcp_config_, RequestIP()).WillOnce(Return(true)); |
| 1696 | EXPECT_CALL(*service, SetState(Service::kStateConfiguring)); |
| 1697 | device_->EstablishLink(); |
| 1698 | EXPECT_EQ(service, device_->selected_service()); |
| 1699 | Mock::VerifyAndClearExpectations(service); // before Cellular dtor |
| 1700 | } |
| 1701 | |
| 1702 | TEST_F(CellularTest, EstablishLinkPPP) { |
| 1703 | scoped_ptr<CellularBearer> bearer( |
| 1704 | new CellularBearer(&proxy_factory_, "", "")); |
| 1705 | bearer->set_ipv4_config_method(IPConfig::kMethodPPP); |
| 1706 | SetCapabilityUniversalActiveBearer(bearer.Pass()); |
| 1707 | device_->state_ = Cellular::kStateConnected; |
| 1708 | |
| 1709 | const int kPID = 123; |
| 1710 | MockGLib &mock_glib(*dynamic_cast<MockGLib *>(modem_info_.glib())); |
| 1711 | EXPECT_CALL(mock_glib, ChildWatchAdd(kPID, _, _)); |
| 1712 | EXPECT_CALL(mock_glib, SpawnAsync(_, _, _, _, _, _, _, _)) |
| 1713 | .WillOnce(DoAll(SetArgumentPointee<6>(kPID), Return(true))); |
| 1714 | device_->EstablishLink(); |
| 1715 | EXPECT_FALSE(device_->ipconfig()); // No DHCP client. |
| 1716 | EXPECT_FALSE(device_->selected_service()); |
| 1717 | EXPECT_FALSE(device_->is_ppp_authenticating_); |
| 1718 | EXPECT_TRUE(device_->ppp_task_); |
| 1719 | } |
| 1720 | |
| 1721 | TEST_F(CellularTest, EstablishLinkStatic) { |
| 1722 | IPAddress::Family kAddressFamily = IPAddress::kFamilyIPv4; |
| 1723 | const char kAddress[] = "10.0.0.1"; |
| 1724 | const char kGateway[] = "10.0.0.254"; |
| 1725 | const int32 kSubnetPrefix = 16; |
| 1726 | const char *const kDNS[] = {"10.0.0.2", "8.8.4.4", "8.8.8.8"}; |
| 1727 | |
| 1728 | scoped_ptr<IPConfig::Properties> ipconfig_properties( |
| 1729 | new IPConfig::Properties); |
| 1730 | ipconfig_properties->address_family = kAddressFamily; |
| 1731 | ipconfig_properties->address = kAddress; |
| 1732 | ipconfig_properties->gateway = kGateway; |
| 1733 | ipconfig_properties->subnet_prefix = kSubnetPrefix; |
| 1734 | ipconfig_properties->dns_servers = vector<string>{kDNS[0], kDNS[1], kDNS[2]}; |
| 1735 | |
| 1736 | scoped_ptr<CellularBearer> bearer( |
| 1737 | new CellularBearer(&proxy_factory_, "", "")); |
| 1738 | bearer->set_ipv4_config_method(IPConfig::kMethodStatic); |
| 1739 | bearer->set_ipv4_config_properties(ipconfig_properties.Pass()); |
| 1740 | SetCapabilityUniversalActiveBearer(bearer.Pass()); |
| 1741 | device_->state_ = Cellular::kStateConnected; |
| 1742 | |
| 1743 | MockCellularService *service = SetMockService(); |
| 1744 | ON_CALL(*service, state()).WillByDefault(Return(Service::kStateUnknown)); |
| 1745 | |
| 1746 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
| 1747 | .WillOnce(DoAll(SetArgumentPointee<1>(IFF_UP), Return(true))); |
| 1748 | EXPECT_CALL(*service, SetState(Service::kStateConfiguring)); |
| 1749 | device_->EstablishLink(); |
| 1750 | EXPECT_EQ(service, device_->selected_service()); |
| 1751 | ASSERT_TRUE(device_->ipconfig()); |
| 1752 | EXPECT_EQ(kAddressFamily, device_->ipconfig()->properties().address_family); |
| 1753 | EXPECT_EQ(kAddress, device_->ipconfig()->properties().address); |
| 1754 | EXPECT_EQ(kGateway, device_->ipconfig()->properties().gateway); |
| 1755 | EXPECT_EQ(kSubnetPrefix, device_->ipconfig()->properties().subnet_prefix); |
| 1756 | ASSERT_EQ(3, device_->ipconfig()->properties().dns_servers.size()); |
| 1757 | EXPECT_EQ(kDNS[0], device_->ipconfig()->properties().dns_servers[0]); |
| 1758 | EXPECT_EQ(kDNS[1], device_->ipconfig()->properties().dns_servers[1]); |
| 1759 | EXPECT_EQ(kDNS[2], device_->ipconfig()->properties().dns_servers[2]); |
| 1760 | Mock::VerifyAndClearExpectations(service); // before Cellular dtor |
| 1761 | } |
| 1762 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1763 | } // namespace shill |