Skip to content

Commit e8f9fad

Browse files
fred-wangmoz-wptsync-bot
authored andcommittedOct 23, 2024
Add WPT tests for getAttributeType with event handler content attributes.
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
1 parent da5e743 commit e8f9fad

1 file changed

+48
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE html>
2+
<link rel="help" href="https://w3c.github.io/trusted-types/dist/spec/#dom-trustedtypepolicyfactory-getattributetype">
3+
<link rel="help" href="https://w3c.github.io/trusted-types/dist/spec/#abstract-opdef-get-trusted-type-data-for-attribute">
4+
<link rel="help" href="https://github.com/w3c/trusted-types/issues/520">
5+
<meta name="assert" content="getAttributeType() with empty attributeNs returns 'TrustedScript' for event handler content attributes.">
6+
<meta name="timeout" content="long">
7+
<script src="/resources/testharness.js"></script>
8+
<script src="/resources/testharnessreport.js"></script>
9+
<script src="/resources/WebIDLParser.js"></script>
10+
<script src="support/namespaces.js"></script>
11+
<script>
12+
promise_setup(async function() {
13+
let attributeNames = [];
14+
function addOnAttributes(IDL, interfaceName) {
15+
// Parsing the whole IDL file is slow, so use a small regexp to extract only
16+
// the part that is relevant for this test.
17+
let regexp = new RegExp(`^.*\(partial \)?interface \(mixin \)?${interfaceName}[^{]*{[^{}]*};$`, "m");
18+
let parsedIDL = WebIDL2.parse(IDL.match(regexp)[0]);
19+
parsedIDL.find(idl => idl.name === interfaceName)
20+
.members.map(member => member.name)
21+
.filter(name => name.length >= 3 && name.startsWith("on") &&
22+
!name.startsWith("onwebkit"))
23+
.forEach(name => attributeNames.push(name));
24+
}
25+
26+
const htmlIDL = await (await fetch("/interfaces/html.idl")).text();
27+
["GlobalEventHandlers", "WindowEventHandlers"].forEach(interfaceName => {
28+
addOnAttributes(htmlIDL, interfaceName);
29+
});
30+
31+
const entrypedMediaIDL = await (await fetch("/interfaces/encrypted-media.idl")).text();
32+
addOnAttributes(entrypedMediaIDL, "HTMLMediaElement");
33+
34+
const svgAnimationsIDL = await (await fetch("/interfaces/svg-animations.idl")).text();
35+
addOnAttributes(svgAnimationsIDL, "SVGAnimationElement");
36+
37+
for (const attributeName of attributeNames) {
38+
promise_test(async () => {
39+
NSURI_ARRAY.forEach(attrNs => {
40+
assert_equals(trustedTypes.getAttributeType(
41+
"dummy", attributeName, "dummyNs", attrNs),
42+
attrNs === NSURI_EMPTY ? "TrustedScript" : null,
43+
`for attrNs='${attrNs}'`);
44+
});
45+
}, `getAttributeType("dummy", "${attributeName}", "dummyNs", attrNs)`);
46+
}
47+
});
48+
</script>

0 commit comments

Comments
 (0)
Please sign in to comment.