mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
191 lines
5.6 KiB
HTML
191 lines
5.6 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"/>
|
|
</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.
|
|
|
|
function fileUriToSrc(path, mustExist) {
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
const Ci = Components.interfaces;
|
|
const Cc = Components.classes;
|
|
const Cr = Components.results;
|
|
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
|
getService(Ci.nsIProperties);
|
|
var f = dirSvc.get("CurWorkD", Ci.nsILocalFile);
|
|
var split = path.split("/");
|
|
for(var i = 0; i < split.length; ++i) {
|
|
f.append(split[i]);
|
|
}
|
|
is(f.exists(), mustExist, 'File ' + path + ' existence mismatch');
|
|
return f.path;
|
|
}
|
|
|
|
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 gTests = [
|
|
{
|
|
tag: 'video',
|
|
src: fileUriToSrc("tests/content/media/test/320x240.ogv", true),
|
|
},{
|
|
tag: 'video',
|
|
src: fileUriToSrc("tests/content/media/test/404.ogv", false),
|
|
}, {
|
|
tag: 'audio',
|
|
src: fileUriToSrc("tests/content/media/test/r11025_s16_c1.wav", true),
|
|
}, {
|
|
tag: 'audio',
|
|
src: fileUriToSrc("tests/content/media/test/404.wav", false),
|
|
}, {
|
|
tag: 'audio',
|
|
src: fileUriToSrc("tests/content/media/test/bug461281.ogg", true),
|
|
}, {
|
|
tag: 'audio',
|
|
src: fileUriToSrc("tests/content/media/test/404.ogg", false),
|
|
}, {
|
|
tag: 'video',
|
|
src: 'http://localhost/404.ogv',
|
|
}, {
|
|
tag: 'audio',
|
|
src: 'http://localhost/404.wav',
|
|
}, {
|
|
tag: 'video',
|
|
src: 'http://example.com/tests/content/media/test/test_info_leak.html'
|
|
}, {
|
|
tag: 'audio',
|
|
src: 'http://example.com/tests/content/media/test/test_info_leak.html'
|
|
}
|
|
];
|
|
|
|
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 == gTests.length) {
|
|
gFinished = true;
|
|
SimpleTest.finish();
|
|
return;
|
|
}
|
|
if (gMedia && gMedia.parentNode) {
|
|
gMedia.parentNode.removeChild(gMedia);
|
|
gMedia = null;
|
|
}
|
|
var t = gTests[gTestNum];
|
|
|
|
log("Testing: " + t.tag + " @ " + t.src);
|
|
|
|
gTestNum++;
|
|
gEventNum = 0;
|
|
createMedia(t.tag, 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(tag, src) {
|
|
gMedia = document.createElement(tag);
|
|
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() {
|
|
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>
|