Skip to content

Commit

Permalink
part 5) Add WPT <Element-setAttribute-respects-Elements-node-document…
Browse files Browse the repository at this point in the history
…s-globals-CSP-after-adoption-from-TT-realm.html>.

Replaces <#46432>.

Differential Revision: https://phabricator.services.mozilla.com/D231921

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1907849
gecko-commit: 5a48fdcefee755d543af0a415b6e1e216c853845
gecko-reviewers: smaug
  • Loading branch information
mbrodesser-Igalia authored and moz-wptsync-bot committed Dec 13, 2024
1 parent 34c9a72 commit fc0f781
Showing 1 changed file with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
const iframeSrcdoc = `
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta
http-equiv="Content-Security-Policy"
content="require-trusted-types-for 'script'"
/>
</head>
<body>
<div id="nonSVGTestElements">
<iframe id="iframe.srcdoc" srcdoc="v"></iframe>
<script id="script.src" src="v"><\/script>
</div>
<svg id="svgTestElements">
<script id="script.href" href="v"><\/script>
<script id="script.xlink:href" xlink:href="v"><\/script>
</svg>
</body>`;

const testCases = [
['iframe', 'srcdoc'],
['script', 'src'],
['script', 'href'],
['script', 'xlink:href'],
];

const sourceFrame = document.createElement("iframe");
sourceFrame.srcdoc = iframeSrcdoc;
document.body.append(sourceFrame);

sourceFrame.addEventListener("load", () => {
testCases.forEach(testCase => {
async_test(t => {
t.step_func_done(() => {
const elementId = testCase.join(".");
const sourceElement =
sourceFrame.contentWindow.document.getElementById(elementId);
const sourceAttr = sourceElement.getAttributeNode(testCase[1]);
sourceElement.removeAttributeNode(sourceAttr);

document.body.append(sourceElement);
// Now `sourceElement`'s node document's global should belong to
// a non-TT realm.
// Hence, below calls of `setAttributeNode` and `setAttributeNS`
// should not throw.
// See the analogous test
// <Element-setAttribute-respects-Elements-node-documents-globals-CSP-after-adoption-from-TT-realm.html>
// for details about the relevant specs.

sourceElement.setAttributeNode(sourceAttr);
sourceElement.setAttributeNS(sourceAttr.namespaceURI,
sourceAttr.name, sourceAttr.value);

assert_true(true,
"Neither `setAttributeNode` nor `setAttributeNS` threw");
})();
}, `Trusted types are not enforced for setAttributeNode and
setAttributeNS after moving the target node from a TT-realm to a
non-TT realm for ${testCase[0]}.${testCase[1]}`);
});
});
</script>
</body>
</html>

0 comments on commit fc0f781

Please sign in to comment.