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