gecko-dev/content/media/test/test_audiowrite.html

80 lines
2.2 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=490705
-->
<head>
<title>Media test: simple audio write checks</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=490705">Mozilla Bug 490705</a>
<pre id="test">
<script class="testbody" type="text/javascript">
var channels = 2;
var rate = 44100;
function runTests() {
var a1 = new Audio();
ok("mozSetup" in a1, "mozSetup should be supported");
ok("mozWriteAudio" in a1, "mozWriteAudio should be supported");
ok("mozCurrentSampleOffset" in a1, "mozCurrentSampleOffset should be supported");
try {
a1.mozSetup(channels, rate);
} catch (ex) {
todo(false, "Audio hardware is disabled, can't test audio write API");
SimpleTest.finish();
return;
}
is(a1.mozChannels, channels, "mozChannels should be " + channels + ".");
is(a1.mozSampleRate, rate, "mozSampleRate should be " + rate + ".");
is(a1.volume, 1.0, "volume should be 1.0 by default.");
// Make sure changing volume on audio changes write audio stream.
a1.volume = 0.5;
is(a1.volume, 0.5, "volume should have been changed to 0.5.");
a1.muted = true;
ok(a1.muted, "volume should be muted.");
is(a1.mozCurrentSampleOffset(), 0, "mozCurrentSampleOffset() not working.");
// Test writing with js array
var samples1 = [.5, .5];
var written = sampleOffset = a1.mozWriteAudio(samples1);
is(written, samples1.length, "Not all samples in JS Array written.");
// Test writing with Float32Array
var samples2 = Float32Array([.2, .3, .2, .3]);
written = a1.mozWriteAudio(samples2);
is(written, samples2.length, "Not all samples in Float32Array written.");
// Test passing the wrong arguments to mozWriteAudio.
var writeArgsOK = false;
try {
// incorrect, should throw
written = a1.mozWriteAudio(samples2.length, samples2);
} catch(e) {
writeArgsOK = true;
}
ok(writeArgsOK, "mozWriteAudio args test failed.");
SimpleTest.finish();
}
window.addEventListener("load", function(e) {
runTests();
}, false);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>