gecko-dev/content/media/test/test_info_leak.html

156 строки
4.7 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=478957
-->
<head>
<title>Test for Bug 478957</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/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>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478957">Mozilla Bug 478957</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<div id="log" style="font-size: small;"></div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 478957 **/
// Tests whether we leak events and state change info when loading stuff from local files from a webserver.
var gEventTypes = [ 'loadstart', 'progress', 'suspend', 'abort', 'error', 'emptied', 'stalled', 'play', 'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'canplay', 'canplaythrough', 'seeking', 'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ];
var gMedia = null;
var gExpectedEvents = ['loadstart', 'error'];
var gTestNum = 0;
var gEventNum = 0;
var gFinished = false;
function log(msg) {
//dump(msg + "\n");
var l = document.getElementById('log');
l.innerHTML += msg + "<br>";
}
function nextTest() {
mediaTestCleanup();
if (gTestNum == gInfoLeakTests.length) {
gFinished = true;
SimpleTest.finish();
return;
}
if (gMedia && gMedia.parentNode) {
gMedia.parentNode.removeChild(gMedia);
gMedia = null;
}
var t = gInfoLeakTests[gTestNum];
log("Testing: " + t.type + " @ " + t.src);
gTestNum++;
gEventNum = 0;
createMedia(t.type, t.src);
}
function listener(evt) {
//log('event ' + evt.type);
ok(gEventNum < gExpectedEvents.length, "Too many events received");
var expected = (gEventNum < gExpectedEvents.length) ? gExpectedEvents[gEventNum] : "NoEvent";
is(evt.type, expected, "Events received in wrong order");
gEventNum++;
if (gEventNum == gExpectedEvents.length) {
// In one second, move onto the next test. This give a chance for any
// other events to come in. Note: we don't expect any events to come
// in, unless we've leaked some info, and 1 second should be enough time
// for the leak to show up.
setTimeout(nextTest, 1000);
}
}
function createMedia(type, src) {
var tag = /^video/.test(type) ? "video" : "audio";
gMedia = document.createElement(tag);
if (!gMedia.canPlayType(type)) {
gMedia = null;
setTimeout(nextTest, 0);
return;
}
for (var i=0; i<gEventTypes.length; i++) {
gMedia.addEventListener(gEventTypes[i], listener, false);
}
gMedia.src = src;
gMedia._name = src;
document.body.appendChild(gMedia);
}
// Define our own ok() and is() functions. The mochitest ones take ages constructing the log
// of all the passes, so only report failures.
function test_ok(b, msg) {
if (!b) {
log("FAILED test_ok: " + msg);
ok(b, msg);
}
}
function test_is(a, b, msg) {
if (a != b) {
log("FAILED test_is: " + msg);
is(a,b,msg);
}
}
function filename(uri) {
return uri.substr(uri.lastIndexOf("/")+1);
}
function checkState() {
if (gMedia != null) {
test_ok(gMedia.networkState <= HTMLMediaElement.NETWORK_LOADING ||
gMedia.networkState == HTMLMediaElement.NETWORK_NO_SOURCE,
"NetworkState of " + gMedia.networkState + " was leaked.");
test_ok(gMedia.readyState == HTMLMediaElement.HAVE_NOTHING,
"Ready state of " + gMedia.readyState + " was leaked");
test_is(gMedia.seeking, false, "Seeking leaked");
test_is(gMedia.currentTime, 0, "Leaked currentTime");
test_ok(isNaN(gMedia.duration), "Leaked duration");
test_is(gMedia.paused, true, "Paused leaked");
test_is(gMedia.ended, false, "Ended leaked");
test_is(gMedia.autoplay, false, "Autoplay leaked");
test_is(gMedia.controls, false, "Controls leaked");
test_is(gMedia.muted, false, "muted leaked");
test_ok(gMedia.error==null || gMedia.error.code==MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED,
"Error code should not exist or be SRC_NOT_SUPPORTED. gMedia.error=" +
(gMedia.error ? gMedia.error.code : "null"));
test_ok(filename(gMedia.currentSrc) == filename(gMedia._name) ||
gMedia.networkState == HTMLMediaElement.NETWORK_NO_SOURCE,
"currentSrc should match candidate uri, if we've got a valid source");
}
if (!gFinished) {
setTimeout(checkState, 1);
}
}
function startTest() {
setTimeout(nextTest, 0);
setTimeout(checkState,1);
}
addLoadEvent(startTest);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>