Bug 845676 - Remove most of the assertion annotations in the content/media mochitests...
[gecko.git] / content / media / test / test_framebuffer.html
blob915aada2d8fb0662d8bc905ada4321af0bd3d2db
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=490705
5 -->
7 <head>
8 <title>Media test: framebuffer size checks</title>
9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=490705">Mozilla Bug 490705</a>
15 <!-- mute audio, since there is no need to hear the sound for these tests -->
16 <audio id='a1' controls></audio>
18 <pre id="test">
19 <script class="testbody" type="text/javascript">
20 var testFile = "bug495794.ogg";
21 var testFileDuration = 0.30;
22 var testFileChannelCount = 6;
23 var testFileSampleRate = 48000;
24 var testFileFrameBufferLength = 6 * 1024;
26 var undef;
28 var currentSampleOffset = 0;
29 var isTimePropertyValid = true;
31 function audioAvailable(event) {
32 var buffer = event.frameBuffer;
34 if ( (typeof event.time !== "number") ||
35 (Math.abs(event.time - currentSampleOffset / testFileSampleRate / testFileChannelCount) > 0.01) ) {
36 isTimePropertyValid = false;
39 currentSampleOffset += buffer.length;
42 var loadedMetadataCalled = false;
43 function loadedMetadata() {
44 loadedMetadataCalled = true;
45 var a1 = document.getElementById('a1');
46 is(a1.mozChannels, testFileChannelCount, "mozChannels should be " + testFileChannelCount + ".");
47 is(a1.mozSampleRate, testFileSampleRate, "mozSampleRate should be " + testFileSampleRate + ".");
48 is(a1.mozFrameBufferLength, testFileFrameBufferLength, "default mozFrameBufferLength should be " + testFileFrameBufferLength + ".");
50 var minFailed = false;
51 try {
52 a1.mozFrameBufferLength = 4;
53 } catch(e) {
54 minFailed = true;
56 ok(minFailed, "mozFrameBufferLength min fail check");
58 var maxFailed = false;
59 try {
60 a1.mozFrameBufferLength = 44444;
61 } catch(e) {
62 maxFailed = true;
64 ok(maxFailed, "mozFrameBufferLength max fail check");
66 a1.mozFrameBufferLength = testFileFrameBufferLength;
69 function checkResults() {
70 ok(loadedMetadataCalled, "loadedmetadata event not dispatched.");
71 ok(isTimePropertyValid, "The audioAvailable event's time attribute was invalid.");
73 var expectedOffset = Math.ceil(testFileDuration * testFileSampleRate * testFileChannelCount);
74 if (expectedOffset % testFileFrameBufferLength !== 0) {
75 expectedOffset += (testFileFrameBufferLength - (expectedOffset % testFileFrameBufferLength));
77 is(currentSampleOffset, expectedOffset, "Check amount of signal data processed");
79 SimpleTest.finish();
82 function audioEnded() {
83 checkResults();
86 function initTest() {
87 var a1 = document.getElementById('a1');
88 a1.addEventListener("ended", audioEnded, false);
89 a1.addEventListener("loadedmetadata", loadedMetadata, false);
90 a1.addEventListener("MozAudioAvailable", audioAvailable, false);
91 a1.src = testFile;
92 a1.muted = true;
93 a1.play();
96 window.addEventListener("load", function(e) {
97 initTest();
98 }, false);
100 SimpleTest.waitForExplicitFinish();
102 </script>
103 </pre>
104 </body>
105 </html>