jsonp-tests.js revision 4bf418104a2c28d41ea15010e041ba1a245ca035
onScriptLoad = (function (s) {
s.onload = ';';
if (typeof s.onload === 'string') {
node.onreadystatechange = function () {
this.onreadystatechange = null;
callback();
}
};
};
} else {
this.onload = null;
callback();
};
};
}
s = null;
name: "send",
"config charset should be set via Y.Get.script": function () {
var test = this,
Y.jsonp("server/service.php?callback={callback}", function () {
Y.jsonp("server/service.php?callback={callback}", {
on: {
},
charset: "test charset"
});
})[0];
// to allow JSONP the chance to clean up the callback registry
// before other tests begin.
});
});
})[0];
// to allow JSONP the chance to clean up the callback registry before
// other tests begin.
}
}));
name : "callbacks",
_should: {
ignore: {
// Get (v3.3) doesn't support onerror in recent webkit
"failure handler in callback object should execute": true
}
},
"callback function as second arg should be success handler": function () {
var self = this;
//console.log(Y.Object.keys(YUI.Env.JSONP), "callback function as second arg should be success handler");
});
});
},
"success handler in callback object should execute": function () {
var self = this;
Y.jsonp("server/service.php?&callback={callback}", {
on: {
//console.log(Y.Object.keys(YUI.Env.JSONP), "success handler in callback object should execute");
});
}
}
});
},
"failure handler in callback object should execute": function () {
var self = this;
Y.jsonp("server/404.php?&callback={callback}", {
on: {
});
},
failure: function () {
//console.log("failure handler in callback object should execute");
// Pass
}
}
});
},
"failure handler in callback object should not execute for successful io": function () {
var self = this;
Y.jsonp("server/service.php?&callback={callback}", {
on: {
//console.log(Y.Object.keys(YUI.Env.JSONP), "failure handler in callback object should not execute for successful io");
// Pass
},
failure: function () {
});
}
}
});
},
"test multiple send() from an instance of Y.JSONPRequest": function () {
var self = this,
count = 0,
on: {
//console.log(Y.Object.keys(YUI.Env.JSONP), "test multiple send() from an instance of Y.JSONPRequest");
if (++count === 3) {
// Pass
});
}
}
}
});
this.wait();
}
// failure for bogus response data (not yet implemented)
// missing {callback} (not sure how to test. No callback would be attached.
// Maybe have the service create a property on YUI and have the test
// look for that after a time?)
// missing success handler (logs a warning)
// JSONPRequest + send
// JSONPRequest + send with config overrides (not yet implemented)
}));
name : "context and args"
}));
name : "format"
}));
name : "allowCache",
"allowCache should preserve the same callback": function () {
var test = this,
remaining = 2,
allowCache: true,
on: {
//console.log(Y.Object.keys(YUI.Env.JSONP), "allowCache should preserve the same callback");
if (callback) {
});
} else if (--remaining) {
} else {
// Pass
});
}
} else {
}
}
}
});
this.wait();
},
"allowCache should not clear proxy if another send() is pending response":
function () {
var test = this,
callbacks = [],
allowCache: true,
on: {
//console.log(Y.Object.keys(YUI.Env.JSONP), "allowCache should not clear proxy if another send() is pending response");
});
});
}
}
}
});
this.wait();
}
}));
name : "timeout",
"timeout should not flush the global proxy": function () {
var test = this,
timeoutCalled = false,
timeout: 1000,
on: {
//console.log(Y.Object.keys(YUI.Env.JSONP), "timeout should not flush the global proxy");
});
},
timeout: function () {
//console.log(Y.Object.keys(YUI.Env.JSONP), "timeout should not flush the global proxy (timeout)");
timeoutCalled = true;
}
}
}),
// Success is measured by the success callback NOT being executed,
// but we're in an async operation, so I need something to trigger
// a test.resume(..). So I'm finding the added script tag and
// hooking a separate onload handler to it, which would execute after
// the success handler if it is called due to callbacks executing in
// subscription order. Not pretty, but better than a longer setTimeout?
})[0];
onScriptLoad(newScript, function () {
});
});
}
/*
,
"timeout should not flush the global proxy across multiple send calls": function () {
// README
// Stubbed from the test above. This test needs to contact the
// serverat the same url, but get varying delays. This means to
// properly test, the server needs to behave randomly, and this test
// needs to iterate until that random behavior matches the expected
// test behavior. Which is icky.
var test = this,
timeoutCalled = false,
jsonp = new Y.JSONPRequest('server/service.php?wait=2&callback={callback}', {
timeout: 1000,
on: {
success: function (data) {
test.resume(function () {
Y.Assert.fail("Success callback executed after timeout");
});
},
timeout: function () {
timeoutCalled = true;
}
}
}),
scripts = Y.all('script')._nodes,
newScript;
jsonp.send();
newScript = Y.Array.filter(Y.all('script')._nodes, function (s) {
return Y.Array.indexOf(scripts, s) === -1;
})[0];
Y.on('load', function () {
test.resume(function () {
Y.Assert.isTrue(timeoutCalled);
});
}, newScript);
test.wait(3000);
}
*/
}));