Bug 1505141 - Always preserveOldProperties for payment request but blank mailing address fields by default. r=jaws
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 21 Nov 2018 00:46:23 +0000
changeset 506707 4f693fc02c24ea7c3e66064ff07b9e50733ee4c4
parent 506706 729cedad713786834a58cdfe94e58d076f8ce59b
child 506708 5128dd79f222e3623c2392d83b7124f7e79db32d
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1505141
milestone65.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 1505141 - Always preserveOldProperties for payment request but blank mailing address fields by default. r=jaws Differential Revision: https://phabricator.services.mozilla.com/D12190
browser/components/payments/content/paymentDialogWrapper.js
browser/components/payments/test/mochitest/test_address_form.html
browser/extensions/formautofill/content/autofillEditForms.js
--- a/browser/components/payments/content/paymentDialogWrapper.js
+++ b/browser/components/payments/content/paymentDialogWrapper.js
@@ -657,20 +657,22 @@ var paymentDialogWrapper = {
       stateChange: {},
     };
     try {
       let isTemporary = record.isTemporary;
       let collection = isTemporary ? this.temporaryStore[collectionName] :
                                      formAutofillStorage[collectionName];
 
       if (guid) {
-        // We only care to preserve old properties for credit cards,
-        // because credit cards don't get their full record sent to the
-        // unprivileged frame (the cc-number is excluded).
-        let preserveOldProperties = collectionName == "creditCards";
+        // We want to preserve old properties since the edit forms are often
+        // shown without all fields visible/enabled and we don't want those
+        // fields to be blanked upon saving. Examples of hidden/disabled fields:
+        // email, cc-number, mailing-address on the payer forms, and payer fields
+        // not requested in the payer form.
+        let preserveOldProperties = true;
         await collection.update(guid, record, preserveOldProperties);
       } else {
         responseMessage.guid = await collection.add(record);
       }
 
       if (isTemporary && collectionName == "addresses") {
         // there will be no formautofill-storage-changed event to update state
         // so add updated collection here
--- a/browser/components/payments/test/mochitest/test_address_form.html
+++ b/browser/components/payments/test/mochitest/test_address_form.html
@@ -169,16 +169,17 @@ add_task(async function test_saveButton(
     guid: undefined,
     messageType: "updateAutofillRecord",
     record: {
       "given-name": "Jaws",
       "family-name": "Swaj",
       "additional-name": "",
       "organization": "Allizom",
       "street-address": "404 Internet Super Highway",
+      "address-level3": "",
       "address-level2": "Firefoxity City",
       "address-level1": "CA",
       "postal-code": "00001",
       "country": "US",
       "tel": "+15555551212",
     },
   }, "Check event details for the message to chrome");
   form.remove();
--- a/browser/extensions/formautofill/content/autofillEditForms.js
+++ b/browser/extensions/formautofill/content/autofillEditForms.js
@@ -43,26 +43,39 @@ class EditAutofillForm {
 
   setDefaultSelectedOptionByValue(select, value) {
     for (let option of select.options) {
       option.defaultSelected = option.value == value;
     }
   }
 
   /**
-   * Get inputs from the form.
+   * Get a record from the form suitable for a save/update in storage.
    * @returns {object}
    */
   buildFormObject() {
+    let initialObject = {};
+    if (this.hasMailingAddressFields) {
+      // Start with an empty string for each mailing-address field so that any
+      // fields hidden for the current country are blanked in the return value.
+      initialObject = {
+        "street-address": "",
+        "address-level3": "",
+        "address-level2": "",
+        "address-level1": "",
+        "postal-code": "",
+      };
+    }
+
     return Array.from(this._elements.form.elements).reduce((obj, input) => {
       if (!input.disabled) {
         obj[input.id] = input.value;
       }
       return obj;
-    }, {});
+    }, initialObject);
   }
 
   /**
    * Handle events
    *
    * @param  {DOMEvent} event
    */
   handleEvent(event) {
@@ -153,16 +166,21 @@ class EditAddress extends EditAutofillFo
       record = {
         country: this.DEFAULT_REGION,
       };
     }
     super.loadRecord(record);
     this.formatForm(record.country);
   }
 
+  get hasMailingAddressFields() {
+    let {addressFields} = this._elements.form.dataset;
+    return !addressFields || addressFields.trim().split(/\s+/).includes("mailing-address");
+  }
+
   /**
    * `mailing-address` is a special attribute token to indicate mailing fields + country.
    *
    * @param {object[]} mailingFieldsOrder - `fieldsOrder` from `getFormFormat`
    * @param {string} addressFields - white-space-separated string of requested address fields to show
    * @returns {object[]} in the same structure as `mailingFieldsOrder` but including non-mail fields
    */
   static computeVisibleFields(mailingFieldsOrder, addressFields) {
@@ -234,17 +252,21 @@ class EditAddress extends EditAutofillFo
 
   /**
    * Update address field visibility and order based on libaddressinput data.
    *
    * @param {object[]} fieldsOrder array of objects with `fieldId` and optional `newLine` properties
    * @param {Set} requiredFields Set of `fieldId` strings that mark which fields are required
    */
   arrangeFields(fieldsOrder, requiredFields) {
+    /**
+     * @see FormAutofillStorage.VALID_ADDRESS_FIELDS
+     */
     let fields = [
+      // `name` is a wrapper for the 3 name fields.
       "name",
       "organization",
       "street-address",
       "address-level3",
       "address-level2",
       "address-level1",
       "postal-code",
       "country",