Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

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

Hosting is provided AltSPAHow to use Git
Please direct any questions on jabber alex.wolf@jabber.ru

Valid HTML 4.0 Transitional Valid CSS!

Designer Alexander Wolf