gecko/content/media/test/test_playback_errors.html

75 lines
2.0 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML>
<html>
<head>
<title>Test playback of media files that should have errors</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" />
<script type="text/javascript" src="manifest.js"></script>
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
var PARALLEL_TESTS = 2;
var testIndex = 0;
var videos = [];
var testsWaiting = 0;
function startTests() {
for (var i = 0; i < videos.length; ++i) {
document.body.removeChild(videos[i]);
}
videos = [];
while (videos.length < PARALLEL_TESTS && testIndex < gErrorTests.length) {
var v = document.createElement('video');
var test = gErrorTests[testIndex];
++testIndex;
if (!v.canPlayType(test.type))
continue;
v.src = test.name;
v._errorCount = 0;
v._ignore = false;
function endedTest(v) {
if (v._ignore)
return;
v._ignore = true;
--testsWaiting;
if (testsWaiting == 0) {
setTimeout(startTests, 0);
}
}
var checkError = function(test, v) { return function(evt) {
evt.stopPropagation();
v._errorCount++;
is(v._errorCount, 1, test.name + " only one error fired");
endedTest(v);
}}(test, v);
var checkEnded = function(test, v) { return function() {
ok(false, test.name + " successfully played");
endedTest(v);
}}(test, v);
v.addEventListener("error", checkError, false);
v.addEventListener("ended", checkEnded, false);
++testsWaiting;
document.body.appendChild(v);
v.play();
videos.push(v);
}
if (videos.length == 0) {
// No new tests were spawned, perhaps the remaining tests on the list are
// not supported, or we just reached the end of the list.
SimpleTest.finish();
}
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(startTests);
</script>
</pre>
</body>
</html>