diff --git a/trusted-types/TrustedTypePolicyFactory-getAttributeType-event-handler-content-attributes.tentative.html b/trusted-types/TrustedTypePolicyFactory-getAttributeType-event-handler-content-attributes.tentative.html index d8e82ab642b1a8..9dc9e7e6f0a9d2 100644 --- a/trusted-types/TrustedTypePolicyFactory-getAttributeType-event-handler-content-attributes.tentative.html +++ b/trusted-types/TrustedTypePolicyFactory-getAttributeType-event-handler-content-attributes.tentative.html @@ -6,61 +6,19 @@ - - diff --git a/trusted-types/set-event-handlers-content-attributes.tentative.html b/trusted-types/set-event-handlers-content-attributes.tentative.html new file mode 100644 index 00000000000000..0dd5f8b3a08030 --- /dev/null +++ b/trusted-types/set-event-handlers-content-attributes.tentative.html @@ -0,0 +1,67 @@ + + + + + + + + + + diff --git a/trusted-types/support/event-handler-attributes.mjs b/trusted-types/support/event-handler-attributes.mjs new file mode 100644 index 00000000000000..8d54524950b9c0 --- /dev/null +++ b/trusted-types/support/event-handler-attributes.mjs @@ -0,0 +1,47 @@ +import '/resources/WebIDLParser.js'; + +export async function getEventHandlerAttributeWithInterfaceNames() { + let attributeNamesWithInterfaceName = []; + function isAttributeImplemented(interfaceName, name) { + switch (interfaceName) { + case 'GlobalEventHandlers': + return name in HTMLElement.prototype; + case 'WindowEventHandlers': + return name in HTMLBodyElement.prototype; + case 'HTMLMediaElement': + return name in HTMLMediaElement.prototype; + case 'SVGAnimationElement': + return name in SVGAnimationElement.prototype; + default: + throw "Unknown interface"; + } + } + 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") && + isAttributeImplemented(interfaceName, name)) + .forEach(name => attributeNamesWithInterfaceName.push({name, interfaceName})); + } + const htmlIDL = await (await fetch("/interfaces/html.idl")).text(); + // GlobalEventHandlers exist on HTMLElement, SVGElement, and MathMLElement. + // WindowEventHandlers exist on HTMLBodyElement, and HTMLFrameSetElement. + ["GlobalEventHandlers", "WindowEventHandlers"].forEach(interfaceName => { + addOnAttributes(htmlIDL, interfaceName); + }); + + const encryptedMediaIDL = await (await fetch("/interfaces/encrypted-media.idl")).text(); + // HTMLMediaElement (the parent for