Tone.js/test/examples/Examples.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-03-26 18:51:25 +00:00
define(["Test", "Examples"], function (Test, Examples) {
var baseUrl = "../examples/";
if (window.__karma__){
2017-03-26 19:21:45 +00:00
baseUrl = "/base/examples/";
2017-03-26 18:51:25 +00:00
}
2017-03-26 19:21:45 +00:00
function getIframeError(url){
return new Promise(function(success, error){
2017-03-26 18:51:25 +00:00
var iframe = document.createElement("iframe");
iframe.onload = function(){
iframe.remove();
2017-03-26 19:21:45 +00:00
success();
2017-03-26 18:51:25 +00:00
};
iframe.width = 1;
iframe.height = 1;
2017-03-26 19:21:45 +00:00
iframe.src = url;
2017-03-26 18:51:25 +00:00
document.body.appendChild(iframe);
//capture the error
iframe.contentWindow.onerror=function(e) {
2017-03-26 19:21:45 +00:00
error(e);
};
});
}
function createTest(url){
it (url, function(){
url = baseUrl + url + ".html";
return testUrl(url).then(getIframeError);
});
}
function testUrl(url){
return new Promise(function(success, fail){
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200) {
success(url);
} else {
fail("404: "+url);
}
}
2017-03-26 18:51:25 +00:00
};
2017-03-26 19:21:45 +00:00
httpRequest.open("GET", url);
httpRequest.send();
2017-03-26 18:51:25 +00:00
});
}
context("Examples", function(){
for (var category in Examples){
var group = Examples[category];
for (var name in group){
var url = group[name];
createTest(url);
}
}
});
});