2012-11-25 19:30:16 +00:00
|
|
|
/*jshint multistr:true, quotmark:false */
|
2012-04-15 21:41:54 +00:00
|
|
|
|
2013-09-03 13:55:32 +00:00
|
|
|
var fireNative, originaljQuery, original$,
|
2013-10-11 19:08:07 +00:00
|
|
|
baseURL = "",
|
2013-09-03 13:55:32 +00:00
|
|
|
supportjQuery = this.jQuery,
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-11-01 21:32:08 +00:00
|
|
|
// see RFC 2606
|
|
|
|
externalHost = "example.com";
|
2011-04-17 03:35:18 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
this.hasPHP = true;
|
|
|
|
this.isLocal = window.location.protocol === "file:";
|
|
|
|
|
2013-09-03 13:55:32 +00:00
|
|
|
// Setup global variables before loading jQuery for testing .noConflict()
|
|
|
|
supportjQuery.noConflict( true );
|
|
|
|
originaljQuery = this.jQuery = undefined;
|
|
|
|
original$ = this.$ = "replaced";
|
2012-11-01 04:40:27 +00:00
|
|
|
|
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
|
2015-09-03 01:46:31 +00:00
|
|
|
* @example q( "main", "foo", "bar" )
|
2009-09-29 18:11:10 +00:00
|
|
|
* @result [<div id="main">, <span id="foo">, <input id="bar">]
|
|
|
|
*/
|
2013-04-09 15:45:09 +00:00
|
|
|
this.q = function() {
|
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++ ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
r.push( document.getElementById( arguments[ i ] ) );
|
2009-09-29 18:11:10 +00:00
|
|
|
}
|
|
|
|
return r;
|
2013-04-09 15:45:09 +00:00
|
|
|
};
|
2009-09-29 18:11:10 +00:00
|
|
|
|
|
|
|
/**
|
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
|
2015-09-18 16:59:48 +00:00
|
|
|
* @example t("Check for something", "//[a]", ["foo", "bar"]);
|
|
|
|
* @result returns true if "//[a]" return two elements with the IDs 'foo' and 'bar'
|
2009-09-29 18:11:10 +00:00
|
|
|
*/
|
2015-09-08 00:26:29 +00:00
|
|
|
QUnit.assert.t = function( a, b, c ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
var f = jQuery( b ).get(),
|
2012-05-28 16:43:41 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-09-08 00:26:29 +00:00
|
|
|
this.deepEqual( f, q.apply( q, c ), a + " (" + b + ")" );
|
2013-04-09 15:45:09 +00:00
|
|
|
};
|
2009-09-29 18:11:10 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
this.createDashboardXML = function() {
|
2012-04-15 21:41:54 +00:00
|
|
|
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>';
|
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
return jQuery.parseXML( string );
|
2013-04-09 15:45:09 +00:00
|
|
|
};
|
2012-04-15 21:41:54 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
this.createWithFriesXML = function() {
|
2012-04-15 21:41:54 +00:00
|
|
|
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> \
|
2012-11-01 21:32:08 +00:00
|
|
|
<jsconf xmlns="http://{{ externalHost }}/ns1"> \
|
|
|
|
<response xmlns:ab="http://{{ externalHost }}/ns2"> \
|
2012-04-15 21:41:54 +00:00
|
|
|
<meta> \
|
|
|
|
<component id="seite1" class="component"> \
|
2012-11-01 21:32:08 +00:00
|
|
|
<properties xmlns:cd="http://{{ externalHost }}/ns3"> \
|
2012-04-15 21:41:54 +00:00
|
|
|
<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> \
|
2012-12-05 13:54:14 +00:00
|
|
|
</soap:Envelope>';
|
2012-04-15 21:41:54 +00:00
|
|
|
|
2012-12-05 13:54:14 +00:00
|
|
|
return jQuery.parseXML( string.replace( /\{\{\s*externalHost\s*\}\}/g, externalHost ) );
|
2013-04-09 15:45:09 +00:00
|
|
|
};
|
2012-04-15 21:41:54 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
this.createXMLFragment = function() {
|
2012-10-15 18:20:36 +00:00
|
|
|
var xml, frag;
|
|
|
|
if ( window.ActiveXObject ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
xml = new ActiveXObject( "msxml2.domdocument" );
|
2012-10-15 18:20:36 +00:00
|
|
|
} else {
|
|
|
|
xml = document.implementation.createDocument( "", "", null );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( xml ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
frag = xml.createElement( "data" );
|
2012-10-15 18:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return frag;
|
2013-04-09 15:45:09 +00:00
|
|
|
};
|
2012-10-15 18:20:36 +00:00
|
|
|
|
2012-11-01 21:32:08 +00:00
|
|
|
fireNative = document.createEvent ?
|
|
|
|
function( node, type ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
var event = document.createEvent( "HTMLEvents" );
|
2015-09-03 01:46:31 +00:00
|
|
|
|
2011-10-28 18:17:14 +00:00
|
|
|
event.initEvent( type, true, true );
|
|
|
|
node.dispatchEvent( event );
|
2012-11-01 21:32:08 +00:00
|
|
|
} :
|
|
|
|
function( node, type ) {
|
2015-09-03 01:46:31 +00:00
|
|
|
node.fireEvent( "on" + type, document.createEventObject() );
|
2011-10-28 18:17:14 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
*
|
2012-12-05 13:54:14 +00:00
|
|
|
* @example url("data/test.html")
|
|
|
|
* @result "data/test.html?10538358428943"
|
2009-09-29 18:11:10 +00:00
|
|
|
*
|
2012-12-05 13:54:14 +00:00
|
|
|
* @example url("data/test.php?foo=bar")
|
|
|
|
* @result "data/test.php?foo=bar&10538358345554"
|
2009-09-29 18:11:10 +00:00
|
|
|
*/
|
2012-05-29 16:40:13 +00:00
|
|
|
function url( value ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
return baseURL + value + ( /\?/.test( value ) ? "&" : "?" ) +
|
2014-02-18 15:49:24 +00:00
|
|
|
new Date().getTime() + "" + parseInt( Math.random() * 100000, 10 );
|
2009-09-29 18:11:10 +00:00
|
|
|
}
|
2011-01-09 21:58:47 +00:00
|
|
|
|
2012-11-26 02:31:19 +00:00
|
|
|
// Ajax testing helper
|
2013-04-09 15:45:09 +00:00
|
|
|
this.ajaxTest = function( title, expect, options ) {
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( title, expect, function( assert ) {
|
|
|
|
var requestOptions;
|
|
|
|
|
|
|
|
if ( jQuery.isFunction( options ) ) {
|
|
|
|
options = options( assert );
|
|
|
|
}
|
|
|
|
options = options || [];
|
|
|
|
requestOptions = options.requests || options.request || options;
|
|
|
|
if ( !jQuery.isArray( requestOptions ) ) {
|
|
|
|
requestOptions = [ requestOptions ];
|
|
|
|
}
|
|
|
|
|
|
|
|
var done = assert.async();
|
|
|
|
|
2012-11-26 10:49:20 +00:00
|
|
|
if ( options.setup ) {
|
|
|
|
options.setup();
|
2012-11-26 02:31:19 +00:00
|
|
|
}
|
2012-12-03 04:32:16 +00:00
|
|
|
|
|
|
|
var completed = false,
|
2012-12-03 16:32:19 +00:00
|
|
|
remaining = requestOptions.length,
|
2012-12-03 04:32:16 +00:00
|
|
|
complete = function() {
|
2012-12-03 16:32:19 +00:00
|
|
|
if ( !completed && --remaining === 0 ) {
|
|
|
|
completed = true;
|
|
|
|
delete ajaxTest.abort;
|
|
|
|
if ( options.teardown ) {
|
|
|
|
options.teardown();
|
|
|
|
}
|
2015-09-03 01:46:31 +00:00
|
|
|
|
|
|
|
// Make sure all events will be called before done()
|
|
|
|
setTimeout( done );
|
2012-11-26 10:49:20 +00:00
|
|
|
}
|
|
|
|
},
|
2012-12-03 16:32:19 +00:00
|
|
|
requests = jQuery.map( requestOptions, function( options ) {
|
2012-12-03 04:32:16 +00:00
|
|
|
var request = ( options.create || jQuery.ajax )( options ),
|
|
|
|
callIfDefined = function( deferType, optionType ) {
|
|
|
|
var handler = options[ deferType ] || !!options[ optionType ];
|
2012-12-03 16:32:19 +00:00
|
|
|
return function( _, status ) {
|
|
|
|
if ( !completed ) {
|
|
|
|
if ( !handler ) {
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.ok( false, "unexpected " + status );
|
2012-12-03 16:32:19 +00:00
|
|
|
} else if ( jQuery.isFunction( handler ) ) {
|
2012-12-03 04:32:16 +00:00
|
|
|
handler.apply( this, arguments );
|
|
|
|
}
|
2012-12-03 16:32:19 +00:00
|
|
|
}
|
|
|
|
};
|
2012-12-03 04:32:16 +00:00
|
|
|
};
|
|
|
|
|
2012-11-26 10:49:20 +00:00
|
|
|
if ( options.afterSend ) {
|
2015-09-03 01:46:31 +00:00
|
|
|
options.afterSend( request, assert );
|
2012-11-26 10:49:20 +00:00
|
|
|
}
|
2012-12-03 04:32:16 +00:00
|
|
|
|
2012-12-03 05:49:40 +00:00
|
|
|
return request
|
|
|
|
.done( callIfDefined( "done", "success" ) )
|
2012-12-03 16:32:19 +00:00
|
|
|
.fail( callIfDefined( "fail", "error" ) )
|
|
|
|
.always( complete );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-12-03 04:32:16 +00:00
|
|
|
|
2012-12-03 16:32:19 +00:00
|
|
|
ajaxTest.abort = function( reason ) {
|
|
|
|
if ( !completed ) {
|
|
|
|
completed = true;
|
|
|
|
delete ajaxTest.abort;
|
2015-09-08 00:26:29 +00:00
|
|
|
assert.ok( false, "aborted " + reason );
|
2012-12-03 16:32:19 +00:00
|
|
|
jQuery.each( requests, function( i, request ) {
|
|
|
|
request.abort();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-12-03 16:32:19 +00:00
|
|
|
}
|
|
|
|
};
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2013-04-09 15:45:09 +00:00
|
|
|
};
|
2012-11-26 02:31:19 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
this.testIframe = function( fileName, name, fn ) {
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( name, function( assert ) {
|
|
|
|
var done = assert.async();
|
2012-04-23 19:43:26 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
// load fixture in iframe
|
|
|
|
var iframe = loadFixture(),
|
|
|
|
win = iframe.contentWindow,
|
2015-09-02 23:52:01 +00:00
|
|
|
interval = setInterval( function() {
|
2013-04-09 15:45:09 +00:00
|
|
|
if ( win && win.jQuery && win.jQuery.isReady ) {
|
|
|
|
clearInterval( interval );
|
2014-02-18 15:49:24 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
// call actual tests passing the correct jQuery instance to use
|
2015-09-03 01:46:31 +00:00
|
|
|
fn.call( this, win.jQuery, win, win.document, assert );
|
|
|
|
done();
|
2013-04-09 15:45:09 +00:00
|
|
|
document.body.removeChild( iframe );
|
|
|
|
iframe = null;
|
|
|
|
}
|
|
|
|
}, 15 );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-11-01 21:32:08 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
function loadFixture() {
|
2014-02-18 15:49:24 +00:00
|
|
|
var src = url( "./data/" + fileName + ".html" ),
|
|
|
|
iframe = jQuery( "<iframe />" ).appendTo( "body" )[ 0 ];
|
2014-07-17 17:25:59 +00:00
|
|
|
iframe.style.cssText = "width: 500px; height: 500px; position: absolute; " +
|
|
|
|
"top: -600px; left: -600px; visibility: hidden;";
|
2014-02-18 15:49:24 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
iframe.contentWindow.location = src;
|
|
|
|
return iframe;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testIframeWithCallback = function( title, fileName, func ) {
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( title, 1, function( assert ) {
|
2013-04-09 15:45:09 +00:00
|
|
|
var iframe;
|
2015-09-03 01:46:31 +00:00
|
|
|
var done = assert.async();
|
2013-04-09 15:45:09 +00:00
|
|
|
|
|
|
|
window.iframeCallback = function() {
|
2015-09-03 01:46:31 +00:00
|
|
|
var args = Array.prototype.slice.call( arguments );
|
|
|
|
|
|
|
|
args.push( assert );
|
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
setTimeout( function() {
|
2015-09-03 01:46:31 +00:00
|
|
|
this.iframeCallback = undefined;
|
|
|
|
|
|
|
|
func.apply( this, args );
|
2013-04-09 15:45:09 +00:00
|
|
|
func = function() {};
|
2015-10-17 21:40:30 +00:00
|
|
|
iframe.remove();
|
2015-09-03 01:46:31 +00:00
|
|
|
|
|
|
|
done();
|
|
|
|
} );
|
2013-04-09 15:45:09 +00:00
|
|
|
};
|
2015-09-02 23:52:01 +00:00
|
|
|
iframe = jQuery( "<div/>" ).css( { position: "absolute", width: "500px", left: "-600px" } )
|
2013-10-11 19:08:07 +00:00
|
|
|
.append( jQuery( "<iframe/>" ).attr( "src", url( "./data/" + fileName ) ) )
|
|
|
|
.appendTo( "#qunit-fixture" );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2013-04-09 15:45:09 +00:00
|
|
|
};
|
2015-09-03 01:46:31 +00:00
|
|
|
this.iframeCallback = undefined;
|
2013-09-06 20:23:20 +00:00
|
|
|
|
|
|
|
// Tests are always loaded async
|
|
|
|
QUnit.config.autostart = false;
|
|
|
|
this.loadTests = function() {
|
2015-09-08 20:03:10 +00:00
|
|
|
// Leverage QUnit URL parsing to detect testSwarm environment and "basic" testing mode
|
|
|
|
var loadSwarm = ( QUnit.urlParams[ "swarmURL" ] + "" ).indexOf( "http" ) === 0,
|
|
|
|
basicTests = ( QUnit.urlParams[ "module" ] + "" ) === "basic";
|
2013-09-06 20:23:20 +00:00
|
|
|
|
2013-09-06 21:11:04 +00:00
|
|
|
// Get testSubproject from testrunner first
|
2015-09-02 23:52:01 +00:00
|
|
|
require( [ "data/testrunner.js" ], function() {
|
2015-09-08 19:56:08 +00:00
|
|
|
var i = 0,
|
|
|
|
tests = [
|
2015-09-08 16:36:02 +00:00
|
|
|
// A special module with basic tests, meant for
|
|
|
|
// not fully supported environments like Android 2.3,
|
|
|
|
// jsdom or PhantomJS. We run it everywhere, though,
|
|
|
|
// to make sure tests are not broken.
|
2015-09-08 19:56:08 +00:00
|
|
|
"unit/basic.js",
|
|
|
|
|
2015-09-08 16:36:02 +00:00
|
|
|
"unit/core.js",
|
|
|
|
"unit/callbacks.js",
|
|
|
|
"unit/deferred.js",
|
2015-10-01 20:03:10 +00:00
|
|
|
"unit/deprecated.js",
|
2015-09-08 16:36:02 +00:00
|
|
|
"unit/support.js",
|
|
|
|
"unit/data.js",
|
|
|
|
"unit/queue.js",
|
|
|
|
"unit/attributes.js",
|
|
|
|
"unit/event.js",
|
|
|
|
"unit/selector.js",
|
|
|
|
"unit/traversing.js",
|
|
|
|
"unit/manipulation.js",
|
|
|
|
"unit/wrap.js",
|
|
|
|
"unit/css.js",
|
|
|
|
"unit/serialize.js",
|
|
|
|
"unit/ajax.js",
|
|
|
|
"unit/effects.js",
|
|
|
|
"unit/offset.js",
|
|
|
|
"unit/dimensions.js",
|
|
|
|
"unit/animation.js",
|
|
|
|
"unit/tween.js"
|
2015-09-08 19:56:08 +00:00
|
|
|
];
|
2013-09-06 21:11:04 +00:00
|
|
|
|
|
|
|
// Ensure load order (to preserve test numbers)
|
2015-09-02 23:52:01 +00:00
|
|
|
( function loadDep() {
|
2015-09-08 19:56:08 +00:00
|
|
|
var dep = tests[ i++ ];
|
2014-02-18 15:49:24 +00:00
|
|
|
|
2013-09-06 21:11:04 +00:00
|
|
|
if ( dep ) {
|
2015-09-08 19:56:08 +00:00
|
|
|
if ( !basicTests || i === 1 ) {
|
|
|
|
require( [ dep ], loadDep );
|
|
|
|
|
|
|
|
// Support: Android 2.3 only
|
|
|
|
// When running basic tests, replace other modules with dummies to avoid overloading
|
|
|
|
// impaired clients.
|
|
|
|
} else {
|
|
|
|
QUnit.module( dep.replace( /^.*\/|\.js$/g, "" ) );
|
|
|
|
loadDep();
|
|
|
|
}
|
2013-11-14 15:17:18 +00:00
|
|
|
|
2014-02-18 15:49:24 +00:00
|
|
|
} else {
|
|
|
|
QUnit.load();
|
2013-09-06 21:11:04 +00:00
|
|
|
|
2014-02-18 15:49:24 +00:00
|
|
|
/**
|
|
|
|
* Run in noConflict mode
|
|
|
|
*/
|
2014-12-09 20:39:24 +00:00
|
|
|
if ( jQuery.noConflict ) {
|
|
|
|
jQuery.noConflict();
|
|
|
|
}
|
2013-09-06 20:23:20 +00:00
|
|
|
|
2014-02-18 15:49:24 +00:00
|
|
|
// Load the TestSwarm listener if swarmURL is in the address.
|
|
|
|
if ( loadSwarm ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
require( [ "http://swarm.jquery.org/js/inject.js?" + ( new Date() ).getTime() ],
|
2014-07-17 17:25:59 +00:00
|
|
|
function() {
|
2013-09-06 21:11:04 +00:00
|
|
|
QUnit.start();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2014-02-18 15:49:24 +00:00
|
|
|
} else {
|
|
|
|
QUnit.start();
|
|
|
|
}
|
2013-09-06 21:11:04 +00:00
|
|
|
}
|
2015-09-02 23:52:01 +00:00
|
|
|
} )();
|
|
|
|
} );
|
2013-09-06 20:23:20 +00:00
|
|
|
};
|