aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Waldron <waldron.rick@gmail.com>2012-10-15 17:11:21 -0400
committerRick Waldron <waldron.rick@gmail.com>2012-10-15 17:11:21 -0400
commitd6c84c5bb55814df0063e04b12c4143d07cba3f7 (patch)
tree3785545676d65a100a4d0a1d6b32ff8ccba04c20
parentcc172a862be468b9847a7bfd653b97cde53d2b64 (diff)
downloadjquery-d6c84c5bb55814df0063e04b12c4143d07cba3f7.tar.gz
jquery-d6c84c5bb55814df0063e04b12c4143d07cba3f7.zip
Breakout JSONP domain-related tests
-rw-r--r--test/unit/ajax.js228
1 files changed, 142 insertions, 86 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 8c1033ee0..00b3bf82f 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1110,7 +1110,7 @@ if ( jQuery.ajax && ( !isLocal || hasPHP ) ) {
}
equal( 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 ) {
+ if ( ++count === 6 ) {
start();
}
});
@@ -1449,53 +1449,20 @@ if ( jQuery.ajax && ( !isLocal || hasPHP ) ) {
});
});
+
jQuery.each( [ "Same Domain", "Cross Domain" ], function( crossDomain, label ) {
- test( "jQuery.ajax() - JSONP, " + label, function() {
- expect( 24 );
+
+ asyncTest( "jQuery.ajax() - JSONP, Query String (?n)" + label, function() {
+ expect( 4 );
var count = 0;
function plus() {
- if ( ++count == 20 ) {
+ if ( ++count === 4 ) {
start();
}
}
- stop();
-
- jQuery.ajax({
- url: "data/jsonp.php",
- dataType: "jsonp",
- crossDomain: crossDomain,
- 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();
- }
- });
-
- 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",
@@ -1511,21 +1478,6 @@ if ( jQuery.ajax && ( !isLocal || hasPHP ) ) {
});
jQuery.ajax({
- url: "data/jsonp.php",
- dataType: "jsonp",
- crossDomain: crossDomain,
- data: "callback=?",
- 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();
- }
- });
-
- jQuery.ajax({
url: "data/jsonp.php?callback=??",
dataType: "jsonp",
crossDomain: crossDomain,
@@ -1540,21 +1492,6 @@ if ( jQuery.ajax && ( !isLocal || hasPHP ) ) {
});
jQuery.ajax({
- url: "data/jsonp.php",
- dataType: "jsonp",
- crossDomain: crossDomain,
- data: "callback=??",
- success: function( data ) {
- ok( data.data, "JSON results returned (GET, data context-free callback)" );
- plus();
- },
- error: function( data ) {
- ok( false, "Ajax error JSON (GET, data context-free callback)" );
- plus();
- }
- });
-
- jQuery.ajax({
url: "data/jsonp.php/??",
dataType: "jsonp",
crossDomain: crossDomain,
@@ -1581,6 +1518,17 @@ if ( jQuery.ajax && ( !isLocal || hasPHP ) ) {
plus();
}
});
+ });
+
+ asyncTest( "jQuery.ajax() - JSONP, Explicit jsonp/Callback param " + label, function() {
+ expect( 9 );
+
+ var count = 0;
+ function plus() {
+ if ( ++count === 4 ) {
+ start();
+ }
+ }
jQuery.ajax({
url: "data/jsonp.php",
@@ -1651,6 +1599,80 @@ if ( jQuery.ajax && ( !isLocal || hasPHP ) ) {
});
jQuery.ajax({
+ url: "data/jsonp.php?callback=XXX",
+ dataType: "jsonp",
+ jsonp: false,
+ jsonpCallback: "XXX",
+ crossDomain: crossDomain,
+ beforeSend: function() {
+ ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
+ plus();
+ },
+ success: function( data ) {
+ ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" );
+ plus();
+ },
+ error: function( data ) {
+ ok( false, "Ajax error JSON (GET, custom callback name with no url manipulation)" );
+ plus();
+ }
+ });
+ });
+
+
+ asyncTest( "jQuery.ajax() - JSONP, Callback in data, " + label, function() {
+ expect( 2 );
+
+ var count = 0;
+ function plus() {
+ if ( ++count === 2 ) {
+ start();
+ }
+ }
+
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ crossDomain: crossDomain,
+ data: "callback=?",
+ 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();
+ }
+ });
+
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ crossDomain: crossDomain,
+ data: "callback=??",
+ success: function( data ) {
+ ok( data.data, "JSON results returned (GET, data context-free callback)" );
+ plus();
+ },
+ error: function( data ) {
+ ok( false, "Ajax error JSON (GET, data context-free callback)" );
+ plus();
+ }
+ });
+ });
+
+
+ asyncTest( "jQuery.ajax() - JSONP, POST, " + label, function() {
+ expect( 3 );
+
+ var count = 0;
+ function plus() {
+ if ( ++count === 3 ) {
+ start();
+ }
+ }
+
+ jQuery.ajax({
type: "POST",
url: "data/jsonp.php",
dataType: "jsonp",
@@ -1696,40 +1718,73 @@ if ( jQuery.ajax && ( !isLocal || hasPHP ) ) {
plus();
}
});
+ });
+
+ asyncTest( "jQuery.ajax() - JSONP, " + label, function() {
+ expect( 3 );
+
+ var count = 0;
+ function plus() {
+ if ( ++count === 2 ) {
+ start();
+ }
+ }
- //#7578
jQuery.ajax({
url: "data/jsonp.php",
dataType: "jsonp",
crossDomain: crossDomain,
- beforeSend: function() {
- strictEqual( this.cache, false, "cache must be false on JSON request" );
+ 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();
- return false;
}
});
jQuery.ajax({
- url: "data/jsonp.php?callback=XXX",
+ url: "data/jsonp.php",
dataType: "jsonp",
- jsonp: false,
- jsonpCallback: "XXX",
crossDomain: crossDomain,
- beforeSend: function() {
- ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
- plus();
- },
success: function( data ) {
- ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" );
- plus();
+ ok( data.data, ( this.alreadyDone ? "this re-used" : "first request" ) + ": JSON results returned (GET, no callback)" );
+ if ( !this.alreadyDone ) {
+ this.alreadyDone = true;
+
+ // NOTE: "this" will create another request identical
+ // to the CALLING request
+ jQuery.ajax( this );
+ } else {
+ plus();
+ }
},
error: function( data ) {
- ok( false, "Ajax error JSON (GET, custom callback name with no url manipulation)" );
+ ok( false, "Ajax error JSON (GET, no callback)" );
plus();
}
});
+ });
+
+ asyncTest( "jQuery.ajax() - #7578, " + label, function() {
+ expect( 1 );
+
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ crossDomain: crossDomain,
+ beforeSend: function() {
+ strictEqual( this.cache, false, "cache must be false on JSON request" );
+ start();
+ return false;
+ }
+ });
+ });
+
+ asyncTest( "jQuery.ajax() - #8205, " + label, function() {
+ expect( 2 );
- //#8205
jQuery.ajax({
url: "data/jsonp.php",
dataType: "jsonp",
@@ -1749,8 +1804,9 @@ if ( jQuery.ajax && ( !isLocal || hasPHP ) ) {
return false;
}
});
- }).always( plus );
-
+ }).always(function() {
+ start();
+ });
});
});