Backed out changeset 0f0e045d2928 (bug 1647043) for multiple formautofill failures. CLOSED TREE
authorCsoregi Natalia <ncsoregi@mozilla.com>
Mon, 22 Jun 2020 09:11:13 +0300
changeset 536501 24787602a9f6bc95a34930d3bc087d4ac54fe1a5
parent 536500 0f0e045d29285c81be9176ea927831b21469aa06
child 536502 5b83370e09132acb7b42a292c078c4114c29737e
push id37528
push usernerli@mozilla.com
push dateMon, 22 Jun 2020 09:33:09 +0000
treeherdermozilla-central@24787602a9f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1647043
milestone79.0a1
backs out0f0e045d29285c81be9176ea927831b21469aa06
first release with
nightly linux32
24787602a9f6 / 79.0a1 / 20200622093309 / files
nightly linux64
24787602a9f6 / 79.0a1 / 20200622093309 / files
nightly mac
24787602a9f6 / 79.0a1 / 20200622093309 / files
nightly win32
24787602a9f6 / 79.0a1 / 20200622093309 / files
nightly win64
24787602a9f6 / 79.0a1 / 20200622093309 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 0f0e045d2928 (bug 1647043) for multiple formautofill failures. CLOSED TREE
browser/extensions/formautofill/FormAutofillStorage.jsm
browser/extensions/formautofill/test/unit/test_creditCardRecords.js
toolkit/modules/CreditCard.jsm
toolkit/modules/tests/xpcshell/test_CreditCard.js
--- a/browser/extensions/formautofill/FormAutofillStorage.jsm
+++ b/browser/extensions/formautofill/FormAutofillStorage.jsm
@@ -1770,23 +1770,16 @@ class CreditCards extends AutofillRecord
     //       it's empty or not.
 
     let hasNewComputedFields = false;
 
     if (creditCard.deleted) {
       return hasNewComputedFields;
     }
 
-    if (!("cc-type" in creditCard)) {
-      let type = CreditCard.getType(creditCard["cc-number"]);
-      if (type) {
-        creditCard["cc-type"] = type;
-      }
-    }
-
     // Compute split names
     if (!("cc-given-name" in creditCard)) {
       let nameParts = FormAutofillNameUtils.splitName(creditCard["cc-name"]);
       creditCard["cc-given-name"] = nameParts.given;
       creditCard["cc-additional-name"] = nameParts.middle;
       creditCard["cc-family-name"] = nameParts.family;
       hasNewComputedFields = true;
     }
--- a/browser/extensions/formautofill/test/unit/test_creditCardRecords.js
+++ b/browser/extensions/formautofill/test/unit/test_creditCardRecords.js
@@ -39,23 +39,21 @@ const TEST_CREDIT_CARD_2 = {
   "cc-exp-year": 2022,
   "cc-type": "mastercard",
 };
 
 const TEST_CREDIT_CARD_3 = {
   "cc-number": "3589993783099582",
   "cc-exp-month": 1,
   "cc-exp-year": 2000,
-  "cc-type": "amex",
 };
 
 const TEST_CREDIT_CARD_4 = {
   "cc-name": "Foo Bar",
   "cc-number": "3589993783099582",
-  "cc-type": "amex",
 };
 
 const TEST_CREDIT_CARD_WITH_BILLING_ADDRESS = {
   "cc-name": "J. Smith",
   "cc-number": "4111111111111111",
   billingAddressGUID: "9m6hf4gfr6ge",
 };
 
@@ -447,17 +445,17 @@ add_task(async function test_update() {
     TEST_CREDIT_CARD_WITH_EMPTY_FIELD
   );
   creditCard = profileStorage.creditCards._data[0];
   Assert.equal(
     creditCard["cc-exp-month"],
     TEST_CREDIT_CARD_WITH_EMPTY_FIELD["cc-exp-month"]
   );
   Assert.equal(creditCard["cc-name"], undefined);
-  Assert.equal(creditCard["cc-type"], "amex");
+  Assert.equal(creditCard["cc-type"], undefined);
   Assert.equal(creditCard.billingAddressGUID, undefined);
 
   // Empty computed fields shouldn't cause any problem.
   await profileStorage.creditCards.update(
     profileStorage.creditCards._data[0].guid,
     TEST_CREDIT_CARD_WITH_EMPTY_COMPUTED_FIELD,
     false
   );
--- a/toolkit/modules/CreditCard.jsm
+++ b/toolkit/modules/CreditCard.jsm
@@ -16,48 +16,16 @@ const SUPPORTED_NETWORKS = Object.freeze
   "discover",
   "jcb",
   "mastercard",
   "mir",
   "unionpay",
   "visa",
 ]);
 
