get-test.js revision e39c414a16a84ae05bd82feec9357e64fc1dc012
var ArrayAssert = Y.ArrayAssert,
ObjectAssert = Y.ObjectAssert,
supports = {
// True if this browser should call an onFailure callback on a link
// that 404s. Currently only Firefox 9+ supports this.
// True if this browser should call an onFailure callback on a
// script that 404s.
jsFailure: !((ua.ie && ua.ie < 9) || (ua.opera && ua.opera < 11.6) || (ua.webkit && ua.webkit < 530.17))
};
}
}
if (typeof urls === "string") {
} else {
}
}
return urls;
}
// -- Basic JS loading -----------------------------------------------------
name: "Basic JS loading",
setUp: function() {
G_SCRIPTS = [];
},
tearDown: function() {
if (this.o) {
this.o.purge();
}
this.removeInsertBeforeNode();
},
createInsertBeforeNode: function() {
},
removeInsertBeforeNode: function() {
if (this.ib) {
}
},
_should: {
ignore: {
}
},
'test: single script, success': function() {
var test = this;
var progress = [];
var counts = {
success:0,
failure:0
};
onProgress: function(o) {
},
onSuccess: function(o) {
var context = this;
test.o = o;
});
},
onFailure: function(o) {
test.o = o;
});
}
});
this.wait();
},
'test: single script, failure': function() {
var test = this;
var counts = {
success:0,
failure:0
};
onSuccess: function(o) {
test.o = o;
});
},
onFailure: function(o) {
var context = this;
test.o = o;
});
}
});
this.wait();
},
'test: single script timeout callback': function() {
var test = this;
timeout: 1,
onTimeout: function(e) {
},
onFailure: function(e) {
},
onSuccess: function() {
}
});
},
'test: single script success, end': function() {
var test = this;
var counts = {
success:0,
failure:0,
end:0
};
onSuccess: function() {
},
onFailure: function() {
},
onEnd: function(o) {
var context = this;
test.o = o;
});
}
});
this.wait();
},
'test: single script failure, end': function() {
var test = this;
var counts = {
success:0,
failure:0,
end:0
};
onFailure: function() {
},
onSuccess: function() {
},
onEnd : function(o) {
var context = this;
test.o = o;
});
}
});
this.wait();
},
'test: multiple scripts, success': function() {
var test = this;
var progress = [];
var counts = {
success:0,
failure:0
};
onFailure: function(o) {
test.o = o;
});
},
onProgress: function(o) {
},
onSuccess: function(o) {
var context = this;
test.o = o;
});
}
});
this.wait();
},
'test: multiple scripts, one failure': function() {
var test = this;
var counts = {
success:0,
failure:0
};
onSuccess: function(o) {
test.o = o;
});
},
onFailure: function(o) {
var context = this;
test.o = o;
});
}
});
this.wait();
},
'test: multiple scripts, success, end': function() {
var test = this;
var progress = [];
var counts = {
success:0,
failure:0,
end:0
};
onSuccess: function() {
},
onProgress: function(o) {
},
onFailure: function() {
},
onEnd: function(o) {
var context = this;
test.o = o;
});
}
});
this.wait();
},
'test: multiple scripts, failure, end': function() {
var test = this;
var counts = {
success:0,
failure:0,
end:0
};
onSuccess: function() {
},
onFailure: function() {
},
onEnd: function(o) {
var context = this;
test.o = o;
});
}
});
this.wait();
},
'test: async multiple scripts, success': function() {
var test = this;
var progress = [];
var counts = {
success:0,
failure:0
};
onFailure: function(o) {
test.o = o;
});
},
onProgress: function(o) {
},
onSuccess: function(o) {
var context = this;
test.o = o;
});
},
async:true
});
this.wait();
},
'test: async multiple scripts, success, end': function() {
var test = this;
var counts = {
success:0,
failure:0,
end:0
};
onSuccess: function() {
},
onFailure: function() {
},
onEnd: function(o) {
var context = this;
test.o = o;
});
},
async:true
});
this.wait();
},
// THE ASYNC FAILURE TESTS NEED TO BE AT THE END,
// BECAUSE ABORTING THEM WILL NOT STOP PARALLEL SCRIPTS
// FROM DOWNLOADING (at least currently) AND SINCE WE USE
// A GLOBAL, IT POLLUTES THE NEXT SUCCESS TEST
// TODO: Maybe we can explore the idea of moving from global to something instance based?
'test: async multiple script, failure': function() {
var test = this;
var counts = {
success:0,
failure:0
};
onSuccess: function(o) {
test.o = o;
});
},
onFailure: function(o) {
var context = this;
test.o = o;
});
},
async:true
});
this.wait();
},
'test: async multiple script, failure, end': function() {
var test = this;
var counts = {
success:0,
failure:0,
end:0
};
onSuccess: function() {
},
onFailure: function() {
},
onEnd: function(o) {
var context = this;
test.o = o;
});
},
async:true
});
this.wait();
},
'test: insertBefore, single' : function() {
var test = this;
insertBefore: "insertBeforeMe",
onSuccess: function(o) {
test.o = o;
});
},
onFailure: function(o) {
test.o = o;
});
}
});
this.wait();
},
'test: insertBefore, multiple' : function() {
var test = this;
insertBefore: "insertBeforeMe",
onSuccess: function(o) {
insertBefore = n;
}
test.o = o;
});
},
onFailure: function(o) {
test.o = o;
});
}
});
this.wait();
},
'test: async, insertBefore, multiple' : function() {
var test = this;
insertBefore: "insertBeforeMe",
onSuccess: function(o) {
insertBefore = n;
}
test.o = o;
});
},
onFailure: function(o) {
test.o = o;
});
},
async:true
});
this.wait();
},
'test: charset, single' : function() {
var test = this;
charset: "ISO-8859-1",
onSuccess: function(o) {
test.o = o;
});
},
onFailure: function(o) {
test.o = o;
});
}
});
this.wait();
},
'test: charset, multiple' : function() {
var test = this;
charset: "ISO-8859-1",
onSuccess: function(o) {
}
test.o = o;
});
},
onFailure: function(o) {
test.o = o;
});
}
});
this.wait();
},
'test: async, charset, multiple' : function() {
var test = this;
charset: "ISO-8859-1",
onSuccess: function(o) {
}
test.o = o;
});
},
onFailure: function(o) {
test.o = o;
});
},
async :true
});
this.wait();
},
'test: attributes, single' : function() {
var test = this;
attributes: {
"charset": "ISO-8859-1",
"title" : "myscripts",
"id" : "my-awesome-script"
},
onSuccess: function(o) {
test.o = o;
});
},
onFailure: function(o) {
test.o = o;
});
}
});
this.wait();
},
'test: attributes, multiple' : function() {
var test = this;
attributes: {
"charset": "ISO-8859-1",
"title" : "myscripts"
},
onSuccess: function(o) {
}
test.o = o;
});
},
onFailure: function(o) {
test.o = o;
});
}
});
this.wait();
},
'test: async, attributes, multiple' : function() {
var test = this;
attributes: {
"charset": "ISO-8859-1",
"title" : "myscripts"
},
onSuccess: function(o) {
}
test.o = o;
});
},
onFailure: function(o) {
test.o = o;
});
},
async :true
});
this.wait();
},
'ignore: abort' : function() {
// Covered above, but worth testing payload also
},
'ignore: timeout' : function() {
// Need delay.js always available to test this reliably. Leaving out for now
},
'scripts should be automatically purged after 20 nodes by default': function () {
var test = this,
urls = [],
i;
for (i = 0; i < 30; ++i) {
}
Y.assert(count > 0 && count < 20, 'there should be fewer than 20 scripts on the page (actual: ' + count + ')');
});
});
this.wait();
},
'test: purgethreshold' : function() {
var test = this;
var nodes = [];
var nodeIds = [];
// Purge only happens at the start of a queue call.
onSuccess: function(o) {
onSuccess: function(o) {
// Convert to id, for final doc check, because purge destroys parentNode
}
purgethreshold: 1,
onSuccess: function(o) {
Assert.isNull(document.getElementById(nodeIds[i]), "Script from previous transaction was not purged");
}
test.o = o;
});
}
});
}
});
}
});
this.wait();
}
});
// -- Basic CSS loading ----------------------------------------------------
name: "Basic CSS loading",
setUp: function() {
},
tearDown: function() {
this.o && this.o.purge();
this.removeInsertBeforeNode();
},
_should: {
ignore: {
}
},
createInsertBeforeNode: function() {
this.ib = Y.Node.create('<link id="insertBeforeMe" href="' + path("ib.css?delay=0") + '" rel="stylesheet" type="text/css" charset="utf-8">');
},
removeInsertBeforeNode: function() {
if (this.ib) {
}
},
'test: single css, success': function() {
var test = this;
var counts = {
success:0,
failure:0
};
onSuccess: function(o) {
var context = this;
test.o = o;
});
},
onFailure: function(o) {
}
});
},
'test: multiple css, success': function() {
var test = this;
var counts = {
success:0,
failure:0
};
onFailure: function(o) {
});
},
onSuccess: function(o) {
var context = this;
test.o = o;
});
}
});
},
'test: insertBefore, single' : function() {
var test = this;
insertBefore: "insertBeforeMe",
onSuccess: function(o) {
// TODO: These don't work as expected on IE (even though insertBefore worked). Better cross-browser assertion?
Assert.areEqual("9991", this.na.getComputedStyle("zIndex"), "a.css does not seem to be inserted before ib.css");
}
test.o = o;
});
}
});
},
'test: insertBefore, multiple' : function() {
var test = this;
insertBefore: "insertBeforeMe",
onSuccess: function(o) {
insertBefore = n;
}
// TODO: These don't work as expected on IE (even though insertBefore worked). Better cross-browser assertion?
Assert.areEqual("9991", this.na.getComputedStyle("zIndex"), "a.css does not seem to be inserted before ib.css");
Assert.areEqual("9992", this.nb.getComputedStyle("zIndex"), "b.css does not seem to be inserted before ib.css");
Assert.areEqual("9993", this.nc.getComputedStyle("zIndex"), "c.css does not seem to be inserted before ib.css");
}
test.o = o;
});
}
});
},
'test: charset, single' : function() {
var test = this;
charset: "ISO-8859-1",
onSuccess: function(o) {
test.o = o;
});
}
});
},
'test: charset, multiple' : function() {
var test = this;
charset: "ISO-8859-1",
onSuccess: function(o) {
}
test.o = o;
});
}
});
},
'test: attributes, single' : function() {
var test = this;
attributes: {
"charset": "ISO-8859-1",
"title": "myscripts"
},
onSuccess: function(o) {
test.o = o;
});
}
});
},
'test: attributes, multiple' : function() {
var test = this;
attributes: {
"charset": "ISO-8859-1",
"title": "myscripts"
},
onSuccess: function(o) {
}
test.o = o;
});
}
});
},
'test: single css, failure': function() {
var test = this;
var counts = {
success:0,
failure:0
};
onSuccess: function(o) {
});
},
onFailure: function(o) {
});
},
onEnd: function(o) {
test.o = o;
}
});
},
'test: multiple css, failure': function() {
var test = this;
var counts = {
success:0,
failure:0
};
onSuccess: function(o) {
});
},
onFailure: function(o) {
Assert.areNotEqual("1234", this.nb.getComputedStyle("zIndex"), "b.css was loaded when it shouldn't have been");
}
test.o = o;
});
},
onEnd: function(o) {
test.o = o;
}
});
this.wait();
},
'CSS nodes should be inserted in order': function () {
var test = this;
], function (err, transaction) {
Assert.areEqual('b', Y.one(nodes[0]).next('link,style').get('id'), 'b.css should have been inserted after a.css');
Assert.areEqual('c', Y.one(nodes[1]).next('link,style').get('id'), 'b.css should have been inserted after a.css');
});
});
this.wait();
}
});
// -- Y.Get Methods --------------------------------------------------------
name: 'Y.Get methods',
tearDown: function () {
this.t && this.t.purge();
},
'abort() should abort a transaction when given a transaction object': function () {
var test = this;
onFailure: function () {
});
},
onProgress: function () {
},
onSuccess: function () {
});
}
});
},
'abort() should abort a transaction when given a transaction id': function () {
var test = this;
onFailure: function () {
});
},
onProgress: function () {
},
onSuccess: function () {
});
}
});
this.wait();
},
// -- css() ------------------------------------------------------------
'css() should accept a URL': function () {
var test = this,
setTimeout(function () {
}, 1);
// Silly hack so we can verify that the CSS request finished without
// having to pass a callback to Y.Get.css().
var t = test.t;
return;
}
}
}, 20);
this.wait();
},
'css() should accept a URL, options object, and callback function': function () {
var test = this,
onFailure: function () {
});
},
onSuccess: function () {
});
}
}, function (err, transaction) {
var self = this;
callbackCalled = true;
});
});
this.wait();
},
'css() should allow the callback function as the second parameter': function () {
var test = this;
var self = this;
});
});
this.wait();
},
'css() should accept an array of URLs': function () {
var test = this;
onFailure: function () {
});
},
onSuccess: function () {
});
}
});
this.wait();
},
'css() should accept a request object': function () {
var test = this;
onFailure: function () {
});
},
onSuccess: function () {
});
}
});
this.wait();
},
'css() should accept an array of request objects': function () {
var test = this;
onFailure: function () {
});
},
onSuccess: function () {
});
}
});
this.wait();
},
'css() should accept a mixed array of URLs and request objects': function () {
var test = this;
onFailure: function () {
});
},
onSuccess: function () {
});
}
});
this.wait();
},
// -- js() -------------------------------------------------------------
'js() should accept a URL': function () {
var test = this,
setTimeout(function () {
}, 1);
// Silly hack so we can verify that the request finished without
// having to pass a callback to Y.Get.js().
var t = test.t;
return;
}
}
}, 20);
this.wait();
},
'js() should accept a URL, options object, and callback function': function () {
var test = this,
onFailure: function () {
});
},
onSuccess: function () {
});
}
}, function (err, transaction) {
var self = this;
callbackCalled = true;
});
});
this.wait();
},
'js() should allow the callback function as the second parameter': function () {
var test = this;
var self = this;
});
});
this.wait();
},
'js() should accept an array of URLs': function () {
var test = this;
onFailure: function () {
});
},
onSuccess: function () {
});
}
});
this.wait();
},
'js() should accept a request object': function () {
var test = this;
onFailure: function () {
});
},
onSuccess: function () {
});
}
});
this.wait();
},
'js() should accept an array of request objects': function () {
var test = this;
onFailure: function () {
});
},
onSuccess: function () {
});
}
});
this.wait();
},
'js() should accept a mixed array of URLs and request objects': function () {
var test = this;
onFailure: function () {
});
},
onSuccess: function () {
});
}
});
this.wait();
},
// -- load() -----------------------------------------------------------
'load() should accept a URL': function () {
var test = this,
setTimeout(function () {
}, 1);
// Silly hack so we can verify that the request finished without
// having to pass a callback to Y.Get.load().
var t = test.t;
return;
}
});
}
}, 20);
this.wait();
},
'load() should accept a URL, options object, and callback function': function () {
var test = this,
onFailure: function () {
});
},
onSuccess: function () {
});
}
}, function (err, transaction) {
var self = this;
callbackCalled = true;
});
});
this.wait();
},
'load() should allow the callback function as the second parameter': function () {
var test = this;
var self = this;
});
});
this.wait();
},
'load() should accept an array of URLs': function () {
var test = this;
onFailure: function () {
});
},
onSuccess: function () {
});
}
});
this.wait();
},
'load() should accept a request object': function () {
var test = this;
onFailure: function () {
});
},
onSuccess: function () {
});
}
});
this.wait();
},
'load() should accept an array of request objects': function () {
var test = this;
onFailure: function () {
});
},
onSuccess: function () {
});
}
});
this.wait();
},
'load() should accept a mixed array of URLs and request objects': function () {
var test = this;
onFailure: function () {
});
},
onSuccess: function () {
});
}
});
this.wait();
},
// -- script() ---------------------------------------------------------
'script() should be an alias for js()': function () {
}
});
// -- Y.Get.Transaction behavior -------------------------------------------
name: 'Transaction behavior',
'transactions should always execute one at a time by default': function () {
var test = this,
// This has to be a >= comparison or it'll fail on Windows due to IE's
// low-res timer.
Assert.isTrue(t2.finish >= t1.finish, "transaction 2 shouldn't start before transaction 1 finishes");
Assert.isTrue(t3.finish >= t2.finish, "transaction 3 shouldn't start before transaction 2 finishes");
});
});
}
this.wait();
}
});
// -- Y.Get.Transaction methods --------------------------------------------
name: 'Transaction methods',
tearDown: function () {
this.t && this.t.purge();
},
'abort() should abort the transaction': function () {
var test = this;
onFailure: function () {
});
},
onProgress: function () {
},
onSuccess: function () {
});
}
});
},
'abort() should accept a custom error message': function () {
var test = this;
onFailure: function () {
}, test.t.errors, "Transaction failed, but wasn't aborted (or was aborted with the wrong error message).");
});
},
onProgress: function () {
},
onSuccess: function () {
});
}
});
},
'execute() should queue callbacks': function () {
var test = this,
callbackOne = true;
});
});
callbackTwo = true;
});
});
this.wait();
},
'execute() should call the callback immediately if the transaction has already finished': function () {
var test = this;
var callbackOne, callbackTwo;
callbackOne = true;
});
callbackTwo = true;
});
});
});
this.wait();
},
'purge() should purge any nodes inserted by the transaction': function () {
var test = this;
var ids = [];
});
t.purge();
});
});
});
}
});
// -- TODO: Y.Get.Transaction properties -----------------------------------------
name: 'Transaction properties',
tearDown: function () {
this.t && this.t.purge();
},
'transactions should have a unique `id` property': function () {
},
'transactions should have a `data` property when a data object is provided': function () {
var data = {};
},
'`errors` property should contain an array of error objects': function () {
var test = this;
}
});
});
this.wait();
},
'`nodes` property should contain an array of injected nodes': function () {
var test = this;
});
});
this.wait();
},
'`options` property should contain transaction options': function () {
data: 'foo',
bar: 'baz'
});
this.t.abort();
},
'`requests` property should contain an array of request objects': function () {
var test = this;
});
});
this.wait();
}
});
// -- TODO: Options --------------------------------------------------------------
name: 'Options'
});
// -- Functional tests -----------------------------------------------------
name: "Functional tests",
'test: Loader, ScrollView' : function() {
var test = this;
});
});
this.wait();
},
'test: Loader, Autocomplete' : function() {
var test = this;
});
});
this.wait();
}
});
}, '3.5.0', {
});