gecko/content/media/test/test_framebuffer.html

107 lines
3.0 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=490705
-->
<head>
<title>Media test: framebuffer size checks</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<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>
<!-- mute audio, since there is no need to hear the sound for these tests -->
<audio id='a1' controls></audio>
<pre id="test">
<script class="testbody" type="text/javascript">
var testFile = "bug495794.ogg";
var testFileDuration = 0.30;
var testFileChannelCount = 6;
var testFileSampleRate = 48000;
var testFileFrameBufferLength = 6 * 1024;
var undef;
var currentSampleOffset = 0;
var isTimePropertyValid = true;
function audioAvailable(event) {
var buffer = event.frameBuffer;
if ( (typeof event.time !== "number") ||
(Math.abs(event.time - currentSampleOffset / testFileSampleRate / testFileChannelCount) > 0.01) ) {
isTimePropertyValid = false;
}
currentSampleOffset += buffer.length;
}
var loadedMetadataCalled = false;
function loadedMetadata() {
loadedMetadataCalled = true;
var a1 = document.getElementById('a1');
is(a1.mozChannels, testFileChannelCount, "mozChannels should be " + testFileChannelCount + ".");
is(a1.mozSampleRate, testFileSampleRate, "mozSampleRate should be " + testFileSampleRate + ".");
is(a1.mozFrameBufferLength, testFileFrameBufferLength, "default mozFrameBufferLength should be " + testFileFrameBufferLength + ".");
var minFailed = false;
try {
a1.mozFrameBufferLength = 4;
} catch(e) {
minFailed = true;
}
ok(minFailed, "mozFrameBufferLength min fail check");
var maxFailed = false;
try {
a1.mozFrameBufferLength = 44444;
} catch(e) {
maxFailed = true;
}
ok(maxFailed, "mozFrameBufferLength max fail check");
a1.mozFrameBufferLength = testFileFrameBufferLength;
}
function checkResults() {
ok(loadedMetadataCalled, "loadedmetadata event not dispatched.");
ok(isTimePropertyValid, "The audioAvailable event's time attribute was invalid.");
var expectedOffset = Math.ceil(testFileDuration * testFileSampleRate * testFileChannelCount);
if (expectedOffset % testFileFrameBufferLength !== 0) {
expectedOffset += (testFileFrameBufferLength - (expectedOffset % testFileFrameBufferLength));
}
is(currentSampleOffset, expectedOffset, "Check amount of signal data processed");
SimpleTest.finish();
}
function audioEnded() {
checkResults();
}
function initTest() {
var a1 = document.getElementById('a1');
a1.addEventListener("ended", audioEnded, false);
a1.addEventListener("loadedmetadata", loadedMetadata, false);
a1.addEventListener("MozAudioAvailable", audioAvailable, false);
a1.src = testFile;
a1.muted = true;
a1.play();
}
window.addEventListener("load", function(e) {
initTest();
}, false);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>