Revised jsonp unit tests and added a test for when the jsonp option is set to false.
This commit is contained in:
parent
158fa822de
commit
0e93b2e24c
1 changed files with 222 additions and 259 deletions
|
@ -1114,17 +1114,20 @@ test("jQuery.getScript(String, Function) - no callback", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery.ajax() - JSONP, Local", function() {
|
jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label ) {
|
||||||
expect(14);
|
|
||||||
|
test("jQuery.ajax() - JSONP, " + label, function() {
|
||||||
|
expect(16);
|
||||||
|
|
||||||
var count = 0;
|
var count = 0;
|
||||||
function plus(){ if ( ++count == 14 ) start(); }
|
function plus(){ if ( ++count == 16 ) start(); }
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: "data/jsonp.php",
|
url: "data/jsonp.php",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
success: function(data){
|
success: function(data){
|
||||||
ok( data.data, "JSON results returned (GET, no callback)" );
|
ok( data.data, "JSON results returned (GET, no callback)" );
|
||||||
plus();
|
plus();
|
||||||
|
@ -1138,6 +1141,7 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: "data/jsonp.php?callback=?",
|
url: "data/jsonp.php?callback=?",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
success: function(data){
|
success: function(data){
|
||||||
ok( data.data, "JSON results returned (GET, url callback)" );
|
ok( data.data, "JSON results returned (GET, url callback)" );
|
||||||
plus();
|
plus();
|
||||||
|
@ -1151,6 +1155,7 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: "data/jsonp.php",
|
url: "data/jsonp.php",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
data: "callback=?",
|
data: "callback=?",
|
||||||
success: function(data){
|
success: function(data){
|
||||||
ok( data.data, "JSON results returned (GET, data callback)" );
|
ok( data.data, "JSON results returned (GET, data callback)" );
|
||||||
|
@ -1165,6 +1170,7 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: "data/jsonp.php?callback=??",
|
url: "data/jsonp.php?callback=??",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
success: function(data){
|
success: function(data){
|
||||||
ok( data.data, "JSON results returned (GET, url context-free callback)" );
|
ok( data.data, "JSON results returned (GET, url context-free callback)" );
|
||||||
plus();
|
plus();
|
||||||
|
@ -1178,6 +1184,7 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: "data/jsonp.php",
|
url: "data/jsonp.php",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
data: "callback=??",
|
data: "callback=??",
|
||||||
success: function(data){
|
success: function(data){
|
||||||
ok( data.data, "JSON results returned (GET, data context-free callback)" );
|
ok( data.data, "JSON results returned (GET, data context-free callback)" );
|
||||||
|
@ -1192,6 +1199,7 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: "data/jsonp.php/??",
|
url: "data/jsonp.php/??",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
success: function(data){
|
success: function(data){
|
||||||
ok( data.data, "JSON results returned (GET, REST-like)" );
|
ok( data.data, "JSON results returned (GET, REST-like)" );
|
||||||
plus();
|
plus();
|
||||||
|
@ -1205,6 +1213,7 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: "data/jsonp.php/???json=1",
|
url: "data/jsonp.php/???json=1",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
success: function(data){
|
success: function(data){
|
||||||
strictEqual( jQuery.type(data), "array", "JSON results returned (GET, REST-like with param)" );
|
strictEqual( jQuery.type(data), "array", "JSON results returned (GET, REST-like with param)" );
|
||||||
plus();
|
plus();
|
||||||
|
@ -1218,6 +1227,7 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: "data/jsonp.php",
|
url: "data/jsonp.php",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
data: {
|
data: {
|
||||||
callback: "?"
|
callback: "?"
|
||||||
},
|
},
|
||||||
|
@ -1234,6 +1244,7 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: "data/jsonp.php",
|
url: "data/jsonp.php",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
jsonp: "callback",
|
jsonp: "callback",
|
||||||
success: function(data){
|
success: function(data){
|
||||||
ok( data.data, "JSON results returned (GET, data obj callback)" );
|
ok( data.data, "JSON results returned (GET, data obj callback)" );
|
||||||
|
@ -1245,9 +1256,16 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.jsonpResults = function(data) {
|
||||||
|
ok( data.data, "JSON results returned (GET, custom callback function)" );
|
||||||
|
window.jsonpResults = undefined;
|
||||||
|
plus();
|
||||||
|
};
|
||||||
|
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: "data/jsonp.php",
|
url: "data/jsonp.php",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
jsonpCallback: "jsonpResults",
|
jsonpCallback: "jsonpResults",
|
||||||
success: function(data){
|
success: function(data){
|
||||||
ok( data.data, "JSON results returned (GET, custom callback name)" );
|
ok( data.data, "JSON results returned (GET, custom callback name)" );
|
||||||
|
@ -1263,6 +1281,7 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "data/jsonp.php",
|
url: "data/jsonp.php",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
success: function(data){
|
success: function(data){
|
||||||
ok( data.data, "JSON results returned (POST, no callback)" );
|
ok( data.data, "JSON results returned (POST, no callback)" );
|
||||||
plus();
|
plus();
|
||||||
|
@ -1278,6 +1297,7 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
url: "data/jsonp.php",
|
url: "data/jsonp.php",
|
||||||
data: "callback=?",
|
data: "callback=?",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
success: function(data){
|
success: function(data){
|
||||||
ok( data.data, "JSON results returned (POST, data callback)" );
|
ok( data.data, "JSON results returned (POST, data callback)" );
|
||||||
plus();
|
plus();
|
||||||
|
@ -1293,6 +1313,7 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
url: "data/jsonp.php",
|
url: "data/jsonp.php",
|
||||||
jsonp: "callback",
|
jsonp: "callback",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
success: function(data){
|
success: function(data){
|
||||||
ok( data.data, "JSON results returned (POST, data obj callback)" );
|
ok( data.data, "JSON results returned (POST, data obj callback)" );
|
||||||
plus();
|
plus();
|
||||||
|
@ -1307,93 +1328,35 @@ test("jQuery.ajax() - JSONP, Local", function() {
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: "data/jsonp.php",
|
url: "data/jsonp.php",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
crossDomain: crossDomain,
|
||||||
beforeSend: function(){
|
beforeSend: function(){
|
||||||
strictEqual( this.cache, false, "cache must be false on JSON request" );
|
strictEqual( this.cache, false, "cache must be false on JSON request" );
|
||||||
plus();
|
plus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test("jQuery.ajax() - JSONP - Custom JSONP Callback", function() {
|
|
||||||
expect(1);
|
|
||||||
stop();
|
|
||||||
|
|
||||||
window.jsonpResults = function(data) {
|
|
||||||
ok( data.data, "JSON results returned (GET, custom callback function)" );
|
|
||||||
window.jsonpResults = undefined;
|
|
||||||
start();
|
|
||||||
};
|
|
||||||
|
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: "data/jsonp.php",
|
url: "data/jsonp.php?callback=XXX",
|
||||||
dataType: "jsonp",
|
|
||||||
jsonpCallback: "jsonpResults"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("jQuery.ajax() - JSONP, Remote", function() {
|
|
||||||
expect(4);
|
|
||||||
|
|
||||||
var count = 0;
|
|
||||||
function plus(){ if ( ++count == 4 ) start(); }
|
|
||||||
|
|
||||||
var base = window.location.href.replace(/[^\/]*$/, "");
|
|
||||||
|
|
||||||
stop();
|
|
||||||
|
|
||||||
jQuery.ajax({
|
|
||||||
url: base + "data/jsonp.php",
|
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
|
jsonp: false,
|
||||||
|
jsonpCallback: "XXX",
|
||||||
|
crossDomain: crossDomain,
|
||||||
|
beforeSend: function() {
|
||||||
|
console.log( this.url );
|
||||||
|
},
|
||||||
success: function(data){
|
success: function(data){
|
||||||
ok( data.data, "JSON results returned (GET, no callback)" );
|
console.log(data);
|
||||||
|
ok( data.data, "JSON results returned (GET, custom callback name with no url manipulation)" );
|
||||||
plus();
|
plus();
|
||||||
},
|
},
|
||||||
error: function(data){
|
error: function(data){
|
||||||
ok( false, "Ajax error JSON (GET, no callback)" );
|
console.log(data);
|
||||||
|
ok( false, "Ajax error JSON (GET, custom callback name with no url manipulation)" );
|
||||||
plus();
|
plus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
jQuery.ajax({
|
|
||||||
url: base + "data/jsonp.php?callback=?",
|
|
||||||
dataType: "jsonp",
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
jQuery.ajax({
|
|
||||||
url: base + "data/jsonp.php",
|
|
||||||
dataType: "jsonp",
|
|
||||||
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: base + "data/jsonp.php",
|
|
||||||
dataType: "jsonp",
|
|
||||||
jsonp: "callback",
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue