content/media/test/test_chaining.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/test/test_chaining.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Media test: chained ogg files.</title>
     1.8 +  <meta charset='utf-8'>
     1.9 +  <script type="text/javascript" src="/MochiKit/Base.js"></script>
    1.10 +  <script type="text/javascript" src="/MochiKit/DOM.js"></script>
    1.11 +  <script type="text/javascript" src="/MochiKit/Style.js"></script>
    1.12 +  <script type="text/javascript" src="/MochiKit/Signal.js"></script>
    1.13 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.15 +  <script type="text/javascript" src="manifest.js"></script>
    1.16 +</head>
    1.17 +<body>
    1.18 +<pre id="test">
    1.19 +<script class="testbody" type="text/javascript">
    1.20 +var manager = new MediaTestManager;
    1.21 +
    1.22 +function finish_test(element) {
    1.23 +  if (element.parentNode)
    1.24 +    element.parentNode.removeChild(element);
    1.25 +  manager.finished(element.token);
    1.26 +}
    1.27 +
    1.28 +function onended(e) {
    1.29 +  var t = e.target;
    1.30 +  is(t._metadataCount, t._links, "We should have received "+ t._links +
    1.31 +     " metadataloaded event. " + t.src);
    1.32 +
    1.33 +  // If we encounter a file that has links with a different numbers of channel,
    1.34 +  // we stop the decoding at the end of the first link. Hence, we report normal
    1.35 +  // |seekable| and |buffered| values.
    1.36 +  if (t._links != 1) {
    1.37 +    is(t.seekable.length, 0, "No seekable ranges should be reported." + t.src);
    1.38 +    is(t.buffered.length, 0, "No buffered region should be reported." + t.src);
    1.39 +  }
    1.40 +
    1.41 +  is(t.played.length, 1, "The played region should be continuous." + t.src);
    1.42 +
    1.43 +  if (t._links != 1) {
    1.44 +    var oldCurrentTime = t.currentTime;
    1.45 +    t.currentTime = 0.0;
    1.46 +    is(t.currentTime, oldCurrentTime,
    1.47 +        "Seeking should be disabled when playing chained media." + t.src);
    1.48 +  }
    1.49 +
    1.50 +  finish_test(t);
    1.51 +}
    1.52 +
    1.53 +function onmetadataloaded(e) {
    1.54 +  var t = e.target;
    1.55 +  if (! t._metadataCount) {
    1.56 +    t._metadataCount = 0;
    1.57 +  }
    1.58 +
    1.59 +  if (t._metadataCount > 1 && t._links === 1) {
    1.60 +    ok(false, "We should receive only one \"loadedmetadata\" event for a chained file we don't support.")
    1.61 +  }
    1.62 +
    1.63 +  // We should be able to assert equality here, but somehow it fails (rarely but
    1.64 +  // still) on try. Instead, we give it a little slack and assert that the index
    1.65 +  // increases monotonically.
    1.66 +  ok(t.mozGetMetadata().index >= t._metadataCount || t._links === 1,
    1.67 +     "The metadata index value should increase." + t.src);
    1.68 +
    1.69 +  // The files have all a user comment name 'index' that increments at each link
    1.70 +  // in the chained media.
    1.71 +  t._metadataCount++;
    1.72 +  if (!t.playing && !t.ended) {
    1.73 +    t.play();
    1.74 +  }
    1.75 +}
    1.76 +
    1.77 +function startTest(test, token) {
    1.78 +  var elemType = /^audio/.test(test.type) ? "audio" : "video";
    1.79 +  var element = document.createElement(elemType);
    1.80 +  document.body.appendChild(element);
    1.81 +  manager.started(token);
    1.82 +  element._links= test.links;
    1.83 +  element.src = test.name;
    1.84 +  element.token = token;
    1.85 +  element.controls = true;
    1.86 +  element.addEventListener("loadedmetadata", onmetadataloaded);
    1.87 +  element.addEventListener("ended", onended);
    1.88 +}
    1.89 +
    1.90 +manager.runTests(gChainingTests, startTest);
    1.91 +</script>
    1.92 +</pre>
    1.93 +</body>
    1.94 +</html>

mercurial