gecko/content/media/video/test/test_load_coalescing.html

103 lines
3.0 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=462455
-->
<head>
<title>Test for Bug 462455</title>
<script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=462455">Mozilla Bug 462455</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 462455 **/
/** Tests case described in bug 462455 comment 22. **/
var gLoadStartsCount = 0;
var gAbortCount = 0;
var gVolumeChanged = 0;
var gEmptiedCount = 0;
function errorHandler(e) {
e.stopPropagation();
}
function abortHandler() {
gAbortCount++;
}
function startHandler() {
gLoadStartsCount++;
}
function loadedHandler() {
is(gLoadStartsCount, 2, "Should have received 2 loadstarts.");
is(gAbortCount, 0, "Shouldn't have aborted any loads");
is(gVolumeChanged, 1, "Should have received volume changed");
is(gEmptiedCount, 1, "EmptiedCount should be 1");
gLoadStartsCount = 0;
gAbortCount = 0;
SimpleTest.finish();
}
function emptiedHandler() {
gEmptiedCount++;
}
function volumeChangeHandler() {
gVolumeChanged++;
}
function testEventOrder() {
var v = document.createElement('video');
v.addEventListener('error', errorHandler, false);
v.addEventListener('abort', abortHandler, false);
v.addEventListener('loadeddata', loadedHandler, false);
v.addEventListener('loadstart', startHandler, false);
v.addEventListener('volumechange', volumeChangeHandler, false);
v.addEventListener('emptied', emptiedHandler, false);
document.body.appendChild(v); // Queues implicit load. This should be silently cancelled by the next explicit load.
var s = document.createElement("source");
s.type = "bogus/type";
s.src = "error-404.ogv";
v.appendChild(s); // Will queue a load. This should be silently cancelled by the next explicit load.
v.load(); // Explicit load. Will cancel queued loads. Expect loadstart, emptied, error events.
v.muted = true; // Will queue a volumechanged event.
// Load continues in background asynchronously.
v.addEventListener('error',
function (event) {
event.stopPropagation();
var s2 = document.createElement("source");
s2.type = "application/ogg";
s2.src = "320x240.ogv";
v.appendChild(s2); // Will queue a load. Expect loadstart, loadeddata etc.
// Should coalesce with the previous load, so there should be 1 load, and volume changed should arrive first.
}, false);
// First two implicit loads will run and silently cancel themselves some time after this function returns. Expect no events.
// Then the volumechange event should run.
// Then the third implicit load (for s2) should run and succeed. Expect loadstart and loadeddata events.
}
addLoadEvent(testEventOrder);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>