summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/content-security-policy/style-src/style-src-inline-style-nonce-blocked-error-event.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/content-security-policy/style-src/style-src-inline-style-nonce-blocked-error-event.html
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/content-security-policy/style-src/style-src-inline-style-nonce-blocked-error-event.html')
-rw-r--r--testing/web-platform/tests/content-security-policy/style-src/style-src-inline-style-nonce-blocked-error-event.html71
1 files changed, 71 insertions, 0 deletions
diff --git a/testing/web-platform/tests/content-security-policy/style-src/style-src-inline-style-nonce-blocked-error-event.html b/testing/web-platform/tests/content-security-policy/style-src/style-src-inline-style-nonce-blocked-error-event.html
new file mode 100644
index 0000000000..e5c0174f6f
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/style-src/style-src-inline-style-nonce-blocked-error-event.html
@@ -0,0 +1,71 @@
+<!doctype html>
+<html>
+<head>
+ <meta http-equiv="Content-Security-Policy" content="style-src 'nonce-nonceynonce';">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+
+ <script>
+ var t_spv = async_test("Should fire a securitypolicyviolation event");
+
+ document.addEventListener("securitypolicyviolation", t_spv.step_func_done(function(e) {
+ assert_equals("style-src-elem", e.violatedDirective);
+ }));
+ </script>
+</head>
+<body>
+ <div id='log'></div>
+
+ <div id="content">Lorem ipsum</div>
+
+ <script>
+ function verifyStep1() {
+ var marginLeft = getComputedStyle(document.querySelector("#content")).getPropertyValue('margin-left');
+ assert_not_equals(marginLeft, '2px', "Content still does not have a 2px margin-left after initial style.");
+ }
+
+ function setupStep2() {
+ var sty = document.createElement("style");
+ sty.nonce = "not-nonceynonce";
+ sty.innerHTML = "#content { margin-left: 2px; }";
+ sty.onerror = styleError;
+ document.body.appendChild(sty);
+ }
+ function verifyStep2() {
+ var marginLeft = getComputedStyle(document.querySelector("#content")).getPropertyValue('margin-left');
+ assert_not_equals(marginLeft, '2px', "Content still does not have a 2px margin-left after inserted style.");
+ }
+
+ function setupStep3() {
+ var e = document.getElementById('style1');
+ e.innerHTML = "#content { margin-left: 2px; }";
+ }
+ function verifyStep3() {
+ var marginLeft = getComputedStyle(document.querySelector("#content")).getPropertyValue('margin-left');
+ assert_not_equals(marginLeft, '2px', "Content still does not have a 2px margin-left after changing style.");
+ test.done();
+ }
+
+ var verifySteps = [ verifyStep1, verifyStep2, verifyStep3 ];
+ var setupSteps = [ setupStep2, setupStep3 ];
+
+ var test = async_test("Test that paragraph remains unmodified and error events received.");
+
+ function styleError() {
+ test.step(function() {
+ verifySteps.shift()();
+ var nextSetup = setupSteps.shift();
+ if (nextSetup)
+ nextSetup();
+ });
+ }
+ </script>
+
+ <style id="style1" nonce="not-nonceynonce"
+ onerror="styleError();">
+ #content {
+ margin-left: 2px;
+ }
+ </style>
+</body>
+</html>