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