summaryrefslogtreecommitdiffstats
path: root/dom/xslt/tests/XSLTMark
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dom/xslt/tests/XSLTMark/XSLTMark-static.js46
-rw-r--r--dom/xslt/tests/XSLTMark/XSLTMark-test.js41
-rw-r--r--dom/xslt/tests/XSLTMark/XSLTMark-view.js171
-rw-r--r--dom/xslt/tests/XSLTMark/XSLTMark.css8
-rw-r--r--dom/xslt/tests/XSLTMark/XSLTMark.xhtml53
5 files changed, 319 insertions, 0 deletions
diff --git a/dom/xslt/tests/XSLTMark/XSLTMark-static.js b/dom/xslt/tests/XSLTMark/XSLTMark-static.js
new file mode 100644
index 0000000000..fcca33e72b
--- /dev/null
+++ b/dom/xslt/tests/XSLTMark/XSLTMark-static.js
@@ -0,0 +1,46 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const enablePrivilege = netscape.security.PrivilegeManager.enablePrivilege;
+const IOSERVICE_CTRID = "@mozilla.org/network/io-service;1";
+const nsIIOService = Ci.nsIIOService;
+const SIS_CTRID = "@mozilla.org/scriptableinputstream;1";
+const nsISIS = Ci.nsIScriptableInputStream;
+const nsIFilePicker = Ci.nsIFilePicker;
+const STDURLMUT_CTRID = "@mozilla.org/network/standard-url-mutator;1";
+const nsIURIMutator = Ci.nsIURIMutator;
+
+const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+
+var gStop = false;
+
+function loadFile(aUriSpec) {
+ enablePrivilege("UniversalXPConnect");
+ var serv = Cc[IOSERVICE_CTRID].getService(nsIIOService);
+ if (!serv) {
+ throw Components.Exception("", Cr.ERR_FAILURE);
+ }
+ var chan = NetUtil.newChannel({
+ uri: aUriSpec,
+ loadUsingSystemPrincipal: true,
+ });
+ var instream = Cc[SIS_CTRID].createInstance(nsISIS);
+ instream.init(chan.open());
+
+ return instream.read(instream.available());
+}
+
+function dump20(aVal) {
+ const pads = " ";
+ if (typeof aVal == "string") {
+ out = aVal;
+ } else if (typeof aVal == "number") {
+ out = Number(aVal).toFixed(2);
+ } else {
+ out = new String(aVal);
+ }
+ dump(pads.substring(0, 20 - out.length));
+ dump(out);
+}
diff --git a/dom/xslt/tests/XSLTMark/XSLTMark-test.js b/dom/xslt/tests/XSLTMark/XSLTMark-test.js
new file mode 100644
index 0000000000..d88a44649a
--- /dev/null
+++ b/dom/xslt/tests/XSLTMark/XSLTMark-test.js
@@ -0,0 +1,41 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var gParser = new DOMParser();
+var gTimeout;
+
+function Test(aTitle, aSourceURL, aStyleURL, aNumber, aObserver) {
+ this.mTitle = aTitle;
+ this.mObserver = aObserver;
+ this.mTotal = aNumber;
+ this.mDone = 0;
+ var xmlcontent = loadFile(aSourceURL);
+ var xslcontent = loadFile(aStyleURL);
+ this.mSource = gParser.parseFromString(xmlcontent, "application/xml");
+ this.mStyle = gParser.parseFromString(xslcontent, "application/xml");
+}
+
+function runTest(aTitle, aSourceURL, aStyleURL, aNumber, aObserver) {
+ test = new Test(aTitle, aSourceURL, aStyleURL, aNumber, aObserver);
+ gTimeout = setTimeout(onNextTransform, 100, test, 0);
+}
+
+function onNextTransform(aTest, aNumber) {
+ var proc = new XSLTProcessor();
+ var startTime = Date.now();
+ proc.importStylesheet(aTest.mStyle);
+ var res = proc.transformToDocument(aTest.mSource);
+ var endTime = Date.now();
+ aNumber++;
+ var progress = (aNumber / aTest.mTotal) * 100;
+ if (aTest.mObserver) {
+ aTest.mObserver.progress(aTest.mTitle, endTime - startTime, progress);
+ }
+ if (aNumber < aTest.mTotal) {
+ gTimeout = setTimeout(onNextTransform, 100, aTest, aNumber);
+ } else if (aTest.mObserver) {
+ aTest.mObserver.done(aTest.mTitle);
+ }
+}
diff --git a/dom/xslt/tests/XSLTMark/XSLTMark-view.js b/dom/xslt/tests/XSLTMark/XSLTMark-view.js
new file mode 100644
index 0000000000..9436b602a7
--- /dev/null
+++ b/dom/xslt/tests/XSLTMark/XSLTMark-view.js
@@ -0,0 +1,171 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var view = {
+ configUrl: null,
+ testArray: null,
+ mCurrent: null,
+
+ browseForConfig() {
+ enablePrivilege("UniversalXPConnect");
+ var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
+ fp.init(window, "XSLTMark Description File", nsIFilePicker.modeOpen);
+ fp.appendFilter("*.conf", "*.conf");
+ fp.appendFilters(nsIFilePicker.filterAll);
+ var res = fp.show();
+
+ if (res == nsIFilePicker.returnOK) {
+ this.configUrl = Cc[STDURLMUT_CTRID].createInstance(nsIURIMutator)
+ .setSpec(fp.fileURL.spec)
+ .finalize();
+ document
+ .getElementById("config")
+ .setAttribute("value", this.configUrl.spec);
+ }
+ this.parseConfig();
+ return true;
+ },
+
+ parseConfig() {
+ this.testArray = new Array();
+ var test;
+ if (!this.configUrl) {
+ return;
+ }
+
+ var content = loadFile(this.configUrl.spec);
+
+ var lines = content.split("\n");
+ var line, res;
+ var head = /^\[(.+)\]$/;
+ var instruct = /^(.+)=(.+)$/;
+ while (lines.length) {
+ line = lines.shift();
+ if (head.test(line)) {
+ test = new Object();
+ res = head.exec(line);
+ test.title = res[1];
+ this.testArray.push(test);
+ } else if (line == "") {
+ test = undefined;
+ } else {
+ res = instruct.exec(line);
+ test[res[1]] = res[2];
+ }
+ }
+ },
+
+ onLoad() {
+ this.mCurrentStatus = document.getElementById("currentStatus");
+ this.mCurrentProgress = document.getElementById("currentProgress");
+ this.mTotalProgress = document.getElementById("totalProgress");
+ this.mOutput = document.getElementById("transformOutput");
+ this.mDetailOutput = document.getElementById("transformDetailedOutput");
+ this.mDetail = true;
+ },
+
+ progress(aTitle, aTime, aProgress) {
+ // dump20(aTitle);
+ // dump20(aTime);
+ // dump20(aProgress);
+ this.mCurrentProgress.value = aProgress;
+ this.displayDetailTime(aTime);
+ this.mTimes.push(aTime);
+ // dump("\n");
+ },
+
+ done(aTitle) {
+ // dump(aTitle + " is finished.\n");
+ this.mCurrent++;
+ this.mCurrentProgress.value = 0;
+ this.displayTotalTime();
+ if (this.mCurrent >= this.testArray.length) {
+ this.mTotalProgress.value = 0;
+ this.mCurrentStatus.value = "done";
+ return;
+ }
+ this.mTotalProgress.value = (this.mCurrent * 100) / this.testArray.length;
+ var test = this.testArray[this.mCurrent];
+ enablePrivilege("UniversalXPConnect");
+ this.displayTest(test.title);
+ runTest(
+ test.title,
+ this.configUrl.resolve(test.input),
+ this.configUrl.resolve(test.stylesheet),
+ test.iterations,
+ this
+ );
+ },
+
+ onStop() {
+ clearTimeout(gTimeout);
+ this.mCurrentProgress.value = 0;
+ this.mTotalProgress.value = 0;
+ this.mCurrentStatus.value = "stopped";
+ },
+
+ displayTest(aTitle) {
+ this.mTimes = new Array();
+ aTitle += "\t";
+ this.mCurrentStatus.value = aTitle;
+ this.mOutput.value += aTitle;
+ if (this.mDetail) {
+ this.mDetailOutput.value += aTitle;
+ }
+ },
+
+ displayDetailTime(aTime) {
+ if (this.mDetail) {
+ this.mDetailOutput.value += aTime + " ms\t";
+ }
+ },
+
+ displayTotalTime() {
+ var sum = 0;
+ for (k = 0; k < this.mTimes.length; k++) {
+ sum += this.mTimes[k];
+ }
+ var mean = sum / this.mTimes.length;
+ this.mOutput.value += Number(mean).toFixed(2) + " ms\t" + sum + " ms\t";
+ var variance = 0;
+ for (k = 0; k < this.mTimes.length; k++) {
+ var n = this.mTimes[k] - mean;
+ variance += n * n;
+ }
+ variance = Math.sqrt(variance / this.mTimes.length);
+ this.mOutput.value += Number(variance).toFixed(2) + "\n";
+ if (this.mDetail) {
+ this.mDetailOutput.value += "\n";
+ }
+ },
+
+ runBenchmark() {
+ enablePrivilege("UniversalXPConnect");
+ if (!this.testArray) {
+ if (!this.configUrl) {
+ this.configUrl = Cc[STDURLMUT_CTRID].createInstance(nsIURIMutator)
+ .setSpec(document.getElementById("config").value)
+ .finalize();
+ }
+ this.parseConfig();
+ }
+
+ this.mCurrent = 0;
+ var test = this.testArray[this.mCurrent];
+ this.mOutput.value = "";
+ if (this.mDetail) {
+ this.mDetailOutput.value = "";
+ }
+ this.displayTest(test.title);
+ runTest(
+ test.title,
+ this.configUrl.resolve(test.input),
+ this.configUrl.resolve(test.stylesheet),
+ test.iterations,
+ this
+ );
+ return true;
+ },
+};
diff --git a/dom/xslt/tests/XSLTMark/XSLTMark.css b/dom/xslt/tests/XSLTMark/XSLTMark.css
new file mode 100644
index 0000000000..80386ae2da
--- /dev/null
+++ b/dom/xslt/tests/XSLTMark/XSLTMark.css
@@ -0,0 +1,8 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+textbox.out {
+ white-space: pre;
+}
diff --git a/dom/xslt/tests/XSLTMark/XSLTMark.xhtml b/dom/xslt/tests/XSLTMark/XSLTMark.xhtml
new file mode 100644
index 0000000000..1527044606
--- /dev/null
+++ b/dom/xslt/tests/XSLTMark/XSLTMark.xhtml
@@ -0,0 +1,53 @@
+<?xml version="1.0"?><!-- -*- Mode: xml; tab-width: 2; indent-tabs-mode: nil -*- -->
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
+<?xml-stylesheet href="XSLTMark.css" type="text/css"?>
+<window id="XSLTMarkHarness"
+ title="XSLTMark"
+ onload="view.onLoad()"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ orient="vertical">
+<script type="application/x-javascript" src="XSLTMark-static.js" />
+<script type="application/x-javascript" src="XSLTMark-test.js" />
+<script type="application/x-javascript" src="XSLTMark-view.js" />
+
+<hbox>
+ <groupbox orient="horizontal">
+ <caption label="test description file" />
+ <label value=""/><!-- needed, otherwise groupbox is broken :-( -->
+ <input xmlns="http://www.w3.org/1999/xhtml" id="config" persist="value" readonly="true"/>
+ <button label="browse..." oncommand="view.browseForConfig();" />
+ </groupbox>
+ <groupbox orient="horizontal">
+ <caption label="test control" />
+ <button label="run..."
+ oncommand="setTimeout('view.runBenchmark();', 0);" />
+ <button label="stop" oncommand="view.onStop();" />
+ </groupbox>
+ <groupbox orient="horizontal">
+ <caption label="options" />
+ <label value="responsiveness: "/>
+ <menulist label="sloppy">
+ <menupopup>
+ <menuitem label="sloppy" selected="true"/>
+ <menuitem label="bad"/>
+ </menupopup>
+ </menulist>
+ </groupbox>
+</hbox>
+<hbox>
+ <input xmlns="http://www.w3.org/1999/xhtml" id="currentStatus" readonly="true" flex="1"/>
+ <progressmeter id="currentProgress" mode="normal" value="0" flex="2"/>
+ <progressmeter id="totalProgress" mode="normal" value="0" flex="2"/>
+</hbox>
+<hbox flex="1">
+ <html:textarea id="transformOutput" class="out" readonly="readonly" flex="1"/>
+</hbox>
+<hbox flex="1">
+ <html:textarea id="transformDetailedOutput" class="out" readonly="readonly" flex="1"/>
+</hbox>
+</window>