mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
57 lines
2.0 KiB
HTML
57 lines
2.0 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.NOT_SUPPORTED_ERR);
|
|
expectException(function() {
|
|
context.createBuffer(2, 2048, 96001);
|
|
}, DOMException.NOT_SUPPORTED_ERR);
|
|
context.createBuffer(2, 2048, 8000); // no exception
|
|
context.createBuffer(2, 2048, 96000); // no exception
|
|
expectException(function() {
|
|
context.createBuffer(2, 0, 48000);
|
|
}, DOMException.NOT_SUPPORTED_ERR);
|
|
SpecialPowers.clearUserPref("media.webaudio.enabled");
|
|
SimpleTest.finish();
|
|
});
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|