X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fajax.js;h=d29eddbfa33a33c8675ddb38e228893f3cbccf3e;hb=e2941d5a98e91c5f61b200b2763e5fa0eb339365;hp=4c8c5009be66ffb4fbd74e861bc13e1ec3a894bf;hpb=63487505c678152e59847e3ab7878ea5f2514dfa;p=jquery.git diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 4c8c500..d29eddb 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1,4 +1,4 @@ -module("ajax"); +module("ajax", { teardown: moduleTeardown }); // Safari 3 randomly crashes when running these tests, // but only in the full suite - you can run just the Ajax @@ -383,53 +383,48 @@ test(".ajax() - hash", function() { test("jQuery ajax - cross-domain detection", function() { - expect( 3 ); + expect( 4 ); var loc = document.location, otherPort = loc.port === 666 ? 667 : 666, - otherProtocol = loc.protocol === "http:" ? "https:" : "http:", - protocolFlag, - hostFlag, - portFlag; + otherProtocol = loc.protocol === "http:" ? "https:" : "http:"; - if ( jQuery.ajax({ + jQuery.ajax({ + dataType: "jsonp", 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({ + jQuery.ajax({ + dataType: "jsonp", 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({ + jQuery.ajax({ + dataType: "jsonp", 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)" ); + }); + + jQuery.ajax({ + dataType: "jsonp", + url: loc.protocol + "//" + loc.host, + crossDomain: true, + beforeSend: function( _ , s ) { + ok( s.crossDomain , "Test forced crossDomain is detected as cross-domain" ); + return false; } - } + }); }); @@ -1086,7 +1081,7 @@ test("jQuery.getScript(String, Function) - no callback", function() { }); test("jQuery.ajax() - JSONP, Local", function() { - expect(9); + expect(10); var count = 0; function plus(){ if ( ++count == 9 ) start(); } @@ -1136,6 +1131,22 @@ test("jQuery.ajax() - JSONP, Local", function() { jQuery.ajax({ url: "data/jsonp.php", dataType: "jsonp", + data: { + callback: "?" + }, + success: function(data){ + ok( data.data, "JSON results returned (GET, processed data callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, processed data callback)" ); + plus(); + } + }); + + jQuery.ajax({ + url: "data/jsonp.php", + dataType: "jsonp", jsonp: "callback", success: function(data){ ok( data.data, "JSON results returned (GET, data obj callback)" );