annotate vakata-jstree-3.3.5/test/unit/libs/qunit.js @ 0:c12e291895ff draft

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