testsuite.js revision b40f5113b5f28daabc29b6ad49c905f290cf6cb7
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathrightvar suite = new Y.Test.Suite("Y.AsyncQueue");
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright// FIXME: remove this and update the tests to handle the asynchronicity
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathrightfunction f() {}
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright Y.Assert.areSame(true, basic instanceof Y.AsyncQueue);
06c1e33a270f80929bf9b9dde81f4061d1949fffDerek Gathright Y.Assert.areSame(f, withCallbacks.next().fn);
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright test_next : function () {
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright function inc() { i++; }
06c1e33a270f80929bf9b9dde81f4061d1949fffDerek Gathright test_chaining : function () {
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo var q = new Y.AsyncQueue();
06c1e33a270f80929bf9b9dde81f4061d1949fffDerek Gathright Y.Assert.areSame(q, q.add(f,f,{fn:f,id:'a'},"garbage"));
06c1e33a270f80929bf9b9dde81f4061d1949fffDerek Gathright test_add : function () {
06c1e33a270f80929bf9b9dde81f4061d1949fffDerek Gathright var q = new Y.AsyncQueue(f);
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright q.add("Only functions and objects are allowed",
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright q.add({},{}); // empty objects are ok, since config can be defaulted
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright // Add from within a callback
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright function x() {
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright // Three x calls scheduled. A fourth added during a callback
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright q = new Y.AsyncQueue(x,f,x,addToQueue,f,x).run();
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright test_remove : function () {
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright function () {
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright fn: function () {
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright function () {
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright Y.Assert.fail("Expected 3, got " + q.size() + " - remove(n) should defer until callback completion");
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright fn: function () {
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright Y.Assert.fail("This callback should have been removed");
06c1e33a270f80929bf9b9dde81f4061d1949fffDerek Gathright function () {
06c1e33a270f80929bf9b9dde81f4061d1949fffDerek Gathright function () {
293b35d70157aeec052a53d4a3ecf875cb7c358bDerek Gathright function X() {
293b35d70157aeec052a53d4a3ecf875cb7c358bDerek Gathright // Removal when the Queue is inactive is immediate
a22e94e50e241a5ae089c072604fec309a0db44eDerek Gathright test_promote : function () {
6ba8d3cf563f904d8a71f8408553c2a10431ea7dDerek Gathright function O() {
a22e94e50e241a5ae089c072604fec309a0db44eDerek Gathright function () {
293b35d70157aeec052a53d4a3ecf875cb7c358bDerek Gathright fn: function () {
293b35d70157aeec052a53d4a3ecf875cb7c358bDerek Gathright } else if (!this.count) {
293b35d70157aeec052a53d4a3ecf875cb7c358bDerek Gathright fn : function () {
293b35d70157aeec052a53d4a3ecf875cb7c358bDerek Gathright function () {
a22e94e50e241a5ae089c072604fec309a0db44eDerek Gathright test_pause : function () {
a22e94e50e241a5ae089c072604fec309a0db44eDerek Gathright fn: function () {
a22e94e50e241a5ae089c072604fec309a0db44eDerek Gathright function () {
a22e94e50e241a5ae089c072604fec309a0db44eDerek Gathright function () {
a22e94e50e241a5ae089c072604fec309a0db44eDerek Gathright function () {
a22e94e50e241a5ae089c072604fec309a0db44eDerek Gathright // Test during timeout
a22e94e50e241a5ae089c072604fec309a0db44eDerek Gathright test_stop : function () {
a22e94e50e241a5ae089c072604fec309a0db44eDerek Gathright fn: function () {
a22e94e50e241a5ae089c072604fec309a0db44eDerek Gathright Y.Assert.fail("Synchronous q.stop() should have cleared this async callback");
setTimeout(function () {
q.run();
this.wait();
test_getCallback : function () {
q = new Y.AsyncQueue(
this.pause();
fn: function () {
q.run();
q.run();
test_isRunning : function () {
var self = this,
q = new Y.AsyncQueue(
fn: function () {
q.pause();
q.run();
this.wait();
test_fn : function () {
q = new Y.AsyncQueue(
q.run();
test_context : function () {
fn : function () {
fn: function () {
fn: function () {
q.run();
test_args : function () {
(new Y.AsyncQueue(
fn: function () {
fn: function () {
})).run();
test_iterations : function () {
self = this;
(new Y.AsyncQueue(
{ fn: function () {
})).run();
this.wait();
test_until : function () {
self = this;
(new Y.AsyncQueue(
fn: function () {
until: function () {
return !this.data;
fn: function () {
until: function () {
{ fn: function () {
})).run();
this.wait();
test_timeout : function () {
self = this,
q = new Y.AsyncQueue(
until: function () {
}).run();
this.wait();
var url = 'queue.html?cachebuster='+Y.guid();
test_events : function () {
var results = [],
self = this,
q = new Y.AsyncQueue(
fn: function () {
on : {
failure : function () {
waitForIOResponse : true
setTimeout(function () {
q.run();
], results);
q.run();
this.wait();
test_preventCallback : function () {
function inc () { i++; }
foo: true,
until : function () {
e.preventDefault();
q.run();
e.preventDefault();
q.run();