Bug 881954 - Generalize test_too_many_elements to run on more than just Ogg audio. r=padenot

This commit is contained in:
Chris Pearce 2013-06-14 09:07:07 +12:00
parent bdc0b78b4e
commit 24f7039d0b
2 changed files with 52 additions and 11 deletions

View File

@ -494,6 +494,25 @@ var gMetadataTests = [
}, },
]; ];
// The resources for test_too_many_elements.
// We loads *lots* of these all at the same time.
var gTooManyElementAudioTests = [
{ name:"small-shot.ogg", type:"audio/ogg" },
{ name:"r11025_s16_c1.wav", type:"audio/x-wav" },
{ name:"detodos.opus", type:"audio/ogg; codecs=opus" },
{ name:"bogus.duh", type:"bogus/duh" }
];
// Unfortunately the WMF backend on Windows 7 can't handle having lots of
// decoders running concurrently, so we only include MPEG files when running on
// Windows versions 8 and later, and non Windows systems.
if (navigator.userAgent.indexOf("Windows") == -1 ||
IsWindows8OrLater()) {
gTooManyElementAudioTests = gTooManyElementAudioTests.concat([
{ name:"small-shot.m4a", type:"audio/mp4" },
{ name:"small-shot.mp3", type:"audio/mpeg" }
]);
}
function checkMetadata(msg, e, test) { function checkMetadata(msg, e, test) {
if (test.width) { if (test.width) {
is(e.videoWidth, test.width, msg + " video width"); is(e.videoWidth, test.width, msg + " video width");

View File

@ -24,43 +24,65 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=713381
const num = 500; const num = 500;
var loadeddata = 0; var loadeddata = 0;
var testName = "?";
var result = document.getElementById("result"); var result = document.getElementById("result");
document.getElementById("expected").innerHTML = " of " + num + " "; document.getElementById("expected").innerHTML = " of " + num + " ";
var finish = function(testNum) { var finish = function(testNum) {
return function() { return function() {
ok(true, "Received loadeddata event for instance " + testNum ); ok(true, testName + ": received loadeddata event for instance " + testNum );
loadeddata++; loadeddata++;
if (loadeddata == num) { if (loadeddata == num) {
ok(true, "Should receive loadeddata events for all " + num + " elements."); ok(true, testName + ": should receive loadeddata events for all " + num + " elements.");
SimpleTest.finish(); nextTest();
} }
} }
}; };
var resource = getPlayableAudio(gSmallTests); var testNum = 0;
function nextTest() {
if (testNum >= gTooManyElementAudioTests.length) {
SimpleTest.finish();
return;
}
var test = gTooManyElementAudioTests[testNum];
testNum++;
if (!document.createElement("audio").canPlayType(test.type)) {
setTimeout(nextTest, 0);
return;
}
var name = test.name;
loadeddata = 0;
testName = name;
if (resource == null) {
todo(false, "No types supported");
} else {
SimpleTest.waitForExplicitFinish();
// Load the resource, and play it to ensure it's entirely downloaded. // Load the resource, and play it to ensure it's entirely downloaded.
// Once it's played through, create a large number of audio elements which // Once it's played through, create a large number of audio elements which
// are the same resource. These will share data with the other resource, and // are the same resource. These will share data with the other resource, and
// so be really cheap to create. // so be really cheap to create.
var res = new Audio(resource.name); var res = new Audio(name);
res.addEventListener("ended", res.addEventListener("ended",
function() { function() {
for (var i=0; i<num; ++i) { for (var i=0; i<num; ++i) {
var a = new Audio(resource.name); var a = new Audio(name);
a.addEventListener("loadeddata", finish(i), false); a.addEventListener("loadeddata", finish(i), false);
} }
}, false); }, false);
res.play(); res.play();
} }
setInterval(function() { result.innerHTML = loadeddata; }, 1000); if (getPlayableAudio(gTooManyElementAudioTests) == null) {
todo(false, "No types supported");
} else {
SimpleTest.waitForExplicitFinish();
nextTest();
}
setInterval(function() { result.innerHTML = testName + ": " + loadeddata; }, 1000);
</script> </script>
</pre> </pre>