gecko/content/media/test/test_info_leak.html
Chris Pearce c7317b404d Bug 564720 - Refactor media tests to be backend independent were possible. r=roc
--HG--
rename : content/media/test/test_play.html => content/media/test/test_play_events.html
rename : content/media/test/test_progress2.html => content/media/test/test_progress.html
rename : content/media/test/test_onloadedmetadata.html => content/media/test/test_replay_metadata.html
rename : content/media/test/test_wav_trunc_seek.html => content/media/test/test_seek_out_of_range.html
rename : content/media/test/test_bug495319.html => content/media/test/test_timeupdate_small_files.html
rename : content/media/test/test_bug486646.html => content/media/test/test_video_to_canvas.html
2010-05-31 10:02:06 +12:00

149 lines
4.4 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() {
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);
evt.stopPropagation();
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;
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 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==HTMLMediaError.MEDIA_ERR_SRC_NOT_SUPPORTED,
"Error code should not exist or be SRC_NOT_SUPPORTED. gMedia.error=" +
(gMedia.error ? gMedia.error.code : "null"));
test_is(gMedia.currentSrc, "", "Leaked currentSrc");
}
if (!gFinished) {
setTimeout(checkState, 1);
}
}
function startTest() {
setTimeout(nextTest, 0);
setTimeout(checkState,1);
}
addLoadEvent(startTest);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>