2009-03-08 14:02:14 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=478957
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 478957</title>
|
2009-05-06 13:46:04 -07:00
|
|
|
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
2009-03-08 14:02:14 -07:00
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
2010-05-30 15:02:06 -07:00
|
|
|
<script type="text/javascript" src="manifest.js"></script>
|
2009-03-08 14:02:14 -07:00
|
|
|
</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.
|
|
|
|
|
|
|
|
|
2009-10-09 04:48:33 -07:00
|
|
|
var gEventTypes = [ 'loadstart', 'progress', 'suspend', 'abort', 'error', 'emptied', 'stalled', 'play', 'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'canplay', 'canplaythrough', 'seeking', 'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ];
|
2009-03-08 14:02:14 -07:00
|
|
|
|
|
|
|
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() {
|
2010-08-26 19:11:46 -07:00
|
|
|
mediaTestCleanup();
|
2010-05-30 15:02:06 -07:00
|
|
|
if (gTestNum == gInfoLeakTests.length) {
|
2009-03-08 14:02:14 -07:00
|
|
|
gFinished = true;
|
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (gMedia && gMedia.parentNode) {
|
|
|
|
gMedia.parentNode.removeChild(gMedia);
|
|
|
|
gMedia = null;
|
|
|
|
}
|
2010-05-30 15:02:06 -07:00
|
|
|
var t = gInfoLeakTests[gTestNum];
|
2009-03-08 14:02:14 -07:00
|
|
|
|
2010-05-30 15:02:06 -07:00
|
|
|
log("Testing: " + t.type + " @ " + t.src);
|
2009-03-08 14:02:14 -07:00
|
|
|
|
|
|
|
gTestNum++;
|
|
|
|
gEventNum = 0;
|
2010-05-30 15:02:06 -07:00
|
|
|
createMedia(t.type, t.src);
|
2009-03-08 14:02:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-30 15:02:06 -07:00
|
|
|
function createMedia(type, src) {
|
|
|
|
var tag = /^video/.test(type) ? "video" : "audio";
|
2009-03-08 14:02:14 -07:00
|
|
|
gMedia = document.createElement(tag);
|
2010-05-30 15:02:06 -07:00
|
|
|
if (!gMedia.canPlayType(type)) {
|
|
|
|
gMedia = null;
|
|
|
|
setTimeout(nextTest, 0);
|
|
|
|
return;
|
|
|
|
}
|
2009-03-08 14:02:14 -07:00
|
|
|
for (var i=0; i<gEventTypes.length; i++) {
|
|
|
|
gMedia.addEventListener(gEventTypes[i], listener, false);
|
|
|
|
}
|
|
|
|
gMedia.src = src;
|
2010-09-02 17:03:03 -07:00
|
|
|
gMedia._name = src;
|
2009-03-08 14:02:14 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-02 17:03:03 -07:00
|
|
|
function filename(uri) {
|
|
|
|
return uri.substr(uri.lastIndexOf("/")+1);
|
|
|
|
}
|
|
|
|
|
2009-03-08 14:02:14 -07:00
|
|
|
function checkState() {
|
2010-05-30 15:02:06 -07:00
|
|
|
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");
|
2010-08-25 01:43:00 -07:00
|
|
|
test_ok(gMedia.error==null || gMedia.error.code==MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED,
|
2010-05-30 15:02:06 -07:00
|
|
|
"Error code should not exist or be SRC_NOT_SUPPORTED. gMedia.error=" +
|
|
|
|
(gMedia.error ? gMedia.error.code : "null"));
|
2010-09-02 17:03:03 -07:00
|
|
|
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");
|
2010-05-30 15:02:06 -07:00
|
|
|
}
|
2009-03-08 14:02:14 -07:00
|
|
|
if (!gFinished) {
|
|
|
|
setTimeout(checkState, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function startTest() {
|
|
|
|
setTimeout(nextTest, 0);
|
|
|
|
setTimeout(checkState,1);
|
|
|
|
}
|
|
|
|
|
|
|
|
addLoadEvent(startTest);
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|