Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [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_capability_universal.h" |
| 6 | |
Nathan Williams | 4b7c2a8 | 2012-04-13 15:19:47 -0400 | [diff] [blame] | 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 10 | #include <base/bind.h> |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 11 | #include <base/stringprintf.h> |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 12 | #include <base/string_util.h> |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 13 | #include <chromeos/dbus/service_constants.h> |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 14 | #include <gmock/gmock.h> |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 15 | #include <gtest/gtest.h> |
| 16 | #include <mobile_provider.h> |
Ben Chan | 5c853ef | 2012-10-05 00:05:37 -0700 | [diff] [blame] | 17 | #include <ModemManager/ModemManager.h> |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 18 | |
| 19 | #include "shill/cellular.h" |
| 20 | #include "shill/cellular_service.h" |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 21 | #include "shill/dbus_adaptor.h" |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 22 | #include "shill/error.h" |
| 23 | #include "shill/event_dispatcher.h" |
| 24 | #include "shill/mock_adaptors.h" |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 25 | #include "shill/mock_cellular_operator_info.h" |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 26 | #include "shill/mock_cellular_service.h" |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 27 | #include "shill/mock_dbus_properties_proxy.h" |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 28 | #include "shill/mock_event_dispatcher.h" |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 29 | #include "shill/mock_mm1_bearer_proxy.h" |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 30 | #include "shill/mock_mm1_modem_modem3gpp_proxy.h" |
| 31 | #include "shill/mock_mm1_modem_modemcdma_proxy.h" |
| 32 | #include "shill/mock_mm1_modem_proxy.h" |
| 33 | #include "shill/mock_mm1_modem_simple_proxy.h" |
| 34 | #include "shill/mock_mm1_sim_proxy.h" |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 35 | #include "shill/mock_modem_info.h" |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 36 | #include "shill/mock_pending_activation_store.h" |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 37 | #include "shill/mock_profile.h" |
| 38 | #include "shill/mock_rtnl_handler.h" |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 39 | #include "shill/proxy_factory.h" |
| 40 | |
| 41 | using base::Bind; |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 42 | using base::StringPrintf; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 43 | using base::Unretained; |
| 44 | using std::string; |
Nathan Williams | 4b7c2a8 | 2012-04-13 15:19:47 -0400 | [diff] [blame] | 45 | using std::vector; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 46 | using testing::InSequence; |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 47 | using testing::Invoke; |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 48 | using testing::InvokeWithoutArgs; |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 49 | using testing::Mock; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 50 | using testing::NiceMock; |
| 51 | using testing::Return; |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 52 | using testing::SaveArg; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 53 | using testing::_; |
| 54 | |
| 55 | namespace shill { |
| 56 | |
| 57 | MATCHER(IsSuccess, "") { |
| 58 | return arg.IsSuccess(); |
| 59 | } |
| 60 | MATCHER(IsFailure, "") { |
| 61 | return arg.IsFailure(); |
| 62 | } |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 63 | MATCHER_P(HasApn, expected_apn, "") { |
| 64 | string apn; |
| 65 | return (DBusProperties::GetString(arg, |
| 66 | CellularCapabilityUniversal::kConnectApn, |
| 67 | &apn) && |
| 68 | apn == expected_apn); |
| 69 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 70 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 71 | class CellularCapabilityUniversalTest : public testing::TestWithParam<string> { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 72 | public: |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 73 | CellularCapabilityUniversalTest(EventDispatcher *dispatcher) |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 74 | : modem_info_(NULL, dispatcher, NULL, NULL, NULL), |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 75 | bearer_proxy_(new mm1::MockBearerProxy()), |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 76 | modem_3gpp_proxy_(new mm1::MockModemModem3gppProxy()), |
| 77 | modem_cdma_proxy_(new mm1::MockModemModemCdmaProxy()), |
| 78 | modem_proxy_(new mm1::MockModemProxy()), |
| 79 | modem_simple_proxy_(new mm1::MockModemSimpleProxy()), |
| 80 | sim_proxy_(new mm1::MockSimProxy()), |
| 81 | properties_proxy_(new MockDBusPropertiesProxy()), |
| 82 | proxy_factory_(this), |
| 83 | capability_(NULL), |
| 84 | device_adaptor_(NULL), |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 85 | cellular_(new Cellular(&modem_info_, |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 86 | "", |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 87 | kMachineAddress, |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 88 | 0, |
| 89 | Cellular::kTypeUniversal, |
| 90 | "", |
| 91 | "", |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 92 | "", |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 93 | &proxy_factory_)), |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 94 | service_(new MockCellularService(&modem_info_, cellular_)) { |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 95 | modem_info_.metrics()->RegisterDevice(cellular_->interface_index(), |
| 96 | Technology::kCellular); |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 97 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 98 | |
| 99 | virtual ~CellularCapabilityUniversalTest() { |
| 100 | cellular_->service_ = NULL; |
| 101 | capability_ = NULL; |
| 102 | device_adaptor_ = NULL; |
| 103 | } |
| 104 | |
| 105 | virtual void SetUp() { |
| 106 | capability_ = dynamic_cast<CellularCapabilityUniversal *>( |
| 107 | cellular_->capability_.get()); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 108 | device_adaptor_ = |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 109 | dynamic_cast<DeviceMockAdaptor *>(cellular_->adaptor()); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 110 | cellular_->service_ = service_; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 111 | |
| 112 | // kStateUnknown leads to minimal extra work in maintaining |
| 113 | // activation state. |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 114 | ON_CALL(*modem_info_.mock_pending_activation_store(), |
| 115 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
| 116 | .WillByDefault(Return(PendingActivationStore::kStateUnknown)); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | virtual void TearDown() { |
| 120 | capability_->proxy_factory_ = NULL; |
| 121 | } |
| 122 | |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 123 | void InitProviderDB() { |
| 124 | modem_info_.SetProviderDB(kTestMobileProviderDBPath); |
| 125 | } |
| 126 | |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 127 | void SetService() { |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 128 | cellular_->service_ = new CellularService(&modem_info_, cellular_); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 129 | } |
| 130 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 131 | void InvokeEnable(bool enable, Error *error, |
| 132 | const ResultCallback &callback, int timeout) { |
| 133 | callback.Run(Error()); |
| 134 | } |
| 135 | void InvokeEnableFail(bool enable, Error *error, |
| 136 | const ResultCallback &callback, int timeout) { |
| 137 | callback.Run(Error(Error::kOperationFailed)); |
| 138 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 139 | void InvokeRegister(const string &operator_id, Error *error, |
| 140 | const ResultCallback &callback, int timeout) { |
| 141 | callback.Run(Error()); |
| 142 | } |
| 143 | |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 144 | void InvokeScan(Error *error, const DBusPropertyMapsCallback &callback, |
| 145 | int timeout) { |
| 146 | callback.Run(CellularCapabilityUniversal::ScanResults(), Error()); |
| 147 | } |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 148 | void ScanError(Error *error, const DBusPropertyMapsCallback &callback, |
| 149 | int timeout) { |
| 150 | error->Populate(Error::kOperationFailed); |
| 151 | } |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 152 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 153 | bool InvokeScanningOrSearchingTimeout() { |
| 154 | capability_->OnScanningOrSearchingTimeout(); |
| 155 | return true; |
| 156 | } |
| 157 | |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 158 | void Set3gppProxy() { |
| 159 | capability_->modem_3gpp_proxy_.reset(modem_3gpp_proxy_.release()); |
| 160 | } |
| 161 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 162 | void SetSimpleProxy() { |
| 163 | capability_->modem_simple_proxy_.reset(modem_simple_proxy_.release()); |
| 164 | } |
| 165 | |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 166 | void ReleaseCapabilityProxies() { |
| 167 | capability_->ReleaseProxies(); |
| 168 | } |
| 169 | |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 170 | void SetRegistrationDroppedUpdateTimeout(int64 timeout_milliseconds) { |
| 171 | capability_->registration_dropped_update_timeout_milliseconds_ = |
| 172 | timeout_milliseconds; |
| 173 | } |
| 174 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 175 | MOCK_METHOD1(TestCallback, void(const Error &error)); |
| 176 | |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 177 | MOCK_METHOD0(DummyCallback, void(void)); |
| 178 | |
| 179 | void SetMockRegistrationDroppedUpdateCallback() { |
| 180 | capability_->registration_dropped_update_callback_.Reset( |
| 181 | Bind(&CellularCapabilityUniversalTest::DummyCallback, |
| 182 | Unretained(this))); |
| 183 | } |
| 184 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 185 | protected: |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 186 | static const char kActiveBearerPathPrefix[]; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 187 | static const char kImei[]; |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 188 | static const char kInactiveBearerPathPrefix[]; |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 189 | static const char kMachineAddress[]; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 190 | static const char kSimPath[]; |
| 191 | static const uint32 kAccessTechnologies; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 192 | static const char kTestMobileProviderDBPath[]; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 193 | |
| 194 | class TestProxyFactory : public ProxyFactory { |
| 195 | public: |
| 196 | explicit TestProxyFactory(CellularCapabilityUniversalTest *test) : |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 197 | test_(test) { |
| 198 | ::DBus::Variant ip_method_dhcp; |
| 199 | ip_method_dhcp.writer().append_uint32(MM_BEARER_IP_METHOD_DHCP); |
| 200 | bearer_ip4config_dhcp_[ |
| 201 | CellularCapabilityUniversal::kIpConfigPropertyMethod] = |
| 202 | ip_method_dhcp; |
| 203 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 204 | |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 205 | virtual mm1::BearerProxyInterface *CreateBearerProxy( |
| 206 | const std::string &path, |
| 207 | const std::string &/*service*/) { |
| 208 | mm1::MockBearerProxy *bearer_proxy = test_->bearer_proxy_.release(); |
| 209 | if (path.find(kActiveBearerPathPrefix) != std::string::npos) |
| 210 | ON_CALL(*bearer_proxy, Connected()).WillByDefault(Return(true)); |
| 211 | else |
| 212 | ON_CALL(*bearer_proxy, Connected()).WillByDefault(Return(false)); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 213 | ON_CALL(*bearer_proxy, Ip4Config()).WillByDefault(Return( |
| 214 | bearer_ip4config_dhcp_)); |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 215 | test_->bearer_proxy_.reset(new mm1::MockBearerProxy()); |
| 216 | return bearer_proxy; |
| 217 | } |
| 218 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 219 | virtual mm1::ModemModem3gppProxyInterface *CreateMM1ModemModem3gppProxy( |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 220 | const std::string &/*path*/, |
| 221 | const std::string &/*service*/) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 222 | return test_->modem_3gpp_proxy_.release(); |
| 223 | } |
| 224 | |
| 225 | virtual mm1::ModemModemCdmaProxyInterface *CreateMM1ModemModemCdmaProxy( |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 226 | const std::string &/*path*/, |
| 227 | const std::string &/*service*/) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 228 | return test_->modem_cdma_proxy_.release(); |
| 229 | } |
| 230 | |
| 231 | virtual mm1::ModemProxyInterface *CreateMM1ModemProxy( |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 232 | const std::string &/*path*/, |
| 233 | const std::string &/*service*/) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 234 | return test_->modem_proxy_.release(); |
| 235 | } |
| 236 | |
| 237 | virtual mm1::ModemSimpleProxyInterface *CreateMM1ModemSimpleProxy( |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 238 | const std::string &/*path*/, |
| 239 | const std::string &/*service*/) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 240 | return test_->modem_simple_proxy_.release(); |
| 241 | } |
| 242 | |
| 243 | virtual mm1::SimProxyInterface *CreateSimProxy( |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 244 | const std::string &/*path*/, |
| 245 | const std::string &/*service*/) { |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 246 | mm1::MockSimProxy *sim_proxy = test_->sim_proxy_.release(); |
| 247 | test_->sim_proxy_.reset(new mm1::MockSimProxy()); |
| 248 | return sim_proxy; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 249 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 250 | virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy( |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 251 | const std::string &/*path*/, |
| 252 | const std::string &/*service*/) { |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 253 | MockDBusPropertiesProxy *properties_proxy = |
| 254 | test_->properties_proxy_.release(); |
| 255 | test_->properties_proxy_.reset(new MockDBusPropertiesProxy()); |
| 256 | return properties_proxy; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 257 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 258 | |
| 259 | private: |
| 260 | CellularCapabilityUniversalTest *test_; |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 261 | DBusPropertiesMap bearer_ip4config_dhcp_; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 262 | }; |
| 263 | |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 264 | MockModemInfo modem_info_; |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 265 | scoped_ptr<mm1::MockBearerProxy> bearer_proxy_; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 266 | scoped_ptr<mm1::MockModemModem3gppProxy> modem_3gpp_proxy_; |
| 267 | scoped_ptr<mm1::MockModemModemCdmaProxy> modem_cdma_proxy_; |
| 268 | scoped_ptr<mm1::MockModemProxy> modem_proxy_; |
| 269 | scoped_ptr<mm1::MockModemSimpleProxy> modem_simple_proxy_; |
| 270 | scoped_ptr<mm1::MockSimProxy> sim_proxy_; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 271 | scoped_ptr<MockDBusPropertiesProxy> properties_proxy_; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 272 | TestProxyFactory proxy_factory_; |
| 273 | CellularCapabilityUniversal *capability_; // Owned by |cellular_|. |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 274 | DeviceMockAdaptor *device_adaptor_; // Owned by |cellular_|. |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 275 | CellularRefPtr cellular_; |
| 276 | MockCellularService *service_; // owned by cellular_ |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 277 | DBusPropertyMapsCallback scan_callback_; // saved for testing scan operations |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 278 | DBusPathCallback connect_callback_; // saved for testing connect operations |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 279 | }; |
| 280 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 281 | // Most of our tests involve using a real EventDispatcher object. |
| 282 | class CellularCapabilityUniversalMainTest |
| 283 | : public CellularCapabilityUniversalTest { |
| 284 | public: |
| 285 | CellularCapabilityUniversalMainTest() : |
| 286 | CellularCapabilityUniversalTest(&dispatcher_) {} |
| 287 | |
| 288 | protected: |
| 289 | EventDispatcher dispatcher_; |
| 290 | }; |
| 291 | |
| 292 | // Tests that involve timers will (or may) use a mock of the event dispatcher |
| 293 | // instead of a real one. |
| 294 | class CellularCapabilityUniversalTimerTest |
| 295 | : public CellularCapabilityUniversalTest { |
| 296 | public: |
| 297 | CellularCapabilityUniversalTimerTest() |
| 298 | : CellularCapabilityUniversalTest(&mock_dispatcher_) {} |
| 299 | |
| 300 | protected: |
| 301 | ::testing::StrictMock<MockEventDispatcher> mock_dispatcher_; |
| 302 | }; |
| 303 | |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 304 | const char CellularCapabilityUniversalTest::kActiveBearerPathPrefix[] = |
| 305 | "/bearer/active"; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 306 | const char CellularCapabilityUniversalTest::kImei[] = "999911110000"; |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 307 | const char CellularCapabilityUniversalTest::kInactiveBearerPathPrefix[] = |
| 308 | "/bearer/inactive"; |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 309 | const char CellularCapabilityUniversalTest::kMachineAddress[] = |
| 310 | "TestMachineAddress"; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 311 | const char CellularCapabilityUniversalTest::kSimPath[] = "/foo/sim"; |
| 312 | const uint32 CellularCapabilityUniversalTest::kAccessTechnologies = |
| 313 | MM_MODEM_ACCESS_TECHNOLOGY_LTE | |
| 314 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 315 | const char CellularCapabilityUniversalTest::kTestMobileProviderDBPath[] = |
| 316 | "provider_db_unittest.bfd"; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 317 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 318 | TEST_F(CellularCapabilityUniversalMainTest, StartModem) { |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 319 | // Set up mock modem properties |
| 320 | DBusPropertiesMap modem_properties; |
| 321 | string operator_name = "TestOperator"; |
| 322 | string operator_code = "001400"; |
| 323 | |
| 324 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 325 | writer().append_uint32(kAccessTechnologies); |
| 326 | |
| 327 | ::DBus::Variant v; |
| 328 | ::DBus::MessageIter writer = v.writer(); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 329 | ::DBus::Struct< uint32_t, bool > quality; |
| 330 | quality._1 = 90; |
| 331 | quality._2 = true; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 332 | writer << quality; |
| 333 | modem_properties[MM_MODEM_PROPERTY_SIGNALQUALITY] = v; |
| 334 | |
| 335 | // Set up mock modem 3gpp properties |
| 336 | DBusPropertiesMap modem3gpp_properties; |
| 337 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS]. |
| 338 | writer().append_uint32(0); |
| 339 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_IMEI]. |
| 340 | writer().append_string(kImei); |
| 341 | |
| 342 | EXPECT_CALL(*modem_proxy_, |
| 343 | Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 344 | .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeEnable)); |
| 345 | EXPECT_CALL(*properties_proxy_, |
| 346 | GetAll(MM_DBUS_INTERFACE_MODEM)) |
| 347 | .WillOnce(Return(modem_properties)); |
| 348 | EXPECT_CALL(*properties_proxy_, |
| 349 | GetAll(MM_DBUS_INTERFACE_MODEM_MODEM3GPP)) |
| 350 | .WillOnce(Return(modem3gpp_properties)); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 351 | |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 352 | // Let the modem report that it is initializing. StartModem() should defer |
| 353 | // enabling the modem until its state changes to disabled. |
| 354 | EXPECT_CALL(*modem_proxy_, State()) |
| 355 | .WillOnce(Return(Cellular::kModemStateInitializing)); |
| 356 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 357 | // After setup we lose pointers to the proxies, so it is hard to set |
| 358 | // expectations. |
| 359 | SetUp(); |
| 360 | |
| 361 | Error error; |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 362 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 363 | ResultCallback callback = |
| 364 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 365 | capability_->StartModem(&error, callback); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 366 | |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 367 | // Verify that the modem has not been enabled. |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 368 | EXPECT_TRUE(capability_->imei_.empty()); |
| 369 | EXPECT_EQ(0, capability_->access_technologies_); |
| 370 | Mock::VerifyAndClearExpectations(this); |
| 371 | |
| 372 | // Change the state to kModemStateDisabling and verify that it still has not |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 373 | // been enabled. |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 374 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
| 375 | capability_->OnModemStateChangedSignal(Cellular::kModemStateInitializing, |
| 376 | Cellular::kModemStateDisabling, 0); |
| 377 | EXPECT_TRUE(capability_->imei_.empty()); |
| 378 | EXPECT_EQ(0, capability_->access_technologies_); |
| 379 | Mock::VerifyAndClearExpectations(this); |
| 380 | |
| 381 | // Change the state of the modem to disabled and verify that it gets enabled. |
| 382 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 383 | capability_->OnModemStateChangedSignal(Cellular::kModemStateDisabling, |
| 384 | Cellular::kModemStateDisabled, 0); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 385 | EXPECT_TRUE(error.IsSuccess()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 386 | EXPECT_EQ(kImei, capability_->imei_); |
| 387 | EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 388 | } |
| 389 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 390 | TEST_F(CellularCapabilityUniversalMainTest, StartModemFail) { |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 391 | EXPECT_CALL(*modem_proxy_, State()) |
| 392 | .WillOnce(Return(Cellular::kModemStateDisabled)); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 393 | EXPECT_CALL(*modem_proxy_, |
| 394 | Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 395 | .WillOnce( |
| 396 | Invoke(this, &CellularCapabilityUniversalTest::InvokeEnableFail)); |
| 397 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 398 | ResultCallback callback = |
| 399 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 400 | SetUp(); |
| 401 | |
| 402 | Error error; |
| 403 | capability_->StartModem(&error, callback); |
Thieu Le | e3b3659 | 2012-08-30 17:50:26 -0700 | [diff] [blame] | 404 | EXPECT_TRUE(error.IsOngoing()); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 405 | } |
| 406 | |
Thieu Le | b9c05e0 | 2013-03-04 14:09:32 -0800 | [diff] [blame] | 407 | TEST_F(CellularCapabilityUniversalMainTest, StartModemAlreadyEnabled) { |
| 408 | EXPECT_CALL(*modem_proxy_, State()) |
| 409 | .WillOnce(Return(Cellular::kModemStateEnabled)); |
| 410 | SetUp(); |
| 411 | capability_->cellular()->modem_state_ = Cellular::kModemStateConnected; |
| 412 | |
| 413 | // Make sure the call to StartModem() doesn't attempt to complete the |
| 414 | // request synchronously, else it will crash DBus-C++. |
| 415 | Error error(Error::kOperationInitiated); |
| 416 | capability_->StartModem(&error, ResultCallback()); |
| 417 | EXPECT_TRUE(error.IsOngoing()); |
| 418 | } |
| 419 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 420 | TEST_F(CellularCapabilityUniversalMainTest, StopModem) { |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 421 | // Save pointers to proxies before they are lost by the call to InitProxies |
| 422 | mm1::MockModemProxy *modem_proxy = modem_proxy_.get(); |
| 423 | SetUp(); |
| 424 | EXPECT_CALL(*modem_proxy, set_state_changed_callback(_)); |
| 425 | capability_->InitProxies(); |
| 426 | |
| 427 | Error error; |
| 428 | ResultCallback callback = |
| 429 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 430 | capability_->StopModem(&error, callback); |
| 431 | EXPECT_TRUE(error.IsSuccess()); |
| 432 | |
| 433 | ResultCallback disable_callback; |
| 434 | EXPECT_CALL(*modem_proxy, |
| 435 | Enable(false, _, _, CellularCapability::kTimeoutEnable)) |
| 436 | .WillOnce(SaveArg<2>(&disable_callback)); |
| 437 | dispatcher_.DispatchPendingEvents(); |
| 438 | |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 439 | ResultCallback set_power_state_callback; |
Thieu Le | 2cac294 | 2013-03-05 18:41:08 -0800 | [diff] [blame] | 440 | EXPECT_CALL( |
| 441 | *modem_proxy, |
| 442 | SetPowerState( |
| 443 | MM_MODEM_POWER_STATE_LOW, _, _, |
| 444 | CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds)) |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 445 | .WillOnce(SaveArg<2>(&set_power_state_callback)); |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 446 | disable_callback.Run(Error(Error::kSuccess)); |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 447 | |
| 448 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 449 | set_power_state_callback.Run(Error(Error::kSuccess)); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 450 | Mock::VerifyAndClearExpectations(this); |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 451 | |
| 452 | // TestCallback should get called with success even if the power state |
| 453 | // callback gets called with an error |
| 454 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 455 | set_power_state_callback.Run(Error(Error::kOperationFailed)); |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 456 | } |
| 457 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 458 | TEST_F(CellularCapabilityUniversalMainTest, StopModemConnected) { |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 459 | // Save pointers to proxies before they are lost by the call to InitProxies |
| 460 | mm1::MockModemProxy *modem_proxy = modem_proxy_.get(); |
| 461 | mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get(); |
| 462 | SetUp(); |
| 463 | EXPECT_CALL(*modem_proxy, set_state_changed_callback(_)); |
| 464 | capability_->InitProxies(); |
| 465 | |
| 466 | ResultCallback disconnect_callback; |
| 467 | Error error; |
| 468 | ResultCallback callback = |
| 469 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 470 | EXPECT_CALL(*modem_simple_proxy, |
| 471 | Disconnect(::DBus::Path("/"), _, _, |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 472 | CellularCapability::kTimeoutDisconnect)) |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 473 | .WillOnce(SaveArg<2>(&disconnect_callback)); |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 474 | capability_->cellular()->modem_state_ = Cellular::kModemStateConnected; |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 475 | capability_->StopModem(&error, callback); |
| 476 | EXPECT_TRUE(error.IsSuccess()); |
| 477 | |
| 478 | ResultCallback disable_callback; |
| 479 | EXPECT_CALL(*modem_proxy, |
| 480 | Enable(false, _, _, CellularCapability::kTimeoutEnable)) |
| 481 | .WillOnce(SaveArg<2>(&disable_callback)); |
| 482 | disconnect_callback.Run(Error(Error::kSuccess)); |
| 483 | |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 484 | ResultCallback set_power_state_callback; |
Thieu Le | 2cac294 | 2013-03-05 18:41:08 -0800 | [diff] [blame] | 485 | EXPECT_CALL( |
| 486 | *modem_proxy, |
| 487 | SetPowerState( |
| 488 | MM_MODEM_POWER_STATE_LOW, _, _, |
| 489 | CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds)) |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 490 | .WillOnce(SaveArg<2>(&set_power_state_callback)); |
| 491 | |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 492 | disable_callback.Run(Error(Error::kSuccess)); |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 493 | |
| 494 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 495 | set_power_state_callback.Run(Error(Error::kSuccess)); |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 496 | } |
| 497 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 498 | TEST_F(CellularCapabilityUniversalMainTest, DisconnectModemNoBearer) { |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 499 | Error error; |
| 500 | ResultCallback disconnect_callback; |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 501 | EXPECT_CALL(*modem_simple_proxy_, |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 502 | Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect)) |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 503 | .Times(0); |
| 504 | capability_->Disconnect(&error, disconnect_callback); |
| 505 | } |
| 506 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 507 | TEST_F(CellularCapabilityUniversalMainTest, DisconnectNoProxy) { |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 508 | Error error; |
| 509 | ResultCallback disconnect_callback; |
| 510 | capability_->bearer_path_ = "/foo"; |
| 511 | EXPECT_CALL(*modem_simple_proxy_, |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 512 | Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect)) |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 513 | .Times(0); |
| 514 | ReleaseCapabilityProxies(); |
| 515 | capability_->Disconnect(&error, disconnect_callback); |
| 516 | } |
| 517 | |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 518 | TEST_F(CellularCapabilityUniversalMainTest, DisconnectWithDeferredCallback) { |
| 519 | Error error; |
| 520 | ResultCallback disconnect_callback; |
| 521 | capability_->bearer_path_ = "/foo"; |
| 522 | EXPECT_CALL(*modem_simple_proxy_, |
| 523 | Disconnect(_, _, _, CellularCapability::kTimeoutDisconnect)); |
| 524 | SetSimpleProxy(); |
| 525 | SetMockRegistrationDroppedUpdateCallback(); |
| 526 | EXPECT_CALL(*this, DummyCallback()); |
| 527 | capability_->Disconnect(&error, disconnect_callback); |
| 528 | } |
| 529 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 530 | TEST_F(CellularCapabilityUniversalMainTest, SimLockStatusChanged) { |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 531 | // Set up mock SIM properties |
| 532 | const char kImsi[] = "310100000001"; |
| 533 | const char kSimIdentifier[] = "9999888"; |
| 534 | const char kOperatorIdentifier[] = "310240"; |
| 535 | const char kOperatorName[] = "Custom SPN"; |
| 536 | DBusPropertiesMap sim_properties; |
| 537 | sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi); |
| 538 | sim_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer() |
| 539 | .append_string(kSimIdentifier); |
| 540 | sim_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer() |
| 541 | .append_string(kOperatorIdentifier); |
| 542 | sim_properties[MM_SIM_PROPERTY_OPERATORNAME].writer() |
| 543 | .append_string(kOperatorName); |
| 544 | |
| 545 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM)) |
| 546 | .WillOnce(Return(sim_properties)); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 547 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 548 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 549 | .Times(1); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 550 | |
| 551 | SetUp(); |
| 552 | InitProviderDB(); |
| 553 | |
| 554 | EXPECT_FALSE(capability_->sim_present_); |
| 555 | EXPECT_TRUE(capability_->sim_proxy_ == NULL); |
| 556 | |
| 557 | capability_->OnSimPathChanged(kSimPath); |
| 558 | EXPECT_TRUE(capability_->sim_present_); |
| 559 | EXPECT_TRUE(capability_->sim_proxy_ != NULL); |
| 560 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 561 | |
| 562 | capability_->imsi_ = ""; |
| 563 | capability_->sim_identifier_ = ""; |
| 564 | capability_->operator_id_ = ""; |
| 565 | capability_->spn_ = ""; |
| 566 | |
| 567 | // SIM is locked. |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 568 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN; |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 569 | capability_->OnSimLockStatusChanged(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 570 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 571 | |
| 572 | EXPECT_EQ("", capability_->imsi_); |
| 573 | EXPECT_EQ("", capability_->sim_identifier_); |
| 574 | EXPECT_EQ("", capability_->operator_id_); |
| 575 | EXPECT_EQ("", capability_->spn_); |
| 576 | |
| 577 | // SIM is unlocked. |
| 578 | properties_proxy_.reset(new MockDBusPropertiesProxy()); |
| 579 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM)) |
| 580 | .WillOnce(Return(sim_properties)); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 581 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 582 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 583 | .Times(1); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 584 | |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 585 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_NONE; |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 586 | capability_->OnSimLockStatusChanged(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 587 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 588 | |
| 589 | EXPECT_EQ(kImsi, capability_->imsi_); |
| 590 | EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_); |
| 591 | EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_); |
| 592 | EXPECT_EQ(kOperatorName, capability_->spn_); |
| 593 | } |
| 594 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 595 | TEST_F(CellularCapabilityUniversalMainTest, PropertiesChanged) { |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 596 | // Set up mock modem properties |
| 597 | DBusPropertiesMap modem_properties; |
| 598 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 599 | writer().append_uint32(kAccessTechnologies); |
| 600 | modem_properties[MM_MODEM_PROPERTY_SIM]. |
| 601 | writer().append_path(kSimPath); |
| 602 | |
| 603 | // Set up mock modem 3gpp properties |
| 604 | DBusPropertiesMap modem3gpp_properties; |
| 605 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS]. |
| 606 | writer().append_uint32(0); |
| 607 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_IMEI]. |
| 608 | writer().append_string(kImei); |
| 609 | |
| 610 | // Set up mock modem sim properties |
| 611 | DBusPropertiesMap sim_properties; |
| 612 | |
| 613 | // After setup we lose pointers to the proxies, so it is hard to set |
| 614 | // expectations. |
| 615 | EXPECT_CALL(*properties_proxy_, |
| 616 | GetAll(MM_DBUS_INTERFACE_SIM)) |
| 617 | .WillOnce(Return(sim_properties)); |
| 618 | |
| 619 | SetUp(); |
| 620 | |
| 621 | EXPECT_EQ("", capability_->imei_); |
| 622 | EXPECT_EQ(MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, |
| 623 | capability_->access_technologies_); |
| 624 | EXPECT_FALSE(capability_->sim_proxy_.get()); |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 625 | EXPECT_CALL(*device_adaptor_, EmitStringChanged( |
| 626 | flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyGsm)); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 627 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 628 | modem_properties, vector<string>()); |
| 629 | EXPECT_EQ(kAccessTechnologies, capability_->access_technologies_); |
| 630 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 631 | EXPECT_TRUE(capability_->sim_proxy_.get()); |
| 632 | |
| 633 | // Changing properties on wrong interface will not have an effect |
| 634 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 635 | modem3gpp_properties, |
| 636 | vector<string>()); |
| 637 | EXPECT_EQ("", capability_->imei_); |
| 638 | |
| 639 | // Changing properties on the right interface gets reflected in the |
| 640 | // capabilities object |
| 641 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM_MODEM3GPP, |
| 642 | modem3gpp_properties, |
| 643 | vector<string>()); |
| 644 | EXPECT_EQ(kImei, capability_->imei_); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 645 | Mock::VerifyAndClearExpectations(device_adaptor_); |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 646 | |
| 647 | // Expect to see changes when the family changes |
| 648 | modem_properties.clear(); |
| 649 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 650 | writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_1XRTT); |
| 651 | EXPECT_CALL(*device_adaptor_, EmitStringChanged( |
| 652 | flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyCdma)). |
| 653 | Times(1); |
| 654 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 655 | modem_properties, |
| 656 | vector<string>()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 657 | Mock::VerifyAndClearExpectations(device_adaptor_); |
| 658 | |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 659 | // Back to LTE |
| 660 | modem_properties.clear(); |
| 661 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 662 | writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_LTE); |
| 663 | EXPECT_CALL(*device_adaptor_, EmitStringChanged( |
| 664 | flimflam::kTechnologyFamilyProperty, flimflam::kTechnologyFamilyGsm)). |
| 665 | Times(1); |
| 666 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 667 | modem_properties, |
| 668 | vector<string>()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 669 | Mock::VerifyAndClearExpectations(device_adaptor_); |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 670 | |
| 671 | // LTE & CDMA - the device adaptor should not be called! |
| 672 | modem_properties.clear(); |
| 673 | modem_properties[MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES]. |
| 674 | writer().append_uint32(MM_MODEM_ACCESS_TECHNOLOGY_LTE | |
| 675 | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT); |
| 676 | EXPECT_CALL(*device_adaptor_, EmitStringChanged(_, _)).Times(0); |
| 677 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 678 | modem_properties, |
| 679 | vector<string>()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 680 | } |
| 681 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 682 | TEST_F(CellularCapabilityUniversalMainTest, UpdateServiceName) { |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 683 | ::DBus::Struct<uint32_t, bool> data; |
| 684 | data._1 = 100; |
| 685 | data._2 = true; |
| 686 | EXPECT_CALL(*modem_proxy_, SignalQuality()).WillRepeatedly(Return(data)); |
| 687 | |
| 688 | SetUp(); |
| 689 | InitProviderDB(); |
| 690 | capability_->InitProxies(); |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 691 | |
| 692 | SetService(); |
| 693 | |
| 694 | size_t len = strlen(CellularCapabilityUniversal::kGenericServiceNamePrefix); |
| 695 | EXPECT_EQ(CellularCapabilityUniversal::kGenericServiceNamePrefix, |
| 696 | cellular_->service_->friendly_name().substr(0, len)); |
| 697 | |
| 698 | capability_->imsi_ = "310240123456789"; |
| 699 | capability_->SetHomeProvider(); |
| 700 | EXPECT_EQ("", capability_->spn_); |
| 701 | EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName()); |
| 702 | EXPECT_EQ(CellularCapabilityUniversal::kGenericServiceNamePrefix, |
| 703 | cellular_->service_->friendly_name().substr(0, len)); |
| 704 | |
| 705 | capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_HOME; |
| 706 | capability_->SetHomeProvider(); |
| 707 | EXPECT_EQ("", capability_->spn_); |
| 708 | EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName()); |
| 709 | EXPECT_EQ("T-Mobile", cellular_->service_->friendly_name()); |
| 710 | |
| 711 | capability_->spn_ = "Test Home Provider"; |
| 712 | capability_->SetHomeProvider(); |
| 713 | EXPECT_EQ("Test Home Provider", cellular_->home_provider().GetName()); |
| 714 | EXPECT_EQ("Test Home Provider", cellular_->service_->friendly_name()); |
| 715 | |
| 716 | capability_->On3GPPRegistrationChanged( |
| 717 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, "", "OTA Name"); |
| 718 | EXPECT_EQ("OTA Name", cellular_->service_->friendly_name()); |
| 719 | |
| 720 | capability_->On3GPPRegistrationChanged( |
| 721 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, "123", "OTA Name 2"); |
| 722 | EXPECT_EQ("OTA Name 2", cellular_->service_->friendly_name()); |
| 723 | |
| 724 | capability_->On3GPPRegistrationChanged( |
| 725 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, "123", ""); |
| 726 | EXPECT_EQ("Test Home Provider", cellular_->service_->friendly_name()); |
| 727 | } |
| 728 | |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 729 | TEST_F(CellularCapabilityUniversalMainTest, UpdateRegistrationState) { |
| 730 | SetUp(); |
| 731 | InitProviderDB(); |
| 732 | capability_->InitProxies(); |
| 733 | |
| 734 | SetService(); |
| 735 | capability_->imsi_ = "310240123456789"; |
| 736 | capability_->SetHomeProvider(); |
| 737 | cellular_->set_modem_state(Cellular::kModemStateConnected); |
| 738 | SetRegistrationDroppedUpdateTimeout(0); |
| 739 | |
| 740 | string home_provider = cellular_->home_provider().GetName(); |
| 741 | string ota_name = cellular_->service_->friendly_name(); |
| 742 | |
| 743 | // Home --> Roaming should be effective immediately. |
| 744 | capability_->On3GPPRegistrationChanged( |
| 745 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 746 | home_provider, |
| 747 | ota_name); |
| 748 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 749 | capability_->registration_state_); |
| 750 | capability_->On3GPPRegistrationChanged( |
| 751 | MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, |
| 752 | home_provider, |
| 753 | ota_name); |
| 754 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, |
| 755 | capability_->registration_state_); |
| 756 | |
| 757 | // Idle --> Roaming should be effective immediately. |
| 758 | capability_->On3GPPRegistrationChanged( |
| 759 | MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, |
| 760 | home_provider, |
| 761 | ota_name); |
| 762 | dispatcher_.DispatchPendingEvents(); |
| 763 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, |
| 764 | capability_->registration_state_); |
| 765 | capability_->On3GPPRegistrationChanged( |
| 766 | MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, |
| 767 | home_provider, |
| 768 | ota_name); |
| 769 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, |
| 770 | capability_->registration_state_); |
| 771 | |
| 772 | // Idle --> Searching should be effective immediately. |
| 773 | capability_->On3GPPRegistrationChanged( |
| 774 | MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, |
| 775 | home_provider, |
| 776 | ota_name); |
| 777 | dispatcher_.DispatchPendingEvents(); |
| 778 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, |
| 779 | capability_->registration_state_); |
| 780 | capability_->On3GPPRegistrationChanged( |
| 781 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 782 | home_provider, |
| 783 | ota_name); |
| 784 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 785 | capability_->registration_state_); |
| 786 | |
| 787 | // Home --> Searching --> Home should never see Searching. |
Prathmesh Prabhu | 08757aa | 2013-05-15 17:17:33 -0700 | [diff] [blame] | 788 | EXPECT_CALL(*(modem_info_.mock_metrics()), |
| 789 | Notify3GPPRegistrationDelayedDropPosted()); |
| 790 | EXPECT_CALL(*(modem_info_.mock_metrics()), |
| 791 | Notify3GPPRegistrationDelayedDropCanceled()); |
| 792 | |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 793 | capability_->On3GPPRegistrationChanged( |
| 794 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 795 | home_provider, |
| 796 | ota_name); |
| 797 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 798 | capability_->registration_state_); |
| 799 | capability_->On3GPPRegistrationChanged( |
| 800 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 801 | home_provider, |
| 802 | ota_name); |
| 803 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 804 | capability_->registration_state_); |
| 805 | capability_->On3GPPRegistrationChanged( |
| 806 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 807 | home_provider, |
| 808 | ota_name); |
| 809 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 810 | capability_->registration_state_); |
| 811 | dispatcher_.DispatchPendingEvents(); |
| 812 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 813 | capability_->registration_state_); |
Prathmesh Prabhu | 08757aa | 2013-05-15 17:17:33 -0700 | [diff] [blame] | 814 | Mock::VerifyAndClearExpectations(modem_info_.mock_metrics()); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 815 | |
| 816 | // Home --> Searching --> wait till dispatch should see Searching |
Prathmesh Prabhu | 08757aa | 2013-05-15 17:17:33 -0700 | [diff] [blame] | 817 | EXPECT_CALL(*(modem_info_.mock_metrics()), |
| 818 | Notify3GPPRegistrationDelayedDropPosted()); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 819 | capability_->On3GPPRegistrationChanged( |
| 820 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 821 | home_provider, |
| 822 | ota_name); |
| 823 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 824 | capability_->registration_state_); |
| 825 | capability_->On3GPPRegistrationChanged( |
| 826 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 827 | home_provider, |
| 828 | ota_name); |
| 829 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 830 | capability_->registration_state_); |
| 831 | dispatcher_.DispatchPendingEvents(); |
| 832 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 833 | capability_->registration_state_); |
Prathmesh Prabhu | 08757aa | 2013-05-15 17:17:33 -0700 | [diff] [blame] | 834 | Mock::VerifyAndClearExpectations(modem_info_.mock_metrics()); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 835 | |
| 836 | // Home --> Searching --> Searching --> wait till dispatch should see |
| 837 | // Searching *and* the first callback should be cancelled. |
| 838 | EXPECT_CALL(*this, DummyCallback()).Times(0); |
Prathmesh Prabhu | 08757aa | 2013-05-15 17:17:33 -0700 | [diff] [blame] | 839 | EXPECT_CALL(*(modem_info_.mock_metrics()), |
| 840 | Notify3GPPRegistrationDelayedDropPosted()); |
| 841 | |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 842 | capability_->On3GPPRegistrationChanged( |
| 843 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 844 | home_provider, |
| 845 | ota_name); |
| 846 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 847 | capability_->registration_state_); |
| 848 | capability_->On3GPPRegistrationChanged( |
| 849 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 850 | home_provider, |
| 851 | ota_name); |
| 852 | SetMockRegistrationDroppedUpdateCallback(); |
| 853 | capability_->On3GPPRegistrationChanged( |
| 854 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 855 | home_provider, |
| 856 | ota_name); |
| 857 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 858 | capability_->registration_state_); |
| 859 | dispatcher_.DispatchPendingEvents(); |
| 860 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 861 | capability_->registration_state_); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | TEST_F(CellularCapabilityUniversalMainTest, |
| 865 | UpdateRegistrationStateModemNotConnected) { |
| 866 | SetUp(); |
| 867 | InitProviderDB(); |
| 868 | capability_->InitProxies(); |
| 869 | SetService(); |
| 870 | |
| 871 | capability_->imsi_ = "310240123456789"; |
| 872 | capability_->SetHomeProvider(); |
| 873 | cellular_->set_modem_state(Cellular::kModemStateRegistered); |
| 874 | SetRegistrationDroppedUpdateTimeout(0); |
| 875 | |
| 876 | string home_provider = cellular_->home_provider().GetName(); |
| 877 | string ota_name = cellular_->service_->friendly_name(); |
| 878 | |
| 879 | // Home --> Searching should be effective immediately. |
| 880 | capability_->On3GPPRegistrationChanged( |
| 881 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 882 | home_provider, |
| 883 | ota_name); |
| 884 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_HOME, |
| 885 | capability_->registration_state_); |
| 886 | capability_->On3GPPRegistrationChanged( |
| 887 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 888 | home_provider, |
| 889 | ota_name); |
| 890 | EXPECT_EQ(MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, |
| 891 | capability_->registration_state_); |
| 892 | } |
| 893 | |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 894 | TEST_F(CellularCapabilityUniversalMainTest, IsValidSimPath) { |
| 895 | // Invalid paths |
| 896 | EXPECT_FALSE(capability_->IsValidSimPath("")); |
| 897 | EXPECT_FALSE(capability_->IsValidSimPath("/")); |
| 898 | |
| 899 | // A valid path |
| 900 | EXPECT_TRUE(capability_->IsValidSimPath( |
| 901 | "/org/freedesktop/ModemManager1/SIM/0")); |
| 902 | |
| 903 | // Note that any string that is not one of the above invalid paths is |
| 904 | // currently regarded as valid, since the ModemManager spec doesn't impose |
| 905 | // a strict format on the path. The validity of this is subject to change. |
| 906 | EXPECT_TRUE(capability_->IsValidSimPath("path")); |
| 907 | } |
| 908 | |
Ben Chan | d759252 | 2013-02-13 16:02:01 -0800 | [diff] [blame] | 909 | TEST_F(CellularCapabilityUniversalMainTest, NormalizeMdn) { |
| 910 | EXPECT_EQ("", capability_->NormalizeMdn("")); |
| 911 | EXPECT_EQ("12345678901", capability_->NormalizeMdn("12345678901")); |
| 912 | EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1 234 567 8901")); |
| 913 | EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1-234-567-8901")); |
| 914 | EXPECT_EQ("12345678901", capability_->NormalizeMdn("+1 (234) 567-8901")); |
| 915 | EXPECT_EQ("12345678901", capability_->NormalizeMdn("1 234 567 8901 ")); |
| 916 | EXPECT_EQ("2345678901", capability_->NormalizeMdn("(234) 567-8901")); |
| 917 | } |
| 918 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 919 | TEST_F(CellularCapabilityUniversalMainTest, SimPathChanged) { |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 920 | // Set up mock modem SIM properties |
| 921 | const char kImsi[] = "310100000001"; |
| 922 | const char kSimIdentifier[] = "9999888"; |
| 923 | const char kOperatorIdentifier[] = "310240"; |
| 924 | const char kOperatorName[] = "Custom SPN"; |
| 925 | DBusPropertiesMap sim_properties; |
| 926 | sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi); |
| 927 | sim_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer() |
| 928 | .append_string(kSimIdentifier); |
| 929 | sim_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer() |
| 930 | .append_string(kOperatorIdentifier); |
| 931 | sim_properties[MM_SIM_PROPERTY_OPERATORNAME].writer() |
| 932 | .append_string(kOperatorName); |
| 933 | |
| 934 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM)) |
| 935 | .Times(1).WillOnce(Return(sim_properties)); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 936 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 937 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 938 | .Times(1); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 939 | |
| 940 | EXPECT_FALSE(capability_->sim_present_); |
| 941 | EXPECT_TRUE(capability_->sim_proxy_ == NULL); |
| 942 | EXPECT_EQ("", capability_->sim_path_); |
| 943 | EXPECT_EQ("", capability_->imsi_); |
| 944 | EXPECT_EQ("", capability_->sim_identifier_); |
| 945 | EXPECT_EQ("", capability_->operator_id_); |
| 946 | EXPECT_EQ("", capability_->spn_); |
| 947 | |
| 948 | capability_->OnSimPathChanged(kSimPath); |
| 949 | EXPECT_TRUE(capability_->sim_present_); |
| 950 | EXPECT_TRUE(capability_->sim_proxy_ != NULL); |
| 951 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 952 | EXPECT_EQ(kImsi, capability_->imsi_); |
| 953 | EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_); |
| 954 | EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_); |
| 955 | EXPECT_EQ(kOperatorName, capability_->spn_); |
| 956 | |
| 957 | // Changing to the same SIM path should be a no-op. |
| 958 | capability_->OnSimPathChanged(kSimPath); |
| 959 | EXPECT_TRUE(capability_->sim_present_); |
| 960 | EXPECT_TRUE(capability_->sim_proxy_ != NULL); |
| 961 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 962 | EXPECT_EQ(kImsi, capability_->imsi_); |
| 963 | EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_); |
| 964 | EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_); |
| 965 | EXPECT_EQ(kOperatorName, capability_->spn_); |
| 966 | |
| 967 | capability_->OnSimPathChanged(""); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 968 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 969 | Mock::VerifyAndClearExpectations(properties_proxy_.get()); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 970 | EXPECT_FALSE(capability_->sim_present_); |
| 971 | EXPECT_TRUE(capability_->sim_proxy_ == NULL); |
| 972 | EXPECT_EQ("", capability_->sim_path_); |
| 973 | EXPECT_EQ("", capability_->imsi_); |
| 974 | EXPECT_EQ("", capability_->sim_identifier_); |
| 975 | EXPECT_EQ("", capability_->operator_id_); |
| 976 | EXPECT_EQ("", capability_->spn_); |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 977 | |
| 978 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM)) |
| 979 | .Times(1).WillOnce(Return(sim_properties)); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 980 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 981 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 982 | .Times(1); |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 983 | |
| 984 | capability_->OnSimPathChanged(kSimPath); |
| 985 | EXPECT_TRUE(capability_->sim_present_); |
| 986 | EXPECT_TRUE(capability_->sim_proxy_ != NULL); |
| 987 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 988 | EXPECT_EQ(kImsi, capability_->imsi_); |
| 989 | EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_); |
| 990 | EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_); |
| 991 | EXPECT_EQ(kOperatorName, capability_->spn_); |
| 992 | |
| 993 | capability_->OnSimPathChanged("/"); |
| 994 | EXPECT_FALSE(capability_->sim_present_); |
| 995 | EXPECT_TRUE(capability_->sim_proxy_ == NULL); |
| 996 | EXPECT_EQ("/", capability_->sim_path_); |
| 997 | EXPECT_EQ("", capability_->imsi_); |
| 998 | EXPECT_EQ("", capability_->sim_identifier_); |
| 999 | EXPECT_EQ("", capability_->operator_id_); |
| 1000 | EXPECT_EQ("", capability_->spn_); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1003 | TEST_F(CellularCapabilityUniversalMainTest, SimPropertiesChanged) { |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1004 | // Set up mock modem properties |
| 1005 | DBusPropertiesMap modem_properties; |
| 1006 | modem_properties[MM_MODEM_PROPERTY_SIM].writer().append_path(kSimPath); |
| 1007 | |
| 1008 | // Set up mock modem sim properties |
| 1009 | const char kImsi[] = "310100000001"; |
| 1010 | DBusPropertiesMap sim_properties; |
| 1011 | sim_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kImsi); |
| 1012 | |
| 1013 | EXPECT_CALL(*properties_proxy_, GetAll(MM_DBUS_INTERFACE_SIM)) |
| 1014 | .WillOnce(Return(sim_properties)); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1015 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1016 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 1017 | .Times(0); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1018 | // After setup we lose pointers to the proxies, so it is hard to set |
| 1019 | // expectations. |
| 1020 | SetUp(); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1021 | InitProviderDB(); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1022 | |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1023 | EXPECT_TRUE(cellular_->home_provider().GetName().empty()); |
| 1024 | EXPECT_TRUE(cellular_->home_provider().GetCountry().empty()); |
| 1025 | EXPECT_TRUE(cellular_->home_provider().GetCode().empty()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1026 | EXPECT_FALSE(capability_->sim_proxy_.get()); |
| 1027 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_MODEM, |
| 1028 | modem_properties, vector<string>()); |
| 1029 | EXPECT_EQ(kSimPath, capability_->sim_path_); |
| 1030 | EXPECT_TRUE(capability_->sim_proxy_.get()); |
| 1031 | EXPECT_EQ(kImsi, capability_->imsi_); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1032 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1033 | |
| 1034 | // Updating the SIM |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1035 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1036 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 1037 | .Times(2); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1038 | DBusPropertiesMap new_properties; |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1039 | const char kCountry[] = "us"; |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1040 | const char kNewImsi[] = "310240123456789"; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1041 | const char kSimIdentifier[] = "9999888"; |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1042 | const char kOperatorIdentifier[] = "310240"; |
| 1043 | const char kOperatorName[] = "Custom SPN"; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1044 | new_properties[MM_SIM_PROPERTY_IMSI].writer().append_string(kNewImsi); |
| 1045 | new_properties[MM_SIM_PROPERTY_SIMIDENTIFIER].writer(). |
| 1046 | append_string(kSimIdentifier); |
| 1047 | new_properties[MM_SIM_PROPERTY_OPERATORIDENTIFIER].writer(). |
| 1048 | append_string(kOperatorIdentifier); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1049 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM, |
| 1050 | new_properties, |
| 1051 | vector<string>()); |
| 1052 | EXPECT_EQ(kNewImsi, capability_->imsi_); |
| 1053 | EXPECT_EQ(kSimIdentifier, capability_->sim_identifier_); |
| 1054 | EXPECT_EQ(kOperatorIdentifier, capability_->operator_id_); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1055 | EXPECT_EQ("", capability_->spn_); |
| 1056 | EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName()); |
| 1057 | EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry()); |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 1058 | EXPECT_EQ(kOperatorIdentifier, cellular_->home_provider().GetCode()); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1059 | EXPECT_EQ(4, capability_->apn_list_.size()); |
| 1060 | |
| 1061 | new_properties[MM_SIM_PROPERTY_OPERATORNAME].writer(). |
| 1062 | append_string(kOperatorName); |
| 1063 | capability_->OnDBusPropertiesChanged(MM_DBUS_INTERFACE_SIM, |
| 1064 | new_properties, |
| 1065 | vector<string>()); |
| 1066 | EXPECT_EQ(kOperatorName, cellular_->home_provider().GetName()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1067 | EXPECT_EQ(kOperatorName, capability_->spn_); |
| 1068 | } |
| 1069 | |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 1070 | MATCHER_P(SizeIs, value, "") { |
| 1071 | return static_cast<size_t>(value) == arg.size(); |
| 1072 | } |
| 1073 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1074 | TEST_F(CellularCapabilityUniversalMainTest, Reset) { |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 1075 | // Save pointers to proxies before they are lost by the call to InitProxies |
| 1076 | mm1::MockModemProxy *modem_proxy = modem_proxy_.get(); |
| 1077 | SetUp(); |
| 1078 | EXPECT_CALL(*modem_proxy, set_state_changed_callback(_)); |
| 1079 | capability_->InitProxies(); |
| 1080 | |
| 1081 | Error error; |
| 1082 | ResultCallback reset_callback; |
| 1083 | |
| 1084 | EXPECT_CALL(*modem_proxy, Reset(_, _, CellularCapability::kTimeoutReset)) |
| 1085 | .WillOnce(SaveArg<1>(&reset_callback)); |
| 1086 | |
| 1087 | capability_->Reset(&error, ResultCallback()); |
| 1088 | EXPECT_TRUE(capability_->resetting_); |
| 1089 | reset_callback.Run(error); |
| 1090 | EXPECT_FALSE(capability_->resetting_); |
| 1091 | } |
| 1092 | |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 1093 | // Validates that OnScanReply does not crash with a null callback. |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1094 | TEST_F(CellularCapabilityUniversalMainTest, ScanWithNullCallback) { |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 1095 | Error error; |
| 1096 | EXPECT_CALL(*modem_3gpp_proxy_, Scan(_, _, CellularCapability::kTimeoutScan)) |
| 1097 | .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::InvokeScan)); |
| 1098 | EXPECT_CALL(*device_adaptor_, |
| 1099 | EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 1100 | SizeIs(0))); |
| 1101 | Set3gppProxy(); |
| 1102 | capability_->Scan(&error, ResultCallback()); |
| 1103 | EXPECT_TRUE(error.IsSuccess()); |
| 1104 | } |
| 1105 | |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 1106 | // Validates that the scanning property is updated |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1107 | TEST_F(CellularCapabilityUniversalMainTest, Scan) { |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 1108 | Error error; |
| 1109 | |
| 1110 | EXPECT_CALL(*modem_3gpp_proxy_, Scan(_, _, CellularCapability::kTimeoutScan)) |
| 1111 | .WillRepeatedly(SaveArg<1>(&scan_callback_)); |
| 1112 | EXPECT_CALL(*device_adaptor_, |
| 1113 | EmitBoolChanged(flimflam::kScanningProperty, true)); |
| 1114 | Set3gppProxy(); |
| 1115 | capability_->Scan(&error, ResultCallback()); |
| 1116 | EXPECT_TRUE(capability_->scanning_); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1117 | Mock::VerifyAndClearExpectations(device_adaptor_); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 1118 | |
| 1119 | // Simulate the completion of the scan with 2 networks in the results. |
| 1120 | EXPECT_CALL(*device_adaptor_, |
| 1121 | EmitBoolChanged(flimflam::kScanningProperty, false)); |
| 1122 | EXPECT_CALL(*device_adaptor_, |
| 1123 | EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 1124 | SizeIs(2))); |
| 1125 | vector<DBusPropertiesMap> results; |
| 1126 | const char kScanID0[] = "testID0"; |
| 1127 | const char kScanID1[] = "testID1"; |
| 1128 | results.push_back(DBusPropertiesMap()); |
| 1129 | results[0][CellularCapabilityUniversal::kOperatorLongProperty]. |
| 1130 | writer().append_string(kScanID0); |
| 1131 | results.push_back(DBusPropertiesMap()); |
| 1132 | results[1][CellularCapabilityUniversal::kOperatorLongProperty]. |
| 1133 | writer().append_string(kScanID1); |
| 1134 | scan_callback_.Run(results, error); |
| 1135 | EXPECT_FALSE(capability_->scanning_); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1136 | Mock::VerifyAndClearExpectations(device_adaptor_); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 1137 | |
| 1138 | // Simulate the completion of the scan with no networks in the results. |
| 1139 | EXPECT_CALL(*device_adaptor_, |
| 1140 | EmitBoolChanged(flimflam::kScanningProperty, true)); |
| 1141 | capability_->Scan(&error, ResultCallback()); |
| 1142 | EXPECT_TRUE(capability_->scanning_); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1143 | Mock::VerifyAndClearExpectations(device_adaptor_); |
| 1144 | |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 1145 | EXPECT_CALL(*device_adaptor_, |
| 1146 | EmitBoolChanged(flimflam::kScanningProperty, false)); |
| 1147 | EXPECT_CALL(*device_adaptor_, |
| 1148 | EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 1149 | SizeIs(0))); |
| 1150 | scan_callback_.Run(vector<DBusPropertiesMap>(), Error()); |
| 1151 | EXPECT_FALSE(capability_->scanning_); |
| 1152 | } |
| 1153 | |
| 1154 | // Validates expected property updates when scan fails |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1155 | TEST_F(CellularCapabilityUniversalMainTest, ScanFailure) { |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 1156 | Error error; |
| 1157 | |
| 1158 | // Test immediate error |
| 1159 | { |
| 1160 | InSequence seq; |
| 1161 | EXPECT_CALL(*modem_3gpp_proxy_, |
| 1162 | Scan(_, _, CellularCapability::kTimeoutScan)) |
| 1163 | .WillOnce(Invoke(this, &CellularCapabilityUniversalTest::ScanError)); |
| 1164 | EXPECT_CALL(*modem_3gpp_proxy_, |
| 1165 | Scan(_, _, CellularCapability::kTimeoutScan)) |
| 1166 | .WillOnce(SaveArg<1>(&scan_callback_)); |
| 1167 | } |
| 1168 | Set3gppProxy(); |
| 1169 | capability_->Scan(&error, ResultCallback()); |
| 1170 | EXPECT_FALSE(capability_->scanning_); |
| 1171 | EXPECT_TRUE(error.IsFailure()); |
| 1172 | |
| 1173 | // Initiate a scan |
| 1174 | error.Populate(Error::kSuccess); |
| 1175 | EXPECT_CALL(*device_adaptor_, |
| 1176 | EmitBoolChanged(flimflam::kScanningProperty, true)); |
| 1177 | capability_->Scan(&error, ResultCallback()); |
| 1178 | EXPECT_TRUE(capability_->scanning_); |
| 1179 | EXPECT_TRUE(error.IsSuccess()); |
| 1180 | |
| 1181 | // Validate that error is returned if Scan is called while already scanning. |
| 1182 | capability_->Scan(&error, ResultCallback()); |
| 1183 | EXPECT_TRUE(capability_->scanning_); |
| 1184 | EXPECT_TRUE(error.IsFailure()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1185 | Mock::VerifyAndClearExpectations(device_adaptor_); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 1186 | |
| 1187 | // Validate that signals are emitted even if an error is reported. |
| 1188 | capability_->found_networks_.clear(); |
| 1189 | capability_->found_networks_.push_back(Stringmap()); |
| 1190 | EXPECT_CALL(*device_adaptor_, |
| 1191 | EmitBoolChanged(flimflam::kScanningProperty, false)); |
| 1192 | EXPECT_CALL(*device_adaptor_, |
| 1193 | EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 1194 | SizeIs(0))); |
| 1195 | vector<DBusPropertiesMap> results; |
| 1196 | scan_callback_.Run(results, Error(Error::kOperationFailed)); |
| 1197 | EXPECT_FALSE(capability_->scanning_); |
| 1198 | } |
| 1199 | |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1200 | // Validates expected behavior of OnListBearersReply function |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1201 | TEST_F(CellularCapabilityUniversalMainTest, OnListBearersReply) { |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1202 | // Check that bearer_path_ is set correctly when an active bearer |
| 1203 | // is returned. |
| 1204 | const size_t kPathCount = 3; |
| 1205 | DBus::Path active_paths[kPathCount], inactive_paths[kPathCount]; |
| 1206 | for (size_t i = 0; i < kPathCount; ++i) { |
| 1207 | active_paths[i] = |
| 1208 | DBus::Path(base::StringPrintf("%s/%zu", kActiveBearerPathPrefix, i)); |
| 1209 | inactive_paths[i] = |
| 1210 | DBus::Path(base::StringPrintf("%s/%zu", kInactiveBearerPathPrefix, i)); |
| 1211 | } |
| 1212 | |
| 1213 | std::vector<DBus::Path> paths; |
| 1214 | paths.push_back(inactive_paths[0]); |
| 1215 | paths.push_back(inactive_paths[1]); |
| 1216 | paths.push_back(active_paths[2]); |
| 1217 | paths.push_back(inactive_paths[1]); |
| 1218 | paths.push_back(inactive_paths[2]); |
| 1219 | |
| 1220 | Error error; |
| 1221 | capability_->OnListBearersReply(paths, error); |
| 1222 | EXPECT_STREQ(capability_->bearer_path_.c_str(), active_paths[2].c_str()); |
| 1223 | |
| 1224 | paths.clear(); |
| 1225 | |
| 1226 | // Check that bearer_path_ is empty if no active bearers are returned. |
| 1227 | paths.push_back(inactive_paths[0]); |
| 1228 | paths.push_back(inactive_paths[1]); |
| 1229 | paths.push_back(inactive_paths[2]); |
| 1230 | paths.push_back(inactive_paths[1]); |
| 1231 | |
| 1232 | capability_->OnListBearersReply(paths, error); |
| 1233 | EXPECT_TRUE(capability_->bearer_path_.empty()); |
| 1234 | |
| 1235 | // Check that returning multiple bearers causes death. |
| 1236 | paths.push_back(active_paths[0]); |
| 1237 | paths.push_back(inactive_paths[1]); |
| 1238 | paths.push_back(inactive_paths[2]); |
| 1239 | paths.push_back(active_paths[1]); |
| 1240 | paths.push_back(inactive_paths[1]); |
| 1241 | |
| 1242 | EXPECT_DEATH(capability_->OnListBearersReply(paths, error), |
| 1243 | "Found more than one active bearer."); |
| 1244 | } |
| 1245 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1246 | // Validates expected behavior of Connect function |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1247 | TEST_F(CellularCapabilityUniversalMainTest, Connect) { |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1248 | mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get(); |
| 1249 | SetSimpleProxy(); |
| 1250 | Error error; |
| 1251 | DBusPropertiesMap properties; |
| 1252 | capability_->apn_try_list_.clear(); |
| 1253 | ResultCallback callback = |
| 1254 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 1255 | DBus::Path bearer("/foo"); |
| 1256 | |
| 1257 | // Test connect failures |
| 1258 | EXPECT_CALL(*modem_simple_proxy, Connect(_, _, _, _)) |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1259 | .WillRepeatedly(SaveArg<2>(&connect_callback_)); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1260 | capability_->Connect(properties, &error, callback); |
| 1261 | EXPECT_TRUE(error.IsSuccess()); |
| 1262 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 1263 | EXPECT_CALL(*service_, ClearLastGoodApn()); |
| 1264 | connect_callback_.Run(bearer, Error(Error::kOperationFailed)); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1265 | Mock::VerifyAndClearExpectations(this); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1266 | |
| 1267 | // Test connect success |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1268 | capability_->Connect(properties, &error, callback); |
| 1269 | EXPECT_TRUE(error.IsSuccess()); |
| 1270 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 1271 | connect_callback_.Run(bearer, Error(Error::kSuccess)); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1272 | Mock::VerifyAndClearExpectations(this); |
Jason Glasgow | 7234ec3 | 2012-05-23 16:01:21 -0400 | [diff] [blame] | 1273 | |
| 1274 | // Test connect failures without a service. Make sure that shill |
| 1275 | // does not crash if the connect failed and there is no |
| 1276 | // CellularService object. This can happen if the modem is enabled |
| 1277 | // and then quickly disabled. |
| 1278 | cellular_->service_ = NULL; |
| 1279 | EXPECT_FALSE(capability_->cellular()->service()); |
Jason Glasgow | 7234ec3 | 2012-05-23 16:01:21 -0400 | [diff] [blame] | 1280 | capability_->Connect(properties, &error, callback); |
| 1281 | EXPECT_TRUE(error.IsSuccess()); |
| 1282 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 1283 | connect_callback_.Run(bearer, Error(Error::kOperationFailed)); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | // Validates Connect iterates over APNs |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1287 | TEST_F(CellularCapabilityUniversalMainTest, ConnectApns) { |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1288 | mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get(); |
| 1289 | SetSimpleProxy(); |
| 1290 | Error error; |
| 1291 | DBusPropertiesMap properties; |
| 1292 | capability_->apn_try_list_.clear(); |
| 1293 | ResultCallback callback = |
| 1294 | Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this)); |
| 1295 | DBus::Path bearer("/bearer0"); |
| 1296 | |
| 1297 | const char apn_name_foo[] = "foo"; |
| 1298 | const char apn_name_bar[] = "bar"; |
| 1299 | EXPECT_CALL(*modem_simple_proxy, Connect(HasApn(apn_name_foo), _, _, _)) |
| 1300 | .WillOnce(SaveArg<2>(&connect_callback_)); |
| 1301 | Stringmap apn1; |
| 1302 | apn1[flimflam::kApnProperty] = apn_name_foo; |
| 1303 | capability_->apn_try_list_.push_back(apn1); |
| 1304 | Stringmap apn2; |
| 1305 | apn2[flimflam::kApnProperty] = apn_name_bar; |
| 1306 | capability_->apn_try_list_.push_back(apn2); |
| 1307 | capability_->FillConnectPropertyMap(&properties); |
| 1308 | capability_->Connect(properties, &error, callback); |
| 1309 | EXPECT_TRUE(error.IsSuccess()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1310 | Mock::VerifyAndClearExpectations(modem_simple_proxy); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1311 | |
| 1312 | EXPECT_CALL(*modem_simple_proxy, Connect(HasApn(apn_name_bar), _, _, _)) |
| 1313 | .WillOnce(SaveArg<2>(&connect_callback_)); |
| 1314 | EXPECT_CALL(*service_, ClearLastGoodApn()); |
| 1315 | connect_callback_.Run(bearer, Error(Error::kInvalidApn)); |
| 1316 | |
| 1317 | EXPECT_CALL(*service_, SetLastGoodApn(apn2)); |
| 1318 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 1319 | connect_callback_.Run(bearer, Error(Error::kSuccess)); |
| 1320 | } |
| 1321 | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1322 | // Validates GetTypeString and AccessTechnologyToTechnologyFamily |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1323 | TEST_F(CellularCapabilityUniversalMainTest, GetTypeString) { |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1324 | const int gsm_technologies[] = { |
| 1325 | MM_MODEM_ACCESS_TECHNOLOGY_LTE, |
| 1326 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS, |
| 1327 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA, |
| 1328 | MM_MODEM_ACCESS_TECHNOLOGY_HSUPA, |
| 1329 | MM_MODEM_ACCESS_TECHNOLOGY_HSDPA, |
| 1330 | MM_MODEM_ACCESS_TECHNOLOGY_UMTS, |
| 1331 | MM_MODEM_ACCESS_TECHNOLOGY_EDGE, |
| 1332 | MM_MODEM_ACCESS_TECHNOLOGY_GPRS, |
| 1333 | MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT, |
| 1334 | MM_MODEM_ACCESS_TECHNOLOGY_GSM, |
| 1335 | MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 1336 | MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 1337 | MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA, |
| 1338 | MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA, |
| 1339 | MM_MODEM_ACCESS_TECHNOLOGY_LTE | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB, |
| 1340 | MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB, |
| 1341 | MM_MODEM_ACCESS_TECHNOLOGY_GSM | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT, |
| 1342 | }; |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 1343 | for (size_t i = 0; i < arraysize(gsm_technologies); ++i) { |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1344 | capability_->access_technologies_ = gsm_technologies[i]; |
| 1345 | ASSERT_EQ(capability_->GetTypeString(), flimflam::kTechnologyFamilyGsm); |
| 1346 | } |
| 1347 | const int cdma_technologies[] = { |
| 1348 | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 1349 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA, |
| 1350 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 1351 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB, |
| 1352 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB | MM_MODEM_ACCESS_TECHNOLOGY_EVDO0, |
| 1353 | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT, |
| 1354 | }; |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 1355 | for (size_t i = 0; i < arraysize(cdma_technologies); ++i) { |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1356 | capability_->access_technologies_ = cdma_technologies[i]; |
| 1357 | ASSERT_EQ(capability_->GetTypeString(), flimflam::kTechnologyFamilyCdma); |
| 1358 | } |
| 1359 | capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; |
| 1360 | ASSERT_EQ(capability_->GetTypeString(), ""); |
| 1361 | } |
| 1362 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1363 | TEST_F(CellularCapabilityUniversalMainTest, AllowRoaming) { |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 1364 | EXPECT_FALSE(cellular_->allow_roaming_); |
| 1365 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
| 1366 | EXPECT_FALSE(capability_->AllowRoaming()); |
| 1367 | capability_->provider_requires_roaming_ = true; |
| 1368 | EXPECT_TRUE(capability_->AllowRoaming()); |
| 1369 | capability_->provider_requires_roaming_ = false; |
| 1370 | cellular_->allow_roaming_ = true; |
| 1371 | EXPECT_TRUE(capability_->AllowRoaming()); |
| 1372 | } |
| 1373 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1374 | TEST_F(CellularCapabilityUniversalMainTest, SetHomeProvider) { |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 1375 | static const char kTestCarrier[] = "The Cellular Carrier"; |
| 1376 | static const char kCountry[] = "us"; |
| 1377 | static const char kCode[] = "310160"; |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 1378 | |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 1379 | EXPECT_FALSE(capability_->home_provider_); |
| 1380 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
| 1381 | |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 1382 | // No mobile provider DB available. |
| 1383 | capability_->SetHomeProvider(); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 1384 | EXPECT_TRUE(cellular_->home_provider().GetName().empty()); |
| 1385 | EXPECT_TRUE(cellular_->home_provider().GetCountry().empty()); |
| 1386 | EXPECT_TRUE(cellular_->home_provider().GetCode().empty()); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 1387 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 1388 | |
| 1389 | InitProviderDB(); |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 1390 | |
| 1391 | // IMSI and Operator Code not available. |
| 1392 | capability_->SetHomeProvider(); |
| 1393 | EXPECT_TRUE(cellular_->home_provider().GetName().empty()); |
| 1394 | EXPECT_TRUE(cellular_->home_provider().GetCountry().empty()); |
| 1395 | EXPECT_TRUE(cellular_->home_provider().GetCode().empty()); |
| 1396 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
| 1397 | |
| 1398 | // Operator Code available. |
| 1399 | capability_->operator_id_ = "310240"; |
| 1400 | capability_->SetHomeProvider(); |
| 1401 | EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName()); |
| 1402 | EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry()); |
| 1403 | EXPECT_EQ("310240", cellular_->home_provider().GetCode()); |
| 1404 | EXPECT_EQ(4, capability_->apn_list_.size()); |
| 1405 | ASSERT_TRUE(capability_->home_provider_); |
| 1406 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
| 1407 | |
| 1408 | cellular_->home_provider_.SetName(""); |
| 1409 | cellular_->home_provider_.SetCountry(""); |
| 1410 | cellular_->home_provider_.SetCode(""); |
| 1411 | |
| 1412 | // IMSI available |
| 1413 | capability_->imsi_ = "310240123456789"; |
| 1414 | capability_->operator_id_.clear(); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 1415 | capability_->SetHomeProvider(); |
| 1416 | EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName()); |
| 1417 | EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry()); |
| 1418 | EXPECT_EQ(kCode, cellular_->home_provider().GetCode()); |
| 1419 | EXPECT_EQ(4, capability_->apn_list_.size()); |
| 1420 | ASSERT_TRUE(capability_->home_provider_); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 1421 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 1422 | |
| 1423 | Cellular::Operator oper; |
| 1424 | cellular_->set_home_provider(oper); |
| 1425 | capability_->spn_ = kTestCarrier; |
| 1426 | capability_->SetHomeProvider(); |
| 1427 | EXPECT_EQ(kTestCarrier, cellular_->home_provider().GetName()); |
| 1428 | EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry()); |
| 1429 | EXPECT_EQ(kCode, cellular_->home_provider().GetCode()); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 1430 | EXPECT_FALSE(capability_->provider_requires_roaming_); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 1431 | |
| 1432 | static const char kCubic[] = "Cubic"; |
| 1433 | capability_->spn_ = kCubic; |
| 1434 | capability_->SetHomeProvider(); |
| 1435 | EXPECT_EQ(kCubic, cellular_->home_provider().GetName()); |
| 1436 | EXPECT_EQ("", cellular_->home_provider().GetCode()); |
| 1437 | ASSERT_TRUE(capability_->home_provider_); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 1438 | EXPECT_TRUE(capability_->provider_requires_roaming_); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 1439 | |
| 1440 | static const char kCUBIC[] = "CUBIC"; |
| 1441 | capability_->spn_ = kCUBIC; |
| 1442 | capability_->home_provider_ = NULL; |
| 1443 | capability_->SetHomeProvider(); |
| 1444 | EXPECT_EQ(kCUBIC, cellular_->home_provider().GetName()); |
| 1445 | EXPECT_EQ("", cellular_->home_provider().GetCode()); |
| 1446 | ASSERT_TRUE(capability_->home_provider_); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 1447 | EXPECT_TRUE(capability_->provider_requires_roaming_); |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 1448 | } |
| 1449 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1450 | TEST_F(CellularCapabilityUniversalMainTest, UpdateScanningProperty) { |
Ben Chan | 8a2c01e | 2013-01-23 10:09:14 -0800 | [diff] [blame] | 1451 | // Save pointers to proxies before they are lost by the call to InitProxies |
| 1452 | // mm1::MockModemProxy *modem_proxy = modem_proxy_.get(); |
| 1453 | SetUp(); |
| 1454 | //EXPECT_CALL(*modem_proxy, set_state_changed_callback(_)); |
| 1455 | capability_->InitProxies(); |
| 1456 | |
| 1457 | EXPECT_FALSE(capability_->scanning_or_searching_); |
| 1458 | capability_->UpdateScanningProperty(); |
| 1459 | EXPECT_FALSE(capability_->scanning_or_searching_); |
| 1460 | |
| 1461 | capability_->scanning_ = true; |
| 1462 | capability_->UpdateScanningProperty(); |
| 1463 | EXPECT_TRUE(capability_->scanning_or_searching_); |
| 1464 | |
| 1465 | capability_->scanning_ = false; |
| 1466 | capability_->cellular()->modem_state_ = Cellular::kModemStateInitializing; |
| 1467 | capability_->UpdateScanningProperty(); |
| 1468 | EXPECT_FALSE(capability_->scanning_or_searching_); |
| 1469 | capability_->cellular()->modem_state_ = Cellular::kModemStateLocked; |
| 1470 | capability_->UpdateScanningProperty(); |
| 1471 | EXPECT_FALSE(capability_->scanning_or_searching_); |
| 1472 | capability_->cellular()->modem_state_ = Cellular::kModemStateDisabled; |
| 1473 | capability_->UpdateScanningProperty(); |
| 1474 | EXPECT_FALSE(capability_->scanning_or_searching_); |
| 1475 | capability_->cellular()->modem_state_ = Cellular::kModemStateEnabling; |
| 1476 | capability_->UpdateScanningProperty(); |
| 1477 | EXPECT_TRUE(capability_->scanning_or_searching_); |
| 1478 | capability_->cellular()->modem_state_ = Cellular::kModemStateEnabled; |
| 1479 | capability_->UpdateScanningProperty(); |
| 1480 | EXPECT_TRUE(capability_->scanning_or_searching_); |
| 1481 | capability_->cellular()->modem_state_ = Cellular::kModemStateSearching; |
| 1482 | capability_->UpdateScanningProperty(); |
| 1483 | EXPECT_TRUE(capability_->scanning_or_searching_); |
| 1484 | capability_->cellular()->modem_state_ = Cellular::kModemStateRegistered; |
| 1485 | capability_->UpdateScanningProperty(); |
| 1486 | EXPECT_FALSE(capability_->scanning_or_searching_); |
| 1487 | capability_->cellular()->modem_state_ = Cellular::kModemStateConnecting; |
| 1488 | capability_->UpdateScanningProperty(); |
| 1489 | EXPECT_FALSE(capability_->scanning_or_searching_); |
| 1490 | capability_->cellular()->modem_state_ = Cellular::kModemStateConnected; |
| 1491 | capability_->UpdateScanningProperty(); |
| 1492 | EXPECT_FALSE(capability_->scanning_or_searching_); |
| 1493 | capability_->cellular()->modem_state_ = Cellular::kModemStateDisconnecting; |
| 1494 | capability_->UpdateScanningProperty(); |
| 1495 | EXPECT_FALSE(capability_->scanning_or_searching_); |
Ben Chan | e1e1e56 | 2013-01-26 00:39:01 -0800 | [diff] [blame] | 1496 | |
Ben Chan | 40a2f86 | 2013-02-13 17:44:38 -0800 | [diff] [blame] | 1497 | // Modem with an unactivated service in the 'enabled' or 'searching' state |
| 1498 | capability_->cellular()->modem_state_ = Cellular::kModemStateEnabled; |
Ben Chan | e1e1e56 | 2013-01-26 00:39:01 -0800 | [diff] [blame] | 1499 | capability_->mdn_ = "0000000000"; |
Ben Chan | e1e1e56 | 2013-01-26 00:39:01 -0800 | [diff] [blame] | 1500 | CellularService::OLP olp; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1501 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_)) |
Ben Chan | 40a2f86 | 2013-02-13 17:44:38 -0800 | [diff] [blame] | 1502 | .WillRepeatedly(Return(&olp)); |
| 1503 | capability_->UpdateScanningProperty(); |
| 1504 | EXPECT_FALSE(capability_->scanning_or_searching_); |
| 1505 | |
| 1506 | capability_->cellular()->modem_state_ = Cellular::kModemStateSearching; |
Ben Chan | e1e1e56 | 2013-01-26 00:39:01 -0800 | [diff] [blame] | 1507 | capability_->UpdateScanningProperty(); |
| 1508 | EXPECT_FALSE(capability_->scanning_or_searching_); |
Ben Chan | 8a2c01e | 2013-01-23 10:09:14 -0800 | [diff] [blame] | 1509 | } |
| 1510 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1511 | TEST_F(CellularCapabilityUniversalTimerTest, UpdateScanningPropertyTimeout) { |
| 1512 | SetUp(); |
| 1513 | capability_->InitProxies(); |
| 1514 | |
| 1515 | EXPECT_FALSE(capability_->scanning_or_searching_); |
| 1516 | EXPECT_TRUE( |
| 1517 | capability_->scanning_or_searching_timeout_callback_.IsCancelled()); |
| 1518 | capability_->UpdateScanningProperty(); |
| 1519 | EXPECT_FALSE(capability_->scanning_or_searching_); |
| 1520 | EXPECT_TRUE( |
| 1521 | capability_->scanning_or_searching_timeout_callback_.IsCancelled()); |
| 1522 | |
| 1523 | EXPECT_CALL(mock_dispatcher_, |
| 1524 | PostDelayedTask( |
| 1525 | _, |
| 1526 | CellularCapabilityUniversal:: |
| 1527 | kDefaultScanningOrSearchingTimeoutMilliseconds)); |
| 1528 | |
| 1529 | capability_->scanning_ = true; |
| 1530 | capability_->UpdateScanningProperty(); |
| 1531 | EXPECT_FALSE( |
| 1532 | capability_->scanning_or_searching_timeout_callback_.IsCancelled()); |
| 1533 | EXPECT_TRUE(capability_->scanning_or_searching_); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1534 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1535 | |
| 1536 | EXPECT_CALL(mock_dispatcher_, |
| 1537 | PostDelayedTask( |
| 1538 | _, |
| 1539 | CellularCapabilityUniversal:: |
| 1540 | kDefaultScanningOrSearchingTimeoutMilliseconds)) |
| 1541 | .Times(0); |
| 1542 | |
| 1543 | capability_->scanning_ = false; |
| 1544 | capability_->UpdateScanningProperty(); |
| 1545 | EXPECT_TRUE( |
| 1546 | capability_->scanning_or_searching_timeout_callback_.IsCancelled()); |
| 1547 | EXPECT_FALSE(capability_->scanning_or_searching_); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1548 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1549 | |
| 1550 | EXPECT_CALL(mock_dispatcher_, |
| 1551 | PostDelayedTask( |
| 1552 | _, |
| 1553 | CellularCapabilityUniversal:: |
| 1554 | kDefaultScanningOrSearchingTimeoutMilliseconds)) |
| 1555 | .WillOnce(InvokeWithoutArgs( |
| 1556 | this, |
| 1557 | &CellularCapabilityUniversalTest::InvokeScanningOrSearchingTimeout)); |
| 1558 | |
| 1559 | capability_->scanning_ = true; |
| 1560 | capability_->UpdateScanningProperty(); |
| 1561 | // The callback has been scheduled |
| 1562 | EXPECT_FALSE( |
| 1563 | capability_->scanning_or_searching_timeout_callback_.IsCancelled()); |
| 1564 | // Our mock invocation worked |
| 1565 | EXPECT_FALSE(capability_->scanning_or_searching_); |
| 1566 | } |
| 1567 | |
| 1568 | TEST_F(CellularCapabilityUniversalMainTest, UpdateStorageIdentifier) { |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 1569 | CellularOperatorInfo::CellularOperator provider; |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 1570 | |
| 1571 | SetService(); |
| 1572 | |
| 1573 | const string prefix = "cellular_" + string(kMachineAddress) + "_"; |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1574 | string default_identifier_pattern = |
| 1575 | prefix + string(CellularCapabilityUniversal::kGenericServiceNamePrefix); |
| 1576 | std::replace_if(default_identifier_pattern.begin(), |
| 1577 | default_identifier_pattern.end(), |
| 1578 | &Service::IllegalChar, '_'); |
| 1579 | default_identifier_pattern += "*"; |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 1580 | |
| 1581 | // |capability_->operator_id_| is "". |
| 1582 | capability_->UpdateStorageIdentifier(); |
| 1583 | EXPECT_TRUE(::MatchPattern(cellular_->service()->storage_identifier_, |
| 1584 | default_identifier_pattern)); |
| 1585 | |
| 1586 | // GetCellularOperatorByMCCMNC returns NULL. |
| 1587 | capability_->operator_id_ = "1"; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1588 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 1589 | GetCellularOperatorByMCCMNC(capability_->operator_id_)) |
| 1590 | .WillOnce( |
| 1591 | Return((const CellularOperatorInfo::CellularOperator *)NULL)); |
| 1592 | |
| 1593 | capability_->UpdateStorageIdentifier(); |
| 1594 | EXPECT_TRUE(::MatchPattern(cellular_->service()->storage_identifier_, |
| 1595 | default_identifier_pattern)); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1596 | Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info()); |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 1597 | |
| 1598 | // |capability_->imsi_| is not "" |
| 1599 | capability_->imsi_ = "TESTIMSI"; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1600 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 1601 | GetCellularOperatorByMCCMNC(capability_->operator_id_)) |
| 1602 | .WillOnce( |
| 1603 | Return((const CellularOperatorInfo::CellularOperator *)NULL)); |
| 1604 | |
| 1605 | capability_->UpdateStorageIdentifier(); |
| 1606 | EXPECT_EQ(prefix + "TESTIMSI", cellular_->service()->storage_identifier_); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1607 | Mock::VerifyAndClearExpectations(modem_info_.mock_cellular_operator_info()); |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 1608 | |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1609 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 1610 | GetCellularOperatorByMCCMNC(capability_->operator_id_)) |
| 1611 | .Times(2) |
| 1612 | .WillRepeatedly(Return(&provider)); |
| 1613 | |
| 1614 | // |provider.identifier_| is "". |
| 1615 | capability_->UpdateStorageIdentifier(); |
| 1616 | EXPECT_EQ(prefix + "TESTIMSI", cellular_->service()->storage_identifier_); |
| 1617 | |
| 1618 | // Success. |
| 1619 | provider.identifier_ = "testidentifier"; |
| 1620 | capability_->UpdateStorageIdentifier(); |
| 1621 | EXPECT_EQ(prefix + "testidentifier", |
| 1622 | cellular_->service()->storage_identifier_); |
| 1623 | } |
| 1624 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1625 | TEST_F(CellularCapabilityUniversalMainTest, UpdateOLP) { |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1626 | CellularService::OLP test_olp; |
| 1627 | test_olp.SetURL("http://testurl"); |
| 1628 | test_olp.SetMethod("POST"); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 1629 | test_olp.SetPostData("imei=${imei}&imsi=${imsi}&mdn=${mdn}&" |
| 1630 | "min=${min}&iccid=${iccid}"); |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1631 | |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1632 | capability_->imei_ = "1"; |
| 1633 | capability_->imsi_ = "2"; |
| 1634 | capability_->mdn_ = "3"; |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1635 | capability_->min_ = "5"; |
| 1636 | capability_->sim_identifier_ = "6"; |
| 1637 | capability_->operator_id_ = "123456"; |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1638 | |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1639 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 1640 | GetOLPByMCCMNC(capability_->operator_id_)) |
| 1641 | .WillRepeatedly(Return(&test_olp)); |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1642 | |
| 1643 | SetService(); |
| 1644 | capability_->UpdateOLP(); |
| 1645 | const CellularService::OLP &olp = cellular_->service()->olp(); |
| 1646 | EXPECT_EQ("http://testurl", olp.GetURL()); |
| 1647 | EXPECT_EQ("POST", olp.GetMethod()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 1648 | EXPECT_EQ("imei=1&imsi=2&mdn=3&min=5&iccid=6", |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1649 | olp.GetPostData()); |
| 1650 | } |
| 1651 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1652 | TEST_F(CellularCapabilityUniversalMainTest, IsMdnValid) { |
| 1653 | capability_->mdn_.clear(); |
| 1654 | EXPECT_FALSE(capability_->IsMdnValid()); |
| 1655 | capability_->mdn_ = "0000000"; |
| 1656 | EXPECT_FALSE(capability_->IsMdnValid()); |
| 1657 | capability_->mdn_ = "0000001"; |
| 1658 | EXPECT_TRUE(capability_->IsMdnValid()); |
| 1659 | capability_->mdn_ = "1231223"; |
| 1660 | EXPECT_TRUE(capability_->IsMdnValid()); |
| 1661 | } |
| 1662 | |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1663 | TEST_F(CellularCapabilityUniversalTimerTest, CompleteActivation) { |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1664 | const char kIccid[] = "1234567"; |
| 1665 | |
| 1666 | capability_->mdn_.clear(); |
| 1667 | capability_->sim_identifier_.clear(); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1668 | |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1669 | EXPECT_CALL(*service_, |
| 1670 | SetActivationState(flimflam::kActivationStateActivating)) |
| 1671 | .Times(0); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1672 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1673 | SetActivationState( |
| 1674 | PendingActivationStore::kIdentifierICCID, _, _)) |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1675 | .Times(0); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1676 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(0); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1677 | Error error; |
| 1678 | capability_->CompleteActivation(&error); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1679 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1680 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1681 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
| 1682 | EXPECT_TRUE( |
| 1683 | capability_->activation_wait_for_registration_callback_.IsCancelled()); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1684 | |
| 1685 | capability_->sim_identifier_ = kIccid; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1686 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1687 | SetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1688 | kIccid, |
| 1689 | PendingActivationStore::kStatePending)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1690 | .Times(1); |
| 1691 | EXPECT_CALL(*service_, |
| 1692 | SetActivationState(flimflam::kActivationStateActivating)) |
| 1693 | .Times(1); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1694 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(1); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1695 | capability_->CompleteActivation(&error); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1696 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1697 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1698 | Mock::VerifyAndClearExpectations(&mock_dispatcher_); |
| 1699 | EXPECT_FALSE( |
| 1700 | capability_->activation_wait_for_registration_callback_.IsCancelled()); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1701 | |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1702 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1703 | SetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1704 | kIccid, |
| 1705 | PendingActivationStore::kStatePending)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1706 | .Times(0); |
| 1707 | EXPECT_CALL(*service_, |
| 1708 | SetActivationState(flimflam::kActivationStateActivating)) |
| 1709 | .Times(0); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1710 | EXPECT_CALL(mock_dispatcher_, PostDelayedTask(_, _)).Times(0); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1711 | capability_->mdn_ = "1231231212"; |
| 1712 | capability_->CompleteActivation(&error); |
| 1713 | } |
| 1714 | |
| 1715 | TEST_F(CellularCapabilityUniversalMainTest, UpdateServiceActivationState) { |
| 1716 | const char kIccid[] = "1234567"; |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1717 | capability_->sim_identifier_.clear(); |
| 1718 | capability_->mdn_ = "0000000000"; |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1719 | CellularService::OLP olp; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1720 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1721 | .WillRepeatedly(Return(&olp)); |
| 1722 | |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 1723 | service_->SetAutoConnect(false); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1724 | EXPECT_CALL(*service_, |
| 1725 | SetActivationState(flimflam::kActivationStateNotActivated)) |
| 1726 | .Times(1); |
| 1727 | capability_->UpdateServiceActivationState(); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1728 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 1729 | EXPECT_FALSE(service_->auto_connect()); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1730 | |
| 1731 | capability_->mdn_ = "1231231122"; |
| 1732 | EXPECT_CALL(*service_, |
| 1733 | SetActivationState(flimflam::kActivationStateActivated)) |
| 1734 | .Times(1); |
| 1735 | capability_->UpdateServiceActivationState(); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1736 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 1737 | EXPECT_TRUE(service_->auto_connect()); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1738 | |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 1739 | service_->SetAutoConnect(false); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1740 | capability_->mdn_ = "0000000000"; |
| 1741 | capability_->sim_identifier_ = kIccid; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1742 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1743 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1744 | kIccid)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1745 | .Times(2) |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1746 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 1747 | .WillOnce(Return(PendingActivationStore::kStatePendingTimeout)); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1748 | EXPECT_CALL(*service_, |
| 1749 | SetActivationState(flimflam::kActivationStateActivating)) |
| 1750 | .Times(1); |
| 1751 | capability_->UpdateServiceActivationState(); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1752 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1753 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 1754 | EXPECT_FALSE(service_->auto_connect()); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1755 | |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1756 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1757 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1758 | kIccid)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1759 | .Times(2) |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1760 | .WillRepeatedly(Return(PendingActivationStore::kStateActivated)); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1761 | EXPECT_CALL(*service_, |
| 1762 | SetActivationState(flimflam::kActivationStateActivated)) |
| 1763 | .Times(1); |
| 1764 | capability_->UpdateServiceActivationState(); |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 1765 | Mock::VerifyAndClearExpectations(service_); |
| 1766 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
| 1767 | EXPECT_TRUE(service_->auto_connect()); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1768 | } |
| 1769 | |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1770 | TEST_F(CellularCapabilityUniversalMainTest, ActivationWaitForRegisterTimeout) { |
| 1771 | const char kIccid[] = "1234567"; |
| 1772 | |
| 1773 | mm1::MockModemProxy *modem_proxy = modem_proxy_.get(); |
| 1774 | capability_->InitProxies(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1775 | EXPECT_CALL(*modem_proxy, Reset(_, _, _)).Times(0); |
| 1776 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1777 | SetActivationState(_, _, _)) |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1778 | .Times(0); |
| 1779 | |
| 1780 | // No ICCID, no MDN |
| 1781 | capability_->sim_identifier_.clear(); |
| 1782 | capability_->mdn_.clear(); |
| 1783 | capability_->reset_done_ = false; |
| 1784 | capability_->OnActivationWaitForRegisterTimeout(); |
| 1785 | |
| 1786 | // State is not activated. |
| 1787 | capability_->sim_identifier_ = kIccid; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1788 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1789 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
| 1790 | .WillOnce(Return(PendingActivationStore::kStateActivated)) |
| 1791 | .WillRepeatedly(Return(PendingActivationStore::kStatePending)); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1792 | capability_->OnActivationWaitForRegisterTimeout(); |
| 1793 | |
| 1794 | // Valid MDN. |
| 1795 | capability_->mdn_ = "0000000001"; |
| 1796 | capability_->OnActivationWaitForRegisterTimeout(); |
| 1797 | |
| 1798 | // Invalid MDN, reset done. |
| 1799 | capability_->mdn_ = "0000000000"; |
| 1800 | capability_->reset_done_ = true; |
| 1801 | capability_->OnActivationWaitForRegisterTimeout(); |
| 1802 | |
| 1803 | Mock::VerifyAndClearExpectations(modem_proxy); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1804 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1805 | |
| 1806 | // Reset not done. |
| 1807 | capability_->reset_done_ = false; |
| 1808 | EXPECT_CALL(*modem_proxy, Reset(_,_,_)).Times(1); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1809 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1810 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
| 1811 | .WillOnce(Return(PendingActivationStore::kStatePending)); |
| 1812 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1813 | SetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1814 | kIccid, |
| 1815 | PendingActivationStore::kStatePendingTimeout)) |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1816 | .Times(1); |
| 1817 | capability_->OnActivationWaitForRegisterTimeout(); |
| 1818 | } |
| 1819 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1820 | TEST_F(CellularCapabilityUniversalMainTest, UpdatePendingActivationState) { |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1821 | const char kIccid[] = "1234567"; |
| 1822 | |
| 1823 | mm1::MockModemProxy *modem_proxy = modem_proxy_.get(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1824 | capability_->InitProxies(); |
| 1825 | capability_->registration_state_ = |
| 1826 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING; |
| 1827 | |
| 1828 | // No MDN, no ICCID. |
| 1829 | capability_->mdn_ = "0000000"; |
| 1830 | capability_->sim_identifier_.clear(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1831 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1832 | GetActivationState(PendingActivationStore::kIdentifierICCID, _)) |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1833 | .Times(0); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1834 | capability_->UpdatePendingActivationState(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1835 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1836 | |
| 1837 | // ICCID known. |
| 1838 | capability_->sim_identifier_ = kIccid; |
| 1839 | |
| 1840 | // After the modem has reset. |
| 1841 | capability_->reset_done_ = true; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1842 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1843 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1844 | kIccid)) |
| 1845 | .Times(1).WillOnce(Return(PendingActivationStore::kStatePending)); |
| 1846 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1847 | SetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1848 | kIccid, |
| 1849 | PendingActivationStore::kStateActivated)) |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1850 | .Times(1); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1851 | capability_->UpdatePendingActivationState(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1852 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1853 | |
| 1854 | // Before reset, not registered. |
| 1855 | capability_->reset_done_ = false; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1856 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1857 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1858 | kIccid)) |
| 1859 | .Times(2).WillRepeatedly(Return(PendingActivationStore::kStatePending)); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1860 | EXPECT_CALL(*service_, |
| 1861 | SetActivationState(flimflam::kActivationStateActivating)) |
| 1862 | .Times(2); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1863 | EXPECT_CALL(*modem_proxy, Reset(_, _, _)).Times(0); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1864 | capability_->UpdatePendingActivationState(); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1865 | Mock::VerifyAndClearExpectations(modem_proxy); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1866 | |
| 1867 | // Before reset, registered. |
| 1868 | capability_->registration_state_ = |
| 1869 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME; |
| 1870 | EXPECT_CALL(*modem_proxy, Reset(_, _, _)).Times(1); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1871 | capability_->UpdatePendingActivationState(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1872 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1873 | |
| 1874 | // Not registered. |
| 1875 | capability_->registration_state_ = |
| 1876 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1877 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1878 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1879 | kIccid)) |
| 1880 | .Times(2).WillRepeatedly(Return(PendingActivationStore::kStateActivated)); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1881 | EXPECT_CALL(*service_, AutoConnect()).Times(0); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1882 | capability_->UpdatePendingActivationState(); |
Prathmesh Prabhu | b5fde53 | 2013-03-19 17:36:09 -0700 | [diff] [blame] | 1883 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1884 | |
| 1885 | // Service, registered. |
| 1886 | capability_->registration_state_ = |
| 1887 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME; |
| 1888 | EXPECT_CALL(*service_, AutoConnect()).Times(1); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1889 | capability_->UpdatePendingActivationState(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1890 | |
| 1891 | cellular_->service_->activation_state_ = |
| 1892 | flimflam::kActivationStateNotActivated; |
| 1893 | |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1894 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1895 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1896 | // Device is connected. |
| 1897 | cellular_->state_ = Cellular::kStateConnected; |
| 1898 | EXPECT_CALL(*service_, |
| 1899 | SetActivationState(flimflam::kActivationStateActivated)) |
| 1900 | .Times(3); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1901 | capability_->UpdatePendingActivationState(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1902 | |
| 1903 | // Device is linked. |
| 1904 | cellular_->state_ = Cellular::kStateLinked; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1905 | capability_->UpdatePendingActivationState(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1906 | |
| 1907 | // Got valid MDN. |
| 1908 | cellular_->state_ = Cellular::kStateRegistered; |
| 1909 | capability_->mdn_ = "1231223"; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1910 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1911 | RemoveEntry(PendingActivationStore::kIdentifierICCID, kIccid)) |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1912 | .Times(1); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1913 | capability_->UpdatePendingActivationState(); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1914 | |
| 1915 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1916 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1917 | |
| 1918 | // Timed out, not registered. |
| 1919 | capability_->mdn_.clear(); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1920 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1921 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1922 | kIccid)) |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1923 | .Times(1) |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1924 | .WillOnce(Return(PendingActivationStore::kStatePendingTimeout)); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1925 | capability_->registration_state_ = |
| 1926 | MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1927 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1928 | SetActivationState(_, _, _)) |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1929 | .Times(0); |
| 1930 | EXPECT_CALL(*service_, SetActivationState(_)).Times(0); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1931 | capability_->UpdatePendingActivationState(); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1932 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1933 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1934 | |
| 1935 | // Timed out, registered. |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1936 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1937 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1938 | kIccid)) |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1939 | .Times(1) |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1940 | .WillOnce(Return(PendingActivationStore::kStatePendingTimeout)); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1941 | capability_->registration_state_ = |
| 1942 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1943 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 1944 | SetActivationState(PendingActivationStore::kIdentifierICCID, |
| 1945 | kIccid, |
| 1946 | PendingActivationStore::kStateActivated)) |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1947 | .Times(1); |
| 1948 | EXPECT_CALL(*service_, |
| 1949 | SetActivationState(flimflam::kActivationStateActivated)) |
| 1950 | .Times(1); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1951 | capability_->UpdatePendingActivationState(); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 1952 | Mock::VerifyAndClearExpectations(service_); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1953 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1954 | } |
| 1955 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1956 | TEST_F(CellularCapabilityUniversalMainTest, UpdateOperatorInfo) { |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 1957 | static const char kOperatorName[] = "Swisscom"; |
| 1958 | InitProviderDB(); |
| 1959 | capability_->serving_operator_.SetCode("22801"); |
| 1960 | SetService(); |
| 1961 | capability_->UpdateOperatorInfo(); |
| 1962 | EXPECT_EQ(kOperatorName, capability_->serving_operator_.GetName()); |
| 1963 | EXPECT_EQ("ch", capability_->serving_operator_.GetCountry()); |
| 1964 | EXPECT_EQ(kOperatorName, cellular_->service()->serving_operator().GetName()); |
| 1965 | |
| 1966 | static const char kTestOperator[] = "Testcom"; |
| 1967 | capability_->serving_operator_.SetName(kTestOperator); |
| 1968 | capability_->serving_operator_.SetCountry(""); |
| 1969 | capability_->UpdateOperatorInfo(); |
| 1970 | EXPECT_EQ(kTestOperator, capability_->serving_operator_.GetName()); |
| 1971 | EXPECT_EQ("ch", capability_->serving_operator_.GetCountry()); |
| 1972 | EXPECT_EQ(kTestOperator, cellular_->service()->serving_operator().GetName()); |
| 1973 | } |
| 1974 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1975 | TEST_F(CellularCapabilityUniversalMainTest, UpdateOperatorInfoViaOperatorId) { |
Ben Chan | 092b12b | 2012-11-07 22:04:05 -0800 | [diff] [blame] | 1976 | static const char kOperatorName[] = "Swisscom"; |
| 1977 | static const char kOperatorId[] = "22801"; |
| 1978 | InitProviderDB(); |
| 1979 | capability_->serving_operator_.SetCode(""); |
| 1980 | SetService(); |
| 1981 | capability_->UpdateOperatorInfo(); |
| 1982 | EXPECT_EQ("", capability_->serving_operator_.GetName()); |
| 1983 | EXPECT_EQ("", capability_->serving_operator_.GetCountry()); |
| 1984 | EXPECT_EQ("", cellular_->service()->serving_operator().GetName()); |
| 1985 | |
| 1986 | capability_->operator_id_ = kOperatorId; |
| 1987 | |
Ben Chan | 092b12b | 2012-11-07 22:04:05 -0800 | [diff] [blame] | 1988 | capability_->UpdateOperatorInfo(); |
| 1989 | EXPECT_EQ(kOperatorId, capability_->serving_operator_.GetCode()); |
| 1990 | EXPECT_EQ(kOperatorName, capability_->serving_operator_.GetName()); |
| 1991 | EXPECT_EQ("ch", capability_->serving_operator_.GetCountry()); |
| 1992 | EXPECT_EQ(kOperatorName, cellular_->service()->serving_operator().GetName()); |
| 1993 | } |
| 1994 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 1995 | TEST_F(CellularCapabilityUniversalMainTest, CreateFriendlyServiceName) { |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 1996 | CellularCapabilityUniversal::friendly_service_name_id_ = 0; |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1997 | EXPECT_EQ("Mobile Network 0", capability_->CreateFriendlyServiceName()); |
| 1998 | EXPECT_EQ("Mobile Network 1", capability_->CreateFriendlyServiceName()); |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 1999 | |
Ben Chan | 092b12b | 2012-11-07 22:04:05 -0800 | [diff] [blame] | 2000 | capability_->operator_id_ = "0123"; |
Ben Chan | 092b12b | 2012-11-07 22:04:05 -0800 | [diff] [blame] | 2001 | EXPECT_EQ("cellular_0123", capability_->CreateFriendlyServiceName()); |
| 2002 | EXPECT_EQ("0123", capability_->serving_operator_.GetCode()); |
| 2003 | |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 2004 | capability_->serving_operator_.SetCode("1234"); |
| 2005 | EXPECT_EQ("cellular_1234", capability_->CreateFriendlyServiceName()); |
| 2006 | |
| 2007 | static const char kHomeProvider[] = "The GSM Home Provider"; |
| 2008 | cellular_->home_provider_.SetName(kHomeProvider); |
| 2009 | EXPECT_EQ("cellular_1234", capability_->CreateFriendlyServiceName()); |
| 2010 | capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_HOME; |
| 2011 | EXPECT_EQ(kHomeProvider, capability_->CreateFriendlyServiceName()); |
| 2012 | |
| 2013 | static const char kTestOperator[] = "A GSM Operator"; |
| 2014 | capability_->serving_operator_.SetName(kTestOperator); |
| 2015 | EXPECT_EQ(kTestOperator, capability_->CreateFriendlyServiceName()); |
| 2016 | |
| 2017 | capability_->registration_state_ = MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING; |
| 2018 | EXPECT_EQ(StringPrintf("%s | %s", kHomeProvider, kTestOperator), |
| 2019 | capability_->CreateFriendlyServiceName()); |
| 2020 | } |
| 2021 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 2022 | TEST_F(CellularCapabilityUniversalMainTest, IsServiceActivationRequired) { |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 2023 | capability_->mdn_ = "0000000000"; |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 2024 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 2025 | |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 2026 | CellularService::OLP olp; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 2027 | EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_)) |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 2028 | .WillOnce(Return((const CellularService::OLP *)NULL)) |
| 2029 | .WillRepeatedly(Return(&olp)); |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 2030 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 2031 | |
| 2032 | capability_->mdn_ = ""; |
| 2033 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 2034 | capability_->mdn_ = "1234567890"; |
| 2035 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 2036 | capability_->mdn_ = "0000000000"; |
| 2037 | EXPECT_TRUE(capability_->IsServiceActivationRequired()); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 2038 | |
| 2039 | const char kIccid[] = "1234567890"; |
| 2040 | capability_->sim_identifier_ = kIccid; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 2041 | EXPECT_CALL(*modem_info_.mock_pending_activation_store(), |
| 2042 | GetActivationState(PendingActivationStore::kIdentifierICCID, |
| 2043 | kIccid)) |
| 2044 | .WillOnce(Return(PendingActivationStore::kStateActivated)) |
| 2045 | .WillOnce(Return(PendingActivationStore::kStatePending)) |
| 2046 | .WillOnce(Return(PendingActivationStore::kStatePendingTimeout)) |
| 2047 | .WillOnce(Return(PendingActivationStore::kStateUnknown)); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 2048 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 2049 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 2050 | EXPECT_FALSE(capability_->IsServiceActivationRequired()); |
| 2051 | EXPECT_TRUE(capability_->IsServiceActivationRequired()); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 2052 | Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store()); |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 2053 | } |
| 2054 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 2055 | TEST_F(CellularCapabilityUniversalMainTest, OnModemCurrentCapabilitiesChanged) { |
Ben Chan | fcca27b | 2013-01-22 15:03:44 -0800 | [diff] [blame] | 2056 | EXPECT_FALSE(capability_->scanning_supported_); |
| 2057 | capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_LTE); |
| 2058 | EXPECT_FALSE(capability_->scanning_supported_); |
| 2059 | capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_CDMA_EVDO); |
| 2060 | EXPECT_FALSE(capability_->scanning_supported_); |
| 2061 | capability_->OnModemCurrentCapabilitiesChanged(MM_MODEM_CAPABILITY_GSM_UMTS); |
| 2062 | EXPECT_TRUE(capability_->scanning_supported_); |
| 2063 | capability_->OnModemCurrentCapabilitiesChanged( |
| 2064 | MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_CDMA_EVDO); |
| 2065 | EXPECT_TRUE(capability_->scanning_supported_); |
| 2066 | } |
| 2067 | |
Arman Uguray | 7af0fac | 2013-03-18 17:35:35 -0700 | [diff] [blame] | 2068 | TEST_F(CellularCapabilityUniversalMainTest, GetNetworkTechnologyStringOnE362) { |
| 2069 | capability_->model_id_.clear(); |
| 2070 | capability_->access_technologies_ = 0; |
| 2071 | EXPECT_TRUE(capability_->GetNetworkTechnologyString().empty()); |
| 2072 | |
| 2073 | capability_->model_id_ = CellularCapabilityUniversal::kE362ModelId; |
| 2074 | EXPECT_EQ(flimflam::kNetworkTechnologyLte, |
| 2075 | capability_->GetNetworkTechnologyString()); |
| 2076 | |
| 2077 | capability_->access_technologies_ = MM_MODEM_ACCESS_TECHNOLOGY_GPRS; |
| 2078 | EXPECT_EQ(flimflam::kNetworkTechnologyLte, |
| 2079 | capability_->GetNetworkTechnologyString()); |
| 2080 | |
| 2081 | capability_->model_id_.clear(); |
| 2082 | EXPECT_EQ(flimflam::kNetworkTechnologyGprs, |
| 2083 | capability_->GetNetworkTechnologyString()); |
| 2084 | } |
| 2085 | |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 2086 | TEST_F(CellularCapabilityUniversalMainTest, ShouldDetectOutOfCredit) { |
Arman Uguray | d42d8ec | 2013-04-08 19:28:21 -0700 | [diff] [blame] | 2087 | capability_->model_id_.clear(); |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 2088 | EXPECT_FALSE(capability_->ShouldDetectOutOfCredit()); |
Arman Uguray | d42d8ec | 2013-04-08 19:28:21 -0700 | [diff] [blame] | 2089 | capability_->model_id_ = CellularCapabilityUniversal::kE362ModelId; |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 2090 | EXPECT_TRUE(capability_->ShouldDetectOutOfCredit()); |
Arman Uguray | d42d8ec | 2013-04-08 19:28:21 -0700 | [diff] [blame] | 2091 | } |
| 2092 | |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2093 | TEST_F(CellularCapabilityUniversalMainTest, SimLockStatusToProperty) { |
| 2094 | Error error; |
| 2095 | KeyValueStore store = capability_->SimLockStatusToProperty(&error); |
| 2096 | EXPECT_FALSE(store.GetBool(flimflam::kSIMLockEnabledProperty)); |
| 2097 | EXPECT_TRUE(store.GetString(flimflam::kSIMLockTypeProperty).empty()); |
| 2098 | EXPECT_EQ(0, store.GetUint(flimflam::kSIMLockRetriesLeftProperty)); |
| 2099 | |
| 2100 | capability_->sim_lock_status_.enabled = true; |
| 2101 | capability_->sim_lock_status_.retries_left = 3; |
| 2102 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN; |
| 2103 | store = capability_->SimLockStatusToProperty(&error); |
| 2104 | EXPECT_TRUE(store.GetBool(flimflam::kSIMLockEnabledProperty)); |
| 2105 | EXPECT_EQ("sim-pin", store.GetString(flimflam::kSIMLockTypeProperty)); |
| 2106 | EXPECT_EQ(3, store.GetUint(flimflam::kSIMLockRetriesLeftProperty)); |
| 2107 | |
| 2108 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK; |
| 2109 | store = capability_->SimLockStatusToProperty(&error); |
| 2110 | EXPECT_EQ("sim-puk", store.GetString(flimflam::kSIMLockTypeProperty)); |
| 2111 | |
| 2112 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN2; |
| 2113 | store = capability_->SimLockStatusToProperty(&error); |
| 2114 | EXPECT_TRUE(store.GetString(flimflam::kSIMLockTypeProperty).empty()); |
| 2115 | |
| 2116 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK2; |
| 2117 | store = capability_->SimLockStatusToProperty(&error); |
| 2118 | EXPECT_TRUE(store.GetString(flimflam::kSIMLockTypeProperty).empty()); |
| 2119 | } |
| 2120 | |
| 2121 | TEST_F(CellularCapabilityUniversalMainTest, OnLockRetriesChanged) { |
| 2122 | CellularCapabilityUniversal::LockRetryData data; |
| 2123 | const uint32 kDefaultRetries = 999; |
| 2124 | |
| 2125 | capability_->OnLockRetriesChanged(data); |
| 2126 | EXPECT_EQ(kDefaultRetries, capability_->sim_lock_status_.retries_left); |
| 2127 | |
| 2128 | data[MM_MODEM_LOCK_SIM_PIN] = 3; |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 2129 | data[MM_MODEM_LOCK_SIM_PUK] = 10; |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2130 | capability_->OnLockRetriesChanged(data); |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 2131 | EXPECT_EQ(3, capability_->sim_lock_status_.retries_left); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2132 | |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 2133 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PUK; |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2134 | capability_->OnLockRetriesChanged(data); |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 2135 | EXPECT_EQ(10, capability_->sim_lock_status_.retries_left); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2136 | |
| 2137 | capability_->sim_lock_status_.lock_type = MM_MODEM_LOCK_SIM_PIN; |
| 2138 | capability_->OnLockRetriesChanged(data); |
| 2139 | EXPECT_EQ(3, capability_->sim_lock_status_.retries_left); |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 2140 | |
| 2141 | data.clear(); |
| 2142 | capability_->OnLockRetriesChanged(data); |
| 2143 | EXPECT_EQ(kDefaultRetries, capability_->sim_lock_status_.retries_left); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | TEST_F(CellularCapabilityUniversalMainTest, OnLockTypeChanged) { |
| 2147 | EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type); |
| 2148 | |
| 2149 | capability_->OnLockTypeChanged(MM_MODEM_LOCK_NONE); |
| 2150 | EXPECT_EQ(MM_MODEM_LOCK_NONE, capability_->sim_lock_status_.lock_type); |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 2151 | EXPECT_FALSE(capability_->sim_lock_status_.enabled); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2152 | |
| 2153 | capability_->OnLockTypeChanged(MM_MODEM_LOCK_SIM_PIN); |
| 2154 | EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type); |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 2155 | EXPECT_TRUE(capability_->sim_lock_status_.enabled); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2156 | |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 2157 | capability_->sim_lock_status_.enabled = false; |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2158 | capability_->OnLockTypeChanged(MM_MODEM_LOCK_SIM_PUK); |
| 2159 | EXPECT_EQ(MM_MODEM_LOCK_SIM_PUK, capability_->sim_lock_status_.lock_type); |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 2160 | EXPECT_TRUE(capability_->sim_lock_status_.enabled); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | TEST_F(CellularCapabilityUniversalMainTest, OnSimLockPropertiesChanged) { |
| 2164 | EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type); |
| 2165 | EXPECT_EQ(0, capability_->sim_lock_status_.retries_left); |
| 2166 | |
| 2167 | DBusPropertiesMap changed; |
| 2168 | vector<string> invalidated; |
| 2169 | |
| 2170 | capability_->OnModemPropertiesChanged(changed, invalidated); |
| 2171 | EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type); |
| 2172 | EXPECT_EQ(0, capability_->sim_lock_status_.retries_left); |
| 2173 | |
| 2174 | ::DBus::Variant variant; |
| 2175 | ::DBus::MessageIter writer = variant.writer(); |
| 2176 | |
| 2177 | // Unlock retries changed, but the SIM wasn't locked. |
| 2178 | CellularCapabilityUniversal::LockRetryData retry_data; |
| 2179 | retry_data[MM_MODEM_LOCK_SIM_PIN] = 3; |
| 2180 | writer << retry_data; |
| 2181 | changed[MM_MODEM_PROPERTY_UNLOCKRETRIES] = variant; |
| 2182 | |
| 2183 | capability_->OnModemPropertiesChanged(changed, invalidated); |
| 2184 | EXPECT_EQ(MM_MODEM_LOCK_UNKNOWN, capability_->sim_lock_status_.lock_type); |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 2185 | EXPECT_EQ(3, capability_->sim_lock_status_.retries_left); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2186 | |
| 2187 | // Unlock retries changed and the SIM got locked. |
| 2188 | variant.clear(); |
| 2189 | writer = variant.writer(); |
| 2190 | writer << static_cast<uint32>(MM_MODEM_LOCK_SIM_PIN); |
| 2191 | changed[MM_MODEM_PROPERTY_UNLOCKREQUIRED] = variant; |
| 2192 | capability_->OnModemPropertiesChanged(changed, invalidated); |
| 2193 | EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type); |
| 2194 | EXPECT_EQ(3, capability_->sim_lock_status_.retries_left); |
| 2195 | |
| 2196 | // Only unlock retries changed. |
| 2197 | changed.erase(MM_MODEM_PROPERTY_UNLOCKREQUIRED); |
| 2198 | retry_data[MM_MODEM_LOCK_SIM_PIN] = 2; |
| 2199 | variant.clear(); |
| 2200 | writer = variant.writer(); |
| 2201 | writer << retry_data; |
| 2202 | changed[MM_MODEM_PROPERTY_UNLOCKRETRIES] = variant; |
| 2203 | capability_->OnModemPropertiesChanged(changed, invalidated); |
| 2204 | EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type); |
| 2205 | EXPECT_EQ(2, capability_->sim_lock_status_.retries_left); |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 2206 | |
| 2207 | // Unlock retries changed with a value that doesn't match the current |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 2208 | // lock type. Default to whatever count is available. |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 2209 | retry_data.clear(); |
| 2210 | retry_data[MM_MODEM_LOCK_SIM_PIN2] = 2; |
| 2211 | variant.clear(); |
| 2212 | writer = variant.writer(); |
| 2213 | writer << retry_data; |
| 2214 | changed[MM_MODEM_PROPERTY_UNLOCKRETRIES] = variant; |
| 2215 | capability_->OnModemPropertiesChanged(changed, invalidated); |
| 2216 | EXPECT_EQ(MM_MODEM_LOCK_SIM_PIN, capability_->sim_lock_status_.lock_type); |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 2217 | EXPECT_EQ(2, capability_->sim_lock_status_.retries_left); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 2220 | } // namespace shill |