mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
tests in HTML file
This commit is contained in:
parent
e0d19c96d2
commit
bb9a621cbc
4 changed files with 109 additions and 4 deletions
|
@ -28,6 +28,8 @@ module.exports = function(config){
|
|||
"test/test.js",
|
||||
{ pattern : "test/audio/*", included : false },
|
||||
{ pattern : "test/audio/*/*", included : false },
|
||||
{ pattern : "test/html/*", included : false },
|
||||
{ pattern : "build/*", included : false },
|
||||
],
|
||||
|
||||
// list of files to exclude
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
define(["helper/Test", "Tone/core/Context", "Tone/core/Tone", "helper/Offline", "helper/Supports"],
|
||||
function(Test, Context, Tone, Offline, Supports){
|
||||
define(["helper/Test", "Tone/core/Context", "Tone/core/Tone", "helper/Offline", "helper/Supports", "helper/LoadHTML"],
|
||||
function(Test, Context, Tone, Offline, Supports, LoadHTML){
|
||||
|
||||
describe("Context", function(){
|
||||
|
||||
|
@ -156,13 +156,16 @@ define(["helper/Test", "Tone/core/Context", "Tone/core/Tone", "helper/Offline",
|
|||
|
||||
context("Tone", function(){
|
||||
|
||||
var orignContext = Tone.context;
|
||||
|
||||
afterEach(function(){
|
||||
if (Tone.context.state !== "closed"){
|
||||
//reset the context
|
||||
if (Tone.context.state !== "closed" && Tone.context !== orignContext){
|
||||
//reset the context
|
||||
return Tone.context.dispose().then(function(){
|
||||
Tone.context = new Context();
|
||||
});
|
||||
}
|
||||
Tone.context = orignContext;
|
||||
});
|
||||
|
||||
it("has a context", function(){
|
||||
|
@ -172,6 +175,7 @@ define(["helper/Test", "Tone/core/Context", "Tone/core/Tone", "helper/Offline",
|
|||
|
||||
it("can set a new context", function(){
|
||||
Tone.context = new Context();
|
||||
return Tone.context.dispose();
|
||||
});
|
||||
|
||||
it("invokes the resume promise", function(){
|
||||
|
@ -201,6 +205,14 @@ define(["helper/Test", "Tone/core/Context", "Tone/core/Tone", "helper/Offline",
|
|||
Context.on("close", closeFn);
|
||||
Tone.context.dispose();
|
||||
});
|
||||
|
||||
it("can have two instances running on the same page", function(){
|
||||
var baseUrl = "../test/html/";
|
||||
if (window.__karma__){
|
||||
baseUrl = "/base/test/html/";
|
||||
}
|
||||
return LoadHTML(baseUrl + "same_context.html");
|
||||
});
|
||||
});
|
||||
|
||||
context("get/set", function(){
|
||||
|
|
53
test/helper/LoadHTML.js
Normal file
53
test/helper/LoadHTML.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
define(["Tone/core/Tone", "Tone/core/Offline", "helper/BufferTest", "Tone/core/Master"], function(Tone, Offline, BufferTest, Master){
|
||||
|
||||
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
|
||||
iframe.contentWindow.onerror=function(e){
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
httpRequest.open("GET", url);
|
||||
httpRequest.send();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} url
|
||||
* @return {Promise}
|
||||
*/
|
||||
return function(url){
|
||||
return testUrl(url).then(getIframeError);
|
||||
};
|
||||
});
|
38
test/html/same_context.html
Normal file
38
test/html/same_context.html
Normal file
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>TWO CONTEXTS RUNNING AT ONCE</title>
|
||||
<script src="../../build/Tone.js"></script>
|
||||
<script src="/base/build/Tone.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
function assert(statement, error){
|
||||
if (!statement){
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
if (Tone && Tone.context){
|
||||
Tone.context.thisisthesamecontext = true;
|
||||
assert(window.TONE_AUDIO_CONTEXT.thisisthesamecontext, "Did not assign global TONE_AUDIO_CONTEXT");
|
||||
} else {
|
||||
throw new Error("NO TONE!");
|
||||
}
|
||||
</script>
|
||||
|
||||
<script src="../../build/Tone.js"></script>
|
||||
<script src="/base/build/Tone.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
if (Tone){
|
||||
assert(window.TONE_AUDIO_CONTEXT === Tone.context, "Did not assign global TONE_AUDIO_CONTEXT 2");
|
||||
assert(Tone.context.thisisthesamecontext, "Not the same AudioContext");
|
||||
} else {
|
||||
throw new Error("NO TONE 2!");
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue