2009-03-08 13:59:08 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=479859
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 479859</title>
|
|
|
|
<script type="application/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>
|
2009-03-08 13:59:08 -07:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=479859">Mozilla Bug 479859</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
function log(msg) {
|
|
|
|
//document.getElementById('log').innerHTML += "<p>" + msg + "</p>";
|
|
|
|
}
|
|
|
|
|
2009-04-26 18:03:47 -07:00
|
|
|
// We don't track: progress, canplay, canplaythrough and stalled events,
|
|
|
|
// as these can be delivered out of order, and/or multiple times.
|
2009-10-09 04:48:33 -07:00
|
|
|
var gEventTypes = [ 'loadstart', 'abort', 'error', 'emptied', 'play',
|
2009-07-09 19:03:01 -07:00
|
|
|
'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'seeking',
|
|
|
|
'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ];
|
2009-03-08 13:59:08 -07:00
|
|
|
|
|
|
|
var gEventNum = 0;
|
|
|
|
var gTestNum = 0;
|
2009-07-09 19:03:01 -07:00
|
|
|
var gTestFileNum = 0;
|
2009-03-08 13:59:08 -07:00
|
|
|
var gExpectedEvents = null;
|
|
|
|
var gTest = null;
|
|
|
|
var gTestName = "?";
|
|
|
|
|
|
|
|
function listener(evt) {
|
|
|
|
log('event ' + evt.type);
|
|
|
|
ok(gEventNum < gExpectedEvents.length, gTestName+" - corrent number of events received");
|
|
|
|
var expected = (gEventNum < gExpectedEvents.length) ? gExpectedEvents[gEventNum] : "NoEvent";
|
|
|
|
is(evt.type, expected, gTestName+" - events received in order");
|
|
|
|
gEventNum++;
|
|
|
|
if (gEventNum == gExpectedEvents.length) {
|
|
|
|
setTimeout(nextTest, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-04 17:44:33 -07:00
|
|
|
function source_error(evt) {
|
|
|
|
log('event source_error');
|
|
|
|
ok(evt.type == "error", "Should only get error events here");
|
|
|
|
ok(gEventNum < gExpectedEvents.length, gTestName+" - corrent number of events received");
|
|
|
|
var expected = (gEventNum < gExpectedEvents.length) ? gExpectedEvents[gEventNum] : "NoEvent";
|
|
|
|
is("source_error", expected, gTestName+" - events received in order");
|
|
|
|
gEventNum++;
|
|
|
|
if (gEventNum == gExpectedEvents.length) {
|
|
|
|
setTimeout(nextTest, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
var gMedia = null;
|
|
|
|
|
|
|
|
function createMedia(tag) {
|
|
|
|
gMedia = document.createElement(tag);
|
2014-01-16 21:58:48 -08:00
|
|
|
gMedia.preload = "auto";
|
2009-03-08 13:59:08 -07:00
|
|
|
for (var i=0; i<gEventTypes.length; i++) {
|
|
|
|
gMedia.addEventListener(gEventTypes[i], listener, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addSource(src, type) {
|
|
|
|
var s = document.createElement("source");
|
2010-11-04 17:44:33 -07:00
|
|
|
s.addEventListener("error", source_error, false);
|
2009-03-08 13:59:08 -07:00
|
|
|
s.src = src;
|
|
|
|
s.type = type;
|
|
|
|
gMedia.appendChild(s);
|
2010-11-04 17:44:33 -07:00
|
|
|
return s;
|
2009-03-08 13:59:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function prependSource(src, type) {
|
|
|
|
var s = document.createElement("source");
|
2010-11-04 17:44:33 -07:00
|
|
|
s.addEventListener("error", source_error, false);
|
2009-03-08 13:59:08 -07:00
|
|
|
s.src = src;
|
|
|
|
s.type = type;
|
|
|
|
gMedia.insertBefore(s, gMedia.firstChild);
|
2010-11-04 17:44:33 -07:00
|
|
|
return s;
|
2009-03-08 13:59:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var gTests = [
|
|
|
|
{
|
|
|
|
// Test 0: adding video to doc, then setting src should load implicitly.
|
|
|
|
create:
|
2009-07-09 19:03:01 -07:00
|
|
|
function(src, type) {
|
2009-03-08 13:59:08 -07:00
|
|
|
document.body.appendChild(gMedia);
|
2009-07-09 19:03:01 -07:00
|
|
|
gMedia.src = src;
|
2009-03-08 13:59:08 -07:00
|
|
|
},
|
2012-11-22 02:38:29 -08:00
|
|
|
expectedEvents: ['ratechange', 'loadstart', 'durationchange', 'loadedmetadata', 'loadeddata']
|
2009-03-08 13:59:08 -07:00
|
|
|
}, {
|
2009-07-09 19:03:01 -07:00
|
|
|
// Test 1: adding video to doc, then adding source.
|
2009-03-08 13:59:08 -07:00
|
|
|
create:
|
2009-07-09 19:03:01 -07:00
|
|
|
function(src, type) {
|
2009-03-08 13:59:08 -07:00
|
|
|
document.body.appendChild(gMedia);
|
2009-07-09 19:03:01 -07:00
|
|
|
addSource(src, type);
|
2009-03-08 13:59:08 -07:00
|
|
|
},
|
2009-10-09 04:48:33 -07:00
|
|
|
expectedEvents: ['loadstart', 'durationchange', 'loadedmetadata', 'loadeddata']
|
2010-09-02 17:03:03 -07:00
|
|
|
},{
|
|
|
|
// Test 2: video with multiple source, the first of which are bad, we should load the last,
|
|
|
|
// and receive error events for failed loads on the source children.
|
2009-03-08 13:59:08 -07:00
|
|
|
create:
|
2009-07-09 19:03:01 -07:00
|
|
|
function(src, type) {
|
2009-03-08 13:59:08 -07:00
|
|
|
document.body.appendChild(gMedia);
|
2009-07-09 19:03:01 -07:00
|
|
|
addSource("404a", type);
|
|
|
|
addSource("404b", type);
|
|
|
|
addSource(src, type);
|
2009-03-08 13:59:08 -07:00
|
|
|
},
|
2010-11-04 17:44:33 -07:00
|
|
|
expectedEvents: ['loadstart', 'source_error', 'source_error', 'durationchange', 'loadedmetadata', 'loadeddata']
|
2009-03-08 13:59:08 -07:00
|
|
|
}, {
|
2009-07-09 19:03:01 -07:00
|
|
|
// Test 3: video with bad src, good <source>, ensure that <source> aren't used.
|
2009-03-08 13:59:08 -07:00
|
|
|
create:
|
2009-07-09 19:03:01 -07:00
|
|
|
function(src, type) {
|
|
|
|
gMedia.src = "404a";
|
|
|
|
addSource(src, type);
|
2009-03-08 13:59:08 -07:00
|
|
|
document.body.appendChild(gMedia);
|
|
|
|
},
|
2012-11-22 02:38:29 -08:00
|
|
|
expectedEvents: ['ratechange', 'loadstart', 'error']
|
2009-03-08 13:59:08 -07:00
|
|
|
}, {
|
2009-07-09 19:03:01 -07:00
|
|
|
// Test 4: video with only bad source, loading, then adding a good source
|
|
|
|
// - should resume load.
|
2009-03-08 13:59:08 -07:00
|
|
|
create:
|
2009-07-09 19:03:01 -07:00
|
|
|
function(src, type) {
|
|
|
|
addSource("404a", type);
|
2010-11-04 17:44:33 -07:00
|
|
|
var s2 = addSource("404b", type);
|
|
|
|
s2.addEventListener("error",
|
2009-03-08 13:59:08 -07:00
|
|
|
function(e) {
|
|
|
|
// Should awaken waiting load, causing successful load.
|
2009-07-09 19:03:01 -07:00
|
|
|
addSource(src, type);
|
2009-03-08 13:59:08 -07:00
|
|
|
},
|
|
|
|
false);
|
|
|
|
document.body.appendChild(gMedia);
|
|
|
|
},
|
2010-11-04 17:44:33 -07:00
|
|
|
expectedEvents: ['loadstart', 'source_error', 'source_error', 'durationchange', 'loadedmetadata', 'loadeddata']
|
2009-03-08 13:59:08 -07:00
|
|
|
}, {
|
2009-07-09 19:03:01 -07:00
|
|
|
// Test 5: video with only 1 bad source, let it fail to load, then prepend
|
|
|
|
// a good <source> to the video, it shouldn't be selected, because the
|
|
|
|
// "pointer" should be after the last child - the bad source.
|
2009-03-08 13:59:08 -07:00
|
|
|
prepended: false,
|
|
|
|
create:
|
2009-07-09 19:03:01 -07:00
|
|
|
function(src, type) {
|
|
|
|
var prepended = false;
|
|
|
|
addSource("404a", type);
|
2010-11-04 17:44:33 -07:00
|
|
|
var s2 = addSource("404b", type);
|
|
|
|
s2.addEventListener("error",
|
2009-03-08 13:59:08 -07:00
|
|
|
function(e) {
|
|
|
|
// Should awaken waiting load, causing successful load.
|
2009-07-09 19:03:01 -07:00
|
|
|
if (!prepended) {
|
|
|
|
prependSource(src, type);
|
|
|
|
prepended = true;
|
2009-03-08 13:59:08 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
false);
|
|
|
|
document.body.appendChild(gMedia);
|
|
|
|
},
|
2010-11-04 17:44:33 -07:00
|
|
|
expectedEvents: ['loadstart', 'source_error', 'source_error']
|
2009-03-08 13:59:08 -07:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
function nextTest() {
|
|
|
|
if (gMedia) {
|
2014-01-16 21:58:48 -08:00
|
|
|
for (var i=0; i<gEventTypes.length; i++) {
|
|
|
|
gMedia.removeEventListener(gEventTypes[i], listener, false);
|
|
|
|
}
|
|
|
|
removeNodeAndSource(gMedia);
|
2009-03-08 13:59:08 -07:00
|
|
|
gMedia = null;
|
|
|
|
}
|
|
|
|
gEventNum = 0;
|
2014-01-16 21:58:48 -08:00
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
if (gTestNum == gTests.length) {
|
2009-07-09 19:03:01 -07:00
|
|
|
gTestNum = 0;
|
|
|
|
++gTestFileNum;
|
|
|
|
if (gTestFileNum == gSmallTests.length) {
|
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
}
|
2009-03-08 13:59:08 -07:00
|
|
|
}
|
2009-07-09 19:03:01 -07:00
|
|
|
|
|
|
|
var src = gSmallTests[gTestFileNum].name;
|
|
|
|
var type = gSmallTests[gTestFileNum].type;
|
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
var t = gTests[gTestNum];
|
|
|
|
gTestNum++;
|
|
|
|
|
2009-07-09 19:03:01 -07:00
|
|
|
createMedia(type.match(/^audio\//) ? "audio" : "video");
|
2009-07-14 07:04:56 -07:00
|
|
|
if (!gMedia.canPlayType(type)) {
|
2009-07-09 19:03:01 -07:00
|
|
|
// Unsupported type, skip to next test
|
|
|
|
nextTest();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gTestName = "Test " + src + " " + (gTestNum - 1);
|
|
|
|
log("Starting " + gTestName);
|
2009-03-08 13:59:08 -07:00
|
|
|
gExpectedEvents = t.expectedEvents;
|
2009-07-09 19:03:01 -07:00
|
|
|
|
|
|
|
t.create(src, type);
|
2009-03-08 13:59:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
addLoadEvent(nextTest);
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<div id="log" style="font-size: small"></div>
|
|
|
|
</body>
|
|
|
|
</html>
|