Commit 168a9ed9 authored by Maria Kazinova's avatar Maria Kazinova Committed by Commit Bot

Enabled FieldDataManager usage for more form extractions in Autofill.

Primarily to let it keep track of fields that have user input.
CL 2035983 allowed AutoFillAgent to use FieldDataManager but it was
still not used for some FormData extractions. This fixes it.

Bug: 957444, 1006745.
Change-Id: If4b3e080e05bb64e144bf4c9b8b08ba62aea997b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2041592
Commit-Queue: Maria Kazinova <kazinova@google.com>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738958}
parent f478aa65
......@@ -329,7 +329,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
const FormData& form = forms[0];
......@@ -421,7 +421,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
......@@ -430,8 +430,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the form that contains the input element.
FormData form_data;
FormFieldData field;
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form_data,
&field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form_data, &field));
if (!unowned) {
EXPECT_EQ(ASCIIToUTF16("TestForm"), form_data.name);
EXPECT_EQ(GURL("http://abc.com"), form_data.action);
......@@ -676,7 +676,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(0U, forms.size());
}
......@@ -686,7 +686,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
......@@ -695,8 +695,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the form and verify it's the correct form.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form, &field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
if (!unowned) {
......@@ -745,7 +745,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Get the textarea element we want to find.
......@@ -757,8 +757,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the form and verify it's the correct form.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(textarea_element, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(textarea_element, nullptr,
&form, &field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
if (!unowned) {
......@@ -813,7 +813,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
......@@ -822,8 +822,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the form that contains the input element.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form, &field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
if (!unowned) {
......@@ -867,8 +867,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form2, &field2));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form2, &field2));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form2.url);
if (!unowned) {
......@@ -909,7 +909,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
......@@ -918,8 +918,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the form that contains the input element.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form, &field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
if (!unowned) {
......@@ -955,8 +955,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form2, &field2));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form2, &field2));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form2.url);
if (!unowned) {
......@@ -989,7 +989,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
......@@ -998,8 +998,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the form that contains the input element.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form, &field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
if (!unowned) {
......@@ -1035,8 +1035,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form2, &field2));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form2, &field2));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form2.url);
if (!unowned) {
......@@ -1072,7 +1072,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
const size_t expected_size = unowned ? 1 : 2;
ASSERT_EQ(expected_size, forms.size());
......@@ -1082,8 +1082,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the form that contains the input element.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form, &field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
if (!unowned) {
......@@ -1126,8 +1126,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form2, &field2));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form2, &field2));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form2.url);
if (!unowned) {
......@@ -1169,7 +1169,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
......@@ -1181,8 +1181,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the form that contains the input element.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form, &field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
if (!unowned) {
......@@ -1257,8 +1257,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form2, &field2));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form2, &field2));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form2.url);
if (!unowned) {
......@@ -1325,7 +1325,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
......@@ -1363,8 +1363,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the form that contains the input element.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form, &field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
......@@ -1397,8 +1397,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form2, &field2));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form2, &field2));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form2.url);
EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
......@@ -1507,7 +1507,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
......@@ -1531,8 +1531,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the form that contains the input element.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form, &field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
......@@ -1559,8 +1559,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form2, &field2));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form2, &field2));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form2.url);
EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
......@@ -1627,7 +1627,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
......@@ -1650,8 +1650,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the form that contains the input element.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form, &field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
......@@ -1678,8 +1678,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form2, &field2));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form2, &field2));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form2.url);
EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
......@@ -1745,7 +1745,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
......@@ -1772,8 +1772,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the form that contains the input element.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form, &field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
......@@ -1800,8 +1800,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(input_element, &form2, &field2));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, nullptr,
&form2, &field2));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form2.url);
EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
......@@ -1864,7 +1864,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Set the auto-filled attribute.
......@@ -1890,8 +1890,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Verify the form is cleared.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(firstname, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname, nullptr, &form,
&field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
EXPECT_FALSE(form.url.is_empty());
......@@ -1975,7 +1975,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Set the autofilled attribute and specify the section attribute.
......@@ -2027,8 +2027,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Verify that the shipping section is cleared, but not the billing one.
FormData form;
FormFieldData field;
EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname_shipping, &form,
&field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname_shipping,
nullptr, &form, &field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
EXPECT_FALSE(form.url.is_empty());
......@@ -2087,7 +2087,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Set the auto-filled attribute.
......@@ -2111,8 +2111,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
// Verify the form is cleared.
FormData form;
FormFieldData field;
EXPECT_TRUE(
FindFormAndFieldForFormControlElement(firstname, &form, &field));
EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname, nullptr, &form,
&field));
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.url);
EXPECT_FALSE(form.url.is_empty());
......@@ -2159,7 +2159,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Set the auto-filled attribute.
......@@ -2214,7 +2214,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Set the auto-filled attribute.
......@@ -2268,7 +2268,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Set the auto-filled attribute.
......@@ -2323,7 +2323,7 @@ class FormAutofillTest : public ChromeRenderViewTest {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Set the autofilled attribute.
......@@ -3261,7 +3261,7 @@ TEST_F(FormAutofillTest, ExtractMultipleForms) {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(2U, forms.size());
// First form.
......@@ -3338,11 +3338,11 @@ TEST_F(FormAutofillTest, OnlyExtractNewForms) {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
// Second call should give nothing as there are no new forms.
forms = form_cache.ExtractNewForms();
forms = form_cache.ExtractNewForms(nullptr);
ASSERT_TRUE(forms.empty());
// Append to the current form will re-extract.
......@@ -3354,7 +3354,7 @@ TEST_F(FormAutofillTest, OnlyExtractNewForms) {
"document.getElementById('testform').appendChild(newInput);");
base::RunLoop().RunUntilIdle();
forms = form_cache.ExtractNewForms();
forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
const std::vector<FormFieldData>& fields = forms[0].fields;
......@@ -3415,7 +3415,7 @@ TEST_F(FormAutofillTest, OnlyExtractNewForms) {
base::RunLoop().RunUntilIdle();
web_frame = GetMainFrame();
forms = form_cache.ExtractNewForms();
forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1U, forms.size());
const std::vector<FormFieldData>& fields2 = forms[0].fields;
......@@ -3461,7 +3461,7 @@ TEST_F(FormAutofillTest, ExtractFormsTooFewFields) {
kAutofillEnforceMinRequiredFieldsForUpload},
// Disabled.
{});
ASSERT_TRUE(FormCache(web_frame).ExtractNewForms().empty());
ASSERT_TRUE(FormCache(web_frame).ExtractNewForms(nullptr).empty());
}
// If at least one of the minimums is not enforced, we parse the form.
......@@ -3473,7 +3473,7 @@ TEST_F(FormAutofillTest, ExtractFormsTooFewFields) {
kAutofillEnforceMinRequiredFieldsForQuery},
// Disabled.
{kAutofillEnforceMinRequiredFieldsForUpload});
ASSERT_FALSE(FormCache(web_frame).ExtractNewForms().empty());
ASSERT_FALSE(FormCache(web_frame).ExtractNewForms(nullptr).empty());
}
}
......@@ -3486,7 +3486,7 @@ TEST_F(FormAutofillTest, ExtractFormsNoFields) {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_TRUE(forms.empty());
}
......@@ -3514,7 +3514,7 @@ TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) {
kAutofillEnforceMinRequiredFieldsForUpload},
// Disabled.
{});
ASSERT_TRUE(FormCache(web_frame).ExtractNewForms().empty());
ASSERT_TRUE(FormCache(web_frame).ExtractNewForms(nullptr).empty());
}
// With small form support, the form is parsed.
......@@ -3527,7 +3527,7 @@ TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) {
{kAutofillEnforceMinRequiredFieldsForHeuristics,
kAutofillEnforceMinRequiredFieldsForQuery,
kAutofillEnforceMinRequiredFieldsForUpload});
ASSERT_FALSE(FormCache(web_frame).ExtractNewForms().empty());
ASSERT_FALSE(FormCache(web_frame).ExtractNewForms(nullptr).empty());
}
}
......@@ -5472,8 +5472,8 @@ TEST_F(FormAutofillTest,
FormData form;
EXPECT_TRUE(UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, nullptr, frame->GetDocument(), extract_mask,
&form, nullptr));
fieldsets, control_elements, nullptr, frame->GetDocument(), nullptr,
extract_mask, &form, nullptr));
EXPECT_TRUE(form.name.empty());
EXPECT_EQ(GURL(frame->GetDocument().Url()), form.url);
......@@ -5535,8 +5535,8 @@ TEST_F(FormAutofillTest,
FormData form;
EXPECT_TRUE(UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, nullptr, frame->GetDocument(), extract_mask,
&form, nullptr));
fieldsets, control_elements, nullptr, frame->GetDocument(), nullptr,
extract_mask, &form, nullptr));
EXPECT_TRUE(form.name.empty());
EXPECT_EQ(GURL(frame->GetDocument().Url()), form.url);
......@@ -5587,8 +5587,8 @@ TEST_F(FormAutofillTest, UnownedFormElementsAndFieldSetsToFormDataWithForm) {
FormData form;
EXPECT_FALSE(UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, nullptr, frame->GetDocument(), extract_mask,
&form, nullptr));
fieldsets, control_elements, nullptr, frame->GetDocument(), nullptr,
extract_mask, &form, nullptr));
}
TEST_F(FormAutofillTest, FormlessForms) {
......@@ -5614,7 +5614,7 @@ TEST_F(FormAutofillTest, FormlessForms) {
features::kAutofillRestrictUnownedFieldsToFormlessCheckout);
FormData form;
EXPECT_FALSE(UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, nullptr, frame->GetDocument(),
fieldsets, control_elements, nullptr, frame->GetDocument(), nullptr,
extract_mask, &form, nullptr));
}
......@@ -5624,7 +5624,7 @@ TEST_F(FormAutofillTest, FormlessForms) {
features::kAutofillRestrictUnownedFieldsToFormlessCheckout);
FormData form;
EXPECT_TRUE(UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, nullptr, frame->GetDocument(),
fieldsets, control_elements, nullptr, frame->GetDocument(), nullptr,
extract_mask, &form, nullptr));
}
}
......@@ -5708,7 +5708,7 @@ TEST_F(FormAutofillTest, FormCache_ExtractNewForms) {
ASSERT_NE(nullptr, web_frame);
FormCache form_cache(web_frame);
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
EXPECT_EQ(test_case.has_extracted_form, forms.size() == 1);
if (test_case.has_extracted_form) {
......
......@@ -83,6 +83,8 @@ using blink::WebVector;
namespace autofill {
using form_util::FindFormAndFieldForFormControlElement;
using form_util::UnownedCheckoutFormElementsAndFieldSetsToFormData;
using mojom::SubmissionSource;
namespace {
......@@ -216,8 +218,8 @@ void AutofillAgent::DidChangeScrollOffsetImpl(
FormData form;
FormFieldData field;
if (form_util::FindFormAndFieldForFormControlElement(element_, &form,
&field)) {
if (FindFormAndFieldForFormControlElement(element_, field_data_manager_.get(),
&form, &field)) {
GetAutofillDriver()->TextFieldDidScroll(
form, field, render_frame()->ElementBoundsInWindow(element_));
}
......@@ -265,8 +267,8 @@ void AutofillAgent::FocusedElementChanged(const WebElement& element) {
FormData form;
FormFieldData field;
if (form_util::FindFormAndFieldForFormControlElement(element_, &form,
&field)) {
if (FindFormAndFieldForFormControlElement(element_, field_data_manager_.get(),
&form, &field)) {
GetAutofillDriver()->FocusOnFormField(
form, field, render_frame()->ElementBoundsInWindow(element_));
}
......@@ -345,8 +347,8 @@ void AutofillAgent::OnTextFieldDidChange(const WebInputElement& element) {
FormData form;
FormFieldData field;
if (form_util::FindFormAndFieldForFormControlElement(element, &form,
&field)) {
if (FindFormAndFieldForFormControlElement(element, field_data_manager_.get(),
&form, &field)) {
GetAutofillDriver()->TextFieldDidChange(
form, field, render_frame()->ElementBoundsInWindow(element),
AutofillTickClock::NowTicks());
......@@ -423,8 +425,8 @@ void AutofillAgent::TriggerRefillIfNeeded(const FormData& form) {
FormFieldData field;
FormData updated_form;
if (form_util::FindFormAndFieldForFormControlElement(element_, &updated_form,
&field) &&
if (FindFormAndFieldForFormControlElement(element_, field_data_manager_.get(),
&updated_form, &field) &&
(!element_.IsAutofilled() || !form.DynamicallySameFormAs(updated_form))) {
base::TimeTicks forms_seen_timestamp = AutofillTickClock::NowTicks();
WebLocalFrame* frame = render_frame()->GetWebFrame();
......@@ -600,9 +602,9 @@ bool AutofillAgent::CollectFormlessElements(FormData* output) {
static_cast<form_util::ExtractMask>(form_util::EXTRACT_VALUE |
form_util::EXTRACT_OPTIONS);
return form_util::UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, nullptr, document, extract_mask, output,
nullptr);
return UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, nullptr, document, field_data_manager_.get(),
extract_mask, output, nullptr);
}
void AutofillAgent::ShowSuggestions(const WebFormControlElement& element,
......@@ -693,8 +695,8 @@ void AutofillAgent::GetElementFormAndFieldData(
blink::WebFormControlElement target_form_control_element =
target_element.To<blink::WebFormControlElement>();
bool success = form_util::FindFormAndFieldForFormControlElement(
target_form_control_element, &form, &field);
bool success = FindFormAndFieldForFormControlElement(
target_form_control_element, field_data_manager_.get(), &form, &field);
if (success) {
// Remember this element so as to autofill the form without focusing the
// field for Autofill Assistant.
......@@ -755,8 +757,8 @@ void AutofillAgent::QueryAutofillSuggestions(
FormData form;
FormFieldData field;
if (!form_util::FindFormAndFieldForFormControlElement(element, &form,
&field)) {
if (!FindFormAndFieldForFormControlElement(element, field_data_manager_.get(),
&form, &field)) {
// If we didn't find the cached form, at least let autocomplete have a shot
// at providing suggestions.
WebFormControlElementToFormField(element, nullptr, form_util::EXTRACT_VALUE,
......@@ -813,7 +815,8 @@ void AutofillAgent::ProcessForms() {
base::TimeTicks forms_seen_timestamp = AutofillTickClock::NowTicks();
WebLocalFrame* frame = render_frame()->GetWebFrame();
std::vector<FormData> forms = form_cache_.ExtractNewForms();
std::vector<FormData> forms =
form_cache_.ExtractNewForms(field_data_manager_.get());
// Always communicate to browser process for topmost frame.
if (!forms.empty() || !frame->Parent()) {
......@@ -911,8 +914,8 @@ void AutofillAgent::SelectWasUpdated(
// found, notify the driver that the the form was modified dynamically.
FormData form;
FormFieldData field;
if (form_util::FindFormAndFieldForFormControlElement(element, &form,
&field) &&
if (FindFormAndFieldForFormControlElement(element_, field_data_manager_.get(),
&form, &field) &&
!field.option_values.empty()) {
GetAutofillDriver()->SelectFieldOptionsDidChange(form);
}
......@@ -1006,8 +1009,8 @@ void AutofillAgent::OnProvisionallySaveForm(
else {
FormData form;
FormFieldData field;
if (form_util::FindFormAndFieldForFormControlElement(element, &form,
&field)) {
if (FindFormAndFieldForFormControlElement(
element, field_data_manager_.get(), &form, &field)) {
GetAutofillDriver()->SelectControlDidChange(
form, field, render_frame()->ElementBoundsInWindow(element));
}
......
......@@ -1829,14 +1829,15 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData(
const std::vector<blink::WebFormControlElement>& control_elements,
const blink::WebFormControlElement* element,
const blink::WebDocument& document,
const FieldDataManager* field_data_manager,
ExtractMask extract_mask,
FormData* form,
FormFieldData* field) {
if (!base::FeatureList::IsEnabled(
features::kAutofillRestrictUnownedFieldsToFormlessCheckout)) {
return UnownedFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, element, document, nullptr, extract_mask,
form, field);
fieldsets, control_elements, element, document, field_data_manager,
extract_mask, form, field);
}
// Only attempt formless Autofill on checkout flows. This avoids the many
......@@ -1853,8 +1854,8 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData(
if (!lang.empty() &&
!base::StartsWith(lang, "en", base::CompareCase::INSENSITIVE_ASCII)) {
return UnownedFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, element, document, nullptr, extract_mask,
form, field);
fieldsets, control_elements, element, document, field_data_manager,
extract_mask, form, field);
}
// A potential problem is that this only checks document.title(), but should
......@@ -1888,8 +1889,8 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData(
form->is_formless_checkout = true;
// Found a keyword: treat this as an unowned form.
return UnownedFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, element, document, nullptr, extract_mask,
form, field);
fieldsets, control_elements, element, document, field_data_manager,
extract_mask, form, field);
}
}
......@@ -1919,8 +1920,8 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData(
return false;
return UnownedFormElementsAndFieldSetsToFormData(
fieldsets, elements_with_autocomplete, element, document, nullptr,
extract_mask, form, field);
fieldsets, elements_with_autocomplete, element, document,
field_data_manager, extract_mask, form, field);
}
bool UnownedPasswordFormElementsAndFieldSetsToFormData(
......@@ -1937,10 +1938,11 @@ bool UnownedPasswordFormElementsAndFieldSetsToFormData(
extract_mask, form, field);
}
bool FindFormAndFieldForFormControlElement(const WebFormControlElement& element,
FormData* form,
FormFieldData* field) {
bool FindFormAndFieldForFormControlElement(
const WebFormControlElement& element,
const FieldDataManager* field_data_manager,
FormData* form,
FormFieldData* field) {
DCHECK(!element.IsNull());
if (!IsAutofillableElement(element))
......@@ -1956,12 +1958,12 @@ bool FindFormAndFieldForFormControlElement(const WebFormControlElement& element,
std::vector<WebFormControlElement> control_elements =
GetUnownedAutofillableFormFieldElements(document.All(), &fieldsets);
return UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, &element, document, extract_mask,
form, field);
fieldsets, control_elements, &element, document, field_data_manager,
extract_mask, form, field);
}
return WebFormElementToFormData(form_element, element, nullptr, extract_mask,
form, field);
return WebFormElementToFormData(form_element, element, field_data_manager,
extract_mask, form, field);
}
void FillForm(const FormData& form, const WebFormControlElement& element) {
......
......@@ -193,6 +193,7 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData(
const std::vector<blink::WebFormControlElement>& control_elements,
const blink::WebFormControlElement* element,
const blink::WebDocument& document,
const FieldDataManager* field_data_manager,
ExtractMask extract_mask,
FormData* form,
FormFieldData* field);
......@@ -216,6 +217,7 @@ bool UnownedPasswordFormElementsAndFieldSetsToFormData(
// Returns false if the form is not found or cannot be serialized.
bool FindFormAndFieldForFormControlElement(
const blink::WebFormControlElement& element,
const FieldDataManager* field_data_manager,
FormData* form,
FormFieldData* field);
......
......@@ -204,7 +204,8 @@ bool IsFormInteresting(const FormData& form, size_t num_editable_elements) {
FormCache::FormCache(WebLocalFrame* frame) : frame_(frame) {}
FormCache::~FormCache() = default;
std::vector<FormData> FormCache::ExtractNewForms() {
std::vector<FormData> FormCache::ExtractNewForms(
const FieldDataManager* field_data_manager) {
std::vector<FormData> forms;
WebDocument document = frame_->GetDocument();
if (document.IsNull())
......@@ -237,7 +238,8 @@ std::vector<FormData> FormCache::ExtractNewForms() {
FormData form;
if (!WebFormElementToFormData(form_element, WebFormControlElement(),
nullptr, extract_mask, &form, nullptr)) {
field_data_manager, extract_mask, &form,
nullptr)) {
continue;
}
......@@ -280,8 +282,8 @@ std::vector<FormData> FormCache::ExtractNewForms() {
FormData synthetic_form;
if (!UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, nullptr, document, extract_mask,
&synthetic_form, nullptr)) {
fieldsets, control_elements, nullptr, document, field_data_manager,
extract_mask, &synthetic_form, nullptr)) {
PruneInitialValueCaches(observed_unique_renderer_ids);
return forms;
}
......
......@@ -14,6 +14,7 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "components/autofill/content/renderer/field_data_manager.h"
#include "components/autofill/core/common/form_data.h"
namespace blink {
......@@ -35,7 +36,8 @@ class FormCache {
// Scans the DOM in |frame_| extracting and storing forms that have not been
// seen before. Returns the extracted forms. Note that modified forms are
// considered new forms.
std::vector<FormData> ExtractNewForms();
std::vector<FormData> ExtractNewForms(
const FieldDataManager* field_data_manager);
// Resets the forms.
void Reset();
......
......@@ -49,7 +49,7 @@ TEST_F(FormCacheBrowserTest, ExtractForms) {
)");
FormCache form_cache(GetMainFrame());
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
const FormData* form1 = GetFormByName(forms, "form1");
ASSERT_TRUE(form1);
......@@ -71,9 +71,9 @@ TEST_F(FormCacheBrowserTest, ExtractFormsTwice) {
)");
FormCache form_cache(GetMainFrame());
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
forms = form_cache.ExtractNewForms();
forms = form_cache.ExtractNewForms(nullptr);
// As nothing has changed, there are no new forms and |forms| should be empty.
EXPECT_TRUE(forms.empty());
}
......@@ -89,7 +89,7 @@ TEST_F(FormCacheBrowserTest, ExtractFormsAfterModification) {
)");
FormCache form_cache(GetMainFrame());
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
// Append an input element to the form and to the list of unowned inputs.
ExecuteJavaScriptForTests(R"(
......@@ -106,7 +106,7 @@ TEST_F(FormCacheBrowserTest, ExtractFormsAfterModification) {
document.body.appendChild(new_input_2);
)");
forms = form_cache.ExtractNewForms();
forms = form_cache.ExtractNewForms(nullptr);
const FormData* form1 = GetFormByName(forms, "form1");
ASSERT_TRUE(form1);
......@@ -128,7 +128,7 @@ TEST_F(FormCacheBrowserTest, FillAndClear) {
)");
FormCache form_cache(GetMainFrame());
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1u, forms.size());
FormData values_to_fill = forms[0];
......@@ -173,7 +173,7 @@ TEST_F(FormCacheBrowserTest, FreeDataOnElementRemoval) {
)");
FormCache form_cache(GetMainFrame());
form_cache.ExtractNewForms();
form_cache.ExtractNewForms(nullptr);
EXPECT_EQ(1u, form_cache.initial_select_values_.size());
EXPECT_EQ(1u, form_cache.initial_checked_state_.size());
......@@ -185,7 +185,7 @@ TEST_F(FormCacheBrowserTest, FreeDataOnElementRemoval) {
}
)");
std::vector<FormData> forms = form_cache.ExtractNewForms();
std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
EXPECT_EQ(0u, forms.size());
EXPECT_EQ(0u, form_cache.initial_select_values_.size());
EXPECT_EQ(0u, form_cache.initial_checked_state_.size());
......
......@@ -1397,7 +1397,8 @@ bool PasswordAutofillAgent::ShowSuggestionPopup(
FormData form;
FormFieldData field;
form_util::FindFormAndFieldForFormControlElement(user_input, &form, &field);
form_util::FindFormAndFieldForFormControlElement(
user_input, field_data_manager_.get(), &form, &field);
int options = 0;
if (show_all)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment