summaryrefslogtreecommitdiffstats
path: root/dom/xslt/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/xslt/tests
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/xslt/tests')
-rw-r--r--dom/xslt/tests/browser/browser.toml8
-rw-r--r--dom/xslt/tests/browser/browser_bug1309630.js74
-rw-r--r--dom/xslt/tests/browser/bug1309630.sjs54
-rw-r--r--dom/xslt/tests/browser/file_bug1309630.html19
-rw-r--r--dom/xslt/tests/mochitest/bug1729517_2.sjs3
-rw-r--r--dom/xslt/tests/mochitest/file_bug1135764.xml3
-rw-r--r--dom/xslt/tests/mochitest/file_bug1135764.xsl19
-rw-r--r--dom/xslt/tests/mochitest/file_bug1729517.js4
-rw-r--r--dom/xslt/tests/mochitest/file_bug1729517.xml31
-rw-r--r--dom/xslt/tests/mochitest/file_bug1729517_2.xml38
-rw-r--r--dom/xslt/tests/mochitest/file_bug1729517_2.xml^headers^2
-rw-r--r--dom/xslt/tests/mochitest/file_metaRefresh.xml16
-rw-r--r--dom/xslt/tests/mochitest/mochitest.toml57
-rw-r--r--dom/xslt/tests/mochitest/test_bug1072116.html37
-rw-r--r--dom/xslt/tests/mochitest/test_bug1135764.html58
-rw-r--r--dom/xslt/tests/mochitest/test_bug1436040.html54
-rw-r--r--dom/xslt/tests/mochitest/test_bug1527308.html38
-rw-r--r--dom/xslt/tests/mochitest/test_bug1729517.html48
-rw-r--r--dom/xslt/tests/mochitest/test_bug319374.html101
-rw-r--r--dom/xslt/tests/mochitest/test_bug427060.html49
-rw-r--r--dom/xslt/tests/mochitest/test_bug440974.html46
-rw-r--r--dom/xslt/tests/mochitest/test_bug453441.html57
-rw-r--r--dom/xslt/tests/mochitest/test_bug468208.html35
-rw-r--r--dom/xslt/tests/mochitest/test_bug511487.html59
-rw-r--r--dom/xslt/tests/mochitest/test_bug551412.html48
-rw-r--r--dom/xslt/tests/mochitest/test_bug551654.html49
-rw-r--r--dom/xslt/tests/mochitest/test_bug566629.html70
-rw-r--r--dom/xslt/tests/mochitest/test_bug566629.xhtml73
-rw-r--r--dom/xslt/tests/mochitest/test_bug603159.html54
-rw-r--r--dom/xslt/tests/mochitest/test_bug616774.html28
-rw-r--r--dom/xslt/tests/mochitest/test_bug667315.html46
-rw-r--r--dom/xslt/tests/mochitest/test_exslt.html249
-rw-r--r--dom/xslt/tests/mochitest/test_metaRefresh.html48
-rw-r--r--dom/xslt/tests/mochitest/test_parameter.html157
-rw-r--r--dom/xslt/tests/mochitest/test_sorting_invalid_lang.html82
35 files changed, 1814 insertions, 0 deletions
diff --git a/dom/xslt/tests/browser/browser.toml b/dom/xslt/tests/browser/browser.toml
new file mode 100644
index 0000000000..03962f02b5
--- /dev/null
+++ b/dom/xslt/tests/browser/browser.toml
@@ -0,0 +1,8 @@
+[DEFAULT]
+
+["browser_bug1309630.js"]
+skip-if = ["true"] # Bug 1776052
+support-files = [
+ "bug1309630.sjs",
+ "file_bug1309630.html",
+]
diff --git a/dom/xslt/tests/browser/browser_bug1309630.js b/dom/xslt/tests/browser/browser_bug1309630.js
new file mode 100644
index 0000000000..0056870fd9
--- /dev/null
+++ b/dom/xslt/tests/browser/browser_bug1309630.js
@@ -0,0 +1,74 @@
+"use strict";
+
+const BASE = "https://example.com/browser/dom/xslt/tests/browser";
+const SERVER_SCRIPT = `${BASE}/bug1309630.sjs`;
+
+function resetCounter() {
+ return fetch(`${SERVER_SCRIPT}?reset_counter`);
+}
+function recordCounter() {
+ return fetch(`${SERVER_SCRIPT}?record_counter`);
+}
+// Returns a promise that resolves to true if the counter in
+// bug1309630.sjs changed by more than 'value' since last calling
+// recordCounter(), or false if it doesn't and we time out.
+function waitForCounterChangeAbove(value) {
+ return TestUtils.waitForCondition(() =>
+ fetch(`${SERVER_SCRIPT}?get_counter_change`).then(response =>
+ response.ok
+ ? response.text().then(str => Number(str) > value)
+ : Promise.reject()
+ )
+ ).then(
+ () => true,
+ () => false
+ );
+}
+
+add_task(async function test_eternal_xslt() {
+ await resetCounter();
+ await BrowserTestUtils.withNewTab(
+ { gBrowser, url: SERVER_SCRIPT, waitForLoad: false },
+ async function (browser) {
+ info("Waiting for XSLT to keep loading");
+
+ ok(
+ await waitForCounterChangeAbove(1),
+ "We should receive at least a request from the document function call."
+ );
+
+ info("Navigating to about:blank");
+ BrowserTestUtils.startLoadingURIString(browser, "about:blank");
+ await BrowserTestUtils.browserLoaded(browser);
+
+ info("Check to see if XSLT stops loading");
+ await recordCounter();
+ ok(
+ !(await waitForCounterChangeAbove(0)),
+ "We shouldn't receive more requests to the XSLT file within the timeout period."
+ );
+ }
+ );
+
+ await resetCounter();
+ await BrowserTestUtils.withNewTab(
+ { gBrowser, url: `${BASE}/file_bug1309630.html` },
+ async function (browser) {
+ ok(
+ await waitForCounterChangeAbove(1),
+ "We should receive at least a request from the document function call."
+ );
+
+ info("Navigating to about:blank");
+ BrowserTestUtils.startLoadingURIString(browser, "about:blank");
+ await BrowserTestUtils.browserLoaded(browser);
+
+ info("Check to see if XSLT stops loading");
+ await recordCounter();
+ ok(
+ !(await waitForCounterChangeAbove(0)),
+ "We shouldn't receive more requests to the XSLT file within the timeout period."
+ );
+ }
+ );
+});
diff --git a/dom/xslt/tests/browser/bug1309630.sjs b/dom/xslt/tests/browser/bug1309630.sjs
new file mode 100644
index 0000000000..9a3f464139
--- /dev/null
+++ b/dom/xslt/tests/browser/bug1309630.sjs
@@ -0,0 +1,54 @@
+function handleRequest(request, response) {
+ const XSLT = `<?xml version="1.0"?>
+ <?xml-stylesheet type="text/xsl" href="#bug"?>
+ <xsl:stylesheet id="bug" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:template name="f" match="/">
+ <xsl:param name="n" select="0" />
+ <xsl:apply-templates select="document(concat('${request.path}?', $n))/xsl:stylesheet/xsl:template[@name='f']">
+ <xsl:with-param name="n" select="$n + 1"/>
+ </xsl:apply-templates>
+ <xsl:call-template name="f">
+ <xsl:with-param name="n" select="$n + 1"/>
+ </xsl:call-template>
+ </xsl:template>
+ </xsl:stylesheet>`;
+
+ // reset_counter sets the counter to -1.
+ if (request.queryString === "reset_counter") {
+ setState("base", "-1");
+ response.write("");
+ return;
+ }
+
+ // record_counter makes us store the current value of the counter.
+ if (request.queryString === "record_counter") {
+ setState("base", getState("counter"));
+ response.write("");
+ return;
+ }
+
+ // get_counter_change returns the difference between the current
+ // value of the counter and the value it had when the script was
+ // loaded with the record_counter query string.
+ if (request.queryString === "get_counter_change") {
+ response.write(
+ String(Number(getState("counter")) - Number(getState("base")))
+ );
+ return;
+ }
+
+ // The XSLT code calls the document() function with a URL pointing to
+ // this script, with the query string set to a counter starting from 0
+ // and incremementing with every call of the document() function.
+ // The first load will happen either from the xml-stylesheet PI, or
+ // with fetch(), to parse a document to pass to
+ // XSLTProcessor.importStylesheet. In that case the query string will
+ // be empty, and we don't change the counter value, we only care about
+ // the loads through the document() function.
+ if (request.queryString) {
+ setState("counter", request.queryString);
+ }
+
+ response.setHeader("Content-Type", "text/xml; charset=utf-8", false);
+ response.write(XSLT);
+}
diff --git a/dom/xslt/tests/browser/file_bug1309630.html b/dom/xslt/tests/browser/file_bug1309630.html
new file mode 100644
index 0000000000..c22889358c
--- /dev/null
+++ b/dom/xslt/tests/browser/file_bug1309630.html
@@ -0,0 +1,19 @@
+<script>
+ let styleDoc = fetch("bug1309630.sjs")
+ .then(response => {
+ if (response.ok) {
+ return response.text();
+ }
+ return Promise.reject();
+ }).then(xslt => {
+ let styleDoc = new DOMParser().parseFromString(xslt, "text/xml");
+ let originalDoc = new DOMParser().parseFromString(
+ "<root/>",
+ "text/xml"
+ );
+
+ let processor = new XSLTProcessor();
+ processor.importStylesheet(styleDoc);
+ processor.transformToDocument(originalDoc);
+ });
+</script>>
diff --git a/dom/xslt/tests/mochitest/bug1729517_2.sjs b/dom/xslt/tests/mochitest/bug1729517_2.sjs
new file mode 100644
index 0000000000..2537a971b0
--- /dev/null
+++ b/dom/xslt/tests/mochitest/bug1729517_2.sjs
@@ -0,0 +1,3 @@
+function handleRequest(request, response) {
+ response.write(request.hasHeader("Referer") ? "FAIL" : "PASS");
+}
diff --git a/dom/xslt/tests/mochitest/file_bug1135764.xml b/dom/xslt/tests/mochitest/file_bug1135764.xml
new file mode 100644
index 0000000000..b9da87e5e5
--- /dev/null
+++ b/dom/xslt/tests/mochitest/file_bug1135764.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?xml-stylesheet type="text/xsl" href="file_bug1135764.xsl"?>
+<root/>
diff --git a/dom/xslt/tests/mochitest/file_bug1135764.xsl b/dom/xslt/tests/mochitest/file_bug1135764.xsl
new file mode 100644
index 0000000000..e739086cbe
--- /dev/null
+++ b/dom/xslt/tests/mochitest/file_bug1135764.xsl
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:output method="html"
+ indent="yes"
+ version="5.0"
+ doctype-system="about:legacy-compat"/>
+
+<xsl:template match="/">
+<html>
+<head>
+</head>
+ <body>
+ Some text
+ </body>
+</html>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/dom/xslt/tests/mochitest/file_bug1729517.js b/dom/xslt/tests/mochitest/file_bug1729517.js
new file mode 100644
index 0000000000..b404dc6778
--- /dev/null
+++ b/dom/xslt/tests/mochitest/file_bug1729517.js
@@ -0,0 +1,4 @@
+/* global fail */
+fail(
+ "documents sandboxed without allow-scripts should NOT be able to run <script src=...>"
+);
diff --git a/dom/xslt/tests/mochitest/file_bug1729517.xml b/dom/xslt/tests/mochitest/file_bug1729517.xml
new file mode 100644
index 0000000000..48658468fc
--- /dev/null
+++ b/dom/xslt/tests/mochitest/file_bug1729517.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
+<!DOCTYPE root [
+ <!ATTLIST xsl:stylesheet id ID #IMPLIED>
+]>
+<root>
+ <xsl:stylesheet id="stylesheet" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ <xsl:template match="/">
+ <html>
+ <head>
+ <title>[]</title>
+ <script type="text/javascript">
+ let failed = [];
+ function fail(desc) {
+ failed.push(desc);
+ document.title = JSON.stringify(failed);
+ }
+
+ function doStuff() {
+ fail("documents sandboxed without allow-scripts should NOT be able to run inline scripts");
+ }
+ </script>
+ <script src="file_bug1729517.js" />
+ </head>
+ <body onload="fail('documents sandboxed without allow-scripts should NOT be able to run script from event handlers'); doStuff();">
+ <img src="about:blank" onerror="fail('documents sandboxed without allow-scripts should NOT be able to run script from event handlers');" />
+ </body>
+ </html>
+ </xsl:template>
+</xsl:stylesheet>
+</root>
diff --git a/dom/xslt/tests/mochitest/file_bug1729517_2.xml b/dom/xslt/tests/mochitest/file_bug1729517_2.xml
new file mode 100644
index 0000000000..5d706e7a05
--- /dev/null
+++ b/dom/xslt/tests/mochitest/file_bug1729517_2.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
+<!DOCTYPE root [
+ <!ATTLIST xsl:stylesheet id ID #IMPLIED>
+]>
+<root>
+ <xsl:stylesheet id="stylesheet" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ <xsl:template match="/">
+ <html>
+ <head>
+ <title>[]</title>
+ <script type="text/javascript">
+ async function checkCOEPAndReferrer() {
+ let results = new Map();
+
+ let win = window.open();
+ result = win.fetch("https://example.org/tests/dom/xslt/tests/mochitest/bug1729517_2.sjs", { mode: "no-cors" }).then(() => {
+ return "FAIL";
+ }, () => {
+ return "PASS";
+ });
+ results.set("Cross-Origin-Embedder-Policy", await result);
+ win.close();
+
+ result = fetch("bug1729517_2.sjs").then((response) => {
+ return response.text();
+ });
+ results.set("Referrer-Policy", await result || "FAIL");
+
+ window.opener.postMessage(results, "*");
+ }
+ </script>
+ </head>
+ <body onload="checkCOEPAndReferrer()" />
+ </html>
+ </xsl:template>
+</xsl:stylesheet>
+</root>
diff --git a/dom/xslt/tests/mochitest/file_bug1729517_2.xml^headers^ b/dom/xslt/tests/mochitest/file_bug1729517_2.xml^headers^
new file mode 100644
index 0000000000..6c83b8d686
--- /dev/null
+++ b/dom/xslt/tests/mochitest/file_bug1729517_2.xml^headers^
@@ -0,0 +1,2 @@
+Referrer-Policy: no-referrer
+Cross-Origin-Embedder-Policy: require-corp
diff --git a/dom/xslt/tests/mochitest/file_metaRefresh.xml b/dom/xslt/tests/mochitest/file_metaRefresh.xml
new file mode 100644
index 0000000000..b9e127b8a5
--- /dev/null
+++ b/dom/xslt/tests/mochitest/file_metaRefresh.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
+<!DOCTYPE root [
+ <!ATTLIST xsl:stylesheet id ID #IMPLIED>
+]>
+<root>
+ <xsl:stylesheet id="stylesheet" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ <xsl:template match="/">
+ <html>
+ <head>
+ <meta http-equiv="refresh" content="2"></meta>
+ </head>
+ </html>
+ </xsl:template>
+</xsl:stylesheet>
+</root>
diff --git a/dom/xslt/tests/mochitest/mochitest.toml b/dom/xslt/tests/mochitest/mochitest.toml
new file mode 100644
index 0000000000..70d313758c
--- /dev/null
+++ b/dom/xslt/tests/mochitest/mochitest.toml
@@ -0,0 +1,57 @@
+[DEFAULT]
+
+["test_bug319374.html"]
+
+["test_bug427060.html"]
+
+["test_bug440974.html"]
+
+["test_bug453441.html"]
+
+["test_bug468208.html"]
+
+["test_bug511487.html"]
+
+["test_bug551412.html"]
+
+["test_bug551654.html"]
+
+["test_bug566629.html"]
+
+["test_bug566629.xhtml"]
+
+["test_bug603159.html"]
+
+["test_bug616774.html"]
+
+["test_bug667315.html"]
+
+["test_bug1072116.html"]
+
+["test_bug1135764.html"]
+support-files = [
+ "file_bug1135764.xml",
+ "file_bug1135764.xsl",
+]
+
+["test_bug1436040.html"]
+
+["test_bug1527308.html"]
+
+["test_bug1729517.html"]
+support-files = [
+ "bug1729517_2.sjs",
+ "file_bug1729517.xml",
+ "file_bug1729517.js",
+ "file_bug1729517_2.xml",
+ "file_bug1729517_2.xml^headers^",
+]
+
+["test_exslt.html"]
+
+["test_metaRefresh.html"]
+support-files = ["file_metaRefresh.xml"]
+
+["test_parameter.html"]
+
+["test_sorting_invalid_lang.html"]
diff --git a/dom/xslt/tests/mochitest/test_bug1072116.html b/dom/xslt/tests/mochitest/test_bug1072116.html
new file mode 100644
index 0000000000..d69b5812b2
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug1072116.html
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1072116
+-->
+<head>
+ <title>Test for Bug 1072116</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1072116">Mozilla Bug 1072116</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 1072116 **/
+var attr = document.createAttribute("c");
+
+var xpathExpr = document.createExpression('a', null);
+
+let isAlive = false;
+try {
+ xpathExpr.evaluate(attr, null, null, null, null);
+} catch(e) {
+ isAlive = true;
+}
+
+ok(isAlive, "Still alive \\o/");
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug1135764.html b/dom/xslt/tests/mochitest/test_bug1135764.html
new file mode 100644
index 0000000000..a368b9b4ab
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug1135764.html
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1135764
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1135764</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+ <script type="application/javascript">
+
+ /** Test for Bug 1135764 **/
+ SimpleTest.waitForExplicitFinish();
+ var counter = 0;
+ var startTimelineValue;
+
+ function waitATick() {
+ ++counter;
+ if (counter == 1) {
+ frames[0].requestAnimationFrame(waitATick);
+ return;
+ }
+ ok(frames[0].document.timeline.currentTime !== startTimelineValue,
+ "The timeline in an XSLT-transformed document should still advance");
+ SimpleTest.finish();
+ }
+ addLoadEvent(function() {
+ SpecialPowers.pushPrefEnv(
+ {
+ set: [
+ ["dom.animations-api.timelines.enabled", true],
+ ],
+ },
+ function() {
+ var ifr = document.querySelector("iframe");
+ ifr.onload = function() {
+ startTimelineValue = frames[0].document.timeline.currentTime;
+ frames[0].requestAnimationFrame(waitATick);
+ };
+ ifr.src = "file_bug1135764.xml";
+ }
+ );
+ });
+ </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1135764">Mozilla Bug 1135764</a>
+<p id="display">
+ <iframe></iframe>
+</p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug1436040.html b/dom/xslt/tests/mochitest/test_bug1436040.html
new file mode 100644
index 0000000000..df17e75779
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug1436040.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Test for xslt-param PIs</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+async_test(t => {
+ let iframe = document.createElement('iframe');
+ let src = `<?xml version="1.0"?>
+ <?xslt-param name="param" value="true"?>
+ <?xml-stylesheet type="text/xml" href="#bug"?>
+ <doc>
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" id="bug">
+ <xsl:output method="html"/>
+ <xsl:param name="param">false</xsl:param>
+ <xsl:template match="/">
+ <xsl:element name="script">parent.postMessage({test: 1, result: <xsl:value-of select="$param"/>}, "*");</xsl:element>
+ </xsl:template>
+ </xsl:stylesheet>
+ </doc>`;
+ iframe.src = "data:text/xml," + encodeURIComponent(src);
+ self.addEventListener("message", t.step_func_done(({data: {test, result}}) => {
+ if (test == 1) {
+ assert_true(result, "The stylesheet param's value should be set by the xslt-param PI.");
+ }
+ }));
+ document.body.appendChild(iframe);
+}, "Test for xslt-param PIs");
+async_test(t => {
+ let iframe = document.createElement('iframe');
+ let src = `<?xml version="1.0"?>
+ <?xslt-param-namespace prefix="foo" namespace="foonamespace"?>
+ <?xslt-param name="param" select="//foo:default"?>
+ <?xml-stylesheet type="text/xml" href="#bug"?>
+ <doc>
+ <default xmlns="foonamespace">true</default>
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" id="bug">
+ <xsl:output method="html"/>
+ <xsl:param name="param">false</xsl:param>
+ <xsl:template match="/">
+ <xsl:element name="script">parent.postMessage({test: 2, result: <xsl:value-of select="$param"/>}, "*");</xsl:element>
+ </xsl:template>
+ </xsl:stylesheet>
+ </doc>`;
+ iframe.src = "data:text/xml," + encodeURIComponent(src);
+ self.addEventListener("message", t.step_func_done(({data: {test, result}}) => {
+ if (test == 2) {
+ assert_true(result, "xslt-param-namespace should have set the right namespace");
+ }
+ }));
+ document.body.appendChild(iframe);
+}, "Test for xslt-param PIs");
+</script>
diff --git a/dom/xslt/tests/mochitest/test_bug1527308.html b/dom/xslt/tests/mochitest/test_bug1527308.html
new file mode 100644
index 0000000000..c37a0c1f00
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug1527308.html
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Test for serialized state in XSLT result document</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+async_test(t => {
+ let iframe = document.createElement('iframe');
+ let src = `<?xml version="1.0"?>
+ <?xml-stylesheet type="text/xml" href="#stylesheet"?>
+ <doc>
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" id="stylesheet">
+ <xsl:output method="html"/>
+ <xsl:template match="/">
+ <html>
+ <xsl:element name="script">self.addEventListener("message", () => { history.go(0); });</xsl:element>
+ <body onload="parent.postMessage(history.state, '*'); history.replaceState('data', 'title');"></body>
+ </html>
+ </xsl:template>
+ </xsl:stylesheet>
+ </doc>`;
+ iframe.src = "data:text/xml," + encodeURIComponent(src);
+ let reloaded = false;
+ self.addEventListener("message", t.step_func(({data: state}) => {
+ if (!reloaded) {
+ assert_equals(state, null, "At this point history.state should be set.");
+ iframe.contentWindow.postMessage("", "*");
+ reloaded = true;
+ return;
+ }
+
+ assert_equals(state, 'data', "Data set through history.replaceState in an XSLT result document should persist.");
+ t.done();
+ }));
+ document.body.appendChild(iframe);
+}, "Test for serialized state in XSLT result document");
+</script>
diff --git a/dom/xslt/tests/mochitest/test_bug1729517.html b/dom/xslt/tests/mochitest/test_bug1729517.html
new file mode 100644
index 0000000000..3dc9eca3c0
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug1729517.html
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title><!-- TODO: insert title here --></title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
+ <script>
+ SimpleTest.waitForExplicitFinish();
+ async function runTest() {
+ let frame = document.getElementById("frame");
+ let loaded = new Promise((resolve) => {
+ frame.addEventListener("load", () => {
+ let failed = JSON.parse(frame.contentDocument.title);
+ ok(failed instanceof Array, "Frame's title is expected to be a JSON representation of the array of failed conditions.");
+ is(failed.length, 0, "No scripts should run in sandboxed iframe document created by XSLT.");
+ for (let desc of failed) {
+ info(desc);
+ }
+ resolve();
+ }, { once: true });
+ });
+ frame.src = "file_bug1729517.xml";
+ await loaded;
+
+ let results = new Promise((resolve) => {
+ addEventListener("message", ({ data }) => {
+ resolve(data);
+ }, { once: true });
+ });
+
+ let win = window.open(`https://example.com/tests/dom/xslt/tests/mochitest/file_bug1729517_2.xml`);
+ for (const [header, result] of await results) {
+ is(result, "PASS", `${header} of the source document should apply to document created by XSLT.`);
+ }
+ win.close();
+
+ SimpleTest.finish();
+ }
+ </script>
+</head>
+<body onload="runTest();">
+<p id="display"></p>
+<iframe sandbox="allow-same-origin" id="frame"></iframe>
+<div id="content" style="display: none"></div>
+<pre id="test"></pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug319374.html b/dom/xslt/tests/mochitest/test_bug319374.html
new file mode 100644
index 0000000000..a833cf281f
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug319374.html
@@ -0,0 +1,101 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=319374
+-->
+<head>
+ <title>Test for Bug 319374</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=319374">Mozilla Bug 319374</a>
+<p id="display"></p>
+<div id="content"><custom-el></custom-el><custom-el></custom-el><custom-el></custom-el></div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+customElements.define("custom-el", class extends HTMLElement {
+ constructor() {
+ super();
+ this.attachShadow({ mode: "open" });
+ this.shadowRoot.innerHTML =
+ `<span attr="attribute"><span></span></span><span> anon text </span><br>`;
+ }
+});
+
+ function testChangesInShadowDOM() {
+ // Test 1: Make sure that modifying anonymous content doesn't
+ // cause non-anonymous XPath result to throw exceptions..
+ var counter = 0;
+ var error = null;
+ try {
+ var xp = new XPathEvaluator();
+ var result = xp.evaluate("*",
+ document.getElementById('content'),
+ null,
+ XPathResult.UNORDERED_NODE_ITERATOR_TYPE,
+ null);
+ var res = null;
+ while ((res = result.iterateNext())) {
+ ++counter;
+ let anon = res.shadowRoot.childNodes;
+ anon[0].firstChild.remove(); // Removing a child node
+ anon[0].removeAttribute("attr1"); // Removing an attribute
+ anon[1].firstChild.data = "anon text changed" // Modifying text data
+ }
+ } catch (e) {
+ error = e;
+ }
+ ok(!error, error);
+ ok(counter == 3, "XPathEvaluator should have found 3 elements.")
+
+ // Test 2: If the context node is in anonymous content, changing some
+ // other anonymous tree shouldn't cause XPath result to throw.
+ let shadowAttr1 = document.getElementById("content").firstChild.
+ shadowRoot.firstChild.getAttributeNode("attr");
+ let shadowAttr2 = document.getElementById("content").lastChild.
+ shadowRoot.firstChild.getAttributeNode("attr");
+ var resultAttr = null;
+ try {
+ var xp2 = xp.evaluate(".",
+ shadowAttr1,
+ null,
+ XPathResult.UNORDERED_NODE_ITERATOR_TYPE,
+ null);
+ // Attribute changing in a different anonymous tree.
+ shadowAttr2.value = "foo";
+ resultAttr = xp2.iterateNext();
+ is(resultAttr, shadowAttr1, "XPathEvaluator returned wrong attribute!");
+ } catch (e) {
+ ok(false, e);
+ }
+
+ // Test 3: If the anonymous tree in which context node is in is modified,
+ // XPath result should throw when iterateNext() is called.
+ resultAttr = null;
+ try {
+ var xp3 = xp.evaluate(".",
+ shadowAttr1,
+ null,
+ XPathResult.UNORDERED_NODE_ITERATOR_TYPE,
+ null);
+ // Attribute changing in the same anonymous tree.
+ shadowAttr1.ownerElement.setAttribute("foo", "bar");
+ resultAttr = xp3.iterateNext();
+ ok(resultAttr == shadowAttr1,
+ "XPathEvaluator should have thrown an exception!")
+ } catch (e) {
+ ok(true, e);
+ }
+
+ SimpleTest.finish();
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ addLoadEvent(testChangesInShadowDOM);
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/xslt/tests/mochitest/test_bug427060.html b/dom/xslt/tests/mochitest/test_bug427060.html
new file mode 100644
index 0000000000..0dac88b74b
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug427060.html
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=427060
+-->
+<head>
+ <title>Test for Bug 427060</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=427060">Mozilla Bug 427060</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 427060 **/
+
+var xmldoc, xsltdoc;
+
+xmldoc = new DOMParser().parseFromString('<opml version="1.0"><body></body></opml>', "text/xml");
+xsltdoc = new DOMParser().parseFromString('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\n\
+ <xsl:template match="/opml">\n\
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\
+ <head>\n\
+ <base target="_blank"></base>\n\
+ </head>\n\
+ <body></body>\n\
+ </html>\n\
+ </xsl:template>\n\
+ </xsl:stylesheet>', "text/xml");
+
+var processor = new XSLTProcessor;
+processor.importStylesheet(xsltdoc);
+try
+{
+ var result = processor.transformToDocument(xmldoc);
+}
+catch (e)
+{
+}
+ok(result && result instanceof Document, "XSLT transform should have created a document");
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug440974.html b/dom/xslt/tests/mochitest/test_bug440974.html
new file mode 100644
index 0000000000..40745ae210
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug440974.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=440974
+-->
+<head>
+ <title>Test for Bug 440974</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=440974">Mozilla Bug 440974</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 440974 **/
+
+function isTxResult(node)
+{
+ return node.namespaceURI == "http://www.mozilla.org/TransforMiix" &&
+ node.localName == "result";
+}
+
+var xmldoc, xsltdoc;
+
+xmldoc = new DOMParser().parseFromString('<items><item><id>1</id></item><item><id>2</id></item><item><id>3</id></item></items>', "text/xml");
+xsltdoc = new DOMParser().parseFromString('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\n\
+ <xsl:output method="xml" />\n\
+ <xsl:template match="item"><foo id="{id}"/></xsl:template>\n\
+ </xsl:stylesheet>', "text/xml");
+
+var processor = new XSLTProcessor;
+processor.importStylesheet(xsltdoc);
+var result = processor.transformToDocument(xmldoc);
+var resultElements = Array.prototype.filter.call(result.getElementsByTagName('*'), isTxResult);
+is(resultElements.length, 1, "there should be only one 'transformiix:result' element");
+is(resultElements[0], result.documentElement, "the 'transformiix:result' element should be the document element");
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug453441.html b/dom/xslt/tests/mochitest/test_bug453441.html
new file mode 100644
index 0000000000..1d8b554c00
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug453441.html
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=453441
+-->
+<head>
+ <title>Test for Bug 453441</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=453441">Mozilla Bug 453441</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 453441 **/
+
+function tryImportStylesheet(xml, valid)
+{
+ var processor = new XSLTProcessor;
+
+ var xsltdoc = new DOMParser().parseFromString(xml, "text/xml");
+ try
+ {
+ processor.importStylesheet(xsltdoc);
+ ok(valid, "should be able to parse this XSLT stylesheet");
+ }
+ catch (e)
+ {
+ ok(!valid, "should not be able to parse this XSLT stylesheet");
+ }
+}
+
+tryImportStylesheet(
+ '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\n\
+ <xsl:template match="/">\n\
+ <html xmlns="http://www.w3.org/1999/xhtml" xsl:version="1.0" />\n\
+ </xsl:template>\n\
+ </xsl:stylesheet>'
+, true);
+
+tryImportStylesheet(
+ '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" />'
+, false);
+
+tryImportStylesheet(
+ '<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" />'
+, false);
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug468208.html b/dom/xslt/tests/mochitest/test_bug468208.html
new file mode 100644
index 0000000000..d3c05c7374
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug468208.html
@@ -0,0 +1,35 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=468208
+-->
+<head>
+ <title>Test for Bug 468208</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=468208">Mozilla Bug 468208</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 468208 **/
+var xslt =
+ '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\n\
+ <xsl:strip-space elements="color"/>\n\
+ </xsl:stylesheet>'
+;
+var xsltdoc = new DOMParser().parseFromString(xslt, "text/xml");
+
+var processor = new XSLTProcessor;
+processor.importStylesheet(xsltdoc);
+ok(true, "XSLT shouldn't leak");
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug511487.html b/dom/xslt/tests/mochitest/test_bug511487.html
new file mode 100644
index 0000000000..324ba04679
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug511487.html
@@ -0,0 +1,59 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=511487
+-->
+<head>
+ <title>Test for Bug 511487</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=511487">Mozilla Bug 511487</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 511487 **/
+
+ var didTransform = false;
+ var processor = new XSLTProcessor();
+ var style =
+ '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/1999/xhtml">' +
+ '<xsl:output method="xml" version="1.0" encoding="UTF-8" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />' +
+ '<xsl:template match="wml">' +
+ '<html xmlns="http://www.w3.org/1999/xhtml">' +
+ '<head>' +
+ '<title>XSLT test</title>' +
+ '</head>' +
+ '<body onload="window.alert(this)">' +
+ '</body>' +
+ '</html>' +
+ '</xsl:template>' +
+ '</xsl:stylesheet>';
+ var styleDoc = new DOMParser().parseFromString (style, "text/xml");
+
+ var data =
+ '<?xml version="1.0"?>' +
+ '<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">' +
+ '<wml><card><p>paragraph</p></card></wml>';
+ var originalDoc = new DOMParser().parseFromString(data, "text/xml");
+
+ processor.importStylesheet(styleDoc);
+ try {
+ var transformedDocument = processor.transformToDocument(originalDoc);
+ didTransform = true;
+ } catch (e) {
+ ok(false, e);
+ }
+
+ ok(didTransform, "transformToDocument didn't succeed!");
+
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug551412.html b/dom/xslt/tests/mochitest/test_bug551412.html
new file mode 100644
index 0000000000..399310a014
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug551412.html
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=551412
+-->
+<head>
+ <title>Test for Bug 551412</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=551412">Mozilla Bug 551412</a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 551412 **/
+
+ var processor = new XSLTProcessor();
+ var style =
+ '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ' +
+ 'xmlns:exsl="http://exslt.org/common" ' +
+ 'version="1.0">' +
+ '<xsl:output method="html"/>' +
+ '<xsl:variable name="rtf">1 <b>2</b> 3</xsl:variable>' +
+ '<xsl:template match="/">' +
+ '<xsl:copy-of select="exsl:node-set($rtf)"/>' +
+ '</xsl:template>' +
+ '</xsl:stylesheet>';
+ var styleDoc = new DOMParser().parseFromString (style, "text/xml");
+
+ var data =
+ '<root/>';
+ var originalDoc = new DOMParser().parseFromString(data, "text/xml");
+
+ processor.importStylesheet(styleDoc);
+
+ var fragment = processor.transformToFragment(originalDoc, document);
+ var content = document.getElementById("content");
+ content.appendChild(fragment);
+ is(content.innerHTML, "1 <b>2</b> 3",
+ "Result of transform should be '1 <b>2</b> 3'");
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug551654.html b/dom/xslt/tests/mochitest/test_bug551654.html
new file mode 100644
index 0000000000..0bdd2dda60
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug551654.html
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=551654
+-->
+<head>
+ <title>Test for Bug 551654</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=551654">Mozilla Bug 551654</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 551654 **/
+
+ var didTransform = false;
+ var processor = new XSLTProcessor();
+ var style =
+ '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ' +
+ 'xmlns:exsl="http://exslt.org/common" ' +
+ 'version="1.0">' +
+ '<xsl:output method="html"/>' +
+ '<xsl:template match="/">' +
+ '<xsl:copy-of select="exsl:node-set(42)"/>' +
+ '</xsl:template>' +
+ '</xsl:stylesheet>';
+ var styleDoc = new DOMParser().parseFromString (style, "text/xml");
+
+ var data =
+ '<root/>';
+ var originalDoc = new DOMParser().parseFromString(data, "text/xml");
+
+ processor.importStylesheet(styleDoc);
+ var fragment = processor.transformToFragment(originalDoc, document);
+ is(fragment.firstChild.nodeType, Node.TEXT_NODE,
+ "Result of transform should be a textnode");
+ is(fragment.firstChild.nodeValue, "42",
+ "Result of transform should be a textnode with value '42'");
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug566629.html b/dom/xslt/tests/mochitest/test_bug566629.html
new file mode 100644
index 0000000000..5670207145
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug566629.html
@@ -0,0 +1,70 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=566629
+-->
+<head>
+ <title>Test for Bug 566629</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=566629">Mozilla Bug 566629</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 566629 **/
+
+var xsltdoc = new DOMParser().parseFromString(
+ '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\
+ xmlns:xhtml="http://www.w3.org/1999/xhtml">\
+ <xsl:template match="/">\
+ <xsl:value-of select="count(//body)"/>\
+ <xsl:text>,</xsl:text>\
+ <xsl:value-of select="count(//xhtml:body)"/>\
+ <xsl:text>,</xsl:text>\
+ <xsl:value-of select="count(//xsl:body)"/>\
+ <xsl:text>,</xsl:text>\
+ <xsl:value-of select="name(//body)"/>\
+ <xsl:text>,</xsl:text>\
+ <xsl:value-of select="local-name(//body)"/>\
+ </xsl:template>\
+ </xsl:stylesheet>',
+ "text/xml");
+
+var processor = new XSLTProcessor;
+processor.importStylesheet(xsltdoc);
+var result = processor.transformToFragment(document, document);
+ok(result instanceof DocumentFragment, "returned a docfragment");
+is(result.firstChild.nodeValue, "1,1,0,BODY,body",
+ "correct treatment of HTML elements in XSLT");
+
+is(document.evaluate("count(//body)", document, null, XPathResult.ANY_TYPE, null).numberValue,
+ 1, "namespace-less node-test");
+is(document.evaluate("count(//a:body)", document,
+ function() { return "http://www.w3.org/1999/xhtml" },
+ XPathResult.ANY_TYPE, null).numberValue,
+ 1, "with-namespace node-test");
+is(document.evaluate("count(//a:body)", document,
+ function() { return "foo" },
+ XPathResult.ANY_TYPE, null).numberValue,
+ 0, "wrong-namespace node-test");
+is(document.evaluate("//bODy", document, null, XPathResult.ANY_TYPE, null).iterateNext(),
+ document.body, "case insensitive matching");
+is(document.evaluate("count(//a:bODy)", document,
+ function() { return "http://www.w3.org/1999/xhtml" },
+ XPathResult.ANY_TYPE, null).numberValue,
+ 0, "with-namespace but wrong casing node-test");
+is(document.evaluate("name(//body)", document, null, XPathResult.ANY_TYPE, null).stringValue,
+ "BODY", "uppercase name() function");
+is(document.evaluate("local-name(//body)", document, null, XPathResult.ANY_TYPE, null).stringValue,
+ "body", "lowercase local-name() function");
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug566629.xhtml b/dom/xslt/tests/mochitest/test_bug566629.xhtml
new file mode 100644
index 0000000000..0880a36002
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug566629.xhtml
@@ -0,0 +1,73 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=566629
+-->
+<head>
+ <title>Test for Bug 566629</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=566629">Mozilla Bug 566629</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+<![CDATA[
+/** Test for Bug 566629 **/
+
+var xsltdoc = new DOMParser().parseFromString(
+ '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\
+ xmlns:xhtml="http://www.w3.org/1999/xhtml">\
+ <xsl:template match="/">\
+ <xsl:value-of select="count(//body)"/>\
+ <xsl:text>,</xsl:text>\
+ <xsl:value-of select="count(//xhtml:body)"/>\
+ <xsl:text>,</xsl:text>\
+ <xsl:value-of select="count(//xsl:body)"/>\
+ <xsl:text>,</xsl:text>\
+ <xsl:value-of select="name(//xhtml:body)"/>\
+ <xsl:text>,</xsl:text>\
+ <xsl:value-of select="local-name(//xhtml:body)"/>\
+ </xsl:template>\
+ </xsl:stylesheet>',
+ "text/xml");
+
+var processor = new XSLTProcessor;
+processor.importStylesheet(xsltdoc);
+var result = processor.transformToFragment(document, document);
+ok(result instanceof DocumentFragment, "returned a docfragment");
+is(result.firstChild.nodeValue, "0,1,0,body,body",
+ "correct treatment of HTML elements in XSLT");
+
+is(document.evaluate("count(//body)", document, null, XPathResult.ANY_TYPE, null).numberValue,
+ 0, "namespace-less node-test");
+is(document.evaluate("count(//a:body)", document,
+ function() { return "http://www.w3.org/1999/xhtml" },
+ XPathResult.ANY_TYPE, null).numberValue,
+ 1, "with-namespace node-test");
+is(document.evaluate("count(//a:body)", document,
+ function() { return "foo" },
+ XPathResult.ANY_TYPE, null).numberValue,
+ 0, "wrong-namespace node-test");
+is(document.evaluate("count(//a:bODy)", document,
+ function() { return "http://www.w3.org/1999/xhtml" },
+ XPathResult.ANY_TYPE, null).numberValue,
+ 0, "with-namespace wrong-casing node-test");
+is(document.evaluate("count(//bODy)", document, null, XPathResult.ANY_TYPE, null).numberValue,
+ 0, "without-namespace wrong-casing node-test");
+is(document.evaluate("name(//a:body)", document,
+ function() { return "http://www.w3.org/1999/xhtml" },
+ XPathResult.ANY_TYPE, null).stringValue,
+ "body", "name()");
+is(document.evaluate("local-name(//a:body)", document,
+ function() { return "http://www.w3.org/1999/xhtml" },
+ XPathResult.ANY_TYPE, null).stringValue,
+ "body", "local-name()");
+]]>
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug603159.html b/dom/xslt/tests/mochitest/test_bug603159.html
new file mode 100644
index 0000000000..95c4efa9c5
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug603159.html
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=603159
+-->
+<head>
+ <title>Test for Bug 603159</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=603159">Mozilla Bug 603159</a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 603159 **/
+
+ var style =
+ '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ' +
+ 'xmlns:date="http://exslt.org/dates-and-times" '+
+ 'version="1.0">' +
+ '<xsl:output method="html"/>' +
+ '<xsl:template match="/">' +
+ '<xsl:value-of select="date:date-time()" /> ' +
+ '</xsl:template>' +
+ '</xsl:stylesheet>';
+ var styleDoc = new DOMParser().parseFromString (style, "text/xml");
+
+ var data = '<root/>';
+ var originalDoc = new DOMParser().parseFromString(data, "text/xml");
+
+ var processor = new XSLTProcessor();
+ processor.importStylesheet(styleDoc);
+
+ var fragment = processor.transformToFragment(originalDoc, document);
+ var content = document.getElementById("content");
+ content.appendChild(fragment);
+
+ // use Gecko's Date.parse to parse, then compare the milliseconds since epoch
+ var xslt_ms = Date.parse(content.innerHTML);
+ var now_ms = new Date().getTime();
+ var accepted_diff = 30 * 60 * 1000; // 30 minutes
+ var diff = Math.abs(now_ms - xslt_ms);
+
+ ok(diff < accepted_diff, "generated timestamp should be not more than "
+ + accepted_diff + " ms before 'now', but the difference was: " + diff);
+
+ content.innerHTML = '';
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug616774.html b/dom/xslt/tests/mochitest/test_bug616774.html
new file mode 100644
index 0000000000..e970b778e9
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug616774.html
@@ -0,0 +1,28 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=616774-->
+<head>
+ <title>Test for Bug 616774</title>
+ <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=616774">Mozilla Bug 616774</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+ 42
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 616774 **/
+is(document.evaluate('- "8"', document, null, XPathResult.ANY_TYPE, null).numberValue, -8, "Negated string literal should evaluate to itself negated");
+is(document.evaluate('- - "999"', document, null, XPathResult.ANY_TYPE, null).numberValue, 999, "String literal should evaluate to itself");
+is(document.evaluate('- - id("content")', document, null, XPathResult.ANY_TYPE, null).numberValue, 42, "DOM element should evaluate to itself coerced to a number");
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_bug667315.html b/dom/xslt/tests/mochitest/test_bug667315.html
new file mode 100644
index 0000000000..a54fa05f42
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_bug667315.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=667315
+-->
+<head>
+ <title>Test for Bug 667315</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=667315">Mozilla Bug 667315</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 667315 **/
+
+var style =
+ '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ' +
+ 'version="1.0">' +
+ '<xsl:variable name="var">' +
+ '<html><p>a</p></html>' +
+ '</xsl:variable>' +
+ '<xsl:template match="/">' +
+ '<xsl:copy-of select="$var" />' +
+ '</xsl:template>' +
+ '</xsl:stylesheet>';
+var styleDoc = new DOMParser().parseFromString (style, "text/xml");
+
+var data = '<root/>';
+var originalDoc = new DOMParser().parseFromString(data, "text/xml");
+
+var processor = new XSLTProcessor();
+processor.importStylesheet(styleDoc);
+
+var doc = processor.transformToDocument(originalDoc);
+ok(doc instanceof HTMLDocument, "should have switched to html output method");
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_exslt.html b/dom/xslt/tests/mochitest/test_exslt.html
new file mode 100644
index 0000000000..739d1c1988
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_exslt.html
@@ -0,0 +1,249 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test EXSLT extensions
+http://www.exslt.org/
+-->
+<head>
+ <title>Test for EXSLT extensions</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript">
+ let tests = [
+ {
+ descr: "Testing common:node-set",
+ expr: "common:node-set($tree)",
+ useCopyOf: true,
+ expResult: "<abc>def</abc>",
+ },
+ {
+ descr: "Testing common:object-type(string)",
+ expr: "common:object-type($string)",
+ expResult: "string",
+ },
+ {
+ descr: "Testing common:object-type(number)",
+ expr: "common:object-type($number)",
+ expResult: "number",
+ },
+ {
+ descr: "Testing common:object-type(boolean)",
+ expr: "common:object-type($boolean)",
+ expResult: "boolean",
+ },
+ {
+ descr: "Testing common:object-type(node-set)",
+ expr: "common:object-type($node-set)",
+ expResult: "node-set",
+ },
+ {
+ descr: "Testing common:object-type(tree)",
+ expr: "common:object-type($tree)",
+ expResult: "RTF",
+ },
+ {
+ descr: "Testing math:max",
+ expr: "math:max(root/numbers/number)",
+ expResult: "11",
+ },
+ {
+ descr: "Testing math:min",
+ expr: "math:min(root/numbers/number)",
+ expResult: "4",
+ },
+ {
+ descr: "Testing math:highest",
+ expr: "math:highest(root/numbers/number)/@id",
+ expResult: "eleven",
+ },
+ {
+ descr: "Testing math:lowest",
+ expr: "math:lowest(root/numbers/number)/@id",
+ expResult: "four",
+ },
+ {
+ descr: "Testing regexp:test",
+ expr: "regexp:test('XSLT is great', 'XSLT', '')",
+ expResult: "true",
+ },
+ {
+ descr: "Testing regexp:match",
+ expr: "regexp:match('XSLT is great', 'XSL.', '')[1]",
+ expResult: "XSLT",
+ },
+ {
+ descr: "Testing regexp:replace",
+ expr: "regexp:replace('Food is great', 'Fo.d', '', 'XSLT')",
+ expResult: "XSLT is great",
+ },
+ {
+ descr: "Testing sets:difference",
+ expr: "sets:difference($i, $e)",
+ useCopyOf: true,
+ expResult: "<city name=\"Paris\" country=\"France\"></city><city name=\"Madrid\" country=\"Spain\"></city><city name=\"Calais\" country=\"France\"></city>",
+ },
+ {
+ descr: "Testing sets:distinct",
+ expr: "strings:concat(sets:distinct(//@country))",
+ expResult: "FranceSpainAustriaGermany",
+ },
+ {
+ descr: "Testing sets:hasSameNode",
+ expr: "sets:has-same-node($i, $e)",
+ expResult: "true",
+ },
+ {
+ descr: "Testing sets:hasSameNode",
+ expr: "sets:has-same-node($i, $o)",
+ expResult: "false",
+ },
+ {
+ descr: "Testing sets:intersection",
+ expr: "sets:intersection($i, $e)",
+ useCopyOf: true,
+ expResult: "<city name=\"Vienna\" country=\"Austria\"></city><city name=\"Berlin\" country=\"Germany\"></city>",
+ },
+ {
+ descr: "Testing sets:leading",
+ expr: "sets:leading($i, $e)",
+ useCopyOf: true,
+ expResult: "<city name=\"Paris\" country=\"France\"></city><city name=\"Madrid\" country=\"Spain\"></city>",
+ },
+ {
+ descr: "Testing sets:leading",
+ expr: "sets:leading($i, $o)",
+ useCopyOf: true,
+ expResult: "",
+ },
+ {
+ descr: "Testing sets:leading",
+ expr: "sets:leading($i, $empty)",
+ useCopyOf: true,
+ expResult: "<city name=\"Paris\" country=\"France\"></city><city name=\"Madrid\" country=\"Spain\"></city><city name=\"Vienna\" country=\"Austria\"></city><city name=\"Calais\" country=\"France\"></city><city name=\"Berlin\" country=\"Germany\"></city>",
+ },
+ {
+ descr: "Testing sets:trailing",
+ expr: "sets:trailing($i, $e)",
+ useCopyOf: true,
+ expResult: "<city name=\"Calais\" country=\"France\"></city><city name=\"Berlin\" country=\"Germany\"></city>",
+ },
+ {
+ descr: "Testing sets:trailing",
+ expr: "sets:trailing($i, $o)",
+ useCopyOf: true,
+ expResult: "",
+ },
+ {
+ descr: "Testing sets:trailing",
+ expr: "sets:trailing($i, $empty)",
+ useCopyOf: true,
+ expResult: "<city name=\"Paris\" country=\"France\"></city><city name=\"Madrid\" country=\"Spain\"></city><city name=\"Vienna\" country=\"Austria\"></city><city name=\"Calais\" country=\"France\"></city><city name=\"Berlin\" country=\"Germany\"></city>",
+ },
+ {
+ descr: "Testing strings:concat",
+ expr: "strings:concat(root/numbers/number/@id)",
+ expResult: "seveneleveneightfour",
+ },
+ {
+ descr: "Testing strings:split",
+ expr: "strings:split('a, simple, list', ', ')",
+ useCopyOf: true,
+ expResult: "<token>a</token><token>simple</token><token>list</token>",
+ },
+ {
+ descr: "Testing strings:split",
+ expr: "strings:split('date math str')",
+ useCopyOf: true,
+ expResult: "<token>date</token><token>math</token><token>str</token>",
+ },
+ {
+ descr: "Testing strings:split",
+ expr: "strings:split('foo', '')",
+ useCopyOf: true,
+ expResult: "<token>f</token><token>o</token><token>o</token>",
+ },
+ {
+ descr: "Testing strings:tokenize",
+ expr: "strings:tokenize('2001-06-03T11:40:23', '-T:')",
+ useCopyOf: true,
+ expResult: "<token>2001</token><token>06</token><token>03</token><token>11</token><token>40</token><token>23</token>",
+ },
+ {
+ descr: "Testing strings:tokenize",
+ expr: "strings:tokenize('date math str')",
+ useCopyOf: true,
+ expResult: "<token>date</token><token>math</token><token>str</token>",
+ },
+ {
+ descr: "Testing strings:tokenize",
+ expr: "strings:tokenize('foo', '')",
+ useCopyOf: true,
+ expResult: "<token>f</token><token>o</token><token>o</token>",
+ },
+ ];
+
+ let style =
+ `<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
+ xmlns:common="http://exslt.org/common"
+ xmlns:math="http://exslt.org/math"
+ xmlns:regexp="http://exslt.org/regular-expressions"
+ xmlns:sets="http://exslt.org/sets"
+ xmlns:strings="http://exslt.org/strings">
+ <xsl:output method="html"/>
+ <xsl:variable name="tree"><abc>def</abc></xsl:variable>
+ <xsl:variable name="string" select="'abc'"/>
+ <xsl:variable name="number" select="123"/>
+ <xsl:variable name="boolean" select="true()"/>
+ <xsl:variable name="node-set" select="//*"/>
+ <xsl:variable name="i" select="/root/sets/city[contains(@name, 'i')]" />
+ <xsl:variable name="e" select="/root/sets/city[contains(@name, 'e')]" />
+ <xsl:variable name="o" select="/root/sets/city[contains(@name, 'o')]" />
+ <xsl:variable name="empty" select="/root/sets/city[contains(@name, 'x')]" />
+ <xsl:template match="/">
+ ${tests.map(({expr, useCopyOf}, i) => `<div id="${i}"><xsl:${useCopyOf ? "copy-of" : "value-of"} select="${expr}"/></div>`).join("\n")}
+ </xsl:template>
+ </xsl:stylesheet>`;
+
+ let styleDoc = new DOMParser().parseFromString(style, "text/xml");
+
+ let data = `<root>
+ <numbers>
+ <number id="seven">7</number>
+ <number id="eleven">11</number>
+ <number id="eight">8</number>
+ <number id="four">4</number>
+ </numbers>
+ <sets>
+ <city name="Paris" country="France" />
+ <city name="Madrid" country="Spain" />
+ <city name="Vienna" country="Austria" />
+ <city name="Barcelona" country="Spain" />
+ <city name="Salzburg" country="Austria" />
+ <city name="Bonn" country="Germany" />
+ <city name="Lyon" country="France" />
+ <city name="Hannover" country="Germany" />
+ <city name="Calais" country="France" />
+ <city name="Berlin" country="Germany" />
+ </sets>
+ </root>`;
+ let originalDoc = new DOMParser().parseFromString(data, "text/xml");
+
+ let processor = new XSLTProcessor();
+ processor.importStylesheet(styleDoc);
+
+ let fragment = processor.transformToFragment(originalDoc, document);
+
+ tests.forEach(({descr, expResult}, i) => {
+ let result = fragment.getElementById(i);
+ is(result.innerHTML, expResult, descr);
+ });
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_metaRefresh.html b/dom/xslt/tests/mochitest/test_metaRefresh.html
new file mode 100644
index 0000000000..21338bed82
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_metaRefresh.html
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title><!-- TODO: insert title here --></title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
+ <script>
+ SimpleTest.waitForExplicitFinish();
+ SimpleTest.requestFlakyTimeout("Use a timeout to check that a load doesn't happen.");
+
+ async function runTest() {
+ function refreshed(frame) {
+ return new Promise((resolve) => {
+ frame.addEventListener("load", () => {
+ let timeout = setTimeout(() => {
+ resolve(false);
+ }, 5000);
+ frame.addEventListener("load", () => {
+ clearTimeout(timeout);
+ resolve(true);
+ }, { once: true });
+ }, { once: true });
+ });
+ }
+
+ let frame = document.getElementById("frame");
+ let result = refreshed(frame);
+ frame.src = "file_metaRefresh.xml";
+ is(await result, true, "Meta refresh should work in iframe document created by XSLT.");
+
+ let sandBoxedFrame = document.getElementById("sandBoxedFrame");
+ result = refreshed(sandBoxedFrame);
+ sandBoxedFrame.src = "file_metaRefresh.xml";
+ is(await result, false, "Meta refresh shouldn't work in sandboxed iframe document created by XSLT.");
+
+ SimpleTest.finish();
+ }
+ </script>
+</head>
+<body onload="runTest();">
+<p id="display"></p>
+<iframe id="frame"></iframe>
+<iframe sandbox="allow-same-origin" id="sandBoxedFrame"></iframe>
+<div id="content" style="display: none"></div>
+<pre id="test"></pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_parameter.html b/dom/xslt/tests/mochitest/test_parameter.html
new file mode 100644
index 0000000000..32acd72fb2
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_parameter.html
@@ -0,0 +1,157 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for setParameter/getParameter</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none"><p id="number">123</p><p id="string">abc</p></div>
+<pre id="test">
+<script>
+ let processor = new XSLTProcessor();
+
+ processor.setParameter(null, "test", "hello");
+ is(processor.getParameter(null, "test"), "hello", "null namespace works");
+
+ processor.setParameter("foo", "bar", "foobar");
+ is(processor.getParameter("foo", "bar"), "foobar", "non-null namespace works");
+
+ processor.setParameter(null, "test", 123);
+ is(processor.getParameter(null, "test"), 123, "number value works");
+
+ processor.removeParameter(null, "test");
+ is(processor.getParameter(null, "test"), null, "removeParameter works");
+
+ is(processor.getParameter(null, "not-here"), null, "nonexistant parameter");
+
+ let parser = new DOMParser();
+ const style =
+ `<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
+ xmlns:exslt="http://exslt.org/common">
+ <xsl:output method="html" />
+ <xsl:param name="test" />
+ <xsl:template match="/">
+ <p id="result"><xsl:value-of select="exslt:object-type($test)" /></p>
+ </xsl:template>
+ </xsl:stylesheet>`;
+ const styleDoc = parser.parseFromString(style, "text/xml");
+
+ const xml = `<root />`;
+ const sourceDoc = parser.parseFromString(xml, "text/xml");
+
+ function checkParameter(value, parameter) {
+ let valueType = typeof value;
+ switch (valueType) {
+ case "number":
+ case "boolean":
+ case "string":
+ is(typeof parameter, valueType, "Parameter has right type");
+ is(parameter, value, "Parameter has right value");
+ return;
+ case "object":
+ if (value instanceof Array || value instanceof NodeList) {
+ ok(parameter instanceof Array, "Parameter has right type");
+ ok(parameter.length == value.length &&
+ parameter.every((p, i) => value[i] === p),
+ "Parameter has right value");
+ return;
+ }
+
+ if (value instanceof Node) {
+ is(parameter, value, "Parameter has right value");
+ return;
+ }
+
+ if (value instanceof XPathResult) {
+ ok(parameter instanceof XPathResult, "Parameter has right type");
+ is(parameter.resultType, value.resultType, "Parameter has right inner type");
+ let valueProperty;
+ switch (value.resultType) {
+ case XPathResult.NUMBER_TYPE:
+ valueProperty = "numberValue";
+ break;
+ case XPathResult.BOOLEAN_TYPE:
+ valueProperty = "booleanValue";
+ break;
+ case XPathResult.STRING_TYPE:
+ valueProperty = "stringValue";
+ break;
+ case XPathResult.FIRST_ORDERED_NODE_TYPE:
+ valueProperty = "singleNodeValue";
+ break;
+ default:
+ ok(false, "Unexpected inner type");
+ return;
+ }
+ is(parameter[valueProperty], value[valueProperty], "Parameter has right value");
+ return;
+ }
+ }
+ ok(false, "Unexpected value");
+ }
+
+ function getXSLTType(value) {
+ let valueType = typeof value;
+ switch (valueType) {
+ case "number":
+ case "boolean":
+ case "string":
+ return valueType;
+ case "object":
+ if (value instanceof Array || value instanceof Node || value instanceof NodeList) {
+ return "node-set";
+ }
+ if (value instanceof XPathResult) {
+ switch (value.resultType) {
+ case XPathResult.NUMBER_TYPE:
+ return "number";
+ case XPathResult.BOOLEAN_TYPE:
+ return "boolean";
+ case XPathResult.STRING_TYPE:
+ return "string";
+ case XPathResult.FIRST_ORDERED_NODE_TYPE:
+ return "node-set";
+ }
+ }
+ }
+ ok(false, "Unexpected value");
+ throw new Error("Unexpected value");
+ }
+
+ function testParameter(value) {
+ let testProcessor = new XSLTProcessor();
+
+ testProcessor.setParameter(null, "test", value);
+ let parameter = testProcessor.getParameter(null, "test");
+
+ checkParameter(value, parameter);
+
+ testProcessor.importStylesheet(styleDoc);
+
+ let fragment = testProcessor.transformToFragment(sourceDoc, document);
+
+ is(
+ fragment.getElementById("result").textContent,
+ getXSLTType(value),
+ "Global parameter has right type in XSLT."
+ );
+ }
+
+ testParameter(123);
+ testParameter(true);
+ testParameter("abcd");
+ testParameter([document]);
+ testParameter(document.documentElement.childNodes);
+ testParameter(document);
+ testParameter(document.evaluate("id('number')", document, null, XPathResult.NUMBER_TYPE));
+ testParameter(document.evaluate("/", document, null, XPathResult.BOOLEAN_TYPE));
+ testParameter(document.evaluate("id('string')", document, null, XPathResult.STRING_TYPE));
+ testParameter(
+ document.evaluate("/", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE)
+ );
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/xslt/tests/mochitest/test_sorting_invalid_lang.html b/dom/xslt/tests/mochitest/test_sorting_invalid_lang.html
new file mode 100644
index 0000000000..6044e43309
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_sorting_invalid_lang.html
@@ -0,0 +1,82 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1734679
+-->
+<head>
+ <title>Test sorting with invalid lang</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1734679">Mozilla Bug 1734679</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/**
+ * Test for Bug 1734679. Invalid language tags should not throw an error, and should
+ * fall back to the app's locale.
+ * */
+
+var xmldoc, xsltdoc;
+
+xmldoc = new DOMParser().parseFromString('<?xml version="1.0" encoding="UTF-8"?>\n\
+ <?xml-stylesheet type="text/xsl" href="sort-lang.xsl" ?>\n\
+ <list>\n\
+ <entry>\n\
+ <technology>CSS</technology>\n\
+ <term>text-direction</term>\n\
+ </entry>\n\
+ <entry>\n\
+ <technology>JavaScript</technology>\n\
+ <term>Array.prototype.sort</term>\n\
+ </entry>\n\
+ </list>\n\
+ ', "text/xml");
+
+xsltdoc = new DOMParser().parseFromString('<?xml version="1.0" encoding="UTF-8"?>\n\
+ <xsl:stylesheet version="1.0"\n\
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\n\
+ <xsl:template match="/">\n\
+ <html>\n\
+ <body>\n\
+ <table border="1">\n\
+ <tr bgcolor="#9acd32">\n\
+ <th>Technology</th>\n\
+ <th>Term</th>\n\
+ </tr>\n\
+ <xsl:for-each select="list/entry">\n\
+ <xsl:sort select="term" lang="$invalidLanguageTag"/>\n\
+ <tr>\n\
+ <td><xsl:value-of select="technology"/></td>\n\
+ <td><xsl:value-of select="term"/></td>\n\
+ </tr>\n\
+ </xsl:for-each>\n\
+ </table>\n\
+ </body>\n\
+ </html>\n\
+ </xsl:template>\n\
+ \n\
+ </xsl:stylesheet>\n\
+ ', "text/xml");
+
+var processor = new XSLTProcessor;
+processor.importStylesheet(xsltdoc);
+
+try
+{
+ var result = processor.transformToDocument(xmldoc);
+}
+catch (e)
+{
+ ok(false, "There was an error.");
+}
+ok(result && result instanceof Document, "XSLT transform should have created a document");
+</script>
+</pre>
+</body>
+</html>