updating Draw tests

now testing correct synchronization with AudioContext.currentTime
This commit is contained in:
Yotam Mann 2018-04-25 11:50:37 -04:00
parent 5e0a2285b4
commit dd9135033e

View file

@ -1,67 +1,66 @@
define(["Test", "Tone/core/Draw", "Tone/core/Tone", "helper/Supports"],
function (Test, Draw, Tone, Supports) {
define(["Test", "Tone/core/Draw", "Tone/core/Tone", "helper/Supports"], function(Test, Draw, Tone, Supports){
describe("Draw", function(){
describe("Draw", function(){
if (Supports.ONLINE_TESTING){
if (Supports.ONLINE_TESTING){
it("can schedule a callback at a AudioContext time", function(done){
var scheduledTime = Tone.now() + 0.2;
Draw.schedule(function(){
expect(Tone.now()).to.be.closeTo(scheduledTime, 0.05);
done();
}, scheduledTime);
});
it("can schedule a callback at a AudioContext time", function(done){
var scheduledTime = Tone.now() + 0.2;
Draw.schedule(function(){
expect(Tone.context.currentTime).to.be.closeTo(scheduledTime, 0.05);
done();
}, scheduledTime);
});
it("can schedule multiple callbacks", function(done){
var callbackCount = 0;
var firstEvent = Tone.now() + 0.1;
Draw.schedule(function(){
callbackCount++;
expect(Tone.now()).to.be.closeTo(firstEvent, 0.05);
}, firstEvent);
it("can schedule multiple callbacks", function(done){
var callbackCount = 0;
var firstEvent = Tone.now() + 0.1;
Draw.schedule(function(){
callbackCount++;
expect(Tone.context.currentTime).to.be.closeTo(firstEvent, 0.05);
}, firstEvent);
var thirdEvent = Tone.now() + 0.3;
Draw.schedule(function(){
callbackCount++;
expect(Tone.now()).to.be.closeTo(thirdEvent, 0.05);
expect(callbackCount).to.equal(3);
done();
}, thirdEvent);
var thirdEvent = Tone.now() + 0.3;
Draw.schedule(function(){
callbackCount++;
expect(Tone.context.currentTime).to.be.closeTo(thirdEvent, 0.05);
expect(callbackCount).to.equal(3);
done();
}, thirdEvent);
var secondEvent = Tone.now() + 0.2;
Draw.schedule(function(){
callbackCount++;
expect(Tone.now()).to.be.closeTo(secondEvent, 0.05);
}, secondEvent);
});
var secondEvent = Tone.now() + 0.2;
Draw.schedule(function(){
callbackCount++;
expect(Tone.context.currentTime).to.be.closeTo(secondEvent, 0.05);
}, secondEvent);
});
it("can cancel scheduled events", function(done){
var callbackCount = 0;
Draw.schedule(function(){
callbackCount++;
}, Tone.now() + 0.1);
it("can cancel scheduled events", function(done){
var callbackCount = 0;
Draw.schedule(function(){
callbackCount++;
}, Tone.now() + 0.1);
Draw.schedule(function(){
throw new Error("should not call this method");
}, Tone.now() + 0.2);
Draw.schedule(function(){
throw new Error("should not call this method");
}, Tone.now() + 0.2);
Draw.schedule(function(){
throw new Error("should not call this method");
}, Tone.now() + 0.25);
Draw.schedule(function(){
throw new Error("should not call this method");
}, Tone.now() + 0.25);
//cancel the second and third events
Draw.cancel(Tone.now() + 0.15);
//cancel the second and third events
Draw.cancel(Tone.now() + 0.15);
//schedule another one after
Draw.schedule(function(){
callbackCount++;
expect(callbackCount).to.equal(2);
done();
}, Tone.now() + 0.3);
//schedule another one after
Draw.schedule(function(){
callbackCount++;
expect(callbackCount).to.equal(2);
done();
}, Tone.now() + 0.3);
});
}
});
}
});
});
});