blob: f1d2fb83e0e0b17e0030bc991b0135bd21200aa0 [file] [log] [blame]
<!DOCTYPE html>
<meta charset=utf-8>
<title>PaymentRequest show() rejects if doc is not fully active</title>
<link rel="help" href="">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
explicit_done: true,
explicit_timeout: true,
const applePay = Object.freeze({
supportedMethods: "",
data: {
version: 3,
merchantIdentifier: "",
countryCode: "US",
merchantCapabilities: ["supports3DS"],
supportedNetworks: ["visa"],
const validMethod = Object.freeze({
supportedMethods: "basic-card",
const validMethods = Object.freeze([validMethod, applePay]);
const validDetails = Object.freeze({
total: {
label: "Total due",
amount: {
currency: "USD",
value: "5.00",
function getLoadedPaymentRequest(iframe, url) {
return new Promise(resolve => {
() => {
const { PaymentRequest } = iframe.contentWindow;
const request = new PaymentRequest(validMethods, validDetails);
{ once: true }
iframe.src = url;
function testAbortShowIfDocumentIsNotActive() {
promise_test(async t => {
const iframe = document.createElement("iframe");
iframe.allowPaymentRequest = true;
// We first got to page1.html, grab a PaymentRequest instance.
const request1 = await getLoadedPaymentRequest(
// We navigate the iframe again, putting request1's document into an inactive state.
const request2 = await getLoadedPaymentRequest(
// Now, request1's relevant global object's document is no longer active.
// So, call .show(), and make sure it rejects appropriately.
await promise_rejects(
"Inactive document, so must throw AbortError"
// request2 has an active document tho, so confirm it's working as expected:;
await request2.abort();
await promise_rejects(
"Abort already called, so InvalidStateError"
// We are done, so clean up.
}, " aborts if the document is not active.");
function testAbortShowIfDocumentIsNotFullyActive() {
promise_test(async t => {
// We nest two iframes and wait for them to load.
const outerIframe = document.createElement("iframe");
outerIframe.allowPaymentRequest = true;
// Load the outer iframe (we don't care about the awaited request)
await getLoadedPaymentRequest(
// Now we create the inner iframe
const innerIframe = outerIframe.contentDocument.createElement("iframe");
innerIframe.allowPaymentRequest = true;
// nest them
// load innerIframe, and get the PaymentRequest instance
const request = await getLoadedPaymentRequest(
// Navigate the outer iframe to a new location.
// Wait for the load event to fire.
await new Promise(resolve => {
outerIframe.addEventListener("load", resolve);
outerIframe.src = "/payment-request/resources/page2.html";
const showPromise =;
// Now, request's relevant global object's document is still active
// (it is the active document of the inner iframe), but is not fully active
// (since the parent of the inner iframe is itself no longer active).
// So, call and make sure it rejects appropriately.
await promise_rejects(
"Active, but not fully active, so must throw AbortError"
// We are done, so clean up.
}, " aborts if the document is active, but not fully active.");
<h2>PaymentRequest show() rejects if doc is not fully active</h2>
Click on each button in sequence from top to bottom without refreshing the
page. Each button will bring up the Payment Request UI window and then will
close it automatically. (If a payment sheet stays open, the test has failed.)
<button onclick="testAbortShowIfDocumentIsNotActive()"> aborts if the document is not active.
<button onclick="testAbortShowIfDocumentIsNotFullyActive()"> aborts if the document is active, but not fully
<li><button onclick="done()">Done!</button></li>
If you find a buggy test, please <a href="">file a bug</a>
and tag one of the <a href="">suggested reviewers</a>.