Bug 1208371 - Wait for "loadedmetadata" before setting up nodes in test_mediaElementAudioSourceNodeCrossOrigin.html. r?padenot
MozReview-Commit-ID: HruqsknDHi7
--- a/dom/media/webaudio/test/test_mediaElementAudioSourceNodeCrossOrigin.html
+++ b/dom/media/webaudio/test/test_mediaElementAudioSourceNodeCrossOrigin.html
@@ -34,24 +34,34 @@ var testsRemaining = tests.length;
tests.forEach(function(e) {
e.ac = new AudioContext();
var a = new Audio();
if (e.cors) {
a.crossOrigin = e.cors;
}
a.src = e.url;
- var measn = e.ac.createMediaElementSource(a);
- var sp = e.ac.createScriptProcessor(2048, 1);
- // Set a couple expandos to track the status of the test
- sp.seenSound = false;
+ document.body.appendChild(a);
- measn.connect(sp);
- a.play();
- document.body.appendChild(a);
+ a.onloadedmetadata = () => {
+ // Wait for "loadedmetadata" before capturing since tracks are then known
+ // directly. If we set up the capture before "loadedmetadata" we
+ // (internally) have to wait an extra async jump for tracks to become known
+ // to main thread, before setting up audio data forwarding to the node.
+ // As that happens, the audio resource may have already ended on slow test
+ // machines, causing failures.
+ a.onloadedmetadata = null;
+ var measn = e.ac.createMediaElementSource(a);
+ var sp = e.ac.createScriptProcessor(2048, 1);
+ sp.seenSound = false;
+ sp.onaudioprocess = checkBufferSilent;
+
+ measn.connect(sp);
+ a.play();
+ };
function checkFinished(sp) {
if (a.ended) {
sp.onaudioprocess = null;
var not = e.expectSilence ? "" : "not";
is(e.expectSilence, !sp.seenSound,
"Buffer is " + not + " silent as expected, for " +
e.url + " (cors: " + e.cors + ")");
@@ -72,15 +82,13 @@ tests.forEach(function(e) {
}
// It is acceptable to find a full buffer of silence here, even if we expect
// sound, because Gecko's looping on media elements is not seamless and we
// can underrun. We are looking for at least one buffer of non-silent data.
e.target.seenSound = !silent || e.target.seenSound;
checkFinished(e.target);
return silent;
}
-
- sp.onaudioprocess = checkBufferSilent;
});
</script>
</pre>
</body>
</html>