Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/cellular.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 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 11 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 12 | #include <mm/mm-modem.h> |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 13 | #include <mobile_provider.h> |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 14 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame^] | 15 | #include "shill/cellular_capability_gsm.h" |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 16 | #include "shill/cellular_service.h" |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 17 | #include "shill/error.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 18 | #include "shill/event_dispatcher.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 19 | #include "shill/mock_device_info.h" |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 20 | #include "shill/mock_dhcp_config.h" |
| 21 | #include "shill/mock_dhcp_provider.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 22 | #include "shill/mock_manager.h" |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 23 | #include "shill/mock_modem_cdma_proxy.h" |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 24 | #include "shill/mock_modem_gsm_card_proxy.h" |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 25 | #include "shill/mock_modem_gsm_network_proxy.h" |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 26 | #include "shill/mock_modem_proxy.h" |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 27 | #include "shill/mock_modem_simple_proxy.h" |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 28 | #include "shill/mock_rtnl_handler.h" |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 29 | #include "shill/nice_mock_control.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 30 | #include "shill/property_store_unittest.h" |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 31 | #include "shill/proxy_factory.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 32 | |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 33 | using std::map; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 34 | using std::string; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 35 | using testing::_; |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 36 | using testing::AnyNumber; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 37 | using testing::NiceMock; |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 38 | using testing::Return; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 39 | using testing::SetArgumentPointee; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 40 | |
| 41 | namespace shill { |
| 42 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 43 | class CellularPropertyTest : public PropertyStoreTest { |
| 44 | public: |
| 45 | CellularPropertyTest() |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 46 | : device_(new Cellular(control_interface(), |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 47 | NULL, |
| 48 | NULL, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 49 | "usb0", |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 50 | "00:01:02:03:04:05", |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 51 | 3, |
| 52 | Cellular::kTypeGSM, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 53 | "", |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 54 | "", |
| 55 | NULL)) {} |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 56 | virtual ~CellularPropertyTest() {} |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 57 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 58 | protected: |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 59 | DeviceRefPtr device_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 62 | TEST_F(CellularPropertyTest, Contains) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 63 | EXPECT_TRUE(device_->store().Contains(flimflam::kNameProperty)); |
| 64 | EXPECT_FALSE(device_->store().Contains("")); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 67 | TEST_F(CellularPropertyTest, Dispatch) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 68 | { |
| 69 | ::DBus::Error error; |
| 70 | EXPECT_TRUE(DBusAdaptor::DispatchOnType( |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 71 | device_->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 72 | flimflam::kCellularAllowRoamingProperty, |
| 73 | PropertyStoreTest::kBoolV, |
| 74 | &error)); |
| 75 | } |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 76 | // Ensure that attempting to write a R/O property returns InvalidArgs error. |
| 77 | { |
| 78 | ::DBus::Error error; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 79 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(device_->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 80 | flimflam::kAddressProperty, |
| 81 | PropertyStoreTest::kStringV, |
| 82 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 83 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 84 | } |
| 85 | { |
| 86 | ::DBus::Error error; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 87 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(device_->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 88 | flimflam::kCarrierProperty, |
| 89 | PropertyStoreTest::kStringV, |
| 90 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 91 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 92 | } |
| 93 | { |
| 94 | ::DBus::Error error; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 95 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(device_->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 96 | flimflam::kPRLVersionProperty, |
| 97 | PropertyStoreTest::kInt16V, |
| 98 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 99 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 100 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 103 | class CellularTest : public testing::Test { |
| 104 | public: |
| 105 | CellularTest() |
| 106 | : manager_(&control_interface_, &dispatcher_, &glib_), |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 107 | device_info_(&control_interface_, &dispatcher_, &manager_), |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 108 | proxy_(new MockModemProxy()), |
| 109 | simple_proxy_(new MockModemSimpleProxy()), |
| 110 | cdma_proxy_(new MockModemCDMAProxy()), |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 111 | gsm_card_proxy_(new MockModemGSMCardProxy()), |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 112 | gsm_network_proxy_(new MockModemGSMNetworkProxy()), |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 113 | proxy_factory_(this), |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 114 | dhcp_config_(new MockDHCPConfig(&control_interface_, |
| 115 | &dispatcher_, |
| 116 | &dhcp_provider_, |
| 117 | kTestDeviceName, |
| 118 | &glib_)), |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 119 | device_(new Cellular(&control_interface_, |
| 120 | &dispatcher_, |
| 121 | &manager_, |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 122 | kTestDeviceName, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 123 | kTestDeviceAddress, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 124 | 3, |
| 125 | Cellular::kTypeGSM, |
| 126 | kDBusOwner, |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 127 | kDBusPath, |
| 128 | NULL)), |
| 129 | provider_db_(NULL) {} |
| 130 | |
| 131 | virtual ~CellularTest() { |
| 132 | mobile_provider_close_db(provider_db_); |
| 133 | provider_db_ = NULL; |
| 134 | } |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 135 | |
| 136 | virtual void SetUp() { |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 137 | device_->proxy_factory_ = &proxy_factory_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 138 | static_cast<Device *>(device_)->rtnl_handler_ = &rtnl_handler_; |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 139 | device_->set_dhcp_provider(&dhcp_provider_); |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 140 | EXPECT_CALL(manager_, device_info()).WillRepeatedly(Return(&device_info_)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 141 | EXPECT_CALL(manager_, DeregisterService(_)).Times(AnyNumber()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | virtual void TearDown() { |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 145 | device_->proxy_factory_ = NULL; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 146 | device_->Stop(); |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 147 | device_->set_dhcp_provider(NULL); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | protected: |
| 151 | class TestProxyFactory : public ProxyFactory { |
| 152 | public: |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 153 | explicit TestProxyFactory(CellularTest *test) : test_(test) {} |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 154 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 155 | virtual ModemProxyInterface *CreateModemProxy( |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 156 | ModemProxyDelegate */*delegate*/, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 157 | const string &/*path*/, |
| 158 | const string &/*service*/) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 159 | return test_->proxy_.release(); |
| 160 | } |
| 161 | |
| 162 | virtual ModemSimpleProxyInterface *CreateModemSimpleProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 163 | const string &/*path*/, |
| 164 | const string &/*service*/) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 165 | return test_->simple_proxy_.release(); |
| 166 | } |
| 167 | |
| 168 | virtual ModemCDMAProxyInterface *CreateModemCDMAProxy( |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 169 | ModemCDMAProxyDelegate */*delegate*/, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 170 | const string &/*path*/, |
| 171 | const string &/*service*/) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 172 | return test_->cdma_proxy_.release(); |
| 173 | } |
| 174 | |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 175 | virtual ModemGSMCardProxyInterface *CreateModemGSMCardProxy( |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 176 | ModemGSMCardProxyDelegate */*delegate*/, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 177 | const string &/*path*/, |
| 178 | const string &/*service*/) { |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 179 | return test_->gsm_card_proxy_.release(); |
| 180 | } |
| 181 | |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 182 | virtual ModemGSMNetworkProxyInterface *CreateModemGSMNetworkProxy( |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 183 | ModemGSMNetworkProxyDelegate */*delegate*/, |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 184 | const string &/*path*/, |
| 185 | const string &/*service*/) { |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 186 | return test_->gsm_network_proxy_.release(); |
| 187 | } |
| 188 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 189 | private: |
| 190 | CellularTest *test_; |
| 191 | }; |
| 192 | |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 193 | static const char kTestDeviceName[]; |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 194 | static const char kTestDeviceAddress[]; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 195 | static const int kTestSocket; |
| 196 | static const char kDBusOwner[]; |
| 197 | static const char kDBusPath[]; |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 198 | static const char kTestCarrier[]; |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 199 | static const char kMEID[]; |
| 200 | static const char kIMEI[]; |
| 201 | static const char kIMSI[]; |
| 202 | static const char kMSISDN[]; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 203 | static const char kTestMobileProviderDBPath[]; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 204 | |
| 205 | void StartRTNLHandler(); |
| 206 | void StopRTNLHandler(); |
| 207 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 208 | NiceMockControl control_interface_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 209 | EventDispatcher dispatcher_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 210 | MockGLib glib_; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 211 | MockManager manager_; |
| 212 | MockDeviceInfo device_info_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 213 | NiceMock<MockRTNLHandler> rtnl_handler_; |
| 214 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 215 | scoped_ptr<MockModemProxy> proxy_; |
| 216 | scoped_ptr<MockModemSimpleProxy> simple_proxy_; |
| 217 | scoped_ptr<MockModemCDMAProxy> cdma_proxy_; |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 218 | scoped_ptr<MockModemGSMCardProxy> gsm_card_proxy_; |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 219 | scoped_ptr<MockModemGSMNetworkProxy> gsm_network_proxy_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 220 | TestProxyFactory proxy_factory_; |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 221 | |
| 222 | MockDHCPProvider dhcp_provider_; |
| 223 | scoped_refptr<MockDHCPConfig> dhcp_config_; |
| 224 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 225 | CellularRefPtr device_; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 226 | mobile_provider_db *provider_db_; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 227 | }; |
| 228 | |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 229 | const char CellularTest::kTestDeviceName[] = "usb0"; |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 230 | const char CellularTest::kTestDeviceAddress[] = "00:01:02:03:04:05"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 231 | const char CellularTest::kDBusOwner[] = ":1.19"; |
| 232 | const char CellularTest::kDBusPath[] = "/org/chromium/ModemManager/Gobi/0"; |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 233 | const char CellularTest::kTestCarrier[] = "The Cellular Carrier"; |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 234 | const char CellularTest::kMEID[] = "D1234567EF8901"; |
| 235 | const char CellularTest::kIMEI[] = "987654321098765"; |
| 236 | const char CellularTest::kIMSI[] = "123456789012345"; |
| 237 | const char CellularTest::kMSISDN[] = "12345678901"; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 238 | const char CellularTest::kTestMobileProviderDBPath[] = |
| 239 | "provider_db_unittest.bfd"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 240 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 241 | TEST_F(CellularTest, GetTypeString) { |
| 242 | EXPECT_EQ("CellularTypeGSM", device_->GetTypeString()); |
| 243 | device_->type_ = Cellular::kTypeCDMA; |
| 244 | EXPECT_EQ("CellularTypeCDMA", device_->GetTypeString()); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | TEST_F(CellularTest, GetStateString) { |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 248 | EXPECT_EQ("CellularStateDisabled", |
| 249 | device_->GetStateString(Cellular::kStateDisabled)); |
| 250 | EXPECT_EQ("CellularStateEnabled", |
| 251 | device_->GetStateString(Cellular::kStateEnabled)); |
| 252 | EXPECT_EQ("CellularStateRegistered", |
| 253 | device_->GetStateString(Cellular::kStateRegistered)); |
| 254 | EXPECT_EQ("CellularStateConnected", |
| 255 | device_->GetStateString(Cellular::kStateConnected)); |
| 256 | EXPECT_EQ("CellularStateLinked", |
| 257 | device_->GetStateString(Cellular::kStateLinked)); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 260 | TEST_F(CellularTest, GetCDMAActivationStateString) { |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 261 | EXPECT_EQ(flimflam::kActivationStateActivated, |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 262 | device_->GetCDMAActivationStateString( |
| 263 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED)); |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 264 | EXPECT_EQ(flimflam::kActivationStateActivating, |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 265 | device_->GetCDMAActivationStateString( |
| 266 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING)); |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 267 | EXPECT_EQ(flimflam::kActivationStateNotActivated, |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 268 | device_->GetCDMAActivationStateString( |
| 269 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED)); |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 270 | EXPECT_EQ(flimflam::kActivationStatePartiallyActivated, |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 271 | device_->GetCDMAActivationStateString( |
| 272 | MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED)); |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 273 | EXPECT_EQ(flimflam::kActivationStateUnknown, |
| 274 | device_->GetCDMAActivationStateString(123)); |
| 275 | } |
| 276 | |
| 277 | TEST_F(CellularTest, GetCDMAActivationErrorString) { |
| 278 | EXPECT_EQ(flimflam::kErrorNeedEvdo, |
| 279 | device_->GetCDMAActivationErrorString( |
| 280 | MM_MODEM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE)); |
| 281 | EXPECT_EQ(flimflam::kErrorNeedHomeNetwork, |
| 282 | device_->GetCDMAActivationErrorString( |
| 283 | MM_MODEM_CDMA_ACTIVATION_ERROR_ROAMING)); |
| 284 | EXPECT_EQ(flimflam::kErrorOtaspFailed, |
| 285 | device_->GetCDMAActivationErrorString( |
| 286 | MM_MODEM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT)); |
| 287 | EXPECT_EQ(flimflam::kErrorOtaspFailed, |
| 288 | device_->GetCDMAActivationErrorString( |
| 289 | MM_MODEM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED)); |
| 290 | EXPECT_EQ(flimflam::kErrorOtaspFailed, |
| 291 | device_->GetCDMAActivationErrorString( |
| 292 | MM_MODEM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED)); |
| 293 | EXPECT_EQ("", |
| 294 | device_->GetCDMAActivationErrorString( |
| 295 | MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR)); |
| 296 | EXPECT_EQ(flimflam::kErrorActivationFailed, |
| 297 | device_->GetCDMAActivationErrorString( |
| 298 | MM_MODEM_CDMA_ACTIVATION_ERROR_NO_SIGNAL)); |
| 299 | EXPECT_EQ(flimflam::kErrorActivationFailed, |
| 300 | device_->GetCDMAActivationErrorString(1234)); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 303 | TEST_F(CellularTest, StartCDMARegister) { |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 304 | const int kStrength = 90; |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 305 | device_->type_ = Cellular::kTypeCDMA; |
| 306 | EXPECT_CALL(*proxy_, Enable(true)).Times(1); |
| 307 | EXPECT_CALL(*simple_proxy_, GetStatus()) |
| 308 | .WillOnce(Return(DBusPropertiesMap())); |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 309 | EXPECT_CALL(*cdma_proxy_, MEID()).WillOnce(Return(kMEID)); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 310 | EXPECT_CALL(*proxy_, GetInfo()).WillOnce(Return(ModemProxyInterface::Info())); |
| 311 | EXPECT_CALL(*cdma_proxy_, GetRegistrationState(_, _)) |
| 312 | .WillOnce(DoAll( |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 313 | SetArgumentPointee<0>(MM_MODEM_CDMA_REGISTRATION_STATE_HOME), |
| 314 | SetArgumentPointee<1>(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN))); |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 315 | EXPECT_CALL(*cdma_proxy_, GetSignalQuality()).WillOnce(Return(kStrength)); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 316 | device_->Start(); |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 317 | EXPECT_EQ(kMEID, device_->meid_); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 318 | dispatcher_.DispatchPendingEvents(); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 319 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 320 | ASSERT_TRUE(device_->service_.get()); |
| 321 | EXPECT_EQ(flimflam::kNetworkTechnology1Xrtt, |
| 322 | device_->service_->network_tech()); |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 323 | EXPECT_EQ(kStrength, device_->service_->strength()); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 324 | EXPECT_EQ(flimflam::kRoamingStateHome, device_->service_->roaming_state()); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 327 | TEST_F(CellularTest, StartGSMRegister) { |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 328 | device_->type_ = Cellular::kTypeGSM; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 329 | provider_db_ = mobile_provider_open_db(kTestMobileProviderDBPath); |
| 330 | ASSERT_TRUE(provider_db_); |
| 331 | device_->provider_db_ = provider_db_; |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 332 | const int kStrength = 70; |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 333 | EXPECT_CALL(*proxy_, Enable(true)).Times(1); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame^] | 334 | EXPECT_CALL(*gsm_network_proxy_, Register("")).Times(1); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 335 | EXPECT_CALL(*simple_proxy_, GetStatus()) |
| 336 | .WillOnce(Return(DBusPropertiesMap())); |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 337 | EXPECT_CALL(*gsm_card_proxy_, GetIMEI()).WillOnce(Return(kIMEI)); |
| 338 | EXPECT_CALL(*gsm_card_proxy_, GetIMSI()).WillOnce(Return(kIMSI)); |
| 339 | EXPECT_CALL(*gsm_card_proxy_, GetSPN()).WillOnce(Return(kTestCarrier)); |
| 340 | EXPECT_CALL(*gsm_card_proxy_, GetMSISDN()).WillOnce(Return(kMSISDN)); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 341 | EXPECT_CALL(*gsm_network_proxy_, AccessTechnology()) |
| 342 | .WillOnce(Return(MM_MODEM_GSM_ACCESS_TECH_EDGE)); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 343 | EXPECT_CALL(*proxy_, GetInfo()).WillOnce(Return(ModemProxyInterface::Info())); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 344 | ModemGSMNetworkProxyInterface::RegistrationInfo reg_info; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 345 | static const char kNetworkID[] = "22803"; |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 346 | reg_info._1 = MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 347 | reg_info._2 = kNetworkID; |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 348 | EXPECT_CALL(*gsm_network_proxy_, GetRegistrationInfo()) |
| 349 | .WillOnce(Return(reg_info)); |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 350 | EXPECT_CALL(*gsm_network_proxy_, GetSignalQuality()) |
| 351 | .WillOnce(Return(kStrength)); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 352 | device_->Start(); |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 353 | EXPECT_EQ(kIMEI, device_->imei_); |
| 354 | EXPECT_EQ(kIMSI, device_->imsi_); |
| 355 | EXPECT_EQ(kTestCarrier, device_->gsm_.spn); |
| 356 | EXPECT_EQ(kMSISDN, device_->mdn_); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 357 | dispatcher_.DispatchPendingEvents(); |
| 358 | EXPECT_EQ(Cellular::kStateRegistered, device_->state_); |
| 359 | ASSERT_TRUE(device_->service_.get()); |
| 360 | EXPECT_EQ(flimflam::kNetworkTechnologyEdge, |
| 361 | device_->service_->network_tech()); |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 362 | EXPECT_EQ(kStrength, device_->service_->strength()); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 363 | EXPECT_EQ(flimflam::kRoamingStateRoaming, device_->service_->roaming_state()); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 364 | EXPECT_EQ(kNetworkID, device_->service_->serving_operator().GetCode()); |
| 365 | EXPECT_EQ("Orange", device_->service_->serving_operator().GetName()); |
| 366 | EXPECT_EQ("ch", device_->service_->serving_operator().GetCountry()); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 369 | TEST_F(CellularTest, StartConnected) { |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 370 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
| 371 | .WillOnce(Return(true)); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 372 | device_->type_ = Cellular::kTypeCDMA; |
| 373 | device_->set_modem_state(Cellular::kModemStateConnected); |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 374 | device_->meid_ = kMEID; |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 375 | EXPECT_CALL(*proxy_, Enable(true)).Times(1); |
| 376 | EXPECT_CALL(*simple_proxy_, GetStatus()) |
| 377 | .WillOnce(Return(DBusPropertiesMap())); |
| 378 | EXPECT_CALL(*proxy_, GetInfo()).WillOnce(Return(ModemProxyInterface::Info())); |
| 379 | EXPECT_CALL(*cdma_proxy_, GetRegistrationState(_, _)) |
| 380 | .WillOnce(DoAll( |
| 381 | SetArgumentPointee<0>(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED), |
| 382 | SetArgumentPointee<1>(MM_MODEM_CDMA_REGISTRATION_STATE_HOME))); |
| 383 | EXPECT_CALL(*cdma_proxy_, GetSignalQuality()).WillOnce(Return(90)); |
| 384 | device_->Start(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 385 | dispatcher_.DispatchPendingEvents(); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 386 | EXPECT_EQ(Cellular::kStateConnected, device_->state_); |
| 387 | } |
| 388 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 389 | TEST_F(CellularTest, StartLinked) { |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 390 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
| 391 | .WillOnce(DoAll(SetArgumentPointee<1>(IFF_UP), Return(true))); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 392 | device_->type_ = Cellular::kTypeCDMA; |
| 393 | device_->set_modem_state(Cellular::kModemStateConnected); |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 394 | device_->meid_ = kMEID; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 395 | EXPECT_CALL(*proxy_, Enable(true)).Times(1); |
| 396 | EXPECT_CALL(*simple_proxy_, GetStatus()) |
| 397 | .WillOnce(Return(DBusPropertiesMap())); |
| 398 | EXPECT_CALL(*proxy_, GetInfo()).WillOnce(Return(ModemProxyInterface::Info())); |
| 399 | EXPECT_CALL(*cdma_proxy_, GetRegistrationState(_, _)) |
| 400 | .WillOnce(DoAll( |
| 401 | SetArgumentPointee<0>(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED), |
| 402 | SetArgumentPointee<1>(MM_MODEM_CDMA_REGISTRATION_STATE_HOME))); |
| 403 | EXPECT_CALL(*cdma_proxy_, GetSignalQuality()).WillOnce(Return(90)); |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 404 | EXPECT_CALL(dhcp_provider_, CreateConfig(kTestDeviceName)) |
| 405 | .WillOnce(Return(dhcp_config_)); |
| 406 | EXPECT_CALL(*dhcp_config_, RequestIP()).WillOnce(Return(true)); |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 407 | EXPECT_CALL(manager_, UpdateService(_)).Times(2); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 408 | device_->Start(); |
| 409 | dispatcher_.DispatchPendingEvents(); |
| 410 | EXPECT_EQ(Cellular::kStateLinked, device_->state_); |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 411 | EXPECT_EQ(Service::kStateConfiguring, device_->service_->state()); |
| 412 | device_->SelectService(NULL); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 415 | TEST_F(CellularTest, InitProxiesCDMA) { |
| 416 | device_->type_ = Cellular::kTypeCDMA; |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 417 | device_->InitCapability(); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 418 | device_->InitProxies(); |
| 419 | EXPECT_TRUE(device_->proxy_.get()); |
| 420 | EXPECT_TRUE(device_->simple_proxy_.get()); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | TEST_F(CellularTest, InitProxiesGSM) { |
| 424 | device_->type_ = Cellular::kTypeGSM; |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 425 | device_->InitCapability(); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 426 | device_->InitProxies(); |
| 427 | EXPECT_TRUE(device_->proxy_.get()); |
| 428 | EXPECT_TRUE(device_->simple_proxy_.get()); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 431 | TEST_F(CellularTest, GetModemStatus) { |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 432 | device_->type_ = Cellular::kTypeCDMA; |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 433 | DBusPropertiesMap props; |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 434 | props["carrier"].writer().append_string(kTestCarrier); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 435 | props["unknown-property"].writer().append_string("irrelevant-value"); |
| 436 | EXPECT_CALL(*simple_proxy_, GetStatus()).WillOnce(Return(props)); |
| 437 | device_->simple_proxy_.reset(simple_proxy_.release()); |
| 438 | device_->state_ = Cellular::kStateEnabled; |
| 439 | device_->GetModemStatus(); |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 440 | EXPECT_EQ(kTestCarrier, device_->carrier_); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 441 | EXPECT_EQ(kTestCarrier, device_->home_provider_.GetName()); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | TEST_F(CellularTest, GetModemInfo) { |
| 445 | static const char kManufacturer[] = "Company"; |
| 446 | static const char kModelID[] = "Gobi 2000"; |
| 447 | static const char kHWRev[] = "A00B1234"; |
| 448 | ModemProxyInterface::Info info; |
| 449 | info._1 = kManufacturer; |
| 450 | info._2 = kModelID; |
| 451 | info._3 = kHWRev; |
| 452 | EXPECT_CALL(*proxy_, GetInfo()).WillOnce(Return(info)); |
| 453 | device_->proxy_.reset(proxy_.release()); |
| 454 | device_->GetModemInfo(); |
| 455 | EXPECT_EQ(kManufacturer, device_->manufacturer_); |
| 456 | EXPECT_EQ(kModelID, device_->model_id_); |
| 457 | EXPECT_EQ(kHWRev, device_->hardware_revision_); |
| 458 | } |
| 459 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 460 | TEST_F(CellularTest, CreateService) { |
| 461 | device_->type_ = Cellular::kTypeCDMA; |
| 462 | static const char kPaymentURL[] = "https://payment.url"; |
| 463 | static const char kUsageURL[] = "https://usage.url"; |
| 464 | device_->cdma_.payment_url = kPaymentURL; |
| 465 | device_->cdma_.usage_url = kUsageURL; |
| 466 | device_->home_provider_.SetName(kTestCarrier); |
| 467 | device_->CreateService(); |
| 468 | ASSERT_TRUE(device_->service_.get()); |
| 469 | EXPECT_EQ(kPaymentURL, device_->service_->payment_url()); |
| 470 | EXPECT_EQ(kUsageURL, device_->service_->usage_url()); |
| 471 | EXPECT_EQ(kTestCarrier, device_->service_->serving_operator().GetName()); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 472 | EXPECT_TRUE(device_->service_->TechnologyIs(Technology::kCellular)); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 475 | namespace { |
| 476 | |
| 477 | MATCHER(ContainsPhoneNumber, "") { |
| 478 | return ContainsKey(arg, Cellular::kConnectPropertyPhoneNumber); |
| 479 | } |
| 480 | |
| 481 | } // namespace {} |
| 482 | |
| 483 | TEST_F(CellularTest, Connect) { |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 484 | Error error; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 485 | EXPECT_CALL(device_info_, GetFlags(device_->interface_index(), _)) |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 486 | .Times(2) |
| 487 | .WillRepeatedly(Return(true)); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 488 | device_->state_ = Cellular::kStateConnected; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 489 | device_->Connect(&error); |
| 490 | EXPECT_EQ(Error::kAlreadyConnected, error.type()); |
| 491 | error.Populate(Error::kSuccess); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 492 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 493 | device_->state_ = Cellular::kStateLinked; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 494 | device_->Connect(&error); |
| 495 | EXPECT_EQ(Error::kAlreadyConnected, error.type()); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 496 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 497 | device_->state_ = Cellular::kStateRegistered; |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 498 | device_->service_ = new CellularService( |
| 499 | &control_interface_, &dispatcher_, &manager_, device_); |
| 500 | |
| 501 | device_->allow_roaming_ = false; |
| 502 | device_->service_->set_roaming_state(flimflam::kRoamingStateRoaming); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 503 | device_->Connect(&error); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 504 | ASSERT_TRUE(device_->task_factory_.empty()); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 505 | EXPECT_EQ(Error::kNotOnHomeNetwork, error.type()); |
| 506 | error.Populate(Error::kSuccess); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 507 | |
| 508 | device_->service_->set_roaming_state(flimflam::kRoamingStateHome); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 509 | device_->Connect(&error); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 510 | ASSERT_FALSE(device_->task_factory_.empty()); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 511 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 512 | |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 513 | device_->allow_roaming_ = true; |
| 514 | device_->service_->set_roaming_state(flimflam::kRoamingStateRoaming); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 515 | device_->Connect(&error); |
| 516 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 517 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 518 | DBusPropertiesMap properties; |
| 519 | properties[Cellular::kConnectPropertyPhoneNumber].writer().append_string( |
| 520 | Cellular::kPhoneNumberGSM); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 521 | EXPECT_CALL(*simple_proxy_, Connect(ContainsPhoneNumber())).Times(2); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 522 | device_->simple_proxy_.reset(simple_proxy_.release()); |
| 523 | dispatcher_.DispatchPendingEvents(); |
| 524 | } |
| 525 | |
Darin Petkov | 48a511a | 2011-09-15 10:33:37 -0700 | [diff] [blame] | 526 | TEST_F(CellularTest, SetGSMAccessTechnology) { |
| 527 | device_->type_ = Cellular::kTypeGSM; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 528 | device_->InitCapability(); |
Darin Petkov | 48a511a | 2011-09-15 10:33:37 -0700 | [diff] [blame] | 529 | device_->SetGSMAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM); |
| 530 | EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_GSM, device_->gsm_.access_technology); |
| 531 | device_->service_ = new CellularService( |
| 532 | &control_interface_, &dispatcher_, &manager_, device_); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame^] | 533 | dynamic_cast<CellularCapabilityGSM *>(device_->capability_.get())-> |
| 534 | registration_state_ = MM_MODEM_GSM_NETWORK_REG_STATUS_HOME; |
Darin Petkov | 48a511a | 2011-09-15 10:33:37 -0700 | [diff] [blame] | 535 | device_->SetGSMAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GPRS); |
| 536 | EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_GPRS, device_->gsm_.access_technology); |
| 537 | EXPECT_EQ(flimflam::kNetworkTechnologyGprs, |
| 538 | device_->service_->network_tech()); |
| 539 | } |
| 540 | |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 541 | TEST_F(CellularTest, UpdateGSMOperatorInfo) { |
| 542 | static const char kOperatorName[] = "Swisscom"; |
| 543 | provider_db_ = mobile_provider_open_db(kTestMobileProviderDBPath); |
| 544 | ASSERT_TRUE(provider_db_); |
| 545 | device_->provider_db_ = provider_db_; |
| 546 | device_->gsm_.network_id = "22801"; |
| 547 | device_->service_ = new CellularService( |
| 548 | &control_interface_, &dispatcher_, &manager_, device_); |
| 549 | device_->UpdateGSMOperatorInfo(); |
| 550 | EXPECT_EQ(kOperatorName, device_->gsm_.operator_name); |
| 551 | EXPECT_EQ("ch", device_->gsm_.operator_country); |
| 552 | EXPECT_EQ(kOperatorName, device_->service_->serving_operator().GetName()); |
| 553 | } |
| 554 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 555 | } // namespace shill |