|
| 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