aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/ajax.js
diff options
context:
space:
mode:
authorjaubourg <j@ubourg.net>2012-04-20 03:02:20 +0200
committerjaubourg <j@ubourg.net>2012-04-20 03:02:20 +0200
commit8ebb2f4793d2c464888b5f0dba97fb5c9d0c9541 (patch)
treed6bb719534c33cb22bdb88aee0a73a0730facec3 /test/unit/ajax.js
parent3e6f94c36046e927121e2b25174f1ecd2e45d65b (diff)
downloadjquery-8ebb2f4793d2c464888b5f0dba97fb5c9d0c9541.tar.gz
jquery-8ebb2f4793d2c464888b5f0dba97fb5c9d0c9541.zip
Fixes #8205. Mitigates memory usage by recycling jsonp callback names the safest possible way (no kittens were harmed in the making of this). Doesn't even try to delete window properties (would necessitate a try/catch for IE which makes the cost in size prohibitive). Unit tests added.
Diffstat (limited to 'test/unit/ajax.js')
-rw-r--r--test/unit/ajax.js45
1 files changed, 43 insertions, 2 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index d13eaaeca..cca72aa5c 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1309,10 +1309,10 @@ test("jQuery.getScript(String, Function) - no callback", function() {
jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label ) {
test("jQuery.ajax() - JSONP, " + label, function() {
- expect(20);
+ expect(24);
var count = 0;
- function plus(){ if ( ++count == 18 ) start(); }
+ function plus(){ if ( ++count == 20 ) start(); }
stop();
@@ -1331,6 +1331,25 @@ jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label )
});
jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ crossDomain: crossDomain,
+ success: function(data){
+ ok( data.data, ( this.alreadyDone ? "this re-used" : "first request" ) + ": JSON results returned (GET, no callback)" );
+ if ( !this.alreadyDone ) {
+ this.alreadyDone = true;
+ jQuery.ajax( this );
+ } else {
+ plus();
+ }
+ },
+ error: function(data){
+ ok( false, "Ajax error JSON (GET, no callback)" );
+ plus();
+ }
+ });
+
+ jQuery.ajax({
url: "data/jsonp.php?callback=?",
dataType: "jsonp",
crossDomain: crossDomain,
@@ -1564,6 +1583,28 @@ jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label )
}
});
+ //#8205
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ crossDomain: crossDomain,
+ beforeSend: function() {
+ this.callback = this.jsonpCallback;
+ }
+ }).pipe(function() {
+ var previous = this;
+ strictEqual( previous.jsonpCallback, undefined, "jsonpCallback option is set back to default in callbacks" );
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ crossDomain: crossDomain,
+ beforeSend: function() {
+ strictEqual( this.jsonpCallback, previous.callback, "JSONP callback name is re-used" );
+ return false;
+ }
+ });
+ }).always( plus );
+
});
});