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/style-src/style-src-attr-blocked-template-move.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="style-src-attr 'none'">
<title>A style attribute parsed in template content is blocked after moving out of the template</title>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
</head>
<body>
<div id='log'></div>
<script>
var t = async_test("A security policy violation is reported for the moved style attribute");
window.addEventListener('securitypolicyviolation', t.step_func_done(function(e) {
assert_equals(e.violatedDirective, 'style-src-attr');
assert_equals(e.blockedURI, 'inline');
}));
var template = document.createElement('template');
template.innerHTML = '<div id="probe" style="background-color: green"></div>';
var probe = template.content.querySelector('#probe');
document.body.append(probe);
test(function() {
assert_equals(probe.style.length, 0);
}, "The style attribute is not applied once the element is moved out of the template");
</script>
</body>
</html>