-// Based on https://en.wikipedia.org/wiki/Payment_card_number
-//
-// Notice:
-//   - CarteBancaire (`4035`, `4360`) is now recognized as Visa.
-//   - UnionPay (`63--`) is now recognized as Discover.
-// This means that the order matters.
-// First we'll try to match more specific card,
-// and if that doesn't match we'll test against the more generic range.
-const CREDIT_CARD_IIN = [
-  { type: "amex", start: 34, end: 34, length: 15 },
-  { type: "amex", start: 37, end: 37, length: 15 },
-  { type: "cartebancaire", start: 4035, end: 4035, length: 16 },
-  { type: "cartebancaire", start: 4360, end: 4360, length: 16 },
-  { type: "diners", start: 300, end: 305, length: 16 },
-  { type: "diners", start: 3095, end: 3095, length: 16 },
-  { type: "diners", start: 36, end: 36, length: 14 },
-  { type: "diners", start: 38, end: 39, length: 16 },
-  { type: "diners", start: 54, end: 55, length: 16 },
-  { type: "discover", start: 6011, end: 6011, length: 16 },
-  { type: "discover", start: 622126, end: 622925, length: 16 },
-  { type: "discover", start: 624000, end: 626999, length: 16 },
-  { type: "discover", start: 628200, end: 628899, length: 16 },
-  { type: "discover", start: 64, end: 65, length: 16 },
-  { type: "jcb", start: 3528, end: 3589, length: 16 },
-  { type: "mastercard", start: 2221, end: 2720, length: 16 },
-  { type: "mastercard", start: 51, end: 55, length: 16 },
-  { type: "mir", start: 2200, end: 2204, length: 16 },
-  { type: "unionpay", start: 62, end: 62, length: 16 },
-  { type: "unionpay", start: 81, end: 81, length: 16 },
-  { type: "visa", start: 4, end: 4, length: 16 },
-].sort((a, b) => b.start - a.start);
-
 class CreditCard {
   /**
    * A CreditCard object represents a credit card, with
    * number, name, expiration, network, and CCV.
    * The number is the only required information when creating
    * an object, all other members are optional. The number
    * is validated during construction and will throw if invalid.
    *
@@ -206,37 +174,16 @@ class CreditCard {
         }
       }
       total += ch;
     }
     return total % 10 == 0;
   }
 
   /**
-   * Attempts to match the number against known network identifiers.
-   *
-   * @param {string} ccNumber
-   *
-   * @returns {string|null}
-   */
-  static getType(ccNumber) {
-    for (let i = 0; i < CREDIT_CARD_IIN.length; i++) {
-      const range = CREDIT_CARD_IIN[i];
-      if (ccNumber.length == range.length) {
-        const prefixLength = Math.floor(Math.log10(range.start)) + 1;
-        const prefix = parseInt(ccNumber.substring(0, prefixLength), 10);
-        if (prefix >= range.start && prefix <= range.end) {
-          return range.type;
-        }
-      }
-    }
-    return null;
-  }
-
-  /**
    * Returns true if the card number is valid and the
    * expiration date has not passed. Otherwise false.
    *
    * @returns {boolean}
    */
   isValid() {
     if (!this.isValidNumber()) {
       return false;
--- a/toolkit/modules/tests/xpcshell/test_CreditCard.js
+++ b/toolkit/modules/tests/xpcshell/test_CreditCard.js
@@ -448,83 +448,8 @@ add_task(async function test_isValidNetw
     !CreditCard.isValidNetwork("Visa"),
     "network validity is case-sensitive"
   );
   Assert.ok(
     !CreditCard.isValidNetwork("madeupnetwork"),
     "unknown network is invalid"
   );
 });
-
-add_task(async function test_getType() {
-  const RECOGNIZED_CARDS = [
-    // Edge cases
-    ["2221000000000000", "mastercard"],
-    ["2720000000000000", "mastercard"],
-    ["2200000000000000", "mir"],
-    ["2204000000000000", "mir"],
-    ["340000000000000", "amex"],
-    ["370000000000000", "amex"],
-    ["3000000000000000", "diners"],
-    ["3050000000000000", "diners"],
-    ["3095000000000000", "diners"],
-    ["36000000000000", "diners"],
-    ["3800000000000000", "diners"],
-    ["3900000000000000", "diners"],
-    ["3528000000000000", "jcb"],
-    ["3589000000000000", "jcb"],
-    ["4035000000000000", "cartebancaire"],
-    ["4360000000000000", "cartebancaire"],
-    ["4000000000000000", "visa"],
-    ["4999999999999999", "visa"],
-    ["5400000000000000", "diners"],
-    ["5500000000000000", "diners"],
-    ["5100000000000000", "mastercard"],
-    ["5399999999999999", "mastercard"],
-    ["6011000000000000", "discover"],
-    ["6221260000000000", "discover"],
-    ["6229250000000000", "discover"],
-    ["6240000000000000", "discover"],
-    ["6269990000000000", "discover"],
-    ["6282000000000000", "discover"],
-    ["6288990000000000", "discover"],
-    ["6400000000000000", "discover"],
-    ["6500000000000000", "discover"],
-    ["6200000000000000", "unionpay"],
-    ["8100000000000000", "unionpay"],
-    // Valid according to Luhn number
-    ["2204941877211882", "mir"],
-    ["2720994326581252", "mastercard"],
-    ["374542158116607", "amex"],
-    ["36006666333344", "diners"],
-    ["3541675340715696", "jcb"],
-    ["3543769248058305", "jcb"],
-    ["4035501428146300", "cartebancaire"],
-    ["4111111111111111", "visa"],
-    ["5346755600299631", "mastercard"],
-    ["5495770093313616", "diners"],
-    ["5574238524540144", "diners"],
-    ["6011029459267962", "discover"],
-    ["6278592974938779", "unionpay"],
-    ["8171999927660000", "unionpay"],
-  ];
-  for (let [value, type] of RECOGNIZED_CARDS) {
-    Assert.equal(
-      CreditCard.getType(value),
-      type,
-      `Expected ${value} to be recognized as ${type}`
-    );
-  }
-
-  const UNRECOGNIZED_CARDS = [
-    ["411111111111111", "15 digits"],
-    ["41111111111111111", "17 digits"],
-    ["", "empty"],
-    ["9111111111111111", "Unknown prefix"],
-  ];
-  for (let [value, reason] of UNRECOGNIZED_CARDS) {
-    Assert.equal(
-      CreditCard.getType(value),
-      null,
-      `Expected ${value} to not match any card because: ${reason}`
-    );
-  }
-});