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

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

Powered by Google App Engine
This is Rietveld 408576698