-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
part 5) Add WPT <Element-setAttribute-respects-Elements-node-document…
…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
1 parent
34c9a72
commit fc0f781
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...tAttribute-respects-Elements-node-documents-globals-CSP-after-adoption-from-TT-realm.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |