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