Tone.js/test/core/Draw.js

68 lines
1.7 KiB
JavaScript
Raw Normal View History

define(["Test", "Tone/core/Draw", "Tone/core/Tone", "helper/Supports"],
function (Test, Draw, Tone, Supports) {
2017-12-30 16:26:29 +00:00
describe("Draw", function(){
2017-12-30 16:26:29 +00:00
if (Supports.ONLINE_TESTING){
2017-12-30 16:26:29 +00:00
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);
});
2017-11-24 22:13:51 +00:00
2017-12-30 16:26:29 +00:00
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);
2017-11-24 22:13:51 +00:00
2017-12-30 16:26:29 +00:00
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);
2017-11-24 22:13:51 +00:00
2017-12-30 16:26:29 +00:00
var secondEvent = Tone.now() + 0.2;
Draw.schedule(function(){
callbackCount++;
expect(Tone.now()).to.be.closeTo(secondEvent, 0.05);
}, secondEvent);
});
2017-12-30 16:26:29 +00:00
it("can cancel scheduled events", function(done){
var callbackCount = 0;
Draw.schedule(function(){
callbackCount++;
}, Tone.now() + 0.1);
2017-12-30 16:26:29 +00:00
Draw.schedule(function(){
throw new Error("should not call this method");
}, Tone.now() + 0.2);
2017-12-30 16:26:29 +00:00
Draw.schedule(function(){
throw new Error("should not call this method");
}, Tone.now() + 0.25);
2017-12-30 16:26:29 +00:00
//cancel the second and third events
Draw.cancel(Tone.now() + 0.15);
2017-12-30 16:26:29 +00:00
//schedule another one after
Draw.schedule(function(){
callbackCount++;
expect(callbackCount).to.equal(2);
done();
}, Tone.now() + 0.3);
2017-12-30 16:26:29 +00:00
});
}
2017-12-30 16:26:29 +00:00
});
});