Kick jsonp - fixes #2682
This commit is contained in:
parent
efdb563fa5
commit
716d1e1804
16 changed files with 8 additions and 362 deletions
|
|
@ -98,75 +98,4 @@ o.spec("xhrMock", function() {
|
|||
o(xhr.getRequestHeader("Content-Type")).equals("foo, bar")
|
||||
})
|
||||
})
|
||||
o.spec("jsonp", function() {
|
||||
o("works", function(done) {
|
||||
$window.$defineRoutes({
|
||||
"GET /test": function(request) {
|
||||
var queryData = parseQueryString(request.query)
|
||||
return {status: 200, responseText: queryData["callback"] + "(" + JSON.stringify({a: 1}) + ")"}
|
||||
}
|
||||
})
|
||||
|
||||
$window["cb"] = finish
|
||||
|
||||
var script = $window.document.createElement("script")
|
||||
script.src = "/test?callback=cb"
|
||||
$window.document.documentElement.appendChild(script)
|
||||
|
||||
function finish(data) {
|
||||
o(data).deepEquals({a: 1})
|
||||
done()
|
||||
}
|
||||
})
|
||||
o("works w/ custom callback key", function(done) {
|
||||
$window.$defineRoutes({
|
||||
"GET /test": function(request) {
|
||||
var queryData = parseQueryString(request.query)
|
||||
return {status: 200, responseText: queryData["cb"] + "(" + JSON.stringify({a: 2}) + ")"}
|
||||
}
|
||||
})
|
||||
$window.$defineJSONPCallbackKey("cb")
|
||||
|
||||
$window["customcb"] = finish2
|
||||
|
||||
var script = $window.document.createElement("script")
|
||||
script.src = "/test?cb=customcb"
|
||||
$window.document.documentElement.appendChild(script)
|
||||
|
||||
function finish2(data) {
|
||||
o(data).deepEquals({a: 2})
|
||||
done()
|
||||
}
|
||||
})
|
||||
o("works with other querystring params", function(done) {
|
||||
$window.$defineRoutes({
|
||||
"GET /test": function(request) {
|
||||
var queryData = parseQueryString(request.query)
|
||||
return {status: 200, responseText: queryData["callback"] + "(" + JSON.stringify({a: 3}) + ")"}
|
||||
}
|
||||
})
|
||||
|
||||
$window["cbwithinparams"] = finish
|
||||
|
||||
var script = $window.document.createElement("script")
|
||||
script.src = "/test?a=b&callback=cbwithinparams&c=d"
|
||||
$window.document.documentElement.appendChild(script)
|
||||
|
||||
function finish(data) {
|
||||
o(data).deepEquals({a: 3})
|
||||
done()
|
||||
}
|
||||
})
|
||||
o("handles error", function(done) {
|
||||
var script = $window.document.createElement("script")
|
||||
script.onerror = finish
|
||||
script.src = "/test?cb=nonexistent"
|
||||
$window.document.documentElement.appendChild(script)
|
||||
|
||||
function finish(e) {
|
||||
o(e.type).equals("error")
|
||||
done()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue