Bug 1501823 - mochitest update for bug 1501823. r=baku
authorEden Chuang <echuang@mozilla.com>
Wed, 21 Nov 2018 11:17:45 +0100
changeset 504101 90a1e84edaa0bd93e949ae797bec18efa2419d76
parent 504100 9671513ce7e7f7eaa22553fadb8e32c53dcc4686
child 504102 176131b18cb4691f1b7e1b1c3d88534815c73b88
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1501823
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 1501823 - mochitest update for bug 1501823. r=baku
dom/payments/test/ShowPaymentChromeScript.js
dom/payments/test/test_showPayment.html
--- a/dom/payments/test/ShowPaymentChromeScript.js
+++ b/dom/payments/test/ShowPaymentChromeScript.js
@@ -1,25 +1,22 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 "use strict";
 
 const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 const paymentSrv = Cc["@mozilla.org/dom/payments/payment-request-service;1"].getService(Ci.nsIPaymentRequestService);
-let expectedCompleteStatus = null;
-let expectedShowAction = "accept";
-let expectedUpdateAction = "accept";
 
 function emitTestFail(message) {
-  sendAsyncMessage("test-fail", message);
+  sendAsyncMessage("test-fail", `${DummyUIService.testName}: ${message}`);
 }
 function emitTestPass(message) {
-  sendAsyncMessage("test-pass", message);
+  sendAsyncMessage("test-pass", `${DummyUIService.testName}: ${message}`);
 }
 
 const shippingAddress = Cc["@mozilla.org/dom/payments/payment-address;1"].
                            createInstance(Ci.nsIPaymentAddress);
 const addressLine = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
 const address = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
 address.data = "Easton Ave";
 addressLine.appendElement(address);
