UnitTC: QUnit path has been changed. Priority, function type check function has been...
[platform/framework/web/web-ui-fw.git] / libs / js / qunit / qunit.js
1 /**
2  * QUnit v1.9.0 - A JavaScript Unit Testing Framework
3  *
4  * http://docs.jquery.com/QUnit
5  *
6  * Copyright (c) 2012 John Resig, Jörn Zaefferer
7  * Dual licensed under the MIT (MIT-LICENSE.txt)
8  * or GPL (GPL-LICENSE.txt) licenses.
9  */
10
11 (function( window ) {
12
13 var QUnit,
14         config,
15         onErrorFnPrev,
16         testId = 0,
17         fileName = (sourceFromStacktrace( 0 ) || "" ).replace(/(:\d+)+\)?/, "").replace(/.+\//, ""),
18         toString = Object.prototype.toString,
19         hasOwn = Object.prototype.hasOwnProperty,
20         defined = {
21         setTimeout: typeof window.setTimeout !== "undefined",
22         sessionStorage: (function() {
23                 var x = "qunit-test-string";
24                 try {
25                         sessionStorage.setItem( x, x );
26                         sessionStorage.removeItem( x );
27                         return true;
28                 } catch( e ) {
29                         return false;
30                 }
31         }())
32 };
33
34 function Test( settings ) {
35         extend( this, settings );
36         this.assertions = [];
37         this.testNumber = ++Test.count;
38 }
39
40 Test.count = 0;
41
42 Test.prototype = {
43         init: function() {
44                 var a, b, li,
45         tests = id( "qunit-tests" );
46
47                 if ( tests ) {
48                         b = document.createElement( "strong" );
49                         b.innerHTML = this.name;
50
51                         // `a` initialized at top of scope
52                         a = document.createElement( "a" );
53                         a.innerHTML = "Rerun";
54                         a.href = QUnit.url({ testNumber: this.testNumber });
55
56                         li = document.createElement( "li" );
57                         li.appendChild( b );
58                         li.appendChild( a );
59                         li.className = "running";
60                         li.id = this.id = "qunit-test-output" + testId++;
61
62                         tests.appendChild( li );
63                 }
64         },
65         setup: function() {
66                 if ( this.module !== config.previousModule ) {
67                         if ( config.previousModule ) {
68                                 runLoggingCallbacks( "moduleDone", QUnit, {
69                                         name: config.previousModule,
70                                         failed: config.moduleStats.bad,
71                                         passed: config.moduleStats.all - config.moduleStats.bad,
72                                         total: config.moduleStats.all
73                                 });
74                         }
75                         config.previousModule = this.module;
76                         config.moduleStats = { all: 0, bad: 0 };
77                         runLoggingCallbacks( "moduleStart", QUnit, {
78                                 name: this.module
79                         });
80                 } else if ( config.autorun ) {
81                         runLoggingCallbacks( "moduleStart", QUnit, {
82                                 name: this.module
83                         });
84                 }
85
86                 config.current = this;
87
88                 this.testEnvironment = extend({
89                         setup: function() {},
90                         teardown: function() {}
91                 }, this.moduleTestEnvironment );
92
93                 runLoggingCallbacks( "testStart", QUnit, {
94                         name: this.testName,
95                         module: this.module
96                 });
97
98                 // allow utility functions to access the current test environment
99                 // TODO why??
100                 QUnit.current_testEnvironment = this.testEnvironment;
101
102                 if ( !config.pollution ) {
103                         saveGlobal();
104                 }
105                 if ( config.notrycatch ) {
106                         this.testEnvironment.setup.call( this.testEnvironment );
107                         return;
108                 }
109                 try {
110                         this.testEnvironment.setup.call( this.testEnvironment );
111                 } catch( e ) {
112                         QUnit.pushFailure( "Setup failed on " + this.testName + ": " + e.message, extractStacktrace( e, 1 ) );
113                 }
114         },
115         run: function() {
116                 config.current = this;
117
118                 var running = id( "qunit-testresult" );
119
120                 if ( running ) {
121                         running.innerHTML = "Running: <br/>" + this.name;
122                 }
123
124                 if ( this.async ) {
125                         QUnit.stop();
126                 }
127
128                 if ( config.notrycatch ) {
129                         this.callback.call( this.testEnvironment, QUnit.assert );
130                         return;
131                 }
132
133                 try {
134                         this.callback.call( this.testEnvironment, QUnit.assert );
135                 } catch( e ) {
136                         QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + e.message, extractStacktrace( e, 0 ) );
137                         // else next test will carry the responsibility
138                         saveGlobal();
139
140                         // Restart the tests if they're blocking
141                         if ( config.blocking ) {
142                                 QUnit.start();
143                         }
144                 }
145         },
146         teardown: function() {
147                 config.current = this;
148                 if ( config.notrycatch ) {
149                         this.testEnvironment.teardown.call( this.testEnvironment );
150                         return;
151                 } else {
152                         try {
153                                 this.testEnvironment.teardown.call( this.testEnvironment );
154                         } catch( e ) {
155                                 QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + e.message, extractStacktrace( e, 1 ) );
156                         }
157                 }
158                 checkPollution();
159         },
160         finish: function() {
161                 config.current = this;
162                 if ( config.requireExpects && this.expected == null ) {
163                         QUnit.pushFailure( "Expected number of assertions to be defined, but expect() was not called.", this.stack );
164                 } else if ( this.expected != null && this.expected != this.assertions.length ) {
165                         QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack );
166                 } else if ( this.expected == null && !this.assertions.length ) {
167                         QUnit.pushFailure( "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.", this.stack );
168                 }
169
170                 var assertion, a, b, i, li, ol,
171                         test = this,
172                         good = 0,
173                         bad = 0,
174                         tests = id( "qunit-tests" );
175
176                 config.stats.all += this.assertions.length;
177                 config.moduleStats.all += this.assertions.length;
178
179                 if ( tests ) {
180                         ol = document.createElement( "ol" );
181
182                         for ( i = 0; i < this.assertions.length; i++ ) {
183                                 assertion = this.assertions[i];
184
185                                 li = document.createElement( "li" );
186                                 li.className = assertion.result ? "pass" : "fail";
187                                 li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" );
188                                 ol.appendChild( li );
189
190                                 if ( assertion.result ) {
191                                         good++;
192                                 } else {
193                                         bad++;
194                                         config.stats.bad++;
195                                         config.moduleStats.bad++;
196                                 }
197                         }
198
199                         // store result when possible
200                         if ( QUnit.config.reorder && defined.sessionStorage ) {
201                                 if ( bad ) {
202                                         sessionStorage.setItem( "qunit-test-" + this.module + "-" + this.testName, bad );
203                                 } else {
204                                         sessionStorage.removeItem( "qunit-test-" + this.module + "-" + this.testName );
205                                 }
206                         }
207
208                         if ( bad === 0 ) {
209                                 ol.style.display = "none";
210                         }
211
212                         // `b` initialized at top of scope
213                         b = document.createElement( "strong" );
214                         b.innerHTML = this.name + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>";
215
216                         addEvent(b, "click", function() {
217                                 var next = b.nextSibling.nextSibling,
218                                         display = next.style.display;
219                                 next.style.display = display === "none" ? "block" : "none";
220                         });
221
222                         addEvent(b, "dblclick", function( e ) {
223                                 var target = e && e.target ? e.target : window.event.srcElement;
224                                 if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) {
225                                         target = target.parentNode;
226                                 }
227                                 if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
228                                         window.location = QUnit.url({ testNumber: test.testNumber });
229                                 }
230                         });
231
232                         // `li` initialized at top of scope
233                         li = id( this.id );
234                         li.className = bad ? "fail" : "pass";
235                         li.removeChild( li.firstChild );
236                         a = li.firstChild;
237                         li.appendChild( b );
238                         li.appendChild ( a );
239                         li.appendChild( ol );
240
241                 } else {
242                         for ( i = 0; i < this.assertions.length; i++ ) {
243                                 if ( !this.assertions[i].result ) {
244                                         bad++;
245                                         config.stats.bad++;
246                                         config.moduleStats.bad++;
247                                 }
248                         }
249                 }
250
251                 runLoggingCallbacks( "testDone", QUnit, {
252                         name: this.testName,
253                         module: this.module,
254                         failed: bad,
255                         passed: this.assertions.length - bad,
256                         total: this.assertions.length
257                 });
258
259                 QUnit.reset();
260
261                 config.current = undefined;
262         },
263
264         queue: function() {
265                 var bad,
266                         test = this;
267
268                 synchronize(function() {
269                         test.init();
270                 });
271                 function run() {
272                         // each of these can by async
273                         synchronize(function() {
274                                 test.setup();
275                         });
276                         synchronize(function() {
277                                 test.run();
278                         });
279                         synchronize(function() {
280                                 test.teardown();
281                         });
282                         synchronize(function() {
283                                 test.finish();
284                         });
285                 }
286
287                 // `bad` initialized at top of scope
288                 // defer when previous test run passed, if storage is available
289                 bad = QUnit.config.reorder && defined.sessionStorage &&
290                                                 +sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName );
291
292                 if ( bad ) {
293                         run();
294                 } else {
295                         synchronize( run, true );
296                 }
297         }
298 };
299
300 // Root QUnit object.
301 // `QUnit` initialized at top of scope
302 QUnit = {
303
304         // call on start of module test to prepend name to all tests
305         module: function( name, testEnvironment ) {
306                 config.currentModule = name;
307                 config.currentModuleTestEnviroment = testEnvironment;
308         },
309
310         asyncTest: function( testName, expected, callback ) {
311                 if ( arguments.length === 2 ) {
312                         callback = expected;
313                         expected = null;
314                 }
315
316                 QUnit.test( testName, expected, callback, true );
317         },
318
319         test: function( testName, expected, callback, async ) {
320                 var test,
321                         name = "<span class='test-name'>" + escapeInnerText( testName ) + "</span>";
322
323                 if ( arguments.length === 2 ) {
324                         callback = expected;
325                         expected = null;
326                 }
327
328                 if ( config.currentModule ) {
329                         name = "<span class='module-name'>" + config.currentModule + "</span>: " + name;
330                 }
331
332                 test = new Test({
333                         name: name,
334                         testName: testName,
335                         expected: expected,
336                         async: async,
337                         callback: callback,
338                         module: config.currentModule,
339                         moduleTestEnvironment: config.currentModuleTestEnviroment,
340                         stack: sourceFromStacktrace( 2 )
341                 });
342
343                 if ( !validTest( test ) ) {
344                         return;
345                 }
346
347                 test.queue();
348         },
349
350         // Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.
351         expect: function( asserts ) {
352                 config.current.expected = asserts;
353         },
354
355         start: function( count ) {
356                 config.semaphore -= count || 1;
357                 // don't start until equal number of stop-calls
358                 if ( config.semaphore > 0 ) {
359                         return;
360                 }
361                 // ignore if start is called more often then stop
362                 if ( config.semaphore < 0 ) {
363                         config.semaphore = 0;
364                 }
365                 // A slight delay, to avoid any current callbacks
366                 if ( defined.setTimeout ) {
367                         window.setTimeout(function() {
368                                 if ( config.semaphore > 0 ) {
369                                         return;
370                                 }
371                                 if ( config.timeout ) {
372                                         clearTimeout( config.timeout );
373                                 }
374
375                                 config.blocking = false;
376                                 process( true );
377                         }, 13);
378                 } else {
379                         config.blocking = false;
380                         process( true );
381                 }
382         },
383
384         stop: function( count ) {
385                 config.semaphore += count || 1;
386                 config.blocking = true;
387
388                 if ( config.testTimeout && defined.setTimeout ) {
389                         clearTimeout( config.timeout );
390                         config.timeout = window.setTimeout(function() {
391                                 QUnit.ok( false, "Test timed out" );
392                                 config.semaphore = 1;
393                                 QUnit.start();
394                         }, config.testTimeout );
395                 }
396         }
397 };
398
399 // Asssert helpers
400 // All of these must call either QUnit.push() or manually do:
401 // - runLoggingCallbacks( "log", .. );
402 // - config.current.assertions.push({ .. });
403 QUnit.assert = {
404         /**
405          * Asserts rough true-ish result.
406          * @name ok
407          * @function
408          * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
409          */
410         ok: function( result, msg ) {
411                 if ( !config.current ) {
412                         throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) );
413                 }
414                 result = !!result;
415
416                 var source,
417                         details = {
418                                 result: result,
419                                 message: msg
420                         };
421
422                 msg = escapeInnerText( msg || (result ? "okay" : "failed" ) );
423                 msg = "<span class='test-message'>" + msg + "</span>";
424
425                 if ( !result ) {
426                         source = sourceFromStacktrace( 2 );
427                         if ( source ) {
428                                 details.source = source;
429                                 msg += "<table><tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText( source ) + "</pre></td></tr></table>";
430                         }
431                 }
432                 runLoggingCallbacks( "log", QUnit, details );
433                 config.current.assertions.push({
434                         result: result,
435                         message: msg
436                 });
437         },
438
439         /**
440          * Assert that the first two arguments are equal, with an optional message.
441          * Prints out both actual and expected values.
442          * @name equal
443          * @function
444          * @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" );
445          */
446         equal: function( actual, expected, message ) {
447                 QUnit.push( expected == actual, actual, expected, message );
448         },
449
450         /**
451          * @name notEqual
452          * @function
453          */
454         notEqual: function( actual, expected, message ) {
455                 QUnit.push( expected != actual, actual, expected, message );
456         },
457
458         /**
459          * @name deepEqual
460          * @function
461          */
462         deepEqual: function( actual, expected, message ) {
463                 QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
464         },
465
466         /**
467          * @name notDeepEqual
468          * @function
469          */
470         notDeepEqual: function( actual, expected, message ) {
471                 QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message );
472         },
473
474         /**
475          * @name strictEqual
476          * @function
477          */
478         strictEqual: function( actual, expected, message ) {
479                 QUnit.push( expected === actual, actual, expected, message );
480         },
481
482         /**
483          * @name notStrictEqual
484          * @function
485          */
486         notStrictEqual: function( actual, expected, message ) {
487                 QUnit.push( expected !== actual, actual, expected, message );
488         },
489
490         throws: function( block, expected, message ) {
491                 var actual,
492                         ok = false;
493
494                 // 'expected' is optional
495                 if ( typeof expected === "string" ) {
496                         message = expected;
497                         expected = null;
498                 }
499
500                 config.current.ignoreGlobalErrors = true;
501                 try {
502                         block.call( config.current.testEnvironment );
503                 } catch (e) {
504                         actual = e;
505                 }
506                 config.current.ignoreGlobalErrors = false;
507
508                 if ( actual ) {
509                         // we don't want to validate thrown error
510                         if ( !expected ) {
511                                 ok = true;
512                         // expected is a regexp
513                         } else if ( QUnit.objectType( expected ) === "regexp" ) {
514                                 ok = expected.test( actual );
515                         // expected is a constructor
516                         } else if ( actual instanceof expected ) {
517                                 ok = true;
518                         // expected is a validation function which returns true is validation passed
519                         } else if ( expected.call( {}, actual ) === true ) {
520                                 ok = true;
521                         }
522
523                         QUnit.push( ok, actual, null, message );
524                 } else {
525                         QUnit.pushFailure( message, null, 'No exception was thrown.' );
526                 }
527         }
528 };
529
530 /**
531  * @deprecate since 1.8.0
532  * Kept assertion helpers in root for backwards compatibility
533  */
534 extend( QUnit, QUnit.assert );
535
536 /**
537  * @deprecated since 1.9.0
538  * Kept global "raises()" for backwards compatibility
539  */
540 QUnit.raises = QUnit.assert.throws;
541
542 /**
543  * @deprecated since 1.0.0, replaced with error pushes since 1.3.0
544  * Kept to avoid TypeErrors for undefined methods.
545  */
546 QUnit.equals = function() {
547         QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" );
548 };
549 QUnit.same = function() {
550         QUnit.push( false, false, false, "QUnit.same has been deprecated since 2009 (e88049a0), use QUnit.deepEqual instead" );
551 };
552
553 // We want access to the constructor's prototype
554 (function() {
555         function F() {}
556         F.prototype = QUnit;
557         QUnit = new F();
558         // Make F QUnit's constructor so that we can add to the prototype later
559         QUnit.constructor = F;
560 }());
561
562 /**
563  * Config object: Maintain internal state
564  * Later exposed as QUnit.config
565  * `config` initialized at top of scope
566  */
567 config = {
568         // The queue of tests to run
569         queue: [],
570
571         // block until document ready
572         blocking: true,
573
574         // when enabled, show only failing tests
575         // gets persisted through sessionStorage and can be changed in UI via checkbox
576         hidepassed: false,
577
578         // by default, run previously failed tests first
579         // very useful in combination with "Hide passed tests" checked
580         reorder: true,
581
582         // by default, modify document.title when suite is done
583         altertitle: true,
584
585         // when enabled, all tests must call expect()
586         requireExpects: false,
587
588         // add checkboxes that are persisted in the query-string
589         // when enabled, the id is set to `true` as a `QUnit.config` property
590         urlConfig: [
591                 {
592                         id: "noglobals",
593                         label: "Check for Globals",
594                         tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings."
595                 },
596                 {
597                         id: "notrycatch",
598                         label: "No try-catch",
599                         tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings."
600                 }
601         ],
602
603         // logging callback queues
604         begin: [],
605         done: [],
606         log: [],
607         testStart: [],
608         testDone: [],
609         moduleStart: [],
610         moduleDone: []
611 };
612
613 // Initialize more QUnit.config and QUnit.urlParams
614 (function() {
615         var i,
616                 location = window.location || { search: "", protocol: "file:" },
617                 params = location.search.slice( 1 ).split( "&" ),
618                 length = params.length,
619                 urlParams = {},
620                 current;
621
622         if ( params[ 0 ] ) {
623                 for ( i = 0; i < length; i++ ) {
624                         current = params[ i ].split( "=" );
625                         current[ 0 ] = decodeURIComponent( current[ 0 ] );
626                         // allow just a key to turn on a flag, e.g., test.html?noglobals
627                         current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
628                         urlParams[ current[ 0 ] ] = current[ 1 ];
629                 }
630         }
631
632         QUnit.urlParams = urlParams;
633
634         // String search anywhere in moduleName+testName
635         config.filter = urlParams.filter;
636
637         // Exact match of the module name
638         config.module = urlParams.module;
639
640         config.testNumber = parseInt( urlParams.testNumber, 10 ) || null;
641
642         // Figure out if we're running the tests from a server or not
643         QUnit.isLocal = location.protocol === "file:";
644 }());
645
646 // Export global variables, unless an 'exports' object exists,
647 // in that case we assume we're in CommonJS (dealt with on the bottom of the script)
648 if ( typeof exports === "undefined" ) {
649         extend( window, QUnit );
650
651         // Expose QUnit object
652         window.QUnit = QUnit;
653 }
654
655 // Extend QUnit object,
656 // these after set here because they should not be exposed as global functions
657 extend( QUnit, {
658         config: config,
659
660         // Initialize the configuration options
661         init: function() {
662                 extend( config, {
663                         stats: { all: 0, bad: 0 },
664                         moduleStats: { all: 0, bad: 0 },
665                         started: +new Date(),
666                         updateRate: 1000,
667                         blocking: false,
668                         autostart: true,
669                         autorun: false,
670                         filter: "",
671                         queue: [],
672                         semaphore: 0
673                 });
674
675                 var tests, banner, result,
676                         qunit = id( "qunit" );
677
678                 if ( qunit ) {
679                         qunit.innerHTML =
680                                 "<h1 id='qunit-header'>" + escapeInnerText( document.title ) + "</h1>" +
681                                 "<h2 id='qunit-banner'></h2>" +
682                                 "<div id='qunit-testrunner-toolbar'></div>" +
683                                 "<h2 id='qunit-userAgent'></h2>" +
684                                 "<ol id='qunit-tests'></ol>";
685                 }
686
687                 tests = id( "qunit-tests" );
688                 banner = id( "qunit-banner" );
689                 result = id( "qunit-testresult" );
690
691                 if ( tests ) {
692                         tests.innerHTML = "";
693                 }
694
695                 if ( banner ) {
696                         banner.className = "";
697                 }
698
699                 if ( result ) {
700                         result.parentNode.removeChild( result );
701                 }
702
703                 if ( tests ) {
704                         result = document.createElement( "p" );
705                         result.id = "qunit-testresult";
706                         result.className = "result";
707                         tests.parentNode.insertBefore( result, tests );
708                         result.innerHTML = "Running...<br/>&nbsp;";
709                 }
710         },
711
712         // Resets the test setup. Useful for tests that modify the DOM.
713         // If jQuery is available, uses jQuery's html(), otherwise just innerHTML.
714         reset: function() {
715                 var fixture;
716
717                 if ( window.jQuery ) {
718                         jQuery( "#qunit-fixture" ).html( config.fixture );
719                 } else {
720                         fixture = id( "qunit-fixture" );
721                         if ( fixture ) {
722                                 fixture.innerHTML = config.fixture;
723                         }
724                 }
725         },
726
727         // Trigger an event on an element.
728         // @example triggerEvent( document.body, "click" );
729         triggerEvent: function( elem, type, event ) {
730                 if ( document.createEvent ) {
731                         event = document.createEvent( "MouseEvents" );
732                         event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,
733                                 0, 0, 0, 0, 0, false, false, false, false, 0, null);
734
735                         elem.dispatchEvent( event );
736                 } else if ( elem.fireEvent ) {
737                         elem.fireEvent( "on" + type );
738                 }
739         },
740
741         // Safe object type checking
742         is: function( type, obj ) {
743                 return QUnit.objectType( obj ) == type;
744         },
745
746         objectType: function( obj ) {
747                 if ( typeof obj === "undefined" ) {
748                                 return "undefined";
749                 // consider: typeof null === object
750                 }
751                 if ( obj === null ) {
752                                 return "null";
753                 }
754
755                 var type = toString.call( obj ).match(/^\[object\s(.*)\]$/)[1] || "";
756
757                 switch ( type ) {
758                         case "Number":
759                                 if ( isNaN(obj) ) {
760                                         return "nan";
761                                 }
762                                 return "number";
763                         case "String":
764                         case "Boolean":
765                         case "Array":
766                         case "Date":
767                         case "RegExp":
768                         case "Function":
769                                 return type.toLowerCase();
770                 }
771                 if ( typeof obj === "object" ) {
772                         return "object";
773                 }
774                 return undefined;
775         },
776
777         push: function( result, actual, expected, message ) {
778                 if ( !config.current ) {
779                         throw new Error( "assertion outside test context, was " + sourceFromStacktrace() );
780                 }
781
782                 var output, source,
783                         details = {
784                                 result: result,
785                                 message: message,
786                                 actual: actual,
787                                 expected: expected
788                         };
789
790                 message = escapeInnerText( message ) || ( result ? "okay" : "failed" );
791                 message = "<span class='test-message'>" + message + "</span>";
792                 output = message;
793
794                 if ( !result ) {
795                         expected = escapeInnerText( QUnit.jsDump.parse(expected) );
796                         actual = escapeInnerText( QUnit.jsDump.parse(actual) );
797                         output += "<table><tr class='test-expected'><th>Expected: </th><td><pre>" + expected + "</pre></td></tr>";
798
799                         if ( actual != expected ) {
800                                 output += "<tr class='test-actual'><th>Result: </th><td><pre>" + actual + "</pre></td></tr>";
801                                 output += "<tr class='test-diff'><th>Diff: </th><td><pre>" + QUnit.diff( expected, actual ) + "</pre></td></tr>";
802                         }
803
804                         source = sourceFromStacktrace();
805
806                         if ( source ) {
807                                 details.source = source;
808                                 output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText( source ) + "</pre></td></tr>";
809                         }
810
811                         output += "</table>";
812                 }
813
814                 runLoggingCallbacks( "log", QUnit, details );
815
816                 config.current.assertions.push({
817                         result: !!result,
818                         message: output
819                 });
820         },
821
822         pushFailure: function( message, source, actual ) {
823                 if ( !config.current ) {
824                         throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) );
825                 }
826
827                 var output,
828                         details = {
829                                 result: false,
830                                 message: message
831                         };
832
833                 message = escapeInnerText( message ) || "error";
834                 message = "<span class='test-message'>" + message + "</span>";
835                 output = message;
836
837                 output += "<table>";
838
839                 if ( actual ) {
840                         output += "<tr class='test-actual'><th>Result: </th><td><pre>" + escapeInnerText( actual ) + "</pre></td></tr>";
841                 }
842
843                 if ( source ) {
844                         details.source = source;
845                         output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText( source ) + "</pre></td></tr>";
846                 }
847
848                 output += "</table>";
849
850                 runLoggingCallbacks( "log", QUnit, details );
851
852                 config.current.assertions.push({
853                         result: false,
854                         message: output
855                 });
856         },
857
858         url: function( params ) {
859                 params = extend( extend( {}, QUnit.urlParams ), params );
860                 var key,
861                         querystring = "?";
862
863                 for ( key in params ) {
864                         if ( !hasOwn.call( params, key ) ) {
865                                 continue;
866                         }
867                         querystring += encodeURIComponent( key ) + "=" +
868                                 encodeURIComponent( params[ key ] ) + "&";
869                 }
870                 return window.location.pathname + querystring.slice( 0, -1 );
871         },
872
873         extend: extend,
874         id: id,
875         addEvent: addEvent
876         // load, equiv, jsDump, diff: Attached later
877 });
878
879 /**
880  * @deprecated: Created for backwards compatibility with test runner that set the hook function
881  * into QUnit.{hook}, instead of invoking it and passing the hook function.
882  * QUnit.constructor is set to the empty F() above so that we can add to it's prototype here.
883  * Doing this allows us to tell if the following methods have been overwritten on the actual
884  * QUnit object.
885  */
886 extend( QUnit.constructor.prototype, {
887
888         // Logging callbacks; all receive a single argument with the listed properties
889         // run test/logs.html for any related changes
890         begin: registerLoggingCallback( "begin" ),
891
892         // done: { failed, passed, total, runtime }
893         done: registerLoggingCallback( "done" ),
894
895         // log: { result, actual, expected, message }
896         log: registerLoggingCallback( "log" ),
897
898         // testStart: { name }
899         testStart: registerLoggingCallback( "testStart" ),
900
901         // testDone: { name, failed, passed, total }
902         testDone: registerLoggingCallback( "testDone" ),
903
904         // moduleStart: { name }
905         moduleStart: registerLoggingCallback( "moduleStart" ),
906
907         // moduleDone: { name, failed, passed, total }
908         moduleDone: registerLoggingCallback( "moduleDone" )
909 });
910
911 if ( typeof document === "undefined" || document.readyState === "complete" ) {
912         config.autorun = true;
913 }
914
915 QUnit.load = function() {
916         runLoggingCallbacks( "begin", QUnit, {} );
917
918         // Initialize the config, saving the execution queue
919         var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, urlConfigCheckboxes,
920                 urlConfigHtml = "",
921                 oldconfig = extend( {}, config );
922
923         QUnit.init();
924         extend(config, oldconfig);
925
926         config.blocking = false;
927
928         len = config.urlConfig.length;
929
930         for ( i = 0; i < len; i++ ) {
931                 val = config.urlConfig[i];
932                 if ( typeof val === "string" ) {
933                         val = {
934                                 id: val,
935                                 label: val,
936                                 tooltip: "[no tooltip available]"
937                         };
938                 }
939                 config[ val.id ] = QUnit.urlParams[ val.id ];
940                 urlConfigHtml += "<input id='qunit-urlconfig-" + val.id + "' name='" + val.id + "' type='checkbox'" + ( config[ val.id ] ? " checked='checked'" : "" ) + " title='" + val.tooltip + "'><label for='qunit-urlconfig-" + val.id + "' title='" + val.tooltip + "'>" + val.label + "</label>";
941         }
942
943         // `userAgent` initialized at top of scope
944         userAgent = id( "qunit-userAgent" );
945         if ( userAgent ) {
946                 userAgent.innerHTML = navigator.userAgent;
947         }
948
949         // `banner` initialized at top of scope
950         banner = id( "qunit-header" );
951         if ( banner ) {
952                 banner.innerHTML = "<a href='" + QUnit.url({ filter: undefined, module: undefined, testNumber: undefined }) + "'>" + banner.innerHTML + "</a> ";
953         }
954
955         // `toolbar` initialized at top of scope
956         toolbar = id( "qunit-testrunner-toolbar" );
957         if ( toolbar ) {
958                 // `filter` initialized at top of scope
959                 filter = document.createElement( "input" );
960                 filter.type = "checkbox";
961                 filter.id = "qunit-filter-pass";
962
963                 addEvent( filter, "click", function() {
964                         var tmp,
965                                 ol = document.getElementById( "qunit-tests" );
966
967                         if ( filter.checked ) {
968                                 ol.className = ol.className + " hidepass";
969                         } else {
970                                 tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " ";
971                                 ol.className = tmp.replace( / hidepass /, " " );
972                         }
973                         if ( defined.sessionStorage ) {
974                                 if (filter.checked) {
975                                         sessionStorage.setItem( "qunit-filter-passed-tests", "true" );
976                                 } else {
977                                         sessionStorage.removeItem( "qunit-filter-passed-tests" );
978                                 }
979                         }
980                 });
981
982                 if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) {
983                         filter.checked = true;
984                         // `ol` initialized at top of scope
985                         ol = document.getElementById( "qunit-tests" );
986                         ol.className = ol.className + " hidepass";
987                 }
988                 toolbar.appendChild( filter );
989
990                 // `label` initialized at top of scope
991                 label = document.createElement( "label" );
992                 label.setAttribute( "for", "qunit-filter-pass" );
993                 label.setAttribute( "title", "Only show tests and assertons that fail. Stored in sessionStorage." );
994                 label.innerHTML = "Hide passed tests";
995                 toolbar.appendChild( label );
996
997                 urlConfigCheckboxes = document.createElement( 'span' );
998                 urlConfigCheckboxes.innerHTML = urlConfigHtml;
999                 addEvent( urlConfigCheckboxes, "change", function( event ) {
1000                         var params = {};
1001                         params[ event.target.name ] = event.target.checked ? true : undefined;
1002                         window.location = QUnit.url( params );
1003                 });
1004                 toolbar.appendChild( urlConfigCheckboxes );
1005         }
1006
1007         // `main` initialized at top of scope
1008         main = id( "qunit-fixture" );
1009         if ( main ) {
1010                 config.fixture = main.innerHTML;
1011         }
1012
1013         if ( config.autostart ) {
1014                 QUnit.start();
1015         }
1016 };
1017
1018 addEvent( window, "load", QUnit.load );
1019
1020 // `onErrorFnPrev` initialized at top of scope
1021 // Preserve other handlers
1022 onErrorFnPrev = window.onerror;
1023
1024 // Cover uncaught exceptions
1025 // Returning true will surpress the default browser handler,
1026 // returning false will let it run.
1027 window.onerror = function ( error, filePath, linerNr ) {
1028         var ret = false;
1029         if ( onErrorFnPrev ) {
1030                 ret = onErrorFnPrev( error, filePath, linerNr );
1031         }
1032
1033         // Treat return value as window.onerror itself does,
1034         // Only do our handling if not surpressed.
1035         if ( ret !== true ) {
1036                 if ( QUnit.config.current ) {
1037                         if ( QUnit.config.current.ignoreGlobalErrors ) {
1038                                 return true;
1039                         }
1040                         QUnit.pushFailure( error, filePath + ":" + linerNr );
1041                 } else {
1042                         QUnit.test( "global failure", function() {
1043                                 QUnit.pushFailure( error, filePath + ":" + linerNr );
1044                         });
1045                 }
1046                 return false;
1047         }
1048
1049         return ret;
1050 };
1051
1052 function done() {
1053         config.autorun = true;
1054
1055         // Log the last module results
1056         if ( config.currentModule ) {
1057                 runLoggingCallbacks( "moduleDone", QUnit, {
1058                         name: config.currentModule,
1059                         failed: config.moduleStats.bad,
1060                         passed: config.moduleStats.all - config.moduleStats.bad,
1061                         total: config.moduleStats.all
1062                 });
1063         }
1064
1065         var i, key,
1066                 banner = id( "qunit-banner" ),
1067                 tests = id( "qunit-tests" ),
1068                 runtime = +new Date() - config.started,
1069                 passed = config.stats.all - config.stats.bad,
1070                 html = [
1071                         "Tests completed in ",
1072                         runtime,
1073                         " milliseconds.<br/>",
1074                         "<span class='passed'>",
1075                         passed,
1076                         "</span> tests of <span class='total'>",
1077                         config.stats.all,
1078                         "</span> passed, <span class='failed'>",
1079                         config.stats.bad,
1080                         "</span> failed."
1081                 ].join( "" );
1082
1083         if ( banner ) {
1084                 banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" );
1085         }
1086
1087         if ( tests ) {
1088                 id( "qunit-testresult" ).innerHTML = html;
1089         }
1090
1091         if ( config.altertitle && typeof document !== "undefined" && document.title ) {
1092                 // show ✖ for good, ✔ for bad suite result in title
1093                 // use escape sequences in case file gets loaded with non-utf-8-charset
1094                 document.title = [
1095                         ( config.stats.bad ? "\u2716" : "\u2714" ),
1096                         document.title.replace( /^[\u2714\u2716] /i, "" )
1097                 ].join( " " );
1098         }
1099
1100         // clear own sessionStorage items if all tests passed
1101         if ( config.reorder && defined.sessionStorage && config.stats.bad === 0 ) {
1102                 // `key` & `i` initialized at top of scope
1103                 for ( i = 0; i < sessionStorage.length; i++ ) {
1104                         key = sessionStorage.key( i++ );
1105                         if ( key.indexOf( "qunit-test-" ) === 0 ) {
1106                                 sessionStorage.removeItem( key );
1107                         }
1108                 }
1109         }
1110
1111         runLoggingCallbacks( "done", QUnit, {
1112                 failed: config.stats.bad,
1113                 passed: passed,
1114                 total: config.stats.all,
1115                 runtime: runtime
1116         });
1117 }
1118
1119 /** @return Boolean: true if this test should be ran */
1120 function validTest( test ) {
1121         var include,
1122                 filter = config.filter && config.filter.toLowerCase(),
1123                 module = config.module && config.module.toLowerCase(),
1124                 fullName = (test.module + ": " + test.testName).toLowerCase();
1125
1126         if ( config.testNumber ) {
1127                 return test.testNumber === config.testNumber;
1128         }
1129
1130         if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) {
1131                 return false;
1132         }
1133
1134         if ( !filter ) {
1135                 return true;
1136         }
1137
1138         include = filter.charAt( 0 ) !== "!";
1139         if ( !include ) {
1140                 filter = filter.slice( 1 );
1141         }
1142
1143         // If the filter matches, we need to honour include
1144         if ( fullName.indexOf( filter ) !== -1 ) {
1145                 return include;
1146         }
1147
1148         // Otherwise, do the opposite
1149         return !include;
1150 }
1151
1152 // so far supports only Firefox, Chrome and Opera (buggy), Safari (for real exceptions)
1153 // Later Safari and IE10 are supposed to support error.stack as well
1154 // See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack
1155 function extractStacktrace( e, offset ) {
1156         offset = offset === undefined ? 3 : offset;
1157
1158         var stack, include, i, regex;
1159
1160         if ( e.stacktrace ) {
1161                 // Opera
1162                 return e.stacktrace.split( "\n" )[ offset + 3 ];
1163         } else if ( e.stack ) {
1164                 // Firefox, Chrome
1165                 stack = e.stack.split( "\n" );
1166                 if (/^error$/i.test( stack[0] ) ) {
1167                         stack.shift();
1168                 }
1169                 if ( fileName ) {
1170                         include = [];
1171                         for ( i = offset; i < stack.length; i++ ) {
1172                                 if ( stack[ i ].indexOf( fileName ) != -1 ) {
1173                                         break;
1174                                 }
1175                                 include.push( stack[ i ] );
1176                         }
1177                         if ( include.length ) {
1178                                 return include.join( "\n" );
1179                         }
1180                 }
1181                 return stack[ offset ];
1182         } else if ( e.sourceURL ) {
1183                 // Safari, PhantomJS
1184                 // hopefully one day Safari provides actual stacktraces
1185                 // exclude useless self-reference for generated Error objects
1186                 if ( /qunit.js$/.test( e.sourceURL ) ) {
1187                         return;
1188                 }
1189                 // for actual exceptions, this is useful
1190                 return e.sourceURL + ":" + e.line;
1191         }
1192 }
1193 function sourceFromStacktrace( offset ) {
1194         try {
1195                 throw new Error();
1196         } catch ( e ) {
1197                 return extractStacktrace( e, offset );
1198         }
1199 }
1200
1201 function escapeInnerText( s ) {
1202         if ( !s ) {
1203                 return "";
1204         }
1205         s = s + "";
1206         return s.replace( /[\&<>]/g, function( s ) {
1207                 switch( s ) {
1208                         case "&": return "&amp;";
1209                         case "<": return "&lt;";
1210                         case ">": return "&gt;";
1211                         default: return s;
1212                 }
1213         });
1214 }
1215
1216 function synchronize( callback, last ) {
1217         config.queue.push( callback );
1218
1219         if ( config.autorun && !config.blocking ) {
1220                 process( last );
1221         }
1222 }
1223
1224 function process( last ) {
1225         function next() {
1226                 process( last );
1227         }
1228         var start = new Date().getTime();
1229         config.depth = config.depth ? config.depth + 1 : 1;
1230
1231         while ( config.queue.length && !config.blocking ) {
1232                 if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) {
1233                         config.queue.shift()();
1234                 } else {
1235                         window.setTimeout( next, 13 );
1236                         break;
1237                 }
1238         }
1239         config.depth--;
1240         if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) {
1241                 done();
1242         }
1243 }
1244
1245 function saveGlobal() {
1246         config.pollution = [];
1247
1248         if ( config.noglobals ) {
1249                 for ( var key in window ) {
1250                         // in Opera sometimes DOM element ids show up here, ignore them
1251                         if ( !hasOwn.call( window, key ) || /^qunit-test-output/.test( key ) ) {
1252                                 continue;
1253                         }
1254                         config.pollution.push( key );
1255                 }
1256         }
1257 }
1258
1259 function checkPollution( name ) {
1260         var newGlobals,
1261                 deletedGlobals,
1262                 old = config.pollution;
1263
1264         saveGlobal();
1265
1266         newGlobals = diff( config.pollution, old );
1267         if ( newGlobals.length > 0 ) {
1268                 QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") );
1269         }
1270
1271         deletedGlobals = diff( old, config.pollution );
1272         if ( deletedGlobals.length > 0 ) {
1273                 QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") );
1274         }
1275 }
1276
1277 // returns a new Array with the elements that are in a but not in b
1278 function diff( a, b ) {
1279         var i, j,
1280                 result = a.slice();
1281
1282         for ( i = 0; i < result.length; i++ ) {
1283                 for ( j = 0; j < b.length; j++ ) {
1284                         if ( result[i] === b[j] ) {
1285                                 result.splice( i, 1 );
1286                                 i--;
1287                                 break;
1288                         }
1289                 }
1290         }
1291         return result;
1292 }
1293
1294 function extend( a, b ) {
1295         for ( var prop in b ) {
1296                 if ( b[ prop ] === undefined ) {
1297                         delete a[ prop ];
1298
1299                 // Avoid "Member not found" error in IE8 caused by setting window.constructor
1300                 } else if ( prop !== "constructor" || a !== window ) {
1301                         a[ prop ] = b[ prop ];
1302                 }
1303         }
1304
1305         return a;
1306 }
1307
1308 function addEvent( elem, type, fn ) {
1309         if ( elem.addEventListener ) {
1310                 elem.addEventListener( type, fn, false );
1311         } else if ( elem.attachEvent ) {
1312                 elem.attachEvent( "on" + type, fn );
1313         } else {
1314                 fn();
1315         }
1316 }
1317
1318 function id( name ) {
1319         return !!( typeof document !== "undefined" && document && document.getElementById ) &&
1320                 document.getElementById( name );
1321 }
1322
1323 function registerLoggingCallback( key ) {
1324         return function( callback ) {
1325                 config[key].push( callback );
1326         };
1327 }
1328
1329 // Supports deprecated method of completely overwriting logging callbacks
1330 function runLoggingCallbacks( key, scope, args ) {
1331         var i, callbacks;
1332         if ( QUnit.hasOwnProperty( key ) ) {
1333                 QUnit[ key ].call(scope, args );
1334         } else {
1335                 callbacks = config[ key ];
1336                 for ( i = 0; i < callbacks.length; i++ ) {
1337                         callbacks[ i ].call( scope, args );
1338                 }
1339         }
1340 }
1341
1342 // Test for equality any JavaScript type.
1343 // Author: Philippe Rathé <prathe@gmail.com>
1344 QUnit.equiv = (function() {
1345
1346         // Call the o related callback with the given arguments.
1347         function bindCallbacks( o, callbacks, args ) {
1348                 var prop = QUnit.objectType( o );
1349                 if ( prop ) {
1350                         if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) {
1351                                 return callbacks[ prop ].apply( callbacks, args );
1352                         } else {
1353                                 return callbacks[ prop ]; // or undefined
1354                         }
1355                 }
1356         }
1357
1358         // the real equiv function
1359         var innerEquiv,
1360                 // stack to decide between skip/abort functions
1361                 callers = [],
1362                 // stack to avoiding loops from circular referencing
1363                 parents = [],
1364
1365                 getProto = Object.getPrototypeOf || function ( obj ) {
1366                         return obj.__proto__;
1367                 },
1368                 callbacks = (function () {
1369
1370                         // for string, boolean, number and null
1371                         function useStrictEquality( b, a ) {
1372                                 if ( b instanceof a.constructor || a instanceof b.constructor ) {
1373                                         // to catch short annotaion VS 'new' annotation of a
1374                                         // declaration
1375                                         // e.g. var i = 1;
1376                                         // var j = new Number(1);
1377                                         return a == b;
1378                                 } else {
1379                                         return a === b;
1380                                 }
1381                         }
1382
1383                         return {
1384                                 "string": useStrictEquality,
1385                                 "boolean": useStrictEquality,
1386                                 "number": useStrictEquality,
1387                                 "null": useStrictEquality,
1388                                 "undefined": useStrictEquality,
1389
1390                                 "nan": function( b ) {
1391                                         return isNaN( b );
1392                                 },
1393
1394                                 "date": function( b, a ) {
1395                                         return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf();
1396                                 },
1397
1398                                 "regexp": function( b, a ) {
1399                                         return QUnit.objectType( b ) === "regexp" &&
1400                                                 // the regex itself
1401                                                 a.source === b.source &&
1402                                                 // and its modifers
1403                                                 a.global === b.global &&
1404                                                 // (gmi) ...
1405                                                 a.ignoreCase === b.ignoreCase &&
1406                                                 a.multiline === b.multiline;
1407                                 },
1408
1409                                 // - skip when the property is a method of an instance (OOP)
1410                                 // - abort otherwise,
1411                                 // initial === would have catch identical references anyway
1412                                 "function": function() {
1413                                         var caller = callers[callers.length - 1];
1414                                         return caller !== Object && typeof caller !== "undefined";
1415                                 },
1416
1417                                 "array": function( b, a ) {
1418                                         var i, j, len, loop;
1419
1420                                         // b could be an object literal here
1421                                         if ( QUnit.objectType( b ) !== "array" ) {
1422                                                 return false;
1423                                         }
1424
1425                                         len = a.length;
1426                                         if ( len !== b.length ) {
1427                                                 // safe and faster
1428                                                 return false;
1429                                         }
1430
1431                                         // track reference to avoid circular references
1432                                         parents.push( a );
1433                                         for ( i = 0; i < len; i++ ) {
1434                                                 loop = false;
1435                                                 for ( j = 0; j < parents.length; j++ ) {
1436                                                         if ( parents[j] === a[i] ) {
1437                                                                 loop = true;// dont rewalk array
1438                                                         }
1439                                                 }
1440                                                 if ( !loop && !innerEquiv(a[i], b[i]) ) {
1441                                                         parents.pop();
1442                                                         return false;
1443                                                 }
1444                                         }
1445                                         parents.pop();
1446                                         return true;
1447                                 },
1448
1449                                 "object": function( b, a ) {
1450                                         var i, j, loop,
1451                                                 // Default to true
1452                                                 eq = true,
1453                                                 aProperties = [],
1454                                                 bProperties = [];
1455
1456                                         // comparing constructors is more strict than using
1457                                         // instanceof
1458                                         if ( a.constructor !== b.constructor ) {
1459                                                 // Allow objects with no prototype to be equivalent to
1460                                                 // objects with Object as their constructor.
1461                                                 if ( !(( getProto(a) === null && getProto(b) === Object.prototype ) ||
1462                                                         ( getProto(b) === null && getProto(a) === Object.prototype ) ) ) {
1463                                                                 return false;
1464                                                 }
1465                                         }
1466
1467                                         // stack constructor before traversing properties
1468                                         callers.push( a.constructor );
1469                                         // track reference to avoid circular references
1470                                         parents.push( a );
1471
1472                                         for ( i in a ) { // be strict: don't ensures hasOwnProperty
1473                                                                         // and go deep
1474                                                 loop = false;
1475                                                 for ( j = 0; j < parents.length; j++ ) {
1476                                                         if ( parents[j] === a[i] ) {
1477                                                                 // don't go down the same path twice
1478                                                                 loop = true;
1479                                                         }
1480                                                 }
1481                                                 aProperties.push(i); // collect a's properties
1482
1483                                                 if (!loop && !innerEquiv( a[i], b[i] ) ) {
1484                                                         eq = false;
1485                                                         break;
1486                                                 }
1487                                         }
1488
1489                                         callers.pop(); // unstack, we are done
1490                                         parents.pop();
1491
1492                                         for ( i in b ) {
1493                                                 bProperties.push( i ); // collect b's properties
1494                                         }
1495
1496                                         // Ensures identical properties name
1497                                         return eq && innerEquiv( aProperties.sort(), bProperties.sort() );
1498                                 }
1499                         };
1500                 }());
1501
1502         innerEquiv = function() { // can take multiple arguments
1503                 var args = [].slice.apply( arguments );
1504                 if ( args.length < 2 ) {
1505                         return true; // end transition
1506                 }
1507
1508                 return (function( a, b ) {
1509                         if ( a === b ) {
1510                                 return true; // catch the most you can
1511                         } else if ( a === null || b === null || typeof a === "undefined" ||
1512                                         typeof b === "undefined" ||
1513                                         QUnit.objectType(a) !== QUnit.objectType(b) ) {
1514                                 return false; // don't lose time with error prone cases
1515                         } else {
1516                                 return bindCallbacks(a, callbacks, [ b, a ]);
1517                         }
1518
1519                         // apply transition with (1..n) arguments
1520                 }( args[0], args[1] ) && arguments.callee.apply( this, args.splice(1, args.length - 1 )) );
1521         };
1522
1523         return innerEquiv;
1524 }());
1525
1526 /**
1527  * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com |
1528  * http://flesler.blogspot.com Licensed under BSD
1529  * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008
1530  *
1531  * @projectDescription Advanced and extensible data dumping for Javascript.
1532  * @version 1.0.0
1533  * @author Ariel Flesler
1534  * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html}
1535  */
1536 QUnit.jsDump = (function() {
1537         function quote( str ) {
1538                 return '"' + str.toString().replace( /"/g, '\\"' ) + '"';
1539         }
1540         function literal( o ) {
1541                 return o + "";
1542         }
1543         function join( pre, arr, post ) {
1544                 var s = jsDump.separator(),
1545                         base = jsDump.indent(),
1546                         inner = jsDump.indent(1);
1547                 if ( arr.join ) {
1548                         arr = arr.join( "," + s + inner );
1549                 }
1550                 if ( !arr ) {
1551                         return pre + post;
1552                 }
1553                 return [ pre, inner + arr, base + post ].join(s);
1554         }
1555         function array( arr, stack ) {
1556                 var i = arr.length, ret = new Array(i);
1557                 this.up();
1558                 while ( i-- ) {
1559                         ret[i] = this.parse( arr[i] , undefined , stack);
1560                 }
1561                 this.down();
1562                 return join( "[", ret, "]" );
1563         }
1564
1565         var reName = /^function (\w+)/,
1566                 jsDump = {
1567                         parse: function( obj, type, stack ) { //type is used mostly internally, you can fix a (custom)type in advance
1568                                 stack = stack || [ ];
1569                                 var inStack, res,
1570                                         parser = this.parsers[ type || this.typeOf(obj) ];
1571
1572                                 type = typeof parser;
1573                                 inStack = inArray( obj, stack );
1574
1575                                 if ( inStack != -1 ) {
1576                                         return "recursion(" + (inStack - stack.length) + ")";
1577                                 }
1578                                 //else
1579                                 if ( type == "function" )  {
1580                                         stack.push( obj );
1581                                         res = parser.call( this, obj, stack );
1582                                         stack.pop();
1583                                         return res;
1584                                 }
1585                                 // else
1586                                 return ( type == "string" ) ? parser : this.parsers.error;
1587                         },
1588                         typeOf: function( obj ) {
1589                                 var type;
1590                                 if ( obj === null ) {
1591                                         type = "null";
1592                                 } else if ( typeof obj === "undefined" ) {
1593                                         type = "undefined";
1594                                 } else if ( QUnit.is( "regexp", obj) ) {
1595                                         type = "regexp";
1596                                 } else if ( QUnit.is( "date", obj) ) {
1597                                         type = "date";
1598                                 } else if ( QUnit.is( "function", obj) ) {
1599                                         type = "function";
1600                                 } else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) {
1601                                         type = "window";
1602                                 } else if ( obj.nodeType === 9 ) {
1603                                         type = "document";
1604                                 } else if ( obj.nodeType ) {
1605                                         type = "node";
1606                                 } else if (
1607                                         // native arrays
1608                                         toString.call( obj ) === "[object Array]" ||
1609                                         // NodeList objects
1610                                         ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) )
1611                                 ) {
1612                                         type = "array";
1613                                 } else {
1614                                         type = typeof obj;
1615                                 }
1616                                 return type;
1617                         },
1618                         separator: function() {
1619                                 return this.multiline ? this.HTML ? "<br />" : "\n" : this.HTML ? "&nbsp;" : " ";
1620                         },
1621                         indent: function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing
1622                                 if ( !this.multiline ) {
1623                                         return "";
1624                                 }
1625                                 var chr = this.indentChar;
1626                                 if ( this.HTML ) {
1627                                         chr = chr.replace( /\t/g, "   " ).replace( / /g, "&nbsp;" );
1628                                 }
1629                                 return new Array( this._depth_ + (extra||0) ).join(chr);
1630                         },
1631                         up: function( a ) {
1632                                 this._depth_ += a || 1;
1633                         },
1634                         down: function( a ) {
1635                                 this._depth_ -= a || 1;
1636                         },
1637                         setParser: function( name, parser ) {
1638                                 this.parsers[name] = parser;
1639                         },
1640                         // The next 3 are exposed so you can use them
1641                         quote: quote,
1642                         literal: literal,
1643                         join: join,
1644                         //
1645                         _depth_: 1,
1646                         // This is the list of parsers, to modify them, use jsDump.setParser
1647                         parsers: {
1648                                 window: "[Window]",
1649                                 document: "[Document]",
1650                                 error: "[ERROR]", //when no parser is found, shouldn"t happen
1651                                 unknown: "[Unknown]",
1652                                 "null": "null",
1653                                 "undefined": "undefined",
1654                                 "function": function( fn ) {
1655                                         var ret = "function",
1656                                                 name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];//functions never have name in IE
1657
1658                                         if ( name ) {
1659                                                 ret += " " + name;
1660                                         }
1661                                         ret += "( ";
1662
1663                                         ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" );
1664                                         return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" );
1665                                 },
1666                                 array: array,
1667                                 nodelist: array,
1668                                 "arguments": array,
1669                                 object: function( map, stack ) {
1670                                         var ret = [ ], keys, key, val, i;
1671                                         QUnit.jsDump.up();
1672                                         if ( Object.keys ) {
1673                                                 keys = Object.keys( map );
1674                                         } else {
1675                                                 keys = [];
1676                                                 for ( key in map ) {
1677                                                         keys.push( key );
1678                                                 }
1679                                         }
1680                                         keys.sort();
1681                                         for ( i = 0; i < keys.length; i++ ) {
1682                                                 key = keys[ i ];
1683                                                 val = map[ key ];
1684                                                 ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) );
1685                                         }
1686                                         QUnit.jsDump.down();
1687                                         return join( "{", ret, "}" );
1688                                 },
1689                                 node: function( node ) {
1690                                         var a, val,
1691                                                 open = QUnit.jsDump.HTML ? "&lt;" : "<",
1692                                                 close = QUnit.jsDump.HTML ? "&gt;" : ">",
1693                                                 tag = node.nodeName.toLowerCase(),
1694                                                 ret = open + tag;
1695
1696                                         for ( a in QUnit.jsDump.DOMAttrs ) {
1697                                                 val = node[ QUnit.jsDump.DOMAttrs[a] ];
1698                                                 if ( val ) {
1699                                                         ret += " " + a + "=" + QUnit.jsDump.parse( val, "attribute" );
1700                                                 }
1701                                         }
1702                                         return ret + close + open + "/" + tag + close;
1703                                 },
1704                                 functionArgs: function( fn ) {//function calls it internally, it's the arguments part of the function
1705                                         var args,
1706                                                 l = fn.length;
1707
1708                                         if ( !l ) {
1709                                                 return "";
1710                                         }
1711
1712                                         args = new Array(l);
1713                                         while ( l-- ) {
1714                                                 args[l] = String.fromCharCode(97+l);//97 is 'a'
1715                                         }
1716                                         return " " + args.join( ", " ) + " ";
1717                                 },
1718                                 key: quote, //object calls it internally, the key part of an item in a map
1719                                 functionCode: "[code]", //function calls it internally, it's the content of the function
1720                                 attribute: quote, //node calls it internally, it's an html attribute value
1721                                 string: quote,
1722                                 date: quote,
1723                                 regexp: literal, //regex
1724                                 number: literal,
1725                                 "boolean": literal
1726                         },
1727                         DOMAttrs: {
1728                                 //attributes to dump from nodes, name=>realName
1729                                 id: "id",
1730                                 name: "name",
1731                                 "class": "className"
1732                         },
1733                         HTML: false,//if true, entities are escaped ( <, >, \t, space and \n )
1734                         indentChar: "  ",//indentation unit
1735                         multiline: true //if true, items in a collection, are separated by a \n, else just a space.
1736                 };
1737
1738         return jsDump;
1739 }());
1740
1741 // from Sizzle.js
1742 function getText( elems ) {
1743         var i, elem,
1744                 ret = "";
1745
1746         for ( i = 0; elems[i]; i++ ) {
1747                 elem = elems[i];
1748
1749                 // Get the text from text nodes and CDATA nodes
1750                 if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
1751                         ret += elem.nodeValue;
1752
1753                 // Traverse everything else, except comment nodes
1754                 } else if ( elem.nodeType !== 8 ) {
1755                         ret += getText( elem.childNodes );
1756                 }
1757         }
1758
1759         return ret;
1760 }
1761
1762 // from jquery.js
1763 function inArray( elem, array ) {
1764         if ( array.indexOf ) {
1765                 return array.indexOf( elem );
1766         }
1767
1768         for ( var i = 0, length = array.length; i < length; i++ ) {
1769                 if ( array[ i ] === elem ) {
1770                         return i;
1771                 }
1772         }
1773
1774         return -1;
1775 }
1776
1777 /*
1778  * Javascript Diff Algorithm
1779  *  By John Resig (http://ejohn.org/)
1780  *  Modified by Chu Alan "sprite"
1781  *
1782  * Released under the MIT license.
1783  *
1784  * More Info:
1785  *  http://ejohn.org/projects/javascript-diff-algorithm/
1786  *
1787  * Usage: QUnit.diff(expected, actual)
1788  *
1789  * QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) == "the  quick <del>brown </del> fox <del>jumped </del><ins>jumps </ins> over"
1790  */
1791 QUnit.diff = (function() {
1792         function diff( o, n ) {
1793                 var i,
1794                         ns = {},
1795                         os = {};
1796
1797                 for ( i = 0; i < n.length; i++ ) {
1798                         if ( ns[ n[i] ] == null ) {
1799                                 ns[ n[i] ] = {
1800                                         rows: [],
1801                                         o: null
1802                                 };
1803                         }
1804                         ns[ n[i] ].rows.push( i );
1805                 }
1806
1807                 for ( i = 0; i < o.length; i++ ) {
1808                         if ( os[ o[i] ] == null ) {
1809                                 os[ o[i] ] = {
1810                                         rows: [],
1811                                         n: null
1812                                 };
1813                         }
1814                         os[ o[i] ].rows.push( i );
1815                 }
1816
1817                 for ( i in ns ) {
1818                         if ( !hasOwn.call( ns, i ) ) {
1819                                 continue;
1820                         }
1821                         if ( ns[i].rows.length == 1 && typeof os[i] != "undefined" && os[i].rows.length == 1 ) {
1822                                 n[ ns[i].rows[0] ] = {
1823                                         text: n[ ns[i].rows[0] ],
1824                                         row: os[i].rows[0]
1825                                 };
1826                                 o[ os[i].rows[0] ] = {
1827                                         text: o[ os[i].rows[0] ],
1828                                         row: ns[i].rows[0]
1829                                 };
1830                         }
1831                 }
1832
1833                 for ( i = 0; i < n.length - 1; i++ ) {
1834                         if ( n[i].text != null && n[ i + 1 ].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null &&
1835                                                 n[ i + 1 ] == o[ n[i].row + 1 ] ) {
1836
1837                                 n[ i + 1 ] = {
1838                                         text: n[ i + 1 ],
1839                                         row: n[i].row + 1
1840                                 };
1841                                 o[ n[i].row + 1 ] = {
1842                                         text: o[ n[i].row + 1 ],
1843                                         row: i + 1
1844                                 };
1845                         }
1846                 }
1847
1848                 for ( i = n.length - 1; i > 0; i-- ) {
1849                         if ( n[i].text != null && n[ i - 1 ].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null &&
1850                                                 n[ i - 1 ] == o[ n[i].row - 1 ]) {
1851
1852                                 n[ i - 1 ] = {
1853                                         text: n[ i - 1 ],
1854                                         row: n[i].row - 1
1855                                 };
1856                                 o[ n[i].row - 1 ] = {
1857                                         text: o[ n[i].row - 1 ],
1858                                         row: i - 1
1859                                 };
1860                         }
1861                 }
1862
1863                 return {
1864                         o: o,
1865                         n: n
1866                 };
1867         }
1868
1869         return function( o, n ) {
1870                 o = o.replace( /\s+$/, "" );
1871                 n = n.replace( /\s+$/, "" );
1872
1873                 var i, pre,
1874                         str = "",
1875                         out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ),
1876                         oSpace = o.match(/\s+/g),
1877                         nSpace = n.match(/\s+/g);
1878
1879                 if ( oSpace == null ) {
1880                         oSpace = [ " " ];
1881                 }
1882                 else {
1883                         oSpace.push( " " );
1884                 }
1885
1886                 if ( nSpace == null ) {
1887                         nSpace = [ " " ];
1888                 }
1889                 else {
1890                         nSpace.push( " " );
1891                 }
1892
1893                 if ( out.n.length === 0 ) {
1894                         for ( i = 0; i < out.o.length; i++ ) {
1895                                 str += "<del>" + out.o[i] + oSpace[i] + "</del>";
1896                         }
1897                 }
1898                 else {
1899                         if ( out.n[0].text == null ) {
1900                                 for ( n = 0; n < out.o.length && out.o[n].text == null; n++ ) {
1901                                         str += "<del>" + out.o[n] + oSpace[n] + "</del>";
1902                                 }
1903                         }
1904
1905                         for ( i = 0; i < out.n.length; i++ ) {
1906                                 if (out.n[i].text == null) {
1907                                         str += "<ins>" + out.n[i] + nSpace[i] + "</ins>";
1908                                 }
1909                                 else {
1910                                         // `pre` initialized at top of scope
1911                                         pre = "";
1912
1913                                         for ( n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) {
1914                                                 pre += "<del>" + out.o[n] + oSpace[n] + "</del>";
1915                                         }
1916                                         str += " " + out.n[i].text + nSpace[i] + pre;
1917                                 }
1918                         }
1919                 }
1920
1921                 return str;
1922         };
1923 }());
1924
1925 // for CommonJS enviroments, export everything
1926 if ( typeof exports !== "undefined" ) {
1927         extend(exports, QUnit);
1928 }
1929
1930 // get at whatever the global object is, like window in browsers
1931 }( (function() {return this;}.call()) ));