Tone.js/test/examples/Examples.js

66 lines
1.4 KiB
JavaScript
Raw Normal View History

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