From dddf9472afb434be7695edbabffd734d3ac60997 Mon Sep 17 00:00:00 2001 From: isherman Date: Wed, 29 Oct 2014 17:07:34 -0700 Subject: [PATCH] [Autofill] Don't save autocomplete text entered into fields with autocomplete="off" This fixes a regression introduced in [ https://codereview.chromium.org/407083002 ]. BUG=423326 TEST=components_unittests R=estade@chromium.org Review URL: https://codereview.chromium.org/688543002 Cr-Commit-Position: refs/heads/master@{#301985} --- .../core/browser/autocomplete_history_manager.cc | 2 ++ .../autocomplete_history_manager_unittest.cc | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/components/autofill/core/browser/autocomplete_history_manager.cc b/components/autofill/core/browser/autocomplete_history_manager.cc index a115b8a202cd..1c970fc3b038 100644 --- a/components/autofill/core/browser/autocomplete_history_manager.cc +++ b/components/autofill/core/browser/autocomplete_history_manager.cc @@ -126,6 +126,7 @@ void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { // - non-empty name // - non-empty value // - text field + // - autocomplete is not disabled // - value is not a credit card number // - value is not a SSN std::vector values; @@ -135,6 +136,7 @@ void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { if (!iter->value.empty() && !iter->name.empty() && IsTextField(*iter) && + iter->should_autocomplete && !autofill::IsValidCreditCardNumber(iter->value) && !autofill::IsSSN(iter->value)) { values.push_back(*iter); diff --git a/components/autofill/core/browser/autocomplete_history_manager_unittest.cc b/components/autofill/core/browser/autocomplete_history_manager_unittest.cc index 3431b823b168..af42bef469af 100644 --- a/components/autofill/core/browser/autocomplete_history_manager_unittest.cc +++ b/components/autofill/core/browser/autocomplete_history_manager_unittest.cc @@ -165,6 +165,28 @@ TEST_F(AutocompleteHistoryManagerTest, SearchField) { autocomplete_manager_->OnFormSubmitted(form); } +// Tests that text entered into fields specifying autocomplete="off" is not sent +// to the WebDatabase to be saved. +TEST_F(AutocompleteHistoryManagerTest, FieldWithAutocompleteOff) { + FormData form; + form.name = ASCIIToUTF16("MyForm"); + form.origin = GURL("http://myform.com/form.html"); + form.action = GURL("http://myform.com/submit.html"); + form.user_submitted = true; + + // Field specifying autocomplete="off". + FormFieldData field; + field.label = ASCIIToUTF16("Something esoteric"); + field.name = ASCIIToUTF16("esoterica"); + field.value = ASCIIToUTF16("a truly esoteric value, I assure you"); + field.form_control_type = "text"; + field.should_autocomplete = false; + form.fields.push_back(field); + + EXPECT_CALL(*web_data_service_.get(), AddFormFields(_)).Times(0); + autocomplete_manager_->OnFormSubmitted(form); +} + namespace { class MockAutofillExternalDelegate : public AutofillExternalDelegate { -- 2.11.4.GIT