Bug 1059265 - reduce number of concurrent playback and active cubeb streams to avoid hitting bug 847903.

This commit is contained in:
JW Wang 2014-09-16 19:35:00 +12:00
parent 3139d9e61c
commit f6db5be896
2 changed files with 42 additions and 31 deletions

View File

@ -5,29 +5,45 @@
var loadsWaiting = 0; var loadsWaiting = 0;
var elements = []; var elements = [];
function loadedData(event) { function checkAllLoaded() {
parent.ok(elements.indexOf(event.target) == -1, "Element already loaded: " + event.target.currentSrc);
elements.push(event.target);
--loadsWaiting; --loadsWaiting;
parent.ok(true, "Loaded " + event.target.currentSrc);
if (loadsWaiting == 0) { if (loadsWaiting == 0) {
parent.loadedAll(elements); parent.loadedAll(elements);
} }
} }
function loadedData(event) {
var e = event.target;
parent.ok(elements.indexOf(e) == -1, "Element already loaded: " + e._name);
parent.info("Loaded " + e._name);
elements.push(e);
// Reset "onerror" handler to avoid triggering another error in removeNodeAndSource().
e.onerror = null;
checkAllLoaded();
}
function error(event) {
var e = event.target;
parent.info("Error " + e._name);
// Don't wait for the element encounting errors.
checkAllLoaded();
}
for (var i = 0; i < parent.gSmallTests.length; ++i) { for (var i = 0; i < parent.gSmallTests.length; ++i) {
var test = parent.gSmallTests[i]; var test = parent.gSmallTests[i];
var elemType = /^audio/.test(test.type) ? "audio" : "video"; var elemType = /^audio/.test(test.type) ? "audio" : "video";
// Associate these elements with the subframe's document // Associate these elements with the subframe's document
var e = document.createElement(elemType); var e = document.createElement(elemType);
e.preload = "auto"; e.preload = "metadata";
if (e.canPlayType(test.type)) { if (e.canPlayType(test.type)) {
e.src = test.name; e.src = test.name;
e.addEventListener("loadeddata", loadedData, false); e._name = test.name;
e.onloadeddata = loadedData;
e.onerror = error;
e.load(); e.load();
++loadsWaiting; ++loadsWaiting;
parent.info("Loading " + e._name);
} }
} }

View File

@ -13,28 +13,27 @@
<pre id="test"> <pre id="test">
<script class="testbody" type="text/javascript"> <script class="testbody" type="text/javascript">
var testsWaiting;
var elements; var elements;
function didPlay(event) { function playElement(e) {
ok(true, "Element ended: " + event.target.currentSrc); // All elements played out, finish the test case.
if (!e) {
removeNodeAndSource(event.target);
--testsWaiting;
if (testsWaiting == 0) {
SimpleTest.finish(); SimpleTest.finish();
} return;
}
function reviveElements() {
// reactivate the elements by moving them to our document
for (var i = 0; i < elements.length; ++i) {
document.body.appendChild(elements[i]);
elements[i].addEventListener("ended", didPlay, false);
} }
testsWaiting = elements.length; e.play();
info("Element play: " + e._name);
var reviveElement = function() {
document.body.appendChild(e);
e.onended = function() {
info("Element ended: " + e._name);
removeNodeAndSource(e);
// Play next element.
playElement(elements.pop());
}
}
setTimeout(reviveElement, 2000);
} }
function loadedAll(elementList) { function loadedAll(elementList) {
@ -43,12 +42,8 @@ function loadedAll(elementList) {
// Blow away the subframe // Blow away the subframe
document.body.removeChild(document.getElementById("frame")); document.body.removeChild(document.getElementById("frame"));
// Start the elements playing. // Play elements one by one to avoid hitting bug 847903 on MacOSX.
for (var i = 0; i < elements.length; ++i) { playElement(elements.pop());
elements[i].play();
}
setTimeout(reviveElements, 2000);
} }
</script> </script>
</pre> </pre>