Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Autofill: Disable autofill for fields outside of forms.
Browse files Browse the repository at this point in the history
BUG=462375

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

Cr-Commit-Position: refs/heads/master@{#318406}
(cherry picked from commit eb9e20d)

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

Cr-Commit-Position: refs/branch-heads/2311@{#51}
Cr-Branched-From: 09b7de5-refs/heads/master@{#317474}
  • Loading branch information
Evan Stade committed Feb 27, 2015
1 parent fc9ff20 commit 63e858a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 63 deletions.
13 changes: 12 additions & 1 deletion chrome/browser/autofill/form_structure_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ 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")
Expand All @@ -55,7 +65,8 @@ 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()) {
files.push_back(input_file);
if (!ContainsKey(set_of_files_to_skip, input_file.BaseName()))
files.push_back(input_file);
}
std::sort(files.begin(), files.end());

Expand Down
2 changes: 1 addition & 1 deletion chrome/renderer/autofill/autofill_renderer_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) {
// Shouldn't crash.
}

TEST_F(AutofillRendererTest, DynamicallyAddedUnownedFormElements) {
TEST_F(AutofillRendererTest, DISABLED_DynamicallyAddedUnownedFormElements) {
std::string html_data;
base::FilePath test_path = ui_test_utils::GetTestFilePath(
base::FilePath(FILE_PATH_LITERAL("autofill")),
Expand Down
38 changes: 20 additions & 18 deletions chrome/renderer/autofill/form_autofill_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2393,7 +2393,7 @@ TEST_F(FormAutofillTest, FindFormForInputElement) {
false);
}

TEST_F(FormAutofillTest, FindFormForInputElementForUnownedForm) {
TEST_F(FormAutofillTest, DISABLED_FindFormForInputElementForUnownedForm) {
TestFindFormForInputElement(
"<INPUT type='text' id='firstname' value='John'/>"
"<INPUT type='text' id='lastname' value='Smith'/>"
Expand All @@ -2420,7 +2420,7 @@ TEST_F(FormAutofillTest, FindFormForTextAreaElement) {
false);
}

TEST_F(FormAutofillTest, FindFormForTextAreaElementForUnownedForm) {
TEST_F(FormAutofillTest, DISABLED_FindFormForTextAreaElementForUnownedForm) {
TestFindFormForTextAreaElement(
"<INPUT type='text' id='firstname' value='John'/>"
"<INPUT type='text' id='lastname' value='Smith'/>"
Expand All @@ -2439,7 +2439,7 @@ TEST_F(FormAutofillTest, FillForm) {
TestFillForm(kFormHtml, false);
}

TEST_F(FormAutofillTest, FillFormForUnownedForm) {
TEST_F(FormAutofillTest, DISABLED_FillFormForUnownedForm) {
TestFillForm(kUnownedFormHtml, true);
}

Expand Down Expand Up @@ -2531,7 +2531,7 @@ TEST_F(FormAutofillTest, PreviewForm) {
TestPreviewForm(kFormHtml, false);
}

TEST_F(FormAutofillTest, PreviewFormForUnownedForm) {
TEST_F(FormAutofillTest, DISABLED_PreviewFormForUnownedForm) {
TestPreviewForm(kUnownedFormHtml, true);
}

Expand Down Expand Up @@ -3406,7 +3406,7 @@ TEST_F(FormAutofillTest, FillFormMaxLength) {
false);
}

TEST_F(FormAutofillTest, FillFormMaxLengthForUnownedForm) {
TEST_F(FormAutofillTest, DISABLED_FillFormMaxLengthForUnownedForm) {
TestFillFormMaxLength(
"<INPUT type='text' id='firstname' maxlength='5'/>"
"<INPUT type='text' id='lastname' maxlength='7'/>"
Expand All @@ -3429,7 +3429,7 @@ TEST_F(FormAutofillTest, FillFormNegativeMaxLength) {
false);
}

TEST_F(FormAutofillTest, FillFormNegativeMaxLengthForUnownedForm) {
TEST_F(FormAutofillTest, DISABLED_FillFormNegativeMaxLengthForUnownedForm) {
TestFillFormNegativeMaxLength(
"<INPUT type='text' id='firstname' maxlength='-1'/>"
"<INPUT type='text' id='lastname' maxlength='-10'/>"
Expand All @@ -3449,7 +3449,7 @@ TEST_F(FormAutofillTest, FillFormEmptyName) {
false);
}

TEST_F(FormAutofillTest, FillFormEmptyNameForUnownedForm) {
TEST_F(FormAutofillTest, DISABLED_FillFormEmptyNameForUnownedForm) {
TestFillFormEmptyName(
"<INPUT type='text' id='firstname'/>"
"<INPUT type='text' id='lastname'/>"
Expand All @@ -3475,7 +3475,7 @@ TEST_F(FormAutofillTest, FillFormEmptyFormNames) {
false);
}

TEST_F(FormAutofillTest, FillFormEmptyFormNamesForUnownedForm) {
TEST_F(FormAutofillTest, DISABLED_FillFormEmptyFormNamesForUnownedForm) {
TestFillFormEmptyFormNames(
"<INPUT type='text' id='firstname'/>"
"<INPUT type='text' id='middlename'/>"
Expand Down Expand Up @@ -3631,7 +3631,7 @@ TEST_F(FormAutofillTest, FillFormNonEmptyField) {
false);
}

TEST_F(FormAutofillTest, FillFormNonEmptyFieldForUnownedForm) {
TEST_F(FormAutofillTest, DISABLED_FillFormNonEmptyFieldForUnownedForm) {
TestFillFormNonEmptyField("<INPUT type='text' id='firstname'/>"
"<INPUT type='text' id='lastname'/>"
"<INPUT type='text' id='email'/>"
Expand Down Expand Up @@ -3659,7 +3659,7 @@ TEST_F(FormAutofillTest, ClearFormWithNode) {
false);
}

TEST_F(FormAutofillTest, ClearFormWithNodeForUnownedForm) {
TEST_F(FormAutofillTest, DISABLED_ClearFormWithNodeForUnownedForm) {
TestClearFormWithNode(
" <!-- Indented on purpose //-->"
" <INPUT type='text' id='firstname' value='Wyatt'/>"
Expand Down Expand Up @@ -3694,7 +3694,8 @@ TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) {
false);
}

TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOneForUnownedForm) {
TEST_F(FormAutofillTest,
DISABLED_ClearFormWithNodeContainingSelectOneForUnownedForm) {
TestClearFormWithNodeContainingSelectOne(
"<INPUT type='text' id='firstname' value='Wyatt'/>"
"<INPUT type='text' id='lastname' value='Earp'/>"
Expand All @@ -3720,7 +3721,7 @@ TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) {
"</FORM>");
}

TEST_F(FormAutofillTest, ClearPreviewedFormWithElementForUnownedForm) {
TEST_F(FormAutofillTest, DISABLED_ClearPreviewedFormWithElementForUnownedForm) {
TestClearPreviewedFormWithElement(
"<INPUT type='text' id='firstname' value='Wyatt'/>"
"<INPUT type='text' id='lastname'/>"
Expand All @@ -3743,7 +3744,7 @@ TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) {
}

TEST_F(FormAutofillTest,
ClearPreviewedFormWithNonEmptyInitiatingNodeForUnownedForm) {
DISABLED_ClearPreviewedFormWithNonEmptyInitiatingNodeForUnownedForm) {
TestClearPreviewedFormWithNonEmptyInitiatingNode(
"<INPUT type='text' id='firstname' value='W'/>"
"<INPUT type='text' id='lastname'/>"
Expand All @@ -3766,7 +3767,7 @@ TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) {
}

TEST_F(FormAutofillTest,
ClearPreviewedFormWithAutofilledInitiatingNodeForUnownedForm) {
DISABLED_ClearPreviewedFormWithAutofilledInitiatingNodeForUnownedForm) {
TestClearPreviewedFormWithAutofilledInitiatingNode(
"<INPUT type='text' id='firstname' value='W'/>"
"<INPUT type='text' id='lastname'/>"
Expand All @@ -3788,7 +3789,7 @@ TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) {
"</FORM>");
}

TEST_F(FormAutofillTest, ClearOnlyAutofilledFieldsForUnownedForm) {
TEST_F(FormAutofillTest, DISABLED_ClearOnlyAutofilledFieldsForUnownedForm) {
TestClearOnlyAutofilledFields(
"<INPUT type='text' id='firstname' value='Wyatt'/>"
"<INPUT type='text' id='lastname' value='Earp'/>"
Expand Down Expand Up @@ -3947,7 +3948,7 @@ TEST_F(FormAutofillTest, SelectOneAsText) {
}

TEST_F(FormAutofillTest,
UnownedFormElementsAndFieldSetsToFormDataFieldsets) {
DISABLED_UnownedFormElementsAndFieldSetsToFormDataFieldsets) {
std::vector<WebElement> fieldsets;
std::vector<WebFormControlElement> control_elements;

Expand Down Expand Up @@ -4009,7 +4010,7 @@ TEST_F(FormAutofillTest,
}

TEST_F(FormAutofillTest,
UnownedFormElementsAndFieldSetsToFormDataControlOutsideOfFieldset) {
DISABLED_UnownedFormElementsAndFieldSetsToFormDataControlOutsideOfFieldset) {
std::vector<WebElement> fieldsets;
std::vector<WebFormControlElement> control_elements;

Expand Down Expand Up @@ -4068,7 +4069,8 @@ TEST_F(FormAutofillTest,
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
}

TEST_F(FormAutofillTest, UnownedFormElementsAndFieldSetsToFormDataWithForm) {
TEST_F(FormAutofillTest,
DISABLED_UnownedFormElementsAndFieldSetsToFormDataWithForm) {
std::vector<WebElement> fieldsets;
std::vector<WebFormControlElement> control_elements;

Expand Down
39 changes: 0 additions & 39 deletions components/autofill/content/renderer/form_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,41 +119,10 @@ 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();
Expand Down Expand Up @@ -222,15 +191,7 @@ 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;
Expand Down
4 changes: 0 additions & 4 deletions components/autofill/content/renderer/form_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ 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_;
Expand Down

0 comments on commit 63e858a

Please sign in to comment.