content/media/test/test_fastSeek.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=778077
     5 -->
     6 <head>
     7   <meta charset="utf-8">
     8   <title>Test for Bug 778077</title>
     9   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    11   <script type="text/javascript" src="manifest.js"></script>
    12 </head>
    13 <body>
    14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=778077">Mozilla Bug 778077</a>
    15 <p id="display"></p>
    16 <div id="content" style="display: none">
    18 </div>
    19 <pre id="test">
    20 </pre>
    21   <script type="application/javascript">
    23     /** Test for Bug 778077 - HTMLMediaElement.fastSeek() **/
    24     // Iterate through a list of keyframe timestamps, and seek to
    25     // halfway between the keyframe and the keyframe after it.
    26     var manager = new MediaTestManager;
    28     function doSeek(v) {
    29       // fastSeek to half way between this keyframe and the next, or if this is the last
    30       // keyframe seek to halfway between this keyframe and the end of media.
    31       var nextKeyFrame = (v.keyframeIndex + 1) < v.keyframes.length ? v.keyframes[v.keyframeIndex + 1] : v.duration;
    32       v.target = (v.keyframes[v.keyframeIndex] + nextKeyFrame) / 2;
    33       v.fastSeek(v.target);
    34       ok(Math.abs(v.currentTime - v.target) < 0.01,
    35          v.name + " seekTo=" + v.target + " currentTime (" + v.currentTime + ") should be close to seek target initially");
    36     }
    38     function onloadedmetadata(event) {
    39       var v = event.target;
    40       doSeek(v);
    41     }
    43     function onseeked(event) {
    44       var v = event.target;
    45       var keyframe = v.keyframes[v.keyframeIndex];
    47       // Check that the current time ended up roughly after the keyframe.
    48       // We must be a bit fuzzy here, as the decoder backend may actually
    49       // seek to the audio sample prior to the keyframe.
    50       ok(v.currentTime >= keyframe - 0.05,
    51          v.name + " seekTo=" + v.target + " currentTime (" + v.currentTime +
    52          ") should be end up roughly after keyframe (" + keyframe + ") after fastSeek");
    54       ok(v.currentTime <= v.target,
    55          v.name + " seekTo=" + v.target + " currentTime (" + v.currentTime +
    56          ") should be end up less than target after fastSeek");
    58       v.keyframeIndex++
    59       if (v.keyframeIndex == v.keyframes.length) {
    60         v.src = "";
    61         v.parentNode.removeChild(v);
    62         manager.finished(v.token);
    63       } else {
    64         doSeek(v);
    65       }
    66     }
    68     function startTest(test, token) {
    69       manager.started(token);
    70       v = document.createElement("video");
    71       v.src = test.name;
    72       v.name = test.name;
    73       v.preload = "metadata";
    74       v.token = token;
    75       v.target = 0;
    76       v.keyframes = test.keyframes;
    77       v.keyframeIndex = 0;
    78       ok(v.keyframes.length > 0, v.name + " - video should have at least one sync point");
    79       v.addEventListener("loadedmetadata", onloadedmetadata);
    80       v.addEventListener("seeked", onseeked);
    81       document.body.appendChild(v);
    82     }
    84     manager.runTests(gFastSeekTests, startTest);
    86   </script>
    87 </body>
    88 </html>

mercurial