diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/trusted-types/empty-default-policy-report-only.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/trusted-types/empty-default-policy-report-only.html')
-rw-r--r-- | testing/web-platform/tests/trusted-types/empty-default-policy-report-only.html | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/testing/web-platform/tests/trusted-types/empty-default-policy-report-only.html b/testing/web-platform/tests/trusted-types/empty-default-policy-report-only.html new file mode 100644 index 0000000000..1ba9c5ec18 --- /dev/null +++ b/testing/web-platform/tests/trusted-types/empty-default-policy-report-only.html @@ -0,0 +1,56 @@ +<!DOCTYPE html> +<html> +<head> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> +</head> +<body> +<script> +// Ensure that only the right events trigger violation reports. +// The Promise will resolve, when an event including the string "done" is +// received. The last line of this test file will cause this trigger. +promise_test(t => { + let count = 0; + return new Promise((resolve, reject) => { + document.addEventListener("securitypolicyviolation", e => { + e.stopPropagation(); + // We count the violation reports. We expect one each for "abc" test cases, and one + // for the "done" line at the end, which signals the end of the test run. + if (e.sample.includes("done")) { + resolve(count); + } else if (e.sample.includes("abc")) { + count++; + } else { + reject(); + } + }); + }).then(counter => { + assert_equals(counter, testCases.length, "event count"); + }); +}, "Count SecurityPolicyViolation events."); + +const testCases = [ + [ "script", "src" ], + [ "div", "innerHTML" ], + [ "script", "text" ], +]; + +trustedTypes.createPolicy("default", {}); + +testCases.forEach(c => { + const name = `${c[0]}.${c[1]} `; + test(t => { + const element = document.createElement(c[0]); + element[c[1]] = "abc"; + if (c[1] == "src") { + assert_equals(element[c[1]], location.protocol + "//" + location.host + "/trusted-types/abc"); + } else { + assert_equals(element[c[1]], "abc"); + } + }, name + "default"); +}); + +// Trigger the exit condition in the "Count" promise test above. +try { document.createElement("script").text = "done"; } catch (e) {} +</script> +</body> |