Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1 | // Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Chan | c54afe5 | 2014-11-05 10:28:08 -0800 | [diff] [blame] | 5 | #include "shill/cellular/mobile_operator_info.h" |
Alex Deymo | cddd2d0 | 2014-11-10 19:55:35 -0800 | [diff] [blame] | 6 | |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 7 | #include <fstream> |
| 8 | #include <map> |
| 9 | #include <ostream> |
| 10 | #include <set> |
| 11 | #include <vector> |
| 12 | |
Ben Chan | 11c213f | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 13 | #include <base/files/file_util.h> |
Ben Chan | cc67c52 | 2014-09-03 07:19:18 -0700 | [diff] [blame] | 14 | #include <base/macros.h> |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 15 | #include <gmock/gmock.h> |
| 16 | #include <gtest/gtest.h> |
| 17 | |
Ben Chan | c54afe5 | 2014-11-05 10:28:08 -0800 | [diff] [blame] | 18 | #include "shill/cellular/mobile_operator_info_impl.h" |
| 19 | #include "shill/event_dispatcher.h" |
| 20 | #include "shill/logging.h" |
| 21 | |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 22 | // These files contain binary protobuf definitions used by the following tests |
| 23 | // inside the namespace ::mobile_operator_db |
| 24 | #define IN_MOBILE_OPERATOR_INFO_UNITTEST_CC |
Ben Chan | c54afe5 | 2014-11-05 10:28:08 -0800 | [diff] [blame] | 25 | #include "shill/mobile_operator_db/test_protos/data_test.h" |
| 26 | #include "shill/mobile_operator_db/test_protos/init_test_empty_db_init.h" |
| 27 | #include "shill/mobile_operator_db/test_protos/init_test_multiple_db_init_1.h" |
| 28 | #include "shill/mobile_operator_db/test_protos/init_test_multiple_db_init_2.h" |
| 29 | #include "shill/mobile_operator_db/test_protos/init_test_successful_init.h" |
| 30 | #include "shill/mobile_operator_db/test_protos/main_test.h" |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 31 | #undef IN_MOBILE_OPERATOR_INFO_UNITTEST_CC |
| 32 | |
| 33 | using base::FilePath; |
| 34 | using shill::mobile_operator_db::MobileOperatorDB; |
| 35 | using std::map; |
| 36 | using std::ofstream; |
| 37 | using std::set; |
| 38 | using std::string; |
| 39 | using std::vector; |
| 40 | using testing::Mock; |
| 41 | using testing::Test; |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 42 | using testing::Values; |
| 43 | using testing::WithParamInterface; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 44 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 45 | // The tests run from the fixture |MobileOperatorInfoMainTest| and |
| 46 | // |MobileOperatorDataTest| can be run in two modes: |
| 47 | // - strict event checking: We check that an event is raised for each update |
| 48 | // to the state of the object. |
| 49 | // - non-strict event checking: We check that a single event is raised as a |
| 50 | // result of many updates to the object. |
| 51 | // The first case corresponds to a very aggressive event loop, that dispatches |
| 52 | // events as soon as they are posted; the second one corresponds to an |
| 53 | // over-crowded event loop that only dispatches events just before we verify |
| 54 | // that events were raised. |
| 55 | // |
| 56 | // We use ::testing::WithParamInterface to templatize the test fixtures to do |
| 57 | // string/non-strict event checking. When writing test cases using these |
| 58 | // fixtures, use the |Update*|, |ExpectEventCount|, |VerifyEventCount| functions |
| 59 | // provided by the fixture, and write the test as if event checking is strict. |
| 60 | // |
| 61 | // For |MobileOperatorObserverTest|, only the strict event checking case makes |
| 62 | // sense, so we only instantiate that. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 63 | namespace shill { |
| 64 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 65 | namespace { |
| 66 | |
| 67 | enum EventCheckingPolicy { |
| 68 | kEventCheckingPolicyStrict, |
| 69 | kEventCheckingPolicyNonStrict |
| 70 | }; |
| 71 | |
| 72 | } // namespace |
| 73 | |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 74 | class MockMobileOperatorInfoObserver : public MobileOperatorInfo::Observer { |
| 75 | public: |
| 76 | MockMobileOperatorInfoObserver() {} |
| 77 | virtual ~MockMobileOperatorInfoObserver() {} |
| 78 | |
| 79 | MOCK_METHOD0(OnOperatorChanged, void()); |
| 80 | }; |
| 81 | |
| 82 | class MobileOperatorInfoInitTest : public Test { |
| 83 | public: |
| 84 | MobileOperatorInfoInitTest() |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 85 | : operator_info_(new MobileOperatorInfo(&dispatcher_, "Operator")), |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 86 | operator_info_impl_(operator_info_->impl()) {} |
| 87 | |
Alex Vakulenko | 016fa0e | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 88 | void TearDown() override { |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 89 | for (const auto& tmp_db_path : tmp_db_paths_) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 90 | base::DeleteFile(tmp_db_path, false); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | protected: |
| 95 | void AddDatabase(const unsigned char database_data[], size_t num_elems) { |
| 96 | FilePath tmp_db_path; |
| 97 | CHECK(base::CreateTemporaryFile(&tmp_db_path)); |
| 98 | tmp_db_paths_.push_back(tmp_db_path); |
| 99 | |
| 100 | ofstream tmp_db(tmp_db_path.value(), ofstream::binary); |
| 101 | for (size_t i = 0; i < num_elems; ++i) { |
| 102 | tmp_db << database_data[i]; |
| 103 | } |
| 104 | tmp_db.close(); |
| 105 | operator_info_->AddDatabasePath(tmp_db_path); |
| 106 | } |
| 107 | |
| 108 | void AssertDatabaseEmpty() { |
| 109 | EXPECT_EQ(0, operator_info_impl_->database()->mno_size()); |
| 110 | EXPECT_EQ(0, operator_info_impl_->database()->imvno_size()); |
| 111 | } |
| 112 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 113 | const MobileOperatorDB* GetDatabase() { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 114 | return operator_info_impl_->database(); |
| 115 | } |
| 116 | |
| 117 | EventDispatcher dispatcher_; |
| 118 | vector<FilePath> tmp_db_paths_; |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 119 | std::unique_ptr<MobileOperatorInfo> operator_info_; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 120 | // Owned by |operator_info_| and tied to its life cycle. |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 121 | MobileOperatorInfoImpl* operator_info_impl_; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 122 | |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 123 | private: |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 124 | DISALLOW_COPY_AND_ASSIGN(MobileOperatorInfoInitTest); |
| 125 | }; |
| 126 | |
| 127 | TEST_F(MobileOperatorInfoInitTest, FailedInitNoPath) { |
| 128 | // - Initialize object with no database paths set |
| 129 | // - Verify that initialization fails. |
| 130 | operator_info_->ClearDatabasePaths(); |
| 131 | EXPECT_FALSE(operator_info_->Init()); |
| 132 | AssertDatabaseEmpty(); |
| 133 | } |
| 134 | |
| 135 | TEST_F(MobileOperatorInfoInitTest, FailedInitBadPath) { |
| 136 | // - Initialize object with non-existent path. |
| 137 | // - Verify that initialization fails. |
| 138 | const FilePath database_path("nonexistent.pbf"); |
| 139 | operator_info_->ClearDatabasePaths(); |
| 140 | operator_info_->AddDatabasePath(database_path); |
| 141 | EXPECT_FALSE(operator_info_->Init()); |
| 142 | AssertDatabaseEmpty(); |
| 143 | } |
| 144 | |
| 145 | TEST_F(MobileOperatorInfoInitTest, FailedInitBadDatabase) { |
| 146 | // - Initialize object with malformed database. |
| 147 | // - Verify that initialization fails. |
| 148 | // TODO(pprabhu): It's hard to get a malformed database in binary format. |
| 149 | } |
| 150 | |
| 151 | TEST_F(MobileOperatorInfoInitTest, EmptyDBInit) { |
| 152 | // - Initialize the object with a database file that is empty. |
| 153 | // - Verify that initialization succeeds, and that the database is empty. |
| 154 | operator_info_->ClearDatabasePaths(); |
| 155 | // Can't use arraysize on empty array. |
| 156 | AddDatabase(mobile_operator_db::init_test_empty_db_init, 0); |
| 157 | EXPECT_TRUE(operator_info_->Init()); |
| 158 | AssertDatabaseEmpty(); |
| 159 | } |
| 160 | |
| 161 | TEST_F(MobileOperatorInfoInitTest, SuccessfulInit) { |
| 162 | operator_info_->ClearDatabasePaths(); |
| 163 | AddDatabase(mobile_operator_db::init_test_successful_init, |
| 164 | arraysize(mobile_operator_db::init_test_successful_init)); |
| 165 | EXPECT_TRUE(operator_info_->Init()); |
| 166 | EXPECT_GT(GetDatabase()->mno_size(), 0); |
| 167 | EXPECT_GT(GetDatabase()->imvno_size(), 0); |
| 168 | } |
| 169 | |
| 170 | TEST_F(MobileOperatorInfoInitTest, MultipleDBInit) { |
| 171 | // - Initialize the object with two database files. |
| 172 | // - Verify that intialization succeeds, and both databases are loaded. |
| 173 | operator_info_->ClearDatabasePaths(); |
| 174 | AddDatabase(mobile_operator_db::init_test_multiple_db_init_1, |
| 175 | arraysize(mobile_operator_db::init_test_multiple_db_init_1)); |
| 176 | AddDatabase(mobile_operator_db::init_test_multiple_db_init_2, |
| 177 | arraysize(mobile_operator_db::init_test_multiple_db_init_2)); |
| 178 | operator_info_->Init(); |
| 179 | EXPECT_GT(GetDatabase()->mno_size(), 0); |
| 180 | EXPECT_GT(GetDatabase()->imvno_size(), 0); |
| 181 | } |
| 182 | |
| 183 | TEST_F(MobileOperatorInfoInitTest, InitWithObserver) { |
| 184 | // - Add an Observer. |
| 185 | // - Initialize the object with empty database file. |
| 186 | // - Verify innitialization succeeds. |
| 187 | MockMobileOperatorInfoObserver dumb_observer; |
| 188 | |
| 189 | operator_info_->ClearDatabasePaths(); |
| 190 | // Can't use arraysize with empty array. |
| 191 | AddDatabase(mobile_operator_db::init_test_empty_db_init, 0); |
| 192 | operator_info_->AddObserver(&dumb_observer); |
| 193 | EXPECT_TRUE(operator_info_->Init()); |
| 194 | } |
| 195 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 196 | class MobileOperatorInfoMainTest |
| 197 | : public MobileOperatorInfoInitTest, |
| 198 | public WithParamInterface<EventCheckingPolicy> { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 199 | public: |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 200 | MobileOperatorInfoMainTest() |
| 201 | : MobileOperatorInfoInitTest(), |
| 202 | event_checking_policy_(GetParam()) {} |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 203 | |
| 204 | virtual void SetUp() { |
| 205 | operator_info_->ClearDatabasePaths(); |
| 206 | AddDatabase(mobile_operator_db::main_test, |
| 207 | arraysize(mobile_operator_db::main_test)); |
| 208 | operator_info_->Init(); |
| 209 | operator_info_->AddObserver(&observer_); |
| 210 | } |
| 211 | |
| 212 | protected: |
| 213 | // /////////////////////////////////////////////////////////////////////////// |
| 214 | // Helper functions. |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 215 | void VerifyMNOWithUUID(const string& uuid) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 216 | EXPECT_TRUE(operator_info_->IsMobileNetworkOperatorKnown()); |
| 217 | EXPECT_FALSE(operator_info_->IsMobileVirtualNetworkOperatorKnown()); |
| 218 | EXPECT_EQ(uuid, operator_info_->uuid()); |
| 219 | } |
| 220 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 221 | void VerifyMVNOWithUUID(const string& uuid) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 222 | EXPECT_TRUE(operator_info_->IsMobileNetworkOperatorKnown()); |
| 223 | EXPECT_TRUE(operator_info_->IsMobileVirtualNetworkOperatorKnown()); |
| 224 | EXPECT_EQ(uuid, operator_info_->uuid()); |
| 225 | } |
| 226 | |
| 227 | void VerifyNoMatch() { |
| 228 | EXPECT_FALSE(operator_info_->IsMobileNetworkOperatorKnown()); |
| 229 | EXPECT_FALSE(operator_info_->IsMobileVirtualNetworkOperatorKnown()); |
| 230 | EXPECT_EQ("", operator_info_->uuid()); |
| 231 | } |
| 232 | |
| 233 | void ExpectEventCount(int count) { |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 234 | // In case we're running in the non-strict event checking mode, we only |
| 235 | // expect one overall event to be raised for all the updates. |
| 236 | if (event_checking_policy_ == kEventCheckingPolicyNonStrict) { |
| 237 | count = (count > 0) ? 1 : 0; |
| 238 | } |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 239 | EXPECT_CALL(observer_, OnOperatorChanged()).Times(count); |
| 240 | } |
| 241 | |
| 242 | void VerifyEventCount() { |
| 243 | dispatcher_.DispatchPendingEvents(); |
| 244 | Mock::VerifyAndClearExpectations(&observer_); |
| 245 | } |
| 246 | |
| 247 | void ResetOperatorInfo() { |
| 248 | operator_info_->Reset(); |
| 249 | // Eat up any events caused by |Reset|. |
| 250 | dispatcher_.DispatchPendingEvents(); |
| 251 | VerifyNoMatch(); |
| 252 | } |
| 253 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 254 | // Use these wrappers to send updates to |operator_info_|. These wrappers |
| 255 | // optionally run the dispatcher if we want strict checking of the number of |
| 256 | // events raised. |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 257 | void UpdateMCCMNC(const std::string& mccmnc) { |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 258 | operator_info_->UpdateMCCMNC(mccmnc); |
| 259 | DispatchPendingEventsIfStrict(); |
| 260 | } |
| 261 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 262 | void UpdateSID(const std::string& sid) { |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 263 | operator_info_->UpdateSID(sid); |
| 264 | DispatchPendingEventsIfStrict(); |
| 265 | } |
| 266 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 267 | void UpdateIMSI(const std::string& imsi) { |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 268 | operator_info_->UpdateIMSI(imsi); |
| 269 | DispatchPendingEventsIfStrict(); |
| 270 | } |
| 271 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 272 | void UpdateICCID(const std::string& iccid) { |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 273 | operator_info_->UpdateICCID(iccid); |
| 274 | DispatchPendingEventsIfStrict(); |
| 275 | } |
| 276 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 277 | void UpdateNID(const std::string& nid) { |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 278 | operator_info_->UpdateNID(nid); |
| 279 | DispatchPendingEventsIfStrict(); |
| 280 | } |
| 281 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 282 | void UpdateOperatorName(const std::string& operator_name) { |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 283 | operator_info_->UpdateOperatorName(operator_name); |
| 284 | DispatchPendingEventsIfStrict(); |
| 285 | } |
| 286 | |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 287 | void UpdateOnlinePortal(const std::string& url, |
| 288 | const std::string& method, |
| 289 | const std::string& post_data) { |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 290 | operator_info_->UpdateOnlinePortal(url, method, post_data); |
| 291 | DispatchPendingEventsIfStrict(); |
| 292 | } |
| 293 | |
| 294 | void DispatchPendingEventsIfStrict() { |
| 295 | if (event_checking_policy_ == kEventCheckingPolicyStrict) { |
| 296 | dispatcher_.DispatchPendingEvents(); |
| 297 | } |
| 298 | } |
| 299 | |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 300 | // /////////////////////////////////////////////////////////////////////////// |
| 301 | // Data. |
| 302 | MockMobileOperatorInfoObserver observer_; |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 303 | const EventCheckingPolicy event_checking_policy_; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 304 | |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 305 | private: |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 306 | DISALLOW_COPY_AND_ASSIGN(MobileOperatorInfoMainTest); |
| 307 | }; |
| 308 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 309 | TEST_P(MobileOperatorInfoMainTest, InitialConditions) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 310 | // - Initialize a new object. |
| 311 | // - Verify that all initial values of properties are reasonable. |
| 312 | EXPECT_FALSE(operator_info_->IsMobileNetworkOperatorKnown()); |
| 313 | EXPECT_FALSE(operator_info_->IsMobileVirtualNetworkOperatorKnown()); |
| 314 | EXPECT_TRUE(operator_info_->uuid().empty()); |
| 315 | EXPECT_TRUE(operator_info_->operator_name().empty()); |
| 316 | EXPECT_TRUE(operator_info_->country().empty()); |
| 317 | EXPECT_TRUE(operator_info_->mccmnc().empty()); |
| 318 | EXPECT_TRUE(operator_info_->sid().empty()); |
| 319 | EXPECT_TRUE(operator_info_->nid().empty()); |
| 320 | EXPECT_TRUE(operator_info_->mccmnc_list().empty()); |
| 321 | EXPECT_TRUE(operator_info_->sid_list().empty()); |
| 322 | EXPECT_TRUE(operator_info_->operator_name_list().empty()); |
| 323 | EXPECT_TRUE(operator_info_->apn_list().empty()); |
| 324 | EXPECT_TRUE(operator_info_->olp_list().empty()); |
| 325 | EXPECT_TRUE(operator_info_->activation_code().empty()); |
| 326 | EXPECT_FALSE(operator_info_->requires_roaming()); |
| 327 | } |
| 328 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 329 | TEST_P(MobileOperatorInfoMainTest, MNOByMCCMNC) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 330 | // message: Has an MNO with no MVNO. |
| 331 | // match by: MCCMNC. |
| 332 | // verify: Observer event, uuid. |
| 333 | |
| 334 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 335 | UpdateMCCMNC("101999"); // No match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 336 | VerifyEventCount(); |
| 337 | VerifyNoMatch(); |
| 338 | |
| 339 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 340 | UpdateMCCMNC("101001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 341 | VerifyEventCount(); |
| 342 | VerifyMNOWithUUID("uuid101"); |
| 343 | |
| 344 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 345 | UpdateMCCMNC("101999"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 346 | VerifyEventCount(); |
| 347 | VerifyNoMatch(); |
| 348 | } |
| 349 | |
Prathmesh Prabhu | 53f47a6 | 2014-07-16 14:06:55 -0700 | [diff] [blame] | 350 | TEST_P(MobileOperatorInfoMainTest, MNOByMCCMNCMultipleMCCMNCOptions) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 351 | // message: Has an MNO with no MCCMNC. |
| 352 | // match by: One of the MCCMNCs of the multiple ones in the MNO. |
| 353 | // verify: Observer event, uuid. |
| 354 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 355 | UpdateMCCMNC("102002"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 356 | VerifyEventCount(); |
| 357 | VerifyMNOWithUUID("uuid102"); |
| 358 | } |
| 359 | |
Prathmesh Prabhu | 53f47a6 | 2014-07-16 14:06:55 -0700 | [diff] [blame] | 360 | TEST_P(MobileOperatorInfoMainTest, MNOByMCCMNCMultipleMNOOptions) { |
| 361 | // message: Two messages with the same MCCMNC. |
| 362 | // match by: Both MNOs matched, one is earmarked. |
| 363 | // verify: The earmarked MNO is picked. |
| 364 | ExpectEventCount(1); |
| 365 | UpdateMCCMNC("124001"); |
| 366 | VerifyEventCount(); |
| 367 | VerifyMNOWithUUID("uuid124002"); |
| 368 | } |
| 369 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 370 | TEST_P(MobileOperatorInfoMainTest, MNOByOperatorName) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 371 | // message: Has an MNO with no MVNO. |
| 372 | // match by: OperatorName. |
| 373 | // verify: Observer event, uuid. |
| 374 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 375 | UpdateOperatorName("name103999"); // No match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 376 | VerifyEventCount(); |
| 377 | VerifyNoMatch(); |
| 378 | |
| 379 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 380 | UpdateOperatorName("name103"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 381 | VerifyEventCount(); |
| 382 | VerifyMNOWithUUID("uuid103"); |
| 383 | |
| 384 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 385 | UpdateOperatorName("name103999"); // No match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 386 | VerifyEventCount(); |
| 387 | VerifyNoMatch(); |
| 388 | } |
| 389 | |
Prathmesh Prabhu | 53f47a6 | 2014-07-16 14:06:55 -0700 | [diff] [blame] | 390 | TEST_P(MobileOperatorInfoMainTest, MNOByOperatorNameMultipleMNOOptions) { |
| 391 | // message: Two messages with the same operator name. |
| 392 | // match by: Both MNOs matched, one is earmarked. |
| 393 | // verify: The earmarked MNO is picked. |
| 394 | ExpectEventCount(1); |
| 395 | UpdateOperatorName("name125001"); |
| 396 | VerifyEventCount(); |
| 397 | VerifyMNOWithUUID("uuid125002"); |
| 398 | } |
| 399 | |
Prathmesh Prabhu | 145a5da | 2014-07-16 17:00:56 -0700 | [diff] [blame] | 400 | TEST_P(MobileOperatorInfoMainTest, MNOByOperatorNameAggressiveMatch) { |
| 401 | // These network operators match by name but only after normalizing the names. |
| 402 | // Both the name from the database and the name provided to |
| 403 | // |UpdateOperatoName| must be normalized for this test to pass. |
| 404 | ExpectEventCount(1); |
| 405 | UpdateOperatorName("name126001 casedoesnotmatch"); |
| 406 | VerifyEventCount(); |
| 407 | VerifyMNOWithUUID("uuid126001"); |
| 408 | |
| 409 | ResetOperatorInfo(); |
| 410 | ExpectEventCount(1); |
| 411 | UpdateOperatorName("name126002 CaseStillDoesNotMatch"); |
| 412 | VerifyEventCount(); |
| 413 | VerifyMNOWithUUID("uuid126002"); |
| 414 | |
| 415 | ResetOperatorInfo(); |
| 416 | ExpectEventCount(1); |
| 417 | UpdateOperatorName("name126003GiveMeMoreSpace"); |
| 418 | VerifyEventCount(); |
| 419 | VerifyMNOWithUUID("uuid126003"); |
| 420 | |
| 421 | ResetOperatorInfo(); |
| 422 | ExpectEventCount(1); |
| 423 | UpdateOperatorName("name126004 Too Much Air Here"); |
| 424 | VerifyEventCount(); |
| 425 | VerifyMNOWithUUID("uuid126004"); |
| 426 | |
| 427 | ResetOperatorInfo(); |
| 428 | ExpectEventCount(1); |
| 429 | UpdateOperatorName("näméwithNon-Äσ¢ii"); |
| 430 | VerifyEventCount(); |
| 431 | VerifyMNOWithUUID("uuid126005"); |
| 432 | } |
| 433 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 434 | TEST_P(MobileOperatorInfoMainTest, MNOByOperatorNameWithLang) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 435 | // message: Has an MNO with no MVNO. |
| 436 | // match by: OperatorName. |
| 437 | // verify: Observer event, fields. |
| 438 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 439 | UpdateOperatorName("name105"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 440 | VerifyEventCount(); |
| 441 | VerifyMNOWithUUID("uuid105"); |
| 442 | } |
| 443 | |
Prathmesh Prabhu | 53f47a6 | 2014-07-16 14:06:55 -0700 | [diff] [blame] | 444 | TEST_P(MobileOperatorInfoMainTest, MNOByOperatorNameMultipleNameOptions) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 445 | // message: Has an MNO with no MVNO. |
| 446 | // match by: OperatorName, one of the multiple present in the MNO. |
| 447 | // verify: Observer event, fields. |
| 448 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 449 | UpdateOperatorName("name104002"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 450 | VerifyEventCount(); |
| 451 | VerifyMNOWithUUID("uuid104"); |
| 452 | } |
| 453 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 454 | TEST_P(MobileOperatorInfoMainTest, MNOByMCCMNCAndOperatorName) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 455 | // message: Has MNOs with no MVNO. |
Prathmesh Prabhu | 53f47a6 | 2014-07-16 14:06:55 -0700 | [diff] [blame] | 456 | // match by: MCCMNC finds two candidates (first one is chosen), Name narrows |
| 457 | // down to one. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 458 | // verify: Observer event, fields. |
| 459 | // This is merely a MCCMNC update. |
Prathmesh Prabhu | 53f47a6 | 2014-07-16 14:06:55 -0700 | [diff] [blame] | 460 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 461 | UpdateMCCMNC("106001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 462 | VerifyEventCount(); |
Prathmesh Prabhu | 53f47a6 | 2014-07-16 14:06:55 -0700 | [diff] [blame] | 463 | VerifyMNOWithUUID("uuid106001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 464 | |
| 465 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 466 | UpdateOperatorName("name106002"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 467 | VerifyEventCount(); |
| 468 | VerifyMNOWithUUID("uuid106002"); |
| 469 | |
| 470 | ResetOperatorInfo(); |
| 471 | // Try updates in reverse order. |
| 472 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 473 | UpdateOperatorName("name106001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 474 | VerifyEventCount(); |
| 475 | VerifyMNOWithUUID("uuid106001"); |
| 476 | } |
| 477 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 478 | TEST_P(MobileOperatorInfoMainTest, MNOByOperatorNameAndMCCMNC) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 479 | // message: Has MNOs with no MVNO. |
Prathmesh Prabhu | 53f47a6 | 2014-07-16 14:06:55 -0700 | [diff] [blame] | 480 | // match by: OperatorName finds two (first one is chosen), MCCMNC narrows down |
| 481 | // to one. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 482 | // verify: Observer event, fields. |
| 483 | // This is merely an OperatorName update. |
Prathmesh Prabhu | 53f47a6 | 2014-07-16 14:06:55 -0700 | [diff] [blame] | 484 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 485 | UpdateOperatorName("name107"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 486 | VerifyEventCount(); |
Prathmesh Prabhu | 53f47a6 | 2014-07-16 14:06:55 -0700 | [diff] [blame] | 487 | VerifyMNOWithUUID("uuid107001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 488 | |
| 489 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 490 | UpdateMCCMNC("107002"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 491 | VerifyEventCount(); |
| 492 | VerifyMNOWithUUID("uuid107002"); |
| 493 | |
| 494 | ResetOperatorInfo(); |
| 495 | // Try updates in reverse order. |
| 496 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 497 | UpdateMCCMNC("107001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 498 | VerifyEventCount(); |
| 499 | VerifyMNOWithUUID("uuid107001"); |
| 500 | } |
| 501 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 502 | TEST_P(MobileOperatorInfoMainTest, MNOByMCCMNCOverridesOperatorName) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 503 | // message: Has MNOs with no MVNO. |
| 504 | // match by: First MCCMNC finds one. Then, OperatorName matches another. |
| 505 | // verify: MCCMNC match prevails. No change on OperatorName update. |
| 506 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 507 | UpdateMCCMNC("108001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 508 | VerifyEventCount(); |
| 509 | VerifyMNOWithUUID("uuid108001"); |
| 510 | |
| 511 | // An event is sent for the updated OperatorName. |
| 512 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 513 | UpdateOperatorName("name108002"); // Does not match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 514 | VerifyEventCount(); |
| 515 | VerifyMNOWithUUID("uuid108001"); |
Prathmesh Prabhu | 82f8b02 | 2014-07-28 14:55:37 -0700 | [diff] [blame] | 516 | // OperatorName from the database is given preference over the user supplied |
| 517 | // one. |
| 518 | EXPECT_EQ("name108001", operator_info_->operator_name()); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 519 | |
| 520 | ResetOperatorInfo(); |
| 521 | // message: Same as above. |
| 522 | // match by: First OperatorName finds one, then MCCMNC overrides it. |
| 523 | // verify: Two events, MCCMNC one overriding the OperatorName one. |
| 524 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 525 | UpdateOperatorName("name108001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 526 | VerifyEventCount(); |
| 527 | VerifyMNOWithUUID("uuid108001"); |
| 528 | |
| 529 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 530 | UpdateMCCMNC("108002"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 531 | VerifyEventCount(); |
| 532 | VerifyMNOWithUUID("uuid108002"); |
Prathmesh Prabhu | 82f8b02 | 2014-07-28 14:55:37 -0700 | [diff] [blame] | 533 | EXPECT_EQ("name108002", operator_info_->operator_name()); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 534 | |
| 535 | // message: Same as above. |
| 536 | // match by: First a *wrong* MCCMNC update, followed by the correct Name |
| 537 | // update. |
| 538 | // verify: No MNO, since MCCMNC is given precedence. |
| 539 | ResetOperatorInfo(); |
| 540 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 541 | UpdateMCCMNC("108999"); // Does not match. |
| 542 | UpdateOperatorName("name108001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 543 | VerifyEventCount(); |
| 544 | VerifyNoMatch(); |
| 545 | } |
| 546 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 547 | TEST_P(MobileOperatorInfoMainTest, MNOByIMSI) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 548 | // message: Has MNO with no MVNO. |
| 549 | // match by: MCCMNC part of IMSI of length 5 / 6. |
| 550 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 551 | UpdateIMSI("109"); // Too short. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 552 | VerifyEventCount(); |
| 553 | VerifyNoMatch(); |
| 554 | |
| 555 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 556 | UpdateIMSI("109995432154321"); // No match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 557 | VerifyEventCount(); |
| 558 | VerifyNoMatch(); |
| 559 | |
| 560 | ResetOperatorInfo(); |
| 561 | // Short MCCMNC match. |
| 562 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 563 | UpdateIMSI("109015432154321"); // First 5 digits match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 564 | VerifyEventCount(); |
| 565 | VerifyMNOWithUUID("uuid10901"); |
| 566 | |
| 567 | ResetOperatorInfo(); |
| 568 | // Long MCCMNC match. |
| 569 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 570 | UpdateIMSI("10900215432154321"); // First 6 digits match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 571 | VerifyEventCount(); |
| 572 | VerifyMNOWithUUID("uuid109002"); |
| 573 | } |
| 574 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 575 | TEST_P(MobileOperatorInfoMainTest, MNOByMCCMNCOverridesIMSI) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 576 | // message: Has MNOs with no MVNO. |
| 577 | // match by: One matches MCCMNC, then one matches a different MCCMNC substring |
| 578 | // of IMSI |
| 579 | // verify: Observer event for the first match, all fields. Second Update |
| 580 | // ignored. |
| 581 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 582 | UpdateMCCMNC("110001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 583 | VerifyEventCount(); |
| 584 | VerifyMNOWithUUID("uuid110001"); |
| 585 | |
| 586 | // MNO remains unchanged on a mismatched IMSI update. |
| 587 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 588 | UpdateIMSI("1100025432154321"); // First 6 digits match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 589 | VerifyEventCount(); |
| 590 | VerifyMNOWithUUID("uuid110001"); |
| 591 | |
| 592 | // MNO remains uncnaged on an invalid IMSI update. |
| 593 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 594 | UpdateIMSI("1100035432154321"); // Prefix does not match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 595 | VerifyEventCount(); |
| 596 | VerifyMNOWithUUID("uuid110001"); |
| 597 | |
| 598 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 599 | UpdateIMSI("110"); // Too small. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 600 | VerifyEventCount(); |
| 601 | VerifyMNOWithUUID("uuid110001"); |
| 602 | |
| 603 | ResetOperatorInfo(); |
| 604 | // Same as above, but this time, match with IMSI, followed by a contradictory |
| 605 | // MCCMNC update. The second update should override the first one. |
| 606 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 607 | UpdateIMSI("1100025432154321"); // First 6 digits match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 608 | VerifyEventCount(); |
| 609 | VerifyMNOWithUUID("uuid110002"); |
| 610 | |
| 611 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 612 | UpdateMCCMNC("110001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 613 | VerifyEventCount(); |
| 614 | VerifyMNOWithUUID("uuid110001"); |
| 615 | } |
| 616 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 617 | TEST_P(MobileOperatorInfoMainTest, MNOUchangedBySecondaryUpdates) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 618 | // This test verifies that only some updates affect the MNO. |
| 619 | // message: Has MNOs with no MVNO. |
| 620 | // match by: First matches the MCCMNC. Later, MNOs with a different MCCMNC |
| 621 | // matchs the given SID, NID, ICCID. |
| 622 | // verify: Only one Observer event, on the first MCCMNC match. |
| 623 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 624 | UpdateMCCMNC("111001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 625 | VerifyEventCount(); |
| 626 | VerifyMNOWithUUID("uuid111001"); |
| 627 | |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 628 | ExpectEventCount(1); // NID change event. |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 629 | UpdateNID("111202"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 630 | VerifyEventCount(); |
| 631 | VerifyMNOWithUUID("uuid111001"); |
| 632 | } |
| 633 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 634 | TEST_P(MobileOperatorInfoMainTest, MVNODefaultMatch) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 635 | // message: MNO with one MVNO (no filter). |
| 636 | // match by: MNO matches by MCCMNC. |
| 637 | // verify: Observer event for MVNO match. Uuid match the MVNO. |
| 638 | // second update: ICCID. |
| 639 | // verify: No observer event, match remains unchanged. |
| 640 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 641 | UpdateMCCMNC("112001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 642 | VerifyEventCount(); |
| 643 | VerifyMVNOWithUUID("uuid112002"); |
| 644 | |
| 645 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 646 | UpdateICCID("112002"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 647 | VerifyEventCount(); |
| 648 | VerifyMVNOWithUUID("uuid112002"); |
| 649 | } |
| 650 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 651 | TEST_P(MobileOperatorInfoMainTest, MVNONameMatch) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 652 | // message: MNO with one MVNO (name filter). |
| 653 | // match by: MNO matches by MCCMNC, |
| 654 | // MVNO fails to match by fist name update, |
| 655 | // then MVNO matches by name. |
| 656 | // verify: Two Observer events: MNO followed by MVNO. |
| 657 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 658 | UpdateMCCMNC("113001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 659 | VerifyEventCount(); |
| 660 | VerifyMNOWithUUID("uuid113001"); |
| 661 | |
| 662 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 663 | UpdateOperatorName("name113999"); // No match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 664 | VerifyEventCount(); |
| 665 | VerifyMNOWithUUID("uuid113001"); |
Prathmesh Prabhu | 82f8b02 | 2014-07-28 14:55:37 -0700 | [diff] [blame] | 666 | // Name from the database is given preference. |
| 667 | EXPECT_EQ("name113001", operator_info_->operator_name()); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 668 | |
| 669 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 670 | UpdateOperatorName("name113002"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 671 | VerifyEventCount(); |
| 672 | VerifyMVNOWithUUID("uuid113002"); |
| 673 | EXPECT_EQ("name113002", operator_info_->operator_name()); |
| 674 | } |
| 675 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 676 | TEST_P(MobileOperatorInfoMainTest, MVNONameMalformedRegexMatch) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 677 | // message: MNO with one MVNO (name filter with a malformed regex). |
| 678 | // match by: MNO matches by MCCMNC. |
| 679 | // MVNO does not match |
| 680 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 681 | UpdateMCCMNC("114001"); |
| 682 | UpdateOperatorName("name["); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 683 | VerifyEventCount(); |
| 684 | VerifyMNOWithUUID("uuid114001"); |
| 685 | } |
| 686 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 687 | TEST_P(MobileOperatorInfoMainTest, MVNONameSubexpressionRegexMatch) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 688 | // message: MNO with one MVNO (name filter with simple regex). |
| 689 | // match by: MNO matches by MCCMNC. |
| 690 | // MVNO does not match with a name whose subexpression matches the |
| 691 | // regex. |
| 692 | ExpectEventCount(2); // One event for just the name update. |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 693 | UpdateMCCMNC("115001"); |
| 694 | UpdateOperatorName("name115_ExtraCrud"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 695 | VerifyEventCount(); |
| 696 | VerifyMNOWithUUID("uuid115001"); |
| 697 | |
| 698 | ResetOperatorInfo(); |
| 699 | ExpectEventCount(2); // One event for just the name update. |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 700 | UpdateMCCMNC("115001"); |
| 701 | UpdateOperatorName("ExtraCrud_name115"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 702 | VerifyEventCount(); |
| 703 | VerifyMNOWithUUID("uuid115001"); |
| 704 | |
| 705 | ResetOperatorInfo(); |
| 706 | ExpectEventCount(2); // One event for just the name update. |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 707 | UpdateMCCMNC("115001"); |
| 708 | UpdateOperatorName("ExtraCrud_name115_ExtraCrud"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 709 | VerifyEventCount(); |
| 710 | VerifyMNOWithUUID("uuid115001"); |
| 711 | |
| 712 | ResetOperatorInfo(); |
| 713 | ExpectEventCount(2); // One event for just the name update. |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 714 | UpdateMCCMNC("115001"); |
| 715 | UpdateOperatorName("name_ExtraCrud_115"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 716 | VerifyEventCount(); |
| 717 | VerifyMNOWithUUID("uuid115001"); |
| 718 | |
| 719 | ResetOperatorInfo(); |
| 720 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 721 | UpdateMCCMNC("115001"); |
| 722 | UpdateOperatorName("name115"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 723 | VerifyEventCount(); |
| 724 | VerifyMVNOWithUUID("uuid115002"); |
| 725 | } |
| 726 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 727 | TEST_P(MobileOperatorInfoMainTest, MVNONameRegexMatch) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 728 | // message: MNO with one MVNO (name filter with non-trivial regex). |
| 729 | // match by: MNO matches by MCCMNC. |
| 730 | // MVNO fails to match several times with different strings. |
| 731 | // MVNO matches several times with different values. |
| 732 | |
| 733 | // Make sure we're not taking the regex literally! |
| 734 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 735 | UpdateMCCMNC("116001"); |
| 736 | UpdateOperatorName("name[a-zA-Z_]*116[0-9]{0,3}"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 737 | VerifyEventCount(); |
| 738 | VerifyMNOWithUUID("uuid116001"); |
| 739 | |
| 740 | ResetOperatorInfo(); |
| 741 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 742 | UpdateMCCMNC("116001"); |
| 743 | UpdateOperatorName("name[a-zA-Z_]116[0-9]"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 744 | VerifyEventCount(); |
| 745 | VerifyMNOWithUUID("uuid116001"); |
| 746 | |
| 747 | ResetOperatorInfo(); |
| 748 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 749 | UpdateMCCMNC("116001"); |
| 750 | UpdateOperatorName("nameb*1167"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 751 | VerifyEventCount(); |
| 752 | VerifyMNOWithUUID("uuid116001"); |
| 753 | |
| 754 | // Success! |
| 755 | ResetOperatorInfo(); |
| 756 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 757 | UpdateMCCMNC("116001"); |
| 758 | UpdateOperatorName("name116"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 759 | VerifyEventCount(); |
| 760 | VerifyMVNOWithUUID("uuid116002"); |
| 761 | |
| 762 | ResetOperatorInfo(); |
| 763 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 764 | UpdateMCCMNC("116001"); |
| 765 | UpdateOperatorName("nameSomeWord116"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 766 | VerifyEventCount(); |
| 767 | VerifyMVNOWithUUID("uuid116002"); |
| 768 | |
| 769 | ResetOperatorInfo(); |
| 770 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 771 | UpdateMCCMNC("116001"); |
| 772 | UpdateOperatorName("name116567"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 773 | VerifyEventCount(); |
| 774 | VerifyMVNOWithUUID("uuid116002"); |
| 775 | } |
| 776 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 777 | TEST_P(MobileOperatorInfoMainTest, MVNONameMatchMultipleFilters) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 778 | // message: MNO with one MVNO with two name filters. |
| 779 | // match by: MNO matches by MCCMNC. |
| 780 | // MVNO first fails on the second filter alone. |
| 781 | // MVNO fails on the first filter alone. |
| 782 | // MVNO matches on both filters. |
| 783 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 784 | UpdateMCCMNC("117001"); |
| 785 | UpdateOperatorName("nameA_crud"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 786 | VerifyEventCount(); |
| 787 | VerifyMNOWithUUID("uuid117001"); |
| 788 | |
| 789 | ResetOperatorInfo(); |
| 790 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 791 | UpdateMCCMNC("117001"); |
| 792 | UpdateOperatorName("crud_nameB"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 793 | VerifyEventCount(); |
| 794 | VerifyMNOWithUUID("uuid117001"); |
| 795 | |
| 796 | ResetOperatorInfo(); |
| 797 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 798 | UpdateMCCMNC("117001"); |
| 799 | UpdateOperatorName("crud_crud"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 800 | VerifyEventCount(); |
| 801 | VerifyMNOWithUUID("uuid117001"); |
| 802 | |
| 803 | ResetOperatorInfo(); |
| 804 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 805 | UpdateMCCMNC("117001"); |
| 806 | UpdateOperatorName("nameA_nameB"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 807 | VerifyEventCount(); |
| 808 | VerifyMVNOWithUUID("uuid117002"); |
| 809 | } |
| 810 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 811 | TEST_P(MobileOperatorInfoMainTest, MVNOIMSIMatch) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 812 | // message: MNO with one MVNO (imsi filter). |
| 813 | // match by: MNO matches by MCCMNC, |
| 814 | // MVNO fails to match by fist imsi update, |
| 815 | // then MVNO matches by imsi. |
| 816 | // verify: Two Observer events: MNO followed by MVNO. |
| 817 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 818 | UpdateMCCMNC("118001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 819 | VerifyEventCount(); |
| 820 | VerifyMNOWithUUID("uuid118001"); |
| 821 | |
| 822 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 823 | UpdateIMSI("1180011234512345"); // No match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 824 | VerifyEventCount(); |
| 825 | VerifyMNOWithUUID("uuid118001"); |
| 826 | |
| 827 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 828 | UpdateIMSI("1180015432154321"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 829 | VerifyEventCount(); |
| 830 | VerifyMVNOWithUUID("uuid118002"); |
| 831 | } |
| 832 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 833 | TEST_P(MobileOperatorInfoMainTest, MVNOICCIDMatch) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 834 | // message: MNO with one MVNO (iccid filter). |
| 835 | // match by: MNO matches by MCCMNC, |
| 836 | // MVNO fails to match by fist iccid update, |
| 837 | // then MVNO matches by iccid. |
| 838 | // verify: Two Observer events: MNO followed by MVNO. |
| 839 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 840 | UpdateMCCMNC("119001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 841 | VerifyEventCount(); |
| 842 | VerifyMNOWithUUID("uuid119001"); |
| 843 | |
| 844 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 845 | UpdateICCID("119987654321"); // No match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 846 | VerifyEventCount(); |
| 847 | VerifyMNOWithUUID("uuid119001"); |
| 848 | |
| 849 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 850 | UpdateICCID("119123456789"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 851 | VerifyEventCount(); |
| 852 | VerifyMVNOWithUUID("uuid119002"); |
| 853 | } |
| 854 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 855 | TEST_P(MobileOperatorInfoMainTest, MVNOSIDMatch) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 856 | // message: MNO with one MVNO (sid filter). |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 857 | // match by: MNO matches by SID, |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 858 | // MVNO fails to match by fist sid update, |
| 859 | // then MVNO matches by sid. |
| 860 | // verify: Two Observer events: MNO followed by MVNO. |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 861 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 862 | UpdateSID("120999"); // No match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 863 | VerifyEventCount(); |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 864 | VerifyNoMatch(); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 865 | |
| 866 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 867 | UpdateSID("120001"); // Only MNO matches. |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 868 | VerifyEventCount(); |
| 869 | VerifyMNOWithUUID("uuid120001"); |
| 870 | EXPECT_EQ("120001", operator_info_->sid()); |
| 871 | |
| 872 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 873 | UpdateSID("120002"); // MVNO matches as well. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 874 | VerifyEventCount(); |
| 875 | VerifyMVNOWithUUID("uuid120002"); |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 876 | EXPECT_EQ("120002", operator_info_->sid()); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 879 | TEST_P(MobileOperatorInfoMainTest, MVNOAllMatch) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 880 | // message: MNO with following MVNOS: |
| 881 | // - one with no filter. |
| 882 | // - one with name filter. |
| 883 | // - one with imsi filter. |
| 884 | // - one with iccid filter. |
| 885 | // - one with name and iccid filter. |
| 886 | // verify: |
| 887 | // - initial MCCMNC matches the default MVNO directly (not MNO) |
| 888 | // - match each of the MVNOs in turn. |
| 889 | // - give super set information that does not match any MVNO correctly, |
| 890 | // verify that the MNO matches. |
| 891 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 892 | UpdateMCCMNC("121001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 893 | VerifyEventCount(); |
| 894 | VerifyMNOWithUUID("uuid121001"); |
| 895 | |
| 896 | ResetOperatorInfo(); |
| 897 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 898 | UpdateMCCMNC("121001"); |
| 899 | UpdateOperatorName("name121003"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 900 | VerifyEventCount(); |
| 901 | VerifyMVNOWithUUID("uuid121003"); |
| 902 | |
| 903 | ResetOperatorInfo(); |
| 904 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 905 | UpdateMCCMNC("121001"); |
| 906 | UpdateIMSI("1210045432154321"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 907 | VerifyEventCount(); |
| 908 | VerifyMVNOWithUUID("uuid121004"); |
| 909 | |
| 910 | ResetOperatorInfo(); |
| 911 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 912 | UpdateMCCMNC("121001"); |
| 913 | UpdateICCID("121005123456789"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 914 | VerifyEventCount(); |
| 915 | VerifyMVNOWithUUID("uuid121005"); |
| 916 | |
| 917 | ResetOperatorInfo(); |
| 918 | ExpectEventCount(3); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 919 | UpdateMCCMNC("121001"); |
| 920 | UpdateOperatorName("name121006"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 921 | VerifyMNOWithUUID("uuid121001"); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 922 | UpdateICCID("121006123456789"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 923 | VerifyEventCount(); |
| 924 | VerifyMVNOWithUUID("uuid121006"); |
| 925 | } |
| 926 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 927 | TEST_P(MobileOperatorInfoMainTest, MVNOMatchAndMismatch) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 928 | // message: MNO with one MVNO with name filter. |
| 929 | // match by: MNO matches by MCCMNC |
| 930 | // MVNO matches by name. |
| 931 | // Second name update causes the MVNO to not match again. |
| 932 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 933 | UpdateMCCMNC("113001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 934 | VerifyEventCount(); |
| 935 | VerifyMNOWithUUID("uuid113001"); |
| 936 | |
| 937 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 938 | UpdateOperatorName("name113002"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 939 | VerifyEventCount(); |
| 940 | VerifyMVNOWithUUID("uuid113002"); |
| 941 | EXPECT_EQ("name113002", operator_info_->operator_name()); |
| 942 | |
| 943 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 944 | UpdateOperatorName("name113999"); // No match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 945 | VerifyEventCount(); |
| 946 | VerifyMNOWithUUID("uuid113001"); |
Prathmesh Prabhu | 82f8b02 | 2014-07-28 14:55:37 -0700 | [diff] [blame] | 947 | // Name from database is given preference. |
| 948 | EXPECT_EQ("name113001", operator_info_->operator_name()); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 951 | TEST_P(MobileOperatorInfoMainTest, MVNOMatchAndReset) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 952 | // message: MVNO with name filter. |
| 953 | // verify; |
| 954 | // - match MVNO by name. |
| 955 | // - Reset object, verify Observer event, and not match. |
| 956 | // - match MVNO by name again. |
| 957 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 958 | UpdateMCCMNC("113001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 959 | VerifyEventCount(); |
| 960 | ExpectEventCount(1); |
| 961 | VerifyMNOWithUUID("uuid113001"); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 962 | UpdateOperatorName("name113002"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 963 | VerifyEventCount(); |
| 964 | VerifyMVNOWithUUID("uuid113002"); |
| 965 | EXPECT_EQ("name113002", operator_info_->operator_name()); |
| 966 | |
| 967 | ExpectEventCount(1); |
| 968 | operator_info_->Reset(); |
| 969 | VerifyEventCount(); |
| 970 | VerifyNoMatch(); |
| 971 | |
| 972 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 973 | UpdateMCCMNC("113001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 974 | VerifyEventCount(); |
| 975 | VerifyMNOWithUUID("uuid113001"); |
| 976 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 977 | UpdateOperatorName("name113002"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 978 | VerifyEventCount(); |
| 979 | VerifyMVNOWithUUID("uuid113002"); |
| 980 | EXPECT_EQ("name113002", operator_info_->operator_name()); |
| 981 | } |
| 982 | |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 983 | // Here, we rely on our knowledge about the implementation: The SID and MCCMNC |
| 984 | // updates follow the same code paths, and so we can get away with not testing |
| 985 | // all the scenarios we test above for MCCMNC. Instead, we only do basic testing |
| 986 | // to make sure that SID upates operator as MCCMNC updates do. |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 987 | TEST_P(MobileOperatorInfoMainTest, MNOBySID) { |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 988 | // message: Has an MNO with no MVNO. |
| 989 | // match by: SID. |
| 990 | // verify: Observer event, uuid. |
| 991 | |
| 992 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 993 | UpdateSID("1229"); // No match. |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 994 | VerifyEventCount(); |
| 995 | VerifyNoMatch(); |
| 996 | |
| 997 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 998 | UpdateSID("1221"); |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 999 | VerifyEventCount(); |
| 1000 | VerifyMNOWithUUID("uuid1221"); |
| 1001 | |
| 1002 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1003 | UpdateSID("1229"); // No Match. |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 1004 | VerifyEventCount(); |
| 1005 | VerifyNoMatch(); |
| 1006 | } |
| 1007 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1008 | TEST_P(MobileOperatorInfoMainTest, MNOByMCCMNCAndSID) { |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 1009 | // message: Has an MNO with no MVNO. |
| 1010 | // match by: SID / MCCMNC alternately. |
| 1011 | // verify: Observer event, uuid. |
| 1012 | |
| 1013 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1014 | UpdateMCCMNC("123999"); // NO match. |
| 1015 | UpdateSID("1239"); // No match. |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 1016 | VerifyEventCount(); |
| 1017 | VerifyNoMatch(); |
| 1018 | |
| 1019 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1020 | UpdateMCCMNC("123001"); |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 1021 | VerifyEventCount(); |
| 1022 | VerifyMNOWithUUID("uuid123001"); |
| 1023 | |
| 1024 | ExpectEventCount(1); |
| 1025 | operator_info_->Reset(); |
| 1026 | VerifyEventCount(); |
| 1027 | VerifyNoMatch(); |
| 1028 | |
| 1029 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1030 | UpdateSID("1232"); |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 1031 | VerifyEventCount(); |
| 1032 | VerifyMNOWithUUID("uuid1232"); |
| 1033 | |
| 1034 | ExpectEventCount(1); |
| 1035 | operator_info_->Reset(); |
| 1036 | VerifyEventCount(); |
| 1037 | VerifyNoMatch(); |
| 1038 | |
| 1039 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1040 | UpdateMCCMNC("123001"); |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 1041 | VerifyEventCount(); |
| 1042 | VerifyMNOWithUUID("uuid123001"); |
| 1043 | } |
| 1044 | |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1045 | class MobileOperatorInfoDataTest : public MobileOperatorInfoMainTest { |
| 1046 | public: |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 1047 | MobileOperatorInfoDataTest() : MobileOperatorInfoMainTest() {} |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1048 | |
| 1049 | // Same as MobileOperatorInfoMainTest, except that the database used is |
| 1050 | // different. |
| 1051 | virtual void SetUp() { |
| 1052 | operator_info_->ClearDatabasePaths(); |
| 1053 | AddDatabase(mobile_operator_db::data_test, |
| 1054 | arraysize(mobile_operator_db::data_test)); |
| 1055 | operator_info_->Init(); |
| 1056 | operator_info_->AddObserver(&observer_); |
| 1057 | } |
| 1058 | |
| 1059 | protected: |
| 1060 | // This is a function that does a best effort verification of the information |
| 1061 | // that is obtained from the database by the MobileOperatorInfo object against |
| 1062 | // expectations stored in the form of data members in this class. |
| 1063 | // This is not a full proof check. In particular: |
| 1064 | // - It is unspecified in some case which of the values from a list is |
| 1065 | // exposed as a property. For example, at best, we can check that |sid| is |
| 1066 | // non-empty. |
| 1067 | // - It is not robust to "" as property values at times. |
| 1068 | void VerifyDatabaseData() { |
| 1069 | EXPECT_EQ(country_, operator_info_->country()); |
| 1070 | EXPECT_EQ(requires_roaming_, operator_info_->requires_roaming()); |
| 1071 | EXPECT_EQ(activation_code_, operator_info_->activation_code()); |
| 1072 | |
| 1073 | EXPECT_EQ(mccmnc_list_.size(), operator_info_->mccmnc_list().size()); |
| 1074 | set<string> mccmnc_set(operator_info_->mccmnc_list().begin(), |
| 1075 | operator_info_->mccmnc_list().end()); |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1076 | for (const auto& mccmnc : mccmnc_list_) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1077 | EXPECT_TRUE(mccmnc_set.find(mccmnc) != mccmnc_set.end()); |
| 1078 | } |
| 1079 | if (mccmnc_list_.size() > 0) { |
| 1080 | // It is not specified which entry will be chosen, but mccmnc() must be |
| 1081 | // non empty. |
| 1082 | EXPECT_FALSE(operator_info_->mccmnc().empty()); |
| 1083 | } |
| 1084 | |
| 1085 | VerifyNameListsMatch(operator_name_list_, |
| 1086 | operator_info_->operator_name_list()); |
| 1087 | |
| 1088 | // This comparison breaks if two apns have the same |apn| field. |
| 1089 | EXPECT_EQ(apn_list_.size(), operator_info_->apn_list().size()); |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1090 | map<string, const MobileOperatorInfo::MobileAPN*> mobile_apns; |
| 1091 | for (const auto& apn_node : operator_info_->apn_list()) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1092 | mobile_apns[apn_node->apn] = apn_node; |
| 1093 | } |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1094 | for (const auto& apn_lhs : apn_list_) { |
Prathmesh Prabhu | f90cf1a | 2014-04-15 16:51:19 -0700 | [diff] [blame] | 1095 | ASSERT_TRUE(mobile_apns.find(apn_lhs->apn) != mobile_apns.end()); |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1096 | const auto& apn_rhs = mobile_apns[apn_lhs->apn]; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1097 | // Only comparing apn, name, username, password. |
| 1098 | EXPECT_EQ(apn_lhs->apn, apn_rhs->apn); |
| 1099 | EXPECT_EQ(apn_lhs->username, apn_rhs->username); |
| 1100 | EXPECT_EQ(apn_lhs->password, apn_rhs->password); |
| 1101 | VerifyNameListsMatch(apn_lhs->operator_name_list, |
| 1102 | apn_rhs->operator_name_list); |
| 1103 | } |
| 1104 | |
| 1105 | EXPECT_EQ(olp_list_.size(), operator_info_->olp_list().size()); |
| 1106 | // This comparison breaks if two OLPs have the same |url|. |
| 1107 | map<string, MobileOperatorInfo::OnlinePortal> olps; |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1108 | for (const auto& olp : operator_info_->olp_list()) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1109 | olps[olp.url] = olp; |
| 1110 | } |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1111 | for (const auto& olp : olp_list_) { |
Prathmesh Prabhu | f90cf1a | 2014-04-15 16:51:19 -0700 | [diff] [blame] | 1112 | ASSERT_TRUE(olps.find(olp.url) != olps.end()); |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1113 | const auto& olp_rhs = olps[olp.url]; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1114 | EXPECT_EQ(olp.method, olp_rhs.method); |
| 1115 | EXPECT_EQ(olp.post_data, olp_rhs.post_data); |
| 1116 | } |
| 1117 | |
| 1118 | EXPECT_EQ(sid_list_.size(), operator_info_->sid_list().size()); |
| 1119 | set<string> sid_set(operator_info_->sid_list().begin(), |
| 1120 | operator_info_->sid_list().end()); |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1121 | for (const auto& sid : sid_list_) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1122 | EXPECT_TRUE(sid_set.find(sid) != sid_set.end()); |
| 1123 | } |
| 1124 | if (sid_list_.size() > 0) { |
| 1125 | // It is not specified which entry will be chosen, but |sid()| must be |
| 1126 | // non-empty. |
| 1127 | EXPECT_FALSE(operator_info_->sid().empty()); |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | // This function does some extra checks for the user data that can not be done |
| 1132 | // when data is obtained from the database. |
| 1133 | void VerifyUserData() { |
| 1134 | EXPECT_EQ(sid_, operator_info_->sid()); |
| 1135 | } |
| 1136 | |
| 1137 | void VerifyNameListsMatch( |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1138 | const vector<MobileOperatorInfo::LocalizedName>& operator_name_list_lhs, |
| 1139 | const vector<MobileOperatorInfo::LocalizedName>& operator_name_list_rhs) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1140 | // This comparison breaks if two localized names have the same |name|. |
| 1141 | map<string, MobileOperatorInfo::LocalizedName> localized_names; |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1142 | for (const auto& localized_name : operator_name_list_rhs) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1143 | localized_names[localized_name.name] = localized_name; |
| 1144 | } |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1145 | for (const auto& localized_name : operator_name_list_lhs) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1146 | EXPECT_TRUE(localized_names.find(localized_name.name) != |
| 1147 | localized_names.end()); |
| 1148 | EXPECT_EQ(localized_name.language, |
| 1149 | localized_names[localized_name.name].language); |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | // Use this function to pre-popluate all the data members of this object with |
| 1154 | // values matching the MNO for the database in |data_test.prototxt|. |
| 1155 | void PopulateMNOData() { |
| 1156 | country_ = "us"; |
| 1157 | requires_roaming_ = true; |
| 1158 | activation_code_ = "open sesame"; |
| 1159 | |
| 1160 | mccmnc_list_.clear(); |
| 1161 | mccmnc_list_.push_back("200001"); |
| 1162 | mccmnc_list_.push_back("200002"); |
Prathmesh Prabhu | 0db0bf0 | 2014-05-06 15:17:44 -0700 | [diff] [blame] | 1163 | mccmnc_list_.push_back("200003"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1164 | |
| 1165 | operator_name_list_.clear(); |
| 1166 | operator_name_list_.push_back({"name200001", "en"}); |
| 1167 | operator_name_list_.push_back({"name200002", ""}); |
| 1168 | |
| 1169 | apn_list_.clear(); |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1170 | MobileOperatorInfo::MobileAPN* apn; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1171 | apn = new MobileOperatorInfo::MobileAPN(); |
| 1172 | apn->apn = "test@test.com"; |
| 1173 | apn->username = "testuser"; |
| 1174 | apn->password = "is_public_boohoohoo"; |
| 1175 | apn->operator_name_list.push_back({"name200003", "hi"}); |
| 1176 | apn_list_.push_back(apn); // Takes ownership. |
| 1177 | |
| 1178 | olp_list_.clear(); |
| 1179 | olp_list_.push_back({"some@random.com", "POST", "random_data"}); |
| 1180 | |
| 1181 | sid_list_.clear(); |
| 1182 | sid_list_.push_back("200123"); |
| 1183 | sid_list_.push_back("200234"); |
Prathmesh Prabhu | 0db0bf0 | 2014-05-06 15:17:44 -0700 | [diff] [blame] | 1184 | sid_list_.push_back("200345"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | // Use this function to pre-populate all the data members of this object with |
| 1188 | // values matching the MVNO for the database in |data_test.prototext|. |
| 1189 | void PopulateMVNOData() { |
| 1190 | country_ = "ca"; |
| 1191 | requires_roaming_ = false; |
| 1192 | activation_code_ = "khul ja sim sim"; |
| 1193 | |
| 1194 | mccmnc_list_.clear(); |
| 1195 | mccmnc_list_.push_back("200001"); |
| 1196 | mccmnc_list_.push_back("200102"); |
| 1197 | |
| 1198 | operator_name_list_.clear(); |
| 1199 | operator_name_list_.push_back({"name200101", "en"}); |
| 1200 | operator_name_list_.push_back({"name200102", ""}); |
| 1201 | |
| 1202 | apn_list_.clear(); |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1203 | MobileOperatorInfo::MobileAPN* apn; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1204 | apn = new MobileOperatorInfo::MobileAPN(); |
| 1205 | apn->apn = "test2@test.com"; |
| 1206 | apn->username = "testuser2"; |
| 1207 | apn->password = "is_public_boohoohoo_too"; |
| 1208 | apn_list_.push_back(apn); // Takes ownership. |
| 1209 | |
| 1210 | olp_list_.clear(); |
| 1211 | olp_list_.push_back({"someother@random.com", "GET", ""}); |
| 1212 | |
| 1213 | sid_list_.clear(); |
| 1214 | sid_list_.push_back("200345"); |
| 1215 | } |
| 1216 | |
| 1217 | // Data to be verified against the database. |
| 1218 | string country_; |
| 1219 | bool requires_roaming_; |
| 1220 | string activation_code_; |
| 1221 | vector<string> mccmnc_list_; |
| 1222 | vector<MobileOperatorInfo::LocalizedName> operator_name_list_; |
| 1223 | ScopedVector<MobileOperatorInfo::MobileAPN> apn_list_; |
| 1224 | vector<MobileOperatorInfo::OnlinePortal> olp_list_; |
| 1225 | vector<string> sid_list_; |
| 1226 | |
| 1227 | // Extra data to be verified only against user updates. |
| 1228 | string sid_; |
| 1229 | |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 1230 | private: |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1231 | DISALLOW_COPY_AND_ASSIGN(MobileOperatorInfoDataTest); |
| 1232 | }; |
| 1233 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1234 | |
| 1235 | TEST_P(MobileOperatorInfoDataTest, MNODetailedInformation) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1236 | // message: MNO with all the information filled in. |
| 1237 | // match by: MNO matches by MCCMNC |
| 1238 | // verify: All information is correctly loaded. |
| 1239 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1240 | UpdateMCCMNC("200001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1241 | VerifyEventCount(); |
| 1242 | VerifyMNOWithUUID("uuid200001"); |
| 1243 | |
| 1244 | PopulateMNOData(); |
| 1245 | VerifyDatabaseData(); |
| 1246 | } |
| 1247 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1248 | TEST_P(MobileOperatorInfoDataTest, MVNOInheritsInformation) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1249 | // message: MVNO with name filter. |
| 1250 | // verify: All the missing fields are carried over to the MVNO from MNO. |
| 1251 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1252 | UpdateMCCMNC("200001"); |
| 1253 | UpdateOperatorName("name200201"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1254 | VerifyEventCount(); |
| 1255 | VerifyMVNOWithUUID("uuid200201"); |
| 1256 | |
| 1257 | PopulateMNOData(); |
| 1258 | VerifyDatabaseData(); |
| 1259 | } |
| 1260 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1261 | TEST_P(MobileOperatorInfoDataTest, MVNOOverridesInformation) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1262 | // match by: MNO matches by MCCMNC, MVNO by name. |
| 1263 | // verify: All information is correctly loaded. |
| 1264 | // The MVNO in this case overrides the information provided by MNO. |
| 1265 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1266 | UpdateMCCMNC("200001"); |
| 1267 | UpdateOperatorName("name200101"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1268 | VerifyEventCount(); |
| 1269 | VerifyMVNOWithUUID("uuid200101"); |
| 1270 | |
| 1271 | PopulateMVNOData(); |
| 1272 | VerifyDatabaseData(); |
| 1273 | } |
| 1274 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1275 | TEST_P(MobileOperatorInfoDataTest, NoUpdatesBeforeMNOMatch) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1276 | // message: MVNO. |
| 1277 | // - do not match MNO with mccmnc/name |
| 1278 | // - on different updates, verify no events. |
| 1279 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1280 | UpdateMCCMNC("200999"); // No match. |
| 1281 | UpdateOperatorName("name200001"); // matches MNO |
| 1282 | UpdateOperatorName("name200101"); // matches MVNO filter. |
| 1283 | UpdateSID("200999"); // No match. |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1284 | VerifyEventCount(); |
| 1285 | VerifyNoMatch(); |
| 1286 | } |
| 1287 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1288 | TEST_P(MobileOperatorInfoDataTest, UserUpdatesOverrideMVNO) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1289 | // - match MVNO. |
| 1290 | // - send updates to properties and verify events are raised and values of |
| 1291 | // updated properties override the ones provided by the database. |
| 1292 | string imsi {"2009991234512345"}; |
| 1293 | string iccid {"200999123456789"}; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1294 | string olp_url {"url@url.com"}; |
| 1295 | string olp_method {"POST"}; |
| 1296 | string olp_post_data {"data"}; |
| 1297 | |
| 1298 | // Determine MVNO. |
| 1299 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1300 | UpdateMCCMNC("200001"); |
| 1301 | UpdateOperatorName("name200101"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1302 | VerifyEventCount(); |
| 1303 | VerifyMVNOWithUUID("uuid200101"); |
| 1304 | |
| 1305 | // Send updates. |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 1306 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1307 | UpdateOnlinePortal(olp_url, olp_method, olp_post_data); |
| 1308 | UpdateIMSI(imsi); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1309 | // No event raised because imsi is not exposed. |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1310 | UpdateICCID(iccid); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1311 | // No event raised because ICCID is not exposed. |
| 1312 | |
| 1313 | VerifyEventCount(); |
| 1314 | |
| 1315 | // Update our expectations. |
| 1316 | PopulateMVNOData(); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1317 | olp_list_.push_back({olp_url, olp_method, olp_post_data}); |
| 1318 | |
| 1319 | VerifyDatabaseData(); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1322 | TEST_P(MobileOperatorInfoDataTest, CachedUserUpdatesOverrideMVNO) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1323 | // message: MVNO. |
| 1324 | // - First send updates that don't identify an MNO. |
| 1325 | // - Then identify an MNO and MVNO. |
| 1326 | // - verify that all the earlier updates are cached, and override the MVNO |
| 1327 | // information. |
| 1328 | string imsi {"2009991234512345"}; |
| 1329 | string iccid {"200999123456789"}; |
| 1330 | string sid {"200999"}; |
| 1331 | string olp_url {"url@url.com"}; |
| 1332 | string olp_method {"POST"}; |
| 1333 | string olp_post_data {"data"}; |
| 1334 | |
| 1335 | // Send updates. |
| 1336 | ExpectEventCount(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1337 | UpdateSID(sid); |
| 1338 | UpdateOnlinePortal(olp_url, olp_method, olp_post_data); |
| 1339 | UpdateIMSI(imsi); |
| 1340 | UpdateICCID(iccid); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1341 | VerifyEventCount(); |
| 1342 | |
| 1343 | // Determine MVNO. |
| 1344 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1345 | UpdateMCCMNC("200001"); |
| 1346 | UpdateOperatorName("name200101"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1347 | VerifyEventCount(); |
| 1348 | VerifyMVNOWithUUID("uuid200101"); |
| 1349 | |
| 1350 | // Update our expectations. |
| 1351 | PopulateMVNOData(); |
| 1352 | sid_ = sid; |
| 1353 | sid_list_.push_back(sid); |
| 1354 | olp_list_.push_back({olp_url, olp_method, olp_post_data}); |
| 1355 | |
| 1356 | VerifyDatabaseData(); |
| 1357 | VerifyUserData(); |
| 1358 | } |
| 1359 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1360 | TEST_P(MobileOperatorInfoDataTest, RedundantUserUpdatesMVNO) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1361 | // - match MVNO. |
| 1362 | // - send redundant updates to properties. |
| 1363 | // - Verify no events, no updates to properties. |
| 1364 | |
| 1365 | // Identify MVNO. |
| 1366 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1367 | UpdateMCCMNC("200001"); |
| 1368 | UpdateOperatorName("name200101"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1369 | VerifyEventCount(); |
| 1370 | VerifyMVNOWithUUID("uuid200101"); |
| 1371 | |
| 1372 | // Send redundant updates. |
| 1373 | // TODO(pprabhu) |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 1374 | // |UpdateOnlinePortal| leads to an event because this is the first time this |
| 1375 | // value are set *by the user*. Although the values from the database were the |
| 1376 | // same, we did not use those values for filters. It would be ideal to not |
| 1377 | // raise these redundant events (since no public information about the object |
| 1378 | // changed), but I haven't invested in doing so yet. |
| 1379 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1380 | UpdateOperatorName(operator_info_->operator_name()); |
| 1381 | UpdateOnlinePortal("someother@random.com", "GET", ""); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1382 | VerifyEventCount(); |
| 1383 | PopulateMVNOData(); |
| 1384 | VerifyDatabaseData(); |
| 1385 | } |
| 1386 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1387 | TEST_P(MobileOperatorInfoDataTest, RedundantCachedUpdatesMVNO) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1388 | // message: MVNO. |
| 1389 | // - First send updates that don't identify MVNO, but match the data. |
| 1390 | // - Then idenityf an MNO and MVNO. |
| 1391 | // - verify that redundant information occurs only once. |
| 1392 | |
| 1393 | // Send redundant updates. |
| 1394 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1395 | UpdateSID(operator_info_->sid()); |
| 1396 | UpdateOperatorName(operator_info_->operator_name()); |
| 1397 | UpdateOnlinePortal("someother@random.com", "GET", ""); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1398 | |
| 1399 | // Identify MVNO. |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1400 | UpdateMCCMNC("200001"); |
| 1401 | UpdateOperatorName("name200101"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1402 | VerifyEventCount(); |
| 1403 | VerifyMVNOWithUUID("uuid200101"); |
| 1404 | |
| 1405 | PopulateMVNOData(); |
| 1406 | VerifyDatabaseData(); |
| 1407 | } |
| 1408 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1409 | TEST_P(MobileOperatorInfoDataTest, ResetClearsInformation) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1410 | // Repeatedly reset the object and check M[V]NO identification and data. |
| 1411 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1412 | UpdateMCCMNC("200001"); |
| 1413 | UpdateOperatorName("name200201"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1414 | VerifyEventCount(); |
| 1415 | VerifyMVNOWithUUID("uuid200201"); |
| 1416 | PopulateMNOData(); |
| 1417 | VerifyDatabaseData(); |
| 1418 | |
| 1419 | ExpectEventCount(1); |
| 1420 | operator_info_->Reset(); |
| 1421 | VerifyEventCount(); |
| 1422 | VerifyNoMatch(); |
| 1423 | |
| 1424 | ExpectEventCount(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1425 | UpdateMCCMNC("200001"); |
| 1426 | UpdateOperatorName("name200101"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1427 | VerifyEventCount(); |
| 1428 | VerifyMVNOWithUUID("uuid200101"); |
| 1429 | PopulateMVNOData(); |
| 1430 | VerifyDatabaseData(); |
| 1431 | |
| 1432 | ExpectEventCount(1); |
| 1433 | operator_info_->Reset(); |
| 1434 | VerifyEventCount(); |
| 1435 | VerifyNoMatch(); |
| 1436 | |
| 1437 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1438 | UpdateMCCMNC("200001"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1439 | VerifyEventCount(); |
| 1440 | VerifyMNOWithUUID("uuid200001"); |
| 1441 | PopulateMNOData(); |
| 1442 | VerifyDatabaseData(); |
| 1443 | } |
| 1444 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1445 | TEST_P(MobileOperatorInfoDataTest, FilteredOLP) { |
Prathmesh Prabhu | 0db0bf0 | 2014-05-06 15:17:44 -0700 | [diff] [blame] | 1446 | // We only check basic filter matching, using the fact that the regex matching |
| 1447 | // code is shared with the MVNO filtering, and is already well tested. |
| 1448 | // (1) None of the filters match. |
| 1449 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1450 | UpdateMCCMNC("200001"); |
Prathmesh Prabhu | 0db0bf0 | 2014-05-06 15:17:44 -0700 | [diff] [blame] | 1451 | VerifyEventCount(); |
| 1452 | VerifyMNOWithUUID("uuid200001"); |
| 1453 | |
| 1454 | ASSERT_EQ(1, operator_info_->olp_list().size()); |
| 1455 | // Just check that the filtered OLPs are not in the list. |
| 1456 | EXPECT_NE("olp@mccmnc", operator_info_->olp_list()[0].url); |
| 1457 | EXPECT_NE("olp@sid", operator_info_->olp_list()[0].url); |
| 1458 | |
| 1459 | // (2) MCCMNC filter matches. |
| 1460 | ExpectEventCount(1); |
| 1461 | operator_info_->Reset(); |
| 1462 | VerifyEventCount(); |
| 1463 | VerifyNoMatch(); |
| 1464 | |
| 1465 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1466 | UpdateMCCMNC("200003"); |
Prathmesh Prabhu | 0db0bf0 | 2014-05-06 15:17:44 -0700 | [diff] [blame] | 1467 | VerifyEventCount(); |
| 1468 | VerifyMNOWithUUID("uuid200001"); |
| 1469 | |
| 1470 | ASSERT_EQ(2, operator_info_->olp_list().size()); |
| 1471 | EXPECT_NE("olp@sid", operator_info_->olp_list()[0].url); |
| 1472 | bool found_olp_by_mccmnc = false; |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1473 | for (const auto& olp : operator_info_->olp_list()) { |
Prathmesh Prabhu | 0db0bf0 | 2014-05-06 15:17:44 -0700 | [diff] [blame] | 1474 | found_olp_by_mccmnc |= ("olp@mccmnc" == olp.url); |
| 1475 | } |
| 1476 | EXPECT_TRUE(found_olp_by_mccmnc); |
| 1477 | |
| 1478 | // (3) SID filter matches. |
| 1479 | ExpectEventCount(1); |
| 1480 | operator_info_->Reset(); |
| 1481 | VerifyEventCount(); |
| 1482 | VerifyNoMatch(); |
| 1483 | |
| 1484 | ExpectEventCount(1); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1485 | UpdateSID("200345"); |
Prathmesh Prabhu | 0db0bf0 | 2014-05-06 15:17:44 -0700 | [diff] [blame] | 1486 | VerifyEventCount(); |
| 1487 | VerifyMNOWithUUID("uuid200001"); |
| 1488 | |
| 1489 | ASSERT_EQ(2, operator_info_->olp_list().size()); |
| 1490 | EXPECT_NE("olp@mccmnc", operator_info_->olp_list()[0].url); |
| 1491 | bool found_olp_by_sid = false; |
Paul Stewart | 2f6c789 | 2015-06-16 13:13:10 -0700 | [diff] [blame^] | 1492 | for (const auto& olp : operator_info_->olp_list()) { |
Prathmesh Prabhu | 0db0bf0 | 2014-05-06 15:17:44 -0700 | [diff] [blame] | 1493 | found_olp_by_sid |= ("olp@sid" == olp.url); |
| 1494 | } |
| 1495 | EXPECT_TRUE(found_olp_by_sid); |
| 1496 | } |
| 1497 | |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1498 | class MobileOperatorInfoObserverTest : public MobileOperatorInfoMainTest { |
| 1499 | public: |
| 1500 | MobileOperatorInfoObserverTest() : MobileOperatorInfoMainTest() {} |
| 1501 | |
| 1502 | // Same as |MobileOperatorInfoMainTest::SetUp|, except that we don't add a |
| 1503 | // default observer. |
| 1504 | virtual void SetUp() { |
| 1505 | operator_info_->ClearDatabasePaths(); |
| 1506 | AddDatabase(mobile_operator_db::data_test, |
| 1507 | arraysize(mobile_operator_db::data_test)); |
| 1508 | operator_info_->Init(); |
| 1509 | } |
| 1510 | |
| 1511 | protected: |
| 1512 | // /////////////////////////////////////////////////////////////////////////// |
| 1513 | // Data. |
| 1514 | MockMobileOperatorInfoObserver second_observer_; |
| 1515 | |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 1516 | private: |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1517 | DISALLOW_COPY_AND_ASSIGN(MobileOperatorInfoObserverTest); |
| 1518 | }; |
| 1519 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1520 | TEST_P(MobileOperatorInfoObserverTest, NoObserver) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1521 | // - Don't add any observers, and then cause an MVNO update to occur. |
| 1522 | // - Verify no crash. |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1523 | UpdateMCCMNC("200001"); |
| 1524 | UpdateOperatorName("name200101"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1527 | TEST_P(MobileOperatorInfoObserverTest, MultipleObservers) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1528 | // - Add two observers, and then cause an MVNO update to occur. |
| 1529 | // - Verify both observers are notified. |
| 1530 | operator_info_->AddObserver(&observer_); |
| 1531 | operator_info_->AddObserver(&second_observer_); |
| 1532 | |
| 1533 | EXPECT_CALL(observer_, OnOperatorChanged()).Times(2); |
| 1534 | EXPECT_CALL(second_observer_, OnOperatorChanged()).Times(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1535 | UpdateMCCMNC("200001"); |
| 1536 | UpdateOperatorName("name200101"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1537 | VerifyMVNOWithUUID("uuid200101"); |
| 1538 | |
| 1539 | dispatcher_.DispatchPendingEvents(); |
| 1540 | } |
| 1541 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1542 | TEST_P(MobileOperatorInfoObserverTest, LateObserver) { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1543 | // - Add one observer, and verify it gets an MVNO update. |
| 1544 | operator_info_->AddObserver(&observer_); |
| 1545 | |
| 1546 | EXPECT_CALL(observer_, OnOperatorChanged()).Times(2); |
| 1547 | EXPECT_CALL(second_observer_, OnOperatorChanged()).Times(0); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1548 | UpdateMCCMNC("200001"); |
| 1549 | UpdateOperatorName("name200101"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1550 | VerifyMVNOWithUUID("uuid200101"); |
| 1551 | dispatcher_.DispatchPendingEvents(); |
| 1552 | Mock::VerifyAndClearExpectations(&observer_); |
| 1553 | Mock::VerifyAndClearExpectations(&second_observer_); |
| 1554 | |
| 1555 | EXPECT_CALL(observer_, OnOperatorChanged()).Times(1); |
| 1556 | EXPECT_CALL(second_observer_, OnOperatorChanged()).Times(0); |
| 1557 | operator_info_->Reset(); |
| 1558 | VerifyNoMatch(); |
| 1559 | dispatcher_.DispatchPendingEvents(); |
| 1560 | Mock::VerifyAndClearExpectations(&observer_); |
| 1561 | Mock::VerifyAndClearExpectations(&second_observer_); |
| 1562 | |
| 1563 | // - Add another observer, verify both get an MVNO update. |
| 1564 | operator_info_->AddObserver(&second_observer_); |
| 1565 | |
| 1566 | EXPECT_CALL(observer_, OnOperatorChanged()).Times(2); |
| 1567 | EXPECT_CALL(second_observer_, OnOperatorChanged()).Times(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1568 | UpdateMCCMNC("200001"); |
| 1569 | UpdateOperatorName("name200101"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1570 | VerifyMVNOWithUUID("uuid200101"); |
| 1571 | dispatcher_.DispatchPendingEvents(); |
| 1572 | Mock::VerifyAndClearExpectations(&observer_); |
| 1573 | Mock::VerifyAndClearExpectations(&second_observer_); |
| 1574 | |
| 1575 | EXPECT_CALL(observer_, OnOperatorChanged()).Times(1); |
| 1576 | EXPECT_CALL(second_observer_, OnOperatorChanged()).Times(1); |
| 1577 | operator_info_->Reset(); |
| 1578 | VerifyNoMatch(); |
| 1579 | dispatcher_.DispatchPendingEvents(); |
| 1580 | Mock::VerifyAndClearExpectations(&observer_); |
| 1581 | Mock::VerifyAndClearExpectations(&second_observer_); |
| 1582 | |
| 1583 | // - Remove an observer, verify it no longer gets updates. |
| 1584 | operator_info_->RemoveObserver(&observer_); |
| 1585 | |
| 1586 | EXPECT_CALL(observer_, OnOperatorChanged()).Times(0); |
| 1587 | EXPECT_CALL(second_observer_, OnOperatorChanged()).Times(2); |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1588 | UpdateMCCMNC("200001"); |
| 1589 | UpdateOperatorName("name200101"); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1590 | VerifyMVNOWithUUID("uuid200101"); |
| 1591 | dispatcher_.DispatchPendingEvents(); |
| 1592 | Mock::VerifyAndClearExpectations(&observer_); |
| 1593 | Mock::VerifyAndClearExpectations(&second_observer_); |
| 1594 | |
| 1595 | EXPECT_CALL(observer_, OnOperatorChanged()).Times(0); |
| 1596 | EXPECT_CALL(second_observer_, OnOperatorChanged()).Times(1); |
| 1597 | operator_info_->Reset(); |
| 1598 | VerifyNoMatch(); |
| 1599 | dispatcher_.DispatchPendingEvents(); |
| 1600 | Mock::VerifyAndClearExpectations(&observer_); |
| 1601 | Mock::VerifyAndClearExpectations(&second_observer_); |
| 1602 | } |
| 1603 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 1604 | INSTANTIATE_TEST_CASE_P(MobileOperatorInfoMainTestInstance, |
| 1605 | MobileOperatorInfoMainTest, |
| 1606 | Values(kEventCheckingPolicyStrict, |
| 1607 | kEventCheckingPolicyNonStrict)); |
| 1608 | INSTANTIATE_TEST_CASE_P(MobileOperatorInfoDataTestInstance, |
| 1609 | MobileOperatorInfoDataTest, |
| 1610 | Values(kEventCheckingPolicyStrict, |
| 1611 | kEventCheckingPolicyNonStrict)); |
| 1612 | // It only makes sense to do strict checking here. |
| 1613 | INSTANTIATE_TEST_CASE_P(MobileOperatorInfoObserverTestInstance, |
| 1614 | MobileOperatorInfoObserverTest, |
| 1615 | Values(kEventCheckingPolicyStrict)); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1616 | } // namespace shill |