| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <string> | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/guid.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/message_loop.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | |
| 12 #include "base/synchronization/waitable_event.h" | |
| 13 #include "chrome/test/base/testing_browser_process.h" | |
| 14 #include "chrome/test/base/testing_profile.h" | |
| 15 #include "components/autofill/browser/autofill_common_test.h" | |
| 16 #include "components/autofill/browser/autofill_metrics.h" | |
| 17 #include "components/autofill/browser/autofill_profile.h" | |
| 18 #include "components/autofill/browser/form_structure.h" | |
| 19 #include "components/autofill/browser/personal_data_manager.h" | |
| 20 #include "components/autofill/browser/personal_data_manager_observer.h" | |
| 21 #include "components/autofill/browser/webdata/autofill_webdata_service.h" | |
| 22 #include "components/autofill/core/common/form_data.h" | |
| 23 #include "components/webdata/encryptor/encryptor.h" | |
| 24 #include "content/public/browser/notification_details.h" | |
| 25 #include "content/public/browser/notification_registrar.h" | |
| 26 #include "content/public/browser/notification_source.h" | |
| 27 #include "content/public/browser/notification_types.h" | |
| 28 #include "content/public/test/mock_notification_observer.h" | |
| 29 #include "content/public/test/test_browser_thread.h" | |
| 30 #include "testing/gmock/include/gmock/gmock.h" | |
| 31 #include "testing/gtest/include/gtest/gtest.h" | |
| 32 | |
| 33 using content::BrowserThread; | |
| 34 | |
| 35 namespace autofill { | |
| 36 namespace { | |
| 37 | |
| 38 ACTION(QuitUIMessageLoop) { | |
| 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 40 base::MessageLoop::current()->Quit(); | |
| 41 } | |
| 42 | |
| 43 class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver { | |
| 44 public: | |
| 45 PersonalDataLoadedObserverMock() {} | |
| 46 virtual ~PersonalDataLoadedObserverMock() {} | |
| 47 | |
| 48 MOCK_METHOD0(OnPersonalDataChanged, void()); | |
| 49 }; | |
| 50 | |
| 51 // Unlike the base AutofillMetrics, exposes copy and assignment constructors, | |
| 52 // which are handy for briefer test code. The AutofillMetrics class is | |
| 53 // stateless, so this is safe. | |
| 54 class TestAutofillMetrics : public AutofillMetrics { | |
| 55 public: | |
| 56 TestAutofillMetrics() {} | |
| 57 virtual ~TestAutofillMetrics() {} | |
| 58 }; | |
| 59 | |
| 60 } // anonymous namespace | |
| 61 | |
| 62 class PersonalDataManagerTest : public testing::Test { | |
| 63 protected: | |
| 64 PersonalDataManagerTest() | |
| 65 : ui_thread_(BrowserThread::UI, &message_loop_), | |
| 66 db_thread_(BrowserThread::DB) { | |
| 67 } | |
| 68 | |
| 69 virtual void SetUp() { | |
| 70 db_thread_.Start(); | |
| 71 | |
| 72 profile_.reset(new TestingProfile); | |
| 73 profile_->CreateWebDataService(); | |
| 74 | |
| 75 test::DisableSystemServices(profile_.get()); | |
| 76 ResetPersonalDataManager(); | |
| 77 } | |
| 78 | |
| 79 virtual void TearDown() { | |
| 80 // Destruction order is imposed explicitly here. | |
| 81 personal_data_.reset(NULL); | |
| 82 profile_.reset(NULL); | |
| 83 | |
| 84 // Schedule another task on the DB thread to notify us that it's safe to | |
| 85 // stop the thread. | |
| 86 base::WaitableEvent done(false, false); | |
| 87 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
| 88 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | |
| 89 done.Wait(); | |
| 90 base::MessageLoop::current()->PostTask(FROM_HERE, | |
| 91 base::MessageLoop::QuitClosure()); | |
| 92 base::MessageLoop::current()->Run(); | |
| 93 db_thread_.Stop(); | |
| 94 } | |
| 95 | |
| 96 void ResetPersonalDataManager() { | |
| 97 personal_data_.reset(new PersonalDataManager("en-US")); | |
| 98 personal_data_->Init(profile_.get()); | |
| 99 personal_data_->AddObserver(&personal_data_observer_); | |
| 100 | |
| 101 // Verify that the web database has been updated and the notification sent. | |
| 102 EXPECT_CALL(personal_data_observer_, | |
| 103 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 104 base::MessageLoop::current()->Run(); | |
| 105 } | |
| 106 | |
| 107 void MakeProfileIncognito() { | |
| 108 profile_->set_incognito(true); | |
| 109 } | |
| 110 | |
| 111 base::MessageLoopForUI message_loop_; | |
| 112 content::TestBrowserThread ui_thread_; | |
| 113 content::TestBrowserThread db_thread_; | |
| 114 scoped_ptr<TestingProfile> profile_; | |
| 115 scoped_ptr<PersonalDataManager> personal_data_; | |
| 116 content::NotificationRegistrar registrar_; | |
| 117 content::MockNotificationObserver observer_; | |
| 118 PersonalDataLoadedObserverMock personal_data_observer_; | |
| 119 }; | |
| 120 | |
| 121 TEST_F(PersonalDataManagerTest, AddProfile) { | |
| 122 // Add profile0 to the database. | |
| 123 AutofillProfile profile0(autofill::test::GetFullProfile()); | |
| 124 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); | |
| 125 personal_data_->AddProfile(profile0); | |
| 126 | |
| 127 // Reload the database. | |
| 128 ResetPersonalDataManager(); | |
| 129 | |
| 130 // Verify the addition. | |
| 131 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | |
| 132 ASSERT_EQ(1U, results1.size()); | |
| 133 EXPECT_EQ(0, profile0.Compare(*results1[0])); | |
| 134 | |
| 135 // Add profile with identical values. Duplicates should not get saved. | |
| 136 AutofillProfile profile0a = profile0; | |
| 137 profile0a.set_guid(base::GenerateGUID()); | |
| 138 personal_data_->AddProfile(profile0a); | |
| 139 | |
| 140 // Reload the database. | |
| 141 ResetPersonalDataManager(); | |
| 142 | |
| 143 // Verify the non-addition. | |
| 144 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | |
| 145 ASSERT_EQ(1U, results2.size()); | |
| 146 EXPECT_EQ(0, profile0.Compare(*results2[0])); | |
| 147 | |
| 148 // New profile with different email. | |
| 149 AutofillProfile profile1 = profile0; | |
| 150 profile1.set_guid(base::GenerateGUID()); | |
| 151 profile1.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("john@smith.com")); | |
| 152 | |
| 153 // Add the different profile. This should save as a separate profile. | |
| 154 // Note that if this same profile was "merged" it would collapse to one | |
| 155 // profile with a multi-valued entry for email. | |
| 156 personal_data_->AddProfile(profile1); | |
| 157 | |
| 158 // Reload the database. | |
| 159 ResetPersonalDataManager(); | |
| 160 | |
| 161 // Verify the addition. | |
| 162 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); | |
| 163 ASSERT_EQ(2U, results3.size()); | |
| 164 EXPECT_EQ(0, profile0.Compare(*results3[0])); | |
| 165 EXPECT_EQ(0, profile1.Compare(*results3[1])); | |
| 166 } | |
| 167 | |
| 168 TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) { | |
| 169 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | |
| 170 test::SetProfileInfo(&profile0, | |
| 171 "Marion", "Mitchell", "Morrison", | |
| 172 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | |
| 173 "91601", "US", "12345678910"); | |
| 174 | |
| 175 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | |
| 176 test::SetProfileInfo(&profile1, | |
| 177 "Josephine", "Alicia", "Saenz", | |
| 178 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", | |
| 179 "US", "19482937549"); | |
| 180 | |
| 181 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | |
| 182 test::SetProfileInfo(&profile2, | |
| 183 "Josephine", "Alicia", "Saenz", | |
| 184 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | |
| 185 "32801", "US", "19482937549"); | |
| 186 | |
| 187 // Add two test profiles to the database. | |
| 188 personal_data_->AddProfile(profile0); | |
| 189 personal_data_->AddProfile(profile1); | |
| 190 | |
| 191 // Verify that the web database has been updated and the notification sent. | |
| 192 EXPECT_CALL(personal_data_observer_, | |
| 193 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 194 base::MessageLoop::current()->Run(); | |
| 195 | |
| 196 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | |
| 197 ASSERT_EQ(2U, results1.size()); | |
| 198 EXPECT_EQ(0, profile0.Compare(*results1[0])); | |
| 199 EXPECT_EQ(0, profile1.Compare(*results1[1])); | |
| 200 | |
| 201 // Update, remove, and add. | |
| 202 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); | |
| 203 personal_data_->UpdateProfile(profile0); | |
| 204 personal_data_->RemoveByGUID(profile1.guid()); | |
| 205 personal_data_->AddProfile(profile2); | |
| 206 | |
| 207 // Verify that the web database has been updated and the notification sent. | |
| 208 EXPECT_CALL(personal_data_observer_, | |
| 209 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 210 base::MessageLoop::current()->Run(); | |
| 211 | |
| 212 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | |
| 213 ASSERT_EQ(2U, results2.size()); | |
| 214 EXPECT_EQ(0, profile0.Compare(*results2[0])); | |
| 215 EXPECT_EQ(0, profile2.Compare(*results2[1])); | |
| 216 | |
| 217 // Reset the PersonalDataManager. This tests that the personal data was saved | |
| 218 // to the web database, and that we can load the profiles from the web | |
| 219 // database. | |
| 220 ResetPersonalDataManager(); | |
| 221 | |
| 222 // Verify that we've loaded the profiles from the web database. | |
| 223 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); | |
| 224 ASSERT_EQ(2U, results3.size()); | |
| 225 EXPECT_EQ(0, profile0.Compare(*results3[0])); | |
| 226 EXPECT_EQ(0, profile2.Compare(*results3[1])); | |
| 227 } | |
| 228 | |
| 229 TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { | |
| 230 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | |
| 231 test::SetCreditCardInfo(&credit_card0, | |
| 232 "John Dillinger", "423456789012" /* Visa */, "01", "2010"); | |
| 233 | |
| 234 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | |
| 235 test::SetCreditCardInfo(&credit_card1, | |
| 236 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); | |
| 237 | |
| 238 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); | |
| 239 test::SetCreditCardInfo(&credit_card2, | |
| 240 "Clyde Barrow", "347666888555" /* American Express */, "04", "2015"); | |
| 241 | |
| 242 // Add two test credit cards to the database. | |
| 243 personal_data_->AddCreditCard(credit_card0); | |
| 244 personal_data_->AddCreditCard(credit_card1); | |
| 245 | |
| 246 // Verify that the web database has been updated and the notification sent. | |
| 247 EXPECT_CALL(personal_data_observer_, | |
| 248 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 249 base::MessageLoop::current()->Run(); | |
| 250 | |
| 251 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); | |
| 252 ASSERT_EQ(2U, results1.size()); | |
| 253 EXPECT_EQ(0, credit_card0.Compare(*results1[0])); | |
| 254 EXPECT_EQ(0, credit_card1.Compare(*results1[1])); | |
| 255 | |
| 256 // Update, remove, and add. | |
| 257 credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe")); | |
| 258 personal_data_->UpdateCreditCard(credit_card0); | |
| 259 personal_data_->RemoveByGUID(credit_card1.guid()); | |
| 260 personal_data_->AddCreditCard(credit_card2); | |
| 261 | |
| 262 // Verify that the web database has been updated and the notification sent. | |
| 263 EXPECT_CALL(personal_data_observer_, | |
| 264 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 265 base::MessageLoop::current()->Run(); | |
| 266 | |
| 267 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | |
| 268 ASSERT_EQ(2U, results2.size()); | |
| 269 EXPECT_EQ(credit_card0, *results2[0]); | |
| 270 EXPECT_EQ(credit_card2, *results2[1]); | |
| 271 | |
| 272 // Reset the PersonalDataManager. This tests that the personal data was saved | |
| 273 // to the web database, and that we can load the credit cards from the web | |
| 274 // database. | |
| 275 ResetPersonalDataManager(); | |
| 276 | |
| 277 // Verify that we've loaded the credit cards from the web database. | |
| 278 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); | |
| 279 ASSERT_EQ(2U, results3.size()); | |
| 280 EXPECT_EQ(credit_card0, *results3[0]); | |
| 281 EXPECT_EQ(credit_card2, *results3[1]); | |
| 282 } | |
| 283 | |
| 284 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) { | |
| 285 // Start with unverified data. | |
| 286 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); | |
| 287 test::SetProfileInfo(&profile, | |
| 288 "Marion", "Mitchell", "Morrison", | |
| 289 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | |
| 290 "91601", "US", "12345678910"); | |
| 291 EXPECT_FALSE(profile.IsVerified()); | |
| 292 | |
| 293 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); | |
| 294 test::SetCreditCardInfo(&credit_card, | |
| 295 "John Dillinger", "423456789012" /* Visa */, "01", "2010"); | |
| 296 EXPECT_FALSE(credit_card.IsVerified()); | |
| 297 | |
| 298 // Add the data to the database. | |
| 299 personal_data_->AddProfile(profile); | |
| 300 personal_data_->AddCreditCard(credit_card); | |
| 301 | |
| 302 // Verify that the web database has been updated and the notification sent. | |
| 303 EXPECT_CALL(personal_data_observer_, | |
| 304 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 305 base::MessageLoop::current()->Run(); | |
| 306 | |
| 307 const std::vector<AutofillProfile*>& profiles1 = | |
| 308 personal_data_->GetProfiles(); | |
| 309 const std::vector<CreditCard*>& cards1 = personal_data_->GetCreditCards(); | |
| 310 ASSERT_EQ(1U, profiles1.size()); | |
| 311 ASSERT_EQ(1U, cards1.size()); | |
| 312 EXPECT_EQ(0, profile.Compare(*profiles1[0])); | |
| 313 EXPECT_EQ(0, credit_card.Compare(*cards1[0])); | |
| 314 | |
| 315 // Try to update with just the origin changed. | |
| 316 AutofillProfile original_profile(profile); | |
| 317 CreditCard original_credit_card(credit_card); | |
| 318 profile.set_origin("Chrome settings"); | |
| 319 credit_card.set_origin("Chrome settings"); | |
| 320 | |
| 321 EXPECT_TRUE(profile.IsVerified()); | |
| 322 EXPECT_TRUE(credit_card.IsVerified()); | |
| 323 | |
| 324 personal_data_->UpdateProfile(profile); | |
| 325 personal_data_->UpdateCreditCard(credit_card); | |
| 326 | |
| 327 // Note: No refresh, as no update is expected. | |
| 328 | |
| 329 const std::vector<AutofillProfile*>& profiles2 = | |
| 330 personal_data_->GetProfiles(); | |
| 331 const std::vector<CreditCard*>& cards2 = personal_data_->GetCreditCards(); | |
| 332 ASSERT_EQ(1U, profiles2.size()); | |
| 333 ASSERT_EQ(1U, cards2.size()); | |
| 334 EXPECT_NE(profile.origin(), profiles2[0]->origin()); | |
| 335 EXPECT_NE(credit_card.origin(), cards2[0]->origin()); | |
| 336 EXPECT_EQ(original_profile.origin(), profiles2[0]->origin()); | |
| 337 EXPECT_EQ(original_credit_card.origin(), cards2[0]->origin()); | |
| 338 | |
| 339 // Try to update with data changed as well. | |
| 340 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); | |
| 341 credit_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe")); | |
| 342 | |
| 343 personal_data_->UpdateProfile(profile); | |
| 344 personal_data_->UpdateCreditCard(credit_card); | |
| 345 | |
| 346 // Verify that the web database has been updated and the notification sent. | |
| 347 EXPECT_CALL(personal_data_observer_, | |
| 348 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 349 base::MessageLoop::current()->Run(); | |
| 350 | |
| 351 const std::vector<AutofillProfile*>& profiles3 = | |
| 352 personal_data_->GetProfiles(); | |
| 353 const std::vector<CreditCard*>& cards3 = personal_data_->GetCreditCards(); | |
| 354 ASSERT_EQ(1U, profiles3.size()); | |
| 355 ASSERT_EQ(1U, cards3.size()); | |
| 356 EXPECT_EQ(0, profile.Compare(*profiles3[0])); | |
| 357 EXPECT_EQ(0, credit_card.Compare(*cards3[0])); | |
| 358 EXPECT_EQ(profile.origin(), profiles3[0]->origin()); | |
| 359 EXPECT_EQ(credit_card.origin(), cards3[0]->origin()); | |
| 360 } | |
| 361 | |
| 362 TEST_F(PersonalDataManagerTest, AddProfilesAndCreditCards) { | |
| 363 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | |
| 364 test::SetProfileInfo(&profile0, | |
| 365 "Marion", "Mitchell", "Morrison", | |
| 366 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | |
| 367 "91601", "US", "12345678910"); | |
| 368 | |
| 369 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | |
| 370 test::SetProfileInfo(&profile1, | |
| 371 "Josephine", "Alicia", "Saenz", | |
| 372 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", | |
| 373 "US", "19482937549"); | |
| 374 | |
| 375 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | |
| 376 test::SetCreditCardInfo(&credit_card0, | |
| 377 "John Dillinger", "423456789012" /* Visa */, "01", "2010"); | |
| 378 | |
| 379 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | |
| 380 test::SetCreditCardInfo(&credit_card1, | |
| 381 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); | |
| 382 | |
| 383 // Add two test profiles to the database. | |
| 384 personal_data_->AddProfile(profile0); | |
| 385 personal_data_->AddProfile(profile1); | |
| 386 | |
| 387 // Verify that the web database has been updated and the notification sent. | |
| 388 EXPECT_CALL(personal_data_observer_, | |
| 389 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 390 base::MessageLoop::current()->Run(); | |
| 391 | |
| 392 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | |
| 393 ASSERT_EQ(2U, results1.size()); | |
| 394 EXPECT_EQ(0, profile0.Compare(*results1[0])); | |
| 395 EXPECT_EQ(0, profile1.Compare(*results1[1])); | |
| 396 | |
| 397 // Add two test credit cards to the database. | |
| 398 personal_data_->AddCreditCard(credit_card0); | |
| 399 personal_data_->AddCreditCard(credit_card1); | |
| 400 | |
| 401 // Verify that the web database has been updated and the notification sent. | |
| 402 EXPECT_CALL(personal_data_observer_, | |
| 403 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 404 base::MessageLoop::current()->Run(); | |
| 405 | |
| 406 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | |
| 407 ASSERT_EQ(2U, results2.size()); | |
| 408 EXPECT_EQ(credit_card0, *results2[0]); | |
| 409 EXPECT_EQ(credit_card1, *results2[1]); | |
| 410 | |
| 411 // Determine uniqueness by inserting all of the GUIDs into a set and verifying | |
| 412 // the size of the set matches the number of GUIDs. | |
| 413 std::set<std::string> guids; | |
| 414 guids.insert(profile0.guid()); | |
| 415 guids.insert(profile1.guid()); | |
| 416 guids.insert(credit_card0.guid()); | |
| 417 guids.insert(credit_card1.guid()); | |
| 418 EXPECT_EQ(4U, guids.size()); | |
| 419 } | |
| 420 | |
| 421 // Test for http://crbug.com/50047. Makes sure that guids are populated | |
| 422 // correctly on load. | |
| 423 TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) { | |
| 424 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | |
| 425 test::SetProfileInfo(&profile0, | |
| 426 "y", "", "", "", "", "", "", "", "", "", "", ""); | |
| 427 | |
| 428 // Add the profile0 to the db. | |
| 429 personal_data_->AddProfile(profile0); | |
| 430 | |
| 431 // Verify that the web database has been updated and the notification sent. | |
| 432 EXPECT_CALL(personal_data_observer_, | |
| 433 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 434 base::MessageLoop::current()->Run(); | |
| 435 | |
| 436 // Verify that we've loaded the profiles from the web database. | |
| 437 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | |
| 438 ASSERT_EQ(1U, results2.size()); | |
| 439 EXPECT_EQ(0, profile0.Compare(*results2[0])); | |
| 440 | |
| 441 // Add a new profile. | |
| 442 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | |
| 443 test::SetProfileInfo(&profile1, | |
| 444 "z", "", "", "", "", "", "", "", "", "", "", ""); | |
| 445 personal_data_->AddProfile(profile1); | |
| 446 | |
| 447 // Verify that the web database has been updated and the notification sent. | |
| 448 EXPECT_CALL(personal_data_observer_, | |
| 449 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 450 base::MessageLoop::current()->Run(); | |
| 451 | |
| 452 // Make sure the two profiles have different GUIDs, both valid. | |
| 453 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); | |
| 454 ASSERT_EQ(2U, results3.size()); | |
| 455 EXPECT_NE(results3[0]->guid(), results3[1]->guid()); | |
| 456 EXPECT_TRUE(base::IsValidGUID(results3[0]->guid())); | |
| 457 EXPECT_TRUE(base::IsValidGUID(results3[1]->guid())); | |
| 458 } | |
| 459 | |
| 460 TEST_F(PersonalDataManagerTest, SetEmptyProfile) { | |
| 461 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | |
| 462 test::SetProfileInfo(&profile0, | |
| 463 "", "", "", "", "", "", "", "", "", "", "", ""); | |
| 464 | |
| 465 // Add the empty profile to the database. | |
| 466 personal_data_->AddProfile(profile0); | |
| 467 | |
| 468 // Note: no refresh here. | |
| 469 | |
| 470 // Reset the PersonalDataManager. This tests that the personal data was saved | |
| 471 // to the web database, and that we can load the profiles from the web | |
| 472 // database. | |
| 473 ResetPersonalDataManager(); | |
| 474 | |
| 475 // Verify that we've loaded the profiles from the web database. | |
| 476 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | |
| 477 ASSERT_EQ(0U, results2.size()); | |
| 478 } | |
| 479 | |
| 480 TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { | |
| 481 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | |
| 482 test::SetCreditCardInfo(&credit_card0, "", "", "", ""); | |
| 483 | |
| 484 // Add the empty credit card to the database. | |
| 485 personal_data_->AddCreditCard(credit_card0); | |
| 486 | |
| 487 // Note: no refresh here. | |
| 488 | |
| 489 // Reset the PersonalDataManager. This tests that the personal data was saved | |
| 490 // to the web database, and that we can load the credit cards from the web | |
| 491 // database. | |
| 492 ResetPersonalDataManager(); | |
| 493 | |
| 494 // Verify that we've loaded the credit cards from the web database. | |
| 495 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | |
| 496 ASSERT_EQ(0U, results2.size()); | |
| 497 } | |
| 498 | |
| 499 TEST_F(PersonalDataManagerTest, Refresh) { | |
| 500 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | |
| 501 test::SetProfileInfo(&profile0, | |
| 502 "Marion", "Mitchell", "Morrison", | |
| 503 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | |
| 504 "91601", "US", "12345678910"); | |
| 505 | |
| 506 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | |
| 507 test::SetProfileInfo(&profile1, | |
| 508 "Josephine", "Alicia", "Saenz", | |
| 509 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", | |
| 510 "US", "19482937549"); | |
| 511 | |
| 512 // Add the test profiles to the database. | |
| 513 personal_data_->AddProfile(profile0); | |
| 514 personal_data_->AddProfile(profile1); | |
| 515 | |
| 516 // Labels depend on other profiles in the list - update labels manually. | |
| 517 std::vector<AutofillProfile *> profile_pointers; | |
| 518 profile_pointers.push_back(&profile0); | |
| 519 profile_pointers.push_back(&profile1); | |
| 520 AutofillProfile::AdjustInferredLabels(&profile_pointers); | |
| 521 | |
| 522 // Verify that the web database has been updated and the notification sent. | |
| 523 EXPECT_CALL(personal_data_observer_, | |
| 524 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 525 base::MessageLoop::current()->Run(); | |
| 526 | |
| 527 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | |
| 528 ASSERT_EQ(2U, results1.size()); | |
| 529 EXPECT_EQ(profile0, *results1[0]); | |
| 530 EXPECT_EQ(profile1, *results1[1]); | |
| 531 | |
| 532 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | |
| 533 test::SetProfileInfo(&profile2, | |
| 534 "Josephine", "Alicia", "Saenz", | |
| 535 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | |
| 536 "32801", "US", "19482937549"); | |
| 537 | |
| 538 // Adjust all labels. | |
| 539 profile_pointers.push_back(&profile2); | |
| 540 AutofillProfile::AdjustInferredLabels(&profile_pointers); | |
| 541 | |
| 542 scoped_refptr<AutofillWebDataService> wds = | |
| 543 AutofillWebDataService::FromBrowserContext(profile_.get()); | |
| 544 ASSERT_TRUE(wds.get()); | |
| 545 wds->AddAutofillProfile(profile2); | |
| 546 | |
| 547 personal_data_->Refresh(); | |
| 548 | |
| 549 // Verify that the web database has been updated and the notification sent. | |
| 550 EXPECT_CALL(personal_data_observer_, | |
| 551 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 552 base::MessageLoop::current()->Run(); | |
| 553 | |
| 554 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | |
| 555 ASSERT_EQ(3U, results2.size()); | |
| 556 EXPECT_EQ(profile0, *results2[0]); | |
| 557 EXPECT_EQ(profile1, *results2[1]); | |
| 558 EXPECT_EQ(profile2, *results2[2]); | |
| 559 | |
| 560 wds->RemoveAutofillProfile(profile1.guid()); | |
| 561 wds->RemoveAutofillProfile(profile2.guid()); | |
| 562 | |
| 563 // Before telling the PDM to refresh, simulate an edit to one of the deleted | |
| 564 // profiles via a SetProfile update (this would happen if the Autofill window | |
| 565 // was open with a previous snapshot of the profiles, and something | |
| 566 // [e.g. sync] removed a profile from the browser. In this edge case, we will | |
| 567 // end up in a consistent state by dropping the write). | |
| 568 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Mar")); | |
| 569 profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jo")); | |
| 570 personal_data_->UpdateProfile(profile0); | |
| 571 personal_data_->AddProfile(profile1); | |
| 572 personal_data_->AddProfile(profile2); | |
| 573 | |
| 574 // Verify that the web database has been updated and the notification sent. | |
| 575 EXPECT_CALL(personal_data_observer_, | |
| 576 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 577 base::MessageLoop::current()->Run(); | |
| 578 | |
| 579 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); | |
| 580 ASSERT_EQ(1U, results3.size()); | |
| 581 EXPECT_EQ(profile0, *results2[0]); | |
| 582 } | |
| 583 | |
| 584 TEST_F(PersonalDataManagerTest, ImportFormData) { | |
| 585 FormData form; | |
| 586 FormFieldData field; | |
| 587 test::CreateTestFormField( | |
| 588 "First name:", "first_name", "George", "text", &field); | |
| 589 form.fields.push_back(field); | |
| 590 test::CreateTestFormField( | |
| 591 "Last name:", "last_name", "Washington", "text", &field); | |
| 592 form.fields.push_back(field); | |
| 593 test::CreateTestFormField( | |
| 594 "Email:", "email", "theprez@gmail.com", "text", &field); | |
| 595 form.fields.push_back(field); | |
| 596 test::CreateTestFormField( | |
| 597 "Address:", "address1", "21 Laussat St", "text", &field); | |
| 598 form.fields.push_back(field); | |
| 599 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 600 form.fields.push_back(field); | |
| 601 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 602 form.fields.push_back(field); | |
| 603 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 604 form.fields.push_back(field); | |
| 605 FormStructure form_structure(form, std::string()); | |
| 606 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 607 const CreditCard* imported_credit_card; | |
| 608 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | |
| 609 &imported_credit_card)); | |
| 610 ASSERT_FALSE(imported_credit_card); | |
| 611 | |
| 612 // Verify that the web database has been updated and the notification sent. | |
| 613 EXPECT_CALL(personal_data_observer_, | |
| 614 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 615 base::MessageLoop::current()->Run(); | |
| 616 | |
| 617 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | |
| 618 test::SetProfileInfo(&expected, "George", NULL, | |
| 619 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, | |
| 620 "San Francisco", "California", "94102", NULL, NULL); | |
| 621 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | |
| 622 ASSERT_EQ(1U, results.size()); | |
| 623 EXPECT_EQ(0, expected.Compare(*results[0])); | |
| 624 } | |
| 625 | |
| 626 TEST_F(PersonalDataManagerTest, ImportFormDataBadEmail) { | |
| 627 FormData form; | |
| 628 FormFieldData field; | |
| 629 test::CreateTestFormField( | |
| 630 "First name:", "first_name", "George", "text", &field); | |
| 631 form.fields.push_back(field); | |
| 632 test::CreateTestFormField( | |
| 633 "Last name:", "last_name", "Washington", "text", &field); | |
| 634 form.fields.push_back(field); | |
| 635 test::CreateTestFormField("Email:", "email", "bogus", "text", &field); | |
| 636 form.fields.push_back(field); | |
| 637 test::CreateTestFormField( | |
| 638 "Address:", "address1", "21 Laussat St", "text", &field); | |
| 639 form.fields.push_back(field); | |
| 640 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 641 form.fields.push_back(field); | |
| 642 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 643 form.fields.push_back(field); | |
| 644 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 645 form.fields.push_back(field); | |
| 646 FormStructure form_structure(form, std::string()); | |
| 647 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 648 const CreditCard* imported_credit_card; | |
| 649 EXPECT_FALSE(personal_data_->ImportFormData(form_structure, | |
| 650 &imported_credit_card)); | |
| 651 ASSERT_EQ(static_cast<CreditCard*>(NULL), imported_credit_card); | |
| 652 | |
| 653 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | |
| 654 ASSERT_EQ(0U, results.size()); | |
| 655 } | |
| 656 | |
| 657 // Tests that a 'confirm email' field does not block profile import. | |
| 658 TEST_F(PersonalDataManagerTest, ImportFormDataTwoEmails) { | |
| 659 FormData form; | |
| 660 FormFieldData field; | |
| 661 test::CreateTestFormField( | |
| 662 "Name:", "name", "George Washington", "text", &field); | |
| 663 form.fields.push_back(field); | |
| 664 test::CreateTestFormField( | |
| 665 "Address:", "address1", "21 Laussat St", "text", &field); | |
| 666 form.fields.push_back(field); | |
| 667 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 668 form.fields.push_back(field); | |
| 669 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 670 form.fields.push_back(field); | |
| 671 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 672 form.fields.push_back(field); | |
| 673 test::CreateTestFormField( | |
| 674 "Email:", "email", "example@example.com", "text", &field); | |
| 675 form.fields.push_back(field); | |
| 676 test::CreateTestFormField( | |
| 677 "Confirm email:", "confirm_email", "example@example.com", "text", &field); | |
| 678 form.fields.push_back(field); | |
| 679 FormStructure form_structure(form, std::string()); | |
| 680 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 681 const CreditCard* imported_credit_card; | |
| 682 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | |
| 683 &imported_credit_card)); | |
| 684 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | |
| 685 ASSERT_EQ(1U, results.size()); | |
| 686 } | |
| 687 | |
| 688 // Tests two email fields containing different values blocks provile import. | |
| 689 TEST_F(PersonalDataManagerTest, ImportFormDataTwoDifferentEmails) { | |
| 690 FormData form; | |
| 691 FormFieldData field; | |
| 692 test::CreateTestFormField( | |
| 693 "Name:", "name", "George Washington", "text", &field); | |
| 694 form.fields.push_back(field); | |
| 695 test::CreateTestFormField( | |
| 696 "Address:", "address1", "21 Laussat St", "text", &field); | |
| 697 form.fields.push_back(field); | |
| 698 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 699 form.fields.push_back(field); | |
| 700 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 701 form.fields.push_back(field); | |
| 702 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 703 form.fields.push_back(field); | |
| 704 test::CreateTestFormField( | |
| 705 "Email:", "email", "example@example.com", "text", &field); | |
| 706 form.fields.push_back(field); | |
| 707 test::CreateTestFormField( | |
| 708 "Email:", "email2", "example2@example.com", "text", &field); | |
| 709 form.fields.push_back(field); | |
| 710 FormStructure form_structure(form, std::string()); | |
| 711 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 712 const CreditCard* imported_credit_card; | |
| 713 EXPECT_FALSE(personal_data_->ImportFormData(form_structure, | |
| 714 &imported_credit_card)); | |
| 715 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | |
| 716 ASSERT_EQ(0U, results.size()); | |
| 717 } | |
| 718 | |
| 719 TEST_F(PersonalDataManagerTest, ImportFormDataNotEnoughFilledFields) { | |
| 720 FormData form; | |
| 721 FormFieldData field; | |
| 722 test::CreateTestFormField( | |
| 723 "First name:", "first_name", "George", "text", &field); | |
| 724 form.fields.push_back(field); | |
| 725 test::CreateTestFormField( | |
| 726 "Last name:", "last_name", "Washington", "text", &field); | |
| 727 form.fields.push_back(field); | |
| 728 test::CreateTestFormField( | |
| 729 "Card number:", "card_number", "4111 1111 1111 1111", "text", &field); | |
| 730 form.fields.push_back(field); | |
| 731 FormStructure form_structure(form, std::string()); | |
| 732 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 733 const CreditCard* imported_credit_card; | |
| 734 EXPECT_FALSE(personal_data_->ImportFormData(form_structure, | |
| 735 &imported_credit_card)); | |
| 736 ASSERT_FALSE(imported_credit_card); | |
| 737 | |
| 738 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | |
| 739 ASSERT_EQ(0U, profiles.size()); | |
| 740 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); | |
| 741 ASSERT_EQ(0U, cards.size()); | |
| 742 } | |
| 743 | |
| 744 TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressUSA) { | |
| 745 // United States addresses must specifiy one address line, a city, state and | |
| 746 // zip code. | |
| 747 FormData form; | |
| 748 FormFieldData field; | |
| 749 test::CreateTestFormField("Name:", "name", "Barack Obama", "text", &field); | |
| 750 form.fields.push_back(field); | |
| 751 test::CreateTestFormField( | |
| 752 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field); | |
| 753 form.fields.push_back(field); | |
| 754 test::CreateTestFormField("City:", "city", "Washington", "text", &field); | |
| 755 form.fields.push_back(field); | |
| 756 test::CreateTestFormField("State:", "state", "DC", "text", &field); | |
| 757 form.fields.push_back(field); | |
| 758 test::CreateTestFormField("Zip:", "zip", "20500", "text", &field); | |
| 759 form.fields.push_back(field); | |
| 760 test::CreateTestFormField("Country:", "country", "USA", "text", &field); | |
| 761 form.fields.push_back(field); | |
| 762 FormStructure form_structure(form, std::string()); | |
| 763 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 764 const CreditCard* imported_credit_card; | |
| 765 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | |
| 766 &imported_credit_card)); | |
| 767 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | |
| 768 ASSERT_EQ(1U, profiles.size()); | |
| 769 } | |
| 770 | |
| 771 TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressGB) { | |
| 772 // British addresses do not require a state/province as the county is usually | |
| 773 // not requested on forms. | |
| 774 FormData form; | |
| 775 FormFieldData field; | |
| 776 test::CreateTestFormField("Name:", "name", "David Cameron", "text", &field); | |
| 777 form.fields.push_back(field); | |
| 778 test::CreateTestFormField( | |
| 779 "Address:", "address", "10 Downing Street", "text", &field); | |
| 780 form.fields.push_back(field); | |
| 781 test::CreateTestFormField("City:", "city", "London", "text", &field); | |
| 782 form.fields.push_back(field); | |
| 783 test::CreateTestFormField( | |
| 784 "Postcode:", "postcode", "SW1A 2AA", "text", &field); | |
| 785 form.fields.push_back(field); | |
| 786 test::CreateTestFormField( | |
| 787 "Country:", "country", "United Kingdom", "text", &field); | |
| 788 form.fields.push_back(field); | |
| 789 FormStructure form_structure(form, std::string()); | |
| 790 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 791 const CreditCard* imported_credit_card; | |
| 792 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | |
| 793 &imported_credit_card)); | |
| 794 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | |
| 795 ASSERT_EQ(1U, profiles.size()); | |
| 796 } | |
| 797 | |
| 798 TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressGI) { | |
| 799 // Gibraltar has the most minimal set of requirements for a valid address. | |
| 800 // There are no cities or provinces and no postal/zip code system. | |
| 801 FormData form; | |
| 802 FormFieldData field; | |
| 803 test::CreateTestFormField( | |
| 804 "Name:", "name", "Sir Adrian Johns", "text", &field); | |
| 805 form.fields.push_back(field); | |
| 806 test::CreateTestFormField( | |
| 807 "Address:", "address", "The Convent, Main Street", "text", &field); | |
| 808 form.fields.push_back(field); | |
| 809 test::CreateTestFormField("Country:", "country", "Gibraltar", "text", &field); | |
| 810 form.fields.push_back(field); | |
| 811 FormStructure form_structure(form, std::string()); | |
| 812 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 813 const CreditCard* imported_credit_card; | |
| 814 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | |
| 815 &imported_credit_card)); | |
| 816 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | |
| 817 ASSERT_EQ(1U, profiles.size()); | |
| 818 } | |
| 819 | |
| 820 TEST_F(PersonalDataManagerTest, ImportPhoneNumberSplitAcrossMultipleFields) { | |
| 821 FormData form; | |
| 822 FormFieldData field; | |
| 823 test::CreateTestFormField( | |
| 824 "First name:", "first_name", "George", "text", &field); | |
| 825 form.fields.push_back(field); | |
| 826 test::CreateTestFormField( | |
| 827 "Last name:", "last_name", "Washington", "text", &field); | |
| 828 form.fields.push_back(field); | |
| 829 test::CreateTestFormField( | |
| 830 "Phone #:", "home_phone_area_code", "650", "text", &field); | |
| 831 field.max_length = 3; | |
| 832 form.fields.push_back(field); | |
| 833 test::CreateTestFormField( | |
| 834 "Phone #:", "home_phone_prefix", "555", "text", &field); | |
| 835 field.max_length = 3; | |
| 836 form.fields.push_back(field); | |
| 837 test::CreateTestFormField( | |
| 838 "Phone #:", "home_phone_suffix", "0000", "text", &field); | |
| 839 field.max_length = 4; | |
| 840 form.fields.push_back(field); | |
| 841 test::CreateTestFormField( | |
| 842 "Address:", "address1", "21 Laussat St", "text", &field); | |
| 843 form.fields.push_back(field); | |
| 844 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 845 form.fields.push_back(field); | |
| 846 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 847 form.fields.push_back(field); | |
| 848 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 849 form.fields.push_back(field); | |
| 850 FormStructure form_structure(form, std::string()); | |
| 851 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 852 const CreditCard* imported_credit_card; | |
| 853 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | |
| 854 &imported_credit_card)); | |
| 855 ASSERT_FALSE(imported_credit_card); | |
| 856 | |
| 857 // Verify that the web database has been updated and the notification sent. | |
| 858 EXPECT_CALL(personal_data_observer_, | |
| 859 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 860 base::MessageLoop::current()->Run(); | |
| 861 | |
| 862 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | |
| 863 test::SetProfileInfo(&expected, "George", NULL, | |
| 864 "Washington", NULL, NULL, "21 Laussat St", NULL, | |
| 865 "San Francisco", "California", "94102", NULL, "(650) 555-0000"); | |
| 866 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | |
| 867 ASSERT_EQ(1U, results.size()); | |
| 868 EXPECT_EQ(0, expected.Compare(*results[0])); | |
| 869 } | |
| 870 | |
| 871 TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) { | |
| 872 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | |
| 873 credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John")); | |
| 874 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | |
| 875 credit_card1.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul")); | |
| 876 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); | |
| 877 credit_card2.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ringo")); | |
| 878 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com"); | |
| 879 credit_card3.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Other")); | |
| 880 CreditCard credit_card4(base::GenerateGUID(), "https://www.example.com"); | |
| 881 credit_card4.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ozzy")); | |
| 882 CreditCard credit_card5(base::GenerateGUID(), "https://www.example.com"); | |
| 883 credit_card5.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Dio")); | |
| 884 | |
| 885 // Add the test credit cards to the database. | |
| 886 personal_data_->AddCreditCard(credit_card0); | |
| 887 personal_data_->AddCreditCard(credit_card1); | |
| 888 personal_data_->AddCreditCard(credit_card2); | |
| 889 personal_data_->AddCreditCard(credit_card3); | |
| 890 personal_data_->AddCreditCard(credit_card4); | |
| 891 personal_data_->AddCreditCard(credit_card5); | |
| 892 | |
| 893 // Reset the PersonalDataManager. This tests that the personal data was saved | |
| 894 // to the web database, and that we can load the credit cards from the web | |
| 895 // database. | |
| 896 ResetPersonalDataManager(); | |
| 897 | |
| 898 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | |
| 899 ASSERT_EQ(6U, results.size()); | |
| 900 EXPECT_EQ(credit_card0.guid(), results[0]->guid()); | |
| 901 EXPECT_EQ(credit_card1.guid(), results[1]->guid()); | |
| 902 EXPECT_EQ(credit_card2.guid(), results[2]->guid()); | |
| 903 EXPECT_EQ(credit_card3.guid(), results[3]->guid()); | |
| 904 EXPECT_EQ(credit_card4.guid(), results[4]->guid()); | |
| 905 EXPECT_EQ(credit_card5.guid(), results[5]->guid()); | |
| 906 } | |
| 907 | |
| 908 TEST_F(PersonalDataManagerTest, AggregateTwoDifferentProfiles) { | |
| 909 FormData form1; | |
| 910 FormFieldData field; | |
| 911 test::CreateTestFormField( | |
| 912 "First name:", "first_name", "George", "text", &field); | |
| 913 form1.fields.push_back(field); | |
| 914 test::CreateTestFormField( | |
| 915 "Last name:", "last_name", "Washington", "text", &field); | |
| 916 form1.fields.push_back(field); | |
| 917 test::CreateTestFormField( | |
| 918 "Email:", "email", "theprez@gmail.com", "text", &field); | |
| 919 form1.fields.push_back(field); | |
| 920 test::CreateTestFormField( | |
| 921 "Address:", "address1", "21 Laussat St", "text", &field); | |
| 922 form1.fields.push_back(field); | |
| 923 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 924 form1.fields.push_back(field); | |
| 925 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 926 form1.fields.push_back(field); | |
| 927 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 928 form1.fields.push_back(field); | |
| 929 | |
| 930 FormStructure form_structure1(form1, std::string()); | |
| 931 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 932 const CreditCard* imported_credit_card; | |
| 933 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | |
| 934 &imported_credit_card)); | |
| 935 ASSERT_FALSE(imported_credit_card); | |
| 936 | |
| 937 // Verify that the web database has been updated and the notification sent. | |
| 938 EXPECT_CALL(personal_data_observer_, | |
| 939 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 940 base::MessageLoop::current()->Run(); | |
| 941 | |
| 942 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | |
| 943 test::SetProfileInfo(&expected, "George", NULL, | |
| 944 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, | |
| 945 "San Francisco", "California", "94102", NULL, NULL); | |
| 946 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | |
| 947 ASSERT_EQ(1U, results1.size()); | |
| 948 EXPECT_EQ(0, expected.Compare(*results1[0])); | |
| 949 | |
| 950 // Now create a completely different profile. | |
| 951 FormData form2; | |
| 952 test::CreateTestFormField( | |
| 953 "First name:", "first_name", "John", "text", &field); | |
| 954 form2.fields.push_back(field); | |
| 955 test::CreateTestFormField( | |
| 956 "Last name:", "last_name", "Adams", "text", &field); | |
| 957 form2.fields.push_back(field); | |
| 958 test::CreateTestFormField( | |
| 959 "Email:", "email", "second@gmail.com", "text", &field); | |
| 960 form2.fields.push_back(field); | |
| 961 test::CreateTestFormField( | |
| 962 "Address:", "address1", "22 Laussat St", "text", &field); | |
| 963 form2.fields.push_back(field); | |
| 964 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 965 form2.fields.push_back(field); | |
| 966 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 967 form2.fields.push_back(field); | |
| 968 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 969 form2.fields.push_back(field); | |
| 970 | |
| 971 FormStructure form_structure2(form2, std::string()); | |
| 972 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 973 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | |
| 974 &imported_credit_card)); | |
| 975 ASSERT_FALSE(imported_credit_card); | |
| 976 | |
| 977 // Verify that the web database has been updated and the notification sent. | |
| 978 EXPECT_CALL(personal_data_observer_, | |
| 979 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 980 base::MessageLoop::current()->Run(); | |
| 981 | |
| 982 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | |
| 983 | |
| 984 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); | |
| 985 test::SetProfileInfo(&expected2, "John", NULL, | |
| 986 "Adams", "second@gmail.com", NULL, "22 Laussat St", NULL, | |
| 987 "San Francisco", "California", "94102", NULL, NULL); | |
| 988 ASSERT_EQ(2U, results2.size()); | |
| 989 EXPECT_EQ(0, expected.Compare(*results2[0])); | |
| 990 EXPECT_EQ(0, expected2.Compare(*results2[1])); | |
| 991 } | |
| 992 | |
| 993 TEST_F(PersonalDataManagerTest, AggregateTwoProfilesWithMultiValue) { | |
| 994 FormData form1; | |
| 995 FormFieldData field; | |
| 996 test::CreateTestFormField( | |
| 997 "First name:", "first_name", "George", "text", &field); | |
| 998 form1.fields.push_back(field); | |
| 999 test::CreateTestFormField( | |
| 1000 "Last name:", "last_name", "Washington", "text", &field); | |
| 1001 form1.fields.push_back(field); | |
| 1002 test::CreateTestFormField( | |
| 1003 "Email:", "email", "theprez@gmail.com", "text", &field); | |
| 1004 form1.fields.push_back(field); | |
| 1005 test::CreateTestFormField( | |
| 1006 "Address:", "address1", "21 Laussat St", "text", &field); | |
| 1007 form1.fields.push_back(field); | |
| 1008 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 1009 form1.fields.push_back(field); | |
| 1010 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 1011 form1.fields.push_back(field); | |
| 1012 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 1013 form1.fields.push_back(field); | |
| 1014 | |
| 1015 FormStructure form_structure1(form1, std::string()); | |
| 1016 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1017 const CreditCard* imported_credit_card; | |
| 1018 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | |
| 1019 &imported_credit_card)); | |
| 1020 ASSERT_FALSE(imported_credit_card); | |
| 1021 | |
| 1022 // Verify that the web database has been updated and the notification sent. | |
| 1023 EXPECT_CALL(personal_data_observer_, | |
| 1024 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1025 base::MessageLoop::current()->Run(); | |
| 1026 | |
| 1027 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | |
| 1028 test::SetProfileInfo(&expected, "George", NULL, | |
| 1029 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, | |
| 1030 "San Francisco", "California", "94102", NULL, NULL); | |
| 1031 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | |
| 1032 ASSERT_EQ(1U, results1.size()); | |
| 1033 EXPECT_EQ(0, expected.Compare(*results1[0])); | |
| 1034 | |
| 1035 // Now create a completely different profile. | |
| 1036 FormData form2; | |
| 1037 test::CreateTestFormField( | |
| 1038 "First name:", "first_name", "John", "text", &field); | |
| 1039 form2.fields.push_back(field); | |
| 1040 test::CreateTestFormField("Last name:", "last_name", "Adams", "text", &field); | |
| 1041 form2.fields.push_back(field); | |
| 1042 test::CreateTestFormField( | |
| 1043 "Email:", "email", "second@gmail.com", "text", &field); | |
| 1044 form2.fields.push_back(field); | |
| 1045 test::CreateTestFormField( | |
| 1046 "Address:", "address1", "21 Laussat St", "text", &field); | |
| 1047 form2.fields.push_back(field); | |
| 1048 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 1049 form2.fields.push_back(field); | |
| 1050 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 1051 form2.fields.push_back(field); | |
| 1052 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 1053 form2.fields.push_back(field); | |
| 1054 | |
| 1055 FormStructure form_structure2(form2, std::string()); | |
| 1056 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1057 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | |
| 1058 &imported_credit_card)); | |
| 1059 ASSERT_FALSE(imported_credit_card); | |
| 1060 | |
| 1061 // Verify that the web database has been updated and the notification sent. | |
| 1062 EXPECT_CALL(personal_data_observer_, | |
| 1063 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1064 base::MessageLoop::current()->Run(); | |
| 1065 | |
| 1066 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | |
| 1067 | |
| 1068 // Modify expected to include multi-valued fields. | |
| 1069 std::vector<base::string16> values; | |
| 1070 expected.GetRawMultiInfo(NAME_FULL, &values); | |
| 1071 values.push_back(ASCIIToUTF16("John Adams")); | |
| 1072 expected.SetRawMultiInfo(NAME_FULL, values); | |
| 1073 expected.GetRawMultiInfo(EMAIL_ADDRESS, &values); | |
| 1074 values.push_back(ASCIIToUTF16("second@gmail.com")); | |
| 1075 expected.SetRawMultiInfo(EMAIL_ADDRESS, values); | |
| 1076 | |
| 1077 ASSERT_EQ(1U, results2.size()); | |
| 1078 EXPECT_EQ(0, expected.Compare(*results2[0])); | |
| 1079 } | |
| 1080 | |
| 1081 TEST_F(PersonalDataManagerTest, AggregateSameProfileWithConflict) { | |
| 1082 FormData form1; | |
| 1083 FormFieldData field; | |
| 1084 test::CreateTestFormField( | |
| 1085 "First name:", "first_name", "George", "text", &field); | |
| 1086 form1.fields.push_back(field); | |
| 1087 test::CreateTestFormField( | |
| 1088 "Last name:", "last_name", "Washington", "text", &field); | |
| 1089 form1.fields.push_back(field); | |
| 1090 test::CreateTestFormField( | |
| 1091 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field); | |
| 1092 form1.fields.push_back(field); | |
| 1093 test::CreateTestFormField( | |
| 1094 "Address Line 2:", "address2", "Suite A", "text", &field); | |
| 1095 form1.fields.push_back(field); | |
| 1096 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 1097 form1.fields.push_back(field); | |
| 1098 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 1099 form1.fields.push_back(field); | |
| 1100 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 1101 form1.fields.push_back(field); | |
| 1102 test::CreateTestFormField( | |
| 1103 "Email:", "email", "theprez@gmail.com", "text", &field); | |
| 1104 form1.fields.push_back(field); | |
| 1105 test::CreateTestFormField("Phone:", "phone", "6505556666", "text", &field); | |
| 1106 form1.fields.push_back(field); | |
| 1107 | |
| 1108 FormStructure form_structure1(form1, std::string()); | |
| 1109 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1110 const CreditCard* imported_credit_card; | |
| 1111 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | |
| 1112 &imported_credit_card)); | |
| 1113 ASSERT_FALSE(imported_credit_card); | |
| 1114 | |
| 1115 // Verify that the web database has been updated and the notification sent. | |
| 1116 EXPECT_CALL(personal_data_observer_, | |
| 1117 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1118 base::MessageLoop::current()->Run(); | |
| 1119 | |
| 1120 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | |
| 1121 test::SetProfileInfo( | |
| 1122 &expected, "George", NULL, "Washington", "theprez@gmail.com", NULL, | |
| 1123 "1600 Pennsylvania Avenue", "Suite A", "San Francisco", "California", | |
| 1124 "94102", NULL, "(650) 555-6666"); | |
| 1125 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | |
| 1126 ASSERT_EQ(1U, results1.size()); | |
| 1127 EXPECT_EQ(0, expected.Compare(*results1[0])); | |
| 1128 | |
| 1129 // Now create an updated profile. | |
| 1130 FormData form2; | |
| 1131 test::CreateTestFormField( | |
| 1132 "First name:", "first_name", "George", "text", &field); | |
| 1133 form2.fields.push_back(field); | |
| 1134 test::CreateTestFormField( | |
| 1135 "Last name:", "last_name", "Washington", "text", &field); | |
| 1136 form2.fields.push_back(field); | |
| 1137 test::CreateTestFormField( | |
| 1138 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field); | |
| 1139 form2.fields.push_back(field); | |
| 1140 test::CreateTestFormField( | |
| 1141 "Address Line 2:", "address2", "Suite A", "text", &field); | |
| 1142 form2.fields.push_back(field); | |
| 1143 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 1144 form2.fields.push_back(field); | |
| 1145 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 1146 form2.fields.push_back(field); | |
| 1147 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 1148 form2.fields.push_back(field); | |
| 1149 test::CreateTestFormField( | |
| 1150 "Email:", "email", "theprez@gmail.com", "text", &field); | |
| 1151 form2.fields.push_back(field); | |
| 1152 // Country gets added. | |
| 1153 test::CreateTestFormField("Country:", "country", "USA", "text", &field); | |
| 1154 form2.fields.push_back(field); | |
| 1155 // Phone gets updated. | |
| 1156 test::CreateTestFormField("Phone:", "phone", "6502231234", "text", &field); | |
| 1157 form2.fields.push_back(field); | |
| 1158 | |
| 1159 FormStructure form_structure2(form2, std::string()); | |
| 1160 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1161 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | |
| 1162 &imported_credit_card)); | |
| 1163 ASSERT_FALSE(imported_credit_card); | |
| 1164 | |
| 1165 // Verify that the web database has been updated and the notification sent. | |
| 1166 EXPECT_CALL(personal_data_observer_, | |
| 1167 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1168 base::MessageLoop::current()->Run(); | |
| 1169 | |
| 1170 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | |
| 1171 | |
| 1172 // Add multi-valued phone number to expectation. Also, country gets added. | |
| 1173 std::vector<base::string16> values; | |
| 1174 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); | |
| 1175 values.push_back(ASCIIToUTF16("(650) 223-1234")); | |
| 1176 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); | |
| 1177 expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); | |
| 1178 ASSERT_EQ(1U, results2.size()); | |
| 1179 EXPECT_EQ(0, expected.Compare(*results2[0])); | |
| 1180 } | |
| 1181 | |
| 1182 TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInOld) { | |
| 1183 FormData form1; | |
| 1184 FormFieldData field; | |
| 1185 test::CreateTestFormField( | |
| 1186 "First name:", "first_name", "George", "text", &field); | |
| 1187 form1.fields.push_back(field); | |
| 1188 test::CreateTestFormField( | |
| 1189 "Last name:", "last_name", "Washington", "text", &field); | |
| 1190 form1.fields.push_back(field); | |
| 1191 test::CreateTestFormField( | |
| 1192 "Address Line 1:", "address", "190 High Street", "text", &field); | |
| 1193 form1.fields.push_back(field); | |
| 1194 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); | |
| 1195 form1.fields.push_back(field); | |
| 1196 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field); | |
| 1197 form1.fields.push_back(field); | |
| 1198 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); | |
| 1199 form1.fields.push_back(field); | |
| 1200 | |
| 1201 FormStructure form_structure1(form1, std::string()); | |
| 1202 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1203 const CreditCard* imported_credit_card; | |
| 1204 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | |
| 1205 &imported_credit_card)); | |
| 1206 EXPECT_FALSE(imported_credit_card); | |
| 1207 | |
| 1208 // Verify that the web database has been updated and the notification sent. | |
| 1209 EXPECT_CALL(personal_data_observer_, | |
| 1210 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1211 base::MessageLoop::current()->Run(); | |
| 1212 | |
| 1213 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | |
| 1214 test::SetProfileInfo(&expected, "George", NULL, | |
| 1215 "Washington", NULL, NULL, "190 High Street", NULL, | |
| 1216 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); | |
| 1217 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | |
| 1218 ASSERT_EQ(1U, results1.size()); | |
| 1219 EXPECT_EQ(0, expected.Compare(*results1[0])); | |
| 1220 | |
| 1221 // Submit a form with new data for the first profile. | |
| 1222 FormData form2; | |
| 1223 test::CreateTestFormField( | |
| 1224 "First name:", "first_name", "George", "text", &field); | |
| 1225 form2.fields.push_back(field); | |
| 1226 test::CreateTestFormField( | |
| 1227 "Last name:", "last_name", "Washington", "text", &field); | |
| 1228 form2.fields.push_back(field); | |
| 1229 test::CreateTestFormField( | |
| 1230 "Email:", "email", "theprez@gmail.com", "text", &field); | |
| 1231 form2.fields.push_back(field); | |
| 1232 test::CreateTestFormField( | |
| 1233 "Address Line 1:", "address", "190 High Street", "text", &field); | |
| 1234 form2.fields.push_back(field); | |
| 1235 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); | |
| 1236 form2.fields.push_back(field); | |
| 1237 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field); | |
| 1238 form2.fields.push_back(field); | |
| 1239 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); | |
| 1240 form2.fields.push_back(field); | |
| 1241 | |
| 1242 FormStructure form_structure2(form2, std::string()); | |
| 1243 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1244 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | |
| 1245 &imported_credit_card)); | |
| 1246 ASSERT_FALSE(imported_credit_card); | |
| 1247 | |
| 1248 // Verify that the web database has been updated and the notification sent. | |
| 1249 EXPECT_CALL(personal_data_observer_, | |
| 1250 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1251 base::MessageLoop::current()->Run(); | |
| 1252 | |
| 1253 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | |
| 1254 | |
| 1255 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); | |
| 1256 test::SetProfileInfo(&expected2, "George", NULL, | |
| 1257 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL, | |
| 1258 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); | |
| 1259 ASSERT_EQ(1U, results2.size()); | |
| 1260 EXPECT_EQ(0, expected2.Compare(*results2[0])); | |
| 1261 } | |
| 1262 | |
| 1263 TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInNew) { | |
| 1264 FormData form1; | |
| 1265 FormFieldData field; | |
| 1266 test::CreateTestFormField( | |
| 1267 "First name:", "first_name", "George", "text", &field); | |
| 1268 form1.fields.push_back(field); | |
| 1269 test::CreateTestFormField( | |
| 1270 "Last name:", "last_name", "Washington", "text", &field); | |
| 1271 form1.fields.push_back(field); | |
| 1272 test::CreateTestFormField( | |
| 1273 "Company:", "company", "Government", "text", &field); | |
| 1274 form1.fields.push_back(field); | |
| 1275 test::CreateTestFormField( | |
| 1276 "Email:", "email", "theprez@gmail.com", "text", &field); | |
| 1277 form1.fields.push_back(field); | |
| 1278 test::CreateTestFormField( | |
| 1279 "Address Line 1:", "address", "190 High Street", "text", &field); | |
| 1280 form1.fields.push_back(field); | |
| 1281 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); | |
| 1282 form1.fields.push_back(field); | |
| 1283 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field); | |
| 1284 form1.fields.push_back(field); | |
| 1285 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); | |
| 1286 form1.fields.push_back(field); | |
| 1287 | |
| 1288 FormStructure form_structure1(form1, std::string()); | |
| 1289 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1290 const CreditCard* imported_credit_card; | |
| 1291 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | |
| 1292 &imported_credit_card)); | |
| 1293 ASSERT_FALSE(imported_credit_card); | |
| 1294 | |
| 1295 // Verify that the web database has been updated and the notification sent. | |
| 1296 EXPECT_CALL(personal_data_observer_, | |
| 1297 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1298 base::MessageLoop::current()->Run(); | |
| 1299 | |
| 1300 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | |
| 1301 test::SetProfileInfo(&expected, "George", NULL, | |
| 1302 "Washington", "theprez@gmail.com", "Government", "190 High Street", NULL, | |
| 1303 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); | |
| 1304 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | |
| 1305 ASSERT_EQ(1U, results1.size()); | |
| 1306 EXPECT_EQ(0, expected.Compare(*results1[0])); | |
| 1307 | |
| 1308 // Submit a form with new data for the first profile. | |
| 1309 FormData form2; | |
| 1310 test::CreateTestFormField( | |
| 1311 "First name:", "first_name", "George", "text", &field); | |
| 1312 form2.fields.push_back(field); | |
| 1313 test::CreateTestFormField( | |
| 1314 "Last name:", "last_name", "Washington", "text", &field); | |
| 1315 form2.fields.push_back(field); | |
| 1316 // Note missing Company field. | |
| 1317 test::CreateTestFormField( | |
| 1318 "Email:", "email", "theprez@gmail.com", "text", &field); | |
| 1319 form2.fields.push_back(field); | |
| 1320 test::CreateTestFormField( | |
| 1321 "Address Line 1:", "address", "190 High Street", "text", &field); | |
| 1322 form2.fields.push_back(field); | |
| 1323 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); | |
| 1324 form2.fields.push_back(field); | |
| 1325 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field); | |
| 1326 form2.fields.push_back(field); | |
| 1327 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); | |
| 1328 form2.fields.push_back(field); | |
| 1329 | |
| 1330 FormStructure form_structure2(form2, std::string()); | |
| 1331 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1332 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | |
| 1333 &imported_credit_card)); | |
| 1334 ASSERT_FALSE(imported_credit_card); | |
| 1335 | |
| 1336 // Verify that the web database has been updated and the notification sent. | |
| 1337 EXPECT_CALL(personal_data_observer_, | |
| 1338 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1339 base::MessageLoop::current()->Run(); | |
| 1340 | |
| 1341 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | |
| 1342 | |
| 1343 // Expect no change. | |
| 1344 ASSERT_EQ(1U, results2.size()); | |
| 1345 EXPECT_EQ(0, expected.Compare(*results2[0])); | |
| 1346 } | |
| 1347 | |
| 1348 TEST_F(PersonalDataManagerTest, AggregateProfileWithInsufficientAddress) { | |
| 1349 FormData form1; | |
| 1350 FormFieldData field; | |
| 1351 test::CreateTestFormField( | |
| 1352 "First name:", "first_name", "George", "text", &field); | |
| 1353 form1.fields.push_back(field); | |
| 1354 test::CreateTestFormField( | |
| 1355 "Last name:", "last_name", "Washington", "text", &field); | |
| 1356 form1.fields.push_back(field); | |
| 1357 test::CreateTestFormField( | |
| 1358 "Company:", "company", "Government", "text", &field); | |
| 1359 form1.fields.push_back(field); | |
| 1360 test::CreateTestFormField( | |
| 1361 "Email:", "email", "theprez@gmail.com", "text", &field); | |
| 1362 form1.fields.push_back(field); | |
| 1363 test::CreateTestFormField( | |
| 1364 "Address Line 1:", "address", "190 High Street", "text", &field); | |
| 1365 form1.fields.push_back(field); | |
| 1366 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); | |
| 1367 form1.fields.push_back(field); | |
| 1368 | |
| 1369 FormStructure form_structure1(form1, std::string()); | |
| 1370 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1371 const CreditCard* imported_credit_card; | |
| 1372 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, | |
| 1373 &imported_credit_card)); | |
| 1374 ASSERT_FALSE(imported_credit_card); | |
| 1375 | |
| 1376 // Since no refresh is expected, reload the data from the database to make | |
| 1377 // sure no changes were written out. | |
| 1378 ResetPersonalDataManager(); | |
| 1379 | |
| 1380 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | |
| 1381 ASSERT_EQ(0U, profiles.size()); | |
| 1382 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); | |
| 1383 ASSERT_EQ(0U, cards.size()); | |
| 1384 } | |
| 1385 | |
| 1386 TEST_F(PersonalDataManagerTest, AggregateExistingAuxiliaryProfile) { | |
| 1387 // Simulate having access to an auxiliary profile. | |
| 1388 // |auxiliary_profile| will be owned by |personal_data_|. | |
| 1389 AutofillProfile* auxiliary_profile = | |
| 1390 new AutofillProfile(base::GenerateGUID(), "https://www.example.com"); | |
| 1391 test::SetProfileInfo(auxiliary_profile, | |
| 1392 "Tester", "Frederick", "McAddressBookTesterson", | |
| 1393 "tester@example.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco", | |
| 1394 "CA", "94102", "US", "1.415.888.9999"); | |
| 1395 ScopedVector<AutofillProfile>& auxiliary_profiles = | |
| 1396 personal_data_->auxiliary_profiles_; | |
| 1397 auxiliary_profiles.push_back(auxiliary_profile); | |
| 1398 | |
| 1399 // Simulate a form submission with a subset of the info. | |
| 1400 // Note that the phone number format is different from the saved format. | |
| 1401 FormData form; | |
| 1402 FormFieldData field; | |
| 1403 test::CreateTestFormField( | |
| 1404 "First name:", "first_name", "Tester", "text", &field); | |
| 1405 form.fields.push_back(field); | |
| 1406 test::CreateTestFormField( | |
| 1407 "Last name:", "last_name", "McAddressBookTesterson", "text", &field); | |
| 1408 form.fields.push_back(field); | |
| 1409 test::CreateTestFormField( | |
| 1410 "Email:", "email", "tester@example.com", "text", &field); | |
| 1411 form.fields.push_back(field); | |
| 1412 test::CreateTestFormField("Address:", "address1", "1 Main", "text", &field); | |
| 1413 form.fields.push_back(field); | |
| 1414 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 1415 form.fields.push_back(field); | |
| 1416 test::CreateTestFormField("State:", "state", "CA", "text", &field); | |
| 1417 form.fields.push_back(field); | |
| 1418 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 1419 form.fields.push_back(field); | |
| 1420 test::CreateTestFormField("Phone:", "phone", "4158889999", "text", &field); | |
| 1421 form.fields.push_back(field); | |
| 1422 | |
| 1423 FormStructure form_structure(form, std::string()); | |
| 1424 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1425 const CreditCard* imported_credit_card; | |
| 1426 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | |
| 1427 &imported_credit_card)); | |
| 1428 EXPECT_FALSE(imported_credit_card); | |
| 1429 | |
| 1430 // Note: No refresh. | |
| 1431 | |
| 1432 // Expect no change. | |
| 1433 const std::vector<AutofillProfile*>& web_profiles = | |
| 1434 personal_data_->web_profiles(); | |
| 1435 EXPECT_EQ(0U, web_profiles.size()); | |
| 1436 ASSERT_EQ(1U, auxiliary_profiles.size()); | |
| 1437 EXPECT_EQ(0, auxiliary_profile->Compare(*auxiliary_profiles[0])); | |
| 1438 } | |
| 1439 | |
| 1440 TEST_F(PersonalDataManagerTest, AggregateTwoDifferentCreditCards) { | |
| 1441 FormData form1; | |
| 1442 | |
| 1443 // Start with a single valid credit card form. | |
| 1444 FormFieldData field; | |
| 1445 test::CreateTestFormField( | |
| 1446 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | |
| 1447 form1.fields.push_back(field); | |
| 1448 test::CreateTestFormField( | |
| 1449 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); | |
| 1450 form1.fields.push_back(field); | |
| 1451 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | |
| 1452 form1.fields.push_back(field); | |
| 1453 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); | |
| 1454 form1.fields.push_back(field); | |
| 1455 | |
| 1456 FormStructure form_structure1(form1, std::string()); | |
| 1457 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1458 const CreditCard* imported_credit_card; | |
| 1459 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | |
| 1460 &imported_credit_card)); | |
| 1461 ASSERT_TRUE(imported_credit_card); | |
| 1462 personal_data_->SaveImportedCreditCard(*imported_credit_card); | |
| 1463 delete imported_credit_card; | |
| 1464 | |
| 1465 // Verify that the web database has been updated and the notification sent. | |
| 1466 EXPECT_CALL(personal_data_observer_, | |
| 1467 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1468 base::MessageLoop::current()->Run(); | |
| 1469 | |
| 1470 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | |
| 1471 test::SetCreditCardInfo(&expected, | |
| 1472 "Biggie Smalls", "4111111111111111", "01", "2011"); | |
| 1473 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | |
| 1474 ASSERT_EQ(1U, results.size()); | |
| 1475 EXPECT_EQ(0, expected.Compare(*results[0])); | |
| 1476 | |
| 1477 // Add a second different valid credit card. | |
| 1478 FormData form2; | |
| 1479 test::CreateTestFormField( | |
| 1480 "Name on card:", "name_on_card", "", "text", &field); | |
| 1481 form2.fields.push_back(field); | |
| 1482 test::CreateTestFormField( | |
| 1483 "Card Number:", "card_number", "5500 0000 0000 0004", "text", &field); | |
| 1484 form2.fields.push_back(field); | |
| 1485 test::CreateTestFormField("Exp Month:", "exp_month", "02", "text", &field); | |
| 1486 form2.fields.push_back(field); | |
| 1487 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); | |
| 1488 form2.fields.push_back(field); | |
| 1489 | |
| 1490 FormStructure form_structure2(form2, std::string()); | |
| 1491 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1492 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | |
| 1493 &imported_credit_card)); | |
| 1494 ASSERT_TRUE(imported_credit_card); | |
| 1495 personal_data_->SaveImportedCreditCard(*imported_credit_card); | |
| 1496 delete imported_credit_card; | |
| 1497 | |
| 1498 // Verify that the web database has been updated and the notification sent. | |
| 1499 EXPECT_CALL(personal_data_observer_, | |
| 1500 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1501 base::MessageLoop::current()->Run(); | |
| 1502 | |
| 1503 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | |
| 1504 test::SetCreditCardInfo(&expected2,"", "5500000000000004", "02", "2012"); | |
| 1505 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | |
| 1506 ASSERT_EQ(2U, results2.size()); | |
| 1507 EXPECT_EQ(0, expected.Compare(*results2[0])); | |
| 1508 EXPECT_EQ(0, expected2.Compare(*results2[1])); | |
| 1509 } | |
| 1510 | |
| 1511 TEST_F(PersonalDataManagerTest, AggregateInvalidCreditCard) { | |
| 1512 FormData form1; | |
| 1513 | |
| 1514 // Start with a single valid credit card form. | |
| 1515 FormFieldData field; | |
| 1516 test::CreateTestFormField( | |
| 1517 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | |
| 1518 form1.fields.push_back(field); | |
| 1519 test::CreateTestFormField( | |
| 1520 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); | |
| 1521 form1.fields.push_back(field); | |
| 1522 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | |
| 1523 form1.fields.push_back(field); | |
| 1524 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); | |
| 1525 form1.fields.push_back(field); | |
| 1526 | |
| 1527 FormStructure form_structure1(form1, std::string()); | |
| 1528 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1529 const CreditCard* imported_credit_card; | |
| 1530 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | |
| 1531 &imported_credit_card)); | |
| 1532 ASSERT_TRUE(imported_credit_card); | |
| 1533 personal_data_->SaveImportedCreditCard(*imported_credit_card); | |
| 1534 delete imported_credit_card; | |
| 1535 | |
| 1536 // Verify that the web database has been updated and the notification sent. | |
| 1537 EXPECT_CALL(personal_data_observer_, | |
| 1538 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1539 base::MessageLoop::current()->Run(); | |
| 1540 | |
| 1541 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | |
| 1542 test::SetCreditCardInfo(&expected, | |
| 1543 "Biggie Smalls", "4111111111111111", "01", "2011"); | |
| 1544 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | |
| 1545 ASSERT_EQ(1U, results.size()); | |
| 1546 EXPECT_EQ(0, expected.Compare(*results[0])); | |
| 1547 | |
| 1548 // Add a second different invalid credit card. | |
| 1549 FormData form2; | |
| 1550 test::CreateTestFormField( | |
| 1551 "Name on card:", "name_on_card", "Jim Johansen", "text", &field); | |
| 1552 form2.fields.push_back(field); | |
| 1553 test::CreateTestFormField( | |
| 1554 "Card Number:", "card_number", "1000000000000000", "text", &field); | |
| 1555 form2.fields.push_back(field); | |
| 1556 test::CreateTestFormField("Exp Month:", "exp_month", "02", "text", &field); | |
| 1557 form2.fields.push_back(field); | |
| 1558 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); | |
| 1559 form2.fields.push_back(field); | |
| 1560 | |
| 1561 FormStructure form_structure2(form2, std::string()); | |
| 1562 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1563 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, | |
| 1564 &imported_credit_card)); | |
| 1565 ASSERT_FALSE(imported_credit_card); | |
| 1566 | |
| 1567 // Since no refresh is expected, reload the data from the database to make | |
| 1568 // sure no changes were written out. | |
| 1569 ResetPersonalDataManager(); | |
| 1570 | |
| 1571 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | |
| 1572 ASSERT_EQ(1U, results2.size()); | |
| 1573 EXPECT_EQ(0, expected.Compare(*results2[0])); | |
| 1574 } | |
| 1575 | |
| 1576 TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) { | |
| 1577 FormData form1; | |
| 1578 | |
| 1579 // Start with a single valid credit card form. | |
| 1580 FormFieldData field; | |
| 1581 test::CreateTestFormField( | |
| 1582 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | |
| 1583 form1.fields.push_back(field); | |
| 1584 test::CreateTestFormField( | |
| 1585 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); | |
| 1586 form1.fields.push_back(field); | |
| 1587 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | |
| 1588 form1.fields.push_back(field); | |
| 1589 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); | |
| 1590 form1.fields.push_back(field); | |
| 1591 | |
| 1592 FormStructure form_structure1(form1, std::string()); | |
| 1593 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1594 const CreditCard* imported_credit_card; | |
| 1595 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | |
| 1596 &imported_credit_card)); | |
| 1597 ASSERT_TRUE(imported_credit_card); | |
| 1598 personal_data_->SaveImportedCreditCard(*imported_credit_card); | |
| 1599 delete imported_credit_card; | |
| 1600 | |
| 1601 // Verify that the web database has been updated and the notification sent. | |
| 1602 EXPECT_CALL(personal_data_observer_, | |
| 1603 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1604 base::MessageLoop::current()->Run(); | |
| 1605 | |
| 1606 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | |
| 1607 test::SetCreditCardInfo(&expected, | |
| 1608 "Biggie Smalls", "4111111111111111", "01", "2011"); | |
| 1609 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | |
| 1610 ASSERT_EQ(1U, results.size()); | |
| 1611 EXPECT_EQ(0, expected.Compare(*results[0])); | |
| 1612 | |
| 1613 // Add a second different valid credit card where the year is different but | |
| 1614 // the credit card number matches. | |
| 1615 FormData form2; | |
| 1616 test::CreateTestFormField( | |
| 1617 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | |
| 1618 form2.fields.push_back(field); | |
| 1619 test::CreateTestFormField( | |
| 1620 "Card Number:", "card_number", "4111 1111 1111 1111", "text", &field); | |
| 1621 form2.fields.push_back(field); | |
| 1622 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | |
| 1623 form2.fields.push_back(field); | |
| 1624 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); | |
| 1625 form2.fields.push_back(field); | |
| 1626 | |
| 1627 FormStructure form_structure2(form2, std::string()); | |
| 1628 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1629 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | |
| 1630 &imported_credit_card)); | |
| 1631 EXPECT_FALSE(imported_credit_card); | |
| 1632 | |
| 1633 // Verify that the web database has been updated and the notification sent. | |
| 1634 EXPECT_CALL(personal_data_observer_, | |
| 1635 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1636 base::MessageLoop::current()->Run(); | |
| 1637 | |
| 1638 // Expect that the newer information is saved. In this case the year is | |
| 1639 // updated to "2012". | |
| 1640 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | |
| 1641 test::SetCreditCardInfo(&expected2, | |
| 1642 "Biggie Smalls", "4111111111111111", "01", "2012"); | |
| 1643 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | |
| 1644 ASSERT_EQ(1U, results2.size()); | |
| 1645 EXPECT_EQ(0, expected2.Compare(*results2[0])); | |
| 1646 } | |
| 1647 | |
| 1648 TEST_F(PersonalDataManagerTest, AggregateEmptyCreditCardWithConflict) { | |
| 1649 FormData form1; | |
| 1650 | |
| 1651 // Start with a single valid credit card form. | |
| 1652 FormFieldData field; | |
| 1653 test::CreateTestFormField( | |
| 1654 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | |
| 1655 form1.fields.push_back(field); | |
| 1656 test::CreateTestFormField( | |
| 1657 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); | |
| 1658 form1.fields.push_back(field); | |
| 1659 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | |
| 1660 form1.fields.push_back(field); | |
| 1661 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); | |
| 1662 form1.fields.push_back(field); | |
| 1663 | |
| 1664 FormStructure form_structure1(form1, std::string()); | |
| 1665 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1666 const CreditCard* imported_credit_card; | |
| 1667 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | |
| 1668 &imported_credit_card)); | |
| 1669 ASSERT_TRUE(imported_credit_card); | |
| 1670 personal_data_->SaveImportedCreditCard(*imported_credit_card); | |
| 1671 delete imported_credit_card; | |
| 1672 | |
| 1673 // Verify that the web database has been updated and the notification sent. | |
| 1674 EXPECT_CALL(personal_data_observer_, | |
| 1675 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1676 base::MessageLoop::current()->Run(); | |
| 1677 | |
| 1678 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | |
| 1679 test::SetCreditCardInfo(&expected, | |
| 1680 "Biggie Smalls", "4111111111111111", "01", "2011"); | |
| 1681 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | |
| 1682 ASSERT_EQ(1U, results.size()); | |
| 1683 EXPECT_EQ(0, expected.Compare(*results[0])); | |
| 1684 | |
| 1685 // Add a second credit card with no number. | |
| 1686 FormData form2; | |
| 1687 test::CreateTestFormField( | |
| 1688 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | |
| 1689 form2.fields.push_back(field); | |
| 1690 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | |
| 1691 form2.fields.push_back(field); | |
| 1692 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); | |
| 1693 form2.fields.push_back(field); | |
| 1694 | |
| 1695 FormStructure form_structure2(form2, std::string()); | |
| 1696 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1697 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, | |
| 1698 &imported_credit_card)); | |
| 1699 EXPECT_FALSE(imported_credit_card); | |
| 1700 | |
| 1701 // Since no refresh is expected, reload the data from the database to make | |
| 1702 // sure no changes were written out. | |
| 1703 ResetPersonalDataManager(); | |
| 1704 | |
| 1705 // No change is expected. | |
| 1706 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | |
| 1707 test::SetCreditCardInfo(&expected2, | |
| 1708 "Biggie Smalls", "4111111111111111", "01", "2011"); | |
| 1709 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | |
| 1710 ASSERT_EQ(1U, results2.size()); | |
| 1711 EXPECT_EQ(0, expected2.Compare(*results2[0])); | |
| 1712 } | |
| 1713 | |
| 1714 TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInNew) { | |
| 1715 FormData form1; | |
| 1716 | |
| 1717 // Start with a single valid credit card form. | |
| 1718 FormFieldData field; | |
| 1719 test::CreateTestFormField( | |
| 1720 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | |
| 1721 form1.fields.push_back(field); | |
| 1722 test::CreateTestFormField( | |
| 1723 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); | |
| 1724 form1.fields.push_back(field); | |
| 1725 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | |
| 1726 form1.fields.push_back(field); | |
| 1727 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); | |
| 1728 form1.fields.push_back(field); | |
| 1729 | |
| 1730 FormStructure form_structure1(form1, std::string()); | |
| 1731 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1732 const CreditCard* imported_credit_card; | |
| 1733 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | |
| 1734 &imported_credit_card)); | |
| 1735 ASSERT_TRUE(imported_credit_card); | |
| 1736 personal_data_->SaveImportedCreditCard(*imported_credit_card); | |
| 1737 delete imported_credit_card; | |
| 1738 | |
| 1739 // Verify that the web database has been updated and the notification sent. | |
| 1740 EXPECT_CALL(personal_data_observer_, | |
| 1741 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1742 base::MessageLoop::current()->Run(); | |
| 1743 | |
| 1744 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | |
| 1745 test::SetCreditCardInfo(&expected, | |
| 1746 "Biggie Smalls", "4111111111111111", "01", "2011"); | |
| 1747 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | |
| 1748 ASSERT_EQ(1U, results.size()); | |
| 1749 EXPECT_EQ(0, expected.Compare(*results[0])); | |
| 1750 | |
| 1751 // Add a second different valid credit card where the name is missing but | |
| 1752 // the credit card number matches. | |
| 1753 FormData form2; | |
| 1754 // Note missing name. | |
| 1755 test::CreateTestFormField( | |
| 1756 "Card Number:", "card_number", "4111111111111111", "text", &field); | |
| 1757 form2.fields.push_back(field); | |
| 1758 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | |
| 1759 form2.fields.push_back(field); | |
| 1760 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); | |
| 1761 form2.fields.push_back(field); | |
| 1762 | |
| 1763 FormStructure form_structure2(form2, std::string()); | |
| 1764 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1765 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | |
| 1766 &imported_credit_card)); | |
| 1767 EXPECT_FALSE(imported_credit_card); | |
| 1768 | |
| 1769 // Since no refresh is expected, reload the data from the database to make | |
| 1770 // sure no changes were written out. | |
| 1771 ResetPersonalDataManager(); | |
| 1772 | |
| 1773 // No change is expected. | |
| 1774 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | |
| 1775 test::SetCreditCardInfo(&expected2, | |
| 1776 "Biggie Smalls", "4111111111111111", "01", "2011"); | |
| 1777 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | |
| 1778 ASSERT_EQ(1U, results2.size()); | |
| 1779 EXPECT_EQ(0, expected2.Compare(*results2[0])); | |
| 1780 | |
| 1781 // Add a third credit card where the expiration date is missing. | |
| 1782 FormData form3; | |
| 1783 test::CreateTestFormField( | |
| 1784 "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field); | |
| 1785 form3.fields.push_back(field); | |
| 1786 test::CreateTestFormField( | |
| 1787 "Card Number:", "card_number", "5555555555554444", "text", &field); | |
| 1788 form3.fields.push_back(field); | |
| 1789 // Note missing expiration month and year.. | |
| 1790 | |
| 1791 FormStructure form_structure3(form3, std::string()); | |
| 1792 form_structure3.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1793 EXPECT_FALSE(personal_data_->ImportFormData(form_structure3, | |
| 1794 &imported_credit_card)); | |
| 1795 ASSERT_FALSE(imported_credit_card); | |
| 1796 | |
| 1797 // Since no refresh is expected, reload the data from the database to make | |
| 1798 // sure no changes were written out. | |
| 1799 ResetPersonalDataManager(); | |
| 1800 | |
| 1801 // No change is expected. | |
| 1802 CreditCard expected3(base::GenerateGUID(), "https://www.example.com"); | |
| 1803 test::SetCreditCardInfo(&expected3, | |
| 1804 "Biggie Smalls", "4111111111111111", "01", "2011"); | |
| 1805 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); | |
| 1806 ASSERT_EQ(1U, results3.size()); | |
| 1807 EXPECT_EQ(0, expected3.Compare(*results3[0])); | |
| 1808 } | |
| 1809 | |
| 1810 TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInOld) { | |
| 1811 // Start with a single valid credit card stored via the preferences. | |
| 1812 // Note the empty name. | |
| 1813 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); | |
| 1814 test::SetCreditCardInfo(&saved_credit_card, | |
| 1815 "", "4111111111111111" /* Visa */, "01", "2011"); | |
| 1816 personal_data_->AddCreditCard(saved_credit_card); | |
| 1817 | |
| 1818 // Verify that the web database has been updated and the notification sent. | |
| 1819 EXPECT_CALL(personal_data_observer_, | |
| 1820 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1821 base::MessageLoop::current()->Run(); | |
| 1822 | |
| 1823 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); | |
| 1824 ASSERT_EQ(1U, results1.size()); | |
| 1825 EXPECT_EQ(saved_credit_card, *results1[0]); | |
| 1826 | |
| 1827 | |
| 1828 // Add a second different valid credit card where the year is different but | |
| 1829 // the credit card number matches. | |
| 1830 FormData form; | |
| 1831 FormFieldData field; | |
| 1832 test::CreateTestFormField( | |
| 1833 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | |
| 1834 form.fields.push_back(field); | |
| 1835 test::CreateTestFormField( | |
| 1836 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); | |
| 1837 form.fields.push_back(field); | |
| 1838 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | |
| 1839 form.fields.push_back(field); | |
| 1840 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); | |
| 1841 form.fields.push_back(field); | |
| 1842 | |
| 1843 FormStructure form_structure(form, std::string()); | |
| 1844 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1845 const CreditCard* imported_credit_card; | |
| 1846 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | |
| 1847 &imported_credit_card)); | |
| 1848 EXPECT_FALSE(imported_credit_card); | |
| 1849 | |
| 1850 // Verify that the web database has been updated and the notification sent. | |
| 1851 EXPECT_CALL(personal_data_observer_, | |
| 1852 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1853 base::MessageLoop::current()->Run(); | |
| 1854 | |
| 1855 // Expect that the newer information is saved. In this case the year is | |
| 1856 // added to the existing credit card. | |
| 1857 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | |
| 1858 test::SetCreditCardInfo(&expected2, | |
| 1859 "Biggie Smalls", "4111111111111111", "01", "2012"); | |
| 1860 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | |
| 1861 ASSERT_EQ(1U, results2.size()); | |
| 1862 EXPECT_EQ(0, expected2.Compare(*results2[0])); | |
| 1863 } | |
| 1864 | |
| 1865 // We allow the user to store a credit card number with separators via the UI. | |
| 1866 // We should not try to re-aggregate the same card with the separators stripped. | |
| 1867 TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithSeparators) { | |
| 1868 // Start with a single valid credit card stored via the preferences. | |
| 1869 // Note the separators in the credit card number. | |
| 1870 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); | |
| 1871 test::SetCreditCardInfo(&saved_credit_card, | |
| 1872 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); | |
| 1873 personal_data_->AddCreditCard(saved_credit_card); | |
| 1874 | |
| 1875 // Verify that the web database has been updated and the notification sent. | |
| 1876 EXPECT_CALL(personal_data_observer_, | |
| 1877 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1878 base::MessageLoop::current()->Run(); | |
| 1879 | |
| 1880 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); | |
| 1881 ASSERT_EQ(1U, results1.size()); | |
| 1882 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); | |
| 1883 | |
| 1884 // Import the same card info, but with different separators in the number. | |
| 1885 FormData form; | |
| 1886 FormFieldData field; | |
| 1887 test::CreateTestFormField( | |
| 1888 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | |
| 1889 form.fields.push_back(field); | |
| 1890 test::CreateTestFormField( | |
| 1891 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); | |
| 1892 form.fields.push_back(field); | |
| 1893 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | |
| 1894 form.fields.push_back(field); | |
| 1895 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); | |
| 1896 form.fields.push_back(field); | |
| 1897 | |
| 1898 FormStructure form_structure(form, std::string()); | |
| 1899 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1900 const CreditCard* imported_credit_card; | |
| 1901 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | |
| 1902 &imported_credit_card)); | |
| 1903 EXPECT_FALSE(imported_credit_card); | |
| 1904 | |
| 1905 // Since no refresh is expected, reload the data from the database to make | |
| 1906 // sure no changes were written out. | |
| 1907 ResetPersonalDataManager(); | |
| 1908 | |
| 1909 // Expect that no new card is saved. | |
| 1910 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | |
| 1911 ASSERT_EQ(1U, results2.size()); | |
| 1912 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); | |
| 1913 } | |
| 1914 | |
| 1915 // Ensure that if a verified profile already exists, aggregated profiles cannot | |
| 1916 // modify it in any way. | |
| 1917 TEST_F(PersonalDataManagerTest, AggregateExistingVerifiedProfileWithConflict) { | |
| 1918 // Start with a verified profile. | |
| 1919 AutofillProfile profile(base::GenerateGUID(), "Chrome settings"); | |
| 1920 test::SetProfileInfo(&profile, | |
| 1921 "Marion", "Mitchell", "Morrison", | |
| 1922 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | |
| 1923 "91601", "US", "12345678910"); | |
| 1924 EXPECT_TRUE(profile.IsVerified()); | |
| 1925 | |
| 1926 // Add the profile to the database. | |
| 1927 personal_data_->AddProfile(profile); | |
| 1928 | |
| 1929 // Verify that the web database has been updated and the notification sent. | |
| 1930 EXPECT_CALL(personal_data_observer_, | |
| 1931 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1932 base::MessageLoop::current()->Run(); | |
| 1933 | |
| 1934 // Simulate a form submission with conflicting info. | |
| 1935 FormData form; | |
| 1936 FormFieldData field; | |
| 1937 test::CreateTestFormField( | |
| 1938 "First name:", "first_name", "Marion", "text", &field); | |
| 1939 form.fields.push_back(field); | |
| 1940 test::CreateTestFormField( | |
| 1941 "Last name:", "last_name", "Morrison", "text", &field); | |
| 1942 form.fields.push_back(field); | |
| 1943 test::CreateTestFormField( | |
| 1944 "Email:", "email", "other.email@example.com", "text", &field); | |
| 1945 form.fields.push_back(field); | |
| 1946 test::CreateTestFormField( | |
| 1947 "Address:", "address1", "123 Zoo St.", "text", &field); | |
| 1948 form.fields.push_back(field); | |
| 1949 test::CreateTestFormField("City:", "city", "Hollywood", "text", &field); | |
| 1950 form.fields.push_back(field); | |
| 1951 test::CreateTestFormField("State:", "state", "CA", "text", &field); | |
| 1952 form.fields.push_back(field); | |
| 1953 test::CreateTestFormField("Zip:", "zip", "91601", "text", &field); | |
| 1954 form.fields.push_back(field); | |
| 1955 | |
| 1956 FormStructure form_structure(form, std::string()); | |
| 1957 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 1958 const CreditCard* imported_credit_card; | |
| 1959 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | |
| 1960 &imported_credit_card)); | |
| 1961 EXPECT_FALSE(imported_credit_card); | |
| 1962 | |
| 1963 // Wait for the refresh, which in this case is a no-op. | |
| 1964 EXPECT_CALL(personal_data_observer_, | |
| 1965 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1966 base::MessageLoop::current()->Run(); | |
| 1967 | |
| 1968 // Expect that no new profile is saved. | |
| 1969 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | |
| 1970 ASSERT_EQ(1U, results.size()); | |
| 1971 EXPECT_EQ(0, profile.Compare(*results[0])); | |
| 1972 } | |
| 1973 | |
| 1974 // Ensure that if a verified credit card already exists, aggregated credit cards | |
| 1975 // cannot modify it in any way. | |
| 1976 TEST_F(PersonalDataManagerTest, | |
| 1977 AggregateExistingVerifiedCreditCardWithConflict) { | |
| 1978 // Start with a verified credit card. | |
| 1979 CreditCard credit_card(base::GenerateGUID(), "Chrome settings"); | |
| 1980 test::SetCreditCardInfo(&credit_card, | |
| 1981 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); | |
| 1982 EXPECT_TRUE(credit_card.IsVerified()); | |
| 1983 | |
| 1984 // Add the credit card to the database. | |
| 1985 personal_data_->AddCreditCard(credit_card); | |
| 1986 | |
| 1987 // Verify that the web database has been updated and the notification sent. | |
| 1988 EXPECT_CALL(personal_data_observer_, | |
| 1989 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 1990 base::MessageLoop::current()->Run(); | |
| 1991 | |
| 1992 // Simulate a form submission with conflicting expiration year. | |
| 1993 FormData form; | |
| 1994 FormFieldData field; | |
| 1995 test::CreateTestFormField( | |
| 1996 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | |
| 1997 form.fields.push_back(field); | |
| 1998 test::CreateTestFormField( | |
| 1999 "Card Number:", "card_number", "4111 1111 1111 1111", "text", &field); | |
| 2000 form.fields.push_back(field); | |
| 2001 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | |
| 2002 form.fields.push_back(field); | |
| 2003 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); | |
| 2004 form.fields.push_back(field); | |
| 2005 | |
| 2006 FormStructure form_structure(form, std::string()); | |
| 2007 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 2008 const CreditCard* imported_credit_card; | |
| 2009 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | |
| 2010 &imported_credit_card)); | |
| 2011 ASSERT_FALSE(imported_credit_card); | |
| 2012 | |
| 2013 // Since no refresh is expected, reload the data from the database to make | |
| 2014 // sure no changes were written out. | |
| 2015 ResetPersonalDataManager(); | |
| 2016 | |
| 2017 // Expect that the saved credit card is not modified. | |
| 2018 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | |
| 2019 ASSERT_EQ(1U, results.size()); | |
| 2020 EXPECT_EQ(0, credit_card.Compare(*results[0])); | |
| 2021 } | |
| 2022 | |
| 2023 // Ensure that verified profiles can be saved via SaveImportedProfile, | |
| 2024 // overwriting existing unverified profiles. | |
| 2025 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithVerifiedData) { | |
| 2026 // Start with an unverified profile. | |
| 2027 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); | |
| 2028 test::SetProfileInfo(&profile, | |
| 2029 "Marion", "Mitchell", "Morrison", | |
| 2030 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | |
| 2031 "91601", "US", "12345678910"); | |
| 2032 EXPECT_FALSE(profile.IsVerified()); | |
| 2033 | |
| 2034 // Add the profile to the database. | |
| 2035 personal_data_->AddProfile(profile); | |
| 2036 | |
| 2037 // Verify that the web database has been updated and the notification sent. | |
| 2038 EXPECT_CALL(personal_data_observer_, | |
| 2039 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 2040 base::MessageLoop::current()->Run(); | |
| 2041 | |
| 2042 AutofillProfile new_verified_profile = profile; | |
| 2043 new_verified_profile.set_guid(base::GenerateGUID()); | |
| 2044 new_verified_profile.set_origin("Chrome settings"); | |
| 2045 new_verified_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Fizzbang, Inc.")); | |
| 2046 EXPECT_TRUE(new_verified_profile.IsVerified()); | |
| 2047 | |
| 2048 personal_data_->SaveImportedProfile(new_verified_profile); | |
| 2049 | |
| 2050 // Verify that the web database has been updated and the notification sent. | |
| 2051 EXPECT_CALL(personal_data_observer_, | |
| 2052 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 2053 base::MessageLoop::current()->Run(); | |
| 2054 | |
| 2055 // Expect that the existing profile is not modified, and instead the new | |
| 2056 // profile is added. | |
| 2057 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | |
| 2058 ASSERT_EQ(1U, results.size()); | |
| 2059 EXPECT_EQ(0, new_verified_profile.Compare(*results[0])); | |
| 2060 } | |
| 2061 | |
| 2062 // Ensure that verified profiles can be saved via SaveImportedProfile, | |
| 2063 // overwriting existing verified profiles as well. | |
| 2064 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithExistingVerifiedData) { | |
| 2065 // Start with a verified profile. | |
| 2066 AutofillProfile profile(base::GenerateGUID(), "Chrome settings"); | |
| 2067 test::SetProfileInfo(&profile, | |
| 2068 "Marion", "Mitchell", "Morrison", | |
| 2069 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | |
| 2070 "91601", "US", "12345678910"); | |
| 2071 EXPECT_TRUE(profile.IsVerified()); | |
| 2072 | |
| 2073 // Add the profile to the database. | |
| 2074 personal_data_->AddProfile(profile); | |
| 2075 | |
| 2076 // Verify that the web database has been updated and the notification sent. | |
| 2077 EXPECT_CALL(personal_data_observer_, | |
| 2078 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 2079 base::MessageLoop::current()->Run(); | |
| 2080 | |
| 2081 AutofillProfile new_verified_profile = profile; | |
| 2082 new_verified_profile.set_guid(base::GenerateGUID()); | |
| 2083 new_verified_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Fizzbang, Inc.")); | |
| 2084 new_verified_profile.SetRawInfo(NAME_MIDDLE, base::string16()); | |
| 2085 EXPECT_TRUE(new_verified_profile.IsVerified()); | |
| 2086 | |
| 2087 personal_data_->SaveImportedProfile(new_verified_profile); | |
| 2088 | |
| 2089 // Verify that the web database has been updated and the notification sent. | |
| 2090 EXPECT_CALL(personal_data_observer_, | |
| 2091 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 2092 base::MessageLoop::current()->Run(); | |
| 2093 | |
| 2094 // The new profile should be merged into the existing one. | |
| 2095 AutofillProfile expected_profile = new_verified_profile; | |
| 2096 expected_profile.set_guid(profile.guid()); | |
| 2097 std::vector<base::string16> names; | |
| 2098 expected_profile.GetRawMultiInfo(NAME_FULL, &names); | |
| 2099 names.insert(names.begin(), ASCIIToUTF16("Marion Mitchell Morrison")); | |
| 2100 expected_profile.SetRawMultiInfo(NAME_FULL, names); | |
| 2101 | |
| 2102 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | |
| 2103 ASSERT_EQ(1U, results.size()); | |
| 2104 EXPECT_EQ(expected_profile, *results[0]); | |
| 2105 } | |
| 2106 | |
| 2107 // Ensure that verified credit cards can be saved via SaveImportedCreditCard. | |
| 2108 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) { | |
| 2109 // Start with a verified credit card. | |
| 2110 CreditCard credit_card(base::GenerateGUID(), "Chrome settings"); | |
| 2111 test::SetCreditCardInfo(&credit_card, | |
| 2112 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); | |
| 2113 EXPECT_TRUE(credit_card.IsVerified()); | |
| 2114 | |
| 2115 // Add the credit card to the database. | |
| 2116 personal_data_->AddCreditCard(credit_card); | |
| 2117 | |
| 2118 // Verify that the web database has been updated and the notification sent. | |
| 2119 EXPECT_CALL(personal_data_observer_, | |
| 2120 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 2121 base::MessageLoop::current()->Run(); | |
| 2122 | |
| 2123 CreditCard new_verified_card = credit_card; | |
| 2124 new_verified_card.set_guid(base::GenerateGUID()); | |
| 2125 new_verified_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("B. Small")); | |
| 2126 EXPECT_TRUE(new_verified_card.IsVerified()); | |
| 2127 | |
| 2128 personal_data_->SaveImportedCreditCard(new_verified_card); | |
| 2129 | |
| 2130 // Verify that the web database has been updated and the notification sent. | |
| 2131 EXPECT_CALL(personal_data_observer_, | |
| 2132 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 2133 base::MessageLoop::current()->Run(); | |
| 2134 | |
| 2135 // Expect that the saved credit card is updated. | |
| 2136 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | |
| 2137 ASSERT_EQ(1U, results.size()); | |
| 2138 EXPECT_EQ(ASCIIToUTF16("B. Small"), results[0]->GetRawInfo(CREDIT_CARD_NAME)); | |
| 2139 } | |
| 2140 | |
| 2141 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) { | |
| 2142 // Check that there are no available types with no profiles stored. | |
| 2143 FieldTypeSet non_empty_types; | |
| 2144 personal_data_->GetNonEmptyTypes(&non_empty_types); | |
| 2145 EXPECT_EQ(0U, non_empty_types.size()); | |
| 2146 | |
| 2147 // Test with one profile stored. | |
| 2148 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | |
| 2149 test::SetProfileInfo(&profile0, | |
| 2150 "Marion", NULL, "Morrison", | |
| 2151 "johnwayne@me.xyz", NULL, "123 Zoo St.", NULL, "Hollywood", "CA", | |
| 2152 "91601", "US", "14155678910"); | |
| 2153 | |
| 2154 personal_data_->AddProfile(profile0); | |
| 2155 | |
| 2156 // Verify that the web database has been updated and the notification sent. | |
| 2157 EXPECT_CALL(personal_data_observer_, | |
| 2158 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 2159 base::MessageLoop::current()->Run(); | |
| 2160 | |
| 2161 personal_data_->GetNonEmptyTypes(&non_empty_types); | |
| 2162 EXPECT_EQ(14U, non_empty_types.size()); | |
| 2163 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); | |
| 2164 EXPECT_TRUE(non_empty_types.count(NAME_LAST)); | |
| 2165 EXPECT_TRUE(non_empty_types.count(NAME_FULL)); | |
| 2166 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); | |
| 2167 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1)); | |
| 2168 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY)); | |
| 2169 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE)); | |
| 2170 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP)); | |
| 2171 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY)); | |
| 2172 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER)); | |
| 2173 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE)); | |
| 2174 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE)); | |
| 2175 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER)); | |
| 2176 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER)); | |
| 2177 | |
| 2178 // Test with multiple profiles stored. | |
| 2179 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | |
| 2180 test::SetProfileInfo(&profile1, | |
| 2181 "Josephine", "Alicia", "Saenz", | |
| 2182 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", | |
| 2183 "US", "16502937549"); | |
| 2184 | |
| 2185 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | |
| 2186 test::SetProfileInfo(&profile2, | |
| 2187 "Josephine", "Alicia", "Saenz", | |
| 2188 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | |
| 2189 "32801", "US", "16502937549"); | |
| 2190 | |
| 2191 personal_data_->AddProfile(profile1); | |
| 2192 personal_data_->AddProfile(profile2); | |
| 2193 | |
| 2194 // Verify that the web database has been updated and the notification sent. | |
| 2195 EXPECT_CALL(personal_data_observer_, | |
| 2196 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 2197 base::MessageLoop::current()->Run(); | |
| 2198 | |
| 2199 personal_data_->GetNonEmptyTypes(&non_empty_types); | |
| 2200 EXPECT_EQ(18U, non_empty_types.size()); | |
| 2201 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); | |
| 2202 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE)); | |
| 2203 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL)); | |
| 2204 EXPECT_TRUE(non_empty_types.count(NAME_LAST)); | |
| 2205 EXPECT_TRUE(non_empty_types.count(NAME_FULL)); | |
| 2206 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); | |
| 2207 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME)); | |
| 2208 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1)); | |
| 2209 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE2)); | |
| 2210 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY)); | |
| 2211 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE)); | |
| 2212 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP)); | |
| 2213 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY)); | |
| 2214 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER)); | |
| 2215 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE)); | |
| 2216 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE)); | |
| 2217 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER)); | |
| 2218 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER)); | |
| 2219 | |
| 2220 // Test with credit card information also stored. | |
| 2221 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); | |
| 2222 test::SetCreditCardInfo(&credit_card, | |
| 2223 "John Dillinger", "423456789012" /* Visa */, | |
| 2224 "01", "2010"); | |
| 2225 personal_data_->AddCreditCard(credit_card); | |
| 2226 | |
| 2227 // Verify that the web database has been updated and the notification sent. | |
| 2228 EXPECT_CALL(personal_data_observer_, | |
| 2229 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 2230 base::MessageLoop::current()->Run(); | |
| 2231 | |
| 2232 personal_data_->GetNonEmptyTypes(&non_empty_types); | |
| 2233 EXPECT_EQ(25U, non_empty_types.size()); | |
| 2234 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); | |
| 2235 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE)); | |
| 2236 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL)); | |
| 2237 EXPECT_TRUE(non_empty_types.count(NAME_LAST)); | |
| 2238 EXPECT_TRUE(non_empty_types.count(NAME_FULL)); | |
| 2239 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); | |
| 2240 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME)); | |
| 2241 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1)); | |
| 2242 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE2)); | |
| 2243 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY)); | |
| 2244 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE)); | |
| 2245 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP)); | |
| 2246 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY)); | |
| 2247 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER)); | |
| 2248 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE)); | |
| 2249 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE)); | |
| 2250 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER)); | |
| 2251 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER)); | |
| 2252 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_NAME)); | |
| 2253 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_NUMBER)); | |
| 2254 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_MONTH)); | |
| 2255 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_2_DIGIT_YEAR)); | |
| 2256 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)); | |
| 2257 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)); | |
| 2258 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR)); | |
| 2259 } | |
| 2260 | |
| 2261 TEST_F(PersonalDataManagerTest, CaseInsensitiveMultiValueAggregation) { | |
| 2262 FormData form1; | |
| 2263 FormFieldData field; | |
| 2264 test::CreateTestFormField( | |
| 2265 "First name:", "first_name", "George", "text", &field); | |
| 2266 form1.fields.push_back(field); | |
| 2267 test::CreateTestFormField( | |
| 2268 "Last name:", "last_name", "Washington", "text", &field); | |
| 2269 form1.fields.push_back(field); | |
| 2270 test::CreateTestFormField( | |
| 2271 "Email:", "email", "theprez@gmail.com", "text", &field); | |
| 2272 form1.fields.push_back(field); | |
| 2273 test::CreateTestFormField( | |
| 2274 "Address:", "address1", "21 Laussat St", "text", &field); | |
| 2275 form1.fields.push_back(field); | |
| 2276 test::CreateTestFormField( | |
| 2277 "City:", "city", "San Francisco", "text", &field); | |
| 2278 form1.fields.push_back(field); | |
| 2279 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 2280 form1.fields.push_back(field); | |
| 2281 test::CreateTestFormField( | |
| 2282 "Zip:", "zip", "94102", "text", &field); | |
| 2283 form1.fields.push_back(field); | |
| 2284 test::CreateTestFormField( | |
| 2285 "Phone number:", "phone_number", "817-555-6789", "text", &field); | |
| 2286 form1.fields.push_back(field); | |
| 2287 | |
| 2288 FormStructure form_structure1(form1, std::string()); | |
| 2289 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 2290 const CreditCard* imported_credit_card; | |
| 2291 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, | |
| 2292 &imported_credit_card)); | |
| 2293 ASSERT_FALSE(imported_credit_card); | |
| 2294 | |
| 2295 // Verify that the web database has been updated and the notification sent. | |
| 2296 EXPECT_CALL(personal_data_observer_, | |
| 2297 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 2298 base::MessageLoop::current()->Run(); | |
| 2299 | |
| 2300 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); | |
| 2301 test::SetProfileInfo(&expected, "George", NULL, | |
| 2302 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, | |
| 2303 "San Francisco", "California", "94102", NULL, "(817) 555-6789"); | |
| 2304 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); | |
| 2305 ASSERT_EQ(1U, results1.size()); | |
| 2306 EXPECT_EQ(0, expected.Compare(*results1[0])); | |
| 2307 | |
| 2308 // Upper-case the first name and change the phone number. | |
| 2309 FormData form2; | |
| 2310 test::CreateTestFormField( | |
| 2311 "First name:", "first_name", "GEORGE", "text", &field); | |
| 2312 form2.fields.push_back(field); | |
| 2313 test::CreateTestFormField( | |
| 2314 "Last name:", "last_name", "Washington", "text", &field); | |
| 2315 form2.fields.push_back(field); | |
| 2316 test::CreateTestFormField( | |
| 2317 "Email:", "email", "theprez@gmail.com", "text", &field); | |
| 2318 form2.fields.push_back(field); | |
| 2319 test::CreateTestFormField( | |
| 2320 "Address:", "address1", "21 Laussat St", "text", &field); | |
| 2321 form2.fields.push_back(field); | |
| 2322 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); | |
| 2323 form2.fields.push_back(field); | |
| 2324 test::CreateTestFormField("State:", "state", "California", "text", &field); | |
| 2325 form2.fields.push_back(field); | |
| 2326 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | |
| 2327 form2.fields.push_back(field); | |
| 2328 test::CreateTestFormField( | |
| 2329 "Phone number:", "phone_number", "214-555-1234", "text", &field); | |
| 2330 form2.fields.push_back(field); | |
| 2331 | |
| 2332 FormStructure form_structure2(form2, std::string()); | |
| 2333 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | |
| 2334 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, | |
| 2335 &imported_credit_card)); | |
| 2336 ASSERT_FALSE(imported_credit_card); | |
| 2337 | |
| 2338 // Verify that the web database has been updated and the notification sent. | |
| 2339 EXPECT_CALL(personal_data_observer_, | |
| 2340 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | |
| 2341 base::MessageLoop::current()->Run(); | |
| 2342 | |
| 2343 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); | |
| 2344 | |
| 2345 // Modify expected to include multi-valued fields. | |
| 2346 std::vector<base::string16> values; | |
| 2347 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); | |
| 2348 values.push_back(ASCIIToUTF16("(214) 555-1234")); | |
| 2349 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); | |
| 2350 | |
| 2351 ASSERT_EQ(1U, results2.size()); | |
| 2352 EXPECT_EQ(0, expected.Compare(*results2[0])); | |
| 2353 } | |
| 2354 | |
| 2355 TEST_F(PersonalDataManagerTest, IncognitoReadOnly) { | |
| 2356 ASSERT_TRUE(personal_data_->GetProfiles().empty()); | |
| 2357 ASSERT_TRUE(personal_data_->GetCreditCards().empty()); | |
| 2358 | |
| 2359 AutofillProfile steve_jobs(base::GenerateGUID(), "https://www.example.com"); | |
| 2360 test::SetProfileInfo(&steve_jobs, "Steven", "Paul", "Jobs", "sjobs@apple.com", | |
| 2361 "Apple Computer, Inc.", "1 Infinite Loop", "", "Cupertino", "CA", "95014", | |
| 2362 "US", "(800) 275-2273"); | |
| 2363 personal_data_->AddProfile(steve_jobs); | |
| 2364 | |
| 2365 CreditCard bill_gates(base::GenerateGUID(), "https://www.example.com"); | |
| 2366 test::SetCreditCardInfo( | |
| 2367 &bill_gates, "William H. Gates", "5555555555554444", "1", "2020"); | |
| 2368 personal_data_->AddCreditCard(bill_gates); | |
| 2369 | |
| 2370 ResetPersonalDataManager(); | |
| 2371 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); | |
| 2372 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); | |
| 2373 | |
| 2374 // After this point no adds, saves, or updates should take effect. | |
| 2375 MakeProfileIncognito(); | |
| 2376 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); | |
| 2377 | |
| 2378 // Add profiles or credit card shouldn't work. | |
| 2379 personal_data_->AddProfile(test::GetFullProfile()); | |
| 2380 | |
| 2381 CreditCard larry_page(base::GenerateGUID(), "https://www.example.com"); | |
| 2382 test::SetCreditCardInfo( | |
| 2383 &larry_page, "Lawrence Page", "4111111111111111", "10", "2025"); | |
| 2384 personal_data_->AddCreditCard(larry_page); | |
| 2385 | |
| 2386 ResetPersonalDataManager(); | |
| 2387 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); | |
| 2388 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); | |
| 2389 | |
| 2390 // Saving or creating profiles from imported profiles shouldn't work. | |
| 2391 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); | |
| 2392 personal_data_->SaveImportedProfile(steve_jobs); | |
| 2393 | |
| 2394 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); | |
| 2395 personal_data_->SaveImportedCreditCard(bill_gates); | |
| 2396 | |
| 2397 ResetPersonalDataManager(); | |
| 2398 EXPECT_EQ(ASCIIToUTF16("Steven"), | |
| 2399 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); | |
| 2400 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), | |
| 2401 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME)); | |
| 2402 | |
| 2403 // Updating existing profiles shouldn't work. | |
| 2404 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); | |
| 2405 personal_data_->UpdateProfile(steve_jobs); | |
| 2406 | |
| 2407 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); | |
| 2408 personal_data_->UpdateCreditCard(bill_gates); | |
| 2409 | |
| 2410 ResetPersonalDataManager(); | |
| 2411 EXPECT_EQ(ASCIIToUTF16("Steven"), | |
| 2412 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); | |
| 2413 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), | |
| 2414 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME)); | |
| 2415 | |
| 2416 // Removing shouldn't work. | |
| 2417 personal_data_->RemoveByGUID(steve_jobs.guid()); | |
| 2418 personal_data_->RemoveByGUID(bill_gates.guid()); | |
| 2419 | |
| 2420 ResetPersonalDataManager(); | |
| 2421 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); | |
| 2422 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); | |
| 2423 } | |
| 2424 | |
| 2425 } // namespace autofill | |
| OLD | NEW |