mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-28 21:26:22 +00:00
LibWeb: Add initial TrustedType WPT tests
This commit is contained in:
parent
5a40115b86
commit
ae3bda993a
Notes:
github-actions[bot]
2025-07-30 14:52:58 +00:00
Author: https://github.com/tete17
Commit: ae3bda993a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5430
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/tcl3 ✅
10 changed files with 617 additions and 0 deletions
|
@ -0,0 +1,99 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 93 tests
|
||||||
|
|
||||||
|
90 Pass
|
||||||
|
3 Fail
|
||||||
|
Pass getAttributeType("dummy", "onabort", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onauxclick", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onbeforeinput", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onbeforematch", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onbeforetoggle", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onblur", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "oncancel", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "oncanplay", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "oncanplaythrough", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onchange", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onclick", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onclose", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "oncommand", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "oncontextlost", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "oncontextmenu", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "oncontextrestored", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "oncopy", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "oncuechange", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "oncut", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "ondblclick", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "ondrag", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "ondragend", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "ondragenter", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "ondragleave", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "ondragover", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "ondragstart", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "ondrop", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "ondurationchange", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onemptied", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onended", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onerror", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onfocus", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onformdata", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "oninput", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "oninvalid", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onkeydown", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onkeypress", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onkeyup", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onload", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onloadeddata", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onloadedmetadata", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onloadstart", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onmousedown", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onmouseenter", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onmouseleave", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onmousemove", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onmouseout", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onmouseover", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onmouseup", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onpaste", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onpause", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onplay", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onplaying", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onprogress", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onratechange", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onreset", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onresize", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onscroll", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onscrollend", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onsecuritypolicyviolation", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onseeked", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onseeking", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onselect", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onslotchange", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onstalled", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onsubmit", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onsuspend", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "ontimeupdate", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "ontoggle", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onvolumechange", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onwaiting", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onwheel", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onafterprint", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onbeforeprint", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onbeforeunload", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onhashchange", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onlanguagechange", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onmessage", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onmessageerror", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onoffline", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "ononline", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onpagehide", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onpagereveal", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onpageshow", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onpageswap", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onpopstate", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onrejectionhandled", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onstorage", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onunhandledrejection", "dummyNs", attrNs)
|
||||||
|
Pass getAttributeType("dummy", "onunload", "dummyNs", attrNs)
|
||||||
|
Fail getAttributeType("dummy", "onbegin", "dummyNs", attrNs)
|
||||||
|
Fail getAttributeType("dummy", "onend", "dummyNs", attrNs)
|
||||||
|
Fail getAttributeType("dummy", "onrepeat", "dummyNs", attrNs)
|
|
@ -0,0 +1,26 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 21 tests
|
||||||
|
|
||||||
|
21 Pass
|
||||||
|
Pass 0: getAttributeType with full namespace info.
|
||||||
|
Pass 0: getAttributeType with element namespace and empty attribute namespace
|
||||||
|
Pass 0: getAttributeType without namespaces.
|
||||||
|
Pass 0: getAttributeType with undefined and empty namespace.
|
||||||
|
Pass 0: getAttributeType with empty and undefined namespace.
|
||||||
|
Pass 0: getAttributeType with empty namespaces.
|
||||||
|
Pass 0: getAttributeType with element namespace and empty attribute namespace.
|
||||||
|
Pass 1: getAttributeType with full namespace info.
|
||||||
|
Pass 1: getAttributeType with element namespace and empty attribute namespace
|
||||||
|
Pass 1: getAttributeType without namespaces.
|
||||||
|
Pass 1: getAttributeType with undefined and empty namespace.
|
||||||
|
Pass 1: getAttributeType with empty and undefined namespace.
|
||||||
|
Pass 1: getAttributeType with empty namespaces.
|
||||||
|
Pass 1: getAttributeType with element namespace and empty attribute namespace.
|
||||||
|
Pass 2: getAttributeType with full namespace info.
|
||||||
|
Pass 2: getAttributeType with element namespace and empty attribute namespace
|
||||||
|
Pass 2: getAttributeType without namespaces.
|
||||||
|
Pass 2: getAttributeType with undefined and empty namespace.
|
||||||
|
Pass 2: getAttributeType with empty and undefined namespace.
|
||||||
|
Pass 2: getAttributeType with empty namespaces.
|
||||||
|
Pass 2: getAttributeType with element namespace and empty attribute namespace.
|
|
@ -0,0 +1,9 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 4 tests
|
||||||
|
|
||||||
|
4 Pass
|
||||||
|
Pass trustedTypes.getAttributeType html script[href]
|
||||||
|
Pass trustedTypes.getAttributeType svg script[href]
|
||||||
|
Pass trustedTypes.getAttributeType svg script[href] xlink href
|
||||||
|
Pass trustedTypes.getAttributeType svg script[href] other href
|
|
@ -0,0 +1,132 @@
|
||||||
|
// GENERATED CONTENT - DO NOT EDIT
|
||||||
|
// Content was automatically extracted by Reffy into webref
|
||||||
|
// (https://github.com/w3c/webref)
|
||||||
|
// Source: Encrypted Media Extensions (https://w3c.github.io/encrypted-media/)
|
||||||
|
|
||||||
|
[Exposed=Window]
|
||||||
|
partial interface Navigator {
|
||||||
|
[SecureContext] Promise<MediaKeySystemAccess> requestMediaKeySystemAccess (
|
||||||
|
DOMString keySystem,
|
||||||
|
sequence<MediaKeySystemConfiguration> supportedConfigurations);
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MediaKeysRequirement {
|
||||||
|
"required",
|
||||||
|
"optional",
|
||||||
|
"not-allowed"
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary MediaKeySystemConfiguration {
|
||||||
|
DOMString label = "";
|
||||||
|
sequence<DOMString> initDataTypes = [];
|
||||||
|
sequence<MediaKeySystemMediaCapability> audioCapabilities = [];
|
||||||
|
sequence<MediaKeySystemMediaCapability> videoCapabilities = [];
|
||||||
|
MediaKeysRequirement distinctiveIdentifier = "optional";
|
||||||
|
MediaKeysRequirement persistentState = "optional";
|
||||||
|
sequence<DOMString> sessionTypes;
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary MediaKeySystemMediaCapability {
|
||||||
|
DOMString contentType = "";
|
||||||
|
DOMString? encryptionScheme = null;
|
||||||
|
DOMString robustness = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
[Exposed=Window, SecureContext] interface MediaKeySystemAccess {
|
||||||
|
readonly attribute DOMString keySystem;
|
||||||
|
MediaKeySystemConfiguration getConfiguration ();
|
||||||
|
Promise<MediaKeys> createMediaKeys ();
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MediaKeySessionType {
|
||||||
|
"temporary",
|
||||||
|
"persistent-license"
|
||||||
|
};
|
||||||
|
|
||||||
|
[Exposed=Window, SecureContext] interface MediaKeys {
|
||||||
|
MediaKeySession createSession (optional MediaKeySessionType sessionType = "temporary");
|
||||||
|
Promise<MediaKeyStatus> getStatusForPolicy (optional MediaKeysPolicy policy = {});
|
||||||
|
Promise<boolean> setServerCertificate (BufferSource serverCertificate);
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary MediaKeysPolicy {
|
||||||
|
DOMString minHdcpVersion;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MediaKeySessionClosedReason {
|
||||||
|
"internal-error",
|
||||||
|
"closed-by-application",
|
||||||
|
"release-acknowledged",
|
||||||
|
"hardware-context-reset",
|
||||||
|
"resource-evicted"
|
||||||
|
};
|
||||||
|
|
||||||
|
[Exposed=Window, SecureContext] interface MediaKeySession : EventTarget {
|
||||||
|
readonly attribute DOMString sessionId;
|
||||||
|
readonly attribute unrestricted double expiration;
|
||||||
|
readonly attribute Promise<MediaKeySessionClosedReason> closed;
|
||||||
|
readonly attribute MediaKeyStatusMap keyStatuses;
|
||||||
|
attribute EventHandler onkeystatuseschange;
|
||||||
|
attribute EventHandler onmessage;
|
||||||
|
Promise<undefined> generateRequest (DOMString initDataType, BufferSource initData);
|
||||||
|
Promise<boolean> load (DOMString sessionId);
|
||||||
|
Promise<undefined> update (BufferSource response);
|
||||||
|
Promise<undefined> close ();
|
||||||
|
Promise<undefined> remove ();
|
||||||
|
};
|
||||||
|
|
||||||
|
[Exposed=Window, SecureContext] interface MediaKeyStatusMap {
|
||||||
|
iterable<BufferSource,MediaKeyStatus>;
|
||||||
|
readonly attribute unsigned long size;
|
||||||
|
boolean has (BufferSource keyId);
|
||||||
|
(MediaKeyStatus or undefined) get (BufferSource keyId);
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MediaKeyStatus {
|
||||||
|
"usable",
|
||||||
|
"expired",
|
||||||
|
"released",
|
||||||
|
"output-restricted",
|
||||||
|
"output-downscaled",
|
||||||
|
"usable-in-future",
|
||||||
|
"status-pending",
|
||||||
|
"internal-error"
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MediaKeyMessageType {
|
||||||
|
"license-request",
|
||||||
|
"license-renewal",
|
||||||
|
"license-release",
|
||||||
|
"individualization-request"
|
||||||
|
};
|
||||||
|
|
||||||
|
[Exposed=Window, SecureContext]
|
||||||
|
interface MediaKeyMessageEvent : Event {
|
||||||
|
constructor(DOMString type, MediaKeyMessageEventInit eventInitDict);
|
||||||
|
readonly attribute MediaKeyMessageType messageType;
|
||||||
|
readonly attribute ArrayBuffer message;
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary MediaKeyMessageEventInit : EventInit {
|
||||||
|
required MediaKeyMessageType messageType;
|
||||||
|
required ArrayBuffer message;
|
||||||
|
};
|
||||||
|
|
||||||
|
[Exposed=Window] partial interface HTMLMediaElement {
|
||||||
|
[SecureContext] readonly attribute MediaKeys? mediaKeys;
|
||||||
|
attribute EventHandler onencrypted;
|
||||||
|
attribute EventHandler onwaitingforkey;
|
||||||
|
[SecureContext] Promise<undefined> setMediaKeys (MediaKeys? mediaKeys);
|
||||||
|
};
|
||||||
|
|
||||||
|
[Exposed=Window]
|
||||||
|
interface MediaEncryptedEvent : Event {
|
||||||
|
constructor(DOMString type, optional MediaEncryptedEventInit eventInitDict = {});
|
||||||
|
readonly attribute DOMString initDataType;
|
||||||
|
readonly attribute ArrayBuffer? initData;
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary MediaEncryptedEventInit : EventInit {
|
||||||
|
DOMString initDataType = "";
|
||||||
|
ArrayBuffer? initData = null;
|
||||||
|
};
|
|
@ -0,0 +1,24 @@
|
||||||
|
<!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="support/namespaces.js"></script>
|
||||||
|
<script type="module">
|
||||||
|
import { getEventHandlerAttributeWithInterfaceNames } from './support/event-handler-attributes.mjs';
|
||||||
|
promise_setup(async function() {
|
||||||
|
for (const attr of await getEventHandlerAttributeWithInterfaceNames()) {
|
||||||
|
promise_test(async () => {
|
||||||
|
NSURI_ARRAY.forEach(attrNs => {
|
||||||
|
assert_equals(trustedTypes.getAttributeType(
|
||||||
|
"dummy", attr.name, NSURI_HTML, attrNs),
|
||||||
|
attrNs === NSURI_EMPTY ? "TrustedScript" : null,
|
||||||
|
`for attrNs='${attrNs}'`);
|
||||||
|
});
|
||||||
|
}, `getAttributeType("dummy", "${attr.name}", "dummyNs", attrNs)`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -0,0 +1,62 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../resources/testharness.js" ></script>
|
||||||
|
<script src="../resources/testharnessreport.js"></script>
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
// Tests for getAttributeType with namespaces, based on
|
||||||
|
// https://crbug.com/1305293 (attachment on comment 0).
|
||||||
|
|
||||||
|
const parser = new DOMParser();
|
||||||
|
[
|
||||||
|
parser.parseFromString(
|
||||||
|
'<!doctype html><html><head><script src="./foo.js"><'+'/script></head></html>',
|
||||||
|
'text/html'),
|
||||||
|
parser.parseFromString(
|
||||||
|
'<html xmlns="http://www.w3.org/1999/xhtml"><head><script src="./foo.js" /></head></html>',
|
||||||
|
'application/xhtml+xml'),
|
||||||
|
parser.parseFromString(
|
||||||
|
'<xml xmlns:html="http://www.w3.org/1999/xhtml"><html:script src="./foo.js" /></xml>',
|
||||||
|
'application/xml')
|
||||||
|
].forEach((doc, index) => {
|
||||||
|
const element = doc.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", 'script')[0];
|
||||||
|
const attribute = element.getAttributeNode("src");
|
||||||
|
|
||||||
|
test(_ => {
|
||||||
|
assert_equals(trustedTypes.getAttributeType(
|
||||||
|
element.localName, attribute.name, element.namespaceURI, attribute.namespaceURI),
|
||||||
|
"TrustedScriptURL");
|
||||||
|
}, `${index}: getAttributeType with full namespace info.`);
|
||||||
|
|
||||||
|
test(_ => {
|
||||||
|
assert_equals(trustedTypes.getAttributeType(
|
||||||
|
element.localName, attribute.name, element.namespaceURI, undefined),
|
||||||
|
"TrustedScriptURL");
|
||||||
|
},`${index}: getAttributeType with element namespace and empty attribute namespace`);
|
||||||
|
|
||||||
|
test(_ => {
|
||||||
|
assert_equals(trustedTypes.getAttributeType(
|
||||||
|
element.localName, attribute.name, undefined, undefined), "TrustedScriptURL");
|
||||||
|
}, `${index}: getAttributeType without namespaces.`);
|
||||||
|
|
||||||
|
test(_ => {
|
||||||
|
assert_equals(trustedTypes.getAttributeType(
|
||||||
|
element.localName, attribute.name, undefined, ""), "TrustedScriptURL");
|
||||||
|
}, `${index}: getAttributeType with undefined and empty namespace.`);
|
||||||
|
|
||||||
|
test(_ => {
|
||||||
|
assert_equals(trustedTypes.getAttributeType(
|
||||||
|
element.localName, attribute.name, "", undefined), "TrustedScriptURL");
|
||||||
|
}, `${index}: getAttributeType with empty and undefined namespace.`);
|
||||||
|
|
||||||
|
test(_ => {
|
||||||
|
assert_equals(trustedTypes.getAttributeType(
|
||||||
|
element.localName, attribute.name, "", ""), "TrustedScriptURL");
|
||||||
|
}, `${index}: getAttributeType with empty namespaces.`);
|
||||||
|
|
||||||
|
test(_ => {
|
||||||
|
assert_equals(trustedTypes.getAttributeType(
|
||||||
|
element.localName, attribute.name, element.namespaceURI, ""), "TrustedScriptURL");
|
||||||
|
}, `${index}: getAttributeType with element namespace and empty attribute namespace.`);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
|
@ -0,0 +1,22 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../resources/testharness.js" ></script>
|
||||||
|
<script src="../resources/testharnessreport.js"></script>
|
||||||
|
<script src="support/helper.sub.js"></script>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="target"></div>
|
||||||
|
<script>
|
||||||
|
test(t => {
|
||||||
|
assert_equals(trustedTypes.getAttributeType("script", "href"), null);
|
||||||
|
}, "trustedTypes.getAttributeType html script[href]");
|
||||||
|
test(t => {
|
||||||
|
assert_equals(trustedTypes.getAttributeType("script", "href", "http://www.w3.org/2000/svg"), "TrustedScriptURL");
|
||||||
|
}, "trustedTypes.getAttributeType svg script[href]");
|
||||||
|
test(t => {
|
||||||
|
assert_equals(trustedTypes.getAttributeType("script", "href", "http://www.w3.org/2000/svg", "http://www.w3.org/1999/xlink"), "TrustedScriptURL");
|
||||||
|
}, "trustedTypes.getAttributeType svg script[href] xlink href");
|
||||||
|
test(t => {
|
||||||
|
assert_equals(trustedTypes.getAttributeType("script", "href", "http://www.w3.org/2000/svg", "http://www.w3.org/other"), null);
|
||||||
|
}, "trustedTypes.getAttributeType svg script[href] other href");
|
||||||
|
</script>
|
||||||
|
</body>
|
|
@ -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 <audio> and <video>) has extra event handlers.
|
||||||
|
addOnAttributes(encryptedMediaIDL, "HTMLMediaElement");
|
||||||
|
|
||||||
|
const svgAnimationsIDL = await (await fetch("../interfaces/svg-animations.idl")).text();
|
||||||
|
// SVGAnimationElement has extra event handlers.
|
||||||
|
addOnAttributes(svgAnimationsIDL, "SVGAnimationElement");
|
||||||
|
|
||||||
|
return attributeNamesWithInterfaceName;
|
||||||
|
}
|
|
@ -0,0 +1,172 @@
|
||||||
|
const INPUTS = {
|
||||||
|
HTML: "Hi, I want to be transformed!",
|
||||||
|
SCRIPT: "Hi, I want to be transformed!",
|
||||||
|
SCRIPTURL: "http://this.is.a.scripturl.test/",
|
||||||
|
};
|
||||||
|
|
||||||
|
const RESULTS = {
|
||||||
|
HTML: "Quack, I want to be a duck!",
|
||||||
|
SCRIPT: "Meow, I want to be a cat!",
|
||||||
|
SCRIPTURL: "http://this.is.a.successful.test/",
|
||||||
|
};
|
||||||
|
|
||||||
|
function createHTMLJS(html) {
|
||||||
|
return html.replace("Hi", "Quack")
|
||||||
|
.replace("transformed", "a duck");
|
||||||
|
}
|
||||||
|
|
||||||
|
function createScriptJS(script) {
|
||||||
|
return script.replace("Hi", "Meow")
|
||||||
|
.replace("transformed", "a cat");
|
||||||
|
}
|
||||||
|
|
||||||
|
function createScriptURLJS(scripturl) {
|
||||||
|
return scripturl.replace("scripturl", "successful");
|
||||||
|
}
|
||||||
|
|
||||||
|
function createHTMLJSWithThreeArguments(html0, html1, html2) {
|
||||||
|
return html0 + html1 + html2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createScriptJSWithThreeArguments(script0, script1, script2) {
|
||||||
|
return script0 + script1 + script2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createScriptURLJSWithThreeArguments(scripturl0, scripturl1, scripturl2) {
|
||||||
|
return scripturl0 + scripturl1 + scripturl2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createHTML_policy(win, c) {
|
||||||
|
return win.trustedTypes.createPolicy('SomeHTMLPolicyName' + c, { createHTML: createHTMLJS });
|
||||||
|
}
|
||||||
|
|
||||||
|
function createScript_policy(win, c) {
|
||||||
|
return win.trustedTypes.createPolicy('SomeScriptPolicyName' + c, { createScript: createScriptJS });
|
||||||
|
}
|
||||||
|
|
||||||
|
function createScriptURL_policy(win, c) {
|
||||||
|
return win.trustedTypes.createPolicy('SomeScriptURLPolicyName' + c, { createScriptURL: createScriptURLJS });
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_trusted_html(win, c, t, tag, attribute, expected) {
|
||||||
|
let p = createHTML_policy(win, c);
|
||||||
|
let html = p.createHTML(INPUTS.HTML);
|
||||||
|
assert_element_accepts_trusted_type(tag, attribute, html, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_trusted_script(win, c, t, tag, attribute, expected) {
|
||||||
|
let p = createScript_policy(win, c);
|
||||||
|
let script = p.createScript(INPUTS.SCRIPT);
|
||||||
|
assert_element_accepts_trusted_type(tag, attribute, script, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_trusted_script_url(win, c, t, tag, attribute, expected) {
|
||||||
|
let p = createScriptURL_policy(win, c);
|
||||||
|
let scripturl = p.createScriptURL(INPUTS.SCRIPTURL);
|
||||||
|
assert_element_accepts_trusted_type(tag, attribute, scripturl, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_trusted_type(tag, attribute, value, expected) {
|
||||||
|
let elem = document.createElement(tag);
|
||||||
|
elem[attribute] = value;
|
||||||
|
assert_equals(elem[attribute] + "", expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_throws_no_trusted_type(tag, attribute, value) {
|
||||||
|
let elem = document.createElement(tag);
|
||||||
|
let prev = elem[attribute];
|
||||||
|
assert_throws_js(TypeError, _ => {
|
||||||
|
elem[attribute] = value;
|
||||||
|
});
|
||||||
|
assert_equals(elem[attribute], prev);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_trusted_html_explicit_set(win, c, t, tag, attribute, expected) {
|
||||||
|
let p = createHTML_policy(win, c);
|
||||||
|
let html = p.createHTML(INPUTS.HTML);
|
||||||
|
assert_element_accepts_trusted_type_explicit_set(tag, attribute, html, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_trusted_script_explicit_set(win, c, t, tag, attribute, expected) {
|
||||||
|
let p = createScript_policy(win, c);
|
||||||
|
let script = p.createScript(INPUTS.SCRIPT);
|
||||||
|
assert_element_accepts_trusted_type_explicit_set(tag, attribute, script, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_trusted_script_url_explicit_set(win, c, t, tag, attribute, expected) {
|
||||||
|
let p = createScriptURL_policy(win, c);
|
||||||
|
let scripturl = p.createScriptURL(INPUTS.SCRIPTURL);
|
||||||
|
assert_element_accepts_trusted_type_explicit_set(tag, attribute, scripturl, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_trusted_type_explicit_set(tag, attribute, value, expected) {
|
||||||
|
let elem = document.createElement(tag);
|
||||||
|
elem.setAttribute(attribute, value);
|
||||||
|
if (!/^on/.test(attribute)) { // "on" attributes are converted to functions.
|
||||||
|
assert_equals(elem[attribute] + "", expected);
|
||||||
|
}
|
||||||
|
assert_equals(elem.getAttribute(attribute), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_throws_no_trusted_type_explicit_set(tag, attribute, value) {
|
||||||
|
let elem = document.createElement(tag);
|
||||||
|
let prev = elem[attribute];
|
||||||
|
assert_throws_js(TypeError, _ => {
|
||||||
|
elem.setAttribute(attribute, value);
|
||||||
|
});
|
||||||
|
assert_equals(elem[attribute], prev);
|
||||||
|
assert_equals(elem.getAttribute(attribute), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_non_trusted_type_explicit_set(tag, attribute, value, expected) {
|
||||||
|
let elem = document.createElement(tag);
|
||||||
|
elem.setAttribute(attribute, value);
|
||||||
|
assert_equals(elem[attribute] + "", expected);
|
||||||
|
assert_equals(elem.getAttribute(attribute), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
let namespace = null;
|
||||||
|
function assert_element_accepts_trusted_html_set_ns(win, c, t, tag, attribute, expected) {
|
||||||
|
let p = createHTML_policy(win, c);
|
||||||
|
let html = p.createHTML(INPUTS.HTML);
|
||||||
|
assert_element_accepts_trusted_type_set_ns(tag, attribute, html, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_trusted_script_set_ns(win, c, t, tag, attribute, expected) {
|
||||||
|
let p = createScript_policy(win, c);
|
||||||
|
let script = p.createScript(INPUTS.SCRIPT);
|
||||||
|
assert_element_accepts_trusted_type_set_ns(tag, attribute, script, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_trusted_script_url_set_ns(win, c, t, tag, attribute, expected) {
|
||||||
|
let p = createScriptURL_policy(win, c);
|
||||||
|
let scripturl = p.createScriptURL(INPUTS.SCRIPTURL);
|
||||||
|
assert_element_accepts_trusted_type_set_ns(tag, attribute, scripturl, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_trusted_type_set_ns(tag, attribute, value, expected) {
|
||||||
|
let elem = document.createElement(tag);
|
||||||
|
elem.setAttributeNS(namespace, attribute, value);
|
||||||
|
let attr_node = elem.getAttributeNodeNS(namespace, attribute);
|
||||||
|
assert_equals(attr_node.value + "", expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_throws_no_trusted_type_set_ns(tag, attribute, value) {
|
||||||
|
let elem = document.createElement(tag);
|
||||||
|
assert_throws_js(TypeError, _ => {
|
||||||
|
elem.setAttributeNS(namespace, attribute, value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_element_accepts_value_set_ns(tag, attribute, value, expected,
|
||||||
|
elementNamespace, attributeNamespace) {
|
||||||
|
let elem = document.createElementNS(elementNamespace, tag);
|
||||||
|
elem.setAttributeNS(attributeNamespace, attribute, value);
|
||||||
|
let attr_node = elem.getAttributeNodeNS(attributeNamespace, attribute);
|
||||||
|
assert_equals(attr_node.value + "", expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGlobalThisStr() {
|
||||||
|
// `globalThis.toString()` is of the form "[Object <someName>]".
|
||||||
|
return globalThis.toString().split(" ")[1].slice(0, -1);
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
const NSURI_EMPTY = '';
|
||||||
|
const NSURI_FOO = 'https://example.com/namespace';
|
||||||
|
const NSURI_HTML = 'http://www.w3.org/1999/xhtml';
|
||||||
|
const NSURI_MATHML = 'http://www.w3.org/1998/Math/MathML';
|
||||||
|
const NSURI_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
|
||||||
|
const NSURI_SVG = 'http://www.w3.org/2000/svg';
|
||||||
|
const NSURI_XLINK = 'http://www.w3.org/1999/xlink';
|
||||||
|
const NSURI_XML = 'http://www.w3.org/XML/1998/namespace';
|
||||||
|
const NSURI_XMLNS = 'http://www.w3.org/XML/1998/namespace';
|
||||||
|
const NSURI_XSLT = 'http://www.w3.org/1999/XSL/Transform';
|
||||||
|
const NSURI_XUL = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
|
||||||
|
const NSURI_ARRAY = [
|
||||||
|
NSURI_EMPTY,
|
||||||
|
NSURI_FOO,
|
||||||
|
NSURI_HTML,
|
||||||
|
NSURI_MATHML,
|
||||||
|
NSURI_RDF,
|
||||||
|
NSURI_SVG,
|
||||||
|
NSURI_XLINK,
|
||||||
|
NSURI_XML,
|
||||||
|
NSURI_XMLNS,
|
||||||
|
NSURI_XSLT,
|
||||||
|
NSURI_XUL,
|
||||||
|
];
|
Loading…
Add table
Add a link
Reference in a new issue