--- qunit-1.11.0.js 2013-02-09 10:22:32.000000000 -0500
+++ qunit-chrome-1.11.0.js 2013-02-12 07:44:05.000000000 -0500
@@ -6,8 +6,75 @@
* Copyright 2012 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
+ * Modified for Firefox extension chrome window usage by Anthony Cassandra.
*/
+//----------------------------------------
+// Special Variables and Functions for Firefox Extension Usage
+
+// This should be set to false for most normal browser-based usages, but
+// should be true if you want to include this as part of a Firefox extension
+// executing javascript in chrome code and displaying in a XUL window.
+//
+var QU_ISCHROME = true;
+
+// For use in generating HTML elements when QU_ISCHROME = true
+var QU_HTMLNS = "http://www.w3.org/1999/xhtml";
+
+// Alternative to createElement() that correct namespace is used.
+function QU_createElement( tagName )
+{
+ if ( QU_ISCHROME )
+ return document.createElementNS( QU_HTMLNS, "html:"+tagName );
+ else
+ return document.createElement( tagName );
+}
+
+// Alternative to assigning the 'innerHTML' property of a node,
+// this converts the HTML fragment into a proper DOM object and appends
+// it to the node.
+//
+function QU_setInnerHTML( parent, childHtmlFragment )
+{
+ if ( QU_ISCHROME )
+ {
+ while (parent.firstChild)
+ parent.removeChild(parent.firstChild);
+ parent.appendChild(Components.classes["@mozilla.org/feed-unescapehtml;1"]
+ .getService(Components.interfaces.nsIScriptableUnescapeHTML)
+ .parseFragment( childHtmlFragment, false, null, parent));
+ }
+ else
+ parent.innerHTML = childHtmlFragment;
+}
+
+// Alternative to using the 'innerHTML' property as a value, this converts
+// DONE into the HTML fragment and returns it as a string.
+//
+function QU_getInnerHTML( node )
+{
+ if ( QU_ISCHROME )
+ {
+ var serializer = new XMLSerializer();
+ var text = "";
+ var children = node.childNodes;
+ for (var i = 0; i < children.length; i++)
+ {
+ var child = children[i];
+ text += serializer.serializeToString(child);
+ }
+ return text;
+ }
+
+ else
+ return node.innerHTML;
+}
+
+//----------------------------------------
+// Beginning of main QUnit code
+
+// Wrapper to allow easily switching between chrome and non-chrome versions.
+
(function( window ) {
var QUnit,
@@ -97,15 +164,14 @@
tests = id( "qunit-tests" );
if ( tests ) {
- b = document.createElement( "strong" );
- b.innerHTML = this.nameHtml;
+ b = QU_createElement( "strong" );
+ QU_setInnerHTML( b, this.nameHtml );
// `a` initialized at top of scope
- a = document.createElement( "a" );
- a.innerHTML = "Rerun";
+ a = QU_createElement( "a" );
+ QU_setInnerHTML( a, "Rerun" );
a.href = QUnit.url({ testNumber: this.testNumber });
-
- li = document.createElement( "li" );
+ li = QU_createElement( "li" );
li.appendChild( b );
li.appendChild( a );
li.className = "running";
@@ -115,7 +181,8 @@
}
},
setup: function() {
- if ( this.module !== config.previousModule ) {
+ // CHANGED: arc
+ if ( ! this.module || (this.module !== config.previousModule )) {
if ( config.previousModule ) {
runLoggingCallbacks( "moduleDone", QUnit, {
name: config.previousModule,
@@ -171,7 +238,8 @@
var running = id( "qunit-testresult" );
if ( running ) {
- running.innerHTML = "Running:
" + this.nameHtml;
+ // CHANGED: arc
+ QU_setInnerHTML( running, "
Running: " + this.nameHtml );
}
if ( this.async ) {
@@ -240,15 +308,15 @@
config.moduleStats.all += this.assertions.length;
if ( tests ) {
- ol = document.createElement( "ol" );
+ ol = QU_createElement( "ol" );
ol.className = "qunit-assert-list";
for ( i = 0; i < this.assertions.length; i++ ) {
assertion = this.assertions[i];
- li = document.createElement( "li" );
+ li = QU_createElement( "li" );
li.className = assertion.result ? "pass" : "fail";
- li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" );
+ QU_setInnerHTML( li, assertion.message || ( assertion.result ? "okay" : "failed" ) );
ol.appendChild( li );
if ( assertion.result ) {
@@ -274,8 +342,8 @@
}
// `b` initialized at top of scope
- b = document.createElement( "strong" );
- b.innerHTML = this.nameHtml + " (" + bad + ", " + good + ", " + this.assertions.length + ")";
+ b = QU_createElement( "strong" );
+ QU_setInnerHTML( b, this.nameHtml + " (" + bad + ", " + good + ", " + this.assertions.length + ")" );
addEvent(b, "click", function() {
var next = b.parentNode.lastChild,
@@ -294,9 +362,9 @@
});
// `time` initialized at top of scope
- time = document.createElement( "span" );
+ time = QU_createElement( "span" );
time.className = "runtime";
- time.innerHTML = this.runtime + " ms";
+ QU_setInnerHTML( time, this.runtime + " ms" );
// `li` initialized at top of scope
li = id( this.id );
@@ -426,6 +494,8 @@
} else {
return config.current.expected;
}
+ // ADDED: arc
+ return config.current.expected;
},
start: function( count ) {
@@ -770,7 +840,11 @@
// Exact match of the module name
config.module = urlParams.module;
- config.testNumber = parseInt( urlParams.testNumber, 10 ) || null;
+ // ADDED: arc
+ if ( urlParams.testNumber )
+ config.testNumber = parseInt( urlParams.testNumber, 10 ) || null;
+ // ADDED: arc
+ else config.testNumber = null;
// Figure out if we're running the tests from a server or not
QUnit.isLocal = location.protocol === "file:";
@@ -802,12 +876,12 @@
qunit = id( "qunit" );
if ( qunit ) {
- qunit.innerHTML =
+ QU_setInnerHTML( qunit,
"