Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-markup-then-disconnected.html - WPT Dashboard Interop Dashboard
<!doctype html>
<meta http-equiv="Content-Security-Policy" content="script-src 'nonce-abc'; style-src 'self'">
<script nonce="abc" src="/resources/testharness.js"></script>
<script nonce="abc" src="/resources/testharnessreport.js"></script>
<script nonce="abc">
var connected = true;
var watcher;
promise_test(async t => {
const timeout_promise = () => new Promise(resolve => t.step_timeout(resolve, 1000));
watcher = new EventWatcher(t, document, ["securitypolicyviolation"], timeout_promise)
.wait_for("securitypolicyviolation").then(t.step_func(e => {
assert_equals(e.blockedURI, "inline");
assert_equals(e.lineNumber, 0);
assert_in_array(e.columnNumber, [0, 1]);
assert_equals(e.target,
connected ? document.getElementById('target')
: document);
}));
return watcher;
});
</script>
<a id="target" onclick="void(0)">Click me</a>
<script nonce="abc">
promise_test(async t => {
var a = document.getElementById('target');
a.onsecuritypolicyviolation =
t.unreached_func("Should not be dispatched on the disconnected target");
a.click();
a.parentNode.removeChild(a);
connected = false;
return watcher;
});
</script>