}
}
-function stop() {
+function stop(allowFailure) {
_config.blocking = true;
- _config.timeout = setTimeout(function() {
+ var handler = allowFailure ? start : function() {
ok( false, "Test timed out" );
start();
- }, _config.asyncTimeout * 1000);
+ };
+ _config.timeout = setTimeout(handler, _config.asyncTimeout * 1000);
}
function start() {
if(_config.timeout)
// Fire the global callback
if( s.global )
jQuery.event.trigger( "ajaxSuccess", [xml, s] );
+ } else {
+ jQuery.handleError(s, xml, status);
}
} catch(e) {
status = "error";
// Determines if an XMLHttpRequest was successful or not
httpSuccess: function(r) {
- return !r.status && location.protocol == "file:" ||
- ( r.status >= 200 && r.status < 300 ) || r.status == 304 ||
- jQuery.browser.safari && r.status == undefined;
+ try {
+ return !r.status && location.protocol == "file:" ||
+ ( r.status >= 200 && r.status < 300 ) || r.status == 304 ||
+ jQuery.browser.safari && r.status == undefined;
+ } catch(e){}
+ return false;
},
// Determines if an XMLHttpRequest returns NotModified
httpNotModified: function(xml, url) {
- var xmlRes = xml.getResponseHeader("Last-Modified");
+ try {
+ var xmlRes = xml.getResponseHeader("Last-Modified");
- // Firefox always returns 200. check Last-Modified date
- return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
- jQuery.browser.safari && xml.status == undefined;
+ // Firefox always returns 200. check Last-Modified date
+ return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
+ jQuery.browser.safari && xml.status == undefined;
+ } catch(e){}
+ return false;
},
/* Get the data out of an XMLHttpRequest.
test("pass-through request object", function() {
expect(7);
- stop();
+ stop(true);
var count = 0;
var success = function() {
if(count++ == 6)
test("load(String, Object, Function) - inject without callback", function() {
expect(1);
- stop(); // check if load can be called with only url
+ stop(true); // check if load can be called with only url
$('#first').load("data/name.php");
});
test("$.getScript(String, Function) - no callback", function() {
expect(1);
- stop();
+ stop(true);
$.getScript("data/test.js");
});
test("$.ajax - beforeSend", function() {
expect(1);
stop();
- var customHeader = "value";
+ var check = false;
$.ajax({
url: "data/name.php",
data: {'req': true},
beforeSend: function(xml) {
- xml.setRequestHeader('X-Custom-Header', customHeader);
+ check = true
},
success: function(data) {
- ok( data == customHeader, "check return value, should be the custom header sent" );
+ ok( check, "check beforeSend was executed" );
start();
}
});