Skip to content

Commit

Permalink
Add WPT tests for getAttributeType with event handler content attribu…
Browse files Browse the repository at this point in the history
…tes.

The spec is not really clear, for now add a tentative test with the
cases detected while implementing the method in Firefox. For details,
see w3c/trusted-types#520

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

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1917783
gecko-commit: 474afb5197ff041a421591d890dd339a2b23fe08
gecko-reviewers: smaug
  • Loading branch information
fred-wang authored and moz-wptsync-bot committed Oct 23, 2024
1 parent da5e743 commit e8f9fad
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<link rel="help" href="https://w3c.github.io/trusted-types/dist/spec/#dom-trustedtypepolicyfactory-getattributetype">
<link rel="help" href="https://w3c.github.io/trusted-types/dist/spec/#abstract-opdef-get-trusted-type-data-for-attribute">
<link rel="help" href="https://github.com/w3c/trusted-types/issues/520">
<meta name="assert" content="getAttributeType() with empty attributeNs returns 'TrustedScript' for event handler content attributes.">
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/WebIDLParser.js"></script>
<script src="support/namespaces.js"></script>
<script>
promise_setup(async function() {
let attributeNames = [];
function addOnAttributes(IDL, interfaceName) {
// Parsing the whole IDL file is slow, so use a small regexp to extract only
// the part that is relevant for this test.
let regexp = new RegExp(`^.*\(partial \)?interface \(mixin \)?${interfaceName}[^{]*{[^{}]*};$`, "m");
let parsedIDL = WebIDL2.parse(IDL.match(regexp)[0]);
parsedIDL.find(idl => idl.name === interfaceName)
.members.map(member => member.name)
.filter(name => name.length >= 3 && name.startsWith("on") &&
!name.startsWith("onwebkit"))
.forEach(name => attributeNames.push(name));
}

const htmlIDL = await (await fetch("/interfaces/html.idl")).text();
["GlobalEventHandlers", "WindowEventHandlers"].forEach(interfaceName => {
addOnAttributes(htmlIDL, interfaceName);
});

const entrypedMediaIDL = await (await fetch("/interfaces/encrypted-media.idl")).text();
addOnAttributes(entrypedMediaIDL, "HTMLMediaElement");

const svgAnimationsIDL = await (await fetch("/interfaces/svg-animations.idl")).text();
addOnAttributes(svgAnimationsIDL, "SVGAnimationElement");

for (const attributeName of attributeNames) {
promise_test(async () => {
NSURI_ARRAY.forEach(attrNs => {
assert_equals(trustedTypes.getAttributeType(
"dummy", attributeName, "dummyNs", attrNs),
attrNs === NSURI_EMPTY ? "TrustedScript" : null,
`for attrNs='${attrNs}'`);
});
}, `getAttributeType("dummy", "${attributeName}", "dummyNs", attrNs)`);
}
});
</script>

0 comments on commit e8f9fad

Please sign in to comment.