From 94fd139ae5d0bdc4274b5e2c4e91035d63876e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20C=C3=A1ceres?= Date: Thu, 29 Nov 2018 21:38:58 +1100 Subject: [PATCH 1/5] Test payment request is showing boolean --- payment-request/payment-is-showing.https.html | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 payment-request/payment-is-showing.https.html diff --git a/payment-request/payment-is-showing.https.html b/payment-request/payment-is-showing.https.html new file mode 100644 index 00000000000000..7d642154203921 --- /dev/null +++ b/payment-request/payment-is-showing.https.html @@ -0,0 +1,135 @@ + +Test for PaymentRequest.show(optional promise) method + + + + + + From f496d16bc8f464f151176235dab028424dc53855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20C=C3=A1ceres?= Date: Wed, 9 Jan 2019 17:35:14 +1100 Subject: [PATCH 2/5] Rework tests --- payment-request/payment-is-showing.https.html | 457 +++++++++++++----- 1 file changed, 337 insertions(+), 120 deletions(-) diff --git a/payment-request/payment-is-showing.https.html b/payment-request/payment-is-showing.https.html index 7d642154203921..5bc022e9afd28a 100644 --- a/payment-request/payment-is-showing.https.html +++ b/payment-request/payment-is-showing.https.html @@ -8,128 +8,345 @@ - + + await promise_rejects( + t, + "AbortError", + iframeShowPromise, + "Expected iframeShowPromise to reject, request is already showing." + ); + + await windowRequest.abort(); + popupWindow.close(); + iframe.remove(); + }, "Given multiple nested browsing contexts, and window calls show() first, other nested browsing contexts can't show a request."); + + promise_test(async t => { + const iframe = await attachIframe(); + const iframeWindow = iframe.contentWindow; + const popupWindow = await loadPopup(); + + // Create requests + const windowRequest = new window.PaymentRequest(methods, details); + const popupRequest = new popupWindow.PaymentRequest(methods, details); + const iframeRequest = new iframeWindow.PaymentRequest(methods, details); + + // Get the showPromise for each browsing context + const [ + popupShowPromise, + windowShowPromise, + iframeShowPromise, + ] = await test_driver.bless("show payment request", () => { + return [ + popupRequest.show(), + windowRequest.show(), + iframeRequest.show(), + ]; + }); + + // windowShowPromise and iframeRequest will both reject + await promise_rejects( + t, + "AbortError", + windowShowPromise, + "Expected windowShowPromise to reject, the popup is showing a payment request." + ); + + await promise_rejects( + t, + "AbortError", + iframeShowPromise, + "Expected iframeShowPromise to reject, the popup is showing a payment request." + ); + + await popupRequest.abort(); + popupWindow.close(); + iframe.remove(); + }, "Given multiple nested browsing contexts, and popup calls show() first, other nested browsing contexts can't show a request."); + + promise_test(async t => { + const iframe = await attachIframe(); + const iframeWindow = iframe.contentWindow; + const popupWindow = await loadPopup(); + + // Create requests + const windowRequest = new window.PaymentRequest(methods, details); + const popupRequest = new popupWindow.PaymentRequest(methods, details); + const iframeRequest = new iframeWindow.PaymentRequest(methods, details); + + // Get the showPromise for each browsing context + const [ + iframeShowPromise, + popupShowPromise, + windowShowPromise, + ] = await test_driver.bless("show payment request", () => { + return [ + iframeRequest.show(), + popupRequest.show(), + windowRequest.show(), + ]; + }); + + // windowShowPromise and iframeRequest will both reject + await promise_rejects( + t, + "AbortError", + windowShowPromise, + "Expected windowShowPromise to reject, the popup is showing a payment request." + ); + + await promise_rejects( + t, + "AbortError", + popupShowPromise, + "Expected popupShowPromise to reject, the popup is showing a payment request." + ); + + await iframeRequest.abort(); + popupWindow.close(); + iframe.remove(); + }, "Given multiple nested browsing contexts, and an iframe calls show() first, other nested browsing contexts can't show a request."); + + promise_test(async t => { + const iframe = await attachIframe(); + const iframeWindow = iframe.contentWindow; + const iframeRequest = new iframeWindow.PaymentRequest(methods, details); + const iframeShowPromise = test_driver.bless("show payment request", () => + iframeRequest.show() + ); + + // We navigate away, causing the payment sheet to close + // and the request is showing boolean to become false. + iframe.src = "blank.html?abc=123"; + await new Promise(resolve => (iframe.onload = resolve)); + await promise_rejects( + t, + "AbortError", + iframeShowPromise, + "Navigating iframe away must cause the iframeShowPromise to reject." + ); + iframe.remove(); + + // Now we should be ok to spin up a new payment request + const request = new window.PaymentRequest(method, details); + const showPromise = request.show(); + await request.abort(); + }, "Navigating an iframe as a nested browsing context sets 'payment request is showing boolean' to false."); + + promise_test(async t => { + const popupWindow = await loadPopup(); + const popupRequest = new popupWindow.PaymentRequest(methods, details); + const showPromise = test_driver.bless("show payment request", () => + popupRequest.show() + ); + + // We navigate away, causing the payment sheet to close + // and the request is showing boolean to become false. + popupWindow.location = "blank.html?abc=123"; + await new Promise(resolve => (popupWindow.onload = resolve)); + await promise_rejects( + t, + "AbortError", + showPromise, + "Navigating away must cause the showPromise to reject with an AbortError" + ); + popupWindow.close(); + + // Now we should be ok to spin up a new payment request. + const request = new window.PaymentRequest(method, details); + request.show(); + await request.abort(); + }, "Navigating a popup as a nested browsing context sets 'payment request is showing boolean' to false."); + + + From 5f1cbd0a42811a6c66bcfdf25f8a5e7023bf900e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20C=C3=A1ceres?= Date: Fri, 11 Jan 2019 13:58:52 +1100 Subject: [PATCH 3/5] Tests for payment-request payment-request/821 --- payment-request/payment-is-showing.https.html | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/payment-request/payment-is-showing.https.html b/payment-request/payment-is-showing.https.html index 5bc022e9afd28a..33667dc6d6bdce 100644 --- a/payment-request/payment-is-showing.https.html +++ b/payment-request/payment-is-showing.https.html @@ -67,8 +67,11 @@ // Try to show a second payment sheet in the same window, which should reject. const showPromise2 = test_driver.bless("show payment request", () => + // Sets the request's state to "closed", and rejects with AbortError. + // See: https://github.com/w3c/payment-request/pull/821 request2.show() ); + await promise_rejects( t, "AbortError", @@ -83,6 +86,22 @@ showPromise1, "request1 was aborted via .abort()" ); + // Finally, request2 should have been "closed", so trying to show + // it will again result in promise rejected with an InvalidStateError. + // See: https://github.com/w3c/payment-request/pull/821 + const rejectedPromise = request2.show(); + await promise_rejects( + t, + "InvalidStateError", + rejectedPromise, + "Attempting to show a second payment request must reject." + ); + // Finally, we confirm that request2's returned promises are unique. + assert_not_equals( + showPromise2, + rejectedPromise, + "Returned Promises be unique" + ); }, "The top browsing context can only show one payment sheet at a time."); promise_test(async t => { @@ -347,6 +366,5 @@ request.show(); await request.abort(); }, "Navigating a popup as a nested browsing context sets 'payment request is showing boolean' to false."); - From fd97a018aafc891e9abc757f1635372d85148905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20C=C3=A1ceres?= Date: Fri, 11 Jan 2019 14:44:45 +1100 Subject: [PATCH 4/5] Add ApplePay payment method --- payment-request/payment-is-showing.https.html | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/payment-request/payment-is-showing.https.html b/payment-request/payment-is-showing.https.html index 33667dc6d6bdce..650b76d61f72d8 100644 --- a/payment-request/payment-is-showing.https.html +++ b/payment-request/payment-is-showing.https.html @@ -11,7 +11,17 @@