From 5127c3035e831e70f11a81abcc22abe52710eea9 Mon Sep 17 00:00:00 2001 From: Sean Lee Date: Tue, 5 Sep 2017 16:42:38 +0800 Subject: [PATCH] Bug 1392528 - Ignore autocomplete="off" attribute for Credit Card related fields. r=MattN MozReview-Commit-ID: BMdySEURsr8 --HG-- extra : rebase_source : 15c96fa1fa398fb9534a63eb6bcd9f408df594a4 --- .../formautofill/FormAutofillHeuristics.jsm | 18 ++++++++++++++---- .../formautofill/FormAutofillUtils.jsm | 4 ---- .../unit/heuristics/third_party/test_CDW.js | 2 +- .../unit/heuristics/third_party/test_CostCo.js | 8 +++++--- .../unit/heuristics/third_party/test_Macys.js | 8 +++----- .../unit/heuristics/third_party/test_NewEgg.js | 6 +++--- .../unit/heuristics/third_party/test_QVC.js | 4 ++-- .../heuristics/third_party/test_Staples.js | 15 ++++++++++++--- .../unit/test_isFieldEligibleForAutofill.js | 4 ++-- 9 files changed, 42 insertions(+), 27 deletions(-) diff --git a/browser/extensions/formautofill/FormAutofillHeuristics.jsm b/browser/extensions/formautofill/FormAutofillHeuristics.jsm index 48d8a068d221e..7bfb2af93eda4 100644 --- a/browser/extensions/formautofill/FormAutofillHeuristics.jsm +++ b/browser/extensions/formautofill/FormAutofillHeuristics.jsm @@ -409,7 +409,7 @@ this.FormAutofillHeuristics = { * all field details in the form. */ getFormInfo(form, allowDuplicates = false) { - if (form.autocomplete == "off" || form.elements.length <= 0) { + if (form.elements.length <= 0) { return []; } @@ -442,7 +442,7 @@ this.FormAutofillHeuristics = { let info = element.getAutocompleteInfo(); // An input[autocomplete="on"] will not be early return here since it stll // needs to find the field name. - if (info && info.fieldName && info.fieldName != "on") { + if (info && info.fieldName && info.fieldName != "on" && info.fieldName != "off") { info._reason = "autocomplete"; return info; } @@ -451,11 +451,14 @@ this.FormAutofillHeuristics = { return null; } + let isAutoCompleteOff = element.autocomplete == "off" || + (element.form && element.form.autocomplete == "off"); + // "email" type of input is accurate for heuristics to determine its Email // field or not. However, "tel" type is used for ZIP code for some web site // (e.g. HomeDepot, BestBuy), so "tel" type should be not used for "tel" // prediction. - if (element.type == "email") { + if (element.type == "email" && !isAutoCompleteOff) { return { fieldName: "email", section: "", @@ -464,7 +467,14 @@ this.FormAutofillHeuristics = { }; } - let regexps = Object.keys(this.RULES); + const FIELDNAMES_IGNORING_AUTOCOMPLETE_OFF = [ + "cc-name", + "cc-number", + "cc-exp-month", + "cc-exp-year", + "cc-exp", + ]; + let regexps = isAutoCompleteOff ? FIELDNAMES_IGNORING_AUTOCOMPLETE_OFF : Object.keys(this.RULES); let labelStrings; let getElementStrings = {}; diff --git a/browser/extensions/formautofill/FormAutofillUtils.jsm b/browser/extensions/formautofill/FormAutofillUtils.jsm index 61e94f1970477..69e8f75d44098 100644 --- a/browser/extensions/formautofill/FormAutofillUtils.jsm +++ b/browser/extensions/formautofill/FormAutofillUtils.jsm @@ -167,10 +167,6 @@ this.FormAutofillUtils = { ALLOWED_TYPES: ["text", "email", "tel", "number"], isFieldEligibleForAutofill(element) { - if (element.autocomplete == "off") { - return false; - } - let tagName = element.tagName; if (tagName == "INPUT") { // `element.type` can be recognized as `text`, if it's missing or invalid. diff --git a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_CDW.js b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_CDW.js index 2654a40140657..488bbae167aa2 100644 --- a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_CDW.js +++ b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_CDW.js @@ -42,7 +42,7 @@ runHeuristicsTest([ // FIXME: bug 1392932 - misdetect ZIP ext string {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"}, // {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-type"}, -// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off + {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"}, // FIXME: bug 1392940 - the below element can not match to "cc-exp-year" regexp directly. diff --git a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_CostCo.js b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_CostCo.js index 2fa99bf0ca5f8..4f4a4c79862ad 100644 --- a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_CostCo.js +++ b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_CostCo.js @@ -47,16 +47,18 @@ runHeuristicsTest([ expectedResult: [ [ // {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-type"}, -// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off + {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"}, // FIXME: bug 1392940 - the below element can not match to "cc-exp-year" regexp directly. // {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-year"}, // {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"}, // ac-off -// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-name"}, // ac-off + {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-name"}, // ac-off + ], + [ + {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off ], - [], [], [], [ diff --git a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Macys.js b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Macys.js index bfccaee89062b..a3442064638e1 100644 --- a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Macys.js +++ b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Macys.js @@ -25,14 +25,12 @@ runHeuristicsTest([ fixturePath: "Checkout_Payment.html", expectedResult: [ [ - /* - {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-type"}, // ac-off +// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-type"}, // ac-off {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"}, // ac-off {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-year"}, // ac-off - {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"}, // ac-off - {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"}, // ac-off -*/ +// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"}, // ac-off +// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"}, // ac-off {"section": "", "addressType": "", "contactType": "", "fieldName": "given-name"}, {"section": "", "addressType": "", "contactType": "", "fieldName": "family-name"}, {"section": "", "addressType": "", "contactType": "", "fieldName": "address-line1"}, diff --git a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_NewEgg.js b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_NewEgg.js index dd47990fbf8b5..5eecc24485140 100644 --- a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_NewEgg.js +++ b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_NewEgg.js @@ -25,7 +25,7 @@ runHeuristicsTest([ expectedResult: [ [ {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-name"}, -// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off + {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"}, {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-year"}, // {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"}, @@ -39,14 +39,14 @@ runHeuristicsTest([ ], [ {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-name"}, -// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off + {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"}, {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-year"}, ], [], [ {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-name"}, -// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off + {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off ], ], }, { diff --git a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_QVC.js b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_QVC.js index f5fc1ad04263a..dee91cc401135 100644 --- a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_QVC.js +++ b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_QVC.js @@ -13,13 +13,13 @@ runHeuristicsTest([ // {"section": "", "addressType": "", "contactType": "", "fieldName": "bday-day"}, // select // {"section": "", "addressType": "", "contactType": "", "fieldName": "bday-year"}, // {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-type"}, -// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // FIXME: bug 1392947 - this is a compound cc-exp field rather than the // separated ones below. the birthday fields are misdetected as // cc-exp-year and cc-exp-month. // {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp"}, {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-year"}, + {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"}, // {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"}, @@ -38,13 +38,13 @@ runHeuristicsTest([ // {"section": "", "addressType": "", "contactType": "", "fieldName": "bday-day"}, // select // {"section": "", "addressType": "", "contactType": "", "fieldName": "bday-year"}, // select // {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-type"}, // select -// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, ac-off // FIXME: bug 1392947 - this is a compound cc-exp field rather than the // separated ones below. the birthday fields are misdetected as // cc-exp-year and cc-exp-month. // {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp"}, // select {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-year"}, + {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, // ac-off {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"}, // {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"}, diff --git a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Staples.js b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Staples.js index caa2249c436f1..2e6e99914ff20 100644 --- a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Staples.js +++ b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Staples.js @@ -32,7 +32,15 @@ runHeuristicsTest([ }, { fixturePath: "PaymentBilling.html", expectedResult: [ - [], + [ + {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, + + // FIXME: bug 1392940 - Since any credit card fields should be + // recognized no matter it's autocomplete="off" or not. This field + // "cc-exp-month" should be fixed as "cc-exp". + {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"}, +// {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"}, + ], ], }, { fixturePath: "PaymentBilling_ac_on.html", @@ -40,8 +48,9 @@ runHeuristicsTest([ [ {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"}, - // Since this is a custom fixture with force autocomplete="on", we can - // fix this later even this should be detected as cc-exp. + // FIXME: bug 1392940 - Since any credit card fields should be + // recognized no matter it's autocomplete="off" or not. This field + // "cc-exp-month" should be fixed as "cc-exp". {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"}, // {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"}, ], diff --git a/browser/extensions/formautofill/test/unit/test_isFieldEligibleForAutofill.js b/browser/extensions/formautofill/test/unit/test_isFieldEligibleForAutofill.js index 9e39f4c5f37be..42dae5d305e2f 100644 --- a/browser/extensions/formautofill/test/unit/test_isFieldEligibleForAutofill.js +++ b/browser/extensions/formautofill/test/unit/test_isFieldEligibleForAutofill.js @@ -31,7 +31,7 @@ const TESTCASES = [ { document: ``, fieldId: "targetElement", - expectedResult: false, + expectedResult: true, }, { document: ``, @@ -46,7 +46,7 @@ const TESTCASES = [ { document: ``, fieldId: "targetElement", - expectedResult: false, + expectedResult: true, }, { document: ``,