X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fajax.js;h=8bfd4d3e05fbd661e5df0dc2f2a297cbe1909926;hb=5a5f67800b048ae274e644547f4b8e03156ffa49;hp=d5f2bc0cf09a9f5e3c5b656ba620b8446afefc58;hpb=69497c3fd7ff560be0e47b4c65076915cca756bc;p=jquery.git diff --git a/test/unit/ajax.js b/test/unit/ajax.js index d5f2bc0..8bfd4d3 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -240,6 +240,46 @@ test("jQuery.ajax() - error callbacks", function() { }); }); +test("jQuery.ajax() - responseText on error", function() { + + expect( 1 ); + + stop(); + + jQuery.ajax({ + url: url("data/errorWithText.php"), + error: function(xhr) { + strictEqual( xhr.responseText , "plain text message" , "Test jXHR.responseText is filled for HTTP errors" ); + }, + complete: function() { + start(); + } + }); +}); + +test(".ajax() - retry with jQuery.ajax( this )", function() { + + expect( 1 ); + + stop(); + + var firstTime = 1; + + jQuery.ajax({ + url: url("data/errorWithText.php"), + error: function() { + if ( firstTime ) { + firstTime = 0; + jQuery.ajax( this ); + } else { + ok( true , "Test retrying with jQuery.ajax(this) works" ); + start(); + } + } + }) + +}); + test(".ajax() - headers" , function() { expect( 2 ); @@ -341,6 +381,73 @@ test(".ajax() - hash", function() { }); }); +test("jQuery ajax - cross-domain detection", function() { + + expect( 4 ); + + var loc = document.location, + otherPort = loc.port === 666 ? 667 : 666, + otherProtocol = loc.protocol === "http:" ? "https:" : "http:", + protocolFlag, + hostFlag, + portFlag, + forcedFlag; + + if ( jQuery.ajax({ + url: otherProtocol + "//" + loc.host, + beforeSend: function( _ , s ) { + protocolFlag = 1; + ok( s.crossDomain , "Test different protocols are detected as cross-domain" ); + return false; + } + }) === false ) { + if ( ! protocolFlag ) { + ok( ! jQuery.support.cors , "Test different protocols are detected as cross-domain (no transport)" ); + } + } + + if ( jQuery.ajax({ + url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ), + beforeSend: function( _ , s ) { + hostFlag = 1; + ok( s.crossDomain , "Test different hostnames are detected as cross-domain" ); + return false; + } + }) === false ) { + if ( ! hostFlag ) { + ok( ! jQuery.support.cors , "Test different hostnames are detected as cross-domain (no transport)" ); + } + } + + if ( jQuery.ajax({ + url: loc.protocol + "//" + loc.hostname + ":" + otherPort, + beforeSend: function( _ , s ) { + portFlag = 1; + ok( s.crossDomain , "Test different ports are detected as cross-domain" ); + return false; + } + }) === false ) { + if ( ! portFlag ) { + ok( ! jQuery.support.cors , "Test different ports are detected as cross-domain (no transport)" ); + } + } + + if ( jQuery.ajax({ + url: loc.protocol + "//" + loc.host, + crossDomain: true, + beforeSend: function( _ , s ) { + forcedFlag = 1; + ok( s.crossDomain , "Test forced crossDomain is detected as cross-domain" ); + return false; + } + }) === false ) { + if ( ! forcedFlag ) { + ok( ! jQuery.support.cors , "Test forced crossDomain is detected as cross-domain (no transport)" ); + } + } + +}); + test(".ajax() - 304", function() { expect( 1 ); stop();