@@ -63,94 +60,106 @@ function rejectShow(requestId) {
                     responseData,       // payment method data
                     "",                 // payer name
                     "",                 // payer email
                     "");                // payer phone
   paymentSrv.respondPayment(showResponse.QueryInterface(Ci.nsIPaymentActionResponse));
 }
 
 function updateShow(requestId) {
-  if (expectedUpdateAction == "updateaddress") {
+  if (DummyUIService.expectedUpdateAction == "updateaddress") {
     paymentSrv.changeShippingAddress(requestId, shippingAddress);
-  } else if (expectedUpdateAction == "accept" || expectedUpdateAction == "error"){
+  } else if (DummyUIService.expectedUpdateAction == "accept" ||
+             DummyUIService.expectedUpdateAction == "error"){
     paymentSrv.changeShippingOption(requestId, "FastShipping");
   } else {
-    emitTestFail("Unknown expected update action: " + expectedUpdateAction);
+    emitTestFail("Unknown expected update action: " + DummyUIService.expectedUpdateAction);
   }
 }
 
 function showRequest(requestId) {
-  if (expectedShowAction == "accept") {
+  const request = paymentSrv.getPaymentRequestById(requestId);
+  if (request.completeStatus == "initial") {
+    return;
+  }
+  if (DummyUIService.expectedShowAction == "accept") {
     acceptShow(requestId);
-  } else if (expectedShowAction == "reject") {
+  } else if (DummyUIService.expectedShowAction == "reject") {
     rejectShow(requestId);
-  } else if (expectedShowAction == "update") {
+  } else if (DummyUIService.expectedShowAction == "update") {
     updateShow(requestId);
   } else {
-    emitTestFail("Unknown expected show action: " + expectedShowAction);
+    emitTestFail("Unknown expected show action: " + DummyUIService.expectedShowAction);
   }
 }
 
 function abortRequest(requestId) {
   let abortResponse = Cc["@mozilla.org/dom/payments/payment-abort-action-response;1"].
                          createInstance(Ci.nsIPaymentAbortActionResponse);
   abortResponse.init(requestId, Ci.nsIPaymentActionResponse.ABORT_SUCCEEDED);
   paymentSrv.respondPayment(abortResponse);
 }
 
 function completeRequest(requestId) {
-  let payRequest = paymentSrv.getPaymentRequestById(requestId);
-  if (expectedCompleteStatus) {
-    if (payRequest.completeStatus == expectedCompleteStatus) {
+  let request = paymentSrv.getPaymentRequestById(requestId);
+  if (DummyUIService.expectedCompleteStatus) {
+    if (request.completeStatus == DummyUIService.expectedCompleteStatus) {
       emitTestPass("request.completeStatus matches expectation of " +
-                   expectedCompleteStatus);
+                   DummyUIService.expectedCompleteStatus);
     } else {
       emitTestFail("request.completeStatus incorrect. Expected " +
-                   expectedCompleteStatus + ", got " + payRequest.completeStatus);
+                   DummyUIService.expectedCompleteStatus + ", got " + request.completeStatus);
     }
   }
   let completeResponse = Cc["@mozilla.org/dom/payments/payment-complete-action-response;1"].
                             createInstance(Ci.nsIPaymentCompleteActionResponse);
   completeResponse.init(requestId, Ci.nsIPaymentActionResponse.COMPLETE_SUCCEEDED);
   paymentSrv.respondPayment(completeResponse.QueryInterface(Ci.nsIPaymentActionResponse));
 }
 
 function updateRequest(requestId) {
   let request = paymentSrv.getPaymentRequestById(requestId);
-  if (expectedUpdateAction == "accept") {
+  if (request.completeStatus !== "") {
+    emitTestFail("request.completeStatus should be empty, but got '" + request.completeStatus + "'.");
+  }
+  if (DummyUIService.expectedUpdateAction == "accept") {
     if (request.paymentDetails.error != "") {
       emitTestFail("updatedDetails should not have errors(" + request.paymentDetails.error + ").");
     }
     const shippingOptions = request.paymentDetails.shippingOptions;
     let shippingOption = shippingOptions.queryElementAt(0, Ci.nsIPaymentShippingOption);
     if (shippingOption.selected) {
       emitTestFail(shippingOption.label + " should not be selected.");
     }
     shippingOption = shippingOptions.queryElementAt(1, Ci.nsIPaymentShippingOption);
     if (!shippingOption.selected) {
       emitTestFail(shippingOption.label + " should be selected.");
     }
     acceptShow(requestId);
-  } else if (expectedUpdateAction == "error") {
+  } else if (DummyUIService.expectedUpdateAction == "error") {
     if (request.paymentDetails.error != "Update with Error") {
       emitTestFail("details.error should be 'Update with Error', but got " + request.paymentDetails.error + ".");
     }
     rejectShow(requestId);
-  } else if (expectedUpdateAction == "updateaddress") {
+  } else if (DummyUIService.expectedUpdateAction == "updateaddress") {
     if (request.paymentDetails.error != "") {
       emitTestFail("updatedDetails should not have errors(" + request.paymentDetails.error + ").");
     }
-    expectedUpdateAction = "accept";
+    DummyUIService.expectedUpdateAction = "accept";
     paymentSrv.changeShippingOption(requestId, "FastShipping");
   } else {
-    emitTestFail("Unknown expected update aciton: " + expectedUpdateAction);
+    emitTestFail("Unknown expected update aciton: " + DummyUIService.expectedUpdateAction);
   }
 }
 
 const DummyUIService = {
+  testName: "",
+  expectedCompleteStatus: null,
+  expectedShowAction: "accept",
+  expectedUpdateAction: "accept",
   showPayment: showRequest,
   abortPayment: abortRequest,
   completePayment: completeRequest,
   updatePayment: updateRequest,
   closePayment: function(requestId) {},
   QueryInterface: ChromeUtils.generateQI([Ci.nsIPaymentUIService]),
 };
 
@@ -209,56 +218,69 @@ function testShowResponseInit() {
     if (e.name != "NS_ERROR_ILLEGAL_VALUE") {
       emitTestFail("Expected 'NS_ERROR_ILLEGAL_VALUE', but got " + e.name + ".");
     }
     emitTestPass("Get expected result for initializing response with accepted and null data.")
   }
   sendAsyncMessage("test-show-response-init-complete");
 }
 
-addMessageListener("set-simple-ui-service", function() {
-  expectedCompleteStatus = null;
-  expectedShowAction = "accept";
-  expectedUpdateAction = "accept";
+addMessageListener("set-simple-ui-service", function(testName) {
+  DummyUIService.testName = testName;
+  DummyUIService.expectedCompleteStatus = null;
+  DummyUIService.expectedShowAction = "accept";
+  DummyUIService.expectedUpdateAction = "accept";
+  sendAsyncMessage("set-simple-ui-service-complete");
 });
 
-addMessageListener("set-normal-ui-service", function() {
-  expectedCompleteStatus = null;
-  expectedShowAction = "update";
-  expectedUpdateAction = "updateaddress";
+addMessageListener("set-normal-ui-service", function(testName) {
+  DummyUIService.testName = testName;
+  DummyUIService.expectedCompleteStatus = null;
+  DummyUIService.expectedShowAction = "update";
+  DummyUIService.expectedUpdateAction = "updateaddress";
+  sendAsyncMessage("set-normal-ui-service-complete");
 });
 
-addMessageListener("set-reject-ui-service", function() {
-  expectedCompleteStatus = null;
-  expectedShowAction = "reject";
-  expectedUpdateAction = "accept";
+addMessageListener("set-reject-ui-service", function(testName) {
+  DummyUIService.testName = testName;
+  DummyUIService.expectedCompleteStatus = null;
+  DummyUIService.expectedShowAction = "reject";
+  DummyUIService.expectedUpdateAction = "error";
+  sendAsyncMessage("set-reject-ui-service-complete");
 });
 
-addMessageListener("set-update-with-ui-service", function() {
-  expectedCompleteStatus = null;
-  expectedShowAction = "update";
-  expectedUpdateAction = "accept";
+addMessageListener("set-update-with-ui-service", function(testName) {
+  DummyUIService.testName = testName;
+  DummyUIService.expectedCompleteStatus = null;
+  DummyUIService.expectedShowAction = "update";
+  DummyUIService.expectedUpdateAction = "accept";
+  sendAsyncMessage("set-update-with-ui-service-complete");
 });
 
-addMessageListener("set-update-with-error-ui-service", function() {
-  expectedCompleteStatus = null;
-  expectedShowAction = "update";
-  expectedUpdateAction = "error";
+addMessageListener("set-update-with-error-ui-service", function(testName) {
+  DummyUIService.testName = testName;
+  DummyUIService.expectedCompleteStatus = null;
+  DummyUIService.expectedShowAction = "update";
+  DummyUIService.expectedUpdateAction = "error";
+  sendAsyncMessage("set-update-with-error-ui-service-complete");
 });
 
 addMessageListener("test-show-response-init", testShowResponseInit);
 
 addMessageListener("set-complete-status-success", function() {
-  expectedCompleteStatus = "success";
+  DummyUIService.expectedCompleteStatus = "success";
+  sendAsyncMessage("set-complete-status-success-complete");
 });
 
 addMessageListener("set-complete-status-fail", function() {
-  expectedCompleteStatus = "fail";
+  DummyUIService.expectedCompleteStatus = "fail";
+  sendAsyncMessage("set-complete-status-fail-complete");
 });
 
 addMessageListener("set-complete-status-unknown", function() {
-  expectedCompleteStatus = "unknown";
+  DummyUIService.expectedCompleteStatus = "unknown";
+  sendAsyncMessage("set-complete-status-unknown-complete");
 });
 
 addMessageListener("teardown", function() {
   paymentSrv.setTestingUIService(null);
   sendAsyncMessage('teardown-complete');
 });
--- a/dom/payments/test/test_showPayment.html
+++ b/dom/payments/test/test_showPayment.html
@@ -20,16 +20,26 @@ https://bugzilla.mozilla.org/show_bug.cg
     ok(false, message);
   }
   function testPassHandler(message) {
     ok(true, message);
   }
   gScript.addMessageListener("test-fail", testFailHandler);
   gScript.addMessageListener("test-pass", testPassHandler);
 
+  async function requestChromeAction(action, params) {
+    await new Promise(resolve => {
+      gScript.addMessageListener(`${action}-complete`, function completeListener() {
+        gScript.removeMessageListener(`${action}-complete`, completeListener);
+        resolve();
+      });
+      gScript.sendAsyncMessage(action, params);
+    });
+  }
+
   // testing data declaration
   // default parameters for PaymentRequest construction
   const defaultMethods = [{
     supportedMethods: "basic-card",
     data: {
       supportedNetworks: ['unionpay', 'visa', 'mastercard', 'amex', 'discover',
                           'diners', 'jcb', 'mir',
       ],
@@ -122,348 +132,381 @@ https://bugzilla.mozilla.org/show_bug.cg
 
   // testing data for PaymentRequest.show() with Non-supported methods
   const nonSupportedMethods = [{
     supportedMethods: "nonsupported-method",
   }];
 
 
   // checking functions
-  function checkAddress(address, fromEvent) {
-    is(address.country, "USA", "address.country should be 'USA'.");
-    is(address.region, "CA", "address.region should be 'CA'.");
-    is(address.city, "San Bruno", "address.city should be 'San Bruno'.");
-    is(address.dependentLocality, "Test locality",
-       "address.dependentLocality should be 'Test locality'.");
-    is(address.postalCode, "94066", "address.postalCode should be '94066'.");
-    is(address.sortingCode, "123456", "address.sortingCode should be '123456'.");
+  function checkAddress(testName, address, fromEvent) {
+    is(address.country,
+       "USA",
+       `${testName}: address.country should be 'USA'.`);
+    is(address.region,
+       "CA",
+       `${testName}: address.region should be 'CA'.`);
+    is(address.city,
+       "San Bruno",
+       `${testName}: address.city should be 'San Bruno'.`);
+    is(address.dependentLocality,
+       "Test locality",
+       `${testName}: address.dependentLocality should be 'Test locality'.`);
+    is(address.postalCode,
+       "94066",
+       `${testName}: address.postalCode should be '94066'.`);
+    is(address.sortingCode,
+       "123456",
+       `${testName}: address.sortingCode should be '123456'.`);
     if (fromEvent) {
-      is(address.addressLine.length, 0, "address.addressLine.length should be 0 from event.");
-      is(address.organization, "", "address.organization should be empty from event.");
-      is(address.recipient, "", "address.recipient should be empty from event.");
-      is(address.phone, "", "address.phone should be empty from event.");
+      is(address.addressLine.length,
+         0,
+         `${testName}: address.addressLine.length should be 0 from event.`);
+      is(address.organization,
+         "",
+         `${testName}: address.organization should be empty from event.`);
+      is(address.recipient,
+         "",
+         `${testName}: address.recipient should be empty from event.`);
+      is(address.phone,
+         "",
+         `${testName}: address.phone should be empty from event.`);
     } else {
-      is(address.addressLine.length, 1, "address.addressLine.length should be 1 from promise.");
-      is(address.addressLine[0], "Easton Ave", "address.addressLine[0] should be 'Easton Ave' from promise.");
-      is(address.organization, "Testing Org", "address.organization should be 'Testing Org' from promise.");
-      is(address.recipient, "Bill A. Pacheco", "address.recipient should be 'Bill A. Pacheco' from promise.");
-      is(address.phone, "+1-434-441-3879", "address.phone should be '+1-434-441-3879' from promise.");
+      is(address.addressLine.length,
+         1,
+         `${testName}: address.addressLine.length should be 1 from promise.`);
+      is(address.addressLine[0],
+         "Easton Ave",
+         `${testName}: address.addressLine[0] should be 'Easton Ave' from promise.`);
+      is(address.organization,
+         "Testing Org",
+         `${testName}: address.organization should be 'Testing Org' from promise.`);
+      is(address.recipient,
+         "Bill A. Pacheco",
+         `${testName}: address.recipient should be 'Bill A. Pacheco' from promise.`);
+      is(address.phone,
+         "+1-434-441-3879",
+         `${testName}: address.phone should be '+1-434-441-3879' from promise.`);
     }
   }
 
-  function checkResponse(response) {
-    is(response.requestId, "test payment", "response.requestId should be 'test payment'.");
-    is(response.methodName, "testing-payment-method", "response.methodName should be 'testing-payment-method'.");
-    is(response.details.paymentToken, "6880281f-0df3-4b8e-916f-66575e2457c1", "response.details.paymentToken should be '6880281f-0df3-4b8e-916f-66575e2457c1'.");
-    checkAddress(response.shippingAddress, false/*fromEvent*/);
-    is(response.shippingOption, "FastShipping", "response.shippingOption should be 'FastShipping'.");
-    is(response.payerName, "Bill A. Pacheco", "response.payerName should be 'Bill A. Pacheco'.");
-    ok(!response.payerEmail, "response.payerEmail should be empty");
-    ok(!response.payerPhone, "response.payerPhone should be empty");
+  function checkResponse(testName, response) {
+    is(response.requestId,
+       "test payment",
+       `${testName}: response.requestId should be 'test payment'.`);
+    is(response.methodName,
+       "testing-payment-method",
+       `${testName}: response.methodName should be 'testing-payment-method'.`);
+    is(response.details.paymentToken,
+       "6880281f-0df3-4b8e-916f-66575e2457c1",
+       `${testName}: response.details.paymentToken should be '6880281f-0df3-4b8e-916f-66575e2457c1'.`);
+    checkAddress(testName, response.shippingAddress, false/*fromEvent*/);
+    is(response.shippingOption,
+       "FastShipping",
+       `${testName}: response.shippingOption should be 'FastShipping'.`);
+    is(response.payerName,
+       "Bill A. Pacheco",
+       `${testName}: response.payerName should be 'Bill A. Pacheco'.`);
+    ok(!response.payerEmail,
+       `${testName}: response.payerEmail should be empty`);
+    ok(!response.payerPhone,
+       `${testName}: response.payerPhone should be empty`);
   }
 
   // testing functions
-  function testShowNormalFlow() {
-    gScript.sendAsyncMessage("set-normal-ui-service");
-    return new Promise((resolve, reject) => {
-      const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
-      payRequest.addEventListener("shippingaddresschange", event => {
-        checkAddress(payRequest.shippingAddress, true/*fromEvent*/);
+  async function testShowNormalFlow() {
+    const testName = "testShowNormalFlow";
+    await requestChromeAction("set-normal-ui-service", testName);
+    return new Promise(async (resolve) => {
+      const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
+      request.addEventListener("shippingaddresschange", event => {
+        checkAddress(testName, request.shippingAddress, true/*fromEvent*/);
         event.updateWith(updateWithPromise(defaultDetails));
       });
-      payRequest.addEventListener("shippingoptionchange", event => {
+      request.addEventListener("shippingoptionchange", event => {
         event.updateWith(updateWithPromise(updatedShippingOptionsDetails));
       });
       const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
-      payRequest.show().then(response => {
-        checkResponse(response, false);
-	checkAddress(payRequest.shippingAddress, false);
-        response.complete().then(() =>{
-          resolve();
-        }).catch(e => {
-          ok(false, "Unexpected error: " + e.name);
-          resolve();
-        });
-      }).catch( e => {
-        ok(false, "Unexpected error: " + e.name);
-        resolve();
-      }).finally(handler.destruct);
+      try {
+        let response = await request.show();
+        checkResponse(testName, response, false);
+        await response.complete();
+      } catch (error) {
+        ok(false, `${testName} Unexpected error: ${e.name}`);
+      }
+      await handler.destruct();
+      resolve();
     });
   }
 
   // testing show with nonsupported methods
-  function testCannotMakePaymentShow() {
-    gScript.sendAsyncMessage("set-simple-ui-service");
-    return new Promise((resolve, reject) => {
-      const payRequest = new PaymentRequest(nonSupportedMethods, defaultDetails);
+  async function testCannotMakePaymentShow() {
+    const testName = "testCannotMakePaymentShow";
+    await requestChromeAction("set-simple-ui-service", testName);
+    return new Promise(async (resolve) => {
+      const request = new PaymentRequest(nonSupportedMethods, defaultDetails);
       const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
-      payRequest.canMakePayment().then(result => {
-        ok(!result, "canMakePayment() should return false, but got " + result + ".");
-        payRequest.show().then( () => {
-          ok(false, "Should be rejected with 'NotSupportedError', but got resolved");
-          resolve();
-        }).catch( e => {
-          is(e.name, "NotSupportedError", "Should be rejected with 'NotSupportedError', but got " + e.name + ".");
-          resolve();
-        });
-      }).finally(handler.destruct);
+      let result = await request.canMakePayment();
+      ok(!result, `${testName}: canMakePayment() should return false.`);
+      try {
+        await request.show();
+        ok(false, `${testName}: should be rejected with 'NotSupportedError' but got resolved.`);
+      } catch (error) {
+        is(error.name, "NotSupportedError", `${testName}: should be rejected with 'NotSupportedError'.`);
+      }
+      await handler.destruct();
+      resolve();
     });
   }
 
   // testing show rejected by user
-  function testRejectShow() {
-    gScript.sendAsyncMessage("set-reject-ui-service");
-    return new Promise((resolve, reject) => {
-      const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
+  async function testRejectShow() {
+    const testName = "testRejectShow";
+    await requestChromeAction("set-reject-ui-service", testName);
+    return new Promise(async(resolve) => {
+      const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
       const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
-      payRequest.show().then((result) => {
-        ok(false, "Should be rejected with 'AbortError', but got resolved");
-        resolve();
-      }, (result) => {
-        is(result.name, "AbortError", "Should be rejected with 'AbortError', but got " + result.name + ".");
-        resolve();
-      }).catch(e => {
-        ok(false, "Unexpected error: " + e.name);
-        resolve();
-      }).finally(handler.destruct);
+      try {
+        await request.show();
+        ok(false, `${testName}: Should be rejected with 'AbortError' but got resolved.`);
+      } catch(error) {
+        is(error.name, "AbortError", `${testName}: Should be rejected with 'AbortError'.`);
+      }
+      await handler.destruct();
+      resolve();
     });
   }
 
   // testing PaymentResponse.complete() with specified result
-  function testCompleteStatus(result) {
-    gScript.sendAsyncMessage("set-simple-ui-service");
+  async function testCompleteStatus(testName, result) {
+    await requestChromeAction("set-simple-ui-service", testName);
     if (result) {
-      gScript.sendAsyncMessage("set-complete-status-"+result);
+      await requestChromeAction(`set-complete-status-${result}`);
     } else {
-      gScript.sendAsyncMessage("set-complete-status-unknown");
+      await requestChromeAction(`set-complete-status-unknown`);
     }
-    return new Promise((resolve, reject) => {
-      const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
+    return new Promise(async (resolve) => {
+      const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
       const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
-      payRequest.show().then(response => {
-        response.complete(result).then(() => {
-          resolve();
-        }).catch(e => {
-          ok(false, "Unexpected error: " + e.name);
-          resolve();
-        });
-      }).catch( e => {
-        ok(false, "Unexpected error: " + e.name);
-        resolve();
-      }).finally(handler.destruct);
+      try {
+        let response = await request.show();
+        await response.complete(result);
+      } catch (error) {
+        ok(false, `${testName}: Unexpected error ${error.name}.`);
+      }
+      await handler.destruct();
+      resolve();
     });
   }
 
-  function testCompleteFail() {
-    return testCompleteStatus("fail");
+  async function testCompleteFail() {
+    const testName = "testCompleteFail";
+    return testCompleteStatus(testName, "fail");
   }
 
-  function testCompleteSuccess() {
-    return testCompleteStatus("success");
+  async function testCompleteSuccess() {
+    const testName = "testCompleteSuccess";
+    return testCompleteStatus(testName, "success");
   }
 
-  function testCompleteUnknown() {
-    return testCompleteStatus("unknown");
+  async function testCompleteUnknown() {
+    const testName = "testCompleteUnknown"
+    return testCompleteStatus(testName, "unknown");
   }
 
-  function testCompleteEmpty() {
-    return testCompleteStatus();
+  async function testCompleteEmpty() {
+    const testName = "testCompleteEmpty";
+    return testCompleteStatus(testName);
   }
 
   // testing PaymentRequestUpdateEvent.updateWith with specified details and error
-  function testUpdateWith(detailsUpdate, expectedError) {
+  async function testUpdateWith(testName, detailsUpdate, expectedError) {
     if (expectedError) {
-      gScript.sendAsyncMessage("set-update-with-error-ui-service");
+      await requestChromeAction("set-update-with-error-ui-service", testName);
     } else {
-      gScript.sendAsyncMessage("set-update-with-ui-service");
+      await requestChromeAction("set-update-with-ui-service", testName);
     }
-    return new Promise((resolve, reject) => {
-      const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
-      payRequest.addEventListener("shippingaddresschange", event => {
+    return new Promise(async (resolve) => {
+      const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
+      request.addEventListener("shippingaddresschange", event => {
         event.updateWith(updateWithPromise(detailsUpdate));
       });
-      payRequest.addEventListener("shippingoptionchange", event => {
+      request.addEventListener("shippingoptionchange", event => {
         event.updateWith(updateWithPromise(detailsUpdate));
       });
       const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
-      payRequest.show().then(response => {
-        if (expectedError) {
-          ok(false, "Should be rejected with " + expectedError + ", but got resolved");
-	  resolve();
-	} else {
-	  response.complete("success").then(() => {
-	    resolve();
-	  })
-	}
-      }, response => {
+      try {
+        const response = await request.show();
         if (expectedError) {
-          is(response.name, expectedError,
-	     "Should be rejected with " + expectedError + ", but got " + response.name);
-	} else {
-	  ok(false, "Unexpected error: " + response.name);
-	}
-	resolve();
-      }).catch(e => {
-        ok(false, "Unexpected error: " + e.name);
-	resolve();
-      }).finally(handler.destruct);
+          ok(false, `${testName}: Should be rejected with ${expectedError} but got resolved.`);
+        } else {
+          await response.complete("success");
+        }
+      } catch(error) {
+        if (expectedError) {
+          is(error.name, expectedError, `${testName}: Should be rejected with ${expectedError}.`);
+        } else {
+          ok(false, `${testName}: Unexpected error ${error.name}.`);
+        }
+      }
+      await handler.destruct();
+      resolve();
     });
   }
 
-  function testUpdateWithReject() {
-    return testUpdateWith(null, "AbortError");
+  async function testUpdateWithReject() {
+    const testName = "testUpdateWithReject";
+    return testUpdateWith(testName, null, "AbortError");
   }
 
-  function testUpdateWithValidDetails() {
-    return testUpdateWith(updatedShippingOptionsDetails, null);
+  async function testUpdateWithValidDetails() {
+    const testName = "testUpdateWithValidDetails";
+    return testUpdateWith(testName, updatedShippingOptionsDetails, null);
   }
 
-  function testUpdateWithInvalidDetails() {
-    return testUpdateWith({total: "invalid details"}, "TypeError");
+  async function testUpdateWithInvalidDetails() {
+    const testName = "testUpdateWithInvalidDetails";
+    return testUpdateWith(testName, {total: "invalid details"}, "TypeError");
   }
 
-  function testUpdateWithError() {
-    return testUpdateWith(updatedErrorDetails, "AbortError");
+  async function testUpdateWithError() {
+    const testName = "testUpdateWithError";
+    return testUpdateWith(testName, updatedErrorDetails, "AbortError");
   }
 
   // testing show with detailsUpdate promise
-  function testShowWithDetailsPromise(detailsUpdate, expectedError) {
+  async function testShowWithDetailsPromise(testName, detailsUpdate, expectedError) {
     if (expectedError) {
-      gScript.sendAsyncMessage("set-reject-ui-service");
+      await requestChromeAction("set-reject-ui-service", testName);
     } else {
-      gScript.sendAsyncMessage("set-simple-ui-service");
+      await requestChromeAction("set-simple-ui-service", testName);
     }
-    return new Promise((resolve, reject) => {
-      const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
-      ok(!payRequest.shippingOption, "payRequest.shippingOption should be null.");
+    return new Promise(async (resolve) => {
+      const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
+      ok(!request.shippingOption, `${testName}: request.shippingOption should be null.`);
       const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
-      payRequest.show(updateWithPromise(detailsUpdate)).then(response => {
+      try {
+        let response = await request.show(updateWithPromise(detailsUpdate));
         if (expectedError) {
-          ok(false, "Should be rejected with " + expectedError + ", but got resolved");
-	  resolve();
-	} else {
-          ok(response.shippingOption, "response.shippingOption should not be null.");
-	  response.complete().then(() => {
-	    resolve();
-	  })
-	}
-      }, response => {
+          ok(false, `${testName}: Should be rejected with ${expectedError} but got resolved.`);
+        } else {
+          ok(response.shippingOption,
+             `${testName}: response.shippingOption should not be null.`);
+        }
+        await response.complete();
+      } catch(error) {
         if (expectedError) {
-          is(response.name, expectedError,
-	     "Should be rejected with " + expectedError + ", but got " + response.name);
-	} else {
-	  ok(false, "Unexpected error: " + response.name);
-	}
-	resolve();
-      }).catch(e => {
-        ok(false, "Unexpected error: " + e.name);
-	resolve();
-      }).finally(handler.destruct);
+          is(error.name, expectedError, `${testName}: Should be rejected with ${expectedError}.`);
+        } else {
+          ok(false, `${testName}: Unexpected error ${error.name}.`);
+        }
+      }
+      await handler.destruct();
+      resolve();
     });
   }
-  function testShowWithValidPromise() {
-    return testShowWithDetailsPromise(updatedShippingOptionsDetails, null);
+  async function testShowWithValidPromise() {
+    const testName = "testShowWithValidPromise";
+    return testShowWithDetailsPromise(testName, updatedShippingOptionsDetails, null);
   }
 
-  function testShowWithRejectedPromise() {
-    return testShowWithDetailsPromise(null, "AbortError");
+  async function testShowWithRejectedPromise() {
+    const testName = "testShowWithRejectedPromise";
+    return testShowWithDetailsPromise(testName, null, "AbortError");
   }
 
-  function testShowWithInvalidPromise() {
-    return testShowWithDetailsPromise({total: "invalid details"}, "TypeError");
+  async function testShowWithInvalidPromise() {
+    const testName = "testShowWithInvalidPromise";
+    return testShowWithDetailsPromise(testName, {total: "invalid details"}, "TypeError");
   }
 
-  function testShowWithErrorPromise() {
-    return testShowWithDetailsPromise(updatedErrorDetails, "AbortError");
+  async function testShowWithErrorPromise() {
+    const testName = "testShowWithErrorPromise";
+    return testShowWithDetailsPromise(testName, updatedErrorDetails, "AbortError");
   }
 
-  function testShowWithPromiseResolvedByRejectedPromise() {
-    gScript.sendAsyncMessage("set-reject-ui-service");
-    return new Promise((resolve, reject)=> {
+  async function testShowWithPromiseResolvedByRejectedPromise() {
+    const testName = "testShowWithPromiseResolvedByRejectedPromise";
+    await requestChromeAction("set-reject-ui-service", testName);
+    return new Promise(async (resolve)=> {
       const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
       const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
       let rejectPromise = Promise.reject(new TypeError());
       let detailsUpdatePromise = Promise.resolve(rejectPromise);
-      request.show(detailsUpdatePromise).then(response => {
-        ok(false, "should be rejected with 'AbortError', but got resolved.");
-	resolve();
-      }, response => {
-        is(response.name, "AbortError", "Exepcted 'AbortError', but got " + response.name + ".");
-	resolve();
-      }).catch(error => {
-        ok(false, "Unexpected error: " + error.name + ".");
-      }).finally(handler.destruct);
+      try {
+        await request.show(detailsUpdatePromise);
+        ok(false, `${testName}: should be rejected with AbortError but got resolved.`);
+      } catch(error) {
+        is(error.name, "AbortError", `${testName}: should be rejected with AbortError.`);
+      }
+      await handler.destruct();
+      resolve();
     });
   }
 
   // testing show response initialization in chrome process
-  function testShowResponseInit() {
-    return new Promise((resolve, reject) => {
-      gScript.addMessageListener("test-show-response-init-complete",
-                                 function showResponseInitCompleteHandler() {
-        gScript.removeMessageListener("test-show-response-init-complete",
-                                      showResponseInitCompleteHandler);
-        resolve();
-      });
-      gScript.sendAsyncMessage("test-show-response-init");
-    });
+  async function testShowResponseInit() {
+    const testName = "testShowResponseInit";
+    await requestChromeAction("test-show-response-init", testName);
   }
 
   // testing show that is not triggered by user.
-  function testShowNotTriggeredByUser() {
-    gScript.sendAsyncMessage("set-simple-ui-service");
-    return new Promise((resolve, reject) => {
-      const payRequest = new PaymentRequest(defaultMethods, defaultDetails);
-      payRequest.show().then(() => {
-        ok(false, "Expected 'SecurityError', but got resolved")
-        resolve();
-      }).catch((err) => {
-        is(err.name, "SecurityError", `Should be rejected with 'SecurityError', but got ${err.name}`);
-        resolve();
-      });
+  async function testShowNotTriggeredByUser() {
+    const testName = "testShowNotTriggeredByUser";
+    await requestChromeAction("set-simple-ui-service", testName);
+    return new Promise(async (resolve) => {
+      const request = new PaymentRequest(defaultMethods, defaultDetails);
+      try {
+        await request.show();
+        ok(false, `${testName}: should be rejected with SecurityError, but got resolved.`);
+      } catch (error) {
+        is(error.name, "SecurityError", `${testName}: should be rejected with SecurityError.`);
+      }
+      resolve();
     });
   }
 
   // teardown function
-  function teardown() {
+  async function teardown() {
     gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
       gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
       gScript.removeMessageListener("test-fail", testFailHandler);
       gScript.removeMessageListener("test-pass", testPassHandler);
       gScript.destroy();
       SimpleTest.finish();
     });
     gScript.sendAsyncMessage("teardown");
   }
 
   // test main body
-  function runTests() {
-    testCannotMakePaymentShow()
-    .then(testRejectShow)
-    .then(testShowNormalFlow)
-    .then(testCompleteSuccess)
-    .then(testCompleteFail)
-    .then(testCompleteUnknown)
-    .then(testCompleteEmpty)
-    .then(testUpdateWithReject)
-    .then(testUpdateWithValidDetails)
-    .then(testUpdateWithInvalidDetails)
-    .then(testUpdateWithError)
-    .then(testShowWithValidPromise)
-    .then(testShowWithInvalidPromise)
-    .then(testShowWithRejectedPromise)
-    .then(testShowWithErrorPromise)
-    .then(testShowWithPromiseResolvedByRejectedPromise)
-    .then(testShowResponseInit)
-    .then(testShowNotTriggeredByUser)
-    .then(teardown)
-    .catch( e => {
-      ok(false, "Unexpected error: " + e.name);
+  async function runTests() {
+    try {
+      await testCannotMakePaymentShow();
+      await testRejectShow();
+      await testShowNormalFlow();
+      await testCompleteSuccess();
+      await testCompleteFail();
+      await testCompleteUnknown();
+      await testCompleteEmpty();
+      await testUpdateWithReject();
+      await testUpdateWithValidDetails();
+      await testUpdateWithInvalidDetails();
+      await testUpdateWithError();
+      await testShowWithValidPromise();
+      await testShowWithInvalidPromise();
+      await testShowWithRejectedPromise();
+      await testShowWithErrorPromise();
+      await testShowWithPromiseResolvedByRejectedPromise();
+      await testShowResponseInit();
+      await testShowNotTriggeredByUser();
+      await teardown();
+    } catch (error) {
+      ok(false, `test_showPayment: Unexpected error: ${error.name}`);
       SimpleTest.finish();
-    });
+    }
   }
 
   window.addEventListener('load', function() {
     SpecialPowers.pushPrefEnv({
       'set': [
         ['dom.payments.request.enabled', true],
       ]
     }, runTests);