content/media/test/test_source.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/test/test_source.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Media test: append source child</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +  <script type="text/javascript" src="manifest.js"></script>
    1.11 +</head>
    1.12 +<body>
    1.13 +<video id="v1"></video>
    1.14 +<audio id="a1"></audio>
    1.15 +<pre id="test">
    1.16 +<script class="testbody" type="text/javascript">
    1.17 +var v1 = document.getElementById("v1");
    1.18 +var a1 = document.getElementById("a1");
    1.19 +v1.preload = "auto";
    1.20 +a1.preload = "auto";
    1.21 +
    1.22 +is(v1.src, "", "src should be null");
    1.23 +is(a1.src, "", "src should be null");
    1.24 +is(v1.currentSrc, "", "currentSrc should be null");
    1.25 +is(a1.currentSrc, "", "currentSrc should be null");
    1.26 +is(v1.childNodes.length, 0, "should have no children");
    1.27 +is(a1.childNodes.length, 0, "should have no children");
    1.28 +
    1.29 +function newSource(filter) {
    1.30 +  var test = null;
    1.31 +  var candidates = gSmallTests.filter(function(x){return filter.test(x.type);});
    1.32 +  if (candidates.length > 0) {
    1.33 +    var e = document.createElement("source");
    1.34 +    e.type = candidates[0].type;
    1.35 +    e.src = candidates[0].name;
    1.36 +    return e;
    1.37 +  } else {
    1.38 +    return null
    1.39 +  }
    1.40 +}
    1.41 +
    1.42 +var audioLoaded = false;
    1.43 +var videoLoaded = false;
    1.44 +
    1.45 +function loaded(e) {
    1.46 +  var media = e.target;
    1.47 +  ok(media.networkState > 0, "networkState should be > 0");
    1.48 +  is(media.childNodes.length, 1, "should have 1 child");
    1.49 +  var sourceFile = media.currentSrc.substring(media.currentSrc.lastIndexOf('/')+1);
    1.50 +  var resource = media.firstChild.src.substring(media.firstChild.src.lastIndexOf('/')+1);
    1.51 +  is(sourceFile, resource, "loaded wrong resource!");
    1.52 +  if (media == a1)
    1.53 +    audioLoaded = true;
    1.54 +  else if (media == v1)
    1.55 +    videoLoaded = true;
    1.56 +  if (audioLoaded && videoLoaded) {
    1.57 +    SimpleTest.finish();
    1.58 +  }
    1.59 +}
    1.60 +
    1.61 +v1.addEventListener('loadeddata', loaded, false);
    1.62 +a1.addEventListener('loadeddata', loaded, false);
    1.63 +
    1.64 +var videoSource = newSource(/^video/);
    1.65 +if (videoSource) {
    1.66 +  v1.appendChild(videoSource);
    1.67 +  v1.load();
    1.68 +} else {
    1.69 +  // No video backends? Don't test anything.
    1.70 +  videoLoaded = true;
    1.71 +}
    1.72 +
    1.73 +var audioSource = newSource(/^audio/);
    1.74 +if (audioSource) {
    1.75 +  a1.appendChild(audioSource);
    1.76 +  a1.load();
    1.77 +} else {
    1.78 +  audioLoaded = true;
    1.79 +}
    1.80 +
    1.81 +if (!audioLoaded && !videoLoaded) {
    1.82 +  SimpleTest.waitForExplicitFinish();
    1.83 +} else {
    1.84 +  if (audioLoaded) {
    1.85 +    todo(false, "No audio types supported");
    1.86 +  }
    1.87 +  if (videoLoaded) {
    1.88 +    todo(false, "No video types supported");
    1.89 +  }
    1.90 +}
    1.91 +
    1.92 +</script>
    1.93 +</pre>
    1.94 +</body>
    1.95 +</html>

mercurial