From 7fcb23f31978aad40b0bb8170d6c078f954bc846 Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Mon, 4 Jan 2021 15:59:11 +0000 Subject: [PATCH] Bug 1683340 - Enable ESLint rule no-async-promise-executor for dom/payments. r=baku Depends on D100134 Differential Revision: https://phabricator.services.mozilla.com/D100135 --- .eslintrc.js | 5 - dom/payments/test/test_basiccard.html | 306 ++++++++++----------- dom/payments/test/test_bug1478740.html | 41 +-- dom/payments/test/test_canMakePayment.html | 39 ++- dom/payments/test/test_closePayment.html | 69 ++--- dom/payments/test/test_showPayment.html | 240 ++++++++-------- 6 files changed, 324 insertions(+), 376 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 444e0c1099b0..b1b6352eba3a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -320,11 +320,6 @@ module.exports = { { files: [ "dom/l10n/tests/mochitest/document_l10n/non-system-principal/test.html", - "dom/payments/test/test_basiccard.html", - "dom/payments/test/test_bug1478740.html", - "dom/payments/test/test_canMakePayment.html", - "dom/payments/test/test_closePayment.html", - "dom/payments/test/test_showPayment.html", "dom/tests/browser/browser_persist_cookies.js", "dom/tests/browser/browser_persist_mixed_content_image.js", ], diff --git a/dom/payments/test/test_basiccard.html b/dom/payments/test/test_basiccard.html index fa264e6a0888..e8d30fbd0632 100644 --- a/dom/payments/test/test_basiccard.html +++ b/dom/payments/test/test_basiccard.html @@ -136,217 +136,187 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1375345 async function testBasicCardRequestWithErrorNetworks() { const testName = "testBasicCardRequestWithErrorNetworks"; - return new Promise(async (resolve) => { - try { - const request = new PaymentRequest(errorNetworksMethods, defaultDetails, defaultOptions); - ok(false, `${testName}: Expected 'TypeError', but got success construction.`); - } catch (e) { - is(e.name, "TypeError", `${testName}: Expected TypeError, but got ${e.name}`); - } - resolve(); - }); + try { + const request = new PaymentRequest(errorNetworksMethods, defaultDetails, defaultOptions); + ok(false, `${testName}: Expected 'TypeError', but got success construction.`); + } catch (e) { + is(e.name, "TypeError", `${testName}: Expected TypeError, but got ${e.name}`); + } } async function testBasicCardRequestWithUnconvertableData() { const testName = "testBasicCardRequestWithUnconvertableData"; - return new Promise(async (resolve) => { - try { - const request = new PaymentRequest(unconvertableDataMethods, defaultDetails, defaultOptions); - ok(false, `${testName}: Expected 'TypeError', but got success construction.`); - } catch (e) { - is(e.name, "TypeError", `${testName}: Expected TypeError, but got ${e.name}`); - } - resolve(); - }); + try { + const request = new PaymentRequest(unconvertableDataMethods, defaultDetails, defaultOptions); + ok(false, `${testName}: Expected 'TypeError', but got success construction.`); + } catch (e) { + is(e.name, "TypeError", `${testName}: Expected TypeError, but got ${e.name}`); + } } async function testBasicCardRequestWithNullData() { const testName = "testBasicCardRequestWithNullData"; - return new Promise(async (resolve) => { - try { - const request = new PaymentRequest(nullDataMethods, defaultDetails, defaultOptions); - ok(request, `${testName}: PaymentRequest should be constructed with null data BasicCardRequest.`); - } catch (e) { - ok(false, `${testName}: Unexpected error: ${e.name}`); - } - resolve(); - }); + try { + const request = new PaymentRequest(nullDataMethods, defaultDetails, defaultOptions); + ok(request, `${testName}: PaymentRequest should be constructed with null data BasicCardRequest.`); + } catch (e) { + ok(false, `${testName}: Unexpected error: ${e.name}`); + } } async function testBasicCardRequestWithEmptyData() { const testName = "testBasicCardRequestWithEmptyData"; - return new Promise(async (resolve) => { - try { - const request = new PaymentRequest(emptyDataMethods, defaultDetails, defaultOptions); - ok(request, `${testName}: PaymentRequest should be constructed with empty data BasicCardRequest.`); - } catch (e) { - ok(false, `${testName}: Unexpected error: ${e.name}`); - } - resolve(); - }); + try { + const request = new PaymentRequest(emptyDataMethods, defaultDetails, defaultOptions); + ok(request, `${testName}: PaymentRequest should be constructed with empty data BasicCardRequest.`); + } catch (e) { + ok(false, `${testName}: Unexpected error: ${e.name}`); + } } async function testCanMakePaymentWithBasicCardRequest() { const testName = "testCanMakePaymentWithBasicCardRequest"; - return new Promise(async (resolve) => { - const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); - try { - const result = await request.canMakePayment(); - ok(result, `${testName}: canMakePayment() should be resolved with true.`); - } catch (e) { - ok(false, `${testName}: Unexpected error: ${e.name}`); - } - resolve(); - }); + const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); + try { + const result = await request.canMakePayment(); + ok(result, `${testName}: canMakePayment() should be resolved with true.`); + } catch (e) { + ok(false, `${testName}: Unexpected error: ${e.name}`); + } } async function testBasicCardSimpleResponse() { const testName = "testBasicCardSimpleResponse"; await requestChromeAction("set-simple-ui-service", testName); - return new Promise(async (resolve) => { - const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); - const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); - try { - const response = await request.show(); - ok(response.details, `${testName}: basiccard response should exists.`); - ok(!response.details.cardholderName, `${testName}: response.details.cardholderName should not exist.`); - is(response.details.cardNumber, "4916855166538720", - `${testName}: response.details.cardNumber should be '4916855166538720'.`); - ok(!response.details.expiryMonth, `${testName}: response.details.expiryMonth should not exist.`); - ok(!response.details.expiryYear, `${testName}: response.details.expiryYear should be '2024'.`); - ok(!response.details.cardSecurityCode, `${testName}: response.details.cardSecurityCode should not exist.`); - ok(!response.details.billingAddress, `${testName}: response.details.billingAddress should not exist.`); - await response.complete("success"); - } catch (e) { - ok(false, `${testName}: Unexpected error: ${e.name}`); - } - await handler.destruct(); - resolve(); - }); + const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); + try { + const response = await request.show(); + ok(response.details, `${testName}: basiccard response should exists.`); + ok(!response.details.cardholderName, `${testName}: response.details.cardholderName should not exist.`); + is(response.details.cardNumber, "4916855166538720", + `${testName}: response.details.cardNumber should be '4916855166538720'.`); + ok(!response.details.expiryMonth, `${testName}: response.details.expiryMonth should not exist.`); + ok(!response.details.expiryYear, `${testName}: response.details.expiryYear should be '2024'.`); + ok(!response.details.cardSecurityCode, `${testName}: response.details.cardSecurityCode should not exist.`); + ok(!response.details.billingAddress, `${testName}: response.details.billingAddress should not exist.`); + await response.complete("success"); + } catch (e) { + ok(false, `${testName}: Unexpected error: ${e.name}`); + } + await handler.destruct(); } async function testBasicCardDetailedResponse() { const testName = "testBasicCardDetailedResponse"; await requestChromeAction("set-detailed-ui-service", testName); - return new Promise(async (resolve) => { - const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); - const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); - try { - const response = await request.show(); - ok(response.details, `${testName}: basiccard response should exists.`); - ok(response.details.cardholderName, `${testName}: response.details.cardholderName should not exist.`); - is(response.details.cardNumber, "4916855166538720", - `${testName}: response.details.cardNumber should be '4916855166538720'.`); - ok(response.details.expiryMonth, `${testName}: response.details.expiryMonth should not exist.`); - ok(response.details.expiryYear, `${testName}: response.details.expiryYear should be '2024'.`); - ok(response.details.cardSecurityCode, `${testName}: response.details.cardSecurityCode should not exist.`); - ok(response.details.billingAddress, `${testName}: response.details.billingAddress should not exist.`); - const billingAddress = response.details.billingAddress; - is(billingAddress.country, "USA", `${testName}: country should be 'USA'.`); - is(billingAddress.addressLine.length, 1, `${testName}: addressLine.length should be 1.`); - is(billingAddress.addressLine[0], "Easton Ave", `${testName}: addressLine[0] should be 'Easton Ave'.`); - is(billingAddress.region, "CA", `${testName}: region should be 'CA'.`); - is(billingAddress.regionCode, "CA", `${testName}: regionCode should be 'CA'.`); - is(billingAddress.city, "San Bruno", `${testName}: city should be 'San Bruno'.`); - is(billingAddress.dependentLocality, "", `${testName}: dependentLocality should be empty.`); - is(billingAddress.postalCode, "94066", `${testName}: postalCode should be '94066'.`); - is(billingAddress.sortingCode, "123456", `${testName}: sortingCode should be '123456'.`); - is(billingAddress.organization, "", `${testName}: organization should be empty.`); - is(billingAddress.recipient, "Bill A. Pacheco", `${testName}: recipient should be 'Bill A. Pacheco'.`); - is(billingAddress.phone, "+14344413879", `${testName}: phone should be '+14344413879'.`); - await response.complete("success"); - } catch (e) { - ok(false, `${testName}: Unexpected error: ${e.name}`); - } - await handler.destruct(); - resolve(); - }); + const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); + try { + const response = await request.show(); + ok(response.details, `${testName}: basiccard response should exists.`); + ok(response.details.cardholderName, `${testName}: response.details.cardholderName should not exist.`); + is(response.details.cardNumber, "4916855166538720", + `${testName}: response.details.cardNumber should be '4916855166538720'.`); + ok(response.details.expiryMonth, `${testName}: response.details.expiryMonth should not exist.`); + ok(response.details.expiryYear, `${testName}: response.details.expiryYear should be '2024'.`); + ok(response.details.cardSecurityCode, `${testName}: response.details.cardSecurityCode should not exist.`); + ok(response.details.billingAddress, `${testName}: response.details.billingAddress should not exist.`); + const billingAddress = response.details.billingAddress; + is(billingAddress.country, "USA", `${testName}: country should be 'USA'.`); + is(billingAddress.addressLine.length, 1, `${testName}: addressLine.length should be 1.`); + is(billingAddress.addressLine[0], "Easton Ave", `${testName}: addressLine[0] should be 'Easton Ave'.`); + is(billingAddress.region, "CA", `${testName}: region should be 'CA'.`); + is(billingAddress.regionCode, "CA", `${testName}: regionCode should be 'CA'.`); + is(billingAddress.city, "San Bruno", `${testName}: city should be 'San Bruno'.`); + is(billingAddress.dependentLocality, "", `${testName}: dependentLocality should be empty.`); + is(billingAddress.postalCode, "94066", `${testName}: postalCode should be '94066'.`); + is(billingAddress.sortingCode, "123456", `${testName}: sortingCode should be '123456'.`); + is(billingAddress.organization, "", `${testName}: organization should be empty.`); + is(billingAddress.recipient, "Bill A. Pacheco", `${testName}: recipient should be 'Bill A. Pacheco'.`); + is(billingAddress.phone, "+14344413879", `${testName}: phone should be '+14344413879'.`); + await response.complete("success"); + } catch (e) { + ok(false, `${testName}: Unexpected error: ${e.name}`); + } + await handler.destruct(); } async function testSpecialAddressResponse() { const testName = "testSpecialAddressResponse"; await requestChromeAction("set-special-address-ui-service", testName); - return new Promise(async (resolve) => { - const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); - const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); - try { - const response = await request.show(); - ok(response.details, `${testName}: BasiccardResponse should exist.`); - ok(response.details.billingAddress, - `${testName}: BasiccardResponse.billingAddress should exist.`); - is(response.details.billingAddress.addressLine[0], ":$%@&*", - `${testName}: AddressLine should be ':$%@&*'`); - await response.complete("success"); - } catch (e) { - ok(false, `${testName}: Unexpected error: ${e.name}`); - } - await handler.destruct(); - resolve(); - }); + const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); + try { + const response = await request.show(); + ok(response.details, `${testName}: BasiccardResponse should exist.`); + ok(response.details.billingAddress, + `${testName}: BasiccardResponse.billingAddress should exist.`); + is(response.details.billingAddress.addressLine[0], ":$%@&*", + `${testName}: AddressLine should be ':$%@&*'`); + await response.complete("success"); + } catch (e) { + ok(false, `${testName}: Unexpected error: ${e.name}`); + } + await handler.destruct(); } async function testMethodChangeWithoutRequestBillingAddress() { const testName = "testMethodChangeWithoutRequestBillingAddress"; await requestChromeAction("method-change-to-basic-card", testName); - return new Promise(async (resolve) => { - const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); - request.addEventListener("paymentmethodchange", async (event) => { - is(event.methodName, "basic-card", `${testName}: PaymentMethodChangeEvent.methodName should be 'basic-card'.`) - ok(event.methodDetails, `PaymentMethodChangeEvent.methodDetails should exist.`); - ok(!event.methodDetails.billingAddress, `PaymentMethodChangeEvent.methodDetails.billingAddres should not exist.`); - event.updateWith(updateDetails); - }); - const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); - try { - const response = await request.show(); - await response.complete("success"); - } catch (error) { - ok(false, `${testName}: Unexpected error: ${error.name}`); - } - await handler.destruct(); - resolve(); + const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); + request.addEventListener("paymentmethodchange", async (event) => { + is(event.methodName, "basic-card", `${testName}: PaymentMethodChangeEvent.methodName should be 'basic-card'.`) + ok(event.methodDetails, `PaymentMethodChangeEvent.methodDetails should exist.`); + ok(!event.methodDetails.billingAddress, `PaymentMethodChangeEvent.methodDetails.billingAddres should not exist.`); + event.updateWith(updateDetails); }); + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); + try { + const response = await request.show(); + await response.complete("success"); + } catch (error) { + ok(false, `${testName}: Unexpected error: ${error.name}`); + } + await handler.destruct(); } async function testMethodChangeWithRequestBillingAddress() { const testName = "testMethodChangeWithRequestBillingAddress"; await requestChromeAction("method-change-to-basic-card", testName); - return new Promise(async (resolve) => { - const options = { - requestPayerName: true, - requestBillingAddress: true, - requestShipping: true, - shippingType: "shipping", - }; - const request = new PaymentRequest(defaultMethods, defaultDetails, options); - request.addEventListener("paymentmethodchange", async (event) => { - is(event.methodName, "basic-card", `${testName}: PaymentMethodChangeEvent.methodName should be 'basic-card'.`) - ok(event.methodDetails, `PaymentMethodChangeEvent.methodDetails should exist.`); - const billingAddress = event.methodDetails.billingAddress; - is(billingAddress.country, "USA", `${testName}: country should be 'USA'.`); - is(billingAddress.addressLine.length, 1, `${testName}: addressLine.length should be 1.`); - is(billingAddress.addressLine[0], "Easton Ave", `${testName}: addressLine[0] should be 'Easton Ave'.`); - is(billingAddress.region, "CA", `${testName}: region should be 'CA'.`); - is(billingAddress.regionCode, "CA", `${testName}: regionCode should be 'CA'.`); - is(billingAddress.city, "San Bruno", `${testName}: city should be 'San Bruno'.`); - is(billingAddress.dependentLocality, "", `${testName}: dependentLocality should be empty.`); - is(billingAddress.postalCode, "94066", `${testName}: postalCode should be '94066'.`); - is(billingAddress.sortingCode, "123456", `${testName}: sortingCode should be '123456'.`); - is(billingAddress.organization, "", `${testName}: organization should be empty.`); - is(billingAddress.recipient, "Bill A. Pacheco", `${testName}: recipient should be 'Bill A. Pacheco'.`); - is(billingAddress.phone, "+14344413879", `${testName}: phone should be '+14344413879'.`); - event.updateWith(updateDetails); - }); - const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); - try { - const response = await request.show(); - await response.complete("success"); - } catch (error) { - ok(false, `${testName}: Unexpected error: ${error.name}`); - } - await handler.destruct(); - resolve(); + const options = { + requestPayerName: true, + requestBillingAddress: true, + requestShipping: true, + shippingType: "shipping", + }; + const request = new PaymentRequest(defaultMethods, defaultDetails, options); + request.addEventListener("paymentmethodchange", async (event) => { + is(event.methodName, "basic-card", `${testName}: PaymentMethodChangeEvent.methodName should be 'basic-card'.`) + ok(event.methodDetails, `PaymentMethodChangeEvent.methodDetails should exist.`); + const billingAddress = event.methodDetails.billingAddress; + is(billingAddress.country, "USA", `${testName}: country should be 'USA'.`); + is(billingAddress.addressLine.length, 1, `${testName}: addressLine.length should be 1.`); + is(billingAddress.addressLine[0], "Easton Ave", `${testName}: addressLine[0] should be 'Easton Ave'.`); + is(billingAddress.region, "CA", `${testName}: region should be 'CA'.`); + is(billingAddress.regionCode, "CA", `${testName}: regionCode should be 'CA'.`); + is(billingAddress.city, "San Bruno", `${testName}: city should be 'San Bruno'.`); + is(billingAddress.dependentLocality, "", `${testName}: dependentLocality should be empty.`); + is(billingAddress.postalCode, "94066", `${testName}: postalCode should be '94066'.`); + is(billingAddress.sortingCode, "123456", `${testName}: sortingCode should be '123456'.`); + is(billingAddress.organization, "", `${testName}: organization should be empty.`); + is(billingAddress.recipient, "Bill A. Pacheco", `${testName}: recipient should be 'Bill A. Pacheco'.`); + is(billingAddress.phone, "+14344413879", `${testName}: phone should be '+14344413879'.`); + event.updateWith(updateDetails); }); + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); + try { + const response = await request.show(); + await response.complete("success"); + } catch (error) { + ok(false, `${testName}: Unexpected error: ${error.name}`); + } + await handler.destruct(); } diff --git a/dom/payments/test/test_bug1478740.html b/dom/payments/test/test_bug1478740.html index 1b39ca41e824..e877face7620 100644 --- a/dom/payments/test/test_bug1478740.html +++ b/dom/payments/test/test_bug1478740.html @@ -39,25 +39,26 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1478740 return `${testName}: Unexpected error(${errName}) when ${timing} the PaymentRequest.`; } - function testMultipleShows() { - return new Promise(async (resolve) => { - const testName = "testMultipleShows"; - await requestChromeAction("start-test", testName); - let expectedResults = ["successful", - "successful", - "successful", - "AbortError", - "AbortError", - "AbortError"]; - let nextStatus = ["creating first page", - "creating second page", - "showing first payment", - "showing second payment", - "showing third payment", - "aborting first payment"]; - let currStatus = nextStatus.shift(); - let ifr1 = document.createElement('iframe'); - let ifr2 = document.createElement('iframe'); + async function testMultipleShows() { + const testName = "testMultipleShows"; + await requestChromeAction("start-test", testName); + let expectedResults = ["successful", + "successful", + "successful", + "AbortError", + "AbortError", + "AbortError"]; + let nextStatus = ["creating first page", + "creating second page", + "showing first payment", + "showing second payment", + "showing third payment", + "aborting first payment"]; + let currStatus = nextStatus.shift(); + let ifr1 = document.createElement('iframe'); + let ifr2 = document.createElement('iframe'); + + await new Promise(resolve => { let listener = async function(event) { let expected = expectedResults.shift(); is(event.data, expected, @@ -95,8 +96,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1478740 gScript.addMessageListener("showing-payment", listener); ifr1.src = "bug1478740.html"; document.body.appendChild(ifr1); - await requestChromeAction("finish-test"); }); + await requestChromeAction("finish-test"); } function teardown() { diff --git a/dom/payments/test/test_canMakePayment.html b/dom/payments/test/test_canMakePayment.html index 2f18932c7814..112fb8ce72fb 100644 --- a/dom/payments/test/test_canMakePayment.html +++ b/dom/payments/test/test_canMakePayment.html @@ -104,29 +104,26 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345365 }); } - function testNotAllowed() { - return new Promise(async (resolve, reject) => { - let payRequest = new PaymentRequest(defaultMethods, defaultDetails); - for (let i = 0; i < 1000; i++) { - try { - await payRequest.canMakePayment(); - } catch(err) { - is(err.name, "NotAllowedError", - "Expected 'NotAllowError', but got '" + err.name + "'"); - break; - } + async function testNotAllowed() { + let payRequest = new PaymentRequest(defaultMethods, defaultDetails); + for (let i = 0; i < 1000; i++) { + try { + await payRequest.canMakePayment(); + } catch(err) { + is(err.name, "NotAllowedError", + "Expected 'NotAllowError', but got '" + err.name + "'"); + break; } - for (let i = 0; i < 1000; i++) { - try { - await new PaymentRequest(defaultMethods, defaultDetails).canMakePayment(); - } catch(err) { - is(err.name, "NotAllowedError", - "Expected 'NotAllowError', but got '" + err.name + "'"); - break; - } + } + for (let i = 0; i < 1000; i++) { + try { + await new PaymentRequest(defaultMethods, defaultDetails).canMakePayment(); + } catch(err) { + is(err.name, "NotAllowedError", + "Expected 'NotAllowError', but got '" + err.name + "'"); + break; } - resolve(); - }); + } } function teardown() { diff --git a/dom/payments/test/test_closePayment.html b/dom/payments/test/test_closePayment.html index fc919e31fabe..8f2ad7cd00c5 100644 --- a/dom/payments/test/test_closePayment.html +++ b/dom/payments/test/test_closePayment.html @@ -40,20 +40,19 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1408234 const testName = "testCloseByReloading"; await requestChromeAction("test-setup", testName); info(testName); - return new Promise(async (resolve) => { - let nextStatus = ["creating", "reloading"]; - let currStatus = nextStatus.shift(); - let ifr = document.createElement('iframe'); - await requestChromeAction("payment-num-set"); - let listener = async function(event) { + let nextStatus = ["creating", "reloading"]; + let currStatus = nextStatus.shift(); + let ifr = document.createElement('iframe'); + await requestChromeAction("payment-num-set"); + + await new Promise((resolve) => { + let listener = function(event) { is(event.data, "successful", `${testName}: Expected 'successful' when ${currStatus}, but got '${event.data}'.`); if (currStatus === "creating") { ifr.contentWindow.location.reload(); } else if (currStatus === "reloading") { window.removeEventListener("message", listener); - await requestChromeAction("payment-num-check", 1); - document.body.removeChild(ifr); resolve(); } currStatus = nextStatus.shift(); @@ -62,6 +61,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1408234 ifr.src = "simple_payment_request.html"; document.body.appendChild(ifr); }); + + await requestChromeAction("payment-num-check", 1); + document.body.removeChild(ifr); + } async function testCloseByRedirecting() { @@ -205,37 +208,35 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1408234 async function testNonfullyActivePayment() { const testName = "testNonfullyActivePayment"; await requestChromeAction("test-setup", testName); - return new Promise(async (resolve) => { - const outer = document.createElement("iframe"); - outer.allow = "payment"; - document.body.appendChild(outer); - await getLoadedPaymentRequest(outer,"blank_page.html"); - const inner = outer.contentDocument.createElement("iframe"); - inner.allow = "payment"; - outer.contentDocument.body.appendChild(inner); + const outer = document.createElement("iframe"); + outer.allow = "payment"; + document.body.appendChild(outer); + await getLoadedPaymentRequest(outer,"blank_page.html"); - const request = await getLoadedPaymentRequest(inner,"blank_page.html"); - ok(request, `${testName}: PaymentRequest in inner iframe should exist.`); + const inner = outer.contentDocument.createElement("iframe"); + inner.allow = "payment"; + outer.contentDocument.body.appendChild(inner); - await new Promise(res => { - outer.addEventListener("load", res); - outer.src = "simple_payment_request.html"; - }); + const request = await getLoadedPaymentRequest(inner,"blank_page.html"); + ok(request, `${testName}: PaymentRequest in inner iframe should exist.`); - let handler = SpecialPowers.getDOMWindowUtils(inner.contentWindow).setHandlingUserInput(true); - try { - const showPromise = await request.show(); - ok(false, `${testName}: expected 'AbortError', but got resolved.`); - } catch (error) { - is(error.name, "AbortError", - `${testName}: expected 'AbortError'.`); - } - await handler.destruct(); - inner.remove(); - outer.remove(); - resolve(); + await new Promise(res => { + outer.addEventListener("load", res); + outer.src = "simple_payment_request.html"; }); + + let handler = SpecialPowers.getDOMWindowUtils(inner.contentWindow).setHandlingUserInput(true); + try { + const showPromise = await request.show(); + ok(false, `${testName}: expected 'AbortError', but got resolved.`); + } catch (error) { + is(error.name, "AbortError", + `${testName}: expected 'AbortError'.`); + } + await handler.destruct(); + inner.remove(); + outer.remove(); } async function teardown() { diff --git a/dom/payments/test/test_showPayment.html b/dom/payments/test/test_showPayment.html index 53d4eb06efce..2a4a0bb4f7e6 100644 --- a/dom/payments/test/test_showPayment.html +++ b/dom/payments/test/test_showPayment.html @@ -215,64 +215,58 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366 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)); - }); - request.addEventListener("shippingoptionchange", event => { - event.updateWith(updateWithPromise(updatedShippingOptionsDetails)); - }); - const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); - 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(); + + const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); + request.addEventListener("shippingaddresschange", event => { + checkAddress(testName, request.shippingAddress, true/*fromEvent*/); + event.updateWith(updateWithPromise(defaultDetails)); }); + request.addEventListener("shippingoptionchange", event => { + event.updateWith(updateWithPromise(updatedShippingOptionsDetails)); + }); + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); + 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(); } // testing show with nonsupported methods 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); - 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(); - }); + + const request = new PaymentRequest(nonSupportedMethods, defaultDetails); + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); + 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(); } // testing show rejected by user 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); - 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(); - }); + + const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); + 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(); } // testing PaymentResponse.complete() with specified result @@ -283,18 +277,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366 } else { await requestChromeAction(`set-complete-status-unknown`); } - return new Promise(async (resolve) => { - const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); - const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); - try { - let response = await request.show(); - await response.complete(result); - } catch (error) { - ok(false, `${testName}: Unexpected error ${error.name}.`); - } - await handler.destruct(); - resolve(); - }); + + const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); + try { + let response = await request.show(); + await response.complete(result); + } catch (error) { + ok(false, `${testName}: Unexpected error ${error.name}.`); + } + await handler.destruct(); } async function testCompleteFail() { @@ -324,32 +316,30 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366 } else { await requestChromeAction("set-update-with-ui-service", testName); } - return new Promise(async (resolve) => { - const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); - request.addEventListener("shippingaddresschange", event => { - event.updateWith(updateWithPromise(detailsUpdate)); - }); - request.addEventListener("shippingoptionchange", event => { - event.updateWith(updateWithPromise(detailsUpdate)); - }); - const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); - try { - const response = await request.show(); - if (expectedError) { - 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(); + + const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); + request.addEventListener("shippingaddresschange", event => { + event.updateWith(updateWithPromise(detailsUpdate)); }); + request.addEventListener("shippingoptionchange", event => { + event.updateWith(updateWithPromise(detailsUpdate)); + }); + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); + try { + const response = await request.show(); + if (expectedError) { + 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(); } async function testUpdateWithReject() { @@ -379,29 +369,27 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366 } else { await requestChromeAction("set-simple-ui-service", testName); } - 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); - try { - let response = await request.show(updateWithPromise(detailsUpdate)); - if (expectedError) { - 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(error.name, expectedError, `${testName}: Should be rejected with ${expectedError}.`); - } else { - ok(false, `${testName}: Unexpected error ${error.name}.`); - } + + const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); + ok(!request.shippingOption, `${testName}: request.shippingOption should be null.`); + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); + try { + let response = await request.show(updateWithPromise(detailsUpdate)); + if (expectedError) { + ok(false, `${testName}: Should be rejected with ${expectedError} but got resolved.`); + } else { + ok(response.shippingOption, + `${testName}: response.shippingOption should not be null.`); } - await handler.destruct(); - resolve(); - }); + await response.complete(); + } 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(); } async function testShowWithValidPromise() { const testName = "testShowWithValidPromise"; @@ -426,20 +414,18 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366 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); - 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(); - }); + + 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); + 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(); } // testing show response initialization in chrome process @@ -452,16 +438,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366 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(); - }); + + 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.`); + } } // teardown function