Coerce s.url to string before calling replace, since replace is also a method of...
[jquery.git] / test / unit / ajax.js
index 6199270..b0c399b 100644 (file)
@@ -104,7 +104,10 @@ test(".ajax() - 304", function() {
        jQuery.ajax({
                url: url("data/notmodified.php"),
                success: function(){ ok(true, "304 ok"); },
-               error: function(){ ok(false, "304 not ok "); },
+               // Do this because opera simply refuses to implement 304 handling :(
+               // A feature-driven way of detecting this would be appreciated
+               // See: http://gist.github.com/599419
+               error: function(){ ok(jQuery.browser.opera, "304 not ok "); },
                complete: function(xhr){ start(); }
        });
 });
@@ -134,7 +137,7 @@ test(".load()) - 404 error callbacks", function() {
 });
 
 test("jQuery.ajax() - abort", function() {
-       expect( 6 );
+       expect( 8 );
        stop();
 
        jQuery('#foo').ajaxStart(function(){
@@ -154,7 +157,10 @@ test("jQuery.ajax() - abort", function() {
                complete: function(){ ok(true, "complete"); }
        });
 
+       equals( xhr.readyState, 1, "XHR readyState indicates successful dispatch" );
+
        xhr.abort();
+       equals( xhr.readyState, 0, "XHR readyState indicates successful abortion" );
 });
 
 test("Ajax events with context", function() {
@@ -286,6 +292,32 @@ test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", fun
        });
 });
 
+test("jQuery.ajax - HEAD requests", function() {
+       expect(2);
+
+       stop();
+       jQuery.ajax({
+               url: url("data/name.html"),
+               type: "HEAD",
+               success: function(data, status, xhr){
+                       var h = xhr.getAllResponseHeaders();
+                       ok( /Date/i.test(h), 'No Date in HEAD response' );
+                       
+                       jQuery.ajax({
+                               url: url("data/name.html"),
+                               data: { whip_it: "good" },
+                               type: "HEAD",
+                               success: function(data, status, xhr){
+                                       var h = xhr.getAllResponseHeaders();
+                                       ok( /Date/i.test(h), 'No Date in HEAD response with data' );
+                                       start();
+                               }
+                       });
+               }
+       });
+       
+});
+
 test("jQuery.ajax - beforeSend", function() {
        expect(1);
        stop();
@@ -362,11 +394,11 @@ test("serialize()", function() {
        );
 
        equals( jQuery('#form').serialize(),
-               "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2",
+               "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
                'Check form serialization as query string');
 
        equals( jQuery('#form :input').serialize(),
-               "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2",
+               "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
                'Check input serialization as query string');
 
        equals( jQuery('#testForm').serialize(),
@@ -378,7 +410,7 @@ test("serialize()", function() {
                'Check input serialization as query string');
 
        equals( jQuery('#form, #testForm').serialize(),
-               "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
+               "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
                'Multiple form serialization as query string');
 
   /* Temporarily disabled. Opera 10 has problems with form serialization.
@@ -1249,13 +1281,20 @@ test("jQuery.ajax - If-Modified-Since support", function() {
                                        start();
                                },
                                error: function() {
-                                       equals(false, "error");
+                                       // Do this because opera simply refuses to implement 304 handling :(
+                                       // A feature-driven way of detecting this would be appreciated
+                                       // See: http://gist.github.com/599419
+                                       ok(jQuery.browser.opera, "error");
+                                       ok(jQuery.browser.opera, "error");
                                        start();
                                }
                        });
                },
                error: function() {
-                       equals(false, "error");
+                       // Do this because opera simply refuses to implement 304 handling :(
+                       // A feature-driven way of detecting this would be appreciated
+                       // See: http://gist.github.com/599419
+                       ok(jQuery.browser.opera, "error");
                        start();
                }
        });
@@ -1288,22 +1327,39 @@ test("jQuery.ajax - Etag support", function() {
                                        start();
                                },
                                error: function() {
-                                       equals(false, "error");
+                                       // Do this because opera simply refuses to implement 304 handling :(
+                                       // A feature-driven way of detecting this would be appreciated
+                                       // See: http://gist.github.com/599419
+                                       ok(jQuery.browser.opera, "error");
+                                       ok(jQuery.browser.opera, "error");
                                        start();
                                }
                        });
                },
                error: function() {
-                       equals(false, "error");
+                       // Do this because opera simply refuses to implement 304 handling :(
+                       // A feature-driven way of detecting this would be appreciated
+                       // See: http://gist.github.com/599419
+                       ok(jQuery.browser.opera, "error");
                        start();
                }
        });
 });
 
 test("jQuery.ajax - active counter", function() {
-    ok( jQuery.ajax.active == 0, "ajax active counter should be zero: " + jQuery.ajax.active );
+    ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
 });
 
+test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
+       var success = false;
+       try {
+               var xhr = jQuery.ajax({ url: document.location });
+               success = true;
+               xhr.abort();
+       } catch (e) {}
+
+       ok( success, "document.location did not generate exception" );
+});
 
 }