2008-12-15 19:32:03 -08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Media test: media selection</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
2009-07-09 19:03:01 -07:00
|
|
|
<script type="application/javascript" src="manifest.js"></script>
|
2008-12-15 19:32:03 -08:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
2010-08-26 19:11:46 -07:00
|
|
|
var manager = new MediaTestManager;
|
2008-12-15 19:32:03 -08:00
|
|
|
|
2009-07-09 19:03:01 -07:00
|
|
|
function maketest(attach_media, name, type, check_metadata) {
|
2010-08-26 19:11:46 -07:00
|
|
|
return function (token) {
|
2008-12-15 19:32:03 -08:00
|
|
|
var e = document.createElement('video');
|
2010-08-26 19:11:46 -07:00
|
|
|
manager.started(token);
|
2009-02-15 17:05:28 -08:00
|
|
|
var errorRun = false;
|
2009-07-09 19:03:01 -07:00
|
|
|
if (check_metadata) {
|
2009-02-15 17:05:28 -08:00
|
|
|
e.addEventListener('loadedmetadata', function () {
|
2008-12-15 19:32:03 -08:00
|
|
|
ok(e.readyState >= HTMLMediaElement.HAVE_METADATA,
|
2010-08-26 19:11:46 -07:00
|
|
|
'test ' + token + ' readyState ' + e.readyState + ' expected >= ' + HTMLMediaElement.HAVE_METADATA);
|
|
|
|
is(e.currentSrc.substring(e.currentSrc.length - name.length), name, 'test ' + token);
|
2009-05-19 02:53:38 -07:00
|
|
|
// The load can go idle due to cache size limits
|
|
|
|
ok(e.networkState >= HTMLMediaElement.NETWORK_IDLE,
|
2010-08-26 19:11:46 -07:00
|
|
|
'test ' + token + ' networkState = ' + e.networkState + ' expected >= ' + HTMLMediaElement.NETWORK_IDLE);
|
2008-12-15 19:32:03 -08:00
|
|
|
check_metadata(e);
|
|
|
|
e.parentNode.removeChild(e);
|
2010-08-26 19:11:46 -07:00
|
|
|
manager.finished(token);
|
2008-12-15 19:32:03 -08:00
|
|
|
}, false);
|
|
|
|
} else {
|
2009-02-15 17:05:28 -08:00
|
|
|
e.addEventListener('error', function(event) {
|
|
|
|
is(errorRun, false, "error handler should run once only!");
|
|
|
|
errorRun = true;
|
|
|
|
is(e.readyState, HTMLMediaElement.HAVE_NOTHING,
|
2010-08-26 19:11:46 -07:00
|
|
|
'test ' + token + ' readyState should be HAVE_NOTHING when load fails.');
|
2009-02-15 17:05:28 -08:00
|
|
|
e.parentNode.removeChild(e);
|
2010-08-26 19:11:46 -07:00
|
|
|
manager.finished(token);
|
2010-11-04 17:44:33 -07:00
|
|
|
}, true);
|
2010-08-26 19:11:46 -07:00
|
|
|
}
|
2009-02-15 17:05:28 -08:00
|
|
|
attach_media(e, name, type);
|
2008-12-15 19:32:03 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2009-07-09 19:03:01 -07:00
|
|
|
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;
|
|
|
|
|
2009-07-14 07:04:56 -07:00
|
|
|
if (!tmpVid.canPlayType(type))
|
2009-07-09 19:03:01 -07:00
|
|
|
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) {
|
2009-07-09 19:03:01 -07:00
|
|
|
checkMetadata(test.name, e, test);
|
2009-07-09 19:03:01 -07:00
|
|
|
}}(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),
|
2008-12-15 19:32:03 -08:00
|
|
|
|
|
|
|
// type hint matches a decoder, actual type matches different decoder
|
2009-07-09 19:03:01 -07:00
|
|
|
maketest(add_source, src, otherType, check),
|
|
|
|
maketest(add_source, 'unknown.raw', type, null),
|
2008-12-15 19:32:03 -08:00
|
|
|
|
|
|
|
// should not start loading, type excludes it from media candiate list
|
2009-07-09 19:03:01 -07:00
|
|
|
maketest(add_source, src, 'bogus/type', null),
|
2008-12-15 19:32:03 -08:00
|
|
|
|
|
|
|
// element doesn't notice source children attached later, needs bug 462455 fixed
|
2009-07-09 19:03:01 -07:00
|
|
|
maketest(late_add_sources_last, src, type, check),
|
|
|
|
maketest(late_add_sources_first, src, type, check));
|
|
|
|
}
|
2008-12-15 19:32:03 -08:00
|
|
|
|
2010-08-26 19:11:46 -07:00
|
|
|
function startTest(test, token) {
|
|
|
|
test(token);
|
2008-12-15 19:32:03 -08:00
|
|
|
}
|
|
|
|
|
2010-08-26 19:11:46 -07:00
|
|
|
manager.runTests(subtests, startTest);
|
|
|
|
|
2008-12-15 19:32:03 -08:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|