A few corrections to the testsuite to imrove the failure testing
This commit is contained in:
parent
a0d5e89a1e
commit
98b1b580c7
3 changed files with 25 additions and 16 deletions
|
@ -33,12 +33,13 @@ function process() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop() {
|
function stop(allowFailure) {
|
||||||
_config.blocking = true;
|
_config.blocking = true;
|
||||||
_config.timeout = setTimeout(function() {
|
var handler = allowFailure ? start : function() {
|
||||||
ok( false, "Test timed out" );
|
ok( false, "Test timed out" );
|
||||||
start();
|
start();
|
||||||
}, _config.asyncTimeout * 1000);
|
};
|
||||||
|
_config.timeout = setTimeout(handler, _config.asyncTimeout * 1000);
|
||||||
}
|
}
|
||||||
function start() {
|
function start() {
|
||||||
if(_config.timeout)
|
if(_config.timeout)
|
||||||
|
|
|
@ -647,6 +647,8 @@ jQuery.extend({
|
||||||
// Fire the global callback
|
// Fire the global callback
|
||||||
if( s.global )
|
if( s.global )
|
||||||
jQuery.event.trigger( "ajaxSuccess", [xml, s] );
|
jQuery.event.trigger( "ajaxSuccess", [xml, s] );
|
||||||
|
} else {
|
||||||
|
jQuery.handleError(s, xml, status);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
status = "error";
|
status = "error";
|
||||||
|
@ -714,18 +716,24 @@ jQuery.extend({
|
||||||
|
|
||||||
// Determines if an XMLHttpRequest was successful or not
|
// Determines if an XMLHttpRequest was successful or not
|
||||||
httpSuccess: function(r) {
|
httpSuccess: function(r) {
|
||||||
return !r.status && location.protocol == "file:" ||
|
try {
|
||||||
( r.status >= 200 && r.status < 300 ) || r.status == 304 ||
|
return !r.status && location.protocol == "file:" ||
|
||||||
jQuery.browser.safari && r.status == undefined;
|
( 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
|
// Determines if an XMLHttpRequest returns NotModified
|
||||||
httpNotModified: function(xml, url) {
|
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
|
// Firefox always returns 200. check Last-Modified date
|
||||||
return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
|
return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
|
||||||
jQuery.browser.safari && xml.status == undefined;
|
jQuery.browser.safari && xml.status == undefined;
|
||||||
|
} catch(e){}
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
/* Get the data out of an XMLHttpRequest.
|
/* Get the data out of an XMLHttpRequest.
|
||||||
|
|
|
@ -24,7 +24,7 @@ test("param", function() {
|
||||||
|
|
||||||
test("pass-through request object", function() {
|
test("pass-through request object", function() {
|
||||||
expect(7);
|
expect(7);
|
||||||
stop();
|
stop(true);
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var success = function() {
|
var success = function() {
|
||||||
if(count++ == 6)
|
if(count++ == 6)
|
||||||
|
@ -60,7 +60,7 @@ test("load(String, Object, Function) - simple: inject text into DOM", function()
|
||||||
|
|
||||||
test("load(String, Object, Function) - inject without callback", function() {
|
test("load(String, Object, Function) - inject without callback", function() {
|
||||||
expect(1);
|
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");
|
$('#first').load("data/name.php");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ test("$.getScript(String, Function) - with callback", function() {
|
||||||
|
|
||||||
test("$.getScript(String, Function) - no callback", function() {
|
test("$.getScript(String, Function) - no callback", function() {
|
||||||
expect(1);
|
expect(1);
|
||||||
stop();
|
stop(true);
|
||||||
$.getScript("data/test.js");
|
$.getScript("data/test.js");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -319,15 +319,15 @@ test("$.ajax - xml: non-namespace elements inside namespaced elements", function
|
||||||
test("$.ajax - beforeSend", function() {
|
test("$.ajax - beforeSend", function() {
|
||||||
expect(1);
|
expect(1);
|
||||||
stop();
|
stop();
|
||||||
var customHeader = "value";
|
var check = false;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "data/name.php",
|
url: "data/name.php",
|
||||||
data: {'req': true},
|
data: {'req': true},
|
||||||
beforeSend: function(xml) {
|
beforeSend: function(xml) {
|
||||||
xml.setRequestHeader('X-Custom-Header', customHeader);
|
check = true
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
ok( data == customHeader, "check return value, should be the custom header sent" );
|
ok( check, "check beforeSend was executed" );
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue