diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/dom/xslt | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/dom/xslt')
9 files changed, 431 insertions, 0 deletions
diff --git a/testing/web-platform/tests/dom/xslt/README.md b/testing/web-platform/tests/dom/xslt/README.md new file mode 100644 index 0000000000..ac713ce179 --- /dev/null +++ b/testing/web-platform/tests/dom/xslt/README.md @@ -0,0 +1,11 @@ +# XSLT + +This directory contains tentative tests for [XSLT](https://dom.spec.whatwg.org/#xslt). + +See [whatwg/dom#181](https://github.com/whatwg/dom/issues/181) for getting XSLT +better specified. + +There are additional details on XSLT in HTML: +- [Interactions with XPath and XSLT](https://html.spec.whatwg.org/multipage/infrastructure.html#interactions-with-xpath-and-xslt) +- [Interaction of `script` elements and XSLT](https://html.spec.whatwg.org/multipage/scripting.html#scriptTagXSLT) (non-normative) +- [Interaction of `template` elements with XSLT and XPath](https://html.spec.whatwg.org/multipage/scripting.html#template-XSLT-XPath) (non-normative) diff --git a/testing/web-platform/tests/dom/xslt/externalScript.js b/testing/web-platform/tests/dom/xslt/externalScript.js new file mode 100644 index 0000000000..7a2bf36225 --- /dev/null +++ b/testing/web-platform/tests/dom/xslt/externalScript.js @@ -0,0 +1 @@ +window.externalScript = true; diff --git a/testing/web-platform/tests/dom/xslt/functions.tentative.window.js b/testing/web-platform/tests/dom/xslt/functions.tentative.window.js new file mode 100644 index 0000000000..81240022dc --- /dev/null +++ b/testing/web-platform/tests/dom/xslt/functions.tentative.window.js @@ -0,0 +1,252 @@ +const xslt_functions = [ + "QName", + "abs", + "accumulator-after", + "accumulator-before", + "adjust-date-to-timezone", + "adjust-dateTime-to-timezone", + "adjust-time-to-timezone", + "analyze-string", + "apply", + "available-environment-variables", + "available-system-properties", + "avg", + "base-uri", + "boolean", + "ceiling", + "codepoint-equal", + "codepoints-to-string", + "collation-key", + "collection", + "compare", + "concat", + "contains", + "contains-token", + "copy-of", + "count", + "current", + "current-date", + "current-dateTime", + "current-group", + "current-grouping-key", + "current-merge-group", + "current-merge-key", + "current-output-uri", + "current-time", + "data", + "dateTime", + "day-from-date", + "day-from-dateTime", + "days-from-duration", + "deep-equal", + "default-collation", + "default-language", + "distinct-values", + "doc", + "doc-available", + "document", + "document-uri", + "element-available", + "element-with-id", + "empty", + "encode-for-uri", + "ends-with", + "environment-variable", + "error", + "escape-html-uri", + "exactly-one", + "exists", + "false", + "filter", + "floor", + "fold-left", + "fold-right", + "for-each", + "for-each-pair", + "format-date", + "format-dateTime", + "format-integer", + "format-number", + "format-time", + "function-arity", + "function-available", + "function-lookup", + "function-name", + "generate-id", + "has-children", + "head", + "hours-from-dateTime", + "hours-from-duration", + "hours-from-time", + "id", + "idref", + "implicit-timezone", + "in-scope-prefixes", + "index-of", + "innermost", + "insert-before", + "iri-to-uri", + "json-doc", + "json-to-xml", + "key", + "lang", + "last", + "load-xquery-module", + "local-name", + "local-name-from-QName", + "lower-case", + "matches", + "max", + "min", + "minutes-from-dateTime", + "minutes-from-duration", + "minutes-from-time", + "month-from-date", + "month-from-dateTime", + "months-from-duration", + "name", + "namespace-uri", + "namespace-uri-for-prefix", + "namespace-uri-from-QName", + "nilled", + "node-name", + "normalize-space", + "normalize-unicode", + "not", + "number", + "one-or-more", + "outermost", + "parse-ietf-date", + "parse-json", + "parse-xml", + "parse-xml-fragment", + "path", + "position", + "prefix-from-QName", + "put", + "random-number-generator", + "regex-group", + "remove", + "replace", + "resolve-QName", + "resolve-uri", + "reverse", + "root", + "round", + "round-half-to-even", + "seconds-from-dateTime", + "seconds-from-duration", + "seconds-from-time", + "serialize", + "snapshot", + "sort", + "starts-with", + "static-base-uri", + "stream-available", + "string", + "string-join", + "string-length", + "string-to-codepoints", + "subsequence", + "substring", + "substring-after", + "substring-before", + "sum", + "system-property", + "tail", + "timezone-from-date", + "timezone-from-dateTime", + "timezone-from-time", + "tokenize", + "trace", + "transform", + "translate", + "true", + "type-available", + "unordered", + "unparsed-entity-public-id", + "unparsed-entity-uri", + "unparsed-text", + "unparsed-text-available", + "unparsed-text-lines", + "upper-case", + "uri-collection", + "xml-to-json", + "year-from-date", + "year-from-dateTime", + "years-from-duration", + "zero-or-one", +]; + +const xslt1_functions = [ + "boolean", + "ceiling", + "concat", + "contains", + "count", + "current", + "document", + "element-available", + "false", + "floor", + "format-number", + "function-available", + "generate-id", + "id", + "key", + "lang", + "last", + "local-name", + "name", + "namespace-uri", + "normalize-space", + "not", + "number", + "position", + "round", + "starts-with", + "string", + "string-length", + "substring", + "substring-after", + "substring-before", + "sum", + "system-property", + "translate", + "true", + "unparsed-entity-uri", +]; + +for (const fn of xslt_functions) { + test(() => { + const xsltSrc = `<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> +<xsl:output method="html" encoding="utf-8" version="5"/> +<xsl:template match="/"> + <xsl:choose> + <xsl:when test='function-available("${fn}")'> + <div>available</div> + </xsl:when> + <xsl:otherwise> + <div>unavailable</div> + </xsl:otherwise> + </xsl:choose> +</xsl:template> +</xsl:stylesheet>`; + + const processor = new XSLTProcessor(); + const parser = new DOMParser(); + processor.importStylesheet( + parser.parseFromString(xsltSrc, "application/xml") + ); + const output = processor.transformToFragment( + parser.parseFromString("<x/>", "application/xml"), + document + ); + + // Note we only expect functions defined in XSLT 1.0 to be defined. + assert_equals( + output.textContent.trim(), + xslt1_functions.indexOf(fn) >= 0 ? "available" : "unavailable" + ); + }, fn); +} diff --git a/testing/web-platform/tests/dom/xslt/invalid-output-encoding-crash.html b/testing/web-platform/tests/dom/xslt/invalid-output-encoding-crash.html new file mode 100644 index 0000000000..d84bb5b3c3 --- /dev/null +++ b/testing/web-platform/tests/dom/xslt/invalid-output-encoding-crash.html @@ -0,0 +1,26 @@ +<body> + +<script id=o_xml type="text/plain"> + <?xml version="1.0" encoding="UTF-8"?> +</script> + +<script id=o_xslt type="text/plain"><?xml version="1.0" encoding="UTF-8"?> + <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + <xsl:output indent="no" omit-xml-declaration="no" encoding="bad-encoding" standalone="yes" /> + </xsl:transform> +</script> + +<script> +addEventListener("load", function() { + const doc = new DOMParser(); + const xml = doc.parseFromString(o_xml.textContent, "text/xml"); + const xsl = doc.parseFromString(o_xslt.textContent, "text/xml"); + const xsltPrs = new XSLTProcessor(); + xsltPrs.importStylesheet(xsl); + xsltPrs.transformToDocument(xml); + + document.body.appendChild(document.createTextNode("PASS: renderer didn't crash")); +}); +</script> + +</body> diff --git a/testing/web-platform/tests/dom/xslt/sort-ref.html b/testing/web-platform/tests/dom/xslt/sort-ref.html new file mode 100644 index 0000000000..163002d0d0 --- /dev/null +++ b/testing/web-platform/tests/dom/xslt/sort-ref.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<link rel=author href="mailto:jarhar@chromium.org"> +<link rel=help href="https://bugs.chromium.org/p/chromium/issues/detail?id=1399858"> + +<div> + <div>1</div> + <div>2</div> + <div>3</div> + <div>7</div> +</div> diff --git a/testing/web-platform/tests/dom/xslt/sort.html b/testing/web-platform/tests/dom/xslt/sort.html new file mode 100644 index 0000000000..631c3edd6a --- /dev/null +++ b/testing/web-platform/tests/dom/xslt/sort.html @@ -0,0 +1,48 @@ +<!DOCTYPE html> +<link rel=match href="sort-ref.html"> + +<body> + <div id="container"></div> +</body> + +<script type="text/xml" id="sampleXml"> + <root> + <node id="1" /> + <node id="7" /> + <node id="3" /> + <node id="2" /> + </root> +</script> + +<script type="text/xml" id="sampleXsl"> + <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"> + + <xsl:template match="/"> + <xsl:apply-templates select="//node"> + <xsl:sort select="@id" data-type="number" /> + </xsl:apply-templates> + </xsl:template> + + <xsl:template match="node"> + <div> + <xsl:value-of select="@id"/> + </div> + </xsl:template> + + </xsl:stylesheet> +</script> + +<script> + let parser = new DOMParser(); + const xslStyleSheet = parser.parseFromString(document.getElementById('sampleXsl').textContent, 'text/xml'); + + const xsltProcessor = new XSLTProcessor(); + xsltProcessor.importStylesheet(xslStyleSheet); + + parser = new DOMParser(); + const xmlDoc = parser.parseFromString(document.getElementById('sampleXml').textContent, 'text/xml'); + + const fragment = xsltProcessor.transformToFragment(xmlDoc, document); + + document.getElementById('container').appendChild(fragment); +</script> diff --git a/testing/web-platform/tests/dom/xslt/strip-space-crash.xml b/testing/web-platform/tests/dom/xslt/strip-space-crash.xml new file mode 100644 index 0000000000..61a906a5e7 --- /dev/null +++ b/testing/web-platform/tests/dom/xslt/strip-space-crash.xml @@ -0,0 +1,33 @@ +<?xml-stylesheet type="text/xsl" href="#style"?> +<xsl:stylesheet + version="1.0" + xml:id="style" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:exsl="http://exslt.org/common" + extension-element-prefixes="exsl" +> + <xsl:strip-space elements="s"/> + + <xsl:template match="/"> + <xsl:variable name="space"> + <s> + <xsl:text> </xsl:text> + <e/> + <xsl:text> </xsl:text> + <e/> + <xsl:text> </xsl:text> + </s> + </xsl:variable> + <xsl:apply-templates select="exsl:node-set($space)/s"/> + </xsl:template> + + <xsl:template match="s"> + <r> + <xsl:variable name="text-nodes" select="text()"/> + <xsl:apply-templates/> + <xsl:copy-of select="$text-nodes"/> + </r> + </xsl:template> + + <xsl:template match="node()"/> +</xsl:stylesheet> diff --git a/testing/web-platform/tests/dom/xslt/transformToFragment-on-node-from-inactive-document-crash.html b/testing/web-platform/tests/dom/xslt/transformToFragment-on-node-from-inactive-document-crash.html new file mode 100644 index 0000000000..38a62a0a9d --- /dev/null +++ b/testing/web-platform/tests/dom/xslt/transformToFragment-on-node-from-inactive-document-crash.html @@ -0,0 +1,11 @@ +<body> +<iframe id=i></iframe> +<script> +var el = i.contentDocument.documentElement; +i.remove() +var x = new XSLTProcessor(); +var xsl =new DOMParser().parseFromString('<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"/>','application/xml'); +x.importStylesheet(xsl); +x.transformToDocument(el); +</script> +</body> diff --git a/testing/web-platform/tests/dom/xslt/transformToFragment.tentative.window.js b/testing/web-platform/tests/dom/xslt/transformToFragment.tentative.window.js new file mode 100644 index 0000000000..7bb6a56855 --- /dev/null +++ b/testing/web-platform/tests/dom/xslt/transformToFragment.tentative.window.js @@ -0,0 +1,39 @@ +const cases = { + internal: '<script>window.internalScript = true;</script>', + external: '<script src="externalScript.js"></script>', +}; + +const loaded = new Promise(resolve => { + window.addEventListener('load', resolve); +}); + +Object.entries(cases).forEach(([k, v]) => { + const xsltSrc = `<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> +<xsl:output method="html" encoding="utf-8" version="5"/> +<xsl:template match="/"> + <section> + ${v} + </section> +</xsl:template> +</xsl:stylesheet>`; + + const processor = new XSLTProcessor(); + const parser = new DOMParser(); + processor.importStylesheet( + parser.parseFromString(xsltSrc, 'application/xml') + ); + document.body.appendChild( + processor.transformToFragment( + parser.parseFromString('<x/>', 'application/xml'), + document + ) + ); + + promise_test(async () => { + await loaded; + assert_true( + window[`${k}Script`], + 'script element from XSLTProcessor.transformToFragment() is evaluated' + ); + }, `${k} script`); +}) |