| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/files/scoped_temp_dir.h" | 18 #include "base/files/scoped_temp_dir.h" |
| 19 #include "base/guid.h" | 19 #include "base/guid.h" |
| 20 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 21 #include "base/metrics/field_trial.h" | 21 #include "base/metrics/field_trial.h" |
| 22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
| 25 #include "base/test/histogram_tester.h" | 25 #include "base/test/histogram_tester.h" |
| 26 #include "base/test/simple_test_clock.h" |
| 26 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| 27 #include "base/time/time.h" | 28 #include "base/time/time.h" |
| 28 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| 29 #include "components/autofill/core/browser/autofill_experiments.h" | 30 #include "components/autofill/core/browser/autofill_experiments.h" |
| 30 #include "components/autofill/core/browser/autofill_profile.h" | 31 #include "components/autofill/core/browser/autofill_profile.h" |
| 31 #include "components/autofill/core/browser/autofill_test_utils.h" | 32 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 32 #include "components/autofill/core/browser/field_types.h" | 33 #include "components/autofill/core/browser/field_types.h" |
| 33 #include "components/autofill/core/browser/form_structure.h" | 34 #include "components/autofill/core/browser/form_structure.h" |
| 34 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 35 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 36 #include "components/autofill/core/browser/test_autofill_clock.h" |
| 35 #include "components/autofill/core/browser/webdata/autofill_table.h" | 37 #include "components/autofill/core/browser/webdata/autofill_table.h" |
| 36 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 38 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| 39 #include "components/autofill/core/common/autofill_clock.h" |
| 37 #include "components/autofill/core/common/autofill_constants.h" | 40 #include "components/autofill/core/common/autofill_constants.h" |
| 38 #include "components/autofill/core/common/autofill_pref_names.h" | 41 #include "components/autofill/core/common/autofill_pref_names.h" |
| 39 #include "components/autofill/core/common/autofill_switches.h" | 42 #include "components/autofill/core/common/autofill_switches.h" |
| 40 #include "components/autofill/core/common/form_data.h" | 43 #include "components/autofill/core/common/form_data.h" |
| 41 #include "components/os_crypt/os_crypt_mocker.h" | 44 #include "components/os_crypt/os_crypt_mocker.h" |
| 42 #include "components/prefs/pref_service.h" | 45 #include "components/prefs/pref_service.h" |
| 43 #include "components/signin/core/browser/account_tracker_service.h" | 46 #include "components/signin/core/browser/account_tracker_service.h" |
| 44 #include "components/signin/core/browser/fake_signin_manager.h" | 47 #include "components/signin/core/browser/fake_signin_manager.h" |
| 45 #include "components/signin/core/browser/test_signin_client.h" | 48 #include "components/signin/core/browser/test_signin_client.h" |
| 46 #include "components/signin/core/common/signin_pref_names.h" | 49 #include "components/signin/core/common/signin_pref_names.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 59 | 62 |
| 60 enum UserMode { USER_MODE_NORMAL, USER_MODE_INCOGNITO }; | 63 enum UserMode { USER_MODE_NORMAL, USER_MODE_INCOGNITO }; |
| 61 | 64 |
| 62 const std::string kUTF8MidlineEllipsis = | 65 const std::string kUTF8MidlineEllipsis = |
| 63 " " | 66 " " |
| 64 "\xE2\x80\xA2\xE2\x80\x86" | 67 "\xE2\x80\xA2\xE2\x80\x86" |
| 65 "\xE2\x80\xA2\xE2\x80\x86" | 68 "\xE2\x80\xA2\xE2\x80\x86" |
| 66 "\xE2\x80\xA2\xE2\x80\x86" | 69 "\xE2\x80\xA2\xE2\x80\x86" |
| 67 "\xE2\x80\xA2\xE2\x80\x86"; | 70 "\xE2\x80\xA2\xE2\x80\x86"; |
| 68 | 71 |
| 72 const base::Time kArbitraryTime = base::Time::FromDoubleT(25); |
| 73 const base::Time kSomeLaterTime = base::Time::FromDoubleT(1000); |
| 74 const base::Time kMuchLaterTime = base::Time::FromDoubleT(5000); |
| 75 |
| 69 ACTION(QuitMainMessageLoop) { | 76 ACTION(QuitMainMessageLoop) { |
| 70 base::MessageLoop::current()->QuitWhenIdle(); | 77 base::MessageLoop::current()->QuitWhenIdle(); |
| 71 } | 78 } |
| 72 | 79 |
| 73 class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver { | 80 class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver { |
| 74 public: | 81 public: |
| 75 PersonalDataLoadedObserverMock() {} | 82 PersonalDataLoadedObserverMock() {} |
| 76 virtual ~PersonalDataLoadedObserverMock() {} | 83 virtual ~PersonalDataLoadedObserverMock() {} |
| 77 | 84 |
| 78 MOCK_METHOD0(OnPersonalDataChanged, void()); | 85 MOCK_METHOD0(OnPersonalDataChanged, void()); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // to test the suggestions based on name as well as on credit card number. | 263 // to test the suggestions based on name as well as on credit card number. |
| 257 void SetupReferenceLocalCreditCards() { | 264 void SetupReferenceLocalCreditCards() { |
| 258 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); | 265 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); |
| 259 | 266 |
| 260 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", | 267 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 261 "https://www.example.com"); | 268 "https://www.example.com"); |
| 262 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", | 269 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", |
| 263 "347666888555" /* American Express */, "04", | 270 "347666888555" /* American Express */, "04", |
| 264 "2999"); | 271 "2999"); |
| 265 credit_card0.set_use_count(3); | 272 credit_card0.set_use_count(3); |
| 266 credit_card0.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 273 credit_card0.set_use_date(AutofillClock::Now() - |
| 274 base::TimeDelta::FromDays(1)); |
| 267 personal_data_->AddCreditCard(credit_card0); | 275 personal_data_->AddCreditCard(credit_card0); |
| 268 | 276 |
| 269 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", | 277 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", |
| 270 "https://www.example.com"); | 278 "https://www.example.com"); |
| 271 credit_card1.set_use_count(300); | 279 credit_card1.set_use_count(300); |
| 272 credit_card1.set_use_date(base::Time::Now() - | 280 credit_card1.set_use_date(AutofillClock::Now() - |
| 273 base::TimeDelta::FromDays(10)); | 281 base::TimeDelta::FromDays(10)); |
| 274 test::SetCreditCardInfo(&credit_card1, "John Dillinger", | 282 test::SetCreditCardInfo(&credit_card1, "John Dillinger", |
| 275 "423456789012" /* Visa */, "01", "2999"); | 283 "423456789012" /* Visa */, "01", "2999"); |
| 276 personal_data_->AddCreditCard(credit_card1); | 284 personal_data_->AddCreditCard(credit_card1); |
| 277 | 285 |
| 278 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", | 286 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", |
| 279 "https://www.example.com"); | 287 "https://www.example.com"); |
| 280 credit_card2.set_use_count(1); | 288 credit_card2.set_use_count(1); |
| 281 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 289 credit_card2.set_use_date(AutofillClock::Now() - |
| 290 base::TimeDelta::FromDays(1)); |
| 282 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker", | 291 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker", |
| 283 "518765432109" /* Mastercard */, "12", "2999"); | 292 "518765432109" /* Mastercard */, "12", "2999"); |
| 284 personal_data_->AddCreditCard(credit_card2); | 293 personal_data_->AddCreditCard(credit_card2); |
| 285 | 294 |
| 286 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 295 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 287 .WillOnce(QuitMainMessageLoop()); | 296 .WillOnce(QuitMainMessageLoop()); |
| 288 base::RunLoop().Run(); | 297 base::RunLoop().Run(); |
| 289 | 298 |
| 290 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 299 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 291 } | 300 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 419 |
| 411 // Verify the addition. | 420 // Verify the addition. |
| 412 std::vector<AutofillProfile*> profiles; | 421 std::vector<AutofillProfile*> profiles; |
| 413 profiles.push_back(&profile0); | 422 profiles.push_back(&profile0); |
| 414 profiles.push_back(&profile1); | 423 profiles.push_back(&profile1); |
| 415 ExpectSameElements(profiles, personal_data_->GetProfiles()); | 424 ExpectSameElements(profiles, personal_data_->GetProfiles()); |
| 416 } | 425 } |
| 417 | 426 |
| 418 // Test that a new profile has its basic information set. | 427 // Test that a new profile has its basic information set. |
| 419 TEST_F(PersonalDataManagerTest, AddProfile_BasicInformation) { | 428 TEST_F(PersonalDataManagerTest, AddProfile_BasicInformation) { |
| 429 // Create the test clock and set the time to a specific value. |
| 430 TestAutofillClock test_clock; |
| 431 test_clock.SetNow(kArbitraryTime); |
| 432 |
| 420 // Add a profile to the database. | 433 // Add a profile to the database. |
| 421 AutofillProfile profile(test::GetFullProfile()); | 434 AutofillProfile profile(test::GetFullProfile()); |
| 422 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); | 435 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); |
| 423 personal_data_->AddProfile(profile); | 436 personal_data_->AddProfile(profile); |
| 424 | 437 |
| 425 // Reload the database. | 438 // Reload the database. |
| 426 ResetPersonalDataManager(USER_MODE_NORMAL); | 439 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 427 | 440 |
| 428 // Verify the addition. | 441 // Verify the addition. |
| 429 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); | 442 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
| 430 ASSERT_EQ(1U, results.size()); | 443 ASSERT_EQ(1U, results.size()); |
| 431 EXPECT_EQ(0, profile.Compare(*results[0])); | 444 EXPECT_EQ(0, profile.Compare(*results[0])); |
| 432 | 445 |
| 433 // Make sure the use count and use date were set. | 446 // Make sure the use count and use date were set. |
| 434 EXPECT_EQ(1U, results[0]->use_count()); | 447 EXPECT_EQ(1U, results[0]->use_count()); |
| 435 EXPECT_NE(base::Time(), results[0]->use_date()); | 448 EXPECT_EQ(kArbitraryTime, results[0]->use_date()); |
| 436 EXPECT_NE(base::Time(), results[0]->modification_date()); | 449 EXPECT_EQ(kArbitraryTime, results[0]->modification_date()); |
| 437 } | 450 } |
| 438 | 451 |
| 439 TEST_F(PersonalDataManagerTest, DontDuplicateServerProfile) { | 452 TEST_F(PersonalDataManagerTest, DontDuplicateServerProfile) { |
| 440 EnableWalletCardImport(); | 453 EnableWalletCardImport(); |
| 441 | 454 |
| 442 std::vector<AutofillProfile> server_profiles; | 455 std::vector<AutofillProfile> server_profiles; |
| 443 server_profiles.push_back( | 456 server_profiles.push_back( |
| 444 AutofillProfile(AutofillProfile::SERVER_PROFILE, "a123")); | 457 AutofillProfile(AutofillProfile::SERVER_PROFILE, "a123")); |
| 445 test::SetProfileInfo(&server_profiles.back(), "John", "", "Doe", "", | 458 test::SetProfileInfo(&server_profiles.back(), "John", "", "Doe", "", |
| 446 "ACME Corp", "500 Oak View", "Apt 8", "Houston", "TX", | 459 "ACME Corp", "500 Oak View", "Apt 8", "Houston", "TX", |
| 447 "77401", "US", ""); | 460 "77401", "US", ""); |
| 448 // Wallet only provides a full name, so the above first and last names | 461 // Wallet only provides a full name, so the above first and last names |
| 449 // will be ignored when the profile is written to the DB. | 462 // will be ignored when the profile is written to the DB. |
| 450 server_profiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); | 463 server_profiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); |
| 451 autofill_table_->SetServerProfiles(server_profiles); | 464 autofill_table_->SetServerProfiles(server_profiles); |
| 452 personal_data_->Refresh(); | 465 personal_data_->Refresh(); |
| 453 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 466 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 454 .WillOnce(QuitMainMessageLoop()); | 467 .WillOnce(QuitMainMessageLoop()); |
| 455 base::RunLoop().Run(); | 468 base::RunLoop().Run(); |
| 456 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); | 469 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); |
| 457 | 470 |
| 458 // Add profile with identical values. Duplicates should not get saved. | 471 // Add profile with identical values. Duplicates should not get saved. |
| 459 AutofillProfile scraped_profile(base::GenerateGUID(), | 472 AutofillProfile scraped_profile(base::GenerateGUID(), |
| 460 "https://www.example.com"); | 473 "https://www.example.com"); |
| 461 test::SetProfileInfo(&scraped_profile, "John", "", "Doe", "", "ACME Corp", | 474 test::SetProfileInfo(&scraped_profile, "John", "", "Doe", "", "ACME Corp", |
| 462 "500 Oak View", "Apt 8", "Houston", "TX", "77401", "US", | 475 "500 Oak View", "Apt 8", "Houston", "TX", "77401", "US", |
| 463 ""); | 476 ""); |
| 464 EXPECT_TRUE(scraped_profile.IsSubsetOf(server_profiles.back(), "en-US")); | 477 EXPECT_TRUE(scraped_profile.IsSubsetOf(server_profiles.back(), "en-US")); |
| 478 |
| 479 // Create the test clock and set the time to a specific value. |
| 480 TestAutofillClock test_clock; |
| 481 test_clock.SetNow(kArbitraryTime); |
| 482 |
| 465 std::string saved_guid = personal_data_->SaveImportedProfile(scraped_profile); | 483 std::string saved_guid = personal_data_->SaveImportedProfile(scraped_profile); |
| 466 EXPECT_NE(scraped_profile.guid(), saved_guid); | 484 EXPECT_NE(scraped_profile.guid(), saved_guid); |
| 467 | 485 |
| 468 personal_data_->Refresh(); | 486 personal_data_->Refresh(); |
| 469 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 487 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 470 .WillOnce(QuitMainMessageLoop()); | 488 .WillOnce(QuitMainMessageLoop()); |
| 471 base::RunLoop().Run(); | 489 base::RunLoop().Run(); |
| 472 | 490 |
| 473 // Verify the non-addition. | 491 // Verify the non-addition. |
| 474 EXPECT_EQ(0U, personal_data_->web_profiles().size()); | 492 EXPECT_EQ(0U, personal_data_->web_profiles().size()); |
| 475 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); | 493 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); |
| 476 | 494 |
| 477 // Verify that the server profile's use date was updated. | 495 // Verify that the server profile's use date was updated with the specified |
| 496 // value. |
| 478 const AutofillProfile* server_profile = personal_data_->GetProfiles()[0]; | 497 const AutofillProfile* server_profile = personal_data_->GetProfiles()[0]; |
| 479 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 498 EXPECT_EQ(kArbitraryTime, server_profile->use_date()); |
| 480 base::Time::Now() - server_profile->use_date()); | |
| 481 } | 499 } |
| 482 | 500 |
| 483 // Tests that SaveImportedProfile sets the modification date on new profiles. | 501 // Tests that SaveImportedProfile sets the modification date on new profiles. |
| 484 TEST_F(PersonalDataManagerTest, SaveImportedProfileSetModificationDate) { | 502 TEST_F(PersonalDataManagerTest, SaveImportedProfileSetModificationDate) { |
| 485 AutofillProfile profile(test::GetFullProfile()); | 503 AutofillProfile profile(test::GetFullProfile()); |
| 486 EXPECT_NE(base::Time(), profile.modification_date()); | 504 EXPECT_NE(base::Time(), profile.modification_date()); |
| 487 | 505 |
| 488 personal_data_->SaveImportedProfile(profile); | 506 personal_data_->SaveImportedProfile(profile); |
| 489 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | 507 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
| 490 ASSERT_EQ(1U, profiles.size()); | 508 ASSERT_EQ(1U, profiles.size()); |
| 491 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 509 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 492 base::Time::Now() - profiles[0]->modification_date()); | 510 AutofillClock::Now() - profiles[0]->modification_date()); |
| 493 } | 511 } |
| 494 | 512 |
| 495 TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) { | 513 TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) { |
| 496 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | 514 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); |
| 497 test::SetProfileInfo(&profile0, | 515 test::SetProfileInfo(&profile0, |
| 498 "Marion", "Mitchell", "Morrison", | 516 "Marion", "Mitchell", "Morrison", |
| 499 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 517 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 500 "91601", "US", "12345678910"); | 518 "91601", "US", "12345678910"); |
| 501 | 519 |
| 502 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 520 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 | 618 |
| 601 // Verify that we've loaded the credit cards from the web database. | 619 // Verify that we've loaded the credit cards from the web database. |
| 602 cards.clear(); | 620 cards.clear(); |
| 603 cards.push_back(&credit_card0); | 621 cards.push_back(&credit_card0); |
| 604 cards.push_back(&credit_card2); | 622 cards.push_back(&credit_card2); |
| 605 ExpectSameElements(cards, personal_data_->GetCreditCards()); | 623 ExpectSameElements(cards, personal_data_->GetCreditCards()); |
| 606 } | 624 } |
| 607 | 625 |
| 608 // Test that a new credit card has its basic information set. | 626 // Test that a new credit card has its basic information set. |
| 609 TEST_F(PersonalDataManagerTest, AddCreditCard_BasicInformation) { | 627 TEST_F(PersonalDataManagerTest, AddCreditCard_BasicInformation) { |
| 628 // Create the test clock and set the time to a specific value. |
| 629 TestAutofillClock test_clock; |
| 630 test_clock.SetNow(kArbitraryTime); |
| 631 |
| 610 // Add a credit to the database. | 632 // Add a credit to the database. |
| 611 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); | 633 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); |
| 612 test::SetCreditCardInfo(&credit_card, "John Dillinger", | 634 test::SetCreditCardInfo(&credit_card, "John Dillinger", |
| 613 "423456789012" /* Visa */, "01", "2999"); | 635 "423456789012" /* Visa */, "01", "2999"); |
| 614 personal_data_->AddCreditCard(credit_card); | 636 personal_data_->AddCreditCard(credit_card); |
| 615 | 637 |
| 616 // Reload the database. | 638 // Reload the database. |
| 617 ResetPersonalDataManager(USER_MODE_NORMAL); | 639 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 618 | 640 |
| 619 // Verify the addition. | 641 // Verify the addition. |
| 620 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 642 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 621 ASSERT_EQ(1U, results.size()); | 643 ASSERT_EQ(1U, results.size()); |
| 622 EXPECT_EQ(0, credit_card.Compare(*results[0])); | 644 EXPECT_EQ(0, credit_card.Compare(*results[0])); |
| 623 | 645 |
| 624 // Make sure the use count and use date were set. | 646 // Make sure the use count and use date were set. |
| 625 EXPECT_EQ(1U, results[0]->use_count()); | 647 EXPECT_EQ(1U, results[0]->use_count()); |
| 626 EXPECT_NE(base::Time(), results[0]->use_date()); | 648 EXPECT_EQ(kArbitraryTime, results[0]->use_date()); |
| 627 EXPECT_NE(base::Time(), results[0]->modification_date()); | 649 EXPECT_EQ(kArbitraryTime, results[0]->modification_date()); |
| 628 } | 650 } |
| 629 | 651 |
| 630 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) { | 652 TEST_F(PersonalDataManagerTest, UpdateUnverifiedProfilesAndCreditCards) { |
| 631 // Start with unverified data. | 653 // Start with unverified data. |
| 632 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); | 654 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); |
| 633 test::SetProfileInfo(&profile, | 655 test::SetProfileInfo(&profile, |
| 634 "Marion", "Mitchell", "Morrison", | 656 "Marion", "Mitchell", "Morrison", |
| 635 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 657 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 636 "91601", "US", "12345678910"); | 658 "91601", "US", "12345678910"); |
| 637 EXPECT_FALSE(profile.IsVerified()); | 659 EXPECT_FALSE(profile.IsVerified()); |
| (...skipping 2771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3409 // Tests that GetProfileSuggestions orders its suggestions based on the frecency | 3431 // Tests that GetProfileSuggestions orders its suggestions based on the frecency |
| 3410 // formula. | 3432 // formula. |
| 3411 TEST_F(PersonalDataManagerTest, GetProfileSuggestions_Ranking) { | 3433 TEST_F(PersonalDataManagerTest, GetProfileSuggestions_Ranking) { |
| 3412 // Set up the profiles. They are named with number suffixes X so the X is the | 3434 // Set up the profiles. They are named with number suffixes X so the X is the |
| 3413 // order in which they should be ordered by frecency. | 3435 // order in which they should be ordered by frecency. |
| 3414 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); | 3436 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); |
| 3415 test::SetProfileInfo(&profile3, "Marion3", "Mitchell", "Morrison", | 3437 test::SetProfileInfo(&profile3, "Marion3", "Mitchell", "Morrison", |
| 3416 "johnwayne@me.xyz", "Fox", | 3438 "johnwayne@me.xyz", "Fox", |
| 3417 "123 Zoo St.\nSecond Line\nThird line", "unit 5", | 3439 "123 Zoo St.\nSecond Line\nThird line", "unit 5", |
| 3418 "Hollywood", "CA", "91601", "US", "12345678910"); | 3440 "Hollywood", "CA", "91601", "US", "12345678910"); |
| 3419 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 3441 profile3.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); |
| 3420 profile3.set_use_count(5); | 3442 profile3.set_use_count(5); |
| 3421 personal_data_->AddProfile(profile3); | 3443 personal_data_->AddProfile(profile3); |
| 3422 | 3444 |
| 3423 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 3445 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 3424 test::SetProfileInfo(&profile1, "Marion1", "Mitchell", "Morrison", | 3446 test::SetProfileInfo(&profile1, "Marion1", "Mitchell", "Morrison", |
| 3425 "johnwayne@me.xyz", "Fox", | 3447 "johnwayne@me.xyz", "Fox", |
| 3426 "123 Zoo St.\nSecond Line\nThird line", "unit 5", | 3448 "123 Zoo St.\nSecond Line\nThird line", "unit 5", |
| 3427 "Hollywood", "CA", "91601", "US", "12345678910"); | 3449 "Hollywood", "CA", "91601", "US", "12345678910"); |
| 3428 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 3450 profile1.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); |
| 3429 profile1.set_use_count(10); | 3451 profile1.set_use_count(10); |
| 3430 personal_data_->AddProfile(profile1); | 3452 personal_data_->AddProfile(profile1); |
| 3431 | 3453 |
| 3432 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 3454 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 3433 test::SetProfileInfo(&profile2, "Marion2", "Mitchell", "Morrison", | 3455 test::SetProfileInfo(&profile2, "Marion2", "Mitchell", "Morrison", |
| 3434 "johnwayne@me.xyz", "Fox", | 3456 "johnwayne@me.xyz", "Fox", |
| 3435 "123 Zoo St.\nSecond Line\nThird line", "unit 5", | 3457 "123 Zoo St.\nSecond Line\nThird line", "unit 5", |
| 3436 "Hollywood", "CA", "91601", "US", "12345678910"); | 3458 "Hollywood", "CA", "91601", "US", "12345678910"); |
| 3437 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 3459 profile2.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(15)); |
| 3438 profile2.set_use_count(300); | 3460 profile2.set_use_count(300); |
| 3439 personal_data_->AddProfile(profile2); | 3461 personal_data_->AddProfile(profile2); |
| 3440 | 3462 |
| 3441 ResetPersonalDataManager(USER_MODE_NORMAL); | 3463 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 3442 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions( | 3464 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions( |
| 3443 AutofillType(NAME_FIRST), base::ASCIIToUTF16("Ma"), false, | 3465 AutofillType(NAME_FIRST), base::ASCIIToUTF16("Ma"), false, |
| 3444 std::vector<ServerFieldType>()); | 3466 std::vector<ServerFieldType>()); |
| 3445 ASSERT_EQ(3U, suggestions.size()); | 3467 ASSERT_EQ(3U, suggestions.size()); |
| 3446 EXPECT_EQ(suggestions[0].value, base::ASCIIToUTF16("Marion1")); | 3468 EXPECT_EQ(suggestions[0].value, base::ASCIIToUTF16("Marion1")); |
| 3447 EXPECT_EQ(suggestions[1].value, base::ASCIIToUTF16("Marion2")); | 3469 EXPECT_EQ(suggestions[1].value, base::ASCIIToUTF16("Marion2")); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3576 GetCreditCardSuggestions_LocalAndServerCardsRanking) { | 3598 GetCreditCardSuggestions_LocalAndServerCardsRanking) { |
| 3577 EnableWalletCardImport(); | 3599 EnableWalletCardImport(); |
| 3578 SetupReferenceLocalCreditCards(); | 3600 SetupReferenceLocalCreditCards(); |
| 3579 | 3601 |
| 3580 // Add some server cards. | 3602 // Add some server cards. |
| 3581 std::vector<CreditCard> server_cards; | 3603 std::vector<CreditCard> server_cards; |
| 3582 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); | 3604 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); |
| 3583 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | 3605 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", |
| 3584 "2999"); | 3606 "2999"); |
| 3585 server_cards.back().set_use_count(2); | 3607 server_cards.back().set_use_count(2); |
| 3586 server_cards.back().set_use_date(base::Time::Now() - | 3608 server_cards.back().set_use_date(AutofillClock::Now() - |
| 3587 base::TimeDelta::FromDays(1)); | 3609 base::TimeDelta::FromDays(1)); |
| 3588 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3610 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 3589 | 3611 |
| 3590 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460")); | 3612 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460")); |
| 3591 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12", | 3613 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12", |
| 3592 "2999"); | 3614 "2999"); |
| 3593 server_cards.back().set_use_count(6); | 3615 server_cards.back().set_use_count(6); |
| 3594 server_cards.back().set_use_date(base::Time::Now() - | 3616 server_cards.back().set_use_date(AutofillClock::Now() - |
| 3595 base::TimeDelta::FromDays(1)); | 3617 base::TimeDelta::FromDays(1)); |
| 3596 | 3618 |
| 3597 test::SetServerCreditCards(autofill_table_, server_cards); | 3619 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3598 personal_data_->Refresh(); | 3620 personal_data_->Refresh(); |
| 3599 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3621 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3600 .WillOnce(QuitMainMessageLoop()); | 3622 .WillOnce(QuitMainMessageLoop()); |
| 3601 base::RunLoop().Run(); | 3623 base::RunLoop().Run(); |
| 3602 | 3624 |
| 3603 std::vector<Suggestion> suggestions = | 3625 std::vector<Suggestion> suggestions = |
| 3604 personal_data_->GetCreditCardSuggestions( | 3626 personal_data_->GetCreditCardSuggestions( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3625 test::SetCreditCardInfo(&credit_card0, "Bonnie Parker", | 3647 test::SetCreditCardInfo(&credit_card0, "Bonnie Parker", |
| 3626 "518765432109" /* Mastercard */, "04", "2999"); | 3648 "518765432109" /* Mastercard */, "04", "2999"); |
| 3627 personal_data_->AddCreditCard(credit_card0); | 3649 personal_data_->AddCreditCard(credit_card0); |
| 3628 | 3650 |
| 3629 // Add an expired card with a higher frecency score. | 3651 // Add an expired card with a higher frecency score. |
| 3630 CreditCard credit_card1("287151C8-6AB1-487C-9095-28E80BE5DA15", | 3652 CreditCard credit_card1("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 3631 "https://www.example.com"); | 3653 "https://www.example.com"); |
| 3632 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", | 3654 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", |
| 3633 "347666888555" /* American Express */, "04", "1999"); | 3655 "347666888555" /* American Express */, "04", "1999"); |
| 3634 credit_card1.set_use_count(300); | 3656 credit_card1.set_use_count(300); |
| 3635 credit_card1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10)); | 3657 credit_card1.set_use_date(AutofillClock::Now() - |
| 3658 base::TimeDelta::FromDays(10)); |
| 3636 personal_data_->AddCreditCard(credit_card1); | 3659 personal_data_->AddCreditCard(credit_card1); |
| 3637 | 3660 |
| 3638 // Add an expired card with a lower frecency score. | 3661 // Add an expired card with a lower frecency score. |
| 3639 CreditCard credit_card2("1141084B-72D7-4B73-90CF-3D6AC154673B", | 3662 CreditCard credit_card2("1141084B-72D7-4B73-90CF-3D6AC154673B", |
| 3640 "https://www.example.com"); | 3663 "https://www.example.com"); |
| 3641 credit_card2.set_use_count(3); | 3664 credit_card2.set_use_count(3); |
| 3642 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 3665 credit_card2.set_use_date(AutofillClock::Now() - |
| 3666 base::TimeDelta::FromDays(1)); |
| 3643 test::SetCreditCardInfo(&credit_card2, "John Dillinger", | 3667 test::SetCreditCardInfo(&credit_card2, "John Dillinger", |
| 3644 "423456789012" /* Visa */, "01", "1998"); | 3668 "423456789012" /* Visa */, "01", "1998"); |
| 3645 personal_data_->AddCreditCard(credit_card2); | 3669 personal_data_->AddCreditCard(credit_card2); |
| 3646 | 3670 |
| 3647 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3671 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3648 .WillOnce(QuitMainMessageLoop()); | 3672 .WillOnce(QuitMainMessageLoop()); |
| 3649 base::RunLoop().Run(); | 3673 base::RunLoop().Run(); |
| 3650 | 3674 |
| 3651 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 3675 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 3652 | 3676 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3668 // when querying credit cards by their number. | 3692 // when querying credit cards by their number. |
| 3669 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) { | 3693 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) { |
| 3670 // Create one normal credit card and one credit card with the number missing. | 3694 // Create one normal credit card and one credit card with the number missing. |
| 3671 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); | 3695 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); |
| 3672 | 3696 |
| 3673 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", | 3697 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 3674 "https://www.example.com"); | 3698 "https://www.example.com"); |
| 3675 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", | 3699 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", |
| 3676 "347666888555" /* American Express */, "04", "2999"); | 3700 "347666888555" /* American Express */, "04", "2999"); |
| 3677 credit_card0.set_use_count(3); | 3701 credit_card0.set_use_count(3); |
| 3678 credit_card0.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 3702 credit_card0.set_use_date(AutofillClock::Now() - |
| 3703 base::TimeDelta::FromDays(1)); |
| 3679 personal_data_->AddCreditCard(credit_card0); | 3704 personal_data_->AddCreditCard(credit_card0); |
| 3680 | 3705 |
| 3681 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", | 3706 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", |
| 3682 "https://www.example.com"); | 3707 "https://www.example.com"); |
| 3683 credit_card1.set_use_count(300); | 3708 credit_card1.set_use_count(300); |
| 3684 credit_card1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10)); | 3709 credit_card1.set_use_date(AutofillClock::Now() - |
| 3710 base::TimeDelta::FromDays(10)); |
| 3685 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2999"); | 3711 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2999"); |
| 3686 personal_data_->AddCreditCard(credit_card1); | 3712 personal_data_->AddCreditCard(credit_card1); |
| 3687 | 3713 |
| 3688 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3714 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3689 .WillOnce(QuitMainMessageLoop()); | 3715 .WillOnce(QuitMainMessageLoop()); |
| 3690 base::RunLoop().Run(); | 3716 base::RunLoop().Run(); |
| 3691 | 3717 |
| 3692 ASSERT_EQ(2U, personal_data_->GetCreditCards().size()); | 3718 ASSERT_EQ(2U, personal_data_->GetCreditCards().size()); |
| 3693 | 3719 |
| 3694 // Sublabel is expiration date when filling card number. The second card | 3720 // Sublabel is expiration date when filling card number. The second card |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3711 // Add some server cards. If there are local dupes, the locals should be | 3737 // Add some server cards. If there are local dupes, the locals should be |
| 3712 // hidden. | 3738 // hidden. |
| 3713 std::vector<CreditCard> server_cards; | 3739 std::vector<CreditCard> server_cards; |
| 3714 // This server card matches a local card, except the local card is missing the | 3740 // This server card matches a local card, except the local card is missing the |
| 3715 // number. This should count as a dupe and thus not be shown in the | 3741 // number. This should count as a dupe and thus not be shown in the |
| 3716 // suggestions since the locally saved card takes precedence. | 3742 // suggestions since the locally saved card takes precedence. |
| 3717 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 3743 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 3718 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 3744 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 3719 "9012" /* Visa */, "01", "2999"); | 3745 "9012" /* Visa */, "01", "2999"); |
| 3720 server_cards.back().set_use_count(2); | 3746 server_cards.back().set_use_count(2); |
| 3721 server_cards.back().set_use_date(base::Time::Now() - | 3747 server_cards.back().set_use_date(AutofillClock::Now() - |
| 3722 base::TimeDelta::FromDays(15)); | 3748 base::TimeDelta::FromDays(15)); |
| 3723 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3749 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 3724 | 3750 |
| 3725 // This server card is identical to a local card, but has a different | 3751 // This server card is identical to a local card, but has a different |
| 3726 // card type. Not a dupe and therefore both should appear in the suggestions. | 3752 // card type. Not a dupe and therefore both should appear in the suggestions. |
| 3727 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); | 3753 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
| 3728 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12", | 3754 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12", |
| 3729 "2999"); | 3755 "2999"); |
| 3730 server_cards.back().set_use_count(3); | 3756 server_cards.back().set_use_count(3); |
| 3731 server_cards.back().set_use_date(base::Time::Now() - | 3757 server_cards.back().set_use_date(AutofillClock::Now() - |
| 3732 base::TimeDelta::FromDays(15)); | 3758 base::TimeDelta::FromDays(15)); |
| 3733 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3759 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 3734 | 3760 |
| 3735 // This unmasked server card is an exact dupe of a local card. Therefore only | 3761 // This unmasked server card is an exact dupe of a local card. Therefore only |
| 3736 // this card should appear in the suggestions as full server cards have | 3762 // this card should appear in the suggestions as full server cards have |
| 3737 // precedence over local cards. | 3763 // precedence over local cards. |
| 3738 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 3764 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 3739 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 3765 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 3740 "347666888555" /* American Express */, "04", "2999"); | 3766 "347666888555" /* American Express */, "04", "2999"); |
| 3741 server_cards.back().set_use_count(1); | 3767 server_cards.back().set_use_count(1); |
| 3742 server_cards.back().set_use_date(base::Time::Now() - | 3768 server_cards.back().set_use_date(AutofillClock::Now() - |
| 3743 base::TimeDelta::FromDays(15)); | 3769 base::TimeDelta::FromDays(15)); |
| 3744 | 3770 |
| 3745 test::SetServerCreditCards(autofill_table_, server_cards); | 3771 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3746 personal_data_->Refresh(); | 3772 personal_data_->Refresh(); |
| 3747 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3773 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3748 .WillOnce(QuitMainMessageLoop()); | 3774 .WillOnce(QuitMainMessageLoop()); |
| 3749 base::RunLoop().Run(); | 3775 base::RunLoop().Run(); |
| 3750 | 3776 |
| 3751 std::vector<Suggestion> suggestions = | 3777 std::vector<Suggestion> suggestions = |
| 3752 personal_data_->GetCreditCardSuggestions( | 3778 personal_data_->GetCreditCardSuggestions( |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3819 TEST_F(PersonalDataManagerTest, | 3845 TEST_F(PersonalDataManagerTest, |
| 3820 DedupeCreditCardToSuggest_FullServerShadowsLocal) { | 3846 DedupeCreditCardToSuggest_FullServerShadowsLocal) { |
| 3821 std::list<CreditCard*> credit_cards; | 3847 std::list<CreditCard*> credit_cards; |
| 3822 | 3848 |
| 3823 // Create 3 different local credit cards. | 3849 // Create 3 different local credit cards. |
| 3824 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", | 3850 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", |
| 3825 "https://www.example.com"); | 3851 "https://www.example.com"); |
| 3826 test::SetCreditCardInfo(&local_card, "Homer Simpson", | 3852 test::SetCreditCardInfo(&local_card, "Homer Simpson", |
| 3827 "423456789012" /* Visa */, "01", "2999"); | 3853 "423456789012" /* Visa */, "01", "2999"); |
| 3828 local_card.set_use_count(3); | 3854 local_card.set_use_count(3); |
| 3829 local_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 3855 local_card.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); |
| 3830 credit_cards.push_back(&local_card); | 3856 credit_cards.push_back(&local_card); |
| 3831 | 3857 |
| 3832 // Create a full server card that is a duplicate of one of the local cards. | 3858 // Create a full server card that is a duplicate of one of the local cards. |
| 3833 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789"); | 3859 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789"); |
| 3834 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", | 3860 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", |
| 3835 "423456789012" /* Visa */, "01", "2999"); | 3861 "423456789012" /* Visa */, "01", "2999"); |
| 3836 full_server_card.set_use_count(1); | 3862 full_server_card.set_use_count(1); |
| 3837 full_server_card.set_use_date(base::Time::Now() - | 3863 full_server_card.set_use_date(AutofillClock::Now() - |
| 3838 base::TimeDelta::FromDays(15)); | 3864 base::TimeDelta::FromDays(15)); |
| 3839 credit_cards.push_back(&full_server_card); | 3865 credit_cards.push_back(&full_server_card); |
| 3840 | 3866 |
| 3841 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); | 3867 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
| 3842 ASSERT_EQ(1U, credit_cards.size()); | 3868 ASSERT_EQ(1U, credit_cards.size()); |
| 3843 | 3869 |
| 3844 const CreditCard* deduped_card(credit_cards.front()); | 3870 const CreditCard* deduped_card(credit_cards.front()); |
| 3845 EXPECT_TRUE(*deduped_card == full_server_card); | 3871 EXPECT_TRUE(*deduped_card == full_server_card); |
| 3846 } | 3872 } |
| 3847 | 3873 |
| 3848 // Tests that only the local card is kept when deduping with a masked server | 3874 // Tests that only the local card is kept when deduping with a masked server |
| 3849 // duplicate of it. | 3875 // duplicate of it. |
| 3850 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_LocalShadowsMasked) { | 3876 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_LocalShadowsMasked) { |
| 3851 std::list<CreditCard*> credit_cards; | 3877 std::list<CreditCard*> credit_cards; |
| 3852 | 3878 |
| 3853 CreditCard local_card("1141084B-72D7-4B73-90CF-3D6AC154673B", | 3879 CreditCard local_card("1141084B-72D7-4B73-90CF-3D6AC154673B", |
| 3854 "https://www.example.com"); | 3880 "https://www.example.com"); |
| 3855 local_card.set_use_count(300); | 3881 local_card.set_use_count(300); |
| 3856 local_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10)); | 3882 local_card.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(10)); |
| 3857 test::SetCreditCardInfo(&local_card, "Homer Simpson", | 3883 test::SetCreditCardInfo(&local_card, "Homer Simpson", |
| 3858 "423456789012" /* Visa */, "01", "2999"); | 3884 "423456789012" /* Visa */, "01", "2999"); |
| 3859 credit_cards.push_back(&local_card); | 3885 credit_cards.push_back(&local_card); |
| 3860 | 3886 |
| 3861 // Create a masked server card that is a duplicate of a local card. | 3887 // Create a masked server card that is a duplicate of a local card. |
| 3862 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); | 3888 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); |
| 3863 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, | 3889 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, |
| 3864 "01", "2999"); | 3890 "01", "2999"); |
| 3865 masked_card.set_use_count(2); | 3891 masked_card.set_use_count(2); |
| 3866 masked_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 3892 masked_card.set_use_date(AutofillClock::Now() - |
| 3893 base::TimeDelta::FromDays(15)); |
| 3867 masked_card.SetTypeForMaskedCard(kVisaCard); | 3894 masked_card.SetTypeForMaskedCard(kVisaCard); |
| 3868 credit_cards.push_back(&masked_card); | 3895 credit_cards.push_back(&masked_card); |
| 3869 | 3896 |
| 3870 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); | 3897 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
| 3871 ASSERT_EQ(1U, credit_cards.size()); | 3898 ASSERT_EQ(1U, credit_cards.size()); |
| 3872 | 3899 |
| 3873 const CreditCard* deduped_card(credit_cards.front()); | 3900 const CreditCard* deduped_card(credit_cards.front()); |
| 3874 EXPECT_TRUE(*deduped_card == local_card); | 3901 EXPECT_TRUE(*deduped_card == local_card); |
| 3875 } | 3902 } |
| 3876 | 3903 |
| 3877 // Tests that identical full server and masked credit cards are not deduped. | 3904 // Tests that identical full server and masked credit cards are not deduped. |
| 3878 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) { | 3905 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) { |
| 3879 std::list<CreditCard*> credit_cards; | 3906 std::list<CreditCard*> credit_cards; |
| 3880 | 3907 |
| 3881 // Create a full server card that is a duplicate of one of the local cards. | 3908 // Create a full server card that is a duplicate of one of the local cards. |
| 3882 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789"); | 3909 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789"); |
| 3883 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", | 3910 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", |
| 3884 "423456789012" /* Visa */, "01", "2999"); | 3911 "423456789012" /* Visa */, "01", "2999"); |
| 3885 full_server_card.set_use_count(1); | 3912 full_server_card.set_use_count(1); |
| 3886 full_server_card.set_use_date(base::Time::Now() - | 3913 full_server_card.set_use_date(AutofillClock::Now() - |
| 3887 base::TimeDelta::FromDays(15)); | 3914 base::TimeDelta::FromDays(15)); |
| 3888 credit_cards.push_back(&full_server_card); | 3915 credit_cards.push_back(&full_server_card); |
| 3889 | 3916 |
| 3890 // Create a masked server card that is a duplicate of a local card. | 3917 // Create a masked server card that is a duplicate of a local card. |
| 3891 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); | 3918 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); |
| 3892 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, | 3919 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, |
| 3893 "01", "2999"); | 3920 "01", "2999"); |
| 3894 masked_card.set_use_count(2); | 3921 masked_card.set_use_count(2); |
| 3895 masked_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 3922 masked_card.set_use_date(AutofillClock::Now() - |
| 3923 base::TimeDelta::FromDays(15)); |
| 3896 masked_card.SetTypeForMaskedCard(kVisaCard); | 3924 masked_card.SetTypeForMaskedCard(kVisaCard); |
| 3897 credit_cards.push_back(&masked_card); | 3925 credit_cards.push_back(&masked_card); |
| 3898 | 3926 |
| 3899 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); | 3927 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
| 3900 EXPECT_EQ(2U, credit_cards.size()); | 3928 EXPECT_EQ(2U, credit_cards.size()); |
| 3901 } | 3929 } |
| 3902 | 3930 |
| 3903 // Tests that slightly different local, full server, and masked credit cards are | 3931 // Tests that slightly different local, full server, and masked credit cards are |
| 3904 // not deduped. | 3932 // not deduped. |
| 3905 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) { | 3933 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) { |
| 3906 std::list<CreditCard*> credit_cards; | 3934 std::list<CreditCard*> credit_cards; |
| 3907 | 3935 |
| 3908 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", | 3936 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", |
| 3909 "https://www.example.com"); | 3937 "https://www.example.com"); |
| 3910 credit_card2.set_use_count(1); | 3938 credit_card2.set_use_count(1); |
| 3911 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 3939 credit_card2.set_use_date(AutofillClock::Now() - |
| 3940 base::TimeDelta::FromDays(1)); |
| 3912 test::SetCreditCardInfo(&credit_card2, "Homer Simpson", | 3941 test::SetCreditCardInfo(&credit_card2, "Homer Simpson", |
| 3913 "518765432109" /* Mastercard */, "", ""); | 3942 "518765432109" /* Mastercard */, "", ""); |
| 3914 credit_cards.push_back(&credit_card2); | 3943 credit_cards.push_back(&credit_card2); |
| 3915 | 3944 |
| 3916 // Create a masked server card that is slightly different of the local card. | 3945 // Create a masked server card that is slightly different of the local card. |
| 3917 CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456"); | 3946 CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456"); |
| 3918 test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "2999"); | 3947 test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "2999"); |
| 3919 credit_card4.set_use_count(3); | 3948 credit_card4.set_use_count(3); |
| 3920 credit_card4.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 3949 credit_card4.set_use_date(AutofillClock::Now() - |
| 3950 base::TimeDelta::FromDays(15)); |
| 3921 credit_card4.SetTypeForMaskedCard(kVisaCard); | 3951 credit_card4.SetTypeForMaskedCard(kVisaCard); |
| 3922 credit_cards.push_back(&credit_card4); | 3952 credit_cards.push_back(&credit_card4); |
| 3923 | 3953 |
| 3924 // Create a full server card that is slightly different of the two other | 3954 // Create a full server card that is slightly different of the two other |
| 3925 // cards. | 3955 // cards. |
| 3926 CreditCard credit_card5(CreditCard::FULL_SERVER_CARD, "c789"); | 3956 CreditCard credit_card5(CreditCard::FULL_SERVER_CARD, "c789"); |
| 3927 test::SetCreditCardInfo(&credit_card5, "Homer Simpson", | 3957 test::SetCreditCardInfo(&credit_card5, "Homer Simpson", |
| 3928 "347666888555" /* American Express */, "04", "2999"); | 3958 "347666888555" /* American Express */, "04", "2999"); |
| 3929 credit_card5.set_use_count(1); | 3959 credit_card5.set_use_count(1); |
| 3930 credit_card5.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 3960 credit_card5.set_use_date(AutofillClock::Now() - |
| 3961 base::TimeDelta::FromDays(15)); |
| 3931 credit_cards.push_back(&credit_card5); | 3962 credit_cards.push_back(&credit_card5); |
| 3932 | 3963 |
| 3933 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); | 3964 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
| 3934 EXPECT_EQ(3U, credit_cards.size()); | 3965 EXPECT_EQ(3U, credit_cards.size()); |
| 3935 } | 3966 } |
| 3936 | 3967 |
| 3937 TEST_F(PersonalDataManagerTest, RecordUseOf) { | 3968 TEST_F(PersonalDataManagerTest, RecordUseOf) { |
| 3938 base::Time creation_time = base::Time::FromTimeT(12345); | 3969 // Create the test clock and set the time to a specific value. |
| 3970 TestAutofillClock test_clock; |
| 3971 test_clock.SetNow(kArbitraryTime); |
| 3939 | 3972 |
| 3940 AutofillProfile profile(test::GetFullProfile()); | 3973 AutofillProfile profile(test::GetFullProfile()); |
| 3941 profile.set_use_date(creation_time); | |
| 3942 profile.set_modification_date(creation_time); | |
| 3943 EXPECT_EQ(1U, profile.use_count()); | 3974 EXPECT_EQ(1U, profile.use_count()); |
| 3944 EXPECT_EQ(creation_time, profile.use_date()); | 3975 EXPECT_EQ(kArbitraryTime, profile.use_date()); |
| 3945 EXPECT_EQ(creation_time, profile.modification_date()); | 3976 EXPECT_EQ(kArbitraryTime, profile.modification_date()); |
| 3946 personal_data_->AddProfile(profile); | 3977 personal_data_->AddProfile(profile); |
| 3947 | 3978 |
| 3948 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); | 3979 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); |
| 3949 test::SetCreditCardInfo(&credit_card, "John Dillinger", | 3980 test::SetCreditCardInfo(&credit_card, "John Dillinger", |
| 3950 "423456789012" /* Visa */, "01", "2999"); | 3981 "423456789012" /* Visa */, "01", "2999"); |
| 3951 credit_card.set_use_date(creation_time); | |
| 3952 credit_card.set_modification_date(creation_time); | |
| 3953 EXPECT_EQ(1U, credit_card.use_count()); | 3982 EXPECT_EQ(1U, credit_card.use_count()); |
| 3954 EXPECT_EQ(creation_time, credit_card.use_date()); | 3983 EXPECT_EQ(kArbitraryTime, credit_card.use_date()); |
| 3955 EXPECT_EQ(creation_time, credit_card.modification_date()); | 3984 EXPECT_EQ(kArbitraryTime, credit_card.modification_date()); |
| 3956 personal_data_->AddCreditCard(credit_card); | 3985 personal_data_->AddCreditCard(credit_card); |
| 3957 | 3986 |
| 3958 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3987 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3959 .WillOnce(QuitMainMessageLoop()); | 3988 .WillOnce(QuitMainMessageLoop()); |
| 3960 base::RunLoop().Run(); | 3989 base::RunLoop().Run(); |
| 3961 | 3990 |
| 3991 // Set the current time to another value. |
| 3992 test_clock.SetNow(kSomeLaterTime); |
| 3993 |
| 3962 // Notify the PDM that the profile and credit card were used. | 3994 // Notify the PDM that the profile and credit card were used. |
| 3963 AutofillProfile* added_profile = | 3995 AutofillProfile* added_profile = |
| 3964 personal_data_->GetProfileByGUID(profile.guid()); | 3996 personal_data_->GetProfileByGUID(profile.guid()); |
| 3965 ASSERT_TRUE(added_profile); | 3997 ASSERT_TRUE(added_profile); |
| 3966 EXPECT_EQ(*added_profile, profile); | 3998 EXPECT_EQ(*added_profile, profile); |
| 3967 EXPECT_EQ(1U, added_profile->use_count()); | 3999 EXPECT_EQ(1U, added_profile->use_count()); |
| 3968 EXPECT_EQ(creation_time, added_profile->use_date()); | 4000 EXPECT_EQ(kArbitraryTime, added_profile->use_date()); |
| 3969 EXPECT_NE(creation_time, added_profile->modification_date()); | 4001 EXPECT_EQ(kArbitraryTime, added_profile->modification_date()); |
| 3970 personal_data_->RecordUseOf(profile); | 4002 personal_data_->RecordUseOf(profile); |
| 3971 | 4003 |
| 3972 CreditCard* added_card = | 4004 CreditCard* added_card = |
| 3973 personal_data_->GetCreditCardByGUID(credit_card.guid()); | 4005 personal_data_->GetCreditCardByGUID(credit_card.guid()); |
| 3974 ASSERT_TRUE(added_card); | 4006 ASSERT_TRUE(added_card); |
| 3975 EXPECT_EQ(*added_card, credit_card); | 4007 EXPECT_EQ(*added_card, credit_card); |
| 3976 EXPECT_EQ(1U, added_card->use_count()); | 4008 EXPECT_EQ(1U, added_card->use_count()); |
| 3977 EXPECT_EQ(creation_time, added_card->use_date()); | 4009 EXPECT_EQ(kArbitraryTime, added_card->use_date()); |
| 3978 EXPECT_NE(creation_time, added_card->modification_date()); | 4010 EXPECT_EQ(kArbitraryTime, added_card->modification_date()); |
| 3979 personal_data_->RecordUseOf(credit_card); | 4011 personal_data_->RecordUseOf(credit_card); |
| 3980 | 4012 |
| 3981 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4013 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3982 .WillOnce(QuitMainMessageLoop()); | 4014 .WillOnce(QuitMainMessageLoop()); |
| 3983 base::RunLoop().Run(); | 4015 base::RunLoop().Run(); |
| 3984 | 4016 |
| 3985 // Verify usage stats are updated. | 4017 // Verify usage stats are updated. |
| 3986 added_profile = personal_data_->GetProfileByGUID(profile.guid()); | 4018 added_profile = personal_data_->GetProfileByGUID(profile.guid()); |
| 3987 ASSERT_TRUE(added_profile); | 4019 ASSERT_TRUE(added_profile); |
| 3988 EXPECT_EQ(2U, added_profile->use_count()); | 4020 EXPECT_EQ(2U, added_profile->use_count()); |
| 3989 EXPECT_NE(creation_time, added_profile->use_date()); | 4021 EXPECT_EQ(kSomeLaterTime, added_profile->use_date()); |
| 3990 EXPECT_NE(creation_time, added_profile->modification_date()); | 4022 EXPECT_EQ(kArbitraryTime, added_profile->modification_date()); |
| 3991 | 4023 |
| 3992 added_card = personal_data_->GetCreditCardByGUID(credit_card.guid()); | 4024 added_card = personal_data_->GetCreditCardByGUID(credit_card.guid()); |
| 3993 ASSERT_TRUE(added_card); | 4025 ASSERT_TRUE(added_card); |
| 3994 EXPECT_EQ(2U, added_card->use_count()); | 4026 EXPECT_EQ(2U, added_card->use_count()); |
| 3995 EXPECT_NE(creation_time, added_card->use_date()); | 4027 EXPECT_EQ(kSomeLaterTime, added_card->use_date()); |
| 3996 EXPECT_NE(creation_time, added_card->modification_date()); | 4028 EXPECT_EQ(kArbitraryTime, added_card->modification_date()); |
| 3997 } | 4029 } |
| 3998 | 4030 |
| 3999 TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) { | 4031 TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) { |
| 4000 EnableWalletCardImport(); | 4032 EnableWalletCardImport(); |
| 4001 | 4033 |
| 4002 std::vector<CreditCard> server_cards; | 4034 std::vector<CreditCard> server_cards; |
| 4003 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 4035 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 4004 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 4036 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 4005 "9012" /* Visa */, "01", "2999"); | 4037 "9012" /* Visa */, "01", "2999"); |
| 4006 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 4038 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 4007 | 4039 |
| 4008 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); | 4040 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
| 4009 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", | 4041 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", |
| 4010 "4444" /* Mastercard */, "12", "2999"); | 4042 "4444" /* Mastercard */, "12", "2999"); |
| 4011 server_cards.back().SetTypeForMaskedCard(kMasterCard); | 4043 server_cards.back().SetTypeForMaskedCard(kMasterCard); |
| 4012 | 4044 |
| 4013 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 4045 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 4014 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 4046 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 4015 "347666888555" /* American Express */, "04", "2999"); | 4047 "347666888555" /* American Express */, "04", "2999"); |
| 4016 | 4048 |
| 4049 // Create the test clock and set the time to a specific value. |
| 4050 TestAutofillClock test_clock; |
| 4051 test_clock.SetNow(kArbitraryTime); |
| 4052 |
| 4017 test::SetServerCreditCards(autofill_table_, server_cards); | 4053 test::SetServerCreditCards(autofill_table_, server_cards); |
| 4018 personal_data_->Refresh(); | 4054 personal_data_->Refresh(); |
| 4019 | 4055 |
| 4020 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4056 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4021 .WillOnce(QuitMainMessageLoop()); | 4057 .WillOnce(QuitMainMessageLoop()); |
| 4022 base::RunLoop().Run(); | 4058 base::RunLoop().Run(); |
| 4023 | 4059 |
| 4024 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 4060 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 4025 | 4061 |
| 4026 if (!OfferStoreUnmaskedCards()) { | 4062 if (!OfferStoreUnmaskedCards()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 4045 | 4081 |
| 4046 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4082 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4047 .WillOnce(QuitMainMessageLoop()); | 4083 .WillOnce(QuitMainMessageLoop()); |
| 4048 base::RunLoop().Run(); | 4084 base::RunLoop().Run(); |
| 4049 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 4085 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 4050 | 4086 |
| 4051 for (size_t i = 0; i < 3; ++i) | 4087 for (size_t i = 0; i < 3; ++i) |
| 4052 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); | 4088 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); |
| 4053 | 4089 |
| 4054 // For an unmasked card, usage data starts out as 2 because of the unmasking | 4090 // For an unmasked card, usage data starts out as 2 because of the unmasking |
| 4055 // which is considered a use. | 4091 // which is considered a use. The use date should now be the specified Now() |
| 4092 // time kArbitraryTime. |
| 4056 EXPECT_EQ(2U, personal_data_->GetCreditCards()[0]->use_count()); | 4093 EXPECT_EQ(2U, personal_data_->GetCreditCards()[0]->use_count()); |
| 4057 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date()); | 4094 EXPECT_EQ(kArbitraryTime, personal_data_->GetCreditCards()[0]->use_date()); |
| 4058 | 4095 |
| 4059 EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count()); | 4096 EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count()); |
| 4060 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); | 4097 EXPECT_NE(kArbitraryTime, personal_data_->GetCreditCards()[1]->use_date()); |
| 4061 | 4098 |
| 4062 // Having unmasked this card, usage stats should be 2 and Now(). | 4099 // Having unmasked this card, usage stats should be 2 and |
| 4100 // kArbitraryTime. |
| 4063 EXPECT_EQ(2U, personal_data_->GetCreditCards()[2]->use_count()); | 4101 EXPECT_EQ(2U, personal_data_->GetCreditCards()[2]->use_count()); |
| 4064 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date()); | 4102 EXPECT_EQ(kArbitraryTime, personal_data_->GetCreditCards()[2]->use_date()); |
| 4065 base::Time initial_use_date = personal_data_->GetCreditCards()[2]->use_date(); | 4103 |
| 4104 // Change the Now() value for a second time. |
| 4105 test_clock.SetNow(kSomeLaterTime); |
| 4066 | 4106 |
| 4067 server_cards.back().set_guid(personal_data_->GetCreditCards()[2]->guid()); | 4107 server_cards.back().set_guid(personal_data_->GetCreditCards()[2]->guid()); |
| 4068 personal_data_->RecordUseOf(server_cards.back()); | 4108 personal_data_->RecordUseOf(server_cards.back()); |
| 4069 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4109 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4070 .WillOnce(QuitMainMessageLoop()); | 4110 .WillOnce(QuitMainMessageLoop()); |
| 4071 base::RunLoop().Run(); | 4111 base::RunLoop().Run(); |
| 4072 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 4112 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 4073 | 4113 |
| 4074 EXPECT_EQ(2U, personal_data_->GetCreditCards()[0]->use_count()); | 4114 EXPECT_EQ(2U, personal_data_->GetCreditCards()[0]->use_count()); |
| 4075 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date()); | 4115 EXPECT_EQ(kArbitraryTime, personal_data_->GetCreditCards()[0]->use_date()); |
| 4076 | 4116 |
| 4077 EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count()); | 4117 EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count()); |
| 4078 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); | 4118 EXPECT_NE(kArbitraryTime, personal_data_->GetCreditCards()[1]->use_date()); |
| 4079 | 4119 |
| 4120 // The RecordUseOf call should have incremented the use_count to 3 and set the |
| 4121 // use_date to kSomeLaterTime. |
| 4080 EXPECT_EQ(3U, personal_data_->GetCreditCards()[2]->use_count()); | 4122 EXPECT_EQ(3U, personal_data_->GetCreditCards()[2]->use_count()); |
| 4081 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date()); | 4123 EXPECT_EQ(kSomeLaterTime, personal_data_->GetCreditCards()[2]->use_date()); |
| 4082 // Time may or may not have elapsed between unmasking and RecordUseOf. | |
| 4083 EXPECT_LE(initial_use_date, personal_data_->GetCreditCards()[2]->use_date()); | |
| 4084 | 4124 |
| 4085 // Can record usage stats on masked cards. | 4125 // Can record usage stats on masked cards. |
| 4086 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid()); | 4126 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid()); |
| 4087 personal_data_->RecordUseOf(server_cards[1]); | 4127 personal_data_->RecordUseOf(server_cards[1]); |
| 4088 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4128 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4089 .WillOnce(QuitMainMessageLoop()); | 4129 .WillOnce(QuitMainMessageLoop()); |
| 4090 base::RunLoop().Run(); | 4130 base::RunLoop().Run(); |
| 4091 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 4131 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 4092 EXPECT_EQ(2U, personal_data_->GetCreditCards()[1]->use_count()); | 4132 EXPECT_EQ(2U, personal_data_->GetCreditCards()[1]->use_count()); |
| 4093 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); | 4133 EXPECT_EQ(kSomeLaterTime, personal_data_->GetCreditCards()[1]->use_date()); |
| 4134 |
| 4135 // Change Now()'s return value for a third time. |
| 4136 test_clock.SetNow(kMuchLaterTime); |
| 4094 | 4137 |
| 4095 // Upgrading to unmasked retains the usage stats (and increments them). | 4138 // Upgrading to unmasked retains the usage stats (and increments them). |
| 4096 CreditCard* unmasked_card2 = &server_cards[1]; | 4139 CreditCard* unmasked_card2 = &server_cards[1]; |
| 4097 unmasked_card2->set_record_type(CreditCard::FULL_SERVER_CARD); | 4140 unmasked_card2->set_record_type(CreditCard::FULL_SERVER_CARD); |
| 4098 unmasked_card2->SetNumber(ASCIIToUTF16("5555555555554444")); | 4141 unmasked_card2->SetNumber(ASCIIToUTF16("5555555555554444")); |
| 4099 personal_data_->UpdateServerCreditCard(*unmasked_card2); | 4142 personal_data_->UpdateServerCreditCard(*unmasked_card2); |
| 4100 | 4143 |
| 4101 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid()); | 4144 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid()); |
| 4102 personal_data_->RecordUseOf(server_cards[1]); | 4145 personal_data_->RecordUseOf(server_cards[1]); |
| 4103 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4146 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 4104 .WillOnce(QuitMainMessageLoop()); | 4147 .WillOnce(QuitMainMessageLoop()); |
| 4105 base::RunLoop().Run(); | 4148 base::RunLoop().Run(); |
| 4106 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 4149 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
| 4107 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count()); | 4150 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count()); |
| 4108 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); | 4151 EXPECT_EQ(kMuchLaterTime, personal_data_->GetCreditCards()[1]->use_date()); |
| 4109 } | 4152 } |
| 4110 | 4153 |
| 4111 TEST_F(PersonalDataManagerTest, ClearAllServerData) { | 4154 TEST_F(PersonalDataManagerTest, ClearAllServerData) { |
| 4112 // Add a server card. | 4155 // Add a server card. |
| 4113 std::vector<CreditCard> server_cards; | 4156 std::vector<CreditCard> server_cards; |
| 4114 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 4157 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
| 4115 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 4158 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
| 4116 "9012" /* Visa */, "01", "2999"); | 4159 "9012" /* Visa */, "01", "2999"); |
| 4117 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 4160 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 4118 test::SetServerCreditCards(autofill_table_, server_cards); | 4161 test::SetServerCreditCards(autofill_table_, server_cards); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4516 | 4559 |
| 4517 // Make sure the new information was merged correctly. | 4560 // Make sure the new information was merged correctly. |
| 4518 for (ProfileField changed_field : test_case.changed_field_values) { | 4561 for (ProfileField changed_field : test_case.changed_field_values) { |
| 4519 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value), | 4562 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value), |
| 4520 saved_profiles.front()->GetRawInfo(changed_field.field_type)); | 4563 saved_profiles.front()->GetRawInfo(changed_field.field_type)); |
| 4521 } | 4564 } |
| 4522 // Verify that the merged profile's use count, use date and modification | 4565 // Verify that the merged profile's use count, use date and modification |
| 4523 // date were properly updated. | 4566 // date were properly updated. |
| 4524 EXPECT_EQ(1U, saved_profiles.front()->use_count()); | 4567 EXPECT_EQ(1U, saved_profiles.front()->use_count()); |
| 4525 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4568 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4526 base::Time::Now() - saved_profiles.front()->use_date()); | 4569 AutofillClock::Now() - saved_profiles.front()->use_date()); |
| 4527 EXPECT_GT( | 4570 EXPECT_GT( |
| 4528 base::TimeDelta::FromMilliseconds(500), | 4571 base::TimeDelta::FromMilliseconds(500), |
| 4529 base::Time::Now() - saved_profiles.front()->modification_date()); | 4572 AutofillClock::Now() - saved_profiles.front()->modification_date()); |
| 4530 } | 4573 } |
| 4531 | 4574 |
| 4532 // Erase the profiles for the next test. | 4575 // Erase the profiles for the next test. |
| 4533 ResetProfiles(); | 4576 ResetProfiles(); |
| 4534 } | 4577 } |
| 4535 } | 4578 } |
| 4536 | 4579 |
| 4537 // Tests that MergeProfile tries to merge the imported profile into the | 4580 // Tests that MergeProfile tries to merge the imported profile into the |
| 4538 // existing profile in decreasing order of frecency. | 4581 // existing profile in decreasing order of frecency. |
| 4539 TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) { | 4582 TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4574 } | 4617 } |
| 4575 | 4618 |
| 4576 // Tests that MergeProfile produces a merged profile with the expected usage | 4619 // Tests that MergeProfile produces a merged profile with the expected usage |
| 4577 // statistics. | 4620 // statistics. |
| 4578 // Flaky on TSan, see crbug.com/686226. | 4621 // Flaky on TSan, see crbug.com/686226. |
| 4579 #if defined(THREAD_SANITIZER) | 4622 #if defined(THREAD_SANITIZER) |
| 4580 #define MAYBE_MergeProfile_UsageStats DISABLED_MergeProfile_UsageStats | 4623 #define MAYBE_MergeProfile_UsageStats DISABLED_MergeProfile_UsageStats |
| 4581 #else | 4624 #else |
| 4582 #define MAYBE_MergeProfile_UsageStats MergeProfile_UsageStats | 4625 #define MAYBE_MergeProfile_UsageStats MergeProfile_UsageStats |
| 4583 #endif | 4626 #endif |
| 4627 TEST_F(PersonalDataManagerTest, MAYBE_MergeProfile_UsageStats) { |
| 4628 // Create the test clock and set the time to a specific value. |
| 4629 TestAutofillClock test_clock; |
| 4630 test_clock.SetNow(kArbitraryTime); |
| 4584 | 4631 |
| 4585 TEST_F(PersonalDataManagerTest, MAYBE_MergeProfile_UsageStats) { | |
| 4586 // Create an initial profile with a use count of 10, an old use date and an | 4632 // Create an initial profile with a use count of 10, an old use date and an |
| 4587 // old modification date of 4 days ago. | 4633 // old modification date of 4 days ago. |
| 4588 AutofillProfile* profile = | 4634 AutofillProfile* profile = |
| 4589 new AutofillProfile(base::GenerateGUID(), "https://www.example.com"); | 4635 new AutofillProfile(base::GenerateGUID(), "https://www.example.com"); |
| 4590 test::SetProfileInfo(profile, "Homer", "Jay", "Simpson", | 4636 test::SetProfileInfo(profile, "Homer", "Jay", "Simpson", |
| 4591 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", | 4637 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 4592 "", "Springfield", "IL", "91601", "US", "12345678910"); | 4638 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4593 profile->set_use_count(4U); | 4639 profile->set_use_count(4U); |
| 4594 profile->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); | 4640 EXPECT_EQ(kArbitraryTime, profile->use_date()); |
| 4595 profile->set_modification_date(base::Time::Now() - | 4641 EXPECT_EQ(kArbitraryTime, profile->modification_date()); |
| 4596 base::TimeDelta::FromDays(4)); | |
| 4597 | 4642 |
| 4598 // Create the |existing_profiles| vector. | 4643 // Create the |existing_profiles| vector. |
| 4599 std::vector<std::unique_ptr<AutofillProfile>> existing_profiles; | 4644 std::vector<std::unique_ptr<AutofillProfile>> existing_profiles; |
| 4600 existing_profiles.push_back(base::WrapUnique(profile)); | 4645 existing_profiles.push_back(base::WrapUnique(profile)); |
| 4601 | 4646 |
| 4647 // Change the current date. |
| 4648 test_clock.SetNow(kSomeLaterTime); |
| 4649 |
| 4602 // Create a new imported profile that will get merged with the existing one. | 4650 // Create a new imported profile that will get merged with the existing one. |
| 4603 AutofillProfile imported_profile(base::GenerateGUID(), | 4651 AutofillProfile imported_profile(base::GenerateGUID(), |
| 4604 "https://www.example.com"); | 4652 "https://www.example.com"); |
| 4605 test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson", | 4653 test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson", |
| 4606 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 4654 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4607 "Springfield", "IL", "91601", "US", "12345678910"); | 4655 "Springfield", "IL", "91601", "US", "12345678910"); |
| 4608 | 4656 |
| 4657 // Change the current date. |
| 4658 test_clock.SetNow(kMuchLaterTime); |
| 4659 |
| 4609 // Merge the imported profile into the existing profiles. | 4660 // Merge the imported profile into the existing profiles. |
| 4610 std::vector<AutofillProfile> profiles; | 4661 std::vector<AutofillProfile> profiles; |
| 4611 std::string guid = personal_data_->MergeProfile( | 4662 std::string guid = personal_data_->MergeProfile( |
| 4612 imported_profile, &existing_profiles, "US-EN", &profiles); | 4663 imported_profile, &existing_profiles, "US-EN", &profiles); |
| 4613 | 4664 |
| 4614 // The new profile should be merged into the existing profile. | 4665 // The new profile should be merged into the existing profile. |
| 4615 EXPECT_EQ(profile->guid(), guid); | 4666 EXPECT_EQ(profile->guid(), guid); |
| 4616 // The use count should have be max(4, 1) => 4. | 4667 // The use count should have be max(4, 1) => 4. |
| 4617 EXPECT_EQ(4U, profile->use_count()); | 4668 EXPECT_EQ(4U, profile->use_count()); |
| 4618 // The use date and modification dates should have been set to less than 500 | 4669 // The use date should be the one of the most recent profile, which is |
| 4619 // milliseconds ago. | 4670 // kSecondArbitraryTime. |
| 4620 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4671 EXPECT_EQ(kSomeLaterTime, profile->use_date()); |
| 4621 base::Time::Now() - profile->use_date()); | 4672 // Since the merge is considered a modification, the modification_date should |
| 4622 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4673 // be set to kMuchLaterTime. |
| 4623 base::Time::Now() - profile->modification_date()); | 4674 EXPECT_EQ(kMuchLaterTime, profile->modification_date()); |
| 4624 } | 4675 } |
| 4625 | 4676 |
| 4626 // Tests that DedupeProfiles sets the correct profile guids to | 4677 // Tests that DedupeProfiles sets the correct profile guids to |
| 4627 // delete after merging similar profiles. | 4678 // delete after merging similar profiles. |
| 4628 TEST_F(PersonalDataManagerTest, DedupeProfiles_ProfilesToDelete) { | 4679 TEST_F(PersonalDataManagerTest, DedupeProfiles_ProfilesToDelete) { |
| 4629 // Create the profile for which to find duplicates. It has the highest | 4680 // Create the profile for which to find duplicates. It has the highest |
| 4630 // frecency. | 4681 // frecency. |
| 4631 AutofillProfile* profile1 = | 4682 AutofillProfile* profile1 = |
| 4632 new AutofillProfile(base::GenerateGUID(), "https://www.example.com"); | 4683 new AutofillProfile(base::GenerateGUID(), "https://www.example.com"); |
| 4633 test::SetProfileInfo(profile1, "Homer", "Jay", "Simpson", | 4684 test::SetProfileInfo(profile1, "Homer", "Jay", "Simpson", |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4847 // 5 has a higher score than 6. This will ensure a deterministic order when | 4898 // 5 has a higher score than 6. This will ensure a deterministic order when |
| 4848 // verifying results. | 4899 // verifying results. |
| 4849 | 4900 |
| 4850 // Create a set of 3 profiles to be merged together. | 4901 // Create a set of 3 profiles to be merged together. |
| 4851 // Create a profile with a higher frecency score. | 4902 // Create a profile with a higher frecency score. |
| 4852 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 4903 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 4853 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", | 4904 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", |
| 4854 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | 4905 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 4855 "", "Springfield", "IL", "91601", "US", ""); | 4906 "", "Springfield", "IL", "91601", "US", ""); |
| 4856 profile1.set_use_count(12); | 4907 profile1.set_use_count(12); |
| 4857 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 4908 profile1.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); |
| 4858 | 4909 |
| 4859 // Create a profile with a medium frecency score. | 4910 // Create a profile with a medium frecency score. |
| 4860 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 4911 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 4861 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", | 4912 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", |
| 4862 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 4913 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4863 "Springfield", "IL", "91601", "", "12345678910"); | 4914 "Springfield", "IL", "91601", "", "12345678910"); |
| 4864 profile2.set_use_count(5); | 4915 profile2.set_use_count(5); |
| 4865 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 4916 profile2.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(3)); |
| 4866 | 4917 |
| 4867 // Create a profile with a lower frecency score. | 4918 // Create a profile with a lower frecency score. |
| 4868 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); | 4919 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); |
| 4869 test::SetProfileInfo(&profile3, "Homer", "J", "Simpson", | 4920 test::SetProfileInfo(&profile3, "Homer", "J", "Simpson", |
| 4870 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 4921 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 4871 "", "Springfield", "IL", "91601", "", ""); | 4922 "", "Springfield", "IL", "91601", "", ""); |
| 4872 profile3.set_use_count(3); | 4923 profile3.set_use_count(3); |
| 4873 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 4924 profile3.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(5)); |
| 4874 | 4925 |
| 4875 // Create a set of two profiles to be merged together. | 4926 // Create a set of two profiles to be merged together. |
| 4876 // Create a profile with a higher frecency score. | 4927 // Create a profile with a higher frecency score. |
| 4877 AutofillProfile profile4(base::GenerateGUID(), "https://www.example.com"); | 4928 AutofillProfile profile4(base::GenerateGUID(), "https://www.example.com"); |
| 4878 test::SetProfileInfo(&profile4, "Marge", "B", "Simpson", | 4929 test::SetProfileInfo(&profile4, "Marge", "B", "Simpson", |
| 4879 "marge.simpson@abc.com", "", "742. Evergreen Terrace", | 4930 "marge.simpson@abc.com", "", "742. Evergreen Terrace", |
| 4880 "", "Springfield", "IL", "91601", "US", ""); | 4931 "", "Springfield", "IL", "91601", "US", ""); |
| 4881 profile4.set_use_count(11); | 4932 profile4.set_use_count(11); |
| 4882 profile4.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 4933 profile4.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); |
| 4883 | 4934 |
| 4884 // Create a profile with a lower frecency score. | 4935 // Create a profile with a lower frecency score. |
| 4885 AutofillProfile profile5(base::GenerateGUID(), "https://www.example.com"); | 4936 AutofillProfile profile5(base::GenerateGUID(), "https://www.example.com"); |
| 4886 test::SetProfileInfo(&profile5, "Marge", "B", "Simpson", | 4937 test::SetProfileInfo(&profile5, "Marge", "B", "Simpson", |
| 4887 "marge.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 4938 "marge.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 4888 "", "Springfield", "IL", "91601", "", ""); | 4939 "", "Springfield", "IL", "91601", "", ""); |
| 4889 profile5.set_use_count(5); | 4940 profile5.set_use_count(5); |
| 4890 profile5.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 4941 profile5.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(3)); |
| 4891 | 4942 |
| 4892 // Create a unique profile. | 4943 // Create a unique profile. |
| 4893 AutofillProfile profile6(base::GenerateGUID(), "https://www.example.com"); | 4944 AutofillProfile profile6(base::GenerateGUID(), "https://www.example.com"); |
| 4894 test::SetProfileInfo(&profile6, "Bart", "J", "Simpson", | 4945 test::SetProfileInfo(&profile6, "Bart", "J", "Simpson", |
| 4895 "bart.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 4946 "bart.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 4896 "", "Springfield", "IL", "91601", "", ""); | 4947 "", "Springfield", "IL", "91601", "", ""); |
| 4897 profile6.set_use_count(10); | 4948 profile6.set_use_count(10); |
| 4898 profile6.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 4949 profile6.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); |
| 4899 | 4950 |
| 4900 // Add three credit cards. Give them a frecency score so that they are | 4951 // Add three credit cards. Give them a frecency score so that they are |
| 4901 // suggested in order (1, 2, 3). This will ensure a deterministic order for | 4952 // suggested in order (1, 2, 3). This will ensure a deterministic order for |
| 4902 // verifying results. | 4953 // verifying results. |
| 4903 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | 4954 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); |
| 4904 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", | 4955 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", |
| 4905 "347666888555" /* American Express */, "04", "2999"); | 4956 "347666888555" /* American Express */, "04", "2999"); |
| 4906 credit_card1.set_use_count(10); | 4957 credit_card1.set_use_count(10); |
| 4907 | 4958 |
| 4908 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); | 4959 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4979 // Tests that ApplyDedupingRoutine merges the profile values correctly, i.e. | 5030 // Tests that ApplyDedupingRoutine merges the profile values correctly, i.e. |
| 4980 // never lose information and keep the syntax of the profile with the higher | 5031 // never lose information and keep the syntax of the profile with the higher |
| 4981 // frecency score. | 5032 // frecency score. |
| 4982 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MergedProfileValues) { | 5033 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MergedProfileValues) { |
| 4983 // Create a profile with a higher frecency score. | 5034 // Create a profile with a higher frecency score. |
| 4984 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 5035 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 4985 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", | 5036 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", |
| 4986 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | 5037 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 4987 "", "Springfield", "IL", "91601", "US", ""); | 5038 "", "Springfield", "IL", "91601", "US", ""); |
| 4988 profile1.set_use_count(10); | 5039 profile1.set_use_count(10); |
| 4989 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 5040 profile1.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); |
| 4990 | 5041 |
| 4991 // Create a profile with a medium frecency score. | 5042 // Create a profile with a medium frecency score. |
| 4992 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 5043 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 4993 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", | 5044 test::SetProfileInfo(&profile2, "Homer", "Jay", "Simpson", |
| 4994 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 5045 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4995 "Springfield", "IL", "91601", "", "12345678910"); | 5046 "Springfield", "IL", "91601", "", "12345678910"); |
| 4996 profile2.set_use_count(5); | 5047 profile2.set_use_count(5); |
| 4997 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 5048 profile2.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(3)); |
| 4998 | 5049 |
| 4999 // Create a profile with a lower frecency score. | 5050 // Create a profile with a lower frecency score. |
| 5000 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); | 5051 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); |
| 5001 test::SetProfileInfo(&profile3, "Homer", "J", "Simpson", | 5052 test::SetProfileInfo(&profile3, "Homer", "J", "Simpson", |
| 5002 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 5053 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 5003 "", "Springfield", "IL", "91601", "", ""); | 5054 "", "Springfield", "IL", "91601", "", ""); |
| 5004 profile3.set_use_count(3); | 5055 profile3.set_use_count(3); |
| 5005 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 5056 profile3.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(5)); |
| 5006 | 5057 |
| 5007 personal_data_->AddProfile(profile1); | 5058 personal_data_->AddProfile(profile1); |
| 5008 personal_data_->AddProfile(profile2); | 5059 personal_data_->AddProfile(profile2); |
| 5009 personal_data_->AddProfile(profile3); | 5060 personal_data_->AddProfile(profile3); |
| 5010 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5061 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5011 .WillOnce(QuitMainMessageLoop()); | 5062 .WillOnce(QuitMainMessageLoop()); |
| 5012 base::RunLoop().Run(); | 5063 base::RunLoop().Run(); |
| 5013 | 5064 |
| 5014 // Make sure the 3 profiles were saved; | 5065 // Make sure the 3 profiles were saved; |
| 5015 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); | 5066 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5071 // Tests that ApplyDedupingRoutine only keeps the verified profile with its | 5122 // Tests that ApplyDedupingRoutine only keeps the verified profile with its |
| 5072 // original data when deduping with similar profiles, even if it has a higher | 5123 // original data when deduping with similar profiles, even if it has a higher |
| 5073 // frecency score. | 5124 // frecency score. |
| 5074 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileFirst) { | 5125 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileFirst) { |
| 5075 // Create a verified profile with a higher frecency score. | 5126 // Create a verified profile with a higher frecency score. |
| 5076 AutofillProfile profile1(base::GenerateGUID(), kSettingsOrigin); | 5127 AutofillProfile profile1(base::GenerateGUID(), kSettingsOrigin); |
| 5077 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", | 5128 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", |
| 5078 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 5129 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 5079 "Springfield", "IL", "91601", "", "12345678910"); | 5130 "Springfield", "IL", "91601", "", "12345678910"); |
| 5080 profile1.set_use_count(7); | 5131 profile1.set_use_count(7); |
| 5081 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 5132 profile1.set_use_date(kMuchLaterTime); |
| 5082 | 5133 |
| 5083 // Create a similar non verified profile with a medium frecency score. | 5134 // Create a similar non verified profile with a medium frecency score. |
| 5084 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 5135 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 5085 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", | 5136 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", |
| 5086 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | 5137 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 5087 "", "Springfield", "IL", "91601", "US", ""); | 5138 "", "Springfield", "IL", "91601", "US", ""); |
| 5088 profile2.set_use_count(5); | 5139 profile2.set_use_count(5); |
| 5089 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 5140 profile2.set_use_date(kSomeLaterTime); |
| 5090 | 5141 |
| 5091 // Create a similar non verified profile with a lower frecency score. | 5142 // Create a similar non verified profile with a lower frecency score. |
| 5092 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); | 5143 AutofillProfile profile3(base::GenerateGUID(), "https://www.example.com"); |
| 5093 test::SetProfileInfo(&profile3, "Homer", "J", "Simpson", | 5144 test::SetProfileInfo(&profile3, "Homer", "J", "Simpson", |
| 5094 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 5145 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 5095 "", "Springfield", "IL", "91601", "", ""); | 5146 "", "Springfield", "IL", "91601", "", ""); |
| 5096 profile3.set_use_count(3); | 5147 profile3.set_use_count(3); |
| 5097 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 5148 profile3.set_use_date(kArbitraryTime); |
| 5098 | 5149 |
| 5099 personal_data_->AddProfile(profile1); | 5150 personal_data_->AddProfile(profile1); |
| 5100 personal_data_->AddProfile(profile2); | 5151 personal_data_->AddProfile(profile2); |
| 5101 personal_data_->AddProfile(profile3); | 5152 personal_data_->AddProfile(profile3); |
| 5102 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5153 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5103 .WillOnce(QuitMainMessageLoop()); | 5154 .WillOnce(QuitMainMessageLoop()); |
| 5104 base::RunLoop().Run(); | 5155 base::RunLoop().Run(); |
| 5105 | 5156 |
| 5106 // Make sure the 3 profiles were saved. | 5157 // Make sure the 3 profiles were saved. |
| 5107 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); | 5158 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 5127 histogram_tester.ExpectUniqueSample( | 5178 histogram_tester.ExpectUniqueSample( |
| 5128 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1); | 5179 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1); |
| 5129 // 2 profile were removed (profiles 2 and 3). | 5180 // 2 profile were removed (profiles 2 and 3). |
| 5130 histogram_tester.ExpectUniqueSample( | 5181 histogram_tester.ExpectUniqueSample( |
| 5131 "Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1); | 5182 "Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1); |
| 5132 | 5183 |
| 5133 // Only the verified |profile1| with its original data should have been kept. | 5184 // Only the verified |profile1| with its original data should have been kept. |
| 5134 EXPECT_EQ(profile1.guid(), profiles[0]->guid()); | 5185 EXPECT_EQ(profile1.guid(), profiles[0]->guid()); |
| 5135 EXPECT_TRUE(profile1 == *profiles[0]); | 5186 EXPECT_TRUE(profile1 == *profiles[0]); |
| 5136 EXPECT_EQ(profile1.use_count(), profiles[0]->use_count()); | 5187 EXPECT_EQ(profile1.use_count(), profiles[0]->use_count()); |
| 5137 EXPECT_LT(profile1.use_date() - TimeDelta::FromSeconds(2), | 5188 EXPECT_EQ(profile1.use_date(), profiles[0]->use_date()); |
| 5138 profiles[0]->use_date()); | |
| 5139 EXPECT_GT(profile1.use_date() + TimeDelta::FromSeconds(2), | |
| 5140 profiles[0]->use_date()); | |
| 5141 } | 5189 } |
| 5142 | 5190 |
| 5143 // Tests that ApplyDedupingRoutine only keeps the verified profile with its | 5191 // Tests that ApplyDedupingRoutine only keeps the verified profile with its |
| 5144 // original data when deduping with similar profiles, even if it has a lower | 5192 // original data when deduping with similar profiles, even if it has a lower |
| 5145 // frecency score. | 5193 // frecency score. |
| 5146 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileLast) { | 5194 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileLast) { |
| 5147 // Create a profile to dedupe with a higher frecency score. | 5195 // Create a profile to dedupe with a higher frecency score. |
| 5148 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 5196 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 5149 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", | 5197 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", |
| 5150 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | 5198 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 5151 "", "Springfield", "IL", "91601", "US", ""); | 5199 "", "Springfield", "IL", "91601", "US", ""); |
| 5152 profile1.set_use_count(5); | 5200 profile1.set_use_count(5); |
| 5153 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 5201 profile1.set_use_date(kMuchLaterTime); |
| 5154 | 5202 |
| 5155 // Create a similar non verified profile with a medium frecency score. | 5203 // Create a similar non verified profile with a medium frecency score. |
| 5156 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 5204 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 5157 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", | 5205 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", |
| 5158 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 5206 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 5159 "", "Springfield", "IL", "91601", "", ""); | 5207 "", "Springfield", "IL", "91601", "", ""); |
| 5160 profile2.set_use_count(5); | 5208 profile2.set_use_count(5); |
| 5161 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 5209 profile2.set_use_date(kSomeLaterTime); |
| 5162 | 5210 |
| 5163 // Create a similar verified profile with a lower frecency score. | 5211 // Create a similar verified profile with a lower frecency score. |
| 5164 AutofillProfile profile3(base::GenerateGUID(), kSettingsOrigin); | 5212 AutofillProfile profile3(base::GenerateGUID(), kSettingsOrigin); |
| 5165 test::SetProfileInfo(&profile3, "Homer", "Jay", "Simpson", | 5213 test::SetProfileInfo(&profile3, "Homer", "Jay", "Simpson", |
| 5166 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 5214 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 5167 "Springfield", "IL", "91601", "", "12345678910"); | 5215 "Springfield", "IL", "91601", "", "12345678910"); |
| 5168 profile3.set_use_count(3); | 5216 profile3.set_use_count(3); |
| 5169 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 5217 profile3.set_use_date(kArbitraryTime); |
| 5170 | 5218 |
| 5171 personal_data_->AddProfile(profile1); | 5219 personal_data_->AddProfile(profile1); |
| 5172 personal_data_->AddProfile(profile2); | 5220 personal_data_->AddProfile(profile2); |
| 5173 personal_data_->AddProfile(profile3); | 5221 personal_data_->AddProfile(profile3); |
| 5174 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5222 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5175 .WillOnce(QuitMainMessageLoop()); | 5223 .WillOnce(QuitMainMessageLoop()); |
| 5176 base::RunLoop().Run(); | 5224 base::RunLoop().Run(); |
| 5177 | 5225 |
| 5178 // Make sure the 3 profiles were saved. | 5226 // Make sure the 3 profiles were saved. |
| 5179 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); | 5227 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5195 // should then have been discarded because it is similar to the verified | 5243 // should then have been discarded because it is similar to the verified |
| 5196 // |profile3|. | 5244 // |profile3|. |
| 5197 ASSERT_EQ(1U, profiles.size()); | 5245 ASSERT_EQ(1U, profiles.size()); |
| 5198 // 3 profiles were considered for dedupe. | 5246 // 3 profiles were considered for dedupe. |
| 5199 histogram_tester.ExpectUniqueSample( | 5247 histogram_tester.ExpectUniqueSample( |
| 5200 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1); | 5248 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1); |
| 5201 // 2 profile were removed (profiles 1 and 2). | 5249 // 2 profile were removed (profiles 1 and 2). |
| 5202 histogram_tester.ExpectUniqueSample( | 5250 histogram_tester.ExpectUniqueSample( |
| 5203 "Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1); | 5251 "Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1); |
| 5204 | 5252 |
| 5205 // Only the verified |profile2| with it's original data should have been kept. | 5253 // Only the verified |profile3| with it's original data should have been kept. |
| 5206 EXPECT_EQ(profile3.guid(), profiles[0]->guid()); | 5254 EXPECT_EQ(profile3.guid(), profiles[0]->guid()); |
| 5207 EXPECT_TRUE(profile3 == *profiles[0]); | 5255 EXPECT_TRUE(profile3 == *profiles[0]); |
| 5208 EXPECT_EQ(profile3.use_count(), profiles[0]->use_count()); | 5256 EXPECT_EQ(profile3.use_count(), profiles[0]->use_count()); |
| 5209 EXPECT_LT(profile3.use_date() - TimeDelta::FromSeconds(2), | 5257 EXPECT_EQ(profile3.use_date(), profiles[0]->use_date()); |
| 5210 profiles[0]->use_date()); | |
| 5211 EXPECT_GT(profile3.use_date() + TimeDelta::FromSeconds(2), | |
| 5212 profiles[0]->use_date()); | |
| 5213 } | 5258 } |
| 5214 | 5259 |
| 5215 // Tests that ApplyDedupingRoutine does not merge unverified data into | 5260 // Tests that ApplyDedupingRoutine does not merge unverified data into |
| 5216 // a verified profile. Also tests that two verified profiles don't get merged. | 5261 // a verified profile. Also tests that two verified profiles don't get merged. |
| 5217 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleVerifiedProfiles) { | 5262 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleVerifiedProfiles) { |
| 5218 // Create a profile to dedupe with a higher frecency score. | 5263 // Create a profile to dedupe with a higher frecency score. |
| 5219 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 5264 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 5220 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", | 5265 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", |
| 5221 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | 5266 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 5222 "", "Springfield", "IL", "91601", "US", ""); | 5267 "", "Springfield", "IL", "91601", "US", ""); |
| 5223 profile1.set_use_count(5); | 5268 profile1.set_use_count(5); |
| 5224 profile1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 5269 profile1.set_use_date(kMuchLaterTime); |
| 5225 | 5270 |
| 5226 // Create a similar verified profile with a medium frecency score. | 5271 // Create a similar verified profile with a medium frecency score. |
| 5227 AutofillProfile profile2(base::GenerateGUID(), kSettingsOrigin); | 5272 AutofillProfile profile2(base::GenerateGUID(), kSettingsOrigin); |
| 5228 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", | 5273 test::SetProfileInfo(&profile2, "Homer", "J", "Simpson", |
| 5229 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 5274 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 5230 "", "Springfield", "IL", "91601", "", ""); | 5275 "", "Springfield", "IL", "91601", "", ""); |
| 5231 profile2.set_use_count(5); | 5276 profile2.set_use_count(5); |
| 5232 profile2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 5277 profile2.set_use_date(kSomeLaterTime); |
| 5233 | 5278 |
| 5234 // Create a similar verified profile with a lower frecency score. | 5279 // Create a similar verified profile with a lower frecency score. |
| 5235 AutofillProfile profile3(base::GenerateGUID(), kSettingsOrigin); | 5280 AutofillProfile profile3(base::GenerateGUID(), kSettingsOrigin); |
| 5236 test::SetProfileInfo(&profile3, "Homer", "Jay", "Simpson", | 5281 test::SetProfileInfo(&profile3, "Homer", "Jay", "Simpson", |
| 5237 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 5282 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 5238 "Springfield", "IL", "91601", "", "12345678910"); | 5283 "Springfield", "IL", "91601", "", "12345678910"); |
| 5239 profile3.set_use_count(3); | 5284 profile3.set_use_count(3); |
| 5240 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 5285 profile3.set_use_date(kArbitraryTime); |
| 5241 | 5286 |
| 5242 personal_data_->AddProfile(profile1); | 5287 personal_data_->AddProfile(profile1); |
| 5243 personal_data_->AddProfile(profile2); | 5288 personal_data_->AddProfile(profile2); |
| 5244 personal_data_->AddProfile(profile3); | 5289 personal_data_->AddProfile(profile3); |
| 5245 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5290 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5246 .WillOnce(QuitMainMessageLoop()); | 5291 .WillOnce(QuitMainMessageLoop()); |
| 5247 base::RunLoop().Run(); | 5292 base::RunLoop().Run(); |
| 5248 | 5293 |
| 5249 // Make sure the 3 profiles were saved. | 5294 // Make sure the 3 profiles were saved. |
| 5250 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); | 5295 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 5277 histogram_tester.ExpectUniqueSample( | 5322 histogram_tester.ExpectUniqueSample( |
| 5278 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); | 5323 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1); |
| 5279 | 5324 |
| 5280 EXPECT_EQ(profile2.guid(), profiles[0]->guid()); | 5325 EXPECT_EQ(profile2.guid(), profiles[0]->guid()); |
| 5281 EXPECT_EQ(profile3.guid(), profiles[1]->guid()); | 5326 EXPECT_EQ(profile3.guid(), profiles[1]->guid()); |
| 5282 // The profiles should have kept their original data. | 5327 // The profiles should have kept their original data. |
| 5283 EXPECT_TRUE(profile2 == *profiles[0]); | 5328 EXPECT_TRUE(profile2 == *profiles[0]); |
| 5284 EXPECT_TRUE(profile3 == *profiles[1]); | 5329 EXPECT_TRUE(profile3 == *profiles[1]); |
| 5285 EXPECT_EQ(profile2.use_count(), profiles[0]->use_count()); | 5330 EXPECT_EQ(profile2.use_count(), profiles[0]->use_count()); |
| 5286 EXPECT_EQ(profile3.use_count(), profiles[1]->use_count()); | 5331 EXPECT_EQ(profile3.use_count(), profiles[1]->use_count()); |
| 5287 EXPECT_LT(profile2.use_date() - TimeDelta::FromSeconds(2), | 5332 EXPECT_EQ(profile2.use_date(), profiles[0]->use_date()); |
| 5288 profiles[0]->use_date()); | 5333 EXPECT_EQ(profile3.use_date(), profiles[1]->use_date()); |
| 5289 EXPECT_GT(profile2.use_date() + TimeDelta::FromSeconds(2), | |
| 5290 profiles[0]->use_date()); | |
| 5291 EXPECT_LT(profile3.use_date() - TimeDelta::FromSeconds(2), | |
| 5292 profiles[1]->use_date()); | |
| 5293 EXPECT_GT(profile3.use_date() + TimeDelta::FromSeconds(2), | |
| 5294 profiles[1]->use_date()); | |
| 5295 } | 5334 } |
| 5296 | 5335 |
| 5297 // Tests that ApplyProfileUseDatesFix sets the use date of profiles from an | 5336 // Tests that ApplyProfileUseDatesFix sets the use date of profiles from an |
| 5298 // incorrect value of 0 to [two weeks from now]. Also tests that SetProfiles | 5337 // incorrect value of 0 to [two weeks from now]. Also tests that SetProfiles |
| 5299 // does not modify any other profiles. | 5338 // does not modify any other profiles. |
| 5300 TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix) { | 5339 TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix) { |
| 5301 // Set the kAutofillProfileUseDatesFixed pref to true so that the fix is not | 5340 // Set the kAutofillProfileUseDatesFixed pref to true so that the fix is not |
| 5302 // applied just yet. | 5341 // applied just yet. |
| 5303 personal_data_->pref_service_->SetBoolean( | 5342 personal_data_->pref_service_->SetBoolean( |
| 5304 prefs::kAutofillProfileUseDatesFixed, true); | 5343 prefs::kAutofillProfileUseDatesFixed, true); |
| 5305 | 5344 |
| 5306 // Create a profile. The use date will be set to now automatically. | 5345 // Create a profile. The use date will be set to now automatically. |
| 5307 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 5346 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 5308 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", | 5347 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", |
| 5309 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", | 5348 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 5310 "", "Springfield", "IL", "91601", "US", "12345678910"); | 5349 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 5350 profile1.set_use_date(kArbitraryTime); |
| 5311 | 5351 |
| 5312 // Create another profile and set its use date to the default value. | 5352 // Create another profile and set its use date to the default value. |
| 5313 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 5353 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 5314 test::SetProfileInfo(&profile2, "Marge", "", "Simpson", | 5354 test::SetProfileInfo(&profile2, "Marge", "", "Simpson", |
| 5315 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", | 5355 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 5316 "", "Springfield", "IL", "91601", "US", "12345678910"); | 5356 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 5317 profile2.set_use_date(base::Time()); | 5357 profile2.set_use_date(base::Time()); |
| 5318 | 5358 |
| 5319 personal_data_->AddProfile(profile1); | 5359 personal_data_->AddProfile(profile1); |
| 5320 personal_data_->AddProfile(profile2); | 5360 personal_data_->AddProfile(profile2); |
| 5321 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5361 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5322 .WillOnce(QuitMainMessageLoop()); | 5362 .WillOnce(QuitMainMessageLoop()); |
| 5323 base::RunLoop().Run(); | 5363 base::RunLoop().Run(); |
| 5324 | 5364 |
| 5325 // Get a sorted list of profiles. |profile1| will be first and |profile2| will | 5365 // Get a sorted list of profiles. |profile1| will be first and |profile2| will |
| 5326 // be second. | 5366 // be second. |
| 5327 std::vector<AutofillProfile*> saved_profiles = | 5367 std::vector<AutofillProfile*> saved_profiles = |
| 5328 personal_data_->GetProfilesToSuggest(); | 5368 personal_data_->GetProfilesToSuggest(); |
| 5329 | 5369 |
| 5330 ASSERT_EQ(2U, saved_profiles.size()); | 5370 ASSERT_EQ(2U, saved_profiles.size()); |
| 5331 | 5371 |
| 5332 // The use dates should not have been modified. | 5372 // The use dates should not have been modified. |
| 5333 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), | 5373 EXPECT_EQ(profile1.use_date(), saved_profiles[0]->use_date()); |
| 5334 saved_profiles[0]->use_date()); | 5374 EXPECT_EQ(profile2.use_date(), saved_profiles[1]->use_date()); |
| 5335 EXPECT_EQ(base::Time(), saved_profiles[1]->use_date()); | |
| 5336 | 5375 |
| 5337 // Set the pref to false to indicate the fix has never been run. | 5376 // Set the pref to false to indicate the fix has never been run. |
| 5338 personal_data_->pref_service_->SetBoolean( | 5377 personal_data_->pref_service_->SetBoolean( |
| 5339 prefs::kAutofillProfileUseDatesFixed, false); | 5378 prefs::kAutofillProfileUseDatesFixed, false); |
| 5340 | 5379 |
| 5380 // Create the test clock and set the time to a specific value. |
| 5381 TestAutofillClock test_clock; |
| 5382 test_clock.SetNow(kSomeLaterTime); |
| 5383 |
| 5341 personal_data_->ApplyProfileUseDatesFix(); | 5384 personal_data_->ApplyProfileUseDatesFix(); |
| 5342 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5385 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5343 .WillOnce(QuitMainMessageLoop()); | 5386 .WillOnce(QuitMainMessageLoop()); |
| 5344 base::RunLoop().Run(); | 5387 base::RunLoop().Run(); |
| 5345 | 5388 |
| 5346 // Get a sorted list of profiles. | 5389 // Get a sorted list of profiles. |
| 5347 saved_profiles = personal_data_->GetProfilesToSuggest(); | 5390 saved_profiles = personal_data_->GetProfilesToSuggest(); |
| 5348 | 5391 |
| 5349 ASSERT_EQ(2U, saved_profiles.size()); | 5392 ASSERT_EQ(2U, saved_profiles.size()); |
| 5350 | 5393 |
| 5351 // |profile1|'s use date should not have been modified. | 5394 // |profile1|'s use date should not have been modified. |
| 5352 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), | 5395 EXPECT_LE(profile1.use_date(), saved_profiles[0]->use_date()); |
| 5353 saved_profiles[0]->use_date()); | |
| 5354 // |profile2|'s use date should have been set to two weeks before now. | 5396 // |profile2|'s use date should have been set to two weeks before now. |
| 5355 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(15), | 5397 EXPECT_EQ(kSomeLaterTime - base::TimeDelta::FromDays(14), |
| 5356 saved_profiles[1]->use_date()); | |
| 5357 EXPECT_GE(base::Time::Now() - base::TimeDelta::FromDays(13), | |
| 5358 saved_profiles[1]->use_date()); | 5398 saved_profiles[1]->use_date()); |
| 5359 } | 5399 } |
| 5360 | 5400 |
| 5361 // Tests that ApplyProfileUseDatesFix does apply the fix if it's already been | 5401 // Tests that ApplyProfileUseDatesFix does apply the fix if it's already been |
| 5362 // applied. | 5402 // applied. |
| 5363 TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix_NotAppliedTwice) { | 5403 TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix_NotAppliedTwice) { |
| 5364 // Set the kAutofillProfileUseDatesFixed pref which means the fix has already | 5404 // Set the kAutofillProfileUseDatesFixed pref which means the fix has already |
| 5365 // been applied. | 5405 // been applied. |
| 5366 personal_data_->pref_service_->SetBoolean( | 5406 personal_data_->pref_service_->SetBoolean( |
| 5367 prefs::kAutofillProfileUseDatesFixed, true); | 5407 prefs::kAutofillProfileUseDatesFixed, true); |
| 5368 | 5408 |
| 5369 // Create two profiles. | 5409 // Create two profiles. |
| 5370 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 5410 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 5371 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", | 5411 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", |
| 5372 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", | 5412 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 5373 "", "Springfield", "IL", "91601", "US", "12345678910"); | 5413 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 5414 profile1.set_use_date(kArbitraryTime); |
| 5374 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 5415 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 5375 test::SetProfileInfo(&profile2, "Marge", "", "Simpson", | 5416 test::SetProfileInfo(&profile2, "Marge", "", "Simpson", |
| 5376 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", | 5417 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 5377 "", "Springfield", "IL", "91601", "US", "12345678910"); | 5418 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 5378 profile2.set_use_date(base::Time()); | 5419 profile2.set_use_date(base::Time()); |
| 5379 | 5420 |
| 5380 personal_data_->AddProfile(profile1); | 5421 personal_data_->AddProfile(profile1); |
| 5381 personal_data_->AddProfile(profile2); | 5422 personal_data_->AddProfile(profile2); |
| 5382 | 5423 |
| 5383 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5424 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5384 .WillOnce(QuitMainMessageLoop()); | 5425 .WillOnce(QuitMainMessageLoop()); |
| 5385 base::RunLoop().Run(); | 5426 base::RunLoop().Run(); |
| 5386 | 5427 |
| 5387 // Get a sorted list of profiles. |profile1| will be first and |profile2| will | 5428 // Get a sorted list of profiles. |profile1| will be first and |profile2| will |
| 5388 // be second. | 5429 // be second. |
| 5389 std::vector<AutofillProfile*> saved_profiles = | 5430 std::vector<AutofillProfile*> saved_profiles = |
| 5390 personal_data_->GetProfilesToSuggest(); | 5431 personal_data_->GetProfilesToSuggest(); |
| 5391 | 5432 |
| 5392 ASSERT_EQ(2U, saved_profiles.size()); | 5433 ASSERT_EQ(2U, saved_profiles.size()); |
| 5393 // The use dates should not have been modified. | 5434 // The use dates should not have been modified. |
| 5394 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), | 5435 EXPECT_EQ(profile1.use_date(), saved_profiles[0]->use_date()); |
| 5395 saved_profiles[0]->use_date()); | |
| 5396 EXPECT_EQ(base::Time(), saved_profiles[1]->use_date()); | 5436 EXPECT_EQ(base::Time(), saved_profiles[1]->use_date()); |
| 5397 } | 5437 } |
| 5398 | 5438 |
| 5399 // Tests that ApplyDedupingRoutine works as expected in a realistic scenario. | 5439 // Tests that ApplyDedupingRoutine works as expected in a realistic scenario. |
| 5400 // Tests that it merges the diffent set of similar profiles independently and | 5440 // Tests that it merges the diffent set of similar profiles independently and |
| 5401 // that the resulting profiles have the right values, has no effect on the other | 5441 // that the resulting profiles have the right values, has no effect on the other |
| 5402 // profiles and that the data of verified profiles is not modified. | 5442 // profiles and that the data of verified profiles is not modified. |
| 5403 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleDedupes) { | 5443 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_MultipleDedupes) { |
| 5404 // Create a Homer home profile with a higher frecency score than other Homer | 5444 // Create a Homer home profile with a higher frecency score than other Homer |
| 5405 // profiles. | 5445 // profiles. |
| 5406 AutofillProfile Homer1(base::GenerateGUID(), "https://www.example.com"); | 5446 AutofillProfile Homer1(base::GenerateGUID(), "https://www.example.com"); |
| 5407 test::SetProfileInfo(&Homer1, "Homer", "J", "Simpson", | 5447 test::SetProfileInfo(&Homer1, "Homer", "J", "Simpson", |
| 5408 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | 5448 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
| 5409 "", "Springfield", "IL", "91601", "US", ""); | 5449 "", "Springfield", "IL", "91601", "US", ""); |
| 5410 Homer1.set_use_count(10); | 5450 Homer1.set_use_count(10); |
| 5411 Homer1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 5451 Homer1.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(1)); |
| 5412 | 5452 |
| 5413 // Create a Homer home profile with a medium frecency score compared to other | 5453 // Create a Homer home profile with a medium frecency score compared to other |
| 5414 // Homer profiles. | 5454 // Homer profiles. |
| 5415 AutofillProfile Homer2(base::GenerateGUID(), "https://www.example.com"); | 5455 AutofillProfile Homer2(base::GenerateGUID(), "https://www.example.com"); |
| 5416 test::SetProfileInfo(&Homer2, "Homer", "Jay", "Simpson", | 5456 test::SetProfileInfo(&Homer2, "Homer", "Jay", "Simpson", |
| 5417 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", | 5457 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 5418 "Springfield", "IL", "91601", "", "12345678910"); | 5458 "Springfield", "IL", "91601", "", "12345678910"); |
| 5419 Homer2.set_use_count(5); | 5459 Homer2.set_use_count(5); |
| 5420 Homer2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 5460 Homer2.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(3)); |
| 5421 | 5461 |
| 5422 // Create a Homer home profile with a lower frecency score than other Homer | 5462 // Create a Homer home profile with a lower frecency score than other Homer |
| 5423 // profiles. | 5463 // profiles. |
| 5424 AutofillProfile Homer3(base::GenerateGUID(), "https://www.example.com"); | 5464 AutofillProfile Homer3(base::GenerateGUID(), "https://www.example.com"); |
| 5425 test::SetProfileInfo(&Homer3, "Homer", "J", "Simpson", | 5465 test::SetProfileInfo(&Homer3, "Homer", "J", "Simpson", |
| 5426 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", | 5466 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", |
| 5427 "", "Springfield", "IL", "91601", "", ""); | 5467 "", "Springfield", "IL", "91601", "", ""); |
| 5428 Homer3.set_use_count(3); | 5468 Homer3.set_use_count(3); |
| 5429 Homer3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 5469 Homer3.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(5)); |
| 5430 | 5470 |
| 5431 // Create a Homer work profile (different address). | 5471 // Create a Homer work profile (different address). |
| 5432 AutofillProfile Homer4(base::GenerateGUID(), "https://www.example.com"); | 5472 AutofillProfile Homer4(base::GenerateGUID(), "https://www.example.com"); |
| 5433 test::SetProfileInfo(&Homer4, "Homer", "J", "Simpson", | 5473 test::SetProfileInfo(&Homer4, "Homer", "J", "Simpson", |
| 5434 "homer.simpson@abc.com", "Fox", "12 Nuclear Plant.", "", | 5474 "homer.simpson@abc.com", "Fox", "12 Nuclear Plant.", "", |
| 5435 "Springfield", "IL", "91601", "US", "9876543"); | 5475 "Springfield", "IL", "91601", "US", "9876543"); |
| 5436 Homer4.set_use_count(3); | 5476 Homer4.set_use_count(3); |
| 5437 Homer4.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 5477 Homer4.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(5)); |
| 5438 | 5478 |
| 5439 // Create a Marge profile with a lower frecency score that other Marge | 5479 // Create a Marge profile with a lower frecency score that other Marge |
| 5440 // profiles. | 5480 // profiles. |
| 5441 AutofillProfile Marge1(base::GenerateGUID(), kSettingsOrigin); | 5481 AutofillProfile Marge1(base::GenerateGUID(), kSettingsOrigin); |
| 5442 test::SetProfileInfo(&Marge1, "Marjorie", "J", "Simpson", | 5482 test::SetProfileInfo(&Marge1, "Marjorie", "J", "Simpson", |
| 5443 "marge.simpson@abc.com", "", "742 Evergreen Terrace", "", | 5483 "marge.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 5444 "Springfield", "IL", "91601", "", "12345678910"); | 5484 "Springfield", "IL", "91601", "", "12345678910"); |
| 5445 Marge1.set_use_count(4); | 5485 Marge1.set_use_count(4); |
| 5446 Marge1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 5486 Marge1.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(3)); |
| 5447 | 5487 |
| 5448 // Create a verified Marge home profile with a lower frecency score that the | 5488 // Create a verified Marge home profile with a lower frecency score that the |
| 5449 // other Marge profile. | 5489 // other Marge profile. |
| 5450 AutofillProfile Marge2(base::GenerateGUID(), "https://www.example.com"); | 5490 AutofillProfile Marge2(base::GenerateGUID(), "https://www.example.com"); |
| 5451 test::SetProfileInfo(&Marge2, "Marjorie", "Jacqueline", "Simpson", | 5491 test::SetProfileInfo(&Marge2, "Marjorie", "Jacqueline", "Simpson", |
| 5452 "marge.simpson@abc.com", "", "742 Evergreen Terrace", "", | 5492 "marge.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 5453 "Springfield", "IL", "91601", "", "12345678910"); | 5493 "Springfield", "IL", "91601", "", "12345678910"); |
| 5454 Marge2.set_use_count(2); | 5494 Marge2.set_use_count(2); |
| 5455 Marge2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(3)); | 5495 Marge2.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(3)); |
| 5456 | 5496 |
| 5457 // Create a Barney profile (guest user). | 5497 // Create a Barney profile (guest user). |
| 5458 AutofillProfile Barney(base::GenerateGUID(), "https://www.example.com"); | 5498 AutofillProfile Barney(base::GenerateGUID(), "https://www.example.com"); |
| 5459 test::SetProfileInfo(&Barney, "Barney", "", "Gumble", "barney.gumble@abc.com", | 5499 test::SetProfileInfo(&Barney, "Barney", "", "Gumble", "barney.gumble@abc.com", |
| 5460 "ABC", "123 Other Street", "", "Springfield", "IL", | 5500 "ABC", "123 Other Street", "", "Springfield", "IL", |
| 5461 "91601", "", ""); | 5501 "91601", "", ""); |
| 5462 Barney.set_use_count(1); | 5502 Barney.set_use_count(1); |
| 5463 Barney.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(180)); | 5503 Barney.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(180)); |
| 5464 | 5504 |
| 5465 personal_data_->AddProfile(Homer1); | 5505 personal_data_->AddProfile(Homer1); |
| 5466 personal_data_->AddProfile(Homer2); | 5506 personal_data_->AddProfile(Homer2); |
| 5467 personal_data_->AddProfile(Homer3); | 5507 personal_data_->AddProfile(Homer3); |
| 5468 personal_data_->AddProfile(Homer4); | 5508 personal_data_->AddProfile(Homer4); |
| 5469 personal_data_->AddProfile(Marge1); | 5509 personal_data_->AddProfile(Marge1); |
| 5470 personal_data_->AddProfile(Marge2); | 5510 personal_data_->AddProfile(Marge2); |
| 5471 personal_data_->AddProfile(Barney); | 5511 personal_data_->AddProfile(Barney); |
| 5472 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5512 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 5473 .WillOnce(QuitMainMessageLoop()); | 5513 .WillOnce(QuitMainMessageLoop()); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5655 EnableAutofillProfileCleanup(); | 5695 EnableAutofillProfileCleanup(); |
| 5656 | 5696 |
| 5657 // The deduping routine should not be run. | 5697 // The deduping routine should not be run. |
| 5658 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); | 5698 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); |
| 5659 | 5699 |
| 5660 // The two duplicate profiles should still be present. | 5700 // The two duplicate profiles should still be present. |
| 5661 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 5701 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5662 } | 5702 } |
| 5663 | 5703 |
| 5664 } // namespace autofill | 5704 } // namespace autofill |
| OLD | NEW |