summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/content-security-policy/securitypolicyviolation/script-sample.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/content-security-policy/securitypolicyviolation/script-sample.html
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/content-security-policy/securitypolicyviolation/script-sample.html')
-rw-r--r--testing/web-platform/tests/content-security-policy/securitypolicyviolation/script-sample.html94
1 files changed, 94 insertions, 0 deletions
diff --git a/testing/web-platform/tests/content-security-policy/securitypolicyviolation/script-sample.html b/testing/web-platform/tests/content-security-policy/securitypolicyviolation/script-sample.html
new file mode 100644
index 0000000000..b38055bf7b
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/securitypolicyviolation/script-sample.html
@@ -0,0 +1,94 @@
+<!doctype html>
+<meta http-equiv="Content-Security-Policy" content="script-src 'nonce-abc' 'report-sample'; style-src 'self'; img-src 'none'">
+<script nonce="abc" src="/resources/testharness.js"></script>
+<script nonce="abc" src="/resources/testharnessreport.js"></script>
+<body>
+<script nonce="abc">
+ function waitForViolation(el) {
+ return new Promise(resolve => {
+ el.addEventListener('securitypolicyviolation', e => resolve(e));
+ });
+ }
+
+ async_test(t => {
+ var s = document.createElement('script');
+ s.innerText = "assert_unreached('inline script block')";
+
+ waitForViolation(s)
+ .then(t.step_func_done(e => {
+ assert_equals(e.blockedURI, "inline");
+ assert_equals(e.sample, "assert_unreached('inline script block')");
+ }));
+
+ document.head.append(s);
+ }, "Inline script should have a sample.");
+
+ async_test(t => {
+ var a = document.createElement("a");
+ a.setAttribute("onclick", "assert_unreached('inline event handler')");
+
+ waitForViolation(a)
+ .then(t.step_func_done(e => {
+ assert_equals(e.blockedURI, "inline");
+ assert_equals(e.sample, "assert_unreached('inline event handler')");
+ }));
+
+ document.body.append(a);
+ a.click();
+ }, "Inline event handlers should have a sample.");
+
+ async_test(t => {
+ var i = document.createElement("iframe");
+ i.src = "javascript:'inline url'";
+
+ waitForViolation(i)
+ .then(t.step_func_done(e => {
+ assert_equals(e.blockedURI, "inline");
+ assert_equals(e.sample, "javascript:'inline url'");
+ }));
+
+ document.body.append(i);
+ }, "JavaScript URLs in iframes should have a sample.");
+
+ async_test(t => {
+ document.addEventListener('securitypolicyviolation', t.step_func(e => {
+ if (e.blockedURI == "eval" &&
+ e.sample == "assert_unreached('eval')") {
+ t.done();
+ }
+ }));
+ try {
+ eval("assert_unreached('eval')");
+ assert_unreached('eval');
+ } catch (e) {
+ }
+ }, "eval() should have a sample.");
+
+ async_test(t => {
+ document.addEventListener('securitypolicyviolation', t.step_func(e => {
+ if (e.blockedURI == "eval" &&
+ e.sample == "assert_unreached('interval')") {
+ t.done();
+ }
+ }));
+ try {
+ setInterval("assert_unreached('interval')", 1000);
+ assert_unreached('interval');
+ } catch (e) {
+ }
+ }, "setInterval() should have a sample.");
+
+ async_test(t => {
+ document.addEventListener('securitypolicyviolation', t.step_func(e => {
+ if (e.blockedURI == "eval" &&
+ e.sample == "assert_unreached('timeout')") {
+ t.done();
+ }
+ }));
+ try {
+ setTimeout("assert_unreached('timeout')", 1000);
+ assert_unreached('timeout');
+ } catch (e) {
+ }
+ }, "setTimeout() should have a sample.");
+</script>