Update unit tests with a leak detection mechanism for the various jQuery globals...
[jquery.git] / test / unit / ajax.js
index adf589e..d29eddb 100644 (file)
@@ -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
@@ -257,6 +257,29 @@ test("jQuery.ajax() - responseText on error", function() {
        });
 });
 
+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 );
@@ -358,6 +381,53 @@ 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:";
+
+       jQuery.ajax({
+               dataType: "jsonp",
+               url: otherProtocol + "//" + loc.host,
+               beforeSend: function( _ , s ) {
+                       ok( s.crossDomain , "Test different protocols are detected as cross-domain" );
+                       return false;
+               }
+       });
+
+       jQuery.ajax({
+               dataType: "jsonp",
+               url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ),
+               beforeSend: function( _ , s ) {
+                       ok( s.crossDomain , "Test different hostnames are detected as cross-domain" );
+                       return false;
+               }
+       });
+
+       jQuery.ajax({
+               dataType: "jsonp",
+               url: loc.protocol + "//" + loc.hostname + ":" + otherPort,
+               beforeSend: function( _ , s ) {
+                       ok( s.crossDomain , "Test different ports are detected as cross-domain" );
+                       return false;
+               }
+       });
+
+       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;
+               }
+       });
+
+});
+
 test(".ajax() - 304", function() {
        expect( 1 );
        stop();
@@ -1011,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(); }
@@ -1061,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)" );