Bug 1482220 - Listen for the autofill edit forms being appended for localization. r=sfoster
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 22 Aug 2018 02:58:38 +0000
changeset 487838 865339e90f1ab9115c447c86205c7105bf155e89
parent 487837 4fca1f7a874da0e7824d4337c40f96462d5f1c03
child 487839 38ad1cc1b0c8804267e83d94940f17252fd26ce8
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfoster
bugs1482220
milestone63.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 1482220 - Listen for the autofill edit forms being appended for localization. r=sfoster Differential Revision: https://phabricator.services.mozilla.com/D3846
browser/components/payments/test/browser/browser_show_dialog.js
browser/extensions/formautofill/content/l10n.js
--- a/browser/components/payments/test/browser/browser_show_dialog.js
+++ b/browser/components/payments/test/browser/browser_show_dialog.js
@@ -157,8 +157,48 @@ add_task(async function test_show_closeR
     await BrowserTestUtils.waitForCondition(() => win.closed, "dialog should be closed");
 
     let result = await ContentTask.spawn(browser, null, async () => content.rqResult);
     ok(result.showException, "Expected promise rejection from the rq.show() promise");
     ok(!result.response,
        "rq.show() shouldn't resolve to a response");
   });
 });
+
+add_task(async function test_localized() {
+  await BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: BLANK_PAGE_URL,
+  }, async browser => {
+    let {win, frame} =
+      await setupPaymentDialog(browser, {
+        methodData,
+        details,
+        merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
+      }
+    );
+
+    await spawnPaymentDialogTask(frame, async function check_l10n() {
+      await ContentTaskUtils.waitForCondition(() => {
+        let telephoneLabel = content.document.querySelector("#tel-container > .label-text");
+        return telephoneLabel && telephoneLabel.textContent.includes("Phone");
+      }, "Check that the telephone number label is localized");
+
+      await ContentTaskUtils.waitForCondition(() => {
+        let ccNumberField = content.document.querySelector("#cc-number");
+        if (!ccNumberField) {
+          return false;
+        }
+        let ccNumberLabel = ccNumberField.parentElement.querySelector(".label-text");
+        return ccNumberLabel.textContent.includes("Number");
+      }, "Check that the cc-number label is localized");
+
+      const L10N_ATTRIBUTE_SELECTOR = "[data-localization], [data-localization-region]";
+      await ContentTaskUtils.waitForCondition(() => {
+        return content.document.querySelectorAll(L10N_ATTRIBUTE_SELECTOR).length === 0;
+      }, "Check that there are no unlocalized strings");
+    });
+
+    // abort the payment request
+    ContentTask.spawn(browser, null, async () => content.rq.abort());
+    await BrowserTestUtils.waitForCondition(() => win.closed, "dialog should be closed");
+  });
+});
--- a/browser/extensions/formautofill/content/l10n.js
+++ b/browser/extensions/formautofill/content/l10n.js
@@ -20,22 +20,38 @@ const L10N_ATTRIBUTES = ["data-localizat
 
 // eslint-disable-next-line mozilla/balanced-listeners
 CONTENT_WIN.addEventListener("DOMContentLoaded", function onDCL(evt) {
   let doc = evt.target;
   FormAutofillUtils.localizeMarkup(doc);
 
   let mutationObserver = new doc.ownerGlobal.MutationObserver(function onMutation(mutations) {
     for (let mutation of mutations) {
-      if (!mutation.target.hasAttribute(mutation.attributeName)) {
-        // The attribute was removed in the meantime.
-        continue;
+      switch (mutation.type) {
+        case "attributes": {
+          if (!mutation.target.hasAttribute(mutation.attributeName)) {
+            // The attribute was removed in the meantime.
+            continue;
+          }
+          FormAutofillUtils.localizeAttributeForElement(mutation.target, mutation.attributeName);
+          break;
+        }
+
+        case "childList": {
+          // We really only care about the <form>s appending inside pages.
+          if (!mutation.addedNodes || !mutation.target.classList ||
+              !mutation.target.classList.contains("page")) {
+            break;
+          }
+          FormAutofillUtils.localizeMarkup(mutation.target);
+          break;
+        }
       }
-      FormAutofillUtils.localizeAttributeForElement(mutation.target, mutation.attributeName);
     }
   });
 
   mutationObserver.observe(doc, {
     attributes: true,
     attributeFilter: L10N_ATTRIBUTES,
+    childList: true,
     subtree: true,
   });
 });