/*jshint multistr:true */ var originaljQuery = this.jQuery || "jQuery", original$ = this.$ || "$", hasPHP = true, // Disable Ajax tests to reduce network strain // Re-enabled (at least the variable should be declared) isLocal = window.location.protocol === "file:", amdDefined; // For testing .noConflict() this.jQuery = originaljQuery; this.$ = original$; /** * Set up a mock AMD define function for testing AMD registration. */ function define( name, dependencies, callback ) { amdDefined = callback(); } define.amd = { jQuery: true }; /** * Returns an array of elements with the given IDs * @example q("main", "foo", "bar") * @result [
, , ] */ function q() { var r = [], i = 0; for ( ; i < arguments.length; i++ ) { r.push( document.getElementById( arguments[i] ) ); } return r; } /** * Asserts that a select matches the given IDs * @param {String} a - Assertion name * @param {String} b - Sizzle selector * @param {String} c - Array of ids to construct what is expected * @example t("Check for something", "//[a]", ["foo", "baar"]); * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar' */ function t( a, b, c ) { var f = jQuery(b).get(), s = "", i = 0; for ( ; i < f.length; i++ ) { s += ( s && "," ) + '"' + f[ i ].id + '"'; } deepEqual(f, q.apply( q, c ), a + " (" + b + ")"); } var createDashboardXML = function() { var string = ' \ \ \ \ \ \ \ \ \ \ '; return jQuery.parseXML(string); }; var createWithFriesXML = function() { var string = ' \ \ \ \ \ \ \ \ \ \ 1 \ \ \ \ \ foo \ \ \ \ \ \ \ '; return jQuery.parseXML(string); }; var createXMLFragment = function() { var xml, frag; if ( window.ActiveXObject ) { xml = new ActiveXObject("msxml2.domdocument"); } else { xml = document.implementation.createDocument( "", "", null ); } if ( xml ) { frag = xml.createElement("data"); } return frag; }; var fireNative; if ( document.createEvent ) { fireNative = function( node, type ) { var event = document.createEvent('HTMLEvents'); event.initEvent( type, true, true ); node.dispatchEvent( event ); }; } else { fireNative = function( node, type ) { var event = document.createEventObject(); node.fireEvent( 'on' + type, event ); }; } /** * Add random number to url to stop caching * * @example url("data/test.html") * @result "data/test.html?10538358428943" * * @example url("data/test.php?foo=bar") * @result "data/test.php?foo=bar&10538358345554" */ function url( value ) { return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random() * 100000, 10); } (function () { this.testIframe = function( fileName, name, fn ) { test(name, function() { // pause execution for now stop(); // load fixture in iframe var iframe = loadFixture(), win = iframe.contentWindow, interval = setInterval( function() { if ( win && win.jQuery && win.jQuery.isReady ) { clearInterval( interval ); // continue start(); // call actual tests passing the correct jQuery instance to use fn.call( this, win.jQuery, win, win.document ); document.body.removeChild( iframe ); iframe = null; } }, 15 ); }); function loadFixture() { var src = url("./data/" + fileName + ".html"), iframe = jQuery("