diff options
Diffstat (limited to 'chromium/components/autofill/core')
14 files changed, 249 insertions, 82 deletions
diff --git a/chromium/components/autofill/core/browser/autofill_manager.cc b/chromium/components/autofill/core/browser/autofill_manager.cc index 01583656d21..50d4ecb114c 100644 --- a/chromium/components/autofill/core/browser/autofill_manager.cc +++ b/chromium/components/autofill/core/browser/autofill_manager.cc @@ -20,6 +20,7 @@ #include "base/feature_list.h" #include "base/files/file_util.h" #include "base/guid.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/memory/ptr_util.h" #include "base/message_loop/message_loop.h" @@ -114,7 +115,12 @@ bool SectionIsAutofilled(const FormStructure& form_structure, // characters removed. base::string16 SanitizeCreditCardFieldValue(const base::string16& value) { base::string16 sanitized; + // We remove whitespace as well as some invisible unicode characters. base::TrimWhitespace(value, base::TRIM_ALL, &sanitized); + base::TrimString(sanitized, + base::string16({base::i18n::kRightToLeftMark, + base::i18n::kLeftToRightMark}), + &sanitized); // Some sites have ____-____-____-____ in their credit card number fields, for // example. base::ReplaceChars(sanitized, base::ASCIIToUTF16("-_"), @@ -2068,7 +2074,7 @@ void AutofillManager::ParseForms(const std::vector<FormData>& forms) { return; // Setup the url for metrics that we will collect for this form. - form_interactions_ukm_logger_->OnFormsParsed(forms[0].origin); + form_interactions_ukm_logger_->OnFormsParsed(forms[0].main_frame_origin); std::vector<FormStructure*> non_queryable_forms; std::vector<FormStructure*> queryable_forms; diff --git a/chromium/components/autofill/core/browser/autofill_manager_unittest.cc b/chromium/components/autofill/core/browser/autofill_manager_unittest.cc index 74d41a7f88f..1fdfdee5ba1 100644 --- a/chromium/components/autofill/core/browser/autofill_manager_unittest.cc +++ b/chromium/components/autofill/core/browser/autofill_manager_unittest.cc @@ -95,6 +95,12 @@ const char kUTF8MidlineEllipsis[] = const base::Time kArbitraryTime = base::Time::FromDoubleT(25); const base::Time kMuchLaterTime = base::Time::FromDoubleT(5000); +const std::string NextYear() { + base::Time::Exploded now; + base::Time::Now().LocalExplode(&now); + return std::to_string(now.year + 1); +} + class MockAutofillClient : public TestAutofillClient { public: MockAutofillClient() {} @@ -982,9 +988,11 @@ class AutofillManagerTest : public testing::Test { if (is_https) { form->origin = GURL("https://myform.com/form.html"); form->action = GURL("https://myform.com/submit.html"); + form->main_frame_origin = GURL("https://myform_root.com/form.html"); } else { form->origin = GURL("http://myform.com/form.html"); form->action = GURL("http://myform.com/submit.html"); + form->main_frame_origin = GURL("http://myform_root.com/form.html"); } FormFieldData field; @@ -1042,7 +1050,7 @@ class AutofillManagerTest : public testing::Test { // Edit the data, and submit. form.fields[1].value = ASCIIToUTF16("4111111111111111"); form.fields[2].value = ASCIIToUTF16("11"); - form.fields[3].value = ASCIIToUTF16("2017"); + form.fields[3].value = ASCIIToUTF16(NextYear()); EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)); FormSubmitted(form); } @@ -1057,7 +1065,7 @@ class AutofillManagerTest : public testing::Test { FormsSeen(std::vector<FormData>(1, *form)); *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"); test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01", - "2017", "1"); + NextYear().c_str(), "1"); card->SetNetworkForMaskedCard(kVisaCard); EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) @@ -1719,13 +1727,36 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsOnly) { } // Test that we return all credit card profile suggestions when the triggering +// field has some invisible unicode characters in it. +TEST_F(AutofillManagerTest, GetCreditCardSuggestions_InvisibleUnicodeOnly) { + // Set up our form data. + FormData form; + CreateTestCreditCardFormData(&form, true, false); + std::vector<FormData> forms(1, form); + FormsSeen(forms); + + FormFieldData field = form.fields[1]; + field.value = base::string16({0x200E, 0x200F}); + GetAutofillSuggestions(form, field); + + // Test that we sent the right values to the external delegate. + external_delegate_->CheckSuggestions( + kDefaultPageID, + Suggestion(std::string("Visa") + kUTF8MidlineEllipsis + "3456", "04/99", + kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), + Suggestion(std::string("Mastercard") + kUTF8MidlineEllipsis + "8765", + "10/98", kMasterCard, + autofill_manager_->GetPackedCreditCardID(5))); +} + +// Test that we return all credit card profile suggestions when the triggering // field has stop characters in it and some input. TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { // Add a credit card with particular numbers that we will attempt to recall. CreditCard credit_card; test::SetCreditCardInfo(&credit_card, "John Smith", "5255667890123123", // Mastercard - "08", "2017", "1"); + "08", NextYear().c_str(), "1"); credit_card.set_guid("00000000-0000-0000-0000-000000000007"); autofill_manager_->AddCreditCard(credit_card); @@ -1740,11 +1771,13 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { field.value = ASCIIToUTF16("5255-66__-____-____"); GetAutofillSuggestions(form, field); + std::string expected_date = "08/" + NextYear().substr(2, 2); + // Test that we sent the right value to the external delegate. external_delegate_->CheckSuggestions( kDefaultPageID, Suggestion(std::string("Mastercard") + kUTF8MidlineEllipsis + "3123", - "08/17", kMasterCard, + expected_date, kMasterCard, autofill_manager_->GetPackedCreditCardID(7))); } @@ -4014,7 +4047,7 @@ TEST_F(AutofillManagerTest, MAYBE_CreditCardSavedWhenAutocompleteOff) { // Edit the data, and submit. form.fields[1].value = ASCIIToUTF16("4111111111111111"); form.fields[2].value = ASCIIToUTF16("11"); - form.fields[3].value = ASCIIToUTF16("2017"); + form.fields[3].value = ASCIIToUTF16(NextYear()); EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)); FormSubmitted(form); } @@ -4033,7 +4066,7 @@ TEST_F(AutofillManagerTest, InvalidCreditCardNumberIsNotSaved) { ASSERT_FALSE(autofill::IsValidCreditCardNumber(ASCIIToUTF16(card))); form.fields[1].value = ASCIIToUTF16(card); form.fields[2].value = ASCIIToUTF16("11"); - form.fields[3].value = ASCIIToUTF16("2017"); + form.fields[3].value = ASCIIToUTF16(NextYear()); EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); FormSubmitted(form); } @@ -4762,7 +4795,7 @@ TEST_F(AutofillManagerTest, DontOfferToSavePaymentsCard) { else if (form.fields[i].name == ASCIIToUTF16("ccmonth")) form.fields[i].value = ASCIIToUTF16("01"); else if (form.fields[i].name == ASCIIToUTF16("ccyear")) - form.fields[i].value = ASCIIToUTF16("2017"); + form.fields[i].value = ASCIIToUTF16(NextYear()); } CardUnmaskDelegate::UnmaskResponse response; @@ -4810,7 +4843,7 @@ TEST_F(AutofillManagerTest, CreditCardDisabledDoesNotSave) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -4886,7 +4919,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -4937,7 +4970,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_RequestCVCEnabled_DoesNotTrigger) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); @@ -4974,7 +5007,7 @@ TEST_F(AutofillManagerTest, UploadCreditCardAndSaveCopy) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16(card_number); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); FormSubmitted(credit_card_form); @@ -5019,7 +5052,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_FeatureNotEnabled) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -5057,7 +5090,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_CvcUnavailable) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16(""); // CVC MISSING base::HistogramTester histogram_tester; @@ -5095,7 +5128,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_CvcInvalidLength) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("1234"); base::HistogramTester histogram_tester; @@ -5133,6 +5166,8 @@ TEST_F(AutofillManagerTest, UploadCreditCard_MultipleCvcFields) { credit_card_form.name = ASCIIToUTF16("MyForm"); credit_card_form.origin = GURL("https://myform.com/form.html"); credit_card_form.action = GURL("https://myform.com/submit.html"); + credit_card_form.main_frame_origin = + GURL("https://myform_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Card Name", "cardname", "", "text", &field); @@ -5154,7 +5189,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_MultipleCvcFields) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16(""); // CVC MISSING credit_card_form.fields[5].value = ASCIIToUTF16("123"); @@ -5193,6 +5228,8 @@ TEST_F(AutofillManagerTest, UploadCreditCard_NoCvcFieldOnForm) { credit_card_form.name = ASCIIToUTF16("MyForm"); credit_card_form.origin = GURL("https://myform.com/form.html"); credit_card_form.action = GURL("https://myform.com/submit.html"); + credit_card_form.main_frame_origin = + GURL("https://myform_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Card Name", "cardname", "", "text", &field); @@ -5210,7 +5247,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_NoCvcFieldOnForm) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); base::HistogramTester histogram_tester; @@ -5248,6 +5285,8 @@ TEST_F(AutofillManagerTest, credit_card_form.name = ASCIIToUTF16("MyForm"); credit_card_form.origin = GURL("https://myform.com/form.html"); credit_card_form.action = GURL("https://myform.com/submit.html"); + credit_card_form.main_frame_origin = + GURL("https://myform_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Card Name", "cardname", "", "text", &field); @@ -5267,7 +5306,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("1234"); base::HistogramTester histogram_tester; @@ -5306,6 +5345,8 @@ TEST_F(AutofillManagerTest, credit_card_form.name = ASCIIToUTF16("MyForm"); credit_card_form.origin = GURL("https://myform.com/form.html"); credit_card_form.action = GURL("https://myform.com/submit.html"); + credit_card_form.main_frame_origin = + GURL("https://myform_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Card Name", "cardname", "", "text", &field); @@ -5325,7 +5366,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -5366,6 +5407,8 @@ TEST_F(AutofillManagerTest, credit_card_form.name = ASCIIToUTF16("MyForm"); credit_card_form.origin = GURL("https://myform.com/form.html"); credit_card_form.action = GURL("https://myform.com/submit.html"); + credit_card_form.main_frame_origin = + GURL("https://myform_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Card Name", "cardname", "", "text", &field); @@ -5385,7 +5428,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -5433,6 +5476,8 @@ TEST_F(AutofillManagerTest, credit_card_form.name = ASCIIToUTF16("MyForm"); credit_card_form.origin = GURL("https://myform.com/form.html"); credit_card_form.action = GURL("https://myform.com/submit.html"); + credit_card_form.main_frame_origin = + GURL("https://myform_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Card Name", "cardname", "", "text", &field); @@ -5450,7 +5495,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); base::HistogramTester histogram_tester; @@ -5494,6 +5539,8 @@ TEST_F(AutofillManagerTest, UploadCreditCard_NoCvcFieldOnFormExperimentOff) { credit_card_form.name = ASCIIToUTF16("MyForm"); credit_card_form.origin = GURL("https://myform.com/form.html"); credit_card_form.action = GURL("https://myform.com/submit.html"); + credit_card_form.main_frame_origin = + GURL("https://myform_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Card Name", "cardname", "", "text", &field); @@ -5511,7 +5558,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_NoCvcFieldOnFormExperimentOff) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); base::HistogramTester histogram_tester; @@ -5553,7 +5600,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); // Confirm upload happened and the new UI flag was sent in the request. @@ -5586,7 +5633,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); // Confirm upload happened and the new UI flag was not sent in the request. @@ -5619,7 +5666,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); // Confirm upload happened and the show Google logo flag was sent in the @@ -5653,7 +5700,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); // Confirm upload happened and the show Google logo flag was not sent in the @@ -5680,7 +5727,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_NoProfileAvailable) { credit_card_form.fields[0].value = ASCIIToUTF16("Bob Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -5726,7 +5773,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_NoRecentlyUsedProfile) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -5764,7 +5811,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16(""); // CVC MISSING base::HistogramTester histogram_tester; @@ -5810,7 +5857,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_NoNameAvailable) { // Edit the data, but don't include a name, and submit. credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -5858,7 +5905,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_ZipCodesConflict) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -5902,7 +5949,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_ZipCodesDiscardWhitespace) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -5946,7 +5993,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -5993,7 +6040,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_ZipCodesHavePrefixMatch) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6038,7 +6085,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_NoZipCodeAvailable) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6083,7 +6130,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_CCFormHasMiddleInitial) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo W. Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6131,7 +6178,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("Flo W. Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6176,7 +6223,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_NoMiddleInitialInCCForm) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6220,7 +6267,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6257,7 +6304,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_CCFormHasMiddleName) { credit_card_form.fields[0].value = ASCIIToUTF16("John Quincy Adams"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6296,7 +6343,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("John Quincy Adams"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6336,7 +6383,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_CCFormRemovesMiddleName) { credit_card_form.fields[0].value = ASCIIToUTF16("John Adams"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6377,7 +6424,7 @@ TEST_F(AutofillManagerTest, credit_card_form.fields[0].value = ASCIIToUTF16("John Adams"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6426,7 +6473,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_NamesHaveToMatch) { credit_card_form.fields[0].value = ASCIIToUTF16("Bob Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6478,7 +6525,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_IgnoreOldProfiles) { credit_card_form.fields[0].value = ASCIIToUTF16("Master Blaster"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6525,7 +6572,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_LogPreviousUseDate) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6566,7 +6613,7 @@ TEST_F(AutofillManagerTest, UploadCreditCard_UploadDetailsFails) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); base::HistogramTester histogram_tester; @@ -6603,8 +6650,8 @@ TEST_F(AutofillManagerTest, DuplicateMaskedCreditCard) { // Add a masked credit card whose |TypeAndLastFourDigits| matches what we will // enter below. CreditCard credit_card(CreditCard::MASKED_SERVER_CARD, "a123"); - test::SetCreditCardInfo(&credit_card, "Flo Master", "1111", "11", "2017", - "1"); + test::SetCreditCardInfo(&credit_card, "Flo Master", "1111", "11", + NextYear().c_str(), "1"); credit_card.SetNetworkForMaskedCard(kVisaCard); personal_data_.AddServerCreditCard(credit_card); @@ -6617,7 +6664,7 @@ TEST_F(AutofillManagerTest, DuplicateMaskedCreditCard) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); // The local save prompt should be shown. @@ -6642,8 +6689,8 @@ TEST_F(AutofillManagerTest, DuplicateMaskedCreditCard_ExperimentOff) { // Add a masked credit card whose |TypeAndLastFourDigits| matches what we will // enter below. CreditCard credit_card(CreditCard::MASKED_SERVER_CARD, "a123"); - test::SetCreditCardInfo(&credit_card, "Flo Master", "1111", "11", "2017", - "1"); + test::SetCreditCardInfo(&credit_card, "Flo Master", "1111", "11", + NextYear().c_str(), "1"); credit_card.SetNetworkForMaskedCard(kVisaCard); personal_data_.AddServerCreditCard(credit_card); @@ -6656,7 +6703,7 @@ TEST_F(AutofillManagerTest, DuplicateMaskedCreditCard_ExperimentOff) { credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); credit_card_form.fields[2].value = ASCIIToUTF16("11"); - credit_card_form.fields[3].value = ASCIIToUTF16("2017"); + credit_card_form.fields[3].value = ASCIIToUTF16(NextYear()); credit_card_form.fields[4].value = ASCIIToUTF16("123"); // The local save prompt should not be shown because the experiment is off. diff --git a/chromium/components/autofill/core/browser/autofill_metrics_unittest.cc b/chromium/components/autofill/core/browser/autofill_metrics_unittest.cc index 9bb357a69b4..403b163f054 100644 --- a/chromium/components/autofill/core/browser/autofill_metrics_unittest.cc +++ b/chromium/components/autofill/core/browser/autofill_metrics_unittest.cc @@ -309,7 +309,7 @@ class TestAutofillManager : public AutofillManager { form_structure->set_form_parsed_timestamp(TimeTicks::Now()); form_structures()->push_back(std::move(form_structure)); - form_interactions_ukm_logger()->OnFormsParsed(form.origin); + form_interactions_ukm_logger()->OnFormsParsed(form.main_frame_origin); } // Calls AutofillManager::OnWillSubmitForm and waits for it to complete. @@ -369,7 +369,7 @@ void VerifyDeveloperEngagementUkm( const ukm::UkmSource* source = ukm_recorder.GetSourceForSourceId(entry->source_id); ASSERT_NE(nullptr, source); - EXPECT_EQ(form.origin, source->url()); + EXPECT_EQ(form.main_frame_origin, source->url()); int expected_metric_value = 0; for (const auto it : expected_metric_values) @@ -406,7 +406,7 @@ void VerifyFormInteractionUkm(const ukm::TestAutoSetUkmRecorder& ukm_recorder, const ukm::UkmSource* source = ukm_recorder.GetSourceForSourceId(entry->source_id); ASSERT_NE(nullptr, source); - EXPECT_EQ(form.origin, source->url()); + EXPECT_EQ(form.main_frame_origin, source->url()); ASSERT_LT(expected_metrics_index, expected_metrics.size()); EXPECT_THAT( @@ -576,6 +576,7 @@ TEST_F(AutofillMetricsTest, QualityMetrics) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); std::vector<ServerFieldType> heuristic_types, server_types; FormFieldData field; @@ -885,6 +886,7 @@ TEST_P(QualityMetricsTest, Classification) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); std::vector<ServerFieldType> heuristic_types, server_types, actual_types; AutofillField field; @@ -1053,6 +1055,7 @@ TEST_F(AutofillMetricsTest, TimingMetrics) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; test::CreateTestFormField( @@ -1092,6 +1095,7 @@ TEST_F(AutofillMetricsTest, QualityMetrics_NoSubmission) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); std::vector<ServerFieldType> heuristic_types, server_types; FormFieldData field; @@ -1279,6 +1283,7 @@ TEST_F(AutofillMetricsTest, QualityMetrics_BasedOnAutocomplete) { form.name = ASCIIToUTF16("MyForm"); form.origin = GURL("http://myform.com/form.html"); form.action = GURL("http://myform.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; // Heuristic value will match with Autocomplete attribute. @@ -1389,6 +1394,7 @@ TEST_F(AutofillMetricsTest, UpiVirtualPaymentAddress) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); std::vector<ServerFieldType> heuristic_types, server_types; FormFieldData field; @@ -1437,6 +1443,7 @@ TEST_F(AutofillMetricsTest, PredictedMetricsWithAutocomplete) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field1; test::CreateTestFormField("Select", "select", "USA", "select-one", &field1); @@ -1504,6 +1511,7 @@ TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); std::vector<ServerFieldType> heuristic_types, server_types; @@ -1601,6 +1609,7 @@ TEST_F(AutofillMetricsTest, StoredProfileCountAutofillableFormSubmission) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); // Three fields is enough to make it an autofillable form. FormFieldData field; @@ -1632,6 +1641,7 @@ TEST_F(AutofillMetricsTest, StoredProfileCountNonAutofillableFormSubmission) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); // Two fields is not enough to make it an autofillable form. FormFieldData field; @@ -1661,6 +1671,7 @@ TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); std::vector<ServerFieldType> heuristic_types, server_types; @@ -1712,6 +1723,7 @@ TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields_NoSubmission) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); std::vector<ServerFieldType> heuristic_types, server_types; @@ -1762,6 +1774,7 @@ TEST_F(AutofillMetricsTest, DeveloperEngagement) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Name", "name", "", "text", &field); @@ -1851,6 +1864,7 @@ TEST_F(AutofillMetricsTest, form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Name", "name", "", "text", &field); @@ -1895,6 +1909,7 @@ TEST_F(AutofillMetricsTest, form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Name", "name", "", "text", &field); @@ -1944,6 +1959,7 @@ TEST_F(AutofillMetricsTest, UkmDeveloperEngagement_LogUpiVpaTypeHint) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Name", "name", "", "text", &field); @@ -2223,6 +2239,7 @@ TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -2294,6 +2311,7 @@ TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -2406,6 +2424,7 @@ TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -2578,6 +2597,7 @@ TEST_F(AutofillMetricsTest, QueriedCreditCardFormIsSecure) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); autofill_client_.set_form_origin(form.origin); FormFieldData field; @@ -2596,6 +2616,7 @@ TEST_F(AutofillMetricsTest, QueriedCreditCardFormIsSecure) { // Simulate having seen this insecure form on page load. form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); autofill_manager_->AddSeenForm(form, field_types, field_types); // Simulate an Autofill query on a credit card field (HTTP, non-secure @@ -2612,6 +2633,7 @@ TEST_F(AutofillMetricsTest, QueriedCreditCardFormIsSecure) { autofill_manager_->Reset(); form.origin = GURL("https://example.com/form.html"); form.action = GURL("https://example.com/submit.html"); + form.main_frame_origin = GURL("https://example_root.com/form.html"); autofill_client_.set_form_origin(form.origin); autofill_manager_->AddSeenForm(form, field_types, field_types); @@ -2634,6 +2656,7 @@ TEST_F(AutofillMetricsTest, PolledProfileSuggestions_DebounceLogs) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -2686,6 +2709,7 @@ TEST_F(AutofillMetricsTest, CreditCardInteractedFormEvents) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -2734,6 +2758,7 @@ TEST_F(AutofillMetricsTest, CreditCardShownFormEvents) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -2874,6 +2899,7 @@ TEST_F(AutofillMetricsTest, CreditCardSelectedFormEvents) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -2945,6 +2971,7 @@ TEST_F(AutofillMetricsTest, CreditCardFilledFormEvents) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -3115,6 +3142,7 @@ TEST_F(AutofillMetricsTest, CreditCardGetRealPanDuration) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -3188,6 +3216,7 @@ TEST_F(AutofillMetricsTest, form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -3230,6 +3259,7 @@ TEST_F(AutofillMetricsTest, form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -3274,6 +3304,7 @@ TEST_F(AutofillMetricsTest, form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -3318,6 +3349,7 @@ TEST_F(AutofillMetricsTest, form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -3371,6 +3403,7 @@ TEST_F(AutofillMetricsTest, ShouldNotLogFormEventNoCardForAddressForm) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -3412,6 +3445,7 @@ TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -3759,6 +3793,7 @@ TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -3980,6 +4015,7 @@ TEST_F(AutofillMetricsTest, AddressInteractedFormEvents) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -4031,6 +4067,7 @@ TEST_F(AutofillMetricsTest, AddressShownFormEvents) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -4120,6 +4157,7 @@ TEST_F(AutofillMetricsTest, AddressFilledFormEvents) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -4185,6 +4223,7 @@ TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -4385,6 +4424,7 @@ TEST_F(AutofillMetricsTest, AddressWillSubmitFormEvents) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -4556,6 +4596,7 @@ TEST_F(AutofillMetricsTest, CreditCardFormEventsAreSegmented) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -4664,6 +4705,7 @@ TEST_F(AutofillMetricsTest, AddressFormEventsAreSegmented) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; @@ -4749,6 +4791,7 @@ TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Name", "name", "", "text", &field); @@ -5051,6 +5094,7 @@ TEST_F(AutofillMetricsTest, UserHappinessFormInteraction_EmptyForm) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); std::vector<FormData> forms(1, form); @@ -5072,6 +5116,7 @@ TEST_F(AutofillMetricsTest, UserHappinessFormInteraction_CreditCardForm) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); // Construct a valid credit card form with minimal fields. FormFieldData field; @@ -5231,6 +5276,7 @@ TEST_F(AutofillMetricsTest, UserHappinessFormInteraction_AddressForm) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Name", "name", "", "text", &field); @@ -5443,6 +5489,7 @@ TEST_F(AutofillMetricsTest, FormFillDuration) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; test::CreateTestFormField("Name", "name", "", "text", &field); @@ -5834,6 +5881,7 @@ TEST_F(AutofillMetricsTest, ProfileActionOnFormSubmitted) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); // Create the form's fields. FormFieldData field; @@ -5953,6 +6001,7 @@ class AutofillMetricsParseQueryResponseTest : public testing::Test { void SetUp() override { FormData form; form.origin = GURL("http://foo.com"); + form.main_frame_origin = GURL("http://foo_root.com"); FormFieldData field; field.form_control_type = "text"; @@ -6086,6 +6135,7 @@ TEST_F(AutofillMetricsTest, NonsecureCreditCardForm) { form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("http://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); autofill_client_.set_form_origin(form.origin); FormFieldData field; @@ -6142,6 +6192,7 @@ TEST_F(AutofillMetricsTest, form.name = ASCIIToUTF16("TestForm"); form.origin = GURL("https://example.com/form.html"); form.action = GURL("http://example.com/submit.html"); + form.main_frame_origin = GURL("http://example_root.com/form.html"); FormFieldData field; std::vector<ServerFieldType> field_types; diff --git a/chromium/components/autofill/core/browser/autofill_test_utils.cc b/chromium/components/autofill/core/browser/autofill_test_utils.cc index e0543b1eaf8..874a4b0fa64 100644 --- a/chromium/components/autofill/core/browser/autofill_test_utils.cc +++ b/chromium/components/autofill/core/browser/autofill_test_utils.cc @@ -132,6 +132,7 @@ void CreateTestAddressFormData(FormData* form, form->name = ASCIIToUTF16("MyForm"); form->origin = GURL("http://myform.com/form.html"); form->action = GURL("http://myform.com/submit.html"); + form->main_frame_origin = GURL("http://myform_root.com/form.html"); types->clear(); FormFieldData field; diff --git a/chromium/components/autofill/core/browser/credit_card_unittest.cc b/chromium/components/autofill/core/browser/credit_card_unittest.cc index 93e5f128678..88c50b58c4e 100644 --- a/chromium/components/autofill/core/browser/credit_card_unittest.cc +++ b/chromium/components/autofill/core/browser/credit_card_unittest.cc @@ -15,6 +15,7 @@ #include "components/autofill/core/browser/autofill_test_utils.h" #include "components/autofill/core/browser/autofill_type.h" #include "components/autofill/core/browser/credit_card.h" +#include "components/autofill/core/browser/test_autofill_clock.h" #include "components/autofill/core/browser/validation.h" #include "components/autofill/core/common/autofill_constants.h" #include "components/autofill/core/common/form_field_data.h" @@ -1236,6 +1237,9 @@ TEST(CreditCardTest, GetLastUsedDateForDisplay) { EXPECT_TRUE( base::Time::FromLocalExploded(kTestDateTimeExploded, &kArbitraryTime)); + TestAutofillClock test_clock; + test_clock.SetNow(kArbitraryTime); + // Test for added to chrome/chromium. CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); credit_card0.set_use_count(1); diff --git a/chromium/components/autofill/core/browser/form_structure.cc b/chromium/components/autofill/core/browser/form_structure.cc index 98393571074..550f1ffd58f 100644 --- a/chromium/components/autofill/core/browser/form_structure.cc +++ b/chromium/components/autofill/core/browser/form_structure.cc @@ -309,6 +309,7 @@ FormStructure::FormStructure(const FormData& form) : form_name_(form.name), source_url_(form.origin), target_url_(form.action), + main_frame_url_(form.main_frame_origin), autofill_count_(0), active_field_count_(0), upload_required_(USE_UPLOAD_RATES), @@ -391,7 +392,7 @@ void FormStructure::DetermineHeuristicTypes(ukm::UkmRecorder* ukm_recorder) { } if (developer_engagement_metrics) - AutofillMetrics::LogDeveloperEngagementUkm(ukm_recorder, source_url(), + AutofillMetrics::LogDeveloperEngagementUkm(ukm_recorder, main_frame_url(), developer_engagement_metrics); if (base::FeatureList::IsEnabled(kAutofillRationalizeFieldTypePredictions)) @@ -563,6 +564,7 @@ std::vector<FormDataPredictions> FormStructure::GetFieldTypePredictions( form.data.name = form_structure->form_name_; form.data.origin = form_structure->source_url_; form.data.action = form_structure->target_url_; + form.data.main_frame_origin = form_structure->main_frame_url_; form.data.is_form_tag = form_structure->is_form_tag_; form.data.is_formless_checkout = form_structure->is_formless_checkout_; form.signature = form_structure->FormSignatureAsStr(); @@ -808,8 +810,8 @@ void FormStructure::LogQualityMetrics( GetFormTypes(), did_autofill_some_possible_fields, elapsed); } } - if (form_interactions_ukm_logger->url() != source_url()) - form_interactions_ukm_logger->UpdateSourceURL(source_url()); + if (form_interactions_ukm_logger->url() != main_frame_url()) + form_interactions_ukm_logger->UpdateSourceURL(main_frame_url()); AutofillMetrics::LogAutofillFormSubmittedState( state, form_parsed_timestamp_, form_interactions_ukm_logger); } @@ -1033,6 +1035,7 @@ FormData FormStructure::ToFormData() const { data.name = form_name_; data.origin = source_url_; data.action = target_url_; + data.main_frame_origin = main_frame_url_; for (size_t i = 0; i < fields_.size(); ++i) { data.fields.push_back(FormFieldData(*fields_[i])); diff --git a/chromium/components/autofill/core/browser/form_structure.h b/chromium/components/autofill/core/browser/form_structure.h index d02b31beeab..9a8e4de1b6d 100644 --- a/chromium/components/autofill/core/browser/form_structure.h +++ b/chromium/components/autofill/core/browser/form_structure.h @@ -208,6 +208,8 @@ class FormStructure { const GURL& target_url() const { return target_url_; } + const GURL& main_frame_url() const { return main_frame_url_; } + bool has_author_specified_types() const { return has_author_specified_types_; } @@ -303,6 +305,9 @@ class FormStructure { // The target URL. GURL target_url_; + // The source URL of the main frame of this form. + GURL main_frame_url_; + // The number of fields able to be auto-filled. size_t autofill_count_; diff --git a/chromium/components/autofill/core/browser/form_structure_unittest.cc b/chromium/components/autofill/core/browser/form_structure_unittest.cc index 3548474f66b..eb21fa925d6 100644 --- a/chromium/components/autofill/core/browser/form_structure_unittest.cc +++ b/chromium/components/autofill/core/browser/form_structure_unittest.cc @@ -3382,6 +3382,7 @@ TEST_F(FormStructureTest, CheckFormSignature) { "https://login.facebook.com&login_form&email&first")), form_structure->FormSignatureAsStr()); + // Checks how digits are removed from field names. field.check_status = FormFieldData::NOT_CHECKABLE; field.label = ASCIIToUTF16("Random Field label"); field.name = ASCIIToUTF16("random1234"); @@ -3391,15 +3392,15 @@ TEST_F(FormStructureTest, CheckFormSignature) { field.name = ASCIIToUTF16("random12345"); form.fields.push_back(field); field.label = ASCIIToUTF16("Random Field label3"); - field.name = ASCIIToUTF16("1random12345678"); + field.name = ASCIIToUTF16("1ran12dom12345678"); form.fields.push_back(field); field.label = ASCIIToUTF16("Random Field label3"); - field.name = ASCIIToUTF16("12345random"); + field.name = ASCIIToUTF16("12345ran123456dom123"); form.fields.push_back(field); form_structure.reset(new FormStructure(form)); EXPECT_EQ(FormStructureTest::Hash64Bit( std::string("https://login.facebook.com&login_form&email&first&" - "random1234&random&1random&random")), + "random1234&random&1ran12dom&random123")), form_structure->FormSignatureAsStr()); } diff --git a/chromium/components/autofill/core/common/BUILD.gn b/chromium/components/autofill/core/common/BUILD.gn index e58160d0360..24f45074e60 100644 --- a/chromium/components/autofill/core/common/BUILD.gn +++ b/chromium/components/autofill/core/common/BUILD.gn @@ -49,7 +49,6 @@ static_library("common") { "//base", "//base:i18n", "//components/variations", - "//third_party/re2", "//url", ] diff --git a/chromium/components/autofill/core/common/DEPS b/chromium/components/autofill/core/common/DEPS deleted file mode 100644 index 0de07bbaf08..00000000000 --- a/chromium/components/autofill/core/common/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "+third_party/re2", -] diff --git a/chromium/components/autofill/core/common/form_data.cc b/chromium/components/autofill/core/common/form_data.cc index 81de550a22b..11c651377c7 100644 --- a/chromium/components/autofill/core/common/form_data.cc +++ b/chromium/components/autofill/core/common/form_data.cc @@ -5,7 +5,6 @@ #include "components/autofill/core/common/form_data.h" #include <stddef.h> - #include <tuple> #include "base/base64.h" @@ -18,7 +17,7 @@ namespace autofill { namespace { -const int kPickleVersion = 5; +const int kPickleVersion = 6; bool ReadGURL(base::PickleIterator* iter, GURL* url) { std::string spec; @@ -66,6 +65,7 @@ FormData::FormData(const FormData& data) : name(data.name), origin(data.origin), action(data.action), + main_frame_origin(data.main_frame_origin), is_form_tag(data.is_form_tag), is_formless_checkout(data.is_formless_checkout), fields(data.fields) {} @@ -119,7 +119,8 @@ bool FormData::operator<(const FormData& form) const { std::ostream& operator<<(std::ostream& os, const FormData& form) { os << base::UTF16ToUTF8(form.name) << " " << form.origin << " " << form.action - << " " << form.is_form_tag << " " << form.is_formless_checkout << " " + << " " << form.main_frame_origin << " " << form.is_form_tag << " " + << form.is_formless_checkout << " " << "Fields:"; for (size_t i = 0; i < form.fields.size(); ++i) { os << form.fields[i] << ","; @@ -135,6 +136,7 @@ void SerializeFormData(const FormData& form_data, base::Pickle* pickle) { SerializeFormFieldDataVector(form_data.fields, pickle); pickle->WriteBool(form_data.is_form_tag); pickle->WriteBool(form_data.is_formless_checkout); + pickle->WriteString(form_data.main_frame_origin.spec()); } void SerializeFormDataToBase64String(const FormData& form_data, @@ -198,6 +200,13 @@ bool DeserializeFormData(base::PickleIterator* iter, FormData* form_data) { } } + if (version >= 6) { + if (!ReadGURL(iter, &temp_form_data.main_frame_origin)) { + LogDeserializationError(version); + return false; + } + } + *form_data = temp_form_data; return true; } diff --git a/chromium/components/autofill/core/common/form_data.h b/chromium/components/autofill/core/common/form_data.h index 5e5a42936f1..c7064803a12 100644 --- a/chromium/components/autofill/core/common/form_data.h +++ b/chromium/components/autofill/core/common/form_data.h @@ -41,6 +41,8 @@ struct FormData { GURL origin; // The action target of the form. GURL action; + // The URL of main frame containing this form. + GURL main_frame_origin; // True if this form is a form tag. bool is_form_tag; // True if the form is made of unowned fields in a non checkout flow. diff --git a/chromium/components/autofill/core/common/form_data_unittest.cc b/chromium/components/autofill/core/common/form_data_unittest.cc index ee174b715eb..c6dee3bec05 100644 --- a/chromium/components/autofill/core/common/form_data_unittest.cc +++ b/chromium/components/autofill/core/common/form_data_unittest.cc @@ -87,6 +87,21 @@ void SerializeInVersion5Format(const FormData& form_data, pickle->WriteBool(form_data.is_formless_checkout); } +void SerializeInVersion6Format(const FormData& form_data, + base::Pickle* pickle) { + pickle->WriteInt(6); + pickle->WriteString16(form_data.name); + pickle->WriteString(form_data.origin.spec()); + pickle->WriteString(form_data.action.spec()); + pickle->WriteInt(static_cast<int>(form_data.fields.size())); + for (size_t i = 0; i < form_data.fields.size(); ++i) { + SerializeFormFieldData(form_data.fields[i], pickle); + } + pickle->WriteBool(form_data.is_form_tag); + pickle->WriteBool(form_data.is_formless_checkout); + pickle->WriteString(form_data.main_frame_origin.spec()); +} + // This function serializes the form data into the pickle in incorrect format // (no version number). void SerializeIncorrectFormat(const FormData& form_data, base::Pickle* pickle) { @@ -102,8 +117,9 @@ void SerializeIncorrectFormat(const FormData& form_data, base::Pickle* pickle) { void FillInDummyFormData(FormData* data) { data->name = base::ASCIIToUTF16("name"); - data->origin = GURL("origin"); - data->action = GURL("action"); + data->origin = GURL("https://example.com"); + data->action = GURL("https://example.com/action"); + data->main_frame_origin = GURL("https://origin-example.com"); data->is_form_tag = true; // Default value. data->is_formless_checkout = false; // Default value. @@ -249,6 +265,21 @@ TEST(FormDataTest, Serialize_v5_Deserialize_vCurrent) { EXPECT_TRUE(actual.SameFormAs(data)); } +TEST(FormDataTest, Serialize_v6_Deserialize_vCurrent) { + FormData data; + FillInDummyFormData(&data); + data.is_formless_checkout = true; + + base::Pickle pickle; + SerializeInVersion6Format(data, &pickle); + + base::PickleIterator iter(pickle); + FormData actual; + EXPECT_TRUE(DeserializeFormData(&iter, &actual)); + + EXPECT_TRUE(actual.SameFormAs(data)); +} + TEST(FormDataTest, SerializeIncorrectFormatAndDeserialize) { FormData data; FillInDummyFormData(&data); diff --git a/chromium/components/autofill/core/common/signatures_util.cc b/chromium/components/autofill/core/common/signatures_util.cc index 8e7695eac75..df549b97d2a 100644 --- a/chromium/components/autofill/core/common/signatures_util.cc +++ b/chromium/components/autofill/core/common/signatures_util.cc @@ -4,30 +4,41 @@ #include "components/autofill/core/common/signatures_util.h" +#include <cctype> + #include "base/sha1.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "components/autofill/core/common/autofill_util.h" #include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_field_data.h" -#include "third_party/re2/src/re2/re2.h" -#include "third_party/re2/src/re2/stringpiece.h" #include "url/gurl.h" namespace autofill { namespace { -// Strip away >= 5 consecutive digits. -const char kIgnorePatternInFieldName[] = "\\d{5,}"; - -// Returns a copy of |input| without all occurrences of -// |kIgnorePatternInFieldName| +// Returns a copy of |input| without >= 5 consecutive digits. std::string StripDigitsIfRequired(const base::string16& input) { - std::string return_string = base::UTF16ToUTF8(input); - re2::RE2::GlobalReplace(&return_string, re2::RE2(kIgnorePatternInFieldName), - re2::StringPiece()); - return return_string; + std::string input_utf8 = base::UTF16ToUTF8(input); + std::string result; + result.reserve(input_utf8.length()); + + for (size_t i = 0; i < input_utf8.length();) { + if (std::isdigit(input_utf8[i])) { + size_t count = 0; + while (i < input_utf8.length() && std::isdigit(input_utf8[i])) { + i++; + count++; + } + if (count < 5) + result.append(input_utf8, i - count, count); + } else { + result.push_back(input_utf8[i]); + i++; + } + } + return result; } } // namespace |