-
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.
Add WPT tests for getAttributeType with event handler content attribu…
…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
1 parent
6dc74e8
commit fc84b07
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...TrustedTypePolicyFactory-getAttributeType-event-handler-content-attributes.tentative.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,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> |