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

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

Issue 2607043002: [Autofill] Credit Card Autofill Last Used Date Experiment (Closed)
Patch Set: Enable unittest on android for time_formatting Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/personal_data_manager.h" 5 #include "components/autofill/core/browser/personal_data_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/files/scoped_temp_dir.h" 18 #include "base/files/scoped_temp_dir.h"
19 #include "base/guid.h" 19 #include "base/guid.h"
20 #include "base/i18n/time_formatting.h"
20 #include "base/memory/ptr_util.h" 21 #include "base/memory/ptr_util.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/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
27 #include "base/time/time.h" 27 #include "base/time/time.h"
28 #include "build/build_config.h" 28 #include "build/build_config.h"
29 #include "components/autofill/core/browser/autofill_experiments.h" 29 #include "components/autofill/core/browser/autofill_experiments.h"
30 #include "components/autofill/core/browser/autofill_profile.h" 30 #include "components/autofill/core/browser/autofill_profile.h"
31 #include "components/autofill/core/browser/autofill_test_utils.h" 31 #include "components/autofill/core/browser/autofill_test_utils.h"
32 #include "components/autofill/core/browser/field_types.h" 32 #include "components/autofill/core/browser/field_types.h"
33 #include "components/autofill/core/browser/form_structure.h" 33 #include "components/autofill/core/browser/form_structure.h"
34 #include "components/autofill/core/browser/personal_data_manager_observer.h" 34 #include "components/autofill/core/browser/personal_data_manager_observer.h"
35 #include "components/autofill/core/browser/webdata/autofill_table.h" 35 #include "components/autofill/core/browser/webdata/autofill_table.h"
36 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 36 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
37 #include "components/autofill/core/common/autofill_constants.h" 37 #include "components/autofill/core/common/autofill_constants.h"
38 #include "components/autofill/core/common/autofill_pref_names.h" 38 #include "components/autofill/core/common/autofill_pref_names.h"
39 #include "components/autofill/core/common/autofill_switches.h" 39 #include "components/autofill/core/common/autofill_switches.h"
40 #include "components/autofill/core/common/form_data.h" 40 #include "components/autofill/core/common/form_data.h"
41 #include "components/os_crypt/os_crypt_mocker.h" 41 #include "components/os_crypt/os_crypt_mocker.h"
42 #include "components/prefs/pref_service.h" 42 #include "components/prefs/pref_service.h"
43 #include "components/signin/core/browser/account_tracker_service.h" 43 #include "components/signin/core/browser/account_tracker_service.h"
44 #include "components/signin/core/browser/fake_signin_manager.h" 44 #include "components/signin/core/browser/fake_signin_manager.h"
45 #include "components/signin/core/browser/test_signin_client.h" 45 #include "components/signin/core/browser/test_signin_client.h"
46 #include "components/signin/core/common/signin_pref_names.h" 46 #include "components/signin/core/common/signin_pref_names.h"
47 #include "components/variations/entropy_provider.h" 47 #include "components/variations/variations_params_manager.h"
48 #include "components/variations/variations_associated_data.h"
49 #include "components/webdata/common/web_data_service_base.h" 48 #include "components/webdata/common/web_data_service_base.h"
50 #include "components/webdata/common/web_database_service.h" 49 #include "components/webdata/common/web_database_service.h"
51 #include "testing/gmock/include/gmock/gmock.h" 50 #include "testing/gmock/include/gmock/gmock.h"
52 #include "testing/gtest/include/gtest/gtest.h" 51 #include "testing/gtest/include/gtest/gtest.h"
53 52
54 using base::ASCIIToUTF16; 53 using base::ASCIIToUTF16;
55 using base::UTF8ToUTF16; 54 using base::UTF8ToUTF16;
56 55
57 namespace autofill { 56 namespace autofill {
58 namespace { 57 namespace {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 web_database_->LoadDatabase(); 138 web_database_->LoadDatabase();
140 autofill_database_service_ = new AutofillWebDataService( 139 autofill_database_service_ = new AutofillWebDataService(
141 web_database_, base::ThreadTaskRunnerHandle::Get(), 140 web_database_, base::ThreadTaskRunnerHandle::Get(),
142 base::ThreadTaskRunnerHandle::Get(), 141 base::ThreadTaskRunnerHandle::Get(),
143 WebDataServiceBase::ProfileErrorCallback()); 142 WebDataServiceBase::ProfileErrorCallback());
144 autofill_database_service_->Init(); 143 autofill_database_service_->Init();
145 144
146 test::DisableSystemServices(prefs_.get()); 145 test::DisableSystemServices(prefs_.get());
147 ResetPersonalDataManager(USER_MODE_NORMAL); 146 ResetPersonalDataManager(USER_MODE_NORMAL);
148 147
149 // There are no field trials enabled by default.
150 field_trial_list_.reset();
151
152 // Reset the deduping pref to its default value. 148 // Reset the deduping pref to its default value.
153 personal_data_->pref_service_->SetInteger( 149 personal_data_->pref_service_->SetInteger(
154 prefs::kAutofillLastVersionDeduped, 0); 150 prefs::kAutofillLastVersionDeduped, 0);
155 personal_data_->pref_service_->SetBoolean( 151 personal_data_->pref_service_->SetBoolean(
156 prefs::kAutofillProfileUseDatesFixed, false); 152 prefs::kAutofillProfileUseDatesFixed, false);
157 } 153 }
158 154
159 void TearDown() override { 155 void TearDown() override {
160 // Order of destruction is important as AutofillManager relies on 156 // Order of destruction is important as AutofillManager relies on
161 // PersonalDataManager to be around when it gets destroyed. 157 // PersonalDataManager to be around when it gets destroyed.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 "518765432109" /* Mastercard */, "12", "2999"); 279 "518765432109" /* Mastercard */, "12", "2999");
284 personal_data_->AddCreditCard(credit_card2); 280 personal_data_->AddCreditCard(credit_card2);
285 281
286 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 282 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
287 .WillOnce(QuitMainMessageLoop()); 283 .WillOnce(QuitMainMessageLoop());
288 base::RunLoop().Run(); 284 base::RunLoop().Run();
289 285
290 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 286 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
291 } 287 }
292 288
289 // Adds three local cards to the |personal_data_|. These cards are different:
290 // One was just added, one was already used in autofill, and the third was
291 // last used more than one year ago.
292 void SetupReferenceCreditCardsForLastUsedVariationTest() {
293 ASSERT_EQ(0U, personal_data_->GetCreditCards().size());
294 base::Time cur_time = base::Time::Now();
295
296 // Test for added to chrome.
297 CreditCard credit_card0("1141084B-72D7-4B73-90CF-3D6AC154673B",
298 "https://www.example.com");
299 credit_card0.set_use_count(1);
300 credit_card0.set_use_date(cur_time - base::TimeDelta::FromDays(1));
301 test::SetCreditCardInfo(&credit_card0, "John Dillinger",
302 "423456789012" /* Visa */, "01", "2021");
303 personal_data_->AddCreditCard(credit_card0);
304
305 // Test for last used date.
306 CreditCard credit_card1("287151C8-6AB1-487C-9095-28E80BE5DA15",
307 "https://www.example.com");
308 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow",
309 "347666888555" /* American Express */, "04",
310 "2021");
311 credit_card1.set_use_count(10);
312 credit_card1.set_use_date(cur_time - base::TimeDelta::FromDays(10));
313 personal_data_->AddCreditCard(credit_card1);
314
315 // Test for last used more than one year ago.
316 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B",
317 "https://www.example.com");
318 credit_card2.set_use_count(5);
319 credit_card2.set_use_date(cur_time - base::TimeDelta::FromDays(366));
320 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker",
321 "518765432109" /* Mastercard */, "12", "2021");
322 personal_data_->AddCreditCard(credit_card2);
323
324 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
325 .WillOnce(QuitMainMessageLoop());
326 base::RunLoop().Run();
327 }
328
293 // Helper methods that simply forward the call to the private member (to avoid 329 // Helper methods that simply forward the call to the private member (to avoid
294 // having to friend every test that needs to access the private 330 // having to friend every test that needs to access the private
295 // PersonalDataManager::ImportAddressProfile or ImportCreditCard). 331 // PersonalDataManager::ImportAddressProfile or ImportCreditCard).
296 bool ImportAddressProfiles(const FormStructure& form) { 332 bool ImportAddressProfiles(const FormStructure& form) {
297 return personal_data_->ImportAddressProfiles(form); 333 return personal_data_->ImportAddressProfiles(form);
298 } 334 }
299 bool ImportCreditCard(const FormStructure& form, 335 bool ImportCreditCard(const FormStructure& form,
300 bool should_return_local_card, 336 bool should_return_local_card,
301 std::unique_ptr<CreditCard>* imported_credit_card) { 337 std::unique_ptr<CreditCard>* imported_credit_card) {
302 return personal_data_->ImportCreditCard(form, should_return_local_card, 338 return personal_data_->ImportCreditCard(form, should_return_local_card,
303 imported_credit_card); 339 imported_credit_card);
304 } 340 }
305 341
306 // Sets up the profile order field trial group and parameter. Sets up the
307 // suggestions limit parameter to |limit_param|.
308 void EnableAutofillProfileLimitFieldTrial(const std::string& limit_param) {
309 DCHECK(!limit_param.empty());
310
311 // Clear the existing |field_trial_list_| and variation parameters.
312 field_trial_list_.reset(NULL);
313 field_trial_list_.reset(
314 new base::FieldTrialList(
315 base::MakeUnique<metrics::SHA1EntropyProvider>("foo")));
316 variations::testing::ClearAllVariationParams();
317
318 std::map<std::string, std::string> params;
319 params[kFrecencyFieldTrialLimitParam] = limit_param;
320 variations::AssociateVariationParams(kFrecencyFieldTrialName, "LimitToN",
321 params);
322
323 field_trial_ = base::FieldTrialList::CreateFieldTrial(
324 kFrecencyFieldTrialName, "LimitToN");
325 field_trial_->group();
326 }
327
328 void SubmitFormAndExpectImportedCardWithData(const FormData& form, 342 void SubmitFormAndExpectImportedCardWithData(const FormData& form,
329 const char* exp_name, 343 const char* exp_name,
330 const char* exp_cc_num, 344 const char* exp_cc_num,
331 const char* exp_cc_month, 345 const char* exp_cc_month,
332 const char* exp_cc_year) { 346 const char* exp_cc_year) {
333 FormStructure form_structure(form); 347 FormStructure form_structure(form);
334 form_structure.DetermineHeuristicTypes(); 348 form_structure.DetermineHeuristicTypes();
335 std::unique_ptr<CreditCard> imported_credit_card; 349 std::unique_ptr<CreditCard> imported_credit_card;
336 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 350 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
337 ASSERT_TRUE(imported_credit_card); 351 ASSERT_TRUE(imported_credit_card);
(...skipping 19 matching lines...) Expand all
357 std::unique_ptr<PrefService> prefs_; 371 std::unique_ptr<PrefService> prefs_;
358 std::unique_ptr<AccountTrackerService> account_tracker_; 372 std::unique_ptr<AccountTrackerService> account_tracker_;
359 std::unique_ptr<FakeSigninManagerBase> signin_manager_; 373 std::unique_ptr<FakeSigninManagerBase> signin_manager_;
360 std::unique_ptr<TestSigninClient> signin_client_; 374 std::unique_ptr<TestSigninClient> signin_client_;
361 scoped_refptr<AutofillWebDataService> autofill_database_service_; 375 scoped_refptr<AutofillWebDataService> autofill_database_service_;
362 scoped_refptr<WebDatabaseService> web_database_; 376 scoped_refptr<WebDatabaseService> web_database_;
363 AutofillTable* autofill_table_; // weak ref 377 AutofillTable* autofill_table_; // weak ref
364 PersonalDataLoadedObserverMock personal_data_observer_; 378 PersonalDataLoadedObserverMock personal_data_observer_;
365 std::unique_ptr<PersonalDataManager> personal_data_; 379 std::unique_ptr<PersonalDataManager> personal_data_;
366 380
367 std::unique_ptr<base::FieldTrialList> field_trial_list_; 381 variations::testing::VariationParamsManager variation_params_;
368 scoped_refptr<base::FieldTrial> field_trial_;
369 }; 382 };
370 383
371 TEST_F(PersonalDataManagerTest, AddProfile) { 384 TEST_F(PersonalDataManagerTest, AddProfile) {
372 // Add profile0 to the database. 385 // Add profile0 to the database.
373 AutofillProfile profile0(test::GetFullProfile()); 386 AutofillProfile profile0(test::GetFullProfile());
374 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); 387 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com"));
375 personal_data_->AddProfile(profile0); 388 personal_data_->AddProfile(profile0);
376 389
377 // Reload the database. 390 // Reload the database.
378 ResetPersonalDataManager(USER_MODE_NORMAL); 391 ResetPersonalDataManager(USER_MODE_NORMAL);
(...skipping 3096 matching lines...) Expand 10 before | Expand all | Expand 10 after
3475 3488
3476 ResetPersonalDataManager(USER_MODE_NORMAL); 3489 ResetPersonalDataManager(USER_MODE_NORMAL);
3477 3490
3478 // Verify that all the profiles are suggested. 3491 // Verify that all the profiles are suggested.
3479 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions( 3492 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions(
3480 AutofillType(NAME_FIRST), base::string16(), false, 3493 AutofillType(NAME_FIRST), base::string16(), false,
3481 std::vector<ServerFieldType>()); 3494 std::vector<ServerFieldType>());
3482 EXPECT_EQ(3U, suggestions.size()); 3495 EXPECT_EQ(3U, suggestions.size());
3483 3496
3484 // Verify that only two profiles are suggested. 3497 // Verify that only two profiles are suggested.
3485 EnableAutofillProfileLimitFieldTrial("2"); 3498 variation_params_.SetVariationParams(
Mathieu 2017/01/27 15:01:44 Thanks for doing this!
jiahuiguo 2017/02/03 07:11:17 Done.
3499 kFrecencyFieldTrialName,
3500 {{kFrecencyFieldTrialLimitParam, "2"}});
3486 3501
3487 suggestions = personal_data_->GetProfileSuggestions( 3502 suggestions = personal_data_->GetProfileSuggestions(
3488 AutofillType(NAME_FIRST), base::string16(), false, 3503 AutofillType(NAME_FIRST), base::string16(), false,
3489 std::vector<ServerFieldType>()); 3504 std::vector<ServerFieldType>());
3490 EXPECT_EQ(2U, suggestions.size()); 3505 EXPECT_EQ(2U, suggestions.size());
3506
3507 variation_params_.ClearAllVariationParams();
3491 } 3508 }
3492 3509
3493 // Tests that GetProfileSuggestions returns the right number of profile 3510 // Tests that GetProfileSuggestions returns the right number of profile
3494 // suggestions when the limit to three field trial is set and there are less 3511 // suggestions when the limit to three field trial is set and there are less
3495 // than three profiles. 3512 // than three profiles.
3496 TEST_F(PersonalDataManagerTest, 3513 TEST_F(PersonalDataManagerTest,
3497 GetProfileSuggestions_LimitIsMoreThanProfileSuggestions) { 3514 GetProfileSuggestions_LimitIsMoreThanProfileSuggestions) {
3498 EnableAutofillProfileLimitFieldTrial("3"); 3515 variation_params_.SetVariationParams(
3516 kFrecencyFieldTrialName,
3517 {{kFrecencyFieldTrialLimitParam, "3"}});
3499 3518
3500 // Set up 2 different profiles. 3519 // Set up 2 different profiles.
3501 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); 3520 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com");
3502 test::SetProfileInfo(&profile1, "Marion1", "Mitchell", "Morrison", 3521 test::SetProfileInfo(&profile1, "Marion1", "Mitchell", "Morrison",
3503 "johnwayne@me.xyz", "Fox", 3522 "johnwayne@me.xyz", "Fox",
3504 "123 Zoo St.\nSecond Line\nThird line", "unit 5", 3523 "123 Zoo St.\nSecond Line\nThird line", "unit 5",
3505 "Hollywood", "CA", "91601", "US", "12345678910"); 3524 "Hollywood", "CA", "91601", "US", "12345678910");
3506 personal_data_->AddProfile(profile1); 3525 personal_data_->AddProfile(profile1);
3507 3526
3508 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); 3527 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
3509 test::SetProfileInfo(&profile2, "Marion2", "Mitchell", "Morrison", 3528 test::SetProfileInfo(&profile2, "Marion2", "Mitchell", "Morrison",
3510 "johnwayne@me.xyz", "Fox", 3529 "johnwayne@me.xyz", "Fox",
3511 "123 Zoo St.\nSecond Line\nThird line", "unit 5", 3530 "123 Zoo St.\nSecond Line\nThird line", "unit 5",
3512 "Hollywood", "CA", "91601", "US", "12345678910"); 3531 "Hollywood", "CA", "91601", "US", "12345678910");
3513 personal_data_->AddProfile(profile2); 3532 personal_data_->AddProfile(profile2);
3514 3533
3515 ResetPersonalDataManager(USER_MODE_NORMAL); 3534 ResetPersonalDataManager(USER_MODE_NORMAL);
3516 3535
3517 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions( 3536 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions(
3518 AutofillType(NAME_FIRST), base::string16(), false, 3537 AutofillType(NAME_FIRST), base::string16(), false,
3519 std::vector<ServerFieldType>()); 3538 std::vector<ServerFieldType>());
3520 EXPECT_EQ(2U, suggestions.size()); 3539 EXPECT_EQ(2U, suggestions.size());
3540
3541 variation_params_.ClearAllVariationParams();
3521 } 3542 }
3522 3543
3523 // Test that a masked server card is not suggested if more that six numbers have 3544 // Test that a masked server card is not suggested if more that six numbers have
3524 // been typed in the field. 3545 // been typed in the field.
3525 TEST_F(PersonalDataManagerTest, 3546 TEST_F(PersonalDataManagerTest,
3526 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) { 3547 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) {
3527 EnableWalletCardImport(); 3548 EnableWalletCardImport();
3528 3549
3529 // Add a masked server card. 3550 // Add a masked server card.
3530 std::vector<CreditCard> server_cards; 3551 std::vector<CreditCard> server_cards;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
3807 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3828 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3808 .WillOnce(QuitMainMessageLoop()); 3829 .WillOnce(QuitMainMessageLoop());
3809 base::RunLoop().Run(); 3830 base::RunLoop().Run();
3810 3831
3811 suggestions = personal_data_->GetCreditCardSuggestions( 3832 suggestions = personal_data_->GetCreditCardSuggestions(
3812 AutofillType(CREDIT_CARD_NAME_FULL), 3833 AutofillType(CREDIT_CARD_NAME_FULL),
3813 /* field_contents= */ base::string16()); 3834 /* field_contents= */ base::string16());
3814 ASSERT_EQ(3U, suggestions.size()); 3835 ASSERT_EQ(3U, suggestions.size());
3815 } 3836 }
3816 3837
3838 // Test that credit card last used date suggestion can be generated correctly
3839 // in variation 1: only show last used date.
3840 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_LastUsedDateOnly) {
Mathieu 2017/01/27 15:01:44 I think you would need to unit-test the GetLastUse
jiahuiguo 2017/02/03 07:11:17 Done.
3841 SetupReferenceCreditCardsForLastUsedVariationTest();
3842
3843 variation_params_.SetVariationParamsWithFeatureAssociations(
3844 kAutofillCreditCardLastUsedDateDisplay.name,
3845 {{kAutofillCreditCardLastUsedDateShowExpirationDateKey, "false"},
3846 {kAutofillCreditCardLastUsedDateShowTimeDetailKey, "false"}},
3847 {kAutofillCreditCardLastUsedDateDisplay.name});
3848
3849 const std::vector<CreditCard*> credit_cards =
3850 personal_data_->GetCreditCards();
3851 ASSERT_EQ(3U, credit_cards.size());
3852
3853 std::vector<Suggestion> suggestions =
3854 personal_data_->GetCreditCardSuggestions(
3855 AutofillType(CREDIT_CARD_NUMBER),
3856 /* field_contents= */ base::string16());
3857 ASSERT_EQ(3U, suggestions.size());
3858
3859 EXPECT_EQ(
3860 ASCIIToUTF16("Last used: ") +
3861 base::TimeFormatWithPattern(credit_cards[2]->use_date(), "MMMdd"),
Mathieu 2017/01/27 15:01:44 I don't think we should call TimeFormatWithPattern
jungshik at Google 2017/01/27 21:43:30 Well, TimeFormatWithPattern is already tested in i
jiahuiguo 2017/02/03 07:11:17 Done.
jiahuiguo 2017/02/03 07:11:17 Done.
3862 suggestions[0].label);
3863
3864 #if defined(GOOGLE_CHROME_BUILD)
3865 EXPECT_EQ(
3866 ASCIIToUTF16("Added to Chrome: ") +
3867 base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
3868 suggestions[1].label);
3869 #elif defined(CHROMIUM_BUILD)
3870 EXPECT_EQ(
3871 ASCIIToUTF16("Added to Chromium: ") +
3872 base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
3873 suggestions[1].label);
3874 #endif
3875
3876 EXPECT_EQ(ASCIIToUTF16("Last used over a year ago"), suggestions[2].label);
3877
3878 variation_params_.ClearAllVariationParams();
3879 }
3880
3881 // Test that credit card last used date suggestion can be generated correctly
3882 // in variation 2: show expiration date and last used date.
3883 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpAndLastUsedDate) {
3884 SetupReferenceCreditCardsForLastUsedVariationTest();
3885
3886 variation_params_.SetVariationParamsWithFeatureAssociations(
3887 kAutofillCreditCardLastUsedDateDisplay.name,
3888 {{kAutofillCreditCardLastUsedDateShowExpirationDateKey, "true"},
3889 {kAutofillCreditCardLastUsedDateShowTimeDetailKey, "false"}},
3890 {kAutofillCreditCardLastUsedDateDisplay.name});
3891
3892 const std::vector<CreditCard*> credit_cards =
3893 personal_data_->GetCreditCards();
3894 ASSERT_EQ(3U, credit_cards.size());
3895
3896 std::vector<Suggestion> suggestions =
3897 personal_data_->GetCreditCardSuggestions(
3898 AutofillType(CREDIT_CARD_NUMBER),
3899 /* field_contents= */ base::string16());
3900 ASSERT_EQ(3U, suggestions.size());
3901
3902 EXPECT_EQ(
3903 ASCIIToUTF16("Exp: 04/21, last used: ") +
3904 base::TimeFormatWithPattern(credit_cards[2]->use_date(), "MMMdd"),
3905 suggestions[0].label);
3906
3907 #if defined(GOOGLE_CHROME_BUILD)
3908 EXPECT_EQ(
3909 ASCIIToUTF16("Exp: 01/21, added to Chrome: ") +
3910 base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
3911 suggestions[1].label);
3912 #elif defined(CHROMIUM_BUILD)
3913 EXPECT_EQ(
3914 ASCIIToUTF16("Exp: 01/21, added to Chromium: ") +
3915 base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
3916 suggestions[1].label);
3917 #endif
3918
3919 EXPECT_EQ(ASCIIToUTF16("Exp: 12/21, last used over a year ago"),
3920 suggestions[2].label);
3921
3922 variation_params_.ClearAllVariationParams();
3923 }
3924
3925 // Test that credit card last used date suggestion can be generated correctly
3926 // in variation 3: show last used date detail.
3927 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_LastUsedDateDetail) {
3928 SetupReferenceCreditCardsForLastUsedVariationTest();
3929
3930 variation_params_.SetVariationParamsWithFeatureAssociations(
3931 kAutofillCreditCardLastUsedDateDisplay.name,
3932 {{kAutofillCreditCardLastUsedDateShowExpirationDateKey, "false"},
3933 {kAutofillCreditCardLastUsedDateShowTimeDetailKey, "true"}},
3934 {kAutofillCreditCardLastUsedDateDisplay.name});
3935
3936 const std::vector<CreditCard*> credit_cards =
3937 personal_data_->GetCreditCards();
3938 ASSERT_EQ(3U, credit_cards.size());
3939
3940 std::vector<Suggestion> suggestions =
3941 personal_data_->GetCreditCardSuggestions(
3942 AutofillType(CREDIT_CARD_NUMBER),
3943 /* field_contents= */ base::string16());
3944 ASSERT_EQ(3U, suggestions.size());
3945
3946 EXPECT_EQ(
3947 ASCIIToUTF16("Last used: ") +
3948 base::TimeFormatWithPattern(credit_cards[2]->use_date(), "MMMddjmm"),
3949 suggestions[0].label);
3950
3951 #if defined(GOOGLE_CHROME_BUILD)
3952 EXPECT_EQ(
3953 ASCIIToUTF16("Added to Chrome: ") +
3954 base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
3955 suggestions[1].label);
3956 #elif defined(CHROMIUM_BUILD)
3957 EXPECT_EQ(
3958 ASCIIToUTF16("Added to Chromium: ") +
3959 base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
3960 suggestions[1].label);
3961 #endif
3962
3963 EXPECT_EQ(ASCIIToUTF16("Last used over a year ago"), suggestions[2].label);
3964
3965 variation_params_.ClearAllVariationParams();
3966 }
3967
3968 // Test that credit card last used date suggestion can be generated correctly
3969 // in variation 4: show expiration date and last used date detail.
3970 TEST_F(PersonalDataManagerTest,
3971 GetCreditCardSuggestions_ExpAndLastUsedDateDetail) {
3972 SetupReferenceCreditCardsForLastUsedVariationTest();
3973
3974 variation_params_.SetVariationParamsWithFeatureAssociations(
3975 kAutofillCreditCardLastUsedDateDisplay.name,
3976 {{kAutofillCreditCardLastUsedDateShowExpirationDateKey, "true"},
3977 {kAutofillCreditCardLastUsedDateShowTimeDetailKey, "true"}},
3978 {kAutofillCreditCardLastUsedDateDisplay.name});
3979
3980 const std::vector<CreditCard*> credit_cards =
3981 personal_data_->GetCreditCards();
3982 ASSERT_EQ(3U, credit_cards.size());
3983
3984 std::vector<Suggestion> suggestions =
3985 personal_data_->GetCreditCardSuggestions(
3986 AutofillType(CREDIT_CARD_NUMBER),
3987 /* field_contents= */ base::string16());
3988 ASSERT_EQ(3U, suggestions.size());
3989
3990 EXPECT_EQ(
3991 ASCIIToUTF16("Exp: 04/21, last used: ") +
3992 base::TimeFormatWithPattern(credit_cards[2]->use_date(), "MMMddjmm"),
3993 suggestions[0].label);
3994
3995 #if defined(GOOGLE_CHROME_BUILD)
3996 EXPECT_EQ(
3997 ASCIIToUTF16("Exp: 01/21, added to Chrome: ") +
3998 base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
3999 suggestions[1].label);
4000 #elif defined(CHROMIUM_BUILD)
4001 EXPECT_EQ(
4002 ASCIIToUTF16("Exp: 01/21, added to Chromium: ") +
4003 base::TimeFormatWithPattern(credit_cards[1]->use_date(), "MMMdd"),
4004 suggestions[1].label);
4005 #endif
4006
4007 EXPECT_EQ(ASCIIToUTF16("Exp: 12/21, last used over a year ago"),
4008 suggestions[2].label);
4009
4010 variation_params_.ClearAllVariationParams();
4011 }
4012
3817 // Tests that only the full server card is kept when deduping with a local 4013 // Tests that only the full server card is kept when deduping with a local
3818 // duplicate of it. 4014 // duplicate of it.
3819 TEST_F(PersonalDataManagerTest, 4015 TEST_F(PersonalDataManagerTest,
3820 DedupeCreditCardToSuggest_FullServerShadowsLocal) { 4016 DedupeCreditCardToSuggest_FullServerShadowsLocal) {
3821 std::list<CreditCard*> credit_cards; 4017 std::list<CreditCard*> credit_cards;
3822 4018
3823 // Create 3 different local credit cards. 4019 // Create 3 different local credit cards.
3824 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", 4020 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15",
3825 "https://www.example.com"); 4021 "https://www.example.com");
3826 test::SetCreditCardInfo(&local_card, "Homer Simpson", 4022 test::SetCreditCardInfo(&local_card, "Homer Simpson",
(...skipping 1812 matching lines...) Expand 10 before | Expand all | Expand 10 after
5639 EnableAutofillProfileCleanup(); 5835 EnableAutofillProfileCleanup();
5640 5836
5641 // The deduping routine should not be run. 5837 // The deduping routine should not be run.
5642 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); 5838 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine());
5643 5839
5644 // The two duplicate profiles should still be present. 5840 // The two duplicate profiles should still be present.
5645 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); 5841 EXPECT_EQ(2U, personal_data_->GetProfiles().size());
5646 } 5842 }
5647 5843
5648 } // namespace autofill 5844 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698