+test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
+ expect( 8 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ setTimeout(function(){
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ start();
+ }).ajaxSend(function(){
+ ok( true, "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete" );
+ }).ajaxError(function(){
+ ok( false, "ajaxError" );
+ }).ajaxSuccess(function(){
+ ok( true, "ajaxSuccess" );
+ });
+
+ jQuery.ajax( url("data/name.html") , {
+ beforeSend: function(){ ok(true, "beforeSend"); },
+ success: function(){ ok(true, "success"); },
+ error: function(){ ok(false, "error"); },
+ complete: function(){ ok(true, "complete"); }
+ });
+ }, 13);
+});
+
+test("jQuery.ajax() - success/error callbacks (remote)", function() {
+
+ var supports = jQuery.support.cors;
+
+ expect( supports ? 9 : 6 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ setTimeout(function(){
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ start();
+ }).ajaxSend(function(){
+ ok( supports , "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete" );
+ }).ajaxError(function(){
+ ok( ! supports, "ajaxError" );
+ }).ajaxSuccess(function(){
+ ok( supports, "ajaxSuccess" );
+ });
+
+ jQuery.ajax({
+ // JULIAN TODO: Get an url especially for jQuery
+ url: "http://rockstarapps.com/test.php",
+ dataType: "text",
+ beforeSend: function(){ ok(supports, "beforeSend"); },
+ success: function( val ){ ok(supports, "success"); ok(supports && val.length, "data received"); },
+ error: function(_ , a , b ){ ok(!supports, "error"); },
+ complete: function(){ ok(true, "complete"); }
+ });
+ }, 13);
+});
+
+test("jQuery.ajax() - success callbacks (late binding)", function() {
+ expect( 8 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ setTimeout(function(){
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ start();
+ }).ajaxSend(function(){
+ ok( true, "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete" );
+ }).ajaxError(function(){
+ ok( false, "ajaxError" );
+ }).ajaxSuccess(function(){
+ ok( true, "ajaxSuccess" );
+ });
+
+ jQuery.ajax({
+ url: url("data/name.html"),
+ beforeSend: function(){ ok(true, "beforeSend"); }
+ })
+ .complete(function(){ ok(true, "complete"); })
+ .success(function(){ ok(true, "success"); })
+ .error(function(){ ok(false, "error"); });
+ }, 13);
+});
+
+test("jQuery.ajax() - success callbacks (oncomplete binding)", function() {
+ expect( 8 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ setTimeout(function(){
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ }).ajaxSend(function(){
+ ok( true, "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete" );
+ }).ajaxError(function(){
+ ok( false, "ajaxError" );
+ }).ajaxSuccess(function(){
+ ok( true, "ajaxSuccess" );
+ });
+
+ jQuery.ajax({
+ url: url("data/name.html"),
+ beforeSend: function(){ ok(true, "beforeSend"); },
+ complete: function(xhr) {
+ xhr
+ .complete(function(){ ok(true, "complete"); })
+ .success(function(){ ok(true, "success"); })
+ .error(function(){ ok(false, "error"); })
+ .complete(function(){ start(); });
+ }
+ })
+ }, 13);
+});
+
+test("jQuery.ajax() - success callbacks (very late binding)", function() {
+ expect( 8 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ setTimeout(function(){
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ }).ajaxSend(function(){
+ ok( true, "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete" );
+ }).ajaxError(function(){
+ ok( false, "ajaxError" );
+ }).ajaxSuccess(function(){
+ ok( true, "ajaxSuccess" );
+ });
+
+ jQuery.ajax({
+ url: url("data/name.html"),
+ beforeSend: function(){ ok(true, "beforeSend"); },
+ complete: function(xhr) {
+ setTimeout (function() {
+ xhr
+ .complete(function(){ ok(true, "complete"); })
+ .success(function(){ ok(true, "success"); })
+ .error(function(){ ok(false, "error"); })
+ .complete(function(){ start(); });
+ },100);
+ }
+ })
+ }, 13);
+});
+
+test("jQuery.ajax() - success callbacks (order)", function() {
+ expect( 1 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ var testString = "";
+
+ setTimeout(function(){
+ jQuery.ajax({
+ url: url("data/name.html"),
+ success: function( _1 , _2 , xhr ) {
+ xhr.success(function() {
+ xhr.success(function() {
+ testString += "E";
+ });
+ testString += "D";
+ });
+ testString += "A";
+ },
+ complete: function() {
+ strictEqual(testString, "ABCDE", "Proper order");
+ start();
+ }
+ }).success(function() {
+ testString += "B";
+ }).success(function() {
+ testString += "C";
+ });
+ }, 13);
+});
+