Bug 1371131 - Part 1. Replace the "cc-number-masked" field name in form autofill storage with "cc-number". r=lchang
authorRay Lin <ralin@mozilla.com>
Mon, 24 Jul 2017 11:41:13 +0800
changeset 419428 05dde481973c4fd927c2992195adaa5a3eb2f2f9
parent 419427 aeb9b61cd780df786b38c415fa67fe692bda68b0
child 419429 6efa0b5aaabe5bd6b5e7c657897c520347e72968
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslchang
bugs1371131
milestone56.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 1371131 - Part 1. Replace the "cc-number-masked" field name in form autofill storage with "cc-number". r=lchang MozReview-Commit-ID: 1RGL4gu7JrK
browser/extensions/formautofill/ProfileStorage.jsm
browser/extensions/formautofill/test/unit/test_creditCardRecords.js
--- a/browser/extensions/formautofill/ProfileStorage.jsm
+++ b/browser/extensions/formautofill/ProfileStorage.jsm
@@ -53,18 +53,18 @@
  *   ],
  *   creditCards: [
  *     {
  *       guid,                 // 12 characters
  *       version,              // schema version in integer
  *
  *       // credit card fields
  *       cc-name,
+ *       cc-number,            // e.g. ************1234
  *       cc-number-encrypted,
- *       cc-number-masked,     // e.g. ************1234
  *       cc-exp-month,
  *       cc-exp-year,          // 2-digit year will be converted to 4 digits
  *                             // upon saving
  *
  *       // computed fields (These fields are computed based on the above fields
  *       // and are not allowed to be modified directly.)
  *       cc-given-name,
  *       cc-additional-name,
@@ -173,18 +173,18 @@ const TEL_COMPONENTS = [
 
 const VALID_ADDRESS_COMPUTED_FIELDS = [
   "name",
   "country-name",
 ].concat(STREET_ADDRESS_COMPONENTS, TEL_COMPONENTS);
 
 const VALID_CREDIT_CARD_FIELDS = [
   "cc-name",
+  "cc-number",
   "cc-number-encrypted",
-  "cc-number-masked",
   "cc-exp-month",
   "cc-exp-year",
 ];
 
 const VALID_CREDIT_CARD_COMPUTED_FIELDS = [
   "cc-given-name",
   "cc-additional-name",
   "cc-family-name",
@@ -1458,34 +1458,33 @@ class CreditCards extends AutofillRecord
     }
 
     return hasNewComputedFields;
   }
 
   _normalizeFields(creditCard) {
     // Fields that should not be set by content.
     delete creditCard["cc-number-encrypted"];
-    delete creditCard["cc-number-masked"];
 
     // Validate and encrypt credit card numbers, and calculate the masked numbers
     if (creditCard["cc-number"]) {
       let ccNumber = creditCard["cc-number"].replace(/\s/g, "");
       delete creditCard["cc-number"];
 
       if (!/^\d+$/.test(ccNumber)) {
         throw new Error("Credit card number contains invalid characters.");
       }
 
       // TODO: Encrypt cc-number here (bug 1337314).
       // e.g. creditCard["cc-number-encrypted"] = Encrypt(creditCard["cc-number"]);
 
       if (ccNumber.length > 4) {
-        creditCard["cc-number-masked"] = "*".repeat(ccNumber.length - 4) + ccNumber.substr(-4);
+        creditCard["cc-number"] = "*".repeat(ccNumber.length - 4) + ccNumber.substr(-4);
       } else {
-        creditCard["cc-number-masked"] = ccNumber;
+        creditCard["cc-number"] = ccNumber;
       }
     }
 
     // Normalize name
     if (creditCard["cc-given-name"] || creditCard["cc-additional-name"] || creditCard["cc-family-name"]) {
       if (!creditCard["cc-name"]) {
         creditCard["cc-name"] = FormAutofillNameUtils.joinNameParts({
           given: creditCard["cc-given-name"],
--- a/browser/extensions/formautofill/test/unit/test_creditCardRecords.js
+++ b/browser/extensions/formautofill/test/unit/test_creditCardRecords.js
@@ -68,23 +68,21 @@ let prepareTestCreditCards = async funct
   await profileStorage._saveImmediately();
 };
 
 let reCCNumber = /^(\*+)(.{4})$/;
 
 let do_check_credit_card_matches = (creditCardWithMeta, creditCard) => {
   for (let key in creditCard) {
     if (key == "cc-number") {
-      do_check_eq(creditCardWithMeta["cc-number"], undefined);
-
       // check "cc-number-encrypted" after encryption lands (bug 1337314).
 
-      let matches = reCCNumber.exec(creditCardWithMeta["cc-number-masked"]);
+      let matches = reCCNumber.exec(creditCardWithMeta["cc-number"]);
       do_check_neq(matches, null);
-      do_check_eq(creditCardWithMeta["cc-number-masked"].length, creditCard["cc-number"].length);
+      do_check_eq(creditCardWithMeta["cc-number"].length, creditCard["cc-number"].length);
       do_check_eq(creditCard["cc-number"].endsWith(matches[2]), true);
     } else {
       do_check_eq(creditCardWithMeta[key], creditCard[key]);
     }
   }
 };
 
 add_task(async function test_initialize() {
@@ -251,17 +249,17 @@ add_task(async function test_validate() 
 
   do_check_eq(creditCards[0]["cc-exp-month"], undefined);
   do_check_eq(creditCards[0]["cc-exp-year"], undefined);
 
   do_check_eq(creditCards[1]["cc-exp-month"], TEST_CREDIT_CARD_WITH_2_DIGITS_YEAR["cc-exp-month"]);
   do_check_eq(creditCards[1]["cc-exp-year"],
     parseInt(TEST_CREDIT_CARD_WITH_2_DIGITS_YEAR["cc-exp-year"], 10) + 2000);
 
-  do_check_eq(creditCards[2]["cc-number-masked"].length, 16);
+  do_check_eq(creditCards[2]["cc-number"].length, 16);
   // TODO: Check the decrypted numbers should not contain spaces after
   //       decryption lands (bug 1337314).
 
   Assert.throws(() => profileStorage.creditCards.add(TEST_CREDIT_CARD_WITH_INVALID_NUMBERS),
     /Credit card number contains invalid characters\./);
 });
 
 add_task(async function test_notifyUsed() {