Bug 836599 - Part 13: Add a unit test for OfflineAudioContext; r=roc

This commit is contained in:
Ehsan Akhgari 2013-05-16 19:31:08 -04:00
parent d2c63bc836
commit 30c4151889
2 changed files with 46 additions and 0 deletions

View File

@ -58,6 +58,7 @@ MOCHITEST_FILES := \
test_mediaDecoding.html \
test_mixingRules.html \
test_nodeToParamConnection.html \
test_OfflineAudioContext.html \
test_pannerNode.html \
test_scriptProcessorNode.html \
test_scriptProcessorNodeChannelCount.html \

View File

@ -0,0 +1,45 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test OfflineAudioContext</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="webaudio.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
SpecialPowers.setBoolPref("media.webaudio.enabled", true);
var ctx = new OfflineAudioContext(2, 100, (new AudioContext()).sampleRate);
ok(ctx instanceof EventTarget, "OfflineAudioContexts must be EventTargets");
var buf = ctx.createBuffer(2, 100, ctx.sampleRate);
for (var i = 0; i < 2; ++i) {
for (var j = 0; j < 100; ++j) {
buf.getChannelData(i)[j] = Math.sin(2 * Math.PI * 200 * j / ctx.sampleRate);
}
}
var src = ctx.createBufferSource();
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");
compareBuffers(e.renderedBuffer.getChannelData(0), buf.getChannelData(0));
compareBuffers(e.renderedBuffer.getChannelData(1), buf.getChannelData(1));
SpecialPowers.clearUserPref("media.webaudio.enabled");
SimpleTest.finish();
}, false);
});
</script>
</pre>
</body>
</html>