Backed out changeset 8641e30ebaf4 (bug 1435871) for multiple browser-chrome failures on payments. CLOSED TREE
authorBrindusan Cristian <cbrindusan@mozilla.com>
Fri, 19 Oct 2018 14:58:11 +0300
changeset 500541 1030155f208e08a4a4673655c8b6b343c1b920a1
parent 500540 ad81b437f8604c61701ae3a3112b8490577308eb
child 500578 18859d2fec94f35e924e9093a99169623e0b2d78
child 500606 295644de04d2b1abbccd102473cbf3023dfce21a
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1435871
milestone64.0a1
backs out8641e30ebaf4bc3c719d6e0cacbd5b4ac6c0f980
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
Backed out changeset 8641e30ebaf4 (bug 1435871) for multiple browser-chrome failures on payments. CLOSED TREE
browser/components/payments/paymentUIService.js
browser/components/payments/test/PaymentTestUtils.jsm
browser/components/payments/test/browser/browser_show_dialog.js
--- a/browser/components/payments/paymentUIService.js
+++ b/browser/components/payments/paymentUIService.js
@@ -27,25 +27,39 @@ function PaymentUIService() {
   this.wrappedJSObject = this;
   XPCOMUtils.defineLazyGetter(this, "log", () => {
     let {ConsoleAPI} = ChromeUtils.import("resource://gre/modules/Console.jsm", {});
     return new ConsoleAPI({
       maxLogLevelPref: "dom.payments.loglevel",
       prefix: "Payment UI Service",
     });
   });
+  Services.wm.addListener(this);
   this.log.debug("constructor");
 }
 
 PaymentUIService.prototype = {
   classID: Components.ID("{01f8bd55-9017-438b-85ec-7c15d2b35cdc}"),
   QueryInterface: ChromeUtils.generateQI([Ci.nsIPaymentUIService]),
   DIALOG_URL: "chrome://payments/content/paymentDialogWrapper.xul",
   REQUEST_ID_PREFIX: "paymentRequest-",
 
+  // nsIWindowMediatorListener implementation:
+
+  onOpenWindow(aWindow) {},
+  onCloseWindow(aWindow) {
+    let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
+    let requestId = this.requestIdForWindow(domWindow);
+    if (!requestId || !paymentSrv.getPaymentRequestById(requestId)) {
+      return;
+    }
+    this.log.debug(`onCloseWindow, close of window for active requestId: ${requestId}`);
+    this.rejectPaymentForClosedDialog(requestId);
+  },
+
   // nsIPaymentUIService implementation:
 
   showPayment(requestId) {
     this.log.debug("showPayment:", requestId);
     let chromeWindow = Services.wm.getMostRecentWindow("navigator:browser");
     chromeWindow.openDialog(`${this.DIALOG_URL}?requestId=${requestId}`,
                             `${this.REQUEST_ID_PREFIX}${requestId}`,
                             "modal,dialog,centerscreen,resizable=no");
@@ -62,16 +76,30 @@ PaymentUIService.prototype = {
     let response = found ?
       Ci.nsIPaymentActionResponse.ABORT_SUCCEEDED :
       Ci.nsIPaymentActionResponse.ABORT_FAILED;
 
     abortResponse.init(requestId, response);
     paymentSrv.respondPayment(abortResponse);
   },
 
+  rejectPaymentForClosedDialog(requestId) {
+    this.log.debug("rejectPaymentForClosedDialog:", requestId);
+    const rejectResponse = Cc["@mozilla.org/dom/payments/payment-show-action-response;1"]
+                            .createInstance(Ci.nsIPaymentShowActionResponse);
+    rejectResponse.init(requestId,
+                        Ci.nsIPaymentActionResponse.PAYMENT_REJECTED,
+                        "", // payment method
+                        null, // payment method data
+                        "", // payer name
+                        "", // payer email
+                        "");// payer phone
+    paymentSrv.respondPayment(rejectResponse);
+  },
+
   completePayment(requestId) {
     // completeStatus should be one of "timeout", "success", "fail", ""
     let {completeStatus} = paymentSrv.getPaymentRequestById(requestId);
     this.log.debug(`completePayment: requestId: ${requestId}, completeStatus: ${completeStatus}`);
 
     let closed;
     switch (completeStatus) {
       case "fail":
--- a/browser/components/payments/test/PaymentTestUtils.jsm
+++ b/browser/components/payments/test/PaymentTestUtils.jsm
@@ -117,16 +117,29 @@ var PaymentTestUtils = {
       const rq = new content.PaymentRequest(Cu.cloneInto(methodData, content), details, options);
       content.rq = rq; // assign it so we can retrieve it later
 
       const handle = content.windowUtils.setHandlingUserInput(true);
       content.showPromise = rq.show();
 
       handle.destruct();
     },
+
+    /**
+     * Add a rejection handler for the `showPromise` created by createAndShowRequest
+     * and stash details of any eventual exception or response in `rqResult`
+     */
+    catchShowPromiseRejection: () => {
+      content.rqResult = {};
+      content.showPromise.then(res => content.rqResult.response = res)
+                         .catch(ex => content.rqResult.showException = {
+                           name: ex.name,
+                           message: ex.message,
+                         });
+    },
   },
 
   DialogContentTasks: {
     getShippingOptions: () => {
       let picker = content.document.querySelector("shipping-option-picker");
       let popupBox = Cu.waiveXrays(picker).dropdown.popupBox;
       let selectedOptionIndex = popupBox.selectedIndex;
       let selectedOption = Cu.waiveXrays(picker).dropdown.selectedOption;
--- a/browser/components/payments/test/browser/browser_show_dialog.js
+++ b/browser/components/payments/test/browser/browser_show_dialog.js
@@ -138,16 +138,41 @@ add_task(async function test_show_comple
     let result = await ContentTask.spawn(browser, {}, PTU.ContentTasks.addCompletionHandler);
 
     is(result.response.shippingOption, "1", "Check shipping option");
 
     await BrowserTestUtils.waitForCondition(() => win.closed, "dialog should be closed");
   });
 });
 
+add_task(async function test_show_closeReject_dialog() {
+  await BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: BLANK_PAGE_URL,
+  }, async browser => {
+    let {win} =
+      await setupPaymentDialog(browser, {
+        methodData,
+        details,
+        merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
+      }
+    );
+    await ContentTask.spawn(browser, null, PTU.ContentTasks.catchShowPromiseRejection);
+
+    info("Closing the dialog to reject the payment request");
+    BrowserTestUtils.closeWindow(win);
+    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,