diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/security/test/csp/test_blob_uri_blocks_modals.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/security/test/csp/test_blob_uri_blocks_modals.html')
-rw-r--r-- | dom/security/test/csp/test_blob_uri_blocks_modals.html | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/dom/security/test/csp/test_blob_uri_blocks_modals.html b/dom/security/test/csp/test_blob_uri_blocks_modals.html new file mode 100644 index 0000000000..3f8de94ed2 --- /dev/null +++ b/dom/security/test/csp/test_blob_uri_blocks_modals.html @@ -0,0 +1,79 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title>Bug 1432170 - Block alert box and new window open as per the sandbox + allow-scripts CSP</title> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"> + </script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> +<iframe style="width:100%;" id="testframe"></iframe> +<script> + +/* Description of the test: + * We apply the sanbox allow-scripts CSP to the blob iframe and check + * if the alert box and new window open is blocked correctly by the CSP. + */ +var testsToRun = { + block_window_open_test: false, + block_alert_test: false, + block_top_nav_alert_test: false, +}; + +SimpleTest.waitForExplicitFinish(); +SimpleTest.requestFlakyTimeout("have to test that alert dialogue is blocked"); + +window.addEventListener("message", receiveMessage); +function receiveMessage(event) { + switch (event.data.test) { + case "block_window_open_test": + testsToRun.block_window_open_test = true; + break; + case "block_alert_test": + is(event.data.msg, "alert blocked by CSP", "alert blocked by CSP"); + testsToRun.block_alert_test = true; + break; + case "block_top_nav_alert_test": + testsToRun.block_top_nav_alert_test = true; + break; + } +} + +var w; +// Set "privacy.partition.bloburl_per_agent_cluster" to false until Bug 1667348 is fixed. +SpecialPowers.pushPrefEnv({ + set: [["privacy.partition.bloburl_per_agent_cluster", false]]}, () => { + // start the test + document.getElementById("testframe").src = "file_blob_uri_blocks_modals.html"; + w = window.open("file_blob_top_nav_block_modals.html"); +}); + +// If alert window is not blocked by CSP then event message is not recieved and +// test fails after setTimeout interval of 1 second. +setTimeout(function () { + is(testsToRun.block_top_nav_alert_test, true, + "blob top nav alert should be blocked by CSP"); + testsToRun.block_top_nav_alert_test = true; + is(testsToRun.block_alert_test, true, + "alert should be blocked by CSP"); + testsToRun.block_alert_test = true; + checkTestsCompleted(); + },1000); + +function checkTestsCompleted() { + for (var prop in testsToRun) { + // some test hasn't run yet so we're not done + if (!testsToRun[prop]) { + return; + } + } + window.removeEventListener("message", receiveMessage); + w.close(); + SimpleTest.finish(); +} + +</script> +</body> +</html> |