gecko/content/media/webaudio/test/test_AudioBuffer.html
Ehsan Akhgari f2d00f14f9 Bug 849230 follow-up: Fix expectException to actually check the exception code, and don't use imaginary DOMException names!
--HG--
extra : rebase_source : df53ddca50487bfc10676fd43e98abb949a2c298
2013-03-22 19:57:08 -04:00

54 lines
1.9 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test whether we can create an AudioContext interface</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script src="webaudio.js" type="text/javascript"></script>
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
SpecialPowers.setBoolPref("media.webaudio.enabled", true);
var context = new AudioContext();
var buffer = context.createBuffer(2, 2048, context.sampleRate);
SpecialPowers.gc(); // Make sure that our channels are accessible after GC
ok(buffer, "Buffer was allocated successfully");
is(buffer.sampleRate, context.sampleRate, "Correct sample rate");
is(buffer.length, 2048, "Correct length");
ok(Math.abs(buffer.duration - 2048 / context.sampleRate) < 0.0001, "Correct duration");
is(buffer.numberOfChannels, 2, "Correct number of channels");
for (var i = 0; i < buffer.numberOfChannels; ++i) {
var buf = buffer.getChannelData(i);
ok(buf, "Buffer index " + i + " exists");
ok(buf instanceof Float32Array, "Result is a typed array");
is(buf.length, buffer.length, "Correct length");
var foundNonZero = false;
for (var j = 0; j < buf.length; ++j) {
if (buf[j] != 0) {
foundNonZero = true;
break;
}
}
ok(!foundNonZero, "Buffer " + i + " should be initialized to 0");
}
expectException(function() {
context.createBuffer(2, 2048, 7999);
}, DOMException.SYNTAX_ERR);
expectException(function() {
context.createBuffer(2, 2048, 96001);
}, DOMException.SYNTAX_ERR);
context.createBuffer(2, 2048, 8000); // no exception
context.createBuffer(2, 2048, 96000); // no exception
SpecialPowers.clearUserPref("media.webaudio.enabled");
SimpleTest.finish();
});
</script>
</pre>
</body>
</html>