diff options
Diffstat (limited to 'testing/web-platform/tests/html/semantics/embedded-content/the-iframe-element/support/iframe_sandbox_block_modals.js')
-rw-r--r-- | testing/web-platform/tests/html/semantics/embedded-content/the-iframe-element/support/iframe_sandbox_block_modals.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/embedded-content/the-iframe-element/support/iframe_sandbox_block_modals.js b/testing/web-platform/tests/html/semantics/embedded-content/the-iframe-element/support/iframe_sandbox_block_modals.js new file mode 100644 index 0000000000..67733d8101 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/embedded-content/the-iframe-element/support/iframe_sandbox_block_modals.js @@ -0,0 +1,18 @@ +function runTest(modalName, expectedValue) { + let timeOutForFailingToOpenModal = 500; + let startTime; + async_test(t => { + let iframe = document.querySelector("iframe"); + iframe.onload = t.step_func(() => { + window.addEventListener("message", t.step_func_done(e => { + // This tests work by checking the call to open the modal diaglog will return immediately (or at least within timeOutForFailingToOpenModal). + // If the modal dialog is not blocked, then it will wait for user input and the test will time out. + assert_less_than(new Date().getTime() - startTime, timeOutForFailingToOpenModal, "Call to open modal dialog did not return immediately"); + assert_equals(e.data, expectedValue, "Call to open modal dialog did not return expected value"); + })); + startTime = new Date().getTime(); + iframe.contentWindow.postMessage(modalName, "*"); + }); + iframe.src = "support/iframe-that-opens-modals.html"; + }, "Frames without `allow-modals` should not be able to open modal dialogs"); +} |