2012-04-15 21:41:54 +00:00
|
|
|
/*jshint multistr:true*/
|
|
|
|
|
2009-09-29 18:06:16 +00:00
|
|
|
var jQuery = this.jQuery || "jQuery", // For testing .noConflict()
|
|
|
|
$ = this.$ || "$",
|
|
|
|
originaljQuery = jQuery,
|
2011-04-17 03:35:18 +00:00
|
|
|
original$ = $,
|
2012-02-14 23:19:32 +00:00
|
|
|
hasPHP = true,
|
2011-10-28 18:17:14 +00:00
|
|
|
amdDefined;
|
2011-04-17 03:35:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up a mock AMD define function for testing AMD registration.
|
|
|
|
*/
|
2012-05-29 16:40:13 +00:00
|
|
|
function define( name, dependencies, callback ) {
|
2011-04-17 03:35:18 +00:00
|
|
|
amdDefined = callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
define.amd = {
|
|
|
|
jQuery: true
|
|
|
|
};
|
2009-09-29 18:11:10 +00:00
|
|
|
|
|
|
|
/**
|
2012-05-29 16:40:13 +00:00
|
|
|
* Returns an array of elements with the given IDs
|
2009-09-29 18:11:10 +00:00
|
|
|
* @example q("main", "foo", "bar")
|
|
|
|
* @result [<div id="main">, <span id="foo">, <input id="bar">]
|
|
|
|
*/
|
|
|
|
function q() {
|
2012-05-28 16:43:41 +00:00
|
|
|
var r = [],
|
|
|
|
i = 0;
|
2009-09-29 18:11:10 +00:00
|
|
|
|
2012-05-28 16:43:41 +00:00
|
|
|
for ( ; i < arguments.length; i++ ) {
|
2009-09-29 18:11:10 +00:00
|
|
|
r.push( document.getElementById( arguments[i] ) );
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-05-29 16:40:13 +00:00
|
|
|
* Asserts that a select matches the given IDs
|
2012-05-28 16:43:41 +00:00
|
|
|
* @param {String} a - Assertion name
|
|
|
|
* @param {String} b - Sizzle selector
|
|
|
|
* @param {String} c - Array of ids to construct what is expected
|
2012-05-29 16:40:13 +00:00
|
|
|
* @example t("Check for something", "//[a]", ["foo", "baar"]);
|
2011-09-12 23:40:14 +00:00
|
|
|
* @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar'
|
2009-09-29 18:11:10 +00:00
|
|
|
*/
|
2012-05-28 16:43:41 +00:00
|
|
|
function t( a, b, c ) {
|
|
|
|
var f = jQuery(b).get(),
|
|
|
|
s = "",
|
|
|
|
i = 0;
|
2009-09-29 18:11:10 +00:00
|
|
|
|
2012-05-28 16:43:41 +00:00
|
|
|
for ( ; i < f.length; i++ ) {
|
|
|
|
s += ( s && "," ) + '"' + f[ i ].id + '"';
|
2009-09-29 18:11:10 +00:00
|
|
|
}
|
|
|
|
|
2012-05-28 16:43:41 +00:00
|
|
|
deepEqual(f, q.apply( q, c ), a + " (" + b + ")");
|
2009-09-29 18:11:10 +00:00
|
|
|
}
|
|
|
|
|
2012-04-15 21:41:54 +00:00
|
|
|
var createDashboardXML = function() {
|
|
|
|
var string = '<?xml version="1.0" encoding="UTF-8"?> \
|
|
|
|
<dashboard> \
|
|
|
|
<locations class="foo"> \
|
|
|
|
<location for="bar" checked="different"> \
|
2012-07-12 02:46:34 +00:00
|
|
|
<infowindowtab normal="ab" mixedCase="yes"> \
|
2012-04-15 21:41:54 +00:00
|
|
|
<tab title="Location"><![CDATA[blabla]]></tab> \
|
|
|
|
<tab title="Users"><![CDATA[blublu]]></tab> \
|
|
|
|
</infowindowtab> \
|
|
|
|
</location> \
|
|
|
|
</locations> \
|
|
|
|
</dashboard>';
|
|
|
|
|
|
|
|
return jQuery.parseXML(string);
|
|
|
|
};
|
|
|
|
|
|
|
|
var createWithFriesXML = function() {
|
|
|
|
var string = '<?xml version="1.0" encoding="UTF-8"?> \
|
|
|
|
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" \
|
|
|
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
|
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> \
|
|
|
|
<soap:Body> \
|
|
|
|
<jsconf xmlns="http://www.example.com/ns1"> \
|
|
|
|
<response xmlns:ab="http://www.example.com/ns2"> \
|
|
|
|
<meta> \
|
|
|
|
<component id="seite1" class="component"> \
|
|
|
|
<properties xmlns:cd="http://www.example.com/ns3"> \
|
|
|
|
<property name="prop1"> \
|
|
|
|
<thing /> \
|
|
|
|
<value>1</value> \
|
|
|
|
</property> \
|
|
|
|
<property name="prop2"> \
|
|
|
|
<thing att="something" /> \
|
|
|
|
</property> \
|
|
|
|
<foo_bar>foo</foo_bar> \
|
|
|
|
</properties> \
|
|
|
|
</component> \
|
|
|
|
</meta> \
|
|
|
|
</response> \
|
|
|
|
</jsconf> \
|
|
|
|
</soap:Body> \
|
|
|
|
</soap:Envelope>';
|
|
|
|
|
|
|
|
return jQuery.parseXML(string);
|
|
|
|
};
|
|
|
|
|
2011-10-28 18:17:14 +00:00
|
|
|
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 );
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-09-29 18:11:10 +00:00
|
|
|
/**
|
2012-05-29 16:40:13 +00:00
|
|
|
* Add random number to url to stop caching
|
2009-09-29 18:11:10 +00:00
|
|
|
*
|
|
|
|
* @example url("data/test.html")
|
|
|
|
* @result "data/test.html?10538358428943"
|
|
|
|
*
|
|
|
|
* @example url("data/test.php?foo=bar")
|
|
|
|
* @result "data/test.php?foo=bar&10538358345554"
|
|
|
|
*/
|
2012-05-29 16:40:13 +00:00
|
|
|
function url( value ) {
|
2009-09-29 18:11:10 +00:00
|
|
|
return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000);
|
|
|
|
}
|
2011-01-09 21:58:47 +00:00
|
|
|
|
|
|
|
(function () {
|
|
|
|
// Store the old counts so that we only assert on tests that have actually leaked,
|
|
|
|
// instead of asserting every time a test has leaked sometime in the past
|
|
|
|
var oldCacheLength = 0,
|
|
|
|
oldFragmentsLength = 0,
|
|
|
|
oldTimersLength = 0,
|
2012-06-11 19:04:34 +00:00
|
|
|
oldActive = 0;
|
2011-01-09 21:58:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that tests have cleaned up properly after themselves. Should be passed as the
|
|
|
|
* teardown function on all modules' lifecycle object.
|
|
|
|
*/
|
|
|
|
this.moduleTeardown = function () {
|
|
|
|
var i, fragmentsLength = 0, cacheLength = 0;
|
|
|
|
|
|
|
|
// Allow QUnit.reset to clean up any attached elements before checking for leaks
|
|
|
|
QUnit.reset();
|
|
|
|
|
|
|
|
for ( i in jQuery.cache ) {
|
|
|
|
++cacheLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
jQuery.fragments = {};
|
|
|
|
|
|
|
|
for ( i in jQuery.fragments ) {
|
|
|
|
++fragmentsLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Because QUnit doesn't have a mechanism for retrieving the number of expected assertions for a test,
|
|
|
|
// if we unconditionally assert any of these, the test will fail with too many assertions :|
|
|
|
|
if ( cacheLength !== oldCacheLength ) {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( cacheLength, oldCacheLength, "No unit tests leak memory in jQuery.cache" );
|
2011-01-09 21:58:47 +00:00
|
|
|
oldCacheLength = cacheLength;
|
|
|
|
}
|
|
|
|
if ( fragmentsLength !== oldFragmentsLength ) {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" );
|
2011-01-09 21:58:47 +00:00
|
|
|
oldFragmentsLength = fragmentsLength;
|
|
|
|
}
|
2012-05-29 02:25:04 +00:00
|
|
|
if ( jQuery.timers && jQuery.timers.length !== oldTimersLength ) {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( jQuery.timers.length, oldTimersLength, "No timers are still running" );
|
2011-01-09 21:58:47 +00:00
|
|
|
oldTimersLength = jQuery.timers.length;
|
|
|
|
}
|
2012-06-11 19:04:34 +00:00
|
|
|
if ( jQuery.active !== undefined && jQuery.active !== oldActive ) {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( jQuery.active, 0, "No AJAX requests are still active" );
|
2011-01-09 21:58:47 +00:00
|
|
|
oldActive = jQuery.active;
|
|
|
|
}
|
2012-02-14 23:19:32 +00:00
|
|
|
};
|
2012-02-23 20:48:12 +00:00
|
|
|
|
|
|
|
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() {
|
2012-04-23 19:43:26 +00:00
|
|
|
var src = url("./data/" + fileName + ".html"),
|
2012-06-11 01:54:16 +00:00
|
|
|
iframe = jQuery("<iframe />").appendTo("body")[0];
|
|
|
|
iframe.style.cssText = "width: 500px; height: 500px; position: absolute; top: -600px; left: -600px; visibility: hidden;";
|
2012-02-23 20:48:12 +00:00
|
|
|
iframe.contentWindow.location = src;
|
|
|
|
return iframe;
|
|
|
|
}
|
|
|
|
};
|
2012-04-23 19:43:26 +00:00
|
|
|
|
|
|
|
this.testIframeWithCallback = function( title, fileName, func ) {
|
|
|
|
|
|
|
|
test( title, function() {
|
|
|
|
var iframe;
|
|
|
|
|
|
|
|
stop();
|
|
|
|
window.iframeCallback = function() {
|
|
|
|
var self = this,
|
|
|
|
args = arguments;
|
|
|
|
setTimeout(function() {
|
|
|
|
window.iframeCallback = undefined;
|
|
|
|
iframe.remove();
|
|
|
|
func.apply( self, args );
|
|
|
|
func = function() {};
|
|
|
|
start();
|
|
|
|
}, 0 );
|
|
|
|
};
|
|
|
|
iframe = jQuery( "<div/>" ).append(
|
2012-08-19 21:41:43 +00:00
|
|
|
jQuery( "<iframe/>" ).attr( "src", url( "./data/" + fileName ) )
|
2012-04-23 19:43:26 +00:00
|
|
|
).appendTo( "body" );
|
|
|
|
});
|
|
|
|
}
|
2012-03-07 17:23:46 +00:00
|
|
|
}());
|
|
|
|
|
|
|
|
// Sandbox start for great justice
|
|
|
|
(function() {
|
|
|
|
var oldStart = window.start;
|
|
|
|
window.start = function() {
|
|
|
|
oldStart();
|
|
|
|
};
|
2012-04-15 21:41:54 +00:00
|
|
|
})();
|