X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fajax.js;h=813c65fbc09dc28b7929299b3da2e23f9bd262ff;hb=12ef255ffdb3c2d045ee37beb9419f14d9c30217;hp=1e1e8123a9dfe429ed3e7cbf2562ac15e068a92b;hpb=62d84e44ac3b4a3673c320514bbf5ac8dc7712d6;p=jquery.git diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 1e1e812..813c65f 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -5,6 +5,8 @@ module("ajax"); // tests and they'll pass //if ( !jQuery.browser.safari ) { +if ( !isLocal ) { + test("$.ajax() - success callbacks", function() { expect( 8 ); @@ -38,37 +40,35 @@ test("$.ajax() - success callbacks", function() { }, 13); }); -if ( !isLocal ) { - test("$.ajax() - error callbacks", function() { - expect( 8 ); - stop(); - - $('#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( true, "ajaxError" ); - }).ajaxSuccess(function(){ - ok( false, "ajaxSuccess" ); - }); - - $.ajaxSetup({ timeout: 500 }); - - $.ajax({ - url: url("data/name.php?wait=5"), - beforeSend: function(){ ok(true, "beforeSend"); }, - success: function(){ ok(false, "success"); }, - error: function(){ ok(true, "error"); }, - complete: function(){ ok(true, "complete"); } - }); - }); -} +test("$.ajax() - error callbacks", function() { + expect( 8 ); + stop(); + + $('#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( true, "ajaxError" ); + }).ajaxSuccess(function(){ + ok( false, "ajaxSuccess" ); + }); + + $.ajaxSetup({ timeout: 500 }); + + $.ajax({ + url: url("data/name.php?wait=5"), + beforeSend: function(){ ok(true, "beforeSend"); }, + success: function(){ ok(false, "success"); }, + error: function(){ ok(true, "error"); }, + complete: function(){ ok(true, "complete"); } + }); +}); test("$.ajax() - disabled globals", function() { expect( 3 ); @@ -218,26 +218,64 @@ test("synchronous request with callbacks", function() { }); test("pass-through request object", function() { - expect(1); + expect(8); stop(true); var target = "data/name.html"; - var count = 0; + var successCount = 0; + var errorCount = 0; + var errorEx = ""; var success = function() { - // Disabled - //if(count++ == 5) - start(); + successCount++; }; + $("#foo").ajaxError(function (e, xml, s, ex) { + errorCount++; + errorEx += ": " + xml.status; + }); + $("#foo").one('ajaxStop', function () { + equals(successCount, 5, "Check all ajax calls successful"); + equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")"); + $("#foo").unbind('ajaxError'); + start(); + }); - /* Test disabled, too many simultaneous requests ok( $.get(url(target), success), "get" ); ok( $.post(url(target), success), "post" ); ok( $.getScript(url("data/test.js"), success), "script" ); ok( $.getJSON(url("data/json_obj.js"), success), "json" ); - */ ok( $.ajax({url: url(target), success: success}), "generic" ); }); +test("ajax cache", function () { + expect(18); + stop(); + + var count = 0; + + $("#firstp").bind("ajaxSuccess", function (e, xml, s) { + var re = /_=(.*?)(&|$)/g; + var oldOne = null; + for (var i = 0; i < 6; i++) { + var ret = re.exec(s.url); + if (!ret) { + break; + } + oldOne = ret[1]; + } + equals(i, 1, "Test to make sure only one 'no-cache' parameter is there"); + ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced"); + if(++count == 6) + start(); + }); + + ok( $.ajax({url: "data/text.php", cache:false}), "test with no parameters" ); + ok( $.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" ); + ok( $.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" ); + ok( $.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" ); + ok( $.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" ); + ok( $.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" ); +}); + test("global ajaxSettings", function() { expect(3); @@ -346,8 +384,6 @@ test("$.getScript(String, Function) - no callback", function() { $.getScript(url("data/test.js"), start); }); -if ( !isLocal ) { - test("$.ajax() - JSONP, Local", function() { expect(7); @@ -362,6 +398,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (GET, no callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, no callback)" ); + plus(); } }); @@ -371,6 +411,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (GET, url callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, url callback)" ); + plus(); } }); @@ -381,6 +425,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (GET, data callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data callback)" ); + plus(); } }); @@ -391,6 +439,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (GET, data obj callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data obj callback)" ); + plus(); } }); @@ -401,6 +453,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (POST, no callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data obj callback)" ); + plus(); } }); @@ -412,6 +468,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (POST, data callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (POST, data callback)" ); + plus(); } }); @@ -423,6 +483,10 @@ test("$.ajax() - JSONP, Local", function() { success: function(data){ ok( data.data, "JSON results returned (POST, data obj callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (POST, data obj callback)" ); + plus(); } }); }); @@ -443,6 +507,10 @@ test("$.ajax() - JSONP, Remote", function() { success: function(data){ ok( data.data, "JSON results returned (GET, no callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, no callback)" ); + plus(); } }); @@ -452,6 +520,10 @@ test("$.ajax() - JSONP, Remote", function() { success: function(data){ ok( data.data, "JSON results returned (GET, url callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, url callback)" ); + plus(); } }); @@ -462,6 +534,10 @@ test("$.ajax() - JSONP, Remote", function() { success: function(data){ ok( data.data, "JSON results returned (GET, data callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data callback)" ); + plus(); } }); @@ -472,6 +548,10 @@ test("$.ajax() - JSONP, Remote", function() { success: function(data){ ok( data.data, "JSON results returned (GET, data obj callback)" ); plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data obj callback)" ); + plus(); } }); }); @@ -515,6 +595,19 @@ test("$.getJSON(String, Function) - JSON object", function() { }); }); +test("$.getJSON(String, Function) - Remote JSON object with assignment", function() { + expect(2); + + var base = window.location.href.replace(/\?.*$/, ""); + + stop(); + $.getJSON(base + "data/json_assigned_obj.js", function() { + ok( typeof json_assigned_obj == "object", 'Check JSON loaded' ); + equals( json_assigned_obj.test, "worked", 'Check JSON obj.test' ); + start(); + }); +}); + test("$.post(String, Hash, Function) - simple with xml", function() { expect(4); stop();