Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/tests/qunit.js

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

Powered by Google App Engine
This is Rietveld