| 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> |
| (...skipping 4236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4247 FormStructure form_structure2(form2); | 4247 FormStructure form_structure2(form2); |
| 4248 form_structure2.DetermineHeuristicTypes(); | 4248 form_structure2.DetermineHeuristicTypes(); |
| 4249 std::unique_ptr<CreditCard> imported_credit_card2; | 4249 std::unique_ptr<CreditCard> imported_credit_card2; |
| 4250 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false, | 4250 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false, |
| 4251 &imported_credit_card2)); | 4251 &imported_credit_card2)); |
| 4252 EXPECT_FALSE(imported_credit_card2); | 4252 EXPECT_FALSE(imported_credit_card2); |
| 4253 } | 4253 } |
| 4254 | 4254 |
| 4255 // Tests the SaveImportedProfile method with different profiles to make sure the | 4255 // Tests the SaveImportedProfile method with different profiles to make sure the |
| 4256 // merge logic works correctly. | 4256 // merge logic works correctly. |
| 4257 // Flaky on TSan, see crbug.com/686226. | 4257 TEST_F(PersonalDataManagerTest, SaveImportedProfile) { |
| 4258 #if defined(THREAD_SANITIZER) | |
| 4259 #define MAYBE_SaveImportedProfile DISABLED_SaveImportedProfile | |
| 4260 #else | |
| 4261 #define MAYBE_SaveImportedProfile SaveImportedProfile | |
| 4262 #endif | |
| 4263 | |
| 4264 TEST_F(PersonalDataManagerTest, MAYBE_SaveImportedProfile) { | |
| 4265 typedef struct { | 4258 typedef struct { |
| 4266 autofill::ServerFieldType field_type; | 4259 autofill::ServerFieldType field_type; |
| 4267 std::string field_value; | 4260 std::string field_value; |
| 4268 } ProfileField; | 4261 } ProfileField; |
| 4269 | 4262 |
| 4270 typedef std::vector<ProfileField> ProfileFields; | 4263 typedef std::vector<ProfileField> ProfileFields; |
| 4271 | 4264 |
| 4272 typedef struct { | 4265 typedef struct { |
| 4273 // Each test starts with a default pre-existing profile and applies these | 4266 // Each test starts with a default pre-existing profile and applies these |
| 4274 // changes to it. | 4267 // changes to it. |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4516 {{ADDRESS_HOME_STATE, "CA"}}}, | 4509 {{ADDRESS_HOME_STATE, "CA"}}}, |
| 4517 | 4510 |
| 4518 // Tests that saving and identical profile except that the company name | 4511 // Tests that saving and identical profile except that the company name |
| 4519 // has different punctuation and case results in a merge and that the | 4512 // has different punctuation and case results in a merge and that the |
| 4520 // syntax of the new profile replaces the old one. | 4513 // syntax of the new profile replaces the old one. |
| 4521 {{{COMPANY_NAME, "Stark inc"}}, | 4514 {{{COMPANY_NAME, "Stark inc"}}, |
| 4522 {{COMPANY_NAME, "Stark Inc."}}, | 4515 {{COMPANY_NAME, "Stark Inc."}}, |
| 4523 {{COMPANY_NAME, "Stark Inc."}}}, | 4516 {{COMPANY_NAME, "Stark Inc."}}}, |
| 4524 }; | 4517 }; |
| 4525 | 4518 |
| 4519 // Create the test clock. |
| 4520 TestAutofillClock test_clock; |
| 4521 |
| 4526 for (TestCase test_case : test_cases) { | 4522 for (TestCase test_case : test_cases) { |
| 4523 // Set the time to a specific value. |
| 4524 test_clock.SetNow(kArbitraryTime); |
| 4525 |
| 4527 SetupReferenceProfile(); | 4526 SetupReferenceProfile(); |
| 4528 const std::vector<AutofillProfile*>& initial_profiles = | 4527 const std::vector<AutofillProfile*>& initial_profiles = |
| 4529 personal_data_->GetProfiles(); | 4528 personal_data_->GetProfiles(); |
| 4530 | 4529 |
| 4531 // Apply changes to the original profile (if applicable). | 4530 // Apply changes to the original profile (if applicable). |
| 4532 for (ProfileField change : test_case.changes_to_original) { | 4531 for (ProfileField change : test_case.changes_to_original) { |
| 4533 initial_profiles.front()->SetRawInfo( | 4532 initial_profiles.front()->SetRawInfo( |
| 4534 change.field_type, base::UTF8ToUTF16(change.field_value)); | 4533 change.field_type, base::UTF8ToUTF16(change.field_value)); |
| 4535 } | 4534 } |
| 4536 | 4535 |
| 4536 // Set the time to a bigger value. |
| 4537 test_clock.SetNow(kSomeLaterTime); |
| 4538 |
| 4537 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | 4539 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); |
| 4538 test::SetProfileInfo(&profile2, "Marion", "Mitchell", "Morrison", | 4540 test::SetProfileInfo(&profile2, "Marion", "Mitchell", "Morrison", |
| 4539 "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5", | 4541 "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5", |
| 4540 "Hollywood", "CA", "91601", "US", "12345678910"); | 4542 "Hollywood", "CA", "91601", "US", "12345678910"); |
| 4541 | 4543 |
| 4542 // Apply changes to the second profile (if applicable). | 4544 // Apply changes to the second profile (if applicable). |
| 4543 for (ProfileField change : test_case.changes_to_new) { | 4545 for (ProfileField change : test_case.changes_to_new) { |
| 4544 profile2.SetRawInfo(change.field_type, | 4546 profile2.SetRawInfo(change.field_type, |
| 4545 base::UTF8ToUTF16(change.field_value)); | 4547 base::UTF8ToUTF16(change.field_value)); |
| 4546 } | 4548 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4558 EXPECT_EQ(1U, saved_profiles.size()); | 4560 EXPECT_EQ(1U, saved_profiles.size()); |
| 4559 | 4561 |
| 4560 // Make sure the new information was merged correctly. | 4562 // Make sure the new information was merged correctly. |
| 4561 for (ProfileField changed_field : test_case.changed_field_values) { | 4563 for (ProfileField changed_field : test_case.changed_field_values) { |
| 4562 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value), | 4564 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value), |
| 4563 saved_profiles.front()->GetRawInfo(changed_field.field_type)); | 4565 saved_profiles.front()->GetRawInfo(changed_field.field_type)); |
| 4564 } | 4566 } |
| 4565 // Verify that the merged profile's use count, use date and modification | 4567 // Verify that the merged profile's use count, use date and modification |
| 4566 // date were properly updated. | 4568 // date were properly updated. |
| 4567 EXPECT_EQ(1U, saved_profiles.front()->use_count()); | 4569 EXPECT_EQ(1U, saved_profiles.front()->use_count()); |
| 4568 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4570 EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->use_date()); |
| 4569 AutofillClock::Now() - saved_profiles.front()->use_date()); | 4571 EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->modification_date()); |
| 4570 EXPECT_GT( | |
| 4571 base::TimeDelta::FromMilliseconds(500), | |
| 4572 AutofillClock::Now() - saved_profiles.front()->modification_date()); | |
| 4573 } | 4572 } |
| 4574 | 4573 |
| 4575 // Erase the profiles for the next test. | 4574 // Erase the profiles for the next test. |
| 4576 ResetProfiles(); | 4575 ResetProfiles(); |
| 4577 } | 4576 } |
| 4578 } | 4577 } |
| 4579 | 4578 |
| 4580 // Tests that MergeProfile tries to merge the imported profile into the | 4579 // Tests that MergeProfile tries to merge the imported profile into the |
| 4581 // existing profile in decreasing order of frecency. | 4580 // existing profile in decreasing order of frecency. |
| 4582 TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) { | 4581 TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) { |
| (...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5695 EnableAutofillProfileCleanup(); | 5694 EnableAutofillProfileCleanup(); |
| 5696 | 5695 |
| 5697 // The deduping routine should not be run. | 5696 // The deduping routine should not be run. |
| 5698 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); | 5697 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); |
| 5699 | 5698 |
| 5700 // The two duplicate profiles should still be present. | 5699 // The two duplicate profiles should still be present. |
| 5701 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); | 5700 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); |
| 5702 } | 5701 } |
| 5703 | 5702 |
| 5704 } // namespace autofill | 5703 } // namespace autofill |
| OLD | NEW |