diff options
Diffstat (limited to 'testing/web-platform/tests/html/cross-origin-opener-policy/resources/postback.html')
-rw-r--r-- | testing/web-platform/tests/html/cross-origin-opener-policy/resources/postback.html | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/cross-origin-opener-policy/resources/postback.html b/testing/web-platform/tests/html/cross-origin-opener-policy/resources/postback.html new file mode 100644 index 0000000000..35b3be5c93 --- /dev/null +++ b/testing/web-platform/tests/html/cross-origin-opener-policy/resources/postback.html @@ -0,0 +1,45 @@ +<!doctype html> +<meta charset=utf-8> +<script src="/common/dispatcher/dispatcher.js"></script> +<script> +const params = new URL(location).searchParams; +const channelName = params.get("channel"); +const responseToken = params.get("responseToken"); +const iframeToken = params.get("iframeToken"); + +// If the channel parameter is set, use the BroadcastChannel-based communication +// method. Otherwise, use the dispatcher (useful in cases where this is embedded +// in a third-party iframe that doesn't share a partition with the top-level +// site). +if (channelName != "null") { + const bc = new BroadcastChannel(channelName); + // Handle the close message from the test-cleanup, forwarding it to the + // top level document, as this iframe and the opening document might not + // be able to close the popup. + bc.onmessage = event => { + if (event.data == "close") { + top.postMessage("close", "*"); + } + }; + + window.addEventListener("message", event => { + bc.postMessage(event.data); + }); + +} else { + window.addEventListener("message", event => { + send(responseToken, JSON.stringify(event.data)); + }); + + async function waitToClose() { + response = await receive(iframeToken); + // Handle the close message from the test-cleanup, forwarding it to the + // top level document, as this iframe and the opening document might not + // be able to close the popup. + if (response == "close") { + top.postMessage("close", "*"); + } + } + waitToClose(); +} +</script> |