Bug 1087944 - Test for the promise returned by OfflineAudioContext.startRendering(). r=ehsan

--HG--
extra : rebase_source : 351f66c2cd7f2c269d7f2c05214d0f291488cf23
This commit is contained in:
Paul Adenot 2014-11-19 18:18:24 +01:00
parent a1aac031b9
commit 9c2b18c89e

View File

@ -10,6 +10,17 @@
<pre id="test">
<script class="testbody" type="text/javascript">
var renderedBuffer = null;
function setOrCompareRenderedBuffer(aRenderedBuffer) {
if (renderedBuffer) {
is(renderedBuffer, aRenderedBuffer, "Rendered buffers from the event and the promise should be the same");
SimpleTest.finish();
} else {
renderedBuffer = aRenderedBuffer;
}
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
var ctx = new OfflineAudioContext(2, 100, 22050);
@ -47,18 +58,31 @@ addLoadEvent(function() {
src.buffer = buf;
src.start(0);
src.connect(ctx.destination);
ctx.startRendering();
ctx.addEventListener("complete", function(e) {
ok(e instanceof OfflineAudioCompletionEvent, "Correct event received");
is(e.renderedBuffer.numberOfChannels, 2, "Correct expected number of buffers");
ok(renderedBuffer != null, "The event should be fired after the promise callback.");
expectNoException(function() {
ctx.startRendering().then(function() {
ok(false, "Promise should not resolve when startRendering is called a second time on an OfflineAudioContext")
}).catch(function(err) {
ok(true, "Promise should reject when startRendering is called a second time on an OfflineAudioContext")
});
});
compareBuffers(e.renderedBuffer, buf);
setOrCompareRenderedBuffer(e.renderedBuffer);
expectException(function() {
ctx.startRendering();
}, DOMException.INVALID_STATE_ERR);
SimpleTest.finish();
}, false);
expectNoException(function() {
ctx.startRendering().then(function(b) {
is(renderedBuffer, null, "The promise callback should be called first.");
setOrCompareRenderedBuffer(b);
}).catch(function (error) {
ok(false, "The promise from OfflineAudioContext.startRendering should never be rejected");
});
});
});
</script>