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