mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
156 lines
5.1 KiB
HTML
156 lines
5.1 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Media test: media selection</title>
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
<script type="application/javascript" src="manifest.js"></script>
|
|
</head>
|
|
<body>
|
|
<pre id="test">
|
|
<script class="testbody" type="text/javascript">
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
function maketest(attach_media, name, type, check_metadata) {
|
|
return function (testNum) {
|
|
var e = document.createElement('video');
|
|
var errorRun = false;
|
|
if (check_metadata) {
|
|
e.addEventListener('loadedmetadata', function () {
|
|
ok(e.readyState >= HTMLMediaElement.HAVE_METADATA,
|
|
'test ' + testNum + ' readyState ' + e.readyState + ' expected >= ' + HTMLMediaElement.HAVE_METADATA);
|
|
is(e.currentSrc.substring(e.currentSrc.length - name.length), name, 'test ' + testNum);
|
|
// The load can go idle due to cache size limits
|
|
ok(e.networkState >= HTMLMediaElement.NETWORK_IDLE,
|
|
'test ' + testNum + ' networkState = ' + e.networkState + ' expected >= ' + HTMLMediaElement.NETWORK_IDLE);
|
|
check_metadata(e);
|
|
e.parentNode.removeChild(e);
|
|
runNextTest();
|
|
}, false);
|
|
e.addEventListener('error', function(e) { e.stopPropagation();}, false);
|
|
} else {
|
|
e.addEventListener('error', function(event) {
|
|
event.stopPropagation();
|
|
is(errorRun, false, "error handler should run once only!");
|
|
errorRun = true;
|
|
is(e.readyState, HTMLMediaElement.HAVE_NOTHING,
|
|
'test ' + testNum + ' readyState should be HAVE_NOTHING when load fails.');
|
|
e.parentNode.removeChild(e);
|
|
runNextTest();
|
|
}, false);
|
|
}
|
|
attach_media(e, name, type);
|
|
}
|
|
}
|
|
|
|
function set_src(element, name, type) {
|
|
element.src = name;
|
|
document.body.appendChild(element);
|
|
}
|
|
|
|
function add_source(element, name, type) {
|
|
do_add_source(element, name, type);
|
|
document.body.appendChild(element);
|
|
}
|
|
|
|
function do_add_source(element, name, type) {
|
|
var source = document.createElement('source');
|
|
if (type) {
|
|
source.type = type;
|
|
}
|
|
source.src = name;
|
|
element.appendChild(source);
|
|
}
|
|
|
|
function add_sources_last(element, name, type) {
|
|
do_add_source(element, name, 'unsupported/type');
|
|
do_add_source(element, name, type);
|
|
document.body.appendChild(element);
|
|
}
|
|
|
|
function add_sources_first(element, name, type) {
|
|
do_add_source(element, name, type);
|
|
do_add_source(element, name, 'unsupported/type');
|
|
document.body.appendChild(element);
|
|
}
|
|
|
|
function late_add_sources_last(element, name, type) {
|
|
document.body.appendChild(element);
|
|
do_add_source(element, name, 'unsupported/type');
|
|
do_add_source(element, name, type);
|
|
}
|
|
|
|
function late_add_sources_first(element, name, type) {
|
|
document.body.appendChild(element);
|
|
do_add_source(element, name, type);
|
|
do_add_source(element, name, 'unsupported/type');
|
|
}
|
|
|
|
var nextTest = 0;
|
|
var subtests = [
|
|
maketest(add_source, 'unknown.raw', 'bogus/type', null)
|
|
];
|
|
|
|
var tmpVid = document.createElement('video');
|
|
|
|
for (var i = 0; i < gSmallTests.length; ++i) {
|
|
var test = gSmallTests[i];
|
|
var src = test.name;
|
|
var type = test.type;
|
|
|
|
if (tmpVid.canPlayType(type) == "no")
|
|
continue;
|
|
|
|
// The following nested function hack is to ensure that 'test' is correctly
|
|
// captured in the closure and we don't end up getting the value 'test'
|
|
// had in the last iteration of the loop. I blame Brendan.
|
|
var check = function(test) { return function (e) {
|
|
if (test.width) {
|
|
is(e.videoWidth, test.width, "video width " + e.currentSrc);
|
|
}
|
|
if (test.height) {
|
|
is(e.videoHeight, test.height, "video height " + e.currentSrc);
|
|
}
|
|
if (test.duration) {
|
|
ok(Math.abs(e.duration - test.duration) < 0.1,
|
|
"duration " + e.currentSrc + " should be around " + test.duration);
|
|
}
|
|
}}(test);
|
|
|
|
var otherType = type.match(/^video\//) ? "audio/x-wav" : "video/ogg";
|
|
subtests.push(maketest(set_src, src, null, check),
|
|
maketest(add_source, src, null, check),
|
|
maketest(add_source, src, type, check),
|
|
maketest(add_sources_last, src, null, check),
|
|
maketest(add_sources_first, src, type, check),
|
|
|
|
// type hint matches a decoder, actual type matches different decoder
|
|
maketest(add_source, src, otherType, check),
|
|
maketest(add_source, 'unknown.raw', type, null),
|
|
|
|
// should not start loading, type excludes it from media candiate list
|
|
maketest(add_source, src, 'bogus/type', null),
|
|
|
|
// element doesn't notice source children attached later, needs bug 462455 fixed
|
|
maketest(late_add_sources_last, src, type, check),
|
|
maketest(late_add_sources_first, src, type, check));
|
|
}
|
|
|
|
function runNextTest() {
|
|
if (nextTest >= subtests.length) {
|
|
SimpleTest.finish();
|
|
return;
|
|
}
|
|
setTimeout(function () {
|
|
subtests[nextTest](nextTest);
|
|
nextTest += 1;
|
|
}, 0);
|
|
}
|
|
|
|
addLoadEvent(runNextTest);
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|