2009-02-15 17:05:28 -08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Media test: append source child</title>
|
|
|
|
<script type="text/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-02-15 17:05:28 -08:00
|
|
|
</head>
|
|
|
|
<body>
|
2010-11-04 17:44:33 -07:00
|
|
|
<video id="v1"></video>
|
|
|
|
<audio id="a1"></audio>
|
2009-02-15 17:05:28 -08:00
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
var v1 = document.getElementById("v1");
|
|
|
|
var a1 = document.getElementById("a1");
|
|
|
|
|
|
|
|
is(v1.src, "", "src should be null");
|
|
|
|
is(a1.src, "", "src should be null");
|
|
|
|
is(v1.currentSrc, "", "currentSrc should be null");
|
|
|
|
is(a1.currentSrc, "", "currentSrc should be null");
|
|
|
|
is(v1.childNodes.length, 0, "should have no children");
|
|
|
|
is(a1.childNodes.length, 0, "should have no children");
|
|
|
|
|
2010-05-30 15:02:06 -07:00
|
|
|
function newSource(filter) {
|
|
|
|
var test = null;
|
|
|
|
var candidates = gSmallTests.filter(function(x){return filter.test(x.type);});
|
2009-02-15 17:05:28 -08:00
|
|
|
var e = document.createElement("source");
|
2010-05-30 15:02:06 -07:00
|
|
|
e.type = candidates[0].type;
|
|
|
|
e.src = candidates[0].name;
|
2009-02-15 17:05:28 -08:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
var audioLoaded = false;
|
|
|
|
var videoLoaded = false;
|
|
|
|
|
2010-05-30 15:02:06 -07:00
|
|
|
function loaded(e) {
|
|
|
|
var media = e.target;
|
2009-02-15 17:05:28 -08:00
|
|
|
ok(media.networkState > 0, "networkState should be > 0");
|
|
|
|
is(media.childNodes.length, 1, "should have 1 child");
|
2010-05-30 15:02:06 -07:00
|
|
|
var sourceFile = media.currentSrc.substring(media.currentSrc.lastIndexOf('/')+1);
|
|
|
|
var resource = media.firstChild.src.substring(media.firstChild.src.lastIndexOf('/')+1);
|
|
|
|
is(sourceFile, resource, "loaded wrong resource!");
|
2009-02-15 17:05:28 -08:00
|
|
|
if (media == a1)
|
|
|
|
audioLoaded = true;
|
|
|
|
else if (media == v1)
|
|
|
|
videoLoaded = true;
|
|
|
|
if (audioLoaded && videoLoaded) {
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-30 15:02:06 -07:00
|
|
|
v1.addEventListener('loadeddata', loaded, false);
|
|
|
|
a1.addEventListener('loadeddata', loaded, false);
|
2009-02-15 17:05:28 -08:00
|
|
|
|
2010-05-30 15:02:06 -07:00
|
|
|
var videoSource = newSource(/^video/);
|
|
|
|
if (videoSource) {
|
|
|
|
v1.appendChild(videoSource);
|
|
|
|
v1.load();
|
|
|
|
} else {
|
|
|
|
// No video backends? Don't test anything.
|
|
|
|
videoLoaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var audioSource = newSource(/^audio/);
|
|
|
|
if (audioSource) {
|
|
|
|
a1.appendChild(audioSource);
|
|
|
|
a1.load();
|
|
|
|
} else {
|
|
|
|
audioLoaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!audioLoaded && !videoLoaded) {
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
} else {
|
|
|
|
todo(false, "No types supported");
|
|
|
|
}
|
2009-02-15 17:05:28 -08:00
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|