diff options
Diffstat (limited to 'test/unit/ajax.js')
-rw-r--r-- | test/unit/ajax.js | 959 |
1 files changed, 482 insertions, 477 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js index a08a3755f..0dceb0251 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -17,15 +17,15 @@ module( "ajax", { jQuery( document ).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" ); moduleTeardown.apply( this, arguments ); } -}); +} ); -(function() { - test("Unit Testing Environment", function () { +( function() { + test( "Unit Testing Environment", function() { expect( 2 ); ok( hasPHP, "Running in an environment with PHP support. The AJAX tests only run if the environment supports PHP!" ); ok( !isLocal, "Unit tests are not ran from file:// (especially in Chrome. If you must test from file:// with Chrome, run it with the --allow-file-access-from-files flag!)" ); - }); + } ); if ( !jQuery.ajax || ( isLocal && !hasPHP ) ) { return; @@ -35,16 +35,16 @@ module( "ajax", { return function() { expected = expected || ""; jQuery( document ).on( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess", function( e ) { - ok( expected.indexOf(e.type) !== -1, e.type ); - }); + ok( expected.indexOf( e.type ) !== -1, e.type ); + } ); }; } //----------- jQuery.ajax() ajaxTest( "jQuery.ajax() - success callbacks", 8, { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"), - url: url("data/name.html"), + setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess" ), + url: url( "data/name.html" ), beforeSend: function() { ok( true, "beforeSend" ); }, @@ -52,14 +52,14 @@ module( "ajax", { ok( true, "success" ); }, complete: function() { - ok( true, "complete"); + ok( true, "complete" ); } - }); + } ); ajaxTest( "jQuery.ajax() - success callbacks - (url, options) syntax", 8, { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"), + setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess" ), create: function( options ) { - return jQuery.ajax( url("data/name.html"), options ); + return jQuery.ajax( url( "data/name.html" ), options ); }, beforeSend: function() { ok( true, "beforeSend" ); @@ -70,47 +70,47 @@ module( "ajax", { complete: function() { ok( true, "complete" ); } - }); + } ); ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"), - url: url("data/name.html"), + setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess" ), + url: url( "data/name.html" ), beforeSend: function() { ok( true, "beforeSend" ); }, success: true, afterSend: function( request ) { - request.always(function() { + request.always( function() { ok( true, "complete" ); - }).done(function() { + } ).done( function() { ok( true, "success" ); - }).fail(function() { + } ).fail( function() { ok( false, "error" ); - }); + } ); } - }); + } ); ajaxTest( "jQuery.ajax() - success callbacks (oncomplete binding)", 8, { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"), - url: url("data/name.html"), + setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess" ), + url: url( "data/name.html" ), beforeSend: function() { ok( true, "beforeSend" ); }, success: true, complete: function( xhr ) { - xhr.always(function() { + xhr.always( function() { ok( true, "complete" ); - }).done(function() { + } ).done( function() { ok( true, "success" ); - }).fail(function() { + } ).fail( function() { ok( false, "error" ); - }); + } ); } - }); + } ); ajaxTest( "jQuery.ajax() - error callbacks", 8, { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError"), - url: url("data/name.php?wait=5"), + setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError" ), + url: url( "data/name.php?wait=5" ), beforeSend: function() { ok( true, "beforeSend" ); }, @@ -123,11 +123,11 @@ module( "ajax", { complete: function() { ok( true, "complete" ); } - }); + } ); ajaxTest( "jQuery.ajax() - textStatus and errorThrown values", 4, [ { - url: url("data/name.php?wait=5"), + url: url( "data/name.php?wait=5" ), error: function( _, textStatus, errorThrown ) { strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" ); strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort" ); @@ -137,37 +137,37 @@ module( "ajax", { } }, { - url: url("data/name.php?wait=5"), + url: url( "data/name.php?wait=5" ), error: function( _, textStatus, errorThrown ) { strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" ); strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')" ); }, afterSend: function( request ) { - request.abort("mystatus"); + request.abort( "mystatus" ); } } - ]); + ] ); ajaxTest( "jQuery.ajax() - responseText on error", 1, { - url: url("data/errorWithText.php"), + url: url( "data/errorWithText.php" ), error: function( xhr ) { strictEqual( xhr.responseText, "plain text message", "Test jqXHR.responseText is filled for HTTP errors" ); } - }); + } ); asyncTest( "jQuery.ajax() - retry with jQuery.ajax( this )", 2, function() { var previousUrl, firstTime = true; - jQuery.ajax({ - url: url("data/errorWithText.php"), + jQuery.ajax( { + url: url( "data/errorWithText.php" ), error: function() { if ( firstTime ) { firstTime = false; jQuery.ajax( this ); } else { ok ( true, "Test retrying with jQuery.ajax(this) works" ); - jQuery.ajax({ - url: url("data/errorWithText.php"), + jQuery.ajax( { + url: url( "data/errorWithText.php" ), data: { "x": 1 }, @@ -183,19 +183,19 @@ module( "ajax", { error: function() { jQuery.ajax( this ); } - }); + } ); } } - }); - }); + } ); + } ); ajaxTest( "jQuery.ajax() - headers", 5, { setup: function() { - jQuery( document ).ajaxSend(function( evt, xhr ) { + jQuery( document ).ajaxSend( function( evt, xhr ) { xhr.setRequestHeader( "ajax-send", "test" ); - }); + } ); }, - url: url("data/headers.php?keys=siMPle_SometHing-elsE_OthEr_Nullable_undefined_Empty_ajax-send"), + url: url( "data/headers.php?keys=siMPle_SometHing-elsE_OthEr_Nullable_undefined_Empty_ajax-send" ), headers: { "siMPle": "value", "SometHing-elsE": "other value", @@ -212,58 +212,59 @@ module( "ajax", { var i, emptyHeader, requestHeaders = jQuery.extend( this.headers, { "ajax-send": "test" - }), + } ), tmp = []; for ( i in requestHeaders ) { tmp.push( i, ": ", requestHeaders[ i ] + "", "\n" ); } - tmp = tmp.join(""); + tmp = tmp.join( "" ); strictEqual( data, tmp, "Headers were sent" ); - strictEqual( xhr.getResponseHeader("Sample-Header"), "Hello World", "Sample header received" ); - ok( data.indexOf( "undefined" ) < 0 , "Undefined header value was not sent" ); + strictEqual( xhr.getResponseHeader( "Sample-Header" ), "Hello World", "Sample header received" ); + ok( data.indexOf( "undefined" ) < 0, "Undefined header value was not sent" ); - emptyHeader = xhr.getResponseHeader("Empty-Header"); + emptyHeader = xhr.getResponseHeader( "Empty-Header" ); if ( emptyHeader === null ) { ok( true, "Firefox doesn't support empty headers" ); } else { strictEqual( emptyHeader, "", "Empty header received" ); } - strictEqual( xhr.getResponseHeader("Sample-Header2"), "Hello World 2", "Second sample header received" ); + strictEqual( xhr.getResponseHeader( "Sample-Header2" ), "Hello World 2", "Second sample header received" ); } - }); + } ); ajaxTest( "jQuery.ajax() - Accept header", 1, { - url: url("data/headers.php?keys=accept"), + url: url( "data/headers.php?keys=accept" ), headers: { Accept: "very wrong accept value" }, beforeSend: function( xhr ) { - xhr.setRequestHeader("Accept", "*/*"); + xhr.setRequestHeader( "Accept", "*/*" ); }, success: function( data ) { strictEqual( data, "accept: */*\n", "Test Accept header is set to last value provided" ); } - }); + } ); ajaxTest( "jQuery.ajax() - contentType", 2, [ { - url: url("data/headers.php?keys=content-type"), + url: url( "data/headers.php?keys=content-type" ), contentType: "test", success: function( data ) { strictEqual( data, "content-type: test\n", "Test content-type is sent when options.contentType is set" ); } }, { - url: url("data/headers.php?keys=content-type"), + url: url( "data/headers.php?keys=content-type" ), contentType: false, success: function( data ) { + // Some server/interpreter combinations always supply a Content-Type to scripts data = data || "content-type: \n"; strictEqual( data, "content-type: \n", "Test content-type is not set when options.contentType===false" ); } } - ]); + ] ); ajaxTest( "jQuery.ajax() - protocol-less urls", 1, { url: "//somedomain.com", @@ -272,7 +273,7 @@ module( "ajax", { return false; }, error: true - }); + } ); ajaxTest( "jQuery.ajax() - hash", 3, [ { @@ -302,7 +303,7 @@ module( "ajax", { }, error: true } - ]); + ] ); ajaxTest( "jQuery.ajax() - cross-domain detection", 8, function() { function request( url, title, crossDomainOrOptions ) { @@ -360,11 +361,11 @@ module( "ajax", { "Cross-domain url with leading space is detected as cross-domain" ) ]; - }); + } ); ajaxTest( "jQuery.ajax() - abort", 9, { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete"), - url: url("data/name.php?wait=5"), + setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete" ), + url: url( "data/name.php?wait=5" ), beforeSend: function() { ok( true, "beforeSend" ); }, @@ -377,11 +378,11 @@ module( "ajax", { complete: function() { ok( true, "complete" ); } - }); + } ); ajaxTest( "jQuery.ajax() - events with context", 12, function() { - var context = document.createElement("div"); + var context = document.createElement( "div" ); function event( e ) { equal( this, context, e.type ); @@ -395,27 +396,27 @@ module( "ajax", { return { setup: function() { - jQuery( context ).appendTo("#foo") + jQuery( context ).appendTo( "#foo" ) .ajaxSend( event ) .ajaxComplete( event ) .ajaxError( event ) .ajaxSuccess( event ); }, - requests: [{ - url: url("data/name.html"), + requests: [ { + url: url( "data/name.html" ), context: context, - beforeSend: callback("beforeSend"), - success: callback("success"), - complete: callback("complete") + beforeSend: callback( "beforeSend" ), + success: callback( "success" ), + complete: callback( "complete" ) }, { - url: url("data/404.html"), + url: url( "data/404.html" ), context: context, - beforeSend: callback("beforeSend"), - error: callback("error"), - complete: callback("complete") - }] + beforeSend: callback( "beforeSend" ), + error: callback( "error" ), + complete: callback( "complete" ) + } ] }; - }); + } ); ajaxTest( "jQuery.ajax() - events without context", 3, function() { function nocallback( msg ) { @@ -424,12 +425,12 @@ module( "ajax", { }; } return { - url: url("data/404.html"), - beforeSend: nocallback("beforeSend"), - error: nocallback("error"), - complete: nocallback("complete") + url: url( "data/404.html" ), + beforeSend: nocallback( "beforeSend" ), + error: nocallback( "error" ), + complete: nocallback( "complete" ) }; - }); + } ); ajaxTest( "#15118 - jQuery.ajax() - function without jQuery.event", 1, function() { var holder; @@ -445,27 +446,27 @@ module( "ajax", { }, success: true }; - }); + } ); ajaxTest( "#15160 - jQuery.ajax() - request manually aborted in ajaxSend", 3, { setup: function() { jQuery( document ).on( "ajaxSend", function( e, jqXHR ) { jqXHR.abort(); - }); + } ); jQuery( document ).on( "ajaxError ajaxComplete", function( e, jqXHR ) { equal( jqXHR.statusText, "abort", "jqXHR.statusText equals abort on global ajaxComplete and ajaxError events" ); - }); + } ); }, - url: url("data/name.html"), + url: url( "data/name.html" ), error: true, complete: function() { ok( true, "complete" ); } - }); + } ); ajaxTest( "jQuery.ajax() - context modification", 1, { - url: url("data/name.html"), + url: url( "data/name.html" ), context: {}, beforeSend: function() { this.test = "foo"; @@ -474,36 +475,36 @@ module( "ajax", { strictEqual( this.context.test, "foo", "Make sure the original object is maintained." ); }, success: true - }); + } ); ajaxTest( "jQuery.ajax() - context modification through ajaxSetup", 3, function() { var obj = {}; return { setup: function() { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { context: obj - }); + } ); strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." ); }, - requests: [{ - url: url("data/name.html"), + requests: [ { + url: url( "data/name.html" ), success: function() { strictEqual( this, obj, "Make sure the original object is maintained." ); } }, { - url: url("data/name.html"), + url: url( "data/name.html" ), context: {}, success: function() { ok( this !== obj, "Make sure overriding context is possible." ); } - }] + } ] }; - }); + } ); ajaxTest( "jQuery.ajax() - disabled globals", 3, { - setup: addGlobalEvents(""), + setup: addGlobalEvents( "" ), global: false, - url: url("data/name.html"), + url: url( "data/name.html" ), beforeSend: function() { ok( true, "beforeSend" ); }, @@ -513,38 +514,38 @@ module( "ajax", { complete: function() { ok( true, "complete" ); } - }); + } ); ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements", 3, { - url: url("data/with_fries.xml"), + url: url( "data/with_fries.xml" ), dataType: "xml", success: function( resp ) { equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" ); equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" ); equal( jQuery( "thing", resp ).length, 2, "things in responseXML" ); } - }); + } ); ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements (over JSONP)", 3, { - url: url("data/with_fries_over_jsonp.php"), + url: url( "data/with_fries_over_jsonp.php" ), dataType: "jsonp xml", success: function( resp ) { equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" ); equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" ); equal( jQuery( "thing", resp ).length, 2, "things in responseXML" ); } - }); + } ); ajaxTest( "jQuery.ajax() - HEAD requests", 2, [ { - url: url("data/name.html"), + url: url( "data/name.html" ), type: "HEAD", success: function( data, status, xhr ) { ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response" ); } }, { - url: url("data/name.html"), + url: url( "data/name.html" ), data: { "whip_it": "good" }, @@ -553,22 +554,22 @@ module( "ajax", { ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response with data" ); } } - ]); + ] ); ajaxTest( "jQuery.ajax() - beforeSend", 1, { - url: url("data/name.html"), + url: url( "data/name.html" ), beforeSend: function() { this.check = true; }, success: function() { ok( this.check, "check beforeSend was executed" ); } - }); + } ); ajaxTest( "jQuery.ajax() - beforeSend, cancel request manually", 2, { create: function() { - return jQuery.ajax({ - url: url("data/name.html"), + return jQuery.ajax( { + url: url( "data/name.html" ), beforeSend: function( xhr ) { ok( true, "beforeSend got called, canceling" ); xhr.abort(); @@ -582,52 +583,52 @@ module( "ajax", { error: function() { ok( false, "request didn't get canceled" ); } - }); + } ); }, fail: function( _, reason ) { strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" ); } - }); + } ); ajaxTest( "jQuery.ajax() - dataType html", 5, { setup: function() { - Globals.register("testFoo"); - Globals.register("testBar"); + Globals.register( "testFoo" ); + Globals.register( "testBar" ); }, dataType: "html", - url: url("data/test.html"), + url: url( "data/test.html" ), success: function( data ) { ok( data.match( /^html text/ ), "Check content for datatype html" ); - jQuery("#ap").html( data ); - strictEqual( window["testFoo"], "foo", "Check if script was evaluated for datatype html" ); - strictEqual( window["testBar"], "bar", "Check if script src was evaluated for datatype html" ); + jQuery( "#ap" ).html( data ); + strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated for datatype html" ); + strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated for datatype html" ); } - }); + } ); ajaxTest( "jQuery.ajax() - synchronous request", 1, { - url: url("data/json_obj.js"), + url: url( "data/json_obj.js" ), dataType: "text", async: false, success: true, afterSend: function( xhr ) { ok( /^\{ "data"/.test( xhr.responseText ), "check returned text" ); } - }); + } ); ajaxTest( "jQuery.ajax() - synchronous request with callbacks", 2, { - url: url("data/json_obj.js"), + url: url( "data/json_obj.js" ), async: false, dataType: "text", success: true, afterSend: function( xhr ) { var result; - xhr.done(function( data ) { + xhr.done( function( data ) { ok( true, "success callback executed" ); result = data; - }); + } ); ok( /^\{ "data"/.test( result ), "check returned text" ); } - }); + } ); asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function() { var target = "data/name.html", @@ -640,24 +641,24 @@ module( "ajax", { jQuery( document ).on( "ajaxError.passthru", function( e, xml ) { errorCount++; errorEx += ": " + xml.status; - }); + } ); jQuery( document ).one( "ajaxStop", function() { equal( successCount, 5, "Check all ajax calls successful" ); equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" ); - jQuery( document ).off("ajaxError.passthru"); + jQuery( document ).off( "ajaxError.passthru" ); start(); - }); - Globals.register("testBar"); - - ok( jQuery.get( url(target), success ), "get" ); - ok( jQuery.post( url(target), success ), "post" ); - ok( jQuery.getScript( url("data/testbar.php"), success ), "script" ); - ok( jQuery.getJSON( url("data/json_obj.js"), success ), "json" ); - ok( jQuery.ajax({ + } ); + Globals.register( "testBar" ); + + ok( jQuery.get( url( target ), success ), "get" ); + ok( jQuery.post( url( target ), success ), "post" ); + ok( jQuery.getScript( url( "data/testbar.php" ), success ), "script" ); + ok( jQuery.getJSON( url( "data/json_obj.js" ), success ), "json" ); + ok( jQuery.ajax( { url: url( target ), success: success - }), "generic" ); - }); + } ), "generic" ); + } ); ajaxTest( "jQuery.ajax() - cache", 12, function() { @@ -669,7 +670,7 @@ module( "ajax", { cache: false, beforeSend: function() { var parameter, tmp; - while(( tmp = re.exec( this.url ) )) { + while ( ( tmp = re.exec( this.url ) ) ) { strictEqual( parameter, undefined, title + ": only one 'no-cache' parameter" ); parameter = tmp[ 1 ]; notStrictEqual( parameter, "tobereplaced555", title + ": parameter (if it was there) was replaced" ); @@ -706,7 +707,7 @@ module( "ajax", { "2 parameters surrounding _=" ) ]; - }); + } ); jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) { @@ -743,24 +744,24 @@ module( "ajax", { strictEqual( jQuery.type( data ), "array", "JSON results returned (GET, REST-like with param)" ); } } - ]); + ] ); ajaxTest( "jQuery.ajax() - JSONP - Explicit callback param" + label, 10, { setup: function() { - Globals.register("functionToCleanUp"); - Globals.register("XXX"); - Globals.register("jsonpResults"); - window["jsonpResults"] = function( data ) { - ok( data["data"], "JSON results returned (GET, custom callback function)" ); + Globals.register( "functionToCleanUp" ); + Globals.register( "XXX" ); + Globals.register( "jsonpResults" ); + window[ "jsonpResults" ] = function( data ) { + ok( data[ "data" ], "JSON results returned (GET, custom callback function)" ); }; }, - requests: [{ + requests: [ { url: "data/jsonp.php", dataType: "jsonp", crossDomain: crossDomain, jsonp: "callback", success: function( data ) { - ok( data["data"], "JSON results returned (GET, data obj callback)" ); + ok( data[ "data" ], "JSON results returned (GET, data obj callback)" ); } }, { url: "data/jsonp.php", @@ -781,10 +782,10 @@ module( "ajax", { crossDomain: crossDomain, jsonpCallback: "functionToCleanUp", success: function( data ) { - ok( data["data"], "JSON results returned (GET, custom callback name to be cleaned up)" ); - strictEqual( window["functionToCleanUp"], true, "Callback was removed (GET, custom callback name to be cleaned up)" ); + ok( data[ "data" ], "JSON results returned (GET, custom callback name to be cleaned up)" ); + strictEqual( window[ "functionToCleanUp" ], true, "Callback was removed (GET, custom callback name to be cleaned up)" ); var xhr; - jQuery.ajax({ + jQuery.ajax( { url: "data/jsonp.php", dataType: "jsonp", crossDomain: crossDomain, @@ -793,11 +794,11 @@ module( "ajax", { xhr = jqXHR; return false; } - }); - xhr.fail(function() { + } ); + xhr.fail( function() { ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" ); - strictEqual( window["functionToCleanUp"], true, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" ); - }); + strictEqual( window[ "functionToCleanUp" ], true, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" ); + } ); } }, { url: "data/jsonp.php?callback=XXX", @@ -809,10 +810,10 @@ module( "ajax", { ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" ); }, success: function( data ) { - ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" ); + ok( data[ "data" ], "JSON results returned (GET, custom callback name with no url manipulation)" ); } - }] - }); + } ] + } ); ajaxTest( "jQuery.ajax() - JSONP - Callback in data" + label, 2, [ { @@ -833,8 +834,7 @@ module( "ajax", { ok( data.data, "JSON results returned (GET, data context-free callback)" ); } } - ]); - + ] ); ajaxTest( "jQuery.ajax() - JSONP - POST" + label, 3, [ { @@ -843,7 +843,7 @@ module( "ajax", { dataType: "jsonp", crossDomain: crossDomain, success: function( data ) { - ok( data["data"], "JSON results returned (POST, no callback)" ); + ok( data[ "data" ], "JSON results returned (POST, no callback)" ); } }, { @@ -853,7 +853,7 @@ module( "ajax", { dataType: "jsonp", crossDomain: crossDomain, success: function( data ) { - ok( data["data"], "JSON results returned (POST, data callback)" ); + ok( data[ "data" ], "JSON results returned (POST, data callback)" ); } }, { @@ -863,10 +863,10 @@ module( "ajax", { dataType: "jsonp", crossDomain: crossDomain, success: function( data ) { - ok( data["data"], "JSON results returned (POST, data obj callback)" ); + ok( data[ "data" ], "JSON results returned (POST, data obj callback)" ); } } - ]); + ] ); ajaxTest( "jQuery.ajax() - JSONP" + label, 3, [ { @@ -880,14 +880,14 @@ module( "ajax", { { create: function( options ) { var request = jQuery.ajax( options ), - promise = request.then(function( data ) { + promise = request.then( function( data ) { ok( data.data, "first request: JSON results returned (GET, no callback)" ); - request = jQuery.ajax( this ).done(function( data ) { + request = jQuery.ajax( this ).done( function( data ) { ok( data.data, "this re-used: JSON results returned (GET, no callback)" ); - }); + } ); promise.abort = request.abort; return request; - }); + } ); promise.abort = request.abort; return promise; }, @@ -896,44 +896,44 @@ module( "ajax", { crossDomain: crossDomain, success: true } - ]); + ] ); - }); + } ); ajaxTest( "jQuery.ajax() - script, Remote", 2, { setup: function() { - Globals.register("testBar"); + Globals.register( "testBar" ); }, url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php", dataType: "script", success: function() { - strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" ); + strictEqual( window[ "testBar" ], "bar", "Script results returned (GET, no callback)" ); } - }); + } ); ajaxTest( "jQuery.ajax() - script, Remote with POST", 3, { setup: function() { - Globals.register("testBar"); + Globals.register( "testBar" ); }, url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php", type: "POST", dataType: "script", success: function( data, status ) { - strictEqual( window["testBar"], "bar", "Script results returned (POST, no callback)" ); + strictEqual( window[ "testBar" ], "bar", "Script results returned (POST, no callback)" ); strictEqual( status, "success", "Script results returned (POST, no callback)" ); } - }); + } ); ajaxTest( "jQuery.ajax() - script, Remote with scheme-less URL", 2, { setup: function() { - Globals.register("testBar"); + Globals.register( "testBar" ); }, url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + "data/testbar.php", dataType: "script", success: function() { - strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" ); + strictEqual( window[ "testBar" ], "bar", "Script results returned (GET, no callback)" ); } - }); + } ); ajaxTest( "jQuery.ajax() - malformed JSON", 2, { url: "data/badjson.js", @@ -942,7 +942,7 @@ module( "ajax", { strictEqual( msg, "parsererror", "A parse error occurred." ); ok( /(invalid|error|exception)/i.test( detailedMsg ), "Detailed parsererror message provided" ); } - }); + } ); ajaxTest( "jQuery.ajax() - script by content-type", 2, [ { @@ -959,7 +959,7 @@ module( "ajax", { }, success: true } - ]); + ] ); ajaxTest( "jQuery.ajax() - JSON by content-type", 5, { url: "data/json.php", @@ -969,15 +969,15 @@ module( "ajax", { }, success: function( json ) { ok( json.length >= 2, "Check length" ); - strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" ); - strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" ); - strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" ); - strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" ); + strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" ); + strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" ); + strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" ); + strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" ); } - }); + } ); ajaxTest( "jQuery.ajax() - JSON by content-type disabled with options", 6, { - url: url("data/json.php"), + url: url( "data/json.php" ), data: { "header": "json", "json": "array" @@ -988,30 +988,30 @@ module( "ajax", { success: function( text ) { strictEqual( typeof text, "string", "json wasn't auto-determined" ); var json = jQuery.parseJSON( text ); - ok( json.length >= 2, "Check length"); - strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" ); - strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" ); - strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" ); - strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" ); + ok( json.length >= 2, "Check length" ); + strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" ); + strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" ); + strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" ); + strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" ); } - }); + } ); ajaxTest( "jQuery.ajax() - simple get", 1, { type: "GET", - url: url("data/name.php?name=foo"), + url: url( "data/name.php?name=foo" ), success: function( msg ) { strictEqual( msg, "bar", "Check for GET" ); } - }); + } ); ajaxTest( "jQuery.ajax() - simple post", 1, { type: "POST", - url: url("data/name.php"), + url: url( "data/name.php" ), data: "name=peter", success: function( msg ) { strictEqual( msg, "pan", "Check for POST" ); } - }); + } ); ajaxTest( "jQuery.ajax() - data option - empty bodies for non-GET requests", 1, { url: "data/echoData.php", @@ -1020,7 +1020,7 @@ module( "ajax", { success: function( result ) { strictEqual( result, "" ); } - }); + } ); var ifModifiedNow = new Date(); @@ -1034,14 +1034,14 @@ module( "ajax", { asyncTest( "jQuery.ajax() - If-Modified-Since support" + label, 4, function() { var url = "data/if_modified_since.php?ts=" + ifModifiedNow++; - jQuery.ajax({ + jQuery.ajax( { url: url, ifModified: true, cache: cache, success: function( data, status ) { strictEqual( status, "success" ); - jQuery.ajax({ + jQuery.ajax( { url: url, ifModified: true, cache: cache, @@ -1053,22 +1053,22 @@ module( "ajax", { complete: function() { start(); } - }); + } ); } - }); - }); + } ); + } ); asyncTest( "jQuery.ajax() - Etag support" + label, 3, function() { var url = "data/etag.php?ts=" + ifModifiedNow++; - jQuery.ajax({ + jQuery.ajax( { url: url, ifModified: true, cache: cache, success: function( data, status ) { strictEqual( status, "success" ); - jQuery.ajax({ + jQuery.ajax( { url: url, ifModified: true, cache: cache, @@ -1079,54 +1079,56 @@ module( "ajax", { complete: function() { start(); } - }); + } ); } - }); - }); + } ); + } ); } /* jQuery.each arguments end */ ); ajaxTest( "jQuery.ajax() - failing cross-domain (non-existing)", 1, { + // see RFC 2606 url: "http://example.invalid", error: function( xhr, _, e ) { ok( true, "file not found: " + xhr.status + " => " + e ); } - }); + } ); ajaxTest( "jQuery.ajax() - failing cross-domain", 1, { url: "http://" + externalHost, error: function( xhr, _, e ) { ok( true, "access denied: " + xhr.status + " => " + e ); } - }); + } ); ajaxTest( "jQuery.ajax() - atom+xml", 1, { - url: url("data/atom+xml.php"), + url: url( "data/atom+xml.php" ), success: function() { ok( true, "success" ); } - }); + } ); asyncTest( "jQuery.ajax() - statusText", 3, function() { - jQuery.ajax( url("data/statusText.php?status=200&text=Hello") ).done(function( _, statusText, jqXHR ) { + jQuery.ajax( url( "data/statusText.php?status=200&text=Hello" ) ).done( function( _, statusText, jqXHR ) { strictEqual( statusText, "success", "callback status text ok for success" ); ok( jqXHR.statusText === "Hello" || jqXHR.statusText === "OK", "jqXHR status text ok for success (" + jqXHR.statusText + ")" ); - jQuery.ajax( url("data/statusText.php?status=404&text=World") ).fail(function( jqXHR, statusText ) { + jQuery.ajax( url( "data/statusText.php?status=404&text=World" ) ).fail( function( jqXHR, statusText ) { strictEqual( statusText, "error", "callback status text ok for error" ); + // ok( jqXHR.statusText === "World" || jQuery.browser.safari && jqXHR.statusText === "Not Found", "jqXHR status text ok for error (" + jqXHR.statusText + ")" ); start(); - }); - }); - }); + } ); + } ); + } ); asyncTest( "jQuery.ajax() - statusCode", 20, function() { var count = 12; function countComplete() { - if ( ! --count ) { + if ( !--count ) { start(); } } @@ -1151,45 +1153,45 @@ module( "ajax", { }, function( uri, isSuccess ) { - jQuery.ajax( url(uri), { + jQuery.ajax( url( uri ), { statusCode: createStatusCodes( "in options", isSuccess ), complete: countComplete - }); + } ); - jQuery.ajax( url(uri), { + jQuery.ajax( url( uri ), { complete: countComplete - }).statusCode( createStatusCodes("immediately with method", isSuccess) ); + } ).statusCode( createStatusCodes( "immediately with method", isSuccess ) ); - jQuery.ajax( url(uri), { + jQuery.ajax( url( uri ), { complete: function( jqXHR ) { - jqXHR.statusCode( createStatusCodes("on complete", isSuccess) ); + jqXHR.statusCode( createStatusCodes( "on complete", isSuccess ) ); countComplete(); } - }); + } ); - jQuery.ajax( url(uri), { + jQuery.ajax( url( uri ), { complete: function( jqXHR ) { - setTimeout(function() { - jqXHR.statusCode( createStatusCodes("very late binding", isSuccess) ); + setTimeout( function() { + jqXHR.statusCode( createStatusCodes( "very late binding", isSuccess ) ); countComplete(); }, 100 ); } - }); + } ); - jQuery.ajax( url(uri), { + jQuery.ajax( url( uri ), { statusCode: createStatusCodes( "all (options)", isSuccess ), complete: function( jqXHR ) { - jqXHR.statusCode( createStatusCodes("all (on complete)", isSuccess) ); - setTimeout(function() { - jqXHR.statusCode( createStatusCodes("all (very late binding)", isSuccess) ); + jqXHR.statusCode( createStatusCodes( "all (on complete)", isSuccess ) ); + setTimeout( function() { + jqXHR.statusCode( createStatusCodes( "all (very late binding)", isSuccess ) ); countComplete(); }, 100 ); } - }).statusCode( createStatusCodes("all (immediately with method)", isSuccess) ); + } ).statusCode( createStatusCodes( "all (immediately with method)", isSuccess ) ); var testString = ""; - jQuery.ajax( url(uri), { + jQuery.ajax( url( uri ), { success: function( a, b, jqXHR ) { ok( isSuccess, "success" ); var statusCode = {}; @@ -1216,16 +1218,16 @@ module( "ajax", { ); countComplete(); } - }); + } ); } /* jQuery.each arguments end*/ ); - }); + } ); ajaxTest( "jQuery.ajax() - transitive conversions", 8, [ { - url: url("data/json.php"), + url: url( "data/json.php" ), converters: { "json myJson": function( data ) { ok( true, "converter called" ); @@ -1240,7 +1242,7 @@ module( "ajax", { } }, { - url: url("data/json.php"), + url: url( "data/json.php" ), converters: { "json myJson": function( data ) { ok( true, "converter called (*)" ); @@ -1255,11 +1257,11 @@ module( "ajax", { strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType (*)" ); } } - ]); + ] ); ajaxTest( "jQuery.ajax() - overrideMimeType", 2, [ { - url: url("data/json.php"), + url: url( "data/json.php" ), beforeSend: function( xhr ) { xhr.overrideMimeType( "application/json" ); }, @@ -1268,26 +1270,26 @@ module( "ajax", { } }, { - url: url("data/json.php"), + url: url( "data/json.php" ), mimeType: "application/json", success: function( json ) { ok( json.data, "Mimetype overridden using mimeType option" ); } } - ]); + ] ); ajaxTest( "jQuery.ajax() - empty json gets to error callback instead of success callback.", 1, { - url: url("data/echoData.php"), + url: url( "data/echoData.php" ), error: function( _, __, error ) { equal( typeof error === "object", true, "Didn't get back error object for empty json response" ); }, dataType: "json" - }); + } ); ajaxTest( "#2688 - jQuery.ajax() - beforeSend, cancel request", 2, { create: function() { - return jQuery.ajax({ - url: url("data/name.html"), + return jQuery.ajax( { + url: url( "data/name.html" ), beforeSend: function() { ok( true, "beforeSend got called, canceling" ); return false; @@ -1301,12 +1303,12 @@ module( "ajax", { error: function() { ok( false, "request didn't get canceled" ); } - }); + } ); }, fail: function( _, reason ) { strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" ); } - }); + } ); ajaxTest( "#2806 - jQuery.ajax() - data option - evaluate function values", 1, { url: "data/echoQuery.php", @@ -1318,24 +1320,24 @@ module( "ajax", { success: function( result ) { strictEqual( result, "key=value" ); } - }); + } ); - test( "#7531 - jQuery.ajax() - Location object as url", function () { + test( "#7531 - jQuery.ajax() - Location object as url", function() { expect( 1 ); var xhr, success = false; try { - xhr = jQuery.ajax({ + xhr = jQuery.ajax( { url: window.location - }); + } ); success = true; xhr.abort(); - } catch (e) { + } catch ( e ) { } ok( success, "document.location did not generate exception" ); - }); + } ); jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) { ajaxTest( "#7578 - jQuery.ajax() - JSONP - default for cache option" + label, 1, { @@ -1347,8 +1349,8 @@ module( "ajax", { return false; }, error: true - }); - }); + } ); + } ); ajaxTest( "#8107 - jQuery.ajax() - multiple method signatures introduced in 1.5", 4, [ { @@ -1361,7 +1363,7 @@ module( "ajax", { }, { create: function() { - return jQuery.ajax("data/name.html"); + return jQuery.ajax( "data/name.html" ); }, done: function() { ok( true, "With only string URL argument" ); @@ -1369,7 +1371,7 @@ module( "ajax", { }, { create: function() { - return jQuery.ajax( "data/name.html", {}); + return jQuery.ajax( "data/name.html", {} ); }, done: function() { ok( true, "With string URL param and map" ); @@ -1384,7 +1386,7 @@ module( "ajax", { ok( true, "With only map" ); } } - ]); + ] ); jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) { ajaxTest( "#8205 - jQuery.ajax() - JSONP - re-use callbacks name" + label, 4, { @@ -1415,7 +1417,7 @@ module( "ajax", { ); } - jQuery.ajax({ + jQuery.ajax( { url: "data/jsonp.php", dataType: "jsonp", crossDomain: crossDomain, @@ -1423,12 +1425,12 @@ module( "ajax", { strictEqual( this.jsonpCallback, previous.callback, "JSONP callback name is re-used" ); return false; } - }); + } ); } - }); - }); + } ); + } ); - test( "#9887 - jQuery.ajax() - Context with circular references (#9887)", function () { + test( "#9887 - jQuery.ajax() - Context with circular references (#9887)", function() { expect( 2 ); var success = false, @@ -1441,13 +1443,13 @@ module( "ajax", { ok( this === context, "context was not deep extended" ); return false; } - }); + } ); success = true; } catch ( e ) { console.log( e ); } ok( success, "context with circular reference did not generate an exception" ); - }); + } ); jQuery.each( [ "as argument", "in settings object" ], function( inSetting, title ) { @@ -1467,12 +1469,12 @@ module( "ajax", { request( false ), request( null ), request( undefined ) - ]); + ] ); - }); + } ); ajaxTest( "#11151 - jQuery.ajax() - parse error body", 2, { - url: url("data/errorWithJSON.php"), + url: url( "data/errorWithJSON.php" ), dataFilter: function( string ) { ok( false, "dataFilter called" ); return string; @@ -1481,16 +1483,17 @@ module( "ajax", { strictEqual( jqXHR.responseText, "{ \"code\": 40, \"message\": \"Bad Request\" }", "Error body properly set" ); deepEqual( jqXHR.responseJSON, { code: 40, message: "Bad Request" }, "Error body properly parsed" ); } - }); + } ); ajaxTest( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE", 1, { - url: url("data/1x1.jpg"), + url: url( "data/1x1.jpg" ), success: function( data ) { ok( data === undefined || /JFIF/.test( data ), "success callback reached" ); } - }); + } ); asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function() { + // Support: Android 2.3 only // Android 2.3 doesn't fire the window.onerror handler, just accept the reality there. if ( /android 2\.3/i.test( navigator.userAgent ) ) { @@ -1506,18 +1509,18 @@ module( "ajax", { window.onerror = onerror; start(); }; - jQuery.ajax({ + jQuery.ajax( { url: "data/badjson.js", dataType: "script", "throws": true - }); - }); + } ); + } ); jQuery.each( [ "method", "type" ], function( _, globalOption ) { function request( option ) { var options = { - url: url("data/echoData.php"), + url: url( "data/echoData.php" ), data: "hello", success: function( msg ) { strictEqual( msg, "hello", "Check for POST (no override)" ); @@ -1539,35 +1542,36 @@ module( "ajax", { jQuery.ajaxSetup( options ); }, requests: [ - request("type"), - request("method"), + request( "type" ), + request( "method" ), request() ] - }); + } ); - }); + } ); ajaxTest( "#13276 - jQuery.ajax() - compatibility between XML documents from ajax requests and parsed string", 1, { url: "data/dashboard.xml", dataType: "xml", success: function( ajaxXML ) { - var parsedXML = jQuery( jQuery.parseXML("<tab title=\"Added\">blibli</tab>") ).find("tab"); + var parsedXML = jQuery( jQuery.parseXML( "<tab title=\"Added\">blibli</tab>" ) ).find( "tab" ); ajaxXML = jQuery( ajaxXML ); try { + // Android 2.3 doesn't automatically adopt nodes from foreign documents. // (see the comment in test/manipulation.js) // Support: Android 2.3 if ( /android 2\.3/i.test( navigator.userAgent ) ) { parsedXML = jQuery( ajaxXML[ 0 ].adoptNode( parsedXML[ 0 ] ) ); } - ajaxXML.find("infowindowtab").append( parsedXML ); - } catch( e ) { + ajaxXML.find( "infowindowtab" ).append( parsedXML ); + } catch ( e ) { strictEqual( e, undefined, "error" ); return; } - strictEqual( ajaxXML.find("tab").length, 3, "Parsed node was added properly" ); + strictEqual( ajaxXML.find( "tab" ).length, 3, "Parsed node was added properly" ); } - }); + } ); ajaxTest( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests", 3, { url: "data/nocontent.php", @@ -1587,17 +1591,17 @@ module( "ajax", { strictEqual( status, "parsererror", "Parser Error" ); strictEqual( error, "converter was called", "Converter was called" ); } - }); + } ); ajaxTest( "#13388 - jQuery.ajax() - responseXML", 3, { - url: url("data/with_fries.xml"), + url: url( "data/with_fries.xml" ), dataType: "xml", success: function( resp, _, jqXHR ) { notStrictEqual( resp, undefined, "XML document exists" ); ok( "responseXML" in jqXHR, "jqXHR.responseXML exists" ); strictEqual( resp, jqXHR.responseXML, "jqXHR.responseXML is set correctly" ); } - }); + } ); ajaxTest( "#13922 - jQuery.ajax() - converter is bypassed for HEAD requests", 3, { url: "data/json.php", @@ -1641,19 +1645,20 @@ module( "ajax", { testIframeWithCallback( "#14379 - jQuery.ajax() on unload", "ajax/onunload.html", function( status ) { expect( 1 ); strictEqual( status, "success", "Request completed" ); - }); + } ); //----------- jQuery.ajaxPrefilter() ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, { dataType: "prefix", setup: function() { + // Ensure prefix does not throw an error - jQuery.ajaxPrefilter("+prefix", function( options, _, jqXHR ) { + jQuery.ajaxPrefilter( "+prefix", function( options, _, jqXHR ) { if ( options.abortInPrefilter ) { jqXHR.abort(); } - }); + } ); }, abortInPrefilter: true, error: function() { @@ -1662,27 +1667,27 @@ module( "ajax", { fail: function( _, reason ) { strictEqual( reason, "canceled", "Request aborted by the prefilter must fail with 'canceled' status text" ); } - }); + } ); //----------- jQuery.ajaxSetup() asyncTest( "jQuery.ajaxSetup()", 1, function() { - jQuery.ajaxSetup({ - url: url("data/name.php?name=foo"), + jQuery.ajaxSetup( { + url: url( "data/name.php?name=foo" ), success: function( msg ) { strictEqual( msg, "bar", "Check for GET" ); start(); } - }); + } ); jQuery.ajax(); - }); + } ); asyncTest( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", 2, function() { var passed = 0, pass = function() { ok( passed++ < 2, "Error callback executed" ); if ( passed === 2 ) { - jQuery( document ).off("ajaxError.setupTest"); + jQuery( document ).off( "ajaxError.setupTest" ); start(); } }, @@ -1693,26 +1698,26 @@ module( "ajax", { jQuery( document ).on( "ajaxError.setupTest", pass ); - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { timeout: 1000 - }); + } ); - jQuery.ajax({ + jQuery.ajax( { type: "GET", - url: url("data/name.php?wait=5"), + url: url( "data/name.php?wait=5" ), error: pass, success: fail - }); - }); + } ); + } ); asyncTest( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", 1, function() { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { timeout: 50 - }); - jQuery.ajax({ + } ); + jQuery.ajax( { type: "GET", timeout: 15000, - url: url("data/name.php?wait=1"), + url: url( "data/name.php?wait=1" ), error: function() { ok( false, "Check for local timeout failed" ); start(); @@ -1721,100 +1726,100 @@ module( "ajax", { ok( true, "Check for local timeout" ); start(); } - }); - }); + } ); + } ); //----------- jQuery.domManip() test( "#11264 - jQuery.domManip() - no side effect because of ajaxSetup or global events", function() { expect( 1 ); - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { type: "POST" - }); + } ); jQuery( document ).on( "ajaxStart ajaxStop", function() { ok( false, "Global event triggered" ); - }); + } ); - jQuery("#qunit-fixture").append("<script src='data/ajax/evalScript.php'></script>"); + jQuery( "#qunit-fixture" ).append( "<script src='data/ajax/evalScript.php'></script>" ); - jQuery( document ).off("ajaxStart ajaxStop"); - }); + jQuery( document ).off( "ajaxStart ajaxStop" ); + } ); asyncTest( "jQuery#load() - always use GET method even if it overrided through ajaxSetup (#11264)", 1, function() { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { type: "POST" - }); + } ); jQuery( "#qunit-fixture" ).load( "data/ajax/method.php", function( method ) { equal( method, "GET" ); start(); - }); - }); + } ); + } ); asyncTest( "#11402 - jQuery.domManip() - script in comments are properly evaluated", 2, function() { - jQuery("#qunit-fixture").load( "data/cleanScript.html", start ); - }); + jQuery( "#qunit-fixture" ).load( "data/cleanScript.html", start ); + } ); //----------- jQuery.get() asyncTest( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", 2, function() { - jQuery.get( url("data/dashboard.xml"), function( xml ) { + jQuery.get( url( "data/dashboard.xml" ), function( xml ) { var content = []; - jQuery( "tab", xml ).each(function() { + jQuery( "tab", xml ).each( function() { content.push( jQuery( this ).text() ); - }); + } ); strictEqual( content[ 0 ], "blabla", "Check first tab" ); strictEqual( content[ 1 ], "blublu", "Check second tab" ); start(); - }); - }); + } ); + } ); asyncTest( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", 1, function() { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { data: "helloworld" - }); - jQuery.get( url("data/echoQuery.php"), function( data ) { + } ); + jQuery.get( url( "data/echoQuery.php" ), function( data ) { ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" ); start(); - }); - }); + } ); + } ); //----------- jQuery.getJSON() asyncTest( "jQuery.getJSON( String, Hash, Function ) - JSON array", 5, function() { jQuery.getJSON( - url("data/json.php"), + url( "data/json.php" ), { "json": "array" }, function( json ) { ok( json.length >= 2, "Check length" ); - strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" ); - strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" ); - strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" ); - strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" ); + strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" ); + strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" ); + strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" ); + strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" ); start(); } ); - }); + } ); asyncTest( "jQuery.getJSON( String, Function ) - JSON object", 2, function() { - jQuery.getJSON( url("data/json.php"), function( json ) { - if ( json && json["data"] ) { - strictEqual( json["data"]["lang"], "en", "Check JSON: lang" ); - strictEqual( json["data"].length, 25, "Check JSON: length" ); + jQuery.getJSON( url( "data/json.php" ), function( json ) { + if ( json && json[ "data" ] ) { + strictEqual( json[ "data" ][ "lang" ], "en", "Check JSON: lang" ); + strictEqual( json[ "data" ].length, 25, "Check JSON: length" ); start(); } - }); - }); + } ); + } ); asyncTest( "jQuery.getJSON() - Using Native JSON", 2, function() { var restore = "JSON" in window, old = window.JSON; if ( !restore ) { - Globals.register("JSON"); + Globals.register( "JSON" ); } window.JSON = { parse: function() { @@ -1823,183 +1828,183 @@ module( "ajax", { return true; } }; - jQuery.getJSON( url("data/json.php"), function( json ) { + jQuery.getJSON( url( "data/json.php" ), function( json ) { strictEqual( json, true, "Verifying return value" ); start(); - }); - }); + } ); + } ); asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function() { jQuery.getJSON( url( window.location.href.replace( /[^\/]*$/, "" ) + "data/json.php" ), function( json ) { strictEqual( json.data.lang, "en", "Check JSON: lang" ); strictEqual( json.data.length, 25, "Check JSON: length" ); start(); - }); - }); + } ); + } ); //----------- jQuery.getScript() asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function() { - Globals.register("testBar"); - jQuery.getScript( url("data/testbar.php"), function() { - strictEqual( window["testBar"], "bar", "Check if script was evaluated" ); + Globals.register( "testBar" ); + jQuery.getScript( url( "data/testbar.php" ), function() { + strictEqual( window[ "testBar" ], "bar", "Check if script was evaluated" ); start(); - }); - }); + } ); + } ); asyncTest( "jQuery.getScript( String, Function ) - no callback", 1, function() { - Globals.register("testBar"); - jQuery.getScript( url("data/testbar.php") ).done( start ); - }); + Globals.register( "testBar" ); + jQuery.getScript( url( "data/testbar.php" ) ).done( start ); + } ); asyncTest( "#8082 - jQuery.getScript( String, Function ) - source as responseText", 2, function() { - Globals.register("testBar"); - jQuery.getScript( url("data/testbar.php"), function( data, _, jqXHR ) { + Globals.register( "testBar" ); + jQuery.getScript( url( "data/testbar.php" ), function( data, _, jqXHR ) { strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script" ); start(); - }); - }); + } ); + } ); //----------- jQuery.fn.load() // check if load can be called with only url asyncTest( "jQuery.fn.load( String )", 2, function() { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { beforeSend: function() { strictEqual( this.type, "GET", "no data means GET request" ); } - }); - jQuery("#first").load( "data/name.html", start ); - }); + } ); + jQuery( "#first" ).load( "data/name.html", start ); + } ); asyncTest( "jQuery.fn.load() - 404 error callbacks", 6, function() { - addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError")(); + addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError" )(); jQuery( document ).ajaxStop( start ); - jQuery("<div/>").load( "data/404.html", function() { + jQuery( "<div/>" ).load( "data/404.html", function() { ok( true, "complete" ); - }); - }); + } ); + } ); // check if load can be called with url and null data asyncTest( "jQuery.fn.load( String, null )", 2, function() { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { beforeSend: function() { strictEqual( this.type, "GET", "no data means GET request" ); } - }); - jQuery("#first").load( "data/name.html", null, start ); - }); + } ); + jQuery( "#first" ).load( "data/name.html", null, start ); + } ); // check if load can be called with url and undefined data asyncTest( "jQuery.fn.load( String, undefined )", 2, function() { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { beforeSend: function() { strictEqual( this.type, "GET", "no data means GET request" ); } - }); - jQuery("#first").load( "data/name.html", undefined, start ); - }); + } ); + jQuery( "#first" ).load( "data/name.html", undefined, start ); + } ); // check if load can be called with only url asyncTest( "jQuery.fn.load( URL_SELECTOR )", 1, function() { - jQuery("#first").load( "data/test3.html div.user", function() { - strictEqual( jQuery( this ).children("div").length, 2, "Verify that specific elements were injected" ); + jQuery( "#first" ).load( "data/test3.html div.user", function() { + strictEqual( jQuery( this ).children( "div" ).length, 2, "Verify that specific elements were injected" ); start(); - }); - }); + } ); + } ); // Selector should be trimmed to avoid leading spaces (#14773) asyncTest( "jQuery.fn.load( URL_SELECTOR with spaces )", 1, function() { - jQuery("#first").load( "data/test3.html #superuser ", function() { - strictEqual( jQuery( this ).children("div").length, 1, "Verify that specific elements were injected" ); + jQuery( "#first" ).load( "data/test3.html #superuser ", function() { + strictEqual( jQuery( this ).children( "div" ).length, 1, "Verify that specific elements were injected" ); start(); - }); - }); + } ); + } ); asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function() { - jQuery("#first").load( url("data/name.html"), function() { - ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" ); + jQuery( "#first" ).load( url( "data/name.html" ), function() { + ok( /^ERROR/.test( jQuery( "#first" ).text() ), "Check if content was injected into the DOM" ); start(); - }); - }); + } ); + } ); asyncTest( "jQuery.fn.load( String, Function ) - check scripts", 7, function() { var verifyEvaluation = function() { - strictEqual( window["testBar"], "bar", "Check if script src was evaluated after load" ); - strictEqual( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM"); + strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated after load" ); + strictEqual( jQuery( "#ap" ).html(), "bar", "Check if script evaluation has modified DOM" ); start(); }; - Globals.register("testFoo"); - Globals.register("testBar"); + Globals.register( "testFoo" ); + Globals.register( "testBar" ); - jQuery("#first").load( url("data/test.html"), function() { - ok( jQuery("#first").html().match( /^html text/ ), "Check content after loading html" ); - strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM" ); - strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" ); + jQuery( "#first" ).load( url( "data/test.html" ), function() { + ok( jQuery( "#first" ).html().match( /^html text/ ), "Check content after loading html" ); + strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" ); + strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated after load" ); setTimeout( verifyEvaluation, 600 ); - }); - }); + } ); + } ); asyncTest( "jQuery.fn.load( String, Function ) - check file with only a script tag", 3, function() { - Globals.register("testFoo"); + Globals.register( "testFoo" ); - jQuery("#first").load( url("data/test2.html"), function() { - strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM"); - strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" ); + jQuery( "#first" ).load( url( "data/test2.html" ), function() { + strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" ); + strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated after load" ); start(); - }); - }); + } ); + } ); asyncTest( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", 2, function() { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { dataFilter: function() { return "Hello World"; } - }); - jQuery("<div/>").load( url("data/name.html"), function( responseText ) { + } ); + jQuery( "<div/>" ).load( url( "data/name.html" ), function( responseText ) { strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" ); strictEqual( responseText, "Hello World", "Test callback receives filtered data" ); start(); - }); - }); + } ); + } ); asyncTest( "jQuery.fn.load( String, Object, Function )", 2, function() { - jQuery("<div />").load( url("data/params_html.php"), { + jQuery( "<div />" ).load( url( "data/params_html.php" ), { "foo": 3, "bar": "ok" }, function() { - var $post = jQuery( this ).find("#post"); - strictEqual( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly" ); - strictEqual( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly" ); + var $post = jQuery( this ).find( "#post" ); + strictEqual( $post.find( "#foo" ).text(), "3", "Check if a hash of data is passed correctly" ); + strictEqual( $post.find( "#bar" ).text(), "ok", "Check if a hash of data is passed correctly" ); start(); - }); - }); + } ); + } ); asyncTest( "jQuery.fn.load( String, String, Function )", 2, function() { - jQuery("<div />").load( url("data/params_html.php"), "foo=3&bar=ok", function() { - var $get = jQuery( this ).find("#get"); - strictEqual( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly" ); - strictEqual( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly" ); + jQuery( "<div />" ).load( url( "data/params_html.php" ), "foo=3&bar=ok", function() { + var $get = jQuery( this ).find( "#get" ); + strictEqual( $get.find( "#foo" ).text(), "3", "Check if a string of data is passed correctly" ); + strictEqual( $get.find( "#bar" ).text(), "ok", "Check if a of data is passed correctly" ); start(); - }); - }); + } ); + } ); asyncTest( "jQuery.fn.load() - callbacks get the correct parameters", 8, function() { var completeArgs = {}; - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { success: function( _, status, jqXHR ) { completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ]; }, error: function( jqXHR, status ) { completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ]; } - }); + } ); jQuery.when.apply( jQuery, - jQuery.map([ + jQuery.map( [ { type: "success", url: "data/echoQuery.php?arg=pop" @@ -2010,67 +2015,67 @@ module( "ajax", { } ], function( options ) { - return jQuery.Deferred(function( defer ) { - jQuery("#foo").load( options.url, function() { + return jQuery.Deferred( function( defer ) { + jQuery( "#foo" ).load( options.url, function() { var args = arguments; strictEqual( completeArgs[ options.url ].length, args.length, "same number of arguments (" + options.type + ")" ); jQuery.each( completeArgs[ options.url ], function( i, value ) { strictEqual( args[ i ], value, "argument #" + i + " is the same (" + options.type + ")" ); - }); + } ); defer.resolve(); - }); - }); - }) + } ); + } ); + } ) ).always( start ); - }); + } ); asyncTest( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", 1, function() { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { dataType: "json" - }); - jQuery( document ).ajaxComplete(function( e, xml, s ) { + } ); + jQuery( document ).ajaxComplete( function( e, xml, s ) { strictEqual( s.dataType, "html", "Verify the load() dataType was html" ); - jQuery( document ).off("ajaxComplete"); + jQuery( document ).off( "ajaxComplete" ); start(); - }); - jQuery("#first").load("data/test3.html"); - }); + } ); + jQuery( "#first" ).load( "data/test3.html" ); + } ); asyncTest( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", 1, function() { var data = { "baz": 1 }; - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { data: { "foo": "bar" } - }); - jQuery("#foo").load( "data/echoQuery.php", data ); - jQuery( document ).ajaxComplete(function( event, jqXHR, options ) { - ok( ~options.data.indexOf("foo=bar"), "Data from ajaxSettings was used" ); + } ); + jQuery( "#foo" ).load( "data/echoQuery.php", data ); + jQuery( document ).ajaxComplete( function( event, jqXHR, options ) { + ok( ~options.data.indexOf( "foo=bar" ), "Data from ajaxSettings was used" ); start(); - }); - }); + } ); + } ); //----------- jQuery.post() asyncTest( "jQuery.post() - data", 3, function() { jQuery.when( jQuery.post( - url("data/name.php"), + url( "data/name.php" ), { xml: "5-2", length: 3 }, function( xml ) { - jQuery( "math", xml ).each(function() { + jQuery( "math", xml ).each( function() { strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); - }); + } ); } ), - jQuery.ajax({ - url: url("data/echoData.php"), + jQuery.ajax( { + url: url( "data/echoData.php" ), type: "POST", data: { "test": { @@ -2081,56 +2086,56 @@ module( "ajax", { success: function( data ) { strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly" ); } - }) - ).always(function() { + } ) + ).always( function() { start(); - }); - }); + } ); + } ); asyncTest( "jQuery.post( String, Hash, Function ) - simple with xml", 4, function() { jQuery.when( jQuery.post( - url("data/name.php"), + url( "data/name.php" ), { "xml": "5-2" }, function( xml ) { - jQuery( "math", xml ).each(function() { + jQuery( "math", xml ).each( function() { strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); - }); + } ); } ), - jQuery.post( url("data/name.php?xml=5-2"), {}, function( xml ) { - jQuery( "math", xml ).each(function() { + jQuery.post( url( "data/name.php?xml=5-2" ), {}, function( xml ) { + jQuery( "math", xml ).each( function() { strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); - }); - }) - ).always(function() { + } ); + } ) + ).always( function() { start(); - }); - }); + } ); + } ); asyncTest( "jQuery[get|post]( options ) - simple with xml", 2, function() { jQuery.when.apply( jQuery, - jQuery.map( [ "get", "post" ] , function( method ) { - return jQuery[ method ]({ + jQuery.map( [ "get", "post" ], function( method ) { + return jQuery[ method ]( { url: url( "data/name.php" ), data: { "xml": "5-2" }, success: function( xml ) { - jQuery( "math", xml ).each(function() { + jQuery( "math", xml ).each( function() { strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); - }); + } ); } - }); - }) - ).always(function() { + } ); + } ) + ).always( function() { start(); - }); - }); + } ); + } ); //----------- jQuery.active @@ -2138,6 +2143,6 @@ module( "ajax", { expect( 1 ); ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active ); - }); + } ); -})(); +} )(); |