qunit.js 62 KB

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