Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/files/scoped_temp_dir.h" | 18 #include "base/files/scoped_temp_dir.h" |
| 19 #include "base/guid.h" | 19 #include "base/guid.h" |
| 20 #include "base/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/test/simple_test_clock.h" | 26 #include "base/test/simple_test_clock.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| 28 #include "base/time/time.h" | 28 #include "base/time/time.h" |
| 29 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| 30 #include "components/autofill/core/browser/autofill_experiments.h" | 30 #include "components/autofill/core/browser/autofill_experiments.h" |
| 31 #include "components/autofill/core/browser/autofill_profile.h" | 31 #include "components/autofill/core/browser/autofill_profile.h" |
| 32 #include "components/autofill/core/browser/autofill_test_utils.h" | 32 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 33 #include "components/autofill/core/browser/field_types.h" | 33 #include "components/autofill/core/browser/field_types.h" |
| 34 #include "components/autofill/core/browser/form_structure.h" | 34 #include "components/autofill/core/browser/form_structure.h" |
| 35 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 35 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 36 #include "components/autofill/core/browser/test_autofill_clock.h" | 36 #include "components/autofill/core/browser/test_autofill_clock.h" |
| 37 #include "components/autofill/core/browser/webdata/autofill_table.h" | 37 #include "components/autofill/core/browser/webdata/autofill_table.h" |
| 38 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 38 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| 39 #include "components/autofill/core/common/autofill_clock.h" | 39 #include "components/autofill/core/common/autofill_clock.h" |
| 40 #include "components/autofill/core/common/autofill_constants.h" | 40 #include "components/autofill/core/common/autofill_constants.h" |
| 41 #include "components/autofill/core/common/autofill_pref_names.h" | 41 #include "components/autofill/core/common/autofill_pref_names.h" |
| 42 #include "components/autofill/core/common/autofill_switches.h" | 42 #include "components/autofill/core/common/autofill_switches.h" |
| 43 #include "components/autofill/core/common/form_data.h" | 43 #include "components/autofill/core/common/form_data.h" |
| 44 #include "components/os_crypt/os_crypt_mocker.h" | 44 #include "components/os_crypt/os_crypt_mocker.h" |
| 45 #include "components/prefs/pref_service.h" | 45 #include "components/prefs/pref_service.h" |
| 46 #include "components/signin/core/browser/account_tracker_service.h" | 46 #include "components/signin/core/browser/account_tracker_service.h" |
| 47 #include "components/signin/core/browser/fake_signin_manager.h" | 47 #include "components/signin/core/browser/fake_signin_manager.h" |
| 48 #include "components/signin/core/browser/test_signin_client.h" | 48 #include "components/signin/core/browser/test_signin_client.h" |
| 49 #include "components/signin/core/common/signin_pref_names.h" | 49 #include "components/signin/core/common/signin_pref_names.h" |
| 50 #include "components/variations/entropy_provider.h" | 50 #include "components/variations/variations_params_manager.h" |
| 51 #include "components/variations/variations_associated_data.h" | |
| 52 #include "components/webdata/common/web_data_service_base.h" | 51 #include "components/webdata/common/web_data_service_base.h" |
| 53 #include "components/webdata/common/web_database_service.h" | 52 #include "components/webdata/common/web_database_service.h" |
| 54 #include "testing/gmock/include/gmock/gmock.h" | 53 #include "testing/gmock/include/gmock/gmock.h" |
| 55 #include "testing/gtest/include/gtest/gtest.h" | 54 #include "testing/gtest/include/gtest/gtest.h" |
| 56 | 55 |
| 57 using base::ASCIIToUTF16; | 56 using base::ASCIIToUTF16; |
| 58 using base::UTF8ToUTF16; | 57 using base::UTF8ToUTF16; |
| 59 | 58 |
| 60 namespace autofill { | 59 namespace autofill { |
| 61 namespace { | 60 namespace { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 web_database_->LoadDatabase(); | 145 web_database_->LoadDatabase(); |
| 147 autofill_database_service_ = new AutofillWebDataService( | 146 autofill_database_service_ = new AutofillWebDataService( |
| 148 web_database_, base::ThreadTaskRunnerHandle::Get(), | 147 web_database_, base::ThreadTaskRunnerHandle::Get(), |
| 149 base::ThreadTaskRunnerHandle::Get(), | 148 base::ThreadTaskRunnerHandle::Get(), |
| 150 WebDataServiceBase::ProfileErrorCallback()); | 149 WebDataServiceBase::ProfileErrorCallback()); |
| 151 autofill_database_service_->Init(); | 150 autofill_database_service_->Init(); |
| 152 | 151 |
| 153 test::DisableSystemServices(prefs_.get()); | 152 test::DisableSystemServices(prefs_.get()); |
| 154 ResetPersonalDataManager(USER_MODE_NORMAL); | 153 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 155 | 154 |
| 156 // There are no field trials enabled by default. | |
| 157 field_trial_list_.reset(); | |
| 158 | |
| 159 // Reset the deduping pref to its default value. | 155 // Reset the deduping pref to its default value. |
| 160 personal_data_->pref_service_->SetInteger( | 156 personal_data_->pref_service_->SetInteger( |
| 161 prefs::kAutofillLastVersionDeduped, 0); | 157 prefs::kAutofillLastVersionDeduped, 0); |
| 162 personal_data_->pref_service_->SetBoolean( | 158 personal_data_->pref_service_->SetBoolean( |
| 163 prefs::kAutofillProfileUseDatesFixed, false); | 159 prefs::kAutofillProfileUseDatesFixed, false); |
| 164 } | 160 } |
| 165 | 161 |
| 166 void TearDown() override { | 162 void TearDown() override { |
| 167 // Order of destruction is important as AutofillManager relies on | 163 // Order of destruction is important as AutofillManager relies on |
| 168 // PersonalDataManager to be around when it gets destroyed. | 164 // PersonalDataManager to be around when it gets destroyed. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 bool ImportAddressProfiles(const FormStructure& form) { | 301 bool ImportAddressProfiles(const FormStructure& form) { |
| 306 return personal_data_->ImportAddressProfiles(form); | 302 return personal_data_->ImportAddressProfiles(form); |
| 307 } | 303 } |
| 308 bool ImportCreditCard(const FormStructure& form, | 304 bool ImportCreditCard(const FormStructure& form, |
| 309 bool should_return_local_card, | 305 bool should_return_local_card, |
| 310 std::unique_ptr<CreditCard>* imported_credit_card) { | 306 std::unique_ptr<CreditCard>* imported_credit_card) { |
| 311 return personal_data_->ImportCreditCard(form, should_return_local_card, | 307 return personal_data_->ImportCreditCard(form, should_return_local_card, |
| 312 imported_credit_card); | 308 imported_credit_card); |
| 313 } | 309 } |
| 314 | 310 |
| 315 // Sets up the profile order field trial group and parameter. Sets up the | |
| 316 // suggestions limit parameter to |limit_param|. | |
| 317 void EnableAutofillProfileLimitFieldTrial(const std::string& limit_param) { | |
| 318 DCHECK(!limit_param.empty()); | |
| 319 | |
| 320 // Clear the existing |field_trial_list_| and variation parameters. | |
| 321 field_trial_list_.reset(NULL); | |
| 322 field_trial_list_.reset( | |
| 323 new base::FieldTrialList( | |
| 324 base::MakeUnique<metrics::SHA1EntropyProvider>("foo"))); | |
| 325 variations::testing::ClearAllVariationParams(); | |
| 326 | |
| 327 std::map<std::string, std::string> params; | |
| 328 params[kFrecencyFieldTrialLimitParam] = limit_param; | |
| 329 variations::AssociateVariationParams(kFrecencyFieldTrialName, "LimitToN", | |
| 330 params); | |
| 331 | |
| 332 field_trial_ = base::FieldTrialList::CreateFieldTrial( | |
| 333 kFrecencyFieldTrialName, "LimitToN"); | |
| 334 field_trial_->group(); | |
| 335 } | |
| 336 | |
| 337 void SubmitFormAndExpectImportedCardWithData(const FormData& form, | 311 void SubmitFormAndExpectImportedCardWithData(const FormData& form, |
| 338 const char* exp_name, | 312 const char* exp_name, |
| 339 const char* exp_cc_num, | 313 const char* exp_cc_num, |
| 340 const char* exp_cc_month, | 314 const char* exp_cc_month, |
| 341 const char* exp_cc_year) { | 315 const char* exp_cc_year) { |
| 342 FormStructure form_structure(form); | 316 FormStructure form_structure(form); |
| 343 form_structure.DetermineHeuristicTypes(); | 317 form_structure.DetermineHeuristicTypes(); |
| 344 std::unique_ptr<CreditCard> imported_credit_card; | 318 std::unique_ptr<CreditCard> imported_credit_card; |
| 345 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 319 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 346 ASSERT_TRUE(imported_credit_card); | 320 ASSERT_TRUE(imported_credit_card); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 366 std::unique_ptr<PrefService> prefs_; | 340 std::unique_ptr<PrefService> prefs_; |
| 367 std::unique_ptr<AccountTrackerService> account_tracker_; | 341 std::unique_ptr<AccountTrackerService> account_tracker_; |
| 368 std::unique_ptr<FakeSigninManagerBase> signin_manager_; | 342 std::unique_ptr<FakeSigninManagerBase> signin_manager_; |
| 369 std::unique_ptr<TestSigninClient> signin_client_; | 343 std::unique_ptr<TestSigninClient> signin_client_; |
| 370 scoped_refptr<AutofillWebDataService> autofill_database_service_; | 344 scoped_refptr<AutofillWebDataService> autofill_database_service_; |
| 371 scoped_refptr<WebDatabaseService> web_database_; | 345 scoped_refptr<WebDatabaseService> web_database_; |
| 372 AutofillTable* autofill_table_; // weak ref | 346 AutofillTable* autofill_table_; // weak ref |
| 373 PersonalDataLoadedObserverMock personal_data_observer_; | 347 PersonalDataLoadedObserverMock personal_data_observer_; |
| 374 std::unique_ptr<PersonalDataManager> personal_data_; | 348 std::unique_ptr<PersonalDataManager> personal_data_; |
| 375 | 349 |
| 376 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 350 variations::testing::VariationParamsManager variation_params_; |
| 377 scoped_refptr<base::FieldTrial> field_trial_; | |
| 378 }; | 351 }; |
| 379 | 352 |
| 380 TEST_F(PersonalDataManagerTest, AddProfile) { | 353 TEST_F(PersonalDataManagerTest, AddProfile) { |
| 381 // Add profile0 to the database. | 354 // Add profile0 to the database. |
| 382 AutofillProfile profile0(test::GetFullProfile()); | 355 AutofillProfile profile0(test::GetFullProfile()); |
| 383 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); | 356 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); |
| 384 personal_data_->AddProfile(profile0); | 357 personal_data_->AddProfile(profile0); |
| 385 | 358 |
| 386 // Reload the database. | 359 // Reload the database. |
| 387 ResetPersonalDataManager(USER_MODE_NORMAL); | 360 ResetPersonalDataManager(USER_MODE_NORMAL); |
| (...skipping 3109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3497 | 3470 |
| 3498 ResetPersonalDataManager(USER_MODE_NORMAL); | 3471 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 3499 | 3472 |
| 3500 // Verify that all the profiles are suggested. | 3473 // Verify that all the profiles are suggested. |
| 3501 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions( | 3474 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions( |
| 3502 AutofillType(NAME_FIRST), base::string16(), false, | 3475 AutofillType(NAME_FIRST), base::string16(), false, |
| 3503 std::vector<ServerFieldType>()); | 3476 std::vector<ServerFieldType>()); |
| 3504 EXPECT_EQ(3U, suggestions.size()); | 3477 EXPECT_EQ(3U, suggestions.size()); |
| 3505 | 3478 |
| 3506 // Verify that only two profiles are suggested. | 3479 // Verify that only two profiles are suggested. |
| 3507 EnableAutofillProfileLimitFieldTrial("2"); | 3480 variation_params_.SetVariationParams( |
| 3481 kFrecencyFieldTrialName, | |
| 3482 {{kFrecencyFieldTrialLimitParam, "2"}}); | |
| 3508 | 3483 |
| 3509 suggestions = personal_data_->GetProfileSuggestions( | 3484 suggestions = personal_data_->GetProfileSuggestions( |
| 3510 AutofillType(NAME_FIRST), base::string16(), false, | 3485 AutofillType(NAME_FIRST), base::string16(), false, |
| 3511 std::vector<ServerFieldType>()); | 3486 std::vector<ServerFieldType>()); |
| 3512 EXPECT_EQ(2U, suggestions.size()); | 3487 EXPECT_EQ(2U, suggestions.size()); |
| 3488 | |
| 3489 variation_params_.ClearAllVariationParams(); | |
|
Mathieu
2017/02/04 02:37:58
same, shouldn't need to be called?
jiahuiguo
2017/02/08 01:21:39
Done.
| |
| 3513 } | 3490 } |
| 3514 | 3491 |
| 3515 // Tests that GetProfileSuggestions returns the right number of profile | 3492 // Tests that GetProfileSuggestions returns the right number of profile |
| 3516 // suggestions when the limit to three field trial is set and there are less | 3493 // suggestions when the limit to three field trial is set and there are less |
| 3517 // than three profiles. | 3494 // than three profiles. |
| 3518 TEST_F(PersonalDataManagerTest, | 3495 TEST_F(PersonalDataManagerTest, |
| 3519 GetProfileSuggestions_LimitIsMoreThanProfileSuggestions) { | 3496 GetProfileSuggestions_LimitIsMoreThanProfileSuggestions) { |
| 3520 EnableAutofillProfileLimitFieldTrial("3"); | 3497 variation_params_.SetVariationParams( |
| 3498 kFrecencyFieldTrialName, | |
| 3499 {{kFrecencyFieldTrialLimitParam, "3"}}); | |
| 3521 | 3500 |
| 3522 // Set up 2 different profiles. | 3501 // Set up 2 different profiles. |
| 3523 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 3502 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
| 3524 test::SetProfileInfo(&profile1, "Marion1", "Mitchell", "Morrison", | 3503 test::SetProfileInfo(&profile1, "Marion1", "Mitchell", "Morrison", |
| 3525 "johnwayne@me.xyz", "Fox", | 3504 "johnwayne@me.xyz", "Fox", |
| 3526 "123 Zoo St.\nSecond Line\nThird line", "unit 5", | 3505 "123 Zoo St.\nSecond Line\nThird line", "unit 5", |
| 3527 "Hollywood", "CA", "91601", "US", "12345678910"); | 3506 "Hollywood", "CA", "91601", "US", "12345678910"); |
| 3528 personal_data_->AddProfile(profile1); | 3507 personal_data_->AddProfile(profile1); |
| 3529 | 3508 |
| 3530 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 3509 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 3531 test::SetProfileInfo(&profile2, "Marion2", "Mitchell", "Morrison", | 3510 test::SetProfileInfo(&profile2, "Marion2", "Mitchell", "Morrison", |
| 3532 "johnwayne@me.xyz", "Fox", | 3511 "johnwayne@me.xyz", "Fox", |
| 3533 "123 Zoo St.\nSecond Line\nThird line", "unit 5", | 3512 "123 Zoo St.\nSecond Line\nThird line", "unit 5", |
| 3534 "Hollywood", "CA", "91601", "US", "12345678910"); | 3513 "Hollywood", "CA", "91601", "US", "12345678910"); |
| 3535 personal_data_->AddProfile(profile2); | 3514 personal_data_->AddProfile(profile2); |
| 3536 | 3515 |
| 3537 ResetPersonalDataManager(USER_MODE_NORMAL); | 3516 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 3538 | 3517 |
| 3539 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions( | 3518 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions( |
| 3540 AutofillType(NAME_FIRST), base::string16(), false, | 3519 AutofillType(NAME_FIRST), base::string16(), false, |
| 3541 std::vector<ServerFieldType>()); | 3520 std::vector<ServerFieldType>()); |
| 3542 EXPECT_EQ(2U, suggestions.size()); | 3521 EXPECT_EQ(2U, suggestions.size()); |
| 3522 | |
| 3523 variation_params_.ClearAllVariationParams(); | |
|
Mathieu
2017/02/04 02:37:58
same
jiahuiguo
2017/02/08 01:21:39
Done.
| |
| 3543 } | 3524 } |
| 3544 | 3525 |
| 3545 // Test that a masked server card is not suggested if more that six numbers have | 3526 // Test that a masked server card is not suggested if more that six numbers have |
| 3546 // been typed in the field. | 3527 // been typed in the field. |
| 3547 TEST_F(PersonalDataManagerTest, | 3528 TEST_F(PersonalDataManagerTest, |
| 3548 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) { | 3529 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) { |
| 3549 EnableWalletCardImport(); | 3530 EnableWalletCardImport(); |
| 3550 | 3531 |
| 3551 // Add a masked server card. | 3532 // Add a masked server card. |
| 3552 std::vector<CreditCard> server_cards; | 3533 std::vector<CreditCard> server_cards; |
| (...skipping 2141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5694 EnableAutofillProfileCleanup(); | 5675 EnableAutofillProfileCleanup(); |
| 5695 | 5676 |
| 5696 // The deduping routine should not be run. | 5677 // The deduping routine should not be run. |
| 5697 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); | 5678 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); |
| 5698 | 5679 |
| 5699 // The two duplicate profiles should still be present. | 5680 // The two duplicate profiles should still be present. |
| 5700 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 5681 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5701 } | 5682 } |
| 5702 | 5683 |
| 5703 } // namespace autofill | 5684 } // namespace autofill |
| OLD | NEW |