Skip to content

Commit

Permalink
Bug 1392528 - Ignore autocomplete="off" attribute for Credit Card rel…
Browse files Browse the repository at this point in the history
…ated fields. r=MattN

MozReview-Commit-ID: BMdySEURsr8

--HG--
extra : rebase_source : 15c96fa1fa398fb9534a63eb6bcd9f408df594a4
  • Loading branch information
weilonge committed Sep 5, 2017
1 parent 79ee6f6 commit 5127c30
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 27 deletions.
18 changes: 14 additions & 4 deletions browser/extensions/formautofill/FormAutofillHeuristics.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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: "",
Expand All @@ -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 = {};
Expand Down
4 changes: 0 additions & 4 deletions browser/extensions/formautofill/FormAutofillUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
[],
[],
[],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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
],
],
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,25 @@ 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",
expectedResult: [
[
{"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"},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const TESTCASES = [
{
document: `<input id="targetElement" type="text" autocomplete="off">`,
fieldId: "targetElement",
expectedResult: false,
expectedResult: true,
},
{
document: `<input id="targetElement">`,
Expand All @@ -46,7 +46,7 @@ const TESTCASES = [
{
document: `<select id="targetElement" autocomplete="off"></select>`,
fieldId: "targetElement",
expectedResult: false,
expectedResult: true,
},
{
document: `<select id="targetElement"></select>`,
Expand Down

0 comments on commit 5127c30

Please sign in to comment.