Bug 1370429 - Part 6: Modify the test case of targeting web sites to support the telephone related fields. r=MattN draft
authorSean Lee <selee@mozilla.com>
Wed, 19 Jul 2017 10:20:32 +0800
changeset 613055 0a874d13c65463d4d499e72fe5cb442eb8180c28
parent 613054 3f7d0d117317e4746b444e410c006df991944c38
child 638602 b7e83ddb9ff3e41ac2025c3071bd693ea2a65d88
push id69715
push userbmo:selee@mozilla.com
push dateFri, 21 Jul 2017 14:12:03 +0000
reviewersMattN
bugs1370429
milestone56.0a1
Bug 1370429 - Part 6: Modify the test case of targeting web sites to support the telephone related fields. r=MattN MozReview-Commit-ID: CqqpjGEnnaw
browser/extensions/formautofill/test/unit/heuristics/third_party/test_CDW.js
browser/extensions/formautofill/test/unit/heuristics/third_party/test_OfficeDepot.js
browser/extensions/formautofill/test/unit/heuristics/third_party/test_Sears.js
browser/extensions/formautofill/test/unit/heuristics/third_party/test_Walmart.js
browser/extensions/formautofill/test/unit/test_collectFormFields.js
--- a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_CDW.js
+++ b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_CDW.js
@@ -10,33 +10,38 @@ runHeuristicsTest([
         {"section": "", "addressType": "", "contactType": "", "fieldName": "given-name"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "family-name"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "organization"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-line1"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-line2"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"}, // city
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-level1"}, // state
         {"section": "", "addressType": "", "contactType": "", "fieldName": "postal-code"},
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"}, // FIXME: ZIP ext
         {"section": "", "addressType": "", "contactType": "", "fieldName": "email"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "tel"},
+        // FIXME: The below "tel-extension" is correct and removed due to the
+        // duplicated field above.
+//      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
       ],
       [],
     ],
   }, {
     fixturePath: "Checkout_BillingPaymentInfo.html",
     expectedResult: [
       [
         {"section": "", "addressType": "", "contactType": "", "fieldName": "given-name"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "family-name"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "organization"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-line1"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-line2"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"}, // city
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-level1"}, // state
         {"section": "", "addressType": "", "contactType": "", "fieldName": "postal-code"},
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"}, // FIXME: ZIP ext
       ],
       [
  /* TODO: Credit Card
         {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-type"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-number"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-year"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"},
--- a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_OfficeDepot.js
+++ b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_OfficeDepot.js
@@ -11,22 +11,20 @@ runHeuristicsTest([
         {"section": "", "addressType": "", "contactType": "", "fieldName": "family-name"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "organization"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-line1"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-line2"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "postal-code"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-level1"}, // state
 
-        // TODO: telphone relative fields should be fixed:
-        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel"},
-//      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-area-code"},
-//      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-local-prefix"},
-//      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-local-suffix"},
-//      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-area-code"},
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-local-prefix"},
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-local-suffix"},
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
 
         {"section": "", "addressType": "", "contactType": "", "fieldName": "email"},
       ],
       [],
     ],
   }, {
     fixturePath: "Payment.html",
     expectedResult: [
@@ -37,22 +35,20 @@ runHeuristicsTest([
         {"section": "", "addressType": "", "contactType": "", "fieldName": "family-name"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "organization"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-line1"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-line2"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "postal-code"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-level1"}, // state
 
-        // TODO: telphone relative fields should be fixed:
-        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel"},
-//      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-area-code"},
-//      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-local-prefix"},
-//      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-local-suffix"},
-//      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-area-code"},
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-local-prefix"},
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-local-suffix"},
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
 
         {"section": "", "addressType": "", "contactType": "", "fieldName": "email"},
       ],
     ],
   }, {
     fixturePath: "SignIn.html",
     expectedResult: [
       [ // ac-off
--- a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Sears.js
+++ b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Sears.js
@@ -63,17 +63,17 @@ runHeuristicsTest([
         {"section": "", "addressType": "", "contactType": "", "fieldName": "given-name"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "family-name"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-line1"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-line2"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"}, // city
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-level1"}, // state
         {"section": "", "addressType": "", "contactType": "", "fieldName": "postal-code"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "tel"},
-//      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
       ],
       [ // check out
         {"section": "", "addressType": "", "contactType": "", "fieldName": "given-name"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "family-name"},
         {"section": "", "addressType": "", "contactType": "", "fieldName": "address-level1"}, // TODO: Wrong. This is for Driver's license.
 //      {"section": "", "addressType": "", "contactType": "", "fieldName": "bday-month"},
 //      {"section": "", "addressType": "", "contactType": "", "fieldName": "bday-day"},
 //      {"section": "", "addressType": "", "contactType": "", "fieldName": "bday-year"},
--- a/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Walmart.js
+++ b/browser/extensions/formautofill/test/unit/heuristics/third_party/test_Walmart.js
@@ -28,16 +28,20 @@ runHeuristicsTest([
       [
       ],
       [
         {"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "given-name"},
         {"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "family-name"},
         {"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "cc-number"},
         {"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"},
         {"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "cc-exp-year"},
+        // FIXME The following field shouldn't be recognized as "tel-extension".
+        // The wrong prediction is caused by the name attr "brwsrAutofillText"
+        // which matches the regexp "ext\\b".
+        {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-extension"},
 //      {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-csc"},
         {"section": "section-payment", "addressType": "", "contactType": "", "fieldName": "tel"},
       ],
     ],
   }, {
     fixturePath: "Shipping.html",
     expectedResult: [
       [
--- a/browser/extensions/formautofill/test/unit/test_collectFormFields.js
+++ b/browser/extensions/formautofill/test/unit/test_collectFormFields.js
@@ -6,32 +6,32 @@
 
 Cu.import("resource://formautofill/FormAutofillHandler.jsm");
 
 const TESTCASES = [
   {
     description: "Form without autocomplete property",
     document: `<form><input id="given-name"><input id="family-name">
                <input id="street-addr"><input id="city"><select id="country"></select>
-               <input id='email'><input id="tel"></form>`,
+               <input id='email'><input id="phone"></form>`,
     addressFieldDetails: [
       {"section": "", "addressType": "", "contactType": "", "fieldName": "given-name"},
       {"section": "", "addressType": "", "contactType": "", "fieldName": "family-name"},
       {"section": "", "addressType": "", "contactType": "", "fieldName": "address-line1"},
       {"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"},
       {"section": "", "addressType": "", "contactType": "", "fieldName": "country"},
       {"section": "", "addressType": "", "contactType": "", "fieldName": "email"},
       {"section": "", "addressType": "", "contactType": "", "fieldName": "tel"},
     ],
     creditCardFieldDetails: [],
     isValidForm: {
       address: true,
       creditCard: false,
     },
-    ids: ["given-name", "family-name", "street-addr", "city", "country", "email", "tel"],
+    ids: ["given-name", "family-name", "street-addr", "city", "country", "email", "phone"],
   },
   {
     description: "An address and credit card form with autocomplete properties and 1 token",
     document: `<form>
                <input id="given-name" autocomplete="given-name">
                <input id="family-name" autocomplete="family-name">
                <input id="street-addr" autocomplete="street-address">
                <input id="city" autocomplete="address-level2">
@@ -154,16 +154,118 @@ const TESTCASES = [
       {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-month"},
       {"section": "", "addressType": "", "contactType": "", "fieldName": "cc-exp-year"},
     ],
     isValidForm: {
       address: false,
       creditCard: false,
     },
   },
+  {
+    description: "Three sets of adjacent phone number fields",
+    document: `<form>
+                 <input id="shippingAreaCode" autocomplete="shipping tel" maxlength="3">
+                 <input id="shippingPrefix" autocomplete="shipping tel" maxlength="3">
+                 <input id="shippingSuffix" autocomplete="shipping tel" maxlength="4">
+                 <input id="shippingTelExt" autocomplete="shipping tel-extension">
+
+                 <input id="billingAreaCode" autocomplete="billing tel" maxlength="3">
+                 <input id="billingPrefix" autocomplete="billing tel" maxlength="3">
+                 <input id="billingSuffix" autocomplete="billing tel" maxlength="4">
+
+                 <input id="otherCountryCode" autocomplete="tel" maxlength="3">
+                 <input id="otherAreaCode" autocomplete="tel" maxlength="3">
+                 <input id="otherPrefix" autocomplete="tel" maxlength="3">
+                 <input id="otherSuffix" autocomplete="tel" maxlength="4">
+               </form>`,
+    addressFieldDetails: [
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel-area-code"},
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel-local-prefix"},
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel-local-suffix"},
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel-extension"},
+      {"section": "", "addressType": "billing", "contactType": "", "fieldName": "tel-area-code"},
+      {"section": "", "addressType": "billing", "contactType": "", "fieldName": "tel-local-prefix"},
+      {"section": "", "addressType": "billing", "contactType": "", "fieldName": "tel-local-suffix"},
+      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-country-code"},
+      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-area-code"},
+      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-local-prefix"},
+      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel-local-suffix"},
+    ],
+    creditCardFieldDetails: [],
+    isValidForm: {
+      address: true,
+      creditCard: false,
+    },
+    ids: [
+      "shippingAreaCode", "shippingPrefix", "shippingSuffix", "shippingTelExt",
+      "billingAreaCode", "billingPrefix", "billingSuffix",
+      "otherCountryCode", "otherAreaCode", "otherPrefix", "otherSuffix",
+    ],
+  },
+  {
+    description: "Dedup the same field names of the different telephone fields.",
+    document: `<form>
+                 <input id="i1" autocomplete="shipping given-name">
+                 <input id="i2" autocomplete="shipping family-name">
+                 <input id="i3" autocomplete="shipping street-address">
+                 <input id="i4" autocomplete="shipping email">
+
+                 <input id="homePhone" maxlength="10">
+                 <input id="mobilePhone" maxlength="10">
+                 <input id="officePhone" maxlength="10">
+               </form>`,
+    addressFieldDetails: [
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name"},
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name"},
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address"},
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email"},
+      {"section": "", "addressType": "", "contactType": "", "fieldName": "tel"},
+    ],
+    creditCardFieldDetails: [],
+    isValidForm: {
+      address: true,
+      creditCard: false,
+    },
+    ids: ["i1", "i2", "i3", "i4", "homePhone"],
+  },
+  {
+    description: "The duplicated phones of a single one and a set with ac, prefix, suffix.",
+    document: `<form>
+                 <input id="i1" autocomplete="shipping given-name">
+                 <input id="i2" autocomplete="shipping family-name">
+                 <input id="i3" autocomplete="shipping street-address">
+                 <input id="i4" autocomplete="shipping email">
+                 <input id="singlePhone" autocomplete="shipping tel">
+                 <input id="shippingAreaCode" autocomplete="shipping tel-area-code">
+                 <input id="shippingPrefix" autocomplete="shipping tel-local-prefix">
+                 <input id="shippingSuffix" autocomplete="shipping tel-local-suffix">
+               </form>`,
+    addressFieldDetails: [
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name"},
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name"},
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address"},
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email"},
+
+      // NOTES: Ideally, there is only one full telephone field(s) in a form for
+      // this case. We can see if there is any better solution later.
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel"},
+
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel-area-code"},
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel-local-prefix"},
+      {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel-local-suffix"},
+    ],
+    creditCardFieldDetails: [],
+    isValidForm: {
+      address: true,
+      creditCard: false,
+    },
+    ids: ["i1", "i2", "i3", "i4",
+          "singlePhone",
+          "shippingAreaCode", "shippingPrefix", "shippingSuffix"],
+  },
 ];
 
 for (let tc of TESTCASES) {
   (function() {
     let testcase = tc;
     add_task(async function() {
       do_print("Starting testcase: " + testcase.description);
 
@@ -184,22 +286,23 @@ for (let tc of TESTCASES) {
         }
         detail.elementWeakRef = Cu.getWeakReference(elementRef);
       });
       let handler = new FormAutofillHandler(formLike);
 
       handler.collectFormFields();
 
       function verifyDetails(handlerDetails, testCaseDetails) {
+        Assert.equal(handlerDetails.length, testCaseDetails.length);
         handlerDetails.forEach((detail, index) => {
-          Assert.equal(detail.section, testCaseDetails[index].section);
-          Assert.equal(detail.addressType, testCaseDetails[index].addressType);
-          Assert.equal(detail.contactType, testCaseDetails[index].contactType);
-          Assert.equal(detail.fieldName, testCaseDetails[index].fieldName);
-          Assert.equal(detail.elementWeakRef.get(), testCaseDetails[index].elementWeakRef.get());
+          Assert.equal(detail.fieldName, testCaseDetails[index].fieldName, "fieldName");
+          Assert.equal(detail.section, testCaseDetails[index].section, "section");
+          Assert.equal(detail.addressType, testCaseDetails[index].addressType, "addressType");
+          Assert.equal(detail.contactType, testCaseDetails[index].contactType, "contactType");
+          Assert.equal(detail.elementWeakRef.get(), testCaseDetails[index].elementWeakRef.get(), "DOM reference");
         });
       }
 
       verifyDetails(handler.addressFieldDetails, testcase.addressFieldDetails);
       verifyDetails(handler.creditCardFieldDetails, testcase.creditCardFieldDetails);
 
       Assert.equal(handler.isValidAddressForm, testcase.isValidForm.address, "Valid Address Form Checking");
       Assert.equal(handler.isValidCreditCardForm, testcase.isValidForm.creditCard, "Valid Credit Card Form Checking");