Commit 92371967 authored by thestig's avatar thestig Committed by Commit bot

Revert of Autofill: Disable autofill for fields outside of forms. (patchset #2...

Revert of Autofill: Disable autofill for fields outside of forms. (patchset #2 id:10006 of https://codereview.chromium.org/964453004/)

Reason for revert:
CL merged to M41/M42. Re-enabling on trunk.

Original issue's description:
> Autofill: Disable autofill for fields outside of forms.
>
> BUG=462375
>
> Committed: https://crrev.com/eb9e20d80c31c2842509e5213d4864eadf84baa1
> Cr-Commit-Position: refs/heads/master@{#318406}

TBR=estade@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=462375

Review URL: https://codereview.chromium.org/974613002

Cr-Commit-Position: refs/heads/master@{#318783}
parent 8b96058b
......@@ -46,16 +46,6 @@ const base::FilePath& GetTestDataDir() {
}
const std::vector<base::FilePath> GetTestFiles() {
static const base::FilePath::CharType* const kFilesToSkip[] = {
FILE_PATH_LITERAL("bug_459132.html"),
FILE_PATH_LITERAL("bug_454366b.html"),
FILE_PATH_LITERAL("bug_454366.html"),
FILE_PATH_LITERAL("25_checkout_m_llbean.com.html"),
};
std::set<base::FilePath> set_of_files_to_skip;
for (size_t i = 0; i < arraysize(kFilesToSkip); ++i)
set_of_files_to_skip.insert(base::FilePath(kFilesToSkip[i]));
base::FilePath dir;
CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &dir));
dir = dir.AppendASCII("chrome/test/data/autofill")
......@@ -65,8 +55,7 @@ const std::vector<base::FilePath> GetTestFiles() {
std::vector<base::FilePath> files;
for (base::FilePath input_file = input_files.Next(); !input_file.empty();
input_file = input_files.Next()) {
if (!ContainsKey(set_of_files_to_skip, input_file.BaseName()))
files.push_back(input_file);
files.push_back(input_file);
}
std::sort(files.begin(), files.end());
......
......@@ -250,7 +250,7 @@ TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) {
// Shouldn't crash.
}
TEST_F(AutofillRendererTest, DISABLED_DynamicallyAddedUnownedFormElements) {
TEST_F(AutofillRendererTest, DynamicallyAddedUnownedFormElements) {
std::string html_data;
base::FilePath test_path = ui_test_utils::GetTestFilePath(
base::FilePath(FILE_PATH_LITERAL("autofill")),
......
......@@ -2393,7 +2393,7 @@ TEST_F(FormAutofillTest, FindFormForInputElement) {
false);
}
TEST_F(FormAutofillTest, DISABLED_FindFormForInputElementForUnownedForm) {
TEST_F(FormAutofillTest, FindFormForInputElementForUnownedForm) {
TestFindFormForInputElement(
"<INPUT type='text' id='firstname' value='John'/>"
"<INPUT type='text' id='lastname' value='Smith'/>"
......@@ -2420,7 +2420,7 @@ TEST_F(FormAutofillTest, FindFormForTextAreaElement) {
false);
}
TEST_F(FormAutofillTest, DISABLED_FindFormForTextAreaElementForUnownedForm) {
TEST_F(FormAutofillTest, FindFormForTextAreaElementForUnownedForm) {
TestFindFormForTextAreaElement(
"<INPUT type='text' id='firstname' value='John'/>"
"<INPUT type='text' id='lastname' value='Smith'/>"
......@@ -2439,7 +2439,7 @@ TEST_F(FormAutofillTest, FillForm) {
TestFillForm(kFormHtml, false);
}
TEST_F(FormAutofillTest, DISABLED_FillFormForUnownedForm) {
TEST_F(FormAutofillTest, FillFormForUnownedForm) {
TestFillForm(kUnownedFormHtml, true);
}
......@@ -2531,7 +2531,7 @@ TEST_F(FormAutofillTest, PreviewForm) {
TestPreviewForm(kFormHtml, false);
}
TEST_F(FormAutofillTest, DISABLED_PreviewFormForUnownedForm) {
TEST_F(FormAutofillTest, PreviewFormForUnownedForm) {
TestPreviewForm(kUnownedFormHtml, true);
}
......@@ -3406,7 +3406,7 @@ TEST_F(FormAutofillTest, FillFormMaxLength) {
false);
}
TEST_F(FormAutofillTest, DISABLED_FillFormMaxLengthForUnownedForm) {
TEST_F(FormAutofillTest, FillFormMaxLengthForUnownedForm) {
TestFillFormMaxLength(
"<INPUT type='text' id='firstname' maxlength='5'/>"
"<INPUT type='text' id='lastname' maxlength='7'/>"
......@@ -3429,7 +3429,7 @@ TEST_F(FormAutofillTest, FillFormNegativeMaxLength) {
false);
}
TEST_F(FormAutofillTest, DISABLED_FillFormNegativeMaxLengthForUnownedForm) {
TEST_F(FormAutofillTest, FillFormNegativeMaxLengthForUnownedForm) {
TestFillFormNegativeMaxLength(
"<INPUT type='text' id='firstname' maxlength='-1'/>"
"<INPUT type='text' id='lastname' maxlength='-10'/>"
......@@ -3449,7 +3449,7 @@ TEST_F(FormAutofillTest, FillFormEmptyName) {
false);
}
TEST_F(FormAutofillTest, DISABLED_FillFormEmptyNameForUnownedForm) {
TEST_F(FormAutofillTest, FillFormEmptyNameForUnownedForm) {
TestFillFormEmptyName(
"<INPUT type='text' id='firstname'/>"
"<INPUT type='text' id='lastname'/>"
......@@ -3475,7 +3475,7 @@ TEST_F(FormAutofillTest, FillFormEmptyFormNames) {
false);
}
TEST_F(FormAutofillTest, DISABLED_FillFormEmptyFormNamesForUnownedForm) {
TEST_F(FormAutofillTest, FillFormEmptyFormNamesForUnownedForm) {
TestFillFormEmptyFormNames(
"<INPUT type='text' id='firstname'/>"
"<INPUT type='text' id='middlename'/>"
......@@ -3631,7 +3631,7 @@ TEST_F(FormAutofillTest, FillFormNonEmptyField) {
false);
}
TEST_F(FormAutofillTest, DISABLED_FillFormNonEmptyFieldForUnownedForm) {
TEST_F(FormAutofillTest, FillFormNonEmptyFieldForUnownedForm) {
TestFillFormNonEmptyField("<INPUT type='text' id='firstname'/>"
"<INPUT type='text' id='lastname'/>"
"<INPUT type='text' id='email'/>"
......@@ -3659,7 +3659,7 @@ TEST_F(FormAutofillTest, ClearFormWithNode) {
false);
}
TEST_F(FormAutofillTest, DISABLED_ClearFormWithNodeForUnownedForm) {
TEST_F(FormAutofillTest, ClearFormWithNodeForUnownedForm) {
TestClearFormWithNode(
" <!-- Indented on purpose //-->"
" <INPUT type='text' id='firstname' value='Wyatt'/>"
......@@ -3694,8 +3694,7 @@ TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) {
false);
}
TEST_F(FormAutofillTest,
DISABLED_ClearFormWithNodeContainingSelectOneForUnownedForm) {
TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOneForUnownedForm) {
TestClearFormWithNodeContainingSelectOne(
"<INPUT type='text' id='firstname' value='Wyatt'/>"
"<INPUT type='text' id='lastname' value='Earp'/>"
......@@ -3721,7 +3720,7 @@ TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) {
"</FORM>");
}
TEST_F(FormAutofillTest, DISABLED_ClearPreviewedFormWithElementForUnownedForm) {
TEST_F(FormAutofillTest, ClearPreviewedFormWithElementForUnownedForm) {
TestClearPreviewedFormWithElement(
"<INPUT type='text' id='firstname' value='Wyatt'/>"
"<INPUT type='text' id='lastname'/>"
......@@ -3744,7 +3743,7 @@ TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) {
}
TEST_F(FormAutofillTest,
DISABLED_ClearPreviewedFormWithNonEmptyInitiatingNodeForUnownedForm) {
ClearPreviewedFormWithNonEmptyInitiatingNodeForUnownedForm) {
TestClearPreviewedFormWithNonEmptyInitiatingNode(
"<INPUT type='text' id='firstname' value='W'/>"
"<INPUT type='text' id='lastname'/>"
......@@ -3767,7 +3766,7 @@ TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) {
}
TEST_F(FormAutofillTest,
DISABLED_ClearPreviewedFormWithAutofilledInitiatingNodeForUnownedForm) {
ClearPreviewedFormWithAutofilledInitiatingNodeForUnownedForm) {
TestClearPreviewedFormWithAutofilledInitiatingNode(
"<INPUT type='text' id='firstname' value='W'/>"
"<INPUT type='text' id='lastname'/>"
......@@ -3789,7 +3788,7 @@ TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) {
"</FORM>");
}
TEST_F(FormAutofillTest, DISABLED_ClearOnlyAutofilledFieldsForUnownedForm) {
TEST_F(FormAutofillTest, ClearOnlyAutofilledFieldsForUnownedForm) {
TestClearOnlyAutofilledFields(
"<INPUT type='text' id='firstname' value='Wyatt'/>"
"<INPUT type='text' id='lastname' value='Earp'/>"
......@@ -3948,7 +3947,7 @@ TEST_F(FormAutofillTest, SelectOneAsText) {
}
TEST_F(FormAutofillTest,
DISABLED_UnownedFormElementsAndFieldSetsToFormDataFieldsets) {
UnownedFormElementsAndFieldSetsToFormDataFieldsets) {
std::vector<WebElement> fieldsets;
std::vector<WebFormControlElement> control_elements;
......@@ -4010,7 +4009,7 @@ TEST_F(FormAutofillTest,
}
TEST_F(FormAutofillTest,
DISABLED_UnownedFormElementsAndFieldSetsToFormDataControlOutsideOfFieldset) {
UnownedFormElementsAndFieldSetsToFormDataControlOutsideOfFieldset) {
std::vector<WebElement> fieldsets;
std::vector<WebFormControlElement> control_elements;
......@@ -4069,8 +4068,7 @@ TEST_F(FormAutofillTest,
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
}
TEST_F(FormAutofillTest,
DISABLED_UnownedFormElementsAndFieldSetsToFormDataWithForm) {
TEST_F(FormAutofillTest, UnownedFormElementsAndFieldSetsToFormDataWithForm) {
std::vector<WebElement> fieldsets;
std::vector<WebFormControlElement> control_elements;
......
......@@ -119,10 +119,41 @@ std::vector<FormData> FormCache::ExtractNewForms() {
parsed_forms_.insert(form);
}
}
// Look for more parseable fields outside of forms.
std::vector<WebElement> fieldsets;
std::vector<WebFormControlElement> control_elements =
GetUnownedAutofillableFormFieldElements(document.all(), &fieldsets);
size_t num_editable_elements =
ScanFormControlElements(control_elements, log_deprecation_messages);
if (ShouldIgnoreForm(num_editable_elements, control_elements.size()))
return forms;
FormData synthetic_form;
if (!UnownedFormElementsAndFieldSetsToFormData(fieldsets, control_elements,
nullptr, document.url(),
REQUIRE_NONE, extract_mask,
&synthetic_form, nullptr)) {
return forms;
}
num_fields_seen += synthetic_form.fields.size();
if (num_fields_seen > kMaxParseableFields)
return forms;
if (synthetic_form.fields.size() >= kRequiredAutofillFields &&
!parsed_forms_.count(synthetic_form)) {
forms.push_back(synthetic_form);
parsed_forms_.insert(synthetic_form);
synthetic_form_ = synthetic_form;
}
return forms;
}
void FormCache::Reset() {
synthetic_form_ = FormData();
parsed_forms_.clear();
initial_select_values_.clear();
initial_checked_state_.clear();
......@@ -191,7 +222,15 @@ bool FormCache::ShowPredictions(const FormDataPredictions& form) {
std::vector<WebFormControlElement> control_elements;
// First check the synthetic form.
bool found_synthetic_form = false;
if (form.data.SameFormAs(synthetic_form_)) {
found_synthetic_form = true;
WebDocument document = frame_.document();
control_elements =
GetUnownedAutofillableFormFieldElements(document.all(), nullptr);
}
if (!found_synthetic_form) {
// Find the real form by searching through the WebDocuments.
bool found_form = false;
......
......@@ -64,6 +64,10 @@ class FormCache {
// The cached forms. Used to prevent re-extraction of forms.
std::set<FormData> parsed_forms_;
// The synthetic FormData is for all the fieldsets in the document without a
// form owner.
FormData synthetic_form_;
// The cached initial values for <select> elements.
std::map<const blink::WebSelectElement, base::string16>
initial_select_values_;
......
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