Bug 1426652 - Allow the form with non-autocomplete-attr cc-number and cc-name as valid credit card form, r=lchang
authorsteveck-chung <schung@mozilla.com>
Wed, 10 Jan 2018 15:50:46 +0800
changeset 453573 c6f4e32c749ba4150616c00da57c4e3b90f72be4
parent 453572 492a154a477f9f38122a5214367a95b76c82b560
child 453574 717d16330a1ba34b2c8e412fa9efde46e0714773
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslchang
bugs1426652
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1426652 - Allow the form with non-autocomplete-attr cc-number and cc-name as valid credit card form, r=lchang MozReview-Commit-ID: 8eqJUSYyPXr
browser/extensions/formautofill/FormAutofillHandler.jsm
browser/extensions/formautofill/test/unit/test_collectFormFields.js
--- a/browser/extensions/formautofill/FormAutofillHandler.jsm
+++ b/browser/extensions/formautofill/FormAutofillHandler.jsm
@@ -735,32 +735,39 @@ class FormAutofillCreditCardSection exte
   constructor(fieldDetails, winUtils) {
     super(fieldDetails, winUtils);
   }
 
   isValidSection() {
     let ccNumberReason = "";
     let hasCCNumber = false;
     let hasExpiryDate = false;
+    let hasCCName = false;
 
     for (let detail of this.fieldDetails) {
       switch (detail.fieldName) {
         case "cc-number":
           hasCCNumber = true;
           ccNumberReason = detail._reason;
           break;
+        case "cc-name":
+        case "cc-given-name":
+        case "cc-additional-name":
+        case "cc-family-name":
+          hasCCName = true;
+          break;
         case "cc-exp":
         case "cc-exp-month":
         case "cc-exp-year":
           hasExpiryDate = true;
           break;
       }
     }
 
-    return hasCCNumber && (ccNumberReason == "autocomplete" || hasExpiryDate);
+    return hasCCNumber && (ccNumberReason == "autocomplete" || hasExpiryDate || hasCCName);
   }
 
   isEnabled() {
     return FormAutofillUtils.isAutofillCreditCardsEnabled;
   }
 
   isRecordCreatable(record) {
     return record["cc-number"] && FormAutofillUtils.isCCNumber(record["cc-number"]);
--- a/browser/extensions/formautofill/test/unit/test_collectFormFields.js
+++ b/browser/extensions/formautofill/test/unit/test_collectFormFields.js
@@ -168,33 +168,53 @@ const TESTCASES = [
     document: `<form>
                <input id="given-name" autocomplete="shipping given-name">
                <input autocomplete="shipping address-level2">
                </form>`,
     sections: [[]],
     validFieldDetails: [],
   },
   {
+    description: "An invalid credit card form due to non-autocomplete-attr cc-number only",
+    document: `<form>
+               <input id="cc-number" name="cc-number">
+               </form>`,
+    sections: [[]],
+    validFieldDetails: [],
+  },
+  {
     description: "An invalid credit card form due to omitted cc-number.",
     document: `<form>
                <input id="cc-name" autocomplete="cc-name">
                <input id="cc-exp-month" autocomplete="cc-exp-month">
                <input id="cc-exp-year" autocomplete="cc-exp-year">
                </form>`,
     sections: [[]],
     validFieldDetails: [],
   },
   {
-    description: "An invalid credit card form due to non-autocomplete-attr cc-number and omitted cc-exp-*.",
+    description: "A valid credit card form with non-autocomplete-attr cc-number and cc-name.",
     document: `<form>
                <input id="cc-name" autocomplete="cc-name">
                <input id="cc-number" name="card-number">
                </form>`,
-    sections: [[]],
-    validFieldDetails: [],
+    sections: [
+      [
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-name"},
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"},
+      ],
+    ],
+    validFieldDetails: [
+      {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-name"},
+      {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"},
+    ],
+    ids: [
+      "cc-name",
+      "cc-number",
+    ],
   },
   {
     description: "A valid credit card form with autocomplete-attr cc-number only.",
     document: `<form>
                <input id="cc-number" autocomplete="cc-number">
                </form>`,
     sections: [
       [