Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(981)

Side by Side Diff: components/autofill/core/browser/personal_data_manager_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698