Skip to content

Commit

Permalink
Add test for importing a srcdoc attribute node from a non-TT realm …
Browse files Browse the repository at this point in the history
…to a TT iframe element throws

First step to fix <w3c/trusted-types#425>.

Will add separate commits for the other tests requested at above ticket.
  • Loading branch information
mbrodesser-Igalia committed Feb 19, 2024
1 parent d643cf9 commit 738c5ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions trusted-types/block-string-assignment-to-Element-setAttribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script';">
</head>
<body>
<iframe id="sourceFrame" src="support/document-without-trusted-types-and-srcdoc-attribute.html"></iframe>
<script>
const nullPolicy = trustedTypes.createPolicy('NullPolicy', {createScript: s => s});

Expand Down Expand Up @@ -109,4 +110,22 @@

assert_equals(script.getAttribute('src'), RESULTS.SCRIPTURL);
}, "`script.src = setAttributeNode(embed.src)` with string works.");

async_test(t => {
const sourceFrame = document.getElementById("sourceFrame");
const targetFrame = document.createElement("iframe");
document.body.append(targetFrame);

t.add_cleanup(() => {
targetFrame.remove();
sourceFrame.contentWindow.location.reload();
});

sourceFrame.addEventListener("load", t.step_func_done(() => {
const div = sourceFrame.contentDocument.body.firstChild;
const attrNode = div.getAttributeNode("srcdoc");
div.removeAttributeNode(attrNode);
assert_throws_js(TypeError, () => { targetFrame.setAttributeNode(attrNode); });
}, { once: true }));
}, "Importing a `srcdoc` attribute node created in a non-TT enforcing realm to an iframe throws.")
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<head>
<meta charset="utf-8">
</head>
<body><div srcdoc="v"></div>doc without TT</body>

0 comments on commit 738c5ba

Please sign in to comment.