gecko-dev/dom/media/test/test_playback.html
Jean-Yves Avenard 39c3ecdd59 Bug 1431169 - P3. Stop playback mochitest on error. r=rillian
Otherwise we need to wait for the test to timeout as the ended event won't be fired.

MozReview-Commit-ID: HKgkG40Dz6w

--HG--
extra : rebase_source : 686e04096d8efc8ee1e4d8024b8b2c9bf52a76a5
2018-01-17 22:38:02 +01:00

123 lines
3.5 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test playback of media files that should play OK</title>
<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 manager = new MediaTestManager;
function startTest(test, token) {
var v = document.createElement('video');
v.preload = "metadata";
v.token = token;
v.prevTime = 0;
v.seenEnded = false;
v.seenSuspend = false;
var handler = {
"ontimeout": function() {
Log(token, "timed out: ended=" + v.seenEnded + ", suspend=" + v.seenSuspend);
}
};
manager.started(token, handler);
v.src = test.name;
v.name = test.name;
var check = function(test, v) { return function() {
is(test.name, v.name, test.name + ": Name should match #1");
checkMetadata(test.name, v, test);
}}(test, v);
var noLoad = function(test, v) { return function() {
ok(false, test.name + " should not fire 'load' event");
}}(test, v);
var noError = function(test, v) { return function() {
ok(false, test.name + " should not fire 'error' event " + v.error.message);
}}(test, v);
var finish = function() {
v.finished = true;
v.removeEventListener("timeupdate", timeUpdate);
removeNodeAndSource(v);
manager.finished(v.token);
}
// We should get "ended" and "suspend" events to finish the test.
var mayFinish = function() {
if (v.seenEnded && v.seenSuspend) {
finish();
}
}
var checkEnded = function(test, v) { return function() {
is(test.name, v.name, test.name + ": Name should match #2");
checkMetadata(test.name, v, test);
is(v.readyState, v.HAVE_CURRENT_DATA, test.name + " checking readyState");
ok(v.ended, test.name + " checking playback has ended");
ok(!v.finished, test.name + " shouldn't be finished");
ok(!v.seenEnded, test.name + " shouldn't be ended");
v.seenEnded = true;
mayFinish();
}}(test, v);
var checkSuspended = function(test, v) { return function() {
if (v.seenSuspend) {
return;
}
is(test.name, v.name, test.name + ": Name should match #3");
v.seenSuspend = true;
mayFinish();
}}(test, v);
var timeUpdate = function(test, v) { return function() {
if (v.prevTime > v.currentTime) {
ok(false, test.name + " time should run forwards: p=" +
v.prevTime + " c=" + v.currentTime);
}
v.prevTime = v.currentTime;
}}(test, v);
v.addEventListener("load", noLoad);
v.addEventListener("error", noError);
v.addEventListener("loadedmetadata", check);
v.addEventListener("timeupdate", timeUpdate);
// We should get "ended" and "suspend" events for every resource
v.addEventListener("ended", checkEnded);
v.addEventListener("suspend", checkSuspended);
document.body.appendChild(v);
v.play();
// Debug timeouts on slow platforms.
if (isSlowPlatform()) {
var events = ["suspend", "play", "canplay", "canplaythrough", "loadstart", "loadedmetadata",
"loadeddata", "playing", "ended", "error", "stalled", "emptied", "abort",
"waiting", "pause"];
function logEvent(e) {
var v = e.target;
Log(e.target.token, "got " + e.type);
}
events.forEach(function(e) {
v.addEventListener(e, logEvent);
});
}
}
manager.runTests(gPlayTests, startTest);
</script>
</pre>
</body>
</html>